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

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