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

Revision 706, 22.9 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
[477]269        /** Returns probability that view point lies in one view cell.
270        */
271        virtual float GetProbability(ViewCell *viewCell) = 0;
[468]272
[477]273        /** Returns render cost of a single view cell given the render cost of an object.
274        */
[609]275        float GetRendercost(ViewCell *viewCell, float objRendercost) const;
[468]276
[580]277        /** Returns container of loaded / generated view cells.
[477]278        */
279        ViewCellContainer &GetViewCells();
[468]280
[485]281        /** Helper function used to split ray sets uniformly
282                into one that is currently used and the other that
283                is saved for later processing.
284                @param sourceRays the input ray set
285                @param maxSize the maximal number of rays that will be used
286                @param usedRays returns the used ray set
287                @param savedRays if not null, returns the saved ray set
[477]288        */
289        void GetRaySets(const VssRayContainer &sourceRays,
[485]290                                        const int maxSize,
291                                        VssRayContainer &usedRays,
292                                        VssRayContainer *savedRays = NULL) const;
293       
[480]294        /** Returns accumulated area of all view cells.
295        */
296        float GetAccVcArea();
[470]297
[480]298        /** Returns area of one view cell.
299        */
300        virtual float GetArea(ViewCell *viewCell) const;
[470]301
[551]302        /** Returns volume of view cell.
[480]303        */
304        virtual float GetVolume(ViewCell *viewCell) const;
[470]305
[480]306        /** Sets the current renderer mainly for view cells statistics.
307        */
308        void SetRenderer(Renderer *renderer);
309
[487]310        /** Computes a (random) view point in the valid view space.
311                @returns true if valid view point was found
312        */
313        virtual bool GetViewPoint(Vector3 &viewPoint) const;
314
[490]315        /** Returns true if this view point is in the valid view space.
316        */
317        virtual bool ViewPointValid(const Vector3 &viewPoint) const;
318
[487]319        /** Sets a view space boundary.
320        */
321        void SetViewSpaceBox(const AxisAlignedBox3 &box);
322
[519]323        AxisAlignedBox3 GetViewSpaceBox() const;
324
[503]325        /** Creates mesh for this view cell.
326        */
327        virtual void CreateMesh(ViewCell *vc) = NULL;
[487]328
[508]329        /** Writes view cells to disc.
330        */
331        virtual bool ExportViewCells(const string filename);
332
[532]333        /** Casts beam to collect view cells.
334        */
335        virtual int CastBeam(Beam &beam);
336
[547]337        /** Checks if view cell is considered as valid.
338        */
[561]339        virtual bool CheckValidity(ViewCell *vc,
[562]340                                                           int minPvsSize,
341                                                           int maxPvsSize) const;
[547]342
[562]343       
344        /** Sets validity of view cell
345        */
346        virtual void SetValidity(ViewCell *vc,
347                                                         int minPvsSize,
348                                                         int maxPvsSize) const;
349
[569]350  /** sets validy of all viewcells */
351        virtual void SetValidity(
352                                                         int minPvsSize,
353                                                         int maxPvsSize) const;
354
[609]355
356        /** set valid viewcells in the range of pvs. sorts the viewcells
[569]357          according to the pvs and then pickups those in the ranges */
358
[609]359   
360        void SetValidityPercentage(const float minValid,        const float maxValid);
[569]361
[609]362    int CountValidViewcells() const;
363
[547]364        /** Returns maximal allowed pvs size.
365        */
366        int GetMaxPvsSize() const;
367
[562]368        /** Returns maximal allowed pvs size.
369        */
370        int GetMinPvsSize() const;
371
[561]372        /** Returns maximal ratio. i.e., currentPVs / maxPvs,
373                where pvs is still considered valid.
374        */
375        float GetMaxPvsRatio() const;
376
[547]377        /** Exports view cell geometry.
378        */
[591]379        virtual void ExportViewCellGeometry(Exporter *exporter,
380                                                                                ViewCell *vc,
[660]381                                                                                const Plane3 *clipPlane = NULL) const = 0;
[547]382
[551]383        virtual void FinalizeViewCells(const bool createMesh);
384
[577]385
[591]386        /** Loads view cells from file. The view cells manager is created with
387                respect to the loaded view cells.
[577]388
389                @returns the view cells manager if loading was successful, false otherwise
390        */
[591]391        static ViewCellsManager *LoadViewCells(const string filename,
392                                                                                   ObjectContainer *objects);
[577]393
[579]394        /** Evaluates statistics values on view cells.
395        */
[580]396        void EvaluateRenderStatistics(float &totalRenderCost,
397                                                                  float &expectedRenderCost,
398                                                                  float &deviation,
399                                                                  float &variance,
400                                                                  int &totalPvs,
401                                                                  float &avgRenderCost);
[579]402
[580]403
404        /** Returns hierarchy of the view cells.
405        */
406        ViewCellsTree *GetViewCellsTree();
407
[581]408        virtual void CollectMergeCandidates(const VssRayContainer &rays,
409                                                                                vector<MergeCandidate> &candidates) = 0;
[580]410
[610]411        void CollectViewCells(const int n);
412
[660]413        /** Returns true if this (logical) view cell is equal to a spatial node.
414        */
[610]415        virtual bool EqualToSpatialNode(ViewCell *viewCell) const { return false;}
[580]416
[660]417        /** Sets current view cells set to active, i.e., the sampling is done in this view cell set.
418        */
419        void SetViewCellsActive();
[599]420
[660]421        /** Evaluates worth of current view cell hierarchy.
422        */
[664]423        void EvalViewCellPartition(Preprocessor *preprocessor);
[660]424
[697]425
[469]426protected:
[480]427
[697]428        /** Returns the bounding box of filter width.
429        */
430        AxisAlignedBox3 GetFilterBBox(const Vector3 &viewPoint, const float width) const;
[609]431
[697]432        /** Intersects box with the tree and returns the number of intersected boxes.
433                @returns number of view cells found
434        */
435        virtual int ComputeBoxIntersections(const AxisAlignedBox3 &box, ViewCellContainer &viewCells) const {return 0;};
436
437        virtual void TestFilter(const ObjectContainer &objects) {};
438
[581]439        /**
440                if the view cells tree was already constructed or not.
441        */
442        bool ViewCellsTreeConstructed() const;
443
[574]444        int CastPassSamples(const int samplesPerPass,
445                                                const int sampleType,
446                                                VssRayContainer &vssRays) const;
[573]447
[482]448        void ParseEnvironment();
449
[508]450        /** Creates unique view cell ids.
451        */
452        void CreateUniqueViewCellIds();
[547]453
[551]454        /** Finalizes, i.e., creates mesh, volume, area etc. for the view cell.
455        */
456        virtual void Finalize(ViewCell *viewCell, const bool createMesh);
457
[480]458        /** Recollects view cells and resets statistics.
459        */
460        void ResetViewCells();
[482]461       
[480]462        /** Collects the view cells in the view cell container.
463        */
464        virtual void CollectViewCells() = 0;
[482]465       
[479]466        /** Evaluates view cells statistics and stores it in
467                mViewCellsStatistics.
468        */
469        void EvaluateViewCellsStats();
[482]470
471        //-- helper functions for view cell visualization
472
473        /** Exports the view cell partition.
474        */
[508]475        void ExportViewCellsForViz(Exporter *exporter) const;
[482]476
477        /** Sets exporter color.
478        */
479        virtual void ExportColor(Exporter *exporter, ViewCell *vc) const = 0;
480
[556]481
[557]482        virtual float GetViewSpaceVolume();
483       
[503]484        /** Creates meshes from the view cells.
485        */
[517]486        void CreateViewCellMeshes();
[503]487
[610]488        /** Takes different measures to prepares the view cells after loading them from disc.
[577]489        */
490        virtual void PrepareLoadedViewCells() {};
491
[704]492        /** Constructs local view cell merge hierarchy.
493        */
494        ViewCell *ConstructLocalMergeTree(ViewCell *currentViewCell,
495                                                                          const ViewCellContainer &viewCells);
496
[660]497        /** Creates clip plane for visualization.
498        */
499        void CreateClipPlane();
[591]500
[660]501        Plane3 mClipPlane;
502        bool mUseClipPlaneForViz;
[591]503
504
[480]505        /// Renders the view cells.
506        Renderer *mRenderer;
[440]507
508        /// Loaded view cells
[469]509        ViewCellContainer mViewCells;
[440]510
[580]511        ViewCellsTree *mViewCellsTree;
512
[706]513        //bool mSampleEmptyViewCells;
514
[440]515        /// maximum number of samples taken for construction of the view cells
516        int mConstructionSamples;
[574]517        int mSamplesPerPass;
518        int mInitialSamples;
[440]519        int mPostProcessSamples;
520        int mVisualizationSamples;
[441]521
[470]522        float mTotalAreaValid;
523        float mTotalArea;
[475]524
[547]525        int mMaxPvsSize;
[562]526        int mMinPvsSize;
[547]527        float mMaxPvsRatio;
528
[660]529        int mSamplingType;
[600]530        int mNumActiveViewCells;
[586]531        bool mCompressViewCells;
532
[660]533        ViewCellsStatistics mCurrentViewCellsStats;
[487]534        /// the scene bounding box
[542]535        AxisAlignedBox3 mViewSpaceBox;
[508]536        /// holds the view cell meshes
[503]537        MeshContainer mMeshContainer;
[508]538        /// if view cells should be exported
539        bool mExportViewCells;
[547]540
[591]541        //bool mMarchTree);
[564]542        bool mOnlyValidViewCells;
[547]543
[580]544        /// if rays should be used to collect merge candidates
545        bool mUseRaysForMerge;
[697]546        /// merge the view cells?
[592]547        bool mMergeViewCells;
[697]548
549        /// the width of the box filter
550        float mFilterWidth;
551        int mMaxFilterSize;
552
[487]553        //-- visualization options
554       
555        /// color code for view cells
556        int mColorCode;
557        bool mExportGeometry;
558        bool mExportRays;
[517]559
560        bool mViewCellsFinished;
[664]561
562        bool mEvaluateViewCells;
[666]563
[693]564        bool mShowVisualization;
565
566        // HACK in order to detect empty view cells
567        void CollectEmptyViewCells();
[694]568        void TestEmptyViewCells(const ObjectContainer &obj);
[693]569
570        ViewCellContainer mEmptyViewCells;
[440]571};
572
[441]573
574
[440]575/**
576        Manages different higher order operations on the view cells.
577*/
578class BspViewCellsManager: public ViewCellsManager
579{
580
581public:
[485]582        /** Constructor taking the bsp tree and the number of samples
583                used to construct the bsp tree.
584        */
[574]585        BspViewCellsManager(BspTree *tree);
[440]586
[477]587        ~BspViewCellsManager();
588
[574]589        int ConstructSubdivision(const ObjectContainer &objects,
[487]590                                  const VssRayContainer &rays);
[440]591
592        int PostProcess(const ObjectContainer &objects,
[466]593                                        const VssRayContainer &rays);
[440]594
595        void Visualize(const ObjectContainer &objects,
[466]596                                   const VssRayContainer &sampleRays);
[440]597
598        int GetType() const;
599       
600        ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
601
602        bool ViewCellsConstructed() const;
603
[475]604        //void PrintStatistics(ostream &s) const;
[452]605
[468]606        int CastLineSegment(const Vector3 &origin,
607                                                const Vector3 &termination,
608                                                ViewCellContainer &viewcells);
609       
[471]610        float GetProbability(ViewCell *viewCell);
[605]611       
[466]612
[503]613        /** Get a viewcell containing the specified point */
[569]614        ViewCell *GetViewCell(const Vector3 &point) const;
[492]615
[503]616        void CreateMesh(ViewCell *vc);
617
[591]618        void ExportViewCellGeometry(Exporter *exporter,
619                                                                ViewCell *vc,
[660]620                                                                const Plane3 *clipPlane = NULL) const;
[580]621       
[587]622        void CollectMergeCandidates(const VssRayContainer &rays,
623                                                                vector<MergeCandidate> &candidates);
[547]624
[587]625        void Finalize(ViewCell *viewCell, const bool createMesh);
626
[590]627        bool ExportViewCells(const string filename);
628
[650]629        ViewCell *ConstructSpatialMergeTree(BspNode *root);
[610]630
631
[440]632protected:
633
[610]634
[590]635        /** HACK
636        */
637        void AddCurrentViewCellsToHierarchy();
638
[480]639        void CollectViewCells();
640
[482]641        void ExportColor(Exporter *exporter, ViewCell *vc) const;
[547]642       
[482]643
[547]644
[440]645        /// the BSP tree.
646        BspTree *mBspTree;
[475]647       
648        vector<BspRay *> mBspRays;
[440]649
650private:
651
652        /** Exports visualization of the BSP splits.
653        */
[477]654        void ExportSplits(const ObjectContainer &objects);
[440]655
656        /** Exports visualization of the BSP PVS.
657        */
[477]658        void ExportBspPvs(const ObjectContainer &objects);
[440]659
[693]660        void TestSubdivision();
[440]661};
662
663/**
664        Manages different higher order operations on the KD type view cells.
665*/
666class KdViewCellsManager: public ViewCellsManager
667{
668
669public:
670
671        KdViewCellsManager(KdTree *tree);
672
[574]673        int ConstructSubdivision(const ObjectContainer &objects,
[487]674                                  const VssRayContainer &rays);
[440]675
[478]676        int CastLineSegment(const Vector3 &origin,
677                                                const Vector3 &termination,
678                                                ViewCellContainer &viewcells);
[440]679
680        int PostProcess(const ObjectContainer &objects,
[466]681                                        const VssRayContainer &rays);
[440]682
683        void Visualize(const ObjectContainer &objects,
[466]684                                   const VssRayContainer &sampleRays);
[440]685
686        int GetType() const;
687
688        bool ViewCellsConstructed() const;
689
[580]690        ViewCell *GenerateViewCell(Mesh *mesh) const;
[440]691
[452]692        /** Prints out statistics of this approach.
693        */
[503]694        //  virtual void PrintStatistics(ostream &s) const;
[569]695        ViewCell *GetViewCell(const Vector3 &point) const { return NULL; }
[452]696
[503]697        float GetProbability(ViewCell *viewCell);
[609]698       
[468]699
[503]700        void CreateMesh(ViewCell *vc);
701
[591]702        void ExportViewCellGeometry(Exporter *exporter,
703                                                                ViewCell *vc,
[660]704                                                                const Plane3 *clipPlane = NULL) const;
[547]705
[591]706        void CollectMergeCandidates(const VssRayContainer &rays,
707                                                                vector<MergeCandidate> &candidates);
[580]708
[440]709protected:
710
[580]711        /** Collects view cells from a hierarchy.
712        */
[480]713        void CollectViewCells();
[580]714
[480]715        KdNode *GetNodeForPvs(KdLeaf *leaf);
[440]716
[482]717        void ExportColor(Exporter *exporter, ViewCell *vc) const;
[440]718
[547]719
[480]720        /// the BSP tree.
721        KdTree *mKdTree;
[440]722
[480]723        /// depth of the KD tree nodes with represent the view cells
724        int mKdPvsDepth;
[440]725};
726
727/**
728        Manages different higher order operations on the view cells
729        for vsp kd tree view cells.
730*/
731class VspKdViewCellsManager: public ViewCellsManager
732{
733
734public:
735
[574]736        VspKdViewCellsManager(VspKdTree *vspKdTree);
[440]737
[574]738        int ConstructSubdivision(const ObjectContainer &objects,
[487]739                                  const VssRayContainer &rays);
[440]740
741
742        int PostProcess(const ObjectContainer &objects,
[466]743                                        const VssRayContainer &rays);
[440]744
745        void Visualize(const ObjectContainer &objects,
[466]746                                   const VssRayContainer &sampleRays);
[440]747
748        int GetType() const;
749       
750        bool ViewCellsConstructed() const;
751
[475]752        //virtual void PrintStatistics(ostream &s) const;
[440]753
[462]754        ViewCell *GenerateViewCell(Mesh *mesh) const;
755
[466]756
757    int CastLineSegment(const Vector3 &origin,
758                                                const Vector3 &termination,
[468]759                                                ViewCellContainer &viewcells);
[466]760
[569]761        ViewCell *GetViewCell(const Vector3 &point) const { return NULL; }
[492]762
[471]763        float GetProbability(ViewCell *viewCell);
[468]764
[609]765
[503]766        void CreateMesh(ViewCell *vc);
767
[591]768        void ExportViewCellGeometry(Exporter *exporter,
769                                                                ViewCell *vc,
[660]770                                                                const Plane3 *clipPlane = NULL) const;
[547]771
[580]772        void CollectMergeCandidates(const VssRayContainer &rays, vector<MergeCandidate> &candidates);
773
[440]774protected:
775
[482]776        void ExportLeaves(const ObjectContainer &objects,
777                                          const VssRayContainer &sampleRays);
778
[480]779        void CollectViewCells();
780
[482]781        void ExportColor(Exporter *exporter, ViewCell *vc) const;
782
783
[547]784
[440]785        /// the BSP tree.
786        VspKdTree *mVspKdTree;
787};
788
789
[442]790
791/**
792        Manages different higher order operations on the view cells.
793*/
794class VspBspViewCellsManager: public ViewCellsManager
795{
796
797public:
798
[574]799        VspBspViewCellsManager(VspBspTree *tree);
[475]800        ~VspBspViewCellsManager();
[442]801
[574]802        int ConstructSubdivision(const ObjectContainer &objects,
[487]803                                  const VssRayContainer &rays);
[442]804
805        int PostProcess(const ObjectContainer &objects,
[466]806                                        const VssRayContainer &rays);
[442]807
808        void Visualize(const ObjectContainer &objects,
[466]809                                   const VssRayContainer &sampleRays);
[442]810
811        int GetType() const;
812       
813        ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
814
815        bool ViewCellsConstructed() const;
816
[468]817       
818        int CastLineSegment(const Vector3 &origin,
819                                                const Vector3 &termination,
820                                                ViewCellContainer &viewcells);
[452]821
[471]822        float GetProbability(ViewCell *viewCell);
[479]823       
[569]824        ViewCell *GetViewCell(const Vector3 &point) const;
[477]825
[487]826        bool GetViewPoint(Vector3 &viewPoint) const;
827
[490]828        bool ViewPointValid(const Vector3 &viewPoint) const;
[503]829
830        void CreateMesh(ViewCell *vc);
831
[577]832        //bool LoadViewCellsGeometry(const string filename, ObjectContainer *objects);
[508]833        bool ExportViewCells(const string filename);
834
[532]835        int CastBeam(Beam &beam);
836
[591]837        void ExportViewCellGeometry(Exporter *exporter,
838                                                                ViewCell *vc,
[660]839                                                                const Plane3 *clipPlane = NULL) const;
[547]840
[551]841        //float GetVolume(ViewCell *viewCell) const;
842
[555]843        void Finalize(ViewCell *viewCell, const bool createMesh);
[551]844
[580]845        void CollectMergeCandidates(const VssRayContainer &rays, vector<MergeCandidate> &candidates);
846
[697]847        /** Returns true if this view cell is equivavalent to a spatial node.
848        */
[609]849        bool EqualToSpatialNode(ViewCell *viewCell) const;
[607]850
[697]851
[442]852protected:
[475]853
[697]854        int ComputeBoxIntersections(const AxisAlignedBox3 &box, ViewCellContainer &viewCells) const;
[651]855       
[610]856        /** Returns node of the spatial hierarchy corresponding to the view cell
857                if such a node exists.
858        */
[609]859        BspNode *GetSpatialNode(ViewCell *viewCell) const;
[610]860
[590]861        /** HACK
862        */
863        void AddCurrentViewCellsToHierarchy();
864
[503]865        /** Merges the view cells.
[442]866        */
[508]867        void MergeViewCells(const VssRayContainer &rays,
868                                                const ObjectContainer &objects);
[503]869       
[564]870        void RefineViewCells(const VssRayContainer &rays, const ObjectContainer &objects);
[442]871
[480]872        void CollectViewCells();
873
[482]874        /** Returns maximal depth difference of view cell
875                leaves in tree.
876        */
877        int GetMaxTreeDiff(ViewCell *vc) const;
[485]878       
[482]879
[485]880        void ExportColor(Exporter *exporter, ViewCell *vc) const;
881
[577]882        void PrepareLoadedViewCells();
883
[650]884        ViewCell *ConstructSpatialMergeTree(BspNode *root);
[649]885
[697]886        void TestFilter(const ObjectContainer &objects);
887
888
889
[442]890        /// the view space partition BSP tree.
891        VspBspTree *mVspBspTree;
892
[591]893
[442]894private:
895
896        /** Exports visualization of the BSP splits.
897        */
[485]898        void ExportSplits(const ObjectContainer &objects,
899                                          const VssRayContainer &rays);
[442]900
901        /** Exports visualization of the BSP PVS.
902        */
[485]903        void ExportBspPvs(const ObjectContainer &objects,
904                                          const VssRayContainer &rays);
[442]905
[693]906        void TestSubdivision();
[442]907};
908
[575]909
910class ViewCellsManagerFactory
911{
912
913public:
914
915        ViewCellsManager *Create(const string mName);
916
917};
918
[440]919#endif
Note: See TracBrowser for help on using the repository browser.