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

Revision 703, 22.7 KB checked in by mattausch, 18 years ago (diff)

started implementation of visibility filter

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