cesium-native 0.47.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 {
28class TilesetContentLoader;
29
30#ifdef CESIUM_DEBUG_TILE_UNLOADING
31class TileReferenceCountTracker {
32private:
33 struct Entry {
34 std::string reason;
35 bool increment;
36 int32_t newCount;
37 };
38
39public:
40 static void addEntry(
41 const uint64_t id,
42 bool increment,
43 const char* reason,
44 int32_t newCount);
45
46private:
47 static std::unordered_map<std::string, std::vector<Entry>> _entries;
48};
49#endif
50
54enum class TileLoadState {
59 Unloading = -2,
60
66
71 Unloaded = 0,
72
81
85 ContentLoaded = 2,
86
90 Done = 3,
91
96 Failed = 4,
97};
98
122class CESIUM3DTILESSELECTION_API Tile final {
123public:
132
140 explicit Tile(TilesetContentLoader* pLoader) noexcept;
141
151 TilesetContentLoader* pLoader,
152 std::unique_ptr<TileExternalContent>&& externalContent) noexcept;
153
162 Tile(TilesetContentLoader* pLoader, TileEmptyContent emptyContent) noexcept;
163
168 ~Tile() noexcept;
169
175 Tile(const Tile& rhs) = delete;
176
182 Tile(Tile&& rhs) noexcept;
183
189 Tile& operator=(const Tile& rhs) = delete;
190
196 Tile& operator=(Tile&& rhs) noexcept = delete;
197
205 Tile* getParent() noexcept { return this->_pParent; }
206
208 const Tile* getParent() const noexcept { return this->_pParent; }
209
217 std::span<Tile> getChildren() noexcept {
218 return std::span<Tile>(this->_children);
219 }
220
222 std::span<const Tile> getChildren() const noexcept {
223 return std::span<const Tile>(this->_children);
224 }
225
231 void clearChildren() noexcept;
232
241 void createChildTiles(std::vector<Tile>&& children);
242
253 const BoundingVolume& getBoundingVolume() const noexcept {
254 return this->_boundingVolume;
255 }
256
264 void setBoundingVolume(const BoundingVolume& value) noexcept {
265 this->_boundingVolume = value;
266 }
267
279 const std::optional<BoundingVolume>& getViewerRequestVolume() const noexcept {
280 return this->_viewerRequestVolume;
281 }
282
290 void
291 setViewerRequestVolume(const std::optional<BoundingVolume>& value) noexcept {
292 this->_viewerRequestVolume = value;
293 }
294
304 double getGeometricError() const noexcept { return this->_geometricError; }
305
313 void setGeometricError(double value) noexcept {
314 this->_geometricError = value;
315 }
316
331 double getNonZeroGeometricError() const noexcept;
332
343 bool getUnconditionallyRefine() const noexcept {
344 return glm::isinf(this->_geometricError);
345 }
346
352 void setUnconditionallyRefine() noexcept {
353 this->_geometricError = std::numeric_limits<double>::infinity();
354 }
355
367 TileRefine getRefine() const noexcept { return this->_refine; }
368
376 void setRefine(TileRefine value) noexcept { this->_refine = value; }
377
386 const glm::dmat4x4& getTransform() const noexcept { return this->_transform; }
387
395 void setTransform(const glm::dmat4x4& value) noexcept {
396 this->_transform = value;
397 }
398
406 const TileID& getTileID() const noexcept { return this->_id; }
407
415 void setTileID(const TileID& id) noexcept { this->_id = id; }
416
428 const std::optional<BoundingVolume>&
429 getContentBoundingVolume() const noexcept {
430 return this->_contentBoundingVolume;
431 }
432
442 const std::optional<BoundingVolume>& value) noexcept {
443 this->_contentBoundingVolume = value;
444 }
445
450 int64_t computeByteSize() const noexcept;
451
455 std::vector<RasterMappedTo3DTile>& getMappedRasterTiles() noexcept {
456 return this->_rasterTiles;
457 }
458
460 const std::vector<RasterMappedTo3DTile>&
461 getMappedRasterTiles() const noexcept {
462 return this->_rasterTiles;
463 }
464
468 const TileContent& getContent() const noexcept { return _content; }
469
471 TileContent& getContent() noexcept { return _content; }
472
476 bool isRenderable() const noexcept;
477
481 bool isRenderContent() const noexcept;
482
486 bool isExternalContent() const noexcept;
487
491 bool isEmptyContent() const noexcept;
492
496 TilesetContentLoader* getLoader() const noexcept;
497
501 TileLoadState getState() const noexcept;
502
509 bool needsWorkerThreadLoading() const noexcept;
510
517 bool needsMainThreadLoading() const noexcept;
518
553 void addReference(const char* reason = nullptr) noexcept;
554
577 void releaseReference(const char* reason = nullptr) noexcept;
578
585 int32_t getReferenceCount() const noexcept;
586
605 bool hasReferencingContent() const noexcept;
606
607private:
608 struct TileConstructorImpl {};
609 template <
610 typename... TileContentArgs,
611 typename TileContentEnable = std::enable_if_t<
612 std::is_constructible_v<TileContent, TileContentArgs&&...>,
613 int>>
614 Tile(
615 TileConstructorImpl tag,
616 TileLoadState loadState,
617 TilesetContentLoader* pLoader,
618 TileContentArgs&&... args);
619
620 void setParent(Tile* pParent) noexcept;
621
622 void setState(TileLoadState state) noexcept;
623
639 bool getMightHaveLatentChildren() const noexcept;
640
641 void setMightHaveLatentChildren(bool mightHaveLatentChildren) noexcept;
642
643 // Position in bounding-volume hierarchy.
644 Tile* _pParent;
645 std::vector<Tile> _children;
646
647 // Properties from tileset.json.
648 // These are immutable after the tile leaves TileState::Unloaded.
649 TileID _id;
650 BoundingVolume _boundingVolume;
651 std::optional<BoundingVolume> _viewerRequestVolume;
652 std::optional<BoundingVolume> _contentBoundingVolume;
653 double _geometricError;
654 TileRefine _refine;
655 glm::dmat4x4 _transform;
656
657 // tile content
658 CesiumUtility::DoublyLinkedListPointers<Tile> _unusedTilesLinks;
659 TileContent _content;
660 TilesetContentLoader* _pLoader;
661 TileLoadState _loadState;
662 bool _mightHaveLatentChildren;
663
664 // mapped raster overlay
665 std::vector<RasterMappedTo3DTile> _rasterTiles;
666
667 int32_t _referenceCount;
668
669 friend class TilesetContentManager;
670 friend class MockTilesetContentManagerTestFixture;
671
672public:
676 typedef CesiumUtility::DoublyLinkedList<Tile, &Tile::_unusedTilesLinks>
678};
679
680} // namespace Cesium3DTilesSelection
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:122
const std::optional< BoundingVolume > & getViewerRequestVolume() const noexcept
Returns the viewer request volume of this tile.
Definition Tile.h:279
const std::optional< BoundingVolume > & getContentBoundingVolume() const noexcept
Returns the BoundingVolume of the renderable content of this tile.
Definition Tile.h:429
const TileID & getTileID() const noexcept
Returns the TileID of this tile.
Definition Tile.h:406
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::vector< RasterMappedTo3DTile > & getMappedRasterTiles() const noexcept
Returns the raster overlay tiles that have been mapped to this tile.
Definition Tile.h:461
void setGeometricError(double value) noexcept
Set the geometric error of the contents of this tile.
Definition Tile.h:313
void setTileID(const TileID &id) noexcept
Set the TileID of this tile.
Definition Tile.h:415
int64_t computeByteSize() const noexcept
Determines the number of bytes in this tile's geometry and texture data.
bool isRenderable() const noexcept
Determines if this tile is currently renderable.
~Tile() noexcept
Default destructor, which clears all resources associated with this tile.
void clearChildren() noexcept
Clears the children of this tile.
std::span< const Tile > getChildren() const noexcept
Returns a view on the children of this tile.
Definition Tile.h:222
void setRefine(TileRefine value) noexcept
Set the refinement strategy of this tile.
Definition Tile.h:376
const glm::dmat4x4 & getTransform() const noexcept
Gets the transformation matrix for this tile.
Definition Tile.h:386
std::span< Tile > getChildren() noexcept
Returns a view on the children of this tile.
Definition Tile.h:217
void setTransform(const glm::dmat4x4 &value) noexcept
Set the transformation matrix for this tile.
Definition Tile.h:395
void setViewerRequestVolume(const std::optional< BoundingVolume > &value) noexcept
Set the viewer request volume of this tile.
Definition Tile.h:291
TileRefine getRefine() const noexcept
The refinement strategy of this tile.
Definition Tile.h:367
Tile(TilesetContentLoader *pLoader, TileEmptyContent emptyContent) noexcept
Construct a tile with an empty content and a loader that is associated with this tile....
void setContentBoundingVolume(const std::optional< BoundingVolume > &value) noexcept
Set the BoundingVolume of the renderable content of this tile.
Definition Tile.h:441
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:264
void setUnconditionallyRefine() noexcept
Marks that this tile should be unconditionally refined.
Definition Tile.h:352
TileContent & getContent() noexcept
Get the content of the tile.
Definition Tile.h:471
const TileContent & getContent() const noexcept
Get the content of the tile.
Definition Tile.h:468
double getGeometricError() const noexcept
Returns the geometric error of this tile.
Definition Tile.h:304
const Tile * getParent() const noexcept
Returns the parent of this tile in the tile hierarchy.
Definition Tile.h:208
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.
@ 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, 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:44