[440] | 1 | #ifndef _ViewCellsManager_H__
|
---|
| 2 | #define _ViewCellsManager_H__
|
---|
| 3 |
|
---|
| 4 | #include "Ray.h"
|
---|
| 5 | #include "VssRay.h"
|
---|
| 6 | #include "Containers.h"
|
---|
| 7 |
|
---|
| 8 | class ViewCell;
|
---|
| 9 | class Intersectable;
|
---|
| 10 | class RenderSimulator;
|
---|
| 11 | class Mesh;
|
---|
| 12 | struct Triangle3;
|
---|
| 13 | class SimulationStatistics;
|
---|
| 14 | class BspTree;
|
---|
| 15 | class KdTree;
|
---|
| 16 | class VspKdTree;
|
---|
| 17 | class VspBspTree;
|
---|
| 18 | class KdNode;
|
---|
| 19 | class KdLeaf;
|
---|
| 20 | class VspKdTree;
|
---|
| 21 | class AxisAlignedBox3;
|
---|
[442] | 22 | class VspBspLeaf;
|
---|
| 23 |
|
---|
[440] | 24 | /**
|
---|
| 25 | Manages different higher order operations on the view cells.
|
---|
| 26 | */
|
---|
| 27 | class ViewCellsManager
|
---|
| 28 | {
|
---|
| 29 |
|
---|
| 30 | public:
|
---|
| 31 |
|
---|
| 32 | /// view cell container types
|
---|
| 33 | enum {BSP, KD, VSP_KD, VSP_BSP};
|
---|
| 34 |
|
---|
| 35 | /** Constructor taking the maximal number of samples used for construction
|
---|
| 36 | */
|
---|
| 37 | ViewCellsManager(const int constructionSamples);
|
---|
| 38 |
|
---|
| 39 | ViewCellsManager();
|
---|
| 40 |
|
---|
| 41 | ~ViewCellsManager();
|
---|
| 42 |
|
---|
| 43 | /** Constructs view cell container with a given number of samples.
|
---|
| 44 | */
|
---|
| 45 | virtual int Construct(const ObjectContainer &objects,
|
---|
| 46 | const VssRayContainer &rays,
|
---|
| 47 | AxisAlignedBox3 *sceneBbox = NULL) = 0;
|
---|
| 48 |
|
---|
[441] | 49 | /** Computes sample contributions of the rays to the view cells PVS.
|
---|
| 50 |
|
---|
| 51 | @param rays bundle of rays used to find intersections with view cells and
|
---|
| 52 | adding the contribution
|
---|
| 53 | @param castRays true if ray should be cast to gain the information, false if rays
|
---|
| 54 | already hold the view cells intersection information and need not be recast.
|
---|
| 55 | @param sampleContributions returns the number of sample contributions
|
---|
| 56 | @param contributingSamples returns the number of contributingSamples
|
---|
[440] | 57 | */
|
---|
[441] | 58 | void ComputeSampleContributions(const RayContainer &rays,
|
---|
| 59 | const bool castRays,
|
---|
| 60 | int &sampleContributions,
|
---|
| 61 | int &contributingSamples);
|
---|
[440] | 62 |
|
---|
[441] | 63 |
|
---|
| 64 | /** Computes sample contribution of a simgle ray to the view cells PVS.
|
---|
| 65 | @param ray finds intersections with view cells and holds the contribution
|
---|
| 66 | @param castRay true if ray should be cast to gain the information, false if ray
|
---|
| 67 | is already holding the information and need not be recast.
|
---|
| 68 |
|
---|
| 69 | @returns number of sample contributions
|
---|
[440] | 70 | */
|
---|
[441] | 71 | virtual int ComputeSampleContributions(Ray &ray, const bool castRay = true) = 0;
|
---|
[440] | 72 |
|
---|
| 73 | /** Post processes view cells givemŽa number of rays.
|
---|
| 74 | */
|
---|
| 75 | virtual int PostProcess(const ObjectContainer &objects,
|
---|
| 76 | const RayContainer &rays) = 0;
|
---|
| 77 |
|
---|
| 78 | /** Show visualization of the view cells.
|
---|
| 79 | */
|
---|
| 80 | virtual void Visualize(const ObjectContainer &objects,
|
---|
| 81 | const RayContainer &sampleRays) = 0;
|
---|
| 82 |
|
---|
| 83 | /** type of the view cell container.
|
---|
| 84 | */
|
---|
| 85 | virtual int GetType() const = 0;
|
---|
| 86 |
|
---|
| 87 | /** Simulates rendering with the given view cell partition.
|
---|
| 88 | @returns render time statistics
|
---|
| 89 | */
|
---|
| 90 | SimulationStatistics SimulateRendering() const;
|
---|
| 91 |
|
---|
| 92 | /** Load the input viewcells. The input viewcells should be given as a collection |
---|
| 93 | of meshes. Each mesh is assume to form a bounded polyhedron defining the interior of |
---|
| 94 | the viewcell. The method then builds a BSP tree of these view cells. |
---|
| 95 | |
---|
| 96 | @param filename file to load |
---|
| 97 | @return true on success |
---|
| 98 | */ |
---|
| 99 | bool LoadViewCells(const string filename);
|
---|
| 100 |
|
---|
| 101 | /** Constructs view cell from base triangle. The ViewCell is extruded along the normal vector.
|
---|
| 102 | @param the base triangle
|
---|
| 103 | @param the height of the newly created view cell
|
---|
| 104 | */
|
---|
| 105 | ViewCell *ExtrudeViewCell(const Triangle3 &baseTri, const float height) const;
|
---|
| 106 |
|
---|
| 107 | /** Merges two view cells.
|
---|
| 108 | @note the piercing rays of the front and back will be ordered
|
---|
| 109 | @returns new view cell based on the merging.
|
---|
| 110 | */
|
---|
[441] | 111 | ViewCell *MergeViewCells(ViewCell &front, ViewCell &back) const;
|
---|
[440] | 112 |
|
---|
| 113 | /** Generates view cell of type specified by this manager
|
---|
| 114 | */
|
---|
| 115 | virtual ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
|
---|
| 116 |
|
---|
| 117 | /** Adds a new view cell to the list of predefined view cells.
|
---|
| 118 | */
|
---|
| 119 | void AddViewCell(ViewCell *viewCell);
|
---|
| 120 |
|
---|
| 121 | /** Derive view cells from objects.
|
---|
| 122 | */
|
---|
| 123 | void DeriveViewCells(const ObjectContainer &objects,
|
---|
| 124 | ViewCellContainer &viewCells,
|
---|
| 125 | const int maxViewCells) const;
|
---|
| 126 |
|
---|
| 127 | /** Sets maximal number of samples used for the
|
---|
| 128 | construction of the view cells.
|
---|
| 129 | */
|
---|
| 130 | void SetVisualizationSamples(const int visSamples);
|
---|
| 131 |
|
---|
| 132 | /** Sets maximal number of samples used for the visualization of the view cells.
|
---|
| 133 | */
|
---|
| 134 | void SetConstructionSamples(const int constructionSamples);
|
---|
| 135 |
|
---|
| 136 | /** Sets maximal number of samples used for the post processing of the view cells.
|
---|
| 137 | */
|
---|
| 138 | void SetPostProcessSamples(const int postProcessingSamples);
|
---|
| 139 |
|
---|
| 140 | /** See set.
|
---|
| 141 | */
|
---|
| 142 | int GetVisualizationSamples() const;
|
---|
| 143 |
|
---|
| 144 | /** See set.
|
---|
| 145 | */
|
---|
| 146 | int GetConstructionSamples() const;
|
---|
| 147 |
|
---|
| 148 | /** See set.
|
---|
| 149 | */
|
---|
| 150 | int GetPostProcessSamples() const;
|
---|
| 151 |
|
---|
| 152 | /** Returns true if view cells wer already constructed.
|
---|
| 153 | */
|
---|
| 154 | virtual bool ViewCellsConstructed() const = 0;
|
---|
[444] | 155 |
|
---|
[441] | 156 |
|
---|
[440] | 157 | protected:
|
---|
[441] | 158 |
|
---|
| 159 |
|
---|
[440] | 160 |
|
---|
| 161 | /** Initialises the render time simulator.
|
---|
| 162 | */
|
---|
| 163 | void InitRenderSimulator();
|
---|
| 164 | /////////////////////
|
---|
| 165 |
|
---|
| 166 |
|
---|
| 167 | /// the view cell corresponding to unbounded space
|
---|
| 168 | ViewCell *mUnbounded;
|
---|
| 169 |
|
---|
| 170 | /// Simulates rendering
|
---|
| 171 | RenderSimulator *mRenderSimulator;
|
---|
| 172 |
|
---|
| 173 | /// Loaded view cells
|
---|
| 174 | ViewCellContainer mViewCells;
|
---|
| 175 |
|
---|
| 176 | /// maximum number of samples taken for construction of the view cells
|
---|
| 177 | int mConstructionSamples;
|
---|
| 178 | int mPostProcessSamples;
|
---|
| 179 | int mVisualizationSamples;
|
---|
[441] | 180 |
|
---|
| 181 | //-- thresholds used for view cells merge |
---|
| 182 | int mMinPvsDif; |
---|
| 183 | int mMinPvs; |
---|
| 184 | int mMaxPvs;
|
---|
[440] | 185 | };
|
---|
| 186 |
|
---|
[441] | 187 |
|
---|
| 188 |
|
---|
[440] | 189 | /**
|
---|
| 190 | Manages different higher order operations on the view cells.
|
---|
| 191 | */
|
---|
| 192 | class BspViewCellsManager: public ViewCellsManager
|
---|
| 193 | {
|
---|
| 194 |
|
---|
| 195 | public:
|
---|
| 196 |
|
---|
| 197 | BspViewCellsManager(BspTree *tree, int constructionSamples);
|
---|
| 198 |
|
---|
| 199 | int Construct(const ObjectContainer &objects,
|
---|
| 200 | const VssRayContainer &rays,
|
---|
| 201 | AxisAlignedBox3 *sceneBbox);
|
---|
| 202 |
|
---|
[441] | 203 | int ComputeSampleContributions(Ray &ray, const bool castRay = false);
|
---|
[440] | 204 |
|
---|
| 205 | int PostProcess(const ObjectContainer &objects,
|
---|
| 206 | const RayContainer &rays);
|
---|
| 207 |
|
---|
| 208 | void Visualize(const ObjectContainer &objects,
|
---|
| 209 | const RayContainer &sampleRays);
|
---|
| 210 |
|
---|
| 211 | int GetType() const;
|
---|
| 212 |
|
---|
| 213 | ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
|
---|
| 214 |
|
---|
| 215 | bool ViewCellsConstructed() const;
|
---|
| 216 |
|
---|
| 217 | protected:
|
---|
| 218 |
|
---|
[441] | 219 | /** Merges view cells front and back leaf view cell.
|
---|
| 220 | */
|
---|
| 221 | bool MergeBspLeafViewCells(BspLeaf *front, BspLeaf *back) const;
|
---|
[440] | 222 |
|
---|
[441] | 223 | /** Returns true if front and back leaf should be merged.
|
---|
| 224 | */
|
---|
| 225 | bool ShouldMerge(BspLeaf *front, BspLeaf *back) const;
|
---|
| 226 |
|
---|
[440] | 227 | /// the BSP tree.
|
---|
| 228 | BspTree *mBspTree;
|
---|
| 229 |
|
---|
| 230 |
|
---|
| 231 | private:
|
---|
| 232 |
|
---|
| 233 |
|
---|
| 234 | /** Exports visualization of the BSP splits.
|
---|
| 235 | */
|
---|
| 236 | void ExportSplits(const ObjectContainer &objects, const RayContainer &sampleRays);
|
---|
| 237 |
|
---|
| 238 | /** Exports visualization of the BSP PVS.
|
---|
| 239 | */
|
---|
| 240 | void ExportBspPvs(const ObjectContainer &objects, const RayContainer &sampleRays);
|
---|
| 241 |
|
---|
| 242 | };
|
---|
| 243 |
|
---|
| 244 | /**
|
---|
| 245 | Manages different higher order operations on the KD type view cells.
|
---|
| 246 | */
|
---|
| 247 | class KdViewCellsManager: public ViewCellsManager
|
---|
| 248 | {
|
---|
| 249 |
|
---|
| 250 | public:
|
---|
| 251 |
|
---|
| 252 | KdViewCellsManager(KdTree *tree);
|
---|
| 253 |
|
---|
| 254 | int Construct(const ObjectContainer &objects,
|
---|
| 255 | const VssRayContainer &rays,
|
---|
| 256 | AxisAlignedBox3 *sceneBbox);
|
---|
| 257 |
|
---|
| 258 | int CastRay(const Ray &ray);
|
---|
| 259 |
|
---|
| 260 | int PostProcess(const ObjectContainer &objects,
|
---|
| 261 | const RayContainer &rays);
|
---|
| 262 |
|
---|
| 263 | void Visualize(const ObjectContainer &objects,
|
---|
| 264 | const RayContainer &sampleRays);
|
---|
| 265 |
|
---|
| 266 | int GetType() const;
|
---|
| 267 |
|
---|
| 268 | bool ViewCellsConstructed() const;
|
---|
| 269 |
|
---|
| 270 |
|
---|
| 271 | protected:
|
---|
| 272 |
|
---|
| 273 | KdNode *GetNodeForPvs(KdLeaf *leaf);
|
---|
| 274 |
|
---|
[441] | 275 | int ComputeSampleContributions(Ray &ray, const bool castRay = true);
|
---|
[440] | 276 |
|
---|
[441] | 277 | /// the BSP tree.
|
---|
| 278 | KdTree *mKdTree;
|
---|
[440] | 279 |
|
---|
[441] | 280 | /// depth of the KD tree nodes with represent the view cells
|
---|
| 281 | int mKdPvsDepth;
|
---|
[440] | 282 | };
|
---|
| 283 |
|
---|
| 284 | /**
|
---|
| 285 | Manages different higher order operations on the view cells
|
---|
| 286 | for vsp kd tree view cells.
|
---|
| 287 | */
|
---|
| 288 | class VspKdViewCellsManager: public ViewCellsManager
|
---|
| 289 | {
|
---|
| 290 |
|
---|
| 291 | public:
|
---|
| 292 |
|
---|
| 293 | VspKdViewCellsManager(VspKdTree *vspKdTree, int constructionSamples);
|
---|
| 294 |
|
---|
| 295 | int Construct(const ObjectContainer &objects,
|
---|
| 296 | const VssRayContainer &rays,
|
---|
| 297 | AxisAlignedBox3 *sceneBbox);
|
---|
| 298 |
|
---|
[441] | 299 | int ComputeSampleContributions(Ray &ray, const bool castRay = true);
|
---|
[440] | 300 |
|
---|
| 301 | int PostProcess(const ObjectContainer &objects,
|
---|
| 302 | const RayContainer &rays);
|
---|
| 303 |
|
---|
| 304 | void Visualize(const ObjectContainer &objects,
|
---|
| 305 | const RayContainer &sampleRays);
|
---|
| 306 |
|
---|
| 307 | int GetType() const;
|
---|
| 308 |
|
---|
| 309 | bool ViewCellsConstructed() const;
|
---|
| 310 |
|
---|
| 311 |
|
---|
| 312 | protected:
|
---|
| 313 |
|
---|
| 314 | /// the BSP tree.
|
---|
| 315 | VspKdTree *mVspKdTree;
|
---|
| 316 | };
|
---|
| 317 |
|
---|
| 318 |
|
---|
[442] | 319 |
|
---|
| 320 | /**
|
---|
| 321 | Manages different higher order operations on the view cells.
|
---|
| 322 | */
|
---|
| 323 | class VspBspViewCellsManager: public ViewCellsManager
|
---|
| 324 | {
|
---|
| 325 |
|
---|
| 326 | public:
|
---|
| 327 |
|
---|
| 328 | VspBspViewCellsManager(VspBspTree *tree, int constructionSamples);
|
---|
| 329 |
|
---|
| 330 | int Construct(const ObjectContainer &objects,
|
---|
| 331 | const VssRayContainer &rays,
|
---|
| 332 | AxisAlignedBox3 *sceneBbox);
|
---|
| 333 |
|
---|
| 334 | int ComputeSampleContributions(Ray &ray, const bool castRay = false);
|
---|
| 335 |
|
---|
| 336 | int PostProcess(const ObjectContainer &objects,
|
---|
| 337 | const RayContainer &rays);
|
---|
| 338 |
|
---|
| 339 | void Visualize(const ObjectContainer &objects,
|
---|
| 340 | const RayContainer &sampleRays);
|
---|
| 341 |
|
---|
| 342 | int GetType() const;
|
---|
| 343 |
|
---|
| 344 | ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
|
---|
| 345 |
|
---|
| 346 | bool ViewCellsConstructed() const;
|
---|
| 347 |
|
---|
| 348 | protected:
|
---|
| 349 |
|
---|
| 350 | /** Merges view cells front and back leaf view cell.
|
---|
| 351 | */
|
---|
| 352 | bool MergeVspBspLeafViewCells(VspBspLeaf *front, VspBspLeaf *back) const;
|
---|
| 353 |
|
---|
| 354 | /** Returns true if front and back leaf should be merged.
|
---|
| 355 | */
|
---|
| 356 | bool ShouldMerge(VspBspLeaf *front, VspBspLeaf *back) const;
|
---|
| 357 |
|
---|
| 358 | /// the view space partition BSP tree.
|
---|
| 359 | VspBspTree *mVspBspTree;
|
---|
| 360 |
|
---|
| 361 |
|
---|
| 362 | private:
|
---|
| 363 |
|
---|
| 364 |
|
---|
| 365 | /** Exports visualization of the BSP splits.
|
---|
| 366 | */
|
---|
| 367 | void ExportSplits(const ObjectContainer &objects, const RayContainer &sampleRays);
|
---|
| 368 |
|
---|
| 369 | /** Exports visualization of the BSP PVS.
|
---|
| 370 | */
|
---|
| 371 | void ExportBspPvs(const ObjectContainer &objects, const RayContainer &sampleRays);
|
---|
| 372 |
|
---|
| 373 | };
|
---|
| 374 |
|
---|
[440] | 375 | #endif
|
---|