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

Revision 1021, 27.4 KB checked in by mattausch, 18 years ago (diff)

added view cells manager for vsposptree

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