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

Revision 1184, 28.2 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;
[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        */
[1159]118        virtual float ComputeSampleContribution(VssRay &ray,
119                                                                                        const bool addRays,
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        */
[1178]385        virtual 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        */
[1160]414        void UpdateScalarPvsSize(ViewCell *vc, const int pvsSize, const int entriesInPvs) const;
[728]415
[870]416        /** Returns bounding box of a view cell.
417        */
418        AxisAlignedBox3 GetViewCellBox(ViewCell *vc);
[859]419
[840]420        /** Exports bounding boxes of objects to file.
421        */
422        bool ExportBoundingBoxes(const string filename, const ObjectContainer &objects) const;
[931]423   
[850]424        /** Load the bounding boxes into the container.
425        */
426        bool LoadBoundingBoxes(const string filename, IndexedBoundingBoxContainer &boxes) const;
[840]427
[1002]428        /** Returns true if pvs should be exported together with the view cells.
429        */
430        bool GetExportPvs() const;
[870]431
432        /** Loads view cells from file. The view cells manager is created with
433                respect to the loaded view cells.
434
[1002]435                @param filename the filename of the view cells
436                @param objects the scene objects
437                @param finalizeViewCells if the view cells should be post processed, i.e.
438                        a mesh is created representing the geometry
439                @param bconverter a conversion routine working with the similarities of bounding
440                boxes: if there is a certain similarity of overlap between bounding boxes, two tested
441                candidate objects are considered to be the same objects
[870]442                @returns the view cells manager if loading was successful, false otherwise
443        */
[938]444        static ViewCellsManager *LoadViewCells(const string &filename,
[931]445                                                                                   ObjectContainer *objects,
[944]446                                                                                   const bool finalizeViewCells,
[931]447                                                                                   BoundingBoxConverter *bconverter = NULL);
[870]448
[904]449
[931]450        ////////////////////////////////////////////////////////7
451        // visiblity filter options
452        // TODO: write own visibiltiy filter class
453        void ApplyFilter(KdTree *kdTree,
454                                         const float viewSpaceFilterSize,
455                                         const float spatialFilterSize);
[904]456
[931]457        void ApplySpatialFilter(KdTree *kdTree,
458                                                        const float spatialFilterSize,
459                                                        ObjectPvs &pvs);
[480]460
[931]461         void ApplyFilter(ViewCell *viewCell,
462                                          KdTree *kdTree,
463                                          const float viewSpaceFilterSize,
464                                          const float spatialFilterSize,
465                                          ObjectPvs &pvs);
466
467        float GetFilterWidth();
468
469        float GetAbsFilterWidth();
470
471       
[697]472        /** Returns the bounding box of filter width.
473        */
474        AxisAlignedBox3 GetFilterBBox(const Vector3 &viewPoint, const float width) const;
[609]475
[979]476
[1155]477        /** Returns true if the view cell is equivalent to a
478                node of the spatial hierarchy. This function can be used for merged
479                view cell.
480                e.g. to see if the spatial tree can be reduced on this location
[1021]481        */
482        virtual bool EqualToSpatialNode(ViewCell *viewCell) const;
483
[1155]484        /** If true, the kd nodes are stored instead of the object pvs.
485        */
486        void SetStoreKdPvs(const bool storeKdPvs);
487
488        /** Returns true if the kd nodes are stored instead of the object pvs.
489        **/
490        bool GetStoreKdPVs() const;
491
[931]492protected:
[1145]493
[931]494        /** Exports bounding boxes as xml stream
495        */
[955]496        //bool ExportBoundingBoxes(ofstream &xmlstream, const ObjectContainer &objects) const;
[931]497
[697]498        /** Intersects box with the tree and returns the number of intersected boxes.
499                @returns number of view cells found
500        */
[710]501        virtual int ComputeBoxIntersections(const AxisAlignedBox3 &box,
502                                                                                ViewCellContainer &viewCells) const;
[697]503
[880]504        /** Tests the visibility filter functionality.
505        */
[697]506        virtual void TestFilter(const ObjectContainer &objects) {};
507
[931]508        /** If the view cells tree was already constructed or not.
[581]509        */
510        bool ViewCellsTreeConstructed() const;
511
[574]512        int CastPassSamples(const int samplesPerPass,
513                                                const int sampleType,
514                                                VssRayContainer &vssRays) const;
[573]515
[931]516        /** Parse the options from the environment file.
517        */
[482]518        void ParseEnvironment();
519
[508]520        /** Creates unique view cell ids.
521        */
522        void CreateUniqueViewCellIds();
[547]523
[551]524        /** Finalizes, i.e., creates mesh, volume, area etc. for the view cell.
525        */
526        virtual void Finalize(ViewCell *viewCell, const bool createMesh);
527
[480]528        /** Recollects view cells and resets statistics.
529        */
530        void ResetViewCells();
[482]531       
[480]532        /** Collects the view cells in the view cell container.
533        */
534        virtual void CollectViewCells() = 0;
[482]535       
[479]536        /** Evaluates view cells statistics and stores it in
537                mViewCellsStatistics.
538        */
539        void EvaluateViewCellsStats();
[482]540
541        //-- helper functions for view cell visualization
542
543        /** Exports the view cell partition.
544        */
[508]545        void ExportViewCellsForViz(Exporter *exporter) const;
[482]546
547        /** Sets exporter color.
548        */
[1021]549        virtual void ExportColor(Exporter *exporter, ViewCell *vc) const;
[482]550
[1002]551        /** Returns volume of the view space.
552        */
[557]553        virtual float GetViewSpaceVolume();
554       
[503]555        /** Creates meshes from the view cells.
556        */
[517]557        void CreateViewCellMeshes();
[503]558
[610]559        /** Takes different measures to prepares the view cells after loading them from disc.
[577]560        */
561        virtual void PrepareLoadedViewCells() {};
562
[704]563        /** Constructs local view cell merge hierarchy.
564        */
565        ViewCell *ConstructLocalMergeTree(ViewCell *currentViewCell,
566                                                                          const ViewCellContainer &viewCells);
567
[713]568        /** Constructs local view cell merge hierarchy based solely on similarity with the
569                current viewcell
570        */
571        ViewCell *ConstructLocalMergeTree2(ViewCell *currentViewCell,
572                                                                           const ViewCellContainer &viewCells);
573 
[660]574        /** Creates clip plane for visualization.
575        */
576        void CreateClipPlane();
[591]577
[860]578        /** Updates pvs of all view cells for statistical evaluation after some more sampling
579        */
[1168]580        void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs);
[752]581
[1002]582       
[979]583        ////////////////////////////////////////////////
[752]584
[1145]585        Preprocessor *mPreprocessor;
586        /// if bounding boxes should be exported together with the view cells
[840]587        bool mExportBboxesForPvs;
588               
[1004]589        //Environment *environment;
[1047]590        AxisAlignedPlane mClipPlane;
[837]591
[660]592        bool mUseClipPlaneForViz;
[591]593
594
[480]595        /// Renders the view cells.
596        Renderer *mRenderer;
[440]597
598        /// Loaded view cells
[469]599        ViewCellContainer mViewCells;
[1002]600        /// the corresponding view cell tree holding the logical description of view cells
[580]601        ViewCellsTree *mViewCellsTree;
[1002]602        /// if empty view cells should be pruned (i.e., invalidated) from this point on
[710]603        bool mPruneEmptyViewCells;
[706]604
[1155]605        /// if the values in the view cell leaves and the interiors are up to date
606        /// this is meant for lazy storing of the pvs, where only a scalar indicating
607        /// pvs size is stored in interiors and not the pvs itself.
[719]608        bool mViewCellPvsIsUpdated;
[1002]609
[440]610        /// maximum number of samples taken for construction of the view cells
611        int mConstructionSamples;
[574]612        int mSamplesPerPass;
613        int mInitialSamples;
[440]614        int mPostProcessSamples;
615        int mVisualizationSamples;
[441]616
[470]617        float mTotalAreaValid;
618        float mTotalArea;
[475]619
[547]620        int mMaxPvsSize;
[562]621        int mMinPvsSize;
[547]622        float mMaxPvsRatio;
623
[660]624        int mSamplingType;
[722]625        int mEvaluationSamplingType;
[600]626        int mNumActiveViewCells;
[586]627        bool mCompressViewCells;
628
[1002]629        /// holds the current view cell statistics
[660]630        ViewCellsStatistics mCurrentViewCellsStats;
[487]631        /// the scene bounding box
[542]632        AxisAlignedBox3 mViewSpaceBox;
[1001]633       
[508]634        /// if view cells should be exported
635        bool mExportViewCells;
[547]636
[1002]637        // if only valid view cells should be considered for processing
[564]638        bool mOnlyValidViewCells;
[547]639
[580]640        /// if rays should be used to collect merge candidates
641        bool mUseRaysForMerge;
[1021]642
[1002]643        /// if there should be an additional merge step after the subdivision
[592]644        bool mMergeViewCells;
[697]645
646        /// the width of the box filter
647        float mFilterWidth;
648        int mMaxFilterSize;
649
[487]650        //-- visualization options
651       
[1002]652        /// color code for view cells visualization
[487]653        int mColorCode;
654        bool mExportGeometry;
655        bool mExportRays;
[517]656
657        bool mViewCellsFinished;
[664]658
659        bool mEvaluateViewCells;
[666]660
[693]661        bool mShowVisualization;
662
663        // HACK in order to detect empty view cells
664        void CollectEmptyViewCells();
[694]665        void TestEmptyViewCells(const ObjectContainer &obj);
[693]666
667        ViewCellContainer mEmptyViewCells;
[728]668
669        int mRenderCostEvaluationType;
[844]670
671        /// if pvs should be exported with view cells
672        bool mExportPvs;
[1155]673
674        bool mStoreKdPvs;
[1178]675
676        VssRayContainer storedRays;
[440]677};
678
[441]679
[440]680/**
681        Manages different higher order operations on the view cells.
682*/
683class BspViewCellsManager: public ViewCellsManager
684{
685
686public:
[485]687        /** Constructor taking the bsp tree and the number of samples
688                used to construct the bsp tree.
689        */
[1004]690        BspViewCellsManager(BspTree *tree);
[440]691
[477]692        ~BspViewCellsManager();
693
[574]694        int ConstructSubdivision(const ObjectContainer &objects,
[487]695                                  const VssRayContainer &rays);
[440]696
697        int PostProcess(const ObjectContainer &objects,
[466]698                                        const VssRayContainer &rays);
[440]699
700        void Visualize(const ObjectContainer &objects,
[466]701                                   const VssRayContainer &sampleRays);
[440]702
703        int GetType() const;
704       
705        ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
706
707        bool ViewCellsConstructed() const;
708
[475]709        //void PrintStatistics(ostream &s) const;
[452]710
[468]711        int CastLineSegment(const Vector3 &origin,
712                                                const Vector3 &termination,
713                                                ViewCellContainer &viewcells);
714       
[471]715        float GetProbability(ViewCell *viewCell);
[605]716       
[466]717
[879]718        /** Get a viewcell containing the specified point
719        */
720        ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const;
[492]721
[503]722        void CreateMesh(ViewCell *vc);
723
[591]724        void ExportViewCellGeometry(Exporter *exporter,
725                                                                ViewCell *vc,
[1047]726                                                                const AxisAlignedPlane *clipPlane = NULL) const;
[580]727       
[587]728        void CollectMergeCandidates(const VssRayContainer &rays,
729                                                                vector<MergeCandidate> &candidates);
[547]730
[587]731        void Finalize(ViewCell *viewCell, const bool createMesh);
732
[931]733        bool ExportViewCells(const string filename, const bool exportPvs, const ObjectContainer &objects);
[590]734
[752]735        /** Constructs merge hierarchy which corresponds to the spatial hierarchy.
736        */
[650]737        ViewCell *ConstructSpatialMergeTree(BspNode *root);
[610]738
[1168]739       
[440]740protected:
741
[480]742        void CollectViewCells();
743
[547]744       
[440]745        /// the BSP tree.
746        BspTree *mBspTree;
[475]747       
748        vector<BspRay *> mBspRays;
[440]749
750private:
751
752        /** Exports visualization of the BSP splits.
753        */
[477]754        void ExportSplits(const ObjectContainer &objects);
[440]755
756        /** Exports visualization of the BSP PVS.
757        */
[477]758        void ExportBspPvs(const ObjectContainer &objects);
[440]759
[1002]760        /** test if subdivision is valid in terms of volume / area.
761        */
[693]762        void TestSubdivision();
[440]763};
764
765/**
766        Manages different higher order operations on the KD type view cells.
767*/
768class KdViewCellsManager: public ViewCellsManager
769{
770
771public:
772
[1004]773        KdViewCellsManager(KdTree *tree);
[440]774
[574]775        int ConstructSubdivision(const ObjectContainer &objects,
[487]776                                  const VssRayContainer &rays);
[440]777
[478]778        int CastLineSegment(const Vector3 &origin,
779                                                const Vector3 &termination,
780                                                ViewCellContainer &viewcells);
[440]781
782        int PostProcess(const ObjectContainer &objects,
[466]783                                        const VssRayContainer &rays);
[440]784
785        void Visualize(const ObjectContainer &objects,
[466]786                                   const VssRayContainer &sampleRays);
[440]787
788        int GetType() const;
789
790        bool ViewCellsConstructed() const;
791
[580]792        ViewCell *GenerateViewCell(Mesh *mesh) const;
[440]793
[452]794        /** Prints out statistics of this approach.
795        */
[503]796        //  virtual void PrintStatistics(ostream &s) const;
[879]797        ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const { return NULL; }
[452]798
[503]799        float GetProbability(ViewCell *viewCell);
[609]800       
[468]801
[503]802        void CreateMesh(ViewCell *vc);
803
[591]804        void ExportViewCellGeometry(Exporter *exporter,
805                                                                ViewCell *vc,
[1047]806                                                                const AxisAlignedPlane *clipPlane = NULL) const;
[547]807
[591]808        void CollectMergeCandidates(const VssRayContainer &rays,
809                                                                vector<MergeCandidate> &candidates);
[580]810
[752]811
[440]812protected:
813
[580]814        /** Collects view cells from a hierarchy.
815        */
[480]816        void CollectViewCells();
[580]817
[480]818        KdNode *GetNodeForPvs(KdLeaf *leaf);
[440]819
820
[480]821        /// the BSP tree.
822        KdTree *mKdTree;
[440]823
[480]824        /// depth of the KD tree nodes with represent the view cells
825        int mKdPvsDepth;
[938]826
827
[440]828};
829
830/**
[442]831        Manages different higher order operations on the view cells.
832*/
833class VspBspViewCellsManager: public ViewCellsManager
834{
835
836public:
837
[1004]838        VspBspViewCellsManager(VspBspTree *tree);
[475]839        ~VspBspViewCellsManager();
[442]840
[574]841        int ConstructSubdivision(const ObjectContainer &objects,
[487]842                                  const VssRayContainer &rays);
[442]843
844        int PostProcess(const ObjectContainer &objects,
[466]845                                        const VssRayContainer &rays);
[442]846
847        void Visualize(const ObjectContainer &objects,
[466]848                                   const VssRayContainer &sampleRays);
[442]849
850        int GetType() const;
851       
852        ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
853
854        bool ViewCellsConstructed() const;
855
[468]856       
857        int CastLineSegment(const Vector3 &origin,
858                                                const Vector3 &termination,
859                                                ViewCellContainer &viewcells);
[452]860
[471]861        float GetProbability(ViewCell *viewCell);
[479]862       
[879]863        ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const;
[477]864
[487]865        bool GetViewPoint(Vector3 &viewPoint) const;
866
[490]867        bool ViewPointValid(const Vector3 &viewPoint) const;
[503]868
869        void CreateMesh(ViewCell *vc);
870
[931]871        bool ExportViewCells(const string filename, const bool exportPvs, const ObjectContainer &objects);
[508]872
[532]873        int CastBeam(Beam &beam);
874
[591]875        void ExportViewCellGeometry(Exporter *exporter,
876                                                                ViewCell *vc,
[1047]877                                                                const AxisAlignedPlane *clipPlane = NULL) const;
[547]878
[551]879        //float GetVolume(ViewCell *viewCell) const;
880
[555]881        void Finalize(ViewCell *viewCell, const bool createMesh);
[551]882
[580]883        void CollectMergeCandidates(const VssRayContainer &rays, vector<MergeCandidate> &candidates);
884
[697]885        /** Returns true if this view cell is equivavalent to a spatial node.
886        */
[609]887        bool EqualToSpatialNode(ViewCell *viewCell) const;
[607]888
[697]889
[442]890protected:
[475]891
[697]892        int ComputeBoxIntersections(const AxisAlignedBox3 &box, ViewCellContainer &viewCells) const;
[651]893       
[610]894        /** Returns node of the spatial hierarchy corresponding to the view cell
895                if such a node exists.
896        */
[609]897        BspNode *GetSpatialNode(ViewCell *viewCell) const;
[610]898
[1021]899        /** Merges view cells according to some criteria
[442]900        */
[508]901        void MergeViewCells(const VssRayContainer &rays,
902                                                const ObjectContainer &objects);
[503]903       
[564]904        void RefineViewCells(const VssRayContainer &rays, const ObjectContainer &objects);
[442]905
[480]906        void CollectViewCells();
907
[482]908        /** Returns maximal depth difference of view cell
909                leaves in tree.
910        */
911        int GetMaxTreeDiff(ViewCell *vc) const;
[485]912       
[482]913
[752]914        /** Prepare view cells for use after loading them from disc.
915        */
[577]916        void PrepareLoadedViewCells();
917
[752]918        /** Constructs merge hierarchy which corresponds to the spatial hierarchy.
919        */
[650]920        ViewCell *ConstructSpatialMergeTree(BspNode *root);
[649]921
[979]922        /// HACK for testing visibility filter functionality
[697]923        void TestFilter(const ObjectContainer &objects);
924
[979]925        /** Visualization of the pvs difference to exact visubility using
926                from point queries.
927        */
928        void VisualizeWithFromPointQueries();
[697]929
[991]930        /** Evaluate from point queries for the current scene.
931        */
932        void EvalFromPointQueries();
[979]933
[1021]934        /** Exports visualization of the BSP splits.
935        */
936        void ExportSplits(const ObjectContainer &objects,
937                                          const VssRayContainer &rays);
[991]938
[1021]939        /** Exports visualization of the BSP PVS.
940        */
941        void ExportBspPvs(const ObjectContainer &objects,
942                                          const VssRayContainer &rays);
943
944
[442]945        /// the view space partition BSP tree.
946        VspBspTree *mVspBspTree;
947
[591]948
[442]949private:
950
[1021]951        /** test if subdivision is valid in terms of volume / area.
[442]952        */
[1021]953        void TestSubdivision();
954};
[442]955
[1184]956#define TEST_EVALUATION 1
[1021]957
958/**
959        Manages different higher order operations on the view cells.
960*/
961class VspOspViewCellsManager: public ViewCellsManager
962{
963
964public:
965
966        VspOspViewCellsManager(VspTree *tree, OspTree *ospTree);
967        ~VspOspViewCellsManager();
968
969        int ConstructSubdivision(const ObjectContainer &objects,
970                                                         const VssRayContainer &rays);
971
972        int PostProcess(const ObjectContainer &objects,
973                                        const VssRayContainer &rays);
974
975        void Visualize(const ObjectContainer &objects,
976                                   const VssRayContainer &sampleRays);
977
978        int GetType() const;
979       
980        ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
981
982        bool ViewCellsConstructed() const;
983
984       
985        int CastLineSegment(const Vector3 &origin,
986                                                const Vector3 &termination,
987                                                ViewCellContainer &viewcells);
988
989        float GetProbability(ViewCell *viewCell);
990       
991        ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const;
992
993        bool GetViewPoint(Vector3 &viewPoint) const;
994
995        bool ViewPointValid(const Vector3 &viewPoint) const;
996
997        void CreateMesh(ViewCell *vc);
998
[1027]999        bool ExportViewCells(const string filename,
1000                                                 const bool exportPvs,
1001                                                 const ObjectContainer &objects);
[1021]1002
1003        int CastBeam(Beam &beam);
1004
1005        void Finalize(ViewCell *viewCell, const bool createMesh);
1006
[1159]1007        /** Stores sample contribution for kd cells or objects.
1008        */
1009        virtual float ComputeSampleContribution(VssRay &ray,
1010                                                                                        const bool addRays,
1011                                                                                        const bool storeViewCells);
[1021]1012
1013protected:
[1180]1014
[1184]1015#if TEST_EVALUATION
[1178]1016        virtual void EvalViewCellPartition();
[1179]1017#endif
[1027]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
[1074]1038        /** Exports visualization of the PVS.
[442]1039        */
[1184]1040        void ExportPvs(
1041                const ObjectContainer &objects,
[1074]1042                const VssRayContainer &rays);
[442]1043
[1021]1044
[1168]1045        /////////////////////////////////////////
[1021]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.