diff --git a/CHANGES.md b/CHANGES.md index 13c2ed0d8..5343e5d35 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,27 @@ # Change Log +### ? - ? + +##### Breaking Changes :mega: + +Many classes have been overhauled to support `EXT_mesh_features` and `EXT_structural_metadata`. This includes the following changes: + +- Replaced `FeatureIDTextureView` with `FeatureIdTextureView`, which views a `ExtensionExtMeshFeaturesFeatureIdTexture`. + - Replaced `FeatureIDTextureViewStatus` with `FeatureIdTextureViewStatus`. + - Replaced `getChannel` with `getChannels`. This retrieves the channels as a vector of integers, instead of a single integer. + - Renamed `getTextureCoordinateAttributeId` to `getTexCoordSetIndex`. +- Replaced `MetadataFeatureTableView` with `PropertyTableView`, which views a `ExtensionExtStructuralMetadataPropertyTable`. + - Added `PropertyTableViewStatus` to indicate whether or not `PropertyTableView` is valid. +- Renamed `MetadataArrayView` to `PropertyArrayView`. +- Replaced `FeatureTextureView` with `PropertyTextureView`, which views a `ExtensionExtMeshFeaturesPropertyTexture`. + - Replaced `FeatureTextureViewStatus` with `PropertyTextureViewStatus`. +- Replaced `FeatureTexturePropertyView` with `PropertyTexturePropertyView`, which views a `ExtensionExtMeshFeaturesPropertyTextureProperty`. + - Replaced `FeatureTexturePropertyViewStatus` with `PropertyTexturePropertyViewStatus`. +- Refactored the `PropertyType` enum to reflect the values of `type` in an `ExtensionExtStructuralMetadataClassProperty`. +- Added the `PropertyComponentType` enum to reflect the values of `componentType` in an `ExtensionExtStructuralMetadataClassProperty`. + +Additionally, views of the data contained by `EXT_feature_metadata` will no longer supported by Cesium Native. The extension will still be parsed, but it will log a warning. Batch tables will also be converted to `EXT_structural_metadata` instead of `EXT_feature_metadata`. + ### v0.25.0 - 2023-06-01 ##### Additions :tada: diff --git a/Cesium3DTilesSelection/src/BatchTableToGltfStructuralMetadata.cpp b/Cesium3DTilesSelection/src/BatchTableToGltfStructuralMetadata.cpp index 1262edbc8..9879ff418 100644 --- a/Cesium3DTilesSelection/src/BatchTableToGltfStructuralMetadata.cpp +++ b/Cesium3DTilesSelection/src/BatchTableToGltfStructuralMetadata.cpp @@ -6,8 +6,8 @@ #include #include #include -#include -#include +#include +#include #include #include @@ -19,7 +19,6 @@ #include using namespace CesiumGltf; -using namespace CesiumGltf::StructuralMetadata; using namespace Cesium3DTilesSelection::CesiumImpl; namespace Cesium3DTilesSelection { @@ -121,82 +120,83 @@ struct CompatibleTypes { // MaskedType or MaskedArrayType, they are considered incompatible with the // other type. private: - std::variant type; + std::variant _type; public: - CompatibleTypes() : type(){}; + CompatibleTypes() : _type(){}; - CompatibleTypes(const MaskedType& maskedType) : type(maskedType){}; + CompatibleTypes(const MaskedType& maskedType) : _type(maskedType){}; CompatibleTypes(const MaskedArrayType& maskedArrayType) - : type(maskedArrayType){}; + : _type(maskedArrayType){}; /** * Whether this is exclusively compatible with array types. */ bool isExclusivelyArray() const { - return std::holds_alternative(type); + return std::holds_alternative(_type); } /** * Marks as incompatible with every type. Fully-incompatible types will be * treated as strings. */ - void makeIncompatible() { type = MaskedType(false); } + void makeIncompatible() { _type = MaskedType(false); } /** * Merges a MaskedType into this CompatibleTypes. */ void operator&=(const MaskedType& inMaskedType) { - if (std::holds_alternative(type)) { - MaskedType& maskedType = std::get(type); + if (std::holds_alternative(_type)) { + MaskedType& maskedType = std::get(_type); maskedType &= inMaskedType; return; } - if (std::holds_alternative(type)) { + if (std::holds_alternative(_type)) { makeIncompatible(); return; } - type = inMaskedType; + _type = inMaskedType; } /** * Merges a MaskedArrayType into this CompatibleTypes. */ void operator&=(const MaskedArrayType& inArrayType) { - if (std::holds_alternative(type)) { - MaskedArrayType& arrayType = std::get(type); + if (std::holds_alternative(_type)) { + MaskedArrayType& arrayType = std::get(_type); arrayType &= inArrayType; return; } - if (std::holds_alternative(type)) { + if (std::holds_alternative(_type)) { makeIncompatible(); return; } - type = inArrayType; + _type = inArrayType; } /** * Merges another CompatibleTypes into this one. */ void operator&=(const CompatibleTypes& inCompatibleTypes) { - if (std::holds_alternative(inCompatibleTypes.type)) { + if (std::holds_alternative(inCompatibleTypes._type)) { // The other CompatibleTypes is compatible with everything, so it does not // change this one. return; } - if (std::holds_alternative(inCompatibleTypes.type)) { + if (std::holds_alternative(inCompatibleTypes._type)) { const MaskedArrayType& arrayType = - std::get(inCompatibleTypes.type); + std::get(inCompatibleTypes._type); operator&=(arrayType); return; } - const MaskedType& maskedType = std::get(inCompatibleTypes.type); + const MaskedType& maskedType = + std::get(inCompatibleTypes._type); operator&=(maskedType); } @@ -206,11 +206,11 @@ struct CompatibleTypes { * MaskedType. */ MaskedType toMaskedType() const { - if (std::holds_alternative(type)) { - return std::get(type); + if (std::holds_alternative(_type)) { + return std::get(_type); } - bool isArray = std::holds_alternative(type); + bool isArray = std::holds_alternative(_type); return MaskedType(!isArray); } @@ -220,11 +220,11 @@ struct CompatibleTypes { * incompatible MaskedArrayType. */ MaskedArrayType toMaskedArrayType() const { - if (std::holds_alternative(type)) { - return std::get(type); + if (std::holds_alternative(_type)) { + return std::get(_type); } - bool isNonArray = std::holds_alternative(type); + bool isNonArray = std::holds_alternative(_type); return MaskedArrayType(!isNonArray); } }; @@ -307,7 +307,7 @@ int64_t roundUp(int64_t num, int64_t multiple) noexcept { } template bool isInRangeForSignedInteger(int64_t value) noexcept { - // this only work if sizeof(T) is smaller than int64_t + // This only works if sizeof(T) is smaller than int64_t static_assert( !std::is_same_v && !std::is_same_v && !std::is_same_v); @@ -960,7 +960,8 @@ void updateBooleanArrayProperty( const TValueGetter& propertyValue) { assert(propertyValue.size() >= propertyTable.count); - classProperty.type = "BOOLEAN"; + classProperty.type = + ExtensionExtStructuralMetadataClassProperty::Type::BOOLEAN; classProperty.array = true; // Fixed-length array of booleans @@ -1494,6 +1495,7 @@ void convertBatchTableToGltfStructuralMetadataExtension( ExtensionExtStructuralMetadataPropertyTable& propertyTable = modelExtension.propertyTables.emplace_back(); + propertyTable.name = "default"; propertyTable.count = featureCount; propertyTable.classProperty = "default"; diff --git a/Cesium3DTilesSelection/test/TestUpgradeBatchTableToExtStructuralMetadata.cpp b/Cesium3DTilesSelection/test/TestUpgradeBatchTableToExtStructuralMetadata.cpp index 712098bff..702ec8bb7 100644 --- a/Cesium3DTilesSelection/test/TestUpgradeBatchTableToExtStructuralMetadata.cpp +++ b/Cesium3DTilesSelection/test/TestUpgradeBatchTableToExtStructuralMetadata.cpp @@ -5,8 +5,8 @@ #include #include #include -#include -#include +#include +#include #include #include @@ -18,7 +18,6 @@ #include using namespace CesiumGltf; -using namespace CesiumGltf::StructuralMetadata; using namespace Cesium3DTilesSelection; using namespace CesiumUtility; @@ -88,13 +87,13 @@ static void checkArrayProperty( REQUIRE(view.status() == PropertyTableViewStatus::Valid); REQUIRE(view.size() == propertyTable.count); - PropertyTablePropertyView> propertyView = - view.getPropertyView>(propertyName); + PropertyTablePropertyView> propertyView = + view.getPropertyView>(propertyName); REQUIRE(propertyView.status() == PropertyTablePropertyViewStatus::Valid); REQUIRE(propertyView.size() == propertyTable.count); REQUIRE(propertyView.size() == static_cast(expectedTotalInstances)); for (size_t i = 0; i < expectedTotalInstances; ++i) { - MetadataArrayView value = + PropertyArrayView value = propertyView.get(static_cast(i)); if (expectedCount > 0) { REQUIRE(value.size() == expectedCount); diff --git a/CesiumGltf/include/CesiumGltf/FeatureIDTextureView.h b/CesiumGltf/include/CesiumGltf/FeatureIDTextureView.h deleted file mode 100644 index c3a29c02f..000000000 --- a/CesiumGltf/include/CesiumGltf/FeatureIDTextureView.h +++ /dev/null @@ -1,141 +0,0 @@ -#pragma once - -#include "CesiumGltf/FeatureIDTexture.h" -#include "CesiumGltf/Texture.h" -#include "CesiumGltf/TextureAccessor.h" -#include "Image.h" -#include "ImageCesium.h" -#include "Model.h" - -#include -#include -#include -#include -#include -#include - -namespace CesiumGltf { - -/** - * @brief The status of a feature id texture view. - * - * The {@link FeatureIDTextureView} constructor always completes successfully, - * but it may not always reflect the actual content of the - * {@link FeatureIDTexture}. This enumeration provides the reason. - */ -enum class FeatureIDTextureViewStatus { - /** - * @brief This view is valid and ready to use. - */ - Valid, - - /** - * @brief This view has not yet been initialized. - */ - InvalidUninitialized, - - /** - * @brief This feature id texture has a texture index that doesn't exist in - * the glTF. - */ - InvalidTextureIndex, - - /** - * @brief This feature id texture has an image index that doesn't exist in - * the glTF. - */ - InvalidImageIndex, - - /** - * @brief This feature id texture has an unknown image channel. - */ - InvalidChannel, - - /** - * @brief This feature id texture has an empty image. - */ - InvalidEmptyImage -}; - -/** - * @brief A view on the image data of {@link FeatureIDTexture}. - * - * It provides the ability to sample the feature IDs from the - * {@link FeatureIDTexture} using texture coordinates. - */ -class FeatureIDTextureView { -public: - /** - * @brief Constructs an uninitialized and invalid view. - */ - FeatureIDTextureView() noexcept; - - /** - * @brief Construct a view of the data specified by a - * {@link FeatureIDTexture}. - * - * @param model The glTF in which to look for the feature id texture's data. - * @param featureIDTexture The feature id texture to create a view for. - */ - FeatureIDTextureView( - const Model& model, - const FeatureIDTexture& featureIDTexture) noexcept; - - /** - * @brief Get the Feature ID for the given texture coordinates. - * - * Will return -1 when the status is not Valid. - * - * @param u The u-component of the texture coordinates. Must be within - * [0.0, 1.0]. - * @param v The v-component of the texture coordinates. Must be within - * [0.0, 1.0]. - * @return The feature ID at the nearest pixel to the texture coordinates. - */ - int64_t getFeatureID(double u, double v) const noexcept; - - /** - * @brief Get the status of this view. - * - * If invalid, it will not be safe to sample feature ids from this view. - */ - FeatureIDTextureViewStatus status() const { return _status; } - - /** - * @brief Get the actual feature ID texture. - * - * This will be nullptr if the feature id texture view runs into problems - * during construction. - */ - const ImageCesium* getImage() const { return _pImage; } - - /** - * @brief Get the channel index that this feature ID texture uses. - */ - int32_t getChannel() const { return _channel; } - - /** - * @brief Get the name of the feature table associated with this feature ID - * texture. - */ - const std::string& getFeatureTableName() const { - return this->_featureTableName; - } - - /** - * @brief Get the texture coordinate attribute index for this feature id - * texture. - */ - int64_t getTextureCoordinateAttributeId() const { - return this->_textureCoordinateAttributeId; - } - -private: - const ImageCesium* _pImage; - int32_t _channel; - int64_t _textureCoordinateAttributeId; - std::string _featureTableName; - FeatureIDTextureViewStatus _status; -}; - -} // namespace CesiumGltf \ No newline at end of file diff --git a/CesiumGltf/include/CesiumGltf/MeshFeaturesFeatureIdTextureView.h b/CesiumGltf/include/CesiumGltf/FeatureIdTextureView.h similarity index 98% rename from CesiumGltf/include/CesiumGltf/MeshFeaturesFeatureIdTextureView.h rename to CesiumGltf/include/CesiumGltf/FeatureIdTextureView.h index c7df25c12..c579ca836 100644 --- a/CesiumGltf/include/CesiumGltf/MeshFeaturesFeatureIdTextureView.h +++ b/CesiumGltf/include/CesiumGltf/FeatureIdTextureView.h @@ -15,8 +15,6 @@ #include namespace CesiumGltf { -namespace MeshFeatures { - /** * @brief The status of a feature ID texture view. * @@ -145,6 +143,4 @@ class FeatureIdTextureView { const ImageCesium* _pImage; }; - -} // namespace MeshFeatures } // namespace CesiumGltf diff --git a/CesiumGltf/include/CesiumGltf/FeatureTexturePropertyView.h b/CesiumGltf/include/CesiumGltf/FeatureTexturePropertyView.h deleted file mode 100644 index bbe87a546..000000000 --- a/CesiumGltf/include/CesiumGltf/FeatureTexturePropertyView.h +++ /dev/null @@ -1,253 +0,0 @@ -#pragma once - -#include "CesiumGltf/ClassProperty.h" -#include "CesiumGltf/ExtensionModelExtFeatureMetadata.h" -#include "CesiumGltf/FeatureTexture.h" -#include "CesiumGltf/Sampler.h" -#include "CesiumGltf/Texture.h" -#include "CesiumGltf/TextureAccessor.h" -#include "CesiumGltf/TextureInfo.h" -#include "Image.h" -#include "ImageCesium.h" -#include "Model.h" - -#include -#include -#include - -namespace CesiumGltf { - -/** - * @brief Indicates the status of a feature texture property view. - * - * The {@link FeatureTexturePropertyView} constructor always completes - * successfully. However it may not always reflect the actual content of the - * corresponding feature texture property. This enumeration provides the reason. - */ -enum class FeatureTexturePropertyViewStatus { - /** - * @brief This view is valid and ready to use. - */ - Valid, - - /** - * @brief This view has not been initialized. - */ - InvalidUninitialized, - - /** - * @brief This feature texture property has a texture index that does not - * exist in the glTF. - */ - InvalidTextureIndex, - - /** - * @brief This feature texture property has a texture sampler index that does - * not exist in the glTF. - */ - InvalidTextureSamplerIndex, - - /** - * @brief This feature texture property has an image index that does not - * exist in the glTF. - */ - InvalidImageIndex, - - /** - * @brief This feature texture property points to an empty image. - */ - InvalidEmptyImage, - - /** - * @brief This feature texture property has an invalid channels string. - */ - InvalidChannelsString -}; - -/** - * @brief The supported component types that can exist in feature id textures. - */ -enum class FeatureTexturePropertyComponentType { - Uint8 - // TODO: add more types. Currently this is the only one outputted by stb, - // so change stb call to output more of the original types. -}; - -/** - * @brief Specifies which channel each component exists in or -1 if the channel - * isn't present. This can be used to un-swizzle pixel data. - */ -struct FeatureTexturePropertyChannelOffsets { - int32_t r = -1; - int32_t g = -1; - int32_t b = -1; - int32_t a = -1; -}; - -/** - * @brief The feature texture property value for a pixel. This will contain - * four channels of the specified type. - * - * Only the first n components will be valid, where n is the number of channels - * in this feature texture property. - * - * @tparam T The component type, must correspond to a valid - * {@link FeatureTexturePropertyComponentType}. - */ -template struct FeatureTexturePropertyValue { T components[4]; }; - -/** - * @brief A view of the data specified by a property from a - * {@link FeatureTexture}. - * - * Provides utilities to sample the feature texture property using texture - * coordinates. - */ -class FeatureTexturePropertyView { -public: - /** - * @brief Construct an uninitialized, invalid view. - */ - FeatureTexturePropertyView() noexcept; - - /** - * @brief Construct a view of the data specified by a feature texture - * property. - * - * @param model The glTF in which to look for the data specified by the - * feature texture property. - * @param classProperty The property description. - * @param textureAccessor The texture accessor for this property. - */ - FeatureTexturePropertyView( - const Model& model, - const ClassProperty& classProperty, - const TextureAccessor& textureAccessor) noexcept; - - /** - * @brief Get the property for the given texture coordinates. - * - * Will return -1s when the status is not Valid or when the templated - * component type doesn't match the image's channel byte-size. - * - * @tparam T The component type to use when interpreting the channels of the - * property's pixel value. - * @param u The u-component of the texture coordinates. Must be within - * [0.0, 1.0]. - * @param v The v-component of the texture coordinates. Must be within - * [0.0, 1.0]. - * @return The property at the nearest pixel to the texture coordinates. - */ - template - FeatureTexturePropertyValue - getProperty(double u, double v) const noexcept { - if (this->_status != FeatureTexturePropertyViewStatus::Valid || - sizeof(T) != this->_pImage->bytesPerChannel) { - FeatureTexturePropertyValue property; - property.components[0] = -1; - property.components[1] = -1; - property.components[2] = -1; - property.components[3] = -1; - return property; - } - - // TODO: actually use the sampler?? - int64_t x = std::clamp( - std::llround(u * this->_pImage->width), - 0LL, - (long long)this->_pImage->width); - int64_t y = std::clamp( - std::llround(v * this->_pImage->height), - 0LL, - (long long)this->_pImage->height); - - int64_t pixelOffset = this->_pImage->bytesPerChannel * - this->_pImage->channels * - (y * this->_pImage->width + x); - const T* pRedChannel = reinterpret_cast( - this->_pImage->pixelData.data() + pixelOffset); - - FeatureTexturePropertyValue property; - property.components[0] = *(pRedChannel + this->_channelOffsets.r); - property.components[1] = *(pRedChannel + this->_channelOffsets.g); - property.components[2] = *(pRedChannel + this->_channelOffsets.b); - property.components[3] = *(pRedChannel + this->_channelOffsets.a); - - return property; - } - - /** - * @brief Get the status of this view. - * - * If invalid, it will not be safe to sample feature ids from this view. - */ - FeatureTexturePropertyViewStatus status() const noexcept { - return this->_status; - } - - /** - * @brief Get the component type for this property. - */ - FeatureTexturePropertyComponentType getPropertyType() const noexcept { - return this->_type; - } - - /** - * @brief Get the component count for this property. - * - * This is also how many channels a pixel value for this property will use. - */ - int64_t getComponentCount() const noexcept { return this->_componentCount; } - - /** - * @brief Get the texture coordinate attribute index for this property. - */ - int64_t getTextureCoordinateAttributeId() const noexcept { - return this->_textureCoordinateAttributeId; - } - - /** - * @brief Whether the component type for this property should be normalized. - */ - bool isNormalized() const noexcept { return this->_normalized; } - - /** - * @brief Get the image containing this property's data. - * - * This will be nullptr if the feature texture property view runs into - * problems during construction. - */ - const ImageCesium* getImage() const noexcept { return this->_pImage; } - - /** - * @brief Get the swizzle string for this texture's channels. Used to - * determine which channel represents red, green, blue, and alpha - * respectively. - */ - const std::string& getSwizzle() const noexcept { - const static std::string empty_str = ""; - return this->_pSwizzle ? *this->_pSwizzle : empty_str; - } - - /** - * @brief Get the {@link FeatureTexturePropertyChannelOffsets} that specifies - * how to un-swizzle this property's pixel values. - */ - const FeatureTexturePropertyChannelOffsets& - getChannelOffsets() const noexcept { - return this->_channelOffsets; - } - -private: - const Sampler* _pSampler; - const ImageCesium* _pImage; - const ClassProperty* _pClassProperty; - const std::string* _pSwizzle; - int64_t _textureCoordinateAttributeId; - FeatureTexturePropertyViewStatus _status; - FeatureTexturePropertyChannelOffsets _channelOffsets; - FeatureTexturePropertyComponentType _type; - int64_t _componentCount; - bool _normalized; -}; -} // namespace CesiumGltf \ No newline at end of file diff --git a/CesiumGltf/include/CesiumGltf/FeatureTextureView.h b/CesiumGltf/include/CesiumGltf/FeatureTextureView.h deleted file mode 100644 index 8b6410579..000000000 --- a/CesiumGltf/include/CesiumGltf/FeatureTextureView.h +++ /dev/null @@ -1,110 +0,0 @@ -#pragma once - -#include "CesiumGltf/Class.h" -#include "CesiumGltf/ClassProperty.h" -#include "CesiumGltf/ExtensionModelExtFeatureMetadata.h" -#include "CesiumGltf/FeatureTexture.h" -#include "CesiumGltf/FeatureTexturePropertyView.h" -#include "CesiumGltf/Texture.h" -#include "CesiumGltf/TextureAccessor.h" -#include "Image.h" -#include "ImageCesium.h" -#include "Model.h" - -namespace CesiumGltf { - -/** - * @brief Indicates the status of a feature texture view. - * - * The {@link FeatureTextureView} constructor always completes successfully. - * However it may not always reflect the actual content of the - * {@link FeatureTexture}. This enumeration provides the reason. - */ -enum class FeatureTextureViewStatus { - /** - * @brief This feature texture view is valid and ready to use. - */ - Valid, - - /** - * @brief This feature texture view is not initialized. - */ - InvalidUninitialized, - - /** - * @brief The glTF is missing the EXT_feature_metadata extension. - */ - InvalidMissingMetadataExtension, - - /** - * @brief The glTF EXT_feature_metadata extension doesn't contain a schema. - */ - InvalidMissingSchema, - - /** - * @brief The feature texture's specified class could not be found in the - * extension. - * - */ - InvalidClassNotFound, - - /** - * @brief A property name specified in the feature texture could not be found - * in the class. - */ - InvalidClassPropertyNotFound, - - /** - * @brief A property view for one of this feature texture's properties failed - * to initialize successfully. Look for the invalid property view's status to - * find why it failed. - */ - InvalidPropertyViewStatus -}; - -/** - * @brief A view on the {@link FeatureTexture}. - * - * Provides access to views on the feature texture properties. - */ -class FeatureTextureView { -public: - /** - * @brief Construct an uninitialized, invalid feature texture view. - */ - FeatureTextureView() noexcept; - - /** - * @brief Construct a view for the feature texture. - * - * @param model The glTF in which to look for the feature texture's data. - * @param featureTexture The feature texture to create a view for. - */ - FeatureTextureView( - const Model& model, - const FeatureTexture& featureTexture) noexcept; - - /** - * @brief Gets the status of this feature texture view. - * - * Indicates whether the view accurately reflects the feature texture's data, - * or whether an error occurred. - */ - FeatureTextureViewStatus status() const noexcept { return this->_status; } - - /** - * @brief Get the views for this feature texture's properties. - */ - const std::unordered_map& - getProperties() const noexcept { - return this->_propertyViews; - } - -private: - const Model* _pModel; - const FeatureTexture* _pFeatureTexture; - const Class* _pClass; - std::unordered_map _propertyViews; - FeatureTextureViewStatus _status; -}; -} // namespace CesiumGltf \ No newline at end of file diff --git a/CesiumGltf/include/CesiumGltf/MetadataArrayView.h b/CesiumGltf/include/CesiumGltf/MetadataArrayView.h deleted file mode 100644 index fe6b94b0c..000000000 --- a/CesiumGltf/include/CesiumGltf/MetadataArrayView.h +++ /dev/null @@ -1,129 +0,0 @@ -#pragma once - -#include "CesiumGltf/PropertyType.h" - -#include - -#include - -#include -#include - -namespace CesiumGltf { -template class MetadataArrayView { -public: - MetadataArrayView() : _valueBuffer{} {} - - MetadataArrayView(const gsl::span& buffer) noexcept - : _valueBuffer{ - CesiumUtility::reintepretCastSpan(buffer)} {} - - const ElementType& operator[](int64_t index) const noexcept { - return _valueBuffer[index]; - } - - int64_t size() const noexcept { - return static_cast(_valueBuffer.size()); - } - -private: - gsl::span _valueBuffer; -}; - -template <> class MetadataArrayView { -public: - MetadataArrayView() : _valueBuffer{}, _bitOffset{0}, _instanceCount{0} {} - - MetadataArrayView( - const gsl::span& buffer, - int64_t bitOffset, - int64_t instanceCount) noexcept - : _valueBuffer{buffer}, - _bitOffset{bitOffset}, - _instanceCount{instanceCount} {} - - bool operator[](int64_t index) const noexcept { - index += _bitOffset; - const int64_t byteIndex = index / 8; - const int64_t bitIndex = index % 8; - const int bitValue = - static_cast(_valueBuffer[byteIndex] >> bitIndex) & 1; - return bitValue == 1; - } - - int64_t size() const noexcept { return _instanceCount; } - -private: - gsl::span _valueBuffer; - int64_t _bitOffset; - int64_t _instanceCount; -}; - -template <> class MetadataArrayView { -public: - MetadataArrayView() - : _valueBuffer{}, _offsetBuffer{}, _offsetType{}, _size{0} {} - - MetadataArrayView( - const gsl::span& buffer, - const gsl::span& offsetBuffer, - PropertyType offsetType, - int64_t size) noexcept - : _valueBuffer{buffer}, - _offsetBuffer{offsetBuffer}, - _offsetType{offsetType}, - _size{size} {} - - std::string_view operator[](int64_t index) const noexcept { - const size_t currentOffset = - getOffsetFromOffsetBuffer(index, _offsetBuffer, _offsetType); - const size_t nextOffset = - getOffsetFromOffsetBuffer(index + 1, _offsetBuffer, _offsetType); - return std::string_view( - reinterpret_cast(_valueBuffer.data() + currentOffset), - (nextOffset - currentOffset)); - } - - int64_t size() const noexcept { return _size; } - -private: - static size_t getOffsetFromOffsetBuffer( - size_t instance, - const gsl::span& offsetBuffer, - PropertyType offsetType) noexcept { - switch (offsetType) { - case PropertyType::Uint8: { - assert(instance < offsetBuffer.size() / sizeof(uint8_t)); - const uint8_t offset = *reinterpret_cast( - offsetBuffer.data() + instance * sizeof(uint8_t)); - return static_cast(offset); - } - case PropertyType::Uint16: { - assert(instance < offsetBuffer.size() / sizeof(uint16_t)); - const uint16_t offset = *reinterpret_cast( - offsetBuffer.data() + instance * sizeof(uint16_t)); - return static_cast(offset); - } - case PropertyType::Uint32: { - assert(instance < offsetBuffer.size() / sizeof(uint32_t)); - const uint32_t offset = *reinterpret_cast( - offsetBuffer.data() + instance * sizeof(uint32_t)); - return static_cast(offset); - } - case PropertyType::Uint64: { - assert(instance < offsetBuffer.size() / sizeof(uint64_t)); - const uint64_t offset = *reinterpret_cast( - offsetBuffer.data() + instance * sizeof(uint64_t)); - return static_cast(offset); - } - default: - assert(false && "Offset type has unknown type"); - return 0; - } - } - gsl::span _valueBuffer; - gsl::span _offsetBuffer; - PropertyType _offsetType; - int64_t _size; -}; -} // namespace CesiumGltf diff --git a/CesiumGltf/include/CesiumGltf/MetadataFeatureTableView.h b/CesiumGltf/include/CesiumGltf/MetadataFeatureTableView.h deleted file mode 100644 index cae3deb92..000000000 --- a/CesiumGltf/include/CesiumGltf/MetadataFeatureTableView.h +++ /dev/null @@ -1,536 +0,0 @@ -#pragma once - -#include "CesiumGltf/ExtensionModelExtFeatureMetadata.h" -#include "CesiumGltf/MetadataPropertyView.h" -#include "CesiumGltf/Model.h" -#include "CesiumGltf/PropertyType.h" - -#include - -#include - -namespace CesiumGltf { -/** - * @brief Utility to retrieve the data of FeatureTable - * - * This should be used to get {@link MetadataPropertyView} of a property since - * it will validate the EXT_Feature_Metadata format to make sure {@link MetadataPropertyView} - * not access out of bound - */ -class MetadataFeatureTableView { -public: - /** - * @brief Create an instance of MetadataFeatureTableView - * @param model The Gltf Model that stores featureTable data - * @param featureTable The FeatureTable that will be used to retrieve the data - * from - */ - MetadataFeatureTableView( - const Model* pModel, - const FeatureTable* pFeatureTable); - - /** - * @brief Find the {@link ClassProperty} which stores the type information of a property based on the property name - * @param propertyName The name of the property to retrieve type info - * @return ClassProperty of a property. Return nullptr if no property is found - */ - const ClassProperty* getClassProperty(const std::string& propertyName) const; - - /** - * @brief Get MetadataPropertyView to view the data of a property stored in - * the FeatureTable. - * - * This method will validate the EXT_Feature_Metadata format to ensure - * MetadataPropertyView retrieve the correct data. T must be uin8_t, int8_t, - * uint16_t, int16_t, uint32_t, int32_t, uint64_t, int64_t, float, double, - * bool, std::string_view, and MetadataArrayView with T must be one of the - * types mentioned above - * - * @param propertyName The name of the property to retrieve data from - * @return ClassProperty of a property. Return nullptr if no property is found - */ - template - MetadataPropertyView - getPropertyView(const std::string& propertyName) const { - if (_pFeatureTable->count < 0) { - return createInvalidPropertyView( - MetadataPropertyViewStatus::InvalidPropertyNotExist); - } - - const ClassProperty* pClassProperty = getClassProperty(propertyName); - if (!pClassProperty) { - return createInvalidPropertyView( - MetadataPropertyViewStatus::InvalidPropertyNotExist); - } - - return getPropertyViewImpl(propertyName, *pClassProperty); - } - - /** - * @brief Get MetadataPropertyView through a callback that accepts property - * name and std::optional> to view the data of a - * property stored in the FeatureTable. - * - * This method will validate the EXT_Feature_Metadata format to ensure - * MetadataPropertyView retrieve the correct data. T must be uin8_t, int8_t, - * uint16_t, int16_t, uint32_t, int32_t, uint64_t, int64_t, float, double, - * bool, std::string_view, and MetadataArrayView with T must be one of the - * types mentioned above. If the property is invalid, std::nullopt will be - * passed to the callback. Otherwise, a valid property view will be passed to - * the callback - * - * @param propertyName The name of the property to retrieve data from - * @tparam callback A callback function that accepts property name and - * std::optional> - */ - template - void - getPropertyView(const std::string& propertyName, Callback&& callback) const { - const ClassProperty* pClassProperty = getClassProperty(propertyName); - if (!pClassProperty) { - return; - } - - PropertyType type = convertStringToPropertyType(pClassProperty->type); - PropertyType componentType = PropertyType::None; - if (pClassProperty->componentType.has_value()) { - componentType = - convertStringToPropertyType(pClassProperty->componentType.value()); - } - - if (type != PropertyType::Array) { - getScalarPropertyViewImpl( - propertyName, - *pClassProperty, - type, - std::forward(callback)); - } else { - getArrayPropertyViewImpl( - propertyName, - *pClassProperty, - componentType, - std::forward(callback)); - } - } - - /** - * @brief Get MetadataPropertyView for each property in the FeatureTable - * through a callback that accepts property name and - * std::optional> to view the data stored in the - * FeatureTableProperty. - * - * This method will validate the EXT_Feature_Metadata format to ensure - * MetadataPropertyView retrieve the correct data. T must be uin8_t, int8_t, - * uint16_t, int16_t, uint32_t, int32_t, uint64_t, int64_t, float, double, - * bool, std::string_view, and MetadataArrayView with T must be one of the - * types mentioned above. If the property is invalid, std::nullopt will be - * passed to the callback. Otherwise, a valid property view will be passed to - * the callback - * - * @param propertyName The name of the property to retrieve data from - * @tparam callback A callback function that accepts property name and - * std::optional> - */ - template void forEachProperty(Callback&& callback) const { - for (const auto& property : this->_pClass->properties) { - getPropertyView(property.first, std::forward(callback)); - } - } - -private: - template - void getArrayPropertyViewImpl( - const std::string& propertyName, - const ClassProperty& classProperty, - PropertyType type, - Callback&& callback) const { - switch (type) { - case PropertyType::Int8: - callback( - propertyName, - getPropertyViewImpl>( - propertyName, - classProperty)); - break; - case PropertyType::Uint8: - callback( - propertyName, - getPropertyViewImpl>( - propertyName, - classProperty)); - break; - case PropertyType::Int16: - callback( - propertyName, - getPropertyViewImpl>( - propertyName, - classProperty)); - break; - case PropertyType::Uint16: - callback( - propertyName, - getPropertyViewImpl>( - propertyName, - classProperty)); - break; - case PropertyType::Int32: - callback( - propertyName, - getPropertyViewImpl>( - propertyName, - classProperty)); - break; - case PropertyType::Uint32: - callback( - propertyName, - getPropertyViewImpl>( - propertyName, - classProperty)); - break; - case PropertyType::Int64: - callback( - propertyName, - getPropertyViewImpl>( - propertyName, - classProperty)); - break; - case PropertyType::Uint64: - callback( - propertyName, - getPropertyViewImpl>( - propertyName, - classProperty)); - break; - case PropertyType::Float32: - callback( - propertyName, - getPropertyViewImpl>( - propertyName, - classProperty)); - break; - case PropertyType::Float64: - callback( - propertyName, - getPropertyViewImpl>( - propertyName, - classProperty)); - break; - case PropertyType::Boolean: - callback( - propertyName, - getPropertyViewImpl>( - propertyName, - classProperty)); - break; - case PropertyType::String: - callback( - propertyName, - getPropertyViewImpl>( - propertyName, - classProperty)); - break; - default: - break; - } - } - - template - void getScalarPropertyViewImpl( - const std::string& propertyName, - const ClassProperty& classProperty, - PropertyType type, - Callback&& callback) const { - switch (type) { - case PropertyType::Int8: - callback( - propertyName, - getPropertyViewImpl(propertyName, classProperty)); - break; - case PropertyType::Uint8: - callback( - propertyName, - getPropertyViewImpl(propertyName, classProperty)); - break; - case PropertyType::Int16: - callback( - propertyName, - getPropertyViewImpl(propertyName, classProperty)); - break; - case PropertyType::Uint16: - callback( - propertyName, - getPropertyViewImpl(propertyName, classProperty)); - break; - case PropertyType::Int32: - callback( - propertyName, - getPropertyViewImpl(propertyName, classProperty)); - break; - case PropertyType::Uint32: - callback( - propertyName, - getPropertyViewImpl(propertyName, classProperty)); - break; - case PropertyType::Int64: - callback( - propertyName, - getPropertyViewImpl(propertyName, classProperty)); - break; - case PropertyType::Uint64: - callback( - propertyName, - getPropertyViewImpl(propertyName, classProperty)); - break; - case PropertyType::Float32: - callback( - propertyName, - getPropertyViewImpl(propertyName, classProperty)); - break; - case PropertyType::Float64: - callback( - propertyName, - getPropertyViewImpl(propertyName, classProperty)); - break; - case PropertyType::Boolean: - callback( - propertyName, - getPropertyViewImpl(propertyName, classProperty)); - break; - case PropertyType::String: - callback( - propertyName, - getPropertyViewImpl(propertyName, classProperty)); - break; - default: - break; - } - } - - template - MetadataPropertyView getPropertyViewImpl( - const std::string& propertyName, - const ClassProperty& classProperty) const { - auto featureTablePropertyIter = - _pFeatureTable->properties.find(propertyName); - if (featureTablePropertyIter == _pFeatureTable->properties.end()) { - return createInvalidPropertyView( - MetadataPropertyViewStatus::InvalidPropertyNotExist); - } - - const FeatureTableProperty& featureTableProperty = - featureTablePropertyIter->second; - - if constexpr (IsMetadataNumeric::value || IsMetadataBoolean::value) { - return getPrimitivePropertyValues(classProperty, featureTableProperty); - } - - if constexpr (IsMetadataString::value) { - return getStringPropertyValues(classProperty, featureTableProperty); - } - - if constexpr ( - IsMetadataNumericArray::value || IsMetadataBooleanArray::value) { - return getPrimitiveArrayPropertyValues< - typename MetadataArrayType::type>( - classProperty, - featureTableProperty); - } - - if constexpr (IsMetadataStringArray::value) { - return getStringArrayPropertyValues(classProperty, featureTableProperty); - } - } - - template - MetadataPropertyView getPrimitivePropertyValues( - const ClassProperty& classProperty, - const FeatureTableProperty& featureTableProperty) const { - const PropertyType type = convertStringToPropertyType(classProperty.type); - if (TypeToPropertyType::value != type) { - return createInvalidPropertyView( - MetadataPropertyViewStatus::InvalidTypeMismatch); - } - - gsl::span valueBuffer; - const auto status = - getBufferSafe(featureTableProperty.bufferView, valueBuffer); - if (status != MetadataPropertyViewStatus::Valid) { - return createInvalidPropertyView(status); - } - - if (valueBuffer.size() % sizeof(T) != 0) { - return createInvalidPropertyView( - MetadataPropertyViewStatus:: - InvalidBufferViewSizeNotDivisibleByTypeSize); - } - - size_t maxRequiredBytes = 0; - if (IsMetadataBoolean::value) { - maxRequiredBytes = static_cast( - glm::ceil(static_cast(_pFeatureTable->count) / 8.0)); - } else { - maxRequiredBytes = _pFeatureTable->count * sizeof(T); - } - - if (valueBuffer.size() < maxRequiredBytes) { - return createInvalidPropertyView( - MetadataPropertyViewStatus::InvalidBufferViewSizeNotFitInstanceCount); - } - - return MetadataPropertyView( - MetadataPropertyViewStatus::Valid, - valueBuffer, - gsl::span(), - gsl::span(), - PropertyType::None, - 0, - _pFeatureTable->count, - classProperty.normalized); - } - - MetadataPropertyView getStringPropertyValues( - const ClassProperty& classProperty, - const FeatureTableProperty& featureTableProperty) const; - - template - MetadataPropertyView> getPrimitiveArrayPropertyValues( - const ClassProperty& classProperty, - const FeatureTableProperty& featureTableProperty) const { - if (classProperty.type != ClassProperty::Type::ARRAY) { - return createInvalidPropertyView>( - MetadataPropertyViewStatus::InvalidTypeMismatch); - } - - if (!classProperty.componentType.has_value()) { - return createInvalidPropertyView>( - MetadataPropertyViewStatus::InvalidTypeMismatch); - } - - const PropertyType componentType = - convertStringToPropertyType(classProperty.componentType.value()); - if (TypeToPropertyType::value != componentType) { - return createInvalidPropertyView>( - MetadataPropertyViewStatus::InvalidTypeMismatch); - } - - gsl::span valueBuffer; - auto status = getBufferSafe(featureTableProperty.bufferView, valueBuffer); - if (status != MetadataPropertyViewStatus::Valid) { - return createInvalidPropertyView>(status); - } - - if (valueBuffer.size() % sizeof(T) != 0) { - return createInvalidPropertyView>( - MetadataPropertyViewStatus:: - InvalidBufferViewSizeNotDivisibleByTypeSize); - } - - const int64_t componentCount = classProperty.componentCount.value_or(0); - if (componentCount > 0 && featureTableProperty.arrayOffsetBufferView >= 0) { - return createInvalidPropertyView>( - MetadataPropertyViewStatus:: - InvalidArrayComponentCountAndOffsetBufferCoexist); - } - - if (componentCount <= 0 && featureTableProperty.arrayOffsetBufferView < 0) { - return createInvalidPropertyView>( - MetadataPropertyViewStatus:: - InvalidArrayComponentCountOrOffsetBufferNotExist); - } - - // fixed array - if (componentCount > 0) { - size_t maxRequiredBytes = 0; - if constexpr (IsMetadataBoolean::value) { - maxRequiredBytes = static_cast(glm::ceil( - static_cast(_pFeatureTable->count * componentCount) / 8.0)); - } else { - maxRequiredBytes = static_cast( - _pFeatureTable->count * componentCount * sizeof(T)); - } - - if (valueBuffer.size() < maxRequiredBytes) { - return createInvalidPropertyView>( - MetadataPropertyViewStatus:: - InvalidBufferViewSizeNotFitInstanceCount); - } - - return MetadataPropertyView>( - MetadataPropertyViewStatus::Valid, - valueBuffer, - gsl::span(), - gsl::span(), - PropertyType::None, - static_cast(componentCount), - static_cast(_pFeatureTable->count), - classProperty.normalized); - } - - // dynamic array - const PropertyType offsetType = - convertOffsetStringToPropertyType(featureTableProperty.offsetType); - if (offsetType == PropertyType::None) { - return createInvalidPropertyView>( - MetadataPropertyViewStatus::InvalidOffsetType); - } - - constexpr bool checkBitsSize = IsMetadataBoolean::value; - gsl::span offsetBuffer; - status = getOffsetBufferSafe( - featureTableProperty.arrayOffsetBufferView, - offsetType, - valueBuffer.size(), - static_cast(_pFeatureTable->count), - checkBitsSize, - offsetBuffer); - if (status != MetadataPropertyViewStatus::Valid) { - return createInvalidPropertyView>(status); - } - - return MetadataPropertyView>( - MetadataPropertyViewStatus::Valid, - valueBuffer, - offsetBuffer, - gsl::span(), - offsetType, - 0, - static_cast(_pFeatureTable->count), - classProperty.normalized); - } - - MetadataPropertyView> - getStringArrayPropertyValues( - const ClassProperty& classProperty, - const FeatureTableProperty& featureTableProperty) const; - - MetadataPropertyViewStatus getBufferSafe( - int32_t bufferViewIdx, - gsl::span& buffer) const noexcept; - - MetadataPropertyViewStatus getOffsetBufferSafe( - int32_t bufferViewIdx, - PropertyType offsetType, - size_t valueBufferSize, - size_t instanceCount, - bool checkBitsSize, - gsl::span& offsetBuffer) const noexcept; - - template - static MetadataPropertyView - createInvalidPropertyView(MetadataPropertyViewStatus invalidStatus) noexcept { - return MetadataPropertyView( - invalidStatus, - gsl::span(), - gsl::span(), - gsl::span(), - PropertyType::None, - 0, - 0, - false); - } - - const Model* _pModel; - const FeatureTable* _pFeatureTable; - const Class* _pClass; -}; -} // namespace CesiumGltf diff --git a/CesiumGltf/include/CesiumGltf/MetadataPropertyView.h b/CesiumGltf/include/CesiumGltf/MetadataPropertyView.h deleted file mode 100644 index 6b535d27d..000000000 --- a/CesiumGltf/include/CesiumGltf/MetadataPropertyView.h +++ /dev/null @@ -1,411 +0,0 @@ -#pragma once - -#include "CesiumGltf/MetadataArrayView.h" -#include "CesiumGltf/PropertyType.h" -#include "CesiumGltf/PropertyTypeTraits.h" - -#include - -#include -#include -#include -#include -#include - -namespace CesiumGltf { -/** - * @brief Indicates the status of a property view. - * - * The {@link MetadataPropertyView} constructor always completes successfully. However, - * it may not always reflect the actual content of the {@link FeatureTableProperty}, but - * instead indicate that its {@link MetadataPropertyView::size} is 0. This enumeration - * provides the reason. - */ -enum class MetadataPropertyViewStatus { - /** - * @brief This property view is valid and ready to use. - */ - Valid, - - /** - * @brief This property view does not exist in the FeatureTable. - */ - InvalidPropertyNotExist, - - /** - * @brief This property view does not have a correct type with what is - * specified in {@link ClassProperty::type}. - */ - InvalidTypeMismatch, - - /** - * @brief This property view does not have a valid value buffer view index. - */ - InvalidValueBufferViewIndex, - - /** - * @brief This array property view does not have a valid array offset buffer - * view index. - */ - InvalidArrayOffsetBufferViewIndex, - - /** - * @brief This string property view does not have a valid string offset buffer - * view index. - */ - InvalidStringOffsetBufferViewIndex, - - /** - * @brief This property view has a valid value buffer view index, but buffer - * view specifies an invalid buffer index - */ - InvalidValueBufferIndex, - - /** - * @brief This property view has a valid array string buffer view index, but - * buffer view specifies an invalid buffer index - */ - InvalidArrayOffsetBufferIndex, - - /** - * @brief This property view has a valid string offset buffer view index, but - * buffer view specifies an invalid buffer index - */ - InvalidStringOffsetBufferIndex, - - /** - * @brief This property view has buffer view's offset not aligned by 8 bytes - */ - InvalidBufferViewNotAligned8Bytes, - - /** - * @brief This property view has an out-of-bound buffer view - */ - InvalidBufferViewOutOfBound, - - /** - * @brief This property view has an invalid buffer view's length which is not - * a multiple of the size of its type or offset type - */ - InvalidBufferViewSizeNotDivisibleByTypeSize, - - /** - * @brief This property view has an invalid buffer view's length which cannot - * fit all the instances of the feature table - */ - InvalidBufferViewSizeNotFitInstanceCount, - - /** - * @brief This array property view has both component count and offset buffer - * view - */ - InvalidArrayComponentCountAndOffsetBufferCoexist, - - /** - * @brief This array property view doesn't have either component count or - * offset buffer view - */ - InvalidArrayComponentCountOrOffsetBufferNotExist, - - /** - * @brief This property view have an unknown offset type - */ - InvalidOffsetType, - - /** - * @brief This property view has offset values not sorted ascendingly - */ - InvalidOffsetValuesNotSortedAscending, - - /** - * @brief This property view has an offset point to an out of bound value - */ - InvalidOffsetValuePointsToOutOfBoundBuffer -}; - -/** - * @brief A view on the data of the FeatureTableProperty - * - * It provides utility to retrieve the actual data stored in the - * {@link FeatureTableProperty::bufferView} like an array of elements. - * Data of each instance can be accessed through the {@link get(int64_t instance)} method - * - * @param ElementType must be uin8_t, int8_t, uint16_t, int16_t, - * uint32_t, int32_t, uint64_t, int64_t, float, double, bool, std::string_view, - * and MetadataArrayView with T must be one of the types mentioned above - */ -template class MetadataPropertyView { -public: - /** - * @brief Constructs a new instance viewing a non-existent property. - */ - MetadataPropertyView() - : _status{MetadataPropertyViewStatus::InvalidPropertyNotExist}, - _valueBuffer{}, - _arrayOffsetBuffer{}, - _stringOffsetBuffer{}, - _offsetType{}, - _offsetSize{}, - _componentCount{}, - _instanceCount{}, - _normalized{} {} - - /** - * @brief Construct a new instance pointing to the data specified by - * FeatureTableProperty - * @param valueBuffer The raw buffer specified by {@link FeatureTableProperty::bufferView} - * @param arrayOffsetBuffer The raw buffer specified by {@link FeatureTableProperty::arrayOffsetBufferView} - * @param stringOffsetBuffer The raw buffer specified by {@link FeatureTableProperty::stringOffsetBufferView} - * @param offsetType The offset type of the arrayOffsetBuffer and stringOffsetBuffer that is specified by {@link FeatureTableProperty::offsetType} - * @param componentCount The number of elements for fixed array value which is specified by {@link FeatureTableProperty::componentCount} - * @param instanceCount The number of instances specified by {@link FeatureTable::count} - * @param normalized Whether this property has a normalized integer type. - */ - MetadataPropertyView( - MetadataPropertyViewStatus status, - gsl::span valueBuffer, - gsl::span arrayOffsetBuffer, - gsl::span stringOffsetBuffer, - PropertyType offsetType, - int64_t componentCount, - int64_t instanceCount, - bool normalized) noexcept - : _status{status}, - _valueBuffer{valueBuffer}, - _arrayOffsetBuffer{arrayOffsetBuffer}, - _stringOffsetBuffer{stringOffsetBuffer}, - _offsetType{offsetType}, - _offsetSize{getOffsetSize(offsetType)}, - _componentCount{componentCount}, - _instanceCount{instanceCount}, - _normalized{normalized} {} - - /** - * @brief Gets the status of this property view. - * - * Indicates whether the view accurately reflects the property's data, or - * whether an error occurred. - */ - MetadataPropertyViewStatus status() const noexcept { return _status; } - - /** - * @brief Get the value of an instance of the FeatureTable. - * @param instance The instance index - * @return The value of the instance - */ - ElementType get(int64_t instance) const noexcept { - assert( - _status == MetadataPropertyViewStatus::Valid && - "Check the status() first to make sure view is valid"); - assert( - size() > 0 && - "Check the size() of the view to make sure it's not empty"); - assert(instance >= 0 && "instance index must be positive"); - - if constexpr (IsMetadataNumeric::value) { - return getNumeric(instance); - } - - if constexpr (IsMetadataBoolean::value) { - return getBoolean(instance); - } - - if constexpr (IsMetadataString::value) { - return getString(instance); - } - - if constexpr (IsMetadataNumericArray::value) { - return getNumericArray::type>( - instance); - } - - if constexpr (IsMetadataBooleanArray::value) { - return getBooleanArray(instance); - } - - if constexpr (IsMetadataStringArray::value) { - return getStringArray(instance); - } - } - - /** - * @brief Get the number of instances in the FeatureTable - * @return The number of instances in the FeatureTable - */ - int64_t size() const noexcept { return _instanceCount; } - - /** - * @brief Get the component count of this property. Only applicable when the - * property is an array type. - * - * @return The component count of this property. - */ - int64_t getComponentCount() const noexcept { return _componentCount; } - - /** - * @brief Whether this property has a normalized integer type. - * - * @return Whether this property has a normalized integer type. - */ - bool isNormalized() const noexcept { return _normalized; } - -private: - ElementType getNumeric(int64_t instance) const noexcept { - return reinterpret_cast(_valueBuffer.data())[instance]; - } - - bool getBoolean(int64_t instance) const noexcept { - const int64_t byteIndex = instance / 8; - const int64_t bitIndex = instance % 8; - const int bitValue = - static_cast(_valueBuffer[byteIndex] >> bitIndex) & 1; - return bitValue == 1; - } - - std::string_view getString(int64_t instance) const noexcept { - const size_t currentOffset = - getOffsetFromOffsetBuffer(instance, _stringOffsetBuffer, _offsetType); - const size_t nextOffset = getOffsetFromOffsetBuffer( - instance + 1, - _stringOffsetBuffer, - _offsetType); - return std::string_view( - reinterpret_cast(_valueBuffer.data() + currentOffset), - (nextOffset - currentOffset)); - } - - template - MetadataArrayView getNumericArray(int64_t instance) const noexcept { - if (_componentCount > 0) { - const gsl::span vals( - _valueBuffer.data() + instance * _componentCount * sizeof(T), - _componentCount * sizeof(T)); - return MetadataArrayView{vals}; - } - - const size_t currentOffset = - getOffsetFromOffsetBuffer(instance, _arrayOffsetBuffer, _offsetType); - const size_t nextOffset = getOffsetFromOffsetBuffer( - instance + 1, - _arrayOffsetBuffer, - _offsetType); - const gsl::span vals( - _valueBuffer.data() + currentOffset, - (nextOffset - currentOffset)); - return MetadataArrayView{vals}; - } - - MetadataArrayView - getStringArray(int64_t instance) const noexcept { - if (_componentCount > 0) { - const gsl::span offsetVals( - _stringOffsetBuffer.data() + instance * _componentCount * _offsetSize, - (_componentCount + 1) * _offsetSize); - return MetadataArrayView( - _valueBuffer, - offsetVals, - _offsetType, - _componentCount); - } - - const size_t currentOffset = - getOffsetFromOffsetBuffer(instance, _arrayOffsetBuffer, _offsetType); - const size_t nextOffset = getOffsetFromOffsetBuffer( - instance + 1, - _arrayOffsetBuffer, - _offsetType); - const gsl::span offsetVals( - _stringOffsetBuffer.data() + currentOffset, - (nextOffset - currentOffset + _offsetSize)); - return MetadataArrayView( - _valueBuffer, - offsetVals, - _offsetType, - (nextOffset - currentOffset) / _offsetSize); - } - - MetadataArrayView getBooleanArray(int64_t instance) const noexcept { - if (_componentCount > 0) { - const size_t offsetBits = _componentCount * instance; - const size_t nextOffsetBits = _componentCount * (instance + 1); - const gsl::span buffer( - _valueBuffer.data() + offsetBits / 8, - (nextOffsetBits / 8 - offsetBits / 8 + 1)); - return MetadataArrayView(buffer, offsetBits % 8, _componentCount); - } - - const size_t currentOffset = - getOffsetFromOffsetBuffer(instance, _arrayOffsetBuffer, _offsetType); - const size_t nextOffset = getOffsetFromOffsetBuffer( - instance + 1, - _arrayOffsetBuffer, - _offsetType); - - const size_t totalBits = nextOffset - currentOffset; - const gsl::span buffer( - _valueBuffer.data() + currentOffset / 8, - (nextOffset / 8 - currentOffset / 8 + 1)); - return MetadataArrayView(buffer, currentOffset % 8, totalBits); - } - - static int64_t getOffsetSize(PropertyType offsetType) noexcept { - switch (offsetType) { - case CesiumGltf::PropertyType::Uint8: - return sizeof(uint8_t); - case CesiumGltf::PropertyType::Uint16: - return sizeof(uint16_t); - case CesiumGltf::PropertyType::Uint32: - return sizeof(uint32_t); - case CesiumGltf::PropertyType::Uint64: - return sizeof(uint64_t); - default: - return 0; - } - } - - static size_t getOffsetFromOffsetBuffer( - size_t instance, - const gsl::span& offsetBuffer, - PropertyType offsetType) noexcept { - switch (offsetType) { - case PropertyType::Uint8: { - assert(instance < offsetBuffer.size() / sizeof(uint8_t)); - const uint8_t offset = *reinterpret_cast( - offsetBuffer.data() + instance * sizeof(uint8_t)); - return static_cast(offset); - } - case PropertyType::Uint16: { - assert(instance < offsetBuffer.size() / sizeof(uint16_t)); - const uint16_t offset = *reinterpret_cast( - offsetBuffer.data() + instance * sizeof(uint16_t)); - return static_cast(offset); - } - case PropertyType::Uint32: { - assert(instance < offsetBuffer.size() / sizeof(uint32_t)); - const uint32_t offset = *reinterpret_cast( - offsetBuffer.data() + instance * sizeof(uint32_t)); - return static_cast(offset); - } - case PropertyType::Uint64: { - assert(instance < offsetBuffer.size() / sizeof(uint64_t)); - const uint64_t offset = *reinterpret_cast( - offsetBuffer.data() + instance * sizeof(uint64_t)); - return static_cast(offset); - } - default: - assert(false && "Offset type has unknown type"); - return 0; - } - } - - MetadataPropertyViewStatus _status; - gsl::span _valueBuffer; - gsl::span _arrayOffsetBuffer; - gsl::span _stringOffsetBuffer; - PropertyType _offsetType; - int64_t _offsetSize; - int64_t _componentCount; - int64_t _instanceCount; - bool _normalized; -}; -} // namespace CesiumGltf diff --git a/CesiumGltf/include/CesiumGltf/StructuralMetadataArrayView.h b/CesiumGltf/include/CesiumGltf/PropertyArrayView.h similarity index 76% rename from CesiumGltf/include/CesiumGltf/StructuralMetadataArrayView.h rename to CesiumGltf/include/CesiumGltf/PropertyArrayView.h index e315584f4..9f3ea6d2f 100644 --- a/CesiumGltf/include/CesiumGltf/StructuralMetadataArrayView.h +++ b/CesiumGltf/include/CesiumGltf/PropertyArrayView.h @@ -1,6 +1,6 @@ #pragma once -#include "CesiumGltf/StructuralMetadataPropertyType.h" +#include "CesiumGltf/PropertyType.h" #include "getOffsetFromOffsetsBuffer.h" #include @@ -11,8 +11,6 @@ #include namespace CesiumGltf { -namespace StructuralMetadata { - /** * @brief A view on an array element of a * {@link ExtensionExtStructuralMetadataPropertyTableProperty}. @@ -20,11 +18,11 @@ namespace StructuralMetadata { * Provides utility to retrieve the data stored in the array of * elements via the array index operator. */ -template class MetadataArrayView { +template class PropertyArrayView { public: - MetadataArrayView() : _values{} {} + PropertyArrayView() : _values{} {} - MetadataArrayView(const gsl::span& buffer) noexcept + PropertyArrayView(const gsl::span& buffer) noexcept : _values{CesiumUtility::reintepretCastSpan(buffer)} {} const ElementType& operator[](int64_t index) const noexcept { @@ -34,14 +32,14 @@ template class MetadataArrayView { int64_t size() const noexcept { return static_cast(_values.size()); } private: - const gsl::span _values; + gsl::span _values; }; -template <> class MetadataArrayView { +template <> class PropertyArrayView { public: - MetadataArrayView() : _values{}, _bitOffset{0}, _size{0} {} + PropertyArrayView() : _values{}, _bitOffset{0}, _size{0} {} - MetadataArrayView( + PropertyArrayView( const gsl::span& buffer, int64_t bitOffset, int64_t size) noexcept @@ -63,15 +61,15 @@ template <> class MetadataArrayView { int64_t _size; }; -template <> class MetadataArrayView { +template <> class PropertyArrayView { public: - MetadataArrayView() + PropertyArrayView() : _values{}, _stringOffsets{}, _stringOffsetType{}, _size{0} {} - MetadataArrayView( + PropertyArrayView( const gsl::span& values, const gsl::span& stringOffsets, - StructuralMetadata::PropertyComponentType stringOffsetType, + PropertyComponentType stringOffsetType, int64_t size) noexcept : _values{values}, _stringOffsets{stringOffsets}, @@ -95,9 +93,7 @@ template <> class MetadataArrayView { private: gsl::span _values; gsl::span _stringOffsets; - StructuralMetadata::PropertyComponentType _stringOffsetType; + PropertyComponentType _stringOffsetType; int64_t _size; }; - -} // namespace StructuralMetadata } // namespace CesiumGltf diff --git a/CesiumGltf/include/CesiumGltf/StructuralMetadataPropertyTablePropertyView.h b/CesiumGltf/include/CesiumGltf/PropertyTablePropertyView.h similarity index 93% rename from CesiumGltf/include/CesiumGltf/StructuralMetadataPropertyTablePropertyView.h rename to CesiumGltf/include/CesiumGltf/PropertyTablePropertyView.h index 320beb349..451c5f14d 100644 --- a/CesiumGltf/include/CesiumGltf/StructuralMetadataPropertyTablePropertyView.h +++ b/CesiumGltf/include/CesiumGltf/PropertyTablePropertyView.h @@ -1,7 +1,7 @@ #pragma once -#include "CesiumGltf/StructuralMetadataArrayView.h" -#include "CesiumGltf/StructuralMetadataPropertyTypeTraits.h" +#include "CesiumGltf/PropertyArrayView.h" +#include "CesiumGltf/PropertyTypeTraits.h" #include @@ -12,8 +12,6 @@ #include namespace CesiumGltf { -namespace StructuralMetadata { - /** * @brief Indicates the status of a property table property view. * @@ -161,7 +159,7 @@ enum class PropertyTablePropertyViewStatus { /** * @brief A view on the data of the * {@link ExtensionExtStructuralMetadataPropertyTableProperty that is created by - * a {@link MetadataPropertyTableView}. + * a {@link PropertyTableView}. * * It provides utility to retrieve the actual data stored in the * {@link ExtensionExtStructuralMetadataPropertyTableProperty::values} like an array of elements. @@ -170,7 +168,7 @@ enum class PropertyTablePropertyViewStatus { * @param ElementType must be one of the following: a scalar (uint8_t, int8_t, * uint16_t, int16_t, uint32_t, int32_t, uint64_t, int64_t, float, double), a * glm vecN composed of one of the scalar types, a glm matN composed of one of - * the scalar types, bool, std::string_view, or MetadataArrayView with T as + * the scalar types, bool, std::string_view, or PropertyArrayView with T as * one of the aforementioned types. */ template class PropertyTablePropertyView { @@ -226,8 +224,8 @@ template class PropertyTablePropertyView { gsl::span values, gsl::span arrayOffsets, gsl::span stringOffsets, - StructuralMetadata::PropertyComponentType arrayOffsetType, - StructuralMetadata::PropertyComponentType stringOffsetType, + PropertyComponentType arrayOffsetType, + PropertyComponentType stringOffsetType, int64_t arrayCount, int64_t size, bool normalized) noexcept @@ -345,14 +343,14 @@ template class PropertyTablePropertyView { } template - MetadataArrayView getNumericArrayValues(int64_t index) const noexcept { + PropertyArrayView getNumericArrayValues(int64_t index) const noexcept { // Handle fixed-length arrays if (_arrayCount > 0) { size_t arraySize = _arrayCount * sizeof(T); const gsl::span values( _values.data() + index * arraySize, arraySize); - return MetadataArrayView{values}; + return PropertyArrayView{values}; } // Handle variable-length arrays @@ -363,19 +361,19 @@ template class PropertyTablePropertyView { const gsl::span values( _values.data() + currentOffset, nextOffset - currentOffset); - return MetadataArrayView{values}; + return PropertyArrayView{values}; } - MetadataArrayView + PropertyArrayView getStringArrayValues(int64_t index) const noexcept { // Handle fixed-length arrays if (_arrayCount > 0) { - // Copy the corresponding string offsets to pass to the MetadataArrayView. + // Copy the corresponding string offsets to pass to the PropertyArrayView. const size_t arraySize = _arrayCount * _stringOffsetTypeSize; const gsl::span stringOffsetValues( _stringOffsets.data() + index * arraySize, arraySize + _stringOffsetTypeSize); - return MetadataArrayView( + return PropertyArrayView( _values, stringOffsetValues, _stringOffsetType, @@ -391,14 +389,14 @@ template class PropertyTablePropertyView { const gsl::span stringOffsetValues( _stringOffsets.data() + currentArrayOffset, arraySize + _arrayOffsetTypeSize); - return MetadataArrayView( + return PropertyArrayView( _values, stringOffsetValues, _stringOffsetType, arraySize / _arrayOffsetTypeSize); } - MetadataArrayView getBooleanArrayValues(int64_t index) const noexcept { + PropertyArrayView getBooleanArrayValues(int64_t index) const noexcept { // Handle fixed-length arrays if (_arrayCount > 0) { const size_t offsetBits = _arrayCount * index; @@ -406,7 +404,7 @@ template class PropertyTablePropertyView { const gsl::span buffer( _values.data() + offsetBits / 8, (nextOffsetBits / 8 - offsetBits / 8 + 1)); - return MetadataArrayView(buffer, offsetBits % 8, _arrayCount); + return PropertyArrayView(buffer, offsetBits % 8, _arrayCount); } // Handle variable-length arrays @@ -418,7 +416,7 @@ template class PropertyTablePropertyView { const gsl::span buffer( _values.data() + currentOffset / 8, (nextOffset / 8 - currentOffset / 8 + 1)); - return MetadataArrayView(buffer, currentOffset % 8, totalBits); + return PropertyArrayView(buffer, currentOffset % 8, totalBits); } static int64_t getOffsetTypeSize(PropertyComponentType offsetType) noexcept { @@ -451,6 +449,4 @@ template class PropertyTablePropertyView { int64_t _size; bool _normalized; }; - -} // namespace StructuralMetadata } // namespace CesiumGltf diff --git a/CesiumGltf/include/CesiumGltf/StructuralMetadataPropertyTableView.h b/CesiumGltf/include/CesiumGltf/PropertyTableView.h similarity index 91% rename from CesiumGltf/include/CesiumGltf/StructuralMetadataPropertyTableView.h rename to CesiumGltf/include/CesiumGltf/PropertyTableView.h index e3c55db2d..84757d07f 100644 --- a/CesiumGltf/include/CesiumGltf/StructuralMetadataPropertyTableView.h +++ b/CesiumGltf/include/CesiumGltf/PropertyTableView.h @@ -2,16 +2,14 @@ #include "CesiumGltf/ExtensionModelExtStructuralMetadata.h" #include "CesiumGltf/Model.h" -#include "CesiumGltf/StructuralMetadataPropertyTablePropertyView.h" -#include "CesiumGltf/StructuralMetadataPropertyType.h" +#include "CesiumGltf/PropertyTablePropertyView.h" +#include "CesiumGltf/PropertyType.h" #include #include namespace CesiumGltf { -namespace StructuralMetadata { - /** * @brief Indicates the status of a property table view. * @@ -107,7 +105,7 @@ class PropertyTableView { * following: a scalar (uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, * uint64_t, int64_t, float, double), a glm vecN composed of one of the scalar * types, a glm matN composed of one of the scalar types, bool, - * std::string_view, or {@link MetadataArrayView} with T as one of the + * std::string_view, or {@link PropertyArrayView} with T as one of the * aforementioned types. * * @param propertyName The name of the property to retrieve data from @@ -119,16 +117,14 @@ class PropertyTableView { getPropertyView(const std::string& propertyName) const { if (this->size() <= 0) { return createInvalidPropertyView( - StructuralMetadata::PropertyTablePropertyViewStatus:: - ErrorInvalidPropertyTable); + PropertyTablePropertyViewStatus::ErrorInvalidPropertyTable); } const ExtensionExtStructuralMetadataClassProperty* pClassProperty = getClassProperty(propertyName); if (!pClassProperty) { return createInvalidPropertyView( - StructuralMetadata::PropertyTablePropertyViewStatus:: - ErrorPropertyDoesNotExist); + PropertyTablePropertyViewStatus::ErrorPropertyDoesNotExist); } return getPropertyViewImpl(propertyName, *pClassProperty); @@ -144,7 +140,7 @@ class PropertyTableView { * following: a scalar (uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, * uint64_t, int64_t, float, double), a glm vecN composed of one of the scalar * types, a glm matN composed of one of the scalar types, bool, - * std::string_view, or {@link MetadataArrayView} with T as one of the + * std::string_view, or {@link PropertyArrayView} with T as one of the * aforementioned types. If the property is invalid, an empty * {@link PropertyTablePropertyView} with an error status will be passed to the * callback. Otherwise, a valid property view will be passed to the callback. @@ -160,8 +156,7 @@ class PropertyTableView { callback( propertyName, createInvalidPropertyView( - StructuralMetadata::PropertyTablePropertyViewStatus:: - ErrorInvalidPropertyTable)); + PropertyTablePropertyViewStatus::ErrorInvalidPropertyTable)); return; } @@ -236,7 +231,7 @@ class PropertyTableView { * following: a scalar (uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, * uint64_t, int64_t, float, double), a glm vecN composed of one of the scalar * types, a glm matN composed of one of the scalar types, bool, - * std::string_view, or {@link MetadataArrayView} with T as one of the + * std::string_view, or {@link PropertyArrayView} with T as one of the * aforementioned types. If the property is invalid, an empty * {@link PropertyTablePropertyView} with an error status code will be passed to the * callback. Otherwise, a valid property view will be passed to @@ -279,70 +274,70 @@ class PropertyTableView { case PropertyComponentType::Int8: callback( propertyName, - getPropertyViewImpl>( + getPropertyViewImpl>( propertyName, classProperty)); break; case PropertyComponentType::Uint8: callback( propertyName, - getPropertyViewImpl>( + getPropertyViewImpl>( propertyName, classProperty)); break; case PropertyComponentType::Int16: callback( propertyName, - getPropertyViewImpl>( + getPropertyViewImpl>( propertyName, classProperty)); break; case PropertyComponentType::Uint16: callback( propertyName, - getPropertyViewImpl>( + getPropertyViewImpl>( propertyName, classProperty)); break; case PropertyComponentType::Int32: callback( propertyName, - getPropertyViewImpl>( + getPropertyViewImpl>( propertyName, classProperty)); break; case PropertyComponentType::Uint32: callback( propertyName, - getPropertyViewImpl>( + getPropertyViewImpl>( propertyName, classProperty)); break; case PropertyComponentType::Int64: callback( propertyName, - getPropertyViewImpl>( + getPropertyViewImpl>( propertyName, classProperty)); break; case PropertyComponentType::Uint64: callback( propertyName, - getPropertyViewImpl>( + getPropertyViewImpl>( propertyName, classProperty)); break; case PropertyComponentType::Float32: callback( propertyName, - getPropertyViewImpl>( + getPropertyViewImpl>( propertyName, classProperty)); break; case PropertyComponentType::Float64: callback( propertyName, - getPropertyViewImpl>( + getPropertyViewImpl>( propertyName, classProperty)); break; @@ -365,70 +360,70 @@ class PropertyTableView { case PropertyComponentType::Int8: callback( propertyName, - getPropertyViewImpl>>( + getPropertyViewImpl>>( propertyName, classProperty)); break; case PropertyComponentType::Uint8: callback( propertyName, - getPropertyViewImpl>>( + getPropertyViewImpl>>( propertyName, classProperty)); break; case PropertyComponentType::Int16: callback( propertyName, - getPropertyViewImpl>>( + getPropertyViewImpl>>( propertyName, classProperty)); break; case PropertyComponentType::Uint16: callback( propertyName, - getPropertyViewImpl>>( + getPropertyViewImpl>>( propertyName, classProperty)); break; case PropertyComponentType::Int32: callback( propertyName, - getPropertyViewImpl>>( + getPropertyViewImpl>>( propertyName, classProperty)); break; case PropertyComponentType::Uint32: callback( propertyName, - getPropertyViewImpl>>( + getPropertyViewImpl>>( propertyName, classProperty)); break; case PropertyComponentType::Int64: callback( propertyName, - getPropertyViewImpl>>( + getPropertyViewImpl>>( propertyName, classProperty)); break; case PropertyComponentType::Uint64: callback( propertyName, - getPropertyViewImpl>>( + getPropertyViewImpl>>( propertyName, classProperty)); break; case PropertyComponentType::Float32: callback( propertyName, - getPropertyViewImpl>>( + getPropertyViewImpl>>( propertyName, classProperty)); break; case PropertyComponentType::Float64: callback( propertyName, - getPropertyViewImpl>>( + getPropertyViewImpl>>( propertyName, classProperty)); break; @@ -490,70 +485,70 @@ class PropertyTableView { case PropertyComponentType::Int8: callback( propertyName, - getPropertyViewImpl>>( + getPropertyViewImpl>>( propertyName, classProperty)); break; case PropertyComponentType::Uint8: callback( propertyName, - getPropertyViewImpl>>( + getPropertyViewImpl>>( propertyName, classProperty)); break; case PropertyComponentType::Int16: callback( propertyName, - getPropertyViewImpl>>( + getPropertyViewImpl>>( propertyName, classProperty)); break; case PropertyComponentType::Uint16: callback( propertyName, - getPropertyViewImpl>>( + getPropertyViewImpl>>( propertyName, classProperty)); break; case PropertyComponentType::Int32: callback( propertyName, - getPropertyViewImpl>>( + getPropertyViewImpl>>( propertyName, classProperty)); break; case PropertyComponentType::Uint32: callback( propertyName, - getPropertyViewImpl>>( + getPropertyViewImpl>>( propertyName, classProperty)); break; case PropertyComponentType::Int64: callback( propertyName, - getPropertyViewImpl>>( + getPropertyViewImpl>>( propertyName, classProperty)); break; case PropertyComponentType::Uint64: callback( propertyName, - getPropertyViewImpl>>( + getPropertyViewImpl>>( propertyName, classProperty)); break; case PropertyComponentType::Float32: callback( propertyName, - getPropertyViewImpl>>( + getPropertyViewImpl>>( propertyName, classProperty)); break; case PropertyComponentType::Float64: callback( propertyName, - getPropertyViewImpl>>( + getPropertyViewImpl>>( propertyName, classProperty)); break; @@ -635,14 +630,14 @@ class PropertyTableView { } else if (type == PropertyType::Boolean) { callback( propertyName, - getPropertyViewImpl>( + getPropertyViewImpl>( propertyName, classProperty)); } else if (type == PropertyType::String) { callback( propertyName, - getPropertyViewImpl>( + getPropertyViewImpl>( propertyName, classProperty)); } else { @@ -1036,7 +1031,7 @@ class PropertyTableView { if (values.size() % sizeof(T) != 0) { return createInvalidPropertyView( - StructuralMetadata::PropertyTablePropertyViewStatus:: + PropertyTablePropertyViewStatus:: ErrorBufferViewSizeNotDivisibleByTypeSize); } @@ -1067,19 +1062,19 @@ class PropertyTableView { propertyTableProperty) const; template - PropertyTablePropertyView> + PropertyTablePropertyView> getPrimitiveArrayPropertyValues( const ExtensionExtStructuralMetadataClassProperty& classProperty, const ExtensionExtStructuralMetadataPropertyTableProperty& propertyTableProperty) const { if (!classProperty.array) { - return createInvalidPropertyView>( + return createInvalidPropertyView>( PropertyTablePropertyViewStatus::ErrorArrayTypeMismatch); } const PropertyType type = convertStringToPropertyType(classProperty.type); if (TypeToPropertyType::value != type) { - return createInvalidPropertyView>( + return createInvalidPropertyView>( PropertyTablePropertyViewStatus::ErrorTypeMismatch); } @@ -1087,31 +1082,31 @@ class PropertyTableView { convertStringToPropertyComponentType( classProperty.componentType.value_or("")); if (TypeToPropertyType::component != componentType) { - return createInvalidPropertyView>( + return createInvalidPropertyView>( PropertyTablePropertyViewStatus::ErrorComponentTypeMismatch); } gsl::span values; auto status = getBufferSafe(propertyTableProperty.values, values); if (status != PropertyTablePropertyViewStatus::Valid) { - return createInvalidPropertyView>(status); + return createInvalidPropertyView>(status); } if (values.size() % sizeof(T) != 0) { - return createInvalidPropertyView>( + return createInvalidPropertyView>( PropertyTablePropertyViewStatus:: ErrorBufferViewSizeNotDivisibleByTypeSize); } const int64_t fixedLengthArrayCount = classProperty.count.value_or(0); if (fixedLengthArrayCount > 0 && propertyTableProperty.arrayOffsets >= 0) { - return createInvalidPropertyView>( + return createInvalidPropertyView>( PropertyTablePropertyViewStatus:: ErrorArrayCountAndOffsetBufferCoexist); } if (fixedLengthArrayCount <= 0 && propertyTableProperty.arrayOffsets < 0) { - return createInvalidPropertyView>( + return createInvalidPropertyView>( PropertyTablePropertyViewStatus:: ErrorArrayCountAndOffsetBufferDontExist); } @@ -1130,12 +1125,12 @@ class PropertyTableView { } if (values.size() < maxRequiredBytes) { - return createInvalidPropertyView>( + return createInvalidPropertyView>( PropertyTablePropertyViewStatus:: ErrorBufferViewSizeDoesNotMatchPropertyTableCount); } - return PropertyTablePropertyView>( + return PropertyTablePropertyView>( PropertyTablePropertyViewStatus::Valid, values, gsl::span(), @@ -1152,7 +1147,7 @@ class PropertyTableView { convertArrayOffsetTypeStringToPropertyComponentType( propertyTableProperty.arrayOffsetType); if (arrayOffsetType == PropertyComponentType::None) { - return createInvalidPropertyView>( + return createInvalidPropertyView>( PropertyTablePropertyViewStatus::ErrorInvalidArrayOffsetType); } @@ -1166,10 +1161,10 @@ class PropertyTableView { checkBitsSize, arrayOffsets); if (status != PropertyTablePropertyViewStatus::Valid) { - return createInvalidPropertyView>(status); + return createInvalidPropertyView>(status); } - return PropertyTablePropertyView>( + return PropertyTablePropertyView>( PropertyTablePropertyViewStatus::Valid, values, arrayOffsets, @@ -1181,7 +1176,7 @@ class PropertyTableView { classProperty.normalized); } - PropertyTablePropertyView> + PropertyTablePropertyView> getStringArrayPropertyValues( const ExtensionExtStructuralMetadataClassProperty& classProperty, const ExtensionExtStructuralMetadataPropertyTableProperty& @@ -1221,6 +1216,4 @@ class PropertyTableView { const ExtensionExtStructuralMetadataClass* _pClass; PropertyTableViewStatus _status; }; - -} // namespace StructuralMetadata } // namespace CesiumGltf diff --git a/CesiumGltf/include/CesiumGltf/StructuralMetadataPropertyTexturePropertyView.h b/CesiumGltf/include/CesiumGltf/PropertyTexturePropertyView.h similarity index 99% rename from CesiumGltf/include/CesiumGltf/StructuralMetadataPropertyTexturePropertyView.h rename to CesiumGltf/include/CesiumGltf/PropertyTexturePropertyView.h index e8f858732..a6b97ccd1 100644 --- a/CesiumGltf/include/CesiumGltf/StructuralMetadataPropertyTexturePropertyView.h +++ b/CesiumGltf/include/CesiumGltf/PropertyTexturePropertyView.h @@ -14,7 +14,6 @@ #include namespace CesiumGltf { -namespace StructuralMetadata { /** * @brief Indicates the status of a property texture property view. * @@ -241,6 +240,4 @@ class PropertyTexturePropertyView { int64_t _count; bool _normalized; }; - -} // namespace StructuralMetadata } // namespace CesiumGltf diff --git a/CesiumGltf/include/CesiumGltf/StructuralMetadataPropertyTextureView.h b/CesiumGltf/include/CesiumGltf/PropertyTextureView.h similarity index 96% rename from CesiumGltf/include/CesiumGltf/StructuralMetadataPropertyTextureView.h rename to CesiumGltf/include/CesiumGltf/PropertyTextureView.h index 9d053357e..69c0f70e2 100644 --- a/CesiumGltf/include/CesiumGltf/StructuralMetadataPropertyTextureView.h +++ b/CesiumGltf/include/CesiumGltf/PropertyTextureView.h @@ -4,7 +4,7 @@ #include "CesiumGltf/ExtensionExtStructuralMetadataClassProperty.h" #include "CesiumGltf/ExtensionExtStructuralMetadataPropertyTexture.h" #include "CesiumGltf/ExtensionModelExtStructuralMetadata.h" -#include "CesiumGltf/StructuralMetadataPropertyTexturePropertyView.h" +#include "CesiumGltf/PropertyTexturePropertyView.h" #include "CesiumGltf/Texture.h" #include "CesiumGltf/TextureAccessor.h" #include "Image.h" @@ -12,8 +12,6 @@ #include "Model.h" namespace CesiumGltf { -namespace StructuralMetadata { - /** * @brief Indicates the status of a property texture view. * @@ -119,6 +117,4 @@ class PropertyTextureView { std::unordered_map _propertyViews; PropertyTextureViewStatus _status; }; - -} // namespace StructuralMetadata } // namespace CesiumGltf diff --git a/CesiumGltf/include/CesiumGltf/PropertyType.h b/CesiumGltf/include/CesiumGltf/PropertyType.h index 130d37fad..e5771a015 100644 --- a/CesiumGltf/include/CesiumGltf/PropertyType.h +++ b/CesiumGltf/include/CesiumGltf/PropertyType.h @@ -6,6 +6,20 @@ namespace CesiumGltf { enum class PropertyType { + Invalid, + Scalar, + Vec2, + Vec3, + Vec4, + Mat2, + Mat3, + Mat4, + String, + Boolean, + Enum +}; + +enum class PropertyComponentType { None, Int8, Uint8, @@ -17,15 +31,25 @@ enum class PropertyType { Uint64, Float32, Float64, - Boolean, - Enum, - String, - Array, }; -std::string convertPropertyTypeToString(CesiumGltf::PropertyType type); +std::string convertPropertyTypeToString(PropertyType type); PropertyType convertStringToPropertyType(const std::string& str); -PropertyType convertOffsetStringToPropertyType(const std::string& str); +std::string +convertPropertyComponentTypeToString(PropertyComponentType componentType); + +PropertyComponentType +convertStringToPropertyComponentType(const std::string& str); + +PropertyComponentType +convertArrayOffsetTypeStringToPropertyComponentType(const std::string& str); + +PropertyComponentType +convertStringOffsetTypeStringToPropertyComponentType(const std::string& str); + +bool isPropertyTypeVecN(PropertyType type); + +bool isPropertyTypeMatN(PropertyType type); } // namespace CesiumGltf diff --git a/CesiumGltf/include/CesiumGltf/PropertyTypeTraits.h b/CesiumGltf/include/CesiumGltf/PropertyTypeTraits.h index 144365665..999947f54 100644 --- a/CesiumGltf/include/CesiumGltf/PropertyTypeTraits.h +++ b/CesiumGltf/include/CesiumGltf/PropertyTypeTraits.h @@ -1,27 +1,29 @@ #pragma once -#include "CesiumGltf/MetadataArrayView.h" +#include "CesiumGltf/PropertyArrayView.h" #include "CesiumGltf/PropertyType.h" +#include + #include #include namespace CesiumGltf { /** - * @brief Check if a C++ type can be represented as a numeric property type + * @brief Check if a C++ type can be represented as a scalar property type */ -template struct IsMetadataNumeric; -template struct IsMetadataNumeric : std::false_type {}; -template <> struct IsMetadataNumeric : std::true_type {}; -template <> struct IsMetadataNumeric : std::true_type {}; -template <> struct IsMetadataNumeric : std::true_type {}; -template <> struct IsMetadataNumeric : std::true_type {}; -template <> struct IsMetadataNumeric : std::true_type {}; -template <> struct IsMetadataNumeric : std::true_type {}; -template <> struct IsMetadataNumeric : std::true_type {}; -template <> struct IsMetadataNumeric : std::true_type {}; -template <> struct IsMetadataNumeric : std::true_type {}; -template <> struct IsMetadataNumeric : std::true_type {}; +template struct IsMetadataScalar; +template struct IsMetadataScalar : std::false_type {}; +template <> struct IsMetadataScalar : std::true_type {}; +template <> struct IsMetadataScalar : std::true_type {}; +template <> struct IsMetadataScalar : std::true_type {}; +template <> struct IsMetadataScalar : std::true_type {}; +template <> struct IsMetadataScalar : std::true_type {}; +template <> struct IsMetadataScalar : std::true_type {}; +template <> struct IsMetadataScalar : std::true_type {}; +template <> struct IsMetadataScalar : std::true_type {}; +template <> struct IsMetadataScalar : std::true_type {}; +template <> struct IsMetadataScalar : std::true_type {}; /** * @brief Check if a C++ type can be represented as an integer property type @@ -39,13 +41,40 @@ template <> struct IsMetadataInteger : std::true_type {}; /** * @brief Check if a C++ type can be represented as a floating-point property - * type + * type. */ template struct IsMetadataFloating; template struct IsMetadataFloating : std::false_type {}; template <> struct IsMetadataFloating : std::true_type {}; template <> struct IsMetadataFloating : std::true_type {}; +/** + * @brief Check if a C++ type can be represented as a vecN type. + */ +template struct IsMetadataVecN; +template struct IsMetadataVecN : std::false_type {}; +template +struct IsMetadataVecN> : IsMetadataScalar {}; + +/** + * @brief Check if a C++ type can be represented as a matN type. + */ +template struct IsMetadataMatN; +template struct IsMetadataMatN : std::false_type {}; +template +struct IsMetadataMatN> : IsMetadataScalar {}; + +/** + * @brief Check if a C++ type can be represented as a numeric property, i.e. + * a scalar / vecN / matN type. + */ +template struct IsMetadataNumeric; +template struct IsMetadataNumeric { + static constexpr bool value = IsMetadataScalar::value || + IsMetadataVecN::value || + IsMetadataMatN::value; +}; + /** * @brief Check if a C++ type can be represented as a boolean property type */ @@ -66,35 +95,35 @@ template <> struct IsMetadataString : std::true_type {}; template struct IsMetadataArray; template struct IsMetadataArray : std::false_type {}; template -struct IsMetadataArray> : std::true_type {}; +struct IsMetadataArray> : std::true_type {}; /** - * @brief Check if a C++ type can be represented as an array of number property - * type + * @brief Check if a C++ type can be represented as an array of numeric elements + * property type */ template struct IsMetadataNumericArray; template struct IsMetadataNumericArray : std::false_type {}; -template struct IsMetadataNumericArray> { +template struct IsMetadataNumericArray> { static constexpr bool value = IsMetadataNumeric::value; }; /** - * @brief Check if a C++ type can be represented as an array of boolean property - * type + * @brief Check if a C++ type can be represented as an array of booleans + * property type */ template struct IsMetadataBooleanArray; template struct IsMetadataBooleanArray : std::false_type {}; template <> -struct IsMetadataBooleanArray> : std::true_type {}; +struct IsMetadataBooleanArray> : std::true_type {}; /** - * @brief Check if a C++ type can be represented as an array of string property + * @brief Check if a C++ type can be represented as an array of strings property * type */ template struct IsMetadataStringArray; template struct IsMetadataStringArray : std::false_type {}; template <> -struct IsMetadataStringArray> +struct IsMetadataStringArray> : std::true_type {}; /** @@ -102,79 +131,137 @@ struct IsMetadataStringArray> */ template struct MetadataArrayType; template -struct MetadataArrayType> { +struct MetadataArrayType> { using type = T; }; /** - * @brief Convert a C++ type to PropertyType + * @brief Convert a C++ type to PropertyType and PropertyComponentType */ template struct TypeToPropertyType; +#pragma region Scalar Property Types + template <> struct TypeToPropertyType { - static constexpr PropertyType component = PropertyType::None; - static constexpr PropertyType value = PropertyType::Uint8; + static constexpr PropertyComponentType component = + PropertyComponentType::Uint8; + static constexpr PropertyType value = PropertyType::Scalar; }; template <> struct TypeToPropertyType { - static constexpr PropertyType component = PropertyType::None; - static constexpr PropertyType value = PropertyType::Int8; + static constexpr PropertyComponentType component = + PropertyComponentType::Int8; + static constexpr PropertyType value = PropertyType::Scalar; }; template <> struct TypeToPropertyType { - static constexpr PropertyType component = PropertyType::None; - static constexpr PropertyType value = PropertyType::Uint16; + static constexpr PropertyComponentType component = + PropertyComponentType::Uint16; + static constexpr PropertyType value = PropertyType::Scalar; }; template <> struct TypeToPropertyType { - static constexpr PropertyType component = PropertyType::None; - static constexpr PropertyType value = PropertyType::Int16; + static constexpr PropertyComponentType component = + PropertyComponentType::Int16; + static constexpr PropertyType value = PropertyType::Scalar; }; template <> struct TypeToPropertyType { - static constexpr PropertyType component = PropertyType::None; - static constexpr PropertyType value = PropertyType::Uint32; + static constexpr PropertyComponentType component = + PropertyComponentType::Uint32; + static constexpr PropertyType value = PropertyType::Scalar; }; template <> struct TypeToPropertyType { - static constexpr PropertyType component = PropertyType::None; - static constexpr PropertyType value = PropertyType::Int32; + static constexpr PropertyComponentType component = + PropertyComponentType::Int32; + static constexpr PropertyType value = PropertyType::Scalar; }; template <> struct TypeToPropertyType { - static constexpr PropertyType component = PropertyType::None; - static constexpr PropertyType value = PropertyType::Uint64; + static constexpr PropertyComponentType component = + PropertyComponentType::Uint64; + static constexpr PropertyType value = PropertyType::Scalar; }; template <> struct TypeToPropertyType { - static constexpr PropertyType component = PropertyType::None; - static constexpr PropertyType value = PropertyType::Int64; + static constexpr PropertyComponentType component = + PropertyComponentType::Int64; + static constexpr PropertyType value = PropertyType::Scalar; }; template <> struct TypeToPropertyType { - static constexpr PropertyType component = PropertyType::None; - static constexpr PropertyType value = PropertyType::Float32; + static constexpr PropertyComponentType component = + PropertyComponentType::Float32; + static constexpr PropertyType value = PropertyType::Scalar; }; template <> struct TypeToPropertyType { - static constexpr PropertyType component = PropertyType::None; - static constexpr PropertyType value = PropertyType::Float64; + static constexpr PropertyComponentType component = + PropertyComponentType::Float64; + static constexpr PropertyType value = PropertyType::Scalar; }; +#pragma endregion + +#pragma region Vector Property Types + +template +struct TypeToPropertyType> { + static constexpr PropertyComponentType component = + TypeToPropertyType::component; + static constexpr PropertyType value = PropertyType::Vec2; +}; + +template +struct TypeToPropertyType> { + static constexpr PropertyComponentType component = + TypeToPropertyType::component; + static constexpr PropertyType value = PropertyType::Vec3; +}; + +template +struct TypeToPropertyType> { + static constexpr PropertyComponentType component = + TypeToPropertyType::component; + static constexpr PropertyType value = PropertyType::Vec4; +}; + +#pragma endregion + +#pragma region Matrix Property Types + +template +struct TypeToPropertyType> { + static constexpr PropertyComponentType component = + TypeToPropertyType::component; + static constexpr PropertyType value = PropertyType::Mat2; +}; + +template +struct TypeToPropertyType> { + static constexpr PropertyComponentType component = + TypeToPropertyType::component; + static constexpr PropertyType value = PropertyType::Mat3; +}; + +template +struct TypeToPropertyType> { + static constexpr PropertyComponentType component = + TypeToPropertyType::component; + static constexpr PropertyType value = PropertyType::Mat4; +}; + +#pragma endregion template <> struct TypeToPropertyType { - static constexpr PropertyType component = PropertyType::None; + static constexpr PropertyComponentType component = + PropertyComponentType::None; static constexpr PropertyType value = PropertyType::Boolean; }; template <> struct TypeToPropertyType { - static constexpr PropertyType component = PropertyType::None; + static constexpr PropertyComponentType component = + PropertyComponentType::None; static constexpr PropertyType value = PropertyType::String; }; - -template -struct TypeToPropertyType> { - static constexpr PropertyType component = TypeToPropertyType::value; - static constexpr PropertyType value = PropertyType::Array; -}; - } // namespace CesiumGltf diff --git a/CesiumGltf/include/CesiumGltf/StructuralMetadataPropertyType.h b/CesiumGltf/include/CesiumGltf/StructuralMetadataPropertyType.h deleted file mode 100644 index 4648c7c12..000000000 --- a/CesiumGltf/include/CesiumGltf/StructuralMetadataPropertyType.h +++ /dev/null @@ -1,59 +0,0 @@ -#pragma once - -#include -#include -#include - -namespace CesiumGltf { -namespace StructuralMetadata { - -enum class PropertyType { - Invalid, - Scalar, - Vec2, - Vec3, - Vec4, - Mat2, - Mat3, - Mat4, - String, - Boolean, - Enum -}; - -enum class PropertyComponentType { - None, - Int8, - Uint8, - Int16, - Uint16, - Int32, - Uint32, - Int64, - Uint64, - Float32, - Float64, -}; - -std::string convertPropertyTypeToString(PropertyType type); - -PropertyType convertStringToPropertyType(const std::string& str); - -std::string -convertPropertyComponentTypeToString(PropertyComponentType componentType); - -PropertyComponentType -convertStringToPropertyComponentType(const std::string& str); - -PropertyComponentType -convertArrayOffsetTypeStringToPropertyComponentType(const std::string& str); - -PropertyComponentType -convertStringOffsetTypeStringToPropertyComponentType(const std::string& str); - -bool isPropertyTypeVecN(PropertyType type); - -bool isPropertyTypeMatN(PropertyType type); - -} // namespace StructuralMetadata -} // namespace CesiumGltf diff --git a/CesiumGltf/include/CesiumGltf/StructuralMetadataPropertyTypeTraits.h b/CesiumGltf/include/CesiumGltf/StructuralMetadataPropertyTypeTraits.h deleted file mode 100644 index 535667d9a..000000000 --- a/CesiumGltf/include/CesiumGltf/StructuralMetadataPropertyTypeTraits.h +++ /dev/null @@ -1,271 +0,0 @@ -#pragma once - -#include "CesiumGltf/StructuralMetadataArrayView.h" -#include "CesiumGltf/StructuralMetadataPropertyType.h" - -#include - -#include -#include - -namespace CesiumGltf { -namespace StructuralMetadata { - -/** - * @brief Check if a C++ type can be represented as a scalar property type - */ -template struct IsMetadataScalar; -template struct IsMetadataScalar : std::false_type {}; -template <> struct IsMetadataScalar : std::true_type {}; -template <> struct IsMetadataScalar : std::true_type {}; -template <> struct IsMetadataScalar : std::true_type {}; -template <> struct IsMetadataScalar : std::true_type {}; -template <> struct IsMetadataScalar : std::true_type {}; -template <> struct IsMetadataScalar : std::true_type {}; -template <> struct IsMetadataScalar : std::true_type {}; -template <> struct IsMetadataScalar : std::true_type {}; -template <> struct IsMetadataScalar : std::true_type {}; -template <> struct IsMetadataScalar : std::true_type {}; - -/** - * @brief Check if a C++ type can be represented as an integer property type - */ -template struct IsMetadataInteger; -template struct IsMetadataInteger : std::false_type {}; -template <> struct IsMetadataInteger : std::true_type {}; -template <> struct IsMetadataInteger : std::true_type {}; -template <> struct IsMetadataInteger : std::true_type {}; -template <> struct IsMetadataInteger : std::true_type {}; -template <> struct IsMetadataInteger : std::true_type {}; -template <> struct IsMetadataInteger : std::true_type {}; -template <> struct IsMetadataInteger : std::true_type {}; -template <> struct IsMetadataInteger : std::true_type {}; - -/** - * @brief Check if a C++ type can be represented as a floating-point property - * type. - */ -template struct IsMetadataFloating; -template struct IsMetadataFloating : std::false_type {}; -template <> struct IsMetadataFloating : std::true_type {}; -template <> struct IsMetadataFloating : std::true_type {}; - -/** - * @brief Check if a C++ type can be represented as a vecN type. - */ -template struct IsMetadataVecN; -template struct IsMetadataVecN : std::false_type {}; -template -struct IsMetadataVecN> : IsMetadataScalar {}; - -/** - * @brief Check if a C++ type can be represented as a matN type. - */ -template struct IsMetadataMatN; -template struct IsMetadataMatN : std::false_type {}; -template -struct IsMetadataMatN> : IsMetadataScalar {}; - -/** - * @brief Check if a C++ type can be represented as a numeric property, i.e. - * a scalar / vecN / matN type. - */ -template struct IsMetadataNumeric; -template struct IsMetadataNumeric { - static constexpr bool value = IsMetadataScalar::value || - IsMetadataVecN::value || - IsMetadataMatN::value; -}; - -/** - * @brief Check if a C++ type can be represented as a boolean property type - */ -template struct IsMetadataBoolean; -template struct IsMetadataBoolean : std::false_type {}; -template <> struct IsMetadataBoolean : std::true_type {}; - -/** - * @brief Check if a C++ type can be represented as a string property type - */ -template struct IsMetadataString; -template struct IsMetadataString : std::false_type {}; -template <> struct IsMetadataString : std::true_type {}; - -/** - * @brief Check if a C++ type can be represented as an array. - */ -template struct IsMetadataArray; -template struct IsMetadataArray : std::false_type {}; -template -struct IsMetadataArray> : std::true_type {}; - -/** - * @brief Check if a C++ type can be represented as an array of numeric elements - * property type - */ -template struct IsMetadataNumericArray; -template struct IsMetadataNumericArray : std::false_type {}; -template struct IsMetadataNumericArray> { - static constexpr bool value = IsMetadataNumeric::value; -}; - -/** - * @brief Check if a C++ type can be represented as an array of booleans - * property type - */ -template struct IsMetadataBooleanArray; -template struct IsMetadataBooleanArray : std::false_type {}; -template <> -struct IsMetadataBooleanArray> : std::true_type {}; - -/** - * @brief Check if a C++ type can be represented as an array of strings property - * type - */ -template struct IsMetadataStringArray; -template struct IsMetadataStringArray : std::false_type {}; -template <> -struct IsMetadataStringArray> - : std::true_type {}; - -/** - * @brief Retrieve the component type of a metadata array - */ -template struct MetadataArrayType; -template -struct MetadataArrayType> { - using type = T; -}; - -/** - * @brief Convert a C++ type to PropertyType and PropertyComponentType - */ -template struct TypeToPropertyType; - -#pragma region Scalar Property Types - -template <> struct TypeToPropertyType { - static constexpr PropertyComponentType component = - PropertyComponentType::Uint8; - static constexpr PropertyType value = PropertyType::Scalar; -}; - -template <> struct TypeToPropertyType { - static constexpr PropertyComponentType component = - PropertyComponentType::Int8; - static constexpr PropertyType value = PropertyType::Scalar; -}; - -template <> struct TypeToPropertyType { - static constexpr PropertyComponentType component = - PropertyComponentType::Uint16; - static constexpr PropertyType value = PropertyType::Scalar; -}; - -template <> struct TypeToPropertyType { - static constexpr PropertyComponentType component = - PropertyComponentType::Int16; - static constexpr PropertyType value = PropertyType::Scalar; -}; - -template <> struct TypeToPropertyType { - static constexpr PropertyComponentType component = - PropertyComponentType::Uint32; - static constexpr PropertyType value = PropertyType::Scalar; -}; - -template <> struct TypeToPropertyType { - static constexpr PropertyComponentType component = - PropertyComponentType::Int32; - static constexpr PropertyType value = PropertyType::Scalar; -}; - -template <> struct TypeToPropertyType { - static constexpr PropertyComponentType component = - PropertyComponentType::Uint64; - static constexpr PropertyType value = PropertyType::Scalar; -}; - -template <> struct TypeToPropertyType { - static constexpr PropertyComponentType component = - PropertyComponentType::Int64; - static constexpr PropertyType value = PropertyType::Scalar; -}; - -template <> struct TypeToPropertyType { - static constexpr PropertyComponentType component = - PropertyComponentType::Float32; - static constexpr PropertyType value = PropertyType::Scalar; -}; - -template <> struct TypeToPropertyType { - static constexpr PropertyComponentType component = - PropertyComponentType::Float64; - static constexpr PropertyType value = PropertyType::Scalar; -}; -#pragma endregion - -#pragma region Vector Property Types - -template -struct TypeToPropertyType> { - static constexpr PropertyComponentType component = - TypeToPropertyType::component; - static constexpr PropertyType value = PropertyType::Vec2; -}; - -template -struct TypeToPropertyType> { - static constexpr PropertyComponentType component = - TypeToPropertyType::component; - static constexpr PropertyType value = PropertyType::Vec3; -}; - -template -struct TypeToPropertyType> { - static constexpr PropertyComponentType component = - TypeToPropertyType::component; - static constexpr PropertyType value = PropertyType::Vec4; -}; - -#pragma endregion - -#pragma region Matrix Property Types - -template -struct TypeToPropertyType> { - static constexpr PropertyComponentType component = - TypeToPropertyType::component; - static constexpr PropertyType value = PropertyType::Mat2; -}; - -template -struct TypeToPropertyType> { - static constexpr PropertyComponentType component = - TypeToPropertyType::component; - static constexpr PropertyType value = PropertyType::Mat3; -}; - -template -struct TypeToPropertyType> { - static constexpr PropertyComponentType component = - TypeToPropertyType::component; - static constexpr PropertyType value = PropertyType::Mat4; -}; - -#pragma endregion - -template <> struct TypeToPropertyType { - static constexpr PropertyComponentType component = - PropertyComponentType::None; - static constexpr PropertyType value = PropertyType::Boolean; -}; - -template <> struct TypeToPropertyType { - static constexpr PropertyComponentType component = - PropertyComponentType::None; - static constexpr PropertyType value = PropertyType::String; -}; - -} // namespace StructuralMetadata -} // namespace CesiumGltf diff --git a/CesiumGltf/include/CesiumGltf/getOffsetFromOffsetsBuffer.h b/CesiumGltf/include/CesiumGltf/getOffsetFromOffsetsBuffer.h index 431430bf4..762f698cc 100644 --- a/CesiumGltf/include/CesiumGltf/getOffsetFromOffsetsBuffer.h +++ b/CesiumGltf/include/CesiumGltf/getOffsetFromOffsetsBuffer.h @@ -1,6 +1,6 @@ #pragma once -#include "CesiumGltf/StructuralMetadataPropertyType.h" +#include "CesiumGltf/PropertyType.h" #include @@ -10,8 +10,6 @@ #include namespace CesiumGltf { -namespace StructuralMetadata { - static size_t getOffsetFromOffsetsBuffer( size_t index, const gsl::span& offsetBuffer, @@ -46,6 +44,4 @@ static size_t getOffsetFromOffsetsBuffer( return 0; } } - -} // namespace StructuralMetadata } // namespace CesiumGltf diff --git a/CesiumGltf/src/FeatureIDTextureView.cpp b/CesiumGltf/src/FeatureIDTextureView.cpp deleted file mode 100644 index 2847314c3..000000000 --- a/CesiumGltf/src/FeatureIDTextureView.cpp +++ /dev/null @@ -1,91 +0,0 @@ -#include "CesiumGltf/FeatureIDTextureView.h" - -namespace CesiumGltf { - -FeatureIDTextureView::FeatureIDTextureView() noexcept - : _pImage(nullptr), - _channel(0), - _textureCoordinateAttributeId(-1), - _featureTableName(), - _status(FeatureIDTextureViewStatus::InvalidUninitialized) {} - -FeatureIDTextureView::FeatureIDTextureView( - const Model& model, - const FeatureIDTexture& featureIDTexture) noexcept - : _pImage(nullptr), - _channel(0), - _textureCoordinateAttributeId(-1), - _featureTableName(featureIDTexture.featureTable), - _status(FeatureIDTextureViewStatus::InvalidUninitialized) { - - this->_textureCoordinateAttributeId = - featureIDTexture.featureIds.texture.texCoord; - - int32_t textureIndex = featureIDTexture.featureIds.texture.index; - if (textureIndex < 0 || - static_cast(textureIndex) >= model.textures.size()) { - this->_status = FeatureIDTextureViewStatus::InvalidTextureIndex; - return; - } - - const Texture& texture = model.textures[static_cast(textureIndex)]; - - // Ignore sampler, we will always use nearest pixel sampling. - if (texture.source < 0 || - static_cast(texture.source) >= model.images.size()) { - this->_status = FeatureIDTextureViewStatus::InvalidImageIndex; - return; - } - - this->_pImage = &model.images[static_cast(texture.source)].cesium; - - // This assumes that if the channel is g, there must be at least two - // channels (r and g). If it is b there must be r, g, and b. If there is a, - // then there must be r, g, b, and a. - if (featureIDTexture.featureIds.channels == "r") { - this->_channel = 0; - } else if (featureIDTexture.featureIds.channels == "g") { - this->_channel = 1; - } else if (featureIDTexture.featureIds.channels == "b") { - this->_channel = 2; - } else if (featureIDTexture.featureIds.channels == "a") { - this->_channel = 3; - } else { - this->_status = FeatureIDTextureViewStatus::InvalidChannel; - return; - } - - if (this->_pImage->width < 1 || this->_pImage->height < 1) { - this->_status = FeatureIDTextureViewStatus::InvalidEmptyImage; - return; - } - - // TODO: once compressed texture support is merged, check that the image is - // decompressed here. - - this->_status = FeatureIDTextureViewStatus::Valid; -} - -int64_t FeatureIDTextureView::getFeatureID(double u, double v) const noexcept { - if (this->_status != FeatureIDTextureViewStatus::Valid) { - return -1; - } - - int64_t x = std::clamp( - std::llround(u * this->_pImage->width), - 0LL, - (long long)this->_pImage->width); - int64_t y = std::clamp( - std::llround(v * this->_pImage->height), - 0LL, - (long long)this->_pImage->height); - - int64_t pixelOffset = this->_pImage->bytesPerChannel * - this->_pImage->channels * - (y * this->_pImage->width + x); - - return static_cast( - this->_pImage - ->pixelData[static_cast(pixelOffset + this->_channel)]); -} -} // namespace CesiumGltf \ No newline at end of file diff --git a/CesiumGltf/src/MeshFeaturesFeatureIdTextureView.cpp b/CesiumGltf/src/FeatureIdTextureView.cpp similarity index 96% rename from CesiumGltf/src/MeshFeaturesFeatureIdTextureView.cpp rename to CesiumGltf/src/FeatureIdTextureView.cpp index 0727e091f..589f98ac2 100644 --- a/CesiumGltf/src/MeshFeaturesFeatureIdTextureView.cpp +++ b/CesiumGltf/src/FeatureIdTextureView.cpp @@ -1,7 +1,6 @@ -#include "CesiumGltf/MeshFeaturesFeatureIdTextureView.h" +#include "CesiumGltf/FeatureIdTextureView.h" namespace CesiumGltf { -namespace MeshFeatures { FeatureIdTextureView::FeatureIdTextureView() noexcept : _status(FeatureIdTextureViewStatus::ErrorUninitialized), _texCoordSetIndex(-1), @@ -104,6 +103,4 @@ int64_t FeatureIdTextureView::getFeatureId(double u, double v) const noexcept { return value; } - -} // namespace MeshFeatures } // namespace CesiumGltf diff --git a/CesiumGltf/src/FeatureTexturePropertyView.cpp b/CesiumGltf/src/FeatureTexturePropertyView.cpp deleted file mode 100644 index 0fe9d7e3c..000000000 --- a/CesiumGltf/src/FeatureTexturePropertyView.cpp +++ /dev/null @@ -1,101 +0,0 @@ - -#include "CesiumGltf/FeatureTexturePropertyView.h" - -namespace CesiumGltf { - -FeatureTexturePropertyView::FeatureTexturePropertyView() noexcept - : _pSampler(nullptr), - _pImage(nullptr), - _pClassProperty(nullptr), - _pSwizzle(nullptr), - _textureCoordinateAttributeId(-1), - _status(FeatureTexturePropertyViewStatus::InvalidUninitialized), - _channelOffsets(), - _type(FeatureTexturePropertyComponentType::Uint8), - _componentCount(0), - _normalized(false) {} - -FeatureTexturePropertyView::FeatureTexturePropertyView( - const Model& model, - const ClassProperty& classProperty, - const TextureAccessor& textureAccessor) noexcept - : _pSampler(nullptr), - _pImage(nullptr), - _pClassProperty(&classProperty), - _pSwizzle(&textureAccessor.channels), - _textureCoordinateAttributeId(textureAccessor.texture.texCoord), - _status(FeatureTexturePropertyViewStatus::InvalidUninitialized), - _channelOffsets(), - _type(FeatureTexturePropertyComponentType::Uint8), - _componentCount(0), - _normalized(false) { - - if (textureAccessor.texture.index < 0 || - static_cast(textureAccessor.texture.index) >= - model.textures.size()) { - this->_status = FeatureTexturePropertyViewStatus::InvalidTextureIndex; - return; - } - - const Texture& texture = - model.textures[static_cast(textureAccessor.texture.index)]; - if (texture.sampler < 0 || - static_cast(texture.sampler) >= model.samplers.size()) { - this->_status = - FeatureTexturePropertyViewStatus::InvalidTextureSamplerIndex; - return; - } - - this->_pSampler = &model.samplers[static_cast(texture.sampler)]; - - if (texture.source < 0 || - static_cast(texture.source) >= model.images.size()) { - this->_status = FeatureTexturePropertyViewStatus::InvalidImageIndex; - return; - } - - this->_pImage = &model.images[static_cast(texture.source)].cesium; - - if (this->_pImage->width < 1 || this->_pImage->height < 1) { - this->_status = FeatureTexturePropertyViewStatus::InvalidEmptyImage; - return; - } - - // TODO: support more types - // this->_type = ... - this->_componentCount = this->_pClassProperty->componentCount - ? *this->_pClassProperty->componentCount - : 1; - this->_normalized = this->_pClassProperty->normalized; - if (textureAccessor.channels.length() > 4 || - textureAccessor.channels.length() > - static_cast(this->_pImage->channels) || - textureAccessor.channels.length() != - static_cast(this->_componentCount)) { - this->_status = FeatureTexturePropertyViewStatus::InvalidChannelsString; - return; - } - - for (size_t i = 0; i < textureAccessor.channels.length(); ++i) { - switch (textureAccessor.channels[i]) { - case 'r': - this->_channelOffsets.r = 0; - break; - case 'g': - this->_channelOffsets.g = 1; - break; - case 'b': - this->_channelOffsets.b = 2; - break; - case 'a': - this->_channelOffsets.a = 3; - break; - default: - this->_status = FeatureTexturePropertyViewStatus::InvalidChannelsString; - return; - } - } - - this->_status = FeatureTexturePropertyViewStatus::Valid; -} -} // namespace CesiumGltf \ No newline at end of file diff --git a/CesiumGltf/src/FeatureTextureView.cpp b/CesiumGltf/src/FeatureTextureView.cpp deleted file mode 100644 index 3ef0bfb55..000000000 --- a/CesiumGltf/src/FeatureTextureView.cpp +++ /dev/null @@ -1,68 +0,0 @@ -#include "CesiumGltf/FeatureTextureView.h" - -namespace CesiumGltf { - -FeatureTextureView::FeatureTextureView() noexcept - : _pModel(nullptr), - _pFeatureTexture(nullptr), - _pClass(nullptr), - _propertyViews(), - _status(FeatureTextureViewStatus::InvalidUninitialized) {} - -FeatureTextureView::FeatureTextureView( - const Model& model, - const FeatureTexture& featureTexture) noexcept - : _pModel(&model), - _pFeatureTexture(&featureTexture), - _pClass(nullptr), - _propertyViews(), - _status(FeatureTextureViewStatus::InvalidUninitialized) { - - const ExtensionModelExtFeatureMetadata* pMetadata = - model.getExtension(); - - if (!pMetadata) { - this->_status = FeatureTextureViewStatus::InvalidMissingMetadataExtension; - return; - } - - if (!pMetadata->schema) { - this->_status = FeatureTextureViewStatus::InvalidMissingSchema; - return; - } - - const auto& classIt = - pMetadata->schema->classes.find(featureTexture.classProperty); - if (classIt == pMetadata->schema->classes.end()) { - this->_status = FeatureTextureViewStatus::InvalidClassNotFound; - return; - } - - this->_pClass = &classIt->second; - - this->_propertyViews.reserve(featureTexture.properties.size()); - for (const auto& property : featureTexture.properties) { - auto classPropertyIt = this->_pClass->properties.find(property.first); - - if (classPropertyIt == this->_pClass->properties.end()) { - this->_status = FeatureTextureViewStatus::InvalidClassPropertyNotFound; - return; - } - - this->_propertyViews[property.first] = FeatureTexturePropertyView( - model, - classPropertyIt->second, - property.second); - } - - for (const auto& propertyView : this->_propertyViews) { - if (propertyView.second.status() != - FeatureTexturePropertyViewStatus::Valid) { - this->_status = FeatureTextureViewStatus::InvalidPropertyViewStatus; - return; - } - } - - this->_status = FeatureTextureViewStatus::Valid; -} -} // namespace CesiumGltf \ No newline at end of file diff --git a/CesiumGltf/src/MetadataFeatureTableView.cpp b/CesiumGltf/src/MetadataFeatureTableView.cpp deleted file mode 100644 index 5c403e8c0..000000000 --- a/CesiumGltf/src/MetadataFeatureTableView.cpp +++ /dev/null @@ -1,386 +0,0 @@ -#include "CesiumGltf/MetadataFeatureTableView.h" - -namespace CesiumGltf { -template -static MetadataPropertyViewStatus checkOffsetBuffer( - const gsl::span& offsetBuffer, - size_t valueBufferSize, - size_t instanceCount, - bool checkBitSize) noexcept { - if (offsetBuffer.size() % sizeof(T) != 0) { - return MetadataPropertyViewStatus:: - InvalidBufferViewSizeNotDivisibleByTypeSize; - } - - const size_t size = offsetBuffer.size() / sizeof(T); - if (size != instanceCount + 1) { - return MetadataPropertyViewStatus::InvalidBufferViewSizeNotFitInstanceCount; - } - - const gsl::span offsetValues( - reinterpret_cast(offsetBuffer.data()), - size); - - for (size_t i = 1; i < offsetValues.size(); ++i) { - if (offsetValues[i] < offsetValues[i - 1]) { - return MetadataPropertyViewStatus::InvalidOffsetValuesNotSortedAscending; - } - } - - if (!checkBitSize) { - if (offsetValues.back() <= valueBufferSize) { - return MetadataPropertyViewStatus::Valid; - } else { - return MetadataPropertyViewStatus:: - InvalidOffsetValuePointsToOutOfBoundBuffer; - } - } - - if (offsetValues.back() / 8 <= valueBufferSize) { - return MetadataPropertyViewStatus::Valid; - } else { - return MetadataPropertyViewStatus:: - InvalidOffsetValuePointsToOutOfBoundBuffer; - } -} - -template -static MetadataPropertyViewStatus checkStringArrayOffsetBuffer( - const gsl::span& arrayOffsetBuffer, - const gsl::span& stringOffsetBuffer, - size_t valueBufferSize, - size_t instanceCount) noexcept { - const auto status = checkOffsetBuffer( - arrayOffsetBuffer, - stringOffsetBuffer.size(), - instanceCount, - false); - if (status != MetadataPropertyViewStatus::Valid) { - return status; - } - - const T* pValue = reinterpret_cast(arrayOffsetBuffer.data()); - return checkOffsetBuffer( - stringOffsetBuffer, - valueBufferSize, - pValue[instanceCount] / sizeof(T), - false); -} - -MetadataFeatureTableView::MetadataFeatureTableView( - const Model* pModel, - const FeatureTable* pFeatureTable) - : _pModel{pModel}, _pFeatureTable{pFeatureTable}, _pClass{nullptr} { - assert(pModel != nullptr && "model must not be nullptr"); - assert(pFeatureTable != nullptr && "featureTable must not be nullptr"); - - const ExtensionModelExtFeatureMetadata* pMetadata = - pModel->getExtension(); - assert( - pMetadata != nullptr && - "Model must contain ExtensionModelExtFeatureMetadata to use " - "FeatureTableView"); - - const std::optional& schema = pMetadata->schema; - assert( - schema != std::nullopt && "ExtensionModelExtFeatureMetadata must contain " - "Schema to use FeatureTableView"); - - auto classIter = - schema->classes.find(_pFeatureTable->classProperty.value_or("")); - if (classIter != schema->classes.end()) { - _pClass = &classIter->second; - } -} - -const ClassProperty* MetadataFeatureTableView::getClassProperty( - const std::string& propertyName) const { - if (_pClass == nullptr) { - return nullptr; - } - - auto propertyIter = _pClass->properties.find(propertyName); - if (propertyIter == _pClass->properties.end()) { - return nullptr; - } - - return &propertyIter->second; -} - -MetadataPropertyViewStatus MetadataFeatureTableView::getBufferSafe( - int32_t bufferViewIdx, - gsl::span& buffer) const noexcept { - buffer = {}; - - const BufferView* pBufferView = - _pModel->getSafe(&_pModel->bufferViews, bufferViewIdx); - if (!pBufferView) { - return MetadataPropertyViewStatus::InvalidValueBufferViewIndex; - } - - const Buffer* pBuffer = - _pModel->getSafe(&_pModel->buffers, pBufferView->buffer); - if (!pBuffer) { - return MetadataPropertyViewStatus::InvalidValueBufferIndex; - } - - // This is technically required for the EXT_feature_metadata spec, but not - // necessarily required for EXT_mesh_features. Due to the discrepancy between - // the two specs, a lot of EXT_feature_metadata glTFs fail to be 8-byte - // aligned. To be forgiving and more compatible, we do not enforce this. - /* - if (pBufferView->byteOffset % 8 != 0) { - return MetadataPropertyViewStatus::InvalidBufferViewNotAligned8Bytes; - } - */ - - if (pBufferView->byteOffset + pBufferView->byteLength > - static_cast(pBuffer->cesium.data.size())) { - return MetadataPropertyViewStatus::InvalidBufferViewOutOfBound; - } - - buffer = gsl::span( - pBuffer->cesium.data.data() + pBufferView->byteOffset, - static_cast(pBufferView->byteLength)); - return MetadataPropertyViewStatus::Valid; -} - -MetadataPropertyViewStatus MetadataFeatureTableView::getOffsetBufferSafe( - int32_t bufferViewIdx, - PropertyType offsetType, - size_t valueBufferSize, - size_t instanceCount, - bool checkBitsSize, - gsl::span& offsetBuffer) const noexcept { - auto status = getBufferSafe(bufferViewIdx, offsetBuffer); - if (status != MetadataPropertyViewStatus::Valid) { - return status; - } - - switch (offsetType) { - case PropertyType::Uint8: - status = checkOffsetBuffer( - offsetBuffer, - valueBufferSize, - instanceCount, - checkBitsSize); - break; - case PropertyType::Uint16: - status = checkOffsetBuffer( - offsetBuffer, - valueBufferSize, - instanceCount, - checkBitsSize); - break; - case PropertyType::Uint32: - status = checkOffsetBuffer( - offsetBuffer, - valueBufferSize, - instanceCount, - checkBitsSize); - break; - case PropertyType::Uint64: - status = checkOffsetBuffer( - offsetBuffer, - valueBufferSize, - instanceCount, - checkBitsSize); - break; - default: - status = MetadataPropertyViewStatus::InvalidOffsetType; - break; - } - - return status; -} - -MetadataPropertyView -MetadataFeatureTableView::getStringPropertyValues( - const ClassProperty& classProperty, - const FeatureTableProperty& featureTableProperty) const { - if (classProperty.type != ClassProperty::Type::STRING) { - return createInvalidPropertyView( - MetadataPropertyViewStatus::InvalidTypeMismatch); - } - - gsl::span valueBuffer; - auto status = getBufferSafe(featureTableProperty.bufferView, valueBuffer); - if (status != MetadataPropertyViewStatus::Valid) { - return createInvalidPropertyView(status); - } - - const PropertyType offsetType = - convertOffsetStringToPropertyType(featureTableProperty.offsetType); - if (offsetType == PropertyType::None) { - return createInvalidPropertyView( - MetadataPropertyViewStatus::InvalidOffsetType); - } - - gsl::span offsetBuffer; - status = getOffsetBufferSafe( - featureTableProperty.stringOffsetBufferView, - offsetType, - valueBuffer.size(), - static_cast(_pFeatureTable->count), - false, - offsetBuffer); - if (status != MetadataPropertyViewStatus::Valid) { - return createInvalidPropertyView(status); - } - - return MetadataPropertyView( - MetadataPropertyViewStatus::Valid, - valueBuffer, - gsl::span(), - offsetBuffer, - offsetType, - 0, - _pFeatureTable->count, - classProperty.normalized); -} - -MetadataPropertyView> -MetadataFeatureTableView::getStringArrayPropertyValues( - const ClassProperty& classProperty, - const FeatureTableProperty& featureTableProperty) const { - if (classProperty.type != ClassProperty::Type::ARRAY) { - return createInvalidPropertyView>( - MetadataPropertyViewStatus::InvalidTypeMismatch); - } - - if (classProperty.componentType != ClassProperty::ComponentType::STRING) { - return createInvalidPropertyView>( - MetadataPropertyViewStatus::InvalidTypeMismatch); - } - - // get value buffer - gsl::span valueBuffer; - auto status = getBufferSafe(featureTableProperty.bufferView, valueBuffer); - if (status != MetadataPropertyViewStatus::Valid) { - return createInvalidPropertyView>( - status); - } - - // check fixed or dynamic array - const int64_t componentCount = classProperty.componentCount.value_or(0); - if (componentCount > 0 && featureTableProperty.arrayOffsetBufferView >= 0) { - return createInvalidPropertyView>( - MetadataPropertyViewStatus:: - InvalidArrayComponentCountAndOffsetBufferCoexist); - } - - if (componentCount <= 0 && featureTableProperty.arrayOffsetBufferView < 0) { - return createInvalidPropertyView>( - MetadataPropertyViewStatus:: - InvalidArrayComponentCountOrOffsetBufferNotExist); - } - - // get offset type - const PropertyType offsetType = - convertOffsetStringToPropertyType(featureTableProperty.offsetType); - if (offsetType == PropertyType::None) { - return createInvalidPropertyView>( - MetadataPropertyViewStatus::InvalidOffsetType); - } - - // get string offset buffer - if (featureTableProperty.stringOffsetBufferView < 0) { - return createInvalidPropertyView>( - MetadataPropertyViewStatus::InvalidStringOffsetBufferViewIndex); - } - - // fixed array - if (componentCount > 0) { - gsl::span stringOffsetBuffer; - status = getOffsetBufferSafe( - featureTableProperty.stringOffsetBufferView, - offsetType, - valueBuffer.size(), - static_cast(_pFeatureTable->count * componentCount), - false, - stringOffsetBuffer); - if (status != MetadataPropertyViewStatus::Valid) { - return createInvalidPropertyView>( - status); - } - - return MetadataPropertyView>( - MetadataPropertyViewStatus::Valid, - valueBuffer, - gsl::span(), - stringOffsetBuffer, - offsetType, - componentCount, - _pFeatureTable->count, - classProperty.normalized); - } - - // dynamic array - gsl::span stringOffsetBuffer; - status = getBufferSafe( - featureTableProperty.stringOffsetBufferView, - stringOffsetBuffer); - if (status != MetadataPropertyViewStatus::Valid) { - return createInvalidPropertyView>( - status); - } - - gsl::span arrayOffsetBuffer; - status = getBufferSafe( - featureTableProperty.arrayOffsetBufferView, - arrayOffsetBuffer); - if (status != MetadataPropertyViewStatus::Valid) { - return createInvalidPropertyView>( - status); - } - - switch (offsetType) { - case PropertyType::Uint8: - status = checkStringArrayOffsetBuffer( - arrayOffsetBuffer, - stringOffsetBuffer, - valueBuffer.size(), - static_cast(_pFeatureTable->count)); - break; - case PropertyType::Uint16: - status = checkStringArrayOffsetBuffer( - arrayOffsetBuffer, - stringOffsetBuffer, - valueBuffer.size(), - static_cast(_pFeatureTable->count)); - break; - case PropertyType::Uint32: - status = checkStringArrayOffsetBuffer( - arrayOffsetBuffer, - stringOffsetBuffer, - valueBuffer.size(), - static_cast(_pFeatureTable->count)); - break; - case PropertyType::Uint64: - status = checkStringArrayOffsetBuffer( - arrayOffsetBuffer, - stringOffsetBuffer, - valueBuffer.size(), - static_cast(_pFeatureTable->count)); - break; - default: - status = MetadataPropertyViewStatus::InvalidOffsetType; - break; - } - - if (status != MetadataPropertyViewStatus::Valid) { - return createInvalidPropertyView>( - status); - } - - return MetadataPropertyView>( - MetadataPropertyViewStatus::Valid, - valueBuffer, - arrayOffsetBuffer, - stringOffsetBuffer, - offsetType, - 0, - _pFeatureTable->count, - classProperty.normalized); -} -} // namespace CesiumGltf diff --git a/CesiumGltf/src/StructuralMetadataPropertyTableView.cpp b/CesiumGltf/src/PropertyTableView.cpp similarity index 93% rename from CesiumGltf/src/StructuralMetadataPropertyTableView.cpp rename to CesiumGltf/src/PropertyTableView.cpp index b6e58fa87..0e06b7d0f 100644 --- a/CesiumGltf/src/StructuralMetadataPropertyTableView.cpp +++ b/CesiumGltf/src/PropertyTableView.cpp @@ -1,8 +1,6 @@ -#include "CesiumGltf/StructuralMetadataPropertyTableView.h" +#include "CesiumGltf/PropertyTableView.h" namespace CesiumGltf { -namespace StructuralMetadata { - template static PropertyTablePropertyViewStatus checkOffsetsBuffer( const gsl::span& offsetBuffer, @@ -333,38 +331,38 @@ PropertyTableView::getStringPropertyValues( classProperty.normalized); } -PropertyTablePropertyView> +PropertyTablePropertyView> PropertyTableView::getStringArrayPropertyValues( const ExtensionExtStructuralMetadataClassProperty& classProperty, const ExtensionExtStructuralMetadataPropertyTableProperty& propertyTableProperty) const { if (!classProperty.array) { - return createInvalidPropertyView>( + return createInvalidPropertyView>( PropertyTablePropertyViewStatus::ErrorArrayTypeMismatch); } if (classProperty.type != ExtensionExtStructuralMetadataClassProperty::Type::STRING) { - return createInvalidPropertyView>( + return createInvalidPropertyView>( PropertyTablePropertyViewStatus::ErrorTypeMismatch); } gsl::span values; auto status = getBufferSafe(propertyTableProperty.values, values); if (status != PropertyTablePropertyViewStatus::Valid) { - return createInvalidPropertyView>( + return createInvalidPropertyView>( status); } // Check if array is fixed or variable length const int64_t fixedLengthArrayCount = classProperty.count.value_or(0); if (fixedLengthArrayCount > 0 && propertyTableProperty.arrayOffsets >= 0) { - return createInvalidPropertyView>( + return createInvalidPropertyView>( PropertyTablePropertyViewStatus::ErrorArrayCountAndOffsetBufferCoexist); } if (fixedLengthArrayCount <= 0 && propertyTableProperty.arrayOffsets < 0) { - return createInvalidPropertyView>( + return createInvalidPropertyView>( PropertyTablePropertyViewStatus:: ErrorArrayCountAndOffsetBufferDontExist); } @@ -374,12 +372,12 @@ PropertyTableView::getStringArrayPropertyValues( convertStringOffsetTypeStringToPropertyComponentType( propertyTableProperty.stringOffsetType); if (stringOffsetType == PropertyComponentType::None) { - return createInvalidPropertyView>( + return createInvalidPropertyView>( PropertyTablePropertyViewStatus::ErrorInvalidStringOffsetType); } if (propertyTableProperty.stringOffsets < 0) { - return createInvalidPropertyView>( + return createInvalidPropertyView>( PropertyTablePropertyViewStatus::ErrorInvalidStringOffsetBufferView); } @@ -393,11 +391,11 @@ PropertyTableView::getStringArrayPropertyValues( static_cast(_pPropertyTable->count * fixedLengthArrayCount), stringOffsets); if (status != PropertyTablePropertyViewStatus::Valid) { - return createInvalidPropertyView>( + return createInvalidPropertyView>( status); } - return PropertyTablePropertyView>( + return PropertyTablePropertyView>( PropertyTablePropertyViewStatus::Valid, values, gsl::span(), @@ -414,12 +412,12 @@ PropertyTableView::getStringArrayPropertyValues( convertArrayOffsetTypeStringToPropertyComponentType( propertyTableProperty.arrayOffsetType); if (arrayOffsetType == PropertyComponentType::None) { - return createInvalidPropertyView>( + return createInvalidPropertyView>( PropertyTablePropertyViewStatus::ErrorInvalidArrayOffsetType); } if (propertyTableProperty.arrayOffsets < 0) { - return createInvalidPropertyView>( + return createInvalidPropertyView>( PropertyTablePropertyViewStatus::ErrorInvalidArrayOffsetBufferView); } @@ -427,14 +425,14 @@ PropertyTableView::getStringArrayPropertyValues( gsl::span stringOffsets; status = getBufferSafe(propertyTableProperty.stringOffsets, stringOffsets); if (status != PropertyTablePropertyViewStatus::Valid) { - return createInvalidPropertyView>( + return createInvalidPropertyView>( status); } gsl::span arrayOffsets; status = getBufferSafe(propertyTableProperty.arrayOffsets, arrayOffsets); if (status != PropertyTablePropertyViewStatus::Valid) { - return createInvalidPropertyView>( + return createInvalidPropertyView>( status); } @@ -477,11 +475,11 @@ PropertyTableView::getStringArrayPropertyValues( } if (status != PropertyTablePropertyViewStatus::Valid) { - return createInvalidPropertyView>( + return createInvalidPropertyView>( status); } - return PropertyTablePropertyView>( + return PropertyTablePropertyView>( PropertyTablePropertyViewStatus::Valid, values, arrayOffsets, @@ -492,6 +490,4 @@ PropertyTableView::getStringArrayPropertyValues( _pPropertyTable->count, classProperty.normalized); } - -} // namespace StructuralMetadata } // namespace CesiumGltf diff --git a/CesiumGltf/src/StructuralMetadataPropertyTexturePropertyView.cpp b/CesiumGltf/src/PropertyTexturePropertyView.cpp similarity index 96% rename from CesiumGltf/src/StructuralMetadataPropertyTexturePropertyView.cpp rename to CesiumGltf/src/PropertyTexturePropertyView.cpp index 409c29166..d854468d2 100644 --- a/CesiumGltf/src/StructuralMetadataPropertyTexturePropertyView.cpp +++ b/CesiumGltf/src/PropertyTexturePropertyView.cpp @@ -1,8 +1,7 @@ -#include "CesiumGltf/StructuralMetadataPropertyTexturePropertyView.h" +#include "CesiumGltf/PropertyTexturePropertyView.h" namespace CesiumGltf { -namespace StructuralMetadata { PropertyTexturePropertyView::PropertyTexturePropertyView() noexcept : _status(PropertyTexturePropertyViewStatus::ErrorUninitialized), _pClassProperty(nullptr), @@ -103,5 +102,4 @@ PropertyTexturePropertyView::PropertyTexturePropertyView( this->_status = PropertyTexturePropertyViewStatus::Valid; } -} // namespace StructuralMetadata } // namespace CesiumGltf diff --git a/CesiumGltf/src/StructuralMetadataPropertyTextureView.cpp b/CesiumGltf/src/PropertyTextureView.cpp similarity index 94% rename from CesiumGltf/src/StructuralMetadataPropertyTextureView.cpp rename to CesiumGltf/src/PropertyTextureView.cpp index 7ebcdab2a..7f917c8a9 100644 --- a/CesiumGltf/src/StructuralMetadataPropertyTextureView.cpp +++ b/CesiumGltf/src/PropertyTextureView.cpp @@ -1,7 +1,6 @@ -#include "CesiumGltf/StructuralMetadataPropertyTextureView.h" +#include "CesiumGltf/PropertyTextureView.h" namespace CesiumGltf { -namespace StructuralMetadata { PropertyTextureView::PropertyTextureView() noexcept : _pModel(nullptr), _pPropertyTexture(nullptr), @@ -80,6 +79,4 @@ PropertyTextureView::getClassProperty(const std::string& propertyName) const { return &propertyIter->second; } - -} // namespace StructuralMetadata } // namespace CesiumGltf diff --git a/CesiumGltf/src/PropertyType.cpp b/CesiumGltf/src/PropertyType.cpp index 91c0e9787..826997cf8 100644 --- a/CesiumGltf/src/PropertyType.cpp +++ b/CesiumGltf/src/PropertyType.cpp @@ -1,123 +1,220 @@ #include "CesiumGltf/PropertyType.h" -#include "CesiumGltf/ClassProperty.h" -#include "CesiumGltf/FeatureTable.h" +#include "CesiumGltf/ExtensionExtStructuralMetadataClassProperty.h" +#include "CesiumGltf/ExtensionExtStructuralMetadataPropertyTable.h" namespace CesiumGltf { -std::string convertPropertyTypeToString(CesiumGltf::PropertyType type) { +std::string convertPropertyTypeToString(PropertyType type) { switch (type) { - case PropertyType::None: - return "NONE"; - case PropertyType::Uint8: - return ClassProperty::Type::UINT8; - case PropertyType::Int8: - return ClassProperty::Type::INT8; - case PropertyType::Uint16: - return ClassProperty::Type::UINT16; - case PropertyType::Int16: - return ClassProperty::Type::INT16; - case PropertyType::Uint32: - return ClassProperty::Type::UINT32; - case PropertyType::Int32: - return ClassProperty::Type::INT32; - case PropertyType::Uint64: - return ClassProperty::Type::UINT64; - case PropertyType::Int64: - return ClassProperty::Type::INT64; - case PropertyType::Float32: - return ClassProperty::Type::FLOAT32; - case PropertyType::Float64: - return ClassProperty::Type::FLOAT64; + case PropertyType::Scalar: + return ExtensionExtStructuralMetadataClassProperty::Type::SCALAR; + case PropertyType::Vec2: + return ExtensionExtStructuralMetadataClassProperty::Type::VEC2; + case PropertyType::Vec3: + return ExtensionExtStructuralMetadataClassProperty::Type::VEC3; + case PropertyType::Vec4: + return ExtensionExtStructuralMetadataClassProperty::Type::VEC4; + case PropertyType::Mat2: + return ExtensionExtStructuralMetadataClassProperty::Type::MAT2; + case PropertyType::Mat3: + return ExtensionExtStructuralMetadataClassProperty::Type::MAT3; + case PropertyType::Mat4: + return ExtensionExtStructuralMetadataClassProperty::Type::MAT4; case PropertyType::Boolean: - return ClassProperty::Type::BOOLEAN; + return ExtensionExtStructuralMetadataClassProperty::Type::BOOLEAN; case PropertyType::Enum: - return ClassProperty::Type::ENUM; + return ExtensionExtStructuralMetadataClassProperty::Type::ENUM; case PropertyType::String: - return ClassProperty::Type::STRING; - case PropertyType::Array: - return ClassProperty::Type::ARRAY; + return ExtensionExtStructuralMetadataClassProperty::Type::STRING; default: - return "NONE"; + return "INVALID"; } } PropertyType convertStringToPropertyType(const std::string& str) { - if (str == ClassProperty::Type::UINT8) { - return PropertyType::Uint8; + if (str == ExtensionExtStructuralMetadataClassProperty::Type::SCALAR) { + return PropertyType::Scalar; } - if (str == ClassProperty::Type::INT8) { - return PropertyType::Int8; + if (str == ExtensionExtStructuralMetadataClassProperty::Type::VEC2) { + return PropertyType::Vec2; } - if (str == ClassProperty::Type::UINT16) { - return PropertyType::Uint16; + if (str == ExtensionExtStructuralMetadataClassProperty::Type::VEC3) { + return PropertyType::Vec3; } - if (str == ClassProperty::Type::INT16) { - return PropertyType::Int16; + if (str == ExtensionExtStructuralMetadataClassProperty::Type::VEC4) { + return PropertyType::Vec4; } - if (str == ClassProperty::Type::UINT32) { - return PropertyType::Uint32; + if (str == ExtensionExtStructuralMetadataClassProperty::Type::MAT2) { + return PropertyType::Mat2; } - if (str == ClassProperty::Type::INT32) { - return PropertyType::Int32; + if (str == ExtensionExtStructuralMetadataClassProperty::Type::MAT3) { + return PropertyType::Mat3; } - if (str == ClassProperty::Type::UINT64) { - return PropertyType::Uint64; + if (str == ExtensionExtStructuralMetadataClassProperty::Type::MAT4) { + return PropertyType::Mat4; } - if (str == ClassProperty::Type::INT64) { - return PropertyType::Int64; + if (str == ExtensionExtStructuralMetadataClassProperty::Type::BOOLEAN) { + return PropertyType::Boolean; } - if (str == ClassProperty::Type::FLOAT32) { - return PropertyType::Float32; + if (str == ExtensionExtStructuralMetadataClassProperty::Type::STRING) { + return PropertyType::String; } - if (str == ClassProperty::Type::FLOAT64) { - return PropertyType::Float64; + if (str == ExtensionExtStructuralMetadataClassProperty::Type::ENUM) { + return PropertyType::Enum; } - if (str == ClassProperty::Type::BOOLEAN) { - return PropertyType::Boolean; + return PropertyType::Invalid; +} + +std::string convertPropertyComponentTypeToString(PropertyComponentType type) { + switch (type) { + case PropertyComponentType::None: + return "NONE"; + case PropertyComponentType::Uint8: + return ExtensionExtStructuralMetadataClassProperty::ComponentType::UINT8; + case PropertyComponentType::Int8: + return ExtensionExtStructuralMetadataClassProperty::ComponentType::INT8; + case PropertyComponentType::Uint16: + return ExtensionExtStructuralMetadataClassProperty::ComponentType::UINT16; + case PropertyComponentType::Int16: + return ExtensionExtStructuralMetadataClassProperty::ComponentType::INT16; + case PropertyComponentType::Uint32: + return ExtensionExtStructuralMetadataClassProperty::ComponentType::UINT32; + case PropertyComponentType::Int32: + return ExtensionExtStructuralMetadataClassProperty::ComponentType::INT32; + case PropertyComponentType::Uint64: + return ExtensionExtStructuralMetadataClassProperty::ComponentType::UINT64; + case PropertyComponentType::Int64: + return ExtensionExtStructuralMetadataClassProperty::ComponentType::INT64; + case PropertyComponentType::Float32: + return ExtensionExtStructuralMetadataClassProperty::ComponentType::FLOAT32; + case PropertyComponentType::Float64: + return ExtensionExtStructuralMetadataClassProperty::ComponentType::FLOAT64; + default: + return "NONE"; } +} - if (str == ClassProperty::Type::STRING) { - return PropertyType::String; +PropertyComponentType +convertStringToPropertyComponentType(const std::string& str) { + if (str == + ExtensionExtStructuralMetadataClassProperty::ComponentType::UINT8) { + return PropertyComponentType::Uint8; } - if (str == ClassProperty::Type::ENUM) { - return PropertyType::Enum; + if (str == ExtensionExtStructuralMetadataClassProperty::ComponentType::INT8) { + return PropertyComponentType::Int8; + } + + if (str == + ExtensionExtStructuralMetadataClassProperty::ComponentType::UINT16) { + return PropertyComponentType::Uint16; } - if (str == ClassProperty::Type::ARRAY) { - return PropertyType::Array; + if (str == + ExtensionExtStructuralMetadataClassProperty::ComponentType::INT16) { + return PropertyComponentType::Int16; } - return PropertyType::None; + if (str == + ExtensionExtStructuralMetadataClassProperty::ComponentType::UINT32) { + return PropertyComponentType::Uint32; + } + + if (str == + ExtensionExtStructuralMetadataClassProperty::ComponentType::INT32) { + return PropertyComponentType::Int32; + } + + if (str == + ExtensionExtStructuralMetadataClassProperty::ComponentType::UINT64) { + return PropertyComponentType::Uint64; + } + + if (str == + ExtensionExtStructuralMetadataClassProperty::ComponentType::INT64) { + return PropertyComponentType::Int64; + } + + if (str == + ExtensionExtStructuralMetadataClassProperty::ComponentType::FLOAT32) { + return PropertyComponentType::Float32; + } + + if (str == + ExtensionExtStructuralMetadataClassProperty::ComponentType::FLOAT64) { + return PropertyComponentType::Float64; + } + + return PropertyComponentType::None; } -PropertyType convertOffsetStringToPropertyType(const std::string& str) { - if (str == FeatureTableProperty::OffsetType::UINT8) { - return PropertyType::Uint8; +PropertyComponentType +convertArrayOffsetTypeStringToPropertyComponentType(const std::string& str) { + if (str == ExtensionExtStructuralMetadataPropertyTableProperty:: + ArrayOffsetType::UINT8) { + return PropertyComponentType::Uint8; + } + + if (str == ExtensionExtStructuralMetadataPropertyTableProperty:: + ArrayOffsetType::UINT16) { + return PropertyComponentType::Uint16; } - if (str == FeatureTableProperty::OffsetType::UINT16) { - return PropertyType::Uint16; + if (str == ExtensionExtStructuralMetadataPropertyTableProperty:: + ArrayOffsetType::UINT32) { + return PropertyComponentType::Uint32; } - if (str == FeatureTableProperty::OffsetType::UINT32) { - return PropertyType::Uint32; + if (str == ExtensionExtStructuralMetadataPropertyTableProperty:: + ArrayOffsetType::UINT64) { + return PropertyComponentType::Uint64; } - if (str == FeatureTableProperty::OffsetType::UINT64) { - return PropertyType::Uint64; + return PropertyComponentType::None; +} + +PropertyComponentType +convertStringOffsetTypeStringToPropertyComponentType(const std::string& str) { + if (str == ExtensionExtStructuralMetadataPropertyTableProperty:: + StringOffsetType::UINT8) { + return PropertyComponentType::Uint8; } - return PropertyType::None; + if (str == ExtensionExtStructuralMetadataPropertyTableProperty:: + StringOffsetType::UINT16) { + return PropertyComponentType::Uint16; + } + + if (str == ExtensionExtStructuralMetadataPropertyTableProperty:: + StringOffsetType::UINT32) { + return PropertyComponentType::Uint32; + } + + if (str == ExtensionExtStructuralMetadataPropertyTableProperty:: + StringOffsetType::UINT64) { + return PropertyComponentType::Uint64; + } + + return PropertyComponentType::None; +} + +bool isPropertyTypeVecN(PropertyType type) { + return type == PropertyType::Vec2 || type == PropertyType::Vec3 || + type == PropertyType::Vec4; +} + +bool isPropertyTypeMatN(PropertyType type) { + return type == PropertyType::Mat2 || type == PropertyType::Mat3 || + type == PropertyType::Mat4; } } // namespace CesiumGltf diff --git a/CesiumGltf/src/StructuralMetadataPropertyType.cpp b/CesiumGltf/src/StructuralMetadataPropertyType.cpp deleted file mode 100644 index ca7613023..000000000 --- a/CesiumGltf/src/StructuralMetadataPropertyType.cpp +++ /dev/null @@ -1,224 +0,0 @@ -#include "CesiumGltf/StructuralMetadataPropertyType.h" - -#include "CesiumGltf/ExtensionExtStructuralMetadataClassProperty.h" -#include "CesiumGltf/ExtensionExtStructuralMetadataPropertyTable.h" - -namespace CesiumGltf { -namespace StructuralMetadata { - -std::string convertPropertyTypeToString(StructuralMetadata::PropertyType type) { - switch (type) { - case PropertyType::Scalar: - return ExtensionExtStructuralMetadataClassProperty::Type::SCALAR; - case PropertyType::Vec2: - return ExtensionExtStructuralMetadataClassProperty::Type::VEC2; - case PropertyType::Vec3: - return ExtensionExtStructuralMetadataClassProperty::Type::VEC3; - case PropertyType::Vec4: - return ExtensionExtStructuralMetadataClassProperty::Type::VEC4; - case PropertyType::Mat2: - return ExtensionExtStructuralMetadataClassProperty::Type::MAT2; - case PropertyType::Mat3: - return ExtensionExtStructuralMetadataClassProperty::Type::MAT3; - case PropertyType::Mat4: - return ExtensionExtStructuralMetadataClassProperty::Type::MAT4; - case PropertyType::Boolean: - return ExtensionExtStructuralMetadataClassProperty::Type::BOOLEAN; - case PropertyType::Enum: - return ExtensionExtStructuralMetadataClassProperty::Type::ENUM; - case PropertyType::String: - return ExtensionExtStructuralMetadataClassProperty::Type::STRING; - default: - return "INVALID"; - } -} - -PropertyType convertStringToPropertyType(const std::string& str) { - if (str == ExtensionExtStructuralMetadataClassProperty::Type::SCALAR) { - return PropertyType::Scalar; - } - - if (str == ExtensionExtStructuralMetadataClassProperty::Type::VEC2) { - return PropertyType::Vec2; - } - - if (str == ExtensionExtStructuralMetadataClassProperty::Type::VEC3) { - return PropertyType::Vec3; - } - - if (str == ExtensionExtStructuralMetadataClassProperty::Type::VEC4) { - return PropertyType::Vec4; - } - - if (str == ExtensionExtStructuralMetadataClassProperty::Type::MAT2) { - return PropertyType::Mat2; - } - - if (str == ExtensionExtStructuralMetadataClassProperty::Type::MAT3) { - return PropertyType::Mat3; - } - - if (str == ExtensionExtStructuralMetadataClassProperty::Type::MAT4) { - return PropertyType::Mat4; - } - - if (str == ExtensionExtStructuralMetadataClassProperty::Type::BOOLEAN) { - return PropertyType::Boolean; - } - - if (str == ExtensionExtStructuralMetadataClassProperty::Type::STRING) { - return PropertyType::String; - } - - if (str == ExtensionExtStructuralMetadataClassProperty::Type::ENUM) { - return PropertyType::Enum; - } - - return PropertyType::Invalid; -} - -std::string convertPropertyComponentTypeToString(PropertyComponentType type) { - switch (type) { - case PropertyComponentType::None: - return "NONE"; - case PropertyComponentType::Uint8: - return ExtensionExtStructuralMetadataClassProperty::ComponentType::UINT8; - case PropertyComponentType::Int8: - return ExtensionExtStructuralMetadataClassProperty::ComponentType::INT8; - case PropertyComponentType::Uint16: - return ExtensionExtStructuralMetadataClassProperty::ComponentType::UINT16; - case PropertyComponentType::Int16: - return ExtensionExtStructuralMetadataClassProperty::ComponentType::INT16; - case PropertyComponentType::Uint32: - return ExtensionExtStructuralMetadataClassProperty::ComponentType::UINT32; - case PropertyComponentType::Int32: - return ExtensionExtStructuralMetadataClassProperty::ComponentType::INT32; - case PropertyComponentType::Uint64: - return ExtensionExtStructuralMetadataClassProperty::ComponentType::UINT64; - case PropertyComponentType::Int64: - return ExtensionExtStructuralMetadataClassProperty::ComponentType::INT64; - case PropertyComponentType::Float32: - return ExtensionExtStructuralMetadataClassProperty::ComponentType::FLOAT32; - case PropertyComponentType::Float64: - return ExtensionExtStructuralMetadataClassProperty::ComponentType::FLOAT64; - default: - return "NONE"; - } -} - -PropertyComponentType -convertStringToPropertyComponentType(const std::string& str) { - if (str == - ExtensionExtStructuralMetadataClassProperty::ComponentType::UINT8) { - return PropertyComponentType::Uint8; - } - - if (str == ExtensionExtStructuralMetadataClassProperty::ComponentType::INT8) { - return PropertyComponentType::Int8; - } - - if (str == - ExtensionExtStructuralMetadataClassProperty::ComponentType::UINT16) { - return PropertyComponentType::Uint16; - } - - if (str == - ExtensionExtStructuralMetadataClassProperty::ComponentType::INT16) { - return PropertyComponentType::Int16; - } - - if (str == - ExtensionExtStructuralMetadataClassProperty::ComponentType::UINT32) { - return PropertyComponentType::Uint32; - } - - if (str == - ExtensionExtStructuralMetadataClassProperty::ComponentType::INT32) { - return PropertyComponentType::Int32; - } - - if (str == - ExtensionExtStructuralMetadataClassProperty::ComponentType::UINT64) { - return PropertyComponentType::Uint64; - } - - if (str == - ExtensionExtStructuralMetadataClassProperty::ComponentType::INT64) { - return PropertyComponentType::Int64; - } - - if (str == - ExtensionExtStructuralMetadataClassProperty::ComponentType::FLOAT32) { - return PropertyComponentType::Float32; - } - - if (str == - ExtensionExtStructuralMetadataClassProperty::ComponentType::FLOAT64) { - return PropertyComponentType::Float64; - } - - return PropertyComponentType::None; -} - -PropertyComponentType -convertArrayOffsetTypeStringToPropertyComponentType(const std::string& str) { - if (str == ExtensionExtStructuralMetadataPropertyTableProperty:: - ArrayOffsetType::UINT8) { - return PropertyComponentType::Uint8; - } - - if (str == ExtensionExtStructuralMetadataPropertyTableProperty:: - ArrayOffsetType::UINT16) { - return PropertyComponentType::Uint16; - } - - if (str == ExtensionExtStructuralMetadataPropertyTableProperty:: - ArrayOffsetType::UINT32) { - return PropertyComponentType::Uint32; - } - - if (str == ExtensionExtStructuralMetadataPropertyTableProperty:: - ArrayOffsetType::UINT64) { - return PropertyComponentType::Uint64; - } - - return PropertyComponentType::None; -} - -PropertyComponentType -convertStringOffsetTypeStringToPropertyComponentType(const std::string& str) { - if (str == ExtensionExtStructuralMetadataPropertyTableProperty:: - StringOffsetType::UINT8) { - return PropertyComponentType::Uint8; - } - - if (str == ExtensionExtStructuralMetadataPropertyTableProperty:: - StringOffsetType::UINT16) { - return PropertyComponentType::Uint16; - } - - if (str == ExtensionExtStructuralMetadataPropertyTableProperty:: - StringOffsetType::UINT32) { - return PropertyComponentType::Uint32; - } - - if (str == ExtensionExtStructuralMetadataPropertyTableProperty:: - StringOffsetType::UINT64) { - return PropertyComponentType::Uint64; - } - - return PropertyComponentType::None; -} - -bool isPropertyTypeVecN(PropertyType type) { - return type == PropertyType::Vec2 || type == PropertyType::Vec3 || - type == PropertyType::Vec4; -} - -bool isPropertyTypeMatN(PropertyType type) { - return type == PropertyType::Mat2 || type == PropertyType::Mat3 || - type == PropertyType::Mat4; -} - -} // namespace StructuralMetadata -} // namespace CesiumGltf diff --git a/CesiumGltf/test/TestMeshFeaturesFeatureIdTextureView.cpp b/CesiumGltf/test/TestFeatureIdTextureView.cpp similarity index 98% rename from CesiumGltf/test/TestMeshFeaturesFeatureIdTextureView.cpp rename to CesiumGltf/test/TestFeatureIdTextureView.cpp index cde38cd03..a6755667f 100644 --- a/CesiumGltf/test/TestMeshFeaturesFeatureIdTextureView.cpp +++ b/CesiumGltf/test/TestFeatureIdTextureView.cpp @@ -1,5 +1,5 @@ #include "CesiumGltf/ExtensionExtMeshFeatures.h" -#include "CesiumGltf/MeshFeaturesFeatureIdTextureView.h" +#include "CesiumGltf/FeatureIdTextureView.h" #include #include @@ -11,7 +11,6 @@ #include using namespace CesiumGltf; -using namespace CesiumGltf::MeshFeatures; TEST_CASE("Test FeatureIdTextureView on feature ID texture with invalid " "texture index") { diff --git a/CesiumGltf/test/TestMetadataFeatureTableView.cpp b/CesiumGltf/test/TestMetadataFeatureTableView.cpp deleted file mode 100644 index 9aabf9e6e..000000000 --- a/CesiumGltf/test/TestMetadataFeatureTableView.cpp +++ /dev/null @@ -1,1164 +0,0 @@ -#include "CesiumGltf/MetadataFeatureTableView.h" - -#include - -#include - -using namespace CesiumGltf; - -TEST_CASE("Test numeric properties") { - Model model; - - // store property value - std::vector values = {12, 34, 30, 11, 34, 34, 11, 33, 122, 33}; - - // Construct buffers in the scope to make sure that tests below doesn't use - // the temp variables. Use index to access the buffer and buffer view instead - size_t valueBufferIndex = 0; - size_t valueBufferViewIndex = 0; - { - Buffer& valueBuffer = model.buffers.emplace_back(); - valueBuffer.cesium.data.resize(values.size() * sizeof(uint32_t)); - valueBuffer.byteLength = - static_cast(valueBuffer.cesium.data.size()); - std::memcpy( - valueBuffer.cesium.data.data(), - values.data(), - valueBuffer.cesium.data.size()); - valueBufferIndex = model.buffers.size() - 1; - - BufferView& valueBufferView = model.bufferViews.emplace_back(); - valueBufferView.buffer = static_cast(model.buffers.size() - 1); - valueBufferView.byteOffset = 0; - valueBufferView.byteLength = valueBuffer.byteLength; - valueBufferViewIndex = model.bufferViews.size() - 1; - } - - // setup metadata - ExtensionModelExtFeatureMetadata& metadata = - model.addExtension(); - - // setup schema - Schema& schema = metadata.schema.emplace(); - Class& testClass = schema.classes["TestClass"]; - ClassProperty& testClassProperty = testClass.properties["TestClassProperty"]; - testClassProperty.type = ClassProperty::Type::UINT32; - - // setup feature table - FeatureTable& featureTable = metadata.featureTables["TestFeatureTable"]; - featureTable.classProperty = "TestClass"; - featureTable.count = static_cast(values.size()); - - // setup feature table property - FeatureTableProperty& featureTableProperty = - featureTable.properties["TestClassProperty"]; - featureTableProperty.bufferView = static_cast(valueBufferViewIndex); - - // test feature table view - MetadataFeatureTableView view(&model, &featureTable); - const ClassProperty* classProperty = - view.getClassProperty("TestClassProperty"); - REQUIRE(classProperty->type == ClassProperty::Type::UINT32); - REQUIRE(classProperty->componentCount == std::nullopt); - REQUIRE(classProperty->componentType == std::nullopt); - - SECTION("Access correct type") { - MetadataPropertyView uint32Property = - view.getPropertyView("TestClassProperty"); - REQUIRE(uint32Property.status() == MetadataPropertyViewStatus::Valid); - REQUIRE(uint32Property.size() > 0); - - for (int64_t i = 0; i < uint32Property.size(); ++i) { - REQUIRE(uint32Property.get(i) == values[static_cast(i)]); - } - } - - SECTION("Access wrong type") { - MetadataPropertyView boolInvalid = - view.getPropertyView("TestClassProperty"); - REQUIRE( - boolInvalid.status() == - MetadataPropertyViewStatus::InvalidTypeMismatch); - - MetadataPropertyView uint8Invalid = - view.getPropertyView("TestClassProperty"); - REQUIRE( - uint8Invalid.status() == - MetadataPropertyViewStatus::InvalidTypeMismatch); - - MetadataPropertyView int32Invalid = - view.getPropertyView("TestClassProperty"); - REQUIRE( - int32Invalid.status() == - MetadataPropertyViewStatus::InvalidTypeMismatch); - - MetadataPropertyView unt64Invalid = - view.getPropertyView("TestClassProperty"); - REQUIRE( - unt64Invalid.status() == - MetadataPropertyViewStatus::InvalidTypeMismatch); - - MetadataPropertyView stringInvalid = - view.getPropertyView("TestClassProperty"); - REQUIRE( - stringInvalid.status() == - MetadataPropertyViewStatus::InvalidTypeMismatch); - - MetadataPropertyView> uint32ArrayInvalid = - view.getPropertyView>("TestClassProperty"); - REQUIRE( - uint32ArrayInvalid.status() == - MetadataPropertyViewStatus::InvalidTypeMismatch); - - MetadataPropertyView> boolArrayInvalid = - view.getPropertyView>("TestClassProperty"); - REQUIRE( - boolArrayInvalid.status() == - MetadataPropertyViewStatus::InvalidTypeMismatch); - - MetadataPropertyView> - stringArrayInvalid = - view.getPropertyView>( - "TestClassProperty"); - REQUIRE( - stringArrayInvalid.status() == - MetadataPropertyViewStatus::InvalidTypeMismatch); - } - - SECTION("Wrong buffer index") { - model.bufferViews[valueBufferViewIndex].buffer = 2; - MetadataPropertyView uint32Property = - view.getPropertyView("TestClassProperty"); - REQUIRE( - uint32Property.status() == - MetadataPropertyViewStatus::InvalidValueBufferIndex); - } - - SECTION("Wrong buffer view index") { - featureTableProperty.bufferView = -1; - MetadataPropertyView uint32Property = - view.getPropertyView("TestClassProperty"); - REQUIRE( - uint32Property.status() == - MetadataPropertyViewStatus::InvalidValueBufferViewIndex); - } - - SECTION("Buffer view points outside of the real buffer length") { - model.buffers[valueBufferIndex].cesium.data.resize(12); - MetadataPropertyView uint32Property = - view.getPropertyView("TestClassProperty"); - REQUIRE( - uint32Property.status() == - MetadataPropertyViewStatus::InvalidBufferViewOutOfBound); - } - - // Even though the EXT_feature_metadata spec technically compels us to - // enforce an 8-byte alignment, we avoid doing so for compatibility with - // incorrect glTFs. - /* - SECTION("Buffer view offset is not a multiple of 8") { - model.bufferViews[valueBufferViewIndex].byteOffset = 1; - MetadataPropertyView uint32Property = - view.getPropertyView("TestClassProperty"); - REQUIRE( - uint32Property.status() == - MetadataPropertyViewStatus::InvalidBufferViewNotAligned8Bytes); - } - */ - - SECTION("Buffer view length isn't multiple of sizeof(T)") { - model.bufferViews[valueBufferViewIndex].byteLength = 13; - MetadataPropertyView uint32Property = - view.getPropertyView("TestClassProperty"); - REQUIRE( - uint32Property.status() == - MetadataPropertyViewStatus:: - InvalidBufferViewSizeNotDivisibleByTypeSize); - } - - SECTION("Buffer view length doesn't match with featureTableCount") { - model.bufferViews[valueBufferViewIndex].byteLength = 12; - MetadataPropertyView uint32Property = - view.getPropertyView("TestClassProperty"); - REQUIRE( - uint32Property.status() == - MetadataPropertyViewStatus::InvalidBufferViewSizeNotFitInstanceCount); - } -} - -TEST_CASE("Test boolean properties") { - Model model; - - // store property value - int64_t instanceCount = 21; - std::vector expected; - std::vector values; - values.resize(3); - for (int64_t i = 0; i < instanceCount; ++i) { - if (i % 2 == 0) { - expected.emplace_back(true); - } else { - expected.emplace_back(false); - } - - uint8_t expectedValue = expected.back(); - int64_t byteIndex = i / 8; - int64_t bitIndex = i % 8; - values[static_cast(byteIndex)] = static_cast( - (expectedValue << bitIndex) | values[static_cast(byteIndex)]); - } - - // Create buffers in the scope, so that tests below don't accidentally refer - // to temp variable. Use index instead if the buffer is needed - { - Buffer& valueBuffer = model.buffers.emplace_back(); - valueBuffer.cesium.data.resize(values.size()); - valueBuffer.byteLength = - static_cast(valueBuffer.cesium.data.size()); - std::memcpy( - valueBuffer.cesium.data.data(), - values.data(), - valueBuffer.cesium.data.size()); - - BufferView& valueBufferView = model.bufferViews.emplace_back(); - valueBufferView.buffer = static_cast(model.buffers.size() - 1); - valueBufferView.byteOffset = 0; - valueBufferView.byteLength = valueBuffer.byteLength; - } - - // setup metadata - ExtensionModelExtFeatureMetadata& metadata = - model.addExtension(); - - // setup schema - Schema& schema = metadata.schema.emplace(); - Class& testClass = schema.classes["TestClass"]; - ClassProperty& testClassProperty = testClass.properties["TestClassProperty"]; - testClassProperty.type = ClassProperty::Type::BOOLEAN; - - // setup feature table - FeatureTable& featureTable = metadata.featureTables["TestFeatureTable"]; - featureTable.classProperty = "TestClass"; - featureTable.count = static_cast(instanceCount); - - // setup feature table property - FeatureTableProperty& featureTableProperty = - featureTable.properties["TestClassProperty"]; - featureTableProperty.bufferView = - static_cast(model.bufferViews.size() - 1); - - // test feature table view - MetadataFeatureTableView view(&model, &featureTable); - const ClassProperty* classProperty = - view.getClassProperty("TestClassProperty"); - REQUIRE(classProperty->type == ClassProperty::Type::BOOLEAN); - REQUIRE(classProperty->componentCount == std::nullopt); - REQUIRE(classProperty->componentType == std::nullopt); - - SECTION("Access correct type") { - MetadataPropertyView boolProperty = - view.getPropertyView("TestClassProperty"); - REQUIRE(boolProperty.status() == MetadataPropertyViewStatus::Valid); - REQUIRE(boolProperty.size() == instanceCount); - for (int64_t i = 0; i < boolProperty.size(); ++i) { - bool expectedValue = expected[static_cast(i)]; - REQUIRE(boolProperty.get(i) == expectedValue); - } - } - - SECTION("Buffer size doesn't match with feature table count") { - featureTable.count = 66; - MetadataPropertyView boolProperty = - view.getPropertyView("TestClassProperty"); - REQUIRE( - boolProperty.status() == - MetadataPropertyViewStatus::InvalidBufferViewSizeNotFitInstanceCount); - } -} - -TEST_CASE("Test string property") { - Model model; - - std::vector expected{"What's up", "Test_0", "Test_1", "", ""}; - size_t totalBytes = 0; - for (const std::string& expectedValue : expected) { - totalBytes += expectedValue.size(); - } - - std::vector offsets((expected.size() + 1) * sizeof(uint32_t)); - std::vector values(totalBytes); - uint32_t* offsetValue = reinterpret_cast(offsets.data()); - for (size_t i = 0; i < expected.size(); ++i) { - const std::string& expectedValue = expected[i]; - std::memcpy( - values.data() + offsetValue[i], - expectedValue.c_str(), - expectedValue.size()); - offsetValue[i + 1] = - offsetValue[i] + static_cast(expectedValue.size()); - } - - // Create buffers in the scope, so that tests below don't accidentally refer - // to temp variable. Use index instead if the buffer is needed. - // Store property value - size_t valueBufferIndex = 0; - size_t valueBufferViewIndex = 0; - { - Buffer& valueBuffer = model.buffers.emplace_back(); - valueBuffer.byteLength = static_cast(values.size()); - valueBuffer.cesium.data = std::move(values); - valueBufferIndex = model.buffers.size() - 1; - - BufferView& valueBufferView = model.bufferViews.emplace_back(); - valueBufferView.buffer = static_cast(valueBufferIndex); - valueBufferView.byteOffset = 0; - valueBufferView.byteLength = valueBuffer.byteLength; - valueBufferViewIndex = model.bufferViews.size() - 1; - } - - // Create buffers in the scope, so that tests below don't accidentally refer - // to temp variable. Use index instead if the buffer is needed. - // Store string offset buffer - size_t offsetBufferIndex = 0; - size_t offsetBufferViewIndex = 0; - { - Buffer& offsetBuffer = model.buffers.emplace_back(); - offsetBuffer.byteLength = static_cast(offsets.size()); - offsetBuffer.cesium.data = std::move(offsets); - offsetBufferIndex = model.buffers.size() - 1; - - BufferView& offsetBufferView = model.bufferViews.emplace_back(); - offsetBufferView.buffer = static_cast(offsetBufferIndex); - offsetBufferView.byteOffset = 0; - offsetBufferView.byteLength = offsetBuffer.byteLength; - offsetBufferViewIndex = model.bufferViews.size() - 1; - } - - // setup metadata - ExtensionModelExtFeatureMetadata& metadata = - model.addExtension(); - - // setup schema - Schema& schema = metadata.schema.emplace(); - Class& testClass = schema.classes["TestClass"]; - ClassProperty& testClassProperty = testClass.properties["TestClassProperty"]; - testClassProperty.type = ClassProperty::Type::STRING; - - // setup feature table - FeatureTable& featureTable = metadata.featureTables["TestFeatureTable"]; - featureTable.classProperty = "TestClass"; - featureTable.count = static_cast(expected.size()); - - // setup feature table property - FeatureTableProperty& featureTableProperty = - featureTable.properties["TestClassProperty"]; - featureTableProperty.offsetType = FeatureTableProperty::OffsetType::UINT32; - featureTableProperty.bufferView = static_cast(valueBufferViewIndex); - featureTableProperty.stringOffsetBufferView = - static_cast(offsetBufferViewIndex); - - // test feature table view - MetadataFeatureTableView view(&model, &featureTable); - const ClassProperty* classProperty = - view.getClassProperty("TestClassProperty"); - REQUIRE(classProperty->type == ClassProperty::Type::STRING); - REQUIRE(classProperty->componentCount == std::nullopt); - REQUIRE(classProperty->componentType == std::nullopt); - - SECTION("Access correct type") { - MetadataPropertyView stringProperty = - view.getPropertyView("TestClassProperty"); - REQUIRE(stringProperty.status() == MetadataPropertyViewStatus::Valid); - for (size_t i = 0; i < expected.size(); ++i) { - REQUIRE(stringProperty.get(static_cast(i)) == expected[i]); - } - } - - SECTION("Wrong offset type") { - featureTableProperty.offsetType = FeatureTableProperty::OffsetType::UINT8; - MetadataPropertyView stringProperty = - view.getPropertyView("TestClassProperty"); - REQUIRE( - stringProperty.status() == - MetadataPropertyViewStatus::InvalidBufferViewSizeNotFitInstanceCount); - - featureTableProperty.offsetType = FeatureTableProperty::OffsetType::UINT64; - stringProperty = - view.getPropertyView("TestClassProperty"); - REQUIRE( - stringProperty.status() == - MetadataPropertyViewStatus::InvalidBufferViewSizeNotFitInstanceCount); - - featureTableProperty.offsetType = "NONSENSE"; - stringProperty = - view.getPropertyView("TestClassProperty"); - REQUIRE( - stringProperty.status() == - MetadataPropertyViewStatus::InvalidOffsetType); - } - - SECTION("Offset values are not sorted ascending") { - uint32_t* offset = reinterpret_cast( - model.buffers[offsetBufferIndex].cesium.data.data()); - offset[2] = - static_cast(model.buffers[valueBufferIndex].byteLength + 4); - MetadataPropertyView stringProperty = - view.getPropertyView("TestClassProperty"); - REQUIRE( - stringProperty.status() == - MetadataPropertyViewStatus::InvalidOffsetValuesNotSortedAscending); - } - - SECTION("Offset value points outside of value buffer") { - uint32_t* offset = reinterpret_cast( - model.buffers[offsetBufferIndex].cesium.data.data()); - offset[featureTable.count] = - static_cast(model.buffers[valueBufferIndex].byteLength + 4); - MetadataPropertyView stringProperty = - view.getPropertyView("TestClassProperty"); - REQUIRE( - stringProperty.status() == - MetadataPropertyViewStatus::InvalidOffsetValuePointsToOutOfBoundBuffer); - } -} - -TEST_CASE("Test fixed numeric array") { - Model model; - - // store property value - std::vector values = - {12, 34, 30, 11, 34, 34, 11, 33, 122, 33, 223, 11}; - - size_t valueBufferViewIndex = 0; - { - Buffer& valueBuffer = model.buffers.emplace_back(); - valueBuffer.cesium.data.resize(values.size() * sizeof(uint32_t)); - valueBuffer.byteLength = - static_cast(valueBuffer.cesium.data.size()); - std::memcpy( - valueBuffer.cesium.data.data(), - values.data(), - valueBuffer.cesium.data.size()); - - BufferView& valueBufferView = model.bufferViews.emplace_back(); - valueBufferView.buffer = static_cast(model.buffers.size() - 1); - valueBufferView.byteOffset = 0; - valueBufferView.byteLength = valueBuffer.byteLength; - valueBufferViewIndex = model.bufferViews.size() - 1; - } - - // setup metadata - ExtensionModelExtFeatureMetadata& metadata = - model.addExtension(); - - // setup schema - Schema& schema = metadata.schema.emplace(); - Class& testClass = schema.classes["TestClass"]; - ClassProperty& testClassProperty = testClass.properties["TestClassProperty"]; - testClassProperty.type = ClassProperty::Type::ARRAY; - testClassProperty.componentType = ClassProperty::ComponentType::UINT32; - testClassProperty.componentCount = 3; - - // setup feature table - FeatureTable& featureTable = metadata.featureTables["TestFeatureTable"]; - featureTable.classProperty = "TestClass"; - featureTable.count = static_cast( - values.size() / - static_cast(testClassProperty.componentCount.value())); - - // setup feature table property - FeatureTableProperty& featureTableProperty = - featureTable.properties["TestClassProperty"]; - featureTableProperty.bufferView = - static_cast(model.bufferViews.size() - 1); - - // test feature table view - MetadataFeatureTableView view(&model, &featureTable); - const ClassProperty* classProperty = - view.getClassProperty("TestClassProperty"); - REQUIRE(classProperty->type == ClassProperty::Type::ARRAY); - REQUIRE(classProperty->componentCount == 3); - REQUIRE(classProperty->componentType == ClassProperty::ComponentType::UINT32); - - SECTION("Access the right type") { - MetadataPropertyView> arrayProperty = - view.getPropertyView>("TestClassProperty"); - REQUIRE(arrayProperty.status() == MetadataPropertyViewStatus::Valid); - - for (int64_t i = 0; i < arrayProperty.size(); ++i) { - MetadataArrayView member = arrayProperty.get(i); - for (int64_t j = 0; j < member.size(); ++j) { - REQUIRE(member[j] == values[static_cast(i * 3 + j)]); - } - } - } - - SECTION("Wrong component type") { - testClassProperty.componentType = ClassProperty::ComponentType::UINT8; - MetadataPropertyView> arrayProperty = - view.getPropertyView>("TestClassProperty"); - REQUIRE( - arrayProperty.status() == - MetadataPropertyViewStatus::InvalidTypeMismatch); - } - - SECTION("Buffer size is not a multiple of type size") { - model.bufferViews[valueBufferViewIndex].byteLength = 13; - MetadataPropertyView> arrayProperty = - view.getPropertyView>("TestClassProperty"); - REQUIRE( - arrayProperty.status() == - MetadataPropertyViewStatus:: - InvalidBufferViewSizeNotDivisibleByTypeSize); - } - - SECTION("Negative component count") { - testClassProperty.componentCount = -1; - MetadataPropertyView> arrayProperty = - view.getPropertyView>("TestClassProperty"); - REQUIRE( - arrayProperty.status() == - MetadataPropertyViewStatus:: - InvalidArrayComponentCountOrOffsetBufferNotExist); - } - - SECTION("Value buffer doesn't fit into feature table count") { - testClassProperty.componentCount = 55; - MetadataPropertyView> arrayProperty = - view.getPropertyView>("TestClassProperty"); - REQUIRE( - arrayProperty.status() == - MetadataPropertyViewStatus::InvalidBufferViewSizeNotFitInstanceCount); - } -} - -TEST_CASE("Test dynamic numeric array") { - Model model; - - // store property value - std::vector> expected{ - {12, 33, 11, 344, 112, 444, 1}, - {}, - {}, - {122, 23, 333, 12}, - {}, - {333, 311, 22, 34}, - {}, - {33, 1888, 233, 33019}}; - size_t numOfElements = 0; - for (const auto& expectedMember : expected) { - numOfElements += expectedMember.size(); - } - - std::vector values(numOfElements * sizeof(uint16_t)); - std::vector offsets((expected.size() + 1) * sizeof(uint64_t)); - uint64_t* offsetValue = reinterpret_cast(offsets.data()); - for (size_t i = 0; i < expected.size(); ++i) { - std::memcpy( - values.data() + offsetValue[i], - expected[i].data(), - expected[i].size() * sizeof(uint16_t)); - offsetValue[i + 1] = offsetValue[i] + expected[i].size() * sizeof(uint16_t); - } - - // store property value - size_t valueBufferViewIndex = 0; - { - Buffer& valueBuffer = model.buffers.emplace_back(); - valueBuffer.byteLength = static_cast(values.size()); - valueBuffer.cesium.data = std::move(values); - - BufferView& valueBufferView = model.bufferViews.emplace_back(); - valueBufferView.buffer = static_cast(model.buffers.size() - 1); - valueBufferView.byteOffset = 0; - valueBufferView.byteLength = valueBuffer.byteLength; - valueBufferViewIndex = model.bufferViews.size() - 1; - } - - // store string offset buffer - size_t offsetBufferViewIndex = 0; - { - Buffer& offsetBuffer = model.buffers.emplace_back(); - offsetBuffer.byteLength = static_cast(offsets.size()); - offsetBuffer.cesium.data = std::move(offsets); - - BufferView& offsetBufferView = model.bufferViews.emplace_back(); - offsetBufferView.buffer = static_cast(model.buffers.size() - 1); - offsetBufferView.byteOffset = 0; - offsetBufferView.byteLength = offsetBuffer.byteLength; - offsetBufferViewIndex = model.bufferViews.size() - 1; - } - - // setup metadata - ExtensionModelExtFeatureMetadata& metadata = - model.addExtension(); - - // setup schema - Schema& schema = metadata.schema.emplace(); - Class& testClass = schema.classes["TestClass"]; - ClassProperty& testClassProperty = testClass.properties["TestClassProperty"]; - testClassProperty.type = ClassProperty::Type::ARRAY; - testClassProperty.componentType = ClassProperty::ComponentType::UINT16; - - // setup feature table - FeatureTable& featureTable = metadata.featureTables["TestFeatureTable"]; - featureTable.classProperty = "TestClass"; - featureTable.count = static_cast(expected.size()); - - // setup feature table property - FeatureTableProperty& featureTableProperty = - featureTable.properties["TestClassProperty"]; - featureTableProperty.bufferView = static_cast(valueBufferViewIndex); - featureTableProperty.arrayOffsetBufferView = - static_cast(offsetBufferViewIndex); - featureTableProperty.offsetType = FeatureTableProperty::OffsetType::UINT64; - - // test feature table view - MetadataFeatureTableView view(&model, &featureTable); - const ClassProperty* classProperty = - view.getClassProperty("TestClassProperty"); - REQUIRE(classProperty->type == ClassProperty::Type::ARRAY); - REQUIRE(classProperty->componentType == ClassProperty::ComponentType::UINT16); - - SECTION("Access the correct type") { - MetadataPropertyView> property = - view.getPropertyView>("TestClassProperty"); - REQUIRE(property.status() == MetadataPropertyViewStatus::Valid); - for (size_t i = 0; i < expected.size(); ++i) { - MetadataArrayView valueMember = - property.get(static_cast(i)); - REQUIRE(valueMember.size() == static_cast(expected[i].size())); - for (size_t j = 0; j < expected[i].size(); ++j) { - REQUIRE(expected[i][j] == valueMember[static_cast(j)]); - } - } - } - - SECTION("Component count and offset buffer appear at the same time") { - testClassProperty.componentCount = 3; - MetadataPropertyView> property = - view.getPropertyView>("TestClassProperty"); - REQUIRE( - property.status() == - MetadataPropertyViewStatus:: - InvalidArrayComponentCountAndOffsetBufferCoexist); - } -} - -TEST_CASE("Test fixed boolean array") { - Model model; - - // store property value - std::vector expected = { - true, - false, - false, - true, - false, - false, - true, - true, - true, - false, - false, - true}; - std::vector values; - size_t requiredBytesSize = static_cast( - glm::ceil(static_cast(expected.size()) / 8.0)); - values.resize(requiredBytesSize); - for (size_t i = 0; i < expected.size(); ++i) { - uint8_t expectedValue = expected[i]; - size_t byteIndex = i / 8; - size_t bitIndex = i % 8; - values[byteIndex] = - static_cast((expectedValue << bitIndex) | values[byteIndex]); - } - - { - Buffer& valueBuffer = model.buffers.emplace_back(); - valueBuffer.cesium.data.resize(values.size()); - valueBuffer.byteLength = - static_cast(valueBuffer.cesium.data.size()); - std::memcpy( - valueBuffer.cesium.data.data(), - values.data(), - valueBuffer.cesium.data.size()); - - BufferView& valueBufferView = model.bufferViews.emplace_back(); - valueBufferView.buffer = static_cast(model.buffers.size() - 1); - valueBufferView.byteOffset = 0; - valueBufferView.byteLength = valueBuffer.byteLength; - } - - // setup metadata - ExtensionModelExtFeatureMetadata& metadata = - model.addExtension(); - - // setup schema - Schema& schema = metadata.schema.emplace(); - Class& testClass = schema.classes["TestClass"]; - ClassProperty& testClassProperty = testClass.properties["TestClassProperty"]; - testClassProperty.type = ClassProperty::Type::ARRAY; - testClassProperty.componentType = ClassProperty::ComponentType::BOOLEAN; - testClassProperty.componentCount = 3; - - // setup feature table - FeatureTable& featureTable = metadata.featureTables["TestFeatureTable"]; - featureTable.classProperty = "TestClass"; - featureTable.count = static_cast( - expected.size() / - static_cast(testClassProperty.componentCount.value())); - - // setup feature table property - FeatureTableProperty& featureTableProperty = - featureTable.properties["TestClassProperty"]; - featureTableProperty.bufferView = - static_cast(model.bufferViews.size() - 1); - - // test feature table view - MetadataFeatureTableView view(&model, &featureTable); - const ClassProperty* classProperty = - view.getClassProperty("TestClassProperty"); - REQUIRE(classProperty->type == ClassProperty::Type::ARRAY); - REQUIRE(classProperty->componentCount == 3); - REQUIRE( - classProperty->componentType == ClassProperty::ComponentType::BOOLEAN); - - SECTION("Access correct type") { - MetadataPropertyView> boolProperty = - view.getPropertyView>("TestClassProperty"); - REQUIRE(boolProperty.status() == MetadataPropertyViewStatus::Valid); - REQUIRE(boolProperty.size() == featureTable.count); - REQUIRE(boolProperty.size() > 0); - for (int64_t i = 0; i < boolProperty.size(); ++i) { - MetadataArrayView valueMember = boolProperty.get(i); - for (int64_t j = 0; j < valueMember.size(); ++j) { - REQUIRE(valueMember[j] == expected[static_cast(i * 3 + j)]); - } - } - } - - SECTION("Value buffer doesn't have enough required bytes") { - testClassProperty.componentCount = 11; - MetadataPropertyView> boolProperty = - view.getPropertyView>("TestClassProperty"); - REQUIRE( - boolProperty.status() == - MetadataPropertyViewStatus::InvalidBufferViewSizeNotFitInstanceCount); - } - - SECTION("Component count is negative") { - testClassProperty.componentCount = -1; - MetadataPropertyView> boolProperty = - view.getPropertyView>("TestClassProperty"); - REQUIRE( - boolProperty.status() == - MetadataPropertyViewStatus:: - InvalidArrayComponentCountOrOffsetBufferNotExist); - } -} - -TEST_CASE("Test dynamic bool array") { - Model model; - - // store property value - std::vector> expected{ - {true, false, true, true, false, true, true}, - {}, - {}, - {}, - {false, false, false, false}, - {true, false, true}, - {false}, - {true, true, true, true, true, false, false}}; - size_t numOfElements = 0; - for (const auto& expectedMember : expected) { - numOfElements += expectedMember.size(); - } - - size_t requiredBytesSize = - static_cast(glm::ceil(static_cast(numOfElements) / 8.0)); - std::vector values(requiredBytesSize); - std::vector offsets((expected.size() + 1) * sizeof(uint64_t)); - uint64_t* offsetValue = reinterpret_cast(offsets.data()); - size_t indexSoFar = 0; - for (size_t i = 0; i < expected.size(); ++i) { - for (size_t j = 0; j < expected[i].size(); ++j) { - uint8_t expectedValue = expected[i][j]; - size_t byteIndex = indexSoFar / 8; - size_t bitIndex = indexSoFar % 8; - values[byteIndex] = static_cast( - (expectedValue << bitIndex) | static_cast(values[byteIndex])); - ++indexSoFar; - } - offsetValue[i + 1] = offsetValue[i] + expected[i].size(); - } - - // store property value - size_t valueBufferViewIndex = 0; - { - Buffer& valueBuffer = model.buffers.emplace_back(); - valueBuffer.byteLength = static_cast(values.size()); - valueBuffer.cesium.data = std::move(values); - - BufferView& valueBufferView = model.bufferViews.emplace_back(); - valueBufferView.buffer = static_cast(model.buffers.size() - 1); - valueBufferView.byteOffset = 0; - valueBufferView.byteLength = valueBuffer.byteLength; - valueBufferViewIndex = model.bufferViews.size() - 1; - } - - // store string offset buffer - size_t offsetBufferViewIndex = 0; - { - Buffer& offsetBuffer = model.buffers.emplace_back(); - offsetBuffer.byteLength = static_cast(offsets.size()); - offsetBuffer.cesium.data = std::move(offsets); - - BufferView& offsetBufferView = model.bufferViews.emplace_back(); - offsetBufferView.buffer = static_cast(model.buffers.size() - 1); - offsetBufferView.byteOffset = 0; - offsetBufferView.byteLength = offsetBuffer.byteLength; - offsetBufferViewIndex = model.bufferViews.size() - 1; - } - - // setup metadata - ExtensionModelExtFeatureMetadata& metadata = - model.addExtension(); - - // setup schema - Schema& schema = metadata.schema.emplace(); - Class& testClass = schema.classes["TestClass"]; - ClassProperty& testClassProperty = testClass.properties["TestClassProperty"]; - testClassProperty.type = ClassProperty::Type::ARRAY; - testClassProperty.componentType = ClassProperty::ComponentType::BOOLEAN; - - // setup feature table - FeatureTable& featureTable = metadata.featureTables["TestFeatureTable"]; - featureTable.classProperty = "TestClass"; - featureTable.count = static_cast(expected.size()); - - // setup feature table property - FeatureTableProperty& featureTableProperty = - featureTable.properties["TestClassProperty"]; - featureTableProperty.bufferView = static_cast(valueBufferViewIndex); - featureTableProperty.arrayOffsetBufferView = - static_cast(offsetBufferViewIndex); - featureTableProperty.offsetType = FeatureTableProperty::OffsetType::UINT64; - - // test feature table view - MetadataFeatureTableView view(&model, &featureTable); - const ClassProperty* classProperty = - view.getClassProperty("TestClassProperty"); - REQUIRE(classProperty->type == ClassProperty::Type::ARRAY); - REQUIRE( - classProperty->componentType == ClassProperty::ComponentType::BOOLEAN); - - SECTION("Access correct type") { - MetadataPropertyView> boolProperty = - view.getPropertyView>("TestClassProperty"); - REQUIRE(boolProperty.status() == MetadataPropertyViewStatus::Valid); - for (size_t i = 0; i < expected.size(); ++i) { - MetadataArrayView arrayMember = - boolProperty.get(static_cast(i)); - REQUIRE(arrayMember.size() == static_cast(expected[i].size())); - for (size_t j = 0; j < expected[i].size(); ++j) { - REQUIRE(expected[i][j] == arrayMember[static_cast(j)]); - } - } - } - - SECTION("Component count and array offset appear at the same time") { - testClassProperty.componentCount = 3; - MetadataPropertyView> boolProperty = - view.getPropertyView>("TestClassProperty"); - REQUIRE( - boolProperty.status() == - MetadataPropertyViewStatus:: - InvalidArrayComponentCountAndOffsetBufferCoexist); - } -} - -TEST_CASE("Test fixed array of string") { - Model model; - - std::vector expected{ - "What's up", - "Breaking news!!! Aliens no longer attacks the US first", - "But they still abduct my cows! Those milk thiefs! 👽 🐮", - "I'm not crazy. My mother had me tested 🤪", - "I love you, meat bags! ❤️", - "Book in the freezer"}; - - size_t totalBytes = 0; - for (const std::string& expectedValue : expected) { - totalBytes += expectedValue.size(); - } - - std::vector offsets((expected.size() + 1) * sizeof(uint32_t)); - std::vector values(totalBytes); - uint32_t* offsetValue = reinterpret_cast(offsets.data()); - for (size_t i = 0; i < expected.size(); ++i) { - const std::string& expectedValue = expected[i]; - std::memcpy( - values.data() + offsetValue[i], - expectedValue.c_str(), - expectedValue.size()); - offsetValue[i + 1] = - offsetValue[i] + static_cast(expectedValue.size()); - } - - // store property value - size_t valueBufferViewIndex = 0; - { - Buffer& valueBuffer = model.buffers.emplace_back(); - valueBuffer.byteLength = static_cast(values.size()); - valueBuffer.cesium.data = std::move(values); - - BufferView& valueBufferView = model.bufferViews.emplace_back(); - valueBufferView.buffer = static_cast(model.buffers.size() - 1); - valueBufferView.byteOffset = 0; - valueBufferView.byteLength = valueBuffer.byteLength; - valueBufferViewIndex = model.bufferViews.size() - 1; - } - - // store string offset buffer - size_t offsetBufferViewIndex = 0; - { - Buffer& offsetBuffer = model.buffers.emplace_back(); - offsetBuffer.byteLength = static_cast(offsets.size()); - offsetBuffer.cesium.data = std::move(offsets); - - BufferView& offsetBufferView = model.bufferViews.emplace_back(); - offsetBufferView.buffer = static_cast(model.buffers.size() - 1); - offsetBufferView.byteOffset = 0; - offsetBufferView.byteLength = offsetBuffer.byteLength; - offsetBufferViewIndex = model.bufferViews.size() - 1; - } - - // setup metadata - ExtensionModelExtFeatureMetadata& metadata = - model.addExtension(); - - // setup schema - Schema& schema = metadata.schema.emplace(); - Class& testClass = schema.classes["TestClass"]; - ClassProperty& testClassProperty = testClass.properties["TestClassProperty"]; - testClassProperty.type = ClassProperty::Type::ARRAY; - testClassProperty.componentType = ClassProperty::ComponentType::STRING; - testClassProperty.componentCount = 2; - - // setup feature table - FeatureTable& featureTable = metadata.featureTables["TestFeatureTable"]; - featureTable.classProperty = "TestClass"; - featureTable.count = static_cast( - expected.size() / - static_cast(testClassProperty.componentCount.value())); - - // setup feature table property - FeatureTableProperty& featureTableProperty = - featureTable.properties["TestClassProperty"]; - featureTableProperty.offsetType = FeatureTableProperty::OffsetType::UINT32; - featureTableProperty.bufferView = static_cast(valueBufferViewIndex); - featureTableProperty.stringOffsetBufferView = - static_cast(offsetBufferViewIndex); - - // test feature table view - MetadataFeatureTableView view(&model, &featureTable); - const ClassProperty* classProperty = - view.getClassProperty("TestClassProperty"); - REQUIRE(classProperty->type == ClassProperty::Type::ARRAY); - REQUIRE(classProperty->componentCount == 2); - REQUIRE(classProperty->componentType == ClassProperty::ComponentType::STRING); - - SECTION("Access correct type") { - MetadataPropertyView> stringProperty = - view.getPropertyView>( - "TestClassProperty"); - REQUIRE(stringProperty.status() == MetadataPropertyViewStatus::Valid); - REQUIRE(stringProperty.size() == 3); - - MetadataArrayView v0 = stringProperty.get(0); - REQUIRE(v0.size() == 2); - REQUIRE(v0[0] == "What's up"); - REQUIRE(v0[1] == "Breaking news!!! Aliens no longer attacks the US first"); - - MetadataArrayView v1 = stringProperty.get(1); - REQUIRE(v1.size() == 2); - REQUIRE(v1[0] == "But they still abduct my cows! Those milk thiefs! 👽 🐮"); - REQUIRE(v1[1] == "I'm not crazy. My mother had me tested 🤪"); - - MetadataArrayView v2 = stringProperty.get(2); - REQUIRE(v2.size() == 2); - REQUIRE(v2[0] == "I love you, meat bags! ❤️"); - REQUIRE(v2[1] == "Book in the freezer"); - } - - SECTION("Component count is negative") { - testClassProperty.componentCount = -1; - MetadataPropertyView> stringProperty = - view.getPropertyView>( - "TestClassProperty"); - REQUIRE( - stringProperty.status() == - MetadataPropertyViewStatus:: - InvalidArrayComponentCountOrOffsetBufferNotExist); - } - - SECTION("Offset type is unknown") { - featureTableProperty.offsetType = "NONSENSE"; - MetadataPropertyView> stringProperty = - view.getPropertyView>( - "TestClassProperty"); - REQUIRE( - stringProperty.status() == - MetadataPropertyViewStatus::InvalidOffsetType); - } - - SECTION("string offset buffer doesn't exist") { - featureTableProperty.stringOffsetBufferView = -1; - MetadataPropertyView> stringProperty = - view.getPropertyView>( - "TestClassProperty"); - REQUIRE( - stringProperty.status() == - MetadataPropertyViewStatus::InvalidStringOffsetBufferViewIndex); - } -} - -TEST_CASE("Test dynamic array of string") { - Model model; - - std::vector> expected{ - {"What's up"}, - {"Breaking news!!! Aliens no longer attacks the US first", - "But they still abduct my cows! Those milk thiefs! 👽 🐮"}, - {"I'm not crazy. My mother had me tested 🤪", - "I love you, meat bags! ❤️", - "Book in the freezer"}}; - - size_t totalBytes = 0; - size_t numOfElements = 0; - for (const auto& expectedValues : expected) { - for (const auto& value : expectedValues) { - totalBytes += value.size(); - } - - numOfElements += expectedValues.size(); - } - - std::vector offsets((expected.size() + 1) * sizeof(uint32_t)); - std::vector stringOffsets((numOfElements + 1) * sizeof(uint32_t)); - std::vector values(totalBytes); - uint32_t* offsetValue = reinterpret_cast(offsets.data()); - uint32_t* stringOffsetValue = - reinterpret_cast(stringOffsets.data()); - size_t strOffsetIdx = 0; - for (size_t i = 0; i < expected.size(); ++i) { - for (size_t j = 0; j < expected[i].size(); ++j) { - const std::string& expectedValue = expected[i][j]; - std::memcpy( - values.data() + stringOffsetValue[strOffsetIdx], - expectedValue.c_str(), - expectedValue.size()); - - stringOffsetValue[strOffsetIdx + 1] = - stringOffsetValue[strOffsetIdx] + - static_cast(expectedValue.size()); - ++strOffsetIdx; - } - - offsetValue[i + 1] = - offsetValue[i] + - static_cast(expected[i].size() * sizeof(uint32_t)); - } - - // store property value - size_t valueBufferViewIndex = 0; - { - Buffer& valueBuffer = model.buffers.emplace_back(); - valueBuffer.byteLength = static_cast(values.size()); - valueBuffer.cesium.data = std::move(values); - - BufferView& valueBufferView = model.bufferViews.emplace_back(); - valueBufferView.buffer = static_cast(model.buffers.size() - 1); - valueBufferView.byteOffset = 0; - valueBufferView.byteLength = valueBuffer.byteLength; - valueBufferViewIndex = model.bufferViews.size() - 1; - } - - // store array offset buffer - size_t offsetBufferViewIndex = 0; - { - Buffer& offsetBuffer = model.buffers.emplace_back(); - offsetBuffer.byteLength = static_cast(offsets.size()); - offsetBuffer.cesium.data = std::move(offsets); - - BufferView& offsetBufferView = model.bufferViews.emplace_back(); - offsetBufferView.buffer = static_cast(model.buffers.size() - 1); - offsetBufferView.byteOffset = 0; - offsetBufferView.byteLength = offsetBuffer.byteLength; - offsetBufferViewIndex = model.bufferViews.size() - 1; - } - - // store string offset buffer - size_t strOffsetBufferViewIndex = 0; - { - Buffer& strOffsetBuffer = model.buffers.emplace_back(); - strOffsetBuffer.byteLength = static_cast(stringOffsets.size()); - strOffsetBuffer.cesium.data = std::move(stringOffsets); - - BufferView& strOffsetBufferView = model.bufferViews.emplace_back(); - strOffsetBufferView.buffer = static_cast(model.buffers.size() - 1); - strOffsetBufferView.byteOffset = 0; - strOffsetBufferView.byteLength = strOffsetBuffer.byteLength; - strOffsetBufferViewIndex = model.bufferViews.size() - 1; - } - - // setup metadata - ExtensionModelExtFeatureMetadata& metadata = - model.addExtension(); - - // setup schema - Schema& schema = metadata.schema.emplace(); - Class& testClass = schema.classes["TestClass"]; - ClassProperty& testClassProperty = testClass.properties["TestClassProperty"]; - testClassProperty.type = ClassProperty::Type::ARRAY; - testClassProperty.componentType = ClassProperty::ComponentType::STRING; - - // setup feature table - FeatureTable& featureTable = metadata.featureTables["TestFeatureTable"]; - featureTable.classProperty = "TestClass"; - featureTable.count = static_cast(expected.size()); - - // setup feature table property - FeatureTableProperty& featureTableProperty = - featureTable.properties["TestClassProperty"]; - featureTableProperty.offsetType = FeatureTableProperty::OffsetType::UINT32; - featureTableProperty.bufferView = static_cast(valueBufferViewIndex); - featureTableProperty.arrayOffsetBufferView = - static_cast(offsetBufferViewIndex); - featureTableProperty.stringOffsetBufferView = - static_cast(strOffsetBufferViewIndex); - - // test feature table view - MetadataFeatureTableView view(&model, &featureTable); - const ClassProperty* classProperty = - view.getClassProperty("TestClassProperty"); - REQUIRE(classProperty->type == ClassProperty::Type::ARRAY); - REQUIRE(classProperty->componentType == ClassProperty::ComponentType::STRING); - - SECTION("Access correct type") { - MetadataPropertyView> stringProperty = - view.getPropertyView>( - "TestClassProperty"); - REQUIRE(stringProperty.status() == MetadataPropertyViewStatus::Valid); - for (size_t i = 0; i < expected.size(); ++i) { - MetadataArrayView stringArray = - stringProperty.get(static_cast(i)); - for (size_t j = 0; j < expected[i].size(); ++j) { - REQUIRE(stringArray[static_cast(j)] == expected[i][j]); - } - } - } -} diff --git a/CesiumGltf/test/TestStructuralMetadataPropertyTablePropertyView.cpp b/CesiumGltf/test/TestPropertyTablePropertyView.cpp similarity index 93% rename from CesiumGltf/test/TestStructuralMetadataPropertyTablePropertyView.cpp rename to CesiumGltf/test/TestPropertyTablePropertyView.cpp index d77e0a2a6..ae1075ec3 100644 --- a/CesiumGltf/test/TestStructuralMetadataPropertyTablePropertyView.cpp +++ b/CesiumGltf/test/TestPropertyTablePropertyView.cpp @@ -1,4 +1,4 @@ -#include "CesiumGltf/StructuralMetadataPropertyTablePropertyView.h" +#include "CesiumGltf/PropertyTablePropertyView.h" #include #include @@ -9,7 +9,7 @@ #include #include -using namespace CesiumGltf::StructuralMetadata; +using namespace CesiumGltf; template static void checkNumeric(const std::vector& expected) { std::vector data; @@ -46,7 +46,7 @@ static void checkVariableLengthArray( offsets.data(), offsets.size() * sizeof(OffsetType)); - PropertyTablePropertyView> property( + PropertyTablePropertyView> property( PropertyTablePropertyViewStatus::Valid, gsl::span(buffer.data(), buffer.size()), gsl::span(offsetBuffer.data(), offsetBuffer.size()), @@ -59,7 +59,7 @@ static void checkVariableLengthArray( size_t expectedIdx = 0; for (int64_t i = 0; i < property.size(); ++i) { - MetadataArrayView values = property.get(i); + PropertyArrayView values = property.get(i); for (int64_t j = 0; j < values.size(); ++j) { REQUIRE(values[j] == data[expectedIdx]); ++expectedIdx; @@ -78,7 +78,7 @@ static void checkFixedLengthArray( buffer.resize(data.size() * sizeof(T)); std::memcpy(buffer.data(), data.data(), data.size() * sizeof(T)); - PropertyTablePropertyView> property( + PropertyTablePropertyView> property( PropertyTablePropertyViewStatus::Valid, gsl::span(buffer.data(), buffer.size()), gsl::span(), @@ -91,7 +91,7 @@ static void checkFixedLengthArray( size_t expectedIdx = 0; for (int64_t i = 0; i < property.size(); ++i) { - MetadataArrayView values = property.get(i); + PropertyArrayView values = property.get(i); for (int64_t j = 0; j < values.size(); ++j) { REQUIRE(values[j] == data[expectedIdx]); ++expectedIdx; @@ -101,7 +101,7 @@ static void checkFixedLengthArray( REQUIRE(expectedIdx == data.size()); } -TEST_CASE("Check StructuralMetadata scalar numeric property view") { +TEST_CASE("Check scalar numeric property view") { SECTION("Uint8 Scalar") { std::vector data{12, 33, 56, 67}; checkNumeric(data); @@ -127,7 +127,7 @@ TEST_CASE("Check StructuralMetadata scalar numeric property view") { } } -TEST_CASE("Check StructuralMetadata vecN numeric property view") { +TEST_CASE("Check vecN numeric property view") { SECTION("Float Vec2") { std::vector data{ glm::vec2(10.001f, 0.005f), @@ -156,7 +156,7 @@ TEST_CASE("Check StructuralMetadata vecN numeric property view") { } } -TEST_CASE("Check StructuralMetadata matN numeric property view") { +TEST_CASE("Check matN numeric property view") { SECTION("Float Mat2") { // clang-format off std::vector data{ @@ -218,7 +218,7 @@ TEST_CASE("Check StructuralMetadata matN numeric property view") { } } -TEST_CASE("Check StructuralMetadata boolean property") { +TEST_CASE("Check boolean property") { std::bitset bits = 0b11110101; unsigned long val = bits.to_ulong(); std::vector data(sizeof(val)); @@ -235,7 +235,7 @@ TEST_CASE("Check StructuralMetadata boolean property") { } } -TEST_CASE("Check StructuralMetadata string property") { +TEST_CASE("Check string property") { std::vector strings{ "This is a fine test", "What's going on", @@ -287,7 +287,7 @@ TEST_CASE("Check StructuralMetadata string property") { } } -TEST_CASE("Check StructuralMetadata fixed-length scalar array property") { +TEST_CASE("Check fixed-length scalar array property") { SECTION("Fixed-length array of 4 uint8_ts") { // clang-format off std::vector data{ @@ -376,7 +376,7 @@ TEST_CASE("Check StructuralMetadata fixed-length scalar array property") { } } -TEST_CASE("Check StructuralMetadata fixed-length vecN array property") { +TEST_CASE("Check fixed-length vecN array property") { SECTION("Fixed-length array of 4 u8vec2s") { // clang-format off std::vector data{ @@ -419,7 +419,7 @@ TEST_CASE("Check StructuralMetadata fixed-length vecN array property") { } } -TEST_CASE("Check StructuralMetadata fixed-length matN array property") { +TEST_CASE("Check fixed-length matN array property") { SECTION("Fixed-length array of 4 i8mat2x2") { // clang-format off std::vector data{ @@ -520,7 +520,7 @@ TEST_CASE("Check StructuralMetadata fixed-length matN array property") { } } -TEST_CASE("Check StructuralMetadata variable-length scalar array property") { +TEST_CASE("Check variable-length scalar array property") { SECTION("Variable-length array of uint8_t") { // clang-format off std::vector data{ @@ -572,7 +572,7 @@ TEST_CASE("Check StructuralMetadata variable-length scalar array property") { } } -TEST_CASE("Check StructuralMetadata variable-length vecN array property") { +TEST_CASE("Check variable-length vecN array property") { SECTION("Variable-length array of ivec2") { // clang-format off std::vector data{ @@ -636,7 +636,7 @@ TEST_CASE("Check StructuralMetadata variable-length vecN array property") { } } -TEST_CASE("Check StructuralMetadata variable-length matN array property") { +TEST_CASE("Check variable-length matN array property") { SECTION("Variable-length array of dmat2") { // clang-format off std::vector data0{ @@ -786,7 +786,7 @@ TEST_CASE("Check StructuralMetadata variable-length matN array property") { } } -TEST_CASE("Check StructuralMetadata fixed-length array of string") { +TEST_CASE("Check fixed-length array of string") { std::vector strings{ "Test 1", "Test 2", @@ -831,7 +831,7 @@ TEST_CASE("Check StructuralMetadata fixed-length array of string") { ¤tStringOffset, sizeof(uint32_t)); - PropertyTablePropertyView> property( + PropertyTablePropertyView> property( PropertyTablePropertyViewStatus::Valid, gsl::span(buffer.data(), buffer.size()), gsl::span(), @@ -844,7 +844,7 @@ TEST_CASE("Check StructuralMetadata fixed-length array of string") { size_t expectedIdx = 0; for (int64_t i = 0; i < property.size(); ++i) { - MetadataArrayView values = property.get(i); + PropertyArrayView values = property.get(i); for (int64_t j = 0; j < values.size(); ++j) { std::string_view v = values[j]; REQUIRE(v == strings[expectedIdx]); @@ -855,8 +855,7 @@ TEST_CASE("Check StructuralMetadata fixed-length array of string") { REQUIRE(expectedIdx == stringCount); } -TEST_CASE( - "Check StructuralMetadata variable-length array of strings property") { +TEST_CASE("Check variable-length array of strings property") { // clang-format off std::vector arrayOffsets{ 0, @@ -904,7 +903,7 @@ TEST_CASE( ¤tOffset, sizeof(uint32_t)); - PropertyTablePropertyView> property( + PropertyTablePropertyView> property( PropertyTablePropertyViewStatus::Valid, gsl::span(buffer.data(), buffer.size()), gsl::span( @@ -919,7 +918,7 @@ TEST_CASE( size_t expectedIdx = 0; for (int64_t i = 0; i < property.size(); ++i) { - MetadataArrayView values = property.get(i); + PropertyArrayView values = property.get(i); for (int64_t j = 0; j < values.size(); ++j) { std::string_view v = values[j]; REQUIRE(v == strings[expectedIdx]); @@ -930,13 +929,13 @@ TEST_CASE( REQUIRE(expectedIdx == stringCount); } -TEST_CASE("Check StructuralMetadata fixed-length boolean array property") { +TEST_CASE("Check fixed-length boolean array property") { std::vector buffer{ static_cast(0b10101111), static_cast(0b11111010), static_cast(0b11100111)}; - PropertyTablePropertyView> property( + PropertyTablePropertyView> property( PropertyTablePropertyViewStatus::Valid, gsl::span(buffer.data(), buffer.size()), gsl::span(), @@ -949,7 +948,7 @@ TEST_CASE("Check StructuralMetadata fixed-length boolean array property") { REQUIRE(property.size() == 2); - MetadataArrayView val0 = property.get(0); + PropertyArrayView val0 = property.get(0); REQUIRE(val0.size() == 12); REQUIRE(static_cast(val0[0]) == 1); REQUIRE(static_cast(val0[1]) == 1); @@ -964,7 +963,7 @@ TEST_CASE("Check StructuralMetadata fixed-length boolean array property") { REQUIRE(static_cast(val0[10]) == 0); REQUIRE(static_cast(val0[11]) == 1); - MetadataArrayView val1 = property.get(1); + PropertyArrayView val1 = property.get(1); REQUIRE(static_cast(val1[0]) == 1); REQUIRE(static_cast(val1[1]) == 1); REQUIRE(static_cast(val1[2]) == 1); @@ -979,7 +978,7 @@ TEST_CASE("Check StructuralMetadata fixed-length boolean array property") { REQUIRE(static_cast(val1[11]) == 1); } -TEST_CASE("Check StructuralMetadata variable-length boolean array property") { +TEST_CASE("Check variable-length boolean array property") { std::vector buffer{ static_cast(0b10101111), static_cast(0b11111010), @@ -988,7 +987,7 @@ TEST_CASE("Check StructuralMetadata variable-length boolean array property") { std::vector offsetBuffer{0, 3, 12, 28}; - PropertyTablePropertyView> property( + PropertyTablePropertyView> property( PropertyTablePropertyViewStatus::Valid, gsl::span(buffer.data(), buffer.size()), gsl::span( @@ -1003,13 +1002,13 @@ TEST_CASE("Check StructuralMetadata variable-length boolean array property") { REQUIRE(property.size() == 3); - MetadataArrayView val0 = property.get(0); + PropertyArrayView val0 = property.get(0); REQUIRE(val0.size() == 3); REQUIRE(static_cast(val0[0]) == 1); REQUIRE(static_cast(val0[1]) == 1); REQUIRE(static_cast(val0[2]) == 1); - MetadataArrayView val1 = property.get(1); + PropertyArrayView val1 = property.get(1); REQUIRE(val1.size() == 9); REQUIRE(static_cast(val1[0]) == 1); REQUIRE(static_cast(val1[1]) == 0); @@ -1021,7 +1020,7 @@ TEST_CASE("Check StructuralMetadata variable-length boolean array property") { REQUIRE(static_cast(val1[7]) == 0); REQUIRE(static_cast(val1[8]) == 1); - MetadataArrayView val2 = property.get(2); + PropertyArrayView val2 = property.get(2); REQUIRE(val2.size() == 16); REQUIRE(static_cast(val2[0]) == 1); REQUIRE(static_cast(val2[1]) == 1); diff --git a/CesiumGltf/test/TestStructuralMetadataPropertyTableView.cpp b/CesiumGltf/test/TestPropertyTableView.cpp similarity index 91% rename from CesiumGltf/test/TestStructuralMetadataPropertyTableView.cpp rename to CesiumGltf/test/TestPropertyTableView.cpp index 952f6d4cd..cfadc098b 100644 --- a/CesiumGltf/test/TestStructuralMetadataPropertyTableView.cpp +++ b/CesiumGltf/test/TestPropertyTableView.cpp @@ -1,11 +1,10 @@ -#include "CesiumGltf/StructuralMetadataPropertyTableView.h" +#include "CesiumGltf/PropertyTableView.h" #include #include using namespace CesiumGltf; -using namespace CesiumGltf::StructuralMetadata; TEST_CASE("Test PropertyTableView on model without EXT_structural_metadata " "extension") { @@ -87,7 +86,7 @@ TEST_CASE("Test property table with nonexistent class") { REQUIRE(!classProperty); } -TEST_CASE("Test StructuralMetadata scalar property") { +TEST_CASE("Test scalar property") { Model model; std::vector values = {12, 34, 30, 11, 34, 34, 11, 33, 122, 33}; @@ -210,8 +209,8 @@ TEST_CASE("Test StructuralMetadata scalar property") { } SECTION("Access incorrectly as array") { - PropertyTablePropertyView> uint32ArrayInvalid = - view.getPropertyView>("TestClassProperty"); + PropertyTablePropertyView> uint32ArrayInvalid = + view.getPropertyView>("TestClassProperty"); REQUIRE( uint32ArrayInvalid.status() == PropertyTablePropertyViewStatus::ErrorArrayTypeMismatch); @@ -265,7 +264,7 @@ TEST_CASE("Test StructuralMetadata scalar property") { } } -TEST_CASE("Test StructuralMetadata vecN property") { +TEST_CASE("Test vecN property") { Model model; std::vector values = { @@ -398,8 +397,8 @@ TEST_CASE("Test StructuralMetadata vecN property") { } SECTION("Access incorrectly as array") { - PropertyTablePropertyView> ivec3ArrayInvalid = - view.getPropertyView>( + PropertyTablePropertyView> ivec3ArrayInvalid = + view.getPropertyView>( "TestClassProperty"); REQUIRE( ivec3ArrayInvalid.status() == @@ -454,7 +453,7 @@ TEST_CASE("Test StructuralMetadata vecN property") { } } -TEST_CASE("Test StructuralMetadata matN property") { +TEST_CASE("Test matN property") { Model model; // clang-format off @@ -598,9 +597,9 @@ TEST_CASE("Test StructuralMetadata matN property") { } SECTION("Access incorrectly as array") { - PropertyTablePropertyView> + PropertyTablePropertyView> u32mat2x2ArrayInvalid = - view.getPropertyView>( + view.getPropertyView>( "TestClassProperty"); REQUIRE( u32mat2x2ArrayInvalid.status() == @@ -657,7 +656,7 @@ TEST_CASE("Test StructuralMetadata matN property") { } } -TEST_CASE("Test StructuralMetadata boolean property") { +TEST_CASE("Test boolean property") { Model model; int64_t instanceCount = 21; @@ -752,7 +751,7 @@ TEST_CASE("Test StructuralMetadata boolean property") { } } -TEST_CASE("Test StructuralMetadata string property") { +TEST_CASE("Test string property") { Model model; std::vector expected{"What's up", "Test_0", "Test_1", "", "Hi"}; @@ -855,9 +854,9 @@ TEST_CASE("Test StructuralMetadata string property") { } SECTION("Wrong array type") { - PropertyTablePropertyView> + PropertyTablePropertyView> stringArrayInvalid = - view.getPropertyView>( + view.getPropertyView>( "TestClassProperty"); REQUIRE( stringArrayInvalid.status() == @@ -928,7 +927,7 @@ TEST_CASE("Test StructuralMetadata string property") { } } -TEST_CASE("Test StructuralMetadata fixed-length scalar array") { +TEST_CASE("Test fixed-length scalar array") { Model model; std::vector values = @@ -994,12 +993,12 @@ TEST_CASE("Test StructuralMetadata fixed-length scalar array") { REQUIRE(classProperty->count == 3); SECTION("Access the right type") { - PropertyTablePropertyView> arrayProperty = - view.getPropertyView>("TestClassProperty"); + PropertyTablePropertyView> arrayProperty = + view.getPropertyView>("TestClassProperty"); REQUIRE(arrayProperty.status() == PropertyTablePropertyViewStatus::Valid); for (int64_t i = 0; i < arrayProperty.size(); ++i) { - MetadataArrayView member = arrayProperty.get(i); + PropertyArrayView member = arrayProperty.get(i); for (int64_t j = 0; j < member.size(); ++j) { REQUIRE(member[j] == values[static_cast(i * 3 + j)]); } @@ -1007,14 +1006,14 @@ TEST_CASE("Test StructuralMetadata fixed-length scalar array") { } SECTION("Wrong type") { - PropertyTablePropertyView> boolArrayInvalid = - view.getPropertyView>("TestClassProperty"); + PropertyTablePropertyView> boolArrayInvalid = + view.getPropertyView>("TestClassProperty"); REQUIRE( boolArrayInvalid.status() == PropertyTablePropertyViewStatus::ErrorTypeMismatch); - PropertyTablePropertyView> uvec2ArrayInvalid = - view.getPropertyView>( + PropertyTablePropertyView> uvec2ArrayInvalid = + view.getPropertyView>( "TestClassProperty"); REQUIRE( uvec2ArrayInvalid.status() == @@ -1022,8 +1021,8 @@ TEST_CASE("Test StructuralMetadata fixed-length scalar array") { } SECTION("Wrong component type") { - PropertyTablePropertyView> int32ArrayInvalid = - view.getPropertyView>("TestClassProperty"); + PropertyTablePropertyView> int32ArrayInvalid = + view.getPropertyView>("TestClassProperty"); REQUIRE( int32ArrayInvalid.status() == PropertyTablePropertyViewStatus::ErrorComponentTypeMismatch); @@ -1039,8 +1038,8 @@ TEST_CASE("Test StructuralMetadata fixed-length scalar array") { SECTION("Buffer size is not a multiple of type size") { model.bufferViews[valueBufferViewIndex].byteLength = 13; - PropertyTablePropertyView> arrayProperty = - view.getPropertyView>("TestClassProperty"); + PropertyTablePropertyView> arrayProperty = + view.getPropertyView>("TestClassProperty"); REQUIRE( arrayProperty.status() == PropertyTablePropertyViewStatus:: @@ -1049,8 +1048,8 @@ TEST_CASE("Test StructuralMetadata fixed-length scalar array") { SECTION("Negative component count") { testClassProperty.count = -1; - PropertyTablePropertyView> arrayProperty = - view.getPropertyView>("TestClassProperty"); + PropertyTablePropertyView> arrayProperty = + view.getPropertyView>("TestClassProperty"); REQUIRE( arrayProperty.status() == PropertyTablePropertyViewStatus:: ErrorArrayCountAndOffsetBufferDontExist); @@ -1058,8 +1057,8 @@ TEST_CASE("Test StructuralMetadata fixed-length scalar array") { SECTION("Value buffer doesn't fit into property table count") { testClassProperty.count = 55; - PropertyTablePropertyView> arrayProperty = - view.getPropertyView>("TestClassProperty"); + PropertyTablePropertyView> arrayProperty = + view.getPropertyView>("TestClassProperty"); REQUIRE( arrayProperty.status() == PropertyTablePropertyViewStatus:: @@ -1067,7 +1066,7 @@ TEST_CASE("Test StructuralMetadata fixed-length scalar array") { } } -TEST_CASE("Test Structural Metadata variable-length scalar array") { +TEST_CASE("Test variable-length scalar array") { Model model; std::vector> expected{ @@ -1169,11 +1168,11 @@ TEST_CASE("Test Structural Metadata variable-length scalar array") { REQUIRE(!classProperty->count); SECTION("Access the correct type") { - PropertyTablePropertyView> property = - view.getPropertyView>("TestClassProperty"); + PropertyTablePropertyView> property = + view.getPropertyView>("TestClassProperty"); REQUIRE(property.status() == PropertyTablePropertyViewStatus::Valid); for (size_t i = 0; i < expected.size(); ++i) { - MetadataArrayView valueMember = + PropertyArrayView valueMember = property.get(static_cast(i)); REQUIRE(valueMember.size() == static_cast(expected[i].size())); for (size_t j = 0; j < expected[i].size(); ++j) { @@ -1185,8 +1184,8 @@ TEST_CASE("Test Structural Metadata variable-length scalar array") { propertyTableProperty.arrayOffsetType = ExtensionExtStructuralMetadataPropertyTableProperty::ArrayOffsetType:: UINT8; - PropertyTablePropertyView> arrayProperty = - view.getPropertyView>("TestClassProperty"); + PropertyTablePropertyView> arrayProperty = + view.getPropertyView>("TestClassProperty"); REQUIRE( arrayProperty.status() == PropertyTablePropertyViewStatus:: @@ -1196,7 +1195,7 @@ TEST_CASE("Test Structural Metadata variable-length scalar array") { ExtensionExtStructuralMetadataPropertyTableProperty::ArrayOffsetType:: UINT16; arrayProperty = - view.getPropertyView>("TestClassProperty"); + view.getPropertyView>("TestClassProperty"); REQUIRE( arrayProperty.status() == PropertyTablePropertyViewStatus:: @@ -1204,7 +1203,7 @@ TEST_CASE("Test Structural Metadata variable-length scalar array") { propertyTableProperty.arrayOffsetType = "NONSENSE"; arrayProperty = - view.getPropertyView>("TestClassProperty"); + view.getPropertyView>("TestClassProperty"); REQUIRE( arrayProperty.status() == PropertyTablePropertyViewStatus::ErrorInvalidArrayOffsetType); @@ -1214,7 +1213,7 @@ TEST_CASE("Test Structural Metadata variable-length scalar array") { ExtensionExtStructuralMetadataPropertyTableProperty::StringOffsetType:: UINT64; arrayProperty = - view.getPropertyView>("TestClassProperty"); + view.getPropertyView>("TestClassProperty"); REQUIRE( arrayProperty.status() == PropertyTablePropertyViewStatus::ErrorInvalidArrayOffsetType); @@ -1227,8 +1226,8 @@ TEST_CASE("Test Structural Metadata variable-length scalar array") { uint64_t* offset = reinterpret_cast( model.buffers[offsetBufferIndex].cesium.data.data()); offset[propertyTable.count] = 0; - PropertyTablePropertyView> arrayProperty = - view.getPropertyView>("TestClassProperty"); + PropertyTablePropertyView> arrayProperty = + view.getPropertyView>("TestClassProperty"); REQUIRE( arrayProperty.status() == PropertyTablePropertyViewStatus::ErrorArrayOffsetsNotSorted); @@ -1239,8 +1238,8 @@ TEST_CASE("Test Structural Metadata variable-length scalar array") { model.buffers[offsetBufferIndex].cesium.data.data()); offset[propertyTable.count] = static_cast(model.buffers[valueBufferIndex].byteLength + 4); - PropertyTablePropertyView> arrayProperty = - view.getPropertyView>("TestClassProperty"); + PropertyTablePropertyView> arrayProperty = + view.getPropertyView>("TestClassProperty"); REQUIRE( arrayProperty.status() == PropertyTablePropertyViewStatus::ErrorArrayOffsetOutOfBounds); @@ -1248,15 +1247,15 @@ TEST_CASE("Test Structural Metadata variable-length scalar array") { SECTION("Count and offset buffer are both present") { testClassProperty.count = 3; - PropertyTablePropertyView> property = - view.getPropertyView>("TestClassProperty"); + PropertyTablePropertyView> property = + view.getPropertyView>("TestClassProperty"); REQUIRE( property.status() == PropertyTablePropertyViewStatus::ErrorArrayCountAndOffsetBufferCoexist); } } -TEST_CASE("Test StructuralMetadata fixed-length vecN array") { +TEST_CASE("Test fixed-length vecN array") { Model model; std::vector values = { @@ -1328,13 +1327,13 @@ TEST_CASE("Test StructuralMetadata fixed-length vecN array") { REQUIRE(classProperty->count == 2); SECTION("Access the right type") { - PropertyTablePropertyView> arrayProperty = - view.getPropertyView>( + PropertyTablePropertyView> arrayProperty = + view.getPropertyView>( "TestClassProperty"); REQUIRE(arrayProperty.status() == PropertyTablePropertyViewStatus::Valid); for (int64_t i = 0; i < arrayProperty.size(); ++i) { - MetadataArrayView member = arrayProperty.get(i); + PropertyArrayView member = arrayProperty.get(i); for (int64_t j = 0; j < member.size(); ++j) { REQUIRE(member[j] == values[static_cast(i * 2 + j)]); } @@ -1342,14 +1341,14 @@ TEST_CASE("Test StructuralMetadata fixed-length vecN array") { } SECTION("Wrong type") { - PropertyTablePropertyView> int32ArrayInvalid = - view.getPropertyView>("TestClassProperty"); + PropertyTablePropertyView> int32ArrayInvalid = + view.getPropertyView>("TestClassProperty"); REQUIRE( int32ArrayInvalid.status() == PropertyTablePropertyViewStatus::ErrorTypeMismatch); - PropertyTablePropertyView> ivec2ArrayInvalid = - view.getPropertyView>( + PropertyTablePropertyView> ivec2ArrayInvalid = + view.getPropertyView>( "TestClassProperty"); REQUIRE( ivec2ArrayInvalid.status() == @@ -1357,8 +1356,8 @@ TEST_CASE("Test StructuralMetadata fixed-length vecN array") { } SECTION("Wrong component type") { - PropertyTablePropertyView> uvec3ArrayInvalid = - view.getPropertyView>( + PropertyTablePropertyView> uvec3ArrayInvalid = + view.getPropertyView>( "TestClassProperty"); REQUIRE( uvec3ArrayInvalid.status() == @@ -1375,8 +1374,8 @@ TEST_CASE("Test StructuralMetadata fixed-length vecN array") { SECTION("Buffer size is not a multiple of type size") { model.bufferViews[valueBufferViewIndex].byteLength = 13; - PropertyTablePropertyView> arrayProperty = - view.getPropertyView>( + PropertyTablePropertyView> arrayProperty = + view.getPropertyView>( "TestClassProperty"); REQUIRE( arrayProperty.status() == @@ -1386,8 +1385,8 @@ TEST_CASE("Test StructuralMetadata fixed-length vecN array") { SECTION("Negative component count") { testClassProperty.count = -1; - PropertyTablePropertyView> arrayProperty = - view.getPropertyView>( + PropertyTablePropertyView> arrayProperty = + view.getPropertyView>( "TestClassProperty"); REQUIRE( arrayProperty.status() == PropertyTablePropertyViewStatus:: @@ -1396,8 +1395,8 @@ TEST_CASE("Test StructuralMetadata fixed-length vecN array") { SECTION("Value buffer doesn't fit into property table count") { testClassProperty.count = 55; - PropertyTablePropertyView> arrayProperty = - view.getPropertyView>( + PropertyTablePropertyView> arrayProperty = + view.getPropertyView>( "TestClassProperty"); REQUIRE( arrayProperty.status() == @@ -1406,7 +1405,7 @@ TEST_CASE("Test StructuralMetadata fixed-length vecN array") { } } -TEST_CASE("Test Structural Metadata variable-length vecN array") { +TEST_CASE("Test variable-length vecN array") { Model model; // clang-format off @@ -1510,12 +1509,12 @@ TEST_CASE("Test Structural Metadata variable-length vecN array") { REQUIRE(!classProperty->count); SECTION("Access the correct type") { - PropertyTablePropertyView> property = - view.getPropertyView>( + PropertyTablePropertyView> property = + view.getPropertyView>( "TestClassProperty"); REQUIRE(property.status() == PropertyTablePropertyViewStatus::Valid); for (size_t i = 0; i < expected.size(); ++i) { - MetadataArrayView valueMember = + PropertyArrayView valueMember = property.get(static_cast(i)); REQUIRE(valueMember.size() == static_cast(expected[i].size())); for (size_t j = 0; j < expected[i].size(); ++j) { @@ -1528,8 +1527,8 @@ TEST_CASE("Test Structural Metadata variable-length vecN array") { propertyTableProperty.arrayOffsetType = ExtensionExtStructuralMetadataPropertyTableProperty::ArrayOffsetType:: UINT8; - PropertyTablePropertyView> arrayProperty = - view.getPropertyView>( + PropertyTablePropertyView> arrayProperty = + view.getPropertyView>( "TestClassProperty"); REQUIRE( arrayProperty.status() == @@ -1539,7 +1538,7 @@ TEST_CASE("Test Structural Metadata variable-length vecN array") { propertyTableProperty.arrayOffsetType = ExtensionExtStructuralMetadataPropertyTableProperty::ArrayOffsetType:: UINT16; - arrayProperty = view.getPropertyView>( + arrayProperty = view.getPropertyView>( "TestClassProperty"); REQUIRE( arrayProperty.status() == @@ -1547,7 +1546,7 @@ TEST_CASE("Test Structural Metadata variable-length vecN array") { ErrorBufferViewSizeDoesNotMatchPropertyTableCount); propertyTableProperty.arrayOffsetType = "NONSENSE"; - arrayProperty = view.getPropertyView>( + arrayProperty = view.getPropertyView>( "TestClassProperty"); REQUIRE( arrayProperty.status() == @@ -1557,7 +1556,7 @@ TEST_CASE("Test Structural Metadata variable-length vecN array") { propertyTableProperty.stringOffsetType = ExtensionExtStructuralMetadataPropertyTableProperty::StringOffsetType:: UINT64; - arrayProperty = view.getPropertyView>( + arrayProperty = view.getPropertyView>( "TestClassProperty"); REQUIRE( arrayProperty.status() == @@ -1571,8 +1570,8 @@ TEST_CASE("Test Structural Metadata variable-length vecN array") { uint64_t* offset = reinterpret_cast( model.buffers[offsetBufferIndex].cesium.data.data()); offset[propertyTable.count] = 0; - PropertyTablePropertyView> arrayProperty = - view.getPropertyView>( + PropertyTablePropertyView> arrayProperty = + view.getPropertyView>( "TestClassProperty"); REQUIRE( arrayProperty.status() == @@ -1584,8 +1583,8 @@ TEST_CASE("Test Structural Metadata variable-length vecN array") { model.buffers[offsetBufferIndex].cesium.data.data()); offset[propertyTable.count] = static_cast(model.buffers[valueBufferIndex].byteLength + 4); - PropertyTablePropertyView> arrayProperty = - view.getPropertyView>( + PropertyTablePropertyView> arrayProperty = + view.getPropertyView>( "TestClassProperty"); REQUIRE( arrayProperty.status() == @@ -1594,8 +1593,8 @@ TEST_CASE("Test Structural Metadata variable-length vecN array") { SECTION("Count and offset buffer are both present") { testClassProperty.count = 3; - PropertyTablePropertyView> property = - view.getPropertyView>( + PropertyTablePropertyView> property = + view.getPropertyView>( "TestClassProperty"); REQUIRE( property.status() == @@ -1603,7 +1602,7 @@ TEST_CASE("Test Structural Metadata variable-length vecN array") { } } -TEST_CASE("Test StructuralMetadata fixed-length matN array") { +TEST_CASE("Test fixed-length matN array") { Model model; // clang-format off @@ -1689,13 +1688,13 @@ TEST_CASE("Test StructuralMetadata fixed-length matN array") { REQUIRE(classProperty->count == 2); SECTION("Access the right type") { - PropertyTablePropertyView> arrayProperty = - view.getPropertyView>( + PropertyTablePropertyView> arrayProperty = + view.getPropertyView>( "TestClassProperty"); REQUIRE(arrayProperty.status() == PropertyTablePropertyViewStatus::Valid); for (int64_t i = 0; i < arrayProperty.size(); ++i) { - MetadataArrayView member = arrayProperty.get(i); + PropertyArrayView member = arrayProperty.get(i); for (int64_t j = 0; j < member.size(); ++j) { REQUIRE(member[j] == values[static_cast(i * 2 + j)]); } @@ -1703,14 +1702,14 @@ TEST_CASE("Test StructuralMetadata fixed-length matN array") { } SECTION("Wrong type") { - PropertyTablePropertyView> int32ArrayInvalid = - view.getPropertyView>("TestClassProperty"); + PropertyTablePropertyView> int32ArrayInvalid = + view.getPropertyView>("TestClassProperty"); REQUIRE( int32ArrayInvalid.status() == PropertyTablePropertyViewStatus::ErrorTypeMismatch); - PropertyTablePropertyView> ivec2ArrayInvalid = - view.getPropertyView>( + PropertyTablePropertyView> ivec2ArrayInvalid = + view.getPropertyView>( "TestClassProperty"); REQUIRE( ivec2ArrayInvalid.status() == @@ -1718,9 +1717,9 @@ TEST_CASE("Test StructuralMetadata fixed-length matN array") { } SECTION("Wrong component type") { - PropertyTablePropertyView> + PropertyTablePropertyView> u32mat2x2ArrayInvalid = - view.getPropertyView>( + view.getPropertyView>( "TestClassProperty"); REQUIRE( u32mat2x2ArrayInvalid.status() == @@ -1737,8 +1736,8 @@ TEST_CASE("Test StructuralMetadata fixed-length matN array") { SECTION("Buffer size is not a multiple of type size") { model.bufferViews[valueBufferViewIndex].byteLength = 13; - PropertyTablePropertyView> arrayProperty = - view.getPropertyView>( + PropertyTablePropertyView> arrayProperty = + view.getPropertyView>( "TestClassProperty"); REQUIRE( arrayProperty.status() == @@ -1748,8 +1747,8 @@ TEST_CASE("Test StructuralMetadata fixed-length matN array") { SECTION("Negative component count") { testClassProperty.count = -1; - PropertyTablePropertyView> arrayProperty = - view.getPropertyView>( + PropertyTablePropertyView> arrayProperty = + view.getPropertyView>( "TestClassProperty"); REQUIRE( arrayProperty.status() == PropertyTablePropertyViewStatus:: @@ -1758,8 +1757,8 @@ TEST_CASE("Test StructuralMetadata fixed-length matN array") { SECTION("Value buffer doesn't fit into property table count") { testClassProperty.count = 55; - PropertyTablePropertyView> arrayProperty = - view.getPropertyView>( + PropertyTablePropertyView> arrayProperty = + view.getPropertyView>( "TestClassProperty"); REQUIRE( arrayProperty.status() == @@ -1768,7 +1767,7 @@ TEST_CASE("Test StructuralMetadata fixed-length matN array") { } } -TEST_CASE("Test Structural Metadata variable-length matN array") { +TEST_CASE("Test variable-length matN array") { Model model; // clang-format off @@ -1892,12 +1891,12 @@ TEST_CASE("Test Structural Metadata variable-length matN array") { REQUIRE(!classProperty->count); SECTION("Access the correct type") { - PropertyTablePropertyView> property = - view.getPropertyView>( + PropertyTablePropertyView> property = + view.getPropertyView>( "TestClassProperty"); REQUIRE(property.status() == PropertyTablePropertyViewStatus::Valid); for (size_t i = 0; i < expected.size(); ++i) { - MetadataArrayView valueMember = + PropertyArrayView valueMember = property.get(static_cast(i)); REQUIRE(valueMember.size() == static_cast(expected[i].size())); for (size_t j = 0; j < expected[i].size(); ++j) { @@ -1910,8 +1909,8 @@ TEST_CASE("Test Structural Metadata variable-length matN array") { propertyTableProperty.arrayOffsetType = ExtensionExtStructuralMetadataPropertyTableProperty::ArrayOffsetType:: UINT8; - PropertyTablePropertyView> arrayProperty = - view.getPropertyView>( + PropertyTablePropertyView> arrayProperty = + view.getPropertyView>( "TestClassProperty"); REQUIRE( arrayProperty.status() == @@ -1921,7 +1920,7 @@ TEST_CASE("Test Structural Metadata variable-length matN array") { propertyTableProperty.arrayOffsetType = ExtensionExtStructuralMetadataPropertyTableProperty::ArrayOffsetType:: UINT16; - arrayProperty = view.getPropertyView>( + arrayProperty = view.getPropertyView>( "TestClassProperty"); REQUIRE( arrayProperty.status() == @@ -1929,7 +1928,7 @@ TEST_CASE("Test Structural Metadata variable-length matN array") { ErrorBufferViewSizeDoesNotMatchPropertyTableCount); propertyTableProperty.arrayOffsetType = "NONSENSE"; - arrayProperty = view.getPropertyView>( + arrayProperty = view.getPropertyView>( "TestClassProperty"); REQUIRE( arrayProperty.status() == @@ -1939,7 +1938,7 @@ TEST_CASE("Test Structural Metadata variable-length matN array") { propertyTableProperty.stringOffsetType = ExtensionExtStructuralMetadataPropertyTableProperty::StringOffsetType:: UINT64; - arrayProperty = view.getPropertyView>( + arrayProperty = view.getPropertyView>( "TestClassProperty"); REQUIRE( arrayProperty.status() == @@ -1953,8 +1952,8 @@ TEST_CASE("Test Structural Metadata variable-length matN array") { uint64_t* offset = reinterpret_cast( model.buffers[offsetBufferIndex].cesium.data.data()); offset[propertyTable.count] = 0; - PropertyTablePropertyView> arrayProperty = - view.getPropertyView>( + PropertyTablePropertyView> arrayProperty = + view.getPropertyView>( "TestClassProperty"); REQUIRE( arrayProperty.status() == @@ -1966,8 +1965,8 @@ TEST_CASE("Test Structural Metadata variable-length matN array") { model.buffers[offsetBufferIndex].cesium.data.data()); offset[propertyTable.count] = static_cast(model.buffers[valueBufferIndex].byteLength + 4); - PropertyTablePropertyView> arrayProperty = - view.getPropertyView>( + PropertyTablePropertyView> arrayProperty = + view.getPropertyView>( "TestClassProperty"); REQUIRE( arrayProperty.status() == @@ -1976,8 +1975,8 @@ TEST_CASE("Test Structural Metadata variable-length matN array") { SECTION("Count and offset buffer are both present") { testClassProperty.count = 3; - PropertyTablePropertyView> property = - view.getPropertyView>( + PropertyTablePropertyView> property = + view.getPropertyView>( "TestClassProperty"); REQUIRE( property.status() == @@ -1985,7 +1984,7 @@ TEST_CASE("Test Structural Metadata variable-length matN array") { } } -TEST_CASE("Test StructuralMetadata fixed-length boolean array") { +TEST_CASE("Test fixed-length boolean array") { Model model; std::vector expected = { @@ -2066,14 +2065,14 @@ TEST_CASE("Test StructuralMetadata fixed-length boolean array") { REQUIRE(classProperty->count == 3); SECTION("Access correct type") { - PropertyTablePropertyView> boolArrayProperty = - view.getPropertyView>("TestClassProperty"); + PropertyTablePropertyView> boolArrayProperty = + view.getPropertyView>("TestClassProperty"); REQUIRE( boolArrayProperty.status() == PropertyTablePropertyViewStatus::Valid); REQUIRE(boolArrayProperty.size() == propertyTable.count); REQUIRE(boolArrayProperty.size() > 0); for (int64_t i = 0; i < boolArrayProperty.size(); ++i) { - MetadataArrayView valueMember = boolArrayProperty.get(i); + PropertyArrayView valueMember = boolArrayProperty.get(i); for (int64_t j = 0; j < valueMember.size(); ++j) { REQUIRE(valueMember[j] == expected[static_cast(i * 3 + j)]); } @@ -2081,8 +2080,8 @@ TEST_CASE("Test StructuralMetadata fixed-length boolean array") { } SECTION("Wrong type") { - PropertyTablePropertyView> uint8ArrayInvalid = - view.getPropertyView>("TestClassProperty"); + PropertyTablePropertyView> uint8ArrayInvalid = + view.getPropertyView>("TestClassProperty"); REQUIRE( uint8ArrayInvalid.status() == PropertyTablePropertyViewStatus::ErrorTypeMismatch); @@ -2098,8 +2097,8 @@ TEST_CASE("Test StructuralMetadata fixed-length boolean array") { SECTION("Value buffer doesn't have enough required bytes") { testClassProperty.count = 11; - PropertyTablePropertyView> boolArrayProperty = - view.getPropertyView>("TestClassProperty"); + PropertyTablePropertyView> boolArrayProperty = + view.getPropertyView>("TestClassProperty"); REQUIRE( boolArrayProperty.status() == PropertyTablePropertyViewStatus:: @@ -2108,8 +2107,8 @@ TEST_CASE("Test StructuralMetadata fixed-length boolean array") { SECTION("Count is negative") { testClassProperty.count = -1; - PropertyTablePropertyView> boolArrayProperty = - view.getPropertyView>("TestClassProperty"); + PropertyTablePropertyView> boolArrayProperty = + view.getPropertyView>("TestClassProperty"); REQUIRE( boolArrayProperty.status() == PropertyTablePropertyViewStatus:: @@ -2117,7 +2116,7 @@ TEST_CASE("Test StructuralMetadata fixed-length boolean array") { } } -TEST_CASE("Test StructuralMetadata variable-length boolean array") { +TEST_CASE("Test variable-length boolean array") { Model model; std::vector> expected{ @@ -2221,12 +2220,12 @@ TEST_CASE("Test StructuralMetadata variable-length boolean array") { REQUIRE(!classProperty->count); SECTION("Access correct type") { - PropertyTablePropertyView> boolArrayProperty = - view.getPropertyView>("TestClassProperty"); + PropertyTablePropertyView> boolArrayProperty = + view.getPropertyView>("TestClassProperty"); REQUIRE( boolArrayProperty.status() == PropertyTablePropertyViewStatus::Valid); for (size_t i = 0; i < expected.size(); ++i) { - MetadataArrayView arrayMember = + PropertyArrayView arrayMember = boolArrayProperty.get(static_cast(i)); REQUIRE(arrayMember.size() == static_cast(expected[i].size())); for (size_t j = 0; j < expected[i].size(); ++j) { @@ -2239,8 +2238,8 @@ TEST_CASE("Test StructuralMetadata variable-length boolean array") { propertyTableProperty.arrayOffsetType = ExtensionExtStructuralMetadataPropertyTableProperty::ArrayOffsetType:: UINT8; - PropertyTablePropertyView> arrayProperty = - view.getPropertyView>("TestClassProperty"); + PropertyTablePropertyView> arrayProperty = + view.getPropertyView>("TestClassProperty"); REQUIRE( arrayProperty.status() == PropertyTablePropertyViewStatus:: @@ -2250,7 +2249,7 @@ TEST_CASE("Test StructuralMetadata variable-length boolean array") { ExtensionExtStructuralMetadataPropertyTableProperty::ArrayOffsetType:: UINT16; arrayProperty = - view.getPropertyView>("TestClassProperty"); + view.getPropertyView>("TestClassProperty"); REQUIRE( arrayProperty.status() == PropertyTablePropertyViewStatus:: @@ -2258,7 +2257,7 @@ TEST_CASE("Test StructuralMetadata variable-length boolean array") { propertyTableProperty.arrayOffsetType = "NONSENSE"; arrayProperty = - view.getPropertyView>("TestClassProperty"); + view.getPropertyView>("TestClassProperty"); REQUIRE( arrayProperty.status() == PropertyTablePropertyViewStatus::ErrorInvalidArrayOffsetType); @@ -2268,7 +2267,7 @@ TEST_CASE("Test StructuralMetadata variable-length boolean array") { ExtensionExtStructuralMetadataPropertyTableProperty::StringOffsetType:: UINT64; arrayProperty = - view.getPropertyView>("TestClassProperty"); + view.getPropertyView>("TestClassProperty"); REQUIRE( arrayProperty.status() == PropertyTablePropertyViewStatus::ErrorInvalidArrayOffsetType); @@ -2281,8 +2280,8 @@ TEST_CASE("Test StructuralMetadata variable-length boolean array") { uint64_t* offset = reinterpret_cast( model.buffers[offsetBufferIndex].cesium.data.data()); offset[propertyTable.count] = 0; - PropertyTablePropertyView> arrayProperty = - view.getPropertyView>("TestClassProperty"); + PropertyTablePropertyView> arrayProperty = + view.getPropertyView>("TestClassProperty"); REQUIRE( arrayProperty.status() == PropertyTablePropertyViewStatus::ErrorArrayOffsetsNotSorted); @@ -2293,8 +2292,8 @@ TEST_CASE("Test StructuralMetadata variable-length boolean array") { model.buffers[offsetBufferIndex].cesium.data.data()); offset[propertyTable.count] = static_cast( model.buffers[valueBufferIndex].byteLength * 8 + 20); - PropertyTablePropertyView> arrayProperty = - view.getPropertyView>("TestClassProperty"); + PropertyTablePropertyView> arrayProperty = + view.getPropertyView>("TestClassProperty"); REQUIRE( arrayProperty.status() == PropertyTablePropertyViewStatus::ErrorArrayOffsetOutOfBounds); @@ -2302,15 +2301,15 @@ TEST_CASE("Test StructuralMetadata variable-length boolean array") { SECTION("Count and offset buffer both present") { testClassProperty.count = 3; - PropertyTablePropertyView> boolArrayProperty = - view.getPropertyView>("TestClassProperty"); + PropertyTablePropertyView> boolArrayProperty = + view.getPropertyView>("TestClassProperty"); REQUIRE( boolArrayProperty.status() == PropertyTablePropertyViewStatus::ErrorArrayCountAndOffsetBufferCoexist); } } -TEST_CASE("Test StructuralMetadata fixed-length arrays of strings") { +TEST_CASE("Test fixed-length arrays of strings") { Model model; std::vector expected{ @@ -2406,24 +2405,24 @@ TEST_CASE("Test StructuralMetadata fixed-length arrays of strings") { REQUIRE(classProperty->count == 2); SECTION("Access correct type") { - PropertyTablePropertyView> + PropertyTablePropertyView> stringProperty = - view.getPropertyView>( + view.getPropertyView>( "TestClassProperty"); REQUIRE(stringProperty.status() == PropertyTablePropertyViewStatus::Valid); REQUIRE(stringProperty.size() == 3); - MetadataArrayView v0 = stringProperty.get(0); + PropertyArrayView v0 = stringProperty.get(0); REQUIRE(v0.size() == 2); REQUIRE(v0[0] == "What's up"); REQUIRE(v0[1] == "Breaking news!!! Aliens no longer attacks the US first"); - MetadataArrayView v1 = stringProperty.get(1); + PropertyArrayView v1 = stringProperty.get(1); REQUIRE(v1.size() == 2); REQUIRE(v1[0] == "But they still abduct my cows! Those milk thiefs! 👽 🐮"); REQUIRE(v1[1] == "I'm not crazy. My mother had me tested 🤪"); - MetadataArrayView v2 = stringProperty.get(2); + PropertyArrayView v2 = stringProperty.get(2); REQUIRE(v2.size() == 2); REQUIRE(v2[0] == "I love you, meat bags! ❤️"); REQUIRE(v2[1] == "Book in the freezer"); @@ -2439,9 +2438,9 @@ TEST_CASE("Test StructuralMetadata fixed-length arrays of strings") { SECTION("Count is negative") { testClassProperty.count = -1; - PropertyTablePropertyView> + PropertyTablePropertyView> stringProperty = - view.getPropertyView>( + view.getPropertyView>( "TestClassProperty"); REQUIRE( stringProperty.status() == PropertyTablePropertyViewStatus:: @@ -2450,9 +2449,9 @@ TEST_CASE("Test StructuralMetadata fixed-length arrays of strings") { SECTION("Offset type is unknown") { propertyTableProperty.stringOffsetType = "NONSENSE"; - PropertyTablePropertyView> + PropertyTablePropertyView> stringProperty = - view.getPropertyView>( + view.getPropertyView>( "TestClassProperty"); REQUIRE( stringProperty.status() == @@ -2462,7 +2461,7 @@ TEST_CASE("Test StructuralMetadata fixed-length arrays of strings") { propertyTableProperty.arrayOffsetType = ExtensionExtStructuralMetadataPropertyTableProperty::ArrayOffsetType:: UINT32; - stringProperty = view.getPropertyView>( + stringProperty = view.getPropertyView>( "TestClassProperty"); REQUIRE( stringProperty.status() == @@ -2471,9 +2470,9 @@ TEST_CASE("Test StructuralMetadata fixed-length arrays of strings") { SECTION("String offsets don't exist") { propertyTableProperty.stringOffsets = -1; - PropertyTablePropertyView> + PropertyTablePropertyView> stringProperty = - view.getPropertyView>( + view.getPropertyView>( "TestClassProperty"); REQUIRE( stringProperty.status() == @@ -2481,7 +2480,7 @@ TEST_CASE("Test StructuralMetadata fixed-length arrays of strings") { } } -TEST_CASE("Test StructuralMetadata variable-length arrays of strings") { +TEST_CASE("Test variable-length arrays of strings") { Model model; std::vector> expected{ @@ -2616,13 +2615,13 @@ TEST_CASE("Test StructuralMetadata variable-length arrays of strings") { REQUIRE(!classProperty->count); SECTION("Access correct type") { - PropertyTablePropertyView> + PropertyTablePropertyView> stringProperty = - view.getPropertyView>( + view.getPropertyView>( "TestClassProperty"); REQUIRE(stringProperty.status() == PropertyTablePropertyViewStatus::Valid); for (size_t i = 0; i < expected.size(); ++i) { - MetadataArrayView stringArray = + PropertyArrayView stringArray = stringProperty.get(static_cast(i)); for (size_t j = 0; j < expected[i].size(); ++j) { REQUIRE(stringArray[static_cast(j)] == expected[i][j]); @@ -2634,9 +2633,9 @@ TEST_CASE("Test StructuralMetadata variable-length arrays of strings") { propertyTableProperty.arrayOffsetType = ExtensionExtStructuralMetadataPropertyTableProperty::ArrayOffsetType:: UINT8; - PropertyTablePropertyView> + PropertyTablePropertyView> arrayProperty = - view.getPropertyView>( + view.getPropertyView>( "TestClassProperty"); REQUIRE( arrayProperty.status() == @@ -2646,7 +2645,7 @@ TEST_CASE("Test StructuralMetadata variable-length arrays of strings") { propertyTableProperty.arrayOffsetType = ExtensionExtStructuralMetadataPropertyTableProperty::ArrayOffsetType:: UINT16; - arrayProperty = view.getPropertyView>( + arrayProperty = view.getPropertyView>( "TestClassProperty"); REQUIRE( arrayProperty.status() == @@ -2654,7 +2653,7 @@ TEST_CASE("Test StructuralMetadata variable-length arrays of strings") { ErrorBufferViewSizeDoesNotMatchPropertyTableCount); propertyTableProperty.arrayOffsetType = "NONSENSE"; - arrayProperty = view.getPropertyView>( + arrayProperty = view.getPropertyView>( "TestClassProperty"); REQUIRE( arrayProperty.status() == @@ -2668,9 +2667,9 @@ TEST_CASE("Test StructuralMetadata variable-length arrays of strings") { propertyTableProperty.stringOffsetType = ExtensionExtStructuralMetadataPropertyTableProperty::StringOffsetType:: UINT8; - PropertyTablePropertyView> + PropertyTablePropertyView> arrayProperty = - view.getPropertyView>( + view.getPropertyView>( "TestClassProperty"); REQUIRE( arrayProperty.status() == @@ -2680,7 +2679,7 @@ TEST_CASE("Test StructuralMetadata variable-length arrays of strings") { propertyTableProperty.stringOffsetType = ExtensionExtStructuralMetadataPropertyTableProperty::StringOffsetType:: UINT16; - arrayProperty = view.getPropertyView>( + arrayProperty = view.getPropertyView>( "TestClassProperty"); REQUIRE( arrayProperty.status() == @@ -2688,7 +2687,7 @@ TEST_CASE("Test StructuralMetadata variable-length arrays of strings") { ErrorBufferViewSizeDoesNotMatchPropertyTableCount); propertyTableProperty.stringOffsetType = "NONSENSE"; - arrayProperty = view.getPropertyView>( + arrayProperty = view.getPropertyView>( "TestClassProperty"); REQUIRE( arrayProperty.status() == @@ -2702,9 +2701,9 @@ TEST_CASE("Test StructuralMetadata variable-length arrays of strings") { uint32_t* offset = reinterpret_cast( model.buffers[arrayOffsetBuffer].cesium.data.data()); offset[0] = static_cast(1000); - PropertyTablePropertyView> + PropertyTablePropertyView> arrayProperty = - view.getPropertyView>( + view.getPropertyView>( "TestClassProperty"); REQUIRE( arrayProperty.status() == @@ -2716,9 +2715,9 @@ TEST_CASE("Test StructuralMetadata variable-length arrays of strings") { uint32_t* offset = reinterpret_cast( model.buffers[stringOffsetBuffer].cesium.data.data()); offset[0] = static_cast(1000); - PropertyTablePropertyView> + PropertyTablePropertyView> arrayProperty = - view.getPropertyView>( + view.getPropertyView>( "TestClassProperty"); REQUIRE( arrayProperty.status() == @@ -2731,9 +2730,9 @@ TEST_CASE("Test StructuralMetadata variable-length arrays of strings") { model.buffers[arrayOffsetBuffer].cesium.data.data()); uint32_t previousValue = offset[propertyTable.count]; offset[propertyTable.count] = static_cast(100000); - PropertyTablePropertyView> + PropertyTablePropertyView> arrayProperty = - view.getPropertyView>( + view.getPropertyView>( "TestClassProperty"); REQUIRE( arrayProperty.status() == @@ -2746,9 +2745,9 @@ TEST_CASE("Test StructuralMetadata variable-length arrays of strings") { model.buffers[stringOffsetBuffer].cesium.data.data()); uint32_t previousValue = offset[6]; offset[6] = static_cast(100000); - PropertyTablePropertyView> + PropertyTablePropertyView> arrayProperty = - view.getPropertyView>( + view.getPropertyView>( "TestClassProperty"); REQUIRE( arrayProperty.status() == @@ -2758,9 +2757,9 @@ TEST_CASE("Test StructuralMetadata variable-length arrays of strings") { SECTION("Count and offset buffer both present") { testClassProperty.count = 3; - PropertyTablePropertyView> + PropertyTablePropertyView> boolArrayProperty = - view.getPropertyView>( + view.getPropertyView>( "TestClassProperty"); REQUIRE( boolArrayProperty.status() == @@ -2768,7 +2767,7 @@ TEST_CASE("Test StructuralMetadata variable-length arrays of strings") { } } -TEST_CASE("Test StructuralMetadata callback on invalid property table view") { +TEST_CASE("Test callback on invalid property table view") { Model model; ExtensionModelExtStructuralMetadata& metadata = model.addExtension(); @@ -2808,7 +2807,7 @@ TEST_CASE("Test StructuralMetadata callback on invalid property table view") { REQUIRE(invokedCallbackCount == 1); } -TEST_CASE("Test StructuralMetadata callback for invalid property") { +TEST_CASE("Test callback for invalid property") { Model model; ExtensionModelExtStructuralMetadata& metadata = model.addExtension(); @@ -2857,7 +2856,7 @@ TEST_CASE("Test StructuralMetadata callback for invalid property") { REQUIRE(invokedCallbackCount == 2); } -TEST_CASE("Test StructuralMetadata callback for scalar property") { +TEST_CASE("Test callback for scalar property") { Model model; std::vector values = {12, 34, 30, 11, 34, 34, 11, 33, 122, 33}; @@ -2948,7 +2947,7 @@ TEST_CASE("Test StructuralMetadata callback for scalar property") { REQUIRE(invokedCallbackCount == 1); } -TEST_CASE("Test StructuralMetadata callback for vecN property") { +TEST_CASE("Test callback for vecN property") { Model model; std::vector values = { @@ -3044,7 +3043,7 @@ TEST_CASE("Test StructuralMetadata callback for vecN property") { REQUIRE(invokedCallbackCount == 1); } -TEST_CASE("Test StructuralMetadata callback for matN property") { +TEST_CASE("Test callback for matN property") { Model model; // clang-format off @@ -3150,7 +3149,7 @@ TEST_CASE("Test StructuralMetadata callback for matN property") { REQUIRE(invokedCallbackCount == 1); } -TEST_CASE("Test StructuralMetadata callback for boolean property") { +TEST_CASE("Test callback for boolean property") { Model model; int64_t instanceCount = 21; @@ -3253,7 +3252,7 @@ TEST_CASE("Test StructuralMetadata callback for boolean property") { REQUIRE(invokedCallbackCount == 1); } -TEST_CASE("Test StructuralMetadata callback for string property") { +TEST_CASE("Test callback for string property") { Model model; std::vector expected{"What's up", "Test_0", "Test_1", "", "Hi"}; @@ -3375,7 +3374,7 @@ TEST_CASE("Test StructuralMetadata callback for string property") { REQUIRE(invokedCallbackCount == 1); } -TEST_CASE("Test StructuralMetadata callback for scalar array") { +TEST_CASE("Test callback for scalar array") { Model model; std::vector values = @@ -3451,10 +3450,10 @@ TEST_CASE("Test StructuralMetadata callback for scalar array") { if constexpr (std::is_same_v< PropertyTablePropertyView< - MetadataArrayView>, + PropertyArrayView>, decltype(propertyValue)>) { for (int64_t i = 0; i < propertyValue.size(); ++i) { - MetadataArrayView member = propertyValue.get(i); + PropertyArrayView member = propertyValue.get(i); for (int64_t j = 0; j < member.size(); ++j) { REQUIRE(member[j] == values[static_cast(i * 3 + j)]); } @@ -3469,7 +3468,7 @@ TEST_CASE("Test StructuralMetadata callback for scalar array") { REQUIRE(invokedCallbackCount == 1); } -TEST_CASE("Test StructuralMetadata callback for vecN array") { +TEST_CASE("Test callback for vecN array") { Model model; std::vector values = { @@ -3551,10 +3550,10 @@ TEST_CASE("Test StructuralMetadata callback for vecN array") { if constexpr (std::is_same_v< PropertyTablePropertyView< - MetadataArrayView>, + PropertyArrayView>, decltype(propertyValue)>) { for (int64_t i = 0; i < propertyValue.size(); ++i) { - MetadataArrayView member = propertyValue.get(i); + PropertyArrayView member = propertyValue.get(i); for (int64_t j = 0; j < member.size(); ++j) { REQUIRE(member[j] == values[static_cast(i * 2 + j)]); } @@ -3569,7 +3568,7 @@ TEST_CASE("Test StructuralMetadata callback for vecN array") { REQUIRE(invokedCallbackCount == 1); } -TEST_CASE("Test StructuralMetadata callback for matN array") { +TEST_CASE("Test callback for matN array") { Model model; // clang-format off @@ -3665,10 +3664,10 @@ TEST_CASE("Test StructuralMetadata callback for matN array") { if constexpr (std::is_same_v< PropertyTablePropertyView< - MetadataArrayView>, + PropertyArrayView>, decltype(propertyValue)>) { for (int64_t i = 0; i < propertyValue.size(); ++i) { - MetadataArrayView member = propertyValue.get(i); + PropertyArrayView member = propertyValue.get(i); for (int64_t j = 0; j < member.size(); ++j) { REQUIRE(member[j] == values[static_cast(i * 2 + j)]); } @@ -3683,7 +3682,7 @@ TEST_CASE("Test StructuralMetadata callback for matN array") { REQUIRE(invokedCallbackCount == 1); } -TEST_CASE("Test StructuralMetadata callback for boolean array") { +TEST_CASE("Test callback for boolean array") { Model model; std::vector expected = { @@ -3775,10 +3774,10 @@ TEST_CASE("Test StructuralMetadata callback for boolean array") { REQUIRE(propertyValue.size() > 0); if constexpr (std::is_same_v< - PropertyTablePropertyView>, + PropertyTablePropertyView>, decltype(propertyValue)>) { for (int64_t i = 0; i < propertyValue.size(); ++i) { - MetadataArrayView member = propertyValue.get(i); + PropertyArrayView member = propertyValue.get(i); for (int64_t j = 0; j < member.size(); ++j) { REQUIRE(member[j] == expected[static_cast(i * 3 + j)]); } @@ -3793,7 +3792,7 @@ TEST_CASE("Test StructuralMetadata callback for boolean array") { REQUIRE(invokedCallbackCount == 1); } -TEST_CASE("Test StructuralMetadata callback for array of strings") { +TEST_CASE("Test callback for array of strings") { Model model; std::vector expected{ @@ -3901,22 +3900,22 @@ TEST_CASE("Test StructuralMetadata callback for array of strings") { if constexpr (std::is_same_v< PropertyTablePropertyView< - MetadataArrayView>, + PropertyArrayView>, decltype(propertyValue)>) { - MetadataArrayView v0 = propertyValue.get(0); + PropertyArrayView v0 = propertyValue.get(0); REQUIRE(v0.size() == 2); REQUIRE(v0[0] == "What's up"); REQUIRE( v0[1] == "Breaking news!!! Aliens no longer attacks the US first"); - MetadataArrayView v1 = propertyValue.get(1); + PropertyArrayView v1 = propertyValue.get(1); REQUIRE(v1.size() == 2); REQUIRE( v1[0] == "But they still abduct my cows! Those milk thiefs! 👽 🐮"); REQUIRE(v1[1] == "I'm not crazy. My mother had me tested 🤪"); - MetadataArrayView v2 = propertyValue.get(2); + PropertyArrayView v2 = propertyValue.get(2); REQUIRE(v2.size() == 2); REQUIRE(v2[0] == "I love you, meat bags! ❤️"); REQUIRE(v2[1] == "Book in the freezer"); diff --git a/CesiumGltf/test/TestStructuralMetadataPropertyTexturePropertyView.cpp b/CesiumGltf/test/TestPropertyTexturePropertyView.cpp similarity index 98% rename from CesiumGltf/test/TestStructuralMetadataPropertyTexturePropertyView.cpp rename to CesiumGltf/test/TestPropertyTexturePropertyView.cpp index e697ceafc..e6d96520e 100644 --- a/CesiumGltf/test/TestStructuralMetadataPropertyTexturePropertyView.cpp +++ b/CesiumGltf/test/TestPropertyTexturePropertyView.cpp @@ -1,4 +1,4 @@ -#include "CesiumGltf/StructuralMetadataPropertyTexturePropertyView.h" +#include "CesiumGltf/PropertyTexturePropertyView.h" #include #include @@ -10,7 +10,6 @@ #include using namespace CesiumGltf; -using namespace CesiumGltf::StructuralMetadata; TEST_CASE( "Test PropertyTexturePropertyView on property with invalid texture index") { diff --git a/CesiumGltf/test/TestStructuralMetadataPropertyTextureView.cpp b/CesiumGltf/test/TestPropertyTextureView.cpp similarity index 98% rename from CesiumGltf/test/TestStructuralMetadataPropertyTextureView.cpp rename to CesiumGltf/test/TestPropertyTextureView.cpp index 01cfed051..6ca05cad2 100644 --- a/CesiumGltf/test/TestStructuralMetadataPropertyTextureView.cpp +++ b/CesiumGltf/test/TestPropertyTextureView.cpp @@ -1,4 +1,4 @@ -#include "CesiumGltf/StructuralMetadataPropertyTextureView.h" +#include "CesiumGltf/PropertyTextureView.h" #include #include @@ -10,7 +10,6 @@ #include using namespace CesiumGltf; -using namespace CesiumGltf::StructuralMetadata; TEST_CASE("Test PropertyTextureView on model without EXT_structural_metadata " "extension") { diff --git a/CesiumGltf/test/TestPropertyType.cpp b/CesiumGltf/test/TestPropertyType.cpp index 4629a7736..9f345f6aa 100644 --- a/CesiumGltf/test/TestPropertyType.cpp +++ b/CesiumGltf/test/TestPropertyType.cpp @@ -1,5 +1,5 @@ -#include "CesiumGltf/ClassProperty.h" -#include "CesiumGltf/FeatureTableProperty.h" +#include "CesiumGltf/ExtensionExtStructuralMetadataClassProperty.h" +#include "CesiumGltf/ExtensionExtStructuralMetadataPropertyTableProperty.h" #include "CesiumGltf/PropertyType.h" #include @@ -9,132 +9,244 @@ using namespace CesiumGltf; TEST_CASE("Test PropertyType utilities function") { SECTION("Convert string to PropertyType") { REQUIRE( - convertStringToPropertyType(ClassProperty::Type::UINT8) == - PropertyType::Uint8); + convertStringToPropertyType( + ExtensionExtStructuralMetadataClassProperty::Type::SCALAR) == + PropertyType::Scalar); REQUIRE( - convertStringToPropertyType(ClassProperty::Type::INT8) == - PropertyType::Int8); + convertStringToPropertyType( + ExtensionExtStructuralMetadataClassProperty::Type::VEC2) == + PropertyType::Vec2); REQUIRE( - convertStringToPropertyType(ClassProperty::Type::UINT16) == - PropertyType::Uint16); + convertStringToPropertyType( + ExtensionExtStructuralMetadataClassProperty::Type::VEC3) == + PropertyType::Vec3); REQUIRE( - convertStringToPropertyType(ClassProperty::Type::INT16) == - PropertyType::Int16); + convertStringToPropertyType( + ExtensionExtStructuralMetadataClassProperty::Type::VEC4) == + PropertyType::Vec4); REQUIRE( - convertStringToPropertyType(ClassProperty::Type::UINT32) == - PropertyType::Uint32); + convertStringToPropertyType( + ExtensionExtStructuralMetadataClassProperty::Type::MAT2) == + PropertyType::Mat2); REQUIRE( - convertStringToPropertyType(ClassProperty::Type::INT32) == - PropertyType::Int32); + convertStringToPropertyType( + ExtensionExtStructuralMetadataClassProperty::Type::MAT3) == + PropertyType::Mat3); REQUIRE( - convertStringToPropertyType(ClassProperty::Type::UINT64) == - PropertyType::Uint64); + convertStringToPropertyType( + ExtensionExtStructuralMetadataClassProperty::Type::MAT4) == + PropertyType::Mat4); REQUIRE( - convertStringToPropertyType(ClassProperty::Type::INT64) == - PropertyType::Int64); + convertStringToPropertyType( + ExtensionExtStructuralMetadataClassProperty::Type::BOOLEAN) == + PropertyType::Boolean); REQUIRE( - convertStringToPropertyType(ClassProperty::Type::FLOAT32) == - PropertyType::Float32); + convertStringToPropertyType( + ExtensionExtStructuralMetadataClassProperty::Type::STRING) == + PropertyType::String); REQUIRE( - convertStringToPropertyType(ClassProperty::Type::FLOAT64) == - PropertyType::Float64); + convertStringToPropertyType( + ExtensionExtStructuralMetadataClassProperty::Type::ENUM) == + PropertyType::Enum); + + REQUIRE(convertStringToPropertyType("invalid") == PropertyType::Invalid); + } + SECTION("Convert string to PropertyComponentType") { REQUIRE( - convertStringToPropertyType(ClassProperty::Type::STRING) == - PropertyType::String); + convertStringToPropertyComponentType( + ExtensionExtStructuralMetadataClassProperty::ComponentType:: + UINT8) == PropertyComponentType::Uint8); REQUIRE( - convertStringToPropertyType(ClassProperty::Type::BOOLEAN) == - PropertyType::Boolean); + convertStringToPropertyComponentType( + ExtensionExtStructuralMetadataClassProperty::ComponentType::INT8) == + PropertyComponentType::Int8); REQUIRE( - convertStringToPropertyType(ClassProperty::Type::ARRAY) == - PropertyType::Array); + convertStringToPropertyComponentType( + ExtensionExtStructuralMetadataClassProperty::ComponentType:: + UINT16) == PropertyComponentType::Uint16); + REQUIRE( + convertStringToPropertyComponentType( + ExtensionExtStructuralMetadataClassProperty::ComponentType:: + INT16) == PropertyComponentType::Int16); - REQUIRE(convertStringToPropertyType("NONESENSE") == PropertyType::None); - } + REQUIRE( + convertStringToPropertyComponentType( + ExtensionExtStructuralMetadataClassProperty::ComponentType:: + UINT32) == PropertyComponentType::Uint32); + + REQUIRE( + convertStringToPropertyComponentType( + ExtensionExtStructuralMetadataClassProperty::ComponentType:: + INT32) == PropertyComponentType::Int32); + REQUIRE( + convertStringToPropertyComponentType( + ExtensionExtStructuralMetadataClassProperty::ComponentType:: + UINT64) == PropertyComponentType::Uint64); - SECTION("PropertyType to String") { REQUIRE( - convertPropertyTypeToString(PropertyType::Uint8) == - ClassProperty::Type::UINT8); + convertStringToPropertyComponentType( + ExtensionExtStructuralMetadataClassProperty::ComponentType:: + INT64) == PropertyComponentType::Int64); REQUIRE( - convertPropertyTypeToString(PropertyType::Int8) == - ClassProperty::Type::INT8); + convertStringToPropertyComponentType( + ExtensionExtStructuralMetadataClassProperty::ComponentType:: + FLOAT32) == PropertyComponentType::Float32); + REQUIRE( + convertStringToPropertyComponentType( + ExtensionExtStructuralMetadataClassProperty::ComponentType:: + FLOAT64) == PropertyComponentType::Float64); + + REQUIRE( + convertStringToPropertyComponentType("invalid") == + PropertyComponentType::None); + } + SECTION("Convert PropertyType to string") { REQUIRE( - convertPropertyTypeToString(PropertyType::Uint16) == - ClassProperty::Type::UINT16); + convertPropertyTypeToString(PropertyType::Scalar) == + ExtensionExtStructuralMetadataClassProperty::Type::SCALAR); REQUIRE( - convertPropertyTypeToString(PropertyType::Int16) == - ClassProperty::Type::INT16); + convertPropertyTypeToString(PropertyType::Vec2) == + ExtensionExtStructuralMetadataClassProperty::Type::VEC2); REQUIRE( - convertPropertyTypeToString(PropertyType::Uint32) == - ClassProperty::Type::UINT32); + convertPropertyTypeToString(PropertyType::Vec3) == + ExtensionExtStructuralMetadataClassProperty::Type::VEC3); REQUIRE( - convertPropertyTypeToString(PropertyType::Int32) == - ClassProperty::Type::INT32); + convertPropertyTypeToString(PropertyType::Vec4) == + ExtensionExtStructuralMetadataClassProperty::Type::VEC4); REQUIRE( - convertPropertyTypeToString(PropertyType::Uint64) == - ClassProperty::Type::UINT64); + convertPropertyTypeToString(PropertyType::Mat2) == + ExtensionExtStructuralMetadataClassProperty::Type::MAT2); REQUIRE( - convertPropertyTypeToString(PropertyType::Int64) == - ClassProperty::Type::INT64); + convertPropertyTypeToString(PropertyType::Mat3) == + ExtensionExtStructuralMetadataClassProperty::Type::MAT3); REQUIRE( - convertPropertyTypeToString(PropertyType::Float32) == - ClassProperty::Type::FLOAT32); + convertPropertyTypeToString(PropertyType::Mat4) == + ExtensionExtStructuralMetadataClassProperty::Type::MAT4); REQUIRE( - convertPropertyTypeToString(PropertyType::Float64) == - ClassProperty::Type::FLOAT64); + convertPropertyTypeToString(PropertyType::Boolean) == + ExtensionExtStructuralMetadataClassProperty::Type::BOOLEAN); REQUIRE( convertPropertyTypeToString(PropertyType::String) == - ClassProperty::Type::STRING); + ExtensionExtStructuralMetadataClassProperty::Type::STRING); REQUIRE( - convertPropertyTypeToString(PropertyType::Boolean) == - ClassProperty::Type::BOOLEAN); + convertPropertyTypeToString(PropertyType::Enum) == + ExtensionExtStructuralMetadataClassProperty::Type::ENUM); + } + + SECTION("Convert PropertyComponentType to string") { + REQUIRE( + convertPropertyComponentTypeToString(PropertyComponentType::Uint8) == + ExtensionExtStructuralMetadataClassProperty::ComponentType::UINT8); + + REQUIRE( + convertPropertyComponentTypeToString(PropertyComponentType::Int8) == + ExtensionExtStructuralMetadataClassProperty::ComponentType::INT8); + + REQUIRE( + convertPropertyComponentTypeToString(PropertyComponentType::Uint16) == + ExtensionExtStructuralMetadataClassProperty::ComponentType::UINT16); + + REQUIRE( + convertPropertyComponentTypeToString(PropertyComponentType::Int16) == + ExtensionExtStructuralMetadataClassProperty::ComponentType::INT16); + + REQUIRE( + convertPropertyComponentTypeToString(PropertyComponentType::Uint32) == + ExtensionExtStructuralMetadataClassProperty::ComponentType::UINT32); + + REQUIRE( + convertPropertyComponentTypeToString(PropertyComponentType::Int32) == + ExtensionExtStructuralMetadataClassProperty::ComponentType::INT32); + + REQUIRE( + convertPropertyComponentTypeToString(PropertyComponentType::Uint64) == + ExtensionExtStructuralMetadataClassProperty::ComponentType::UINT64); + + REQUIRE( + convertPropertyComponentTypeToString(PropertyComponentType::Int64) == + ExtensionExtStructuralMetadataClassProperty::ComponentType::INT64); + + REQUIRE( + convertPropertyComponentTypeToString(PropertyComponentType::Float32) == + ExtensionExtStructuralMetadataClassProperty::ComponentType::FLOAT32); + + REQUIRE( + convertPropertyComponentTypeToString(PropertyComponentType::Float64) == + ExtensionExtStructuralMetadataClassProperty::ComponentType::FLOAT64); + } + + SECTION("Convert array offset type string to PropertyComponentType") { + REQUIRE( + convertArrayOffsetTypeStringToPropertyComponentType( + ExtensionExtStructuralMetadataPropertyTableProperty:: + ArrayOffsetType::UINT8) == PropertyComponentType::Uint8); + + REQUIRE( + convertArrayOffsetTypeStringToPropertyComponentType( + ExtensionExtStructuralMetadataPropertyTableProperty:: + ArrayOffsetType::UINT16) == PropertyComponentType::Uint16); + + REQUIRE( + convertArrayOffsetTypeStringToPropertyComponentType( + ExtensionExtStructuralMetadataPropertyTableProperty:: + ArrayOffsetType::UINT32) == PropertyComponentType::Uint32); + + REQUIRE( + convertArrayOffsetTypeStringToPropertyComponentType( + ExtensionExtStructuralMetadataPropertyTableProperty:: + ArrayOffsetType::UINT64) == PropertyComponentType::Uint64); REQUIRE( - convertPropertyTypeToString(PropertyType::Array) == - ClassProperty::Type::ARRAY); + convertArrayOffsetTypeStringToPropertyComponentType("invalid") == + PropertyComponentType::None); } - SECTION("OffsetString to PropertyType") { + SECTION("Convert string offset type string to PropertyComponentType") { REQUIRE( - convertOffsetStringToPropertyType( - FeatureTableProperty::OffsetType::UINT8) == PropertyType::Uint8); + convertStringOffsetTypeStringToPropertyComponentType( + ExtensionExtStructuralMetadataPropertyTableProperty:: + StringOffsetType::UINT8) == PropertyComponentType::Uint8); REQUIRE( - convertOffsetStringToPropertyType( - FeatureTableProperty::OffsetType::UINT16) == PropertyType::Uint16); + convertStringOffsetTypeStringToPropertyComponentType( + ExtensionExtStructuralMetadataPropertyTableProperty:: + StringOffsetType::UINT16) == PropertyComponentType::Uint16); REQUIRE( - convertOffsetStringToPropertyType( - FeatureTableProperty::OffsetType::UINT32) == PropertyType::Uint32); + convertStringOffsetTypeStringToPropertyComponentType( + ExtensionExtStructuralMetadataPropertyTableProperty:: + StringOffsetType::UINT32) == PropertyComponentType::Uint32); REQUIRE( - convertOffsetStringToPropertyType( - FeatureTableProperty::OffsetType::UINT64) == PropertyType::Uint64); + convertStringOffsetTypeStringToPropertyComponentType( + ExtensionExtStructuralMetadataPropertyTableProperty:: + StringOffsetType::UINT64) == PropertyComponentType::Uint64); REQUIRE( - convertOffsetStringToPropertyType("NONESENSE") == PropertyType::None); + convertStringOffsetTypeStringToPropertyComponentType("invalid") == + PropertyComponentType::None); } } diff --git a/CesiumGltf/test/TestPropertyTypeTrait.cpp b/CesiumGltf/test/TestPropertyTypeTrait.cpp deleted file mode 100644 index b85157eaa..000000000 --- a/CesiumGltf/test/TestPropertyTypeTrait.cpp +++ /dev/null @@ -1,82 +0,0 @@ -#include "CesiumGltf/PropertyTypeTraits.h" - -#include - -TEST_CASE("Test PropertyTypeTrait") { - SECTION("IsNumeric") { - REQUIRE(CesiumGltf::IsMetadataNumeric::value); - REQUIRE(CesiumGltf::IsMetadataNumeric::value); - - REQUIRE(CesiumGltf::IsMetadataNumeric::value); - REQUIRE(CesiumGltf::IsMetadataNumeric::value); - - REQUIRE(CesiumGltf::IsMetadataNumeric::value); - REQUIRE(CesiumGltf::IsMetadataNumeric::value); - - REQUIRE(CesiumGltf::IsMetadataNumeric::value); - REQUIRE(CesiumGltf::IsMetadataNumeric::value); - - REQUIRE(CesiumGltf::IsMetadataNumeric::value); - REQUIRE(CesiumGltf::IsMetadataNumeric::value); - - REQUIRE(CesiumGltf::IsMetadataNumeric::value == false); - REQUIRE(CesiumGltf::IsMetadataNumeric::value == false); - } - - SECTION("IsBoolean") { - REQUIRE(CesiumGltf::IsMetadataBoolean::value); - REQUIRE(CesiumGltf::IsMetadataBoolean::value == false); - } - - SECTION("IsString") { - REQUIRE(CesiumGltf::IsMetadataString::value); - REQUIRE(CesiumGltf::IsMetadataString::value == false); - } - - SECTION("IsNumericArray") { - REQUIRE(CesiumGltf::IsMetadataNumericArray< - CesiumGltf::MetadataArrayView>::value); - - REQUIRE( - CesiumGltf::IsMetadataNumericArray< - CesiumGltf::MetadataArrayView>::value == false); - } - - SECTION("IsBooleanArray") { - REQUIRE(CesiumGltf::IsMetadataBooleanArray< - CesiumGltf::MetadataArrayView>::value); - - REQUIRE( - CesiumGltf::IsMetadataBooleanArray< - CesiumGltf::MetadataArrayView>::value == false); - } - - SECTION("IsStringArray") { - REQUIRE(CesiumGltf::IsMetadataStringArray< - CesiumGltf::MetadataArrayView>::value); - - REQUIRE( - CesiumGltf::IsMetadataStringArray< - CesiumGltf::MetadataArrayView>::value == false); - } - - SECTION("ArrayType") { - using type = CesiumGltf::MetadataArrayType< - CesiumGltf::MetadataArrayView>::type; - REQUIRE(std::is_same_v); - } - - SECTION("TypeToPropertyType") { - CesiumGltf::PropertyType value = - CesiumGltf::TypeToPropertyType::value; - REQUIRE(value == CesiumGltf::PropertyType::Uint32); - - auto component = CesiumGltf::TypeToPropertyType< - CesiumGltf::MetadataArrayView>::component; - value = CesiumGltf::TypeToPropertyType< - CesiumGltf::MetadataArrayView>::value; - CesiumGltf::PropertyType expected = CesiumGltf::PropertyType::Array; - REQUIRE(value == expected); - REQUIRE(component == CesiumGltf::PropertyType::Uint32); - } -} diff --git a/CesiumGltf/test/TestStructuralMetadataPropertyTypeTraits.cpp b/CesiumGltf/test/TestPropertyTypeTraits.cpp similarity index 95% rename from CesiumGltf/test/TestStructuralMetadataPropertyTypeTraits.cpp rename to CesiumGltf/test/TestPropertyTypeTraits.cpp index 42c0a5313..caa8d1eaf 100644 --- a/CesiumGltf/test/TestStructuralMetadataPropertyTypeTraits.cpp +++ b/CesiumGltf/test/TestPropertyTypeTraits.cpp @@ -1,10 +1,10 @@ -#include "CesiumGltf/StructuralMetadataPropertyTypeTraits.h" +#include "CesiumGltf/PropertyTypeTraits.h" #include -using namespace CesiumGltf::StructuralMetadata; +using namespace CesiumGltf; -TEST_CASE("Test StructuralMetadata PropertyTypeTraits") { +TEST_CASE("Test PropertyTypeTraits") { SECTION("IsScalar") { REQUIRE(IsMetadataScalar::value); REQUIRE(IsMetadataScalar::value); @@ -140,25 +140,25 @@ TEST_CASE("Test StructuralMetadata PropertyTypeTraits") { } SECTION("IsNumericArray") { - REQUIRE(IsMetadataNumericArray>::value); - REQUIRE(IsMetadataNumericArray>::value); - REQUIRE(IsMetadataNumericArray>::value); - REQUIRE(!IsMetadataNumericArray>::value); + REQUIRE(IsMetadataNumericArray>::value); + REQUIRE(IsMetadataNumericArray>::value); + REQUIRE(IsMetadataNumericArray>::value); + REQUIRE(!IsMetadataNumericArray>::value); } SECTION("IsBooleanArray") { - REQUIRE(IsMetadataBooleanArray>::value); - REQUIRE(!IsMetadataBooleanArray>::value); + REQUIRE(IsMetadataBooleanArray>::value); + REQUIRE(!IsMetadataBooleanArray>::value); } SECTION("IsStringArray") { - REQUIRE(IsMetadataStringArray>::value); - REQUIRE(!IsMetadataStringArray>::value); - REQUIRE(!IsMetadataStringArray>::value); + REQUIRE(IsMetadataStringArray>::value); + REQUIRE(!IsMetadataStringArray>::value); + REQUIRE(!IsMetadataStringArray>::value); } SECTION("ArrayType") { - using type = MetadataArrayType>::type; + using type = MetadataArrayType>::type; REQUIRE(std::is_same_v); } diff --git a/CesiumGltf/test/TestPropertyView.cpp b/CesiumGltf/test/TestPropertyView.cpp deleted file mode 100644 index 42a112ec8..000000000 --- a/CesiumGltf/test/TestPropertyView.cpp +++ /dev/null @@ -1,589 +0,0 @@ -#include "CesiumGltf/MetadataPropertyView.h" - -#include -#include - -#include -#include -#include -#include -#include - -template static void checkNumeric(const std::vector& expected) { - std::vector data; - data.resize(expected.size() * sizeof(T)); - std::memcpy(data.data(), expected.data(), data.size()); - - CesiumGltf::MetadataPropertyView property( - CesiumGltf::MetadataPropertyViewStatus::Valid, - gsl::span(data.data(), data.size()), - gsl::span(), - gsl::span(), - CesiumGltf::PropertyType::None, - 0, - static_cast(expected.size()), - false); - - for (int64_t i = 0; i < property.size(); ++i) { - REQUIRE(property.get(i) == expected[static_cast(i)]); - } -} - -template -static void checkDynamicArray( - const std::vector& data, - const std::vector offset, - CesiumGltf::PropertyType offsetType, - int64_t instanceCount) { - // copy data to buffer - std::vector buffer; - buffer.resize(data.size() * sizeof(T)); - std::memcpy(buffer.data(), data.data(), data.size() * sizeof(T)); - - // copy offset to buffer - std::vector offsetBuffer; - offsetBuffer.resize(offset.size() * sizeof(E)); - std::memcpy(offsetBuffer.data(), offset.data(), offset.size() * sizeof(E)); - - CesiumGltf::MetadataPropertyView> property( - CesiumGltf::MetadataPropertyViewStatus::Valid, - gsl::span(buffer.data(), buffer.size()), - gsl::span(offsetBuffer.data(), offsetBuffer.size()), - gsl::span(), - offsetType, - 0, - instanceCount, - false); - - size_t expectedIdx = 0; - for (int64_t i = 0; i < property.size(); ++i) { - CesiumGltf::MetadataArrayView vals = property.get(i); - for (int64_t j = 0; j < vals.size(); ++j) { - REQUIRE(vals[j] == data[expectedIdx]); - ++expectedIdx; - } - } - - REQUIRE(expectedIdx == data.size()); -} - -template -static void checkFixedArray( - const std::vector& data, - int64_t componentCount, - int64_t instanceCount) { - std::vector buffer; - buffer.resize(data.size() * sizeof(T)); - std::memcpy(buffer.data(), data.data(), data.size() * sizeof(T)); - - CesiumGltf::MetadataPropertyView> property( - CesiumGltf::MetadataPropertyViewStatus::Valid, - gsl::span(buffer.data(), buffer.size()), - gsl::span(), - gsl::span(), - CesiumGltf::PropertyType::None, - componentCount, - instanceCount, - false); - - size_t expectedIdx = 0; - for (int64_t i = 0; i < property.size(); ++i) { - CesiumGltf::MetadataArrayView vals = property.get(i); - for (int64_t j = 0; j < vals.size(); ++j) { - REQUIRE(vals[j] == data[expectedIdx]); - ++expectedIdx; - } - } - - REQUIRE(expectedIdx == data.size()); -} - -TEST_CASE("Check create numeric property view") { - SECTION("Uint8") { - std::vector data{12, 33, 56, 67}; - checkNumeric(data); - } - - SECTION("Int32") { - std::vector data{111222, -11133, -56000, 670000}; - checkNumeric(data); - } - - SECTION("Float") { - std::vector data{12.3333f, -12.44555f, -5.6111f, 6.7421f}; - checkNumeric(data); - } - - SECTION("Double") { - std::vector data{ - 12222.3302121, - -12000.44555, - -5000.6113111, - 6.7421}; - checkNumeric(data); - } -} - -TEST_CASE("Check boolean value") { - std::bitset bits = 0b11110101; - unsigned long val = bits.to_ulong(); - std::vector data(sizeof(val)); - std::memcpy(data.data(), &val, sizeof(val)); - - size_t instanceCount = sizeof(unsigned long) * CHAR_BIT; - CesiumGltf::MetadataPropertyView property( - CesiumGltf::MetadataPropertyViewStatus::Valid, - gsl::span(data.data(), data.size()), - gsl::span(), - gsl::span(), - CesiumGltf::PropertyType::None, - 0, - static_cast(instanceCount), - false); - for (int64_t i = 0; i < property.size(); ++i) { - REQUIRE(property.get(i) == bits[static_cast(i)]); - } -} - -TEST_CASE("Check string value") { - std::vector strings{ - "This is a fine test", - "What's going on", - "Good morning"}; - size_t totalSize = 0; - for (const auto& s : strings) { - totalSize += s.size(); - } - - uint32_t currentOffset = 0; - std::vector buffer; - buffer.resize(totalSize); - for (size_t i = 0; i < strings.size(); ++i) { - std::memcpy( - buffer.data() + currentOffset, - strings[i].data(), - strings[i].size()); - currentOffset += static_cast(strings[i].size()); - } - - // copy offset to buffer - std::vector offsetBuffer; - offsetBuffer.resize((strings.size() + 1) * sizeof(uint32_t)); - currentOffset = 0; - for (size_t i = 0; i < strings.size(); ++i) { - std::memcpy( - offsetBuffer.data() + i * sizeof(uint32_t), - ¤tOffset, - sizeof(uint32_t)); - currentOffset += static_cast(strings[i].size()); - } - std::memcpy( - offsetBuffer.data() + strings.size() * sizeof(uint32_t), - ¤tOffset, - sizeof(uint32_t)); - - CesiumGltf::MetadataPropertyView property( - CesiumGltf::MetadataPropertyViewStatus::Valid, - gsl::span(buffer.data(), buffer.size()), - gsl::span(), - gsl::span(offsetBuffer.data(), offsetBuffer.size()), - CesiumGltf::PropertyType::Uint32, - 0, - static_cast(strings.size()), - false); - for (int64_t i = 0; i < property.size(); ++i) { - REQUIRE(property.get(i) == strings[static_cast(i)]); - } -} - -TEST_CASE("Check fixed numeric array") { - SECTION("Fixed array of 4 uint8_ts") { - // clang-format off - std::vector data{ - 210, 211, 3, 42, - 122, 22, 1, 45}; - // clang-format on - checkFixedArray(data, 4, static_cast(data.size() / 4)); - } - - SECTION("Fixed array of 3 int8_ts") { - // clang-format off - std::vector data{ - 122, -12, 3, - 44, 11, -2, - 5, 6, -22, - 5, 6, 1}; - // clang-format on - checkFixedArray(data, 3, static_cast(data.size() / 3)); - } - - SECTION("Fixed array of 4 int16_ts") { - // clang-format off - std::vector data{ - -122, 12, 3, 44, - 11, 2, 5, -6000, - 119, 30, 51, 200, - 22000, -500, 6000, 1}; - // clang-format on - checkFixedArray(data, 4, static_cast(data.size() / 4)); - } - - SECTION("Fixed array of 6 uint32_ts") { - // clang-format off - std::vector data{ - 122, 12, 3, 44, 34444, 2222, - 11, 2, 5, 6000, 1111, 2222, - 119, 30, 51, 200, 12534, 11, - 22000, 500, 6000, 1, 3, 7}; - // clang-format on - checkFixedArray(data, 6, static_cast(data.size() / 6)); - } - - SECTION("Fixed array of 2 int32_ts") { - // clang-format off - std::vector data{ - 122, 12, - 3, 44}; - // clang-format on - checkFixedArray(data, 2, static_cast(data.size() / 2)); - } - - SECTION("Fixed array of 4 uint64_ts") { - // clang-format off - std::vector data{ - 10022, 120000, 2422, 1111, - 3, 440000, 333, 1455}; - // clang-format on - checkFixedArray(data, 4, static_cast(data.size() / 4)); - } - - SECTION("Fixed array of 4 int64_ts") { - // clang-format off - std::vector data{ - 10022, -120000, 2422, 1111, - 3, 440000, -333, 1455}; - // clang-format on - checkFixedArray(data, 4, static_cast(data.size() / 4)); - } - - SECTION("Fixed array of 4 floats") { - // clang-format off - std::vector data{ - 10.022f, -12.43f, 242.2f, 1.111f, - 3.333f, 440000.1f, -33.3f, 14.55f}; - // clang-format on - checkFixedArray(data, 4, static_cast(data.size() / 4)); - } - - SECTION("Fixed array of 4 double") { - // clang-format off - std::vector data{ - 10.022, -12.43, 242.2, 1.111, - 3.333, 440000.1, -33.3, 14.55}; - // clang-format on - checkFixedArray(data, 4, static_cast(data.size() / 4)); - } -} - -TEST_CASE("Check numeric dynamic array") { - SECTION("array of uint8_t") { - // clang-format off - std::vector data{ - 3, 2, - 0, 45, 2, 1, 4, - 1, 3, 2, - 1, 3, 4, 1 - }; - std::vector offset{ - 0, 2, 7, 10, 14 - }; - // clang-format on - - checkDynamicArray(data, offset, CesiumGltf::PropertyType::Uint32, 4); - } - - SECTION("array of int32_t") { - // clang-format off - std::vector data{ - 3, 200, - 0, 450, 200, 1, 4, - 1, 3, 2, - 1, 3, 4, 1 - }; - std::vector offset{ - 0, 2 * sizeof(int32_t), 7 * sizeof(int32_t), 10 * sizeof(int32_t), 14 * sizeof(int32_t) - }; - // clang-format on - - checkDynamicArray(data, offset, CesiumGltf::PropertyType::Uint32, 4); - } - - SECTION("array of double") { - // clang-format off - std::vector data{ - 3.333, 200.2, - 0.1122, 4.50, 2.30, 1.22, 4.444, - 1.4, 3.3, 2.2, - 1.11, 3.2, 4.111, 1.44 - }; - std::vector offset{ - 0, 2 * sizeof(double), 7 * sizeof(double), 10 * sizeof(double), 14 * sizeof(double) - }; - // clang-format on - - checkDynamicArray(data, offset, CesiumGltf::PropertyType::Uint32, 4); - } -} - -TEST_CASE("Check fixed array of string") { - std::vector strings{ - "Test 1", - "Test 2", - "Test 3", - "Test 4", - "Test 5", - "Test 6", - "This is a fine test", - "What's going on", - "Good morning"}; - size_t totalSize = 0; - for (const auto& s : strings) { - totalSize += s.size(); - } - - uint32_t currentOffset = 0; - std::vector buffer; - buffer.resize(totalSize); - for (size_t i = 0; i < strings.size(); ++i) { - std::memcpy( - buffer.data() + currentOffset, - strings[i].data(), - strings[i].size()); - currentOffset += static_cast(strings[i].size()); - } - - // copy offset to buffer - std::vector offsetBuffer; - offsetBuffer.resize((strings.size() + 1) * sizeof(uint32_t)); - currentOffset = 0; - for (size_t i = 0; i < strings.size(); ++i) { - std::memcpy( - offsetBuffer.data() + i * sizeof(uint32_t), - ¤tOffset, - sizeof(uint32_t)); - currentOffset += static_cast(strings[i].size()); - } - std::memcpy( - offsetBuffer.data() + strings.size() * sizeof(uint32_t), - ¤tOffset, - sizeof(uint32_t)); - - CesiumGltf::MetadataPropertyView< - CesiumGltf::MetadataArrayView> - property( - CesiumGltf::MetadataPropertyViewStatus::Valid, - gsl::span(buffer.data(), buffer.size()), - gsl::span(), - gsl::span(offsetBuffer.data(), offsetBuffer.size()), - CesiumGltf::PropertyType::Uint32, - 3, - static_cast(strings.size() / 3), - false); - - size_t expectedIdx = 0; - for (int64_t i = 0; i < property.size(); ++i) { - CesiumGltf::MetadataArrayView vals = property.get(i); - for (int64_t j = 0; j < vals.size(); ++j) { - std::string_view v = vals[j]; - REQUIRE(v == strings[expectedIdx]); - ++expectedIdx; - } - } - - REQUIRE(expectedIdx == strings.size()); -} - -TEST_CASE("Check dynamic array of string") { - // clang-format off - std::vector arrayOffset{ - 0, - 4 * sizeof(uint32_t), - 7 * sizeof(uint32_t), - 11 * sizeof(uint32_t) - }; - - std::vector strings{ - "Test 1", "Test 2", "Test 3", "Test 4", - "Test 5", "Test 6", "Test 7", - "test 8", "Test 9", "Test 10", "Test 11" - }; - // clang-format on - - size_t totalSize = 0; - for (const auto& s : strings) { - totalSize += s.size(); - } - - uint32_t currentOffset = 0; - std::vector buffer; - buffer.resize(totalSize); - for (size_t i = 0; i < strings.size(); ++i) { - std::memcpy( - buffer.data() + currentOffset, - strings[i].data(), - strings[i].size()); - currentOffset += static_cast(strings[i].size()); - } - - std::vector offsetBuffer; - offsetBuffer.resize((strings.size() + 1) * sizeof(uint32_t)); - currentOffset = 0; - for (size_t i = 0; i < strings.size(); ++i) { - std::memcpy( - offsetBuffer.data() + i * sizeof(uint32_t), - ¤tOffset, - sizeof(uint32_t)); - currentOffset += static_cast(strings[i].size()); - } - std::memcpy( - offsetBuffer.data() + strings.size() * sizeof(uint32_t), - ¤tOffset, - sizeof(uint32_t)); - - CesiumGltf::MetadataPropertyView< - CesiumGltf::MetadataArrayView> - property( - CesiumGltf::MetadataPropertyViewStatus::Valid, - gsl::span(buffer.data(), buffer.size()), - gsl::span( - reinterpret_cast(arrayOffset.data()), - arrayOffset.size() * sizeof(uint32_t)), - gsl::span(offsetBuffer.data(), offsetBuffer.size()), - CesiumGltf::PropertyType::Uint32, - 0, - 3, - false); - - size_t expectedIdx = 0; - for (int64_t i = 0; i < property.size(); ++i) { - CesiumGltf::MetadataArrayView vals = property.get(i); - for (int64_t j = 0; j < vals.size(); ++j) { - std::string_view v = vals[j]; - REQUIRE(v == strings[expectedIdx]); - ++expectedIdx; - } - } - - REQUIRE(expectedIdx == strings.size()); -} - -TEST_CASE("Check fixed array of boolean") { - std::vector buffer{ - static_cast(0b10101111), - static_cast(0b11111010), - static_cast(0b11100111)}; - - CesiumGltf::MetadataPropertyView> - property( - CesiumGltf::MetadataPropertyViewStatus::Valid, - gsl::span(buffer.data(), buffer.size()), - gsl::span(), - gsl::span(), - CesiumGltf::PropertyType::Uint32, - 12, - 2, - false); - - REQUIRE(property.size() == 2); - - CesiumGltf::MetadataArrayView val0 = property.get(0); - REQUIRE(val0.size() == 12); - REQUIRE(static_cast(val0[0]) == 1); - REQUIRE(static_cast(val0[1]) == 1); - REQUIRE(static_cast(val0[2]) == 1); - REQUIRE(static_cast(val0[3]) == 1); - REQUIRE(static_cast(val0[4]) == 0); - REQUIRE(static_cast(val0[5]) == 1); - REQUIRE(static_cast(val0[6]) == 0); - REQUIRE(static_cast(val0[7]) == 1); - REQUIRE(static_cast(val0[8]) == 0); - REQUIRE(static_cast(val0[9]) == 1); - REQUIRE(static_cast(val0[10]) == 0); - REQUIRE(static_cast(val0[11]) == 1); - - CesiumGltf::MetadataArrayView val1 = property.get(1); - REQUIRE(static_cast(val1[0]) == 1); - REQUIRE(static_cast(val1[1]) == 1); - REQUIRE(static_cast(val1[2]) == 1); - REQUIRE(static_cast(val1[3]) == 1); - REQUIRE(static_cast(val1[4]) == 1); - REQUIRE(static_cast(val1[5]) == 1); - REQUIRE(static_cast(val1[6]) == 1); - REQUIRE(static_cast(val1[7]) == 0); - REQUIRE(static_cast(val1[8]) == 0); - REQUIRE(static_cast(val1[9]) == 1); - REQUIRE(static_cast(val1[10]) == 1); - REQUIRE(static_cast(val1[11]) == 1); -} - -TEST_CASE("Check dynamic array of boolean") { - std::vector buffer{ - static_cast(0b10101111), - static_cast(0b11111010), - static_cast(0b11100111), - static_cast(0b11110110)}; - - std::vector offsetBuffer{0, 3, 12, 28}; - - CesiumGltf::MetadataPropertyView> - property( - CesiumGltf::MetadataPropertyViewStatus::Valid, - gsl::span(buffer.data(), buffer.size()), - gsl::span( - reinterpret_cast(offsetBuffer.data()), - offsetBuffer.size() * sizeof(uint32_t)), - gsl::span(), - CesiumGltf::PropertyType::Uint32, - 0, - 3, - false); - - REQUIRE(property.size() == 3); - - CesiumGltf::MetadataArrayView val0 = property.get(0); - REQUIRE(val0.size() == 3); - REQUIRE(static_cast(val0[0]) == 1); - REQUIRE(static_cast(val0[1]) == 1); - REQUIRE(static_cast(val0[2]) == 1); - - CesiumGltf::MetadataArrayView val1 = property.get(1); - REQUIRE(val1.size() == 9); - REQUIRE(static_cast(val1[0]) == 1); - REQUIRE(static_cast(val1[1]) == 0); - REQUIRE(static_cast(val1[2]) == 1); - REQUIRE(static_cast(val1[3]) == 0); - REQUIRE(static_cast(val1[4]) == 1); - REQUIRE(static_cast(val1[5]) == 0); - REQUIRE(static_cast(val1[6]) == 1); - REQUIRE(static_cast(val1[7]) == 0); - REQUIRE(static_cast(val1[8]) == 1); - - CesiumGltf::MetadataArrayView val2 = property.get(2); - REQUIRE(val2.size() == 16); - REQUIRE(static_cast(val2[0]) == 1); - REQUIRE(static_cast(val2[1]) == 1); - REQUIRE(static_cast(val2[2]) == 1); - REQUIRE(static_cast(val2[3]) == 1); - REQUIRE(static_cast(val2[4]) == 1); - REQUIRE(static_cast(val2[5]) == 1); - REQUIRE(static_cast(val2[6]) == 1); - REQUIRE(static_cast(val2[7]) == 0); - REQUIRE(static_cast(val2[8]) == 0); - REQUIRE(static_cast(val2[9]) == 1); - REQUIRE(static_cast(val2[10]) == 1); - REQUIRE(static_cast(val2[11]) == 1); - REQUIRE(static_cast(val2[12]) == 0); - REQUIRE(static_cast(val2[13]) == 1); - REQUIRE(static_cast(val2[14]) == 1); - REQUIRE(static_cast(val2[15]) == 0); -} diff --git a/CesiumGltf/test/TestStructuralMetadataPropertyType.cpp b/CesiumGltf/test/TestStructuralMetadataPropertyType.cpp deleted file mode 100644 index fbd27e44a..000000000 --- a/CesiumGltf/test/TestStructuralMetadataPropertyType.cpp +++ /dev/null @@ -1,253 +0,0 @@ -#include "CesiumGltf/ExtensionExtStructuralMetadataClassProperty.h" -#include "CesiumGltf/ExtensionExtStructuralMetadataPropertyTableProperty.h" -#include "CesiumGltf/StructuralMetadataPropertyType.h" - -#include - -using namespace CesiumGltf; -using namespace StructuralMetadata; - -TEST_CASE("Test StructuralMetadata PropertyType utilities function") { - SECTION("Convert string to PropertyType") { - REQUIRE( - convertStringToPropertyType( - ExtensionExtStructuralMetadataClassProperty::Type::SCALAR) == - PropertyType::Scalar); - - REQUIRE( - convertStringToPropertyType( - ExtensionExtStructuralMetadataClassProperty::Type::VEC2) == - PropertyType::Vec2); - - REQUIRE( - convertStringToPropertyType( - ExtensionExtStructuralMetadataClassProperty::Type::VEC3) == - PropertyType::Vec3); - - REQUIRE( - convertStringToPropertyType( - ExtensionExtStructuralMetadataClassProperty::Type::VEC4) == - PropertyType::Vec4); - - REQUIRE( - convertStringToPropertyType( - ExtensionExtStructuralMetadataClassProperty::Type::MAT2) == - PropertyType::Mat2); - - REQUIRE( - convertStringToPropertyType( - ExtensionExtStructuralMetadataClassProperty::Type::MAT3) == - PropertyType::Mat3); - - REQUIRE( - convertStringToPropertyType( - ExtensionExtStructuralMetadataClassProperty::Type::MAT4) == - PropertyType::Mat4); - - REQUIRE( - convertStringToPropertyType( - ExtensionExtStructuralMetadataClassProperty::Type::BOOLEAN) == - PropertyType::Boolean); - - REQUIRE( - convertStringToPropertyType( - ExtensionExtStructuralMetadataClassProperty::Type::STRING) == - PropertyType::String); - - REQUIRE( - convertStringToPropertyType( - ExtensionExtStructuralMetadataClassProperty::Type::ENUM) == - PropertyType::Enum); - - REQUIRE(convertStringToPropertyType("invalid") == PropertyType::Invalid); - } - - SECTION("Convert string to PropertyComponentType") { - REQUIRE( - convertStringToPropertyComponentType( - ExtensionExtStructuralMetadataClassProperty::ComponentType:: - UINT8) == PropertyComponentType::Uint8); - - REQUIRE( - convertStringToPropertyComponentType( - ExtensionExtStructuralMetadataClassProperty::ComponentType::INT8) == - PropertyComponentType::Int8); - - REQUIRE( - convertStringToPropertyComponentType( - ExtensionExtStructuralMetadataClassProperty::ComponentType:: - UINT16) == PropertyComponentType::Uint16); - REQUIRE( - convertStringToPropertyComponentType( - ExtensionExtStructuralMetadataClassProperty::ComponentType:: - INT16) == PropertyComponentType::Int16); - - REQUIRE( - convertStringToPropertyComponentType( - ExtensionExtStructuralMetadataClassProperty::ComponentType:: - UINT32) == PropertyComponentType::Uint32); - - REQUIRE( - convertStringToPropertyComponentType( - ExtensionExtStructuralMetadataClassProperty::ComponentType:: - INT32) == PropertyComponentType::Int32); - REQUIRE( - convertStringToPropertyComponentType( - ExtensionExtStructuralMetadataClassProperty::ComponentType:: - UINT64) == PropertyComponentType::Uint64); - - REQUIRE( - convertStringToPropertyComponentType( - ExtensionExtStructuralMetadataClassProperty::ComponentType:: - INT64) == PropertyComponentType::Int64); - - REQUIRE( - convertStringToPropertyComponentType( - ExtensionExtStructuralMetadataClassProperty::ComponentType:: - FLOAT32) == PropertyComponentType::Float32); - REQUIRE( - convertStringToPropertyComponentType( - ExtensionExtStructuralMetadataClassProperty::ComponentType:: - FLOAT64) == PropertyComponentType::Float64); - - REQUIRE( - convertStringToPropertyComponentType("invalid") == - PropertyComponentType::None); - } - - SECTION("Convert PropertyType to string") { - REQUIRE( - convertPropertyTypeToString(PropertyType::Scalar) == - ExtensionExtStructuralMetadataClassProperty::Type::SCALAR); - - REQUIRE( - convertPropertyTypeToString(PropertyType::Vec2) == - ExtensionExtStructuralMetadataClassProperty::Type::VEC2); - - REQUIRE( - convertPropertyTypeToString(PropertyType::Vec3) == - ExtensionExtStructuralMetadataClassProperty::Type::VEC3); - - REQUIRE( - convertPropertyTypeToString(PropertyType::Vec4) == - ExtensionExtStructuralMetadataClassProperty::Type::VEC4); - - REQUIRE( - convertPropertyTypeToString(PropertyType::Mat2) == - ExtensionExtStructuralMetadataClassProperty::Type::MAT2); - - REQUIRE( - convertPropertyTypeToString(PropertyType::Mat3) == - ExtensionExtStructuralMetadataClassProperty::Type::MAT3); - - REQUIRE( - convertPropertyTypeToString(PropertyType::Mat4) == - ExtensionExtStructuralMetadataClassProperty::Type::MAT4); - - REQUIRE( - convertPropertyTypeToString(PropertyType::Boolean) == - ExtensionExtStructuralMetadataClassProperty::Type::BOOLEAN); - - REQUIRE( - convertPropertyTypeToString(PropertyType::String) == - ExtensionExtStructuralMetadataClassProperty::Type::STRING); - - REQUIRE( - convertPropertyTypeToString(PropertyType::Enum) == - ExtensionExtStructuralMetadataClassProperty::Type::ENUM); - } - - SECTION("Convert PropertyComponentType to string") { - REQUIRE( - convertPropertyComponentTypeToString(PropertyComponentType::Uint8) == - ExtensionExtStructuralMetadataClassProperty::ComponentType::UINT8); - - REQUIRE( - convertPropertyComponentTypeToString(PropertyComponentType::Int8) == - ExtensionExtStructuralMetadataClassProperty::ComponentType::INT8); - - REQUIRE( - convertPropertyComponentTypeToString(PropertyComponentType::Uint16) == - ExtensionExtStructuralMetadataClassProperty::ComponentType::UINT16); - - REQUIRE( - convertPropertyComponentTypeToString(PropertyComponentType::Int16) == - ExtensionExtStructuralMetadataClassProperty::ComponentType::INT16); - - REQUIRE( - convertPropertyComponentTypeToString(PropertyComponentType::Uint32) == - ExtensionExtStructuralMetadataClassProperty::ComponentType::UINT32); - - REQUIRE( - convertPropertyComponentTypeToString(PropertyComponentType::Int32) == - ExtensionExtStructuralMetadataClassProperty::ComponentType::INT32); - - REQUIRE( - convertPropertyComponentTypeToString(PropertyComponentType::Uint64) == - ExtensionExtStructuralMetadataClassProperty::ComponentType::UINT64); - - REQUIRE( - convertPropertyComponentTypeToString(PropertyComponentType::Int64) == - ExtensionExtStructuralMetadataClassProperty::ComponentType::INT64); - - REQUIRE( - convertPropertyComponentTypeToString(PropertyComponentType::Float32) == - ExtensionExtStructuralMetadataClassProperty::ComponentType::FLOAT32); - - REQUIRE( - convertPropertyComponentTypeToString(PropertyComponentType::Float64) == - ExtensionExtStructuralMetadataClassProperty::ComponentType::FLOAT64); - } - - SECTION("Convert array offset type string to PropertyComponentType") { - REQUIRE( - convertArrayOffsetTypeStringToPropertyComponentType( - ExtensionExtStructuralMetadataPropertyTableProperty:: - ArrayOffsetType::UINT8) == PropertyComponentType::Uint8); - - REQUIRE( - convertArrayOffsetTypeStringToPropertyComponentType( - ExtensionExtStructuralMetadataPropertyTableProperty:: - ArrayOffsetType::UINT16) == PropertyComponentType::Uint16); - - REQUIRE( - convertArrayOffsetTypeStringToPropertyComponentType( - ExtensionExtStructuralMetadataPropertyTableProperty:: - ArrayOffsetType::UINT32) == PropertyComponentType::Uint32); - - REQUIRE( - convertArrayOffsetTypeStringToPropertyComponentType( - ExtensionExtStructuralMetadataPropertyTableProperty:: - ArrayOffsetType::UINT64) == PropertyComponentType::Uint64); - - REQUIRE( - convertArrayOffsetTypeStringToPropertyComponentType("invalid") == - PropertyComponentType::None); - } - - SECTION("Convert string offset type string to PropertyComponentType") { - REQUIRE( - convertStringOffsetTypeStringToPropertyComponentType( - ExtensionExtStructuralMetadataPropertyTableProperty:: - StringOffsetType::UINT8) == PropertyComponentType::Uint8); - - REQUIRE( - convertStringOffsetTypeStringToPropertyComponentType( - ExtensionExtStructuralMetadataPropertyTableProperty:: - StringOffsetType::UINT16) == PropertyComponentType::Uint16); - - REQUIRE( - convertStringOffsetTypeStringToPropertyComponentType( - ExtensionExtStructuralMetadataPropertyTableProperty:: - StringOffsetType::UINT32) == PropertyComponentType::Uint32); - - REQUIRE( - convertStringOffsetTypeStringToPropertyComponentType( - ExtensionExtStructuralMetadataPropertyTableProperty:: - StringOffsetType::UINT64) == PropertyComponentType::Uint64); - - REQUIRE( - convertStringOffsetTypeStringToPropertyComponentType("invalid") == - PropertyComponentType::None); - } -}