Add property types for structural metadata

This commit is contained in:
Janine Liu 2023-05-15 16:58:17 -04:00
parent c1e852fb7a
commit 14997fb031
3 changed files with 524 additions and 0 deletions

View File

@ -0,0 +1,57 @@
#pragma once
#include <cstdint>
#include <string>
#include <string_view>
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(CesiumGltf::StructuralMetadata::PropertyType type);
CesiumGltf::StructuralMetadata::PropertyType
convertStringToPropertyType(const std::string& str);
std::string convertPropertyComponentTypeToString(
CesiumGltf::StructuralMetadata::PropertyComponentType componentType);
CesiumGltf::StructuralMetadata::PropertyComponentType
convertStringToPropertyComponentType(const std::string& str);
CesiumGltf::StructuralMetadata::PropertyComponentType
convertArrayOffsetTypeStringToPropertyComponentType(const std::string& str);
CesiumGltf::StructuralMetadata::PropertyComponentType
convertStringOffsetTypeStringToPropertyComponentType(const std::string& str);
} // namespace StructuralMetadata
} // namespace CesiumGltf

View File

@ -0,0 +1,214 @@
#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 StructuralMetadata::PropertyType::Vec2;
}
if (str == ExtensionExtStructuralMetadataClassProperty::Type::VEC3) {
return StructuralMetadata::PropertyType::Vec3;
}
if (str == ExtensionExtStructuralMetadataClassProperty::Type::VEC4) {
return StructuralMetadata::PropertyType::Vec4;
}
if (str == ExtensionExtStructuralMetadataClassProperty::Type::MAT2) {
return StructuralMetadata::PropertyType::Mat2;
}
if (str == ExtensionExtStructuralMetadataClassProperty::Type::MAT3) {
return StructuralMetadata::PropertyType::Mat3;
}
if (str == ExtensionExtStructuralMetadataClassProperty::Type::MAT4) {
return StructuralMetadata::PropertyType::Mat4;
}
if (str == ExtensionExtStructuralMetadataClassProperty::Type::BOOLEAN) {
return StructuralMetadata::PropertyType::Boolean;
}
if (str == ExtensionExtStructuralMetadataClassProperty::Type::STRING) {
return StructuralMetadata::PropertyType::String;
}
if (str == ExtensionExtStructuralMetadataClassProperty::Type::ENUM) {
return StructuralMetadata::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";
}
}
StructuralMetadata::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;
}
StructuralMetadata::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;
}
StructuralMetadata::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;
}
} // namespace StructuralMetadata
} // namespace CesiumGltf

View File

@ -0,0 +1,253 @@
#include "CesiumGltf/ExtensionExtStructuralMetadataClassProperty.h"
#include "CesiumGltf/ExtensionExtStructuralMetadataPropertyTableProperty.h"
#include "CesiumGltf/StructuralMetadataPropertyType.h"
#include <catch2/catch.hpp>
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);
}
}