source: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h @ 480

Revision 480, 12.4 KB checked in by mattausch, 19 years ago (diff)

axis aligned split for vsp bsp view cells

RevLine 
[440]1#ifndef _ViewCellsManager_H__
2#define _ViewCellsManager_H__
3
4#include "Ray.h"
5#include "VssRay.h"
6#include "Containers.h"
[475]7#include "ViewCell.h"
[440]8
9class ViewCell;
10class Intersectable;
11class RenderSimulator;
[480]12class Renderer;
[440]13class Mesh;
14struct Triangle3;
15class SimulationStatistics;
16class BspTree;
17class KdTree;
18class VspKdTree;
19class VspBspTree;
20class KdNode;
21class KdLeaf;
22class VspKdTree;
23class AxisAlignedBox3;
[448]24class BspLeaf;
[475]25class ViewCellsStatistics;
[442]26
[475]27struct BspRay;
28
[440]29/**
30        Manages different higher order operations on the view cells.
31*/
32class ViewCellsManager
33{
34
35public:
[467]36  struct PvsStatistics {
37        int minPvs;
38        int maxPvs;
39        float avgPvs;
40        int viewcells;
41  };
[466]42 
43  /// view cell container types
44  enum {BSP, KD, VSP_KD, VSP_BSP};
45 
[440]46        /** Constructor taking the maximal number of samples used for construction
47        */
48        ViewCellsManager(const int constructionSamples);
49
50        ViewCellsManager();
51
[462]52        virtual ~ViewCellsManager();
[440]53
54        /** Constructs view cell container with a given number of samples.
55        */
56        virtual int Construct(const ObjectContainer &objects,
57                                                  const VssRayContainer &rays,
58                                                  AxisAlignedBox3 *sceneBbox = NULL) = 0;
59
[441]60        /** Computes sample contributions of the rays to the view cells PVS.
61       
62                @param rays bundle of rays used to find intersections with view cells and
63                adding the contribution
64                @param castRays true if ray should be cast to gain the information, false if rays
65                already hold the view cells intersection information and need not be recast.
66                @param sampleContributions returns the number of sample contributions
67                @param contributingSamples returns the number of contributingSamples
[440]68        */
[475]69        void  ComputeSampleContributions(const VssRayContainer &rays);
[440]70
[441]71
[475]72        /** Computes sample contribution of a simgle ray to the view cells PVS.
73                @param ray finds intersections with view cells and holds the contribution
74                @param castRay true if ray should be cast to gain the information, false if ray
75                is already holding the information and need not be recast.
[466]76         
[475]77                @returns number of sample contributions
78        */
79        virtual void ComputeSampleContributions(VssRay &ray);
[466]80 
[452]81        /** Prints out statistics of the view cells.
82        */
[475]83        virtual void PrintStatistics(ostream &s) const;
[452]84
[440]85        /** Post processes view cells givemŽa number of rays.
86        */
[475]87        virtual int PostProcess(const ObjectContainer &objects,
88                                                        const VssRayContainer &rays) = 0;
[440]89
90        /** Show visualization of the view cells.
91        */
92        virtual void Visualize(const ObjectContainer &objects,
[466]93                                                   const VssRayContainer &sampleRays) = 0;
[440]94
95        /** type of the view cell container.
96        */
97        virtual int GetType() const = 0;
98
[463]99        /** Load the input viewcells. The input viewcells should be given as a collection
100                of meshes. Each mesh is assume to form a bounded polyhedron defining the interior of
101                the viewcell. The method then builds a BSP tree of these view cells.
102               
103                @param filename file to load
104                @return true on success
105    */
[440]106    bool LoadViewCells(const string filename);
107
108        /** Constructs view cell from base triangle. The ViewCell is extruded along the normal vector.
109                @param the base triangle
110                @param the height of the newly created view cell
111        */
112        ViewCell *ExtrudeViewCell(const Triangle3 &baseTri, const float height) const;
113
114        /** Merges two view cells.
115                @note the piercing rays of the front and back will be ordered   
116                @returns new view cell based on the merging.
117        */
[441]118        ViewCell *MergeViewCells(ViewCell &front, ViewCell &back) const;
[440]119       
120        /** Generates view cell of type specified by this manager
121        */
122        virtual ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
123
124        /** Adds a new view cell to the list of predefined view cells.
125        */
126        void AddViewCell(ViewCell *viewCell);
127
128        /** Derive view cells from objects.
129        */
130        void DeriveViewCells(const ObjectContainer &objects,
131                                                 ViewCellContainer &viewCells,
132                                                 const int maxViewCells) const;
133
134        /** Sets maximal number of samples used for the
135                construction of the view cells.
136        */
137        void SetVisualizationSamples(const int visSamples);
138
139        /** Sets maximal number of samples used for the visualization of the view cells.
140        */
141        void SetConstructionSamples(const int constructionSamples);
142
143        /** Sets maximal number of samples used for the post processing of the view cells.
144        */
145        void SetPostProcessSamples(const int postProcessingSamples);
146
147        /** See set.
148        */
149        int GetVisualizationSamples() const;
150
151        /** See set.
152        */
153        int GetConstructionSamples() const;
154
155        /** See set.
156        */
157        int GetPostProcessSamples() const;
158
159        /** Returns true if view cells wer already constructed.
160        */
161        virtual bool ViewCellsConstructed() const = 0;
[441]162
[477]163        /** cast line segment to get a list of unique viewcells which are intersected
164                by this line segment
165        */
[466]166 
[477]167        virtual int CastLineSegment(const Vector3 &origin,
[466]168                                                          const Vector3 &termination,
169                                                          ViewCellContainer &viewcells
170                                                          ) = 0;
171
[477]172        virtual void GetPvsStatistics(PvsStatistics &stat);
[466]173
[477]174        virtual void PrintPvsStatistics(ostream &s);
[467]175
[477]176        /** Returns probability that view point lies in one view cell.
177        */
178        virtual float GetProbability(ViewCell *viewCell) = 0;
[468]179
[477]180        /** Returns render cost of a single view cell given the render cost of an object.
181        */
182        virtual float GetRendercost(ViewCell *viewCell, float objRendercost) const = 0;
[468]183
[477]184        /** Returns vector of loaded / generated view cells.
185        */
186        ViewCellContainer &GetViewCells();
[468]187
[477]188        /** Helper function used to split ray set into one used for view cell
189                construction and one cast after construction.
190        */
191        void GetRaySets(const VssRayContainer &sourceRays,
192                                        VssRayContainer &constructionRays,
193                                        VssRayContainer &savedRays) const;
[440]194
[480]195        /** Returns accumulated area of all view cells.
196        */
197        float GetAccVcArea();
[470]198
[480]199        /** Returns area of one view cell.
200        */
201        virtual float GetArea(ViewCell *viewCell) const;
[470]202
[480]203        /** Returns volume of view cells.
204        */
205        virtual float GetVolume(ViewCell *viewCell) const;
[470]206
[480]207        virtual AxisAlignedBox3 GetSceneBbox() const = 0;
[477]208
[480]209        /** Sets the current renderer mainly for view cells statistics.
210        */
211        void SetRenderer(Renderer *renderer);
212
213       
[469]214protected:
[480]215
216        /** Recollects view cells and resets statistics.
217        */
218        void ResetViewCells();
219        /** Collects the view cells in the view cell container.
220        */
221        virtual void CollectViewCells() = 0;
222
[479]223        /** Evaluates view cells statistics and stores it in
224                mViewCellsStatistics.
225        */
226        void EvaluateViewCellsStats();
[469]227               
[440]228        /// the view cell corresponding to unbounded space
229        ViewCell *mUnbounded;
230
[480]231        /// Renders the view cells.
232        Renderer *mRenderer;
[440]233
234        /// Loaded view cells
[469]235        ViewCellContainer mViewCells;
[440]236
237        /// maximum number of samples taken for construction of the view cells
238        int mConstructionSamples;
239        int mPostProcessSamples;
240        int mVisualizationSamples;
[441]241
[463]242        //-- thresholds used for view cells merge
243        int mMinPvsDif;
244        int mMinPvs;
[441]245        int mMaxPvs;
[470]246
247        float mTotalAreaValid;
248        float mTotalArea;
[475]249
250        ViewCellsStatistics mViewCellsStats;
[440]251};
252
[441]253
254
[440]255/**
256        Manages different higher order operations on the view cells.
257*/
258class BspViewCellsManager: public ViewCellsManager
259{
260
261public:
262
263        BspViewCellsManager(BspTree *tree, int constructionSamples);
264
[477]265        ~BspViewCellsManager();
266
[440]267        int Construct(const ObjectContainer &objects,
268                                  const VssRayContainer &rays,
269                                  AxisAlignedBox3 *sceneBbox);
270
271
272        int PostProcess(const ObjectContainer &objects,
[466]273                                        const VssRayContainer &rays);
[440]274
275        void Visualize(const ObjectContainer &objects,
[466]276                                   const VssRayContainer &sampleRays);
[440]277
278        int GetType() const;
279       
280        ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
281
282        bool ViewCellsConstructed() const;
283
[475]284        //void PrintStatistics(ostream &s) const;
[452]285
[468]286        int CastLineSegment(const Vector3 &origin,
287                                                const Vector3 &termination,
288                                                ViewCellContainer &viewcells);
289       
[471]290        float GetProbability(ViewCell *viewCell);
[469]291        float GetRendercost(ViewCell *viewCell, float objRendercost) const;
[466]292
[477]293        AxisAlignedBox3 GetSceneBbox() const;
294
[440]295protected:
296
[480]297        void CollectViewCells();
298
[441]299        /** Merges view cells front and back leaf view cell.
300        */
301        bool MergeBspLeafViewCells(BspLeaf *front, BspLeaf *back) const;
[440]302
[441]303        /** Returns true if front and back leaf should be merged.
304        */
305        bool ShouldMerge(BspLeaf *front, BspLeaf *back) const;
306
[477]307        void ConstructBspRays(const VssRayContainer &rays,
308                                                  const int numSamples);
[440]309        /// the BSP tree.
310        BspTree *mBspTree;
[475]311       
312        vector<BspRay *> mBspRays;
[440]313
314private:
315
316        /** Exports visualization of the BSP splits.
317        */
[477]318        void ExportSplits(const ObjectContainer &objects);
[440]319
320        /** Exports visualization of the BSP PVS.
321        */
[477]322        void ExportBspPvs(const ObjectContainer &objects);
[440]323
324};
325
326/**
327        Manages different higher order operations on the KD type view cells.
328*/
329class KdViewCellsManager: public ViewCellsManager
330{
331
332public:
333
334        KdViewCellsManager(KdTree *tree);
335
336        int Construct(const ObjectContainer &objects,
337                                  const VssRayContainer &rays,
338                                  AxisAlignedBox3 *sceneBbox);
339
[478]340        int CastLineSegment(const Vector3 &origin,
341                                                const Vector3 &termination,
342                                                ViewCellContainer &viewcells);
[440]343
344        int PostProcess(const ObjectContainer &objects,
[466]345                                        const VssRayContainer &rays);
[440]346
347        void Visualize(const ObjectContainer &objects,
[466]348                                   const VssRayContainer &sampleRays);
[440]349
350        int GetType() const;
351
352        bool ViewCellsConstructed() const;
353
354
[452]355        /** Prints out statistics of this approach.
356        */
[475]357        //void PrintStatistics(ostream &s) const;
[452]358
[471]359        float GetProbability(ViewCell *viewCell);
[469]360        float GetRendercost(ViewCell *viewCell, float objRendercost) const;
[477]361       
362        AxisAlignedBox3 GetSceneBbox() const;
[468]363
[440]364protected:
365
[480]366        void CollectViewCells();
367        KdNode *GetNodeForPvs(KdLeaf *leaf);
[440]368
369
[480]370        /// the BSP tree.
371        KdTree *mKdTree;
[440]372
[480]373        /// depth of the KD tree nodes with represent the view cells
374        int mKdPvsDepth;
[440]375};
376
377/**
378        Manages different higher order operations on the view cells
379        for vsp kd tree view cells.
380*/
381class VspKdViewCellsManager: public ViewCellsManager
382{
383
384public:
385
386        VspKdViewCellsManager(VspKdTree *vspKdTree, int constructionSamples);
387
388        int Construct(const ObjectContainer &objects,
389                                  const VssRayContainer &rays,
390                                  AxisAlignedBox3 *sceneBbox);
391
392
393        int PostProcess(const ObjectContainer &objects,
[466]394                                        const VssRayContainer &rays);
[440]395
396        void Visualize(const ObjectContainer &objects,
[466]397                                   const VssRayContainer &sampleRays);
[440]398
399        int GetType() const;
400       
401        bool ViewCellsConstructed() const;
402
[475]403        //virtual void PrintStatistics(ostream &s) const;
[440]404
[462]405        ViewCell *GenerateViewCell(Mesh *mesh) const;
406
[466]407
408    int CastLineSegment(const Vector3 &origin,
409                                                const Vector3 &termination,
[468]410                                                ViewCellContainer &viewcells);
[466]411
[471]412        float GetProbability(ViewCell *viewCell);
[469]413        float GetRendercost(ViewCell *viewCell, float objRendercost) const;
[468]414
[477]415        AxisAlignedBox3 GetSceneBbox() const;
416
[440]417protected:
418
[480]419        void CollectViewCells();
420
[440]421        /// the BSP tree.
422        VspKdTree *mVspKdTree;
423};
424
425
[442]426
427/**
428        Manages different higher order operations on the view cells.
429*/
430class VspBspViewCellsManager: public ViewCellsManager
431{
432
433public:
434
435        VspBspViewCellsManager(VspBspTree *tree, int constructionSamples);
[475]436        ~VspBspViewCellsManager();
[442]437
438        int Construct(const ObjectContainer &objects,
439                                  const VssRayContainer &rays,
440                                  AxisAlignedBox3 *sceneBbox);
441
442
443        int PostProcess(const ObjectContainer &objects,
[466]444                                        const VssRayContainer &rays);
[442]445
446        void Visualize(const ObjectContainer &objects,
[466]447                                   const VssRayContainer &sampleRays);
[442]448
449        int GetType() const;
450       
451        ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
452
453        bool ViewCellsConstructed() const;
454
[475]455        //void PrintStatistics(ostream &s) const;
[468]456       
457        int CastLineSegment(const Vector3 &origin,
458                                                const Vector3 &termination,
459                                                ViewCellContainer &viewcells);
[452]460
[471]461        float GetProbability(ViewCell *viewCell);
[469]462        float GetRendercost(ViewCell *viewCell, float objRendercost) const;
[479]463       
[477]464        AxisAlignedBox3 GetSceneBbox() const;
465
[442]466protected:
467
[475]468        /** Constructs bsp rays for post processing and visualization.
469        */
470        void ConstructBspRays(const VssRayContainer &rays, const int numSamples);
471
[442]472        /** Merges view cells front and back leaf view cell.
473        */
[448]474        bool MergeVspBspLeafViewCells(BspLeaf *front, BspLeaf *back) const;
[442]475
476        /** Returns true if front and back leaf should be merged.
477        */
[448]478        bool ShouldMerge(BspLeaf *front, BspLeaf *back) const;
[442]479
[480]480        void CollectViewCells();
481
[442]482        /// the view space partition BSP tree.
483        VspBspTree *mVspBspTree;
484
[475]485        vector<BspRay *> mBspRays;
[442]486
487private:
488
489
490        /** Exports visualization of the BSP splits.
491        */
[475]492        void ExportSplits(const ObjectContainer &objects);
[442]493
494        /** Exports visualization of the BSP PVS.
495        */
[475]496        void ExportBspPvs(const ObjectContainer &objects);
[442]497
498};
499
[440]500#endif
Note: See TracBrowser for help on using the repository browser.