cesium-native 0.51.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 {
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 {
60
66
72
81
86
90 Done = 3,
91
96 Failed = 4,
97};
98
122class CESIUM3DTILESSELECTION_API Tile final {
123public:
132
141
151 explicit Tile(
152 TilesetContentLoader* pLoader,
153 const TileID& tileID = {}) noexcept;
154
173 TilesetContentLoader* pLoader,
174 const TileID& tileID,
175 std::unique_ptr<TileExternalContent>&& externalContent) noexcept;
176
195 TilesetContentLoader* pLoader,
196 const TileID& tileID,
197 TileEmptyContent emptyContent) noexcept;
198
203 ~Tile() noexcept;
204
210 Tile(const Tile& rhs) = delete;
211
217 Tile(Tile&& rhs) noexcept;
218
224 Tile& operator=(const Tile& rhs) = delete;
225
231 Tile& operator=(Tile&& rhs) noexcept = delete;
232
240 Tile* getParent() noexcept { return this->_pParent; }
241
243 const Tile* getParent() const noexcept { return this->_pParent; }
244
252 std::span<Tile> getChildren() noexcept {
253 return std::span<Tile>(this->_children);
254 }
255
257 std::span<const Tile> getChildren() const noexcept {
258 return std::span<const Tile>(this->_children);
259 }
260
266 void clearChildren() noexcept;
267
276 void createChildTiles(std::vector<Tile>&& children);
277
288 const BoundingVolume& getBoundingVolume() const noexcept {
289 return this->_boundingVolume;
290 }
291
299 void setBoundingVolume(const BoundingVolume& value) noexcept {
300 this->_boundingVolume = value;
301 }
302
314 const std::optional<BoundingVolume>& getViewerRequestVolume() const noexcept {
315 return this->_viewerRequestVolume;
316 }
317
325 void
326 setViewerRequestVolume(const std::optional<BoundingVolume>& value) noexcept {
327 this->_viewerRequestVolume = value;
328 }
329
339 double getGeometricError() const noexcept { return this->_geometricError; }
340
348 void setGeometricError(double value) noexcept {
349 this->_geometricError = value;
350 }
351
366 double getNonZeroGeometricError() const noexcept;
367
378 bool getUnconditionallyRefine() const noexcept {
379 return glm::isinf(this->_geometricError);
380 }
381
387 void setUnconditionallyRefine() noexcept {
388 this->_geometricError = std::numeric_limits<double>::infinity();
389 }
390
402 TileRefine getRefine() const noexcept { return this->_refine; }
403
411 void setRefine(TileRefine value) noexcept { this->_refine = value; }
412
421 const glm::dmat4x4& getTransform() const noexcept { return this->_transform; }
422
430 void setTransform(const glm::dmat4x4& value) noexcept {
431 this->_transform = value;
432 }
433
441 const TileID& getTileID() const noexcept { return this->_id; }
442
450 void setTileID(const TileID& id) noexcept { this->_id = id; }
451
463 const std::optional<BoundingVolume>&
464 getContentBoundingVolume() const noexcept {
465 return this->_contentBoundingVolume;
466 }
467
477 const std::optional<BoundingVolume>& value) noexcept {
478 this->_contentBoundingVolume = value;
479 }
480
485 int64_t computeByteSize() const noexcept;
486
491 return this->_rasterTiles;
492 }
493
495 const std::vector<RasterMappedTo3DTile>&
496 getMappedRasterTiles() const noexcept {
497 return this->_rasterTiles;
498 }
499
503 const TileContent& getContent() const noexcept { return _content; }
504
506 TileContent& getContent() noexcept { return _content; }
507
511 bool isRenderable() const noexcept;
512
516 bool isRenderContent() const noexcept;
517
521 bool isExternalContent() const noexcept;
522
526 bool isEmptyContent() const noexcept;
527
532
536 TileLoadState getState() const noexcept;
537
544 bool needsWorkerThreadLoading() const noexcept;
545
552 bool needsMainThreadLoading() const noexcept;
553
588 void addReference(const char* reason = nullptr) const noexcept;
589
612 void releaseReference(const char* reason = nullptr) const noexcept;
613
620 int32_t getReferenceCount() const noexcept;
621
640 bool hasReferencingContent() const noexcept;
641
642private:
643 struct TileConstructorImpl {};
644 template <
645 typename... TileContentArgs,
646 typename TileContentEnable = std::enable_if_t<
647 std::is_constructible_v<TileContent, TileContentArgs&&...>,
648 int>>
649 Tile(
650 TileConstructorImpl tag,
651 TileLoadState loadState,
652 TilesetContentLoader* pLoader,
653 const TileID& tileID,
654 TileContentArgs&&... args);
655
656 void setParent(Tile* pParent) noexcept;
657
658 void setState(TileLoadState state) noexcept;
659
675 bool getMightHaveLatentChildren() const noexcept;
676
677 void setMightHaveLatentChildren(bool mightHaveLatentChildren) noexcept;
678
679 // Position in bounding-volume hierarchy.
680 Tile* _pParent;
681 std::vector<Tile> _children;
682
683 // Properties from tileset.json.
684 // These are immutable after the tile leaves TileState::Unloaded.
685 TileID _id;
686 BoundingVolume _boundingVolume;
687 std::optional<BoundingVolume> _viewerRequestVolume;
688 std::optional<BoundingVolume> _contentBoundingVolume;
689 double _geometricError;
690 TileRefine _refine;
691 glm::dmat4x4 _transform;
692
693 // tile content
694 CesiumUtility::DoublyLinkedListPointers<Tile> _unusedTilesLinks;
695 TileContent _content;
696 TilesetContentLoader* _pLoader;
697 TileLoadState _loadState;
698 bool _mightHaveLatentChildren;
699
700 // mapped raster overlay
701 std::vector<RasterMappedTo3DTile> _rasterTiles;
702
703 mutable int32_t _referenceCount;
704
705 friend class TilesetContentManager;
706 friend class MockTilesetContentManagerTestFixture;
707
708public:
712 typedef CesiumUtility::DoublyLinkedList<Tile, &Tile::_unusedTilesLinks>
714};
715
716} // 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
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:314
const std::optional< BoundingVolume > & getContentBoundingVolume() const noexcept
Returns the BoundingVolume of the renderable content of this tile.
Definition Tile.h:464
const TileID & getTileID() const noexcept
Returns the TileID of this tile.
Definition Tile.h:441
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:713
const std::vector< RasterMappedTo3DTile > & getMappedRasterTiles() const noexcept
Returns the raster overlay tiles that have been mapped to this tile.
Definition Tile.h:496
void setGeometricError(double value) noexcept
Set the geometric error of the contents of this tile.
Definition Tile.h:348
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:450
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.
bool needsMainThreadLoading() const noexcept
Determines if this tile requires main-thread loading.
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:240
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:131
std::span< const Tile > getChildren() const noexcept
Returns a view on the children of this tile.
Definition Tile.h:257
CesiumUtility::IntrusivePointer< const Tile > ConstPointer
A reference counting pointer to a const Tile.
Definition Tile.h:140
bool needsWorkerThreadLoading() const noexcept
Determines if this tile requires worker-thread loading.
void setRefine(TileRefine value) noexcept
Set the refinement strategy of this tile.
Definition Tile.h:411
const glm::dmat4x4 & getTransform() const noexcept
Gets the transformation matrix for this tile.
Definition Tile.h:421
std::span< Tile > getChildren() noexcept
Returns a view on the children of this tile.
Definition Tile.h:252
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:430
void setViewerRequestVolume(const std::optional< BoundingVolume > &value) noexcept
Set the viewer request volume of this tile.
Definition Tile.h:326
TileRefine getRefine() const noexcept
The refinement strategy of this tile.
Definition Tile.h:402
std::vector< RasterMappedTo3DTile > & getMappedRasterTiles() noexcept
Returns the raster overlay tiles that have been mapped to this tile.
Definition Tile.h:490
int32_t getReferenceCount() const noexcept
Gets the current number of references to this tile.
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:476
const BoundingVolume & getBoundingVolume() const noexcept
Returns the BoundingVolume of this tile.
Definition Tile.h:288
void setBoundingVolume(const BoundingVolume &value) noexcept
Set the BoundingVolume of this tile.
Definition Tile.h:299
void setUnconditionallyRefine() noexcept
Marks that this tile should be unconditionally refined.
Definition Tile.h:387
bool getUnconditionallyRefine() const noexcept
Returns whether to unconditionally refine this tile.
Definition Tile.h:378
TileContent & getContent() noexcept
Get the content of the tile.
Definition Tile.h:506
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:503
double getGeometricError() const noexcept
Returns the geometric error of this tile.
Definition Tile.h:339
const Tile * getParent() const noexcept
Returns the parent of this tile in the tile hierarchy.
Definition Tile.h:243
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:85
@ Unloading
This tile is in the process of being unloaded, but could not be fully unloaded because an asynchronou...
Definition Tile.h:59
@ ContentLoading
The tile content is currently being loaded.
Definition Tile.h:80
@ FailedTemporarily
Something went wrong while loading this tile, but it may be a temporary problem.
Definition Tile.h:65
@ Unloaded
The tile is not yet loaded at all, beyond the metadata in tileset.json.
Definition Tile.h:71
@ Failed
Something went wrong while loading this tile and it will not be retried.
Definition Tile.h:96
@ Done
The tile is completely done loading.
Definition Tile.h:90
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:45