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

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