cesium-native 0.53.0
Loading...
Searching...
No Matches
Tile.h
1#pragma once
2
3#include <Cesium3DTilesSelection/BoundingVolume.h>
4#include <Cesium3DTilesSelection/Library.h>
5#include <Cesium3DTilesSelection/RasterMappedTo3DTile.h>
6#include <Cesium3DTilesSelection/TileContent.h>
7#include <Cesium3DTilesSelection/TileID.h>
8#include <Cesium3DTilesSelection/TileRefine.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
174 TilesetContentLoader* pLoader,
175 const TileID& tileID,
176 std::unique_ptr<TileExternalContent>&& externalContent) noexcept;
177
196 TilesetContentLoader* pLoader,
197 const TileID& tileID,
198 TileEmptyContent emptyContent) noexcept;
199
204 ~Tile() noexcept;
205
211 Tile(const Tile& rhs) = delete;
212
218 Tile(Tile&& rhs) noexcept;
219
225 Tile& operator=(const Tile& rhs) = delete;
226
232 Tile& operator=(Tile&& rhs) noexcept = delete;
233
241 Tile* getParent() noexcept { return this->_pParent; }
242
244 const Tile* getParent() const noexcept { return this->_pParent; }
245
253 std::span<Tile> getChildren() noexcept {
254 return std::span<Tile>(this->_children);
255 }
256
258 std::span<const Tile> getChildren() const noexcept {
259 return std::span<const Tile>(this->_children);
260 }
261
267 void clearChildren() noexcept;
268
277 void createChildTiles(std::vector<Tile>&& children);
278
289 const BoundingVolume& getBoundingVolume() const noexcept {
290 return this->_boundingVolume;
291 }
292
300 void setBoundingVolume(const BoundingVolume& value) noexcept {
301 this->_boundingVolume = value;
302 }
303
315 const std::optional<BoundingVolume>& getViewerRequestVolume() const noexcept {
316 return this->_viewerRequestVolume;
317 }
318
326 void
327 setViewerRequestVolume(const std::optional<BoundingVolume>& value) noexcept {
328 this->_viewerRequestVolume = value;
329 }
330
340 double getGeometricError() const noexcept { return this->_geometricError; }
341
349 void setGeometricError(double value) noexcept {
350 this->_geometricError = value;
351 }
352
367 double getNonZeroGeometricError() const noexcept;
368
379 bool getUnconditionallyRefine() const noexcept {
380 return glm::isinf(this->_geometricError);
381 }
382
388 void setUnconditionallyRefine() noexcept {
389 this->_geometricError = std::numeric_limits<double>::infinity();
390 }
391
403 TileRefine getRefine() const noexcept { return this->_refine; }
404
412 void setRefine(TileRefine value) noexcept { this->_refine = value; }
413
422 const glm::dmat4x4& getTransform() const noexcept { return this->_transform; }
423
431 void setTransform(const glm::dmat4x4& value) noexcept {
432 this->_transform = value;
433 }
434
442 const TileID& getTileID() const noexcept { return this->_id; }
443
451 void setTileID(const TileID& id) noexcept { this->_id = id; }
452
464 const std::optional<BoundingVolume>&
465 getContentBoundingVolume() const noexcept {
466 return this->_contentBoundingVolume;
467 }
468
478 const std::optional<BoundingVolume>& value) noexcept {
479 this->_contentBoundingVolume = value;
480 }
481
486 int64_t computeByteSize() const noexcept;
487
492 return this->_rasterTiles;
493 }
494
496 const std::vector<RasterMappedTo3DTile>&
497 getMappedRasterTiles() const noexcept {
498 return this->_rasterTiles;
499 }
500
504 const TileContent& getContent() const noexcept { return _content; }
505
507 TileContent& getContent() noexcept { return _content; }
508
512 bool isRenderable() const noexcept;
513
517 bool isRenderContent() const noexcept;
518
522 bool isExternalContent() const noexcept;
523
527 bool isEmptyContent() const noexcept;
528
533
537 TileLoadState getState() const noexcept;
538
548 bool needsWorkerThreadLoading(const GltfModifier* pModifier) const noexcept;
549
559 bool needsMainThreadLoading(const GltfModifier* pModifier) const noexcept;
560
595 void addReference(const char* reason = nullptr) const noexcept;
596
619 void releaseReference(const char* reason = nullptr) const noexcept;
620
627 int32_t getReferenceCount() const noexcept;
628
647 bool hasReferencingContent() const noexcept;
648
649private:
650 struct TileConstructorImpl {};
651 template <
652 typename... TileContentArgs,
653 typename TileContentEnable = std::enable_if_t<
654 std::is_constructible_v<TileContent, TileContentArgs&&...>,
655 int>>
656 Tile(
657 TileConstructorImpl tag,
658 TileLoadState loadState,
659 TilesetContentLoader* pLoader,
660 const TileID& tileID,
661 TileContentArgs&&... args);
662
663 void setParent(Tile* pParent) noexcept;
664
665 void setState(TileLoadState state) noexcept;
666
682 bool getMightHaveLatentChildren() const noexcept;
683
684 void setMightHaveLatentChildren(bool mightHaveLatentChildren) noexcept;
685
686 // Position in bounding-volume hierarchy.
687 Tile* _pParent;
688 std::vector<Tile> _children;
689
690 // Properties from tileset.json.
691 // These are immutable after the tile leaves TileState::Unloaded.
692 TileID _id;
693 BoundingVolume _boundingVolume;
694 std::optional<BoundingVolume> _viewerRequestVolume;
695 std::optional<BoundingVolume> _contentBoundingVolume;
696 double _geometricError;
697 TileRefine _refine;
698 glm::dmat4x4 _transform;
699
700 // tile content
701 CesiumUtility::DoublyLinkedListPointers<Tile> _unusedTilesLinks;
702 TileContent _content;
703 TilesetContentLoader* _pLoader;
704 TileLoadState _loadState;
705 bool _mightHaveLatentChildren;
706
707 // mapped raster overlay
708 std::vector<RasterMappedTo3DTile> _rasterTiles;
709
710 mutable int32_t _referenceCount;
711
712 friend class TilesetContentManager;
713 friend class MockTilesetContentManagerTestFixture;
714
715public:
719 typedef CesiumUtility::DoublyLinkedList<Tile, &Tile::_unusedTilesLinks>
721};
722
723} // 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...
A tile in a Tileset.
Definition Tile.h:123
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....
const std::optional< BoundingVolume > & getViewerRequestVolume() const noexcept
Returns the viewer request volume of this tile.
Definition Tile.h:315
const std::optional< BoundingVolume > & getContentBoundingVolume() const noexcept
Returns the BoundingVolume of the renderable content of this tile.
Definition Tile.h:465
const TileID & getTileID() const noexcept
Returns the TileID of this tile.
Definition Tile.h:442
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:720
const std::vector< RasterMappedTo3DTile > & getMappedRasterTiles() const noexcept
Returns the raster overlay tiles that have been mapped to this tile.
Definition Tile.h:497
void setGeometricError(double value) noexcept
Set the geometric error of the contents of this tile.
Definition Tile.h:349
bool isExternalContent() const noexcept
Determines if this tile has external tileset content.
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:451
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.
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:241
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:258
CesiumUtility::IntrusivePointer< const Tile > ConstPointer
A reference counting pointer to a const Tile.
Definition Tile.h:141
void setRefine(TileRefine value) noexcept
Set the refinement strategy of this tile.
Definition Tile.h:412
const glm::dmat4x4 & getTransform() const noexcept
Gets the transformation matrix for this tile.
Definition Tile.h:422
std::span< Tile > getChildren() noexcept
Returns a view on the children of this tile.
Definition Tile.h:253
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:431
void setViewerRequestVolume(const std::optional< BoundingVolume > &value) noexcept
Set the viewer request volume of this tile.
Definition Tile.h:327
bool needsWorkerThreadLoading(const GltfModifier *pModifier) const noexcept
Determines if this tile requires worker-thread loading.
TileRefine getRefine() const noexcept
The refinement strategy of this tile.
Definition Tile.h:403
std::vector< RasterMappedTo3DTile > & getMappedRasterTiles() noexcept
Returns the raster overlay tiles that have been mapped to this tile.
Definition Tile.h:491
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 releaseReference(const char *reason=nullptr) const noexcept
Removes a reference from this tile. A live reference will keep this tile from being destroyed,...
void setContentBoundingVolume(const std::optional< BoundingVolume > &value) noexcept
Set the BoundingVolume of the renderable content of this tile.
Definition Tile.h:477
const BoundingVolume & getBoundingVolume() const noexcept
Returns the BoundingVolume of this tile.
Definition Tile.h:289
void setBoundingVolume(const BoundingVolume &value) noexcept
Set the BoundingVolume of this tile.
Definition Tile.h:300
void setUnconditionallyRefine() noexcept
Marks that this tile should be unconditionally refined.
Definition Tile.h:388
bool getUnconditionallyRefine() const noexcept
Returns whether to unconditionally refine this tile.
Definition Tile.h:379
TileContent & getContent() noexcept
Get the content of the tile.
Definition Tile.h:507
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:504
double getGeometricError() const noexcept
Returns the geometric error of this tile.
Definition Tile.h:340
const Tile * getParent() const noexcept
Returns the parent of this tile in the tile hierarchy.
Definition Tile.h:244
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< CesiumGeometry::BoundingSphere, CesiumGeometry::OrientedBoundingBox, CesiumGeospatial::BoundingRegion, CesiumGeospatial::BoundingRegionWithLooseFittingHeights, CesiumGeospatial::S2CellBoundingVolume, CesiumGeometry::BoundingCylinderRegion > 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:39
Utility classes for Cesium.
STL namespace.
A content tag that indicates a tile has no content.
Definition TileContent.h:46