cesium-native  0.41.0
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 
25 namespace Cesium3DTilesSelection {
26 
27 class TilesetContentManager;
28 class TilesetMetadata;
29 class TilesetHeightQuery;
30 class TilesetHeightRequest;
31 class TilesetSharedAssetSystem;
32 
39 class CESIUM3DTILESSELECTION_API Tileset final {
40 public:
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 
242  int64_t getTotalDataBytes() const noexcept;
243 
268  const TilesetMetadata* getMetadata(const Tile* pTile = nullptr) const;
269 
285  CesiumAsync::Future<const TilesetMetadata*> loadMetadata();
286 
305  CesiumAsync::Future<SampleHeightResult> sampleHeightMostDetailed(
306  const std::vector<CesiumGeospatial::Cartographic>& positions);
307 
308 private:
317  struct TraversalDetails {
325  bool allAreRenderable = true;
326 
336  bool anyWereRenderedLastFrame = false;
337 
356  uint32_t notYetRenderableCount = 0;
357  };
358 
366  struct FrameState {
367  const std::vector<ViewState>& frustums;
368  std::vector<double> fogDensities;
369  int32_t lastFrameNumber;
370  int32_t currentFrameNumber;
371  };
372 
373  TraversalDetails _renderLeaf(
374  const FrameState& frameState,
375  Tile& tile,
376  double tilePriority,
377  ViewUpdateResult& result);
378  TraversalDetails _renderInnerTile(
379  const FrameState& frameState,
380  Tile& tile,
381  ViewUpdateResult& result);
382  bool _kickDescendantsAndRenderTile(
383  const FrameState& frameState,
384  Tile& tile,
385  ViewUpdateResult& result,
386  TraversalDetails& traversalDetails,
387  size_t firstRenderedDescendantIndex,
388  size_t workerThreadLoadQueueIndex,
389  size_t mainThreadLoadQueueIndex,
390  bool queuedForLoad,
391  double tilePriority);
393  _checkOcclusion(const Tile& tile, const FrameState& frameState);
394 
395  TraversalDetails _visitTile(
396  const FrameState& frameState,
397  uint32_t depth,
398  bool meetsSse,
399  bool ancestorMeetsSse,
400  Tile& tile,
401  double tilePriority,
402  ViewUpdateResult& result);
403 
404  struct CullResult {
405  // whether we should visit this tile
406  bool shouldVisit = true;
407  // whether this tile was culled (Note: we might still want to visit it)
408  bool culled = false;
409  };
410 
411  // TODO: abstract these into a composable culling interface.
412  void _frustumCull(
413  const Tile& tile,
414  const FrameState& frameState,
415  bool cullWithChildrenBounds,
416  CullResult& cullResult);
417  void _fogCull(
418  const FrameState& frameState,
419  const std::vector<double>& distances,
420  CullResult& cullResult);
421  bool _meetsSse(
422  const std::vector<ViewState>& frustums,
423  const Tile& tile,
424  const std::vector<double>& distances,
425  bool culled) const noexcept;
426 
427  TraversalDetails _visitTileIfNeeded(
428  const FrameState& frameState,
429  uint32_t depth,
430  bool ancestorMeetsSse,
431  Tile& tile,
432  ViewUpdateResult& result);
433  TraversalDetails _visitVisibleChildrenNearToFar(
434  const FrameState& frameState,
435  uint32_t depth,
436  bool ancestorMeetsSse,
437  Tile& tile,
438  ViewUpdateResult& result);
439 
455  bool _loadAndRenderAdditiveRefinedTile(
456  Tile& tile,
457  ViewUpdateResult& result,
458  double tilePriority,
459  bool queuedForLoad);
460 
461  void _processWorkerThreadLoadQueue();
462  void _processMainThreadLoadQueue();
463 
464  void _unloadCachedTiles(double timeBudget) noexcept;
465  void _markTileVisited(Tile& tile) noexcept;
466 
467  void _updateLodTransitions(
468  const FrameState& frameState,
469  float deltaTime,
470  ViewUpdateResult& result) const noexcept;
471 
472  TilesetExternals _externals;
473  CesiumAsync::AsyncSystem _asyncSystem;
474 
475  TilesetOptions _options;
476 
477  int32_t _previousFrameNumber;
478  ViewUpdateResult _updateResult;
479 
480  enum class TileLoadPriorityGroup {
485  Preload = 0,
486 
491  Normal = 1,
492 
498  Urgent = 2
499  };
500 
501  struct TileLoadTask {
505  Tile* pTile;
506 
514  TileLoadPriorityGroup group;
515 
521  double priority;
522 
523  bool operator<(const TileLoadTask& rhs) const noexcept {
524  if (this->group == rhs.group)
525  return this->priority < rhs.priority;
526  else
527  return this->group > rhs.group;
528  }
529  };
530 
531  std::vector<TileLoadTask> _mainThreadLoadQueue;
532  std::vector<TileLoadTask> _workerThreadLoadQueue;
533  std::vector<Tile*> _heightQueryLoadQueue;
534 
535  Tile::LoadedLinkedList _loadedTiles;
536 
537  // Holds computed distances, to avoid allocating them on the heap during tile
538  // selection.
539  std::vector<double> _distances;
540 
541  // Holds the occlusion proxies of the children of a tile. Store them in this
542  // scratch variable so that it can allocate only when growing bigger.
543  std::vector<const TileOcclusionRendererProxy*> _childOcclusionProxies;
544 
546  _pTilesetContentManager;
547 
548  std::list<TilesetHeightRequest> _heightRequests;
549 
550  void addTileToLoadQueue(
551  Tile& tile,
552  TileLoadPriorityGroup priorityGroup,
553  double priority);
554 
555  static TraversalDetails createTraversalDetailsForSingleTile(
556  const FrameState& frameState,
557  const Tile& tile,
558  const TileSelectionState& lastFrameSelectionState);
559 
560  Tileset(const Tileset& rhs) = delete;
561  Tileset& operator=(const Tileset& rhs) = delete;
562 };
563 
564 } // namespace Cesium3DTilesSelection
A collection of RasterOverlay instances that are associated with a Tileset.
A tile in a Tileset.
Definition: Tile.h:97
CesiumUtility::DoublyLinkedList< Tile, &Tile::_loadedTilesLinks > LoadedLinkedList
A CesiumUtility::DoublyLinkedList for tile objects.
Definition: Tile.h:558
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
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.
CesiumGeospatial::Ellipsoid & getEllipsoid() noexcept
Gets the CesiumGeospatial::Ellipsoid used by this tileset.
Definition: Tileset.h:164
~Tileset() noexcept
Destroys this tileset.
const CesiumAsync::AsyncSystem & getAsyncSystem() const noexcept
Returns the CesiumAsync::AsyncSystem that is used for dispatching asynchronous tasks.
Definition: Tileset.h:144
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 TilesetExternals & getExternals() const noexcept
Gets the TilesetExternals that summarize the external interfaces used by this tileset.
Definition: Tileset.h:131
const TilesetOptions & getOptions() const noexcept
Gets the TilesetOptions of this tileset.
Definition: Tileset.h:149
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
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
Classes that implement the 3D Tiles standard.
Classes that support asynchronous operations.
Classes for geospatial computations in Cesium.
Utility classes for Cesium.
The result of sampling heights with Tileset::sampleHeightMostDetailed.
Additional options for configuring a Tileset.