source: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h @ 844

Revision 844, 23.9 KB checked in by mattausch, 18 years ago (diff)

adding functionality for bounding box hacks

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