[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 |
|
---|
[676] | 502 | bool mShowVisualization;
|
---|
[440] | 503 | };
|
---|
| 504 |
|
---|
[441] | 505 |
|
---|
| 506 |
|
---|
[440] | 507 | /**
|
---|
| 508 | Manages different higher order operations on the view cells.
|
---|
| 509 | */
|
---|
| 510 | class BspViewCellsManager: public ViewCellsManager
|
---|
| 511 | {
|
---|
| 512 |
|
---|
| 513 | public:
|
---|
[485] | 514 | /** Constructor taking the bsp tree and the number of samples
|
---|
| 515 | used to construct the bsp tree.
|
---|
| 516 | */
|
---|
[574] | 517 | BspViewCellsManager(BspTree *tree);
|
---|
[440] | 518 |
|
---|
[477] | 519 | ~BspViewCellsManager();
|
---|
| 520 |
|
---|
[574] | 521 | int ConstructSubdivision(const ObjectContainer &objects,
|
---|
[487] | 522 | const VssRayContainer &rays);
|
---|
[440] | 523 |
|
---|
| 524 | int PostProcess(const ObjectContainer &objects,
|
---|
[466] | 525 | const VssRayContainer &rays);
|
---|
[440] | 526 |
|
---|
| 527 | void Visualize(const ObjectContainer &objects,
|
---|
[466] | 528 | const VssRayContainer &sampleRays);
|
---|
[440] | 529 |
|
---|
| 530 | int GetType() const;
|
---|
| 531 |
|
---|
| 532 | ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
|
---|
| 533 |
|
---|
| 534 | bool ViewCellsConstructed() const;
|
---|
| 535 |
|
---|
[475] | 536 | //void PrintStatistics(ostream &s) const;
|
---|
[452] | 537 |
|
---|
[468] | 538 | int CastLineSegment(const Vector3 &origin,
|
---|
| 539 | const Vector3 &termination,
|
---|
| 540 | ViewCellContainer &viewcells);
|
---|
| 541 |
|
---|
[471] | 542 | float GetProbability(ViewCell *viewCell);
|
---|
[605] | 543 |
|
---|
[466] | 544 |
|
---|
[503] | 545 | /** Get a viewcell containing the specified point */
|
---|
[569] | 546 | ViewCell *GetViewCell(const Vector3 &point) const;
|
---|
[492] | 547 |
|
---|
[503] | 548 | void CreateMesh(ViewCell *vc);
|
---|
| 549 |
|
---|
[591] | 550 | void ExportViewCellGeometry(Exporter *exporter,
|
---|
| 551 | ViewCell *vc,
|
---|
[660] | 552 | const Plane3 *clipPlane = NULL) const;
|
---|
[580] | 553 |
|
---|
[587] | 554 | void CollectMergeCandidates(const VssRayContainer &rays,
|
---|
| 555 | vector<MergeCandidate> &candidates);
|
---|
[547] | 556 |
|
---|
[587] | 557 | void Finalize(ViewCell *viewCell, const bool createMesh);
|
---|
| 558 |
|
---|
[590] | 559 | bool ExportViewCells(const string filename);
|
---|
| 560 |
|
---|
[650] | 561 | ViewCell *ConstructSpatialMergeTree(BspNode *root);
|
---|
[610] | 562 |
|
---|
| 563 |
|
---|
[440] | 564 | protected:
|
---|
| 565 |
|
---|
[610] | 566 |
|
---|
[590] | 567 | /** HACK
|
---|
| 568 | */
|
---|
| 569 | void AddCurrentViewCellsToHierarchy();
|
---|
| 570 |
|
---|
[480] | 571 | void CollectViewCells();
|
---|
| 572 |
|
---|
[482] | 573 | void ExportColor(Exporter *exporter, ViewCell *vc) const;
|
---|
[547] | 574 |
|
---|
[482] | 575 |
|
---|
[547] | 576 |
|
---|
[440] | 577 | /// the BSP tree.
|
---|
| 578 | BspTree *mBspTree;
|
---|
[475] | 579 |
|
---|
| 580 | vector<BspRay *> mBspRays;
|
---|
[440] | 581 |
|
---|
| 582 | private:
|
---|
| 583 |
|
---|
| 584 | /** Exports visualization of the BSP splits.
|
---|
| 585 | */
|
---|
[477] | 586 | void ExportSplits(const ObjectContainer &objects);
|
---|
[440] | 587 |
|
---|
| 588 | /** Exports visualization of the BSP PVS.
|
---|
| 589 | */
|
---|
[477] | 590 | void ExportBspPvs(const ObjectContainer &objects);
|
---|
[440] | 591 |
|
---|
| 592 | };
|
---|
| 593 |
|
---|
| 594 | /**
|
---|
| 595 | Manages different higher order operations on the KD type view cells.
|
---|
| 596 | */
|
---|
| 597 | class KdViewCellsManager: public ViewCellsManager
|
---|
| 598 | {
|
---|
| 599 |
|
---|
| 600 | public:
|
---|
| 601 |
|
---|
| 602 | KdViewCellsManager(KdTree *tree);
|
---|
| 603 |
|
---|
[574] | 604 | int ConstructSubdivision(const ObjectContainer &objects,
|
---|
[487] | 605 | const VssRayContainer &rays);
|
---|
[440] | 606 |
|
---|
[478] | 607 | int CastLineSegment(const Vector3 &origin,
|
---|
| 608 | const Vector3 &termination,
|
---|
| 609 | ViewCellContainer &viewcells);
|
---|
[440] | 610 |
|
---|
| 611 | int PostProcess(const ObjectContainer &objects,
|
---|
[466] | 612 | const VssRayContainer &rays);
|
---|
[440] | 613 |
|
---|
| 614 | void Visualize(const ObjectContainer &objects,
|
---|
[466] | 615 | const VssRayContainer &sampleRays);
|
---|
[440] | 616 |
|
---|
| 617 | int GetType() const;
|
---|
| 618 |
|
---|
| 619 | bool ViewCellsConstructed() const;
|
---|
| 620 |
|
---|
[580] | 621 | ViewCell *GenerateViewCell(Mesh *mesh) const;
|
---|
[440] | 622 |
|
---|
[452] | 623 | /** Prints out statistics of this approach.
|
---|
| 624 | */
|
---|
[503] | 625 | // virtual void PrintStatistics(ostream &s) const;
|
---|
[569] | 626 | ViewCell *GetViewCell(const Vector3 &point) const { return NULL; }
|
---|
[452] | 627 |
|
---|
[503] | 628 | float GetProbability(ViewCell *viewCell);
|
---|
[609] | 629 |
|
---|
[468] | 630 |
|
---|
[503] | 631 | void CreateMesh(ViewCell *vc);
|
---|
| 632 |
|
---|
[591] | 633 | void ExportViewCellGeometry(Exporter *exporter,
|
---|
| 634 | ViewCell *vc,
|
---|
[660] | 635 | const Plane3 *clipPlane = NULL) const;
|
---|
[547] | 636 |
|
---|
[591] | 637 | void CollectMergeCandidates(const VssRayContainer &rays,
|
---|
| 638 | vector<MergeCandidate> &candidates);
|
---|
[580] | 639 |
|
---|
[440] | 640 | protected:
|
---|
| 641 |
|
---|
[580] | 642 | /** Collects view cells from a hierarchy.
|
---|
| 643 | */
|
---|
[480] | 644 | void CollectViewCells();
|
---|
[580] | 645 |
|
---|
[480] | 646 | KdNode *GetNodeForPvs(KdLeaf *leaf);
|
---|
[440] | 647 |
|
---|
[482] | 648 | void ExportColor(Exporter *exporter, ViewCell *vc) const;
|
---|
[440] | 649 |
|
---|
[547] | 650 |
|
---|
[480] | 651 | /// the BSP tree.
|
---|
| 652 | KdTree *mKdTree;
|
---|
[440] | 653 |
|
---|
[480] | 654 | /// depth of the KD tree nodes with represent the view cells
|
---|
| 655 | int mKdPvsDepth;
|
---|
[440] | 656 | };
|
---|
| 657 |
|
---|
| 658 | /**
|
---|
| 659 | Manages different higher order operations on the view cells
|
---|
| 660 | for vsp kd tree view cells.
|
---|
| 661 | */
|
---|
| 662 | class VspKdViewCellsManager: public ViewCellsManager
|
---|
| 663 | {
|
---|
| 664 |
|
---|
| 665 | public:
|
---|
| 666 |
|
---|
[574] | 667 | VspKdViewCellsManager(VspKdTree *vspKdTree);
|
---|
[440] | 668 |
|
---|
[574] | 669 | int ConstructSubdivision(const ObjectContainer &objects,
|
---|
[487] | 670 | const VssRayContainer &rays);
|
---|
[440] | 671 |
|
---|
| 672 |
|
---|
| 673 | int PostProcess(const ObjectContainer &objects,
|
---|
[466] | 674 | const VssRayContainer &rays);
|
---|
[440] | 675 |
|
---|
| 676 | void Visualize(const ObjectContainer &objects,
|
---|
[466] | 677 | const VssRayContainer &sampleRays);
|
---|
[440] | 678 |
|
---|
| 679 | int GetType() const;
|
---|
| 680 |
|
---|
| 681 | bool ViewCellsConstructed() const;
|
---|
| 682 |
|
---|
[475] | 683 | //virtual void PrintStatistics(ostream &s) const;
|
---|
[440] | 684 |
|
---|
[462] | 685 | ViewCell *GenerateViewCell(Mesh *mesh) const;
|
---|
| 686 |
|
---|
[466] | 687 |
|
---|
| 688 | int CastLineSegment(const Vector3 &origin,
|
---|
| 689 | const Vector3 &termination,
|
---|
[468] | 690 | ViewCellContainer &viewcells);
|
---|
[466] | 691 |
|
---|
[569] | 692 | ViewCell *GetViewCell(const Vector3 &point) const { return NULL; }
|
---|
[492] | 693 |
|
---|
[471] | 694 | float GetProbability(ViewCell *viewCell);
|
---|
[468] | 695 |
|
---|
[609] | 696 |
|
---|
[503] | 697 | void CreateMesh(ViewCell *vc);
|
---|
| 698 |
|
---|
[591] | 699 | void ExportViewCellGeometry(Exporter *exporter,
|
---|
| 700 | ViewCell *vc,
|
---|
[660] | 701 | const Plane3 *clipPlane = NULL) const;
|
---|
[547] | 702 |
|
---|
[580] | 703 | void CollectMergeCandidates(const VssRayContainer &rays, vector<MergeCandidate> &candidates);
|
---|
| 704 |
|
---|
[440] | 705 | protected:
|
---|
| 706 |
|
---|
[482] | 707 | void ExportLeaves(const ObjectContainer &objects,
|
---|
| 708 | const VssRayContainer &sampleRays);
|
---|
| 709 |
|
---|
[480] | 710 | void CollectViewCells();
|
---|
| 711 |
|
---|
[482] | 712 | void ExportColor(Exporter *exporter, ViewCell *vc) const;
|
---|
| 713 |
|
---|
| 714 |
|
---|
[547] | 715 |
|
---|
[440] | 716 | /// the BSP tree.
|
---|
| 717 | VspKdTree *mVspKdTree;
|
---|
| 718 | };
|
---|
| 719 |
|
---|
| 720 |
|
---|
[442] | 721 |
|
---|
| 722 | /**
|
---|
| 723 | Manages different higher order operations on the view cells.
|
---|
| 724 | */
|
---|
| 725 | class VspBspViewCellsManager: public ViewCellsManager
|
---|
| 726 | {
|
---|
| 727 |
|
---|
| 728 | public:
|
---|
| 729 |
|
---|
[574] | 730 | VspBspViewCellsManager(VspBspTree *tree);
|
---|
[475] | 731 | ~VspBspViewCellsManager();
|
---|
[442] | 732 |
|
---|
[574] | 733 | int ConstructSubdivision(const ObjectContainer &objects,
|
---|
[487] | 734 | const VssRayContainer &rays);
|
---|
[442] | 735 |
|
---|
| 736 | int PostProcess(const ObjectContainer &objects,
|
---|
[466] | 737 | const VssRayContainer &rays);
|
---|
[442] | 738 |
|
---|
| 739 | void Visualize(const ObjectContainer &objects,
|
---|
[466] | 740 | const VssRayContainer &sampleRays);
|
---|
[442] | 741 |
|
---|
| 742 | int GetType() const;
|
---|
| 743 |
|
---|
| 744 | ViewCell *GenerateViewCell(Mesh *mesh = NULL) const;
|
---|
| 745 |
|
---|
| 746 | bool ViewCellsConstructed() const;
|
---|
| 747 |
|
---|
[468] | 748 |
|
---|
| 749 | int CastLineSegment(const Vector3 &origin,
|
---|
| 750 | const Vector3 &termination,
|
---|
| 751 | ViewCellContainer &viewcells);
|
---|
[452] | 752 |
|
---|
[471] | 753 | float GetProbability(ViewCell *viewCell);
|
---|
[479] | 754 |
|
---|
[569] | 755 | ViewCell *GetViewCell(const Vector3 &point) const;
|
---|
[477] | 756 |
|
---|
[487] | 757 | bool GetViewPoint(Vector3 &viewPoint) const;
|
---|
| 758 |
|
---|
[490] | 759 | bool ViewPointValid(const Vector3 &viewPoint) const;
|
---|
[503] | 760 |
|
---|
| 761 | void CreateMesh(ViewCell *vc);
|
---|
| 762 |
|
---|
[577] | 763 | //bool LoadViewCellsGeometry(const string filename, ObjectContainer *objects);
|
---|
[508] | 764 | bool ExportViewCells(const string filename);
|
---|
| 765 |
|
---|
[532] | 766 | int CastBeam(Beam &beam);
|
---|
| 767 |
|
---|
[591] | 768 | void ExportViewCellGeometry(Exporter *exporter,
|
---|
| 769 | ViewCell *vc,
|
---|
[660] | 770 | const Plane3 *clipPlane = NULL) const;
|
---|
[547] | 771 |
|
---|
[551] | 772 | //float GetVolume(ViewCell *viewCell) const;
|
---|
| 773 |
|
---|
[555] | 774 | void Finalize(ViewCell *viewCell, const bool createMesh);
|
---|
[551] | 775 |
|
---|
[580] | 776 | void CollectMergeCandidates(const VssRayContainer &rays, vector<MergeCandidate> &candidates);
|
---|
| 777 |
|
---|
[609] | 778 | bool EqualToSpatialNode(ViewCell *viewCell) const;
|
---|
[607] | 779 |
|
---|
[442] | 780 | protected:
|
---|
[475] | 781 |
|
---|
[651] | 782 |
|
---|
[610] | 783 | /** Returns node of the spatial hierarchy corresponding to the view cell
|
---|
| 784 | if such a node exists.
|
---|
| 785 | */
|
---|
[609] | 786 | BspNode *GetSpatialNode(ViewCell *viewCell) const;
|
---|
[610] | 787 |
|
---|
[590] | 788 | /** HACK
|
---|
| 789 | */
|
---|
| 790 | void AddCurrentViewCellsToHierarchy();
|
---|
| 791 |
|
---|
[503] | 792 | /** Merges the view cells.
|
---|
[442] | 793 | */
|
---|
[508] | 794 | void MergeViewCells(const VssRayContainer &rays,
|
---|
| 795 | const ObjectContainer &objects);
|
---|
[503] | 796 |
|
---|
[564] | 797 | void RefineViewCells(const VssRayContainer &rays, const ObjectContainer &objects);
|
---|
[442] | 798 |
|
---|
[480] | 799 | void CollectViewCells();
|
---|
| 800 |
|
---|
[482] | 801 | /** Returns maximal depth difference of view cell
|
---|
| 802 | leaves in tree.
|
---|
| 803 | */
|
---|
| 804 | int GetMaxTreeDiff(ViewCell *vc) const;
|
---|
[485] | 805 |
|
---|
[482] | 806 |
|
---|
[485] | 807 | void ExportColor(Exporter *exporter, ViewCell *vc) const;
|
---|
| 808 |
|
---|
[577] | 809 | void PrepareLoadedViewCells();
|
---|
| 810 |
|
---|
[650] | 811 | ViewCell *ConstructSpatialMergeTree(BspNode *root);
|
---|
[649] | 812 |
|
---|
[442] | 813 | /// the view space partition BSP tree.
|
---|
| 814 | VspBspTree *mVspBspTree;
|
---|
| 815 |
|
---|
[591] | 816 |
|
---|
[442] | 817 | private:
|
---|
| 818 |
|
---|
| 819 | /** Exports visualization of the BSP splits.
|
---|
| 820 | */
|
---|
[485] | 821 | void ExportSplits(const ObjectContainer &objects,
|
---|
| 822 | const VssRayContainer &rays);
|
---|
[442] | 823 |
|
---|
| 824 | /** Exports visualization of the BSP PVS.
|
---|
| 825 | */
|
---|
[485] | 826 | void ExportBspPvs(const ObjectContainer &objects,
|
---|
| 827 | const VssRayContainer &rays);
|
---|
[442] | 828 |
|
---|
| 829 | };
|
---|
| 830 |
|
---|
[575] | 831 |
|
---|
| 832 | class ViewCellsManagerFactory
|
---|
| 833 | {
|
---|
| 834 |
|
---|
| 835 | public:
|
---|
| 836 |
|
---|
| 837 | ViewCellsManager *Create(const string mName);
|
---|
| 838 |
|
---|
| 839 | };
|
---|
| 840 |
|
---|
[440] | 841 | #endif
|
---|