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

Revision 502, 14.6 KB checked in by bittner, 19 years ago (diff)

bsp viewcell location

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;
[482]26class Exporter;
[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,
[487]57                                                  const VssRayContainer &rays) = 0;
[440]58
[441]59        /** Computes sample contributions of the rays to the view cells PVS.
60       
61                @param rays bundle of rays used to find intersections with view cells and
62                adding the contribution
63                @param castRays true if ray should be cast to gain the information, false if rays
64                already hold the view cells intersection information and need not be recast.
65                @param sampleContributions returns the number of sample contributions
66                @param contributingSamples returns the number of contributingSamples
[440]67        */
[475]68        void  ComputeSampleContributions(const VssRayContainer &rays);
[440]69
[441]70
[475]71        /** Computes sample contribution of a simgle ray to the view cells PVS.
72                @param ray finds intersections with view cells and holds the contribution
73                @param castRay true if ray should be cast to gain the information, false if ray
74                is already holding the information and need not be recast.
[466]75         
[475]76                @returns number of sample contributions
77        */
78        virtual void ComputeSampleContributions(VssRay &ray);
[466]79 
[452]80        /** Prints out statistics of the view cells.
81        */
[475]82        virtual void PrintStatistics(ostream &s) const;
[452]83
[440]84        /** Post processes view cells givemŽa number of rays.
85        */
[475]86        virtual int PostProcess(const ObjectContainer &objects,
87                                                        const VssRayContainer &rays) = 0;
[440]88
89        /** Show visualization of the view cells.
90        */
91        virtual void Visualize(const ObjectContainer &objects,
[466]92                                                   const VssRayContainer &sampleRays) = 0;
[440]93
94        /** type of the view cell container.
95        */
96        virtual int GetType() const = 0;
97
[463]98        /** Load the input viewcells. The input viewcells should be given as a collection
99                of meshes. Each mesh is assume to form a bounded polyhedron defining the interior of
100                the viewcell. The method then builds a BSP tree of these view cells.
101               
102                @param filename file to load
103                @return true on success
104    */
[440]105    bool LoadViewCells(const string filename);
106
107        /** Constructs view cell from base triangle. The ViewCell is extruded along the normal vector.
108                @param the base triangle
109                @param the height of the newly created view cell
110        */
111        ViewCell *ExtrudeViewCell(const Triangle3 &baseTri, const float height) const;
112
113        /** Merges two view cells.
114                @note the piercing rays of the front and back will be ordered   
115                @returns new view cell based on the merging.
116        */
[441]117        ViewCell *MergeViewCells(ViewCell &front, ViewCell &back) const;
[440]118       
119        /** Generates view cell of type specified by this manager
120        */
121        virtual ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
122
123        /** Adds a new view cell to the list of predefined view cells.
124        */
125        void AddViewCell(ViewCell *viewCell);
126
127        /** Derive view cells from objects.
128        */
129        void DeriveViewCells(const ObjectContainer &objects,
130                                                 ViewCellContainer &viewCells,
131                                                 const int maxViewCells) const;
132
133        /** Sets maximal number of samples used for the
134                construction of the view cells.
135        */
136        void SetVisualizationSamples(const int visSamples);
137
138        /** Sets maximal number of samples used for the visualization of the view cells.
139        */
140        void SetConstructionSamples(const int constructionSamples);
141
142        /** Sets maximal number of samples used for the post processing of the view cells.
143        */
144        void SetPostProcessSamples(const int postProcessingSamples);
145
146        /** See set.
147        */
148        int GetVisualizationSamples() const;
149
150        /** See set.
151        */
152        int GetConstructionSamples() const;
153
154        /** See set.
155        */
156        int GetPostProcessSamples() const;
157
158        /** Returns true if view cells wer already constructed.
159        */
160        virtual bool ViewCellsConstructed() const = 0;
[441]161
[477]162        /** cast line segment to get a list of unique viewcells which are intersected
163                by this line segment
164        */
[466]165 
[477]166        virtual int CastLineSegment(const Vector3 &origin,
[466]167                                                          const Vector3 &termination,
168                                                          ViewCellContainer &viewcells
169                                                          ) = 0;
170
[477]171        virtual void GetPvsStatistics(PvsStatistics &stat);
[466]172
[492]173  /** Get a viewcell containing the specified point */
174  virtual ViewCell *GetViewCell(const Vector3 &point) = 0;
175 
176  virtual void
177  PrintPvsStatistics(ostream &s);
[467]178
[477]179        /** Returns probability that view point lies in one view cell.
180        */
181        virtual float GetProbability(ViewCell *viewCell) = 0;
[468]182
[477]183        /** Returns render cost of a single view cell given the render cost of an object.
184        */
185        virtual float GetRendercost(ViewCell *viewCell, float objRendercost) const = 0;
[468]186
[477]187        /** Returns vector of loaded / generated view cells.
188        */
189        ViewCellContainer &GetViewCells();
[468]190
[485]191        /** Helper function used to split ray sets uniformly
192                into one that is currently used and the other that
193                is saved for later processing.
194                @param sourceRays the input ray set
195                @param maxSize the maximal number of rays that will be used
196                @param usedRays returns the used ray set
197                @param savedRays if not null, returns the saved ray set
[477]198        */
199        void GetRaySets(const VssRayContainer &sourceRays,
[485]200                                        const int maxSize,
201                                        VssRayContainer &usedRays,
202                                        VssRayContainer *savedRays = NULL) const;
203       
[480]204        /** Returns accumulated area of all view cells.
205        */
206        float GetAccVcArea();
[470]207
[480]208        /** Returns area of one view cell.
209        */
210        virtual float GetArea(ViewCell *viewCell) const;
[470]211
[480]212        /** Returns volume of view cells.
213        */
214        virtual float GetVolume(ViewCell *viewCell) const;
[470]215
[480]216        virtual AxisAlignedBox3 GetSceneBbox() const = 0;
[477]217
[480]218        /** Sets the current renderer mainly for view cells statistics.
219        */
220        void SetRenderer(Renderer *renderer);
221
[487]222        /** Computes a (random) view point in the valid view space.
223                @returns true if valid view point was found
224        */
225        virtual bool GetViewPoint(Vector3 &viewPoint) const;
226
[490]227        /** Returns true if this view point is in the valid view space.
228        */
229        virtual bool ViewPointValid(const Vector3 &viewPoint) const;
230
[487]231        /** Sets a view space boundary.
232        */
233        void SetViewSpaceBox(const AxisAlignedBox3 &box);
234
235
[469]236protected:
[480]237
[482]238        void ParseEnvironment();
239
[480]240        /** Recollects view cells and resets statistics.
241        */
242        void ResetViewCells();
[482]243       
[480]244        /** Collects the view cells in the view cell container.
245        */
246        virtual void CollectViewCells() = 0;
[482]247       
[479]248        /** Evaluates view cells statistics and stores it in
249                mViewCellsStatistics.
250        */
251        void EvaluateViewCellsStats();
[482]252
253
254        //-- helper functions for view cell visualization
255
256        /** Exports the view cell partition.
257        */
258        void ExportViewCells(Exporter *exporter) const;
259
260        /** Sets exporter color.
261        */
262        virtual void ExportColor(Exporter *exporter, ViewCell *vc) const = 0;
263
264        /** Exports view cell geometry.
265        */
[485]266        virtual void ExportVcGeometry(Exporter *exporter, ViewCell *vc) const = 0;
[482]267
[489]268        /// the view cell corresponding to space ouside the valid view space
269        //ViewCell *mOutOfBoundsCell;
[440]270
[480]271        /// Renders the view cells.
272        Renderer *mRenderer;
[440]273
274        /// Loaded view cells
[469]275        ViewCellContainer mViewCells;
[440]276
277        /// maximum number of samples taken for construction of the view cells
278        int mConstructionSamples;
279        int mPostProcessSamples;
280        int mVisualizationSamples;
[441]281
[463]282        //-- thresholds used for view cells merge
283        int mMinPvsDif;
284        int mMinPvs;
[441]285        int mMaxPvs;
[470]286
287        float mTotalAreaValid;
288        float mTotalArea;
[475]289
290        ViewCellsStatistics mViewCellsStats;
[487]291        /// the scene bounding box
292        AxisAlignedBox3 mSceneBox;
293
294        //-- visualization options
295       
296        /// color code for view cells
297        int mColorCode;
298        bool mExportGeometry;
299        bool mExportRays;
[440]300};
301
[441]302
303
[440]304/**
305        Manages different higher order operations on the view cells.
306*/
307class BspViewCellsManager: public ViewCellsManager
308{
309
310public:
[485]311        /** Constructor taking the bsp tree and the number of samples
312                used to construct the bsp tree.
313        */
[440]314        BspViewCellsManager(BspTree *tree, int constructionSamples);
315
[477]316        ~BspViewCellsManager();
317
[440]318        int Construct(const ObjectContainer &objects,
[487]319                                  const VssRayContainer &rays);
[440]320
321
322        int PostProcess(const ObjectContainer &objects,
[466]323                                        const VssRayContainer &rays);
[440]324
325        void Visualize(const ObjectContainer &objects,
[466]326                                   const VssRayContainer &sampleRays);
[440]327
328        int GetType() const;
329       
330        ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
331
332        bool ViewCellsConstructed() const;
333
[475]334        //void PrintStatistics(ostream &s) const;
[452]335
[468]336        int CastLineSegment(const Vector3 &origin,
337                                                const Vector3 &termination,
338                                                ViewCellContainer &viewcells);
339       
[471]340        float GetProbability(ViewCell *viewCell);
[469]341        float GetRendercost(ViewCell *viewCell, float objRendercost) const;
[466]342
[477]343        AxisAlignedBox3 GetSceneBbox() const;
344
[492]345  /** Get a viewcell containing the specified point */
[502]346  ViewCell *GetViewCell(const Vector3 &point);
[492]347
[440]348protected:
349
[480]350        void CollectViewCells();
351
[441]352        /** Merges view cells front and back leaf view cell.
353        */
354        bool MergeBspLeafViewCells(BspLeaf *front, BspLeaf *back) const;
[440]355
[441]356        /** Returns true if front and back leaf should be merged.
357        */
358        bool ShouldMerge(BspLeaf *front, BspLeaf *back) const;
359
[477]360        void ConstructBspRays(const VssRayContainer &rays,
361                                                  const int numSamples);
[482]362
363        void ExportColor(Exporter *exporter, ViewCell *vc) const;
[485]364        void ExportVcGeometry(Exporter *exporter, ViewCell *vc) const;
[482]365
[440]366        /// the BSP tree.
367        BspTree *mBspTree;
[475]368       
369        vector<BspRay *> mBspRays;
[440]370
371private:
372
373        /** Exports visualization of the BSP splits.
374        */
[477]375        void ExportSplits(const ObjectContainer &objects);
[440]376
377        /** Exports visualization of the BSP PVS.
378        */
[477]379        void ExportBspPvs(const ObjectContainer &objects);
[440]380
381};
382
383/**
384        Manages different higher order operations on the KD type view cells.
385*/
386class KdViewCellsManager: public ViewCellsManager
387{
388
389public:
390
391        KdViewCellsManager(KdTree *tree);
392
393        int Construct(const ObjectContainer &objects,
[487]394                                  const VssRayContainer &rays);
[440]395
[478]396        int CastLineSegment(const Vector3 &origin,
397                                                const Vector3 &termination,
398                                                ViewCellContainer &viewcells);
[440]399
400        int PostProcess(const ObjectContainer &objects,
[466]401                                        const VssRayContainer &rays);
[440]402
403        void Visualize(const ObjectContainer &objects,
[466]404                                   const VssRayContainer &sampleRays);
[440]405
406        int GetType() const;
407
408        bool ViewCellsConstructed() const;
409
410
[452]411        /** Prints out statistics of this approach.
412        */
[492]413  //  virtual void PrintStatistics(ostream &s) const;
414  ViewCell *GetViewCell(const Vector3 &point) { return NULL; }
[452]415
[492]416  float GetProbability(ViewCell *viewCell);
417  float GetRendercost(ViewCell *viewCell, float objRendercost) const;
418 
419  AxisAlignedBox3 GetSceneBbox() const;
[468]420
[440]421protected:
422
[480]423        void CollectViewCells();
424        KdNode *GetNodeForPvs(KdLeaf *leaf);
[440]425
[482]426        void ExportColor(Exporter *exporter, ViewCell *vc) const;
[485]427        void ExportVcGeometry(Exporter *exporter, ViewCell *vc) const;
[440]428
[480]429        /// the BSP tree.
430        KdTree *mKdTree;
[440]431
[480]432        /// depth of the KD tree nodes with represent the view cells
433        int mKdPvsDepth;
[440]434};
435
436/**
437        Manages different higher order operations on the view cells
438        for vsp kd tree view cells.
439*/
440class VspKdViewCellsManager: public ViewCellsManager
441{
442
443public:
444
445        VspKdViewCellsManager(VspKdTree *vspKdTree, int constructionSamples);
446
447        int Construct(const ObjectContainer &objects,
[487]448                                  const VssRayContainer &rays);
[440]449
450
451        int PostProcess(const ObjectContainer &objects,
[466]452                                        const VssRayContainer &rays);
[440]453
454        void Visualize(const ObjectContainer &objects,
[466]455                                   const VssRayContainer &sampleRays);
[440]456
457        int GetType() const;
458       
459        bool ViewCellsConstructed() const;
460
[475]461        //virtual void PrintStatistics(ostream &s) const;
[440]462
[462]463        ViewCell *GenerateViewCell(Mesh *mesh) const;
464
[466]465
466    int CastLineSegment(const Vector3 &origin,
467                                                const Vector3 &termination,
[468]468                                                ViewCellContainer &viewcells);
[466]469
[492]470  ViewCell *GetViewCell(const Vector3 &point) { return NULL; }
471
[471]472        float GetProbability(ViewCell *viewCell);
[469]473        float GetRendercost(ViewCell *viewCell, float objRendercost) const;
[468]474
[477]475        AxisAlignedBox3 GetSceneBbox() const;
[440]476protected:
477
[482]478        void ExportLeaves(const ObjectContainer &objects,
479                                          const VssRayContainer &sampleRays);
480
[480]481        void CollectViewCells();
482
[482]483        void ExportColor(Exporter *exporter, ViewCell *vc) const;
[485]484        void ExportVcGeometry(Exporter *exporter, ViewCell *vc) const;
[482]485
486
[440]487        /// the BSP tree.
488        VspKdTree *mVspKdTree;
489};
490
491
[442]492
493/**
494        Manages different higher order operations on the view cells.
495*/
496class VspBspViewCellsManager: public ViewCellsManager
497{
498
499public:
500
501        VspBspViewCellsManager(VspBspTree *tree, int constructionSamples);
[475]502        ~VspBspViewCellsManager();
[442]503
504        int Construct(const ObjectContainer &objects,
[487]505                                  const VssRayContainer &rays);
[442]506
507        int PostProcess(const ObjectContainer &objects,
[466]508                                        const VssRayContainer &rays);
[442]509
510        void Visualize(const ObjectContainer &objects,
[466]511                                   const VssRayContainer &sampleRays);
[442]512
513        int GetType() const;
514       
515        ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
516
517        bool ViewCellsConstructed() const;
518
[468]519       
520        int CastLineSegment(const Vector3 &origin,
521                                                const Vector3 &termination,
522                                                ViewCellContainer &viewcells);
[452]523
[471]524        float GetProbability(ViewCell *viewCell);
[469]525        float GetRendercost(ViewCell *viewCell, float objRendercost) const;
[479]526       
[477]527        AxisAlignedBox3 GetSceneBbox() const;
528
[492]529  ViewCell *GetViewCell(const Vector3 &point);
530
[487]531        bool GetViewPoint(Vector3 &viewPoint) const;
532
[490]533        bool ViewPointValid(const Vector3 &viewPoint) const;
[442]534protected:
[485]535        /** DEPRECATED
[475]536        */
[485]537        int MergeViewCells(const VssRayContainer &rays) const;
[475]538
[442]539        /** Returns true if front and back leaf should be merged.
540        */
[448]541        bool ShouldMerge(BspLeaf *front, BspLeaf *back) const;
[442]542
[480]543        void CollectViewCells();
544
[482]545        /** Returns maximal depth difference of view cell
546                leaves in tree.
547        */
548        int GetMaxTreeDiff(ViewCell *vc) const;
[485]549       
[482]550
[485]551        void ExportColor(Exporter *exporter, ViewCell *vc) const;
552        void ExportVcGeometry(Exporter *exporter, ViewCell *vc) const;
553
554
[442]555        /// the view space partition BSP tree.
556        VspBspTree *mVspBspTree;
557
558private:
559
560        /** Exports visualization of the BSP splits.
561        */
[485]562        void ExportSplits(const ObjectContainer &objects,
563                                          const VssRayContainer &rays);
[442]564
565        /** Exports visualization of the BSP PVS.
566        */
[485]567        void ExportBspPvs(const ObjectContainer &objects,
568                                          const VssRayContainer &rays);
[442]569
570};
571
[440]572#endif
Note: See TracBrowser for help on using the repository browser.