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