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