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

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