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

Revision 859, 24.6 KB checked in by bittner, 18 years ago (diff)

apply filter routine for working modules

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