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

Revision 931, 25.7 KB checked in by mattausch, 18 years ago (diff)

added bounding boxes to xml description

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