cesium-native 0.48.0
Loading...
Searching...
No Matches
Tileset.h
1#pragma once
2
3#include <Cesium3DTilesSelection/Library.h>
4#include <Cesium3DTilesSelection/LoadedTileEnumerator.h>
5#include <Cesium3DTilesSelection/RasterOverlayCollection.h>
6#include <Cesium3DTilesSelection/SampleHeightResult.h>
7#include <Cesium3DTilesSelection/Tile.h>
8#include <Cesium3DTilesSelection/TilesetContentLoader.h>
9#include <Cesium3DTilesSelection/TilesetContentLoaderFactory.h>
10#include <Cesium3DTilesSelection/TilesetExternals.h>
11#include <Cesium3DTilesSelection/TilesetLoadFailureDetails.h>
12#include <Cesium3DTilesSelection/TilesetOptions.h>
13#include <Cesium3DTilesSelection/TilesetViewGroup.h>
14#include <Cesium3DTilesSelection/ViewState.h>
15#include <Cesium3DTilesSelection/ViewUpdateResult.h>
16#include <CesiumAsync/AsyncSystem.h>
17#include <CesiumUtility/IntrusivePointer.h>
18
19#include <rapidjson/fwd.h>
20
21#include <list>
22#include <memory>
23#include <string>
24#include <vector>
25
26namespace Cesium3DTilesSelection {
27
28class TilesetContentManager;
29class TilesetMetadata;
30class TilesetHeightQuery;
31struct TilesetHeightRequest;
35
42class CESIUM3DTILESSELECTION_API Tileset final {
43public:
53 const TilesetExternals& externals,
54 std::unique_ptr<TilesetContentLoader>&& pCustomLoader,
55 std::unique_ptr<Tile>&& pRootTile,
56 const TilesetOptions& options = TilesetOptions());
57
65 const TilesetExternals& externals,
66 const std::string& url,
67 const TilesetOptions& options = TilesetOptions());
68
81 const TilesetExternals& externals,
82 int64_t ionAssetID,
83 const std::string& ionAccessToken,
84 const TilesetOptions& options = TilesetOptions(),
85 const std::string& ionAssetEndpointUrl = "https://api.cesium.com/");
86
97 const TilesetExternals& externals,
98 TilesetContentLoaderFactory&& loaderFactory,
99 const TilesetOptions& options = TilesetOptions());
100
111 ~Tileset() noexcept;
112
119
126
131 std::optional<CesiumUtility::Credit> getUserCredit() const noexcept;
132
136 const std::vector<CesiumUtility::Credit>& getTilesetCredits() const noexcept;
137
142 void setShowCreditsOnScreen(bool showCreditsOnScreen) noexcept;
143
148 TilesetExternals& getExternals() noexcept { return this->_externals; }
149
154 const TilesetExternals& getExternals() const noexcept {
155 return this->_externals;
156 }
157
163 return this->_asyncSystem;
164 }
165
167 const CesiumAsync::AsyncSystem& getAsyncSystem() const noexcept {
168 return this->_asyncSystem;
169 }
170
172 const TilesetOptions& getOptions() const noexcept { return this->_options; }
173
177 TilesetOptions& getOptions() noexcept { return this->_options; }
178
183 return this->_options.ellipsoid;
184 }
185
188 return this->_options.ellipsoid;
189 }
190
196 Tile* getRootTile() noexcept;
197
199 const Tile* getRootTile() const noexcept;
200
205
207 const RasterOverlayCollection& getOverlays() const noexcept;
208
213
216
227 [[deprecated("Instead of `tileset.updateViewOffline(...)`, call "
228 "`tileset.updateViewGroupOffline(tileset.getDefaultViewGroup(), "
229 "...)`.")]] const ViewUpdateResult&
230 updateViewOffline(const std::vector<ViewState>& frustums);
231
247 [[deprecated("Instead of `tileset.updateView(...)`, call "
248 "`tileset.updateViewGroup(tileset.getDefaultViewGroup(), ...)` "
249 "followed by `tileset.loadTiles()`.")]] const ViewUpdateResult&
250 updateView(const std::vector<ViewState>& frustums, float deltaTime = 0.0f);
251
255 int32_t getNumberOfTilesLoaded() const;
256
264 float computeLoadProgress() noexcept;
265
283
286
292 void forEachLoadedTile(const std::function<void(Tile& tile)>& callback);
293
300 const std::function<void(const Tile& tile)>& callback) const;
301
306 int64_t getTotalDataBytes() const noexcept;
307
332 const TilesetMetadata* getMetadata(const Tile* pTile = nullptr) const;
333
350
370 const std::vector<CesiumGeospatial::Cartographic>& positions);
371
379
382
407 TilesetViewGroup& viewGroup,
408 const std::vector<ViewState>& frustums,
409 float deltaTime = 0.0f);
410
431 TilesetViewGroup& viewGroup,
432 const std::vector<ViewState>& frustums);
433
446 void loadTiles();
447
461
462 Tileset(const Tileset& rhs) = delete;
463 Tileset& operator=(const Tileset& rhs) = delete;
464
465private:
474 struct TraversalDetails {
482 bool allAreRenderable = true;
483
493 bool anyWereRenderedLastFrame = false;
494
513 uint32_t notYetRenderableCount = 0;
514 };
515
516 TraversalDetails _renderLeaf(
517 const TilesetFrameState& frameState,
518 Tile& tile,
519 double tilePriority,
520 ViewUpdateResult& result);
521 TraversalDetails _renderInnerTile(
522 const TilesetFrameState& frameState,
523 Tile& tile,
524 ViewUpdateResult& result);
525 bool _kickDescendantsAndRenderTile(
526 const TilesetFrameState& frameState,
527 Tile& tile,
528 ViewUpdateResult& result,
529 TraversalDetails& traversalDetails,
530 size_t firstRenderedDescendantIndex,
531 const TilesetViewGroup::LoadQueueCheckpoint& loadQueueBeforeChildren,
532 bool queuedForLoad,
533 double tilePriority);
534 TileOcclusionState _checkOcclusion(const Tile& tile);
535
536 TraversalDetails _visitTile(
537 const TilesetFrameState& frameState,
538 uint32_t depth,
539 bool meetsSse,
540 bool ancestorMeetsSse,
541 Tile& tile,
542 double tilePriority,
543 ViewUpdateResult& result);
544
545 struct CullResult {
546 // whether we should visit this tile
547 bool shouldVisit = true;
548 // whether this tile was culled (Note: we might still want to visit it)
549 bool culled = false;
550 };
551
552 // TODO: abstract these into a composable culling interface.
553 void _frustumCull(
554 const Tile& tile,
555 const TilesetFrameState& frameState,
556 bool cullWithChildrenBounds,
557 CullResult& cullResult);
558 void _fogCull(
559 const TilesetFrameState& frameState,
560 const std::vector<double>& distances,
561 CullResult& cullResult);
562 bool _meetsSse(
563 const std::vector<ViewState>& frustums,
564 const Tile& tile,
565 const std::vector<double>& distances,
566 bool culled) const noexcept;
567
568 TraversalDetails _visitTileIfNeeded(
569 const TilesetFrameState& frameState,
570 uint32_t depth,
571 bool ancestorMeetsSse,
572 Tile& tile,
573 ViewUpdateResult& result);
574 TraversalDetails _visitVisibleChildrenNearToFar(
575 const TilesetFrameState& frameState,
576 uint32_t depth,
577 bool ancestorMeetsSse,
578 Tile& tile,
579 ViewUpdateResult& result);
580
596 bool _loadAndRenderAdditiveRefinedTile(
597 const TilesetFrameState& frameState,
598 Tile& tile,
599 ViewUpdateResult& result,
600 double tilePriority,
601 bool queuedForLoad);
602
603 void _unloadCachedTiles(double timeBudget) noexcept;
604
605 void _updateLodTransitions(
606 const TilesetFrameState& frameState,
607 float deltaTime,
608 ViewUpdateResult& result) const noexcept;
609
610 TilesetExternals _externals;
611 CesiumAsync::AsyncSystem _asyncSystem;
612
613 TilesetOptions _options;
614
615 // Holds computed distances, to avoid allocating them on the heap during tile
616 // selection.
617 std::vector<double> _distances;
618
619 // Holds the occlusion proxies of the children of a tile. Store them in this
620 // scratch variable so that it can allocate only when growing bigger.
621 std::vector<const TileOcclusionRendererProxy*> _childOcclusionProxies;
622
624 _pTilesetContentManager;
625
626 std::list<TilesetHeightRequest> _heightRequests;
627
628 TilesetViewGroup _defaultViewGroup;
629
630 void addTileToLoadQueue(
631 const TilesetFrameState& frameState,
632 Tile& tile,
633 TileLoadPriorityGroup priorityGroup,
634 double priority);
635
636 static TraversalDetails createTraversalDetailsForSingleTile(
637 const TilesetFrameState& frameState,
638 const Tile& tile);
639};
640
641} // namespace Cesium3DTilesSelection
A "virtual collection" that allows enumeration through the loaded tiles in a subtree rooted at a give...
A "virtual collection" that allows enumeration through the loaded tiles in a subtree rooted at a give...
A collection of CesiumRasterOverlays::RasterOverlay instances that are associated with a Tileset.
The base class for something that requests loading of specific tiles from a 3D Tiles Tileset.
A tile in a Tileset.
Definition Tile.h:122
External interfaces used by a Tileset.
Captures information about the current frame during a call to Tileset::updateViewGroup.
Holds the metadata associated with a Tileset or an external tileset.
Contains assets that are potentially shared across multiple Tilesets.
Represents a group of views that collectively select tiles from a particular Tileset.
Tileset(const TilesetExternals &externals, TilesetContentLoaderFactory &&loaderFactory, const TilesetOptions &options=TilesetOptions())
Constructs a new instance with the given TilesetContentLoaderFactory.
void setShowCreditsOnScreen(bool showCreditsOnScreen) noexcept
Sets whether or not the tileset's credits should be shown on screen.
CesiumGeospatial::Ellipsoid & getEllipsoid() noexcept
Gets the CesiumGeospatial::Ellipsoid used by this tileset.
Definition Tileset.h:187
LoadedConstTileEnumerator loadedTiles() const
Gets an object that can be used to enumerate the loaded tiles of this tileset.
Tileset(const TilesetExternals &externals, int64_t ionAssetID, const std::string &ionAccessToken, const TilesetOptions &options=TilesetOptions(), const std::string &ionAssetEndpointUrl="https://api.cesium.com/")
Constructs a new instance with the given asset ID on Cesium ion.
Tileset(const TilesetExternals &externals, const std::string &url, const TilesetOptions &options=TilesetOptions())
Constructs a new instance with a given tileset.json URL.
CesiumAsync::AsyncSystem & getAsyncSystem() noexcept
Returns the CesiumAsync::AsyncSystem that is used for dispatching asynchronous tasks.
Definition Tileset.h:162
Tile * getRootTile() noexcept
Gets the root tile of this tileset.
CesiumAsync::Future< SampleHeightResult > sampleHeightMostDetailed(const std::vector< CesiumGeospatial::Cartographic > &positions)
Initiates an asynchronous query for the height of this tileset at a list of cartographic positions (l...
const TilesetOptions & getOptions() const noexcept
Gets the TilesetOptions of this tileset.
Definition Tileset.h:172
const TilesetExternals & getExternals() const noexcept
Gets the TilesetExternals that summarize the external interfaces used by this tileset.
Definition Tileset.h:154
void forEachLoadedTile(const std::function< void(Tile &tile)> &callback)
Invokes a function for each tile that is currently loaded.
const CesiumAsync::AsyncSystem & getAsyncSystem() const noexcept
Returns the CesiumAsync::AsyncSystem that is used for dispatching asynchronous tasks.
Definition Tileset.h:167
void loadTiles()
Loads the tiles that are currently deemed the most important, across all height queries and TilesetVi...
int32_t getNumberOfTilesLoaded() const
Gets the total number of tiles that are currently loaded.
CesiumAsync::SharedFuture< void > & getAsyncDestructionCompleteEvent()
A future that resolves when this Tileset has been destroyed (i.e. its destructor has been called) and...
CesiumAsync::SharedFuture< void > & getRootTileAvailableEvent()
A future that resolves when the details of the root tile of this tileset are available....
void registerLoadRequester(TileLoadRequester &requester)
Registers a tile load requester with this Tileset. Registered tile load requesters get to influence w...
TilesetViewGroup & getDefaultViewGroup()
Gets the default view group that is used when calling updateView.
float computeLoadProgress() noexcept
Gets the percentage of tiles that had been loaded for the default view group as of the last time it w...
const ViewUpdateResult & updateViewOffline(const std::vector< ViewState > &frustums)
Updates this view but waits for all tiles that meet sse to finish loading and ready to be rendered be...
int64_t getTotalDataBytes() const noexcept
Gets the total number of bytes of tile and raster overlay data that are currently loaded.
TilesetOptions & getOptions() noexcept
Gets the TilesetOptions of this tileset.
Definition Tileset.h:177
std::optional< CesiumUtility::Credit > getUserCredit() const noexcept
Gets the CesiumUtility::Credit created from TilesetOptions::credit, if any.
const TilesetMetadata * getMetadata(const Tile *pTile=nullptr) const
Gets the TilesetMetadata associated with the main or external tileset.json that contains a given tile...
const ViewUpdateResult & updateView(const std::vector< ViewState > &frustums, float deltaTime=0.0f)
Updates this view, returning the set of tiles to render in this view.
const ViewUpdateResult & updateViewGroup(TilesetViewGroup &viewGroup, const std::vector< ViewState > &frustums, float deltaTime=0.0f)
Updates a view group, returning the set of tiles to render in this view.
const CesiumGeospatial::Ellipsoid & getEllipsoid() const
Gets the CesiumGeospatial::Ellipsoid used by this tileset.
Definition Tileset.h:182
~Tileset() noexcept
Destroys this tileset.
Tileset(const TilesetExternals &externals, std::unique_ptr< TilesetContentLoader > &&pCustomLoader, std::unique_ptr< Tile > &&pRootTile, const TilesetOptions &options=TilesetOptions())
Constructs a new instance with a given custom tileset loader.
const std::vector< CesiumUtility::Credit > & getTilesetCredits() const noexcept
Get tileset credits.
RasterOverlayCollection & getOverlays() noexcept
Returns the RasterOverlayCollection of this tileset.
CesiumAsync::Future< const TilesetMetadata * > loadMetadata()
Asynchronously loads the metadata associated with the main tileset.json.
const ViewUpdateResult & updateViewGroupOffline(TilesetViewGroup &viewGroup, const std::vector< ViewState > &frustums)
Updates a view group, returning the set of tiles to render in this view. Unlike updateViewGroup,...
TilesetExternals & getExternals() noexcept
Gets the TilesetExternals that summarize the external interfaces used by this tileset.
Definition Tileset.h:148
TilesetSharedAssetSystem & getSharedAssetSystem() noexcept
Returns the TilesetSharedAssetSystem of this tileset.
The state of the view that is used during the traversal of a tileset.
Definition ViewState.h:25
Reports the results of Tileset::updateViewGroup.
A system for managing asynchronous requests and tasks.
Definition AsyncSystem.h:36
A quadratic surface defined in Cartesian coordinates.
Definition Ellipsoid.h:39
A smart pointer that calls addReference and releaseReference on the controlled object.
Classes that implement the 3D Tiles standard.
TileOcclusionState
The occlusion state of a tile as reported by the renderer proxy.
Classes that support asynchronous operations.
Classes for geospatial computations in Cesium.
Utility classes for Cesium.
STL namespace.
The result of sampling heights with Tileset::sampleHeightMostDetailed.
Additional options for configuring a Tileset.
A checkpoint within this view group's load queue.