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