1 | #ifndef _ViewCellsManager_H__
|
---|
2 | #define _ViewCellsManager_H__
|
---|
3 |
|
---|
4 | #include "Ray.h"
|
---|
5 | #include "VssRay.h"
|
---|
6 | #include "Containers.h"
|
---|
7 | #include "ViewCell.h"
|
---|
8 | #include "ViewCellBsp.h"
|
---|
9 |
|
---|
10 | class ViewCell;
|
---|
11 | class Intersectable;
|
---|
12 | class RenderSimulator;
|
---|
13 | class Renderer;
|
---|
14 | class Mesh;
|
---|
15 | struct Triangle3;
|
---|
16 | class SimulationStatistics;
|
---|
17 | class BspTree;
|
---|
18 | class KdTree;
|
---|
19 | class VspKdTree;
|
---|
20 | class VspBspTree;
|
---|
21 | class KdNode;
|
---|
22 | class KdLeaf;
|
---|
23 | class VspKdTree;
|
---|
24 | class AxisAlignedBox3;
|
---|
25 | class BspLeaf;
|
---|
26 | class ViewCellsStatistics;
|
---|
27 | class Exporter;
|
---|
28 | class Beam;
|
---|
29 | class Preprocessor;
|
---|
30 | class ViewCellsTree;
|
---|
31 | class MergeCandidate;
|
---|
32 |
|
---|
33 | struct BspRay;
|
---|
34 |
|
---|
35 |
|
---|
36 | /** Probably Visible Set */
|
---|
37 | class PrVs
|
---|
38 | {
|
---|
39 | public:
|
---|
40 | /// viewcells
|
---|
41 | ViewCellContainer mViewCells;
|
---|
42 | /// aggregated pvs
|
---|
43 | ObjectPvs mPvs;
|
---|
44 |
|
---|
45 | // input parameter is the render budget for the PrVS
|
---|
46 | float mRenderBudget;
|
---|
47 |
|
---|
48 | /// some characteristic values could be here
|
---|
49 |
|
---|
50 | };
|
---|
51 |
|
---|
52 | /**
|
---|
53 | Manages different higher order operations on the view cells.
|
---|
54 | */
|
---|
55 | class ViewCellsManager
|
---|
56 | {
|
---|
57 |
|
---|
58 | public:
|
---|
59 | struct PvsStatistics {
|
---|
60 | int minPvs;
|
---|
61 | int maxPvs;
|
---|
62 | float avgPvs;
|
---|
63 | int viewcells;
|
---|
64 | };
|
---|
65 |
|
---|
66 |
|
---|
67 | /// view cell container types
|
---|
68 | enum {BSP, KD, VSP_KD, VSP_BSP};
|
---|
69 |
|
---|
70 | /** Constructor taking the initial and construction samples.
|
---|
71 | @param initialSamples the maximal number of samples used for creating the hierarchy
|
---|
72 | of view cells
|
---|
73 | @param constructionSamples the maximal number of samples used for construction
|
---|
74 | */
|
---|
75 | ViewCellsManager(const int initialSamples, const int constructionSamples);
|
---|
76 |
|
---|
77 | ViewCellsManager();
|
---|
78 |
|
---|
79 | virtual ~ViewCellsManager();
|
---|
80 |
|
---|
81 | /** Constructs view cells container taking a preprocessor
|
---|
82 | @returns the output rays (if not null)
|
---|
83 | */
|
---|
84 | int Construct(Preprocessor *preprocessor, VssRayContainer *outRays = NULL);
|
---|
85 |
|
---|
86 | /** Constructs view cell container with a given number of samples.
|
---|
87 | */
|
---|
88 | virtual int ConstructSubdivision(const ObjectContainer &objects,
|
---|
89 | const VssRayContainer &rays) = 0;
|
---|
90 |
|
---|
91 | /** Computes sample contributions of the rays to the view cells PVS.
|
---|
92 |
|
---|
93 | @param rays bundle of rays used to find intersections with view cells and
|
---|
94 | adding the contribution
|
---|
95 | @param addRays true if rays should be added to the PVSs of the viewcells they
|
---|
96 | intersect
|
---|
97 | @param storeViewCells true if view cells should be stored in the ray
|
---|
98 | */
|
---|
99 | float ComputeSampleContributions(const VssRayContainer &rays,
|
---|
100 | const bool addContributions,
|
---|
101 | const bool storeViewCells);
|
---|
102 |
|
---|
103 | /** Add sample contributions to the viewcells they intersect */
|
---|
104 | void AddSampleContributions(const VssRayContainer &rays);
|
---|
105 |
|
---|
106 |
|
---|
107 | /** Computes sample contribution of a simgle ray to the view cells PVS.
|
---|
108 | @param ray finds intersections with view cells and holds the contribution
|
---|
109 | @param castRay true if ray should be cast to gain the information, false if ray
|
---|
110 | is already holding the information and need not be recast.
|
---|
111 |
|
---|
112 | @returns number of sample contributions
|
---|
113 | */
|
---|
114 | virtual float ComputeSampleContributions(VssRay &ray,
|
---|
115 | const bool addRays,
|
---|
116 | const bool storeViewCells);
|
---|
117 |
|
---|
118 | virtual void AddSampleContributions(VssRay &ray);
|
---|
119 |
|
---|
120 | /** Prints out statistics of the view cells.
|
---|
121 | */
|
---|
122 | virtual void PrintStatistics(ostream &s) const;
|
---|
123 |
|
---|
124 | /** Post processes view cells givemŽa number of rays.
|
---|
125 | */
|
---|
126 | virtual int PostProcess(const ObjectContainer &objects,
|
---|
127 | const VssRayContainer &rays) = 0;
|
---|
128 |
|
---|
129 | /** Show visualization of the view cells.
|
---|
130 | */
|
---|
131 | virtual void Visualize(const ObjectContainer &objects,
|
---|
132 | const VssRayContainer &sampleRays) = 0;
|
---|
133 |
|
---|
134 | /** type of the view cell container.
|
---|
135 | */
|
---|
136 | virtual int GetType() const = 0;
|
---|
137 |
|
---|
138 | /** Load the input viewcells. The input viewcells should be given as a collection
|
---|
139 | of meshes. Each mesh is assume to form a bounded polyhedron defining the interior of
|
---|
140 | the viewcell. The method then builds a BSP tree of these view cells.
|
---|
141 |
|
---|
142 | @param filename file to load
|
---|
143 | @return true on success
|
---|
144 | */
|
---|
145 | virtual bool LoadViewCellsGeometry(const string filename);
|
---|
146 |
|
---|
147 |
|
---|
148 | /** Constructs view cell from base triangle. The ViewCell is extruded along the normal vector.
|
---|
149 | @param the base triangle
|
---|
150 | @param the height of the newly created view cell
|
---|
151 | */
|
---|
152 | ViewCell *ExtrudeViewCell(const Triangle3 &baseTri, const float height) const;
|
---|
153 |
|
---|
154 | /** Merges two view cells.
|
---|
155 | @note the piercing rays of the front and back will be ordered
|
---|
156 | @returns new view cell based on the merging.
|
---|
157 | */
|
---|
158 | ViewCellInterior *MergeViewCells(ViewCell *front, ViewCell *back) const;
|
---|
159 |
|
---|
160 | /** Merges a container of view cells.
|
---|
161 | @returns new view cell based on the merging.
|
---|
162 | */
|
---|
163 | ViewCellInterior *MergeViewCells(ViewCellContainer &children) const;
|
---|
164 |
|
---|
165 | /** Generates view cell of type specified by this manager
|
---|
166 | */
|
---|
167 | virtual ViewCell *GenerateViewCell(Mesh *mesh = NULL) const = 0;
|
---|
168 |
|
---|
169 | /** Adds a new view cell to the list of predefined view cells.
|
---|
170 | */
|
---|
171 | void AddViewCell(ViewCell *viewCell);
|
---|
172 |
|
---|
173 | /** Derive view cells from objects.
|
---|
174 | */
|
---|
175 | void DeriveViewCells(const ObjectContainer &objects,
|
---|
176 | ViewCellContainer &viewCells,
|
---|
177 | const int maxViewCells) const;
|
---|
178 |
|
---|
179 | /** Sets maximal number of samples used for the
|
---|
180 | construction of the view cells.
|
---|
181 | */
|
---|
182 | void SetVisualizationSamples(const int visSamples);
|
---|
183 |
|
---|
184 | /** Sets maximal number of samples used for the construction of the view cells.
|
---|
185 | */
|
---|
186 | void SetConstructionSamples(const int constructionSamples);
|
---|
187 |
|
---|
188 | /** Sets maximal number of samples used for the visualization of the view cells.
|
---|
189 | */
|
---|
190 | void SetInitialSamples(const int initialSamples);
|
---|
191 |
|
---|
192 | /** Sets maximal number of samples used for the post processing of the view cells.
|
---|
193 | */
|
---|
194 | void SetPostProcessSamples(const int postProcessingSamples);
|
---|
195 |
|
---|
196 | /** See set.
|
---|
197 | */
|
---|
198 | int GetVisualizationSamples() const;
|
---|
199 |
|
---|
200 | /** See set.
|
---|
201 | */
|
---|
202 | int GetConstructionSamples() const;
|
---|
203 |
|
---|
204 | /** See set.
|
---|
205 | */
|
---|
206 | int GetPostProcessSamples() const;
|
---|
207 |
|
---|
208 | /** Returns true if view cells wer already constructed.
|
---|
209 | */
|
---|
210 | virtual bool ViewCellsConstructed() const = 0;
|
---|
211 |
|
---|
212 | /** cast line segment to get a list of unique viewcells which are intersected
|
---|
213 | by this line segment
|
---|
214 | */
|
---|
215 |
|
---|
216 | virtual int CastLineSegment(const Vector3 &origin,
|
---|
217 | const Vector3 &termination,
|
---|
218 | ViewCellContainer &viewcells
|
---|
219 | ) = 0;
|
---|
220 |
|
---|
221 | virtual void GetPvsStatistics(PvsStatistics &stat);
|
---|
222 |
|
---|
223 | virtual void GetPrVS(const Vector3 &viewPoint, PrVs &prvs);
|
---|
224 |
|
---|
225 | /** Get a viewcell containing the specified point
|
---|
226 | */
|
---|
227 | virtual ViewCell *GetViewCell(const Vector3 &point) const = 0;
|
---|
228 |
|
---|
229 | virtual void PrintPvsStatistics(ostream &s);
|
---|
230 |
|
---|
231 | /** Returns probability that view point lies in one view cell.
|
---|
232 | */
|
---|
233 | virtual float GetProbability(ViewCell *viewCell) = 0;
|
---|
234 |
|
---|
235 | /** Returns render cost of a single view cell given the render cost of an object.
|
---|
236 | */
|
---|
237 | float GetRendercost(ViewCell *viewCell, float objRendercost) const;
|
---|
238 |
|
---|
239 | /** Returns container of loaded / generated view cells.
|
---|
240 | */
|
---|
241 | ViewCellContainer &GetViewCells();
|
---|
242 |
|
---|
243 | /** Helper function used to split ray sets uniformly
|
---|
244 | into one that is currently used and the other that
|
---|
245 | is saved for later processing.
|
---|
246 | @param sourceRays the input ray set
|
---|
247 | @param maxSize the maximal number of rays that will be used
|
---|
248 | @param usedRays returns the used ray set
|
---|
249 | @param savedRays if not null, returns the saved ray set
|
---|
250 | */
|
---|
251 | void GetRaySets(const VssRayContainer &sourceRays,
|
---|
252 | const int maxSize,
|
---|
253 | VssRayContainer &usedRays,
|
---|
254 | VssRayContainer *savedRays = NULL) const;
|
---|
255 |
|
---|
256 | /** Returns accumulated area of all view cells.
|
---|
257 | */
|
---|
258 | float GetAccVcArea();
|
---|
259 |
|
---|
260 | /** Returns area of one view cell.
|
---|
261 | */
|
---|
262 | virtual float GetArea(ViewCell *viewCell) const;
|
---|
263 |
|
---|
264 | /** Returns volume of view cell.
|
---|
265 | */
|
---|
266 | virtual float GetVolume(ViewCell *viewCell) const;
|
---|
267 |
|
---|
268 | /** Sets the current renderer mainly for view cells statistics.
|
---|
269 | */
|
---|
270 | void SetRenderer(Renderer *renderer);
|
---|
271 |
|
---|
272 | /** Computes a (random) view point in the valid view space.
|
---|
273 | @returns true if valid view point was found
|
---|
274 | */
|
---|
275 | virtual bool GetViewPoint(Vector3 &viewPoint) const;
|
---|
276 |
|
---|
277 | /** Returns true if this view point is in the valid view space.
|
---|
278 | */
|
---|
279 | virtual bool ViewPointValid(const Vector3 &viewPoint) const;
|
---|
280 |
|
---|
281 | /** Sets a view space boundary.
|
---|
282 | */
|
---|
283 | void SetViewSpaceBox(const AxisAlignedBox3 &box);
|
---|
284 |
|
---|
285 | AxisAlignedBox3 GetViewSpaceBox() const;
|
---|
286 |
|
---|
287 | /** Creates mesh for this view cell.
|
---|
288 | */
|
---|
289 | virtual void CreateMesh(ViewCell *vc) = NULL;
|
---|
290 |
|
---|
291 | /** Writes view cells to disc.
|
---|
292 | */
|
---|
293 | virtual bool ExportViewCells(const string filename);
|
---|
294 |
|
---|
295 | /** Casts beam to collect view cells.
|
---|
296 | */
|
---|
297 | virtual int CastBeam(Beam &beam);
|
---|
298 |
|
---|
299 | /** Checks if view cell is considered as valid.
|
---|
300 | */
|
---|
301 | virtual bool CheckValidity(ViewCell *vc,
|
---|
302 | int minPvsSize,
|
---|
303 | int maxPvsSize) const;
|
---|
304 |
|
---|
305 |
|
---|
306 | /** Sets validity of view cell
|
---|
307 | */
|
---|
308 | virtual void SetValidity(ViewCell *vc,
|
---|
309 | int minPvsSize,
|
---|
310 | int maxPvsSize) const;
|
---|
311 |
|
---|
312 | /** sets validy of all viewcells */
|
---|
313 | virtual void SetValidity(
|
---|
314 | int minPvsSize,
|
---|
315 | int maxPvsSize) const;
|
---|
316 |
|
---|
317 |
|
---|
318 | /** set valid viewcells in the range of pvs. sorts the viewcells
|
---|
319 | according to the pvs and then pickups those in the ranges */
|
---|
320 |
|
---|
321 |
|
---|
322 | void SetValidityPercentage(const float minValid, const float maxValid);
|
---|
323 |
|
---|
324 | int CountValidViewcells() const;
|
---|
325 |
|
---|
326 | /** Returns maximal allowed pvs size.
|
---|
327 | */
|
---|
328 | int GetMaxPvsSize() const;
|
---|
329 |
|
---|
330 | /** Returns maximal allowed pvs size.
|
---|
331 | */
|
---|
332 | int GetMinPvsSize() const;
|
---|
333 |
|
---|
334 | /** Returns maximal ratio. i.e., currentPVs / maxPvs,
|
---|
335 | where pvs is still considered valid.
|
---|
336 | */
|
---|
337 | float GetMaxPvsRatio() const;
|
---|
338 |
|
---|
339 | /** Exports view cell geometry.
|
---|
340 | */
|
---|
341 | virtual void ExportViewCellGeometry(Exporter *exporter,
|
---|
342 | ViewCell *vc,
|
---|
343 | const Plane3 *clipPlane = NULL) const = 0;
|
---|
344 |
|
---|
345 | virtual void FinalizeViewCells(const bool createMesh);
|
---|
346 |
|
---|
347 |
|
---|
348 | /** Loads view cells from file. The view cells manager is created with
|
---|
349 | respect to the loaded view cells.
|
---|
350 |
|
---|
351 | @returns the view cells manager if loading was successful, false otherwise
|
---|
352 | */
|
---|
353 | static ViewCellsManager *LoadViewCells(const string filename,
|
---|
354 | ObjectContainer *objects);
|
---|
355 |
|
---|
356 | /** Evaluates statistics values on view cells.
|
---|
357 | */
|
---|
358 | void EvaluateRenderStatistics(float &totalRenderCost,
|
---|
359 | float &expectedRenderCost,
|
---|
360 | float &deviation,
|
---|
361 | float &variance,
|
---|
362 | int &totalPvs,
|
---|
363 | float &avgRenderCost);
|
---|
364 |
|
---|
365 |
|
---|
366 | /** Returns hierarchy of the view cells.
|
---|
367 | */
|
---|
368 | ViewCellsTree *GetViewCellsTree();
|
---|
369 |
|
---|
370 | virtual void CollectMergeCandidates(const VssRayContainer &rays,
|
---|
371 | vector<MergeCandidate> &candidates) = 0;
|
---|
372 |
|
---|
373 | void CollectViewCells(const int n);
|
---|
374 |
|
---|
375 | /** Returns true if this (logical) view cell is equal to a spatial node.
|
---|
376 | */
|
---|
377 | virtual bool EqualToSpatialNode(ViewCell *viewCell) const { return false;}
|
---|
378 |
|
---|
379 | /** Sets current view cells set to active, i.e., the sampling is done in this view cell set.
|
---|
380 | */
|
---|
381 | void SetViewCellsActive();
|
---|
382 |
|
---|
383 | /** Evaluates worth of current view cell hierarchy.
|
---|
384 | */
|
---|
385 | void EvalViewCellPartition(Preprocessor *preprocessor);
|
---|
386 |
|
---|
387 |
|
---|
388 | protected:
|
---|
389 |
|
---|
390 | /** Returns the bounding box of filter width.
|
---|
391 | */
|
---|
392 | AxisAlignedBox3 GetFilterBBox(const Vector3 &viewPoint, const float width) const;
|
---|
393 |
|
---|
394 | /** Intersects box with the tree and returns the number of intersected boxes.
|
---|
395 | @returns number of view cells found
|
---|
396 | */
|
---|
397 | virtual int ComputeBoxIntersections(const AxisAlignedBox3 &box, ViewCellContainer &viewCells) const {return 0;};
|
---|
398 |
|
---|
399 | virtual void TestFilter(const ObjectContainer &objects) {};
|
---|
400 |
|
---|
401 | /**
|
---|
402 | if the view cells tree was already constructed or not.
|
---|
403 | */
|
---|
404 | bool ViewCellsTreeConstructed() const;
|
---|
405 |
|
---|
406 | int CastPassSamples(const int samplesPerPass,
|
---|
407 | const int sampleType,
|
---|
408 | VssRayContainer &vssRays) const;
|
---|
409 |
|
---|
410 | void ParseEnvironment();
|
---|
411 |
|
---|
412 | /** Creates unique view cell ids.
|
---|
413 | */
|
---|
414 | void CreateUniqueViewCellIds();
|
---|
415 |
|
---|
416 | /** Finalizes, i.e., creates mesh, volume, area etc. for the view cell.
|
---|
417 | */
|
---|
418 | virtual void Finalize(ViewCell *viewCell, const bool createMesh);
|
---|
419 |
|
---|
420 | /** Recollects view cells and resets statistics.
|
---|
421 | */
|
---|
422 | void ResetViewCells();
|
---|
423 |
|
---|
424 | /** Collects the view cells in the view cell container.
|
---|
425 | */
|
---|
426 | virtual void CollectViewCells() = 0;
|
---|
427 |
|
---|
428 | /** Evaluates view cells statistics and stores it in
|
---|
429 | mViewCellsStatistics.
|
---|
430 | */
|
---|
431 | void EvaluateViewCellsStats();
|
---|
432 |
|
---|
433 | //-- helper functions for view cell visualization
|
---|
434 |
|
---|
435 | /** Exports the view cell partition.
|
---|
436 | */
|
---|
437 | void ExportViewCellsForViz(Exporter *exporter) const;
|
---|
438 |
|
---|
439 | /** Sets exporter color.
|
---|
440 | */
|
---|
441 | virtual void ExportColor(Exporter *exporter, ViewCell *vc) const = 0;
|
---|
442 |
|
---|
443 |
|
---|
444 | virtual float GetViewSpaceVolume();
|
---|
445 |
|
---|
446 | /** Creates meshes from the view cells.
|
---|
447 | */
|
---|
448 | void CreateViewCellMeshes();
|
---|
449 |
|
---|
450 | /** Takes different measures to prepares the view cells after loading them from disc.
|
---|
451 | */
|
---|
452 | virtual void PrepareLoadedViewCells() {};
|
---|
453 |
|
---|
454 | /** Creates clip plane for visualization.
|
---|
455 | */
|
---|
456 | void CreateClipPlane();
|
---|
457 |
|
---|
458 | Plane3 mClipPlane;
|
---|
459 | bool mUseClipPlaneForViz;
|
---|
460 |
|
---|
461 |
|
---|
462 | /// Renders the view cells.
|
---|
463 | Renderer *mRenderer;
|
---|
464 |
|
---|
465 | /// Loaded view cells
|
---|
466 | ViewCellContainer mViewCells;
|
---|
467 |
|
---|
468 | ViewCellsTree *mViewCellsTree;
|
---|
469 |
|
---|
470 | /// maximum number of samples taken for construction of the view cells
|
---|
471 | int mConstructionSamples;
|
---|
472 | int mSamplesPerPass;
|
---|
473 | int mInitialSamples;
|
---|
474 | int mPostProcessSamples;
|
---|
475 | int mVisualizationSamples;
|
---|
476 |
|
---|
477 | float mTotalAreaValid;
|
---|
478 | float mTotalArea;
|
---|
479 |
|
---|
480 | int mMaxPvsSize;
|
---|
481 | int mMinPvsSize;
|
---|
482 | float mMaxPvsRatio;
|
---|
483 |
|
---|
484 | int mSamplingType;
|
---|
485 | int mNumActiveViewCells;
|
---|
486 | bool mCompressViewCells;
|
---|
487 |
|
---|
488 | ViewCellsStatistics mCurrentViewCellsStats;
|
---|
489 | /// the scene bounding box
|
---|
490 | AxisAlignedBox3 mViewSpaceBox;
|
---|
491 | /// holds the view cell meshes
|
---|
492 | MeshContainer mMeshContainer;
|
---|
493 | /// if view cells should be exported
|
---|
494 | bool mExportViewCells;
|
---|
495 |
|
---|
496 | //bool mMarchTree);
|
---|
497 | bool mOnlyValidViewCells;
|
---|
498 |
|
---|
499 | /// if rays should be used to collect merge candidates
|
---|
500 | bool mUseRaysForMerge;
|
---|
501 | /// merge the view cells?
|
---|
502 | bool mMergeViewCells;
|
---|
503 |
|
---|
504 | /// the width of the box filter
|
---|
505 | float mFilterWidth;
|
---|
506 | int mMaxFilterSize;
|
---|
507 |
|
---|
508 | //-- visualization options
|
---|
509 |
|
---|
510 | /// color code for view cells
|
---|
511 | int mColorCode;
|
---|
512 | bool mExportGeometry;
|
---|
513 | bool mExportRays;
|
---|
514 |
|
---|
515 | bool mViewCellsFinished;
|
---|
516 |
|
---|
517 | bool mEvaluateViewCells;
|
---|
518 |
|
---|
519 | bool mShowVisualization;
|
---|
520 |
|
---|
521 | // HACK in order to detect empty view cells
|
---|
522 | void CollectEmptyViewCells();
|
---|
523 | void TestEmptyViewCells(const ObjectContainer &obj);
|
---|
524 |
|
---|
525 | ViewCellContainer mEmptyViewCells;
|
---|
526 | };
|
---|
527 |
|
---|
528 |
|
---|
529 |
|
---|
530 | /**
|
---|
531 | Manages different higher order operations on the view cells.
|
---|
532 | */
|
---|
533 | class BspViewCellsManager: public ViewCellsManager
|
---|
534 | {
|
---|
535 |
|
---|
536 | public:
|
---|
537 | /** Constructor taking the bsp tree and the number of samples
|
---|
538 | used to construct the bsp tree.
|
---|
539 | */
|
---|
540 | BspViewCellsManager(BspTree *tree);
|
---|
541 |
|
---|
542 | ~BspViewCellsManager();
|
---|
543 |
|
---|
544 | int ConstructSubdivision(const ObjectContainer &objects,
|
---|
545 | const VssRayContainer &rays);
|
---|
546 |
|
---|
547 | int PostProcess(const ObjectContainer &objects,
|
---|
548 | const VssRayContainer &rays);
|
---|
549 |
|
---|
550 | void Visualize(const ObjectContainer &objects,
|
---|
551 | const VssRayContainer &sampleRays);
|
---|
552 |
|
---|
553 | int GetType() const;
|
---|
554 |
|
---|
555 | ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
|
---|
556 |
|
---|
557 | bool ViewCellsConstructed() const;
|
---|
558 |
|
---|
559 | //void PrintStatistics(ostream &s) const;
|
---|
560 |
|
---|
561 | int CastLineSegment(const Vector3 &origin,
|
---|
562 | const Vector3 &termination,
|
---|
563 | ViewCellContainer &viewcells);
|
---|
564 |
|
---|
565 | float GetProbability(ViewCell *viewCell);
|
---|
566 |
|
---|
567 |
|
---|
568 | /** Get a viewcell containing the specified point */
|
---|
569 | ViewCell *GetViewCell(const Vector3 &point) const;
|
---|
570 |
|
---|
571 | void CreateMesh(ViewCell *vc);
|
---|
572 |
|
---|
573 | void ExportViewCellGeometry(Exporter *exporter,
|
---|
574 | ViewCell *vc,
|
---|
575 | const Plane3 *clipPlane = NULL) const;
|
---|
576 |
|
---|
577 | void CollectMergeCandidates(const VssRayContainer &rays,
|
---|
578 | vector<MergeCandidate> &candidates);
|
---|
579 |
|
---|
580 | void Finalize(ViewCell *viewCell, const bool createMesh);
|
---|
581 |
|
---|
582 | bool ExportViewCells(const string filename);
|
---|
583 |
|
---|
584 | ViewCell *ConstructSpatialMergeTree(BspNode *root);
|
---|
585 |
|
---|
586 |
|
---|
587 | protected:
|
---|
588 |
|
---|
589 |
|
---|
590 | /** HACK
|
---|
591 | */
|
---|
592 | void AddCurrentViewCellsToHierarchy();
|
---|
593 |
|
---|
594 | void CollectViewCells();
|
---|
595 |
|
---|
596 | void ExportColor(Exporter *exporter, ViewCell *vc) const;
|
---|
597 |
|
---|
598 |
|
---|
599 |
|
---|
600 | /// the BSP tree.
|
---|
601 | BspTree *mBspTree;
|
---|
602 |
|
---|
603 | vector<BspRay *> mBspRays;
|
---|
604 |
|
---|
605 | private:
|
---|
606 |
|
---|
607 | /** Exports visualization of the BSP splits.
|
---|
608 | */
|
---|
609 | void ExportSplits(const ObjectContainer &objects);
|
---|
610 |
|
---|
611 | /** Exports visualization of the BSP PVS.
|
---|
612 | */
|
---|
613 | void ExportBspPvs(const ObjectContainer &objects);
|
---|
614 |
|
---|
615 | void TestSubdivision();
|
---|
616 | };
|
---|
617 |
|
---|
618 | /**
|
---|
619 | Manages different higher order operations on the KD type view cells.
|
---|
620 | */
|
---|
621 | class KdViewCellsManager: public ViewCellsManager
|
---|
622 | {
|
---|
623 |
|
---|
624 | public:
|
---|
625 |
|
---|
626 | KdViewCellsManager(KdTree *tree);
|
---|
627 |
|
---|
628 | int ConstructSubdivision(const ObjectContainer &objects,
|
---|
629 | const VssRayContainer &rays);
|
---|
630 |
|
---|
631 | int CastLineSegment(const Vector3 &origin,
|
---|
632 | const Vector3 &termination,
|
---|
633 | ViewCellContainer &viewcells);
|
---|
634 |
|
---|
635 | int PostProcess(const ObjectContainer &objects,
|
---|
636 | const VssRayContainer &rays);
|
---|
637 |
|
---|
638 | void Visualize(const ObjectContainer &objects,
|
---|
639 | const VssRayContainer &sampleRays);
|
---|
640 |
|
---|
641 | int GetType() const;
|
---|
642 |
|
---|
643 | bool ViewCellsConstructed() const;
|
---|
644 |
|
---|
645 | ViewCell *GenerateViewCell(Mesh *mesh) const;
|
---|
646 |
|
---|
647 | /** Prints out statistics of this approach.
|
---|
648 | */
|
---|
649 | // virtual void PrintStatistics(ostream &s) const;
|
---|
650 | ViewCell *GetViewCell(const Vector3 &point) const { return NULL; }
|
---|
651 |
|
---|
652 | float GetProbability(ViewCell *viewCell);
|
---|
653 |
|
---|
654 |
|
---|
655 | void CreateMesh(ViewCell *vc);
|
---|
656 |
|
---|
657 | void ExportViewCellGeometry(Exporter *exporter,
|
---|
658 | ViewCell *vc,
|
---|
659 | const Plane3 *clipPlane = NULL) const;
|
---|
660 |
|
---|
661 | void CollectMergeCandidates(const VssRayContainer &rays,
|
---|
662 | vector<MergeCandidate> &candidates);
|
---|
663 |
|
---|
664 | protected:
|
---|
665 |
|
---|
666 | /** Collects view cells from a hierarchy.
|
---|
667 | */
|
---|
668 | void CollectViewCells();
|
---|
669 |
|
---|
670 | KdNode *GetNodeForPvs(KdLeaf *leaf);
|
---|
671 |
|
---|
672 | void ExportColor(Exporter *exporter, ViewCell *vc) const;
|
---|
673 |
|
---|
674 |
|
---|
675 | /// the BSP tree.
|
---|
676 | KdTree *mKdTree;
|
---|
677 |
|
---|
678 | /// depth of the KD tree nodes with represent the view cells
|
---|
679 | int mKdPvsDepth;
|
---|
680 | };
|
---|
681 |
|
---|
682 | /**
|
---|
683 | Manages different higher order operations on the view cells
|
---|
684 | for vsp kd tree view cells.
|
---|
685 | */
|
---|
686 | class VspKdViewCellsManager: public ViewCellsManager
|
---|
687 | {
|
---|
688 |
|
---|
689 | public:
|
---|
690 |
|
---|
691 | VspKdViewCellsManager(VspKdTree *vspKdTree);
|
---|
692 |
|
---|
693 | int ConstructSubdivision(const ObjectContainer &objects,
|
---|
694 | const VssRayContainer &rays);
|
---|
695 |
|
---|
696 |
|
---|
697 | int PostProcess(const ObjectContainer &objects,
|
---|
698 | const VssRayContainer &rays);
|
---|
699 |
|
---|
700 | void Visualize(const ObjectContainer &objects,
|
---|
701 | const VssRayContainer &sampleRays);
|
---|
702 |
|
---|
703 | int GetType() const;
|
---|
704 |
|
---|
705 | bool ViewCellsConstructed() const;
|
---|
706 |
|
---|
707 | //virtual void PrintStatistics(ostream &s) const;
|
---|
708 |
|
---|
709 | ViewCell *GenerateViewCell(Mesh *mesh) const;
|
---|
710 |
|
---|
711 |
|
---|
712 | int CastLineSegment(const Vector3 &origin,
|
---|
713 | const Vector3 &termination,
|
---|
714 | ViewCellContainer &viewcells);
|
---|
715 |
|
---|
716 | ViewCell *GetViewCell(const Vector3 &point) const { return NULL; }
|
---|
717 |
|
---|
718 | float GetProbability(ViewCell *viewCell);
|
---|
719 |
|
---|
720 |
|
---|
721 | void CreateMesh(ViewCell *vc);
|
---|
722 |
|
---|
723 | void ExportViewCellGeometry(Exporter *exporter,
|
---|
724 | ViewCell *vc,
|
---|
725 | const Plane3 *clipPlane = NULL) const;
|
---|
726 |
|
---|
727 | void CollectMergeCandidates(const VssRayContainer &rays, vector<MergeCandidate> &candidates);
|
---|
728 |
|
---|
729 | protected:
|
---|
730 |
|
---|
731 | void ExportLeaves(const ObjectContainer &objects,
|
---|
732 | const VssRayContainer &sampleRays);
|
---|
733 |
|
---|
734 | void CollectViewCells();
|
---|
735 |
|
---|
736 | void ExportColor(Exporter *exporter, ViewCell *vc) const;
|
---|
737 |
|
---|
738 |
|
---|
739 |
|
---|
740 | /// the BSP tree.
|
---|
741 | VspKdTree *mVspKdTree;
|
---|
742 | };
|
---|
743 |
|
---|
744 |
|
---|
745 |
|
---|
746 | /**
|
---|
747 | Manages different higher order operations on the view cells.
|
---|
748 | */
|
---|
749 | class VspBspViewCellsManager: public ViewCellsManager
|
---|
750 | {
|
---|
751 |
|
---|
752 | public:
|
---|
753 |
|
---|
754 | VspBspViewCellsManager(VspBspTree *tree);
|
---|
755 | ~VspBspViewCellsManager();
|
---|
756 |
|
---|
757 | int ConstructSubdivision(const ObjectContainer &objects,
|
---|
758 | const VssRayContainer &rays);
|
---|
759 |
|
---|
760 | int PostProcess(const ObjectContainer &objects,
|
---|
761 | const VssRayContainer &rays);
|
---|
762 |
|
---|
763 | void Visualize(const ObjectContainer &objects,
|
---|
764 | const VssRayContainer &sampleRays);
|
---|
765 |
|
---|
766 | int GetType() const;
|
---|
767 |
|
---|
768 | ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
|
---|
769 |
|
---|
770 | bool ViewCellsConstructed() const;
|
---|
771 |
|
---|
772 |
|
---|
773 | int CastLineSegment(const Vector3 &origin,
|
---|
774 | const Vector3 &termination,
|
---|
775 | ViewCellContainer &viewcells);
|
---|
776 |
|
---|
777 | float GetProbability(ViewCell *viewCell);
|
---|
778 |
|
---|
779 | ViewCell *GetViewCell(const Vector3 &point) const;
|
---|
780 |
|
---|
781 | bool GetViewPoint(Vector3 &viewPoint) const;
|
---|
782 |
|
---|
783 | bool ViewPointValid(const Vector3 &viewPoint) const;
|
---|
784 |
|
---|
785 | void CreateMesh(ViewCell *vc);
|
---|
786 |
|
---|
787 | //bool LoadViewCellsGeometry(const string filename, ObjectContainer *objects);
|
---|
788 | bool ExportViewCells(const string filename);
|
---|
789 |
|
---|
790 | int CastBeam(Beam &beam);
|
---|
791 |
|
---|
792 | void ExportViewCellGeometry(Exporter *exporter,
|
---|
793 | ViewCell *vc,
|
---|
794 | const Plane3 *clipPlane = NULL) const;
|
---|
795 |
|
---|
796 | //float GetVolume(ViewCell *viewCell) const;
|
---|
797 |
|
---|
798 | void Finalize(ViewCell *viewCell, const bool createMesh);
|
---|
799 |
|
---|
800 | void CollectMergeCandidates(const VssRayContainer &rays, vector<MergeCandidate> &candidates);
|
---|
801 |
|
---|
802 | /** Returns true if this view cell is equivavalent to a spatial node.
|
---|
803 | */
|
---|
804 | bool EqualToSpatialNode(ViewCell *viewCell) const;
|
---|
805 |
|
---|
806 |
|
---|
807 | protected:
|
---|
808 |
|
---|
809 | int ComputeBoxIntersections(const AxisAlignedBox3 &box, ViewCellContainer &viewCells) const;
|
---|
810 |
|
---|
811 | /** Returns node of the spatial hierarchy corresponding to the view cell
|
---|
812 | if such a node exists.
|
---|
813 | */
|
---|
814 | BspNode *GetSpatialNode(ViewCell *viewCell) const;
|
---|
815 |
|
---|
816 | /** HACK
|
---|
817 | */
|
---|
818 | void AddCurrentViewCellsToHierarchy();
|
---|
819 |
|
---|
820 | /** Merges the view cells.
|
---|
821 | */
|
---|
822 | void MergeViewCells(const VssRayContainer &rays,
|
---|
823 | const ObjectContainer &objects);
|
---|
824 |
|
---|
825 | void RefineViewCells(const VssRayContainer &rays, const ObjectContainer &objects);
|
---|
826 |
|
---|
827 | void CollectViewCells();
|
---|
828 |
|
---|
829 | /** Returns maximal depth difference of view cell
|
---|
830 | leaves in tree.
|
---|
831 | */
|
---|
832 | int GetMaxTreeDiff(ViewCell *vc) const;
|
---|
833 |
|
---|
834 |
|
---|
835 | void ExportColor(Exporter *exporter, ViewCell *vc) const;
|
---|
836 |
|
---|
837 | void PrepareLoadedViewCells();
|
---|
838 |
|
---|
839 | ViewCell *ConstructSpatialMergeTree(BspNode *root);
|
---|
840 |
|
---|
841 | void TestFilter(const ObjectContainer &objects);
|
---|
842 |
|
---|
843 |
|
---|
844 |
|
---|
845 | /// the view space partition BSP tree.
|
---|
846 | VspBspTree *mVspBspTree;
|
---|
847 |
|
---|
848 |
|
---|
849 | private:
|
---|
850 |
|
---|
851 | /** Exports visualization of the BSP splits.
|
---|
852 | */
|
---|
853 | void ExportSplits(const ObjectContainer &objects,
|
---|
854 | const VssRayContainer &rays);
|
---|
855 |
|
---|
856 | /** Exports visualization of the BSP PVS.
|
---|
857 | */
|
---|
858 | void ExportBspPvs(const ObjectContainer &objects,
|
---|
859 | const VssRayContainer &rays);
|
---|
860 |
|
---|
861 | void TestSubdivision();
|
---|
862 | };
|
---|
863 |
|
---|
864 |
|
---|
865 | class ViewCellsManagerFactory
|
---|
866 | {
|
---|
867 |
|
---|
868 | public:
|
---|
869 |
|
---|
870 | ViewCellsManager *Create(const string mName);
|
---|
871 |
|
---|
872 | };
|
---|
873 |
|
---|
874 | #endif
|
---|