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