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

Revision 1074, 27.6 KB checked in by mattausch, 18 years ago (diff)

wked on view space object space partition

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