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

Revision 870, 24.8 KB checked in by mattausch, 18 years ago (diff)

added pvs

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