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

Revision 1283, 6.0 KB checked in by bittner, 18 years ago (diff)

mlrt tests

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        friend ViewCellsParseHandlers;
92
93public:
94        /** Constructor with the object space hierarchy type as argument.
95        */
96        HierarchyManager(VspTree *vspTree, const int objectSpaceHierarchyType);
97        /** Hack: OspTree will copy the content from this kd tree.
98                Only view space hierarchy will be constructed.
99        */
100        HierarchyManager(VspTree *vspTree, KdTree *kdTree);
101
102        /** Constructs the view space and object space subdivision from a given set of rays
103                and a set of objects.
104                @param sampleRays the set of sample rays the construction is based on
105                @param objects the set of objects
106        */
107        void Construct(const VssRayContainer &sampleRays,
108                                   const ObjectContainer &objects,
109                                   AxisAlignedBox3 *forcedViewSpace);
110
111        /** Constructs first view cells, then object space partition.
112        */
113        void Construct2(const VssRayContainer &sampleRays,
114                                        const ObjectContainer &objects,
115                                        AxisAlignedBox3 *forcedViewSpace);
116
117        /** Constructs only vsp tree.
118        */
119        void Construct3(const VssRayContainer &sampleRays,
120                                        const ObjectContainer &objects,
121                                        AxisAlignedBox3 *forcedViewSpace);
122
123        enum
124        {
125                NO_OBJ_SUBDIV,
126                KD_BASED_OBJ_SUBDIV,
127                BV_BASED_OBJ_SUBDIV
128        };
129
130        /** The type of object space subdivison
131        */
132        inline int GetObjectSpaceSubdivisonType() const
133        {
134                return mObjectSpaceSubdivisonType;
135        }
136       
137        void SetViewCellsManager(ViewCellsManager *vcm);
138
139        void SetViewCellsTree(ViewCellsTree *vcTree);
140
141        void ExportObjectSpaceHierarchy(OUT_STREAM &stream);
142
143        bool AddSampleToPvs(
144                Intersectable *obj,
145                const Vector3 &hitPoint,
146                ViewCell *vc,
147                const float pdf,
148                float &contribution) const;
149
150        void PrintObjectSpaceHierarchyStatistics(ofstream &stream) const;
151
152        VspTree *GetVspTree() { return mVspTree; }
153
154        void ExportObjectSpaceHierarchyForViz(const ObjectContainer &objects) const;
155    ~HierarchyManager();
156
157protected:
158
159        bool GlobalTerminationCriteriaMet(SubdivisionCandidate *candidate) const;
160
161        /** Prepare construction of the hierarchies, set parameters, compute
162                first split candidates.
163        */
164        void PrepareConstruction(
165                const VssRayContainer &sampleRays,
166                const ObjectContainer &objects,
167                AxisAlignedBox3 *forcedViewSpace,
168                RayInfoContainer &viewSpaceRays,
169                RayInfoContainer &objectSpaceRays);
170
171        void RunConstruction(const bool repair);
172        bool SubdivideSubdivisionCandidate(SubdivisionCandidate *sc);
173
174        bool FinishedConstruction() const;
175
176        SubdivisionCandidate *NextSubdivisionCandidate();
177
178        void RepairQueue();
179
180        void CollectDirtyCandidates(vector<SubdivisionCandidate *> &dirtyList);
181
182        void EvalSubdivisionStats(const SubdivisionCandidate &tData);
183
184        void AddSubdivisionStats(
185                const int splits,
186                const float renderCostDecr,
187                const float totalRenderCost);
188
189        void CollectObjectSpaceDirtyList();
190        void CollectViewSpaceDirtyList();
191
192        bool AddSampleToPvs(Intersectable *obj,
193                                                const float pdf,
194                                                float &contribution) const;
195
196        void CollectViewSpaceDirtyList(SubdivisionCandidateContainer &dirtyList);
197        void CollectObjectSpaceDirtyList(SubdivisionCandidateContainer &dirtyList);
198               
199
200protected:
201
202        int mObjectSpaceSubdivisonType;
203
204        VspTree *mVspTree;
205        OspTree *mOspTree;
206        BvHierarchy *mBvHierarchy;
207
208        AxisAlignedBox3 mBoundingBox;
209
210        SplitQueue mTQueue;
211
212        SubdivisionCandidate *mCurrentCandidate;
213
214        //-- global criteria
215        float mTermMinGlobalCostRatio;
216        int mTermGlobalCostMissTolerance;
217        int mGlobalCostMisses;
218
219        /// keeps track of cost during subdivision
220        float mTotalCost;
221
222        ofstream mSubdivisionStats;
223};
224
225}
226
227#endif
Note: See TracBrowser for help on using the repository browser.