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