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

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