cesium-native  0.41.0
RasterOverlayTileProvider.h
1 #pragma once
2 
3 #include "Library.h"
4 
5 #include <CesiumAsync/IAssetAccessor.h>
6 #include <CesiumGeospatial/Projection.h>
7 #include <CesiumGltfReader/GltfReader.h>
8 #include <CesiumUtility/Assert.h>
9 #include <CesiumUtility/CreditSystem.h>
10 #include <CesiumUtility/ErrorList.h>
11 #include <CesiumUtility/IntrusivePointer.h>
12 #include <CesiumUtility/ReferenceCounted.h>
13 #include <CesiumUtility/Tracing.h>
14 
15 #include <spdlog/fwd.h>
16 
17 #include <optional>
18 
19 namespace CesiumRasterOverlays {
20 
21 class RasterOverlay;
22 class RasterOverlayTile;
23 class IPrepareRasterOverlayRendererResources;
24 
28 struct CESIUMRASTEROVERLAYS_API LoadedRasterOverlayImage {
36 
44 
49  std::vector<CesiumUtility::Credit> credits{};
50 
58 
63  bool moreDetailAvailable = false;
64 };
65 
75 
82  std::vector<CesiumUtility::Credit> credits{};
83 
88  bool moreDetailAvailable = true;
89 
107  bool allowEmptyImages = false;
108 };
109 
111 
119 
120  ~TileProviderAndTile() noexcept;
121 };
122 
129 class CESIUMRASTEROVERLAYS_API RasterOverlayTileProvider
131  RasterOverlayTileProvider> {
132 public:
145  const CesiumAsync::AsyncSystem& asyncSystem,
146  const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
147  const CesiumGeospatial::Ellipsoid& ellipsoid
148  CESIUM_DEFAULT_ELLIPSOID) noexcept;
149 
168  const CesiumAsync::AsyncSystem& asyncSystem,
169  const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
170  std::optional<CesiumUtility::Credit> credit,
171  const std::shared_ptr<IPrepareRasterOverlayRendererResources>&
172  pPrepareRendererResources,
173  const std::shared_ptr<spdlog::logger>& pLogger,
174  const CesiumGeospatial::Projection& projection,
175  const CesiumGeometry::Rectangle& coverageRectangle) noexcept;
176 
178  virtual ~RasterOverlayTileProvider() noexcept;
179 
199  bool isPlaceholder() const noexcept { return this->_pPlaceholder != nullptr; }
200 
204  RasterOverlay& getOwner() noexcept { return *this->_pOwner; }
205 
207  const RasterOverlay& getOwner() const noexcept { return *this->_pOwner; }
208 
212  const std::shared_ptr<CesiumAsync::IAssetAccessor>&
213  getAssetAccessor() const noexcept {
214  return this->_pAssetAccessor;
215  }
216 
220  const CesiumAsync::AsyncSystem& getAsyncSystem() const noexcept {
221  return this->_asyncSystem;
222  }
223 
228  const std::shared_ptr<IPrepareRasterOverlayRendererResources>&
229  getPrepareRendererResources() const noexcept {
230  return this->_pPrepareRendererResources;
231  }
232 
237  const std::shared_ptr<spdlog::logger>& getLogger() const noexcept {
238  return this->_pLogger;
239  }
240 
244  const CesiumGeospatial::Projection& getProjection() const noexcept {
245  return this->_projection;
246  }
247 
253  return this->_coverageRectangle;
254  }
255 
276  const CesiumGeometry::Rectangle& rectangle,
277  const glm::dvec2& targetScreenPixels);
278 
282  int64_t getTileDataBytes() const noexcept { return this->_tileDataBytes; }
283 
287  uint32_t getNumberOfTilesLoading() const noexcept {
288  CESIUM_ASSERT(this->_totalTilesCurrentlyLoading > -1);
289  return this->_totalTilesCurrentlyLoading;
290  }
291 
302  void removeTile(RasterOverlayTile* pTile) noexcept;
303 
307  const std::optional<CesiumUtility::Credit>& getCredit() const noexcept {
308  return _credit;
309  }
310 
328 
351 
352 protected:
360  loadTileImage(RasterOverlayTile& overlayTile) = 0;
361 
373  const std::string& url,
374  const std::vector<CesiumAsync::IAssetAccessor::THeader>& headers = {},
375  LoadTileImageFromUrlOptions&& options = {}) const;
376 
377 private:
379  doLoad(RasterOverlayTile& tile, bool isThrottledLoad);
380 
388  void beginTileLoad(bool isThrottledLoad) noexcept;
389 
398  void finalizeTileLoad(bool isThrottledLoad) noexcept;
399 
400 private:
402  CesiumAsync::AsyncSystem _asyncSystem;
403  std::shared_ptr<CesiumAsync::IAssetAccessor> _pAssetAccessor;
404  std::optional<CesiumUtility::Credit> _credit;
405  std::shared_ptr<IPrepareRasterOverlayRendererResources>
406  _pPrepareRendererResources;
407  std::shared_ptr<spdlog::logger> _pLogger;
408  CesiumGeospatial::Projection _projection;
409  CesiumGeometry::Rectangle _coverageRectangle;
411  int64_t _tileDataBytes;
412  int32_t _totalTilesCurrentlyLoading;
413  int32_t _throttledTilesCurrentlyLoading;
414  CESIUM_TRACE_DECLARE_TRACK_SET(
415  _loadingSlots,
416  "Raster Overlay Tile Loading Slot");
417 };
418 } // namespace CesiumRasterOverlays
A system for managing asynchronous requests and tasks.
Definition: AsyncSystem.h:36
A value that will be available in the future, as produced by AsyncSystem.
Definition: Future.h:29
A quadratic surface defined in Cartesian coordinates.
Definition: Ellipsoid.h:38
Provides individual tiles for a RasterOverlay on demand.
void removeTile(RasterOverlayTile *pTile) noexcept
Removes a no-longer-referenced tile from this provider's cache and deletes it.
bool loadTileThrottled(RasterOverlayTile &tile)
Loads a tile, unless there are too many tile loads already in progress.
const std::shared_ptr< spdlog::logger > & getLogger() const noexcept
Gets the logger to which to send messages about the tile provider and tiles.
virtual CesiumAsync::Future< LoadedRasterOverlayImage > loadTileImage(RasterOverlayTile &overlayTile)=0
Loads the image for a tile.
const CesiumGeometry::Rectangle & getCoverageRectangle() const noexcept
Returns the coverage CesiumGeometry::Rectangle of this instance.
CesiumAsync::Future< TileProviderAndTile > loadTile(RasterOverlayTile &tile)
Loads a tile immediately, without throttling requests.
CesiumUtility::IntrusivePointer< RasterOverlayTile > getTile(const CesiumGeometry::Rectangle &rectangle, const glm::dvec2 &targetScreenPixels)
Returns a new RasterOverlayTile with the given specifications.
CesiumAsync::Future< LoadedRasterOverlayImage > loadTileImageFromUrl(const std::string &url, const std::vector< CesiumAsync::IAssetAccessor::THeader > &headers={}, LoadTileImageFromUrlOptions &&options={}) const
Loads an image from a URL and optionally some request headers.
const CesiumAsync::AsyncSystem & getAsyncSystem() const noexcept
Gets the async system used to do work in threads.
RasterOverlay & getOwner() noexcept
Returns the RasterOverlay that created this instance.
const RasterOverlay & getOwner() const noexcept
Returns the RasterOverlay that created this instance.
virtual ~RasterOverlayTileProvider() noexcept
Default destructor.
RasterOverlayTileProvider(const CesiumUtility::IntrusivePointer< const RasterOverlay > &pOwner, const CesiumAsync::AsyncSystem &asyncSystem, const std::shared_ptr< CesiumAsync::IAssetAccessor > &pAssetAccessor, const CesiumGeospatial::Ellipsoid &ellipsoid CESIUM_DEFAULT_ELLIPSOID) noexcept
uint32_t getNumberOfTilesLoading() const noexcept
Returns the number of tiles that are currently loading.
const CesiumGeospatial::Projection & getProjection() const noexcept
Returns the CesiumGeospatial::Projection of this instance.
const std::shared_ptr< IPrepareRasterOverlayRendererResources > & getPrepareRendererResources() const noexcept
Gets the interface used to prepare raster overlay images for rendering.
int64_t getTileDataBytes() const noexcept
Gets the number of bytes of tile data that are currently loaded.
RasterOverlayTileProvider(const CesiumUtility::IntrusivePointer< const RasterOverlay > &pOwner, const CesiumAsync::AsyncSystem &asyncSystem, const std::shared_ptr< CesiumAsync::IAssetAccessor > &pAssetAccessor, std::optional< CesiumUtility::Credit > credit, const std::shared_ptr< IPrepareRasterOverlayRendererResources > &pPrepareRendererResources, const std::shared_ptr< spdlog::logger > &pLogger, const CesiumGeospatial::Projection &projection, const CesiumGeometry::Rectangle &coverageRectangle) noexcept
Creates a new instance.
const std::optional< CesiumUtility::Credit > & getCredit() const noexcept
Get the per-TileProvider Credit if one exists.
const std::shared_ptr< CesiumAsync::IAssetAccessor > & getAssetAccessor() const noexcept
Get the system to use for asychronous requests and threaded work.
Raster image data for a tile in a quadtree.
The base class for a rasterized image that can be draped over a Tileset. The image may be very,...
A reference-counted base class, meant to be used with IntrusivePointer.
std::variant< GeographicProjection, WebMercatorProjection > Projection
A projection.
Definition: Projection.h:25
Classes for raster overlays, which allow draping massive 2D textures over a model.
A 2D rectangle.
Definition: Rectangle.h:14
Options for RasterOverlayTileProvider::loadTileImageFromUrl.
CesiumGeometry::Rectangle rectangle
The rectangle definining the bounds of the image being loaded, expressed in the RasterOverlayTileProv...
std::vector< CesiumUtility::Credit > credits
The credits to display with this tile.
bool moreDetailAvailable
Whether more detailed data, beyond this image, is available within the bounds of this image.
bool allowEmptyImages
Whether empty (zero length) images are accepted as a valid response.
Summarizes the result of loading an image of a RasterOverlay.
Holds a tile and its corresponding tile provider. Used as the return value of RasterOverlayTileProvid...
The container to store the error and warning list when loading a tile or glTF content.
Definition: ErrorList.h:17