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

Revision 1155, 28.1 KB checked in by mattausch, 18 years ago (diff)

added support for kd pvs sampling

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