Skip to content

Commit

Permalink
Much refactoring for raster tiles to follow same process->requeue pat…
Browse files Browse the repository at this point in the history
…tern as tiles

Still need a last bit of debugging. The raster processing lambdas aren't completing
  • Loading branch information
csciguy8 committed Jan 12, 2024
1 parent 409e290 commit 1e11977
Show file tree
Hide file tree
Showing 18 changed files with 437 additions and 677 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,29 +105,28 @@ class CESIUM3DTILESSELECTION_API QuadtreeRasterOverlayTileProvider
* @return A Future that resolves to the loaded image data or error
* information.
*/
virtual CesiumAsync::Future<LoadedRasterOverlayImage>
loadQuadtreeTileImage(const CesiumGeometry::QuadtreeTileID& tileID) const = 0;

virtual bool getLoadQuadtreeTileImageWork(
virtual CesiumAsync::Future<RasterLoadResult> loadQuadtreeTileImage(
const CesiumGeometry::QuadtreeTileID& tileID,
std::string& outUrl) = 0;
const ResponseDataMap& responsesByUrl) const = 0;

private:
virtual CesiumAsync::Future<LoadedRasterOverlayImage>
loadTileImage(RasterOverlayTile& overlayTile) override final;
virtual CesiumAsync::Future<RasterLoadResult> loadTileImage(
RasterOverlayTile& overlayTile,
const ResponseDataMap& responsesByUrl) override final;

virtual void getLoadTileImageWork(
RasterOverlayTile& overlayTile,
RequestDataVec& outRequests,
RequestData& outRequest,
RasterProcessingCallback& outCallback) override;

struct LoadedQuadtreeImage {
std::shared_ptr<LoadedRasterOverlayImage> pLoaded = nullptr;
std::shared_ptr<RasterLoadResult> pResult = nullptr;
std::optional<CesiumGeometry::Rectangle> subset = std::nullopt;
};

CesiumAsync::SharedFuture<LoadedQuadtreeImage>
getQuadtreeTile(const CesiumGeometry::QuadtreeTileID& tileID);
CesiumAsync::SharedFuture<LoadedQuadtreeImage> getQuadtreeTile(
const CesiumGeometry::QuadtreeTileID& tileID,
const ResponseDataMap& responsesByUrl);

/**
* @brief Map raster tiles to geometry tile.
Expand All @@ -139,15 +138,11 @@ class CESIUM3DTILESSELECTION_API QuadtreeRasterOverlayTileProvider
* data that is required to cover the rectangle with the given geometric
* error.
*/
std::vector<CesiumAsync::SharedFuture<LoadedQuadtreeImage>>
mapRasterTilesToGeometryTile(
const CesiumGeometry::Rectangle& geometryRectangle,
const glm::dvec2 targetScreenPixels);

void getMapRasterTilesToGeometryTileWork(
void mapRasterTilesToGeometryTile(
const CesiumGeometry::Rectangle& geometryRectangle,
const glm::dvec2 targetScreenPixels,
RequestDataVec& outRequests);
const ResponseDataMap& responsesByUrl,
std::vector<CesiumAsync::SharedFuture<LoadedQuadtreeImage>>& outTiles);

void unloadCachedTiles();

Expand All @@ -163,7 +158,7 @@ class CESIUM3DTILESSELECTION_API QuadtreeRasterOverlayTileProvider
const CesiumGeometry::Rectangle& targetRectangle,
const std::vector<LoadedQuadtreeImage>& images);

static LoadedRasterOverlayImage combineImages(
static RasterLoadResult combineImages(
const CesiumGeometry::Rectangle& targetRectangle,
const CesiumGeospatial::Projection& projection,
std::vector<LoadedQuadtreeImage>&& images);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,26 @@
namespace Cesium3DTilesSelection {

class Tile;
struct LoadedRasterOverlayImage;

typedef std::function<CesiumAsync::Future<LoadedRasterOverlayImage>(
struct RasterLoadResult {
std::optional<CesiumGltf::ImageCesium> image{};
CesiumGeometry::Rectangle rectangle = {};
std::vector<Credit> credits = {};
std::vector<std::string> errors{};
std::vector<std::string> warnings{};
bool moreDetailAvailable = false;

RequestData requestData;

RasterLoadState state = RasterLoadState::Unloaded;

void* pRendererResources = nullptr;
};

typedef std::function<CesiumAsync::Future<RasterLoadResult>(
RasterOverlayTile&,
RasterOverlayTileProvider*)>
RasterOverlayTileProvider*,
const ResponseDataMap&)>
RasterProcessingCallback;

/**
Expand Down Expand Up @@ -189,12 +204,13 @@ class RasterMappedTo3DTile final {
* false. Otherwise, it begins the asynchronous process to load the tile and
* returns true.
*/
CesiumAsync::Future<bool> loadThrottled(
CesiumAsync::Future<RasterLoadResult> loadThrottled(
CesiumAsync::AsyncSystem& callerAsync,
const ResponseDataMap& responsesByUrl,
RasterProcessingCallback rasterCallback) noexcept;

void getLoadThrottledWork(
RequestDataVec& outRequests,
RequestData& outRequest,
RasterProcessingCallback& outCallback);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,47 @@ struct Credit;
class RasterOverlay;
class RasterOverlayTileProvider;

enum class RasterLoadState {
/**
* @brief Indicator for a placeholder tile.
*/
Placeholder = -3,

/**
* @brief The image request or image creation failed.
*/
Failed = -2,

/**
* @brief
*/
RequestRequired = -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 Raster image data for a tile in a quadtree.
*
* Instances of this clas represent tiles of a quadtree that have
* Instances of this class 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
Expand All @@ -29,41 +66,6 @@ class RasterOverlayTileProvider;
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.
*
Expand All @@ -90,7 +92,7 @@ class RasterOverlayTile final
* @brief Constructs a placeholder tile for the tile provider.
*
* The {@link getState} of this instance will always be
* {@link LoadState::Placeholder}.
* {@link RasterLoadState::Placeholder}.
*
* @param tileProvider The {@link RasterOverlayTileProvider}. This object
* _must_ remain valid for the entire lifetime of the tile. If the tile
Expand Down Expand Up @@ -170,9 +172,9 @@ class RasterOverlayTile final
}

/**
* @brief Returns the current {@link LoadState}.
* @brief Returns the current {@link RasterLoadState}.
*/
LoadState getState() const noexcept { return this->_state; }
RasterLoadState getState() const noexcept { return this->_state; }

/**
* @brief Returns the list of {@link Credit}s needed for this tile.
Expand All @@ -185,7 +187,7 @@ class RasterOverlayTile final
* @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`}.
* this tile is {@link RasterLoadState `Loaded`} or {@link RasterLoadState `Done`}.
*
* @return The image data.
*/
Expand All @@ -197,7 +199,7 @@ class RasterOverlayTile final
* @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`}.
* this tile is {@link RasterLoadState `Loaded`} or {@link RasterLoadState `Done`}.
*
* @return The image data.
*/
Expand All @@ -206,11 +208,11 @@ class RasterOverlayTile final
/**
* @brief Create the renderer resources for the loaded image.
*
* If the {@link getState} of this tile is not {@link LoadState `Loaded`},
* If the {@link getState} of this tile is not {@link RasterLoadState `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`}.
* will change to {@link RasterLoadState `Done`}.
*/
void loadInMainThread();

Expand Down Expand Up @@ -243,7 +245,7 @@ class RasterOverlayTile final
friend class Tileset;
friend class TilesetContentManager;

void setState(LoadState newState) noexcept;
void setState(RasterLoadState newState) noexcept;

// This is a raw pointer instead of an IntrusivePointer in order to avoid
// circular references, particularly among a placeholder tile provider and
Expand All @@ -254,7 +256,7 @@ class RasterOverlayTile final
glm::dvec2 _targetScreenPixels;
CesiumGeometry::Rectangle _rectangle;
std::vector<Credit> _tileCredits;
LoadState _state;
RasterLoadState _state;
CesiumGltf::ImageCesium _image;
void* _pRendererResources;
MoreDetailAvailable _moreDetailAvailable;
Expand Down
Loading

0 comments on commit 1e11977

Please sign in to comment.