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

Revision 1379, 8.0 KB checked in by mattausch, 18 years ago (diff)

fixed sah for objeect partition
loader for single triangles also for x3d

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#if 0
45template <typename T> class GtPriority
46{
47public:
48        bool operator() (const T c1, const T c2) const
49        {
50                //return false;
51                return c1->GetPriority() < c2->GetPriority();
52        }
53};
54
55typedef std::priority_queue<SubdivisionCandidate *,
56                                                        std::vector<SubdivisionCandidate *>,
57                                                        GtPriority<std::vector<SubdivisionCandidate *>::value_type> > SplitQueue;
58#endif
59
60
[1288]61
62/** View space partition statistics.
63*/
64class HierarchyStatistics: public StatisticsBase
65{
66public:
67
68        /// total number of nodes
69        int nodes;
70        /// maximal reached depth
71        int maxDepth;
72        /// accumulated depth
73        int accumDepth;
74
[1313]75        float repairTime;
76
[1288]77        // Constructor
78        HierarchyStatistics()
79        {
80                Reset();
81        }
82
83        int Nodes() const {return nodes;}
84        int Interior() const { return nodes / 2; }
85        int Leaves() const { return (nodes / 2) + 1; }
86       
87        // TODO: computation wrong
88        double AvgDepth() const { return accumDepth / (double)Leaves();}
89
90        void Reset()
91        {
92                nodes = 0;
93                maxDepth = 0;
94                accumDepth = 0;
[1313]95                repairTime = 0;
[1288]96        }
97
98        void Print(ostream &app) const;
99
100        friend ostream &operator<<(ostream &s, const HierarchyStatistics &stat)
101        {
102                stat.Print(s);
103                return s;
104        }
105};
106
107
[1237]108typedef FlexibleHeap<SubdivisionCandidate *> SplitQueue;
109
110/** This class implements a structure holding two different hierarchies,
111        one for object space partitioning and one for view space partitioning.
112
113        The object space and the view space are subdivided using a cost heuristics.
114        If an object space split or a view space split is chosen is also evaluated
115        based on the heuristics.
116       
117        The view space heuristics is evaluated by weighting and adding the pvss of the back and
118        front node of each specific split. unlike for the standalone method vspbsp tree,
119        the pvs of an object would not be the pvs of single object but that of all objects
120        which are contained in the same leaf of the object subdivision. This could be done
121        by storing the pointer to the object space partition parent, which would allow access to all children.
122        Another possibility is to include traced kd-cells in the ray casing process.
123
124        Accordingly, the object space heuristics is evaluated by storing a pvs of view cells with each object.
125        the contribution to an object to the pvs is the number of view cells it can be seen from.
126
127        @note
128        There is a potential efficiency problem involved in a sense that once a certain type
129        of split is chosen for view space / object space, the candidates for the next split of
130        object space / view space must be reevaluated.
131       
132*/
133class HierarchyManager
134{
[1259]135        friend VspTree;
136        friend OspTree;
137        friend BvHierarchy;
[1279]138        friend ViewCellsParseHandlers;
[1259]139
[1237]140public:
[1279]141        /** Constructor with the object space hierarchy type as argument.
[1237]142        */
[1279]143        HierarchyManager(VspTree *vspTree, const int objectSpaceHierarchyType);
144        /** Hack: OspTree will copy the content from this kd tree.
145                Only view space hierarchy will be constructed.
146        */
147        HierarchyManager(VspTree *vspTree, KdTree *kdTree);
[1237]148
[1286]149        ~HierarchyManager();
150
[1237]151        /** Constructs the view space and object space subdivision from a given set of rays
152                and a set of objects.
153                @param sampleRays the set of sample rays the construction is based on
154                @param objects the set of objects
155        */
[1308]156        void Construct(
[1293]157                const VssRayContainer &sampleRays,
158                const ObjectContainer &objects,
159                AxisAlignedBox3 *forcedViewSpace);
[1237]160
[1259]161        enum
162        {
163                NO_OBJ_SUBDIV,
164                KD_BASED_OBJ_SUBDIV,
165                BV_BASED_OBJ_SUBDIV
166        };
[1237]167
[1370]168        enum
169        {
170                NO_VIEWSPACE_SUBDIV,
171                KD_BASED_VIEWSPACE_SUBDIV
172        };
173
[1259]174        /** The type of object space subdivison
175        */
[1370]176        int GetObjectSpaceSubdivisionType() const;     
177        /** The type of view space space subdivison
178        */
179        int GetViewSpaceSubdivisionType() const;
180        /** Sets a pointer to the view cells manager.
181        */             
[1279]182        void SetViewCellsManager(ViewCellsManager *vcm);
[1370]183        /** Sets a pointer to the view cells tree.
184        */
[1279]185        void SetViewCellsTree(ViewCellsTree *vcTree);
[1370]186        /** Exports the object hierarchy to disc.
187        */
[1279]188        void ExportObjectSpaceHierarchy(OUT_STREAM &stream);
[1370]189        /** Adds a sample to the pvs of the specified view cell.
190        */
[1279]191        bool AddSampleToPvs(
192                Intersectable *obj,
193                const Vector3 &hitPoint,
194                ViewCell *vc,
195                const float pdf,
196                float &contribution) const;
197
[1313]198        void PrintHierarchyStatistics(ofstream &stream) const;
[1279]199
[1379]200        VspTree *GetVspTree();
[1279]201
[1379]202        AxisAlignedBox3 GetViewSpaceBox() const;
203
[1287]204        void ExportObjectSpaceHierarchy(
205                Exporter *exporter,
206                const ObjectContainer &objects) const;
[1279]207
[1286]208
[1237]209protected:
210
211        bool GlobalTerminationCriteriaMet(SubdivisionCandidate *candidate) const;
212
213        /** Prepare construction of the hierarchies, set parameters, compute
214                first split candidates.
215        */
[1308]216        void PrepareObjectSpaceSubdivision(
[1237]217                const VssRayContainer &sampleRays,
[1308]218                const ObjectContainer &objects);
[1237]219
[1311]220        void RunConstruction(
221                const VssRayContainer &sampleRays,
222                const ObjectContainer &objects,
223                AxisAlignedBox3 *forcedViewSpace);
224
[1287]225        bool ApplySubdivisionCandidate(SubdivisionCandidate *sc);
[1237]226
227        bool FinishedConstruction() const;
228
229        SubdivisionCandidate *NextSubdivisionCandidate();
230
231        void RepairQueue();
232
233        void CollectDirtyCandidates(vector<SubdivisionCandidate *> &dirtyList);
234
235        void EvalSubdivisionStats(const SubdivisionCandidate &tData);
236
[1259]237        void AddSubdivisionStats(
238                const int splits,
[1237]239                const float renderCostDecr,
240                const float totalRenderCost);
241
[1259]242        void CollectObjectSpaceDirtyList();
243        void CollectViewSpaceDirtyList();
[1237]244
[1259]245        bool AddSampleToPvs(Intersectable *obj,
246                                                const float pdf,
247                                                float &contribution) const;
248
249        void CollectViewSpaceDirtyList(SubdivisionCandidateContainer &dirtyList);
250        void CollectObjectSpaceDirtyList(SubdivisionCandidateContainer &dirtyList);
251               
[1287]252        void ExportOspTree(Exporter *exporter, const ObjectContainer &objects) const;
253        void ExportBvHierarchy(Exporter *exporter, const ObjectContainer &objects) const;
[1259]254
[1308]255        void PrepareBvHierarchy(
[1286]256                const VssRayContainer &sampleRays,
[1287]257                const ObjectContainer &objects);
[1286]258
[1308]259        void PrepareOspTree(
[1286]260                const VssRayContainer &sampleRays,
[1287]261                const ObjectContainer &objects);
[1286]262
[1288]263        void ParseEnvironment();
264
[1308]265        bool StartObjectSpaceSubdivision() const;
[1329]266        bool StartViewSpaceSubdivision() const;
[1288]267
[1311]268        void PrepareViewSpaceSubdivision(
269                const VssRayContainer &sampleRays,
[1379]270                const ObjectContainer &objects);
[1308]271
[1313]272        bool ObjectSpaceSubdivisionConstructed() const;
[1329]273        bool ViewSpaceSubdivisionConstructed() const;
[1311]274
[1313]275    void ResetQueue();
276
[1370]277        void FinishObjectSpaceSubdivision() const;
[1313]278
[1370]279        int GetObjectSpaceSubdivisionDepth() const;
280
[1237]281protected:
282
[1323]283        enum {SEQUENTIAL, INTERLEAVED};
[1329]284       
[1308]285        int mObjectSpaceSubdivisionType;
[1329]286    int mViewSpaceSubdivisionType;
287
[1323]288        /// the original osp type
289        int mSavedObjectSpaceSubdivisionType;
[1329]290        int mSavedViewSpaceSubdivisionType;
[1323]291
[1293]292        int mConstructionType;
[1259]293
294        VspTree *mVspTree;
295        OspTree *mOspTree;
296        BvHierarchy *mBvHierarchy;
297
[1237]298        AxisAlignedBox3 mBoundingBox;
299
300        SplitQueue mTQueue;
301
302        SubdivisionCandidate *mCurrentCandidate;
303
304        //-- global criteria
305        float mTermMinGlobalCostRatio;
306        int mTermGlobalCostMissTolerance;
307        int mGlobalCostMisses;
308
309        /// keeps track of cost during subdivision
310        float mTotalCost;
311
[1288]312        HierarchyStatistics mHierarchyStats;
313
[1308]314        int mMinDepthForObjectSpaceSubdivion;
[1370]315        int mMinDepthForViewSpaceSubdivion;
[1308]316
[1294]317        int mTermMaxLeaves;
[1237]318        ofstream mSubdivisionStats;
[1314]319
320        bool mRepairQueue;
[1370]321
322        bool mStartWithObjectSpace;
[1237]323};
324
325}
326
327#endif
Note: See TracBrowser for help on using the repository browser.