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

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