Blender  V2.93
ViewMapBuilder.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 #pragma once
18 
24 #include <vector>
25 
26 #include "GridDensityProvider.h"
27 #include "Silhouette.h"
28 #include "SilhouetteGeomEngine.h"
29 #include "ViewEdgeXBuilder.h"
30 #include "ViewMap.h"
31 
32 #include "../geometry/Geom.h"
33 #include "../geometry/GeomUtils.h"
34 #include "../geometry/Grid.h"
35 #include "../geometry/SweepLine.h"
36 
37 #include "../scene_graph/NodeGroup.h"
38 #include "../scene_graph/TriangleRep.h"
39 
40 #include "../system/FreestyleConfig.h"
41 #include "../system/ProgressBar.h"
42 #include "../system/RenderMonitor.h"
43 #include "../system/TimeUtils.h"
44 
45 #include "../winged_edge/WEdge.h"
46 #include "../winged_edge/WXEdge.h"
47 
48 #ifdef WITH_CXX_GUARDEDALLOC
49 # include "MEM_guardedalloc.h"
50 #endif
51 
52 namespace Freestyle {
53 
54 using namespace Geometry;
55 
57  private:
58  ViewMap *_ViewMap; // result
59  // SilhouetteGeomEngine _GeomEngine;
60  ProgressBar *_pProgressBar;
61  RenderMonitor *_pRenderMonitor;
62  Vec3r _viewpoint;
63  bool _orthographicProjection;
64  Grid *_Grid;
65  ViewEdgeXBuilder *_pViewEdgeBuilder;
66  bool _EnableQI;
67  double _epsilon;
68 
69  // tmp values:
70  int _currentId;
71  int _currentFId;
72  int _currentSVertexId;
73 
74  public:
75  typedef enum {
77  } intersection_algo;
78 
79  typedef enum {
87  } visibility_algo;
88 
89  inline ViewMapBuilder()
90  {
91  _pProgressBar = NULL;
92  _pRenderMonitor = NULL;
93  _Grid = NULL;
94  _currentId = 1;
95  _currentFId = 0;
96  _currentSVertexId = 0;
97  _pViewEdgeBuilder = new ViewEdgeXBuilder;
98  _EnableQI = true;
99  }
100 
102  {
103  if (_pViewEdgeBuilder) {
104  delete _pViewEdgeBuilder;
105  _pViewEdgeBuilder = NULL;
106  }
107  }
108 
109  /* Build Grid for ray casting */
111  void BuildGrid(WingedEdge &we, const BBox<Vec3r> &bbox, unsigned int sceneNumFaces);
112 
114  void computeInitialViewEdges(WingedEdge &);
115 
117  void computeCusps(ViewMap *ioViewMap);
118 
122  void DetectCusps(ViewEdge *ioEdge);
123 
125  inline void setViewpoint(const Vec3r &ivp)
126  {
127  _viewpoint = ivp;
129  }
130 
139  inline void setTransform(const real iModelViewMatrix[4][4],
140  const real iProjectionMatrix[4][4],
141  const int iViewport[4],
142  real iFocalLength,
143  real /*iAspect*/,
144  real /*iFovy*/)
145  {
146  _orthographicProjection = (iProjectionMatrix[3][3] != 0.0);
148  iModelViewMatrix, iProjectionMatrix, iViewport, iFocalLength);
149  }
150 
151  inline void setFrustum(real iZnear, real iZfar)
152  {
153  SilhouetteGeomEngine::setFrustum(iZnear, iZfar);
154  }
155 
161  ViewMap *BuildViewMap(WingedEdge &we,
162  visibility_algo iAlgo,
163  real epsilon,
164  const BBox<Vec3r> &bbox,
165  unsigned int sceneNumFaces);
166 
167  void CullViewEdges(ViewMap *ioViewMap,
168  real viewProscenium[4],
169  real occluderProscenium[4],
170  bool extensiveFEdgeSearch = true);
171 
180  void ComputeIntersections(ViewMap *ioViewMap,
181  intersection_algo iAlgo = sweep_line,
182  real epsilon = 1.0e-06);
183 
188  void ComputeEdgesVisibility(ViewMap *ioViewMap,
189  WingedEdge &we,
190  const BBox<Vec3r> &bbox,
191  unsigned int sceneNumFaces,
192  visibility_algo iAlgo = ray_casting,
193  real epsilon = 1.0e-6);
194 
195  void setGrid(Grid *iGrid)
196  {
197  _Grid = iGrid;
198  }
199 
203  inline void setProgressBar(ProgressBar *iProgressBar)
204  {
205  _pProgressBar = iProgressBar;
206  }
207 
208  inline void setRenderMonitor(RenderMonitor *iRenderMonitor)
209  {
210  _pRenderMonitor = iRenderMonitor;
211  }
212 
213  inline void setEnableQI(bool iBool)
214  {
215  _EnableQI = iBool;
216  }
217 
218  protected:
220  void ComputeSweepLineIntersections(ViewMap *ioViewMap, real epsilon = 1.0e-6);
221 
228  void ComputeRayCastingVisibility(ViewMap *ioViewMap, real epsilon = 1.0e-6);
229  void ComputeFastRayCastingVisibility(ViewMap *ioViewMap, real epsilon = 1.0e-6);
230  void ComputeVeryFastRayCastingVisibility(ViewMap *ioViewMap, real epsilon = 1.0e-6);
231 
232  void ComputeCumulativeVisibility(ViewMap *ioViewMap,
233  WingedEdge &we,
234  const BBox<Vec3r> &bbox,
235  real epsilon,
236  bool cull,
237  GridDensityProviderFactory &factory);
238  void ComputeDetailedVisibility(ViewMap *ioViewMap,
239  WingedEdge &we,
240  const BBox<Vec3r> &bbox,
241  real epsilon,
242  bool cull,
243  GridDensityProviderFactory &factory);
244 
260  int ComputeRayCastingVisibility(FEdge *fe,
261  Grid *iGrid,
262  real epsilon,
263  set<ViewShape *> &oOccluders,
264  Polygon3r **oaPolygon,
265  unsigned timestamp);
266  // FIXME
267  void FindOccludee(
268  FEdge *fe, Grid *iGrid, real epsilon, Polygon3r **oaPolygon, unsigned timestamp);
269  void FindOccludee(FEdge *fe,
270  Grid *iGrid,
271  real epsilon,
272  Polygon3r **oaPolygon,
273  unsigned timestamp,
274  Vec3r &u,
275  Vec3r &A,
276  Vec3r &origin,
277  Vec3r &edgeDir,
278  vector<WVertex *> &faceVertices);
279 
280 #ifdef WITH_CXX_GUARDEDALLOC
281  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewMapBuilder")
282 #endif
283 };
284 
285 } /* 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:32
double real
Definition: Precision.h:26
static double epsilon