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

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