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