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