cesium-native 0.50.0
Loading...
Searching...
No Matches
RasterOverlayTileProvider.h
1#pragma once
2
3#include <CesiumAsync/IAssetAccessor.h>
4#include <CesiumGeospatial/Projection.h>
5#include <CesiumGltfReader/GltfReader.h>
6#include <CesiumRasterOverlays/Library.h>
7#include <CesiumUtility/Assert.h>
8#include <CesiumUtility/CreditSystem.h>
9#include <CesiumUtility/ErrorList.h>
10#include <CesiumUtility/IntrusivePointer.h>
11#include <CesiumUtility/ReferenceCounted.h>
12#include <CesiumUtility/Tracing.h>
13
14#include <spdlog/fwd.h>
15
16#include <optional>
17
18namespace CesiumRasterOverlays {
19
20class RasterOverlay;
23
27struct CESIUMRASTEROVERLAYS_API LoadedRasterOverlayImage {
35
43
48 std::vector<CesiumUtility::Credit> credits{};
49
57
62 bool moreDetailAvailable = false;
63
67 int64_t getSizeBytes() const {
68 int64_t accum = 0;
69 accum += int64_t(sizeof(LoadedRasterOverlayImage));
70 accum += int64_t(this->credits.capacity() * sizeof(CesiumUtility::Credit));
71 if (this->pImage) {
72 accum += this->pImage->getSizeBytes();
73 }
74 return accum;
75 }
76};
77
87
94 std::vector<CesiumUtility::Credit> credits{};
95
101
119 bool allowEmptyImages = false;
120};
121
123
138
145class CESIUMRASTEROVERLAYS_API RasterOverlayTileProvider
146 : public CesiumUtility::ReferenceCountedNonThreadSafe<
148public:
164 const CesiumAsync::AsyncSystem& asyncSystem,
165 const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
166 const std::shared_ptr<CesiumUtility::CreditSystem>& pCreditSystem,
167 const CesiumGeospatial::Ellipsoid& ellipsoid
168 CESIUM_DEFAULT_ELLIPSOID) noexcept;
169
190 const CesiumAsync::AsyncSystem& asyncSystem,
191 const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
192 const std::shared_ptr<CesiumUtility::CreditSystem>& pCreditSystem,
193 std::optional<CesiumUtility::Credit> credit,
194 const std::shared_ptr<IPrepareRasterOverlayRendererResources>&
195 pPrepareRendererResources,
196 const std::shared_ptr<spdlog::logger>& pLogger,
197 const CesiumGeospatial::Projection& projection,
198 const CesiumGeometry::Rectangle& coverageRectangle) noexcept;
199
201 virtual ~RasterOverlayTileProvider() noexcept;
202
209
229 bool isPlaceholder() const noexcept { return this->_pPlaceholder != nullptr; }
230
234 RasterOverlay& getOwner() noexcept { return *this->_pOwner; }
235
237 const RasterOverlay& getOwner() const noexcept { return *this->_pOwner; }
238
242 const std::shared_ptr<CesiumAsync::IAssetAccessor>&
243 getAssetAccessor() const noexcept {
244 return this->_pAssetAccessor;
245 }
246
250 const std::shared_ptr<CesiumUtility::CreditSystem>&
251 getCreditSystem() const noexcept {
252 return this->_pCreditSystem;
253 }
254
258 const CesiumAsync::AsyncSystem& getAsyncSystem() const noexcept {
259 return this->_asyncSystem;
260 }
261
266 const std::shared_ptr<IPrepareRasterOverlayRendererResources>&
268 return this->_pPrepareRendererResources;
269 }
270
275 const std::shared_ptr<spdlog::logger>& getLogger() const noexcept {
276 return this->_pLogger;
277 }
278
283 return this->_projection;
284 }
285
291 return this->_coverageRectangle;
292 }
293
314 const CesiumGeometry::Rectangle& rectangle,
315 const glm::dvec2& targetScreenPixels);
316
320 int64_t getTileDataBytes() const noexcept { return this->_tileDataBytes; }
321
325 uint32_t getNumberOfTilesLoading() const noexcept {
326 CESIUM_ASSERT(this->_totalTilesCurrentlyLoading > -1);
327 return static_cast<uint32_t>(this->_totalTilesCurrentlyLoading);
328 }
329
341
345 const std::optional<CesiumUtility::Credit>& getCredit() const noexcept {
346 return _credit;
347 }
348
366
389
390protected:
399
411 const std::string& url,
412 const std::vector<CesiumAsync::IAssetAccessor::THeader>& headers = {},
413 LoadTileImageFromUrlOptions&& options = {}) const;
414
415private:
417 doLoad(RasterOverlayTile& tile, bool isThrottledLoad);
418
426 void beginTileLoad(bool isThrottledLoad) noexcept;
427
436 void finalizeTileLoad(bool isThrottledLoad) noexcept;
437
438private:
439 struct DestructionCompleteDetails {
442 };
443
444 CesiumUtility::IntrusivePointer<RasterOverlay> _pOwner;
445 CesiumAsync::AsyncSystem _asyncSystem;
446 std::shared_ptr<CesiumAsync::IAssetAccessor> _pAssetAccessor;
447 std::shared_ptr<CesiumUtility::CreditSystem> _pCreditSystem;
448 std::optional<CesiumUtility::Credit> _credit;
449 std::shared_ptr<IPrepareRasterOverlayRendererResources>
450 _pPrepareRendererResources;
451 std::shared_ptr<spdlog::logger> _pLogger;
453 CesiumGeometry::Rectangle _coverageRectangle;
454 CesiumUtility::IntrusivePointer<RasterOverlayTile> _pPlaceholder;
455 int64_t _tileDataBytes;
456 int32_t _totalTilesCurrentlyLoading;
457 int32_t _throttledTilesCurrentlyLoading;
458 std::optional<DestructionCompleteDetails> _destructionCompleteDetails;
459 CESIUM_TRACE_DECLARE_TRACK_SET(
460 _loadingSlots,
461 "Raster Overlay Tile Loading Slot")
462};
463} // 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 promise that can be resolved or rejected by an asynchronous task.
Definition Promise.h:19
A value that will be available in the future, as produced by AsyncSystem. Unlike Future,...
A quadratic surface defined in Cartesian coordinates.
Definition Ellipsoid.h:39
An interface between Cesium Native and the application using it, allowing Cesium Native to pass loade...
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.
const std::optional< CesiumUtility::Credit > & getCredit() const noexcept
Get the per-TileProvider CesiumUtility::Credit if one exists.
CesiumUtility::IntrusivePointer< RasterOverlayTile > getTile(const CesiumGeometry::Rectangle &rectangle, const glm::dvec2 &targetScreenPixels)
Returns a new RasterOverlayTile with the given specifications.
bool loadTileThrottled(RasterOverlayTile &tile)
Loads a tile, unless there are too many tile loads already in progress.
const RasterOverlay & getOwner() const noexcept
Returns the RasterOverlay that created this instance.
RasterOverlay & getOwner() noexcept
Returns the RasterOverlay that created this instance.
CesiumAsync::Future< TileProviderAndTile > loadTile(RasterOverlayTile &tile)
Loads a tile immediately, without throttling requests.
CesiumAsync::SharedFuture< void > & getAsyncDestructionCompleteEvent()
A future that resolves when this RasterOverlayTileProvider has been destroyed (i.e....
virtual CesiumAsync::Future< LoadedRasterOverlayImage > loadTileImage(RasterOverlayTile &overlayTile)=0
Loads the image for a tile.
const std::shared_ptr< IPrepareRasterOverlayRendererResources > & getPrepareRendererResources() const noexcept
Gets the interface used to prepare raster overlay images for rendering.
virtual ~RasterOverlayTileProvider() noexcept
Default destructor.
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.
uint32_t getNumberOfTilesLoading() const noexcept
Returns the number of tiles that are currently loading.
const CesiumGeometry::Rectangle & getCoverageRectangle() const noexcept
Returns the coverage CesiumGeometry::Rectangle of this instance.
const std::shared_ptr< spdlog::logger > & getLogger() const noexcept
Gets the logger to which to send messages about the tile provider and tiles.
RasterOverlayTileProvider(const CesiumUtility::IntrusivePointer< const RasterOverlay > &pOwner, const CesiumAsync::AsyncSystem &asyncSystem, const std::shared_ptr< CesiumAsync::IAssetAccessor > &pAssetAccessor, const std::shared_ptr< CesiumUtility::CreditSystem > &pCreditSystem, 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 CesiumGeospatial::Projection & getProjection() const noexcept
Returns the CesiumGeospatial::Projection of this instance.
const CesiumAsync::AsyncSystem & getAsyncSystem() const noexcept
Gets the async system used to do work in threads.
RasterOverlayTileProvider(const CesiumUtility::IntrusivePointer< const RasterOverlay > &pOwner, const CesiumAsync::AsyncSystem &asyncSystem, const std::shared_ptr< CesiumAsync::IAssetAccessor > &pAssetAccessor, const std::shared_ptr< CesiumUtility::CreditSystem > &pCreditSystem, const CesiumGeospatial::Ellipsoid &ellipsoid=CesiumGeospatial::Ellipsoid::WGS84) noexcept
int64_t getTileDataBytes() const noexcept
Gets the number of bytes of tile data that are currently loaded.
bool isPlaceholder() const noexcept
Returns whether this is a placeholder.
const std::shared_ptr< CesiumUtility::CreditSystem > & getCreditSystem() const noexcept
Get the credit system that receives credits from this tile provider.
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 Cesium3DTilesSelection::Tileset....
A smart pointer that calls addReference and releaseReference on the controlled object.
Classes that support asynchronous operations.
std::variant< GeographicProjection, WebMercatorProjection > Projection
A projection.
Definition Projection.h:25
Classes for raster overlays, which allow draping massive 2D textures over a model.
Utility classes for Cesium.
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.
int64_t getSizeBytes() const
Returns the size of this LoadedRasterOverlayImage in bytes.
CesiumUtility::ErrorList errorList
Errors and warnings from loading the image.
std::vector< CesiumUtility::Credit > credits
The CesiumUtility::Credit objects that decribe the attributions that are required when using the imag...
CesiumGeometry::Rectangle rectangle
The projected rectangle defining the bounds of this image.
bool moreDetailAvailable
Whether more detailed data, beyond this image, is available within the bounds of this image.
CesiumUtility::IntrusivePointer< CesiumGltf::ImageAsset > pImage
The loaded image.
Holds a tile and its corresponding tile provider. Used as the return value of RasterOverlayTileProvid...
CesiumUtility::IntrusivePointer< RasterOverlayTile > pTile
A CesiumUtility::IntrusivePointer to the RasterOverlayTile used for this tile.
CesiumUtility::IntrusivePointer< RasterOverlayTileProvider > pTileProvider
A CesiumUtility::IntrusivePointer to the RasterOverlayTileProvider used for this tile.
Represents an HTML string that should be shown on screen to attribute third parties for used data,...
The container to store the error and warning list when loading a tile or glTF content.
Definition ErrorList.h:18