cesium-native  0.41.0
QuadtreeRasterOverlayTileProvider.h
1 #pragma once
2 
3 #include "IPrepareRasterOverlayRendererResources.h"
4 #include "Library.h"
5 #include "RasterOverlayTileProvider.h"
6 
7 #include <CesiumAsync/AsyncSystem.h>
8 #include <CesiumAsync/IAssetAccessor.h>
9 #include <CesiumGeometry/QuadtreeTileID.h>
10 #include <CesiumGeometry/QuadtreeTilingScheme.h>
11 #include <CesiumUtility/CreditSystem.h>
12 
13 #include <list>
14 #include <memory>
15 #include <optional>
16 
17 namespace CesiumRasterOverlays {
18 
19 class CESIUMRASTEROVERLAYS_API QuadtreeRasterOverlayTileProvider
20  : public RasterOverlayTileProvider {
21 
22 public:
44  const CesiumAsync::AsyncSystem& asyncSystem,
45  const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
46  std::optional<CesiumUtility::Credit> credit,
47  const std::shared_ptr<IPrepareRasterOverlayRendererResources>&
48  pPrepareRendererResources,
49  const std::shared_ptr<spdlog::logger>& pLogger,
50  const CesiumGeospatial::Projection& projection,
51  const CesiumGeometry::QuadtreeTilingScheme& tilingScheme,
52  const CesiumGeometry::Rectangle& coverageRectangle,
53  uint32_t minimumLevel,
54  uint32_t maximumLevel,
55  uint32_t imageWidth,
56  uint32_t imageHeight) noexcept;
57 
61  uint32_t getMinimumLevel() const noexcept { return this->_minimumLevel; }
62 
66  uint32_t getMaximumLevel() const noexcept { return this->_maximumLevel; }
67 
71  uint32_t getWidth() const noexcept { return this->_imageWidth; }
72 
76  uint32_t getHeight() const noexcept { return this->_imageHeight; }
77 
83  return this->_tilingScheme;
84  }
85 
96  const CesiumGeometry::Rectangle& rectangle,
97  const glm::dvec2& screenPixels);
98 
99 protected:
109 
110 private:
112  loadTileImage(RasterOverlayTile& overlayTile) override final;
113 
114  struct LoadedQuadtreeImage {
115  std::shared_ptr<LoadedRasterOverlayImage> pLoaded = nullptr;
116  std::optional<CesiumGeometry::Rectangle> subset = std::nullopt;
117  };
118 
120  getQuadtreeTile(const CesiumGeometry::QuadtreeTileID& tileID);
121 
132  std::vector<CesiumAsync::SharedFuture<LoadedQuadtreeImage>>
133  mapRasterTilesToGeometryTile(
134  const CesiumGeometry::Rectangle& geometryRectangle,
135  const glm::dvec2 targetScreenPixels);
136 
137  void unloadCachedTiles();
138 
139  struct CombinedImageMeasurements {
140  CesiumGeometry::Rectangle rectangle;
141  int32_t widthPixels;
142  int32_t heightPixels;
143  int32_t channels;
144  int32_t bytesPerChannel;
145  };
146 
147  static CombinedImageMeasurements measureCombinedImage(
148  const CesiumGeometry::Rectangle& targetRectangle,
149  const std::vector<LoadedQuadtreeImage>& images);
150 
151  static LoadedRasterOverlayImage combineImages(
152  const CesiumGeometry::Rectangle& targetRectangle,
153  const CesiumGeospatial::Projection& projection,
154  std::vector<LoadedQuadtreeImage>&& images);
155 
156  uint32_t _minimumLevel;
157  uint32_t _maximumLevel;
158  uint32_t _imageWidth;
159  uint32_t _imageHeight;
161 
162  struct CacheEntry {
165  };
166 
167  // Tiles at the beginning of this list are the least recently used (oldest),
168  // while the tiles at the end are most recently used (newest).
169  using TileLeastRecentlyUsedList = std::list<CacheEntry>;
170  TileLeastRecentlyUsedList _tilesOldToRecent;
171 
172  // Allows a Future to be looked up by quadtree tile ID.
173  std::unordered_map<
175  TileLeastRecentlyUsedList::iterator>
176  _tileLookup;
177 
178  std::atomic<int64_t> _cachedBytes;
179 };
180 } // 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
Defines how a rectangular region is divided into quadtree tiles.
uint32_t getHeight() const noexcept
Returns the image height of this instance, in pixels.
uint32_t computeLevelFromTargetScreenPixels(const CesiumGeometry::Rectangle &rectangle, const glm::dvec2 &screenPixels)
Computes the best quadtree level to use for an image intended to cover a given projected rectangle wh...
uint32_t getMinimumLevel() const noexcept
Returns the minimum tile level of this instance.
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
Creates a new instance.
virtual CesiumAsync::Future< LoadedRasterOverlayImage > loadQuadtreeTileImage(const CesiumGeometry::QuadtreeTileID &tileID) const =0
Asynchronously loads a tile in the quadtree.
const CesiumGeometry::QuadtreeTilingScheme & getTilingScheme() const noexcept
Returns the CesiumGeometry::QuadtreeTilingScheme of this instance.
uint32_t getWidth() const noexcept
Returns the image width of this instance, in pixels.
uint32_t getMaximumLevel() const noexcept
Returns the maximum tile level of this instance.
Provides individual tiles for a RasterOverlay on demand.
Raster image data for a tile in a quadtree.
A smart pointer that calls addReference and releaseReference on the controlled object.
std::variant< GeographicProjection, WebMercatorProjection > Projection
A projection.
Definition: Projection.h:25
Classes for raster overlays, which allow draping massive 2D textures over a model.
Uniquely identifies a node in a quadtree.
A 2D rectangle.
Definition: Rectangle.h:14