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

Revision 871, 24.9 KB checked in by bittner, 18 years ago (diff)

RenderSampler?

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        */
239        virtual ViewCell *GetViewCell(const Vector3 &point) const = 0;
240 
241        virtual void PrintPvsStatistics(ostream &s);
242
243        /** Updates pvs of the view cell hierarchy if necessary.
244        */
245        void UpdatePvs();
246
247        /** Returns probability that view point lies in one view cell.
248        */
249        virtual float GetProbability(ViewCell *viewCell) = 0;
250
251        /** Returns render cost of a single view cell given the render cost of an object.
252        */
253        float GetRendercost(ViewCell *viewCell) const;
254
255        /** Returns reference to container of loaded / generated view cells.
256        */
257        ViewCellContainer &GetViewCells();
258
259        /** Helper function used to split ray sets uniformly
260                into one that is currently used and the other that
261                is saved for later processing.
262                @param sourceRays the input ray set
263                @param maxSize the maximal number of rays that will be used
264                @param usedRays returns the used ray set
265                @param savedRays if not null, returns the saved ray set
266        */
267        void GetRaySets(const VssRayContainer &sourceRays,
268                                        const int maxSize,
269                                        VssRayContainer &usedRays,
270                                        VssRayContainer *savedRays = NULL) const;
271       
272        /** Returns accumulated area of all view cells.
273        */
274        float GetAccVcArea();
275
276        /** Returns area of one view cell.
277        */
278        virtual float GetArea(ViewCell *viewCell) const;
279
280        /** Returns volume of view cell.
281        */
282        virtual float GetVolume(ViewCell *viewCell) const;
283
284        /** Sets the current renderer mainly for view cells statistics.
285        */
286        void SetRenderer(Renderer *renderer);
287
288        /** Computes a (random) view point in the valid view space.
289                @returns true if valid view point was found
290        */
291        virtual bool GetViewPoint(Vector3 &viewPoint) const;
292
293        /** Returns true if this view point is in the valid view space.
294        */
295        virtual bool ViewPointValid(const Vector3 &viewPoint) const;
296
297        /** Sets a view space boundary.
298        */
299        void SetViewSpaceBox(const AxisAlignedBox3 &box);
300
301        AxisAlignedBox3 GetViewSpaceBox() const;
302
303        /** Creates mesh for this view cell.
304        */
305        virtual void CreateMesh(ViewCell *vc) = NULL;
306
307        /** Writes view cells to disc.
308        */
309        virtual bool ExportViewCells(const string filename, const bool exportPvs);
310
311        /** Casts beam to collect view cells.
312        */
313        virtual int CastBeam(Beam &beam);
314
315        /** Checks if view cell is considered as valid.
316        */
317        virtual bool CheckValidity(ViewCell *vc,
318                                                           int minPvsSize,
319                                                           int maxPvsSize) const;
320
321       
322        /** Sets validity of view cell
323        */
324        virtual void SetValidity(ViewCell *vc,
325                                                         int minPvsSize,
326                                                         int maxPvsSize) const;
327
328        /** sets validy of all viewcells
329        */
330        virtual void SetValidity(int minPvsSize,
331                                                         int maxPvsSize) const;
332
333
334        /** set valid viewcells in the range of pvs. sorts the viewcells
335          according to the pvs and then pickups those in the ranges
336          */
337        void SetValidityPercentage(const float minValid, const float maxValid);
338
339    int CountValidViewcells() const;
340
341        /** Returns maximal allowed pvs size.
342        */
343        int GetMaxPvsSize() const;
344
345        /** Returns maximal allowed pvs size.
346        */
347        int GetMinPvsSize() const;
348
349        /** Returns maximal ratio. i.e., currentPVs / maxPvs,
350                where pvs is still considered valid.
351        */
352        float GetMaxPvsRatio() const;
353
354        /** Exports view cell geometry.
355        */
356        virtual void ExportViewCellGeometry(Exporter *exporter,
357                                                                                ViewCell *vc,
358                                                                                const Plane3 *clipPlane = NULL) const = 0;
359
360        /** Brings the view cells into their final state, computes meshes and volume.
361        */
362        virtual void FinalizeViewCells(const bool createMesh);
363
364        /** Evaluates statistics values on view cells.
365        */
366        void EvaluateRenderStatistics(float &totalRenderCost,
367                                                                  float &expectedRenderCost,
368                                                                  float &deviation,
369                                                                  float &variance,
370                                                                  int &totalPvs,
371                                                                  float &avgRenderCost);
372
373
374        /** Returns hierarchy of the view cells.
375        */
376        ViewCellsTree *GetViewCellsTree();
377
378        virtual void CollectMergeCandidates(const VssRayContainer &rays,
379                                                                                vector<MergeCandidate> &candidates) = 0;
380
381        void CollectViewCells(const int n);
382
383        /** Returns true if this (logical) view cell is equal to a spatial node.
384        */
385        virtual bool EqualToSpatialNode(ViewCell *viewCell) const;
386
387        /** Sets current view cells set to active, i.e., the sampling is done in this view cell set.
388        */
389        void SetViewCellsActive();
390
391        /** Evaluates worth of current view cell hierarchy.
392        */
393        void EvalViewCellPartition(Preprocessor *preprocessor);
394
395        /** Sets maximal size of a view cell filter.
396        */
397        void SetMaxFilterSize(const int size);
398
399        /** Returns maximal filter size.
400        */
401        int GetMaxFilterSize() const;
402
403        /** Deletes interior nodes from the tree which have negative merge cost set (local merge).
404        */ 
405        void DeleteLocalMergeTree(ViewCell *vc) const;
406 
407        /** Evaluautes histogram for a given number of view cells.
408        */
409        void EvalViewCellHistogram(const string filename, const int nViewCells);
410
411        /** Evaluautes histogram for a given number of view cells.
412        */
413        void EvalViewCellHistogramForPvsSize(const string filename, const int nViewCells);
414
415        /** Evaluates the render cost of a view cell.
416        */
417        float EvalRenderCost(Intersectable *obj) const;
418
419    void
420        ApplyFilter(KdTree *kdTree,
421                                const float viewSpaceFilterSize,
422                                const float spatialFilterSize
423                                );
424
425        /** Returns bounding box of a view cell.
426        */
427        AxisAlignedBox3 GetViewCellBox(ViewCell *vc);
428
429        /** Exports bounding boxes of objects to file.
430        */
431        bool ExportBoundingBoxes(const string filename, const ObjectContainer &objects) const;
432
433        /** Load the bounding boxes into the container.
434        */
435        bool LoadBoundingBoxes(const string filename, IndexedBoundingBoxContainer &boxes) const;
436
437  bool GetExportPvs() const {
438        return mExportPvs;
439  }
440
441        /** Loads view cells from file. The view cells manager is created with
442                respect to the loaded view cells.
443
444                @returns the view cells manager if loading was successful, false otherwise
445        */
446        static ViewCellsManager *LoadViewCells(const string filename, ObjectContainer *objects);
447
448protected:
449    void
450        ApplyFilter(ViewCell *viewCell,
451                                KdTree *kdTree,
452                                const float viewSpaceFilterSize,
453                                const float spatialFilterSize,
454                                ObjectPvs &pvs
455                                );
456
457 
458        /** Returns the bounding box of filter width.
459        */
460        AxisAlignedBox3 GetFilterBBox(const Vector3 &viewPoint, const float width) const;
461
462        /** Intersects box with the tree and returns the number of intersected boxes.
463                @returns number of view cells found
464        */
465        virtual int ComputeBoxIntersections(const AxisAlignedBox3 &box,
466                                                                                ViewCellContainer &viewCells) const;
467
468        virtual void TestFilter(const ObjectContainer &objects) {};
469
470        /**
471                if the view cells tree was already constructed or not.
472        */
473        bool ViewCellsTreeConstructed() const;
474
475        int CastPassSamples(const int samplesPerPass,
476                                                const int sampleType,
477                                                VssRayContainer &vssRays) const;
478
479        void ParseEnvironment();
480
481        /** Creates unique view cell ids.
482        */
483        void CreateUniqueViewCellIds();
484
485        /** Finalizes, i.e., creates mesh, volume, area etc. for the view cell.
486        */
487        virtual void Finalize(ViewCell *viewCell, const bool createMesh);
488
489        /** Recollects view cells and resets statistics.
490        */
491        void ResetViewCells();
492       
493        /** Collects the view cells in the view cell container.
494        */
495        virtual void CollectViewCells() = 0;
496       
497        /** Evaluates view cells statistics and stores it in
498                mViewCellsStatistics.
499        */
500        void EvaluateViewCellsStats();
501
502        //-- helper functions for view cell visualization
503
504        /** Exports the view cell partition.
505        */
506        void ExportViewCellsForViz(Exporter *exporter) const;
507
508        /** Sets exporter color.
509        */
510        virtual void ExportColor(Exporter *exporter, ViewCell *vc) const = 0;
511
512
513        virtual float GetViewSpaceVolume();
514       
515        /** Creates meshes from the view cells.
516        */
517        void CreateViewCellMeshes();
518
519        /** Takes different measures to prepares the view cells after loading them from disc.
520        */
521        virtual void PrepareLoadedViewCells() {};
522
523        /** Constructs local view cell merge hierarchy.
524        */
525        ViewCell *ConstructLocalMergeTree(ViewCell *currentViewCell,
526                                                                          const ViewCellContainer &viewCells);
527
528        /** Constructs local view cell merge hierarchy based solely on similarity with the
529                current viewcell
530        */
531        ViewCell *ConstructLocalMergeTree2(ViewCell *currentViewCell,
532                                                                           const ViewCellContainer &viewCells);
533 
534
535        /** Creates clip plane for visualization.
536        */
537        void CreateClipPlane();
538
539        /** Updates pvs of all view cells for statistical evaluation after some more sampling
540        */
541        virtual void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs) = 0;
542
543
544
545        /// if bounding boxes should also be exported
546        bool mExportBboxesForPvs;
547               
548
549        Plane3 mClipPlane;
550
551        bool mUseClipPlaneForViz;
552
553
554        /// Renders the view cells.
555        Renderer *mRenderer;
556
557        /// Loaded view cells
558        ViewCellContainer mViewCells;
559
560        ViewCellsTree *mViewCellsTree;
561
562        bool mPruneEmptyViewCells;
563
564        bool mViewCellPvsIsUpdated;
565        /// maximum number of samples taken for construction of the view cells
566        int mConstructionSamples;
567        int mSamplesPerPass;
568        int mInitialSamples;
569        int mPostProcessSamples;
570        int mVisualizationSamples;
571
572        float mTotalAreaValid;
573        float mTotalArea;
574
575        int mMaxPvsSize;
576        int mMinPvsSize;
577        float mMaxPvsRatio;
578
579        int mSamplingType;
580        int mEvaluationSamplingType;
581        int mNumActiveViewCells;
582        bool mCompressViewCells;
583
584        ViewCellsStatistics mCurrentViewCellsStats;
585        /// the scene bounding box
586        AxisAlignedBox3 mViewSpaceBox;
587        /// holds the view cell meshes
588        MeshContainer mMeshContainer;
589        /// if view cells should be exported
590        bool mExportViewCells;
591
592        //bool mMarchTree);
593        bool mOnlyValidViewCells;
594
595        /// if rays should be used to collect merge candidates
596        bool mUseRaysForMerge;
597        /// merge the view cells?
598        bool mMergeViewCells;
599
600        /// the width of the box filter
601        float mFilterWidth;
602        int mMaxFilterSize;
603
604        //-- visualization options
605       
606        /// color code for view cells
607        int mColorCode;
608        bool mExportGeometry;
609        bool mExportRays;
610
611        bool mViewCellsFinished;
612
613        bool mEvaluateViewCells;
614
615        bool mShowVisualization;
616
617        // HACK in order to detect empty view cells
618        void CollectEmptyViewCells();
619        void TestEmptyViewCells(const ObjectContainer &obj);
620
621        ViewCellContainer mEmptyViewCells;
622
623        int mRenderCostEvaluationType;
624
625        /// if pvs should be exported with view cells
626        bool mExportPvs;
627};
628
629
630
631/**
632        Manages different higher order operations on the view cells.
633*/
634class BspViewCellsManager: public ViewCellsManager
635{
636
637public:
638        /** Constructor taking the bsp tree and the number of samples
639                used to construct the bsp tree.
640        */
641        BspViewCellsManager(BspTree *tree);
642
643        ~BspViewCellsManager();
644
645        int ConstructSubdivision(const ObjectContainer &objects,
646                                  const VssRayContainer &rays);
647
648        int PostProcess(const ObjectContainer &objects,
649                                        const VssRayContainer &rays);
650
651        void Visualize(const ObjectContainer &objects,
652                                   const VssRayContainer &sampleRays);
653
654        int GetType() const;
655       
656        ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
657
658        bool ViewCellsConstructed() const;
659
660        //void PrintStatistics(ostream &s) const;
661
662        int CastLineSegment(const Vector3 &origin,
663                                                const Vector3 &termination,
664                                                ViewCellContainer &viewcells);
665       
666        float GetProbability(ViewCell *viewCell);
667       
668
669        /** Get a viewcell containing the specified point */
670        ViewCell *GetViewCell(const Vector3 &point) const;
671
672        void CreateMesh(ViewCell *vc);
673
674        void ExportViewCellGeometry(Exporter *exporter,
675                                                                ViewCell *vc,
676                                                                const Plane3 *clipPlane = NULL) const;
677       
678        void CollectMergeCandidates(const VssRayContainer &rays,
679                                                                vector<MergeCandidate> &candidates);
680
681        void Finalize(ViewCell *viewCell, const bool createMesh);
682
683        bool ExportViewCells(const string filename, const bool exportPvs);
684
685        /** Constructs merge hierarchy which corresponds to the spatial hierarchy.
686        */
687        ViewCell *ConstructSpatialMergeTree(BspNode *root);
688
689        /** Updates the pvs in the view cells tree.
690        */
691        void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs);
692
693
694protected:
695
696
697        void CollectViewCells();
698
699        void ExportColor(Exporter *exporter, ViewCell *vc) const;
700       
701        /// the BSP tree.
702        BspTree *mBspTree;
703       
704        vector<BspRay *> mBspRays;
705
706private:
707
708        /** Exports visualization of the BSP splits.
709        */
710        void ExportSplits(const ObjectContainer &objects);
711
712        /** Exports visualization of the BSP PVS.
713        */
714        void ExportBspPvs(const ObjectContainer &objects);
715
716        void TestSubdivision();
717};
718
719/**
720        Manages different higher order operations on the KD type view cells.
721*/
722class KdViewCellsManager: public ViewCellsManager
723{
724
725public:
726
727        KdViewCellsManager(KdTree *tree);
728
729        int ConstructSubdivision(const ObjectContainer &objects,
730                                  const VssRayContainer &rays);
731
732        int CastLineSegment(const Vector3 &origin,
733                                                const Vector3 &termination,
734                                                ViewCellContainer &viewcells);
735
736        int PostProcess(const ObjectContainer &objects,
737                                        const VssRayContainer &rays);
738
739        void Visualize(const ObjectContainer &objects,
740                                   const VssRayContainer &sampleRays);
741
742        int GetType() const;
743
744        bool ViewCellsConstructed() const;
745
746        ViewCell *GenerateViewCell(Mesh *mesh) const;
747
748        /** Prints out statistics of this approach.
749        */
750        //  virtual void PrintStatistics(ostream &s) const;
751        ViewCell *GetViewCell(const Vector3 &point) const { return NULL; }
752
753        float GetProbability(ViewCell *viewCell);
754       
755
756        void CreateMesh(ViewCell *vc);
757
758        void ExportViewCellGeometry(Exporter *exporter,
759                                                                ViewCell *vc,
760                                                                const Plane3 *clipPlane = NULL) const;
761
762        void CollectMergeCandidates(const VssRayContainer &rays,
763                                                                vector<MergeCandidate> &candidates);
764
765
766protected:
767
768        virtual void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs) {};
769        /** Collects view cells from a hierarchy.
770        */
771        void CollectViewCells();
772
773        KdNode *GetNodeForPvs(KdLeaf *leaf);
774
775        void ExportColor(Exporter *exporter, ViewCell *vc) const;
776
777
778        /// the BSP tree.
779        KdTree *mKdTree;
780
781        /// depth of the KD tree nodes with represent the view cells
782        int mKdPvsDepth;
783};
784
785/**
786        Manages different higher order operations on the view cells
787        for vsp kd tree view cells.
788*/
789class VspKdViewCellsManager: public ViewCellsManager
790{
791
792public:
793
794        VspKdViewCellsManager(VspKdTree *vspKdTree);
795
796        int ConstructSubdivision(const ObjectContainer &objects,
797                                  const VssRayContainer &rays);
798
799
800        int PostProcess(const ObjectContainer &objects,
801                                        const VssRayContainer &rays);
802
803        void Visualize(const ObjectContainer &objects,
804                                   const VssRayContainer &sampleRays);
805
806        int GetType() const;
807       
808        bool ViewCellsConstructed() const;
809
810        //virtual void PrintStatistics(ostream &s) const;
811
812        ViewCell *GenerateViewCell(Mesh *mesh) const;
813
814
815    int CastLineSegment(const Vector3 &origin,
816                                                const Vector3 &termination,
817                                                ViewCellContainer &viewcells);
818
819        ViewCell *GetViewCell(const Vector3 &point) const { return NULL; }
820
821        float GetProbability(ViewCell *viewCell);
822
823
824        void CreateMesh(ViewCell *vc);
825
826        void ExportViewCellGeometry(Exporter *exporter,
827                                                                ViewCell *vc,
828                                                                const Plane3 *clipPlane = NULL) const;
829
830        void CollectMergeCandidates(const VssRayContainer &rays, vector<MergeCandidate> &candidates);
831
832        virtual void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs) {};
833protected:
834
835        void ExportLeaves(const ObjectContainer &objects,
836                                          const VssRayContainer &sampleRays);
837
838        void CollectViewCells();
839
840        void ExportColor(Exporter *exporter, ViewCell *vc) const;
841
842
843
844        /// the BSP tree.
845        VspKdTree *mVspKdTree;
846};
847
848
849
850/**
851        Manages different higher order operations on the view cells.
852*/
853class VspBspViewCellsManager: public ViewCellsManager
854{
855
856public:
857
858        VspBspViewCellsManager(VspBspTree *tree);
859        ~VspBspViewCellsManager();
860
861        int ConstructSubdivision(const ObjectContainer &objects,
862                                  const VssRayContainer &rays);
863
864        int PostProcess(const ObjectContainer &objects,
865                                        const VssRayContainer &rays);
866
867        void Visualize(const ObjectContainer &objects,
868                                   const VssRayContainer &sampleRays);
869
870        int GetType() const;
871       
872        ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
873
874        bool ViewCellsConstructed() const;
875
876       
877        int CastLineSegment(const Vector3 &origin,
878                                                const Vector3 &termination,
879                                                ViewCellContainer &viewcells);
880
881        float GetProbability(ViewCell *viewCell);
882       
883        ViewCell *GetViewCell(const Vector3 &point) const;
884
885        bool GetViewPoint(Vector3 &viewPoint) const;
886
887        bool ViewPointValid(const Vector3 &viewPoint) const;
888
889        void CreateMesh(ViewCell *vc);
890
891        bool ExportViewCells(const string filename, const bool exportPvs);
892
893        int CastBeam(Beam &beam);
894
895        void ExportViewCellGeometry(Exporter *exporter,
896                                                                ViewCell *vc,
897                                                                const Plane3 *clipPlane = NULL) const;
898
899        //float GetVolume(ViewCell *viewCell) const;
900
901        void Finalize(ViewCell *viewCell, const bool createMesh);
902
903        void CollectMergeCandidates(const VssRayContainer &rays, vector<MergeCandidate> &candidates);
904
905        /** Returns true if this view cell is equivavalent to a spatial node.
906        */
907        bool EqualToSpatialNode(ViewCell *viewCell) const;
908
909
910protected:
911
912        int ComputeBoxIntersections(const AxisAlignedBox3 &box, ViewCellContainer &viewCells) const;
913       
914        /** Returns node of the spatial hierarchy corresponding to the view cell
915                if such a node exists.
916        */
917        BspNode *GetSpatialNode(ViewCell *viewCell) const;
918
919        /** Merges the view cells.
920        */
921        void MergeViewCells(const VssRayContainer &rays,
922                                                const ObjectContainer &objects);
923       
924        void RefineViewCells(const VssRayContainer &rays, const ObjectContainer &objects);
925
926        void CollectViewCells();
927
928        /** Returns maximal depth difference of view cell
929                leaves in tree.
930        */
931        int GetMaxTreeDiff(ViewCell *vc) const;
932       
933
934        void ExportColor(Exporter *exporter, ViewCell *vc) const;
935
936        /** Prepare view cells for use after loading them from disc.
937        */
938        void PrepareLoadedViewCells();
939
940        /** Constructs merge hierarchy which corresponds to the spatial hierarchy.
941        */
942        ViewCell *ConstructSpatialMergeTree(BspNode *root);
943
944        void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs);
945
946
947        // HACK
948        void TestFilter(const ObjectContainer &objects);
949
950
951
952        /// the view space partition BSP tree.
953        VspBspTree *mVspBspTree;
954
955
956private:
957
958        /** Exports visualization of the BSP splits.
959        */
960        void ExportSplits(const ObjectContainer &objects,
961                                          const VssRayContainer &rays);
962
963        /** Exports visualization of the BSP PVS.
964        */
965        void ExportBspPvs(const ObjectContainer &objects,
966                                          const VssRayContainer &rays);
967
968        void TestSubdivision();
969};
970
971
972class ViewCellsManagerFactory
973{
974
975public:
976
977        ViewCellsManager *Create(const string mName);
978
979};
980
981}
982
983#endif
Note: See TracBrowser for help on using the repository browser.