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

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