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

Revision 1259, 5.3 KB checked in by mattausch, 18 years ago (diff)
Line 
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"
12#include "SubdivisionCandidate.h"
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;
41class BvHierarchy;
42
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
61typedef FlexibleHeap<SubdivisionCandidate *> SplitQueue;
62
63/** This class implements a structure holding two different hierarchies,
64        one for object space partitioning and one for view space partitioning.
65
66        The object space and the view space are subdivided using a cost heuristics.
67        If an object space split or a view space split is chosen is also evaluated
68        based on the heuristics.
69       
70        The view space heuristics is evaluated by weighting and adding the pvss of the back and
71        front node of each specific split. unlike for the standalone method vspbsp tree,
72        the pvs of an object would not be the pvs of single object but that of all objects
73        which are contained in the same leaf of the object subdivision. This could be done
74        by storing the pointer to the object space partition parent, which would allow access to all children.
75        Another possibility is to include traced kd-cells in the ray casing process.
76
77        Accordingly, the object space heuristics is evaluated by storing a pvs of view cells with each object.
78        the contribution to an object to the pvs is the number of view cells it can be seen from.
79
80        @note
81        There is a potential efficiency problem involved in a sense that once a certain type
82        of split is chosen for view space / object space, the candidates for the next split of
83        object space / view space must be reevaluated.
84       
85*/
86class HierarchyManager
87{
88        friend VspTree;
89        friend OspTree;
90        friend BvHierarchy;
91
92public:
93        /** Constructor taking an object space partition and a view space partition tree.
94        */
95        HierarchyManager(VspTree &vspTree, OspTree &ospTree);
96
97        /** Constructs the view space and object space subdivision from a given set of rays
98                and a set of objects.
99                @param sampleRays the set of sample rays the construction is based on
100                @param objects the set of objects
101        */
102        void Construct(const VssRayContainer &sampleRays,
103                                   const ObjectContainer &objects,
104                                   AxisAlignedBox3 *forcedViewSpace);
105
106        /** Constructs first view cells, then object space partition.
107        */
108        void Construct2(const VssRayContainer &sampleRays,
109                                        const ObjectContainer &objects,
110                                        AxisAlignedBox3 *forcedViewSpace);
111
112        /** Constructs only vsp tree.
113        */
114        void Construct3(const VssRayContainer &sampleRays,
115                                        const ObjectContainer &objects,
116                                        AxisAlignedBox3 *forcedViewSpace);
117
118        enum
119        {
120                NO_OBJ_SUBDIV,
121                KD_BASED_OBJ_SUBDIV,
122                BV_BASED_OBJ_SUBDIV
123        };
124
125        /** The type of object space subdivison
126        */
127        inline int GetObjectSpaceSubdivisonType() const
128        {
129                return mObjectSpaceSubdivisonType;
130        }
131       
132protected:
133
134        bool GlobalTerminationCriteriaMet(SubdivisionCandidate *candidate) const;
135
136        /** Prepare construction of the hierarchies, set parameters, compute
137                first split candidates.
138        */
139        void PrepareConstruction(
140                const VssRayContainer &sampleRays,
141                const ObjectContainer &objects,
142                AxisAlignedBox3 *forcedViewSpace,
143                RayInfoContainer &viewSpaceRays,
144                RayInfoContainer &objectSpaceRays);
145
146        void RunConstruction(const bool repair);
147        bool SubdivideSubdivisionCandidate(SubdivisionCandidate *sc);
148
149        bool FinishedConstruction() const;
150
151        SubdivisionCandidate *NextSubdivisionCandidate();
152
153        void RepairQueue();
154
155        void CollectDirtyCandidates(vector<SubdivisionCandidate *> &dirtyList);
156
157        void EvalSubdivisionStats(const SubdivisionCandidate &tData);
158
159        void AddSubdivisionStats(
160                const int splits,
161                const float renderCostDecr,
162                const float totalRenderCost);
163
164        void CollectObjectSpaceDirtyList();
165        void CollectViewSpaceDirtyList();
166
167        bool AddSampleToPvs(Intersectable *obj,
168                                                const float pdf,
169                                                float &contribution) const;
170
171        void CollectViewSpaceDirtyList(SubdivisionCandidateContainer &dirtyList);
172        void CollectObjectSpaceDirtyList(SubdivisionCandidateContainer &dirtyList);
173               
174
175protected:
176
177        int mObjectSpaceSubdivisonType;
178
179        VspTree *mVspTree;
180        OspTree *mOspTree;
181        BvHierarchy *mBvHierarchy;
182
183        AxisAlignedBox3 mBoundingBox;
184
185        SplitQueue mTQueue;
186
187        SubdivisionCandidate *mCurrentCandidate;
188
189        //-- global criteria
190        float mTermMinGlobalCostRatio;
191        int mTermGlobalCostMissTolerance;
192        int mGlobalCostMisses;
193
194        /// keeps track of cost during subdivision
195        float mTotalCost;
196
197        ofstream mSubdivisionStats;
198};
199
200}
201
202#endif
Note: See TracBrowser for help on using the repository browser.