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 |
|
---|
16 | namespace GtpVisibilityPreprocessor {
|
---|
17 |
|
---|
18 | class ViewCellLeaf;
|
---|
19 | class OspTree;
|
---|
20 | class VspTree;
|
---|
21 | class Plane3;
|
---|
22 | class AxisAlignedBox3;
|
---|
23 | class Ray;
|
---|
24 | class ViewCellsStatistics;
|
---|
25 | class ViewCellsManager;
|
---|
26 | class MergeCandidate;
|
---|
27 | class Beam;
|
---|
28 | class ViewCellsTree;
|
---|
29 | class Environment;
|
---|
30 | class VspInterior;
|
---|
31 | class VspLeaf;
|
---|
32 | class VspNode;
|
---|
33 | class KdNode;
|
---|
34 | class KdInterior;
|
---|
35 | class KdLeaf;
|
---|
36 | class OspTree;
|
---|
37 | class KdIntersectable;
|
---|
38 | class KdTree;
|
---|
39 | class VspTree;
|
---|
40 | class KdTreeStatistics;
|
---|
41 |
|
---|
42 |
|
---|
43 |
|
---|
44 | #if 0
|
---|
45 | template <typename T> class GtPriority
|
---|
46 | {
|
---|
47 | public:
|
---|
48 | bool operator() (const T c1, const T c2) const
|
---|
49 | {
|
---|
50 | //return false;
|
---|
51 | return c1->GetPriority() < c2->GetPriority();
|
---|
52 | }
|
---|
53 | };
|
---|
54 |
|
---|
55 | typedef std::priority_queue<SubdivisionCandidate *,
|
---|
56 | std::vector<SubdivisionCandidate *>,
|
---|
57 | GtPriority<std::vector<SubdivisionCandidate *>::value_type> > SplitQueue;
|
---|
58 | #endif
|
---|
59 |
|
---|
60 |
|
---|
61 | typedef 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 | */
|
---|
86 | class HierarchyManager
|
---|
87 | {
|
---|
88 | public:
|
---|
89 | /** Constructor taking an object space partition and a view space partition tree.
|
---|
90 | */
|
---|
91 | HierarchyManager(VspTree &vspTree, OspTree &ospTree);
|
---|
92 |
|
---|
93 | /** Constructs the view space and object space subdivision from a given set of rays
|
---|
94 | and a set of objects.
|
---|
95 | @param sampleRays the set of sample rays the construction is based on
|
---|
96 | @param objects the set of objects
|
---|
97 | */
|
---|
98 | void Construct(const VssRayContainer &sampleRays,
|
---|
99 | const ObjectContainer &objects,
|
---|
100 | AxisAlignedBox3 *forcedViewSpace);
|
---|
101 |
|
---|
102 | /** Constructs first view cells, then object space partition.
|
---|
103 | */
|
---|
104 | void Construct2(const VssRayContainer &sampleRays,
|
---|
105 | const ObjectContainer &objects,
|
---|
106 | AxisAlignedBox3 *forcedViewSpace);
|
---|
107 |
|
---|
108 | /** Constructs only vsp tree.
|
---|
109 | */
|
---|
110 | void Construct3(const VssRayContainer &sampleRays,
|
---|
111 | const ObjectContainer &objects,
|
---|
112 | AxisAlignedBox3 *forcedViewSpace);
|
---|
113 |
|
---|
114 | public:
|
---|
115 | VspTree &mVspTree;
|
---|
116 | OspTree &mOspTree;
|
---|
117 |
|
---|
118 | protected:
|
---|
119 |
|
---|
120 | bool GlobalTerminationCriteriaMet(SubdivisionCandidate *candidate) const;
|
---|
121 |
|
---|
122 | /** Prepare construction of the hierarchies, set parameters, compute
|
---|
123 | first split candidates.
|
---|
124 | */
|
---|
125 | void PrepareConstruction(
|
---|
126 | const VssRayContainer &sampleRays,
|
---|
127 | const ObjectContainer &objects,
|
---|
128 | AxisAlignedBox3 *forcedViewSpace,
|
---|
129 | RayInfoContainer &viewSpaceRays,
|
---|
130 | RayInfoContainer &objectSpaceRays);
|
---|
131 |
|
---|
132 | void RunConstruction(const bool repair);
|
---|
133 | bool SubdivideSubdivisionCandidate(SubdivisionCandidate *sc);
|
---|
134 |
|
---|
135 | bool FinishedConstruction() const;
|
---|
136 |
|
---|
137 | SubdivisionCandidate *NextSubdivisionCandidate();
|
---|
138 |
|
---|
139 | void RepairQueue();
|
---|
140 |
|
---|
141 | void CollectDirtyCandidates(vector<SubdivisionCandidate *> &dirtyList);
|
---|
142 |
|
---|
143 | void EvalSubdivisionStats(const SubdivisionCandidate &tData);
|
---|
144 |
|
---|
145 | void AddSubdivisionStats(const int splits,
|
---|
146 | const float renderCostDecr,
|
---|
147 | const float totalRenderCost);
|
---|
148 |
|
---|
149 |
|
---|
150 | protected:
|
---|
151 |
|
---|
152 | AxisAlignedBox3 mBoundingBox;
|
---|
153 |
|
---|
154 | SplitQueue mTQueue;
|
---|
155 |
|
---|
156 | SubdivisionCandidate *mCurrentCandidate;
|
---|
157 |
|
---|
158 | //-- global criteria
|
---|
159 | float mTermMinGlobalCostRatio;
|
---|
160 | int mTermGlobalCostMissTolerance;
|
---|
161 | int mGlobalCostMisses;
|
---|
162 |
|
---|
163 | /// keeps track of cost during subdivision
|
---|
164 | float mTotalCost;
|
---|
165 |
|
---|
166 | ofstream mSubdivisionStats;
|
---|
167 | };
|
---|
168 |
|
---|
169 | }
|
---|
170 |
|
---|
171 | #endif
|
---|