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

Revision 1001, 26.0 KB checked in by mattausch, 18 years ago (diff)

added mesh instance support
improved support for occlusion queries + other extensions

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. The view ells are created by taking the object
173                geometry into account.
174        */
175        void DeriveViewCells(const ObjectContainer &objects,
176                                                 ViewCellContainer &viewCells,
177                                                 const int maxViewCells) const;
178
179        /** Sets maximal number of samples used for the
180                construction of the view cells.
181        */
182        void SetVisualizationSamples(const int visSamples);
183
184        /** Sets maximal number of samples used for the construction of the view cells.
185        */
186        void SetConstructionSamples(const int constructionSamples);
187
188        /** Sets maximal number of samples used for the visualization of the view cells.
189        */
190        void SetInitialSamples(const int initialSamples);
191
192        /** Sets maximal number of samples used for the post processing of the view cells.
193        */
194        void SetPostProcessSamples(const int postProcessingSamples);
195
196        /** See set.
197        */
198        int GetVisualizationSamples() const;
199
200        /** See set.
201        */
202        int GetConstructionSamples() const;
203
204        /** See set.
205        */
206        int GetPostProcessSamples() const;
207
208        /** Returns true if view cells wer already constructed.
209        */
210        virtual bool ViewCellsConstructed() const = 0;
211
212        /** cast line segment to get a list of unique viewcells which are intersected
213                by this line segment
214        */
215 
216        virtual int CastLineSegment(const Vector3 &origin,
217                                                          const Vector3 &termination,
218                                                          ViewCellContainer &viewcells
219                                                          ) = 0;
220
221        virtual void GetPvsStatistics(PvsStatistics &stat);
222
223        virtual void GetPrVS(const Vector3 &viewPoint, PrVs &prvs, const float filterWidth);
224 
225        /** Get a viewcell containing the specified point
226                @param active if the active or elementary view cell should be returned.
227        */
228        virtual ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const = 0;
229 
230        virtual void PrintPvsStatistics(ostream &s);
231
232        /** Updates pvs of the view cell hierarchy if necessary.
233        */
234        void UpdatePvs();
235
236        /** Returns probability that view point lies in one view cell.
237        */
238        virtual float GetProbability(ViewCell *viewCell) = 0;
239
240        /** Returns render cost of a single view cell given the render cost of an object.
241        */
242        float GetRendercost(ViewCell *viewCell) const;
243
244        /** Returns reference to container of loaded / generated view cells.
245        */
246        ViewCellContainer &GetViewCells();
247
248        /** Helper function used to split ray sets uniformly
249                into one that is currently used and the other that
250                is saved for later processing.
251                @param sourceRays the input ray set
252                @param maxSize the maximal number of rays that will be used
253                @param usedRays returns the used ray set
254                @param savedRays if not null, returns the saved ray set
255        */
256        void GetRaySets(const VssRayContainer &sourceRays,
257                                        const int maxSize,
258                                        VssRayContainer &usedRays,
259                                        VssRayContainer *savedRays = NULL) const;
260       
261        /** Returns accumulated area of all view cells.
262        */
263        float GetAccVcArea();
264
265        /** Returns area of one view cell.
266        */
267        virtual float GetArea(ViewCell *viewCell) const;
268
269        /** Returns volume of view cell.
270        */
271        virtual float GetVolume(ViewCell *viewCell) const;
272
273        /** Sets the current renderer mainly for view cells statistics.
274        */
275        void SetRenderer(Renderer *renderer);
276
277        /** Computes a (random) view point in the valid view space.
278                @returns true if valid view point was found
279        */
280        virtual bool GetViewPoint(Vector3 &viewPoint) const;
281
282        /** Returns true if this view point is in the valid view space.
283        */
284        virtual bool ViewPointValid(const Vector3 &viewPoint) const;
285
286        /** Sets a view space boundary.
287        */
288        void SetViewSpaceBox(const AxisAlignedBox3 &box);
289
290        AxisAlignedBox3 GetViewSpaceBox() const;
291
292        /** Creates mesh for this view cell.
293        */
294        virtual void CreateMesh(ViewCell *vc) = NULL;
295
296        /** Writes view cells to disc.
297        */
298        virtual bool ExportViewCells(const string filename, const bool exportPvs, const ObjectContainer &objects);
299
300        /** Casts beam to collect view cells.
301        */
302        virtual int CastBeam(Beam &beam);
303
304        /** Checks if view cell is considered as valid.
305        */
306        virtual bool CheckValidity(ViewCell *vc,
307                                                           int minPvsSize,
308                                                           int maxPvsSize) const;
309
310       
311        /** Sets validity of view cell
312        */
313        virtual void SetValidity(ViewCell *vc,
314                                                         int minPvsSize,
315                                                         int maxPvsSize) const;
316
317        /** sets validy of all viewcells
318        */
319        virtual void SetValidity(int minPvsSize,
320                                                         int maxPvsSize) const;
321
322
323        /** set valid viewcells in the range of pvs. sorts the viewcells
324          according to the pvs and then pickups those in the ranges
325          */
326        void SetValidityPercentage(const float minValid, const float maxValid);
327
328    int CountValidViewcells() const;
329
330        /** Returns maximal allowed pvs size.
331        */
332        int GetMaxPvsSize() const;
333
334        /** Returns maximal allowed pvs size.
335        */
336        int GetMinPvsSize() const;
337
338        /** Returns maximal ratio. i.e., currentPVs / maxPvs,
339                where pvs is still considered valid.
340        */
341        float GetMaxPvsRatio() const;
342
343        /** Exports view cell geometry.
344        */
345        virtual void ExportViewCellGeometry(Exporter *exporter,
346                                                                                ViewCell *vc,
347                                                                                const Plane3 *clipPlane = NULL) const = 0;
348
349        /** Brings the view cells into their final state, computes meshes and volume.
350        */
351        virtual void FinalizeViewCells(const bool createMesh);
352
353        /** Evaluates statistics values on view cells.
354        */
355        void EvaluateRenderStatistics(float &totalRenderCost,
356                                                                  float &expectedRenderCost,
357                                                                  float &deviation,
358                                                                  float &variance,
359                                                                  int &totalPvs,
360                                                                  float &avgRenderCost);
361
362
363        /** Returns hierarchy of the view cells.
364        */
365        ViewCellsTree *GetViewCellsTree();
366
367        virtual void CollectMergeCandidates(const VssRayContainer &rays,
368                                                                                vector<MergeCandidate> &candidates) = 0;
369
370        void CollectViewCells(const int n);
371
372        /** Returns true if this (logical) view cell is equal to a spatial node.
373        */
374        virtual bool EqualToSpatialNode(ViewCell *viewCell) const;
375
376        /** Sets current view cells set to active, i.e., the sampling is done in this view cell set.
377        */
378        void SetViewCellsActive();
379
380        /** Evaluates worth of current view cell hierarchy.
381        */
382        void EvalViewCellPartition(Preprocessor *preprocessor);
383
384        /** Sets maximal size of a view cell filter.
385        */
386        void SetMaxFilterSize(const int size);
387
388        /** Returns maximal filter size.
389        */
390        int GetMaxFilterSize() const;
391
392        /** Deletes interior nodes from the tree which have negative merge cost set (local merge).
393        */ 
394        void DeleteLocalMergeTree(ViewCell *vc) const;
395 
396        /** Evaluautes histogram for a given number of view cells.
397        */
398        void EvalViewCellHistogram(const string filename, const int nViewCells);
399
400        /** Evaluautes histogram for a given number of view cells.
401        */
402        void EvalViewCellHistogramForPvsSize(const string filename, const int nViewCells);
403
404        /** Evaluates the render cost of a view cell.
405        */
406        float EvalRenderCost(Intersectable *obj) const;
407
408   
409       
410        /** Returns bounding box of a view cell.
411        */
412        AxisAlignedBox3 GetViewCellBox(ViewCell *vc);
413
414        /** Exports bounding boxes of objects to file.
415        */
416        bool ExportBoundingBoxes(const string filename, const ObjectContainer &objects) const;
417   
418        /** Load the bounding boxes into the container.
419        */
420        bool LoadBoundingBoxes(const string filename, IndexedBoundingBoxContainer &boxes) const;
421
422        bool GetExportPvs() const
423        {
424                return mExportPvs;
425        }
426
427        /** Loads view cells from file. The view cells manager is created with
428                respect to the loaded view cells.
429
430                @returns the view cells manager if loading was successful, false otherwise
431        */
432        static ViewCellsManager *LoadViewCells(const string &filename,
433                                                                                   ObjectContainer *objects,
434                                                                                   Environment *env,
435                                                                                   const bool finalizeViewCells,
436                                                                                   BoundingBoxConverter *bconverter = NULL);
437
438
439        ////////////////////////////////////////////////////////7
440        // visiblity filter options
441        // TODO: write own visibiltiy filter class
442        void ApplyFilter(KdTree *kdTree,
443                                         const float viewSpaceFilterSize,
444                                         const float spatialFilterSize);
445
446        void ApplySpatialFilter(KdTree *kdTree,
447                                                        const float spatialFilterSize,
448                                                        ObjectPvs &pvs);
449
450         void ApplyFilter(ViewCell *viewCell,
451                                          KdTree *kdTree,
452                                          const float viewSpaceFilterSize,
453                                          const float spatialFilterSize,
454                                          ObjectPvs &pvs);
455
456        float GetFilterWidth();
457
458        float GetAbsFilterWidth();
459
460       
461        /** Returns the bounding box of filter width.
462        */
463        AxisAlignedBox3 GetFilterBBox(const Vector3 &viewPoint, const float width) const;
464
465
466protected:
467        /** Exports bounding boxes as xml stream
468        */
469        //bool ExportBoundingBoxes(ofstream &xmlstream, const ObjectContainer &objects) const;
470
471        /** Intersects box with the tree and returns the number of intersected boxes.
472                @returns number of view cells found
473        */
474        virtual int ComputeBoxIntersections(const AxisAlignedBox3 &box,
475                                                                                ViewCellContainer &viewCells) const;
476
477        /** Tests the visibility filter functionality.
478        */
479        virtual void TestFilter(const ObjectContainer &objects) {};
480
481        /** If the view cells tree was already constructed or not.
482        */
483        bool ViewCellsTreeConstructed() const;
484
485        int CastPassSamples(const int samplesPerPass,
486                                                const int sampleType,
487                                                VssRayContainer &vssRays) const;
488
489        /** Parse the options from the environment file.
490        */
491        void ParseEnvironment();
492
493        /** Creates unique view cell ids.
494        */
495        void CreateUniqueViewCellIds();
496
497        /** Finalizes, i.e., creates mesh, volume, area etc. for the view cell.
498        */
499        virtual void Finalize(ViewCell *viewCell, const bool createMesh);
500
501        /** Recollects view cells and resets statistics.
502        */
503        void ResetViewCells();
504       
505        /** Collects the view cells in the view cell container.
506        */
507        virtual void CollectViewCells() = 0;
508       
509        /** Evaluates view cells statistics and stores it in
510                mViewCellsStatistics.
511        */
512        void EvaluateViewCellsStats();
513
514        //-- helper functions for view cell visualization
515
516        /** Exports the view cell partition.
517        */
518        void ExportViewCellsForViz(Exporter *exporter) const;
519
520        /** Sets exporter color.
521        */
522        virtual void ExportColor(Exporter *exporter, ViewCell *vc) const = 0;
523
524
525        virtual float GetViewSpaceVolume();
526       
527        /** Creates meshes from the view cells.
528        */
529        void CreateViewCellMeshes();
530
531        /** Takes different measures to prepares the view cells after loading them from disc.
532        */
533        virtual void PrepareLoadedViewCells() {};
534
535        /** Constructs local view cell merge hierarchy.
536        */
537        ViewCell *ConstructLocalMergeTree(ViewCell *currentViewCell,
538                                                                          const ViewCellContainer &viewCells);
539
540        /** Constructs local view cell merge hierarchy based solely on similarity with the
541                current viewcell
542        */
543        ViewCell *ConstructLocalMergeTree2(ViewCell *currentViewCell,
544                                                                           const ViewCellContainer &viewCells);
545 
546
547        /** Creates clip plane for visualization.
548        */
549        void CreateClipPlane();
550
551        /** Updates pvs of all view cells for statistical evaluation after some more sampling
552        */
553        virtual void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs) = 0;
554
555
556        ////////////////////////////////////////////////
557
558        /// if bounding boxes should also be exported
559        bool mExportBboxesForPvs;
560               
561        Environment *environment;
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       
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        /** Evaluate from point queries for the current scene.
976        */
977        void EvalFromPointQueries();
978
979
980        /// the view space partition BSP tree.
981        VspBspTree *mVspBspTree;
982
983
984private:
985
986        /** Exports visualization of the BSP splits.
987        */
988        void ExportSplits(const ObjectContainer &objects,
989                                          const VssRayContainer &rays);
990
991        /** Exports visualization of the BSP PVS.
992        */
993        void ExportBspPvs(const ObjectContainer &objects,
994                                          const VssRayContainer &rays);
995
996        void TestSubdivision();
997};
998
999
1000class ViewCellsManagerFactory
1001{
1002
1003public:
1004
1005        ViewCellsManager *Create(const string mName);
1006
1007};
1008
1009}
1010
1011#endif
Note: See TracBrowser for help on using the repository browser.