source: GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h @ 1576

Revision 1576, 9.3 KB checked in by mattausch, 18 years ago (diff)

added measurement for pvs entries size decrease during subdivision

RevLine 
[1237]1#ifndef _HierarchyManager_H__
2#define _HierarchyManager_H__
3
4#include <stack>
5
6#include "Mesh.h"
7#include "Containers.h"
8#include "Statistics.h"
9#include "VssRay.h"
10#include "RayInfo.h"
11#include "gzstream.h"
[1239]12#include "SubdivisionCandidate.h"
[1237]13
14
15
16namespace GtpVisibilityPreprocessor {
17
18class ViewCellLeaf;
19class OspTree;
20class VspTree;
21class Plane3;
22class AxisAlignedBox3;
23class Ray;
24class ViewCellsStatistics;
25class ViewCellsManager;
26class MergeCandidate;
27class Beam;
28class ViewCellsTree;
29class Environment;
30class VspInterior;
31class VspLeaf;
32class VspNode;
33class KdNode;
34class KdInterior;
35class KdLeaf;
36class OspTree;
37class KdIntersectable;
38class KdTree;
39class VspTree;
40class KdTreeStatistics;
[1259]41class BvHierarchy;
[1287]42class Exporter;
[1237]43
44
45
[1551]46/** View space / object space hierarchy statistics.
[1288]47*/
48class HierarchyStatistics: public StatisticsBase
49{
50public:
[1576]51        /// total number of entries in the pvs
52        int pvsEntries;
53        /// storage cost
54        int memory;
[1288]55        /// total number of nodes
56        int nodes;
57        /// maximal reached depth
58        int maxDepth;
59        /// accumulated depth
60        int accumDepth;
[1449]61        /// time spent for queue repair
[1313]62        float repairTime;
[1449]63        // global cost ratio violations
64        int mGlobalCostMisses;
[1313]65
[1288]66        // Constructor
67        HierarchyStatistics()
68        {
69                Reset();
70        }
71
72        int Nodes() const {return nodes;}
73        int Interior() const { return nodes / 2; }
74        int Leaves() const { return (nodes / 2) + 1; }
75       
76        // TODO: computation wrong
77        double AvgDepth() const { return accumDepth / (double)Leaves();}
78
[1449]79        void Reset()
[1288]80        {
[1449]81                mGlobalCostMisses = 0;
[1288]82                nodes = 0;
83                maxDepth = 0;
84                accumDepth = 0;
[1313]85                repairTime = 0;
[1576]86                memory = 0;
87                pvsEntries = 0;
[1288]88        }
89
90        void Print(ostream &app) const;
91
92        friend ostream &operator<<(ostream &s, const HierarchyStatistics &stat)
93        {
94                stat.Print(s);
95                return s;
96        }
97};
98
99
[1237]100typedef FlexibleHeap<SubdivisionCandidate *> SplitQueue;
101
102/** This class implements a structure holding two different hierarchies,
103        one for object space partitioning and one for view space partitioning.
104
105        The object space and the view space are subdivided using a cost heuristics.
106        If an object space split or a view space split is chosen is also evaluated
107        based on the heuristics.
108       
109        The view space heuristics is evaluated by weighting and adding the pvss of the back and
110        front node of each specific split. unlike for the standalone method vspbsp tree,
111        the pvs of an object would not be the pvs of single object but that of all objects
112        which are contained in the same leaf of the object subdivision. This could be done
113        by storing the pointer to the object space partition parent, which would allow access to all children.
114        Another possibility is to include traced kd-cells in the ray casing process.
115
116        Accordingly, the object space heuristics is evaluated by storing a pvs of view cells with each object.
117        the contribution to an object to the pvs is the number of view cells it can be seen from.
118
119        @note
120        There is a potential efficiency problem involved in a sense that once a certain type
121        of split is chosen for view space / object space, the candidates for the next split of
122        object space / view space must be reevaluated.
123*/
124class HierarchyManager
125{
[1259]126        friend VspTree;
127        friend OspTree;
128        friend BvHierarchy;
[1279]129        friend ViewCellsParseHandlers;
[1259]130
[1237]131public:
[1421]132        /** Constructor with the view space partition tree and
133                the object space hierarchy type as argument.
[1237]134        */
[1421]135        HierarchyManager(const int objectSpaceHierarchyType);
[1279]136        /** Hack: OspTree will copy the content from this kd tree.
137                Only view space hierarchy will be constructed.
138        */
[1421]139        HierarchyManager(KdTree *kdTree);
[1237]140
[1421]141        /** Deletes space partition and view space partition.
142        */
[1286]143        ~HierarchyManager();
144
[1237]145        /** Constructs the view space and object space subdivision from a given set of rays
146                and a set of objects.
147                @param sampleRays the set of sample rays the construction is based on
148                @param objects the set of objects
149        */
[1308]150        void Construct(
[1293]151                const VssRayContainer &sampleRays,
152                const ObjectContainer &objects,
153                AxisAlignedBox3 *forcedViewSpace);
[1237]154
[1259]155        enum
156        {
157                NO_OBJ_SUBDIV,
158                KD_BASED_OBJ_SUBDIV,
159                BV_BASED_OBJ_SUBDIV
160        };
[1237]161
[1370]162        enum
163        {
164                NO_VIEWSPACE_SUBDIV,
165                KD_BASED_VIEWSPACE_SUBDIV
166        };
167
[1259]168        /** The type of object space subdivison
169        */
[1370]170        int GetObjectSpaceSubdivisionType() const;     
171        /** The type of view space space subdivison
172        */
173        int GetViewSpaceSubdivisionType() const;
174        /** Sets a pointer to the view cells manager.
175        */             
[1279]176        void SetViewCellsManager(ViewCellsManager *vcm);
[1370]177        /** Sets a pointer to the view cells tree.
178        */
[1279]179        void SetViewCellsTree(ViewCellsTree *vcTree);
[1370]180        /** Exports the object hierarchy to disc.
181        */
[1279]182        void ExportObjectSpaceHierarchy(OUT_STREAM &stream);
[1370]183        /** Adds a sample to the pvs of the specified view cell.
184        */
[1279]185        bool AddSampleToPvs(
186                Intersectable *obj,
187                const Vector3 &hitPoint,
188                ViewCell *vc,
189                const float pdf,
190                float &contribution) const;
191
[1421]192        /** Print out statistics.
193        */
194        void PrintHierarchyStatistics(ostream &stream) const;
[1279]195
[1421]196        /** Returns the view space partition tree.
197        */
[1379]198        VspTree *GetVspTree();
[1279]199
[1421]200        /** Returns view space bounding box.
201        */
[1563]202        //AxisAlignedBox3 GetViewSpaceBox() const;
[1421]203        /** Returns object space bounding box.
204        */
[1416]205        AxisAlignedBox3 GetObjectSpaceBox() const;
[1379]206
[1421]207        /** Exports object space hierarchy for visualization.
208        */
[1287]209        void ExportObjectSpaceHierarchy(
210                Exporter *exporter,
[1416]211                const ObjectContainer &objects,
[1418]212                const AxisAlignedBox3 *bbox,
213                const bool exportBounds = true) const;
[1279]214
[1421]215        /** Returns intersectable pierced by this ray.
216        */
[1418]217        Intersectable *GetIntersectable(
218                const VssRay &ray,
219                const bool isTermination) const;
220
[1419]221        friend ostream &operator<<(ostream &s, const HierarchyManager &hm)
222        {
[1421]223                hm.PrintHierarchyStatistics(s);
[1419]224                return s;
225        }
226
[1421]227
[1237]228protected:
229
230        bool GlobalTerminationCriteriaMet(SubdivisionCandidate *candidate) const;
231
232        /** Prepare construction of the hierarchies, set parameters, compute
233                first split candidates.
234        */
[1308]235        void PrepareObjectSpaceSubdivision(
[1237]236                const VssRayContainer &sampleRays,
[1308]237                const ObjectContainer &objects);
[1237]238
[1311]239        void RunConstruction(
[1449]240                const bool repairQueue,
[1311]241                const VssRayContainer &sampleRays,
242                const ObjectContainer &objects,
243                AxisAlignedBox3 *forcedViewSpace);
[1449]244       
245        void RunConstruction(const bool repairQueue);
246               
[1287]247        bool ApplySubdivisionCandidate(SubdivisionCandidate *sc);
[1237]248
249        bool FinishedConstruction() const;
250
251        SubdivisionCandidate *NextSubdivisionCandidate();
252
253        void RepairQueue();
254
255        void CollectDirtyCandidates(vector<SubdivisionCandidate *> &dirtyList);
256
257        void EvalSubdivisionStats(const SubdivisionCandidate &tData);
258
[1259]259        void AddSubdivisionStats(
260                const int splits,
[1237]261                const float renderCostDecr,
[1576]262                const float totalRenderCost,
263                const int totalPvsEntries);
[1237]264
[1259]265        void CollectObjectSpaceDirtyList();
266        void CollectViewSpaceDirtyList();
[1237]267
[1259]268        bool AddSampleToPvs(Intersectable *obj,
269                                                const float pdf,
270                                                float &contribution) const;
271
272        void CollectViewSpaceDirtyList(SubdivisionCandidateContainer &dirtyList);
273        void CollectObjectSpaceDirtyList(SubdivisionCandidateContainer &dirtyList);
274               
[1287]275        void ExportOspTree(Exporter *exporter, const ObjectContainer &objects) const;
[1259]276
[1418]277        void ParseEnvironment();
[1415]278
[1418]279        bool StartObjectSpaceSubdivision() const;
280        bool StartViewSpaceSubdivision() const;
281
[1308]282        void PrepareBvHierarchy(
[1286]283                const VssRayContainer &sampleRays,
[1287]284                const ObjectContainer &objects);
[1286]285
[1308]286        void PrepareOspTree(
[1286]287                const VssRayContainer &sampleRays,
[1287]288                const ObjectContainer &objects);
[1286]289
[1311]290        void PrepareViewSpaceSubdivision(
291                const VssRayContainer &sampleRays,
[1379]292                const ObjectContainer &objects);
[1308]293
[1313]294        bool ObjectSpaceSubdivisionConstructed() const;
[1329]295        bool ViewSpaceSubdivisionConstructed() const;
[1311]296
[1313]297    void ResetQueue();
298
[1418]299        void FinishObjectSpaceSubdivision(const ObjectContainer &objects) const;
[1313]300
[1370]301        int GetObjectSpaceSubdivisionDepth() const;
302
[1449]303        void ConstructInterleaved(
304                const VssRayContainer &sampleRays,
305                const ObjectContainer &objects,
306                AxisAlignedBox3 *forcedViewSpace);
307
[1548]308        /** Use iteration to construct the object space hierarchy.
309        */
[1449]310        void ConstructMultiLevel(
311                const VssRayContainer &sampleRays,
312                const ObjectContainer &objects,
313                AxisAlignedBox3 *forcedViewSpace);
314
[1548]315        /** Reset the object space subdivision.
316                E.g., deletes hierarchy and resets stats.
317                so construction can be restarted.
318        */
319        void ResetObjectSpaceSubdivision(
320                const VssRayContainer &rays,
321                const ObjectContainer &objects);
[1449]322
[1557]323        void HierarchyManager::ResetViewSpaceSubdivision(
324                const VssRayContainer &rays,
325                const ObjectContainer &objects);
326
[1237]327protected:
328
[1323]329        enum {SEQUENTIAL, INTERLEAVED};
[1329]330       
[1308]331        int mObjectSpaceSubdivisionType;
[1329]332    int mViewSpaceSubdivisionType;
333
[1323]334        /// the original osp type
335        int mSavedObjectSpaceSubdivisionType;
[1329]336        int mSavedViewSpaceSubdivisionType;
[1323]337
[1293]338        int mConstructionType;
[1259]339
340        VspTree *mVspTree;
341        OspTree *mOspTree;
342        BvHierarchy *mBvHierarchy;
343
[1237]344        AxisAlignedBox3 mBoundingBox;
345
346        SplitQueue mTQueue;
347
348        SubdivisionCandidate *mCurrentCandidate;
349
[1449]350        ////////
[1576]351        //-- global termination criteria
352
[1237]353        float mTermMinGlobalCostRatio;
354        int mTermGlobalCostMissTolerance;
[1449]355       
[1576]356        ////////////////////
357
[1237]358        /// keeps track of cost during subdivision
359        float mTotalCost;
360
[1576]361        int mTotalPvsEntries;
[1288]362        HierarchyStatistics mHierarchyStats;
363
[1308]364        int mMinDepthForObjectSpaceSubdivion;
[1370]365        int mMinDepthForViewSpaceSubdivion;
[1308]366
[1294]367        int mTermMaxLeaves;
[1237]368        ofstream mSubdivisionStats;
[1314]369
370        bool mRepairQueue;
[1370]371
372        bool mStartWithObjectSpace;
[1449]373
374        bool mUseMultiLevelConstruction;
[1237]375};
376
377}
378
379#endif
Note: See TracBrowser for help on using the repository browser.