cesium-native 0.46.0
Loading...
Searching...
No Matches
Tileset.h
1#pragma once
2
3#include <Cesium3DTilesSelection/Library.h>
4#include <Cesium3DTilesSelection/RasterOverlayCollection.h>
5#include <Cesium3DTilesSelection/SampleHeightResult.h>
6#include <Cesium3DTilesSelection/Tile.h>
7#include <Cesium3DTilesSelection/TilesetContentLoader.h>
8#include <Cesium3DTilesSelection/TilesetContentLoaderFactory.h>
9#include <Cesium3DTilesSelection/TilesetExternals.h>
10#include <Cesium3DTilesSelection/TilesetLoadFailureDetails.h>
11#include <Cesium3DTilesSelection/TilesetOptions.h>
12#include <Cesium3DTilesSelection/ViewState.h>
13#include <Cesium3DTilesSelection/ViewUpdateResult.h>
14#include <CesiumAsync/AsyncSystem.h>
15#include <CesiumUtility/IntrusivePointer.h>
16
17#include <rapidjson/fwd.h>
18
19#include <list>
20#include <memory>
21#include <string>
22#include <vector>
23
24namespace Cesium3DTilesSelection {
25
26class TilesetContentManager;
27class TilesetMetadata;
28class TilesetHeightQuery;
29struct TilesetHeightRequest;
30class TilesetSharedAssetSystem;
31
38class CESIUM3DTILESSELECTION_API Tileset final {
39public:
49 const TilesetExternals& externals,
50 std::unique_ptr<TilesetContentLoader>&& pCustomLoader,
51 std::unique_ptr<Tile>&& pRootTile,
52 const TilesetOptions& options = TilesetOptions());
53
61 const TilesetExternals& externals,
62 const std::string& url,
63 const TilesetOptions& options = TilesetOptions());
64
77 const TilesetExternals& externals,
78 int64_t ionAssetID,
79 const std::string& ionAccessToken,
80 const TilesetOptions& options = TilesetOptions(),
81 const std::string& ionAssetEndpointUrl = "https://api.cesium.com/");
82
93 const TilesetExternals& externals,
94 TilesetContentLoaderFactory&& loaderFactory,
95 const TilesetOptions& options = TilesetOptions());
96
107 ~Tileset() noexcept;
108
114 CesiumAsync::SharedFuture<void>& getAsyncDestructionCompleteEvent();
115
121 CesiumAsync::SharedFuture<void>& getRootTileAvailableEvent();
122
126 const std::vector<CesiumUtility::Credit>& getTilesetCredits() const noexcept;
127
132 void setShowCreditsOnScreen(bool showCreditsOnScreen) noexcept;
133
138 TilesetExternals& getExternals() noexcept { return this->_externals; }
139
144 const TilesetExternals& getExternals() const noexcept {
145 return this->_externals;
146 }
147
153 return this->_asyncSystem;
154 }
155
157 const CesiumAsync::AsyncSystem& getAsyncSystem() const noexcept {
158 return this->_asyncSystem;
159 }
160
162 const TilesetOptions& getOptions() const noexcept { return this->_options; }
163
167 TilesetOptions& getOptions() noexcept { return this->_options; }
168
173 return this->_options.ellipsoid;
174 }
175
178 return this->_options.ellipsoid;
179 }
180
186 Tile* getRootTile() noexcept;
187
189 const Tile* getRootTile() const noexcept;
190
194 RasterOverlayCollection& getOverlays() noexcept;
195
197 const RasterOverlayCollection& getOverlays() const noexcept;
198
202 TilesetSharedAssetSystem& getSharedAssetSystem() noexcept;
203
205 const TilesetSharedAssetSystem& getSharedAssetSystem() const noexcept;
206
217 const ViewUpdateResult&
218 updateViewOffline(const std::vector<ViewState>& frustums);
219
230 const ViewUpdateResult&
231 updateView(const std::vector<ViewState>& frustums, float deltaTime = 0.0f);
232
236 int32_t getNumberOfTilesLoaded() const;
237
242 float computeLoadProgress() noexcept;
243
249 void forEachLoadedTile(const std::function<void(Tile& tile)>& callback);
250
256 void forEachLoadedTile(
257 const std::function<void(const Tile& tile)>& callback) const;
258
263 int64_t getTotalDataBytes() const noexcept;
264
289 const TilesetMetadata* getMetadata(const Tile* pTile = nullptr) const;
290
306 CesiumAsync::Future<const TilesetMetadata*> loadMetadata();
307
326 CesiumAsync::Future<SampleHeightResult> sampleHeightMostDetailed(
327 const std::vector<CesiumGeospatial::Cartographic>& positions);
328
329 Tileset(const Tileset& rhs) = delete;
330 Tileset& operator=(const Tileset& rhs) = delete;
331
332private:
341 struct TraversalDetails {
349 bool allAreRenderable = true;
350
360 bool anyWereRenderedLastFrame = false;
361
380 uint32_t notYetRenderableCount = 0;
381 };
382
390 struct FrameState {
391 const std::vector<ViewState>& frustums;
392 std::vector<double> fogDensities;
393 int32_t lastFrameNumber;
394 int32_t currentFrameNumber;
395 };
396
397 TraversalDetails _renderLeaf(
398 const FrameState& frameState,
399 Tile& tile,
400 double tilePriority,
401 ViewUpdateResult& result);
402 TraversalDetails _renderInnerTile(
403 const FrameState& frameState,
404 Tile& tile,
405 ViewUpdateResult& result);
406 bool _kickDescendantsAndRenderTile(
407 const FrameState& frameState,
408 Tile& tile,
409 ViewUpdateResult& result,
410 TraversalDetails& traversalDetails,
411 size_t firstRenderedDescendantIndex,
412 size_t workerThreadLoadQueueIndex,
413 size_t mainThreadLoadQueueIndex,
414 bool queuedForLoad,
415 double tilePriority);
416 TileOcclusionState
417 _checkOcclusion(const Tile& tile, const FrameState& frameState);
418
419 TraversalDetails _visitTile(
420 const FrameState& frameState,
421 uint32_t depth,
422 bool meetsSse,
423 bool ancestorMeetsSse,
424 Tile& tile,
425 double tilePriority,
426 ViewUpdateResult& result);
427
428 struct CullResult {
429 // whether we should visit this tile
430 bool shouldVisit = true;
431 // whether this tile was culled (Note: we might still want to visit it)
432 bool culled = false;
433 };
434
435 // TODO: abstract these into a composable culling interface.
436 void _frustumCull(
437 const Tile& tile,
438 const FrameState& frameState,
439 bool cullWithChildrenBounds,
440 CullResult& cullResult);
441 void _fogCull(
442 const FrameState& frameState,
443 const std::vector<double>& distances,
444 CullResult& cullResult);
445 bool _meetsSse(
446 const std::vector<ViewState>& frustums,
447 const Tile& tile,
448 const std::vector<double>& distances,
449 bool culled) const noexcept;
450
451 TraversalDetails _visitTileIfNeeded(
452 const FrameState& frameState,
453 uint32_t depth,
454 bool ancestorMeetsSse,
455 Tile& tile,
456 ViewUpdateResult& result);
457 TraversalDetails _visitVisibleChildrenNearToFar(
458 const FrameState& frameState,
459 uint32_t depth,
460 bool ancestorMeetsSse,
461 Tile& tile,
462 ViewUpdateResult& result);
463
479 bool _loadAndRenderAdditiveRefinedTile(
480 Tile& tile,
481 ViewUpdateResult& result,
482 double tilePriority,
483 bool queuedForLoad);
484
485 void _processWorkerThreadLoadQueue();
486 void _processMainThreadLoadQueue();
487
488 void _clearChildrenRecursively(Tile* pTile) noexcept;
489 void _unloadCachedTiles(double timeBudget) noexcept;
490 void _markTileVisited(Tile& tile) noexcept;
491
492 void _updateLodTransitions(
493 const FrameState& frameState,
494 float deltaTime,
495 ViewUpdateResult& result) const noexcept;
496
497 TilesetExternals _externals;
498 CesiumAsync::AsyncSystem _asyncSystem;
499
500 TilesetOptions _options;
501
502 int32_t _previousFrameNumber;
503 ViewUpdateResult _updateResult;
504
505 enum class TileLoadPriorityGroup {
510 Preload = 0,
511
516 Normal = 1,
517
523 Urgent = 2
524 };
525
526 struct TileLoadTask {
530 Tile* pTile;
531
539 TileLoadPriorityGroup group;
540
546 double priority;
547
548 bool operator<(const TileLoadTask& rhs) const noexcept {
549 if (this->group == rhs.group)
550 return this->priority < rhs.priority;
551 else
552 return this->group > rhs.group;
553 }
554 };
555
556 std::vector<TileLoadTask> _mainThreadLoadQueue;
557 std::vector<TileLoadTask> _workerThreadLoadQueue;
558 std::vector<Tile*> _heightQueryLoadQueue;
559
560 Tile::LoadedLinkedList _loadedTiles;
561
562 // Holds computed distances, to avoid allocating them on the heap during tile
563 // selection.
564 std::vector<double> _distances;
565
566 // Holds the occlusion proxies of the children of a tile. Store them in this
567 // scratch variable so that it can allocate only when growing bigger.
568 std::vector<const TileOcclusionRendererProxy*> _childOcclusionProxies;
569
571 _pTilesetContentManager;
572
573 std::list<TilesetHeightRequest> _heightRequests;
574
575 void addTileToLoadQueue(
576 Tile& tile,
577 TileLoadPriorityGroup priorityGroup,
578 double priority);
579
580 static TraversalDetails createTraversalDetailsForSingleTile(
581 const FrameState& frameState,
582 const Tile& tile,
583 const TileSelectionState& lastFrameSelectionState);
584};
585
586} // namespace Cesium3DTilesSelection
A collection of CesiumRasterOverlays::RasterOverlay instances that are associated with a Tileset.
A tile in a Tileset.
Definition Tile.h:121
External interfaces used by a Tileset.
Holds the metadata associated with a Tileset or an external tileset.
Contains assets that are potentially shared across multiple Tilesets.
A 3D Tiles tileset, used for streaming massive heterogeneous 3D geospatial datasets.
Definition Tileset.h:38
Tileset(const TilesetExternals &externals, TilesetContentLoaderFactory &&loaderFactory, const TilesetOptions &options=TilesetOptions())
Constructs a new instance with the given TilesetContentLoaderFactory.
CesiumGeospatial::Ellipsoid & getEllipsoid() noexcept
Gets the CesiumGeospatial::Ellipsoid used by this tileset.
Definition Tileset.h:177
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:152
Tile * getRootTile() noexcept
Gets the root tile of this tileset.
const TilesetOptions & getOptions() const noexcept
Gets the TilesetOptions of this tileset.
Definition Tileset.h:162
const TilesetExternals & getExternals() const noexcept
Gets the TilesetExternals that summarize the external interfaces used by this tileset.
Definition Tileset.h:144
const CesiumAsync::AsyncSystem & getAsyncSystem() const noexcept
Returns the CesiumAsync::AsyncSystem that is used for dispatching asynchronous tasks.
Definition Tileset.h:157
TilesetOptions & getOptions() noexcept
Gets the TilesetOptions of this tileset.
Definition Tileset.h:167
const CesiumGeospatial::Ellipsoid & getEllipsoid() const
Gets the CesiumGeospatial::Ellipsoid used by this tileset.
Definition Tileset.h:172
~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.
The state of the view that is used during the traversal of a tileset.
Definition ViewState.h:23
Reports the results of Tileset::updateView.
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.
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.