Blender  V3.3
ViewMapBuilder.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #pragma once
4 
10 #include <vector>
11 
12 #include "GridDensityProvider.h"
13 #include "Silhouette.h"
14 #include "SilhouetteGeomEngine.h"
15 #include "ViewEdgeXBuilder.h"
16 #include "ViewMap.h"
17 
18 #include "../geometry/Geom.h"
19 #include "../geometry/GeomUtils.h"
20 #include "../geometry/Grid.h"
21 #include "../geometry/SweepLine.h"
22 
23 #include "../scene_graph/NodeGroup.h"
24 #include "../scene_graph/TriangleRep.h"
25 
26 #include "../system/FreestyleConfig.h"
27 #include "../system/ProgressBar.h"
28 #include "../system/RenderMonitor.h"
29 #include "../system/TimeUtils.h"
30 
31 #include "../winged_edge/WEdge.h"
32 #include "../winged_edge/WXEdge.h"
33 
34 #ifdef WITH_CXX_GUARDEDALLOC
35 # include "MEM_guardedalloc.h"
36 #endif
37 
38 namespace Freestyle {
39 
40 using namespace Geometry;
41 
43  private:
44  ViewMap *_ViewMap; // result
45  // SilhouetteGeomEngine _GeomEngine;
46  ProgressBar *_pProgressBar;
47  RenderMonitor *_pRenderMonitor;
48  Vec3r _viewpoint;
49  bool _orthographicProjection;
50  Grid *_Grid;
51  ViewEdgeXBuilder *_pViewEdgeBuilder;
52  bool _EnableQI;
53  double _epsilon;
54 
55  // tmp values:
56  int _currentId;
57  int _currentFId;
58  int _currentSVertexId;
59 
60  public:
61  typedef enum {
63  } intersection_algo;
64 
65  typedef enum {
73  } visibility_algo;
74 
75  inline ViewMapBuilder()
76  {
77  _pProgressBar = NULL;
78  _pRenderMonitor = NULL;
79  _Grid = NULL;
80  _currentId = 1;
81  _currentFId = 0;
82  _currentSVertexId = 0;
83  _pViewEdgeBuilder = new ViewEdgeXBuilder;
84  _EnableQI = true;
85  }
86 
87  inline ~ViewMapBuilder()
88  {
89  if (_pViewEdgeBuilder) {
90  delete _pViewEdgeBuilder;
91  _pViewEdgeBuilder = NULL;
92  }
93  }
94 
95  /* Build Grid for ray casting */
97  void BuildGrid(WingedEdge &we, const BBox<Vec3r> &bbox, unsigned int sceneNumFaces);
98 
100  void computeInitialViewEdges(WingedEdge &);
101 
103  void computeCusps(ViewMap *ioViewMap);
104 
108  void DetectCusps(ViewEdge *ioEdge);
109 
111  inline void setViewpoint(const Vec3r &ivp)
112  {
113  _viewpoint = ivp;
115  }
116 
125  inline void setTransform(const real iModelViewMatrix[4][4],
126  const real iProjectionMatrix[4][4],
127  const int iViewport[4],
128  real iFocalLength,
129  real /*iAspect*/,
130  real /*iFovy*/)
131  {
132  _orthographicProjection = (iProjectionMatrix[3][3] != 0.0);
134  iModelViewMatrix, iProjectionMatrix, iViewport, iFocalLength);
135  }
136 
137  inline void setFrustum(real iZnear, real iZfar)
138  {
139  SilhouetteGeomEngine::setFrustum(iZnear, iZfar);
140  }
141 
147  ViewMap *BuildViewMap(WingedEdge &we,
148  visibility_algo iAlgo,
149  real epsilon,
150  const BBox<Vec3r> &bbox,
151  unsigned int sceneNumFaces);
152 
153  void CullViewEdges(ViewMap *ioViewMap,
154  real viewProscenium[4],
155  real occluderProscenium[4],
156  bool extensiveFEdgeSearch = true);
157 
166  void ComputeIntersections(ViewMap *ioViewMap,
167  intersection_algo iAlgo = sweep_line,
168  real epsilon = 1.0e-06);
169 
174  void ComputeEdgesVisibility(ViewMap *ioViewMap,
175  WingedEdge &we,
176  const BBox<Vec3r> &bbox,
177  unsigned int sceneNumFaces,
178  visibility_algo iAlgo = ray_casting,
179  real epsilon = 1.0e-6);
180 
181  void setGrid(Grid *iGrid)
182  {
183  _Grid = iGrid;
184  }
185 
189  inline void setProgressBar(ProgressBar *iProgressBar)
190  {
191  _pProgressBar = iProgressBar;
192  }
193 
194  inline void setRenderMonitor(RenderMonitor *iRenderMonitor)
195  {
196  _pRenderMonitor = iRenderMonitor;
197  }
198 
199  inline void setEnableQI(bool iBool)
200  {
201  _EnableQI = iBool;
202  }
203 
204  protected:
206  void ComputeSweepLineIntersections(ViewMap *ioViewMap, real epsilon = 1.0e-6);
207 
214  void ComputeRayCastingVisibility(ViewMap *ioViewMap, real epsilon = 1.0e-6);
215  void ComputeFastRayCastingVisibility(ViewMap *ioViewMap, real epsilon = 1.0e-6);
216  void ComputeVeryFastRayCastingVisibility(ViewMap *ioViewMap, real epsilon = 1.0e-6);
217 
218  void ComputeCumulativeVisibility(ViewMap *ioViewMap,
219  WingedEdge &we,
220  const BBox<Vec3r> &bbox,
221  real epsilon,
222  bool cull,
223  GridDensityProviderFactory &factory);
224  void ComputeDetailedVisibility(ViewMap *ioViewMap,
225  WingedEdge &we,
226  const BBox<Vec3r> &bbox,
227  real epsilon,
228  bool cull,
229  GridDensityProviderFactory &factory);
230 
246  int ComputeRayCastingVisibility(FEdge *fe,
247  Grid *iGrid,
248  real epsilon,
249  set<ViewShape *> &oOccluders,
250  Polygon3r **oaPolygon,
251  unsigned timestamp);
252  // FIXME
253  void FindOccludee(
254  FEdge *fe, Grid *iGrid, real epsilon, Polygon3r **oaPolygon, unsigned timestamp);
255  void FindOccludee(FEdge *fe,
256  Grid *iGrid,
257  real epsilon,
258  Polygon3r **oaPolygon,
259  unsigned timestamp,
260  Vec3r &u,
261  Vec3r &A,
262  Vec3r &origin,
263  Vec3r &edgeDir,
264  vector<WVertex *> &faceVertices);
265 
266 #ifdef WITH_CXX_GUARDEDALLOC
267  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewMapBuilder")
268 #endif
269 };
270 
271 } /* namespace Freestyle */
Class to define a cell grid surrounding the projected image of a scene.
Read Guarded memory(de)allocation.
Class to perform all geometric operations dedicated to silhouette. That, for example,...
Classes to define a silhouette structure.
Class to build view edges and the underlying chains of feature edges...
Classes to define a View Map (ViewVertex, ViewEdge, etc.)
static void setViewpoint(const Vec3r &ivp)
static void setFrustum(real iZNear, real iZFar)
static void setTransform(const real iModelViewMatrix[4][4], const real iProjectionMatrix[4][4], const int iViewport[4], real iFocal)
void setTransform(const real iModelViewMatrix[4][4], const real iProjectionMatrix[4][4], const int iViewport[4], real iFocalLength, real, real)
void setGrid(Grid *iGrid)
void setEnableQI(bool iBool)
void setViewpoint(const Vec3r &ivp)
void setFrustum(real iZnear, real iZfar)
void setProgressBar(ProgressBar *iProgressBar)
void setRenderMonitor(RenderMonitor *iRenderMonitor)
void DetectCusps(ViewEdge *ioEdge)
inherits from class Rep
Definition: AppCanvas.cpp:18
double real
Definition: Precision.h:12
static double epsilon