Skip to content

Commit

Permalink
Height queries against implicit tilesets.
Browse files Browse the repository at this point in the history
  • Loading branch information
kring committed Sep 11, 2024
1 parent 349bc22 commit b7a4244
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 29 deletions.
22 changes: 18 additions & 4 deletions Cesium3DTilesSelection/include/Cesium3DTilesSelection/Tile.h
Original file line number Diff line number Diff line change
Expand Up @@ -501,10 +501,24 @@ class CESIUM3DTILESSELECTION_API Tile final {

void setState(TileLoadState state) noexcept;

bool shouldContentContinueUpdating() const noexcept;
/**
* @brief Gets a flag indicating whether this tile might have latent children.
* Latent children don't exist in the `_children` property, but can be created
* by the {@link TilesetContentLoader}.
*
* When true, this tile might have children that can be created by the
* TilesetContentLoader but that aren't reflected in the `_children` property
* yet. For example, in implicit tiling, we save memory by only creating
* explicit Tile instances from implicit availability as those instances are
* needed. When this flag is true, that creation of explicit instances hasn't
* been done yet for this tile.
*
* If this flag is false, the children have already been created, if they
* exist. The tile may still have no children because it is a leaf node.
*/
bool getMightHaveLatentChildren() const noexcept;

void
setContentShouldContinueUpdating(bool shouldContentContinueUpdating) noexcept;
void setMightHaveLatentChildren(bool mightHaveLatentChildren) noexcept;

// Position in bounding-volume hierarchy.
Tile* _pParent;
Expand All @@ -528,7 +542,7 @@ class CESIUM3DTILESSELECTION_API Tile final {
TileContent _content;
TilesetContentLoader* _pLoader;
TileLoadState _loadState;
bool _shouldContentContinueUpdating;
bool _mightHaveLatentChildren;

// mapped raster overlay
std::vector<RasterMappedTo3DTile> _rasterTiles;
Expand Down
16 changes: 8 additions & 8 deletions Cesium3DTilesSelection/src/Tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Tile::Tile(
_content{std::forward<TileContentArgs>(args)...},
_pLoader{pLoader},
_loadState{loadState},
_shouldContentContinueUpdating{true} {}
_mightHaveLatentChildren{true} {}

Tile::Tile(Tile&& rhs) noexcept
: _pParent(rhs._pParent),
Expand All @@ -74,7 +74,7 @@ Tile::Tile(Tile&& rhs) noexcept
_content(std::move(rhs._content)),
_pLoader{rhs._pLoader},
_loadState{rhs._loadState},
_shouldContentContinueUpdating{rhs._shouldContentContinueUpdating} {
_mightHaveLatentChildren{rhs._mightHaveLatentChildren} {
// since children of rhs will have the parent pointed to rhs,
// we will reparent them to this tile as rhs will be destroyed after this
for (Tile& tile : this->_children) {
Expand Down Expand Up @@ -105,7 +105,7 @@ Tile& Tile::operator=(Tile&& rhs) noexcept {
this->_content = std::move(rhs._content);
this->_pLoader = rhs._pLoader;
this->_loadState = rhs._loadState;
this->_shouldContentContinueUpdating = rhs._shouldContentContinueUpdating;
this->_mightHaveLatentChildren = rhs._mightHaveLatentChildren;
}

return *this;
Expand Down Expand Up @@ -227,12 +227,12 @@ void Tile::setParent(Tile* pParent) noexcept { this->_pParent = pParent; }

void Tile::setState(TileLoadState state) noexcept { this->_loadState = state; }

bool Tile::shouldContentContinueUpdating() const noexcept {
return this->_shouldContentContinueUpdating;
bool Tile::getMightHaveLatentChildren() const noexcept {
return this->_mightHaveLatentChildren;
}

void Tile::setContentShouldContinueUpdating(
bool shouldContentContinueUpdating) noexcept {
this->_shouldContentContinueUpdating = shouldContentContinueUpdating;
void Tile::setMightHaveLatentChildren(bool mightHaveLatentChildren) noexcept {
this->_mightHaveLatentChildren = mightHaveLatentChildren;
}

} // namespace Cesium3DTilesSelection
4 changes: 4 additions & 0 deletions Cesium3DTilesSelection/src/Tileset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,10 @@ bool Tileset::tryCompleteHeightRequest(

auto checkTile =
[this, &tilesNeedingLoading, &tileStillNeedsLoading](Tile* pTile) {
this->_pTilesetContentManager->createLatentChildrenIfNecessary(
*pTile,
this->getOptions());

TileLoadState state = pTile->getState();
if (state == TileLoadState::Unloading) {
// This tile is in the process of unloading, which must complete
Expand Down
31 changes: 15 additions & 16 deletions Cesium3DTilesSelection/src/TilesetContentManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1070,16 +1070,22 @@ void TilesetContentManager::updateTileContent(
updateDoneState(tile, tilesetOptions);
}

if (tile.shouldContentContinueUpdating()) {
this->createLatentChildrenIfNecessary(tile, tilesetOptions);
}

void TilesetContentManager::createLatentChildrenIfNecessary(
Tile& tile,
const TilesetOptions& tilesetOptions) {
if (tile.getMightHaveLatentChildren()) {
TileChildrenResult childrenResult =
this->_pLoader->createTileChildren(tile, tilesetOptions.ellipsoid);
if (childrenResult.state == TileLoadResultState::Success) {
tile.createChildTiles(std::move(childrenResult.children));
}

bool shouldTileContinueUpdated =
bool mightStillHaveLatentChildren =
childrenResult.state == TileLoadResultState::RetryLater;
tile.setContentShouldContinueUpdating(shouldTileContinueUpdated);
tile.setMightHaveLatentChildren(mightStillHaveLatentChildren);
}
}

Expand Down Expand Up @@ -1379,19 +1385,12 @@ void TilesetContentManager::updateContentLoadedState(
void TilesetContentManager::updateDoneState(
Tile& tile,
const TilesetOptions& tilesetOptions) {
// The reason for this method to terminate early when
// Tile::shouldContentContinueUpdating() returns true is that: When a tile has
// Tile::shouldContentContinueUpdating() to be true, it means the tile's
// children need to be created by the
// TilesetContentLoader::createTileChildren() which is invoked in the
// TilesetContentManager::updateTileContent() method. In the
// updateDoneState(), RasterOverlayTiles that are mapped to the tile will
// begin updating. If there are more RasterOverlayTiles with higher LOD and
// the current tile is a leaf, more upsample children will be created for that
// tile. So to accurately determine if a tile is a leaf, it needs the tile to
// have no children and Tile::shouldContentContinueUpdating() to return false
// which means the loader has no more children for this tile.
if (tile.shouldContentContinueUpdating()) {
if (tile.getMightHaveLatentChildren()) {
// This tile might have latent children, so we don't know yet whether it has
// children or not. We need to know that before we can continue this
// function, which will decide whether or not to create upsampled children
// for this tile. It only makes sense to create upsampled children for a
// tile that definitely doesn't have real children.
return;
}

Expand Down
4 changes: 4 additions & 0 deletions Cesium3DTilesSelection/src/TilesetContentManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ class TilesetContentManager

void updateTileContent(Tile& tile, const TilesetOptions& tilesetOptions);

void createLatentChildrenIfNecessary(
Tile& tile,
const TilesetOptions& tilesetOptions);

bool unloadTileContent(Tile& tile);

void waitUntilIdle();
Expand Down
2 changes: 1 addition & 1 deletion Cesium3DTilesSelection/test/MockTilesetContentManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ void MockTilesetContentManagerTestFixture::setTileLoadState(
void MockTilesetContentManagerTestFixture::setTileShouldContinueUpdating(
Cesium3DTilesSelection::Tile& tile,
bool shouldContinueUpdating) {
tile.setContentShouldContinueUpdating(shouldContinueUpdating);
tile.setMightHaveLatentChildren(shouldContinueUpdating);
}
} // namespace Cesium3DTilesSelection

0 comments on commit b7a4244

Please sign in to comment.