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

Revision 1006, 25.5 KB checked in by mattausch, 18 years ago (diff)

started viewspace-objectspace subdivision
removed memory leaks

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;
[503]34
[1004]35
[475]36struct BspRay;
37
[677]38
39/** Probably Visible Set */
[697]40class PrVs
41{
42public:
[704]43  /// root of view cells tree
44  ViewCell *mViewCell;
45
[880]46  // input parameter is the render budget for the PrVs
[677]47  float mRenderBudget;
48
49  /// some characteristic values could be here
50 
51};
52
[850]53
54/**     Manages different higher order operations on the view cells.
[440]55*/
56class ViewCellsManager
57{
58public:
[728]59        struct PvsStatistics
60        {
61                int minPvs;
62                int maxPvs;
63                float avgPvs;
64                int viewcells;
[467]65  };
[697]66
[728]67        /// view cell container types
68        enum {BSP, KD, VSP_KD, VSP_BSP};
[466]69 
[931]70        /// render cost evaluation type
[728]71        enum {PER_OBJECT, PER_TRIANGLE};
72
[1004]73        /** Default constructor.
[440]74        */
[1004]75        ViewCellsManager();
[440]76
[462]77        virtual ~ViewCellsManager();
[440]78
[527]79        /** Constructs view cells container taking a preprocessor
[570]80                @returns the output rays (if not null)
81        */
82        int Construct(Preprocessor *preprocessor, VssRayContainer *outRays = NULL);
[527]83
[440]84        /** Constructs view cell container with a given number of samples.
85        */
[574]86        virtual int ConstructSubdivision(const ObjectContainer &objects,
[487]87                                                  const VssRayContainer &rays) = 0;
[440]88
[441]89        /** Computes sample contributions of the rays to the view cells PVS.
90       
91                @param rays bundle of rays used to find intersections with view cells and
92                adding the contribution
[563]93                @param addRays true if rays should be added to the PVSs of the viewcells they
[574]94                intersect
95                @param storeViewCells true if view cells should be stored in the ray
96        */
[697]97        float ComputeSampleContributions(const VssRayContainer &rays,
[574]98                                                                   const bool addContributions,
99                                                                   const bool storeViewCells);
[440]100
[697]101        /** Add sample contributions to the viewcells they intersect */
102        void AddSampleContributions(const VssRayContainer &rays);
[563]103 
[441]104
[475]105        /** Computes sample contribution of a simgle ray to the view cells PVS.
106                @param ray finds intersections with view cells and holds the contribution
107                @param castRay true if ray should be cast to gain the information, false if ray
108                is already holding the information and need not be recast.
[466]109         
[475]110                @returns number of sample contributions
111        */
[591]112        virtual float ComputeSampleContributions(VssRay &ray,
113                                                                                         const bool addRays,
114                                                                                         const bool storeViewCells);
[563]115
[591]116        virtual void AddSampleContributions(VssRay &ray);
[563]117
[452]118        /** Prints out statistics of the view cells.
119        */
[475]120        virtual void PrintStatistics(ostream &s) const;
[452]121
[440]122        /** Post processes view cells givemŽa number of rays.
123        */
[475]124        virtual int PostProcess(const ObjectContainer &objects,
125                                                        const VssRayContainer &rays) = 0;
[440]126
127        /** Show visualization of the view cells.
128        */
129        virtual void Visualize(const ObjectContainer &objects,
[466]130                                                   const VssRayContainer &sampleRays) = 0;
[440]131
132        /** type of the view cell container.
133        */
134        virtual int GetType() const = 0;
135
[463]136        /** Load the input viewcells. The input viewcells should be given as a collection
137                of meshes. Each mesh is assume to form a bounded polyhedron defining the interior of
138                the viewcell. The method then builds a BSP tree of these view cells.
139               
140                @param filename file to load
141                @return true on success
142    */
[577]143    virtual bool LoadViewCellsGeometry(const string filename);
[440]144
[577]145       
[440]146        /** Constructs view cell from base triangle. The ViewCell is extruded along the normal vector.
147                @param the base triangle
148                @param the height of the newly created view cell
149        */
150        ViewCell *ExtrudeViewCell(const Triangle3 &baseTri, const float height) const;
151
152        /** Merges two view cells.
153                @note the piercing rays of the front and back will be ordered   
154                @returns new view cell based on the merging.
155        */
[582]156        ViewCellInterior *MergeViewCells(ViewCell *front, ViewCell *back) const;
157
158        /** Merges a container of view cells.
159                @returns new view cell based on the merging.
160        */
161        ViewCellInterior *MergeViewCells(ViewCellContainer &children) const;
[440]162       
163        /** Generates view cell of type specified by this manager
164        */
[580]165        virtual ViewCell *GenerateViewCell(Mesh *mesh = NULL) const = 0;
[440]166
167        /** Adds a new view cell to the list of predefined view cells.
168        */
169        void AddViewCell(ViewCell *viewCell);
170
[1002]171        /** Derive view cells from scene objects. The view ells are created by taking the object
[1001]172                geometry into account.
[440]173        */
[1002]174        void DeriveViewCellsFromObjects(const ObjectContainer &objects,
175                                                                        ViewCellContainer &viewCells,
176                                                                        const int maxViewCells) const;
[440]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
[1002]207        /** Returns true if view cells are already constructed.
[440]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;
[1002]406   
407        /** Sets pvs size of view cell as a scalar. Used when storing pvs only in the leaves
408                of the hierarchy.
409        */
[1004]410        void SetScalarPvsSize(ViewCell *vc, const int pvsSize) const;
[728]411
[1002]412
[870]413        /** Returns bounding box of a view cell.
414        */
415        AxisAlignedBox3 GetViewCellBox(ViewCell *vc);
[859]416
[840]417        /** Exports bounding boxes of objects to file.
418        */
419        bool ExportBoundingBoxes(const string filename, const ObjectContainer &objects) const;
[931]420   
[850]421        /** Load the bounding boxes into the container.
422        */
423        bool LoadBoundingBoxes(const string filename, IndexedBoundingBoxContainer &boxes) const;
[840]424
[1002]425        /** Returns true if pvs should be exported together with the view cells.
426        */
427        bool GetExportPvs() const;
[870]428
429        /** Loads view cells from file. The view cells manager is created with
430                respect to the loaded view cells.
431
[1002]432                @param filename the filename of the view cells
433                @param objects the scene objects
434                @param finalizeViewCells if the view cells should be post processed, i.e.
435                        a mesh is created representing the geometry
436                @param bconverter a conversion routine working with the similarities of bounding
437                boxes: if there is a certain similarity of overlap between bounding boxes, two tested
438                candidate objects are considered to be the same objects
[870]439                @returns the view cells manager if loading was successful, false otherwise
440        */
[938]441        static ViewCellsManager *LoadViewCells(const string &filename,
[931]442                                                                                   ObjectContainer *objects,
[944]443                                                                                   const bool finalizeViewCells,
[931]444                                                                                   BoundingBoxConverter *bconverter = NULL);
[870]445
[904]446
[931]447        ////////////////////////////////////////////////////////7
448        // visiblity filter options
449        // TODO: write own visibiltiy filter class
450        void ApplyFilter(KdTree *kdTree,
451                                         const float viewSpaceFilterSize,
452                                         const float spatialFilterSize);
[904]453
[931]454        void ApplySpatialFilter(KdTree *kdTree,
455                                                        const float spatialFilterSize,
456                                                        ObjectPvs &pvs);
[480]457
[931]458         void ApplyFilter(ViewCell *viewCell,
459                                          KdTree *kdTree,
460                                          const float viewSpaceFilterSize,
461                                          const float spatialFilterSize,
462                                          ObjectPvs &pvs);
463
464        float GetFilterWidth();
465
466        float GetAbsFilterWidth();
467
468       
[697]469        /** Returns the bounding box of filter width.
470        */
471        AxisAlignedBox3 GetFilterBBox(const Vector3 &viewPoint, const float width) const;
[609]472
[979]473
[931]474protected:
475        /** Exports bounding boxes as xml stream
476        */
[955]477        //bool ExportBoundingBoxes(ofstream &xmlstream, const ObjectContainer &objects) const;
[931]478
[697]479        /** Intersects box with the tree and returns the number of intersected boxes.
480                @returns number of view cells found
481        */
[710]482        virtual int ComputeBoxIntersections(const AxisAlignedBox3 &box,
483                                                                                ViewCellContainer &viewCells) const;
[697]484
[880]485        /** Tests the visibility filter functionality.
486        */
[697]487        virtual void TestFilter(const ObjectContainer &objects) {};
488
[931]489        /** If the view cells tree was already constructed or not.
[581]490        */
491        bool ViewCellsTreeConstructed() const;
492
[574]493        int CastPassSamples(const int samplesPerPass,
494                                                const int sampleType,
495                                                VssRayContainer &vssRays) const;
[573]496
[931]497        /** Parse the options from the environment file.
498        */
[482]499        void ParseEnvironment();
500
[508]501        /** Creates unique view cell ids.
502        */
503        void CreateUniqueViewCellIds();
[547]504
[551]505        /** Finalizes, i.e., creates mesh, volume, area etc. for the view cell.
506        */
507        virtual void Finalize(ViewCell *viewCell, const bool createMesh);
508
[480]509        /** Recollects view cells and resets statistics.
510        */
511        void ResetViewCells();
[482]512       
[480]513        /** Collects the view cells in the view cell container.
514        */
515        virtual void CollectViewCells() = 0;
[482]516       
[479]517        /** Evaluates view cells statistics and stores it in
518                mViewCellsStatistics.
519        */
520        void EvaluateViewCellsStats();
[482]521
522        //-- helper functions for view cell visualization
523
524        /** Exports the view cell partition.
525        */
[508]526        void ExportViewCellsForViz(Exporter *exporter) const;
[482]527
528        /** Sets exporter color.
529        */
530        virtual void ExportColor(Exporter *exporter, ViewCell *vc) const = 0;
531
[1002]532        /** Returns volume of the view space.
533        */
[557]534        virtual float GetViewSpaceVolume();
535       
[503]536        /** Creates meshes from the view cells.
537        */
[517]538        void CreateViewCellMeshes();
[503]539
[610]540        /** Takes different measures to prepares the view cells after loading them from disc.
[577]541        */
542        virtual void PrepareLoadedViewCells() {};
543
[704]544        /** Constructs local view cell merge hierarchy.
545        */
546        ViewCell *ConstructLocalMergeTree(ViewCell *currentViewCell,
547                                                                          const ViewCellContainer &viewCells);
548
[713]549        /** Constructs local view cell merge hierarchy based solely on similarity with the
550                current viewcell
551        */
552        ViewCell *ConstructLocalMergeTree2(ViewCell *currentViewCell,
553                                                                           const ViewCellContainer &viewCells);
554 
555
[660]556        /** Creates clip plane for visualization.
557        */
558        void CreateClipPlane();
[591]559
[860]560        /** Updates pvs of all view cells for statistical evaluation after some more sampling
561        */
[752]562        virtual void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs) = 0;
563
[1002]564       
[979]565        ////////////////////////////////////////////////
[752]566
[840]567        /// if bounding boxes should also be exported
568        bool mExportBboxesForPvs;
569               
[1004]570        //Environment *environment;
[660]571        Plane3 mClipPlane;
[837]572
[660]573        bool mUseClipPlaneForViz;
[591]574
575
[480]576        /// Renders the view cells.
577        Renderer *mRenderer;
[440]578
579        /// Loaded view cells
[469]580        ViewCellContainer mViewCells;
[1002]581        /// the corresponding view cell tree holding the logical description of view cells
[580]582        ViewCellsTree *mViewCellsTree;
[1002]583        /// if empty view cells should be pruned (i.e., invalidated) from this point on
[710]584        bool mPruneEmptyViewCells;
[706]585
[1002]586        /// if the pvss in the view cell leaves and the interiors are up to date
[719]587        bool mViewCellPvsIsUpdated;
[1002]588
[440]589        /// maximum number of samples taken for construction of the view cells
590        int mConstructionSamples;
[574]591        int mSamplesPerPass;
592        int mInitialSamples;
[440]593        int mPostProcessSamples;
594        int mVisualizationSamples;
[441]595
[470]596        float mTotalAreaValid;
597        float mTotalArea;
[475]598
[547]599        int mMaxPvsSize;
[562]600        int mMinPvsSize;
[547]601        float mMaxPvsRatio;
602
[660]603        int mSamplingType;
[722]604        int mEvaluationSamplingType;
[600]605        int mNumActiveViewCells;
[586]606        bool mCompressViewCells;
607
[1002]608        /// holds the current view cell statistics
[660]609        ViewCellsStatistics mCurrentViewCellsStats;
[487]610        /// the scene bounding box
[542]611        AxisAlignedBox3 mViewSpaceBox;
[1001]612       
[508]613        /// if view cells should be exported
614        bool mExportViewCells;
[547]615
[1002]616        // if only valid view cells should be considered for processing
[564]617        bool mOnlyValidViewCells;
[547]618
[580]619        /// if rays should be used to collect merge candidates
620        bool mUseRaysForMerge;
[1002]621        /// if there should be an additional merge step after the subdivision
[592]622        bool mMergeViewCells;
[697]623
624        /// the width of the box filter
625        float mFilterWidth;
626        int mMaxFilterSize;
627
[487]628        //-- visualization options
629       
[1002]630        /// color code for view cells visualization
[487]631        int mColorCode;
632        bool mExportGeometry;
633        bool mExportRays;
[517]634
635        bool mViewCellsFinished;
[664]636
637        bool mEvaluateViewCells;
[666]638
[693]639        bool mShowVisualization;
640
641        // HACK in order to detect empty view cells
642        void CollectEmptyViewCells();
[694]643        void TestEmptyViewCells(const ObjectContainer &obj);
[693]644
645        ViewCellContainer mEmptyViewCells;
[728]646
647        int mRenderCostEvaluationType;
[844]648
649        /// if pvs should be exported with view cells
650        bool mExportPvs;
[440]651};
652
[441]653
[440]654/**
655        Manages different higher order operations on the view cells.
656*/
657class BspViewCellsManager: public ViewCellsManager
658{
659
660public:
[485]661        /** Constructor taking the bsp tree and the number of samples
662                used to construct the bsp tree.
663        */
[1004]664        BspViewCellsManager(BspTree *tree);
[440]665
[477]666        ~BspViewCellsManager();
667
[574]668        int ConstructSubdivision(const ObjectContainer &objects,
[487]669                                  const VssRayContainer &rays);
[440]670
671        int PostProcess(const ObjectContainer &objects,
[466]672                                        const VssRayContainer &rays);
[440]673
674        void Visualize(const ObjectContainer &objects,
[466]675                                   const VssRayContainer &sampleRays);
[440]676
677        int GetType() const;
678       
679        ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
680
681        bool ViewCellsConstructed() const;
682
[475]683        //void PrintStatistics(ostream &s) const;
[452]684
[468]685        int CastLineSegment(const Vector3 &origin,
686                                                const Vector3 &termination,
687                                                ViewCellContainer &viewcells);
688       
[471]689        float GetProbability(ViewCell *viewCell);
[605]690       
[466]691
[879]692        /** Get a viewcell containing the specified point
693        */
694        ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const;
[492]695
[503]696        void CreateMesh(ViewCell *vc);
697
[591]698        void ExportViewCellGeometry(Exporter *exporter,
699                                                                ViewCell *vc,
[660]700                                                                const Plane3 *clipPlane = NULL) const;
[580]701       
[587]702        void CollectMergeCandidates(const VssRayContainer &rays,
703                                                                vector<MergeCandidate> &candidates);
[547]704
[587]705        void Finalize(ViewCell *viewCell, const bool createMesh);
706
[931]707        bool ExportViewCells(const string filename, const bool exportPvs, const ObjectContainer &objects);
[590]708
[752]709        /** Constructs merge hierarchy which corresponds to the spatial hierarchy.
710        */
[650]711        ViewCell *ConstructSpatialMergeTree(BspNode *root);
[610]712
[752]713        /** Updates the pvs in the view cells tree.
714        */
715        void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs);
[610]716
[859]717
[440]718protected:
719
[610]720
[480]721        void CollectViewCells();
722
[482]723        void ExportColor(Exporter *exporter, ViewCell *vc) const;
[547]724       
[440]725        /// the BSP tree.
726        BspTree *mBspTree;
[475]727       
728        vector<BspRay *> mBspRays;
[440]729
730private:
731
732        /** Exports visualization of the BSP splits.
733        */
[477]734        void ExportSplits(const ObjectContainer &objects);
[440]735
736        /** Exports visualization of the BSP PVS.
737        */
[477]738        void ExportBspPvs(const ObjectContainer &objects);
[440]739
[1002]740        /** test if subdivision is valid in terms of volume / area.
741        */
[693]742        void TestSubdivision();
[440]743};
744
745/**
746        Manages different higher order operations on the KD type view cells.
747*/
748class KdViewCellsManager: public ViewCellsManager
749{
750
751public:
752
[1004]753        KdViewCellsManager(KdTree *tree);
[440]754
[574]755        int ConstructSubdivision(const ObjectContainer &objects,
[487]756                                  const VssRayContainer &rays);
[440]757
[478]758        int CastLineSegment(const Vector3 &origin,
759                                                const Vector3 &termination,
760                                                ViewCellContainer &viewcells);
[440]761
762        int PostProcess(const ObjectContainer &objects,
[466]763                                        const VssRayContainer &rays);
[440]764
765        void Visualize(const ObjectContainer &objects,
[466]766                                   const VssRayContainer &sampleRays);
[440]767
768        int GetType() const;
769
770        bool ViewCellsConstructed() const;
771
[580]772        ViewCell *GenerateViewCell(Mesh *mesh) const;
[440]773
[452]774        /** Prints out statistics of this approach.
775        */
[503]776        //  virtual void PrintStatistics(ostream &s) const;
[879]777        ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const { return NULL; }
[452]778
[503]779        float GetProbability(ViewCell *viewCell);
[609]780       
[468]781
[503]782        void CreateMesh(ViewCell *vc);
783
[591]784        void ExportViewCellGeometry(Exporter *exporter,
785                                                                ViewCell *vc,
[660]786                                                                const Plane3 *clipPlane = NULL) const;
[547]787
[591]788        void CollectMergeCandidates(const VssRayContainer &rays,
789                                                                vector<MergeCandidate> &candidates);
[580]790
[752]791
[440]792protected:
793
[752]794        virtual void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs) {};
[580]795        /** Collects view cells from a hierarchy.
796        */
[480]797        void CollectViewCells();
[580]798
[480]799        KdNode *GetNodeForPvs(KdLeaf *leaf);
[440]800
[482]801        void ExportColor(Exporter *exporter, ViewCell *vc) const;
[440]802
[547]803
[480]804        /// the BSP tree.
805        KdTree *mKdTree;
[440]806
[480]807        /// depth of the KD tree nodes with represent the view cells
808        int mKdPvsDepth;
[938]809
810
[440]811};
812
813/**
[442]814        Manages different higher order operations on the view cells.
815*/
816class VspBspViewCellsManager: public ViewCellsManager
817{
818
819public:
820
[1004]821        VspBspViewCellsManager(VspBspTree *tree);
[475]822        ~VspBspViewCellsManager();
[442]823
[574]824        int ConstructSubdivision(const ObjectContainer &objects,
[487]825                                  const VssRayContainer &rays);
[442]826
827        int PostProcess(const ObjectContainer &objects,
[466]828                                        const VssRayContainer &rays);
[442]829
830        void Visualize(const ObjectContainer &objects,
[466]831                                   const VssRayContainer &sampleRays);
[442]832
833        int GetType() const;
834       
835        ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
836
837        bool ViewCellsConstructed() const;
838
[468]839       
840        int CastLineSegment(const Vector3 &origin,
841                                                const Vector3 &termination,
842                                                ViewCellContainer &viewcells);
[452]843
[471]844        float GetProbability(ViewCell *viewCell);
[479]845       
[879]846        ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const;
[477]847
[487]848        bool GetViewPoint(Vector3 &viewPoint) const;
849
[490]850        bool ViewPointValid(const Vector3 &viewPoint) const;
[503]851
852        void CreateMesh(ViewCell *vc);
853
[931]854        bool ExportViewCells(const string filename, const bool exportPvs, const ObjectContainer &objects);
[508]855
[532]856        int CastBeam(Beam &beam);
857
[591]858        void ExportViewCellGeometry(Exporter *exporter,
859                                                                ViewCell *vc,
[660]860                                                                const Plane3 *clipPlane = NULL) const;
[547]861
[551]862        //float GetVolume(ViewCell *viewCell) const;
863
[555]864        void Finalize(ViewCell *viewCell, const bool createMesh);
[551]865
[580]866        void CollectMergeCandidates(const VssRayContainer &rays, vector<MergeCandidate> &candidates);
867
[697]868        /** Returns true if this view cell is equivavalent to a spatial node.
869        */
[609]870        bool EqualToSpatialNode(ViewCell *viewCell) const;
[607]871
[697]872
[442]873protected:
[475]874
[697]875        int ComputeBoxIntersections(const AxisAlignedBox3 &box, ViewCellContainer &viewCells) const;
[651]876       
[610]877        /** Returns node of the spatial hierarchy corresponding to the view cell
878                if such a node exists.
879        */
[609]880        BspNode *GetSpatialNode(ViewCell *viewCell) const;
[610]881
[503]882        /** Merges the view cells.
[442]883        */
[508]884        void MergeViewCells(const VssRayContainer &rays,
885                                                const ObjectContainer &objects);
[503]886       
[564]887        void RefineViewCells(const VssRayContainer &rays, const ObjectContainer &objects);
[442]888
[480]889        void CollectViewCells();
890
[482]891        /** Returns maximal depth difference of view cell
892                leaves in tree.
893        */
894        int GetMaxTreeDiff(ViewCell *vc) const;
[485]895       
[482]896
[485]897        void ExportColor(Exporter *exporter, ViewCell *vc) const;
898
[752]899        /** Prepare view cells for use after loading them from disc.
900        */
[577]901        void PrepareLoadedViewCells();
902
[752]903        /** Constructs merge hierarchy which corresponds to the spatial hierarchy.
904        */
[650]905        ViewCell *ConstructSpatialMergeTree(BspNode *root);
[649]906
[752]907        void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs);
908
909
[979]910        /// HACK for testing visibility filter functionality
[697]911        void TestFilter(const ObjectContainer &objects);
912
913
[979]914        /** Visualization of the pvs difference to exact visubility using
915                from point queries.
916        */
917        void VisualizeWithFromPointQueries();
[697]918
[991]919        /** Evaluate from point queries for the current scene.
920        */
921        void EvalFromPointQueries();
[979]922
[991]923
[442]924        /// the view space partition BSP tree.
925        VspBspTree *mVspBspTree;
926
[591]927
[442]928private:
929
930        /** Exports visualization of the BSP splits.
931        */
[485]932        void ExportSplits(const ObjectContainer &objects,
933                                          const VssRayContainer &rays);
[442]934
935        /** Exports visualization of the BSP PVS.
936        */
[485]937        void ExportBspPvs(const ObjectContainer &objects,
938                                          const VssRayContainer &rays);
[442]939
[1002]940        /** test if subdivision is valid in terms of volume / area.
941        */
[693]942        void TestSubdivision();
[442]943};
944
[575]945
[1002]946/*class ViewCellsManagerFactory
[575]947{
948public:
949        ViewCellsManager *Create(const string mName);
[1002]950};*/
[575]951
[860]952}
953
[440]954#endif
Note: See TracBrowser for help on using the repository browser.