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

Revision 1845, 32.6 KB checked in by mattausch, 18 years ago (diff)

improved object pvs

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;
309
[490]310        /** Returns true if this view point is in the valid view space.
311        */
312        virtual bool ViewPointValid(const Vector3 &viewPoint) const;
313
[487]314        /** Sets a view space boundary.
315        */
316        void SetViewSpaceBox(const AxisAlignedBox3 &box);
317
[519]318        AxisAlignedBox3 GetViewSpaceBox() const;
319
[503]320        /** Creates mesh for this view cell.
321        */
322        virtual void CreateMesh(ViewCell *vc) = NULL;
[487]323
[508]324        /** Writes view cells to disc.
325        */
[1027]326        virtual bool ExportViewCells(const string filename,
327                                                                 const bool exportPvs,
328                                                                 const ObjectContainer &objects);
[508]329
[532]330        /** Casts beam to collect view cells.
331        */
332        virtual int CastBeam(Beam &beam);
333
[547]334        /** Checks if view cell is considered as valid.
335        */
[561]336        virtual bool CheckValidity(ViewCell *vc,
[562]337                                                           int minPvsSize,
338                                                           int maxPvsSize) const;
[547]339
[562]340       
341        /** Sets validity of view cell
342        */
343        virtual void SetValidity(ViewCell *vc,
344                                                         int minPvsSize,
345                                                         int maxPvsSize) const;
346
[710]347        /** sets validy of all viewcells
348        */
[810]349        virtual void SetValidity(int minPvsSize,
[569]350                                                         int maxPvsSize) const;
351
[609]352
353        /** set valid viewcells in the range of pvs. sorts the viewcells
[710]354          according to the pvs and then pickups those in the ranges
355          */
356        void SetValidityPercentage(const float minValid, const float maxValid);
[569]357
[1545]358        /** Returns number of valid view cells.
359        */
[609]360    int CountValidViewcells() const;
361
[547]362        /** Returns maximal allowed pvs size.
363        */
364        int GetMaxPvsSize() const;
365
[562]366        /** Returns maximal allowed pvs size.
367        */
368        int GetMinPvsSize() const;
[561]369        /** Returns maximal ratio. i.e., currentPVs / maxPvs,
370                where pvs is still considered valid.
371        */
372        float GetMaxPvsRatio() const;
[547]373        /** Exports view cell geometry.
374        */
[1416]375        virtual void ExportViewCellGeometry(
376                Exporter *exporter,
377                ViewCell *vc,
378                const AxisAlignedBox3 *box,
379                const AxisAlignedPlane *clipPlane = NULL
380                ) const = 0;
[547]381
[860]382        /** Brings the view cells into their final state, computes meshes and volume.
383        */
[551]384        virtual void FinalizeViewCells(const bool createMesh);
385
[579]386        /** Evaluates statistics values on view cells.
387        */
[580]388        void EvaluateRenderStatistics(float &totalRenderCost,
389                                                                  float &expectedRenderCost,
390                                                                  float &deviation,
391                                                                  float &variance,
[1709]392                                                                  float &totalPvs,
[580]393                                                                  float &avgRenderCost);
[579]394
[580]395
396        /** Returns hierarchy of the view cells.
397        */
398        ViewCellsTree *GetViewCellsTree();
399
[1545]400        /** Collect candidates for the view cell merge.
401        */
[581]402        virtual void CollectMergeCandidates(const VssRayContainer &rays,
[1022]403                                                                                vector<MergeCandidate> &candidates);
[580]404
[1294]405        /** Collects n view cells and stores it as the active view cells.
406        */
[610]407        void CollectViewCells(const int n);
408
[1686]409        /** Sets current view cells set to active,
410                i.e., the sampling is done in this view cell set.
[660]411        */
412        void SetViewCellsActive();
[599]413
[1145]414        /** Evaluates render cost statistics of current view cell hierarchy.
[660]415        */
[1178]416        virtual void EvalViewCellPartition();
[660]417
[728]418        /** Sets maximal size of a view cell filter.
419        */
420        void SetMaxFilterSize(const int size);
[697]421
[840]422        /** Returns maximal filter size.
423        */
424        int GetMaxFilterSize() const;
[746]425
[1686]426        /** Deletes interior nodes from the tree which have negative
427                merge cost set (local merge).
[840]428        */ 
429        void DeleteLocalMergeTree(ViewCell *vc) const;
[713]430 
[728]431        /** Evaluautes histogram for a given number of view cells.
432        */
433        void EvalViewCellHistogram(const string filename, const int nViewCells);
434
[735]435        /** Evaluautes histogram for a given number of view cells.
436        */
437        void EvalViewCellHistogramForPvsSize(const string filename, const int nViewCells);
438
[728]439        /** Evaluates the render cost of a view cell.
440        */
[1703]441        static float EvalRenderCost(Intersectable *obj);
[1002]442   
443        /** Sets pvs size of view cell as a scalar. Used when storing pvs only in the leaves
444                of the hierarchy.
445        */
[1709]446        void UpdateScalarPvsSize(ViewCell *vc, const float pvsCost, const int entriesInPvs) const;
[728]447
[870]448        /** Returns bounding box of a view cell.
449        */
450        AxisAlignedBox3 GetViewCellBox(ViewCell *vc);
[859]451
[840]452        /** Exports bounding boxes of objects to file.
453        */
454        bool ExportBoundingBoxes(const string filename, const ObjectContainer &objects) const;
[931]455   
[850]456        /** Load the bounding boxes into the container.
457        */
458        bool LoadBoundingBoxes(const string filename, IndexedBoundingBoxContainer &boxes) const;
[840]459
[1002]460        /** Returns true if pvs should be exported together with the view cells.
461        */
462        bool GetExportPvs() const;
[870]463
[1786]464        /** Efficiently merges the view cells in the container.
465        */
[1787]466        void MergeViewCellsRecursivly(ObjectPvs &pvs,
467                                                                  const ViewCellContainer &viewCells) const;
[1786]468
[1845]469        virtual void CompressViewCells();
470
[1582]471        /////////////////////////////
472        // static members
473       
474        /** Loads view cells from file. The view cells manager is created with
475                respect to the loaded view cells.
[870]476
[1582]477                @param filename the filename of the view cells
478                @param objects the scene objects
479                @param finalizeViewCells if the view cells should be post processed, i.e.
480                        a mesh is created representing the geometry
481                @param bconverter a conversion routine working with the similarities of bounding
482                boxes: if there is a certain similarity of overlap between bounding boxes, two tested
483                candidate objects are considered to be the same objects
484                @returns the view cells manager if loading was successful, false otherwise
485        */
486        static ViewCellsManager *LoadViewCells(const string &filename,
487                                                                                   ObjectContainer *objects,
[1676]488                                                                                   bool finalizeViewCells = false,
[1582]489                                                                                   BoundingBoxConverter *bconverter = NULL);
[870]490
[904]491
[931]492        ////////////////////////////////////////////////////////7
493        // visiblity filter options
[1294]494
[931]495        // TODO: write own visibiltiy filter class
[1761]496  void ApplyFilter(KdTree *kdTree,
[931]497                                         const float viewSpaceFilterSize,
498                                         const float spatialFilterSize);
[904]499
[1715]500  // new adaptive version of the filter
[1761]501  PvsFilterStatistics
[1715]502  ApplyFilter2(ViewCell *viewCell,
[1824]503                                                         const bool useViewSpaceFilter,
504                                                         const float filterSize,
505                                                         ObjectPvs &pvs,
506                                                         vector<AxisAlignedBox3> *filteredBoxes = NULL
507                                                         );
[1715]508
[931]509        void ApplySpatialFilter(KdTree *kdTree,
510                                                        const float spatialFilterSize,
511                                                        ObjectPvs &pvs);
[480]512
[931]513         void ApplyFilter(ViewCell *viewCell,
514                                          KdTree *kdTree,
515                                          const float viewSpaceFilterSize,
516                                          const float spatialFilterSize,
517                                          ObjectPvs &pvs);
518
519        float GetFilterWidth();
520
521        float GetAbsFilterWidth();
522
[697]523        /** Returns the bounding box of filter width.
524        */
525        AxisAlignedBox3 GetFilterBBox(const Vector3 &viewPoint, const float width) const;
[609]526
[1294]527        //////////////////////////////////////////////////////////////////
[979]528
[1155]529        /** If true, the kd nodes are stored instead of the object pvs.
530        */
531        void SetStoreKdPvs(const bool storeKdPvs);
532
533        /** Returns true if the kd nodes are stored instead of the object pvs.
534        **/
535        bool GetStoreKdPVs() const;
536
[1570]537        /** Exports single view cells for visualization.
538                @param objects the scene objects
539                @param limit the maximal number of output view cells
540                @param sortViewCells if the view cells should be sorted by pvs size
541                @param exportPvs if the pvs should also be exported
542                @param exportRays if sample rays should be exported as well
[1580]543                @param maxRays maximum number of rays to export
544                @param prefix the prefix for the output file
[1570]545                @param visRays additional rays
546        */
[1686]547        virtual void ExportSingleViewCells(const ObjectContainer &objects,
548                                                                           const int maxViewCells,
549                                                                           const bool sortViewCells,
550                                                                           const bool exportPvs,
551                                                                           const bool exportRays,
552                                                                           const int maxRays,
553                                                                           const string prefix,
554                                                                           VssRayContainer *visRays = NULL) = NULL;
[1570]555
[1580]556       
557        void ViewCellsManager::ResetPvs();
[1582]558 
559  Preprocessor *GetPreprocessor() const {
560        return mPreprocessor;
561  }
[1580]562
[1582]563  void SetPreprocessor(Preprocessor *p) {
564        mPreprocessor = p;
565  }
[1580]566
[1608]567  void UpdatePvsForEvaluation();
568
[931]569protected:
[1145]570
[1787]571        void MergeViewCellsRecursivly(ObjectPvs &pvs,
572                                                                  const ViewCellContainer &viewCells,
573                                                                  const int leftIdx,
574                                                                  const int rightIdx) const;
575
[697]576        /** Intersects box with the tree and returns the number of intersected boxes.
577                @returns number of view cells found
578        */
[710]579        virtual int ComputeBoxIntersections(const AxisAlignedBox3 &box,
580                                                                                ViewCellContainer &viewCells) const;
[697]581
[880]582        /** Tests the visibility filter functionality.
583        */
[697]584        virtual void TestFilter(const ObjectContainer &objects) {};
585
[931]586        /** If the view cells tree was already constructed or not.
[581]587        */
588        bool ViewCellsTreeConstructed() const;
589
[1294]590        /** Requests preprocessor to cast samplesPerPass samples of a specific type.
591        */
[574]592        int CastPassSamples(const int samplesPerPass,
[1768]593                                                const vector<int> &strategies,
[574]594                                                VssRayContainer &vssRays) const;
[573]595
[931]596        /** Parse the options from the environment file.
597        */
[482]598        void ParseEnvironment();
599
[508]600        /** Creates unique view cell ids.
601        */
602        void CreateUniqueViewCellIds();
[547]603
[551]604        /** Finalizes, i.e., creates mesh, volume, area etc. for the view cell.
605        */
606        virtual void Finalize(ViewCell *viewCell, const bool createMesh);
607
[480]608        /** Recollects view cells and resets statistics.
609        */
610        void ResetViewCells();
[482]611       
[1707]612        /** Sets this view cell to active.
613        */
614        void SetViewCellActive(ViewCell *vc) const;
615
[480]616        /** Collects the view cells in the view cell container.
617        */
618        virtual void CollectViewCells() = 0;
[482]619       
[479]620        /** Evaluates view cells statistics and stores it in
621                mViewCellsStatistics.
622        */
623        void EvaluateViewCellsStats();
[482]624
[1580]625       
[1416]626        ///////////////////////
[482]627        //-- helper functions for view cell visualization
628
629        /** Exports the view cell partition.
630        */
[1686]631        void ExportViewCellsForViz(Exporter *exporter,
632                                                           const AxisAlignedBox3 *box,
[1760]633                                                           const bool colorCode,
634                                                           const AxisAlignedPlane *clipPlane
635                                                           ) const;
[482]636
637        /** Sets exporter color.
638        */
[1773]639        virtual void ExportColor(Exporter *exporter,
640                                                         ViewCell *vc,
641                                                         const bool colorCode) const;
[1545]642       
[1416]643        /** Creates meshes from the view cells.
644        */
645        void CreateViewCellMeshes();
[1545]646
647    /** Creates clip plane for visualization.
[1416]648        */
649        void CreateClipPlane();
[482]650
[1416]651        AxisAlignedPlane *GetClipPlane();
[1545]652       
[1551]653        void ExportMergedViewCells(const ObjectContainer &objects);
654
[1416]655        ///////////////////////
656
[1002]657        /** Returns volume of the view space.
658        */
[557]659        virtual float GetViewSpaceVolume();
[1416]660        /** Prepares the view cells for sampling after loading them from disc.
[503]661        */
[577]662        virtual void PrepareLoadedViewCells() {};
[704]663        /** Constructs local view cell merge hierarchy.
664        */
665        ViewCell *ConstructLocalMergeTree(ViewCell *currentViewCell,
666                                                                          const ViewCellContainer &viewCells);
667
[713]668        /** Constructs local view cell merge hierarchy based solely on similarity with the
669                current viewcell
670        */
671        ViewCell *ConstructLocalMergeTree2(ViewCell *currentViewCell,
672                                                                           const ViewCellContainer &viewCells);
673 
[860]674        /** Updates pvs of all view cells for statistical evaluation after some more sampling
675        */
[1168]676        void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs);
[752]677
[1679]678        virtual void ExportStats(const string &mergeStats);
[1582]679
680 
[979]681        ////////////////////////////////////////////////
[752]682
[1145]683        Preprocessor *mPreprocessor;
684        /// if bounding boxes should be exported together with the view cells
[840]685        bool mExportBboxesForPvs;
[1416]686        /// the clip plane for visualization
687        AxisAlignedPlane mClipPlaneForViz;
688        /// if the visualization is using the clip plane
[660]689        bool mUseClipPlaneForViz;
[480]690        /// Renders the view cells.
691        Renderer *mRenderer;
[440]692        /// Loaded view cells
[469]693        ViewCellContainer mViewCells;
[1416]694        /// the view cell hierarchy (i.e., the logical description of view cells)
[580]695        ViewCellsTree *mViewCellsTree;
[1414]696       
[1773]697        std::vector<int> mStrategies;
698
[1416]699        /** if the values in the view cell leaves and the interiors are up to date
700                this is meant for lazy storing of the pvs, where only a scalar indicating
701                pvs size is stored in interiors and not the pvs itself.
702        */
[719]703        bool mViewCellPvsIsUpdated;
[1002]704
[1416]705        /// maximum number of samples for the view cell construction
[440]706        int mConstructionSamples;
[574]707        int mSamplesPerPass;
708        int mInitialSamples;
[440]709        int mPostProcessSamples;
710        int mVisualizationSamples;
[441]711
[470]712        float mTotalAreaValid;
713        float mTotalArea;
[475]714
[547]715        int mMaxPvsSize;
[562]716        int mMinPvsSize;
[547]717        float mMaxPvsRatio;
718
[660]719        int mSamplingType;
[722]720        int mEvaluationSamplingType;
[600]721        int mNumActiveViewCells;
[586]722        bool mCompressViewCells;
723
[1002]724        /// holds the current view cell statistics
[660]725        ViewCellsStatistics mCurrentViewCellsStats;
[487]726        /// the scene bounding box
[542]727        AxisAlignedBox3 mViewSpaceBox;
[1001]728       
[508]729        /// if view cells should be exported
730        bool mExportViewCells;
[547]731
[1002]732        // if only valid view cells should be considered for processing
[564]733        bool mOnlyValidViewCells;
[547]734
[580]735        /// if rays should be used to collect merge candidates
736        bool mUseRaysForMerge;
[1021]737
[1002]738        /// if there should be an additional merge step after the subdivision
[592]739        bool mMergeViewCells;
[697]740
741        /// the width of the box filter
742        float mFilterWidth;
[1570]743        /// Maximal size of the filter in terms of contributing view cells
[697]744        int mMaxFilterSize;
[1570]745       
[1576]746        // only for debugging
[1686]747        VssRayContainer storedRays;
748
[1545]749        //////////////////
[487]750        //-- visualization options
751       
[1002]752        /// color code for view cells visualization
[1570]753        bool mShowVisualization;
[487]754        int mColorCode;
755        bool mExportGeometry;
756        bool mExportRays;
[517]757        bool mViewCellsFinished;
[664]758        bool mEvaluateViewCells;
[844]759
760        /// if pvs should be exported with view cells
761        bool mExportPvs;
[1155]762
[1703]763        static int sRenderCostEvaluationType;
764
765        /// if view cells geometry should be used from other sources
[1545]766        bool mUsePredefinedViewCells;
[440]767};
768
[441]769
[1545]770/** Manages different higher order operations on the view cells.
[440]771*/
772class BspViewCellsManager: public ViewCellsManager
773{
774
775public:
[485]776        /** Constructor taking the bsp tree and the number of samples
777                used to construct the bsp tree.
778        */
[1264]779        BspViewCellsManager(ViewCellsTree *viewCellsTree, BspTree *tree);
[440]780
[477]781        ~BspViewCellsManager();
[1582]782
[574]783        int ConstructSubdivision(const ObjectContainer &objects,
[487]784                                  const VssRayContainer &rays);
[440]785
786        int PostProcess(const ObjectContainer &objects,
[466]787                                        const VssRayContainer &rays);
[440]788
789        void Visualize(const ObjectContainer &objects,
[466]790                                   const VssRayContainer &sampleRays);
[440]791
792        int GetType() const;
793       
794        ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
795
796        bool ViewCellsConstructed() const;
797
[475]798        //void PrintStatistics(ostream &s) const;
[452]799
[468]800        int CastLineSegment(const Vector3 &origin,
801                                                const Vector3 &termination,
802                                                ViewCellContainer &viewcells);
803       
[1294]804        /** Returns the probability that the view point lies
805                in this view cells.
806        */
[471]807        float GetProbability(ViewCell *viewCell);
[466]808
[1294]809        /** Get a viewcell containing the specified point.
[879]810        */
811        ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const;
[492]812
[1294]813        /** Creates mesh for this view cell.
814        */
[503]815        void CreateMesh(ViewCell *vc);
816
[1416]817        void ExportViewCellGeometry(Exporter *exporter,
818                                                                ViewCell *vc,
819                                                                const AxisAlignedBox3 *box,
820                                                                const AxisAlignedPlane *clipPlane = NULL
821                                                                ) const;
[580]822       
[587]823        void CollectMergeCandidates(const VssRayContainer &rays,
824                                                                vector<MergeCandidate> &candidates);
[547]825
[587]826        void Finalize(ViewCell *viewCell, const bool createMesh);
827
[1416]828        bool ExportViewCells(const string filename,
829                                                 const bool exportPvs,
830                                                 const ObjectContainer &objects);
[590]831
[752]832        /** Constructs merge hierarchy which corresponds to the spatial hierarchy.
833        */
[650]834        ViewCell *ConstructSpatialMergeTree(BspNode *root);
[610]835
[1686]836        void ExportSingleViewCells(const ObjectContainer &objects,
837                                                           const int maxViewCells,
838                                                           const bool sortViewCells,
839                                                           const bool exportPvs,
840                                                           const bool exportRays,
841                                                           const int maxRays,
842                                                           const string prefix,
843                                                           VssRayContainer *visRays = NULL);
[1545]844
[440]845protected:
846
[480]847        void CollectViewCells();
[547]848       
[440]849        /// the BSP tree.
850        BspTree *mBspTree;
[475]851        vector<BspRay *> mBspRays;
[440]852
853private:
854
[1545]855        /** Constructs a spatial merge tree only 2 levels deep.
856        */
857        ViewCell *ConstructDummyMergeTree(BspNode *root);
858
[440]859        /** Exports visualization of the BSP splits.
860        */
[477]861        void ExportSplits(const ObjectContainer &objects);
[440]862
[1002]863        /** test if subdivision is valid in terms of volume / area.
864        */
[693]865        void TestSubdivision();
[440]866};
867
[1545]868
[440]869/**
870        Manages different higher order operations on the KD type view cells.
871*/
872class KdViewCellsManager: public ViewCellsManager
873{
874
875public:
876
[1264]877        KdViewCellsManager(ViewCellsTree *viewCellsTree, KdTree *tree);
[440]878
[574]879        int ConstructSubdivision(const ObjectContainer &objects,
[1686]880                                                         const VssRayContainer &rays);
[440]881
[478]882        int CastLineSegment(const Vector3 &origin,
883                                                const Vector3 &termination,
884                                                ViewCellContainer &viewcells);
[440]885
886        int PostProcess(const ObjectContainer &objects,
[466]887                                        const VssRayContainer &rays);
[440]888
889        void Visualize(const ObjectContainer &objects,
[466]890                                   const VssRayContainer &sampleRays);
[440]891
892        int GetType() const;
893
894        bool ViewCellsConstructed() const;
895
[580]896        ViewCell *GenerateViewCell(Mesh *mesh) const;
[440]897
[452]898        /** Prints out statistics of this approach.
899        */
[503]900        //  virtual void PrintStatistics(ostream &s) const;
[1416]901        ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const
902        { return NULL; }
[452]903
[503]904        float GetProbability(ViewCell *viewCell);
[609]905       
[503]906        void CreateMesh(ViewCell *vc);
907
[1686]908        void ExportViewCellGeometry(Exporter *exporter,
909                                                                ViewCell *vc,
910                                                                const AxisAlignedBox3 *box,
911                                                                const AxisAlignedPlane *clipPlane = NULL) const;
[547]912
[1416]913
[591]914        void CollectMergeCandidates(const VssRayContainer &rays,
915                                                                vector<MergeCandidate> &candidates);
[580]916
[1686]917        void ExportSingleViewCells(const ObjectContainer &objects,
918                                                           const int maxViewCells,
919                                                           const bool sortViewCells,
920                                                           const bool exportPvs,
921                                                           const bool exportRays,
922                                                           const int maxRays,
923                                                           const string prefix,
924                                                           VssRayContainer *visRays = NULL);
[752]925
[440]926protected:
927
[580]928        /** Collects view cells from a hierarchy.
929        */
[480]930        void CollectViewCells();
[580]931
[480]932        KdNode *GetNodeForPvs(KdLeaf *leaf);
[440]933
[1570]934        ////////////////////////////////////////
[440]935
[480]936        /// the BSP tree.
937        KdTree *mKdTree;
[440]938
[480]939        /// depth of the KD tree nodes with represent the view cells
940        int mKdPvsDepth;
[938]941
942
[440]943};
944
[1570]945
946/** Manages different higher order operations on the view cells.
[442]947*/
948class VspBspViewCellsManager: public ViewCellsManager
949{
950
951public:
952
[1264]953        VspBspViewCellsManager(ViewCellsTree *viewCellsTree, VspBspTree *tree);
[475]954        ~VspBspViewCellsManager();
[442]955
[574]956        int ConstructSubdivision(const ObjectContainer &objects,
[1686]957                                                         const VssRayContainer &rays);
[442]958
959        int PostProcess(const ObjectContainer &objects,
[466]960                                        const VssRayContainer &rays);
[442]961
962        void Visualize(const ObjectContainer &objects,
[466]963                                   const VssRayContainer &sampleRays);
[442]964
965        int GetType() const;
966       
967        ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
968
969        bool ViewCellsConstructed() const;
970
[468]971       
972        int CastLineSegment(const Vector3 &origin,
973                                                const Vector3 &termination,
974                                                ViewCellContainer &viewcells);
[452]975
[471]976        float GetProbability(ViewCell *viewCell);
[479]977       
[879]978        ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const;
[477]979
[487]980        bool GetViewPoint(Vector3 &viewPoint) const;
981
[490]982        bool ViewPointValid(const Vector3 &viewPoint) const;
[503]983
984        void CreateMesh(ViewCell *vc);
985
[1686]986        bool ExportViewCells(const string filename,
987                                                 const bool exportPvs,
988                                                 const ObjectContainer &objects);
[508]989
[532]990        int CastBeam(Beam &beam);
[1416]991       
[1686]992        void ExportViewCellGeometry(Exporter *exporter,
993                                                                ViewCell *vc,
994                                                                const AxisAlignedBox3 *box,
995                                                                const AxisAlignedPlane *clipPlane = NULL) const;
[532]996
[547]997
[555]998        void Finalize(ViewCell *viewCell, const bool createMesh);
[551]999
[1686]1000        void CollectMergeCandidates(const VssRayContainer &rays,
1001                                                                vector<MergeCandidate> &candidates);
[580]1002
[1686]1003        void ExportSingleViewCells(const ObjectContainer &objects,
1004                                                           const int maxViewCells,
1005                                                           const bool sortViewCells,
1006                                                           const bool exportPvs,
1007                                                           const bool exportRays,               
1008                                                           const int maxRays,
1009                                                           const string prefix,
1010                                                           VssRayContainer *visRays = NULL);
[1570]1011
1012
[442]1013protected:
[475]1014
[1686]1015        int ComputeBoxIntersections(const AxisAlignedBox3 &box,
1016                                                                ViewCellContainer &viewCells) const;
[651]1017       
[1021]1018        /** Merges view cells according to some criteria
[442]1019        */
[508]1020        void MergeViewCells(const VssRayContainer &rays,
1021                                                const ObjectContainer &objects);
[503]1022       
[564]1023        void RefineViewCells(const VssRayContainer &rays, const ObjectContainer &objects);
[442]1024
[480]1025        void CollectViewCells();
1026
[482]1027        /** Returns maximal depth difference of view cell
1028                leaves in tree.
1029        */
1030        int GetMaxTreeDiff(ViewCell *vc) const;
1031
[752]1032        /** Prepare view cells for use after loading them from disc.
1033        */
[577]1034        void PrepareLoadedViewCells();
1035
[752]1036        /** Constructs merge hierarchy which corresponds to the spatial hierarchy.
1037        */
[650]1038        ViewCell *ConstructSpatialMergeTree(BspNode *root);
[649]1039
[979]1040        /// HACK for testing visibility filter functionality
[697]1041        void TestFilter(const ObjectContainer &objects);
1042
[979]1043        /** Visualization of the pvs difference to exact visubility using
1044                from point queries.
1045        */
1046        void VisualizeWithFromPointQueries();
[697]1047
[991]1048        /** Evaluate from point queries for the current scene.
1049        */
1050        void EvalFromPointQueries();
[979]1051
[1021]1052        /** Exports visualization of the BSP splits.
1053        */
1054        void ExportSplits(const ObjectContainer &objects,
1055                                          const VssRayContainer &rays);
[991]1056
[1686]1057
1058        /////////////////////////
1059
[442]1060        /// the view space partition BSP tree.
1061        VspBspTree *mVspBspTree;
1062
[591]1063
[442]1064private:
1065
[1021]1066        /** test if subdivision is valid in terms of volume / area.
[442]1067        */
[1021]1068        void TestSubdivision();
1069};
[442]1070
[1662]1071#define TEST_EVALUATION 0
[1021]1072
1073/**
1074        Manages different higher order operations on the view cells.
1075*/
1076class VspOspViewCellsManager: public ViewCellsManager
1077{
[1740]1078        friend class ViewCellsParseHandlers;
[1021]1079public:
1080
[1740]1081        VspOspViewCellsManager(ViewCellsTree *vcTree, const string &hierarchyType);
[1278]1082       
[1021]1083        ~VspOspViewCellsManager();
1084
1085        int ConstructSubdivision(const ObjectContainer &objects,
1086                                                         const VssRayContainer &rays);
1087
1088        int PostProcess(const ObjectContainer &objects,
1089                                        const VssRayContainer &rays);
1090
[1686]1091        void Visualize(const ObjectContainer &objects,
[1021]1092                                   const VssRayContainer &sampleRays);
1093
1094        int GetType() const;
1095       
1096        ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
1097
[1743]1098  virtual Intersectable *
1099  GetIntersectable(const VssRay &ray, const bool isTermination) const;
1100
[1021]1101        bool ViewCellsConstructed() const;
1102
1103       
1104        int CastLineSegment(const Vector3 &origin,
1105                                                const Vector3 &termination,
1106                                                ViewCellContainer &viewcells);
1107
1108        float GetProbability(ViewCell *viewCell);
1109       
1110        ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const;
1111
1112        bool GetViewPoint(Vector3 &viewPoint) const;
1113
1114        bool ViewPointValid(const Vector3 &viewPoint) const;
1115
1116        void CreateMesh(ViewCell *vc);
1117
[1027]1118        bool ExportViewCells(const string filename,
1119                                                 const bool exportPvs,
1120                                                 const ObjectContainer &objects);
[1021]1121
1122        int CastBeam(Beam &beam);
1123
1124        void Finalize(ViewCell *viewCell, const bool createMesh);
1125
[1159]1126        /** Stores sample contribution for kd cells or objects.
1127        */
1128        virtual float ComputeSampleContribution(VssRay &ray,
1129                                                                                        const bool addRays,
1130                                                                                        const bool storeViewCells);
[1021]1131
[1201]1132        ViewCellsManager *LoadViewCells(const string &filename,
[1666]1133                                                                        ObjectContainer *objects,
1134                                                                        const bool finalizeViewCells,
1135                                                                        BoundingBoxConverter *bconverter);
[1201]1136
[1666]1137        void ExportSingleViewCells(const ObjectContainer &objects,
1138                                                           const int maxViewCells,
1139                                                           const bool sortViewCells,
1140                                                           const bool exportPvs,
1141                                                           const bool exportRays,
1142                                                           const int maxRays,
1143                                                           const string prefix,
1144                                                           VssRayContainer *visRays = NULL);
[1570]1145
[1021]1146protected:
[1180]1147
[1740]1148        VspOspViewCellsManager(ViewCellsTree *vcTree, HierarchyManager *hm);
1149       
[1709]1150#if 1//TEST_EVALUATION
1151        virtual void EvalViewCellPartition();
1152#endif
[1416]1153
[1027]1154        /** Exports view cell geometry.
1155        */
[1666]1156        void ExportViewCellGeometry(Exporter *exporter,
1157                                                                ViewCell *vc,
1158                                                                const AxisAlignedBox3 *box,
1159                                                                const AxisAlignedPlane *clipPlane = NULL) const;
[1027]1160
[1666]1161        int ComputeBoxIntersections(const AxisAlignedBox3 &box,
1162                                                                ViewCellContainer &viewCells) const;
[1021]1163       
1164        void CollectViewCells();
1165
[1845]1166        virtual void CompressViewCells();
1167
[1021]1168        /** Prepare view cells for use after loading them from disc.
1169        */
1170        void PrepareLoadedViewCells();
1171
1172        /** Constructs merge hierarchy which corresponds to the spatial hierarchy.
1173        */
1174        ViewCell *ConstructSpatialMergeTree(VspNode *root);
1175
[1074]1176        /** Exports visualization of the PVS.
[442]1177        */
[1666]1178        void ExportPvs(const ObjectContainer &objects, const VssRayContainer &rays);
[442]1179
[1740]1180        /** Returns a hierarchy manager of the given name.
1181        */
1182        static HierarchyManager *CreateHierarchyManager(const string &name);
1183
[1679]1184        //void ExportStats(const string &mergeStats);
[1021]1185
[1168]1186        /////////////////////////////////////////
[1259]1187
[1845]1188    /** collect objects intersecting a given spatial box
1189        */
1190        virtual void CollectObjects(const AxisAlignedBox3 &box, ObjectContainer &objects);
[1737]1191
[1027]1192        HierarchyManager *mHierarchyManager;
[442]1193};
1194
[575]1195
[860]1196}
1197
[440]1198#endif
Note: See TracBrowser for help on using the repository browser.