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