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

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