Blender  V3.3
GridDensityProvider.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #pragma once
4 
10 #include <algorithm>
11 #include <memory>
12 #include <stdexcept>
13 
14 #include "AutoPtrHelper.h"
15 #include "OccluderSource.h"
16 
17 #include "../geometry/BBox.h"
18 
19 #include "BKE_global.h"
20 
21 #ifdef WITH_CXX_GUARDEDALLOC
22 # include "MEM_guardedalloc.h"
23 #endif
24 
25 namespace Freestyle {
26 
28  // Disallow copying and assignment
30  GridDensityProvider &operator=(const GridDensityProvider &other);
31 
32  public:
34  {
35  }
36 
37  virtual ~GridDensityProvider(){};
38 
39  float cellSize()
40  {
41  return _cellSize;
42  }
43 
44  unsigned cellsX()
45  {
46  return _cellsX;
47  }
48 
49  unsigned cellsY()
50  {
51  return _cellsY;
52  }
53 
54  float cellOrigin(int index)
55  {
56  if (index < 2) {
57  return _cellOrigin[index];
58  }
59  else {
60  throw new out_of_range("GridDensityProvider::cellOrigin can take only indexes of 0 or 1.");
61  }
62  }
63 
65  {
66  source.begin();
67  if (source.isValid()) {
68  const Vec3r &initialPoint = source.getGridSpacePolygon().getVertices()[0];
69  proscenium[0] = proscenium[1] = initialPoint[0];
70  proscenium[2] = proscenium[3] = initialPoint[1];
71  while (source.isValid()) {
73  source.next();
74  }
75  }
76  if (G.debug & G_DEBUG_FREESTYLE) {
77  cout << "Proscenium: (" << proscenium[0] << ", " << proscenium[1] << ", " << proscenium[2]
78  << ", " << proscenium[3] << ")" << endl;
79  }
80  }
81 
83  const BBox<Vec3r> &bbox,
84  real proscenium[4])
85  {
86  // Transform the coordinates of the 8 corners of the 3D bounding box
87  real xm = bbox.getMin()[0], xM = bbox.getMax()[0];
88  real ym = bbox.getMin()[1], yM = bbox.getMax()[1];
89  real zm = bbox.getMin()[2], zM = bbox.getMax()[2];
90  Vec3r p1 = transform(Vec3r(xm, ym, zm));
91  Vec3r p2 = transform(Vec3r(xm, ym, zM));
92  Vec3r p3 = transform(Vec3r(xm, yM, zm));
93  Vec3r p4 = transform(Vec3r(xm, yM, zM));
94  Vec3r p5 = transform(Vec3r(xM, ym, zm));
95  Vec3r p6 = transform(Vec3r(xM, ym, zM));
96  Vec3r p7 = transform(Vec3r(xM, yM, zm));
97  Vec3r p8 = transform(Vec3r(xM, yM, zM));
98  // Determine the proscenium face according to the min and max values of the transformed x and y
99  // coordinates
100  proscenium[0] = std::min(std::min(std::min(p1.x(), p2.x()), std::min(p3.x(), p4.x())),
101  std::min(std::min(p5.x(), p6.x()), std::min(p7.x(), p8.x())));
102  proscenium[1] = std::max(std::max(std::max(p1.x(), p2.x()), std::max(p3.x(), p4.x())),
103  std::max(std::max(p5.x(), p6.x()), std::max(p7.x(), p8.x())));
104  proscenium[2] = std::min(std::min(std::min(p1.y(), p2.y()), std::min(p3.y(), p4.y())),
105  std::min(std::min(p5.y(), p6.y()), std::min(p7.y(), p8.y())));
106  proscenium[3] = std::max(std::max(std::max(p1.y(), p2.y()), std::max(p3.y(), p4.y())),
107  std::max(std::max(p5.y(), p6.y()), std::max(p7.y(), p8.y())));
108  if (G.debug & G_DEBUG_FREESTYLE) {
109  cout << "Proscenium: " << proscenium[0] << ", " << proscenium[1] << ", " << proscenium[2]
110  << ", " << proscenium[3] << endl;
111  }
112  }
113 
114  protected:
116  unsigned _cellsX, _cellsY;
117  float _cellSize;
118  float _cellOrigin[2];
119 
120 #ifdef WITH_CXX_GUARDEDALLOC
121  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:GridDensityProvider")
122 #endif
123 };
124 
126  // Disallow copying and assignment
129 
130  public:
132  {
133  }
134 
136  const real proscenium[4]) = 0;
137 
139  OccluderSource &source,
140  const BBox<Vec3r> &bbox,
141  const GridHelpers::Transform &transform) = 0;
142 
144 
146  {
147  }
148 
149 #ifdef WITH_CXX_GUARDEDALLOC
150  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:GridDensityProviderFactory")
151 #endif
152 };
153 
154 } /* namespace Freestyle */
Utility header for auto_ptr/unique_ptr selection.
@ G_DEBUG_FREESTYLE
Definition: BKE_global.h:181
Read Guarded memory(de)allocation.
Class to define a cell grid surrounding the projected image of a scene.
SIMD_FORCE_INLINE btVector3 transform(const btVector3 &point) const
btGeneric6DofConstraint & operator=(btGeneric6DofConstraint &other)
const Point & getMax() const
Definition: BBox.h:72
const Point & getMin() const
Definition: BBox.h:67
const vector< Point > & getVertices() const
Definition: Polygon.h:67
virtual AutoPtr< GridDensityProvider > newGridDensityProvider(OccluderSource &source)=0
virtual AutoPtr< GridDensityProvider > newGridDensityProvider(OccluderSource &source, const real proscenium[4])=0
virtual AutoPtr< GridDensityProvider > newGridDensityProvider(OccluderSource &source, const BBox< Vec3r > &bbox, const GridHelpers::Transform &transform)=0
static void calculateOptimalProscenium(OccluderSource &source, real proscenium[4])
GridDensityProvider(OccluderSource &source)
static void calculateQuickProscenium(const GridHelpers::Transform &transform, const BBox< Vec3r > &bbox, real proscenium[4])
Polygon3r & getGridSpacePolygon()
value_type x() const
Definition: VecMat.h:518
value_type y() const
Definition: VecMat.h:528
#define G(x, y, z)
VecMat::Vec3< real > Vec3r
Definition: Geom.h:28
void expandProscenium(real proscenium[4], const Polygon3r &polygon)
Definition: GridHelpers.h:152
inherits from class Rep
Definition: AppCanvas.cpp:18
double real
Definition: Precision.h:12
#define min(a, b)
Definition: sort.c:35
float max