cesium-native 0.67.0
Loading...
Searching...
No Matches
Tile.h
1#pragma once
2
3#include <Cesium3DTiles/BoundingVolume.h>
4#include <Cesium3DTiles/TileRefine.h>
5#include <Cesium3DTilesSelection/Library.h>
6#include <Cesium3DTilesSelection/RasterMappedTo3DTile.h>
7#include <Cesium3DTilesSelection/TileContent.h>
8#include <Cesium3DTilesSelection/TileID.h>
9#include <Cesium3DTilesSelection/TileSelectionState.h>
10#include <CesiumUtility/DoublyLinkedList.h>
11#include <CesiumUtility/IntrusivePointer.h>
12
13#include <glm/common.hpp>
14
15#include <atomic>
16#include <limits>
17#include <memory>
18#include <optional>
19#include <span>
20#include <string>
21#include <vector>
22
23#ifdef CESIUM_DEBUG_TILE_UNLOADING
24#include <unordered_map>
25#endif
26
27namespace Cesium3DTilesSelection {
29class GltfModifier;
30
31#ifdef CESIUM_DEBUG_TILE_UNLOADING
32class TileReferenceCountTracker {
33private:
34 struct Entry {
35 std::string reason;
36 bool increment;
37 int32_t newCount;
38 };
39
40public:
41 static void addEntry(
42 const uint64_t id,
43 bool increment,
44 const char* reason,
45 int32_t newCount);
46
47private:
48 static std::unordered_map<std::string, std::vector<Entry>> _entries;
49};
50#endif
51
55enum class TileLoadState {
61
67
73
82
87
91 Done = 3,
92
97 Failed = 4,
98};
99
123class CESIUM3DTILESSELECTION_API Tile final {
124public:
133
142
152 explicit Tile(
153 TilesetContentLoader* pLoader,
154 const TileID& tileID = {}) noexcept;
155
175 TilesetContentLoader* pLoader,
176 const TileID& tileID,
177 std::unique_ptr<TileExternalContent>&& externalContent) noexcept;
178
198 TilesetContentLoader* pLoader,
199 const TileID& tileID,
200 TileEmptyContent emptyContent) noexcept;
201
206 ~Tile() noexcept;
207
213 Tile(const Tile& rhs) = delete;
214
220 Tile(Tile&& rhs) noexcept;
221
227 Tile& operator=(const Tile& rhs) = delete;
228
234 Tile& operator=(Tile&& rhs) noexcept = delete;
235
243 Tile* getParent() noexcept { return this->_pParent; }
244
246 const Tile* getParent() const noexcept { return this->_pParent; }
247
255 std::span<Tile> getChildren() noexcept {
256 return std::span<Tile>(this->_children);
257 }
258
260 std::span<const Tile> getChildren() const noexcept {
261 return std::span<const Tile>(this->_children);
262 }
263
269 void clearChildren() noexcept;
270
279 void createChildTiles(std::vector<Tile>&& children);
280
291 const Cesium3DTiles::BoundingVolume& getBoundingVolume() const noexcept {
292 return this->_boundingVolume;
293 }
294
303 this->_boundingVolume = value;
304 }
305
317 const std::optional<Cesium3DTiles::BoundingVolume>&
318 getViewerRequestVolume() const noexcept {
319 return this->_viewerRequestVolume;
320 }
321
330 const std::optional<Cesium3DTiles::BoundingVolume>& value) noexcept {
331 this->_viewerRequestVolume = value;
332 }
333
343 double getGeometricError() const noexcept { return this->_geometricError; }
344
352 void setGeometricError(double value) noexcept {
353 this->_geometricError = value;
354 }
355
371 double getNonZeroGeometricError() const noexcept;
372
383 bool getUnconditionallyRefine() const noexcept {
384 return glm::isinf(this->_geometricError);
385 }
386
392 void setUnconditionallyRefine() noexcept {
393 this->_geometricError = std::numeric_limits<double>::infinity();
394 }
395
406 Cesium3DTiles::TileRefine getRefine() const noexcept { return this->_refine; }
407
416 this->_refine = value;
417 }
418
427 const glm::dmat4x4& getTransform() const noexcept { return this->_transform; }
428
436 void setTransform(const glm::dmat4x4& value) noexcept {
437 this->_transform = value;
438 }
439
447 const TileID& getTileID() const noexcept { return this->_id; }
448
456 void setTileID(const TileID& id) noexcept { this->_id = id; }
457
469 const std::optional<Cesium3DTiles::BoundingVolume>&
470 getContentBoundingVolume() const noexcept {
471 return this->_contentBoundingVolume;
472 }
473
483 const std::optional<Cesium3DTiles::BoundingVolume>& value) noexcept {
484 this->_contentBoundingVolume = value;
485 }
486
491 int64_t computeByteSize() const noexcept;
492
497 return this->_rasterTiles;
498 }
499
501 const std::vector<RasterMappedTo3DTile>&
502 getMappedRasterTiles() const noexcept {
503 return this->_rasterTiles;
504 }
505
509 const TileContent& getContent() const noexcept { return _content; }
510
512 TileContent& getContent() noexcept { return _content; }
513
517 bool isRenderable() const noexcept;
518
522 bool isRenderContent() const noexcept;
523
527 bool isExternalContent() const noexcept;
528
532 bool isEmptyContent() const noexcept;
533
538
542 TileLoadState getState() const noexcept;
543
553 bool needsWorkerThreadLoading(const GltfModifier* pModifier) const noexcept;
554
564 bool needsMainThreadLoading(const GltfModifier* pModifier) const noexcept;
565
600 void addReference(const char* reason = nullptr) const noexcept;
601
624 void releaseReference(const char* reason = nullptr) const noexcept;
625
632 int32_t getReferenceCount() const noexcept;
633
652 bool hasReferencingContent() const noexcept;
653
658 void setGroup(int64_t group) { this->_group = group; }
659
664 std::optional<int64_t> getGroup() const noexcept { return this->_group; }
665
666private:
667 struct TileConstructorImpl {};
668 template <
669 typename... TileContentArgs,
670 typename TileContentEnable = std::enable_if_t<
671 std::is_constructible_v<TileContent, TileContentArgs&&...>,
672 int>>
673 Tile(
674 TileConstructorImpl tag,
675 TileLoadState loadState,
676 TilesetContentLoader* pLoader,
677 const TileID& tileID,
678 TileContentArgs&&... args);
679
680 void setParent(Tile* pParent) noexcept;
681
682 void setState(TileLoadState state) noexcept;
683
699 bool getMightHaveLatentChildren() const noexcept;
700
701 void setMightHaveLatentChildren(bool mightHaveLatentChildren) noexcept;
702
703 // Position in bounding-volume hierarchy.
704 Tile* _pParent;
705 std::vector<Tile> _children;
706
707 // Properties from tileset.json.
708 // These are immutable after the tile leaves TileState::Unloaded.
709 TileID _id;
710 Cesium3DTiles::BoundingVolume _boundingVolume;
711 std::optional<Cesium3DTiles::BoundingVolume> _viewerRequestVolume;
712 std::optional<Cesium3DTiles::BoundingVolume> _contentBoundingVolume;
713 double _geometricError;
714 Cesium3DTiles::TileRefine _refine;
715 glm::dmat4x4 _transform;
716
717 // tile content
718 CesiumUtility::DoublyLinkedListPointers<Tile> _unusedTilesLinks;
719 TileContent _content;
720 TilesetContentLoader* _pLoader;
721 TileLoadState _loadState;
722 bool _mightHaveLatentChildren;
723
724 // mapped raster overlay
725 std::vector<RasterMappedTo3DTile> _rasterTiles;
726
727 mutable int32_t _referenceCount;
728
729 friend class TilesetContentManager;
730 friend class MockTilesetContentManagerTestFixture;
731
732 std::optional<int64_t> _group;
733
734public:
738 typedef CesiumUtility::DoublyLinkedList<Tile, &Tile::_unusedTilesLinks>
740};
741
742} // namespace Cesium3DTilesSelection
An abstract class that allows modifying a tile's glTF model after it has been loaded.
The result of applying a CesiumRasterOverlays::RasterOverlayTile to geometry.
A tile content container that can store and query the content type that is currently being owned by t...
Tile(TilesetContentLoader *pLoader, const TileID &tileID={}) noexcept
Construct a tile with unknown content and a loader that is used to load the content of this tile....
void setViewerRequestVolume(const std::optional< Cesium3DTiles::BoundingVolume > &value) noexcept
Set the viewer request volume of this tile.
Definition Tile.h:329
Cesium3DTiles::TileRefine getRefine() const noexcept
The refinement strategy of this tile.
Definition Tile.h:406
const TileID & getTileID() const noexcept
Returns the TileID of this tile.
Definition Tile.h:447
double getNonZeroGeometricError() const noexcept
Gets the tile's geometric error as if by calling getGeometricError, except that if the error is small...
CesiumUtility::DoublyLinkedList< Tile, &Tile::_unusedTilesLinks > UnusedLinkedList
A CesiumUtility::DoublyLinkedList for tile objects.
Definition Tile.h:739
void setRefine(Cesium3DTiles::TileRefine value) noexcept
Set the refinement strategy of this tile.
Definition Tile.h:415
const std::vector< RasterMappedTo3DTile > & getMappedRasterTiles() const noexcept
Returns the raster overlay tiles that have been mapped to this tile.
Definition Tile.h:502
void setGeometricError(double value) noexcept
Set the geometric error of the contents of this tile.
Definition Tile.h:352
bool isExternalContent() const noexcept
Determines if this tile has external tileset content.
void setContentBoundingVolume(const std::optional< Cesium3DTiles::BoundingVolume > &value) noexcept
Set the Cesium3DTiles::BoundingVolume of the renderable content of this tile.
Definition Tile.h:482
void setBoundingVolume(const Cesium3DTiles::BoundingVolume &value) noexcept
Set the Cesium3DTiles::BoundingVolume of this tile.
Definition Tile.h:302
TileLoadState getState() const noexcept
Returns the TileLoadState of this tile.
void setTileID(const TileID &id) noexcept
Set the TileID of this tile.
Definition Tile.h:456
bool hasReferencingContent() const noexcept
Determines if this tile's getContent counts as a reference to this tile.
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.
const std::optional< Cesium3DTiles::BoundingVolume > & getViewerRequestVolume() const noexcept
Returns the viewer request volume of this tile.
Definition Tile.h:318
bool isRenderContent() const noexcept
Determines if this tile has mesh content.
Tile(TilesetContentLoader *pLoader, const TileID &tileID, std::unique_ptr< TileExternalContent > &&externalContent) noexcept
Construct a tile with an external content and a loader that is associated with this tile....
Tile * getParent() noexcept
Returns the parent of this tile in the tile hierarchy.
Definition Tile.h:243
bool isRenderable() const noexcept
Determines if this tile is currently renderable.
~Tile() noexcept
Default destructor, which clears all resources associated with this tile.
Tile(TilesetContentLoader *pLoader, const TileID &tileID, TileEmptyContent emptyContent) noexcept
Construct a tile with an empty content and a loader that is associated with this tile....
void clearChildren() noexcept
Clears the children of this tile.
CesiumUtility::IntrusivePointer< Tile > Pointer
A reference counting pointer to a Tile.
Definition Tile.h:132
std::span< const Tile > getChildren() const noexcept
Returns a view on the children of this tile.
Definition Tile.h:260
CesiumUtility::IntrusivePointer< const Tile > ConstPointer
A reference counting pointer to a const Tile.
Definition Tile.h:141
const glm::dmat4x4 & getTransform() const noexcept
Gets the transformation matrix for this tile.
Definition Tile.h:427
std::span< Tile > getChildren() noexcept
Returns a view on the children of this tile.
Definition Tile.h:255
TilesetContentLoader * getLoader() const noexcept
get the loader that is used to load the tile content.
void addReference(const char *reason=nullptr) const noexcept
Adds a reference to this tile. A live reference will keep this tile from being destroyed,...
void setTransform(const glm::dmat4x4 &value) noexcept
Set the transformation matrix for this tile.
Definition Tile.h:436
bool needsWorkerThreadLoading(const GltfModifier *pModifier) const noexcept
Determines if this tile requires worker-thread loading.
const std::optional< Cesium3DTiles::BoundingVolume > & getContentBoundingVolume() const noexcept
Returns the Cesium3DTiles::BoundingVolume of the renderable content of this tile.
Definition Tile.h:470
std::vector< RasterMappedTo3DTile > & getMappedRasterTiles() noexcept
Returns the raster overlay tiles that have been mapped to this tile.
Definition Tile.h:496
int32_t getReferenceCount() const noexcept
Gets the current number of references to this tile.
bool needsMainThreadLoading(const GltfModifier *pModifier) const noexcept
Determines if this tile requires main-thread loading.
void setGroup(int64_t group)
Set the group ID for this tile.
Definition Tile.h:658
void releaseReference(const char *reason=nullptr) const noexcept
Removes a reference from this tile. A live reference will keep this tile from being destroyed,...
void setUnconditionallyRefine() noexcept
Marks that this tile should be unconditionally refined.
Definition Tile.h:392
std::optional< int64_t > getGroup() const noexcept
Get the group ID for this tile.
Definition Tile.h:664
bool getUnconditionallyRefine() const noexcept
Returns whether to unconditionally refine this tile.
Definition Tile.h:383
TileContent & getContent() noexcept
Get the content of the tile.
Definition Tile.h:512
bool isEmptyContent() const noexcept
Determines if this tile has empty content.
const TileContent & getContent() const noexcept
Get the content of the tile.
Definition Tile.h:509
double getGeometricError() const noexcept
Returns the geometric error of this tile.
Definition Tile.h:343
const Tile * getParent() const noexcept
Returns the parent of this tile in the tile hierarchy.
Definition Tile.h:246
const Cesium3DTiles::BoundingVolume & getBoundingVolume() const noexcept
Returns the Cesium3DTiles::BoundingVolume of this tile.
Definition Tile.h:291
The loader interface to load the tile content.
A smart pointer that calls addReference and releaseReference on the controlled object.
Classes that implement the 3D Tiles standard.
@ ContentLoaded
The tile content has finished loading.
Definition Tile.h:86
@ Unloading
This tile is in the process of being unloaded, but could not be fully unloaded because an asynchronou...
Definition Tile.h:60
@ ContentLoading
The tile content is currently being loaded.
Definition Tile.h:81
@ FailedTemporarily
Something went wrong while loading this tile, but it may be a temporary problem.
Definition Tile.h:66
@ Unloaded
The tile is not yet loaded at all, beyond the metadata in tileset.json.
Definition Tile.h:72
@ Failed
Something went wrong while loading this tile and it will not be retried.
Definition Tile.h:97
@ Done
The tile is completely done loading.
Definition Tile.h:91
std::variant< std::string, CesiumGeometry::QuadtreeTileID, CesiumGeometry::OctreeTileID, CesiumGeometry::UpsampledQuadtreeNode > TileID
An identifier for a Tile inside the tile hierarchy.
Definition TileID.h:39
Classes that represent or enable fundamental elements of 3D Tiles.
std::variant< CesiumGeometry::BoundingSphere, CesiumGeometry::OrientedBoundingBox, CesiumGeospatial::BoundingRegion, CesiumGeospatial::BoundingRegionWithLooseFittingHeights, CesiumGeospatial::S2CellBoundingVolume, CesiumGeometry::BoundingCylinderRegion > BoundingVolume
A bounding volume.
TileRefine
Refinement strategies for a tile in 3D Tiles.
Definition TileRefine.h:11
Utility classes for Cesium.
STL namespace.
A content tag that indicates a tile has no content.
Definition TileContent.h:52