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

Revision 884, 25.4 KB checked in by bittner, 18 years ago (diff)

Spatial visibility filter

Line 
1#ifndef _ViewCellsManager_H__
2#define _ViewCellsManager_H__
3
4#include "Ray.h"
5#include "VssRay.h"
6#include "Containers.h"
7#include "ViewCell.h"
8#include "ViewCellBsp.h"
9
10namespace GtpVisibilityPreprocessor {
11
12class ViewCell;
13class Intersectable;
14class RenderSimulator;
15class Renderer;
16class Mesh;
17struct Triangle3;
18class SimulationStatistics;
19class BspTree;
20class KdTree;
21class VspKdTree;
22class VspBspTree;
23class KdNode;
24class KdLeaf;
25class VspKdTree;
26class AxisAlignedBox3;
27class BspLeaf;
28class ViewCellsStatistics;
29class Exporter;
30class Beam;
31class Preprocessor;
32class ViewCellsTree;
33class MergeCandidate;
34
35struct BspRay;
36
37
38/** Probably Visible Set */
39class PrVs
40{
41public:
42  /// root of view cells tree
43  ViewCell *mViewCell;
44
45  // input parameter is the render budget for the PrVs
46  float mRenderBudget;
47
48  /// some characteristic values could be here
49 
50};
51
52
53struct IndexedBoundingBox: public std::pair<int, AxisAlignedBox3>
54{
55        typedef std::pair<int, AxisAlignedBox3> IndexedBoundingBoxParent;
56
57        IndexedBoundingBox(int idx, const AxisAlignedBox3 &box): IndexedBoundingBoxParent(idx, box)
58        {
59
60        }
61};
62
63/**     Manages different higher order operations on the view cells.
64*/
65class ViewCellsManager
66{
67public:
68        struct PvsStatistics
69        {
70                int minPvs;
71                int maxPvs;
72                float avgPvs;
73                int viewcells;
74  };
75
76        /// view cell container types
77        enum {BSP, KD, VSP_KD, VSP_BSP};
78 
79        /// view cells evaluation type
80        enum {PER_OBJECT, PER_TRIANGLE};
81
82        /** Constructor taking the initial and construction samples.
83                @param initialSamples the maximal number of samples used for creating the hierarchy
84                of view cells
85                @param constructionSamples the maximal number of samples used for construction
86        */
87        ViewCellsManager(const int initialSamples, const int constructionSamples);
88
89        ViewCellsManager();
90
91        virtual ~ViewCellsManager();
92
93        /** Constructs view cells container taking a preprocessor
94                @returns the output rays (if not null)
95        */
96        int Construct(Preprocessor *preprocessor, VssRayContainer *outRays = NULL);
97
98        /** Constructs view cell container with a given number of samples.
99        */
100        virtual int ConstructSubdivision(const ObjectContainer &objects,
101                                                  const VssRayContainer &rays) = 0;
102
103        /** Computes sample contributions of the rays to the view cells PVS.
104       
105                @param rays bundle of rays used to find intersections with view cells and
106                adding the contribution
107                @param addRays true if rays should be added to the PVSs of the viewcells they
108                intersect
109                @param storeViewCells true if view cells should be stored in the ray
110        */
111        float ComputeSampleContributions(const VssRayContainer &rays,
112                                                                   const bool addContributions,
113                                                                   const bool storeViewCells);
114
115        /** Add sample contributions to the viewcells they intersect */
116        void AddSampleContributions(const VssRayContainer &rays);
117 
118
119        /** Computes sample contribution of a simgle ray to the view cells PVS.
120                @param ray finds intersections with view cells and holds the contribution
121                @param castRay true if ray should be cast to gain the information, false if ray
122                is already holding the information and need not be recast.
123         
124                @returns number of sample contributions
125        */
126        virtual float ComputeSampleContributions(VssRay &ray,
127                                                                                         const bool addRays,
128                                                                                         const bool storeViewCells);
129
130        virtual void AddSampleContributions(VssRay &ray);
131
132        /** Prints out statistics of the view cells.
133        */
134        virtual void PrintStatistics(ostream &s) const;
135
136        /** Post processes view cells givemŽa number of rays.
137        */
138        virtual int PostProcess(const ObjectContainer &objects,
139                                                        const VssRayContainer &rays) = 0;
140
141        /** Show visualization of the view cells.
142        */
143        virtual void Visualize(const ObjectContainer &objects,
144                                                   const VssRayContainer &sampleRays) = 0;
145
146        /** type of the view cell container.
147        */
148        virtual int GetType() const = 0;
149
150        /** Load the input viewcells. The input viewcells should be given as a collection
151                of meshes. Each mesh is assume to form a bounded polyhedron defining the interior of
152                the viewcell. The method then builds a BSP tree of these view cells.
153               
154                @param filename file to load
155                @return true on success
156    */
157    virtual bool LoadViewCellsGeometry(const string filename);
158
159       
160        /** Constructs view cell from base triangle. The ViewCell is extruded along the normal vector.
161                @param the base triangle
162                @param the height of the newly created view cell
163        */
164        ViewCell *ExtrudeViewCell(const Triangle3 &baseTri, const float height) const;
165
166        /** Merges two view cells.
167                @note the piercing rays of the front and back will be ordered   
168                @returns new view cell based on the merging.
169        */
170        ViewCellInterior *MergeViewCells(ViewCell *front, ViewCell *back) const;
171
172        /** Merges a container of view cells.
173                @returns new view cell based on the merging.
174        */
175        ViewCellInterior *MergeViewCells(ViewCellContainer &children) const;
176       
177        /** Generates view cell of type specified by this manager
178        */
179        virtual ViewCell *GenerateViewCell(Mesh *mesh = NULL) const = 0;
180
181        /** Adds a new view cell to the list of predefined view cells.
182        */
183        void AddViewCell(ViewCell *viewCell);
184
185        /** Derive view cells from objects.
186        */
187        void DeriveViewCells(const ObjectContainer &objects,
188                                                 ViewCellContainer &viewCells,
189                                                 const int maxViewCells) const;
190
191        /** Sets maximal number of samples used for the
192                construction of the view cells.
193        */
194        void SetVisualizationSamples(const int visSamples);
195
196        /** Sets maximal number of samples used for the construction of the view cells.
197        */
198        void SetConstructionSamples(const int constructionSamples);
199
200        /** Sets maximal number of samples used for the visualization of the view cells.
201        */
202        void SetInitialSamples(const int initialSamples);
203
204        /** Sets maximal number of samples used for the post processing of the view cells.
205        */
206        void SetPostProcessSamples(const int postProcessingSamples);
207
208        /** See set.
209        */
210        int GetVisualizationSamples() const;
211
212        /** See set.
213        */
214        int GetConstructionSamples() const;
215
216        /** See set.
217        */
218        int GetPostProcessSamples() const;
219
220        /** Returns true if view cells wer already constructed.
221        */
222        virtual bool ViewCellsConstructed() const = 0;
223
224        /** cast line segment to get a list of unique viewcells which are intersected
225                by this line segment
226        */
227 
228        virtual int CastLineSegment(const Vector3 &origin,
229                                                          const Vector3 &termination,
230                                                          ViewCellContainer &viewcells
231                                                          ) = 0;
232
233        virtual void GetPvsStatistics(PvsStatistics &stat);
234
235        virtual void GetPrVS(const Vector3 &viewPoint, PrVs &prvs);
236 
237        /** Get a viewcell containing the specified point
238                @param active if the active or elementary view cell should be returned.
239        */
240        virtual ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const = 0;
241 
242        virtual void PrintPvsStatistics(ostream &s);
243
244        /** Updates pvs of the view cell hierarchy if necessary.
245        */
246        void UpdatePvs();
247
248        /** Returns probability that view point lies in one view cell.
249        */
250        virtual float GetProbability(ViewCell *viewCell) = 0;
251
252        /** Returns render cost of a single view cell given the render cost of an object.
253        */
254        float GetRendercost(ViewCell *viewCell) const;
255
256        /** Returns reference to container of loaded / generated view cells.
257        */
258        ViewCellContainer &GetViewCells();
259
260        /** Helper function used to split ray sets uniformly
261                into one that is currently used and the other that
262                is saved for later processing.
263                @param sourceRays the input ray set
264                @param maxSize the maximal number of rays that will be used
265                @param usedRays returns the used ray set
266                @param savedRays if not null, returns the saved ray set
267        */
268        void GetRaySets(const VssRayContainer &sourceRays,
269                                        const int maxSize,
270                                        VssRayContainer &usedRays,
271                                        VssRayContainer *savedRays = NULL) const;
272       
273        /** Returns accumulated area of all view cells.
274        */
275        float GetAccVcArea();
276
277        /** Returns area of one view cell.
278        */
279        virtual float GetArea(ViewCell *viewCell) const;
280
281        /** Returns volume of view cell.
282        */
283        virtual float GetVolume(ViewCell *viewCell) const;
284
285        /** Sets the current renderer mainly for view cells statistics.
286        */
287        void SetRenderer(Renderer *renderer);
288
289        /** Computes a (random) view point in the valid view space.
290                @returns true if valid view point was found
291        */
292        virtual bool GetViewPoint(Vector3 &viewPoint) const;
293
294        /** Returns true if this view point is in the valid view space.
295        */
296        virtual bool ViewPointValid(const Vector3 &viewPoint) const;
297
298        /** Sets a view space boundary.
299        */
300        void SetViewSpaceBox(const AxisAlignedBox3 &box);
301
302        AxisAlignedBox3 GetViewSpaceBox() const;
303
304        /** Creates mesh for this view cell.
305        */
306        virtual void CreateMesh(ViewCell *vc) = NULL;
307
308        /** Writes view cells to disc.
309        */
310        virtual bool ExportViewCells(const string filename, const bool exportPvs);
311
312        /** Casts beam to collect view cells.
313        */
314        virtual int CastBeam(Beam &beam);
315
316        /** Checks if view cell is considered as valid.
317        */
318        virtual bool CheckValidity(ViewCell *vc,
319                                                           int minPvsSize,
320                                                           int maxPvsSize) const;
321
322       
323        /** Sets validity of view cell
324        */
325        virtual void SetValidity(ViewCell *vc,
326                                                         int minPvsSize,
327                                                         int maxPvsSize) const;
328
329        /** sets validy of all viewcells
330        */
331        virtual void SetValidity(int minPvsSize,
332                                                         int maxPvsSize) const;
333
334
335        /** set valid viewcells in the range of pvs. sorts the viewcells
336          according to the pvs and then pickups those in the ranges
337          */
338        void SetValidityPercentage(const float minValid, const float maxValid);
339
340    int CountValidViewcells() const;
341
342        /** Returns maximal allowed pvs size.
343        */
344        int GetMaxPvsSize() const;
345
346        /** Returns maximal allowed pvs size.
347        */
348        int GetMinPvsSize() const;
349
350        /** Returns maximal ratio. i.e., currentPVs / maxPvs,
351                where pvs is still considered valid.
352        */
353        float GetMaxPvsRatio() const;
354
355        /** Exports view cell geometry.
356        */
357        virtual void ExportViewCellGeometry(Exporter *exporter,
358                                                                                ViewCell *vc,
359                                                                                const Plane3 *clipPlane = NULL) const = 0;
360
361        /** Brings the view cells into their final state, computes meshes and volume.
362        */
363        virtual void FinalizeViewCells(const bool createMesh);
364
365        /** Evaluates statistics values on view cells.
366        */
367        void EvaluateRenderStatistics(float &totalRenderCost,
368                                                                  float &expectedRenderCost,
369                                                                  float &deviation,
370                                                                  float &variance,
371                                                                  int &totalPvs,
372                                                                  float &avgRenderCost);
373
374
375        /** Returns hierarchy of the view cells.
376        */
377        ViewCellsTree *GetViewCellsTree();
378
379        virtual void CollectMergeCandidates(const VssRayContainer &rays,
380                                                                                vector<MergeCandidate> &candidates) = 0;
381
382        void CollectViewCells(const int n);
383
384        /** Returns true if this (logical) view cell is equal to a spatial node.
385        */
386        virtual bool EqualToSpatialNode(ViewCell *viewCell) const;
387
388        /** Sets current view cells set to active, i.e., the sampling is done in this view cell set.
389        */
390        void SetViewCellsActive();
391
392        /** Evaluates worth of current view cell hierarchy.
393        */
394        void EvalViewCellPartition(Preprocessor *preprocessor);
395
396        /** Sets maximal size of a view cell filter.
397        */
398        void SetMaxFilterSize(const int size);
399
400        /** Returns maximal filter size.
401        */
402        int GetMaxFilterSize() const;
403
404        /** Deletes interior nodes from the tree which have negative merge cost set (local merge).
405        */ 
406        void DeleteLocalMergeTree(ViewCell *vc) const;
407 
408        /** Evaluautes histogram for a given number of view cells.
409        */
410        void EvalViewCellHistogram(const string filename, const int nViewCells);
411
412        /** Evaluautes histogram for a given number of view cells.
413        */
414        void EvalViewCellHistogramForPvsSize(const string filename, const int nViewCells);
415
416        /** Evaluates the render cost of a view cell.
417        */
418        float EvalRenderCost(Intersectable *obj) const;
419
420    void
421        ApplyFilter(KdTree *kdTree,
422                                const float viewSpaceFilterSize,
423                                const float spatialFilterSize
424                                );
425
426  void
427  ApplySpatialFilter(
428                                         KdTree *kdTree,
429                                         const float spatialFilterSize,
430                                         ObjectPvs &pvs
431                                         );
432       
433        /** Returns bounding box of a view cell.
434        */
435        AxisAlignedBox3 GetViewCellBox(ViewCell *vc);
436
437        /** Exports bounding boxes of objects to file.
438        */
439        bool ExportBoundingBoxes(const string filename, const ObjectContainer &objects) const;
440
441        /** Load the bounding boxes into the container.
442        */
443        bool LoadBoundingBoxes(const string filename, IndexedBoundingBoxContainer &boxes) const;
444
445  bool GetExportPvs() const {
446        return mExportPvs;
447  }
448
449        /** Loads view cells from file. The view cells manager is created with
450                respect to the loaded view cells.
451
452                @returns the view cells manager if loading was successful, false otherwise
453        */
454        static ViewCellsManager *LoadViewCells(const string filename, ObjectContainer *objects);
455
456  float GetFilterWidth() {
457        return Magnitude(mViewSpaceBox.Size())*mFilterWidth;
458  }
459 
460protected:
461    void
462        ApplyFilter(ViewCell *viewCell,
463                                KdTree *kdTree,
464                                const float viewSpaceFilterSize,
465                                const float spatialFilterSize,
466                                ObjectPvs &pvs
467                                );
468
469 
470        /** Returns the bounding box of filter width.
471        */
472        AxisAlignedBox3 GetFilterBBox(const Vector3 &viewPoint, const float width) const;
473
474        /** Intersects box with the tree and returns the number of intersected boxes.
475                @returns number of view cells found
476        */
477        virtual int ComputeBoxIntersections(const AxisAlignedBox3 &box,
478                                                                                ViewCellContainer &viewCells) const;
479
480        /** Tests the visibility filter functionality.
481        */
482        virtual void TestFilter(const ObjectContainer &objects) {};
483
484        /**
485                if the view cells tree was already constructed or not.
486        */
487        bool ViewCellsTreeConstructed() const;
488
489        int CastPassSamples(const int samplesPerPass,
490                                                const int sampleType,
491                                                VssRayContainer &vssRays) const;
492
493        void ParseEnvironment();
494
495        /** Creates unique view cell ids.
496        */
497        void CreateUniqueViewCellIds();
498
499        /** Finalizes, i.e., creates mesh, volume, area etc. for the view cell.
500        */
501        virtual void Finalize(ViewCell *viewCell, const bool createMesh);
502
503        /** Recollects view cells and resets statistics.
504        */
505        void ResetViewCells();
506       
507        /** Collects the view cells in the view cell container.
508        */
509        virtual void CollectViewCells() = 0;
510       
511        /** Evaluates view cells statistics and stores it in
512                mViewCellsStatistics.
513        */
514        void EvaluateViewCellsStats();
515
516        //-- helper functions for view cell visualization
517
518        /** Exports the view cell partition.
519        */
520        void ExportViewCellsForViz(Exporter *exporter) const;
521
522        /** Sets exporter color.
523        */
524        virtual void ExportColor(Exporter *exporter, ViewCell *vc) const = 0;
525
526
527        virtual float GetViewSpaceVolume();
528       
529        /** Creates meshes from the view cells.
530        */
531        void CreateViewCellMeshes();
532
533        /** Takes different measures to prepares the view cells after loading them from disc.
534        */
535        virtual void PrepareLoadedViewCells() {};
536
537        /** Constructs local view cell merge hierarchy.
538        */
539        ViewCell *ConstructLocalMergeTree(ViewCell *currentViewCell,
540                                                                          const ViewCellContainer &viewCells);
541
542        /** Constructs local view cell merge hierarchy based solely on similarity with the
543                current viewcell
544        */
545        ViewCell *ConstructLocalMergeTree2(ViewCell *currentViewCell,
546                                                                           const ViewCellContainer &viewCells);
547 
548
549        /** Creates clip plane for visualization.
550        */
551        void CreateClipPlane();
552
553        /** Updates pvs of all view cells for statistical evaluation after some more sampling
554        */
555        virtual void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs) = 0;
556
557
558
559        /// if bounding boxes should also be exported
560        bool mExportBboxesForPvs;
561               
562
563        Plane3 mClipPlane;
564
565        bool mUseClipPlaneForViz;
566
567
568        /// Renders the view cells.
569        Renderer *mRenderer;
570
571        /// Loaded view cells
572        ViewCellContainer mViewCells;
573
574        ViewCellsTree *mViewCellsTree;
575
576        bool mPruneEmptyViewCells;
577
578        bool mViewCellPvsIsUpdated;
579        /// maximum number of samples taken for construction of the view cells
580        int mConstructionSamples;
581        int mSamplesPerPass;
582        int mInitialSamples;
583        int mPostProcessSamples;
584        int mVisualizationSamples;
585
586        float mTotalAreaValid;
587        float mTotalArea;
588
589        int mMaxPvsSize;
590        int mMinPvsSize;
591        float mMaxPvsRatio;
592
593        int mSamplingType;
594        int mEvaluationSamplingType;
595        int mNumActiveViewCells;
596        bool mCompressViewCells;
597
598        ViewCellsStatistics mCurrentViewCellsStats;
599        /// the scene bounding box
600        AxisAlignedBox3 mViewSpaceBox;
601        /// holds the view cell meshes
602        MeshContainer mMeshContainer;
603        /// if view cells should be exported
604        bool mExportViewCells;
605
606        //bool mMarchTree);
607        bool mOnlyValidViewCells;
608
609        /// if rays should be used to collect merge candidates
610        bool mUseRaysForMerge;
611        /// merge the view cells?
612        bool mMergeViewCells;
613
614        /// the width of the box filter
615        float mFilterWidth;
616        int mMaxFilterSize;
617
618        //-- visualization options
619       
620        /// color code for view cells
621        int mColorCode;
622        bool mExportGeometry;
623        bool mExportRays;
624
625        bool mViewCellsFinished;
626
627        bool mEvaluateViewCells;
628
629        bool mShowVisualization;
630
631        // HACK in order to detect empty view cells
632        void CollectEmptyViewCells();
633        void TestEmptyViewCells(const ObjectContainer &obj);
634
635        ViewCellContainer mEmptyViewCells;
636
637        int mRenderCostEvaluationType;
638
639        /// if pvs should be exported with view cells
640        bool mExportPvs;
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);
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);
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);
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        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);
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);
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);
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.