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

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