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