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