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

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