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