cesium-native  0.41.0
Tile.h
1 #pragma once
2 
3 #include "BoundingVolume.h"
4 #include "Library.h"
5 #include "RasterMappedTo3DTile.h"
6 #include "TileContent.h"
7 #include "TileID.h"
8 #include "TileRefine.h"
9 #include "TileSelectionState.h"
10 
11 #include <CesiumUtility/DoublyLinkedList.h>
12 
13 #include <glm/common.hpp>
14 #include <gsl/span>
15 
16 #include <atomic>
17 #include <limits>
18 #include <memory>
19 #include <optional>
20 #include <string>
21 #include <vector>
22 
23 namespace Cesium3DTilesSelection {
24 class TilesetContentLoader;
25 
29 enum class TileLoadState {
34  Unloading = -2,
35 
40  FailedTemporarily = -1,
41 
46  Unloaded = 0,
47 
55  ContentLoading = 1,
56 
60  ContentLoaded = 2,
61 
65  Done = 3,
66 
71  Failed = 4,
72 };
73 
97 class CESIUM3DTILESSELECTION_API Tile final {
98 public:
106  explicit Tile(TilesetContentLoader* pLoader) noexcept;
107 
116  TilesetContentLoader* pLoader,
117  std::unique_ptr<TileExternalContent>&& externalContent) noexcept;
118 
126  Tile(TilesetContentLoader* pLoader, TileEmptyContent emptyContent) noexcept;
127 
132  ~Tile() noexcept = default;
133 
139  Tile(const Tile& rhs) = delete;
140 
146  Tile(Tile&& rhs) noexcept;
147 
153  Tile& operator=(const Tile& rhs) = delete;
154 
160  Tile& operator=(Tile&& rhs) noexcept;
161 
169  Tile* getParent() noexcept { return this->_pParent; }
170 
172  const Tile* getParent() const noexcept { return this->_pParent; }
173 
181  gsl::span<Tile> getChildren() noexcept {
182  return gsl::span<Tile>(this->_children);
183  }
184 
186  gsl::span<const Tile> getChildren() const noexcept {
187  return gsl::span<const Tile>(this->_children);
188  }
189 
198  void createChildTiles(std::vector<Tile>&& children);
199 
210  const BoundingVolume& getBoundingVolume() const noexcept {
211  return this->_boundingVolume;
212  }
213 
221  void setBoundingVolume(const BoundingVolume& value) noexcept {
222  this->_boundingVolume = value;
223  }
224 
236  const std::optional<BoundingVolume>& getViewerRequestVolume() const noexcept {
237  return this->_viewerRequestVolume;
238  }
239 
247  void
248  setViewerRequestVolume(const std::optional<BoundingVolume>& value) noexcept {
249  this->_viewerRequestVolume = value;
250  }
251 
261  double getGeometricError() const noexcept { return this->_geometricError; }
262 
270  void setGeometricError(double value) noexcept {
271  this->_geometricError = value;
272  }
273 
288  double getNonZeroGeometricError() const noexcept;
289 
300  bool getUnconditionallyRefine() const noexcept {
301  return glm::isinf(this->_geometricError);
302  }
303 
309  void setUnconditionallyRefine() noexcept {
310  this->_geometricError = std::numeric_limits<double>::infinity();
311  }
312 
324  TileRefine getRefine() const noexcept { return this->_refine; }
325 
333  void setRefine(TileRefine value) noexcept { this->_refine = value; }
334 
343  const glm::dmat4x4& getTransform() const noexcept { return this->_transform; }
344 
352  void setTransform(const glm::dmat4x4& value) noexcept {
353  this->_transform = value;
354  }
355 
363  const TileID& getTileID() const noexcept { return this->_id; }
364 
372  void setTileID(const TileID& id) noexcept { this->_id = id; }
373 
385  const std::optional<BoundingVolume>&
386  getContentBoundingVolume() const noexcept {
387  return this->_contentBoundingVolume;
388  }
389 
399  const std::optional<BoundingVolume>& value) noexcept {
400  this->_contentBoundingVolume = value;
401  }
402 
411  return this->_lastSelectionState;
412  }
413 
415  const TileSelectionState& getLastSelectionState() const noexcept {
416  return this->_lastSelectionState;
417  }
418 
426  void setLastSelectionState(const TileSelectionState& newState) noexcept {
427  this->_lastSelectionState = newState;
428  }
429 
434  int64_t computeByteSize() const noexcept;
435 
439  std::vector<RasterMappedTo3DTile>& getMappedRasterTiles() noexcept {
440  return this->_rasterTiles;
441  }
442 
444  const std::vector<RasterMappedTo3DTile>&
445  getMappedRasterTiles() const noexcept {
446  return this->_rasterTiles;
447  }
448 
452  const TileContent& getContent() const noexcept { return _content; }
453 
455  TileContent& getContent() noexcept { return _content; }
456 
460  bool isRenderable() const noexcept;
461 
465  bool isRenderContent() const noexcept;
466 
470  bool isExternalContent() const noexcept;
471 
475  bool isEmptyContent() const noexcept;
476 
480  TilesetContentLoader* getLoader() const noexcept;
481 
485  TileLoadState getState() const noexcept;
486 
487 private:
488  struct TileConstructorImpl {};
489  template <
490  typename... TileContentArgs,
491  typename TileContentEnable = std::enable_if_t<
492  std::is_constructible_v<TileContent, TileContentArgs&&...>,
493  int>>
494  Tile(
495  TileConstructorImpl tag,
496  TileLoadState loadState,
497  TilesetContentLoader* pLoader,
498  TileContentArgs&&... args);
499 
500  void setParent(Tile* pParent) noexcept;
501 
502  void setState(TileLoadState state) noexcept;
503 
519  bool getMightHaveLatentChildren() const noexcept;
520 
521  void setMightHaveLatentChildren(bool mightHaveLatentChildren) noexcept;
522 
523  // Position in bounding-volume hierarchy.
524  Tile* _pParent;
525  std::vector<Tile> _children;
526 
527  // Properties from tileset.json.
528  // These are immutable after the tile leaves TileState::Unloaded.
529  TileID _id;
530  BoundingVolume _boundingVolume;
531  std::optional<BoundingVolume> _viewerRequestVolume;
532  std::optional<BoundingVolume> _contentBoundingVolume;
533  double _geometricError;
534  TileRefine _refine;
535  glm::dmat4x4 _transform;
536 
537  // Selection state
538  TileSelectionState _lastSelectionState;
539 
540  // tile content
541  CesiumUtility::DoublyLinkedListPointers<Tile> _loadedTilesLinks;
542  TileContent _content;
543  TilesetContentLoader* _pLoader;
544  TileLoadState _loadState;
545  bool _mightHaveLatentChildren;
546 
547  // mapped raster overlay
548  std::vector<RasterMappedTo3DTile> _rasterTiles;
549 
550  friend class TilesetContentManager;
551  friend class MockTilesetContentManagerTestFixture;
552 
553 public:
557  typedef CesiumUtility::DoublyLinkedList<Tile, &Tile::_loadedTilesLinks>
559 };
560 
561 } // namespace Cesium3DTilesSelection
The result of applying a RasterOverlayTile to geometry.
A tile content container that can store and query the content type that is currently being owned by t...
Definition: TileContent.h:207
A description of the state of a Tile during the rendering process.
A tile in a Tileset.
Definition: Tile.h:97
gsl::span< Tile > getChildren() noexcept
Returns a view on the children of this tile.
Definition: Tile.h:181
TileContent & getContent() noexcept
Definition: Tile.h:455
const Tile * getParent() const noexcept
Returns the parent of this tile in the tile hierarchy.
Definition: Tile.h:172
const std::vector< RasterMappedTo3DTile > & getMappedRasterTiles() const noexcept
Returns the raster overlay tiles that have been mapped to this tile.
Definition: Tile.h:445
double getNonZeroGeometricError() const noexcept
Gets the tile's geometric error as if by calling getGeometricError, except that if the error is small...
Tile(TilesetContentLoader *pLoader) noexcept
Construct a tile with unknown content and a loader that is used to load the content of this tile....
const std::optional< BoundingVolume > & getContentBoundingVolume() const noexcept
Returns the BoundingVolume of the renderable content of this tile.
Definition: Tile.h:386
const BoundingVolume & getBoundingVolume() const noexcept
Returns the BoundingVolume of this tile.
Definition: Tile.h:210
void setGeometricError(double value) noexcept
Set the geometric error of the contents of this tile.
Definition: Tile.h:270
void setLastSelectionState(const TileSelectionState &newState) noexcept
Set the TileSelectionState of this tile.
Definition: Tile.h:426
void setTileID(const TileID &id) noexcept
Set the TileID of this tile.
Definition: Tile.h:372
int64_t computeByteSize() const noexcept
Determines the number of bytes in this tile's geometry and texture data.
void createChildTiles(std::vector< Tile > &&children)
Assigns the given child tiles to this tile.
bool isRenderable() const noexcept
Determines if this tile is currently renderable.
const std::optional< BoundingVolume > & getViewerRequestVolume() const noexcept
Returns the viewer request volume of this tile.
Definition: Tile.h:236
const glm::dmat4x4 & getTransform() const noexcept
Gets the transformation matrix for this tile.
Definition: Tile.h:343
void setRefine(TileRefine value) noexcept
Set the refinement strategy of this tile.
Definition: Tile.h:333
const TileID & getTileID() const noexcept
Returns the TileID of this tile.
Definition: Tile.h:363
void setTransform(const glm::dmat4x4 &value) noexcept
Set the transformation matrix for this tile.
Definition: Tile.h:352
void setViewerRequestVolume(const std::optional< BoundingVolume > &value) noexcept
Set the viewer request volume of this tile.
Definition: Tile.h:248
TileRefine getRefine() const noexcept
The refinement strategy of this tile.
Definition: Tile.h:324
gsl::span< const Tile > getChildren() const noexcept
Returns a view on the children of this tile.
Definition: Tile.h:186
Tile(TilesetContentLoader *pLoader, TileEmptyContent emptyContent) noexcept
Construct a tile with an empty content and a loader that is associated with this tile....
TileSelectionState & getLastSelectionState() noexcept
Returns the TileSelectionState of this tile.
Definition: Tile.h:410
void setContentBoundingVolume(const std::optional< BoundingVolume > &value) noexcept
Set the BoundingVolume of the renderable content of this tile.
Definition: Tile.h:398
Tile(TilesetContentLoader *pLoader, std::unique_ptr< TileExternalContent > &&externalContent) noexcept
Construct a tile with an external content and a loader that is associated with this tile....
void setBoundingVolume(const BoundingVolume &value) noexcept
Set the BoundingVolume of this tile.
Definition: Tile.h:221
void setUnconditionallyRefine() noexcept
Marks that this tile should be unconditionally refined.
Definition: Tile.h:309
~Tile() noexcept=default
Default destructor, which clears all resources associated with this tile.
const TileSelectionState & getLastSelectionState() const noexcept
Returns the TileSelectionState of this tile.
Definition: Tile.h:415
double getGeometricError() const noexcept
Returns the geometric error of this tile.
Definition: Tile.h:261
const TileContent & getContent() const noexcept
get the content of the tile.
Definition: Tile.h:452
The loader interface to load the tile content.
Classes that implement the 3D Tiles standard.
@ ContentLoaded
The tile content has finished loading.
@ Unloading
This tile is in the process of being unloaded, but could not be fully unloaded because an asynchronou...
@ ContentLoading
The tile content is currently being loaded.
@ FailedTemporarily
Something went wrong while loading this tile, but it may be a temporary problem.
@ Unloaded
The tile is not yet loaded at all, beyond the metadata in tileset.json.
@ Failed
Something went wrong while loading this tile and it will not be retried.
@ Done
The tile is completely done loading.
std::variant< CesiumGeometry::BoundingSphere, CesiumGeometry::OrientedBoundingBox, CesiumGeospatial::BoundingRegion, CesiumGeospatial::BoundingRegionWithLooseFittingHeights, CesiumGeospatial::S2CellBoundingVolume > BoundingVolume
A bounding volume.
TileRefine
Refinement strategies for a Cesium3DTilesSelection::Tile.
Definition: TileRefine.h:8
std::variant< std::string, CesiumGeometry::QuadtreeTileID, CesiumGeometry::OctreeTileID, CesiumGeometry::UpsampledQuadtreeNode > TileID
An identifier for a Tile inside the tile hierarchy.
Definition: TileID.h:40
Utility classes for Cesium.
A content tag that indicates a tile has no content.
Definition: TileContent.h:45