[440] | 1 | #ifndef _ViewCellsManager_H__
|
---|
| 2 | #define _ViewCellsManager_H__
|
---|
| 3 |
|
---|
| 4 | #include "Ray.h"
|
---|
| 5 | #include "VssRay.h"
|
---|
| 6 | #include "Containers.h"
|
---|
[475] | 7 | #include "ViewCell.h"
|
---|
[610] | 8 | #include "ViewCellBsp.h"
|
---|
[440] | 9 |
|
---|
| 10 | class ViewCell;
|
---|
| 11 | class Intersectable;
|
---|
| 12 | class RenderSimulator;
|
---|
[480] | 13 | class Renderer;
|
---|
[440] | 14 | class Mesh;
|
---|
| 15 | struct Triangle3;
|
---|
| 16 | class SimulationStatistics;
|
---|
| 17 | class BspTree;
|
---|
| 18 | class KdTree;
|
---|
| 19 | class VspKdTree;
|
---|
| 20 | class VspBspTree;
|
---|
| 21 | class KdNode;
|
---|
| 22 | class KdLeaf;
|
---|
| 23 | class VspKdTree;
|
---|
| 24 | class AxisAlignedBox3;
|
---|
[448] | 25 | class BspLeaf;
|
---|
[475] | 26 | class ViewCellsStatistics;
|
---|
[482] | 27 | class Exporter;
|
---|
[532] | 28 | class Beam;
|
---|
[570] | 29 | class Preprocessor;
|
---|
[580] | 30 | class ViewCellsTree;
|
---|
| 31 | class MergeCandidate;
|
---|
[503] | 32 |
|
---|
[475] | 33 | struct BspRay;
|
---|
| 34 |
|
---|
[677] | 35 |
|
---|
| 36 | /** Probably Visible Set */
|
---|
[697] | 37 | class PrVs
|
---|
| 38 | {
|
---|
| 39 | public:
|
---|
[704] | 40 | /// root of view cells tree
|
---|
| 41 | ViewCell *mViewCell;
|
---|
| 42 |
|
---|
[677] | 43 | // input parameter is the render budget for the PrVS
|
---|
| 44 | float mRenderBudget;
|
---|
| 45 |
|
---|
| 46 | /// some characteristic values could be here
|
---|
| 47 |
|
---|
| 48 | };
|
---|
| 49 |
|
---|
[440] | 50 | /**
|
---|
| 51 | Manages different higher order operations on the view cells.
|
---|
| 52 | */
|
---|
| 53 | class ViewCellsManager
|
---|
| 54 | {
|
---|
| 55 | public:
|
---|
[728] | 56 | struct PvsStatistics
|
---|
| 57 | {
|
---|
| 58 | int minPvs;
|
---|
| 59 | int maxPvs;
|
---|
| 60 | float avgPvs;
|
---|
| 61 | int viewcells;
|
---|
[467] | 62 | };
|
---|
[697] | 63 |
|
---|
[728] | 64 | /// view cell container types
|
---|
| 65 | enum {BSP, KD, VSP_KD, VSP_BSP};
|
---|
[466] | 66 |
|
---|
[728] | 67 | /// view cells evaluation type
|
---|
| 68 | enum {PER_OBJECT, PER_TRIANGLE};
|
---|
| 69 |
|
---|
[574] | 70 | /** Constructor taking the initial and construction samples.
|
---|
| 71 | @param initialSamples the maximal number of samples used for creating the hierarchy
|
---|
| 72 | of view cells
|
---|
| 73 | @param constructionSamples the maximal number of samples used for construction
|
---|
[440] | 74 | */
|
---|
[574] | 75 | ViewCellsManager(const int initialSamples, const int constructionSamples);
|
---|
[440] | 76 |
|
---|
| 77 | ViewCellsManager();
|
---|
| 78 |
|
---|
[462] | 79 | virtual ~ViewCellsManager();
|
---|
[440] | 80 |
|
---|
[527] | 81 | /** Constructs view cells container taking a preprocessor
|
---|
[570] | 82 | @returns the output rays (if not null)
|
---|
| 83 | */
|
---|
| 84 | int Construct(Preprocessor *preprocessor, VssRayContainer *outRays = NULL);
|
---|
[527] | 85 |
|
---|
[440] | 86 | /** Constructs view cell container with a given number of samples.
|
---|
| 87 | */
|
---|
[574] | 88 | virtual int ConstructSubdivision(const ObjectContainer &objects,
|
---|
[487] | 89 | const VssRayContainer &rays) = 0;
|
---|
[440] | 90 |
|
---|
[441] | 91 | /** Computes sample contributions of the rays to the view cells PVS.
|
---|
| 92 |
|
---|
| 93 | @param rays bundle of rays used to find intersections with view cells and
|
---|
| 94 | adding the contribution
|
---|
[563] | 95 | @param addRays true if rays should be added to the PVSs of the viewcells they
|
---|
[574] | 96 | intersect
|
---|
| 97 | @param storeViewCells true if view cells should be stored in the ray
|
---|
| 98 | */
|
---|
[697] | 99 | float ComputeSampleContributions(const VssRayContainer &rays,
|
---|
[574] | 100 | const bool addContributions,
|
---|
| 101 | const bool storeViewCells);
|
---|
[440] | 102 |
|
---|
[697] | 103 | /** Add sample contributions to the viewcells they intersect */
|
---|
| 104 | void AddSampleContributions(const VssRayContainer &rays);
|
---|
[563] | 105 |
|
---|
[441] | 106 |
|
---|
[475] | 107 | /** Computes sample contribution of a simgle ray to the view cells PVS.
|
---|
| 108 | @param ray finds intersections with view cells and holds the contribution
|
---|
| 109 | @param castRay true if ray should be cast to gain the information, false if ray
|
---|
| 110 | is already holding the information and need not be recast.
|
---|
[466] | 111 |
|
---|
[475] | 112 | @returns number of sample contributions
|
---|
| 113 | */
|
---|
[591] | 114 | virtual float ComputeSampleContributions(VssRay &ray,
|
---|
| 115 | const bool addRays,
|
---|
| 116 | const bool storeViewCells);
|
---|
[563] | 117 |
|
---|
[591] | 118 | virtual void AddSampleContributions(VssRay &ray);
|
---|
[563] | 119 |
|
---|
[452] | 120 | /** Prints out statistics of the view cells.
|
---|
| 121 | */
|
---|
[475] | 122 | virtual void PrintStatistics(ostream &s) const;
|
---|
[452] | 123 |
|
---|
[440] | 124 | /** Post processes view cells givemŽa number of rays.
|
---|
| 125 | */
|
---|
[475] | 126 | virtual int PostProcess(const ObjectContainer &objects,
|
---|
| 127 | const VssRayContainer &rays) = 0;
|
---|
[440] | 128 |
|
---|
| 129 | /** Show visualization of the view cells.
|
---|
| 130 | */
|
---|
| 131 | virtual void Visualize(const ObjectContainer &objects,
|
---|
[466] | 132 | const VssRayContainer &sampleRays) = 0;
|
---|
[440] | 133 |
|
---|
| 134 | /** type of the view cell container.
|
---|
| 135 | */
|
---|
| 136 | virtual int GetType() const = 0;
|
---|
| 137 |
|
---|
[463] | 138 | /** Load the input viewcells. The input viewcells should be given as a collection
|
---|
| 139 | of meshes. Each mesh is assume to form a bounded polyhedron defining the interior of
|
---|
| 140 | the viewcell. The method then builds a BSP tree of these view cells.
|
---|
| 141 |
|
---|
| 142 | @param filename file to load
|
---|
| 143 | @return true on success
|
---|
| 144 | */
|
---|
[577] | 145 | virtual bool LoadViewCellsGeometry(const string filename);
|
---|
[440] | 146 |
|
---|
[577] | 147 |
|
---|
[440] | 148 | /** Constructs view cell from base triangle. The ViewCell is extruded along the normal vector.
|
---|
| 149 | @param the base triangle
|
---|
| 150 | @param the height of the newly created view cell
|
---|
| 151 | */
|
---|
| 152 | ViewCell *ExtrudeViewCell(const Triangle3 &baseTri, const float height) const;
|
---|
| 153 |
|
---|
| 154 | /** Merges two view cells.
|
---|
| 155 | @note the piercing rays of the front and back will be ordered
|
---|
| 156 | @returns new view cell based on the merging.
|
---|
| 157 | */
|
---|
[582] | 158 | ViewCellInterior *MergeViewCells(ViewCell *front, ViewCell *back) const;
|
---|
| 159 |
|
---|
| 160 | /** Merges a container of view cells.
|
---|
| 161 | @returns new view cell based on the merging.
|
---|
| 162 | */
|
---|
| 163 | ViewCellInterior *MergeViewCells(ViewCellContainer &children) const;
|
---|
[440] | 164 |
|
---|
| 165 | /** Generates view cell of type specified by this manager
|
---|
| 166 | */
|
---|
[580] | 167 | virtual ViewCell *GenerateViewCell(Mesh *mesh = NULL) const = 0;
|
---|
[440] | 168 |
|
---|
| 169 | /** Adds a new view cell to the list of predefined view cells.
|
---|
| 170 | */
|
---|
| 171 | void AddViewCell(ViewCell *viewCell);
|
---|
| 172 |
|
---|
| 173 | /** Derive view cells from objects.
|
---|
| 174 | */
|
---|
| 175 | void DeriveViewCells(const ObjectContainer &objects,
|
---|
| 176 | ViewCellContainer &viewCells,
|
---|
| 177 | const int maxViewCells) const;
|
---|
| 178 |
|
---|
| 179 | /** Sets maximal number of samples used for the
|
---|
| 180 | construction of the view cells.
|
---|
| 181 | */
|
---|
| 182 | void SetVisualizationSamples(const int visSamples);
|
---|
| 183 |
|
---|
[574] | 184 | /** Sets maximal number of samples used for the construction of the view cells.
|
---|
[440] | 185 | */
|
---|
| 186 | void SetConstructionSamples(const int constructionSamples);
|
---|
| 187 |
|
---|
[574] | 188 | /** Sets maximal number of samples used for the visualization of the view cells.
|
---|
| 189 | */
|
---|
| 190 | void SetInitialSamples(const int initialSamples);
|
---|
| 191 |
|
---|
[440] | 192 | /** Sets maximal number of samples used for the post processing of the view cells.
|
---|
| 193 | */
|
---|
| 194 | void SetPostProcessSamples(const int postProcessingSamples);
|
---|
| 195 |
|
---|
| 196 | /** See set.
|
---|
| 197 | */
|
---|
| 198 | int GetVisualizationSamples() const;
|
---|
| 199 |
|
---|
| 200 | /** See set.
|
---|
| 201 | */
|
---|
| 202 | int GetConstructionSamples() const;
|
---|
| 203 |
|
---|
| 204 | /** See set.
|
---|
| 205 | */
|
---|
| 206 | int GetPostProcessSamples() const;
|
---|
| 207 |
|
---|
| 208 | /** Returns true if view cells wer already constructed.
|
---|
| 209 | */
|
---|
| 210 | virtual bool ViewCellsConstructed() const = 0;
|
---|
[441] | 211 |
|
---|
[477] | 212 | /** cast line segment to get a list of unique viewcells which are intersected
|
---|
| 213 | by this line segment
|
---|
| 214 | */
|
---|
[466] | 215 |
|
---|
[477] | 216 | virtual int CastLineSegment(const Vector3 &origin,
|
---|
[466] | 217 | const Vector3 &termination,
|
---|
| 218 | ViewCellContainer &viewcells
|
---|
| 219 | ) = 0;
|
---|
| 220 |
|
---|
[477] | 221 | virtual void GetPvsStatistics(PvsStatistics &stat);
|
---|
[466] | 222 |
|
---|
[697] | 223 | virtual void GetPrVS(const Vector3 &viewPoint, PrVs &prvs);
|
---|
[677] | 224 |
|
---|
[697] | 225 | /** Get a viewcell containing the specified point
|
---|
| 226 | */
|
---|
[569] | 227 | virtual ViewCell *GetViewCell(const Vector3 &point) const = 0;
|
---|
[492] | 228 |
|
---|
[503] | 229 | virtual void PrintPvsStatistics(ostream &s);
|
---|
[467] | 230 |
|
---|
[719] | 231 | /** Updates pvs of the view cell hierarchy if necessary.
|
---|
| 232 | */
|
---|
| 233 | void UpdatePvs();
|
---|
| 234 |
|
---|
[477] | 235 | /** Returns probability that view point lies in one view cell.
|
---|
| 236 | */
|
---|
| 237 | virtual float GetProbability(ViewCell *viewCell) = 0;
|
---|
[468] | 238 |
|
---|
[477] | 239 | /** Returns render cost of a single view cell given the render cost of an object.
|
---|
| 240 | */
|
---|
[728] | 241 | float GetRendercost(ViewCell *viewCell) const;
|
---|
[468] | 242 |
|
---|
[720] | 243 | /** Returns reference to container of loaded / generated view cells.
|
---|
[477] | 244 | */
|
---|
| 245 | ViewCellContainer &GetViewCells();
|
---|
[468] | 246 |
|
---|
[485] | 247 | /** Helper function used to split ray sets uniformly
|
---|
| 248 | into one that is currently used and the other that
|
---|
| 249 | is saved for later processing.
|
---|
| 250 | @param sourceRays the input ray set
|
---|
| 251 | @param maxSize the maximal number of rays that will be used
|
---|
| 252 | @param usedRays returns the used ray set
|
---|
| 253 | @param savedRays if not null, returns the saved ray set
|
---|
[477] | 254 | */
|
---|
| 255 | void GetRaySets(const VssRayContainer &sourceRays,
|
---|
[485] | 256 | const int maxSize,
|
---|
| 257 | VssRayContainer &usedRays,
|
---|
| 258 | VssRayContainer *savedRays = NULL) const;
|
---|
| 259 |
|
---|
[480] | 260 | /** Returns accumulated area of all view cells.
|
---|
| 261 | */
|
---|
| 262 | float GetAccVcArea();
|
---|
[470] | 263 |
|
---|
[480] | 264 | /** Returns area of one view cell.
|
---|
| 265 | */
|
---|
| 266 | virtual float GetArea(ViewCell *viewCell) const;
|
---|
[470] | 267 |
|
---|
[551] | 268 | /** Returns volume of view cell.
|
---|
[480] | 269 | */
|
---|
| 270 | virtual float GetVolume(ViewCell *viewCell) const;
|
---|
[470] | 271 |
|
---|
[480] | 272 | /** Sets the current renderer mainly for view cells statistics.
|
---|
| 273 | */
|
---|
| 274 | void SetRenderer(Renderer *renderer);
|
---|
| 275 |
|
---|
[487] | 276 | /** Computes a (random) view point in the valid view space.
|
---|
| 277 | @returns true if valid view point was found
|
---|
| 278 | */
|
---|
| 279 | virtual bool GetViewPoint(Vector3 &viewPoint) const;
|
---|
| 280 |
|
---|
[490] | 281 | /** Returns true if this view point is in the valid view space.
|
---|
| 282 | */
|
---|
| 283 | virtual bool ViewPointValid(const Vector3 &viewPoint) const;
|
---|
| 284 |
|
---|
[487] | 285 | /** Sets a view space boundary.
|
---|
| 286 | */
|
---|
| 287 | void SetViewSpaceBox(const AxisAlignedBox3 &box);
|
---|
| 288 |
|
---|
[519] | 289 | AxisAlignedBox3 GetViewSpaceBox() const;
|
---|
| 290 |
|
---|
[503] | 291 | /** Creates mesh for this view cell.
|
---|
| 292 | */
|
---|
| 293 | virtual void CreateMesh(ViewCell *vc) = NULL;
|
---|
[487] | 294 |
|
---|
[508] | 295 | /** Writes view cells to disc.
|
---|
| 296 | */
|
---|
| 297 | virtual bool ExportViewCells(const string filename);
|
---|
| 298 |
|
---|
[532] | 299 | /** Casts beam to collect view cells.
|
---|
| 300 | */
|
---|
| 301 | virtual int CastBeam(Beam &beam);
|
---|
| 302 |
|
---|
[547] | 303 | /** Checks if view cell is considered as valid.
|
---|
| 304 | */
|
---|
[561] | 305 | virtual bool CheckValidity(ViewCell *vc,
|
---|
[562] | 306 | int minPvsSize,
|
---|
| 307 | int maxPvsSize) const;
|
---|
[547] | 308 |
|
---|
[562] | 309 |
|
---|
| 310 | /** Sets validity of view cell
|
---|
| 311 | */
|
---|
| 312 | virtual void SetValidity(ViewCell *vc,
|
---|
| 313 | int minPvsSize,
|
---|
| 314 | int maxPvsSize) const;
|
---|
| 315 |
|
---|
[710] | 316 | /** sets validy of all viewcells
|
---|
| 317 | */
|
---|
[569] | 318 | virtual void SetValidity(
|
---|
| 319 | int minPvsSize,
|
---|
| 320 | int maxPvsSize) const;
|
---|
| 321 |
|
---|
[609] | 322 |
|
---|
| 323 | /** set valid viewcells in the range of pvs. sorts the viewcells
|
---|
[710] | 324 | according to the pvs and then pickups those in the ranges
|
---|
| 325 | */
|
---|
| 326 | void SetValidityPercentage(const float minValid, const float maxValid);
|
---|
[569] | 327 |
|
---|
[609] | 328 | int CountValidViewcells() const;
|
---|
| 329 |
|
---|
[547] | 330 | /** Returns maximal allowed pvs size.
|
---|
| 331 | */
|
---|
| 332 | int GetMaxPvsSize() const;
|
---|
| 333 |
|
---|
[562] | 334 | /** Returns maximal allowed pvs size.
|
---|
| 335 | */
|
---|
| 336 | int GetMinPvsSize() const;
|
---|
| 337 |
|
---|
[561] | 338 | /** Returns maximal ratio. i.e., currentPVs / maxPvs,
|
---|
| 339 | where pvs is still considered valid.
|
---|
| 340 | */
|
---|
| 341 | float GetMaxPvsRatio() const;
|
---|
| 342 |
|
---|
[547] | 343 | /** Exports view cell geometry.
|
---|
| 344 | */
|
---|
[591] | 345 | virtual void ExportViewCellGeometry(Exporter *exporter,
|
---|
| 346 | ViewCell *vc,
|
---|
[660] | 347 | const Plane3 *clipPlane = NULL) const = 0;
|
---|
[547] | 348 |
|
---|
[551] | 349 | virtual void FinalizeViewCells(const bool createMesh);
|
---|
| 350 |
|
---|
[577] | 351 |
|
---|
[591] | 352 | /** Loads view cells from file. The view cells manager is created with
|
---|
| 353 | respect to the loaded view cells.
|
---|
[577] | 354 |
|
---|
| 355 | @returns the view cells manager if loading was successful, false otherwise
|
---|
| 356 | */
|
---|
[591] | 357 | static ViewCellsManager *LoadViewCells(const string filename,
|
---|
| 358 | ObjectContainer *objects);
|
---|
[577] | 359 |
|
---|
[579] | 360 | /** Evaluates statistics values on view cells.
|
---|
| 361 | */
|
---|
[580] | 362 | void EvaluateRenderStatistics(float &totalRenderCost,
|
---|
| 363 | float &expectedRenderCost,
|
---|
| 364 | float &deviation,
|
---|
| 365 | float &variance,
|
---|
| 366 | int &totalPvs,
|
---|
| 367 | float &avgRenderCost);
|
---|
[579] | 368 |
|
---|
[580] | 369 |
|
---|
| 370 | /** Returns hierarchy of the view cells.
|
---|
| 371 | */
|
---|
| 372 | ViewCellsTree *GetViewCellsTree();
|
---|
| 373 |
|
---|
[581] | 374 | virtual void CollectMergeCandidates(const VssRayContainer &rays,
|
---|
| 375 | vector<MergeCandidate> &candidates) = 0;
|
---|
[580] | 376 |
|
---|
[610] | 377 | void CollectViewCells(const int n);
|
---|
| 378 |
|
---|
[660] | 379 | /** Returns true if this (logical) view cell is equal to a spatial node.
|
---|
| 380 | */
|
---|
[710] | 381 | virtual bool EqualToSpatialNode(ViewCell *viewCell) const;
|
---|
[580] | 382 |
|
---|
[660] | 383 | /** Sets current view cells set to active, i.e., the sampling is done in this view cell set.
|
---|
| 384 | */
|
---|
| 385 | void SetViewCellsActive();
|
---|
[599] | 386 |
|
---|
[660] | 387 | /** Evaluates worth of current view cell hierarchy.
|
---|
| 388 | */
|
---|
[664] | 389 | void EvalViewCellPartition(Preprocessor *preprocessor);
|
---|
[660] | 390 |
|
---|
[728] | 391 | /** Sets maximal size of a view cell filter.
|
---|
| 392 | */
|
---|
| 393 | void SetMaxFilterSize(const int size);
|
---|
[697] | 394 |
|
---|
[746] | 395 | int GetMaxFilterSize() {
|
---|
| 396 | return mMaxFilterSize;
|
---|
| 397 | }
|
---|
| 398 |
|
---|
| 399 | /** deletes interior nodes from the tree which have negative merge cost set (local merge) */
|
---|
| 400 | void
|
---|
| 401 | DeleteLocalMergeTree(ViewCell *vc
|
---|
| 402 | ) const;
|
---|
[713] | 403 |
|
---|
[728] | 404 | /** Evaluautes histogram for a given number of view cells.
|
---|
| 405 | */
|
---|
| 406 | void EvalViewCellHistogram(const string filename, const int nViewCells);
|
---|
| 407 |
|
---|
[735] | 408 | /** Evaluautes histogram for a given number of view cells.
|
---|
| 409 | */
|
---|
| 410 | void EvalViewCellHistogramForPvsSize(const string filename, const int nViewCells);
|
---|
| 411 |
|
---|
[728] | 412 | /** Evaluates the render cost of a view cell.
|
---|
| 413 | */
|
---|
| 414 | float EvalRenderCost(Intersectable *obj) const;
|
---|
| 415 |
|
---|
[469] | 416 | protected:
|
---|
[480] | 417 |
|
---|
[697] | 418 | /** Returns the bounding box of filter width.
|
---|
| 419 | */
|
---|
| 420 | AxisAlignedBox3 GetFilterBBox(const Vector3 &viewPoint, const float width) const;
|
---|
[609] | 421 |
|
---|
[697] | 422 | /** Intersects box with the tree and returns the number of intersected boxes.
|
---|
| 423 | @returns number of view cells found
|
---|
| 424 | */
|
---|
[710] | 425 | virtual int ComputeBoxIntersections(const AxisAlignedBox3 &box,
|
---|
| 426 | ViewCellContainer &viewCells) const;
|
---|
[697] | 427 |
|
---|
| 428 | virtual void TestFilter(const ObjectContainer &objects) {};
|
---|
| 429 |
|
---|
[581] | 430 | /**
|
---|
| 431 | if the view cells tree was already constructed or not.
|
---|
| 432 | */
|
---|
| 433 | bool ViewCellsTreeConstructed() const;
|
---|
| 434 |
|
---|
[574] | 435 | int CastPassSamples(const int samplesPerPass,
|
---|
| 436 | const int sampleType,
|
---|
| 437 | VssRayContainer &vssRays) const;
|
---|
[573] | 438 |
|
---|
[482] | 439 | void ParseEnvironment();
|
---|
| 440 |
|
---|
[508] | 441 | /** Creates unique view cell ids.
|
---|
| 442 | */
|
---|
| 443 | void CreateUniqueViewCellIds();
|
---|
[547] | 444 |
|
---|
[551] | 445 | /** Finalizes, i.e., creates mesh, volume, area etc. for the view cell.
|
---|
| 446 | */
|
---|
| 447 | virtual void Finalize(ViewCell *viewCell, const bool createMesh);
|
---|
| 448 |
|
---|
[480] | 449 | /** Recollects view cells and resets statistics.
|
---|
| 450 | */
|
---|
| 451 | void ResetViewCells();
|
---|
[482] | 452 |
|
---|
[480] | 453 | /** Collects the view cells in the view cell container.
|
---|
| 454 | */
|
---|
| 455 | virtual void CollectViewCells() = 0;
|
---|
[482] | 456 |
|
---|
[479] | 457 | /** Evaluates view cells statistics and stores it in
|
---|
| 458 | mViewCellsStatistics.
|
---|
| 459 | */
|
---|
| 460 | void EvaluateViewCellsStats();
|
---|
[482] | 461 |
|
---|
| 462 | //-- helper functions for view cell visualization
|
---|
| 463 |
|
---|
| 464 | /** Exports the view cell partition.
|
---|
| 465 | */
|
---|
[508] | 466 | void ExportViewCellsForViz(Exporter *exporter) const;
|
---|
[482] | 467 |
|
---|
| 468 | /** Sets exporter color.
|
---|
| 469 | */
|
---|
| 470 | virtual void ExportColor(Exporter *exporter, ViewCell *vc) const = 0;
|
---|
| 471 |
|
---|
[556] | 472 |
|
---|
[557] | 473 | virtual float GetViewSpaceVolume();
|
---|
| 474 |
|
---|
[503] | 475 | /** Creates meshes from the view cells.
|
---|
| 476 | */
|
---|
[517] | 477 | void CreateViewCellMeshes();
|
---|
[503] | 478 |
|
---|
[610] | 479 | /** Takes different measures to prepares the view cells after loading them from disc.
|
---|
[577] | 480 | */
|
---|
| 481 | virtual void PrepareLoadedViewCells() {};
|
---|
| 482 |
|
---|
[704] | 483 | /** Constructs local view cell merge hierarchy.
|
---|
| 484 | */
|
---|
| 485 | ViewCell *ConstructLocalMergeTree(ViewCell *currentViewCell,
|
---|
| 486 | const ViewCellContainer &viewCells);
|
---|
| 487 |
|
---|
[713] | 488 | /** Constructs local view cell merge hierarchy based solely on similarity with the
|
---|
| 489 | current viewcell
|
---|
| 490 | */
|
---|
| 491 | ViewCell *ConstructLocalMergeTree2(ViewCell *currentViewCell,
|
---|
| 492 | const ViewCellContainer &viewCells);
|
---|
| 493 |
|
---|
| 494 |
|
---|
[660] | 495 | /** Creates clip plane for visualization.
|
---|
| 496 | */
|
---|
| 497 | void CreateClipPlane();
|
---|
[591] | 498 |
|
---|
[752] | 499 | virtual void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs) = 0;
|
---|
| 500 |
|
---|
| 501 |
|
---|
| 502 |
|
---|
[660] | 503 | Plane3 mClipPlane;
|
---|
| 504 | bool mUseClipPlaneForViz;
|
---|
[591] | 505 |
|
---|
| 506 |
|
---|
[480] | 507 | /// Renders the view cells.
|
---|
| 508 | Renderer *mRenderer;
|
---|
[440] | 509 |
|
---|
| 510 | /// Loaded view cells
|
---|
[469] | 511 | ViewCellContainer mViewCells;
|
---|
[440] | 512 |
|
---|
[580] | 513 | ViewCellsTree *mViewCellsTree;
|
---|
| 514 |
|
---|
[710] | 515 | bool mPruneEmptyViewCells;
|
---|
[706] | 516 |
|
---|
[719] | 517 | bool mViewCellPvsIsUpdated;
|
---|
[440] | 518 | /// maximum number of samples taken for construction of the view cells
|
---|
| 519 | int mConstructionSamples;
|
---|
[574] | 520 | int mSamplesPerPass;
|
---|
| 521 | int mInitialSamples;
|
---|
[440] | 522 | int mPostProcessSamples;
|
---|
| 523 | int mVisualizationSamples;
|
---|
[441] | 524 |
|
---|
[470] | 525 | float mTotalAreaValid;
|
---|
| 526 | float mTotalArea;
|
---|
[475] | 527 |
|
---|
[547] | 528 | int mMaxPvsSize;
|
---|
[562] | 529 | int mMinPvsSize;
|
---|
[547] | 530 | float mMaxPvsRatio;
|
---|
| 531 |
|
---|
[660] | 532 | int mSamplingType;
|
---|
[722] | 533 | int mEvaluationSamplingType;
|
---|
[600] | 534 | int mNumActiveViewCells;
|
---|
[586] | 535 | bool mCompressViewCells;
|
---|
| 536 |
|
---|
[660] | 537 | ViewCellsStatistics mCurrentViewCellsStats;
|
---|
[487] | 538 | /// the scene bounding box
|
---|
[542] | 539 | AxisAlignedBox3 mViewSpaceBox;
|
---|
[508] | 540 | /// holds the view cell meshes
|
---|
[503] | 541 | MeshContainer mMeshContainer;
|
---|
[508] | 542 | /// if view cells should be exported
|
---|
| 543 | bool mExportViewCells;
|
---|
[547] | 544 |
|
---|
[591] | 545 | //bool mMarchTree);
|
---|
[564] | 546 | bool mOnlyValidViewCells;
|
---|
[547] | 547 |
|
---|
[580] | 548 | /// if rays should be used to collect merge candidates
|
---|
| 549 | bool mUseRaysForMerge;
|
---|
[697] | 550 | /// merge the view cells?
|
---|
[592] | 551 | bool mMergeViewCells;
|
---|
[697] | 552 |
|
---|
| 553 | /// the width of the box filter
|
---|
| 554 | float mFilterWidth;
|
---|
| 555 | int mMaxFilterSize;
|
---|
| 556 |
|
---|
[487] | 557 | //-- visualization options
|
---|
| 558 |
|
---|
| 559 | /// color code for view cells
|
---|
| 560 | int mColorCode;
|
---|
| 561 | bool mExportGeometry;
|
---|
| 562 | bool mExportRays;
|
---|
[517] | 563 |
|
---|
| 564 | bool mViewCellsFinished;
|
---|
[664] | 565 |
|
---|
| 566 | bool mEvaluateViewCells;
|
---|
[666] | 567 |
|
---|
[693] | 568 | bool mShowVisualization;
|
---|
| 569 |
|
---|
| 570 | // HACK in order to detect empty view cells
|
---|
| 571 | void CollectEmptyViewCells();
|
---|
[694] | 572 | void TestEmptyViewCells(const ObjectContainer &obj);
|
---|
[693] | 573 |
|
---|
| 574 | ViewCellContainer mEmptyViewCells;
|
---|
[728] | 575 |
|
---|
| 576 | int mRenderCostEvaluationType;
|
---|
[440] | 577 | };
|
---|
| 578 |
|
---|
[441] | 579 |
|
---|
| 580 |
|
---|
[440] | 581 | /**
|
---|
| 582 | Manages different higher order operations on the view cells.
|
---|
| 583 | */
|
---|
| 584 | class BspViewCellsManager: public ViewCellsManager
|
---|
| 585 | {
|
---|
| 586 |
|
---|
| 587 | public:
|
---|
[485] | 588 | /** Constructor taking the bsp tree and the number of samples
|
---|
| 589 | used to construct the bsp tree.
|
---|
| 590 | */
|
---|
[574] | 591 | BspViewCellsManager(BspTree *tree);
|
---|
[440] | 592 |
|
---|
[477] | 593 | ~BspViewCellsManager();
|
---|
| 594 |
|
---|
[574] | 595 | int ConstructSubdivision(const ObjectContainer &objects,
|
---|
[487] | 596 | const VssRayContainer &rays);
|
---|
[440] | 597 |
|
---|
| 598 | int PostProcess(const ObjectContainer &objects,
|
---|
[466] | 599 | const VssRayContainer &rays);
|
---|
[440] | 600 |
|
---|
| 601 | void Visualize(const ObjectContainer &objects,
|
---|
[466] | 602 | const VssRayContainer &sampleRays);
|
---|
[440] | 603 |
|
---|
| 604 | int GetType() const;
|
---|
| 605 |
|
---|
| 606 | ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
|
---|
| 607 |
|
---|
| 608 | bool ViewCellsConstructed() const;
|
---|
| 609 |
|
---|
[475] | 610 | //void PrintStatistics(ostream &s) const;
|
---|
[452] | 611 |
|
---|
[468] | 612 | int CastLineSegment(const Vector3 &origin,
|
---|
| 613 | const Vector3 &termination,
|
---|
| 614 | ViewCellContainer &viewcells);
|
---|
| 615 |
|
---|
[471] | 616 | float GetProbability(ViewCell *viewCell);
|
---|
[605] | 617 |
|
---|
[466] | 618 |
|
---|
[503] | 619 | /** Get a viewcell containing the specified point */
|
---|
[569] | 620 | ViewCell *GetViewCell(const Vector3 &point) const;
|
---|
[492] | 621 |
|
---|
[503] | 622 | void CreateMesh(ViewCell *vc);
|
---|
| 623 |
|
---|
[591] | 624 | void ExportViewCellGeometry(Exporter *exporter,
|
---|
| 625 | ViewCell *vc,
|
---|
[660] | 626 | const Plane3 *clipPlane = NULL) const;
|
---|
[580] | 627 |
|
---|
[587] | 628 | void CollectMergeCandidates(const VssRayContainer &rays,
|
---|
| 629 | vector<MergeCandidate> &candidates);
|
---|
[547] | 630 |
|
---|
[587] | 631 | void Finalize(ViewCell *viewCell, const bool createMesh);
|
---|
| 632 |
|
---|
[590] | 633 | bool ExportViewCells(const string filename);
|
---|
| 634 |
|
---|
[752] | 635 | /** Constructs merge hierarchy which corresponds to the spatial hierarchy.
|
---|
| 636 | */
|
---|
[650] | 637 | ViewCell *ConstructSpatialMergeTree(BspNode *root);
|
---|
[610] | 638 |
|
---|
[752] | 639 | /** Updates the pvs in the view cells tree.
|
---|
| 640 | */
|
---|
| 641 | void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs);
|
---|
[610] | 642 |
|
---|
[440] | 643 | protected:
|
---|
| 644 |
|
---|
[610] | 645 |
|
---|
[590] | 646 | /** HACK
|
---|
| 647 | */
|
---|
| 648 | void AddCurrentViewCellsToHierarchy();
|
---|
| 649 |
|
---|
[480] | 650 | void CollectViewCells();
|
---|
| 651 |
|
---|
[482] | 652 | void ExportColor(Exporter *exporter, ViewCell *vc) const;
|
---|
[547] | 653 |
|
---|
[482] | 654 |
|
---|
[547] | 655 |
|
---|
[440] | 656 | /// the BSP tree.
|
---|
| 657 | BspTree *mBspTree;
|
---|
[475] | 658 |
|
---|
| 659 | vector<BspRay *> mBspRays;
|
---|
[440] | 660 |
|
---|
| 661 | private:
|
---|
| 662 |
|
---|
| 663 | /** Exports visualization of the BSP splits.
|
---|
| 664 | */
|
---|
[477] | 665 | void ExportSplits(const ObjectContainer &objects);
|
---|
[440] | 666 |
|
---|
| 667 | /** Exports visualization of the BSP PVS.
|
---|
| 668 | */
|
---|
[477] | 669 | void ExportBspPvs(const ObjectContainer &objects);
|
---|
[440] | 670 |
|
---|
[693] | 671 | void TestSubdivision();
|
---|
[440] | 672 | };
|
---|
| 673 |
|
---|
| 674 | /**
|
---|
| 675 | Manages different higher order operations on the KD type view cells.
|
---|
| 676 | */
|
---|
| 677 | class KdViewCellsManager: public ViewCellsManager
|
---|
| 678 | {
|
---|
| 679 |
|
---|
| 680 | public:
|
---|
| 681 |
|
---|
| 682 | KdViewCellsManager(KdTree *tree);
|
---|
| 683 |
|
---|
[574] | 684 | int ConstructSubdivision(const ObjectContainer &objects,
|
---|
[487] | 685 | const VssRayContainer &rays);
|
---|
[440] | 686 |
|
---|
[478] | 687 | int CastLineSegment(const Vector3 &origin,
|
---|
| 688 | const Vector3 &termination,
|
---|
| 689 | ViewCellContainer &viewcells);
|
---|
[440] | 690 |
|
---|
| 691 | int PostProcess(const ObjectContainer &objects,
|
---|
[466] | 692 | const VssRayContainer &rays);
|
---|
[440] | 693 |
|
---|
| 694 | void Visualize(const ObjectContainer &objects,
|
---|
[466] | 695 | const VssRayContainer &sampleRays);
|
---|
[440] | 696 |
|
---|
| 697 | int GetType() const;
|
---|
| 698 |
|
---|
| 699 | bool ViewCellsConstructed() const;
|
---|
| 700 |
|
---|
[580] | 701 | ViewCell *GenerateViewCell(Mesh *mesh) const;
|
---|
[440] | 702 |
|
---|
[452] | 703 | /** Prints out statistics of this approach.
|
---|
| 704 | */
|
---|
[503] | 705 | // virtual void PrintStatistics(ostream &s) const;
|
---|
[569] | 706 | ViewCell *GetViewCell(const Vector3 &point) const { return NULL; }
|
---|
[452] | 707 |
|
---|
[503] | 708 | float GetProbability(ViewCell *viewCell);
|
---|
[609] | 709 |
|
---|
[468] | 710 |
|
---|
[503] | 711 | void CreateMesh(ViewCell *vc);
|
---|
| 712 |
|
---|
[591] | 713 | void ExportViewCellGeometry(Exporter *exporter,
|
---|
| 714 | ViewCell *vc,
|
---|
[660] | 715 | const Plane3 *clipPlane = NULL) const;
|
---|
[547] | 716 |
|
---|
[591] | 717 | void CollectMergeCandidates(const VssRayContainer &rays,
|
---|
| 718 | vector<MergeCandidate> &candidates);
|
---|
[580] | 719 |
|
---|
[752] | 720 |
|
---|
[440] | 721 | protected:
|
---|
| 722 |
|
---|
[752] | 723 | virtual void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs) {};
|
---|
[580] | 724 | /** Collects view cells from a hierarchy.
|
---|
| 725 | */
|
---|
[480] | 726 | void CollectViewCells();
|
---|
[580] | 727 |
|
---|
[480] | 728 | KdNode *GetNodeForPvs(KdLeaf *leaf);
|
---|
[440] | 729 |
|
---|
[482] | 730 | void ExportColor(Exporter *exporter, ViewCell *vc) const;
|
---|
[440] | 731 |
|
---|
[547] | 732 |
|
---|
[480] | 733 | /// the BSP tree.
|
---|
| 734 | KdTree *mKdTree;
|
---|
[440] | 735 |
|
---|
[480] | 736 | /// depth of the KD tree nodes with represent the view cells
|
---|
| 737 | int mKdPvsDepth;
|
---|
[440] | 738 | };
|
---|
| 739 |
|
---|
| 740 | /**
|
---|
| 741 | Manages different higher order operations on the view cells
|
---|
| 742 | for vsp kd tree view cells.
|
---|
| 743 | */
|
---|
| 744 | class VspKdViewCellsManager: public ViewCellsManager
|
---|
| 745 | {
|
---|
| 746 |
|
---|
| 747 | public:
|
---|
| 748 |
|
---|
[574] | 749 | VspKdViewCellsManager(VspKdTree *vspKdTree);
|
---|
[440] | 750 |
|
---|
[574] | 751 | int ConstructSubdivision(const ObjectContainer &objects,
|
---|
[487] | 752 | const VssRayContainer &rays);
|
---|
[440] | 753 |
|
---|
| 754 |
|
---|
| 755 | int PostProcess(const ObjectContainer &objects,
|
---|
[466] | 756 | const VssRayContainer &rays);
|
---|
[440] | 757 |
|
---|
| 758 | void Visualize(const ObjectContainer &objects,
|
---|
[466] | 759 | const VssRayContainer &sampleRays);
|
---|
[440] | 760 |
|
---|
| 761 | int GetType() const;
|
---|
| 762 |
|
---|
| 763 | bool ViewCellsConstructed() const;
|
---|
| 764 |
|
---|
[475] | 765 | //virtual void PrintStatistics(ostream &s) const;
|
---|
[440] | 766 |
|
---|
[462] | 767 | ViewCell *GenerateViewCell(Mesh *mesh) const;
|
---|
| 768 |
|
---|
[466] | 769 |
|
---|
| 770 | int CastLineSegment(const Vector3 &origin,
|
---|
| 771 | const Vector3 &termination,
|
---|
[468] | 772 | ViewCellContainer &viewcells);
|
---|
[466] | 773 |
|
---|
[569] | 774 | ViewCell *GetViewCell(const Vector3 &point) const { return NULL; }
|
---|
[492] | 775 |
|
---|
[471] | 776 | float GetProbability(ViewCell *viewCell);
|
---|
[468] | 777 |
|
---|
[609] | 778 |
|
---|
[503] | 779 | void CreateMesh(ViewCell *vc);
|
---|
| 780 |
|
---|
[591] | 781 | void ExportViewCellGeometry(Exporter *exporter,
|
---|
| 782 | ViewCell *vc,
|
---|
[660] | 783 | const Plane3 *clipPlane = NULL) const;
|
---|
[547] | 784 |
|
---|
[580] | 785 | void CollectMergeCandidates(const VssRayContainer &rays, vector<MergeCandidate> &candidates);
|
---|
| 786 |
|
---|
[752] | 787 | virtual void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs) {};
|
---|
[440] | 788 | protected:
|
---|
| 789 |
|
---|
[482] | 790 | void ExportLeaves(const ObjectContainer &objects,
|
---|
| 791 | const VssRayContainer &sampleRays);
|
---|
| 792 |
|
---|
[480] | 793 | void CollectViewCells();
|
---|
| 794 |
|
---|
[482] | 795 | void ExportColor(Exporter *exporter, ViewCell *vc) const;
|
---|
| 796 |
|
---|
| 797 |
|
---|
[547] | 798 |
|
---|
[440] | 799 | /// the BSP tree.
|
---|
| 800 | VspKdTree *mVspKdTree;
|
---|
| 801 | };
|
---|
| 802 |
|
---|
| 803 |
|
---|
[442] | 804 |
|
---|
| 805 | /**
|
---|
| 806 | Manages different higher order operations on the view cells.
|
---|
| 807 | */
|
---|
| 808 | class VspBspViewCellsManager: public ViewCellsManager
|
---|
| 809 | {
|
---|
| 810 |
|
---|
| 811 | public:
|
---|
| 812 |
|
---|
[574] | 813 | VspBspViewCellsManager(VspBspTree *tree);
|
---|
[475] | 814 | ~VspBspViewCellsManager();
|
---|
[442] | 815 |
|
---|
[574] | 816 | int ConstructSubdivision(const ObjectContainer &objects,
|
---|
[487] | 817 | const VssRayContainer &rays);
|
---|
[442] | 818 |
|
---|
| 819 | int PostProcess(const ObjectContainer &objects,
|
---|
[466] | 820 | const VssRayContainer &rays);
|
---|
[442] | 821 |
|
---|
| 822 | void Visualize(const ObjectContainer &objects,
|
---|
[466] | 823 | const VssRayContainer &sampleRays);
|
---|
[442] | 824 |
|
---|
| 825 | int GetType() const;
|
---|
| 826 |
|
---|
| 827 | ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
|
---|
| 828 |
|
---|
| 829 | bool ViewCellsConstructed() const;
|
---|
| 830 |
|
---|
[468] | 831 |
|
---|
| 832 | int CastLineSegment(const Vector3 &origin,
|
---|
| 833 | const Vector3 &termination,
|
---|
| 834 | ViewCellContainer &viewcells);
|
---|
[452] | 835 |
|
---|
[471] | 836 | float GetProbability(ViewCell *viewCell);
|
---|
[479] | 837 |
|
---|
[569] | 838 | ViewCell *GetViewCell(const Vector3 &point) const;
|
---|
[477] | 839 |
|
---|
[487] | 840 | bool GetViewPoint(Vector3 &viewPoint) const;
|
---|
| 841 |
|
---|
[490] | 842 | bool ViewPointValid(const Vector3 &viewPoint) const;
|
---|
[503] | 843 |
|
---|
| 844 | void CreateMesh(ViewCell *vc);
|
---|
| 845 |
|
---|
[577] | 846 | //bool LoadViewCellsGeometry(const string filename, ObjectContainer *objects);
|
---|
[508] | 847 | bool ExportViewCells(const string filename);
|
---|
| 848 |
|
---|
[532] | 849 | int CastBeam(Beam &beam);
|
---|
| 850 |
|
---|
[591] | 851 | void ExportViewCellGeometry(Exporter *exporter,
|
---|
| 852 | ViewCell *vc,
|
---|
[660] | 853 | const Plane3 *clipPlane = NULL) const;
|
---|
[547] | 854 |
|
---|
[551] | 855 | //float GetVolume(ViewCell *viewCell) const;
|
---|
| 856 |
|
---|
[555] | 857 | void Finalize(ViewCell *viewCell, const bool createMesh);
|
---|
[551] | 858 |
|
---|
[580] | 859 | void CollectMergeCandidates(const VssRayContainer &rays, vector<MergeCandidate> &candidates);
|
---|
| 860 |
|
---|
[697] | 861 | /** Returns true if this view cell is equivavalent to a spatial node.
|
---|
| 862 | */
|
---|
[609] | 863 | bool EqualToSpatialNode(ViewCell *viewCell) const;
|
---|
[607] | 864 |
|
---|
[697] | 865 |
|
---|
[442] | 866 | protected:
|
---|
[475] | 867 |
|
---|
[697] | 868 | int ComputeBoxIntersections(const AxisAlignedBox3 &box, ViewCellContainer &viewCells) const;
|
---|
[651] | 869 |
|
---|
[610] | 870 | /** Returns node of the spatial hierarchy corresponding to the view cell
|
---|
| 871 | if such a node exists.
|
---|
| 872 | */
|
---|
[609] | 873 | BspNode *GetSpatialNode(ViewCell *viewCell) const;
|
---|
[610] | 874 |
|
---|
[590] | 875 | /** HACK
|
---|
| 876 | */
|
---|
| 877 | void AddCurrentViewCellsToHierarchy();
|
---|
| 878 |
|
---|
[503] | 879 | /** Merges the view cells.
|
---|
[442] | 880 | */
|
---|
[508] | 881 | void MergeViewCells(const VssRayContainer &rays,
|
---|
| 882 | const ObjectContainer &objects);
|
---|
[503] | 883 |
|
---|
[564] | 884 | void RefineViewCells(const VssRayContainer &rays, const ObjectContainer &objects);
|
---|
[442] | 885 |
|
---|
[480] | 886 | void CollectViewCells();
|
---|
| 887 |
|
---|
[482] | 888 | /** Returns maximal depth difference of view cell
|
---|
| 889 | leaves in tree.
|
---|
| 890 | */
|
---|
| 891 | int GetMaxTreeDiff(ViewCell *vc) const;
|
---|
[485] | 892 |
|
---|
[482] | 893 |
|
---|
[485] | 894 | void ExportColor(Exporter *exporter, ViewCell *vc) const;
|
---|
| 895 |
|
---|
[752] | 896 | /** Prepare view cells for use after loading them from disc.
|
---|
| 897 | */
|
---|
[577] | 898 | void PrepareLoadedViewCells();
|
---|
| 899 |
|
---|
[752] | 900 | /** Constructs merge hierarchy which corresponds to the spatial hierarchy.
|
---|
| 901 | */
|
---|
[650] | 902 | ViewCell *ConstructSpatialMergeTree(BspNode *root);
|
---|
[649] | 903 |
|
---|
[752] | 904 | void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs);
|
---|
| 905 |
|
---|
| 906 |
|
---|
| 907 | // HACK
|
---|
[697] | 908 | void TestFilter(const ObjectContainer &objects);
|
---|
| 909 |
|
---|
| 910 |
|
---|
| 911 |
|
---|
[442] | 912 | /// the view space partition BSP tree.
|
---|
| 913 | VspBspTree *mVspBspTree;
|
---|
| 914 |
|
---|
[591] | 915 |
|
---|
[442] | 916 | private:
|
---|
| 917 |
|
---|
| 918 | /** Exports visualization of the BSP splits.
|
---|
| 919 | */
|
---|
[485] | 920 | void ExportSplits(const ObjectContainer &objects,
|
---|
| 921 | const VssRayContainer &rays);
|
---|
[442] | 922 |
|
---|
| 923 | /** Exports visualization of the BSP PVS.
|
---|
| 924 | */
|
---|
[485] | 925 | void ExportBspPvs(const ObjectContainer &objects,
|
---|
| 926 | const VssRayContainer &rays);
|
---|
[442] | 927 |
|
---|
[693] | 928 | void TestSubdivision();
|
---|
[442] | 929 | };
|
---|
| 930 |
|
---|
[575] | 931 |
|
---|
| 932 | class ViewCellsManagerFactory
|
---|
| 933 | {
|
---|
| 934 |
|
---|
| 935 | public:
|
---|
| 936 |
|
---|
| 937 | ViewCellsManager *Create(const string mName);
|
---|
| 938 |
|
---|
| 939 | };
|
---|
| 940 |
|
---|
[440] | 941 | #endif
|
---|