cesium-native 0.55.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 const CesiumUtility::CreditSource& getCreditSource() const noexcept;
149
154 TilesetExternals& getExternals() noexcept { return this->_externals; }
155
160 const TilesetExternals& getExternals() const noexcept {
161 return this->_externals;
162 }
163
169 return this->_asyncSystem;
170 }
171
173 const CesiumAsync::AsyncSystem& getAsyncSystem() const noexcept {
174 return this->_asyncSystem;
175 }
176
178 const TilesetOptions& getOptions() const noexcept { return this->_options; }
179
183 TilesetOptions& getOptions() noexcept { return this->_options; }
184
189 return this->_options.ellipsoid;
190 }
191
194 return this->_options.ellipsoid;
195 }
196
202 const Tile* getRootTile() const noexcept;
203
208
210 const RasterOverlayCollection& getOverlays() const noexcept;
211
216
219
230 [[deprecated("Instead of `tileset.updateViewOffline(...)`, call "
231 "`tileset.updateViewGroupOffline(tileset.getDefaultViewGroup(), "
232 "...)`.")]] const ViewUpdateResult&
233 updateViewOffline(const std::vector<ViewState>& frustums);
234
250 [[deprecated("Instead of `tileset.updateView(...)`, call "
251 "`tileset.updateViewGroup(tileset.getDefaultViewGroup(), ...)` "
252 "followed by `tileset.loadTiles()`.")]] const ViewUpdateResult&
253 updateView(const std::vector<ViewState>& frustums, float deltaTime = 0.0f);
254
258 int32_t getNumberOfTilesLoaded() const;
259
267 float computeLoadProgress() noexcept;
268
286
293 const std::function<void(const Tile& tile)>& callback) const;
294
299 int64_t getTotalDataBytes() const noexcept;
300
325 const TilesetMetadata* getMetadata(const Tile* pTile = nullptr) const;
326
343
363 const std::vector<CesiumGeospatial::Cartographic>& positions);
364
372
375
400 TilesetViewGroup& viewGroup,
401 const std::vector<ViewState>& frustums,
402 float deltaTime = 0.0f);
403
424 TilesetViewGroup& viewGroup,
425 const std::vector<ViewState>& frustums);
426
439 void loadTiles();
440
454
466 bool waitForAllLoadsToComplete(double maximumWaitTimeInMilliseconds);
467
468 Tileset(const Tileset& rhs) = delete;
469 Tileset& operator=(const Tileset& rhs) = delete;
470
471private:
480 struct TraversalDetails {
488 bool allAreRenderable = true;
489
499 bool anyWereRenderedLastFrame = false;
500
519 uint32_t notYetRenderableCount = 0;
520 };
521
522 TraversalDetails _renderLeaf(
523 const TilesetFrameState& frameState,
524 Tile& tile,
525 double tilePriority,
526 ViewUpdateResult& result);
527 TraversalDetails _renderInnerTile(
528 const TilesetFrameState& frameState,
529 Tile& tile,
530 ViewUpdateResult& result);
531 bool _kickDescendantsAndRenderTile(
532 const TilesetFrameState& frameState,
533 Tile& tile,
534 ViewUpdateResult& result,
535 TraversalDetails& traversalDetails,
536 size_t firstRenderedDescendantIndex,
537 const TilesetViewGroup::LoadQueueCheckpoint& loadQueueBeforeChildren,
538 bool queuedForLoad,
539 double tilePriority);
540 TileOcclusionState _checkOcclusion(const Tile& tile);
541
542 TraversalDetails _visitTile(
543 const TilesetFrameState& frameState,
544 uint32_t depth,
545 bool meetsSse,
546 bool ancestorMeetsSse,
547 Tile& tile,
548 double tilePriority,
549 ViewUpdateResult& result);
550
551 struct CullResult {
552 // whether we should visit this tile
553 bool shouldVisit = true;
554 // whether this tile was culled (Note: we might still want to visit it)
555 bool culled = false;
556 };
557
558 // TODO: abstract these into a composable culling interface.
559 void _frustumCull(
560 const Tile& tile,
561 const TilesetFrameState& frameState,
562 bool cullWithChildrenBounds,
563 CullResult& cullResult);
564 void _fogCull(
565 const TilesetFrameState& frameState,
566 const std::vector<double>& distances,
567 CullResult& cullResult);
568 bool _meetsSse(
569 const std::vector<ViewState>& frustums,
570 const Tile& tile,
571 const std::vector<double>& distances,
572 bool culled) const noexcept;
573
574 TraversalDetails _visitTileIfNeeded(
575 const TilesetFrameState& frameState,
576 uint32_t depth,
577 bool ancestorMeetsSse,
578 Tile& tile,
579 ViewUpdateResult& result);
580 TraversalDetails _visitVisibleChildrenNearToFar(
581 const TilesetFrameState& frameState,
582 uint32_t depth,
583 bool ancestorMeetsSse,
584 Tile& tile,
585 ViewUpdateResult& result);
586
602 bool _loadAndRenderAdditiveRefinedTile(
603 const TilesetFrameState& frameState,
604 Tile& tile,
605 ViewUpdateResult& result,
606 double tilePriority,
607 bool queuedForLoad);
608
609 void _unloadCachedTiles(double timeBudget) noexcept;
610
611 void _updateLodTransitions(
612 const TilesetFrameState& frameState,
613 float deltaTime,
614 ViewUpdateResult& result) const noexcept;
615
616 TilesetExternals _externals;
617 CesiumAsync::AsyncSystem _asyncSystem;
618
619 TilesetOptions _options;
620
621 // Holds computed distances, to avoid allocating them on the heap during tile
622 // selection.
623 std::vector<double> _distances;
624
625 // Holds the occlusion proxies of the children of a tile. Store them in this
626 // scratch variable so that it can allocate only when growing bigger.
627 std::vector<const TileOcclusionRendererProxy*> _childOcclusionProxies;
628
630 _pTilesetContentManager;
631
632 std::list<TilesetHeightRequest> _heightRequests;
633
634 TilesetViewGroup _defaultViewGroup;
635
636 void addTileToLoadQueue(
637 const TilesetFrameState& frameState,
638 Tile& tile,
639 TileLoadPriorityGroup priorityGroup,
640 double priority);
641
642 static TraversalDetails createTraversalDetailsForSingleTile(
643 const TilesetFrameState& frameState,
644 const Tile& tile);
645};
646
647} // namespace Cesium3DTilesSelection
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:123
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. This holds all of the fields of ...
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:193
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:168
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:178
const TilesetExternals & getExternals() const noexcept
Gets the TilesetExternals that summarize the external interfaces used by this tileset.
Definition Tileset.h:160
const CesiumUtility::CreditSource & getCreditSource() const noexcept
Gets the CesiumUtility::CreditSource that identifies this tileset's credits with the CesiumUtility::C...
const CesiumAsync::AsyncSystem & getAsyncSystem() const noexcept
Returns the CesiumAsync::AsyncSystem that is used for dispatching asynchronous tasks.
Definition Tileset.h:173
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:183
std::optional< CesiumUtility::Credit > getUserCredit() const noexcept
Gets the CesiumUtility::Credit created from TilesetOptions::credit, if any.
void forEachLoadedTile(const std::function< void(const Tile &tile)> &callback) const
Invokes a function for each tile that is currently loaded.
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:188
~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.
bool waitForAllLoadsToComplete(double maximumWaitTimeInMilliseconds)
Waits until no tile loads are in progress. This function must be called from the main thread,...
const Tile * getRootTile() const noexcept
Gets the root tile of this tileset.
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:154
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.