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

Revision 944, 25.6 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
464protected:
465        /** Exports bounding boxes as xml stream
466        */
467        bool ExportBoundingBoxes(ofstream &xmlstream, const ObjectContainer &objects) const;
468
469        /** Intersects box with the tree and returns the number of intersected boxes.
470                @returns number of view cells found
471        */
472        virtual int ComputeBoxIntersections(const AxisAlignedBox3 &box,
473                                                                                ViewCellContainer &viewCells) const;
474
475        /** Tests the visibility filter functionality.
476        */
477        virtual void TestFilter(const ObjectContainer &objects) {};
478
479        /** If the view cells tree was already constructed or not.
480        */
481        bool ViewCellsTreeConstructed() const;
482
483        int CastPassSamples(const int samplesPerPass,
484                                                const int sampleType,
485                                                VssRayContainer &vssRays) const;
486
487        /** Parse the options from the environment file.
488        */
489        void ParseEnvironment();
490
491        /** Creates unique view cell ids.
492        */
493        void CreateUniqueViewCellIds();
494
495        /** Finalizes, i.e., creates mesh, volume, area etc. for the view cell.
496        */
497        virtual void Finalize(ViewCell *viewCell, const bool createMesh);
498
499        /** Recollects view cells and resets statistics.
500        */
501        void ResetViewCells();
502       
503        /** Collects the view cells in the view cell container.
504        */
505        virtual void CollectViewCells() = 0;
506       
507        /** Evaluates view cells statistics and stores it in
508                mViewCellsStatistics.
509        */
510        void EvaluateViewCellsStats();
511
512        //-- helper functions for view cell visualization
513
514        /** Exports the view cell partition.
515        */
516        void ExportViewCellsForViz(Exporter *exporter) const;
517
518        /** Sets exporter color.
519        */
520        virtual void ExportColor(Exporter *exporter, ViewCell *vc) const = 0;
521
522
523        virtual float GetViewSpaceVolume();
524       
525        /** Creates meshes from the view cells.
526        */
527        void CreateViewCellMeshes();
528
529        /** Takes different measures to prepares the view cells after loading them from disc.
530        */
531        virtual void PrepareLoadedViewCells() {};
532
533        /** Constructs local view cell merge hierarchy.
534        */
535        ViewCell *ConstructLocalMergeTree(ViewCell *currentViewCell,
536                                                                          const ViewCellContainer &viewCells);
537
538        /** Constructs local view cell merge hierarchy based solely on similarity with the
539                current viewcell
540        */
541        ViewCell *ConstructLocalMergeTree2(ViewCell *currentViewCell,
542                                                                           const ViewCellContainer &viewCells);
543 
544
545        /** Creates clip plane for visualization.
546        */
547        void CreateClipPlane();
548
549        /** Updates pvs of all view cells for statistical evaluation after some more sampling
550        */
551        virtual void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs) = 0;
552
553
554
555        /// if bounding boxes should also be exported
556        bool mExportBboxesForPvs;
557               
558        Environment *environment;
559        Plane3 mClipPlane;
560
561        bool mUseClipPlaneForViz;
562
563
564        /// Renders the view cells.
565        Renderer *mRenderer;
566
567        /// Loaded view cells
568        ViewCellContainer mViewCells;
569
570        ViewCellsTree *mViewCellsTree;
571
572        bool mPruneEmptyViewCells;
573
574        bool mViewCellPvsIsUpdated;
575        /// maximum number of samples taken for construction of the view cells
576        int mConstructionSamples;
577        int mSamplesPerPass;
578        int mInitialSamples;
579        int mPostProcessSamples;
580        int mVisualizationSamples;
581
582        float mTotalAreaValid;
583        float mTotalArea;
584
585        int mMaxPvsSize;
586        int mMinPvsSize;
587        float mMaxPvsRatio;
588
589        int mSamplingType;
590        int mEvaluationSamplingType;
591        int mNumActiveViewCells;
592        bool mCompressViewCells;
593
594        ViewCellsStatistics mCurrentViewCellsStats;
595        /// the scene bounding box
596        AxisAlignedBox3 mViewSpaceBox;
597        /// holds the view cell meshes
598        MeshContainer mMeshContainer;
599        /// if view cells should be exported
600        bool mExportViewCells;
601
602        //bool mMarchTree);
603        bool mOnlyValidViewCells;
604
605        /// if rays should be used to collect merge candidates
606        bool mUseRaysForMerge;
607        /// merge the view cells?
608        bool mMergeViewCells;
609
610        /// the width of the box filter
611        float mFilterWidth;
612        int mMaxFilterSize;
613
614        //-- visualization options
615       
616        /// color code for view cells
617        int mColorCode;
618        bool mExportGeometry;
619        bool mExportRays;
620
621        bool mViewCellsFinished;
622
623        bool mEvaluateViewCells;
624
625        bool mShowVisualization;
626
627        // HACK in order to detect empty view cells
628        void CollectEmptyViewCells();
629        void TestEmptyViewCells(const ObjectContainer &obj);
630
631        ViewCellContainer mEmptyViewCells;
632
633        int mRenderCostEvaluationType;
634
635        /// if pvs should be exported with view cells
636        bool mExportPvs;
637
638        Environment *mEnvironment;
639};
640
641
642
643/**
644        Manages different higher order operations on the view cells.
645*/
646class BspViewCellsManager: public ViewCellsManager
647{
648
649public:
650        /** Constructor taking the bsp tree and the number of samples
651                used to construct the bsp tree.
652        */
653        BspViewCellsManager(BspTree *tree, Environment *env);
654
655        ~BspViewCellsManager();
656
657        int ConstructSubdivision(const ObjectContainer &objects,
658                                  const VssRayContainer &rays);
659
660        int PostProcess(const ObjectContainer &objects,
661                                        const VssRayContainer &rays);
662
663        void Visualize(const ObjectContainer &objects,
664                                   const VssRayContainer &sampleRays);
665
666        int GetType() const;
667       
668        ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
669
670        bool ViewCellsConstructed() const;
671
672        //void PrintStatistics(ostream &s) const;
673
674        int CastLineSegment(const Vector3 &origin,
675                                                const Vector3 &termination,
676                                                ViewCellContainer &viewcells);
677       
678        float GetProbability(ViewCell *viewCell);
679       
680
681        /** Get a viewcell containing the specified point
682        */
683        ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const;
684
685        void CreateMesh(ViewCell *vc);
686
687        void ExportViewCellGeometry(Exporter *exporter,
688                                                                ViewCell *vc,
689                                                                const Plane3 *clipPlane = NULL) const;
690       
691        void CollectMergeCandidates(const VssRayContainer &rays,
692                                                                vector<MergeCandidate> &candidates);
693
694        void Finalize(ViewCell *viewCell, const bool createMesh);
695
696        bool ExportViewCells(const string filename, const bool exportPvs, const ObjectContainer &objects);
697
698        /** Constructs merge hierarchy which corresponds to the spatial hierarchy.
699        */
700        ViewCell *ConstructSpatialMergeTree(BspNode *root);
701
702        /** Updates the pvs in the view cells tree.
703        */
704        void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs);
705
706
707protected:
708
709
710        void CollectViewCells();
711
712        void ExportColor(Exporter *exporter, ViewCell *vc) const;
713       
714        /// the BSP tree.
715        BspTree *mBspTree;
716       
717        vector<BspRay *> mBspRays;
718
719private:
720
721        /** Exports visualization of the BSP splits.
722        */
723        void ExportSplits(const ObjectContainer &objects);
724
725        /** Exports visualization of the BSP PVS.
726        */
727        void ExportBspPvs(const ObjectContainer &objects);
728
729        void TestSubdivision();
730};
731
732/**
733        Manages different higher order operations on the KD type view cells.
734*/
735class KdViewCellsManager: public ViewCellsManager
736{
737
738public:
739
740        KdViewCellsManager(KdTree *tree, Environment *env);
741
742        int ConstructSubdivision(const ObjectContainer &objects,
743                                  const VssRayContainer &rays);
744
745        int CastLineSegment(const Vector3 &origin,
746                                                const Vector3 &termination,
747                                                ViewCellContainer &viewcells);
748
749        int PostProcess(const ObjectContainer &objects,
750                                        const VssRayContainer &rays);
751
752        void Visualize(const ObjectContainer &objects,
753                                   const VssRayContainer &sampleRays);
754
755        int GetType() const;
756
757        bool ViewCellsConstructed() const;
758
759        ViewCell *GenerateViewCell(Mesh *mesh) const;
760
761        /** Prints out statistics of this approach.
762        */
763        //  virtual void PrintStatistics(ostream &s) const;
764        ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const { return NULL; }
765
766        float GetProbability(ViewCell *viewCell);
767       
768
769        void CreateMesh(ViewCell *vc);
770
771        void ExportViewCellGeometry(Exporter *exporter,
772                                                                ViewCell *vc,
773                                                                const Plane3 *clipPlane = NULL) const;
774
775        void CollectMergeCandidates(const VssRayContainer &rays,
776                                                                vector<MergeCandidate> &candidates);
777
778
779protected:
780
781        virtual void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs) {};
782        /** Collects view cells from a hierarchy.
783        */
784        void CollectViewCells();
785
786        KdNode *GetNodeForPvs(KdLeaf *leaf);
787
788        void ExportColor(Exporter *exporter, ViewCell *vc) const;
789
790
791        /// the BSP tree.
792        KdTree *mKdTree;
793
794        /// depth of the KD tree nodes with represent the view cells
795        int mKdPvsDepth;
796
797
798};
799
800/**
801        Manages different higher order operations on the view cells
802        for vsp kd tree view cells.
803*/
804class VspKdViewCellsManager: public ViewCellsManager
805{
806
807public:
808
809        VspKdViewCellsManager(VspKdTree *vspKdTree, Environment *env);
810
811        int ConstructSubdivision(const ObjectContainer &objects,
812                                  const VssRayContainer &rays);
813
814
815        int PostProcess(const ObjectContainer &objects,
816                                        const VssRayContainer &rays);
817
818        void Visualize(const ObjectContainer &objects,
819                                   const VssRayContainer &sampleRays);
820
821        int GetType() const;
822       
823        bool ViewCellsConstructed() const;
824
825        //virtual void PrintStatistics(ostream &s) const;
826
827        ViewCell *GenerateViewCell(Mesh *mesh) const;
828
829
830    int CastLineSegment(const Vector3 &origin,
831                                                const Vector3 &termination,
832                                                ViewCellContainer &viewcells);
833
834        ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const { return NULL; }
835
836        float GetProbability(ViewCell *viewCell);
837
838
839        void CreateMesh(ViewCell *vc);
840
841        void ExportViewCellGeometry(Exporter *exporter,
842                                                                ViewCell *vc,
843                                                                const Plane3 *clipPlane = NULL) const;
844
845        void CollectMergeCandidates(const VssRayContainer &rays, vector<MergeCandidate> &candidates);
846
847        virtual void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs) {};
848protected:
849
850        void ExportLeaves(const ObjectContainer &objects,
851                                          const VssRayContainer &sampleRays);
852
853        void CollectViewCells();
854
855        void ExportColor(Exporter *exporter, ViewCell *vc) const;
856
857
858
859        /// the BSP tree.
860        VspKdTree *mVspKdTree;
861};
862
863
864
865/**
866        Manages different higher order operations on the view cells.
867*/
868class VspBspViewCellsManager: public ViewCellsManager
869{
870
871public:
872
873        VspBspViewCellsManager(VspBspTree *tree, Environment *env);
874        ~VspBspViewCellsManager();
875
876        int ConstructSubdivision(const ObjectContainer &objects,
877                                  const VssRayContainer &rays);
878
879        int PostProcess(const ObjectContainer &objects,
880                                        const VssRayContainer &rays);
881
882        void Visualize(const ObjectContainer &objects,
883                                   const VssRayContainer &sampleRays);
884
885        int GetType() const;
886       
887        ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
888
889        bool ViewCellsConstructed() const;
890
891       
892        int CastLineSegment(const Vector3 &origin,
893                                                const Vector3 &termination,
894                                                ViewCellContainer &viewcells);
895
896        float GetProbability(ViewCell *viewCell);
897       
898        ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const;
899
900        bool GetViewPoint(Vector3 &viewPoint) const;
901
902        bool ViewPointValid(const Vector3 &viewPoint) const;
903
904        void CreateMesh(ViewCell *vc);
905
906        bool ExportViewCells(const string filename, const bool exportPvs, const ObjectContainer &objects);
907
908        int CastBeam(Beam &beam);
909
910        void ExportViewCellGeometry(Exporter *exporter,
911                                                                ViewCell *vc,
912                                                                const Plane3 *clipPlane = NULL) const;
913
914        //float GetVolume(ViewCell *viewCell) const;
915
916        void Finalize(ViewCell *viewCell, const bool createMesh);
917
918        void CollectMergeCandidates(const VssRayContainer &rays, vector<MergeCandidate> &candidates);
919
920        /** Returns true if this view cell is equivavalent to a spatial node.
921        */
922        bool EqualToSpatialNode(ViewCell *viewCell) const;
923
924
925protected:
926
927        int ComputeBoxIntersections(const AxisAlignedBox3 &box, ViewCellContainer &viewCells) const;
928       
929        /** Returns node of the spatial hierarchy corresponding to the view cell
930                if such a node exists.
931        */
932        BspNode *GetSpatialNode(ViewCell *viewCell) const;
933
934        /** Merges the view cells.
935        */
936        void MergeViewCells(const VssRayContainer &rays,
937                                                const ObjectContainer &objects);
938       
939        void RefineViewCells(const VssRayContainer &rays, const ObjectContainer &objects);
940
941        void CollectViewCells();
942
943        /** Returns maximal depth difference of view cell
944                leaves in tree.
945        */
946        int GetMaxTreeDiff(ViewCell *vc) const;
947       
948
949        void ExportColor(Exporter *exporter, ViewCell *vc) const;
950
951        /** Prepare view cells for use after loading them from disc.
952        */
953        void PrepareLoadedViewCells();
954
955        /** Constructs merge hierarchy which corresponds to the spatial hierarchy.
956        */
957        ViewCell *ConstructSpatialMergeTree(BspNode *root);
958
959        void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs);
960
961
962        // HACK
963        void TestFilter(const ObjectContainer &objects);
964
965
966
967        /// the view space partition BSP tree.
968        VspBspTree *mVspBspTree;
969
970
971private:
972
973        /** Exports visualization of the BSP splits.
974        */
975        void ExportSplits(const ObjectContainer &objects,
976                                          const VssRayContainer &rays);
977
978        /** Exports visualization of the BSP PVS.
979        */
980        void ExportBspPvs(const ObjectContainer &objects,
981                                          const VssRayContainer &rays);
982
983        void TestSubdivision();
984};
985
986
987class ViewCellsManagerFactory
988{
989
990public:
991
992        ViewCellsManager *Create(const string mName);
993
994};
995
996}
997
998#endif
Note: See TracBrowser for help on using the repository browser.