Skip to content

Commit

Permalink
Add ImplicitTiling class.
Browse files Browse the repository at this point in the history
  • Loading branch information
kring committed Nov 7, 2023
1 parent bb9caf1 commit 22b447e
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 67 deletions.
48 changes: 48 additions & 0 deletions Cesium3DTilesContent/include/Cesium3DTilesContent/ImplicitTiling.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#pragma once

#include <string>

namespace CesiumGeometry {
struct QuadtreeTileID;
struct OctreeTileID;
} // namespace CesiumGeometry

namespace Cesium3DTilesContent {

/**
* @brief Helper functions for working with 3D Tiles implicit tiling.
*/
class ImplicitTiling {
public:
/**
* @brief Resolves a templatized implicit tiling URL with a quadtree tile ID.
*
* @param baseUrl The base URL that is used to resolve the urlTemplate if it
* is a relative path.
* @param urlTemplate The templatized URL.
* @param quadtreeID The quadtree ID to use in resolving the parameters in the
* URL template.
* @return The resolved URL.
*/
static std::string resolveUrl(
const std::string& baseUrl,
const std::string& urlTemplate,
const CesiumGeometry::QuadtreeTileID& quadtreeID);

/**
* @brief Resolves a templatized implicit tiling URL with an octree tile ID.
*
* @param baseUrl The base URL that is used to resolve the urlTemplate if it
* is a relative path.
* @param urlTemplate The templatized URL.
* @param octreeID The octree ID to use in resolving the parameters in the
* URL template.
* @return The resolved URL.
*/
static std::string resolveUrl(
const std::string& baseUrl,
const std::string& urlTemplate,
const CesiumGeometry::OctreeTileID& octreeID);
};

} // namespace Cesium3DTilesContent
57 changes: 57 additions & 0 deletions Cesium3DTilesContent/src/ImplicitTiling.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include <Cesium3DTilesContent/ImplicitTiling.h>
#include <CesiumGeometry/OctreeTileID.h>
#include <CesiumGeometry/QuadtreeTileID.h>
#include <CesiumUtility/Uri.h>

namespace Cesium3DTilesContent {

/*static*/ std::string ImplicitTiling::resolveUrl(
const std::string& baseUrl,
const std::string& urlTemplate,
const CesiumGeometry::QuadtreeTileID& quadtreeID) {
std::string url = CesiumUtility::Uri::substituteTemplateParameters(
urlTemplate,
[&quadtreeID](const std::string& placeholder) {
if (placeholder == "level") {
return std::to_string(quadtreeID.level);
}
if (placeholder == "x") {
return std::to_string(quadtreeID.x);
}
if (placeholder == "y") {
return std::to_string(quadtreeID.y);
}

return placeholder;
});

return CesiumUtility::Uri::resolve(baseUrl, url);
}

/*static*/ std::string ImplicitTiling::resolveUrl(
const std::string& baseUrl,
const std::string& urlTemplate,
const CesiumGeometry::OctreeTileID& octreeID) {
std::string url = CesiumUtility::Uri::substituteTemplateParameters(
urlTemplate,
[&octreeID](const std::string& placeholder) {
if (placeholder == "level") {
return std::to_string(octreeID.level);
}
if (placeholder == "x") {
return std::to_string(octreeID.x);
}
if (placeholder == "y") {
return std::to_string(octreeID.y);
}
if (placeholder == "z") {
return std::to_string(octreeID.z);
}

return placeholder;
});

return CesiumUtility::Uri::resolve(baseUrl, url);
}

} // namespace Cesium3DTilesContent
39 changes: 9 additions & 30 deletions Cesium3DTilesSelection/src/ImplicitOctreeLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "logTileLoadResult.h"

#include <Cesium3DTilesContent/GltfConverters.h>
#include <Cesium3DTilesContent/ImplicitTiling.h>
#include <Cesium3DTilesSelection/Tile.h>
#include <CesiumAsync/IAssetResponse.h>
#include <CesiumUtility/Uri.h>
Expand Down Expand Up @@ -274,8 +275,10 @@ ImplicitOctreeLoader::loadTileContent(const TileLoadInput& loadInput) {
this->_loadedSubtrees[subtreeLevelIdx].find(subtreeMortonIdx);
if (subtreeIt == this->_loadedSubtrees[subtreeLevelIdx].end()) {
// subtree is not loaded, so load it now.
std::string subtreeUrl =
resolveUrl(this->_baseUrl, this->_subtreeUrlTemplate, subtreeID);
std::string subtreeUrl = ImplicitTiling::resolveUrl(
this->_baseUrl,
this->_subtreeUrlTemplate,
subtreeID);
return SubtreeAvailability::loadSubtree(
3,
asyncSystem,
Expand Down Expand Up @@ -311,8 +314,10 @@ ImplicitOctreeLoader::loadTileContent(const TileLoadInput& loadInput) {
TileLoadResultState::Success});
}

std::string tileUrl =
resolveUrl(this->_baseUrl, this->_contentUrlTemplate, *pOctreeID);
std::string tileUrl = ImplicitTiling::resolveUrl(
this->_baseUrl,
this->_contentUrlTemplate,
*pOctreeID);
return requestTileContent(
pLogger,
asyncSystem,
Expand Down Expand Up @@ -389,30 +394,4 @@ void ImplicitOctreeLoader::addSubtreeAvailability(
subtreeMortonID,
std::move(subtreeAvailability));
}

std::string ImplicitOctreeLoader::resolveUrl(
const std::string& baseUrl,
const std::string& urlTemplate,
const CesiumGeometry::OctreeTileID& octreeID) {
std::string url = CesiumUtility::Uri::substituteTemplateParameters(
urlTemplate,
[&octreeID](const std::string& placeholder) {
if (placeholder == "level") {
return std::to_string(octreeID.level);
}
if (placeholder == "x") {
return std::to_string(octreeID.x);
}
if (placeholder == "y") {
return std::to_string(octreeID.y);
}
if (placeholder == "z") {
return std::to_string(octreeID.z);
}

return placeholder;
});

return CesiumUtility::Uri::resolve(baseUrl, url);
}
} // namespace Cesium3DTilesSelection
5 changes: 0 additions & 5 deletions Cesium3DTilesSelection/src/ImplicitOctreeLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ class ImplicitOctreeLoader : public TilesetContentLoader {
Cesium3DTilesContent::SubtreeAvailability&& subtreeAvailability);

private:
static std::string resolveUrl(
const std::string& baseUrl,
const std::string& urlTemplate,
const CesiumGeometry::OctreeTileID& octreeID);

std::string _baseUrl;
std::string _contentUrlTemplate;
std::string _subtreeUrlTemplate;
Expand Down
36 changes: 9 additions & 27 deletions Cesium3DTilesSelection/src/ImplicitQuadtreeLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "logTileLoadResult.h"

#include <Cesium3DTilesContent/GltfConverters.h>
#include <Cesium3DTilesContent/ImplicitTiling.h>
#include <Cesium3DTilesSelection/Tile.h>
#include <CesiumAsync/IAssetResponse.h>
#include <CesiumGeometry/QuadtreeTileID.h>
Expand Down Expand Up @@ -297,8 +298,10 @@ ImplicitQuadtreeLoader::loadTileContent(const TileLoadInput& loadInput) {
this->_loadedSubtrees[subtreeLevelIdx].find(subtreeMortonIdx);
if (subtreeIt == this->_loadedSubtrees[subtreeLevelIdx].end()) {
// subtree is not loaded, so load it now.
std::string subtreeUrl =
resolveUrl(this->_baseUrl, this->_subtreeUrlTemplate, subtreeID);
std::string subtreeUrl = ImplicitTiling::resolveUrl(
this->_baseUrl,
this->_subtreeUrlTemplate,
subtreeID);
return SubtreeAvailability::loadSubtree(
2,
asyncSystem,
Expand Down Expand Up @@ -334,8 +337,10 @@ ImplicitQuadtreeLoader::loadTileContent(const TileLoadInput& loadInput) {
TileLoadResultState::Success});
}

std::string tileUrl =
resolveUrl(this->_baseUrl, this->_contentUrlTemplate, *pQuadtreeID);
std::string tileUrl = ImplicitTiling::resolveUrl(
this->_baseUrl,
this->_contentUrlTemplate,
*pQuadtreeID);
return requestTileContent(
pLogger,
asyncSystem,
Expand Down Expand Up @@ -410,27 +415,4 @@ void ImplicitQuadtreeLoader::addSubtreeAvailability(
subtreeMortonID,
std::move(subtreeAvailability));
}

std::string ImplicitQuadtreeLoader::resolveUrl(
const std::string& baseUrl,
const std::string& urlTemplate,
const CesiumGeometry::QuadtreeTileID& quadtreeID) {
std::string url = CesiumUtility::Uri::substituteTemplateParameters(
urlTemplate,
[&quadtreeID](const std::string& placeholder) {
if (placeholder == "level") {
return std::to_string(quadtreeID.level);
}
if (placeholder == "x") {
return std::to_string(quadtreeID.x);
}
if (placeholder == "y") {
return std::to_string(quadtreeID.y);
}

return placeholder;
});

return CesiumUtility::Uri::resolve(baseUrl, url);
}
} // namespace Cesium3DTilesSelection
5 changes: 0 additions & 5 deletions Cesium3DTilesSelection/src/ImplicitQuadtreeLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ class ImplicitQuadtreeLoader : public TilesetContentLoader {
Cesium3DTilesContent::SubtreeAvailability&& subtreeAvailability);

private:
static std::string resolveUrl(
const std::string& baseUrl,
const std::string& urlTemplate,
const CesiumGeometry::QuadtreeTileID& quadtreeID);

std::string _baseUrl;
std::string _contentUrlTemplate;
std::string _subtreeUrlTemplate;
Expand Down

0 comments on commit 22b447e

Please sign in to comment.