[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 |
|
---|
[860] | 10 | namespace GtpVisibilityPreprocessor {
|
---|
| 11 |
|
---|
[440] | 12 | class ViewCell;
|
---|
| 13 | class Intersectable;
|
---|
| 14 | class RenderSimulator;
|
---|
[480] | 15 | class Renderer;
|
---|
[440] | 16 | class Mesh;
|
---|
| 17 | struct Triangle3;
|
---|
| 18 | class SimulationStatistics;
|
---|
| 19 | class BspTree;
|
---|
| 20 | class KdTree;
|
---|
[1006] | 21 | class VspOspTree;
|
---|
[440] | 22 | class VspBspTree;
|
---|
| 23 | class KdNode;
|
---|
| 24 | class KdLeaf;
|
---|
| 25 | class AxisAlignedBox3;
|
---|
[448] | 26 | class BspLeaf;
|
---|
[475] | 27 | class ViewCellsStatistics;
|
---|
[482] | 28 | class Exporter;
|
---|
[532] | 29 | class Beam;
|
---|
[570] | 30 | class Preprocessor;
|
---|
[580] | 31 | class ViewCellsTree;
|
---|
| 32 | class MergeCandidate;
|
---|
[931] | 33 | class BoundingBoxConverter;
|
---|
[1021] | 34 | class VspTree;
|
---|
| 35 | class OspTree;
|
---|
| 36 | class VspNode;
|
---|
[1027] | 37 | class HierarchyManager;
|
---|
[1259] | 38 | class BvHierarchy;
|
---|
[1264] | 39 | class ViewCellsTree;
|
---|
[1259] | 40 |
|
---|
[1047] | 41 | struct AxisAlignedPlane;
|
---|
[475] | 42 | struct BspRay;
|
---|
| 43 |
|
---|
[677] | 44 |
|
---|
[1145] | 45 | /** Probably Visible Set
|
---|
| 46 | */
|
---|
[697] | 47 | class PrVs
|
---|
| 48 | {
|
---|
| 49 | public:
|
---|
[704] | 50 | /// root of view cells tree
|
---|
| 51 | ViewCell *mViewCell;
|
---|
| 52 |
|
---|
[880] | 53 | // input parameter is the render budget for the PrVs
|
---|
[677] | 54 | float mRenderBudget;
|
---|
| 55 |
|
---|
[1557] | 56 | // some characteristic values could be stored as well
|
---|
[677] | 57 | };
|
---|
| 58 |
|
---|
[850] | 59 | /** Manages different higher order operations on the view cells.
|
---|
[440] | 60 | */
|
---|
| 61 | class ViewCellsManager
|
---|
| 62 | {
|
---|
| 63 | public:
|
---|
[728] | 64 | struct PvsStatistics
|
---|
| 65 | {
|
---|
[1737] | 66 | float minPvs;
|
---|
| 67 | float maxPvs;
|
---|
| 68 | float avgPvs;
|
---|
| 69 | float avgFilteredPvs;
|
---|
| 70 | float avgFilterContribution;
|
---|
| 71 | int viewcells;
|
---|
[1545] | 72 | };
|
---|
[697] | 73 |
|
---|
[728] | 74 | /// view cell container types
|
---|
[1021] | 75 | enum {BSP, KD, VSP_KD, VSP_BSP, VSP_OSP};
|
---|
[466] | 76 |
|
---|
[931] | 77 | /// render cost evaluation type
|
---|
[728] | 78 | enum {PER_OBJECT, PER_TRIANGLE};
|
---|
| 79 |
|
---|
[1545] | 80 | friend class X3dViewCellsParseHandlers;
|
---|
[1709] | 81 |
|
---|
[1004] | 82 | /** Default constructor.
|
---|
[440] | 83 | */
|
---|
[1264] | 84 | ViewCellsManager(ViewCellsTree *viewCellsTree);
|
---|
[440] | 85 |
|
---|
[462] | 86 | virtual ~ViewCellsManager();
|
---|
[440] | 87 |
|
---|
[527] | 88 | /** Constructs view cells container taking a preprocessor
|
---|
[570] | 89 | @returns the output rays (if not null)
|
---|
| 90 | */
|
---|
| 91 | int Construct(Preprocessor *preprocessor, VssRayContainer *outRays = NULL);
|
---|
[527] | 92 |
|
---|
[440] | 93 | /** Constructs view cell container with a given number of samples.
|
---|
| 94 | */
|
---|
[1709] | 95 | virtual int ConstructSubdivision(const ObjectContainer &objects,
|
---|
| 96 | const VssRayContainer &rays) = 0;
|
---|
[440] | 97 |
|
---|
[441] | 98 | /** Computes sample contributions of the rays to the view cells PVS.
|
---|
| 99 |
|
---|
| 100 | @param rays bundle of rays used to find intersections with view cells and
|
---|
| 101 | adding the contribution
|
---|
[563] | 102 | @param addRays true if rays should be added to the PVSs of the viewcells they
|
---|
[574] | 103 | intersect
|
---|
| 104 | @param storeViewCells true if view cells should be stored in the ray
|
---|
| 105 | */
|
---|
[697] | 106 | float ComputeSampleContributions(const VssRayContainer &rays,
|
---|
[1155] | 107 | const bool addContributions,
|
---|
| 108 | const bool storeViewCells);
|
---|
[440] | 109 |
|
---|
[1155] | 110 | /** Add sample contributions to the viewcells they intersect
|
---|
| 111 | */
|
---|
[697] | 112 | void AddSampleContributions(const VssRayContainer &rays);
|
---|
[563] | 113 |
|
---|
[441] | 114 |
|
---|
[475] | 115 | /** Computes sample contribution of a simgle ray to the view cells PVS.
|
---|
| 116 | @param ray finds intersections with view cells and holds the contribution
|
---|
[1570] | 117 | @param addSample if sample should be added to the pvs
|
---|
| 118 |
|
---|
[475] | 119 | @returns number of sample contributions
|
---|
| 120 | */
|
---|
[1159] | 121 | virtual float ComputeSampleContribution(VssRay &ray,
|
---|
| 122 | const bool addRays,
|
---|
| 123 | const bool storeViewCells);
|
---|
[563] | 124 |
|
---|
[591] | 125 | virtual void AddSampleContributions(VssRay &ray);
|
---|
[563] | 126 |
|
---|
[452] | 127 | /** Prints out statistics of the view cells.
|
---|
| 128 | */
|
---|
[475] | 129 | virtual void PrintStatistics(ostream &s) const;
|
---|
[452] | 130 |
|
---|
[440] | 131 | /** Post processes view cells givemŽa number of rays.
|
---|
| 132 | */
|
---|
[475] | 133 | virtual int PostProcess(const ObjectContainer &objects,
|
---|
| 134 | const VssRayContainer &rays) = 0;
|
---|
[440] | 135 |
|
---|
| 136 | /** Show visualization of the view cells.
|
---|
| 137 | */
|
---|
| 138 | virtual void Visualize(const ObjectContainer &objects,
|
---|
[466] | 139 | const VssRayContainer &sampleRays) = 0;
|
---|
[440] | 140 |
|
---|
[1737] | 141 | /** collect objects intersecting a given spatial box */
|
---|
| 142 | virtual void CollectObjects(const AxisAlignedBox3 &box, ObjectContainer &objects);
|
---|
| 143 |
|
---|
[440] | 144 | /** type of the view cell container.
|
---|
| 145 | */
|
---|
| 146 | virtual int GetType() const = 0;
|
---|
| 147 |
|
---|
[463] | 148 | /** Load the input viewcells. The input viewcells should be given as a collection
|
---|
[1545] | 149 | of meshes. Each mesh is assume to form a bounded polyhedron
|
---|
| 150 | defining the interior of the viewcell. The view cells manager
|
---|
| 151 | is responsible for building a hierarchy over these view cells.
|
---|
[463] | 152 |
|
---|
| 153 | @param filename file to load
|
---|
| 154 | @return true on success
|
---|
| 155 | */
|
---|
[1545] | 156 | virtual bool LoadViewCellsGeometry(const string filename, const bool extrudeBaseTriangle);
|
---|
[577] | 157 |
|
---|
[440] | 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 |
|
---|
[1545] | 169 | /** Generates view cell of the type specified by this manager
|
---|
[440] | 170 | */
|
---|
[580] | 171 | virtual ViewCell *GenerateViewCell(Mesh *mesh = NULL) const = 0;
|
---|
[440] | 172 |
|
---|
[1545] | 173 | /** Constructs view cell from base triangle.
|
---|
| 174 | The view cell is extruded along the normal vector.
|
---|
| 175 | @param the base triangle
|
---|
| 176 | @param the height of the newly created view cell
|
---|
[440] | 177 | */
|
---|
[1545] | 178 | ViewCell *ExtrudeViewCell(const Triangle3 &baseTri, const float height) const;
|
---|
[440] | 179 |
|
---|
[1743] | 180 |
|
---|
| 181 | virtual Intersectable *
|
---|
| 182 | GetIntersectable(const VssRay &ray, const bool isTermination) const;
|
---|
| 183 |
|
---|
[440] | 184 | /** Sets maximal number of samples used for the
|
---|
| 185 | construction of the view cells.
|
---|
| 186 | */
|
---|
| 187 | void SetVisualizationSamples(const int visSamples);
|
---|
| 188 |
|
---|
[574] | 189 | /** Sets maximal number of samples used for the construction of the view cells.
|
---|
[440] | 190 | */
|
---|
| 191 | void SetConstructionSamples(const int constructionSamples);
|
---|
| 192 |
|
---|
[574] | 193 | /** Sets maximal number of samples used for the visualization of the view cells.
|
---|
| 194 | */
|
---|
| 195 | void SetInitialSamples(const int initialSamples);
|
---|
| 196 |
|
---|
[440] | 197 | /** Sets maximal number of samples used for the post processing of the view cells.
|
---|
| 198 | */
|
---|
| 199 | void SetPostProcessSamples(const int postProcessingSamples);
|
---|
| 200 |
|
---|
| 201 | /** See set.
|
---|
| 202 | */
|
---|
| 203 | int GetVisualizationSamples() const;
|
---|
| 204 |
|
---|
| 205 | /** See set.
|
---|
| 206 | */
|
---|
| 207 | int GetConstructionSamples() const;
|
---|
| 208 |
|
---|
| 209 | /** See set.
|
---|
| 210 | */
|
---|
| 211 | int GetPostProcessSamples() const;
|
---|
| 212 |
|
---|
[1002] | 213 | /** Returns true if view cells are already constructed.
|
---|
[440] | 214 | */
|
---|
| 215 | virtual bool ViewCellsConstructed() const = 0;
|
---|
[441] | 216 |
|
---|
[477] | 217 | /** cast line segment to get a list of unique viewcells which are intersected
|
---|
| 218 | by this line segment
|
---|
| 219 | */
|
---|
[466] | 220 |
|
---|
[477] | 221 | virtual int CastLineSegment(const Vector3 &origin,
|
---|
[466] | 222 | const Vector3 &termination,
|
---|
| 223 | ViewCellContainer &viewcells
|
---|
| 224 | ) = 0;
|
---|
| 225 |
|
---|
[1294] | 226 | /** Returns a stats about the global pvs.
|
---|
| 227 | */
|
---|
[477] | 228 | virtual void GetPvsStatistics(PvsStatistics &stat);
|
---|
[466] | 229 |
|
---|
[904] | 230 | virtual void GetPrVS(const Vector3 &viewPoint, PrVs &prvs, const float filterWidth);
|
---|
[677] | 231 |
|
---|
[697] | 232 | /** Get a viewcell containing the specified point
|
---|
[879] | 233 | @param active if the active or elementary view cell should be returned.
|
---|
[697] | 234 | */
|
---|
[879] | 235 | virtual ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const = 0;
|
---|
[492] | 236 |
|
---|
[503] | 237 | virtual void PrintPvsStatistics(ostream &s);
|
---|
[467] | 238 |
|
---|
[719] | 239 | /** Updates pvs of the view cell hierarchy if necessary.
|
---|
| 240 | */
|
---|
| 241 | void UpdatePvs();
|
---|
| 242 |
|
---|
[477] | 243 | /** Returns probability that view point lies in one view cell.
|
---|
| 244 | */
|
---|
| 245 | virtual float GetProbability(ViewCell *viewCell) = 0;
|
---|
[468] | 246 |
|
---|
[477] | 247 | /** Returns render cost of a single view cell given the render cost of an object.
|
---|
| 248 | */
|
---|
[728] | 249 | float GetRendercost(ViewCell *viewCell) const;
|
---|
[468] | 250 |
|
---|
[720] | 251 | /** Returns reference to container of loaded / generated view cells.
|
---|
[477] | 252 | */
|
---|
| 253 | ViewCellContainer &GetViewCells();
|
---|
[468] | 254 |
|
---|
[485] | 255 | /** Helper function used to split ray sets uniformly
|
---|
| 256 | into one that is currently used and the other that
|
---|
| 257 | is saved for later processing.
|
---|
| 258 | @param sourceRays the input ray set
|
---|
| 259 | @param maxSize the maximal number of rays that will be used
|
---|
| 260 | @param usedRays returns the used ray set
|
---|
| 261 | @param savedRays if not null, returns the saved ray set
|
---|
[477] | 262 | */
|
---|
| 263 | void GetRaySets(const VssRayContainer &sourceRays,
|
---|
[485] | 264 | const int maxSize,
|
---|
| 265 | VssRayContainer &usedRays,
|
---|
| 266 | VssRayContainer *savedRays = NULL) const;
|
---|
| 267 |
|
---|
[480] | 268 | /** Returns accumulated area of all view cells.
|
---|
| 269 | */
|
---|
| 270 | float GetAccVcArea();
|
---|
[470] | 271 |
|
---|
[480] | 272 | /** Returns area of one view cell.
|
---|
| 273 | */
|
---|
| 274 | virtual float GetArea(ViewCell *viewCell) const;
|
---|
[470] | 275 |
|
---|
[551] | 276 | /** Returns volume of view cell.
|
---|
[480] | 277 | */
|
---|
| 278 | virtual float GetVolume(ViewCell *viewCell) const;
|
---|
[470] | 279 |
|
---|
[480] | 280 | /** Sets the current renderer mainly for view cells statistics.
|
---|
| 281 | */
|
---|
| 282 | void SetRenderer(Renderer *renderer);
|
---|
| 283 |
|
---|
[487] | 284 | /** Computes a (random) view point in the valid view space.
|
---|
| 285 | @returns true if valid view point was found
|
---|
| 286 | */
|
---|
| 287 | virtual bool GetViewPoint(Vector3 &viewPoint) const;
|
---|
| 288 |
|
---|
[490] | 289 | /** Returns true if this view point is in the valid view space.
|
---|
| 290 | */
|
---|
| 291 | virtual bool ViewPointValid(const Vector3 &viewPoint) const;
|
---|
| 292 |
|
---|
[487] | 293 | /** Sets a view space boundary.
|
---|
| 294 | */
|
---|
| 295 | void SetViewSpaceBox(const AxisAlignedBox3 &box);
|
---|
| 296 |
|
---|
[519] | 297 | AxisAlignedBox3 GetViewSpaceBox() const;
|
---|
| 298 |
|
---|
[503] | 299 | /** Creates mesh for this view cell.
|
---|
| 300 | */
|
---|
| 301 | virtual void CreateMesh(ViewCell *vc) = NULL;
|
---|
[487] | 302 |
|
---|
[508] | 303 | /** Writes view cells to disc.
|
---|
| 304 | */
|
---|
[1027] | 305 | virtual bool ExportViewCells(const string filename,
|
---|
| 306 | const bool exportPvs,
|
---|
| 307 | const ObjectContainer &objects);
|
---|
[508] | 308 |
|
---|
[532] | 309 | /** Casts beam to collect view cells.
|
---|
| 310 | */
|
---|
| 311 | virtual int CastBeam(Beam &beam);
|
---|
| 312 |
|
---|
[547] | 313 | /** Checks if view cell is considered as valid.
|
---|
| 314 | */
|
---|
[561] | 315 | virtual bool CheckValidity(ViewCell *vc,
|
---|
[562] | 316 | int minPvsSize,
|
---|
| 317 | int maxPvsSize) const;
|
---|
[547] | 318 |
|
---|
[562] | 319 |
|
---|
| 320 | /** Sets validity of view cell
|
---|
| 321 | */
|
---|
| 322 | virtual void SetValidity(ViewCell *vc,
|
---|
| 323 | int minPvsSize,
|
---|
| 324 | int maxPvsSize) const;
|
---|
| 325 |
|
---|
[710] | 326 | /** sets validy of all viewcells
|
---|
| 327 | */
|
---|
[810] | 328 | virtual void SetValidity(int minPvsSize,
|
---|
[569] | 329 | int maxPvsSize) const;
|
---|
| 330 |
|
---|
[609] | 331 |
|
---|
| 332 | /** set valid viewcells in the range of pvs. sorts the viewcells
|
---|
[710] | 333 | according to the pvs and then pickups those in the ranges
|
---|
| 334 | */
|
---|
| 335 | void SetValidityPercentage(const float minValid, const float maxValid);
|
---|
[569] | 336 |
|
---|
[1545] | 337 | /** Returns number of valid view cells.
|
---|
| 338 | */
|
---|
[609] | 339 | int CountValidViewcells() const;
|
---|
| 340 |
|
---|
[547] | 341 | /** Returns maximal allowed pvs size.
|
---|
| 342 | */
|
---|
| 343 | int GetMaxPvsSize() const;
|
---|
| 344 |
|
---|
[562] | 345 | /** Returns maximal allowed pvs size.
|
---|
| 346 | */
|
---|
| 347 | int GetMinPvsSize() const;
|
---|
[561] | 348 | /** Returns maximal ratio. i.e., currentPVs / maxPvs,
|
---|
| 349 | where pvs is still considered valid.
|
---|
| 350 | */
|
---|
| 351 | float GetMaxPvsRatio() const;
|
---|
[547] | 352 | /** Exports view cell geometry.
|
---|
| 353 | */
|
---|
[1416] | 354 | virtual void ExportViewCellGeometry(
|
---|
| 355 | Exporter *exporter,
|
---|
| 356 | ViewCell *vc,
|
---|
| 357 | const AxisAlignedBox3 *box,
|
---|
| 358 | const AxisAlignedPlane *clipPlane = NULL
|
---|
| 359 | ) const = 0;
|
---|
[547] | 360 |
|
---|
[860] | 361 | /** Brings the view cells into their final state, computes meshes and volume.
|
---|
| 362 | */
|
---|
[551] | 363 | virtual void FinalizeViewCells(const bool createMesh);
|
---|
| 364 |
|
---|
[579] | 365 | /** Evaluates statistics values on view cells.
|
---|
| 366 | */
|
---|
[580] | 367 | void EvaluateRenderStatistics(float &totalRenderCost,
|
---|
| 368 | float &expectedRenderCost,
|
---|
| 369 | float &deviation,
|
---|
| 370 | float &variance,
|
---|
[1709] | 371 | float &totalPvs,
|
---|
[580] | 372 | float &avgRenderCost);
|
---|
[579] | 373 |
|
---|
[580] | 374 |
|
---|
| 375 | /** Returns hierarchy of the view cells.
|
---|
| 376 | */
|
---|
| 377 | ViewCellsTree *GetViewCellsTree();
|
---|
| 378 |
|
---|
[1545] | 379 | /** Collect candidates for the view cell merge.
|
---|
| 380 | */
|
---|
[581] | 381 | virtual void CollectMergeCandidates(const VssRayContainer &rays,
|
---|
[1022] | 382 | vector<MergeCandidate> &candidates);
|
---|
[580] | 383 |
|
---|
[1294] | 384 | /** Collects n view cells and stores it as the active view cells.
|
---|
| 385 | */
|
---|
[610] | 386 | void CollectViewCells(const int n);
|
---|
| 387 |
|
---|
[1686] | 388 | /** Sets current view cells set to active,
|
---|
| 389 | i.e., the sampling is done in this view cell set.
|
---|
[660] | 390 | */
|
---|
| 391 | void SetViewCellsActive();
|
---|
[599] | 392 |
|
---|
[1145] | 393 | /** Evaluates render cost statistics of current view cell hierarchy.
|
---|
[660] | 394 | */
|
---|
[1178] | 395 | virtual void EvalViewCellPartition();
|
---|
[660] | 396 |
|
---|
[728] | 397 | /** Sets maximal size of a view cell filter.
|
---|
| 398 | */
|
---|
| 399 | void SetMaxFilterSize(const int size);
|
---|
[697] | 400 |
|
---|
[840] | 401 | /** Returns maximal filter size.
|
---|
| 402 | */
|
---|
| 403 | int GetMaxFilterSize() const;
|
---|
[746] | 404 |
|
---|
[1686] | 405 | /** Deletes interior nodes from the tree which have negative
|
---|
| 406 | merge cost set (local merge).
|
---|
[840] | 407 | */
|
---|
| 408 | void DeleteLocalMergeTree(ViewCell *vc) const;
|
---|
[713] | 409 |
|
---|
[728] | 410 | /** Evaluautes histogram for a given number of view cells.
|
---|
| 411 | */
|
---|
| 412 | void EvalViewCellHistogram(const string filename, const int nViewCells);
|
---|
| 413 |
|
---|
[735] | 414 | /** Evaluautes histogram for a given number of view cells.
|
---|
| 415 | */
|
---|
| 416 | void EvalViewCellHistogramForPvsSize(const string filename, const int nViewCells);
|
---|
| 417 |
|
---|
[728] | 418 | /** Evaluates the render cost of a view cell.
|
---|
| 419 | */
|
---|
[1703] | 420 | static float EvalRenderCost(Intersectable *obj);
|
---|
[1002] | 421 |
|
---|
| 422 | /** Sets pvs size of view cell as a scalar. Used when storing pvs only in the leaves
|
---|
| 423 | of the hierarchy.
|
---|
| 424 | */
|
---|
[1709] | 425 | void UpdateScalarPvsSize(ViewCell *vc, const float pvsCost, const int entriesInPvs) const;
|
---|
[728] | 426 |
|
---|
[870] | 427 | /** Returns bounding box of a view cell.
|
---|
| 428 | */
|
---|
| 429 | AxisAlignedBox3 GetViewCellBox(ViewCell *vc);
|
---|
[859] | 430 |
|
---|
[840] | 431 | /** Exports bounding boxes of objects to file.
|
---|
| 432 | */
|
---|
| 433 | bool ExportBoundingBoxes(const string filename, const ObjectContainer &objects) const;
|
---|
[931] | 434 |
|
---|
[850] | 435 | /** Load the bounding boxes into the container.
|
---|
| 436 | */
|
---|
| 437 | bool LoadBoundingBoxes(const string filename, IndexedBoundingBoxContainer &boxes) const;
|
---|
[840] | 438 |
|
---|
[1002] | 439 | /** Returns true if pvs should be exported together with the view cells.
|
---|
| 440 | */
|
---|
| 441 | bool GetExportPvs() const;
|
---|
[870] | 442 |
|
---|
[1582] | 443 | /////////////////////////////
|
---|
| 444 | // static members
|
---|
| 445 |
|
---|
| 446 | /** Loads view cells from file. The view cells manager is created with
|
---|
| 447 | respect to the loaded view cells.
|
---|
[870] | 448 |
|
---|
[1582] | 449 | @param filename the filename of the view cells
|
---|
| 450 | @param objects the scene objects
|
---|
| 451 | @param finalizeViewCells if the view cells should be post processed, i.e.
|
---|
| 452 | a mesh is created representing the geometry
|
---|
| 453 | @param bconverter a conversion routine working with the similarities of bounding
|
---|
| 454 | boxes: if there is a certain similarity of overlap between bounding boxes, two tested
|
---|
| 455 | candidate objects are considered to be the same objects
|
---|
| 456 | @returns the view cells manager if loading was successful, false otherwise
|
---|
| 457 | */
|
---|
| 458 | static ViewCellsManager *LoadViewCells(const string &filename,
|
---|
| 459 | ObjectContainer *objects,
|
---|
[1676] | 460 | bool finalizeViewCells = false,
|
---|
[1582] | 461 | BoundingBoxConverter *bconverter = NULL);
|
---|
[870] | 462 |
|
---|
[904] | 463 |
|
---|
[931] | 464 | ////////////////////////////////////////////////////////7
|
---|
| 465 | // visiblity filter options
|
---|
[1294] | 466 |
|
---|
[931] | 467 | // TODO: write own visibiltiy filter class
|
---|
| 468 | void ApplyFilter(KdTree *kdTree,
|
---|
| 469 | const float viewSpaceFilterSize,
|
---|
| 470 | const float spatialFilterSize);
|
---|
[904] | 471 |
|
---|
[1715] | 472 | // new adaptive version of the filter
|
---|
| 473 | void
|
---|
| 474 | ApplyFilter2(ViewCell *viewCell,
|
---|
[1737] | 475 | const bool useViewSpaceFilter,
|
---|
[1715] | 476 | const float filterSize,
|
---|
| 477 | ObjectPvs &pvs
|
---|
| 478 | );
|
---|
| 479 |
|
---|
[931] | 480 | void ApplySpatialFilter(KdTree *kdTree,
|
---|
| 481 | const float spatialFilterSize,
|
---|
| 482 | ObjectPvs &pvs);
|
---|
[480] | 483 |
|
---|
[931] | 484 | void ApplyFilter(ViewCell *viewCell,
|
---|
| 485 | KdTree *kdTree,
|
---|
| 486 | const float viewSpaceFilterSize,
|
---|
| 487 | const float spatialFilterSize,
|
---|
| 488 | ObjectPvs &pvs);
|
---|
| 489 |
|
---|
| 490 | float GetFilterWidth();
|
---|
| 491 |
|
---|
| 492 | float GetAbsFilterWidth();
|
---|
| 493 |
|
---|
[697] | 494 | /** Returns the bounding box of filter width.
|
---|
| 495 | */
|
---|
| 496 | AxisAlignedBox3 GetFilterBBox(const Vector3 &viewPoint, const float width) const;
|
---|
[609] | 497 |
|
---|
[1294] | 498 | //////////////////////////////////////////////////////////////////
|
---|
[979] | 499 |
|
---|
[1155] | 500 | /** If true, the kd nodes are stored instead of the object pvs.
|
---|
| 501 | */
|
---|
| 502 | void SetStoreKdPvs(const bool storeKdPvs);
|
---|
| 503 |
|
---|
| 504 | /** Returns true if the kd nodes are stored instead of the object pvs.
|
---|
| 505 | **/
|
---|
| 506 | bool GetStoreKdPVs() const;
|
---|
| 507 |
|
---|
[1570] | 508 | /** Adds a sample to the pvs of the specified view cell.
|
---|
| 509 | @param obj the hit object
|
---|
| 510 | @param hitPoint the point where the object is hit.
|
---|
| 511 | @param vc the sanpled view cell
|
---|
| 512 | @param pdf probability of the ray
|
---|
| 513 | @param contribution the relative pvs contribution
|
---|
| 514 | @returns true if the sample gives a contribution to the pvs.
|
---|
| 515 | */
|
---|
[1686] | 516 | virtual bool AddSampleToPvs(Intersectable *obj,
|
---|
| 517 | const Vector3 &hitPoint,
|
---|
| 518 | ViewCell *vc,
|
---|
| 519 | const float pdf,
|
---|
| 520 | float &contribution) const;
|
---|
[1259] | 521 |
|
---|
[1570] | 522 | /** Exports single view cells for visualization.
|
---|
| 523 | @param objects the scene objects
|
---|
| 524 | @param limit the maximal number of output view cells
|
---|
| 525 | @param sortViewCells if the view cells should be sorted by pvs size
|
---|
| 526 | @param exportPvs if the pvs should also be exported
|
---|
| 527 | @param exportRays if sample rays should be exported as well
|
---|
[1580] | 528 | @param maxRays maximum number of rays to export
|
---|
| 529 | @param prefix the prefix for the output file
|
---|
[1570] | 530 | @param visRays additional rays
|
---|
| 531 | */
|
---|
[1686] | 532 | virtual void ExportSingleViewCells(const ObjectContainer &objects,
|
---|
| 533 | const int maxViewCells,
|
---|
| 534 | const bool sortViewCells,
|
---|
| 535 | const bool exportPvs,
|
---|
| 536 | const bool exportRays,
|
---|
| 537 | const int maxRays,
|
---|
| 538 | const string prefix,
|
---|
| 539 | VssRayContainer *visRays = NULL) = NULL;
|
---|
[1570] | 540 |
|
---|
[1580] | 541 |
|
---|
| 542 | void ViewCellsManager::ResetPvs();
|
---|
[1582] | 543 |
|
---|
| 544 | Preprocessor *GetPreprocessor() const {
|
---|
| 545 | return mPreprocessor;
|
---|
| 546 | }
|
---|
[1580] | 547 |
|
---|
[1582] | 548 | void SetPreprocessor(Preprocessor *p) {
|
---|
| 549 | mPreprocessor = p;
|
---|
| 550 | }
|
---|
[1580] | 551 |
|
---|
[1608] | 552 | void UpdatePvsForEvaluation();
|
---|
| 553 |
|
---|
[931] | 554 | protected:
|
---|
[1145] | 555 |
|
---|
[697] | 556 | /** Intersects box with the tree and returns the number of intersected boxes.
|
---|
| 557 | @returns number of view cells found
|
---|
| 558 | */
|
---|
[710] | 559 | virtual int ComputeBoxIntersections(const AxisAlignedBox3 &box,
|
---|
| 560 | ViewCellContainer &viewCells) const;
|
---|
[697] | 561 |
|
---|
[880] | 562 | /** Tests the visibility filter functionality.
|
---|
| 563 | */
|
---|
[697] | 564 | virtual void TestFilter(const ObjectContainer &objects) {};
|
---|
| 565 |
|
---|
[931] | 566 | /** If the view cells tree was already constructed or not.
|
---|
[581] | 567 | */
|
---|
| 568 | bool ViewCellsTreeConstructed() const;
|
---|
| 569 |
|
---|
[1294] | 570 | /** Requests preprocessor to cast samplesPerPass samples of a specific type.
|
---|
| 571 | */
|
---|
[574] | 572 | int CastPassSamples(const int samplesPerPass,
|
---|
| 573 | const int sampleType,
|
---|
| 574 | VssRayContainer &vssRays) const;
|
---|
[573] | 575 |
|
---|
[931] | 576 | /** Parse the options from the environment file.
|
---|
| 577 | */
|
---|
[482] | 578 | void ParseEnvironment();
|
---|
| 579 |
|
---|
[508] | 580 | /** Creates unique view cell ids.
|
---|
| 581 | */
|
---|
| 582 | void CreateUniqueViewCellIds();
|
---|
[547] | 583 |
|
---|
[551] | 584 | /** Finalizes, i.e., creates mesh, volume, area etc. for the view cell.
|
---|
| 585 | */
|
---|
| 586 | virtual void Finalize(ViewCell *viewCell, const bool createMesh);
|
---|
| 587 |
|
---|
[480] | 588 | /** Recollects view cells and resets statistics.
|
---|
| 589 | */
|
---|
| 590 | void ResetViewCells();
|
---|
[482] | 591 |
|
---|
[1707] | 592 | /** Sets this view cell to active.
|
---|
| 593 | */
|
---|
| 594 | void SetViewCellActive(ViewCell *vc) const;
|
---|
| 595 |
|
---|
[480] | 596 | /** Collects the view cells in the view cell container.
|
---|
| 597 | */
|
---|
| 598 | virtual void CollectViewCells() = 0;
|
---|
[482] | 599 |
|
---|
[479] | 600 | /** Evaluates view cells statistics and stores it in
|
---|
| 601 | mViewCellsStatistics.
|
---|
| 602 | */
|
---|
| 603 | void EvaluateViewCellsStats();
|
---|
[482] | 604 |
|
---|
[1580] | 605 |
|
---|
[1416] | 606 | ///////////////////////
|
---|
[482] | 607 | //-- helper functions for view cell visualization
|
---|
| 608 |
|
---|
| 609 | /** Exports the view cell partition.
|
---|
| 610 | */
|
---|
[1686] | 611 | void ExportViewCellsForViz(Exporter *exporter,
|
---|
| 612 | const AxisAlignedBox3 *box,
|
---|
| 613 | const AxisAlignedPlane *clipPlane = NULL,
|
---|
| 614 | const bool colorCode = 0) const;
|
---|
[482] | 615 |
|
---|
| 616 | /** Sets exporter color.
|
---|
| 617 | */
|
---|
[1571] | 618 | virtual void ExportColor(Exporter *exporter, ViewCell *vc, const bool colorCode) const;
|
---|
[1545] | 619 |
|
---|
[1416] | 620 | /** Creates meshes from the view cells.
|
---|
| 621 | */
|
---|
| 622 | void CreateViewCellMeshes();
|
---|
[1545] | 623 |
|
---|
| 624 | /** Creates clip plane for visualization.
|
---|
[1416] | 625 | */
|
---|
| 626 | void CreateClipPlane();
|
---|
[482] | 627 |
|
---|
[1416] | 628 | AxisAlignedPlane *GetClipPlane();
|
---|
[1545] | 629 |
|
---|
[1551] | 630 | void ExportMergedViewCells(const ObjectContainer &objects);
|
---|
| 631 |
|
---|
[1416] | 632 | ///////////////////////
|
---|
| 633 |
|
---|
[1002] | 634 | /** Returns volume of the view space.
|
---|
| 635 | */
|
---|
[557] | 636 | virtual float GetViewSpaceVolume();
|
---|
[1416] | 637 | /** Prepares the view cells for sampling after loading them from disc.
|
---|
[503] | 638 | */
|
---|
[577] | 639 | virtual void PrepareLoadedViewCells() {};
|
---|
[704] | 640 | /** Constructs local view cell merge hierarchy.
|
---|
| 641 | */
|
---|
| 642 | ViewCell *ConstructLocalMergeTree(ViewCell *currentViewCell,
|
---|
| 643 | const ViewCellContainer &viewCells);
|
---|
| 644 |
|
---|
[713] | 645 | /** Constructs local view cell merge hierarchy based solely on similarity with the
|
---|
| 646 | current viewcell
|
---|
| 647 | */
|
---|
| 648 | ViewCell *ConstructLocalMergeTree2(ViewCell *currentViewCell,
|
---|
| 649 | const ViewCellContainer &viewCells);
|
---|
| 650 |
|
---|
[860] | 651 | /** Updates pvs of all view cells for statistical evaluation after some more sampling
|
---|
| 652 | */
|
---|
[1168] | 653 | void UpdatePvsForEvaluation(ViewCell *root, ObjectPvs &pvs);
|
---|
[752] | 654 |
|
---|
[1679] | 655 | virtual void ExportStats(const string &mergeStats);
|
---|
[1582] | 656 |
|
---|
| 657 |
|
---|
[979] | 658 | ////////////////////////////////////////////////
|
---|
[752] | 659 |
|
---|
[1145] | 660 | Preprocessor *mPreprocessor;
|
---|
| 661 | /// if bounding boxes should be exported together with the view cells
|
---|
[840] | 662 | bool mExportBboxesForPvs;
|
---|
[1416] | 663 | /// the clip plane for visualization
|
---|
| 664 | AxisAlignedPlane mClipPlaneForViz;
|
---|
| 665 | /// if the visualization is using the clip plane
|
---|
[660] | 666 | bool mUseClipPlaneForViz;
|
---|
[480] | 667 | /// Renders the view cells.
|
---|
| 668 | Renderer *mRenderer;
|
---|
[440] | 669 | /// Loaded view cells
|
---|
[469] | 670 | ViewCellContainer mViewCells;
|
---|
[1416] | 671 | /// the view cell hierarchy (i.e., the logical description of view cells)
|
---|
[580] | 672 | ViewCellsTree *mViewCellsTree;
|
---|
[1414] | 673 |
|
---|
[1416] | 674 | /** if the values in the view cell leaves and the interiors are up to date
|
---|
| 675 | this is meant for lazy storing of the pvs, where only a scalar indicating
|
---|
| 676 | pvs size is stored in interiors and not the pvs itself.
|
---|
| 677 | */
|
---|
[719] | 678 | bool mViewCellPvsIsUpdated;
|
---|
[1002] | 679 |
|
---|
[1416] | 680 | /// maximum number of samples for the view cell construction
|
---|
[440] | 681 | int mConstructionSamples;
|
---|
[574] | 682 | int mSamplesPerPass;
|
---|
| 683 | int mInitialSamples;
|
---|
[440] | 684 | int mPostProcessSamples;
|
---|
| 685 | int mVisualizationSamples;
|
---|
[441] | 686 |
|
---|
[470] | 687 | float mTotalAreaValid;
|
---|
| 688 | float mTotalArea;
|
---|
[475] | 689 |
|
---|
[547] | 690 | int mMaxPvsSize;
|
---|
[562] | 691 | int mMinPvsSize;
|
---|
[547] | 692 | float mMaxPvsRatio;
|
---|
| 693 |
|
---|
[660] | 694 | int mSamplingType;
|
---|
[722] | 695 | int mEvaluationSamplingType;
|
---|
[600] | 696 | int mNumActiveViewCells;
|
---|
[586] | 697 | bool mCompressViewCells;
|
---|
| 698 |
|
---|
[1002] | 699 | /// holds the current view cell statistics
|
---|
[660] | 700 | ViewCellsStatistics mCurrentViewCellsStats;
|
---|
[487] | 701 | /// the scene bounding box
|
---|
[542] | 702 | AxisAlignedBox3 mViewSpaceBox;
|
---|
[1001] | 703 |
|
---|
[508] | 704 | /// if view cells should be exported
|
---|
| 705 | bool mExportViewCells;
|
---|
[547] | 706 |
|
---|
[1002] | 707 | // if only valid view cells should be considered for processing
|
---|
[564] | 708 | bool mOnlyValidViewCells;
|
---|
[547] | 709 |
|
---|
[580] | 710 | /// if rays should be used to collect merge candidates
|
---|
| 711 | bool mUseRaysForMerge;
|
---|
[1021] | 712 |
|
---|
[1002] | 713 | /// if there should be an additional merge step after the subdivision
|
---|
[592] | 714 | bool mMergeViewCells;
|
---|
[697] | 715 |
|
---|
| 716 | /// the width of the box filter
|
---|
| 717 | float mFilterWidth;
|
---|
[1570] | 718 | /// Maximal size of the filter in terms of contributing view cells
|
---|
[697] | 719 | int mMaxFilterSize;
|
---|
[1570] | 720 |
|
---|
[1576] | 721 | // only for debugging
|
---|
[1686] | 722 | VssRayContainer storedRays;
|
---|
| 723 |
|
---|
[1545] | 724 | //////////////////
|
---|
[487] | 725 | //-- visualization options
|
---|
| 726 |
|
---|
[1002] | 727 | /// color code for view cells visualization
|
---|
[1570] | 728 | bool mShowVisualization;
|
---|
[487] | 729 | int mColorCode;
|
---|
| 730 | bool mExportGeometry;
|
---|
| 731 | bool mExportRays;
|
---|
[517] | 732 | bool mViewCellsFinished;
|
---|
[664] | 733 | bool mEvaluateViewCells;
|
---|
[844] | 734 |
|
---|
| 735 | /// if pvs should be exported with view cells
|
---|
| 736 | bool mExportPvs;
|
---|
[1155] | 737 |
|
---|
[1703] | 738 | static int sRenderCostEvaluationType;
|
---|
| 739 |
|
---|
| 740 | /// if view cells geometry should be used from other sources
|
---|
[1545] | 741 | bool mUsePredefinedViewCells;
|
---|
[440] | 742 | };
|
---|
| 743 |
|
---|
[441] | 744 |
|
---|
[1545] | 745 | /** Manages different higher order operations on the view cells.
|
---|
[440] | 746 | */
|
---|
| 747 | class BspViewCellsManager: public ViewCellsManager
|
---|
| 748 | {
|
---|
| 749 |
|
---|
| 750 | public:
|
---|
[485] | 751 | /** Constructor taking the bsp tree and the number of samples
|
---|
| 752 | used to construct the bsp tree.
|
---|
| 753 | */
|
---|
[1264] | 754 | BspViewCellsManager(ViewCellsTree *viewCellsTree, BspTree *tree);
|
---|
[440] | 755 |
|
---|
[477] | 756 | ~BspViewCellsManager();
|
---|
[1582] | 757 |
|
---|
[574] | 758 | int ConstructSubdivision(const ObjectContainer &objects,
|
---|
[487] | 759 | const VssRayContainer &rays);
|
---|
[440] | 760 |
|
---|
| 761 | int PostProcess(const ObjectContainer &objects,
|
---|
[466] | 762 | const VssRayContainer &rays);
|
---|
[440] | 763 |
|
---|
| 764 | void Visualize(const ObjectContainer &objects,
|
---|
[466] | 765 | const VssRayContainer &sampleRays);
|
---|
[440] | 766 |
|
---|
| 767 | int GetType() const;
|
---|
| 768 |
|
---|
| 769 | ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
|
---|
| 770 |
|
---|
| 771 | bool ViewCellsConstructed() const;
|
---|
| 772 |
|
---|
[475] | 773 | //void PrintStatistics(ostream &s) const;
|
---|
[452] | 774 |
|
---|
[468] | 775 | int CastLineSegment(const Vector3 &origin,
|
---|
| 776 | const Vector3 &termination,
|
---|
| 777 | ViewCellContainer &viewcells);
|
---|
| 778 |
|
---|
[1294] | 779 | /** Returns the probability that the view point lies
|
---|
| 780 | in this view cells.
|
---|
| 781 | */
|
---|
[471] | 782 | float GetProbability(ViewCell *viewCell);
|
---|
[466] | 783 |
|
---|
[1294] | 784 | /** Get a viewcell containing the specified point.
|
---|
[879] | 785 | */
|
---|
| 786 | ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const;
|
---|
[492] | 787 |
|
---|
[1294] | 788 | /** Creates mesh for this view cell.
|
---|
| 789 | */
|
---|
[503] | 790 | void CreateMesh(ViewCell *vc);
|
---|
| 791 |
|
---|
[1416] | 792 | void ExportViewCellGeometry(Exporter *exporter,
|
---|
| 793 | ViewCell *vc,
|
---|
| 794 | const AxisAlignedBox3 *box,
|
---|
| 795 | const AxisAlignedPlane *clipPlane = NULL
|
---|
| 796 | ) const;
|
---|
[580] | 797 |
|
---|
[587] | 798 | void CollectMergeCandidates(const VssRayContainer &rays,
|
---|
| 799 | vector<MergeCandidate> &candidates);
|
---|
[547] | 800 |
|
---|
[587] | 801 | void Finalize(ViewCell *viewCell, const bool createMesh);
|
---|
| 802 |
|
---|
[1416] | 803 | bool ExportViewCells(const string filename,
|
---|
| 804 | const bool exportPvs,
|
---|
| 805 | const ObjectContainer &objects);
|
---|
[590] | 806 |
|
---|
[752] | 807 | /** Constructs merge hierarchy which corresponds to the spatial hierarchy.
|
---|
| 808 | */
|
---|
[650] | 809 | ViewCell *ConstructSpatialMergeTree(BspNode *root);
|
---|
[610] | 810 |
|
---|
[1686] | 811 | void ExportSingleViewCells(const ObjectContainer &objects,
|
---|
| 812 | const int maxViewCells,
|
---|
| 813 | const bool sortViewCells,
|
---|
| 814 | const bool exportPvs,
|
---|
| 815 | const bool exportRays,
|
---|
| 816 | const int maxRays,
|
---|
| 817 | const string prefix,
|
---|
| 818 | VssRayContainer *visRays = NULL);
|
---|
[1545] | 819 |
|
---|
[440] | 820 | protected:
|
---|
| 821 |
|
---|
[480] | 822 | void CollectViewCells();
|
---|
[547] | 823 |
|
---|
[440] | 824 | /// the BSP tree.
|
---|
| 825 | BspTree *mBspTree;
|
---|
[475] | 826 | vector<BspRay *> mBspRays;
|
---|
[440] | 827 |
|
---|
| 828 | private:
|
---|
| 829 |
|
---|
[1545] | 830 | /** Constructs a spatial merge tree only 2 levels deep.
|
---|
| 831 | */
|
---|
| 832 | ViewCell *ConstructDummyMergeTree(BspNode *root);
|
---|
| 833 |
|
---|
[440] | 834 | /** Exports visualization of the BSP splits.
|
---|
| 835 | */
|
---|
[477] | 836 | void ExportSplits(const ObjectContainer &objects);
|
---|
[440] | 837 |
|
---|
[1002] | 838 | /** test if subdivision is valid in terms of volume / area.
|
---|
| 839 | */
|
---|
[693] | 840 | void TestSubdivision();
|
---|
[440] | 841 | };
|
---|
| 842 |
|
---|
[1545] | 843 |
|
---|
[440] | 844 | /**
|
---|
| 845 | Manages different higher order operations on the KD type view cells.
|
---|
| 846 | */
|
---|
| 847 | class KdViewCellsManager: public ViewCellsManager
|
---|
| 848 | {
|
---|
| 849 |
|
---|
| 850 | public:
|
---|
| 851 |
|
---|
[1264] | 852 | KdViewCellsManager(ViewCellsTree *viewCellsTree, KdTree *tree);
|
---|
[440] | 853 |
|
---|
[574] | 854 | int ConstructSubdivision(const ObjectContainer &objects,
|
---|
[1686] | 855 | const VssRayContainer &rays);
|
---|
[440] | 856 |
|
---|
[478] | 857 | int CastLineSegment(const Vector3 &origin,
|
---|
| 858 | const Vector3 &termination,
|
---|
| 859 | ViewCellContainer &viewcells);
|
---|
[440] | 860 |
|
---|
| 861 | int PostProcess(const ObjectContainer &objects,
|
---|
[466] | 862 | const VssRayContainer &rays);
|
---|
[440] | 863 |
|
---|
| 864 | void Visualize(const ObjectContainer &objects,
|
---|
[466] | 865 | const VssRayContainer &sampleRays);
|
---|
[440] | 866 |
|
---|
| 867 | int GetType() const;
|
---|
| 868 |
|
---|
| 869 | bool ViewCellsConstructed() const;
|
---|
| 870 |
|
---|
[580] | 871 | ViewCell *GenerateViewCell(Mesh *mesh) const;
|
---|
[440] | 872 |
|
---|
[452] | 873 | /** Prints out statistics of this approach.
|
---|
| 874 | */
|
---|
[503] | 875 | // virtual void PrintStatistics(ostream &s) const;
|
---|
[1416] | 876 | ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const
|
---|
| 877 | { return NULL; }
|
---|
[452] | 878 |
|
---|
[503] | 879 | float GetProbability(ViewCell *viewCell);
|
---|
[609] | 880 |
|
---|
[503] | 881 | void CreateMesh(ViewCell *vc);
|
---|
| 882 |
|
---|
[1686] | 883 | void ExportViewCellGeometry(Exporter *exporter,
|
---|
| 884 | ViewCell *vc,
|
---|
| 885 | const AxisAlignedBox3 *box,
|
---|
| 886 | const AxisAlignedPlane *clipPlane = NULL) const;
|
---|
[547] | 887 |
|
---|
[1416] | 888 |
|
---|
[591] | 889 | void CollectMergeCandidates(const VssRayContainer &rays,
|
---|
| 890 | vector<MergeCandidate> &candidates);
|
---|
[580] | 891 |
|
---|
[1686] | 892 | void ExportSingleViewCells(const ObjectContainer &objects,
|
---|
| 893 | const int maxViewCells,
|
---|
| 894 | const bool sortViewCells,
|
---|
| 895 | const bool exportPvs,
|
---|
| 896 | const bool exportRays,
|
---|
| 897 | const int maxRays,
|
---|
| 898 | const string prefix,
|
---|
| 899 | VssRayContainer *visRays = NULL);
|
---|
[752] | 900 |
|
---|
[440] | 901 | protected:
|
---|
| 902 |
|
---|
[580] | 903 | /** Collects view cells from a hierarchy.
|
---|
| 904 | */
|
---|
[480] | 905 | void CollectViewCells();
|
---|
[580] | 906 |
|
---|
[480] | 907 | KdNode *GetNodeForPvs(KdLeaf *leaf);
|
---|
[440] | 908 |
|
---|
[1570] | 909 | ////////////////////////////////////////
|
---|
[440] | 910 |
|
---|
[480] | 911 | /// the BSP tree.
|
---|
| 912 | KdTree *mKdTree;
|
---|
[440] | 913 |
|
---|
[480] | 914 | /// depth of the KD tree nodes with represent the view cells
|
---|
| 915 | int mKdPvsDepth;
|
---|
[938] | 916 |
|
---|
| 917 |
|
---|
[440] | 918 | };
|
---|
| 919 |
|
---|
[1570] | 920 |
|
---|
| 921 | /** Manages different higher order operations on the view cells.
|
---|
[442] | 922 | */
|
---|
| 923 | class VspBspViewCellsManager: public ViewCellsManager
|
---|
| 924 | {
|
---|
| 925 |
|
---|
| 926 | public:
|
---|
| 927 |
|
---|
[1264] | 928 | VspBspViewCellsManager(ViewCellsTree *viewCellsTree, VspBspTree *tree);
|
---|
[475] | 929 | ~VspBspViewCellsManager();
|
---|
[442] | 930 |
|
---|
[574] | 931 | int ConstructSubdivision(const ObjectContainer &objects,
|
---|
[1686] | 932 | const VssRayContainer &rays);
|
---|
[442] | 933 |
|
---|
| 934 | int PostProcess(const ObjectContainer &objects,
|
---|
[466] | 935 | const VssRayContainer &rays);
|
---|
[442] | 936 |
|
---|
| 937 | void Visualize(const ObjectContainer &objects,
|
---|
[466] | 938 | const VssRayContainer &sampleRays);
|
---|
[442] | 939 |
|
---|
| 940 | int GetType() const;
|
---|
| 941 |
|
---|
| 942 | ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
|
---|
| 943 |
|
---|
| 944 | bool ViewCellsConstructed() const;
|
---|
| 945 |
|
---|
[468] | 946 |
|
---|
| 947 | int CastLineSegment(const Vector3 &origin,
|
---|
| 948 | const Vector3 &termination,
|
---|
| 949 | ViewCellContainer &viewcells);
|
---|
[452] | 950 |
|
---|
[471] | 951 | float GetProbability(ViewCell *viewCell);
|
---|
[479] | 952 |
|
---|
[879] | 953 | ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const;
|
---|
[477] | 954 |
|
---|
[487] | 955 | bool GetViewPoint(Vector3 &viewPoint) const;
|
---|
| 956 |
|
---|
[490] | 957 | bool ViewPointValid(const Vector3 &viewPoint) const;
|
---|
[503] | 958 |
|
---|
| 959 | void CreateMesh(ViewCell *vc);
|
---|
| 960 |
|
---|
[1686] | 961 | bool ExportViewCells(const string filename,
|
---|
| 962 | const bool exportPvs,
|
---|
| 963 | const ObjectContainer &objects);
|
---|
[508] | 964 |
|
---|
[532] | 965 | int CastBeam(Beam &beam);
|
---|
[1416] | 966 |
|
---|
[1686] | 967 | void ExportViewCellGeometry(Exporter *exporter,
|
---|
| 968 | ViewCell *vc,
|
---|
| 969 | const AxisAlignedBox3 *box,
|
---|
| 970 | const AxisAlignedPlane *clipPlane = NULL) const;
|
---|
[532] | 971 |
|
---|
[547] | 972 |
|
---|
[555] | 973 | void Finalize(ViewCell *viewCell, const bool createMesh);
|
---|
[551] | 974 |
|
---|
[1686] | 975 | void CollectMergeCandidates(const VssRayContainer &rays,
|
---|
| 976 | vector<MergeCandidate> &candidates);
|
---|
[580] | 977 |
|
---|
[1686] | 978 | void ExportSingleViewCells(const ObjectContainer &objects,
|
---|
| 979 | const int maxViewCells,
|
---|
| 980 | const bool sortViewCells,
|
---|
| 981 | const bool exportPvs,
|
---|
| 982 | const bool exportRays,
|
---|
| 983 | const int maxRays,
|
---|
| 984 | const string prefix,
|
---|
| 985 | VssRayContainer *visRays = NULL);
|
---|
[1570] | 986 |
|
---|
| 987 |
|
---|
[442] | 988 | protected:
|
---|
[475] | 989 |
|
---|
[1686] | 990 | int ComputeBoxIntersections(const AxisAlignedBox3 &box,
|
---|
| 991 | ViewCellContainer &viewCells) const;
|
---|
[651] | 992 |
|
---|
[1021] | 993 | /** Merges view cells according to some criteria
|
---|
[442] | 994 | */
|
---|
[508] | 995 | void MergeViewCells(const VssRayContainer &rays,
|
---|
| 996 | const ObjectContainer &objects);
|
---|
[503] | 997 |
|
---|
[564] | 998 | void RefineViewCells(const VssRayContainer &rays, const ObjectContainer &objects);
|
---|
[442] | 999 |
|
---|
[480] | 1000 | void CollectViewCells();
|
---|
| 1001 |
|
---|
[482] | 1002 | /** Returns maximal depth difference of view cell
|
---|
| 1003 | leaves in tree.
|
---|
| 1004 | */
|
---|
| 1005 | int GetMaxTreeDiff(ViewCell *vc) const;
|
---|
| 1006 |
|
---|
[752] | 1007 | /** Prepare view cells for use after loading them from disc.
|
---|
| 1008 | */
|
---|
[577] | 1009 | void PrepareLoadedViewCells();
|
---|
| 1010 |
|
---|
[752] | 1011 | /** Constructs merge hierarchy which corresponds to the spatial hierarchy.
|
---|
| 1012 | */
|
---|
[650] | 1013 | ViewCell *ConstructSpatialMergeTree(BspNode *root);
|
---|
[649] | 1014 |
|
---|
[979] | 1015 | /// HACK for testing visibility filter functionality
|
---|
[697] | 1016 | void TestFilter(const ObjectContainer &objects);
|
---|
| 1017 |
|
---|
[979] | 1018 | /** Visualization of the pvs difference to exact visubility using
|
---|
| 1019 | from point queries.
|
---|
| 1020 | */
|
---|
| 1021 | void VisualizeWithFromPointQueries();
|
---|
[697] | 1022 |
|
---|
[991] | 1023 | /** Evaluate from point queries for the current scene.
|
---|
| 1024 | */
|
---|
| 1025 | void EvalFromPointQueries();
|
---|
[979] | 1026 |
|
---|
[1021] | 1027 | /** Exports visualization of the BSP splits.
|
---|
| 1028 | */
|
---|
| 1029 | void ExportSplits(const ObjectContainer &objects,
|
---|
| 1030 | const VssRayContainer &rays);
|
---|
[991] | 1031 |
|
---|
[1686] | 1032 |
|
---|
| 1033 | /////////////////////////
|
---|
| 1034 |
|
---|
[442] | 1035 | /// the view space partition BSP tree.
|
---|
| 1036 | VspBspTree *mVspBspTree;
|
---|
| 1037 |
|
---|
[591] | 1038 |
|
---|
[442] | 1039 | private:
|
---|
| 1040 |
|
---|
[1021] | 1041 | /** test if subdivision is valid in terms of volume / area.
|
---|
[442] | 1042 | */
|
---|
[1021] | 1043 | void TestSubdivision();
|
---|
| 1044 | };
|
---|
[442] | 1045 |
|
---|
[1662] | 1046 | #define TEST_EVALUATION 0
|
---|
[1021] | 1047 |
|
---|
| 1048 | /**
|
---|
| 1049 | Manages different higher order operations on the view cells.
|
---|
| 1050 | */
|
---|
| 1051 | class VspOspViewCellsManager: public ViewCellsManager
|
---|
| 1052 | {
|
---|
[1740] | 1053 | friend class ViewCellsParseHandlers;
|
---|
[1021] | 1054 | public:
|
---|
| 1055 |
|
---|
[1740] | 1056 | VspOspViewCellsManager(ViewCellsTree *vcTree, const string &hierarchyType);
|
---|
[1278] | 1057 |
|
---|
[1021] | 1058 | ~VspOspViewCellsManager();
|
---|
| 1059 |
|
---|
| 1060 | int ConstructSubdivision(const ObjectContainer &objects,
|
---|
| 1061 | const VssRayContainer &rays);
|
---|
| 1062 |
|
---|
| 1063 | int PostProcess(const ObjectContainer &objects,
|
---|
| 1064 | const VssRayContainer &rays);
|
---|
| 1065 |
|
---|
[1686] | 1066 | void Visualize(const ObjectContainer &objects,
|
---|
[1021] | 1067 | const VssRayContainer &sampleRays);
|
---|
| 1068 |
|
---|
| 1069 | int GetType() const;
|
---|
| 1070 |
|
---|
| 1071 | ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
|
---|
| 1072 |
|
---|
[1743] | 1073 | virtual Intersectable *
|
---|
| 1074 | GetIntersectable(const VssRay &ray, const bool isTermination) const;
|
---|
| 1075 |
|
---|
[1021] | 1076 | bool ViewCellsConstructed() const;
|
---|
| 1077 |
|
---|
| 1078 |
|
---|
| 1079 | int CastLineSegment(const Vector3 &origin,
|
---|
| 1080 | const Vector3 &termination,
|
---|
| 1081 | ViewCellContainer &viewcells);
|
---|
| 1082 |
|
---|
| 1083 | float GetProbability(ViewCell *viewCell);
|
---|
| 1084 |
|
---|
| 1085 | ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const;
|
---|
| 1086 |
|
---|
| 1087 | bool GetViewPoint(Vector3 &viewPoint) const;
|
---|
| 1088 |
|
---|
| 1089 | bool ViewPointValid(const Vector3 &viewPoint) const;
|
---|
| 1090 |
|
---|
| 1091 | void CreateMesh(ViewCell *vc);
|
---|
| 1092 |
|
---|
[1027] | 1093 | bool ExportViewCells(const string filename,
|
---|
| 1094 | const bool exportPvs,
|
---|
| 1095 | const ObjectContainer &objects);
|
---|
[1021] | 1096 |
|
---|
| 1097 | int CastBeam(Beam &beam);
|
---|
| 1098 |
|
---|
| 1099 | void Finalize(ViewCell *viewCell, const bool createMesh);
|
---|
| 1100 |
|
---|
[1159] | 1101 | /** Stores sample contribution for kd cells or objects.
|
---|
| 1102 | */
|
---|
| 1103 | virtual float ComputeSampleContribution(VssRay &ray,
|
---|
| 1104 | const bool addRays,
|
---|
| 1105 | const bool storeViewCells);
|
---|
[1021] | 1106 |
|
---|
[1201] | 1107 | ViewCellsManager *LoadViewCells(const string &filename,
|
---|
[1666] | 1108 | ObjectContainer *objects,
|
---|
| 1109 | const bool finalizeViewCells,
|
---|
| 1110 | BoundingBoxConverter *bconverter);
|
---|
[1201] | 1111 |
|
---|
[1666] | 1112 | bool AddSampleToPvs(Intersectable *obj,
|
---|
| 1113 | const Vector3 &hitPoint,
|
---|
| 1114 | ViewCell *vc,
|
---|
| 1115 | const float pdf,
|
---|
| 1116 | float &contribution) const;
|
---|
[1201] | 1117 |
|
---|
[1666] | 1118 | void ExportSingleViewCells(const ObjectContainer &objects,
|
---|
| 1119 | const int maxViewCells,
|
---|
| 1120 | const bool sortViewCells,
|
---|
| 1121 | const bool exportPvs,
|
---|
| 1122 | const bool exportRays,
|
---|
| 1123 | const int maxRays,
|
---|
| 1124 | const string prefix,
|
---|
| 1125 | VssRayContainer *visRays = NULL);
|
---|
[1570] | 1126 |
|
---|
[1021] | 1127 | protected:
|
---|
[1180] | 1128 |
|
---|
[1740] | 1129 | VspOspViewCellsManager(ViewCellsTree *vcTree, HierarchyManager *hm);
|
---|
| 1130 |
|
---|
[1709] | 1131 | #if 1//TEST_EVALUATION
|
---|
| 1132 | virtual void EvalViewCellPartition();
|
---|
| 1133 | #endif
|
---|
[1416] | 1134 |
|
---|
[1027] | 1135 | /** Exports view cell geometry.
|
---|
| 1136 | */
|
---|
[1666] | 1137 | void ExportViewCellGeometry(Exporter *exporter,
|
---|
| 1138 | ViewCell *vc,
|
---|
| 1139 | const AxisAlignedBox3 *box,
|
---|
| 1140 | const AxisAlignedPlane *clipPlane = NULL) const;
|
---|
[1027] | 1141 |
|
---|
[1666] | 1142 | int ComputeBoxIntersections(const AxisAlignedBox3 &box,
|
---|
| 1143 | ViewCellContainer &viewCells) const;
|
---|
[1021] | 1144 |
|
---|
| 1145 | void CollectViewCells();
|
---|
| 1146 |
|
---|
| 1147 | /** Prepare view cells for use after loading them from disc.
|
---|
| 1148 | */
|
---|
| 1149 | void PrepareLoadedViewCells();
|
---|
| 1150 |
|
---|
| 1151 | /** Constructs merge hierarchy which corresponds to the spatial hierarchy.
|
---|
| 1152 | */
|
---|
| 1153 | ViewCell *ConstructSpatialMergeTree(VspNode *root);
|
---|
| 1154 |
|
---|
[1074] | 1155 | /** Exports visualization of the PVS.
|
---|
[442] | 1156 | */
|
---|
[1666] | 1157 | void ExportPvs(const ObjectContainer &objects, const VssRayContainer &rays);
|
---|
[442] | 1158 |
|
---|
[1740] | 1159 | /** Returns a hierarchy manager of the given name.
|
---|
| 1160 | */
|
---|
| 1161 | static HierarchyManager *CreateHierarchyManager(const string &name);
|
---|
| 1162 |
|
---|
[1679] | 1163 | //void ExportStats(const string &mergeStats);
|
---|
[1021] | 1164 |
|
---|
[1168] | 1165 | /////////////////////////////////////////
|
---|
[1259] | 1166 |
|
---|
[1737] | 1167 | /** collect objects intersecting a given spatial box */
|
---|
| 1168 | virtual void CollectObjects(const AxisAlignedBox3 &box, ObjectContainer &objects);
|
---|
| 1169 |
|
---|
[1027] | 1170 | HierarchyManager *mHierarchyManager;
|
---|
[442] | 1171 | };
|
---|
| 1172 |
|
---|
[575] | 1173 |
|
---|
[860] | 1174 | }
|
---|
| 1175 |
|
---|
[440] | 1176 | #endif
|
---|