初始提交: UE5.3项目基础框架

This commit is contained in:
2025-10-14 11:14:54 +08:00
commit 721d9fd98e
5334 changed files with 316782 additions and 0 deletions

View File

@ -0,0 +1,129 @@
#pragma once
#include "Library.h"
#include "RasterOverlay.h"
#include <CesiumAsync/IAssetRequest.h>
#include <CesiumGeospatial/Ellipsoid.h>
#include <functional>
#include <memory>
namespace CesiumRasterOverlays {
/**
* @brief Styles of Bing Maps overlays.
*
* Constants that can be passed to a {@link BingMapsRasterOverlay} to
* indicate the overlays that should be painted.
*/
struct BingMapsStyle final {
/**
* @brief Aerial imagery.
*/
static const std::string AERIAL;
/**
* @brief Aerial imagery with a road overlay.
* @deprecated See https://github.com/CesiumGS/cesium/issues/7128.
* Use `BingMapsStyle.AERIAL_WITH_LABELS_ON_DEMAND` instead
*/
static const std::string AERIAL_WITH_LABELS;
/**
* @brief Aerial imagery with a road overlay.
*/
static const std::string AERIAL_WITH_LABELS_ON_DEMAND;
/**
* @brief Roads without additional imagery.
* @deprecated See https://github.com/CesiumGS/cesium/issues/7128.
* Use `BingMapsStyle.ROAD_ON_DEMAND` instead
*/
static const std::string ROAD;
/**
* @brief Roads without additional imagery.
*/
static const std::string ROAD_ON_DEMAND;
/**
* @brief A dark version of the road maps.
*/
static const std::string CANVAS_DARK;
/**
* @brief A lighter version of the road maps.
*/
static const std::string CANVAS_LIGHT;
/**
* @brief A grayscale version of the road maps.
*/
static const std::string CANVAS_GRAY;
/**
* @brief Ordnance Survey imagery.
*
* This imagery is visible only for the London, UK area.
*/
static const std::string ORDNANCE_SURVEY;
/**
* @brief Collins Bart imagery.
*/
static const std::string COLLINS_BART;
};
/**
* @brief A {@link RasterOverlay} that uses Bing Maps as the source for the
* imagery data.
*/
class CESIUMRASTEROVERLAYS_API BingMapsRasterOverlay final
: public RasterOverlay {
public:
/**
* @brief Creates a new instance.
*
* @param name The user-given name of this overlay layer.
* @param url The url of the Bing Maps server hosting the imagery.
* @param key The Bing Maps key for your application, which can be created at
* https://www.bingmapsportal.com/.
* @param mapStyle The type of Bing Maps imagery to load. A value from
* {@link BingMapsStyle}, with {@link BingMapsStyle::AERIAL} being the
* default.
* @param culture The culture to use when requesting Bing Maps imagery. Not
* all cultures are supported. See
* http://msdn.microsoft.com/en-us/library/hh441729.aspx for information on
* the supported cultures.
* @param overlayOptions The {@link RasterOverlayOptions} for this instance.
*/
BingMapsRasterOverlay(
const std::string& name,
const std::string& url,
const std::string& key,
const std::string& mapStyle = BingMapsStyle::AERIAL,
const std::string& culture = "",
const RasterOverlayOptions& overlayOptions = {});
virtual ~BingMapsRasterOverlay() override;
virtual CesiumAsync::Future<CreateTileProviderResult> createTileProvider(
const CesiumAsync::AsyncSystem& asyncSystem,
const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
const std::shared_ptr<CesiumUtility::CreditSystem>& pCreditSystem,
const std::shared_ptr<IPrepareRasterOverlayRendererResources>&
pPrepareRendererResources,
const std::shared_ptr<spdlog::logger>& pLogger,
CesiumUtility::IntrusivePointer<const RasterOverlay> pOwner)
const override;
private:
static const std::string BING_LOGO_HTML;
std::string _url;
std::string _key;
std::string _mapStyle;
std::string _culture;
};
} // namespace CesiumRasterOverlays

View File

@ -0,0 +1,37 @@
#pragma once
#include "CesiumGeospatial/Ellipsoid.h"
#include "RasterOverlay.h"
namespace CesiumRasterOverlays {
/**
* @brief A raster overlay that gives each tile to which it is attached a random
* color with 50% opacity. This is useful for debugging a tileset, to visualize
* how it is divided into tiles.
*/
class CESIUMRASTEROVERLAYS_API DebugColorizeTilesRasterOverlay
: public RasterOverlay {
public:
/**
* @copydoc RasterOverlay::RasterOverlay
*/
DebugColorizeTilesRasterOverlay(
const std::string& name,
const RasterOverlayOptions& overlayOptions = RasterOverlayOptions());
/**
* @copydoc RasterOverlay::createTileProvider
*/
virtual CesiumAsync::Future<CreateTileProviderResult> createTileProvider(
const CesiumAsync::AsyncSystem& asyncSystem,
const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
const std::shared_ptr<CesiumUtility::CreditSystem>& pCreditSystem,
const std::shared_ptr<IPrepareRasterOverlayRendererResources>&
pPrepareRendererResources,
const std::shared_ptr<spdlog::logger>& pLogger,
CesiumUtility::IntrusivePointer<const RasterOverlay> pOwner)
const override;
};
} // namespace CesiumRasterOverlays

View File

@ -0,0 +1,83 @@
#pragma once
#include "Library.h"
#include <any>
namespace CesiumGltf {
struct ImageAsset;
}
namespace CesiumRasterOverlays {
class RasterOverlayTile;
}
namespace CesiumRasterOverlays {
/**
* @brief An interface between Cesium Native and the application using it,
* allowing Cesium Native to pass loaded raster overlay data to the implementing
* application in order for the application to prepare it to be used in its
* renderer of choice. This could involve creating a texture asset, uploading
* the texture data to the GPU, or any other similar tasks required.
*/
class CESIUMRASTEROVERLAYS_API IPrepareRasterOverlayRendererResources {
public:
/**
* @brief Prepares a raster overlay tile.
*
* This method is invoked in the load thread and may modify the image.
*
* @param image The raster tile image to prepare.
* @param rendererOptions Renderer options associated with the raster overlay tile from {@link RasterOverlayOptions::rendererOptions}.
* @returns Arbitrary data representing the result of the load process. This
* data is passed to {@link prepareRasterInMainThread} as the
* `pLoadThreadResult` parameter.
*/
virtual void* prepareRasterInLoadThread(
CesiumGltf::ImageAsset& image,
const std::any& rendererOptions) = 0;
/**
* @brief Further preprares a raster overlay tile.
*
* This is called after {@link prepareRasterInLoadThread}, and unlike that
* method, this one is called from the same thread that called
* {@link Cesium3DTilesSelection::Tileset::updateView}.
*
* @param rasterTile The raster tile to prepare.
* @param pLoadThreadResult The value returned from
* {@link prepareRasterInLoadThread}.
* @returns Arbitrary data representing the result of the load process. Note
* that the value returned by {@link prepareRasterInLoadThread} will _not_ be
* automatically preserved and passed to {@link freeRaster}. If you need to free
* that value, do it in this method before returning. If you need that value
* later, add it to the object returned from this method.
*/
virtual void* prepareRasterInMainThread(
RasterOverlayTile& rasterTile,
void* pLoadThreadResult) = 0;
/**
* @brief Frees previously-prepared renderer resources for a raster tile.
*
* This method is always called from the thread that destroyed the
* {@link RasterOverlayTile}. When raster overlays are used with tilesets,
* this is the thread that called {@link Cesium3DTilesSelection::Tileset::updateView} or deleted the
* tileset.
*
* @param rasterTile The tile for which to free renderer resources.
* @param pLoadThreadResult The result returned by
* {@link prepareRasterInLoadThread}. If {@link prepareRasterInMainThread}
* has already been called, this parameter will be `nullptr`.
* @param pMainThreadResult The result returned by
* {@link prepareRasterInMainThread}. If {@link prepareRasterInMainThread}
* has not yet been called, this parameter will be `nullptr`.
*/
virtual void freeRaster(
const RasterOverlayTile& rasterTile,
void* pLoadThreadResult,
void* pMainThreadResult) noexcept = 0;
};
} // namespace CesiumRasterOverlays

View File

@ -0,0 +1,84 @@
#pragma once
#include "Library.h"
#include "RasterOverlay.h"
#include <CesiumAsync/IAssetRequest.h>
#include <CesiumGeospatial/Ellipsoid.h>
#include <functional>
#include <memory>
namespace CesiumRasterOverlays {
/**
* @brief A {@link RasterOverlay} that obtains imagery data from Cesium ion.
*/
class CESIUMRASTEROVERLAYS_API IonRasterOverlay final : public RasterOverlay {
public:
/**
* @brief Creates a new instance.
*
* The tiles that are provided by this instance will contain
* imagery data that was obtained from the Cesium ion asset
* with the given ID, accessed with the given access token.
*
* @param name The user-given name of this overlay layer.
* @param ionAssetID The asset ID.
* @param ionAccessToken The access token.
* @param overlayOptions The {@link RasterOverlayOptions} for this instance.
* @param ionAssetEndpointUrl The URL of the ion endpoint to make our requests
* to.
*/
IonRasterOverlay(
const std::string& name,
int64_t ionAssetID,
const std::string& ionAccessToken,
const RasterOverlayOptions& overlayOptions = {},
const std::string& ionAssetEndpointUrl = "https://api.cesium.com/");
virtual ~IonRasterOverlay() override;
virtual CesiumAsync::Future<CreateTileProviderResult> createTileProvider(
const CesiumAsync::AsyncSystem& asyncSystem,
const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
const std::shared_ptr<CesiumUtility::CreditSystem>& pCreditSystem,
const std::shared_ptr<IPrepareRasterOverlayRendererResources>&
pPrepareRendererResources,
const std::shared_ptr<spdlog::logger>& pLogger,
CesiumUtility::IntrusivePointer<const RasterOverlay> pOwner)
const override;
private:
int64_t _ionAssetID;
std::string _ionAccessToken;
std::string _ionAssetEndpointUrl;
struct AssetEndpointAttribution {
std::string html;
bool collapsible = true;
};
struct ExternalAssetEndpoint {
std::string externalType;
std::string url;
std::string mapStyle;
std::string key;
std::string culture;
std::string accessToken;
std::vector<AssetEndpointAttribution> attributions;
};
static std::unordered_map<std::string, ExternalAssetEndpoint> endpointCache;
CesiumAsync::Future<CreateTileProviderResult> createTileProvider(
const ExternalAssetEndpoint& endpoint,
const CesiumAsync::AsyncSystem& asyncSystem,
const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
const std::shared_ptr<CesiumUtility::CreditSystem>& pCreditSystem,
const std::shared_ptr<IPrepareRasterOverlayRendererResources>&
pPrepareRendererResources,
const std::shared_ptr<spdlog::logger>& pLogger,
CesiumUtility::IntrusivePointer<const RasterOverlay> pOwner) const;
};
} // namespace CesiumRasterOverlays

View File

@ -0,0 +1,19 @@
#pragma once
/**
* @brief Classes for raster overlays, which allow draping massive 2D textures
* over a model.
*
* @mermaid-interactive{dependencies/CesiumRasterOverlays}
*/
namespace CesiumRasterOverlays {}
#if defined(_WIN32) && defined(CESIUM_SHARED)
#ifdef CESIUMRASTEROVERLAYS_BUILDING
#define CESIUMRASTEROVERLAYS_API __declspec(dllexport)
#else
#define CESIUMRASTEROVERLAYS_API __declspec(dllimport)
#endif
#else
#define CESIUMRASTEROVERLAYS_API
#endif

View File

@ -0,0 +1,195 @@
#pragma once
#include "IPrepareRasterOverlayRendererResources.h"
#include "Library.h"
#include "RasterOverlayTileProvider.h"
#include <CesiumAsync/AsyncSystem.h>
#include <CesiumAsync/IAssetAccessor.h>
#include <CesiumAsync/SharedAssetDepot.h>
#include <CesiumGeometry/QuadtreeTileID.h>
#include <CesiumGeometry/QuadtreeTilingScheme.h>
#include <CesiumUtility/CreditSystem.h>
#include <CesiumUtility/Result.h>
#include <CesiumUtility/SharedAsset.h>
#include <list>
#include <memory>
#include <optional>
namespace CesiumRasterOverlays {
/**
* @brief A base class used for raster overlay providers that use a
* quadtree-based tiling scheme. This includes \ref TileMapServiceRasterOverlay,
* \ref BingMapsRasterOverlay, and \ref WebMapServiceRasterOverlay.
*
* To implement a new raster overlay provider based on
* QuadtreeRasterOverlayTileProvider, use this as the base class and override
* \ref QuadtreeRasterOverlayTileProvider::loadQuadtreeTileImage
* "loadQuadtreeTileImage" with code that makes requests to your service.
*/
class CESIUMRASTEROVERLAYS_API QuadtreeRasterOverlayTileProvider
: public RasterOverlayTileProvider {
public:
/**
* @brief Creates a new instance.
*
* @param pOwner The raster overlay that created this tile provider.
* @param asyncSystem The async system used to do work in threads.
* @param pAssetAccessor The interface used to obtain assets (tiles, etc.) for
* this raster overlay.
* @param credit The {@link CesiumUtility::Credit} for this tile provider, if it exists.
* @param pPrepareRendererResources The interface used to prepare raster
* images for rendering.
* @param pLogger The logger to which to send messages about the tile provider
* and tiles.
* @param projection The {@link CesiumGeospatial::Projection}.
* @param tilingScheme The tiling scheme to be used by this {@link QuadtreeRasterOverlayTileProvider}.
* @param coverageRectangle The {@link CesiumGeometry::Rectangle}.
* @param minimumLevel The minimum quadtree tile level.
* @param maximumLevel The maximum quadtree tile level.
* @param imageWidth The image width.
* @param imageHeight The image height.
*/
QuadtreeRasterOverlayTileProvider(
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::QuadtreeTilingScheme& tilingScheme,
const CesiumGeometry::Rectangle& coverageRectangle,
uint32_t minimumLevel,
uint32_t maximumLevel,
uint32_t imageWidth,
uint32_t imageHeight) noexcept;
/**
* @brief Returns the minimum tile level of this instance.
*/
uint32_t getMinimumLevel() const noexcept { return this->_minimumLevel; }
/**
* @brief Returns the maximum tile level of this instance.
*/
uint32_t getMaximumLevel() const noexcept { return this->_maximumLevel; }
/**
* @brief Returns the image width of this instance, in pixels.
*/
uint32_t getWidth() const noexcept { return this->_imageWidth; }
/**
* @brief Returns the image height of this instance, in pixels.
*/
uint32_t getHeight() const noexcept { return this->_imageHeight; }
/**
* @brief Returns the {@link CesiumGeometry::QuadtreeTilingScheme} of this
* instance.
*/
const CesiumGeometry::QuadtreeTilingScheme& getTilingScheme() const noexcept {
return this->_tilingScheme;
}
/**
* @brief Computes the best quadtree level to use for an image intended to
* cover a given projected rectangle when it is a given size on the screen.
*
* @param rectangle The range of projected coordinates to cover.
* @param screenPixels The number of screen pixels to be covered by the
* rectangle.
* @return The level.
*/
uint32_t computeLevelFromTargetScreenPixels(
const CesiumGeometry::Rectangle& rectangle,
const glm::dvec2& screenPixels);
protected:
/**
* @brief Asynchronously loads a tile in the quadtree.
*
* @param tileID The ID of the quadtree tile to load.
* @return A Future that resolves to the loaded image data or error
* information.
*/
virtual CesiumAsync::Future<LoadedRasterOverlayImage>
loadQuadtreeTileImage(const CesiumGeometry::QuadtreeTileID& tileID) const = 0;
private:
virtual CesiumAsync::Future<LoadedRasterOverlayImage>
loadTileImage(RasterOverlayTile& overlayTile) override final;
struct LoadedQuadtreeImage
: public CesiumUtility::SharedAsset<LoadedQuadtreeImage> {
LoadedQuadtreeImage(
const std::shared_ptr<LoadedRasterOverlayImage>& pLoaded_,
const std::optional<CesiumGeometry::Rectangle>& subset_)
: pLoaded(pLoaded_), subset(subset_) {}
std::shared_ptr<LoadedRasterOverlayImage> pLoaded = nullptr;
std::optional<CesiumGeometry::Rectangle> subset = std::nullopt;
int64_t getSizeBytes() const {
int64_t accum = 0;
accum += int64_t(sizeof(LoadedQuadtreeImage));
if (pLoaded) {
accum += pLoaded->getSizeBytes();
}
return accum;
}
};
CesiumAsync::SharedFuture<CesiumUtility::ResultPointer<LoadedQuadtreeImage>>
getQuadtreeTile(const CesiumGeometry::QuadtreeTileID& tileID);
/**
* @brief Map raster tiles to geometry tile.
*
* @param geometryRectangle The rectangle for which to load tiles.
* @param targetGeometricError The geometric error controlling which quadtree
* level to use to cover the rectangle.
* @return A vector of shared futures, each of which will resolve to image
* data that is required to cover the rectangle with the given geometric
* error.
*/
std::vector<CesiumAsync::SharedFuture<
CesiumUtility::ResultPointer<LoadedQuadtreeImage>>>
mapRasterTilesToGeometryTile(
const CesiumGeometry::Rectangle& geometryRectangle,
const glm::dvec2 targetScreenPixels);
struct CombinedImageMeasurements {
CesiumGeometry::Rectangle rectangle;
int32_t widthPixels;
int32_t heightPixels;
int32_t channels;
int32_t bytesPerChannel;
};
static CombinedImageMeasurements measureCombinedImage(
const CesiumGeometry::Rectangle& targetRectangle,
const std::vector<CesiumUtility::ResultPointer<LoadedQuadtreeImage>>&
images);
static LoadedRasterOverlayImage combineImages(
const CesiumGeometry::Rectangle& targetRectangle,
const CesiumGeospatial::Projection& projection,
std::vector<CesiumUtility::ResultPointer<LoadedQuadtreeImage>>&& images);
uint32_t _minimumLevel;
uint32_t _maximumLevel;
uint32_t _imageWidth;
uint32_t _imageHeight;
CesiumGeometry::QuadtreeTilingScheme _tilingScheme;
CesiumUtility::IntrusivePointer<CesiumAsync::SharedAssetDepot<
LoadedQuadtreeImage,
CesiumGeometry::QuadtreeTileID>>
_pTileDepot;
};
} // namespace CesiumRasterOverlays

View File

@ -0,0 +1,256 @@
#pragma once
#include "Library.h"
#include "RasterOverlayLoadFailureDetails.h"
#include <CesiumAsync/AsyncSystem.h>
#include <CesiumAsync/IAssetAccessor.h>
#include <CesiumGeospatial/Ellipsoid.h>
#include <CesiumGltf/Ktx2TranscodeTargets.h>
#include <CesiumUtility/IntrusivePointer.h>
#include <CesiumUtility/ReferenceCounted.h>
#include <nonstd/expected.hpp>
#include <spdlog/fwd.h>
#include <any>
#include <functional>
#include <memory>
#include <optional>
#include <string>
namespace CesiumUtility {
struct Credit;
class CreditSystem;
} // namespace CesiumUtility
namespace CesiumRasterOverlays {
class IPrepareRasterOverlayRendererResources;
class RasterOverlayTileProvider;
/**
* @brief Options for loading raster overlays.
*/
struct CESIUMRASTEROVERLAYS_API RasterOverlayOptions {
/**
* @brief The maximum number of overlay tiles that may simultaneously be in
* the process of loading.
*/
int32_t maximumSimultaneousTileLoads = 20;
/**
* @brief The maximum number of bytes to use to cache sub-tiles in memory.
*
* This is used by provider types, such as
* {@link QuadtreeRasterOverlayTileProvider}, that have an underlying tiling
* scheme that may not align with the tiling scheme of the geometry tiles on
* which the raster overlay tiles are draped. Because a single sub-tile may
* overlap multiple geometry tiles, it is useful to cache loaded sub-tiles
* in memory in case they're needed again soon. This property controls the
* maximum size of that cache.
*/
int64_t subTileCacheBytes = 16 * 1024 * 1024;
/**
* @brief The maximum pixel size of raster overlay textures, in either
* direction.
*
* Images created by this overlay will be no more than this number of pixels
* in either direction. This may result in reduced raster overlay detail in
* some cases. For example, in a {@link QuadtreeRasterOverlayTileProvider},
* this property will limit the number of quadtree tiles that may be mapped to
* a given geometry tile. The selected quadtree level for a geometry tile is
* reduced in order to stay under this limit.
*/
int32_t maximumTextureSize = 2048;
/**
* @brief The maximum number of pixels of error when rendering this overlay.
* This is used to select an appropriate level-of-detail.
*
* When this property has its default value, 2.0, it means that raster overlay
* images will be sized so that, when zoomed in closest, a single pixel in
* the raster overlay maps to approximately 2x2 pixels on the screen.
*/
double maximumScreenSpaceError = 2.0;
/**
* @brief For each possible input transmission format, this struct names
* the ideal target gpu-compressed pixel format to transcode to.
*/
CesiumGltf::Ktx2TranscodeTargets ktx2TranscodeTargets;
/**
* @brief A callback function that is invoked when a raster overlay resource
* fails to load.
*
* Raster overlay resources include a Cesium ion asset endpoint or any
* resources required for raster overlay metadata.
*
* This callback is invoked by the {@link Cesium3DTilesSelection::RasterOverlayCollection} when an
* error occurs while it is creating a tile provider for this RasterOverlay.
* It is always invoked in the main thread.
*/
std::function<void(const RasterOverlayLoadFailureDetails&)> loadErrorCallback;
/**
* @brief Whether or not to display the credits on screen.
*/
bool showCreditsOnScreen = false;
/**
* @brief Arbitrary data that will be passed to {@link Cesium3DTilesSelection::IPrepareRendererResources::prepareRasterInLoadThread},
* for example, data to control the per-raster overlay client-specific texture
* properties.
*
* This object is copied and given to background texture preparation threads,
* so it must be inexpensive to copy.
*/
std::any rendererOptions;
/**
* @brief The ellipsoid used for this raster overlay.
*/
CesiumGeospatial::Ellipsoid ellipsoid = CesiumGeospatial::Ellipsoid::WGS84;
};
/**
* @brief The base class for a rasterized image that can be draped
* over a {@link Cesium3DTilesSelection::Tileset}. The image may be very, very high resolution, so only
* small pieces of it are mapped to the Tileset at a time.
*
* Instances of this class can be added to the {@link Cesium3DTilesSelection::RasterOverlayCollection}
* that is returned by {@link Cesium3DTilesSelection::Tileset::getOverlays}.
*
* Instances of this class must be allocated on the heap, and their lifetimes
* must be managed with {@link CesiumUtility::IntrusivePointer}.
*
* @see BingMapsRasterOverlay
* @see IonRasterOverlay
* @see TileMapServiceRasterOverlay
* @see WebMapServiceRasterOverlay
*/
class RasterOverlay
: public CesiumUtility::ReferenceCountedNonThreadSafe<RasterOverlay> {
public:
/**
* @brief Creates a new instance.
*
* @param name The user-given name of this overlay layer.
* @param overlayOptions The {@link RasterOverlayOptions} for this instance.
*/
RasterOverlay(
const std::string& name,
const RasterOverlayOptions& overlayOptions = RasterOverlayOptions());
virtual ~RasterOverlay() noexcept;
/**
* @brief A future that resolves when this RasterOverlay has been destroyed
* (i.e. its destructor has been called) and all async operations that it was
* executing have completed.
*
* @param asyncSystem The AsyncSystem to use for the returned SharedFuture,
* if required. If this method is called multiple times, all invocations
* must pass {@link CesiumAsync::AsyncSystem} instances that compare equal to each other.
*/
CesiumAsync::SharedFuture<void>&
getAsyncDestructionCompleteEvent(const CesiumAsync::AsyncSystem& asyncSystem);
/**
* @brief Gets the name of this overlay.
*/
const std::string& getName() const noexcept { return this->_name; }
/**
* @brief Gets options for this overlay.
*/
RasterOverlayOptions& getOptions() noexcept { return this->_options; }
/** @copydoc getOptions */
const RasterOverlayOptions& getOptions() const noexcept {
return this->_options;
}
/**
* @brief Gets the credits for this overlay.
*/
const std::vector<CesiumUtility::Credit>& getCredits() const noexcept {
return this->_credits;
}
/**
* @brief Gets the credits for this overlay.
*/
std::vector<CesiumUtility::Credit>& getCredits() noexcept {
return this->_credits;
}
/**
* @brief Create a placeholder tile provider can be used in place of the real
* one while {@link createTileProvider} completes asynchronously.
*
* @param asyncSystem The async system used to do work in threads.
* @param pAssetAccessor The interface used to download assets like overlay
* metadata and tiles.
* @param ellipsoid The {@link CesiumGeospatial::Ellipsoid}.
* @return The placeholder.
*/
CesiumUtility::IntrusivePointer<RasterOverlayTileProvider> createPlaceholder(
const CesiumAsync::AsyncSystem& asyncSystem,
const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
const CesiumGeospatial::Ellipsoid& ellipsoid
CESIUM_DEFAULT_ELLIPSOID) const;
/**
* @brief A result from a call to \ref createTileProvider. This is expected to
* be an \ref CesiumUtility::IntrusivePointer "IntrusivePointer" to a \ref
* RasterOverlayTileProvider, but may be a \ref
* RasterOverlayLoadFailureDetails if creating the tile provider wasn't
* successful.
*/
using CreateTileProviderResult = nonstd::expected<
CesiumUtility::IntrusivePointer<RasterOverlayTileProvider>,
RasterOverlayLoadFailureDetails>;
/**
* @brief Begins asynchronous creation of a tile provider for this overlay
* and eventually returns it via a Future.
*
* @param asyncSystem The async system used to do work in threads.
* @param pAssetAccessor The interface used to download assets like overlay
* metadata and tiles.
* @param pCreditSystem The {@link CesiumUtility::CreditSystem} to use when creating a
* per-TileProvider {@link CesiumUtility::Credit}.
* @param pPrepareRendererResources The interface used to prepare raster
* images for rendering.
* @param pLogger The logger to which to send messages about the tile provider
* and tiles.
* @param pOwner The overlay that owns this overlay, or nullptr if this
* overlay is not aggregated.
* @return The future that resolves to the tile provider when it is ready, or
* to error details in the case of an error.
*/
virtual CesiumAsync::Future<CreateTileProviderResult> createTileProvider(
const CesiumAsync::AsyncSystem& asyncSystem,
const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
const std::shared_ptr<CesiumUtility::CreditSystem>& pCreditSystem,
const std::shared_ptr<IPrepareRasterOverlayRendererResources>&
pPrepareRendererResources,
const std::shared_ptr<spdlog::logger>& pLogger,
CesiumUtility::IntrusivePointer<const RasterOverlay> pOwner) const = 0;
private:
struct DestructionCompleteDetails {
CesiumAsync::AsyncSystem asyncSystem;
CesiumAsync::Promise<void> promise;
CesiumAsync::SharedFuture<void> future;
};
std::string _name;
RasterOverlayOptions _options;
std::vector<CesiumUtility::Credit> _credits;
std::optional<DestructionCompleteDetails> _destructionCompleteDetails;
};
} // namespace CesiumRasterOverlays

View File

@ -0,0 +1,82 @@
#pragma once
#include "Library.h"
#include <CesiumGeometry/Rectangle.h>
#include <CesiumGeospatial/BoundingRegion.h>
#include <CesiumGeospatial/Projection.h>
#include <vector>
namespace CesiumRasterOverlays {
/**
* @brief Holds details of the {@link Cesium3DTilesSelection::TileRenderContent} that are useful
* for raster overlays.
*/
struct CESIUMRASTEROVERLAYS_API RasterOverlayDetails {
/**
* @brief Construct an empty RasterOverlayDetails.
*/
RasterOverlayDetails();
/**
* @brief Construct a RasterOverlayDetails with given projections, the
* rectangles generated by the projections, and the bounding region covered
* those rectangles.
*
* @param rasterOverlayProjections The raster overlay projections for which
* texture coordinates have been generated.
* @param rasterOverlayRectangles The rectangle covered by this tile in each
* of the {@link rasterOverlayProjections}.
* @param boundingRegion The precise bounding region of this tile.
*/
RasterOverlayDetails(
std::vector<CesiumGeospatial::Projection>&& rasterOverlayProjections,
std::vector<CesiumGeometry::Rectangle>&& rasterOverlayRectangles,
const CesiumGeospatial::BoundingRegion& boundingRegion);
/**
* @brief Finds the rectangle corresponding to a given projection in
* {@link rasterOverlayProjections}.
*
* @param projection The projection.
* @return The tile's rectangle in the given projection, or nullptr if the
* projection is not in {@link rasterOverlayProjections}.
*/
const CesiumGeometry::Rectangle* findRectangleForOverlayProjection(
const CesiumGeospatial::Projection& projection) const;
/**
* @brief Merge the other RasterOverlayDetails's projections, rectangles, and
* bounding region together.
*
* @param other The other instance of RasterOverlayDetails that will be merged
* with this.
* @param ellipsoid The {@link CesiumGeospatial::Ellipsoid}.
*/
void merge(
const RasterOverlayDetails& other,
const CesiumGeospatial::Ellipsoid& ellipsoid CESIUM_DEFAULT_ELLIPSOID);
/**
* @brief The raster overlay projections for which texture coordinates have
* been generated.
*
* For the projection at index `n`, there is a set of texture coordinates
* with the attribute name `_CESIUMOVERLAY_n` that corresponds to that
* projection.
*/
std::vector<CesiumGeospatial::Projection> rasterOverlayProjections;
/**
* @brief The rectangle covered by this tile in each of the
* {@link rasterOverlayProjections}.
*/
std::vector<CesiumGeometry::Rectangle> rasterOverlayRectangles;
/**
* @brief The precise bounding region of this tile.
*/
CesiumGeospatial::BoundingRegion boundingRegion;
};
} // namespace CesiumRasterOverlays

View File

@ -0,0 +1,58 @@
#pragma once
#include <CesiumUtility/IntrusivePointer.h>
#include <memory>
#include <string>
namespace CesiumAsync {
class IAssetRequest;
}
namespace CesiumRasterOverlays {
class RasterOverlay;
/**
* @brief The type of load that failed in `RasterOverlayLoadFailureDetails`.
*/
enum class RasterOverlayLoadType {
/**
* @brief An unknown load error.
*/
Unknown,
/**
* @brief A Cesium ion asset endpoint.
*/
CesiumIon,
/**
* @brief An initial load needed to create the overlay's tile provider.
*/
TileProvider
};
/**
* @brief Details on a failure while attempting to load a raster overlay tile.
*/
class RasterOverlayLoadFailureDetails {
public:
/**
* @brief The type of request that failed to load.
*/
RasterOverlayLoadType type = RasterOverlayLoadType::Unknown;
/**
* @brief The request that failed. The request itself may have succeeded, but
* the failure occurred while processing this request.
*/
std::shared_ptr<CesiumAsync::IAssetRequest> pRequest = nullptr;
/**
* @brief A human-readable explanation of what failed.
*/
std::string message = "";
};
} // namespace CesiumRasterOverlays

View File

@ -0,0 +1,267 @@
#pragma once
#include <CesiumAsync/AsyncSystem.h>
#include <CesiumAsync/IAssetRequest.h>
#include <CesiumGeometry/Rectangle.h>
#include <CesiumGltf/Model.h>
#include <CesiumUtility/IntrusivePointer.h>
#include <CesiumUtility/ReferenceCounted.h>
#include <vector>
namespace CesiumUtility {
struct Credit;
}
namespace CesiumRasterOverlays {
class RasterOverlay;
class RasterOverlayTileProvider;
/**
* @brief Raster image data for a tile in a quadtree.
*
* Instances of this clas represent tiles of a quadtree that have
* an associated image, which us used as an imagery overlay
* for tile geometry. The connection between the imagery data
* and the actual tile geometry is established via the
* {@link Cesium3DTilesSelection::RasterMappedTo3DTile} class, which combines a
* raster overlay tile with texture coordinates, to map the
* image on the geometry of a {@link Cesium3DTilesSelection::Tile}.
*/
class RasterOverlayTile final
: public CesiumUtility::ReferenceCountedNonThreadSafe<RasterOverlayTile> {
public:
/**
* @brief Lifecycle states of a raster overlay tile.
*/
enum class LoadState {
/**
* @brief Indicator for a placeholder tile.
*/
Placeholder = -2,
/**
* @brief The image request or image creation failed.
*/
Failed = -1,
/**
* @brief The initial state
*/
Unloaded = 0,
/**
* @brief The request for loading the image data is still pending.
*/
Loading = 1,
/**
* @brief The image data has been loaded and the image has been created.
*/
Loaded = 2,
/**
* @brief The rendering resources for the image data have been created.
*/
Done = 3
};
/**
* @brief Tile availability states.
*
* Values of this enumeration are returned by
* {@link Cesium3DTilesSelection::RasterMappedTo3DTile::update}, which in turn is called by
* `TilesetContentManager::updateDoneState`. These values are used to
* determine whether a leaf tile has been reached, but the associated raster
* tiles are not yet the most detailed ones that are available.
*/
enum class MoreDetailAvailable {
/** @brief There are no more detailed raster tiles. */
No = 0,
/** @brief There are more detailed raster tiles. */
Yes = 1,
/** @brief It is not known whether more detailed raster tiles are available.
*/
Unknown = 2
};
/**
* @brief Constructs a placeholder tile for the tile provider.
*
* The {@link getState} of this instance will always be
* {@link LoadState::Placeholder}.
*
* @param tileProvider The {@link RasterOverlayTileProvider}. This object
* _must_ remain valid for the entire lifetime of the tile. If the tile
* provider is destroyed before the tile, undefined behavior will result.
*/
RasterOverlayTile(RasterOverlayTileProvider& tileProvider) noexcept;
/**
* @brief Creates a new instance.
*
* The tile will start in the `Unloaded` state, and will not begin loading
* until {@link RasterOverlayTileProvider::loadTile} or
* {@link RasterOverlayTileProvider::loadTileThrottled} is called.
*
* @param tileProvider The {@link RasterOverlayTileProvider}. This object
* _must_ remain valid for the entire lifetime of the tile. If the tile
* provider is destroyed before the tile, undefined behavior may result.
* @param targetScreenPixels The maximum number of pixels on the screen that
* this tile is meant to cover. The overlay image should be approximately this
* many pixels divided by the
* {@link RasterOverlayOptions::maximumScreenSpaceError} in order to achieve
* the desired level-of-detail, but it does not need to be exactly this size.
* @param imageryRectangle The rectangle that the returned image must cover.
* It is allowed to cover a slightly larger rectangle in order to maintain
* pixel alignment. It may also cover a smaller rectangle when the overlay
* itself does not cover the entire rectangle.
*/
RasterOverlayTile(
RasterOverlayTileProvider& tileProvider,
const glm::dvec2& targetScreenPixels,
const CesiumGeometry::Rectangle& imageryRectangle) noexcept;
/** @brief Default destructor. */
~RasterOverlayTile();
/**
* @brief Returns the {@link RasterOverlayTileProvider} that created this instance.
*/
RasterOverlayTileProvider& getTileProvider() noexcept {
return *this->_pTileProvider;
}
/**
* @brief Returns the {@link RasterOverlayTileProvider} that created this instance.
*/
const RasterOverlayTileProvider& getTileProvider() const noexcept {
return *this->_pTileProvider;
}
/**
* @brief Returns the {@link RasterOverlay} that created this instance.
*/
RasterOverlay& getOverlay() noexcept;
/**
* @brief Returns the {@link RasterOverlay} that created this instance.
*/
const RasterOverlay& getOverlay() const noexcept;
/**
* @brief Returns the {@link CesiumGeometry::Rectangle} that defines the bounds
* of this tile in the raster overlay's projected coordinates.
*/
const CesiumGeometry::Rectangle& getRectangle() const noexcept {
return this->_rectangle;
}
/**
* @brief Gets the number of screen pixels in each direction that should be
* covered by this tile's texture.
*
* This is used to control which content (how highly detailed) the
* {@link RasterOverlayTileProvider} uses within the bounds of this tile.
*/
glm::dvec2 getTargetScreenPixels() const noexcept {
return this->_targetScreenPixels;
}
/**
* @brief Returns the current {@link LoadState}.
*/
LoadState getState() const noexcept { return this->_state; }
/**
* @brief Returns the list of \ref CesiumUtility::Credit "Credit"s needed for
* this tile.
*/
const std::vector<CesiumUtility::Credit>& getCredits() const noexcept {
return this->_tileCredits;
}
/**
* @brief Returns the image data for the tile.
*
* This will only contain valid image data if the {@link getState} of
* this tile is {@link LoadState `Loaded`} or {@link LoadState `Done`}.
*
* @return The image data.
*/
CesiumUtility::IntrusivePointer<const CesiumGltf::ImageAsset>
getImage() const noexcept {
return this->_pImage;
}
/**
* @brief Returns the image data for the tile.
*
* This will only contain valid image data if the {@link getState} of
* this tile is {@link LoadState `Loaded`} or {@link LoadState `Done`}.
*
* @return The image data.
*/
CesiumUtility::IntrusivePointer<CesiumGltf::ImageAsset> getImage() noexcept {
return this->_pImage;
}
/**
* @brief Create the renderer resources for the loaded image.
*
* If the {@link getState} of this tile is not {@link LoadState `Loaded`},
* then nothing will be done. Otherwise, the renderer resources will be
* prepared, so that they may later be obtained with
* {@link getRendererResources}, and the {@link getState} of this tile
* will change to {@link LoadState `Done`}.
*/
void loadInMainThread();
/**
* @brief Returns the renderer resources that have been created for this tile.
*/
void* getRendererResources() const noexcept {
return this->_pRendererResources;
}
/**
* @brief Set the renderer resources for this tile.
*
* This function is not supposed to be called by clients.
*/
void setRendererResources(void* pValue) noexcept {
this->_pRendererResources = pValue;
}
/**
* @brief Determines if more detailed data is available for the spatial area
* covered by this tile.
*/
MoreDetailAvailable isMoreDetailAvailable() const noexcept {
return this->_moreDetailAvailable;
}
private:
friend class RasterOverlayTileProvider;
void setState(LoadState newState) noexcept;
// This is a raw pointer instead of an IntrusivePointer in order to avoid
// circular references, particularly among a placeholder tile provider and
// placeholder tile. However, to avoid undefined behavior, the tile provider
// is required to outlive the tile. In normal use, the RasterOverlayCollection
// ensures that this is true.
RasterOverlayTileProvider* _pTileProvider;
glm::dvec2 _targetScreenPixels;
CesiumGeometry::Rectangle _rectangle;
std::vector<CesiumUtility::Credit> _tileCredits;
LoadState _state;
CesiumUtility::IntrusivePointer<CesiumGltf::ImageAsset> _pImage;
void* _pRendererResources;
MoreDetailAvailable _moreDetailAvailable;
};
} // namespace CesiumRasterOverlays

View File

@ -0,0 +1,436 @@
#pragma once
#include "Library.h"
#include <CesiumAsync/IAssetAccessor.h>
#include <CesiumGeospatial/Projection.h>
#include <CesiumGltfReader/GltfReader.h>
#include <CesiumUtility/Assert.h>
#include <CesiumUtility/CreditSystem.h>
#include <CesiumUtility/ErrorList.h>
#include <CesiumUtility/IntrusivePointer.h>
#include <CesiumUtility/ReferenceCounted.h>
#include <CesiumUtility/Tracing.h>
#include <spdlog/fwd.h>
#include <optional>
namespace CesiumRasterOverlays {
class RasterOverlay;
class RasterOverlayTile;
class IPrepareRasterOverlayRendererResources;
/**
* @brief Summarizes the result of loading an image of a {@link RasterOverlay}.
*/
struct CESIUMRASTEROVERLAYS_API LoadedRasterOverlayImage {
/**
* @brief The loaded image.
*
* This will be an empty optional if the loading failed. In this case,
* the `errors` vector will contain the corresponding error messages.
*/
CesiumUtility::IntrusivePointer<CesiumGltf::ImageAsset> pImage{nullptr};
/**
* @brief The projected rectangle defining the bounds of this image.
*
* The rectangle extends from the left side of the leftmost pixel to the
* right side of the rightmost pixel, and similar for the vertical direction.
*/
CesiumGeometry::Rectangle rectangle{};
/**
* @brief The {@link CesiumUtility::Credit} objects that decribe the attributions that
* are required when using the image.
*/
std::vector<CesiumUtility::Credit> credits{};
/**
* @brief Errors and warnings from loading the image.
*
* If the image was loaded successfully, there should not be any errors (but
* there may be warnings).
*/
CesiumUtility::ErrorList errorList{};
/**
* @brief Whether more detailed data, beyond this image, is available within
* the bounds of this image.
*/
bool moreDetailAvailable = false;
/**
* @brief Returns the size of this `LoadedRasterOverlayImage` in bytes.
*/
int64_t getSizeBytes() const {
int64_t accum = 0;
accum += int64_t(sizeof(LoadedRasterOverlayImage));
accum += int64_t(this->credits.capacity() * sizeof(CesiumUtility::Credit));
if (this->pImage) {
accum += this->pImage->getSizeBytes();
}
return accum;
}
};
/**
* @brief Options for {@link RasterOverlayTileProvider::loadTileImageFromUrl}.
*/
struct LoadTileImageFromUrlOptions {
/**
* @brief The rectangle definining the bounds of the image being loaded,
* expressed in the {@link RasterOverlayTileProvider}'s projection.
*/
CesiumGeometry::Rectangle rectangle{};
/**
* @brief The credits to display with this tile.
*
* This property is copied verbatim to the
* {@link LoadedRasterOverlayImage::credits} property.
*/
std::vector<CesiumUtility::Credit> credits{};
/**
* @brief Whether more detailed data, beyond this image, is available within
* the bounds of this image.
*/
bool moreDetailAvailable = true;
/**
* @brief Whether empty (zero length) images are accepted as a valid
* response.
*
* If true, an otherwise valid response with zero length will be accepted as
* a valid 0x0 image. If false, such a response will be reported as an
* error.
*
* {@link RasterOverlayTileProvider::loadTile} and
* {@link RasterOverlayTileProvider::loadTileThrottled} will treat such an
* image as "failed" and use the quadtree parent (or ancestor) image
* instead, but will not report any error.
*
* This flag should only be set to `true` when the tile source uses a
* zero-length response as an indication that this tile is - as expected -
* not available.
*/
bool allowEmptyImages = false;
};
class RasterOverlayTileProvider;
/**
* @brief Holds a tile and its corresponding tile provider. Used as the return
* value of {@link RasterOverlayTileProvider::loadTile}.
*/
struct TileProviderAndTile {
/** @brief A \ref CesiumUtility::IntrusivePointer to the \ref
* RasterOverlayTileProvider used for this tile. */
CesiumUtility::IntrusivePointer<RasterOverlayTileProvider> pTileProvider;
/** @brief A \ref CesiumUtility::IntrusivePointer to the \ref
* RasterOverlayTile used for this tile. */
CesiumUtility::IntrusivePointer<RasterOverlayTile> pTile;
~TileProviderAndTile() noexcept;
};
/**
* @brief Provides individual tiles for a {@link RasterOverlay} on demand.
*
* Instances of this class must be allocated on the heap, and their lifetimes
* must be managed with {@link CesiumUtility::IntrusivePointer}.
*/
class CESIUMRASTEROVERLAYS_API RasterOverlayTileProvider
: public CesiumUtility::ReferenceCountedNonThreadSafe<
RasterOverlayTileProvider> {
public:
/**
* Constructs a placeholder tile provider.
*
* @see RasterOverlayTileProvider::isPlaceholder
*
* @param pOwner The raster overlay that created this tile provider.
* @param asyncSystem The async system used to do work in threads.
* @param pAssetAccessor The interface used to obtain assets (tiles, etc.) for
* this raster overlay.
* @param ellipsoid The {@link CesiumGeospatial::Ellipsoid}.
*/
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;
/**
* @brief Creates a new instance.
*
* @param pOwner The raster overlay that created this tile provider.
* @param asyncSystem The async system used to do work in threads.
* @param pAssetAccessor The interface used to obtain assets (tiles, etc.) for
* this raster overlay.
* @param credit The {@link CesiumUtility::Credit} for this tile provider, if it exists.
* @param pPrepareRendererResources The interface used to prepare raster
* images for rendering.
* @param pLogger The logger to which to send messages about the tile provider
* and tiles.
* @param projection The {@link CesiumGeospatial::Projection}.
* @param coverageRectangle The rectangle that bounds all the area covered by
* this overlay, expressed in projected coordinates.
*/
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;
/** @brief Default destructor. */
virtual ~RasterOverlayTileProvider() noexcept;
/**
* @brief Returns whether this is a placeholder.
*
* For many types of {@link RasterOverlay}, we can't create a functioning
* `RasterOverlayTileProvider` right away. For example, we may not know the
* bounds of the overlay, or what projection it uses, until after we've
* (asynchronously) loaded a metadata service that gives us this information.
*
* So until that real `RasterOverlayTileProvider` becomes available, we use
* a placeholder. When {@link RasterOverlayTileProvider::getTile} is invoked
* on a placeholder, it returns a {@link RasterOverlayTile} that is also
* a placeholder. And whenever we see a placeholder `RasterOverlayTile` in
* {@link Cesium3DTilesSelection::RasterMappedTo3DTile::update}, we check if the corresponding `RasterOverlay` is
* ready yet. Once it's ready, we remove the placeholder tile and replace
* it with the real tiles.
*
* So the placeholder system gives us a way to defer the mapping of raster
* overlay tiles to geometry tiles until that mapping can be determined.
*/
bool isPlaceholder() const noexcept { return this->_pPlaceholder != nullptr; }
/**
* @brief Returns the {@link RasterOverlay} that created this instance.
*/
RasterOverlay& getOwner() noexcept { return *this->_pOwner; }
/** @copydoc getOwner */
const RasterOverlay& getOwner() const noexcept { return *this->_pOwner; }
/**
* @brief Get the system to use for asychronous requests and threaded work.
*/
const std::shared_ptr<CesiumAsync::IAssetAccessor>&
getAssetAccessor() const noexcept {
return this->_pAssetAccessor;
}
/**
* @brief Gets the async system used to do work in threads.
*/
const CesiumAsync::AsyncSystem& getAsyncSystem() const noexcept {
return this->_asyncSystem;
}
/**
* @brief Gets the interface used to prepare raster overlay images for
* rendering.
*/
const std::shared_ptr<IPrepareRasterOverlayRendererResources>&
getPrepareRendererResources() const noexcept {
return this->_pPrepareRendererResources;
}
/**
* @brief Gets the logger to which to send messages about the tile provider
* and tiles.
*/
const std::shared_ptr<spdlog::logger>& getLogger() const noexcept {
return this->_pLogger;
}
/**
* @brief Returns the {@link CesiumGeospatial::Projection} of this instance.
*/
const CesiumGeospatial::Projection& getProjection() const noexcept {
return this->_projection;
}
/**
* @brief Returns the coverage {@link CesiumGeometry::Rectangle} of this
* instance.
*/
const CesiumGeometry::Rectangle& getCoverageRectangle() const noexcept {
return this->_coverageRectangle;
}
/**
* @brief Returns a new {@link RasterOverlayTile} with the given
* specifications.
*
* The returned tile will not start loading immediately. To start loading,
* call {@link RasterOverlayTileProvider::loadTile} or
* {@link RasterOverlayTileProvider::loadTileThrottled}.
*
* @param rectangle The rectangle that the returned image must cover. It is
* allowed to cover a slightly larger rectangle in order to maintain pixel
* alignment. It may also cover a smaller rectangle when the overlay itself
* does not cover the entire rectangle.
* @param targetScreenPixels The maximum number of pixels on the screen that
* this tile is meant to cover. The overlay image should be approximately this
* many pixels divided by the
* {@link RasterOverlayOptions::maximumScreenSpaceError} in order to achieve
* the desired level-of-detail, but it does not need to be exactly this size.
* @return The tile.
*/
CesiumUtility::IntrusivePointer<RasterOverlayTile> getTile(
const CesiumGeometry::Rectangle& rectangle,
const glm::dvec2& targetScreenPixels);
/**
* @brief Gets the number of bytes of tile data that are currently loaded.
*/
int64_t getTileDataBytes() const noexcept { return this->_tileDataBytes; }
/**
* @brief Returns the number of tiles that are currently loading.
*/
uint32_t getNumberOfTilesLoading() const noexcept {
CESIUM_ASSERT(this->_totalTilesCurrentlyLoading > -1);
return static_cast<uint32_t>(this->_totalTilesCurrentlyLoading);
}
/**
* @brief Removes a no-longer-referenced tile from this provider's cache and
* deletes it.
*
* This function is not supposed to be called by client. Calling this method
* in a tile with a reference count greater than 0 will result in undefined
* behavior.
*
* @param pTile The tile, which must have no oustanding references.
*/
void removeTile(RasterOverlayTile* pTile) noexcept;
/**
* @brief Get the per-TileProvider {@link CesiumUtility::Credit} if one exists.
*/
const std::optional<CesiumUtility::Credit>& getCredit() const noexcept {
return _credit;
}
/**
* @brief Loads a tile immediately, without throttling requests.
*
* If the tile is not in the `Tile::LoadState::Unloaded` state, this method
* returns without doing anything. Otherwise, it puts the tile into the
* `Tile::LoadState::Loading` state and begins the asynchronous process
* to load the tile. When the process completes, the tile will be in the
* `Tile::LoadState::Loaded` or `Tile::LoadState::Failed` state.
*
* Calling this method on many tiles at once can result in very slow
* performance. Consider using {@link loadTileThrottled} instead.
*
* @param tile The tile to load.
* @return A future that, when the tile is loaded, resolves to the loaded tile
* and the tile provider that loaded it.
*/
CesiumAsync::Future<TileProviderAndTile> loadTile(RasterOverlayTile& tile);
/**
* @brief Loads a tile, unless there are too many tile loads already in
* progress.
*
* If the tile is not in the `Tile::LoadState::Unloading` state, this method
* returns true without doing anything. If too many tile loads are
* already in flight, it returns false without doing anything. Otherwise, it
* puts the tile into the `Tile::LoadState::Loading` state, begins the
* asynchronous process to load the tile, and returns true. When the process
* completes, the tile will be in the `Tile::LoadState::Loaded` or
* `Tile::LoadState::Failed` state.
*
* The number of allowable simultaneous tile requests is provided in the
* {@link RasterOverlayOptions::maximumSimultaneousTileLoads} property of
* {@link RasterOverlay::getOptions}.
*
* @param tile The tile to load.
* @returns True if the tile load process is started or is already complete,
* false if the load could not be started because too many loads are already
* in progress.
*/
bool loadTileThrottled(RasterOverlayTile& tile);
protected:
/**
* @brief Loads the image for a tile.
*
* @param overlayTile The overlay tile for which to load the image.
* @return A future that resolves to the image or error information.
*/
virtual CesiumAsync::Future<LoadedRasterOverlayImage>
loadTileImage(RasterOverlayTile& overlayTile) = 0;
/**
* @brief Loads an image from a URL and optionally some request headers.
*
* This is a useful helper function for implementing {@link loadTileImage}.
*
* @param url The URL.
* @param headers The request headers.
* @param options Additional options for the load process.
* @return A future that resolves to the image or error information.
*/
CesiumAsync::Future<LoadedRasterOverlayImage> loadTileImageFromUrl(
const std::string& url,
const std::vector<CesiumAsync::IAssetAccessor::THeader>& headers = {},
LoadTileImageFromUrlOptions&& options = {}) const;
private:
CesiumAsync::Future<TileProviderAndTile>
doLoad(RasterOverlayTile& tile, bool isThrottledLoad);
/**
* @brief Begins the process of loading of a tile.
*
* This method should be called at the beginning of the tile load process.
*
* @param isThrottledLoad True if the load was originally throttled.
*/
void beginTileLoad(bool isThrottledLoad) noexcept;
/**
* @brief Finalizes loading of a tile.
*
* This method should be called at the end of the tile load process,
* no matter whether the load succeeded or failed.
*
* @param isThrottledLoad True if the load was originally throttled.
*/
void finalizeTileLoad(bool isThrottledLoad) noexcept;
private:
CesiumUtility::IntrusivePointer<RasterOverlay> _pOwner;
CesiumAsync::AsyncSystem _asyncSystem;
std::shared_ptr<CesiumAsync::IAssetAccessor> _pAssetAccessor;
std::optional<CesiumUtility::Credit> _credit;
std::shared_ptr<IPrepareRasterOverlayRendererResources>
_pPrepareRendererResources;
std::shared_ptr<spdlog::logger> _pLogger;
CesiumGeospatial::Projection _projection;
CesiumGeometry::Rectangle _coverageRectangle;
CesiumUtility::IntrusivePointer<RasterOverlayTile> _pPlaceholder;
int64_t _tileDataBytes;
int32_t _totalTilesCurrentlyLoading;
int32_t _throttledTilesCurrentlyLoading;
CESIUM_TRACE_DECLARE_TRACK_SET(
_loadingSlots,
"Raster Overlay Tile Loading Slot")
};
} // namespace CesiumRasterOverlays

View File

@ -0,0 +1,194 @@
#pragma once
#include "Library.h"
#include "RasterOverlayDetails.h"
#include <CesiumGeometry/QuadtreeTileID.h>
#include <CesiumGeospatial/Ellipsoid.h>
#include <CesiumGeospatial/Projection.h>
#include <glm/fwd.hpp>
#include <optional>
#include <string_view>
#include <vector>
namespace CesiumGltf {
struct Model;
}
namespace CesiumRasterOverlays {
/**
* @brief A collection of utilities useful for operations involving raster
* overlay tiles.
*/
struct CESIUMRASTEROVERLAYS_API RasterOverlayUtilities {
/**
* @brief Texture coordinates will be stored in the glTF under the following
* name, appended with a number. See \ref
* createRasterOverlayTextureCoordinates.
*/
static constexpr std::string_view DEFAULT_TEXTURE_COORDINATE_BASE_NAME =
"_CESIUMOVERLAY_";
/**
* @brief Creates texture coordinates for mapping {@link RasterOverlay} tiles
* to a glTF model.
*
* Generates new texture coordinates for the `gltf` using the given
* `projections`. The first new texture coordinate (`u` or `s`) will be 0.0 at
* the `minimumX` of the given `rectangle` and 1.0 at the `maximumX`. The
* second texture coordinate (`v` or `t`) will be 0.0 at the `minimumY` of
* the given `rectangle` and 1.0 at the `maximumY`.
*
* Coordinate values for vertices in between these extremes are determined by
* projecting the vertex position with the `projection` and then computing the
* fractional distance of that projected position between the minimum and
* maximum.
*
* Projected positions that fall outside the `globeRectangle` will be clamped
* to the edges, so the coordinate values will never be less then 0.0 or
* greater than 1.0.
*
* These texture coordinates are stored in the provided glTF, and a new
* primitive attribute is added to each primitive for each projection. The new
* primitive attributes are named with `textureCoordinateAttributeBaseName`
* followed by a number, starting with `firstTextureCoordinateID` and
* incrementing for each projection. For example, if
* `textureCoordinateAttributeBaseName` is
* `_CESIUMOVERLAY_` and `firstTextureCoordinateID` is 0 (the defaults), then
* the texture coordinates for the first projection will be stored in an
* attribute named `_CESIUMOVERLAY_0`, the second will be in
* `_CESIUMOVERLAY_1`, and so on.
*
* @param gltf The glTF model.
* @param modelToEcefTransform The transformation of this glTF to ECEF
* coordinates.
* @param globeRectangle The rectangle that all projected vertex positions are
* expected to lie within. If this parameter is std::nullopt, it is computed
* from the vertices.
* @param projections The projections for which to generate texture
* coordinates. There is a linear relationship between the coordinates of this
* projection and the generated texture coordinates.
* @param invertVCoordinate True if the V texture coordinate should be
* inverted so that it is 1.0 at the Southern end of the rectangle and 0.0 at
* the Northern end. This is useful with images that use the typical North-up
* orientation.
* @param textureCoordinateAttributeBaseName The base name to use for the
* texture coordinate attributes, without a number on the end. Defaults to
* {@link DEFAULT_TEXTURE_COORDINATE_BASE_NAME}.
* @param firstTextureCoordinateID The texture coordinate ID of the first
* projection.
* @return The details of the generated texture coordinates.
*/
static std::optional<RasterOverlayDetails>
createRasterOverlayTextureCoordinates(
CesiumGltf::Model& gltf,
const glm::dmat4& modelToEcefTransform,
const std::optional<CesiumGeospatial::GlobeRectangle>& globeRectangle,
std::vector<CesiumGeospatial::Projection>&& projections,
bool invertVCoordinate = false,
const std::string_view& textureCoordinateAttributeBaseName =
DEFAULT_TEXTURE_COORDINATE_BASE_NAME,
int32_t firstTextureCoordinateID = 0);
/**
* @brief Creates a new glTF model from one of the quadtree children of the
* given parent model.
*
* The parent model subdivision is guided by texture coordinates. These
* texture coordinates must follow a map projection, and the parent tile is
* divided into quadrants as divided by this map projection. To create the
* necessary texture coordinates, use
* {@link createRasterOverlayTextureCoordinates}.
*
* @param parentModel The parent model to upsample.
* @param childID The quadtree tile ID of the child model. This is used to
* determine which of the four children of the parent tile to generate.
* @param hasInvertedVCoordinate True if the V texture coordinate has 0.0 as
* the Northern-most coordinate; False if the V texture coordinate has 0.0 as
* the Southern-most coordiante.
* @param textureCoordinateAttributeBaseName The base name of the attribute
* that holds the projected texture coordinates. The `textureCoordinateIndex`
* is appended to this name. Defaults to
* {@link DEFAULT_TEXTURE_COORDINATE_BASE_NAME}.
* @param textureCoordinateIndex The index of the texture coordinate set to
* use. For example, if `textureCoordinateAttributeBaseName` is
* `_CESIUMOVERLAY_` and this parameter is 0 (the defaults), then the texture
* coordinates are read from a vertex attribute named `_CESIUMOVERLAY_0`.
* @param ellipsoid The {@link CesiumGeospatial::Ellipsoid}.
* @return The upsampled model.
*/
static std::optional<CesiumGltf::Model> upsampleGltfForRasterOverlays(
const CesiumGltf::Model& parentModel,
CesiumGeometry::UpsampledQuadtreeNode childID,
bool hasInvertedVCoordinate = false,
const std::string_view& textureCoordinateAttributeBaseName =
DEFAULT_TEXTURE_COORDINATE_BASE_NAME,
int32_t textureCoordinateIndex = 0,
const CesiumGeospatial::Ellipsoid& ellipsoid =
CesiumGeospatial::Ellipsoid::WGS84);
/**
* @brief Computes the desired screen pixels for a raster overlay texture.
*
* This method is used to determine the appropriate number of "screen pixels"
* to use for a raster overlay texture to be attached to a glTF (which is
* usually a 3D Tiles tile). In other words, how detailed should the texture
* be? The answer depends, of course, on how close we'll get to the model. If
* we're going to get very close, we'll need a higher-resolution raster
* overlay texture than if we will stay far away from it.
*
* In 3D Tiles, we can only get so close to a model before it switches to the
* next higher level-of-detail by showing its children instead. The switch
* distance is controlled by the `geometric error` of the tile, as well as by
* the `maximum screen space error` of the tileset. So this method requires
* both of those parameters.
*
* The answer also depends on the size of the model on the screen at this
* switch distance. To determine that, this method takes a projection and a
* rectangle that bounds the tile, expressed in that projection. This
* rectangle is projected onto the screen at the switch distance, and the size
* of that rectangle on the screen is the `target screen pixels` returned by
* this method.
*
* The `target screen pixels` returned here may be further modified by the
* raster overlay's {@link RasterOverlayTileProvider::getTile} method. In particular, it
* will usually be divided by the raster overlay's `maximum screen space
* error` of the raster overlay (not to be confused with the `maximum screen
* space error` of the tileset, mentioned above).
*
* @param geometricError The geometric error of the tile.
* @param maximumScreenSpaceError The maximum screen-space error used to
* render the tileset.
* @param projection The projection in which the `rectangle` parameter is
* provided.
* @param rectangle The 2D extent of the tile, expressed in the `projection`.
* @param ellipsoid The ellipsoid with which computations are performed.
* @return The desired screen pixels.
*/
static glm::dvec2 computeDesiredScreenPixels(
double geometricError,
double maximumScreenSpaceError,
const CesiumGeospatial::Projection& projection,
const CesiumGeometry::Rectangle& rectangle,
const CesiumGeospatial::Ellipsoid& ellipsoid CESIUM_DEFAULT_ELLIPSOID);
/**
* @brief Computes the texture translation and scale necessary to align a
* raster overlay with the given rectangle on geometry whose texture
* coordinates were computed using a different rectangle.
*
* @param geometryRectangle The geometry rectangle used to the compute the
* texture coordinates.
* @param overlayRectangle The rectangle covered by the raster overlay
* texture.
* @return The translation in X and Y, and the scale in Z and W.
*/
static glm::dvec4 computeTranslationAndScale(
const CesiumGeometry::Rectangle& geometryRectangle,
const CesiumGeometry::Rectangle& overlayRectangle);
};
} // namespace CesiumRasterOverlays

View File

@ -0,0 +1,90 @@
#pragma once
#include "Library.h"
#include "RasterOverlay.h"
#include "RasterOverlayTileProvider.h"
#include <CesiumAsync/AsyncSystem.h>
#include <CesiumGeospatial/CartographicPolygon.h>
#include <CesiumGeospatial/Ellipsoid.h>
#include <CesiumGeospatial/Projection.h>
#include <spdlog/fwd.h>
#include <memory>
#include <string>
#include <vector>
namespace CesiumRasterOverlays {
/**
* @brief A raster overlay made from rasterizing a set of \ref
* CesiumGeospatial::CartographicPolygon "CartographicPolygon" objects. The
* resulting overlay is monochromatic - white where pixels are inside of the
* polygons, and black where they are not.
*/
class CESIUMRASTEROVERLAYS_API RasterizedPolygonsOverlay final
: public RasterOverlay {
public:
/**
* @brief Creates a new RasterizedPolygonsOverlay.
*
* @param name The user-given name of this polygon layer.
* @param polygons The \ref CesiumGeospatial::CartographicPolygon
* "CartographicPolygon" objects to rasterize.
* @param invertSelection If true, the overlay's colors will be inverted. The
* pixels inside of polygons will be black, and those outside will be white.
* @param ellipsoid The ellipsoid that this RasterOverlay is being generated
* for.
* @param projection The projection that this RasterOverlay is being generated
* for.
* @param overlayOptions Options to use for this RasterOverlay.
*/
RasterizedPolygonsOverlay(
const std::string& name,
const std::vector<CesiumGeospatial::CartographicPolygon>& polygons,
bool invertSelection,
const CesiumGeospatial::Ellipsoid& ellipsoid,
const CesiumGeospatial::Projection& projection,
const RasterOverlayOptions& overlayOptions = {});
virtual ~RasterizedPolygonsOverlay() override;
virtual CesiumAsync::Future<CreateTileProviderResult> createTileProvider(
const CesiumAsync::AsyncSystem& asyncSystem,
const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
const std::shared_ptr<CesiumUtility::CreditSystem>& pCreditSystem,
const std::shared_ptr<IPrepareRasterOverlayRendererResources>&
pPrepareRendererResources,
const std::shared_ptr<spdlog::logger>& pLogger,
CesiumUtility::IntrusivePointer<const RasterOverlay> pOwner)
const override;
/**
* @brief Gets the polygons that are being rasterized to create this overlay.
*/
const std::vector<CesiumGeospatial::CartographicPolygon>&
getPolygons() const noexcept {
return this->_polygons;
}
/**
* @brief Gets the value of the `invertSelection` value passed to the
* constructor.
*/
bool getInvertSelection() const noexcept { return this->_invertSelection; }
/**
* @brief Gets the ellipsoid that this overlay is being generated for.
*/
const CesiumGeospatial::Ellipsoid& getEllipsoid() const noexcept {
return this->_ellipsoid;
}
private:
std::vector<CesiumGeospatial::CartographicPolygon> _polygons;
bool _invertSelection;
CesiumGeospatial::Ellipsoid _ellipsoid;
CesiumGeospatial::Projection _projection;
};
} // namespace CesiumRasterOverlays

View File

@ -0,0 +1,125 @@
#pragma once
#include "Library.h"
#include "RasterOverlay.h"
#include <CesiumAsync/IAssetRequest.h>
#include <CesiumGeometry/QuadtreeTilingScheme.h>
#include <CesiumGeospatial/Ellipsoid.h>
#include <CesiumGeospatial/GlobeRectangle.h>
#include <CesiumGeospatial/Projection.h>
#include <functional>
#include <memory>
namespace CesiumRasterOverlays {
/**
* @brief Options for tile map service accesses.
*/
struct TileMapServiceRasterOverlayOptions {
/**
* @brief The file extension for images on the server.
*/
std::optional<std::string> fileExtension;
/**
* @brief A credit for the data source, which is displayed on the canvas.
*/
std::optional<std::string> credit;
/**
* @brief The minimum level-of-detail supported by the imagery provider.
*
* Take care when specifying this that the number of tiles at the minimum
* level is small, such as four or less. A larger number is likely to
* result in rendering problems.
*/
std::optional<uint32_t> minimumLevel;
/**
* @brief The maximum level-of-detail supported by the imagery provider.
*
* This will be `std::nullopt` if there is no limit.
*/
std::optional<uint32_t> maximumLevel;
/**
* @brief The {@link CesiumGeometry::Rectangle}, in radians, covered by the
* image.
*/
std::optional<CesiumGeometry::Rectangle> coverageRectangle;
/**
* @brief The {@link CesiumGeospatial::Projection} that is used.
*/
std::optional<CesiumGeospatial::Projection> projection;
/**
* @brief The {@link CesiumGeometry::QuadtreeTilingScheme} specifying how
* the ellipsoidal surface is broken into tiles.
*/
std::optional<CesiumGeometry::QuadtreeTilingScheme> tilingScheme;
/**
* @brief Pixel width of image tiles.
*/
std::optional<uint32_t> tileWidth;
/**
* @brief Pixel height of image tiles.
*/
std::optional<uint32_t> tileHeight;
/**
* @brief An otion to flip the x- and y values of a tile map resource.
*
* Older versions of gdal2tiles.py flipped X and Y values in
* `tilemapresource.xml`. Specifying this option will do the same, allowing
* for loading of these incorrect tilesets.
*/
std::optional<bool> flipXY;
};
/**
* @brief A {@link RasterOverlay} based on tile map service imagery.
*/
class CESIUMRASTEROVERLAYS_API TileMapServiceRasterOverlay final
: public RasterOverlay {
public:
/**
* @brief Creates a new instance.
*
* @param name The user-given name of this overlay layer.
* @param url The base URL.
* @param headers The headers. This is a list of pairs of strings of the
* form (Key,Value) that will be inserted as request headers internally.
* @param tmsOptions The {@link TileMapServiceRasterOverlayOptions}.
* @param overlayOptions The {@link RasterOverlayOptions} for this instance.
*/
TileMapServiceRasterOverlay(
const std::string& name,
const std::string& url,
const std::vector<CesiumAsync::IAssetAccessor::THeader>& headers = {},
const TileMapServiceRasterOverlayOptions& tmsOptions = {},
const RasterOverlayOptions& overlayOptions = {});
virtual ~TileMapServiceRasterOverlay() override;
virtual CesiumAsync::Future<CreateTileProviderResult> createTileProvider(
const CesiumAsync::AsyncSystem& asyncSystem,
const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
const std::shared_ptr<CesiumUtility::CreditSystem>& pCreditSystem,
const std::shared_ptr<IPrepareRasterOverlayRendererResources>&
pPrepareRendererResources,
const std::shared_ptr<spdlog::logger>& pLogger,
CesiumUtility::IntrusivePointer<const RasterOverlay> pOwner)
const override;
private:
std::string _url;
std::vector<CesiumAsync::IAssetAccessor::THeader> _headers;
TileMapServiceRasterOverlayOptions _options;
};
} // namespace CesiumRasterOverlays

View File

@ -0,0 +1,107 @@
#pragma once
#include "Library.h"
#include "RasterOverlay.h"
#include <CesiumAsync/IAssetRequest.h>
#include <CesiumGeometry/QuadtreeTilingScheme.h>
#include <CesiumGeospatial/Ellipsoid.h>
#include <CesiumGeospatial/GlobeRectangle.h>
#include <CesiumGeospatial/Projection.h>
#include <memory>
namespace CesiumRasterOverlays {
/**
* @brief Options for Web Map Service (WMS) overlays.
*/
struct WebMapServiceRasterOverlayOptions {
/**
* @brief The Web Map Service version. The default is "1.3.0".
*/
std::string version = "1.3.0";
/**
* @brief Comma separated Web Map Service layer names to request.
*/
std::string layers;
/**
* @brief The image format to request, expressed as a MIME type to be given to
* the server. The default is "image/png".
*/
std::string format = "image/png";
/**
* @brief A credit for the data source, which is displayed on the canvas.
*/
std::optional<std::string> credit;
/**
* @brief The minimum level-of-detail supported by the imagery provider.
*
* Take care when specifying this that the number of tiles at the minimum
* level is small, such as four or less. A larger number is likely to
* result in rendering problems.
*/
int32_t minimumLevel = 0;
/**
* @brief The maximum level-of-detail supported by the imagery provider.
*/
int32_t maximumLevel = 14;
/**
* @brief Pixel width of image tiles.
*/
int32_t tileWidth = 256;
/**
* @brief Pixel height of image tiles.
*/
int32_t tileHeight = 256;
};
/**
* @brief A {@link RasterOverlay} accessing images from a Web Map Service (WMS) server.
*/
class CESIUMRASTEROVERLAYS_API WebMapServiceRasterOverlay final
: public RasterOverlay {
public:
/**
* @brief Creates a new instance.
*
* @param name The user-given name of this overlay layer.
* @param url The base URL.
* @param headers The headers. This is a list of pairs of strings of the
* form (Key,Value) that will be inserted as request headers internally.
* @param wmsOptions The {@link WebMapServiceRasterOverlayOptions}.
* @param overlayOptions The {@link RasterOverlayOptions} for this instance.
*/
WebMapServiceRasterOverlay(
const std::string& name,
const std::string& url,
const std::vector<CesiumAsync::IAssetAccessor::THeader>& headers = {},
const WebMapServiceRasterOverlayOptions& wmsOptions = {},
const RasterOverlayOptions& overlayOptions = {});
virtual ~WebMapServiceRasterOverlay() override;
virtual CesiumAsync::Future<CreateTileProviderResult> createTileProvider(
const CesiumAsync::AsyncSystem& asyncSystem,
const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
const std::shared_ptr<CesiumUtility::CreditSystem>& pCreditSystem,
const std::shared_ptr<IPrepareRasterOverlayRendererResources>&
pPrepareRendererResources,
const std::shared_ptr<spdlog::logger>& pLogger,
CesiumUtility::IntrusivePointer<const RasterOverlay> pOwner)
const override;
private:
std::string _baseUrl;
std::vector<CesiumAsync::IAssetAccessor::THeader> _headers;
WebMapServiceRasterOverlayOptions _options;
};
} // namespace CesiumRasterOverlays

View File

@ -0,0 +1,159 @@
#pragma once
#include "Library.h"
#include "RasterOverlay.h"
#include <CesiumAsync/IAssetRequest.h>
#include <CesiumGeometry/QuadtreeTilingScheme.h>
#include <CesiumGeospatial/Ellipsoid.h>
#include <CesiumGeospatial/GlobeRectangle.h>
#include <CesiumGeospatial/Projection.h>
#include <functional>
#include <memory>
#include <vector>
namespace CesiumRasterOverlays {
/**
* @brief Options for {@link WebMapTileServiceRasterOverlay}.
*/
struct WebMapTileServiceRasterOverlayOptions {
/**
* @brief The MIME type for images to retrieve from the server.
*
* Default value is "image/jpeg"
*/
std::optional<std::string> format;
/**
* @brief The subdomains to use for the <code>{s}</code> placeholder in the URL template.
*
* If this parameter is a single string, each character in the string is a
* subdomain. If it is an array, each element in the array is a subdomain.
*/
std::vector<std::string> subdomains;
/**
* @brief A credit for the data source, which is displayed on the canvas.
*/
std::optional<std::string> credit;
/**
* @brief The layer name for WMTS requests.
*/
std::string layer;
/**
* @brief The style name for WMTS requests.
*/
std::string style;
/**
* @brief The identifier of the TileMatrixSet to use for WMTS requests.
*/
std::string tileMatrixSetID;
/**
* @brief A list of identifiers in the TileMatrix to use for WMTS requests,
* one per TileMatrix level.
*/
std::optional<std::vector<std::string>> tileMatrixLabels;
/**
* @brief The minimum level-of-detail supported by the imagery provider.
*
* Take care when specifying this that the number of tiles at the minimum
* level is small, such as four or less. A larger number is likely to
* result in rendering problems.
* Default value is 0.
*/
std::optional<uint32_t> minimumLevel;
/**
* @brief The maximum level-of-detail supported by the imagery provider.
*
* Default value is 25.
*/
std::optional<uint32_t> maximumLevel;
/**
* @brief The {@link CesiumGeometry::Rectangle}, in radians, covered by the
* image.
*/
std::optional<CesiumGeometry::Rectangle> coverageRectangle;
/**
* @brief The {@link CesiumGeospatial::Projection} that is used.
*/
std::optional<CesiumGeospatial::Projection> projection;
/**
* @brief The {@link CesiumGeometry::QuadtreeTilingScheme} specifying how
* the ellipsoidal surface is broken into tiles.
*/
std::optional<CesiumGeometry::QuadtreeTilingScheme> tilingScheme;
/**
* @brief A object containing static dimensions and their values.
*/
std::optional<std::map<std::string, std::string>> dimensions;
/**
* @brief Pixel width of image tiles.
*
* Default value is 256
*/
std::optional<uint32_t> tileWidth;
/**
* @brief Pixel height of image tiles.
*
* Default value is 256
*/
std::optional<uint32_t> tileHeight;
};
/**
* @brief A {@link RasterOverlay} accessing images from a Web Map Tile Service
* (WMTS) server.
*/
class CESIUMRASTEROVERLAYS_API WebMapTileServiceRasterOverlay final
: public RasterOverlay {
public:
/**
* @brief Creates a new instance.
*
* @param name The user-given name of this overlay layer.
* @param url The base URL.
* @param headers The headers. This is a list of pairs of strings of the
* form (Key,Value) that will be inserted as request headers internally.
* @param tmsOptions The {@link WebMapTileServiceRasterOverlayOptions}.
* @param overlayOptions The {@link RasterOverlayOptions} for this instance.
*/
WebMapTileServiceRasterOverlay(
const std::string& name,
const std::string& url,
const std::vector<CesiumAsync::IAssetAccessor::THeader>& headers = {},
const WebMapTileServiceRasterOverlayOptions& tmsOptions = {},
const RasterOverlayOptions& overlayOptions = {});
virtual ~WebMapTileServiceRasterOverlay() override;
virtual CesiumAsync::Future<CreateTileProviderResult> createTileProvider(
const CesiumAsync::AsyncSystem& asyncSystem,
const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
const std::shared_ptr<CesiumUtility::CreditSystem>& pCreditSystem,
const std::shared_ptr<IPrepareRasterOverlayRendererResources>&
pPrepareRendererResources,
const std::shared_ptr<spdlog::logger>& pLogger,
CesiumUtility::IntrusivePointer<const RasterOverlay> pOwner)
const override;
private:
std::string _url;
std::vector<CesiumAsync::IAssetAccessor::THeader> _headers;
WebMapTileServiceRasterOverlayOptions _options;
};
} // namespace CesiumRasterOverlays