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

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