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

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