[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 |
|
---|
| 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;
|
---|
[1259] | 41 | class BvHierarchy;
|
---|
[1237] | 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 | {
|
---|
[1259] | 88 | friend VspTree;
|
---|
| 89 | friend OspTree;
|
---|
| 90 | friend BvHierarchy;
|
---|
[1279] | 91 | friend ViewCellsParseHandlers;
|
---|
[1259] | 92 |
|
---|
[1237] | 93 | public:
|
---|
[1279] | 94 | /** Constructor with the object space hierarchy type as argument.
|
---|
[1237] | 95 | */
|
---|
[1279] | 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);
|
---|
[1237] | 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 |
|
---|
[1259] | 123 | enum
|
---|
| 124 | {
|
---|
| 125 | NO_OBJ_SUBDIV,
|
---|
| 126 | KD_BASED_OBJ_SUBDIV,
|
---|
| 127 | BV_BASED_OBJ_SUBDIV
|
---|
| 128 | };
|
---|
[1237] | 129 |
|
---|
[1259] | 130 | /** The type of object space subdivison
|
---|
| 131 | */
|
---|
| 132 | inline int GetObjectSpaceSubdivisonType() const
|
---|
| 133 | {
|
---|
| 134 | return mObjectSpaceSubdivisonType;
|
---|
| 135 | }
|
---|
| 136 |
|
---|
[1279] | 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;
|
---|
[1283] | 155 | ~HierarchyManager();
|
---|
[1279] | 156 |
|
---|
[1237] | 157 | protected:
|
---|
| 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 |
|
---|
[1259] | 184 | void AddSubdivisionStats(
|
---|
| 185 | const int splits,
|
---|
[1237] | 186 | const float renderCostDecr,
|
---|
| 187 | const float totalRenderCost);
|
---|
| 188 |
|
---|
[1259] | 189 | void CollectObjectSpaceDirtyList();
|
---|
| 190 | void CollectViewSpaceDirtyList();
|
---|
[1237] | 191 |
|
---|
[1259] | 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 |
|
---|
[1237] | 200 | protected:
|
---|
| 201 |
|
---|
[1259] | 202 | int mObjectSpaceSubdivisonType;
|
---|
| 203 |
|
---|
| 204 | VspTree *mVspTree;
|
---|
| 205 | OspTree *mOspTree;
|
---|
| 206 | BvHierarchy *mBvHierarchy;
|
---|
| 207 |
|
---|
[1237] | 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
|
---|