[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:
|
---|
[467] | 31 | struct PvsStatistics {
|
---|
| 32 | int minPvs;
|
---|
| 33 | int maxPvs;
|
---|
| 34 | float avgPvs;
|
---|
| 35 | int viewcells;
|
---|
| 36 | };
|
---|
[466] | 37 |
|
---|
| 38 | /// view cell container types
|
---|
| 39 | enum {BSP, KD, VSP_KD, VSP_BSP};
|
---|
| 40 |
|
---|
[440] | 41 | /** Constructor taking the maximal number of samples used for construction
|
---|
| 42 | */
|
---|
| 43 | ViewCellsManager(const int constructionSamples);
|
---|
| 44 |
|
---|
| 45 | ViewCellsManager();
|
---|
| 46 |
|
---|
[462] | 47 | virtual ~ViewCellsManager();
|
---|
[440] | 48 |
|
---|
| 49 | /** Constructs view cell container with a given number of samples.
|
---|
| 50 | */
|
---|
| 51 | virtual int Construct(const ObjectContainer &objects,
|
---|
| 52 | const VssRayContainer &rays,
|
---|
| 53 | AxisAlignedBox3 *sceneBbox = NULL) = 0;
|
---|
| 54 |
|
---|
[441] | 55 | /** Computes sample contributions of the rays to the view cells PVS.
|
---|
| 56 |
|
---|
| 57 | @param rays bundle of rays used to find intersections with view cells and
|
---|
| 58 | adding the contribution
|
---|
| 59 | @param castRays true if ray should be cast to gain the information, false if rays
|
---|
| 60 | already hold the view cells intersection information and need not be recast.
|
---|
| 61 | @param sampleContributions returns the number of sample contributions
|
---|
| 62 | @param contributingSamples returns the number of contributingSamples
|
---|
[440] | 63 | */
|
---|
[468] | 64 | void ComputeSampleContributions(const VssRayContainer &rays);
|
---|
[440] | 65 |
|
---|
[441] | 66 |
|
---|
[466] | 67 | /** Computes sample contribution of a simgle ray to the view cells PVS.
|
---|
| 68 | @param ray finds intersections with view cells and holds the contribution
|
---|
| 69 | @param castRay true if ray should be cast to gain the information, false if ray
|
---|
| 70 | is already holding the information and need not be recast.
|
---|
| 71 |
|
---|
| 72 | @returns number of sample contributions
|
---|
| 73 | */
|
---|
| 74 | virtual void ComputeSampleContributions(VssRay &ray
|
---|
| 75 | );
|
---|
| 76 |
|
---|
[452] | 77 | /** Prints out statistics of the view cells.
|
---|
| 78 | */
|
---|
| 79 | virtual void PrintStatistics(ostream &s) const = 0;
|
---|
| 80 |
|
---|
[440] | 81 | /** Post processes view cells givemŽa number of rays.
|
---|
| 82 | */
|
---|
[466] | 83 | virtual int PostProcess(const ObjectContainer &objects,
|
---|
| 84 | const VssRayContainer &rays) = 0;
|
---|
[440] | 85 |
|
---|
| 86 | /** Show visualization of the view cells.
|
---|
| 87 | */
|
---|
| 88 | virtual void Visualize(const ObjectContainer &objects,
|
---|
[466] | 89 | const VssRayContainer &sampleRays) = 0;
|
---|
[440] | 90 |
|
---|
| 91 | /** type of the view cell container.
|
---|
| 92 | */
|
---|
| 93 | virtual int GetType() const = 0;
|
---|
| 94 |
|
---|
[463] | 95 | /** Load the input viewcells. The input viewcells should be given as a collection
|
---|
| 96 | of meshes. Each mesh is assume to form a bounded polyhedron defining the interior of
|
---|
| 97 | the viewcell. The method then builds a BSP tree of these view cells.
|
---|
| 98 |
|
---|
| 99 | @param filename file to load
|
---|
| 100 | @return true on success
|
---|
| 101 | */
|
---|
[440] | 102 | bool LoadViewCells(const string filename);
|
---|
| 103 |
|
---|
| 104 | /** Constructs view cell from base triangle. The ViewCell is extruded along the normal vector.
|
---|
| 105 | @param the base triangle
|
---|
| 106 | @param the height of the newly created view cell
|
---|
| 107 | */
|
---|
| 108 | ViewCell *ExtrudeViewCell(const Triangle3 &baseTri, const float height) const;
|
---|
| 109 |
|
---|
| 110 | /** Merges two view cells.
|
---|
| 111 | @note the piercing rays of the front and back will be ordered
|
---|
| 112 | @returns new view cell based on the merging.
|
---|
| 113 | */
|
---|
[441] | 114 | ViewCell *MergeViewCells(ViewCell &front, ViewCell &back) const;
|
---|
[440] | 115 |
|
---|
| 116 | /** Generates view cell of type specified by this manager
|
---|
| 117 | */
|
---|
| 118 | virtual ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
|
---|
| 119 |
|
---|
| 120 | /** Adds a new view cell to the list of predefined view cells.
|
---|
| 121 | */
|
---|
| 122 | void AddViewCell(ViewCell *viewCell);
|
---|
| 123 |
|
---|
| 124 | /** Derive view cells from objects.
|
---|
| 125 | */
|
---|
| 126 | void DeriveViewCells(const ObjectContainer &objects,
|
---|
| 127 | ViewCellContainer &viewCells,
|
---|
| 128 | const int maxViewCells) const;
|
---|
| 129 |
|
---|
| 130 | /** Sets maximal number of samples used for the
|
---|
| 131 | construction of the view cells.
|
---|
| 132 | */
|
---|
| 133 | void SetVisualizationSamples(const int visSamples);
|
---|
| 134 |
|
---|
| 135 | /** Sets maximal number of samples used for the visualization of the view cells.
|
---|
| 136 | */
|
---|
| 137 | void SetConstructionSamples(const int constructionSamples);
|
---|
| 138 |
|
---|
| 139 | /** Sets maximal number of samples used for the post processing of the view cells.
|
---|
| 140 | */
|
---|
| 141 | void SetPostProcessSamples(const int postProcessingSamples);
|
---|
| 142 |
|
---|
| 143 | /** See set.
|
---|
| 144 | */
|
---|
| 145 | int GetVisualizationSamples() const;
|
---|
| 146 |
|
---|
| 147 | /** See set.
|
---|
| 148 | */
|
---|
| 149 | int GetConstructionSamples() const;
|
---|
| 150 |
|
---|
| 151 | /** See set.
|
---|
| 152 | */
|
---|
| 153 | int GetPostProcessSamples() const;
|
---|
| 154 |
|
---|
| 155 | /** Returns true if view cells wer already constructed.
|
---|
| 156 | */
|
---|
| 157 | virtual bool ViewCellsConstructed() const = 0;
|
---|
[441] | 158 |
|
---|
[466] | 159 | /** cast line segment to get a list of unique viewcells which are intersected
|
---|
| 160 | by this line segment */
|
---|
| 161 |
|
---|
| 162 | virtual int CastLineSegment(const Vector3 &origin,
|
---|
| 163 | const Vector3 &termination,
|
---|
| 164 | ViewCellContainer &viewcells
|
---|
| 165 | ) = 0;
|
---|
| 166 |
|
---|
[467] | 167 | virtual void GetPvsStatistics(PvsStatistics &stat);
|
---|
[466] | 168 |
|
---|
[467] | 169 | virtual void
|
---|
| 170 | PrintPvsStatistics(ostream &s);
|
---|
| 171 |
|
---|
[468] | 172 | /** Returns probability that view point lies in one view cell.
|
---|
| 173 | */
|
---|
| 174 | virtual float GetProbability(ViewCell *viewCell) = 0;
|
---|
| 175 |
|
---|
| 176 | /** Returns render cost of a single view cell given the render cost of an object.
|
---|
| 177 | */
|
---|
| 178 | virtual float GetRendercost(ViewCell *viewCell, float objRendercost) = 0;
|
---|
| 179 |
|
---|
| 180 | /** Returns vector of loaded / generated view cells.
|
---|
| 181 | */
|
---|
| 182 | ViewCellContainer &GetViewCells();
|
---|
| 183 |
|
---|
[440] | 184 | protected:
|
---|
[441] | 185 |
|
---|
[440] | 186 |
|
---|
| 187 | /** Initialises the render time simulator.
|
---|
| 188 | */
|
---|
| 189 | void InitRenderSimulator();
|
---|
| 190 | /////////////////////
|
---|
| 191 |
|
---|
| 192 |
|
---|
| 193 | /// the view cell corresponding to unbounded space
|
---|
| 194 | ViewCell *mUnbounded;
|
---|
| 195 |
|
---|
| 196 | /// Simulates rendering
|
---|
| 197 | RenderSimulator *mRenderSimulator;
|
---|
| 198 |
|
---|
| 199 | /// Loaded view cells
|
---|
[467] | 200 | ViewCellContainer mViewCells;
|
---|
[440] | 201 |
|
---|
| 202 | /// maximum number of samples taken for construction of the view cells
|
---|
| 203 | int mConstructionSamples;
|
---|
| 204 | int mPostProcessSamples;
|
---|
| 205 | int mVisualizationSamples;
|
---|
[441] | 206 |
|
---|
[463] | 207 | //-- thresholds used for view cells merge
|
---|
| 208 | int mMinPvsDif;
|
---|
| 209 | int mMinPvs;
|
---|
[441] | 210 | int mMaxPvs;
|
---|
[440] | 211 | };
|
---|
| 212 |
|
---|
[441] | 213 |
|
---|
| 214 |
|
---|
[440] | 215 | /**
|
---|
| 216 | Manages different higher order operations on the view cells.
|
---|
| 217 | */
|
---|
| 218 | class BspViewCellsManager: public ViewCellsManager
|
---|
| 219 | {
|
---|
| 220 |
|
---|
| 221 | public:
|
---|
| 222 |
|
---|
| 223 | BspViewCellsManager(BspTree *tree, int constructionSamples);
|
---|
| 224 |
|
---|
| 225 | int Construct(const ObjectContainer &objects,
|
---|
| 226 | const VssRayContainer &rays,
|
---|
| 227 | AxisAlignedBox3 *sceneBbox);
|
---|
| 228 |
|
---|
| 229 |
|
---|
| 230 | int PostProcess(const ObjectContainer &objects,
|
---|
[466] | 231 | const VssRayContainer &rays);
|
---|
[440] | 232 |
|
---|
| 233 | void Visualize(const ObjectContainer &objects,
|
---|
[466] | 234 | const VssRayContainer &sampleRays);
|
---|
[440] | 235 |
|
---|
| 236 | int GetType() const;
|
---|
| 237 |
|
---|
| 238 | ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
|
---|
| 239 |
|
---|
| 240 | bool ViewCellsConstructed() const;
|
---|
| 241 |
|
---|
[452] | 242 | void PrintStatistics(ostream &s) const;
|
---|
| 243 |
|
---|
[462] | 244 | ~BspViewCellsManager();
|
---|
[466] | 245 |
|
---|
[468] | 246 | int CastLineSegment(const Vector3 &origin,
|
---|
| 247 | const Vector3 &termination,
|
---|
| 248 | ViewCellContainer &viewcells);
|
---|
| 249 |
|
---|
| 250 | float GetProbability(ViewCell *viewCell);
|
---|
| 251 | float GetRendercost(ViewCell *viewCell, float objRendercost);
|
---|
[466] | 252 |
|
---|
[440] | 253 | protected:
|
---|
| 254 |
|
---|
[441] | 255 | /** Merges view cells front and back leaf view cell.
|
---|
| 256 | */
|
---|
| 257 | bool MergeBspLeafViewCells(BspLeaf *front, BspLeaf *back) const;
|
---|
[440] | 258 |
|
---|
[441] | 259 | /** Returns true if front and back leaf should be merged.
|
---|
| 260 | */
|
---|
| 261 | bool ShouldMerge(BspLeaf *front, BspLeaf *back) const;
|
---|
| 262 |
|
---|
[440] | 263 | /// the BSP tree.
|
---|
| 264 | BspTree *mBspTree;
|
---|
| 265 |
|
---|
| 266 |
|
---|
| 267 | private:
|
---|
| 268 |
|
---|
| 269 |
|
---|
| 270 | /** Exports visualization of the BSP splits.
|
---|
| 271 | */
|
---|
[466] | 272 | void ExportSplits(const ObjectContainer &objects, const VssRayContainer &sampleRays);
|
---|
[440] | 273 |
|
---|
| 274 | /** Exports visualization of the BSP PVS.
|
---|
| 275 | */
|
---|
[466] | 276 | void ExportBspPvs(const ObjectContainer &objects, const VssRayContainer &sampleRays);
|
---|
[440] | 277 |
|
---|
| 278 | };
|
---|
| 279 |
|
---|
| 280 | /**
|
---|
| 281 | Manages different higher order operations on the KD type view cells.
|
---|
| 282 | */
|
---|
| 283 | class KdViewCellsManager: public ViewCellsManager
|
---|
| 284 | {
|
---|
| 285 |
|
---|
| 286 | public:
|
---|
| 287 |
|
---|
| 288 | KdViewCellsManager(KdTree *tree);
|
---|
| 289 |
|
---|
| 290 | int Construct(const ObjectContainer &objects,
|
---|
| 291 | const VssRayContainer &rays,
|
---|
| 292 | AxisAlignedBox3 *sceneBbox);
|
---|
| 293 |
|
---|
[466] | 294 | int CastLineSegment(const Vector3 &origin,
|
---|
| 295 | const Vector3 &termination,
|
---|
| 296 | ViewCellContainer &viewcells
|
---|
| 297 | ) ;
|
---|
[440] | 298 |
|
---|
| 299 | int PostProcess(const ObjectContainer &objects,
|
---|
[466] | 300 | const VssRayContainer &rays);
|
---|
[440] | 301 |
|
---|
| 302 | void Visualize(const ObjectContainer &objects,
|
---|
[466] | 303 | const VssRayContainer &sampleRays);
|
---|
[440] | 304 |
|
---|
| 305 | int GetType() const;
|
---|
| 306 |
|
---|
| 307 | bool ViewCellsConstructed() const;
|
---|
| 308 |
|
---|
| 309 |
|
---|
[452] | 310 | /** Prints out statistics of this approach.
|
---|
| 311 | */
|
---|
| 312 | virtual void PrintStatistics(ostream &s) const;
|
---|
| 313 |
|
---|
[468] | 314 | float GetProbability(ViewCell *viewCell);
|
---|
| 315 | float GetRendercost(ViewCell *viewCell, float objRendercost);
|
---|
| 316 |
|
---|
[440] | 317 | protected:
|
---|
| 318 |
|
---|
| 319 | KdNode *GetNodeForPvs(KdLeaf *leaf);
|
---|
| 320 |
|
---|
| 321 |
|
---|
[441] | 322 | /// the BSP tree.
|
---|
| 323 | KdTree *mKdTree;
|
---|
[440] | 324 |
|
---|
[441] | 325 | /// depth of the KD tree nodes with represent the view cells
|
---|
| 326 | int mKdPvsDepth;
|
---|
[440] | 327 | };
|
---|
| 328 |
|
---|
| 329 | /**
|
---|
| 330 | Manages different higher order operations on the view cells
|
---|
| 331 | for vsp kd tree view cells.
|
---|
| 332 | */
|
---|
| 333 | class VspKdViewCellsManager: public ViewCellsManager
|
---|
| 334 | {
|
---|
| 335 |
|
---|
| 336 | public:
|
---|
| 337 |
|
---|
| 338 | VspKdViewCellsManager(VspKdTree *vspKdTree, int constructionSamples);
|
---|
| 339 |
|
---|
[462] | 340 | ~VspKdViewCellsManager();
|
---|
| 341 |
|
---|
[440] | 342 | int Construct(const ObjectContainer &objects,
|
---|
| 343 | const VssRayContainer &rays,
|
---|
| 344 | AxisAlignedBox3 *sceneBbox);
|
---|
| 345 |
|
---|
| 346 |
|
---|
| 347 | int PostProcess(const ObjectContainer &objects,
|
---|
[466] | 348 | const VssRayContainer &rays);
|
---|
[440] | 349 |
|
---|
| 350 | void Visualize(const ObjectContainer &objects,
|
---|
[466] | 351 | const VssRayContainer &sampleRays);
|
---|
[440] | 352 |
|
---|
| 353 | int GetType() const;
|
---|
| 354 |
|
---|
| 355 | bool ViewCellsConstructed() const;
|
---|
| 356 |
|
---|
[452] | 357 | virtual void PrintStatistics(ostream &s) const;
|
---|
[440] | 358 |
|
---|
[462] | 359 | ViewCell *GenerateViewCell(Mesh *mesh) const;
|
---|
| 360 |
|
---|
[466] | 361 |
|
---|
| 362 | int CastLineSegment(const Vector3 &origin,
|
---|
| 363 | const Vector3 &termination,
|
---|
[468] | 364 | ViewCellContainer &viewcells);
|
---|
[466] | 365 |
|
---|
[468] | 366 | float GetProbability(ViewCell *viewCell);
|
---|
| 367 | float GetRendercost(ViewCell *viewCell, float objRendercost);
|
---|
| 368 |
|
---|
[440] | 369 | protected:
|
---|
| 370 |
|
---|
| 371 | /// the BSP tree.
|
---|
| 372 | VspKdTree *mVspKdTree;
|
---|
| 373 | };
|
---|
| 374 |
|
---|
| 375 |
|
---|
[442] | 376 |
|
---|
| 377 | /**
|
---|
| 378 | Manages different higher order operations on the view cells.
|
---|
| 379 | */
|
---|
| 380 | class VspBspViewCellsManager: public ViewCellsManager
|
---|
| 381 | {
|
---|
| 382 |
|
---|
| 383 | public:
|
---|
| 384 |
|
---|
| 385 | VspBspViewCellsManager(VspBspTree *tree, int constructionSamples);
|
---|
| 386 |
|
---|
[462] | 387 | ~VspBspViewCellsManager();
|
---|
| 388 |
|
---|
[442] | 389 | int Construct(const ObjectContainer &objects,
|
---|
| 390 | const VssRayContainer &rays,
|
---|
| 391 | AxisAlignedBox3 *sceneBbox);
|
---|
| 392 |
|
---|
| 393 |
|
---|
| 394 | int PostProcess(const ObjectContainer &objects,
|
---|
[466] | 395 | const VssRayContainer &rays);
|
---|
[442] | 396 |
|
---|
| 397 | void Visualize(const ObjectContainer &objects,
|
---|
[466] | 398 | const VssRayContainer &sampleRays);
|
---|
[442] | 399 |
|
---|
| 400 | int GetType() const;
|
---|
| 401 |
|
---|
| 402 | ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
|
---|
| 403 |
|
---|
| 404 | bool ViewCellsConstructed() const;
|
---|
| 405 |
|
---|
[452] | 406 | void PrintStatistics(ostream &s) const;
|
---|
[468] | 407 |
|
---|
| 408 | int CastLineSegment(const Vector3 &origin,
|
---|
| 409 | const Vector3 &termination,
|
---|
| 410 | ViewCellContainer &viewcells);
|
---|
[452] | 411 |
|
---|
[468] | 412 | float GetProbability(ViewCell *viewCell);
|
---|
| 413 | float GetRendercost(ViewCell *viewCell, float objRendercost);
|
---|
[466] | 414 |
|
---|
[468] | 415 |
|
---|
[442] | 416 | protected:
|
---|
| 417 |
|
---|
| 418 | /** Merges view cells front and back leaf view cell.
|
---|
| 419 | */
|
---|
[448] | 420 | bool MergeVspBspLeafViewCells(BspLeaf *front, BspLeaf *back) const;
|
---|
[442] | 421 |
|
---|
| 422 | /** Returns true if front and back leaf should be merged.
|
---|
| 423 | */
|
---|
[448] | 424 | bool ShouldMerge(BspLeaf *front, BspLeaf *back) const;
|
---|
[442] | 425 |
|
---|
| 426 | /// the view space partition BSP tree.
|
---|
| 427 | VspBspTree *mVspBspTree;
|
---|
| 428 |
|
---|
| 429 |
|
---|
| 430 | private:
|
---|
| 431 |
|
---|
| 432 |
|
---|
| 433 | /** Exports visualization of the BSP splits.
|
---|
| 434 | */
|
---|
[466] | 435 | void ExportSplits(const ObjectContainer &objects, const VssRayContainer &sampleRays);
|
---|
[442] | 436 |
|
---|
| 437 | /** Exports visualization of the BSP PVS.
|
---|
| 438 | */
|
---|
[466] | 439 | void ExportBspPvs(const ObjectContainer &objects, const VssRayContainer &sampleRays);
|
---|
[442] | 440 |
|
---|
| 441 | };
|
---|
| 442 |
|
---|
[440] | 443 | #endif
|
---|