Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow access to Tileset-level metadata (schema, schemaUri, groups, metadata) #709

Merged
merged 33 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
31f0ed5
Expose Schema on Tileset.
kring Aug 18, 2023
0dbf930
Start reading metadata and groups properties.
kring Aug 18, 2023
056eecc
Give tileset a root "external" tile.
kring Aug 21, 2023
44ad786
Expose metadata on root tile and external tilesets.
kring Aug 21, 2023
789fed8
Support metadata on external tilesets.
kring Aug 21, 2023
e99b00d
Formatting.
kring Aug 21, 2023
79d33e2
Fix Clang/GCC compiler error.
kring Aug 21, 2023
8f8cb9b
Generate Reader classes, remove hand-written versions.
kring Aug 22, 2023
cfaaf4d
Add doc for readers.
kring Aug 22, 2023
c0fc8b6
More tileset metadata to a separate struct.
kring Aug 22, 2023
ef2ac5d
Add missing file.
kring Aug 22, 2023
c68207a
Add MetadataQuery class.
kring Aug 23, 2023
056edba
Add a test based on material variants.
kring Aug 23, 2023
20cbc17
Formatting.
kring Aug 23, 2023
d0a3091
Fix dodgy destructor declaration.
kring Aug 23, 2023
ea6a74e
Fix another clang warning.
kring Aug 23, 2023
3585ba3
Merge remote-tracking branch 'origin/json-read-tweaks' into tileset-m…
kring Aug 23, 2023
532d4e7
Merge remote-tracking branch 'origin/generated-readers' into tileset-…
kring Aug 23, 2023
d24e5f9
Update CHANGES.md, remove unnecessary change.
kring Aug 23, 2023
fe26c94
Remove unnecessary forward declaration.
kring Aug 23, 2023
9f73df1
Merge remote-tracking branch 'origin/generated-readers' into tileset-…
kring Aug 24, 2023
9a1abb2
Add missing dll export of FoundMetadataProperty.
kring Aug 24, 2023
153890d
Add `Tileset::loadMetadata`.
kring Aug 28, 2023
6145b54
Update CHANGES.md.
kring Aug 28, 2023
51e798e
Add test for async schema loading.
kring Aug 28, 2023
946887a
Add getArrayOfStrings helper to JsonValue.
kring Aug 28, 2023
5bf8a7b
struct -> class
kring Aug 28, 2023
31fc053
Fix clang warning.
kring Aug 28, 2023
3f40341
Fix VS2017/2019 warning.
kring Aug 28, 2023
5637a68
Merge remote-tracking branch 'origin/generated-readers' into tileset-…
kring Aug 30, 2023
7c8f4b1
Fix test failures, change some CHECK to REQUIRE.
kring Aug 30, 2023
57476c3
Changes from review.
kring Aug 30, 2023
a2d5b92
Fix misnaming.
kring Aug 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add getArrayOfStrings helper to JsonValue.
  • Loading branch information
kring committed Aug 28, 2023
commit 946887abe7dea03f4b0e3fd83b100fd946a19bae
42 changes: 7 additions & 35 deletions Cesium3DTilesSelection/test/TestTilesetSelectionAlgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1272,13 +1272,8 @@ TEST_CASE("Allows access to material variants") {
"Names of material variants to be expected in the glTF assets");
REQUIRE(found1->propertyValue.isArray());

const JsonValue::Array& variantsJson = found1->propertyValue.getArray();
std::vector<std::string> variants(variantsJson.size());
std::transform(
variantsJson.begin(),
variantsJson.end(),
variants.begin(),
[](const JsonValue& value) { return value.getStringOrDefault(""); });
std::vector<std::string> variants =
found1->propertyValue.getArrayOfStrings("");
REQUIRE(variants.size() == 4);
CHECK(variants[0] == "RGB");
CHECK(variants[1] == "RRR");
Expand All @@ -1287,8 +1282,6 @@ TEST_CASE("Allows access to material variants") {

std::vector<std::vector<std::string>> variantsByGroup;
for (const Cesium3DTiles::GroupMetadata& group : pMetadata->groups) {
std::vector<std::string>& groupVariants = variantsByGroup.emplace_back();

std::optional<Cesium3DTiles::FoundMetadataProperty> found2 =
Cesium3DTiles::MetadataQuery::findFirstPropertyWithSemantic(
*pMetadata->schema,
Expand All @@ -1297,12 +1290,7 @@ TEST_CASE("Allows access to material variants") {
REQUIRE(found2);
REQUIRE(found2->propertyValue.isArray());

const JsonValue::Array& groupVariantsJson =
found2->propertyValue.getArray();
groupVariants.reserve(groupVariantsJson.size());
for (size_t i = 0; i < groupVariantsJson.size(); ++i) {
groupVariants.emplace_back(groupVariantsJson[i].getStringOrDefault(""));
}
variantsByGroup.emplace_back(found2->propertyValue.getArrayOfStrings(""));
}

std::vector<std::vector<std::string>> expected = {
Expand Down Expand Up @@ -1375,15 +1363,8 @@ TEST_CASE("Allows access to material variants in an external schema") {
"Names of material variants to be expected in the glTF assets");
REQUIRE(found1->propertyValue.isArray());

const JsonValue::Array& variantsJson = found1->propertyValue.getArray();
std::vector<std::string> variants(variantsJson.size());
std::transform(
variantsJson.begin(),
variantsJson.end(),
variants.begin(),
[](const JsonValue& value) {
return value.getStringOrDefault("");
});
std::vector<std::string> variants =
found1->propertyValue.getArrayOfStrings("");
REQUIRE(variants.size() == 4);
CHECK(variants[0] == "RGB");
CHECK(variants[1] == "RRR");
Expand All @@ -1392,24 +1373,15 @@ TEST_CASE("Allows access to material variants in an external schema") {

std::vector<std::vector<std::string>> variantsByGroup;
for (const Cesium3DTiles::GroupMetadata& group : pMetadata->groups) {
std::vector<std::string>& groupVariants =
variantsByGroup.emplace_back();

std::optional<Cesium3DTiles::FoundMetadataProperty> found2 =
Cesium3DTiles::MetadataQuery::findFirstPropertyWithSemantic(
*pMetadata->schema,
group,
"MATERIAL_VARIANTS");
REQUIRE(found2);
REQUIRE(found2->propertyValue.isArray());

const JsonValue::Array& groupVariantsJson =
found2->propertyValue.getArray();
groupVariants.reserve(groupVariantsJson.size());
for (size_t i = 0; i < groupVariantsJson.size(); ++i) {
groupVariants.emplace_back(
groupVariantsJson[i].getStringOrDefault(""));
}
variantsByGroup.emplace_back(
found2->propertyValue.getArrayOfStrings(""));
}

std::vector<std::vector<std::string>> expected = {
Expand Down
11 changes: 11 additions & 0 deletions CesiumUtility/include/CesiumUtility/JsonValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,17 @@ class CESIUMUTILITY_API JsonValue final {
return std::get<JsonValue::Array>(this->value);
}

/**
* @brief Gets an array of strings from the value.
*
* @param defaultString The default string to include in the array for an
* element that is not a string.
* @return The array of strings, or an empty array if this value is not an
* array at all.
*/
[[nodiscard]] std::vector<std::string>
getArrayOfStrings(const std::string& defaultString) const;

/**
* @brief Gets the bool from the value.
* @return The bool.
Expand Down
18 changes: 18 additions & 0 deletions CesiumUtility/src/JsonValue.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "CesiumUtility/JsonValue.h"

#include <algorithm>

namespace CesiumUtility {

const JsonValue* JsonValue::getValuePtrForKey(const std::string& key) const {
Expand Down Expand Up @@ -31,3 +33,19 @@ JsonValue* JsonValue::getValuePtrForKey(const std::string& key) {
}

} // namespace CesiumUtility
std::vector<std::string> CesiumUtility::JsonValue::getArrayOfStrings(
const std::string& defaultString) const {
if (!this->isArray())
return std::vector<std::string>();

const JsonValue::Array& array = this->getArray();
std::vector<std::string> result(array.size());
std::transform(
array.begin(),
array.end(),
result.begin(),
[&defaultString](const JsonValue& value) {
return value.getStringOrDefault(defaultString);
});
return result;
}