[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 |
|
---|
| 10 | class ViewCell;
|
---|
| 11 | class Intersectable;
|
---|
| 12 | class RenderSimulator;
|
---|
[480] | 13 | class Renderer;
|
---|
[440] | 14 | class Mesh;
|
---|
| 15 | struct Triangle3;
|
---|
| 16 | class SimulationStatistics;
|
---|
| 17 | class BspTree;
|
---|
| 18 | class KdTree;
|
---|
| 19 | class VspKdTree;
|
---|
| 20 | class VspBspTree;
|
---|
| 21 | class KdNode;
|
---|
| 22 | class KdLeaf;
|
---|
| 23 | class VspKdTree;
|
---|
| 24 | class AxisAlignedBox3;
|
---|
[448] | 25 | class BspLeaf;
|
---|
[475] | 26 | class ViewCellsStatistics;
|
---|
[482] | 27 | class Exporter;
|
---|
[532] | 28 | class Beam;
|
---|
[570] | 29 | class Preprocessor;
|
---|
[580] | 30 | class ViewCellsTree;
|
---|
| 31 | class MergeCandidate;
|
---|
[503] | 32 |
|
---|
[475] | 33 | struct BspRay;
|
---|
| 34 |
|
---|
[677] | 35 |
|
---|
| 36 | /** Probably Visible Set */
|
---|
[697] | 37 | class PrVs
|
---|
| 38 | {
|
---|
| 39 | public:
|
---|
[677] | 40 | /// viewcells
|
---|
[697] | 41 | ViewCellContainer mViewCells;
|
---|
| 42 | /// aggregated pvs
|
---|
[677] | 43 | ObjectPvs mPvs;
|
---|
| 44 |
|
---|
| 45 | // input parameter is the render budget for the PrVS
|
---|
| 46 | float mRenderBudget;
|
---|
| 47 |
|
---|
| 48 | /// some characteristic values could be here
|
---|
| 49 |
|
---|
| 50 | };
|
---|
| 51 |
|
---|
[440] | 52 | /**
|
---|
| 53 | Manages different higher order operations on the view cells.
|
---|
| 54 | */
|
---|
| 55 | class ViewCellsManager
|
---|
| 56 | {
|
---|
| 57 |
|
---|
| 58 | public:
|
---|
[467] | 59 | struct PvsStatistics {
|
---|
| 60 | int minPvs;
|
---|
| 61 | int maxPvs;
|
---|
| 62 | float avgPvs;
|
---|
| 63 | int viewcells;
|
---|
| 64 | };
|
---|
[466] | 65 |
|
---|
[697] | 66 |
|
---|
[466] | 67 | /// view cell container types
|
---|
| 68 | enum {BSP, KD, VSP_KD, VSP_BSP};
|
---|
| 69 |
|
---|
[574] | 70 | /** Constructor taking the initial and construction samples.
|
---|
| 71 | @param initialSamples the maximal number of samples used for creating the hierarchy
|
---|
| 72 | of view cells
|
---|
| 73 | @param constructionSamples the maximal number of samples used for construction
|
---|
[440] | 74 | */
|
---|
[574] | 75 | ViewCellsManager(const int initialSamples, const int constructionSamples);
|
---|
[440] | 76 |
|
---|
| 77 | ViewCellsManager();
|
---|
| 78 |
|
---|
[462] | 79 | virtual ~ViewCellsManager();
|
---|
[440] | 80 |
|
---|
[527] | 81 | /** Constructs view cells container taking a preprocessor
|
---|
[570] | 82 | @returns the output rays (if not null)
|
---|
| 83 | */
|
---|
| 84 | int Construct(Preprocessor *preprocessor, VssRayContainer *outRays = NULL);
|
---|
[527] | 85 |
|
---|
[440] | 86 | /** Constructs view cell container with a given number of samples.
|
---|
| 87 | */
|
---|
[574] | 88 | virtual int ConstructSubdivision(const ObjectContainer &objects,
|
---|
[487] | 89 | const VssRayContainer &rays) = 0;
|
---|
[440] | 90 |
|
---|
[441] | 91 | /** Computes sample contributions of the rays to the view cells PVS.
|
---|
| 92 |
|
---|
| 93 | @param rays bundle of rays used to find intersections with view cells and
|
---|
| 94 | adding the contribution
|
---|
[563] | 95 | @param addRays true if rays should be added to the PVSs of the viewcells they
|
---|
[574] | 96 | intersect
|
---|
| 97 | @param storeViewCells true if view cells should be stored in the ray
|
---|
| 98 | */
|
---|
[697] | 99 | float ComputeSampleContributions(const VssRayContainer &rays,
|
---|
[574] | 100 | const bool addContributions,
|
---|
| 101 | const bool storeViewCells);
|
---|
[440] | 102 |
|
---|
[697] | 103 | /** Add sample contributions to the viewcells they intersect */
|
---|
| 104 | void AddSampleContributions(const VssRayContainer &rays);
|
---|
[563] | 105 |
|
---|
[441] | 106 |
|
---|
[475] | 107 | /** Computes sample contribution of a simgle ray to the view cells PVS.
|
---|
| 108 | @param ray finds intersections with view cells and holds the contribution
|
---|
| 109 | @param castRay true if ray should be cast to gain the information, false if ray
|
---|
| 110 | is already holding the information and need not be recast.
|
---|
[466] | 111 |
|
---|
[475] | 112 | @returns number of sample contributions
|
---|
| 113 | */
|
---|
[591] | 114 | virtual float ComputeSampleContributions(VssRay &ray,
|
---|
| 115 | const bool addRays,
|
---|
| 116 | const bool storeViewCells);
|
---|
[563] | 117 |
|
---|
[591] | 118 | virtual void AddSampleContributions(VssRay &ray);
|
---|
[563] | 119 |
|
---|
[452] | 120 | /** Prints out statistics of the view cells.
|
---|
| 121 | */
|
---|
[475] | 122 | virtual void PrintStatistics(ostream &s) const;
|
---|
[452] | 123 |
|
---|
[440] | 124 | /** Post processes view cells givemŽa number of rays.
|
---|
| 125 | */
|
---|
[475] | 126 | virtual int PostProcess(const ObjectContainer &objects,
|
---|
| 127 | const VssRayContainer &rays) = 0;
|
---|
[440] | 128 |
|
---|
| 129 | /** Show visualization of the view cells.
|
---|
| 130 | */
|
---|
| 131 | virtual void Visualize(const ObjectContainer &objects,
|
---|
[466] | 132 | const VssRayContainer &sampleRays) = 0;
|
---|
[440] | 133 |
|
---|
| 134 | /** type of the view cell container.
|
---|
| 135 | */
|
---|
| 136 | virtual int GetType() const = 0;
|
---|
| 137 |
|
---|
[463] | 138 | /** Load the input viewcells. The input viewcells should be given as a collection
|
---|
| 139 | of meshes. Each mesh is assume to form a bounded polyhedron defining the interior of
|
---|
| 140 | the viewcell. The method then builds a BSP tree of these view cells.
|
---|
| 141 |
|
---|
| 142 | @param filename file to load
|
---|
| 143 | @return true on success
|
---|
| 144 | */
|
---|
[577] | 145 | virtual bool LoadViewCellsGeometry(const string filename);
|
---|
[440] | 146 |
|
---|
[577] | 147 |
|
---|
[440] | 148 | /** Constructs view cell from base triangle. The ViewCell is extruded along the normal vector.
|
---|
| 149 | @param the base triangle
|
---|
| 150 | @param the height of the newly created view cell
|
---|
| 151 | */
|
---|
| 152 | ViewCell *ExtrudeViewCell(const Triangle3 &baseTri, const float height) const;
|
---|
| 153 |
|
---|
| 154 | /** Merges two view cells.
|
---|
| 155 | @note the piercing rays of the front and back will be ordered
|
---|
| 156 | @returns new view cell based on the merging.
|
---|
| 157 | */
|
---|
[582] | 158 | ViewCellInterior *MergeViewCells(ViewCell *front, ViewCell *back) const;
|
---|
| 159 |
|
---|
| 160 | /** Merges a container of view cells.
|
---|
| 161 | @returns new view cell based on the merging.
|
---|
| 162 | */
|
---|
| 163 | ViewCellInterior *MergeViewCells(ViewCellContainer &children) const;
|
---|
[440] | 164 |
|
---|
| 165 | /** Generates view cell of type specified by this manager
|
---|
| 166 | */
|
---|
[580] | 167 | virtual ViewCell *GenerateViewCell(Mesh *mesh = NULL) const = 0;
|
---|
[440] | 168 |
|
---|
| 169 | /** Adds a new view cell to the list of predefined view cells.
|
---|
| 170 | */
|
---|
| 171 | void AddViewCell(ViewCell *viewCell);
|
---|
| 172 |
|
---|
| 173 | /** Derive view cells from objects.
|
---|
| 174 | */
|
---|
| 175 | void DeriveViewCells(const ObjectContainer &objects,
|
---|
| 176 | ViewCellContainer &viewCells,
|
---|
| 177 | const int maxViewCells) const;
|
---|
| 178 |
|
---|
| 179 | /** Sets maximal number of samples used for the
|
---|
| 180 | construction of the view cells.
|
---|
| 181 | */
|
---|
| 182 | void SetVisualizationSamples(const int visSamples);
|
---|
| 183 |
|
---|
[574] | 184 | /** Sets maximal number of samples used for the construction of the view cells.
|
---|
[440] | 185 | */
|
---|
| 186 | void SetConstructionSamples(const int constructionSamples);
|
---|
| 187 |
|
---|
[574] | 188 | /** Sets maximal number of samples used for the visualization of the view cells.
|
---|
| 189 | */
|
---|
| 190 | void SetInitialSamples(const int initialSamples);
|
---|
| 191 |
|
---|
[440] | 192 | /** Sets maximal number of samples used for the post processing of the view cells.
|
---|
| 193 | */
|
---|
| 194 | void SetPostProcessSamples(const int postProcessingSamples);
|
---|
| 195 |
|
---|
| 196 | /** See set.
|
---|
| 197 | */
|
---|
| 198 | int GetVisualizationSamples() const;
|
---|
| 199 |
|
---|
| 200 | /** See set.
|
---|
| 201 | */
|
---|
| 202 | int GetConstructionSamples() const;
|
---|
| 203 |
|
---|
| 204 | /** See set.
|
---|
| 205 | */
|
---|
| 206 | int GetPostProcessSamples() const;
|
---|
| 207 |
|
---|
| 208 | /** Returns true if view cells wer already constructed.
|
---|
| 209 | */
|
---|
| 210 | virtual bool ViewCellsConstructed() const = 0;
|
---|
[441] | 211 |
|
---|
[477] | 212 | /** cast line segment to get a list of unique viewcells which are intersected
|
---|
| 213 | by this line segment
|
---|
| 214 | */
|
---|
[466] | 215 |
|
---|
[477] | 216 | virtual int CastLineSegment(const Vector3 &origin,
|
---|
[466] | 217 | const Vector3 &termination,
|
---|
| 218 | ViewCellContainer &viewcells
|
---|
| 219 | ) = 0;
|
---|
| 220 |
|
---|
[477] | 221 | virtual void GetPvsStatistics(PvsStatistics &stat);
|
---|
[466] | 222 |
|
---|
[697] | 223 | virtual void GetPrVS(const Vector3 &viewPoint, PrVs &prvs);
|
---|
[677] | 224 |
|
---|
[697] | 225 | /** Get a viewcell containing the specified point
|
---|
| 226 | */
|
---|
[569] | 227 | virtual ViewCell *GetViewCell(const Vector3 &point) const = 0;
|
---|
[492] | 228 |
|
---|
[503] | 229 | virtual void PrintPvsStatistics(ostream &s);
|
---|
[467] | 230 |
|
---|
[477] | 231 | /** Returns probability that view point lies in one view cell.
|
---|
| 232 | */
|
---|
| 233 | virtual float GetProbability(ViewCell *viewCell) = 0;
|
---|
[468] | 234 |
|
---|
[477] | 235 | /** Returns render cost of a single view cell given the render cost of an object.
|
---|
| 236 | */
|
---|
[609] | 237 | float GetRendercost(ViewCell *viewCell, float objRendercost) const;
|
---|
[468] | 238 |
|
---|
[580] | 239 | /** Returns container of loaded / generated view cells.
|
---|
[477] | 240 | */
|
---|
| 241 | ViewCellContainer &GetViewCells();
|
---|
[468] | 242 |
|
---|
[485] | 243 | /** Helper function used to split ray sets uniformly
|
---|
| 244 | into one that is currently used and the other that
|
---|
| 245 | is saved for later processing.
|
---|
| 246 | @param sourceRays the input ray set
|
---|
| 247 | @param maxSize the maximal number of rays that will be used
|
---|
| 248 | @param usedRays returns the used ray set
|
---|
| 249 | @param savedRays if not null, returns the saved ray set
|
---|
[477] | 250 | */
|
---|
| 251 | void GetRaySets(const VssRayContainer &sourceRays,
|
---|
[485] | 252 | const int maxSize,
|
---|
| 253 | VssRayContainer &usedRays,
|
---|
| 254 | VssRayContainer *savedRays = NULL) const;
|
---|
| 255 |
|
---|
[480] | 256 | /** Returns accumulated area of all view cells.
|
---|
| 257 | */
|
---|
| 258 | float GetAccVcArea();
|
---|
[470] | 259 |
|
---|
[480] | 260 | /** Returns area of one view cell.
|
---|
| 261 | */
|
---|
| 262 | virtual float GetArea(ViewCell *viewCell) const;
|
---|
[470] | 263 |
|
---|
[551] | 264 | /** Returns volume of view cell.
|
---|
[480] | 265 | */
|
---|
| 266 | virtual float GetVolume(ViewCell *viewCell) const;
|
---|
[470] | 267 |
|
---|
[480] | 268 | /** Sets the current renderer mainly for view cells statistics.
|
---|
| 269 | */
|
---|
| 270 | void SetRenderer(Renderer *renderer);
|
---|
| 271 |
|
---|
[487] | 272 | /** Computes a (random) view point in the valid view space.
|
---|
| 273 | @returns true if valid view point was found
|
---|
| 274 | */
|
---|
| 275 | virtual bool GetViewPoint(Vector3 &viewPoint) const;
|
---|
| 276 |
|
---|
[490] | 277 | /** Returns true if this view point is in the valid view space.
|
---|
| 278 | */
|
---|
| 279 | virtual bool ViewPointValid(const Vector3 &viewPoint) const;
|
---|
| 280 |
|
---|
[487] | 281 | /** Sets a view space boundary.
|
---|
| 282 | */
|
---|
| 283 | void SetViewSpaceBox(const AxisAlignedBox3 &box);
|
---|
| 284 |
|
---|
[519] | 285 | AxisAlignedBox3 GetViewSpaceBox() const;
|
---|
| 286 |
|
---|
[503] | 287 | /** Creates mesh for this view cell.
|
---|
| 288 | */
|
---|
| 289 | virtual void CreateMesh(ViewCell *vc) = NULL;
|
---|
[487] | 290 |
|
---|
[508] | 291 | /** Writes view cells to disc.
|
---|
| 292 | */
|
---|
| 293 | virtual bool ExportViewCells(const string filename);
|
---|
| 294 |
|
---|
[532] | 295 | /** Casts beam to collect view cells.
|
---|
| 296 | */
|
---|
| 297 | virtual int CastBeam(Beam &beam);
|
---|
| 298 |
|
---|
[547] | 299 | /** Checks if view cell is considered as valid.
|
---|
| 300 | */
|
---|
[561] | 301 | virtual bool CheckValidity(ViewCell *vc,
|
---|
[562] | 302 | int minPvsSize,
|
---|
| 303 | int maxPvsSize) const;
|
---|
[547] | 304 |
|
---|
[562] | 305 |
|
---|
| 306 | /** Sets validity of view cell
|
---|
| 307 | */
|
---|
| 308 | virtual void SetValidity(ViewCell *vc,
|
---|
| 309 | int minPvsSize,
|
---|
| 310 | int maxPvsSize) const;
|
---|
| 311 |
|
---|
[569] | 312 | /** sets validy of all viewcells */
|
---|
| 313 | virtual void SetValidity(
|
---|
| 314 | int minPvsSize,
|
---|
| 315 | int maxPvsSize) const;
|
---|
| 316 |
|
---|
[609] | 317 |
|
---|
| 318 | /** set valid viewcells in the range of pvs. sorts the viewcells
|
---|
[569] | 319 | according to the pvs and then pickups those in the ranges */
|
---|
| 320 |
|
---|
[609] | 321 |
|
---|
| 322 | void SetValidityPercentage(const float minValid, const float maxValid);
|
---|
[569] | 323 |
|
---|
[609] | 324 | int CountValidViewcells() const;
|
---|
| 325 |
|
---|
[547] | 326 | /** Returns maximal allowed pvs size.
|
---|
| 327 | */
|
---|
| 328 | int GetMaxPvsSize() const;
|
---|
| 329 |
|
---|
[562] | 330 | /** Returns maximal allowed pvs size.
|
---|
| 331 | */
|
---|
| 332 | int GetMinPvsSize() const;
|
---|
| 333 |
|
---|
[561] | 334 | /** Returns maximal ratio. i.e., currentPVs / maxPvs,
|
---|
| 335 | where pvs is still considered valid.
|
---|
| 336 | */
|
---|
| 337 | float GetMaxPvsRatio() const;
|
---|
| 338 |
|
---|
[547] | 339 | /** Exports view cell geometry.
|
---|
| 340 | */
|
---|
[591] | 341 | virtual void ExportViewCellGeometry(Exporter *exporter,
|
---|
| 342 | ViewCell *vc,
|
---|
[660] | 343 | const Plane3 *clipPlane = NULL) const = 0;
|
---|
[547] | 344 |
|
---|
[551] | 345 | virtual void FinalizeViewCells(const bool createMesh);
|
---|
| 346 |
|
---|
[577] | 347 |
|
---|
[591] | 348 | /** Loads view cells from file. The view cells manager is created with
|
---|
| 349 | respect to the loaded view cells.
|
---|
[577] | 350 |
|
---|
| 351 | @returns the view cells manager if loading was successful, false otherwise
|
---|
| 352 | */
|
---|
[591] | 353 | static ViewCellsManager *LoadViewCells(const string filename,
|
---|
| 354 | ObjectContainer *objects);
|
---|
[577] | 355 |
|
---|
[579] | 356 | /** Evaluates statistics values on view cells.
|
---|
| 357 | */
|
---|
[580] | 358 | void EvaluateRenderStatistics(float &totalRenderCost,
|
---|
| 359 | float &expectedRenderCost,
|
---|
| 360 | float &deviation,
|
---|
| 361 | float &variance,
|
---|
| 362 | int &totalPvs,
|
---|
| 363 | float &avgRenderCost);
|
---|
[579] | 364 |
|
---|
[580] | 365 |
|
---|
| 366 | /** Returns hierarchy of the view cells.
|
---|
| 367 | */
|
---|
| 368 | ViewCellsTree *GetViewCellsTree();
|
---|
| 369 |
|
---|
[581] | 370 | virtual void CollectMergeCandidates(const VssRayContainer &rays,
|
---|
| 371 | vector<MergeCandidate> &candidates) = 0;
|
---|
[580] | 372 |
|
---|
[610] | 373 | void CollectViewCells(const int n);
|
---|
| 374 |
|
---|
[660] | 375 | /** Returns true if this (logical) view cell is equal to a spatial node.
|
---|
| 376 | */
|
---|
[610] | 377 | virtual bool EqualToSpatialNode(ViewCell *viewCell) const { return false;}
|
---|
[580] | 378 |
|
---|
[660] | 379 | /** Sets current view cells set to active, i.e., the sampling is done in this view cell set.
|
---|
| 380 | */
|
---|
| 381 | void SetViewCellsActive();
|
---|
[599] | 382 |
|
---|
[660] | 383 | /** Evaluates worth of current view cell hierarchy.
|
---|
| 384 | */
|
---|
[664] | 385 | void EvalViewCellPartition(Preprocessor *preprocessor);
|
---|
[660] | 386 |
|
---|
[697] | 387 |
|
---|
[469] | 388 | protected:
|
---|
[480] | 389 |
|
---|
[697] | 390 | /** Returns the bounding box of filter width.
|
---|
| 391 | */
|
---|
| 392 | AxisAlignedBox3 GetFilterBBox(const Vector3 &viewPoint, const float width) const;
|
---|
[609] | 393 |
|
---|
[697] | 394 | /** Intersects box with the tree and returns the number of intersected boxes.
|
---|
| 395 | @returns number of view cells found
|
---|
| 396 | */
|
---|
| 397 | virtual int ComputeBoxIntersections(const AxisAlignedBox3 &box, ViewCellContainer &viewCells) const {return 0;};
|
---|
| 398 |
|
---|
| 399 | virtual void TestFilter(const ObjectContainer &objects) {};
|
---|
| 400 |
|
---|
[581] | 401 | /**
|
---|
| 402 | if the view cells tree was already constructed or not.
|
---|
| 403 | */
|
---|
| 404 | bool ViewCellsTreeConstructed() const;
|
---|
| 405 |
|
---|
[574] | 406 | int CastPassSamples(const int samplesPerPass,
|
---|
| 407 | const int sampleType,
|
---|
| 408 | VssRayContainer &vssRays) const;
|
---|
[573] | 409 |
|
---|
[482] | 410 | void ParseEnvironment();
|
---|
| 411 |
|
---|
[508] | 412 | /** Creates unique view cell ids.
|
---|
| 413 | */
|
---|
| 414 | void CreateUniqueViewCellIds();
|
---|
[547] | 415 |
|
---|
[551] | 416 | /** Finalizes, i.e., creates mesh, volume, area etc. for the view cell.
|
---|
| 417 | */
|
---|
| 418 | virtual void Finalize(ViewCell *viewCell, const bool createMesh);
|
---|
| 419 |
|
---|
[480] | 420 | /** Recollects view cells and resets statistics.
|
---|
| 421 | */
|
---|
| 422 | void ResetViewCells();
|
---|
[482] | 423 |
|
---|
[480] | 424 | /** Collects the view cells in the view cell container.
|
---|
| 425 | */
|
---|
| 426 | virtual void CollectViewCells() = 0;
|
---|
[482] | 427 |
|
---|
[479] | 428 | /** Evaluates view cells statistics and stores it in
|
---|
| 429 | mViewCellsStatistics.
|
---|
| 430 | */
|
---|
| 431 | void EvaluateViewCellsStats();
|
---|
[482] | 432 |
|
---|
| 433 | //-- helper functions for view cell visualization
|
---|
| 434 |
|
---|
| 435 | /** Exports the view cell partition.
|
---|
| 436 | */
|
---|
[508] | 437 | void ExportViewCellsForViz(Exporter *exporter) const;
|
---|
[482] | 438 |
|
---|
| 439 | /** Sets exporter color.
|
---|
| 440 | */
|
---|
| 441 | virtual void ExportColor(Exporter *exporter, ViewCell *vc) const = 0;
|
---|
| 442 |
|
---|
[556] | 443 |
|
---|
[557] | 444 | virtual float GetViewSpaceVolume();
|
---|
| 445 |
|
---|
[503] | 446 | /** Creates meshes from the view cells.
|
---|
| 447 | */
|
---|
[517] | 448 | void CreateViewCellMeshes();
|
---|
[503] | 449 |
|
---|
[610] | 450 | /** Takes different measures to prepares the view cells after loading them from disc.
|
---|
[577] | 451 | */
|
---|
| 452 | virtual void PrepareLoadedViewCells() {};
|
---|
| 453 |
|
---|
[660] | 454 | /** Creates clip plane for visualization.
|
---|
| 455 | */
|
---|
| 456 | void CreateClipPlane();
|
---|
[591] | 457 |
|
---|
[660] | 458 | Plane3 mClipPlane;
|
---|
| 459 | bool mUseClipPlaneForViz;
|
---|
[591] | 460 |
|
---|
| 461 |
|
---|
[480] | 462 | /// Renders the view cells.
|
---|
| 463 | Renderer *mRenderer;
|
---|
[440] | 464 |
|
---|
| 465 | /// Loaded view cells
|
---|
[469] | 466 | ViewCellContainer mViewCells;
|
---|
[440] | 467 |
|
---|
[580] | 468 | ViewCellsTree *mViewCellsTree;
|
---|
| 469 |
|
---|
[440] | 470 | /// maximum number of samples taken for construction of the view cells
|
---|
| 471 | int mConstructionSamples;
|
---|
[574] | 472 | int mSamplesPerPass;
|
---|
| 473 | int mInitialSamples;
|
---|
[440] | 474 | int mPostProcessSamples;
|
---|
| 475 | int mVisualizationSamples;
|
---|
[441] | 476 |
|
---|
[470] | 477 | float mTotalAreaValid;
|
---|
| 478 | float mTotalArea;
|
---|
[475] | 479 |
|
---|
[547] | 480 | int mMaxPvsSize;
|
---|
[562] | 481 | int mMinPvsSize;
|
---|
[547] | 482 | float mMaxPvsRatio;
|
---|
| 483 |
|
---|
[660] | 484 | int mSamplingType;
|
---|
[600] | 485 | int mNumActiveViewCells;
|
---|
[586] | 486 | bool mCompressViewCells;
|
---|
| 487 |
|
---|
[660] | 488 | ViewCellsStatistics mCurrentViewCellsStats;
|
---|
[487] | 489 | /// the scene bounding box
|
---|
[542] | 490 | AxisAlignedBox3 mViewSpaceBox;
|
---|
[508] | 491 | /// holds the view cell meshes
|
---|
[503] | 492 | MeshContainer mMeshContainer;
|
---|
[508] | 493 | /// if view cells should be exported
|
---|
| 494 | bool mExportViewCells;
|
---|
[547] | 495 |
|
---|
[591] | 496 | //bool mMarchTree);
|
---|
[564] | 497 | bool mOnlyValidViewCells;
|
---|
[547] | 498 |
|
---|
[580] | 499 | /// if rays should be used to collect merge candidates
|
---|
| 500 | bool mUseRaysForMerge;
|
---|
[697] | 501 | /// merge the view cells?
|
---|
[592] | 502 | bool mMergeViewCells;
|
---|
[697] | 503 |
|
---|
| 504 | /// the width of the box filter
|
---|
| 505 | float mFilterWidth;
|
---|
| 506 | int mMaxFilterSize;
|
---|
| 507 |
|
---|
[487] | 508 | //-- visualization options
|
---|
| 509 |
|
---|
| 510 | /// color code for view cells
|
---|
| 511 | int mColorCode;
|
---|
| 512 | bool mExportGeometry;
|
---|
| 513 | bool mExportRays;
|
---|
[517] | 514 |
|
---|
| 515 | bool mViewCellsFinished;
|
---|
[664] | 516 |
|
---|
| 517 | bool mEvaluateViewCells;
|
---|
[666] | 518 |
|
---|
[693] | 519 | bool mShowVisualization;
|
---|
| 520 |
|
---|
| 521 | // HACK in order to detect empty view cells
|
---|
| 522 | void CollectEmptyViewCells();
|
---|
[694] | 523 | void TestEmptyViewCells(const ObjectContainer &obj);
|
---|
[693] | 524 |
|
---|
| 525 | ViewCellContainer mEmptyViewCells;
|
---|
[440] | 526 | };
|
---|
| 527 |
|
---|
[441] | 528 |
|
---|
| 529 |
|
---|
[440] | 530 | /**
|
---|
| 531 | Manages different higher order operations on the view cells.
|
---|
| 532 | */
|
---|
| 533 | class BspViewCellsManager: public ViewCellsManager
|
---|
| 534 | {
|
---|
| 535 |
|
---|
| 536 | public:
|
---|
[485] | 537 | /** Constructor taking the bsp tree and the number of samples
|
---|
| 538 | used to construct the bsp tree.
|
---|
| 539 | */
|
---|
[574] | 540 | BspViewCellsManager(BspTree *tree);
|
---|
[440] | 541 |
|
---|
[477] | 542 | ~BspViewCellsManager();
|
---|
| 543 |
|
---|
[574] | 544 | int ConstructSubdivision(const ObjectContainer &objects,
|
---|
[487] | 545 | const VssRayContainer &rays);
|
---|
[440] | 546 |
|
---|
| 547 | int PostProcess(const ObjectContainer &objects,
|
---|
[466] | 548 | const VssRayContainer &rays);
|
---|
[440] | 549 |
|
---|
| 550 | void Visualize(const ObjectContainer &objects,
|
---|
[466] | 551 | const VssRayContainer &sampleRays);
|
---|
[440] | 552 |
|
---|
| 553 | int GetType() const;
|
---|
| 554 |
|
---|
| 555 | ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
|
---|
| 556 |
|
---|
| 557 | bool ViewCellsConstructed() const;
|
---|
| 558 |
|
---|
[475] | 559 | //void PrintStatistics(ostream &s) const;
|
---|
[452] | 560 |
|
---|
[468] | 561 | int CastLineSegment(const Vector3 &origin,
|
---|
| 562 | const Vector3 &termination,
|
---|
| 563 | ViewCellContainer &viewcells);
|
---|
| 564 |
|
---|
[471] | 565 | float GetProbability(ViewCell *viewCell);
|
---|
[605] | 566 |
|
---|
[466] | 567 |
|
---|
[503] | 568 | /** Get a viewcell containing the specified point */
|
---|
[569] | 569 | ViewCell *GetViewCell(const Vector3 &point) const;
|
---|
[492] | 570 |
|
---|
[503] | 571 | void CreateMesh(ViewCell *vc);
|
---|
| 572 |
|
---|
[591] | 573 | void ExportViewCellGeometry(Exporter *exporter,
|
---|
| 574 | ViewCell *vc,
|
---|
[660] | 575 | const Plane3 *clipPlane = NULL) const;
|
---|
[580] | 576 |
|
---|
[587] | 577 | void CollectMergeCandidates(const VssRayContainer &rays,
|
---|
| 578 | vector<MergeCandidate> &candidates);
|
---|
[547] | 579 |
|
---|
[587] | 580 | void Finalize(ViewCell *viewCell, const bool createMesh);
|
---|
| 581 |
|
---|
[590] | 582 | bool ExportViewCells(const string filename);
|
---|
| 583 |
|
---|
[650] | 584 | ViewCell *ConstructSpatialMergeTree(BspNode *root);
|
---|
[610] | 585 |
|
---|
| 586 |
|
---|
[440] | 587 | protected:
|
---|
| 588 |
|
---|
[610] | 589 |
|
---|
[590] | 590 | /** HACK
|
---|
| 591 | */
|
---|
| 592 | void AddCurrentViewCellsToHierarchy();
|
---|
| 593 |
|
---|
[480] | 594 | void CollectViewCells();
|
---|
| 595 |
|
---|
[482] | 596 | void ExportColor(Exporter *exporter, ViewCell *vc) const;
|
---|
[547] | 597 |
|
---|
[482] | 598 |
|
---|
[547] | 599 |
|
---|
[440] | 600 | /// the BSP tree.
|
---|
| 601 | BspTree *mBspTree;
|
---|
[475] | 602 |
|
---|
| 603 | vector<BspRay *> mBspRays;
|
---|
[440] | 604 |
|
---|
| 605 | private:
|
---|
| 606 |
|
---|
| 607 | /** Exports visualization of the BSP splits.
|
---|
| 608 | */
|
---|
[477] | 609 | void ExportSplits(const ObjectContainer &objects);
|
---|
[440] | 610 |
|
---|
| 611 | /** Exports visualization of the BSP PVS.
|
---|
| 612 | */
|
---|
[477] | 613 | void ExportBspPvs(const ObjectContainer &objects);
|
---|
[440] | 614 |
|
---|
[693] | 615 | void TestSubdivision();
|
---|
[440] | 616 | };
|
---|
| 617 |
|
---|
| 618 | /**
|
---|
| 619 | Manages different higher order operations on the KD type view cells.
|
---|
| 620 | */
|
---|
| 621 | class KdViewCellsManager: public ViewCellsManager
|
---|
| 622 | {
|
---|
| 623 |
|
---|
| 624 | public:
|
---|
| 625 |
|
---|
| 626 | KdViewCellsManager(KdTree *tree);
|
---|
| 627 |
|
---|
[574] | 628 | int ConstructSubdivision(const ObjectContainer &objects,
|
---|
[487] | 629 | const VssRayContainer &rays);
|
---|
[440] | 630 |
|
---|
[478] | 631 | int CastLineSegment(const Vector3 &origin,
|
---|
| 632 | const Vector3 &termination,
|
---|
| 633 | ViewCellContainer &viewcells);
|
---|
[440] | 634 |
|
---|
| 635 | int PostProcess(const ObjectContainer &objects,
|
---|
[466] | 636 | const VssRayContainer &rays);
|
---|
[440] | 637 |
|
---|
| 638 | void Visualize(const ObjectContainer &objects,
|
---|
[466] | 639 | const VssRayContainer &sampleRays);
|
---|
[440] | 640 |
|
---|
| 641 | int GetType() const;
|
---|
| 642 |
|
---|
| 643 | bool ViewCellsConstructed() const;
|
---|
| 644 |
|
---|
[580] | 645 | ViewCell *GenerateViewCell(Mesh *mesh) const;
|
---|
[440] | 646 |
|
---|
[452] | 647 | /** Prints out statistics of this approach.
|
---|
| 648 | */
|
---|
[503] | 649 | // virtual void PrintStatistics(ostream &s) const;
|
---|
[569] | 650 | ViewCell *GetViewCell(const Vector3 &point) const { return NULL; }
|
---|
[452] | 651 |
|
---|
[503] | 652 | float GetProbability(ViewCell *viewCell);
|
---|
[609] | 653 |
|
---|
[468] | 654 |
|
---|
[503] | 655 | void CreateMesh(ViewCell *vc);
|
---|
| 656 |
|
---|
[591] | 657 | void ExportViewCellGeometry(Exporter *exporter,
|
---|
| 658 | ViewCell *vc,
|
---|
[660] | 659 | const Plane3 *clipPlane = NULL) const;
|
---|
[547] | 660 |
|
---|
[591] | 661 | void CollectMergeCandidates(const VssRayContainer &rays,
|
---|
| 662 | vector<MergeCandidate> &candidates);
|
---|
[580] | 663 |
|
---|
[440] | 664 | protected:
|
---|
| 665 |
|
---|
[580] | 666 | /** Collects view cells from a hierarchy.
|
---|
| 667 | */
|
---|
[480] | 668 | void CollectViewCells();
|
---|
[580] | 669 |
|
---|
[480] | 670 | KdNode *GetNodeForPvs(KdLeaf *leaf);
|
---|
[440] | 671 |
|
---|
[482] | 672 | void ExportColor(Exporter *exporter, ViewCell *vc) const;
|
---|
[440] | 673 |
|
---|
[547] | 674 |
|
---|
[480] | 675 | /// the BSP tree.
|
---|
| 676 | KdTree *mKdTree;
|
---|
[440] | 677 |
|
---|
[480] | 678 | /// depth of the KD tree nodes with represent the view cells
|
---|
| 679 | int mKdPvsDepth;
|
---|
[440] | 680 | };
|
---|
| 681 |
|
---|
| 682 | /**
|
---|
| 683 | Manages different higher order operations on the view cells
|
---|
| 684 | for vsp kd tree view cells.
|
---|
| 685 | */
|
---|
| 686 | class VspKdViewCellsManager: public ViewCellsManager
|
---|
| 687 | {
|
---|
| 688 |
|
---|
| 689 | public:
|
---|
| 690 |
|
---|
[574] | 691 | VspKdViewCellsManager(VspKdTree *vspKdTree);
|
---|
[440] | 692 |
|
---|
[574] | 693 | int ConstructSubdivision(const ObjectContainer &objects,
|
---|
[487] | 694 | const VssRayContainer &rays);
|
---|
[440] | 695 |
|
---|
| 696 |
|
---|
| 697 | int PostProcess(const ObjectContainer &objects,
|
---|
[466] | 698 | const VssRayContainer &rays);
|
---|
[440] | 699 |
|
---|
| 700 | void Visualize(const ObjectContainer &objects,
|
---|
[466] | 701 | const VssRayContainer &sampleRays);
|
---|
[440] | 702 |
|
---|
| 703 | int GetType() const;
|
---|
| 704 |
|
---|
| 705 | bool ViewCellsConstructed() const;
|
---|
| 706 |
|
---|
[475] | 707 | //virtual void PrintStatistics(ostream &s) const;
|
---|
[440] | 708 |
|
---|
[462] | 709 | ViewCell *GenerateViewCell(Mesh *mesh) const;
|
---|
| 710 |
|
---|
[466] | 711 |
|
---|
| 712 | int CastLineSegment(const Vector3 &origin,
|
---|
| 713 | const Vector3 &termination,
|
---|
[468] | 714 | ViewCellContainer &viewcells);
|
---|
[466] | 715 |
|
---|
[569] | 716 | ViewCell *GetViewCell(const Vector3 &point) const { return NULL; }
|
---|
[492] | 717 |
|
---|
[471] | 718 | float GetProbability(ViewCell *viewCell);
|
---|
[468] | 719 |
|
---|
[609] | 720 |
|
---|
[503] | 721 | void CreateMesh(ViewCell *vc);
|
---|
| 722 |
|
---|
[591] | 723 | void ExportViewCellGeometry(Exporter *exporter,
|
---|
| 724 | ViewCell *vc,
|
---|
[660] | 725 | const Plane3 *clipPlane = NULL) const;
|
---|
[547] | 726 |
|
---|
[580] | 727 | void CollectMergeCandidates(const VssRayContainer &rays, vector<MergeCandidate> &candidates);
|
---|
| 728 |
|
---|
[440] | 729 | protected:
|
---|
| 730 |
|
---|
[482] | 731 | void ExportLeaves(const ObjectContainer &objects,
|
---|
| 732 | const VssRayContainer &sampleRays);
|
---|
| 733 |
|
---|
[480] | 734 | void CollectViewCells();
|
---|
| 735 |
|
---|
[482] | 736 | void ExportColor(Exporter *exporter, ViewCell *vc) const;
|
---|
| 737 |
|
---|
| 738 |
|
---|
[547] | 739 |
|
---|
[440] | 740 | /// the BSP tree.
|
---|
| 741 | VspKdTree *mVspKdTree;
|
---|
| 742 | };
|
---|
| 743 |
|
---|
| 744 |
|
---|
[442] | 745 |
|
---|
| 746 | /**
|
---|
| 747 | Manages different higher order operations on the view cells.
|
---|
| 748 | */
|
---|
| 749 | class VspBspViewCellsManager: public ViewCellsManager
|
---|
| 750 | {
|
---|
| 751 |
|
---|
| 752 | public:
|
---|
| 753 |
|
---|
[574] | 754 | VspBspViewCellsManager(VspBspTree *tree);
|
---|
[475] | 755 | ~VspBspViewCellsManager();
|
---|
[442] | 756 |
|
---|
[574] | 757 | int ConstructSubdivision(const ObjectContainer &objects,
|
---|
[487] | 758 | const VssRayContainer &rays);
|
---|
[442] | 759 |
|
---|
| 760 | int PostProcess(const ObjectContainer &objects,
|
---|
[466] | 761 | const VssRayContainer &rays);
|
---|
[442] | 762 |
|
---|
| 763 | void Visualize(const ObjectContainer &objects,
|
---|
[466] | 764 | const VssRayContainer &sampleRays);
|
---|
[442] | 765 |
|
---|
| 766 | int GetType() const;
|
---|
| 767 |
|
---|
| 768 | ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
|
---|
| 769 |
|
---|
| 770 | bool ViewCellsConstructed() const;
|
---|
| 771 |
|
---|
[468] | 772 |
|
---|
| 773 | int CastLineSegment(const Vector3 &origin,
|
---|
| 774 | const Vector3 &termination,
|
---|
| 775 | ViewCellContainer &viewcells);
|
---|
[452] | 776 |
|
---|
[471] | 777 | float GetProbability(ViewCell *viewCell);
|
---|
[479] | 778 |
|
---|
[569] | 779 | ViewCell *GetViewCell(const Vector3 &point) const;
|
---|
[477] | 780 |
|
---|
[487] | 781 | bool GetViewPoint(Vector3 &viewPoint) const;
|
---|
| 782 |
|
---|
[490] | 783 | bool ViewPointValid(const Vector3 &viewPoint) const;
|
---|
[503] | 784 |
|
---|
| 785 | void CreateMesh(ViewCell *vc);
|
---|
| 786 |
|
---|
[577] | 787 | //bool LoadViewCellsGeometry(const string filename, ObjectContainer *objects);
|
---|
[508] | 788 | bool ExportViewCells(const string filename);
|
---|
| 789 |
|
---|
[532] | 790 | int CastBeam(Beam &beam);
|
---|
| 791 |
|
---|
[591] | 792 | void ExportViewCellGeometry(Exporter *exporter,
|
---|
| 793 | ViewCell *vc,
|
---|
[660] | 794 | const Plane3 *clipPlane = NULL) const;
|
---|
[547] | 795 |
|
---|
[551] | 796 | //float GetVolume(ViewCell *viewCell) const;
|
---|
| 797 |
|
---|
[555] | 798 | void Finalize(ViewCell *viewCell, const bool createMesh);
|
---|
[551] | 799 |
|
---|
[580] | 800 | void CollectMergeCandidates(const VssRayContainer &rays, vector<MergeCandidate> &candidates);
|
---|
| 801 |
|
---|
[697] | 802 | /** Returns true if this view cell is equivavalent to a spatial node.
|
---|
| 803 | */
|
---|
[609] | 804 | bool EqualToSpatialNode(ViewCell *viewCell) const;
|
---|
[607] | 805 |
|
---|
[697] | 806 |
|
---|
[442] | 807 | protected:
|
---|
[475] | 808 |
|
---|
[697] | 809 | int ComputeBoxIntersections(const AxisAlignedBox3 &box, ViewCellContainer &viewCells) const;
|
---|
[651] | 810 |
|
---|
[610] | 811 | /** Returns node of the spatial hierarchy corresponding to the view cell
|
---|
| 812 | if such a node exists.
|
---|
| 813 | */
|
---|
[609] | 814 | BspNode *GetSpatialNode(ViewCell *viewCell) const;
|
---|
[610] | 815 |
|
---|
[590] | 816 | /** HACK
|
---|
| 817 | */
|
---|
| 818 | void AddCurrentViewCellsToHierarchy();
|
---|
| 819 |
|
---|
[503] | 820 | /** Merges the view cells.
|
---|
[442] | 821 | */
|
---|
[508] | 822 | void MergeViewCells(const VssRayContainer &rays,
|
---|
| 823 | const ObjectContainer &objects);
|
---|
[503] | 824 |
|
---|
[564] | 825 | void RefineViewCells(const VssRayContainer &rays, const ObjectContainer &objects);
|
---|
[442] | 826 |
|
---|
[480] | 827 | void CollectViewCells();
|
---|
| 828 |
|
---|
[482] | 829 | /** Returns maximal depth difference of view cell
|
---|
| 830 | leaves in tree.
|
---|
| 831 | */
|
---|
| 832 | int GetMaxTreeDiff(ViewCell *vc) const;
|
---|
[485] | 833 |
|
---|
[482] | 834 |
|
---|
[485] | 835 | void ExportColor(Exporter *exporter, ViewCell *vc) const;
|
---|
| 836 |
|
---|
[577] | 837 | void PrepareLoadedViewCells();
|
---|
| 838 |
|
---|
[650] | 839 | ViewCell *ConstructSpatialMergeTree(BspNode *root);
|
---|
[649] | 840 |
|
---|
[697] | 841 | void TestFilter(const ObjectContainer &objects);
|
---|
| 842 |
|
---|
| 843 |
|
---|
| 844 |
|
---|
[442] | 845 | /// the view space partition BSP tree.
|
---|
| 846 | VspBspTree *mVspBspTree;
|
---|
| 847 |
|
---|
[591] | 848 |
|
---|
[442] | 849 | private:
|
---|
| 850 |
|
---|
| 851 | /** Exports visualization of the BSP splits.
|
---|
| 852 | */
|
---|
[485] | 853 | void ExportSplits(const ObjectContainer &objects,
|
---|
| 854 | const VssRayContainer &rays);
|
---|
[442] | 855 |
|
---|
| 856 | /** Exports visualization of the BSP PVS.
|
---|
| 857 | */
|
---|
[485] | 858 | void ExportBspPvs(const ObjectContainer &objects,
|
---|
| 859 | const VssRayContainer &rays);
|
---|
[442] | 860 |
|
---|
[693] | 861 | void TestSubdivision();
|
---|
[442] | 862 | };
|
---|
| 863 |
|
---|
[575] | 864 |
|
---|
| 865 | class ViewCellsManagerFactory
|
---|
| 866 | {
|
---|
| 867 |
|
---|
| 868 | public:
|
---|
| 869 |
|
---|
| 870 | ViewCellsManager *Create(const string mName);
|
---|
| 871 |
|
---|
| 872 | };
|
---|
| 873 |
|
---|
[440] | 874 | #endif
|
---|