cesium-native 0.46.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
12#include <glm/common.hpp>
13
14#include <atomic>
15#include <limits>
16#include <memory>
17#include <optional>
18#include <span>
19#include <string>
20#include <vector>
21
22#ifdef CESIUM_DEBUG_TILE_UNLOADING
23#include <unordered_map>
24#endif
25
26namespace Cesium3DTilesSelection {
27class TilesetContentLoader;
28
29#ifdef CESIUM_DEBUG_TILE_UNLOADING
30class TileDoNotUnloadSubtreeCountTracker {
31private:
32 struct Entry {
33 std::string reason;
34 bool increment;
35 int32_t newCount;
36 };
37
38public:
39 static void addEntry(
40 const uint64_t id,
41 bool increment,
42 const std::string& reason,
43 int32_t newCount);
44
45private:
46 static std::unordered_map<std::string, std::vector<Entry>> _entries;
47};
48#endif
49
53enum class TileLoadState {
58 Unloading = -2,
59
65
70 Unloaded = 0,
71
80
84 ContentLoaded = 2,
85
89 Done = 3,
90
95 Failed = 4,
96};
97
121class CESIUM3DTILESSELECTION_API Tile final {
122public:
130 explicit Tile(TilesetContentLoader* pLoader) noexcept;
131
141 TilesetContentLoader* pLoader,
142 std::unique_ptr<TileExternalContent>&& externalContent) noexcept;
143
152 Tile(TilesetContentLoader* pLoader, TileEmptyContent emptyContent) noexcept;
153
158 ~Tile() noexcept = default;
159
165 Tile(const Tile& rhs) = delete;
166
172 Tile(Tile&& rhs) noexcept;
173
179 Tile& operator=(const Tile& rhs) = delete;
180
186 Tile& operator=(Tile&& rhs) noexcept;
187
195 Tile* getParent() noexcept { return this->_pParent; }
196
198 const Tile* getParent() const noexcept { return this->_pParent; }
199
207 std::span<Tile> getChildren() noexcept {
208 return std::span<Tile>(this->_children);
209 }
210
212 std::span<const Tile> getChildren() const noexcept {
213 return std::span<const Tile>(this->_children);
214 }
215
221 void clearChildren() noexcept;
222
231 void createChildTiles(std::vector<Tile>&& children);
232
243 const BoundingVolume& getBoundingVolume() const noexcept {
244 return this->_boundingVolume;
245 }
246
254 void setBoundingVolume(const BoundingVolume& value) noexcept {
255 this->_boundingVolume = value;
256 }
257
269 const std::optional<BoundingVolume>& getViewerRequestVolume() const noexcept {
270 return this->_viewerRequestVolume;
271 }
272
280 void
281 setViewerRequestVolume(const std::optional<BoundingVolume>& value) noexcept {
282 this->_viewerRequestVolume = value;
283 }
284
294 double getGeometricError() const noexcept { return this->_geometricError; }
295
303 void setGeometricError(double value) noexcept {
304 this->_geometricError = value;
305 }
306
321 double getNonZeroGeometricError() const noexcept;
322
333 bool getUnconditionallyRefine() const noexcept {
334 return glm::isinf(this->_geometricError);
335 }
336
342 void setUnconditionallyRefine() noexcept {
343 this->_geometricError = std::numeric_limits<double>::infinity();
344 }
345
357 TileRefine getRefine() const noexcept { return this->_refine; }
358
366 void setRefine(TileRefine value) noexcept { this->_refine = value; }
367
376 const glm::dmat4x4& getTransform() const noexcept { return this->_transform; }
377
385 void setTransform(const glm::dmat4x4& value) noexcept {
386 this->_transform = value;
387 }
388
396 const TileID& getTileID() const noexcept { return this->_id; }
397
405 void setTileID(const TileID& id) noexcept { this->_id = id; }
406
418 const std::optional<BoundingVolume>&
419 getContentBoundingVolume() const noexcept {
420 return this->_contentBoundingVolume;
421 }
422
432 const std::optional<BoundingVolume>& value) noexcept {
433 this->_contentBoundingVolume = value;
434 }
435
444 return this->_lastSelectionState;
445 }
446
449 return this->_lastSelectionState;
450 }
451
459 void setLastSelectionState(const TileSelectionState& newState) noexcept {
460 this->_lastSelectionState = newState;
461 }
462
467 int64_t computeByteSize() const noexcept;
468
472 std::vector<RasterMappedTo3DTile>& getMappedRasterTiles() noexcept {
473 return this->_rasterTiles;
474 }
475
477 const std::vector<RasterMappedTo3DTile>&
478 getMappedRasterTiles() const noexcept {
479 return this->_rasterTiles;
480 }
481
485 const TileContent& getContent() const noexcept { return _content; }
486
488 TileContent& getContent() noexcept { return _content; }
489
493 bool isRenderable() const noexcept;
494
498 bool isRenderContent() const noexcept;
499
503 bool isExternalContent() const noexcept;
504
508 bool isEmptyContent() const noexcept;
509
513 TilesetContentLoader* getLoader() const noexcept;
514
518 TileLoadState getState() const noexcept;
519
526 int32_t getDoNotUnloadSubtreeCount() const noexcept {
527 return this->_doNotUnloadSubtreeCount;
528 }
529
536 void incrementDoNotUnloadSubtreeCount(const char* reason) noexcept;
537
544 void decrementDoNotUnloadSubtreeCount(const char* reason) noexcept;
545
552 void incrementDoNotUnloadSubtreeCountOnParent(const char* reason) noexcept;
553
560 void decrementDoNotUnloadSubtreeCountOnParent(const char* reason) noexcept;
561
562private:
563 void incrementDoNotUnloadSubtreeCount(const std::string& reason) noexcept;
564
565 void decrementDoNotUnloadSubtreeCount(const std::string& reason) noexcept;
566
567 struct TileConstructorImpl {};
568 template <
569 typename... TileContentArgs,
570 typename TileContentEnable = std::enable_if_t<
571 std::is_constructible_v<TileContent, TileContentArgs&&...>,
572 int>>
573 Tile(
574 TileConstructorImpl tag,
575 TileLoadState loadState,
576 TilesetContentLoader* pLoader,
577 TileContentArgs&&... args);
578
579 void setParent(Tile* pParent) noexcept;
580
581 void setState(TileLoadState state) noexcept;
582
598 bool getMightHaveLatentChildren() const noexcept;
599
600 void setMightHaveLatentChildren(bool mightHaveLatentChildren) noexcept;
601
602 // Position in bounding-volume hierarchy.
603 Tile* _pParent;
604 std::vector<Tile> _children;
605
606 // Properties from tileset.json.
607 // These are immutable after the tile leaves TileState::Unloaded.
608 TileID _id;
609 BoundingVolume _boundingVolume;
610 std::optional<BoundingVolume> _viewerRequestVolume;
611 std::optional<BoundingVolume> _contentBoundingVolume;
612 double _geometricError;
613 TileRefine _refine;
614 glm::dmat4x4 _transform;
615
616 // Selection state
617 TileSelectionState _lastSelectionState;
618
619 // tile content
620 CesiumUtility::DoublyLinkedListPointers<Tile> _loadedTilesLinks;
621 TileContent _content;
622 TilesetContentLoader* _pLoader;
623 TileLoadState _loadState;
624 bool _mightHaveLatentChildren;
625
626 // mapped raster overlay
627 std::vector<RasterMappedTo3DTile> _rasterTiles;
628
629 // Number of existing claims on this tile preventing it and its parent
630 // external tileset (if any) from being unloaded from the tree.
631 int32_t _doNotUnloadSubtreeCount = 0;
632
633 friend class TilesetContentManager;
634 friend class MockTilesetContentManagerTestFixture;
635
636public:
640 typedef CesiumUtility::DoublyLinkedList<Tile, &Tile::_loadedTilesLinks>
642};
643
644} // 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 description of the state of a Tile during the rendering process.
A tile in a Tileset.
Definition Tile.h:121
const std::optional< BoundingVolume > & getViewerRequestVolume() const noexcept
Returns the viewer request volume of this tile.
Definition Tile.h:269
const std::optional< BoundingVolume > & getContentBoundingVolume() const noexcept
Returns the BoundingVolume of the renderable content of this tile.
Definition Tile.h:419
const TileID & getTileID() const noexcept
Returns the TileID of this tile.
Definition Tile.h:396
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....
TileSelectionState & getLastSelectionState() noexcept
Returns the TileSelectionState of this tile.
Definition Tile.h:443
const std::vector< RasterMappedTo3DTile > & getMappedRasterTiles() const noexcept
Returns the raster overlay tiles that have been mapped to this tile.
Definition Tile.h:478
void setGeometricError(double value) noexcept
Set the geometric error of the contents of this tile.
Definition Tile.h:303
void setLastSelectionState(const TileSelectionState &newState) noexcept
Set the TileSelectionState of this tile.
Definition Tile.h:459
void setTileID(const TileID &id) noexcept
Set the TileID of this tile.
Definition Tile.h:405
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.
const TileSelectionState & getLastSelectionState() const noexcept
Returns the TileSelectionState of this tile.
Definition Tile.h:448
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:212
void setRefine(TileRefine value) noexcept
Set the refinement strategy of this tile.
Definition Tile.h:366
void incrementDoNotUnloadSubtreeCount(const char *reason) noexcept
Increments the internal count denoting that the tile and its ancestors should not be unloaded.
const glm::dmat4x4 & getTransform() const noexcept
Gets the transformation matrix for this tile.
Definition Tile.h:376
std::span< Tile > getChildren() noexcept
Returns a view on the children of this tile.
Definition Tile.h:207
void setTransform(const glm::dmat4x4 &value) noexcept
Set the transformation matrix for this tile.
Definition Tile.h:385
void setViewerRequestVolume(const std::optional< BoundingVolume > &value) noexcept
Set the viewer request volume of this tile.
Definition Tile.h:281
TileRefine getRefine() const noexcept
The refinement strategy of this tile.
Definition Tile.h:357
Tile(TilesetContentLoader *pLoader, TileEmptyContent emptyContent) noexcept
Construct a tile with an empty content and a loader that is associated with this tile....
void decrementDoNotUnloadSubtreeCount(const char *reason) noexcept
Decrements the internal count denoting that the tile and its ancestors should not be unloaded.
void setContentBoundingVolume(const std::optional< BoundingVolume > &value) noexcept
Set the BoundingVolume of the renderable content of this tile.
Definition Tile.h:431
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:254
void decrementDoNotUnloadSubtreeCountOnParent(const char *reason) noexcept
Decrements the internal count denoting that the tile and its ancestors should not be unloaded startin...
void setUnconditionallyRefine() noexcept
Marks that this tile should be unconditionally refined.
Definition Tile.h:342
~Tile() noexcept=default
Default destructor, which clears all resources associated with this tile.
TileContent & getContent() noexcept
Get the content of the tile.
Definition Tile.h:488
void incrementDoNotUnloadSubtreeCountOnParent(const char *reason) noexcept
Increments the internal count denoting that the tile and its ancestors should not be unloaded startin...
const TileContent & getContent() const noexcept
Get the content of the tile.
Definition Tile.h:485
double getGeometricError() const noexcept
Returns the geometric error of this tile.
Definition Tile.h:294
const Tile * getParent() const noexcept
Returns the parent of this tile in the tile hierarchy.
Definition Tile.h:198
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, 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