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

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