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

Revision 1074, 27.6 KB checked in by mattausch, 18 years ago (diff)

wked on view space object space partition

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
562        /** Creates clip plane for visualization.
563        */
564        void CreateClipPlane();
565
566        /** Updates pvs of all view cells for statistical evaluation after some more sampling
567        */
568        virtual void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs) = 0;
569
570       
571        ////////////////////////////////////////////////
572
573        /// if bounding boxes should also be exported
574        bool mExportBboxesForPvs;
575               
576        //Environment *environment;
577        AxisAlignedPlane mClipPlane;
578
579        bool mUseClipPlaneForViz;
580
581
582        /// Renders the view cells.
583        Renderer *mRenderer;
584
585        /// Loaded view cells
586        ViewCellContainer mViewCells;
587        /// the corresponding view cell tree holding the logical description of view cells
588        ViewCellsTree *mViewCellsTree;
589        /// if empty view cells should be pruned (i.e., invalidated) from this point on
590        bool mPruneEmptyViewCells;
591
592        /// if the pvss in the view cell leaves and the interiors are up to date
593        bool mViewCellPvsIsUpdated;
594
595        /// maximum number of samples taken for construction of the view cells
596        int mConstructionSamples;
597        int mSamplesPerPass;
598        int mInitialSamples;
599        int mPostProcessSamples;
600        int mVisualizationSamples;
601
602        float mTotalAreaValid;
603        float mTotalArea;
604
605        int mMaxPvsSize;
606        int mMinPvsSize;
607        float mMaxPvsRatio;
608
609        int mSamplingType;
610        int mEvaluationSamplingType;
611        int mNumActiveViewCells;
612        bool mCompressViewCells;
613
614        /// holds the current view cell statistics
615        ViewCellsStatistics mCurrentViewCellsStats;
616        /// the scene bounding box
617        AxisAlignedBox3 mViewSpaceBox;
618       
619        /// if view cells should be exported
620        bool mExportViewCells;
621
622        // if only valid view cells should be considered for processing
623        bool mOnlyValidViewCells;
624
625        /// if rays should be used to collect merge candidates
626        bool mUseRaysForMerge;
627
628        /// if there should be an additional merge step after the subdivision
629        bool mMergeViewCells;
630
631        /// the width of the box filter
632        float mFilterWidth;
633        int mMaxFilterSize;
634
635        //-- visualization options
636       
637        /// color code for view cells visualization
638        int mColorCode;
639        bool mExportGeometry;
640        bool mExportRays;
641
642        bool mViewCellsFinished;
643
644        bool mEvaluateViewCells;
645
646        bool mShowVisualization;
647
648        // HACK in order to detect empty view cells
649        void CollectEmptyViewCells();
650        void TestEmptyViewCells(const ObjectContainer &obj);
651
652        ViewCellContainer mEmptyViewCells;
653
654        int mRenderCostEvaluationType;
655
656        /// if pvs should be exported with view cells
657        bool mExportPvs;
658};
659
660
661/**
662        Manages different higher order operations on the view cells.
663*/
664class BspViewCellsManager: public ViewCellsManager
665{
666
667public:
668        /** Constructor taking the bsp tree and the number of samples
669                used to construct the bsp tree.
670        */
671        BspViewCellsManager(BspTree *tree);
672
673        ~BspViewCellsManager();
674
675        int ConstructSubdivision(const ObjectContainer &objects,
676                                  const VssRayContainer &rays);
677
678        int PostProcess(const ObjectContainer &objects,
679                                        const VssRayContainer &rays);
680
681        void Visualize(const ObjectContainer &objects,
682                                   const VssRayContainer &sampleRays);
683
684        int GetType() const;
685       
686        ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
687
688        bool ViewCellsConstructed() const;
689
690        //void PrintStatistics(ostream &s) const;
691
692        int CastLineSegment(const Vector3 &origin,
693                                                const Vector3 &termination,
694                                                ViewCellContainer &viewcells);
695       
696        float GetProbability(ViewCell *viewCell);
697       
698
699        /** Get a viewcell containing the specified point
700        */
701        ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const;
702
703        void CreateMesh(ViewCell *vc);
704
705        void ExportViewCellGeometry(Exporter *exporter,
706                                                                ViewCell *vc,
707                                                                const AxisAlignedPlane *clipPlane = NULL) const;
708       
709        void CollectMergeCandidates(const VssRayContainer &rays,
710                                                                vector<MergeCandidate> &candidates);
711
712        void Finalize(ViewCell *viewCell, const bool createMesh);
713
714        bool ExportViewCells(const string filename, const bool exportPvs, const ObjectContainer &objects);
715
716        /** Constructs merge hierarchy which corresponds to the spatial hierarchy.
717        */
718        ViewCell *ConstructSpatialMergeTree(BspNode *root);
719
720        /** Updates the pvs in the view cells tree.
721        */
722        void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs);
723
724
725protected:
726
727        void CollectViewCells();
728
729       
730        /// the BSP tree.
731        BspTree *mBspTree;
732       
733        vector<BspRay *> mBspRays;
734
735private:
736
737        /** Exports visualization of the BSP splits.
738        */
739        void ExportSplits(const ObjectContainer &objects);
740
741        /** Exports visualization of the BSP PVS.
742        */
743        void ExportBspPvs(const ObjectContainer &objects);
744
745        /** test if subdivision is valid in terms of volume / area.
746        */
747        void TestSubdivision();
748};
749
750/**
751        Manages different higher order operations on the KD type view cells.
752*/
753class KdViewCellsManager: public ViewCellsManager
754{
755
756public:
757
758        KdViewCellsManager(KdTree *tree);
759
760        int ConstructSubdivision(const ObjectContainer &objects,
761                                  const VssRayContainer &rays);
762
763        int CastLineSegment(const Vector3 &origin,
764                                                const Vector3 &termination,
765                                                ViewCellContainer &viewcells);
766
767        int PostProcess(const ObjectContainer &objects,
768                                        const VssRayContainer &rays);
769
770        void Visualize(const ObjectContainer &objects,
771                                   const VssRayContainer &sampleRays);
772
773        int GetType() const;
774
775        bool ViewCellsConstructed() const;
776
777        ViewCell *GenerateViewCell(Mesh *mesh) const;
778
779        /** Prints out statistics of this approach.
780        */
781        //  virtual void PrintStatistics(ostream &s) const;
782        ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const { return NULL; }
783
784        float GetProbability(ViewCell *viewCell);
785       
786
787        void CreateMesh(ViewCell *vc);
788
789        void ExportViewCellGeometry(Exporter *exporter,
790                                                                ViewCell *vc,
791                                                                const AxisAlignedPlane *clipPlane = NULL) const;
792
793        void CollectMergeCandidates(const VssRayContainer &rays,
794                                                                vector<MergeCandidate> &candidates);
795
796
797protected:
798
799        virtual void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs) {};
800        /** Collects view cells from a hierarchy.
801        */
802        void CollectViewCells();
803
804        KdNode *GetNodeForPvs(KdLeaf *leaf);
805
806
807        /// the BSP tree.
808        KdTree *mKdTree;
809
810        /// depth of the KD tree nodes with represent the view cells
811        int mKdPvsDepth;
812
813
814};
815
816/**
817        Manages different higher order operations on the view cells.
818*/
819class VspBspViewCellsManager: public ViewCellsManager
820{
821
822public:
823
824        VspBspViewCellsManager(VspBspTree *tree);
825        ~VspBspViewCellsManager();
826
827        int ConstructSubdivision(const ObjectContainer &objects,
828                                  const VssRayContainer &rays);
829
830        int PostProcess(const ObjectContainer &objects,
831                                        const VssRayContainer &rays);
832
833        void Visualize(const ObjectContainer &objects,
834                                   const VssRayContainer &sampleRays);
835
836        int GetType() const;
837       
838        ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
839
840        bool ViewCellsConstructed() const;
841
842       
843        int CastLineSegment(const Vector3 &origin,
844                                                const Vector3 &termination,
845                                                ViewCellContainer &viewcells);
846
847        float GetProbability(ViewCell *viewCell);
848       
849        ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const;
850
851        bool GetViewPoint(Vector3 &viewPoint) const;
852
853        bool ViewPointValid(const Vector3 &viewPoint) const;
854
855        void CreateMesh(ViewCell *vc);
856
857        bool ExportViewCells(const string filename, const bool exportPvs, const ObjectContainer &objects);
858
859        int CastBeam(Beam &beam);
860
861        void ExportViewCellGeometry(Exporter *exporter,
862                                                                ViewCell *vc,
863                                                                const AxisAlignedPlane *clipPlane = NULL) const;
864
865        //float GetVolume(ViewCell *viewCell) const;
866
867        void Finalize(ViewCell *viewCell, const bool createMesh);
868
869        void CollectMergeCandidates(const VssRayContainer &rays, vector<MergeCandidate> &candidates);
870
871        /** Returns true if this view cell is equivavalent to a spatial node.
872        */
873        bool EqualToSpatialNode(ViewCell *viewCell) const;
874
875
876protected:
877
878        int ComputeBoxIntersections(const AxisAlignedBox3 &box, ViewCellContainer &viewCells) const;
879       
880        /** Returns node of the spatial hierarchy corresponding to the view cell
881                if such a node exists.
882        */
883        BspNode *GetSpatialNode(ViewCell *viewCell) const;
884
885        /** Merges view cells according to some criteria
886        */
887        void MergeViewCells(const VssRayContainer &rays,
888                                                const ObjectContainer &objects);
889       
890        void RefineViewCells(const VssRayContainer &rays, const ObjectContainer &objects);
891
892        void CollectViewCells();
893
894        /** Returns maximal depth difference of view cell
895                leaves in tree.
896        */
897        int GetMaxTreeDiff(ViewCell *vc) const;
898       
899
900        /** Prepare view cells for use after loading them from disc.
901        */
902        void PrepareLoadedViewCells();
903
904        /** Constructs merge hierarchy which corresponds to the spatial hierarchy.
905        */
906        ViewCell *ConstructSpatialMergeTree(BspNode *root);
907
908        void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs);
909
910
911        /// HACK for testing visibility filter functionality
912        void TestFilter(const ObjectContainer &objects);
913
914
915        /** Visualization of the pvs difference to exact visubility using
916                from point queries.
917        */
918        void VisualizeWithFromPointQueries();
919
920        /** Evaluate from point queries for the current scene.
921        */
922        void EvalFromPointQueries();
923
924        /** Exports visualization of the BSP splits.
925        */
926        void ExportSplits(const ObjectContainer &objects,
927                                          const VssRayContainer &rays);
928
929        /** Exports visualization of the BSP PVS.
930        */
931        void ExportBspPvs(const ObjectContainer &objects,
932                                          const VssRayContainer &rays);
933
934
935        /// the view space partition BSP tree.
936        VspBspTree *mVspBspTree;
937
938
939private:
940
941        /** test if subdivision is valid in terms of volume / area.
942        */
943        void TestSubdivision();
944};
945
946
947/**
948        Manages different higher order operations on the view cells.
949*/
950class VspOspViewCellsManager: public ViewCellsManager
951{
952
953public:
954
955        VspOspViewCellsManager(VspTree *tree, OspTree *ospTree);
956        ~VspOspViewCellsManager();
957
958        int ConstructSubdivision(const ObjectContainer &objects,
959                                                         const VssRayContainer &rays);
960
961        int PostProcess(const ObjectContainer &objects,
962                                        const VssRayContainer &rays);
963
964        void Visualize(const ObjectContainer &objects,
965                                   const VssRayContainer &sampleRays);
966
967        int GetType() const;
968       
969        ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
970
971        bool ViewCellsConstructed() const;
972
973       
974        int CastLineSegment(const Vector3 &origin,
975                                                const Vector3 &termination,
976                                                ViewCellContainer &viewcells);
977
978        float GetProbability(ViewCell *viewCell);
979       
980        ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const;
981
982        bool GetViewPoint(Vector3 &viewPoint) const;
983
984        bool ViewPointValid(const Vector3 &viewPoint) const;
985
986        void CreateMesh(ViewCell *vc);
987
988        bool ExportViewCells(const string filename,
989                                                 const bool exportPvs,
990                                                 const ObjectContainer &objects);
991
992        int CastBeam(Beam &beam);
993
994        void Finalize(ViewCell *viewCell, const bool createMesh);
995
996
997protected:
998
999       
1000        /** Exports view cell geometry.
1001        */
1002        void ExportViewCellGeometry(Exporter *exporter,
1003                ViewCell *vc,
1004                const AxisAlignedPlane *clipPlane = NULL) const;
1005
1006        int ComputeBoxIntersections(const AxisAlignedBox3 &box,
1007                ViewCellContainer &viewCells) const;
1008       
1009        void CollectViewCells();
1010
1011
1012        /** Prepare view cells for use after loading them from disc.
1013        */
1014        void PrepareLoadedViewCells();
1015
1016        /** Constructs merge hierarchy which corresponds to the spatial hierarchy.
1017        */
1018        ViewCell *ConstructSpatialMergeTree(VspNode *root);
1019
1020        void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs);
1021
1022        /** Exports visualization of the PVS.
1023        */
1024        void ExportPvs(const ObjectContainer &objects,
1025                const VssRayContainer &rays);
1026
1027
1028        /// the view space partition tree.
1029        VspTree *mVspTree;
1030        OspTree *mOspTree;
1031
1032        HierarchyManager *mHierarchyManager;
1033};
1034
1035
1036/*class ViewCellsManagerFactory
1037{
1038public:
1039        ViewCellsManager *Create(const string mName);
1040};*/
1041
1042}
1043
1044#endif
Note: See TracBrowser for help on using the repository browser.