cesium-native 0.43.0
Loading...
Searching...
No Matches
Tileset.h
1#pragma once
2
3#include "Library.h"
4#include "RasterOverlayCollection.h"
5#include "SampleHeightResult.h"
6#include "Tile.h"
7#include "TilesetContentLoader.h"
8#include "TilesetExternals.h"
9#include "TilesetLoadFailureDetails.h"
10#include "TilesetOptions.h"
11#include "ViewState.h"
12#include "ViewUpdateResult.h"
13
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 <optional>
22#include <string>
23#include <vector>
24
25namespace Cesium3DTilesSelection {
26
27class TilesetContentManager;
28class TilesetMetadata;
29class TilesetHeightQuery;
30struct TilesetHeightRequest;
31class TilesetSharedAssetSystem;
32
39class CESIUM3DTILESSELECTION_API Tileset final {
40public:
50 const TilesetExternals& externals,
51 std::unique_ptr<TilesetContentLoader>&& pCustomLoader,
52 std::unique_ptr<Tile>&& pRootTile,
53 const TilesetOptions& options = TilesetOptions());
54
62 const TilesetExternals& externals,
63 const std::string& url,
64 const TilesetOptions& options = TilesetOptions());
65
78 const TilesetExternals& externals,
79 int64_t ionAssetID,
80 const std::string& ionAccessToken,
81 const TilesetOptions& options = TilesetOptions(),
82 const std::string& ionAssetEndpointUrl = "https://api.cesium.com/");
83
94 ~Tileset() noexcept;
95
101 CesiumAsync::SharedFuture<void>& getAsyncDestructionCompleteEvent();
102
108 CesiumAsync::SharedFuture<void>& getRootTileAvailableEvent();
109
113 const std::vector<CesiumUtility::Credit>& getTilesetCredits() const noexcept;
114
119 void setShowCreditsOnScreen(bool showCreditsOnScreen) noexcept;
120
125 TilesetExternals& getExternals() noexcept { return this->_externals; }
126
131 const TilesetExternals& getExternals() const noexcept {
132 return this->_externals;
133 }
134
140 return this->_asyncSystem;
141 }
142
144 const CesiumAsync::AsyncSystem& getAsyncSystem() const noexcept {
145 return this->_asyncSystem;
146 }
147
149 const TilesetOptions& getOptions() const noexcept { return this->_options; }
150
154 TilesetOptions& getOptions() noexcept { return this->_options; }
155
160 return this->_options.ellipsoid;
161 }
162
165 return this->_options.ellipsoid;
166 }
167
173 Tile* getRootTile() noexcept;
174
176 const Tile* getRootTile() const noexcept;
177
181 RasterOverlayCollection& getOverlays() noexcept;
182
184 const RasterOverlayCollection& getOverlays() const noexcept;
185
189 TilesetSharedAssetSystem& getSharedAssetSystem() noexcept;
190
192 const TilesetSharedAssetSystem& getSharedAssetSystem() const noexcept;
193
204 const ViewUpdateResult&
205 updateViewOffline(const std::vector<ViewState>& frustums);
206
217 const ViewUpdateResult&
218 updateView(const std::vector<ViewState>& frustums, float deltaTime = 0.0f);
219
223 int32_t getNumberOfTilesLoaded() const;
224
229 float computeLoadProgress() noexcept;
230
236 void forEachLoadedTile(const std::function<void(Tile& tile)>& callback);
237
243 void forEachLoadedTile(
244 const std::function<void(const Tile& tile)>& callback) const;
245
250 int64_t getTotalDataBytes() const noexcept;
251
276 const TilesetMetadata* getMetadata(const Tile* pTile = nullptr) const;
277
293 CesiumAsync::Future<const TilesetMetadata*> loadMetadata();
294
313 CesiumAsync::Future<SampleHeightResult> sampleHeightMostDetailed(
314 const std::vector<CesiumGeospatial::Cartographic>& positions);
315
316private:
325 struct TraversalDetails {
333 bool allAreRenderable = true;
334
344 bool anyWereRenderedLastFrame = false;
345
364 uint32_t notYetRenderableCount = 0;
365 };
366
374 struct FrameState {
375 const std::vector<ViewState>& frustums;
376 std::vector<double> fogDensities;
377 int32_t lastFrameNumber;
378 int32_t currentFrameNumber;
379 };
380
381 TraversalDetails _renderLeaf(
382 const FrameState& frameState,
383 Tile& tile,
384 double tilePriority,
385 ViewUpdateResult& result);
386 TraversalDetails _renderInnerTile(
387 const FrameState& frameState,
388 Tile& tile,
389 ViewUpdateResult& result);
390 bool _kickDescendantsAndRenderTile(
391 const FrameState& frameState,
392 Tile& tile,
393 ViewUpdateResult& result,
394 TraversalDetails& traversalDetails,
395 size_t firstRenderedDescendantIndex,
396 size_t workerThreadLoadQueueIndex,
397 size_t mainThreadLoadQueueIndex,
398 bool queuedForLoad,
399 double tilePriority);
400 TileOcclusionState
401 _checkOcclusion(const Tile& tile, const FrameState& frameState);
402
403 TraversalDetails _visitTile(
404 const FrameState& frameState,
405 uint32_t depth,
406 bool meetsSse,
407 bool ancestorMeetsSse,
408 Tile& tile,
409 double tilePriority,
410 ViewUpdateResult& result);
411
412 struct CullResult {
413 // whether we should visit this tile
414 bool shouldVisit = true;
415 // whether this tile was culled (Note: we might still want to visit it)
416 bool culled = false;
417 };
418
419 // TODO: abstract these into a composable culling interface.
420 void _frustumCull(
421 const Tile& tile,
422 const FrameState& frameState,
423 bool cullWithChildrenBounds,
424 CullResult& cullResult);
425 void _fogCull(
426 const FrameState& frameState,
427 const std::vector<double>& distances,
428 CullResult& cullResult);
429 bool _meetsSse(
430 const std::vector<ViewState>& frustums,
431 const Tile& tile,
432 const std::vector<double>& distances,
433 bool culled) const noexcept;
434
435 TraversalDetails _visitTileIfNeeded(
436 const FrameState& frameState,
437 uint32_t depth,
438 bool ancestorMeetsSse,
439 Tile& tile,
440 ViewUpdateResult& result);
441 TraversalDetails _visitVisibleChildrenNearToFar(
442 const FrameState& frameState,
443 uint32_t depth,
444 bool ancestorMeetsSse,
445 Tile& tile,
446 ViewUpdateResult& result);
447
463 bool _loadAndRenderAdditiveRefinedTile(
464 Tile& tile,
465 ViewUpdateResult& result,
466 double tilePriority,
467 bool queuedForLoad);
468
469 void _processWorkerThreadLoadQueue();
470 void _processMainThreadLoadQueue();
471
472 void _unloadCachedTiles(double timeBudget) noexcept;
473 void _markTileVisited(Tile& tile) noexcept;
474
475 void _updateLodTransitions(
476 const FrameState& frameState,
477 float deltaTime,
478 ViewUpdateResult& result) const noexcept;
479
480 TilesetExternals _externals;
481 CesiumAsync::AsyncSystem _asyncSystem;
482
483 TilesetOptions _options;
484
485 int32_t _previousFrameNumber;
486 ViewUpdateResult _updateResult;
487
488 enum class TileLoadPriorityGroup {
493 Preload = 0,
494
499 Normal = 1,
500
506 Urgent = 2
507 };
508
509 struct TileLoadTask {
513 Tile* pTile;
514
522 TileLoadPriorityGroup group;
523
529 double priority;
530
531 bool operator<(const TileLoadTask& rhs) const noexcept {
532 if (this->group == rhs.group)
533 return this->priority < rhs.priority;
534 else
535 return this->group > rhs.group;
536 }
537 };
538
539 std::vector<TileLoadTask> _mainThreadLoadQueue;
540 std::vector<TileLoadTask> _workerThreadLoadQueue;
541 std::vector<Tile*> _heightQueryLoadQueue;
542
543 Tile::LoadedLinkedList _loadedTiles;
544
545 // Holds computed distances, to avoid allocating them on the heap during tile
546 // selection.
547 std::vector<double> _distances;
548
549 // Holds the occlusion proxies of the children of a tile. Store them in this
550 // scratch variable so that it can allocate only when growing bigger.
551 std::vector<const TileOcclusionRendererProxy*> _childOcclusionProxies;
552
554 _pTilesetContentManager;
555
556 std::list<TilesetHeightRequest> _heightRequests;
557
558 void addTileToLoadQueue(
559 Tile& tile,
560 TileLoadPriorityGroup priorityGroup,
561 double priority);
562
563 static TraversalDetails createTraversalDetailsForSingleTile(
564 const FrameState& frameState,
565 const Tile& tile,
566 const TileSelectionState& lastFrameSelectionState);
567
568 Tileset(const Tileset& rhs) = delete;
569 Tileset& operator=(const Tileset& rhs) = delete;
570};
571
572} // namespace Cesium3DTilesSelection
A collection of CesiumRasterOverlays::RasterOverlay instances that are associated with a Tileset.
A tile in a Tileset.
Definition Tile.h:97
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:39
CesiumGeospatial::Ellipsoid & getEllipsoid() noexcept
Gets the CesiumGeospatial::Ellipsoid used by this tileset.
Definition Tileset.h:164
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:139
Tile * getRootTile() noexcept
Gets the root tile of this tileset.
const TilesetOptions & getOptions() const noexcept
Gets the TilesetOptions of this tileset.
Definition Tileset.h:149
const TilesetExternals & getExternals() const noexcept
Gets the TilesetExternals that summarize the external interfaces used by this tileset.
Definition Tileset.h:131
const CesiumAsync::AsyncSystem & getAsyncSystem() const noexcept
Returns the CesiumAsync::AsyncSystem that is used for dispatching asynchronous tasks.
Definition Tileset.h:144
TilesetOptions & getOptions() noexcept
Gets the TilesetOptions of this tileset.
Definition Tileset.h:154
const CesiumGeospatial::Ellipsoid & getEllipsoid() const
Gets the CesiumGeospatial::Ellipsoid used by this tileset.
Definition Tileset.h:159
~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:24
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:38
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.