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