3#include <CesiumGltf/Enum.h>
4#include <CesiumGltf/PropertyArrayView.h>
5#include <CesiumGltf/PropertyTransformations.h>
6#include <CesiumGltf/PropertyTypeTraits.h>
7#include <CesiumGltf/PropertyView.h>
8#include <CesiumUtility/Assert.h>
144template <
typename ElementType,
bool Normalized = false>
161template <
typename ElementType>
174 _arrayOffsetTypeSize{0},
177 _stringOffsetTypeSize{0} {}
190 _arrayOffsetTypeSize{0},
193 _stringOffsetTypeSize{0} {
196 "An empty property view should not be constructed with a valid status");
214 _arrayOffsetTypeSize{0},
217 _stringOffsetTypeSize{0} {
228 this->_status = PropertyTablePropertyViewStatus::ErrorNonexistentProperty;
249 std::span<const std::byte> values) noexcept
273 std::span<const std::byte> values) noexcept
280 _arrayOffsetTypeSize{0},
283 _stringOffsetTypeSize{0} {}
301 std::span<const std::byte> values,
302 std::span<const std::byte> arrayOffsets,
303 std::span<const std::byte> stringOffsets,
336 std::span<const std::byte> values,
337 std::span<const std::byte> arrayOffsets,
338 std::span<const std::byte> stringOffsets,
345 _arrayOffsets{arrayOffsets},
346 _arrayOffsetType{arrayOffsetType},
348 _stringOffsets{stringOffsets},
349 _stringOffsetType{stringOffsetType},
367 std::optional<PropertyValueViewToCopy<ElementType>>
368 get(int64_t index)
const noexcept {
371 CESIUM_ASSERT(index >= 0 &&
"index must be non-negative");
372 CESIUM_ASSERT(index < size() &&
"index must be less than size");
374 return propertyValueViewToCopy(this->defaultValue());
377 ElementType value = getRaw(index);
379 if (value == this->noData()) {
380 return propertyValueViewToCopy(this->defaultValue());
368 get(int64_t index)
const noexcept {
…}
400 ElementType
getRaw(int64_t index)
const noexcept {
403 "Check the status() first to make sure view is valid");
406 "Check the size() of the view to make sure it's not empty");
407 CESIUM_ASSERT(index >= 0 &&
"index must be non-negative");
408 CESIUM_ASSERT(index < size() &&
"index must be less than size");
411 return getNumericValue(index);
415 return getBooleanValue(index);
419 return getStringValue(index);
423 return getNumericArrayValues<
428 return getBooleanArrayValues(index);
432 return getStringArrayValues(index);
400 ElementType
getRaw(int64_t index)
const noexcept {
…}
443 int64_t
size() const noexcept {
return _size; }
446 ElementType getNumericValue(int64_t index)
const noexcept {
447 return reinterpret_cast<const ElementType*
>(_values.data())[index];
450 bool getBooleanValue(int64_t index)
const noexcept {
451 const int64_t byteIndex = index / 8;
452 const int64_t bitIndex = index % 8;
454 static_cast<int>(_values[
static_cast<size_t>(byteIndex)] >> bitIndex) &
456 return bitValue == 1;
459 std::string_view getStringValue(int64_t index)
const noexcept {
460 const size_t currentOffset = getOffsetFromOffsetsBuffer(
461 static_cast<size_t>(index),
464 const size_t nextOffset = getOffsetFromOffsetsBuffer(
465 static_cast<size_t>(index + 1),
468 return std::string_view(
469 reinterpret_cast<const char*
>(_values.data() + currentOffset),
470 nextOffset - currentOffset);
473 template <
typename T>
474 PropertyArrayView<T> getNumericArrayValues(int64_t index)
const noexcept {
475 size_t count =
static_cast<size_t>(this->arrayCount());
478 size_t arraySize = count *
sizeof(T);
479 const std::span<const std::byte> values(
480 _values.data() +
static_cast<size_t>(index) * arraySize,
482 return PropertyArrayView<T>{values};
487 const size_t currentOffset = getOffsetFromOffsetsBuffer(
488 static_cast<size_t>(index),
492 const size_t nextOffset = getOffsetFromOffsetsBuffer(
493 static_cast<size_t>(index + 1),
497 const std::span<const std::byte> values(
498 _values.data() + currentOffset,
499 nextOffset - currentOffset);
500 return PropertyArrayView<T>{values};
503 PropertyArrayView<std::string_view>
504 getStringArrayValues(int64_t index)
const noexcept {
505 size_t count =
static_cast<size_t>(this->arrayCount());
509 const size_t arraySize =
510 count *
static_cast<size_t>(_stringOffsetTypeSize);
511 const std::span<const std::byte> stringOffsetValues(
512 _stringOffsets.data() +
static_cast<size_t>(index) * arraySize,
513 arraySize +
static_cast<size_t>(_stringOffsetTypeSize));
514 return PropertyArrayView<std::string_view>(
518 static_cast<int64_t
>(count));
522 const size_t currentArrayOffset =
523 getOffsetFromOffsetsBuffer(
524 static_cast<size_t>(index),
527 static_cast<size_t>(_stringOffsetTypeSize);
528 const size_t nextArrayOffset = getOffsetFromOffsetsBuffer(
529 static_cast<size_t>(index + 1),
532 static_cast<size_t>(_stringOffsetTypeSize);
533 const size_t arraySize = nextArrayOffset - currentArrayOffset;
534 const std::span<const std::byte> stringOffsetValues(
535 _stringOffsets.data() + currentArrayOffset,
536 arraySize +
static_cast<size_t>(_stringOffsetTypeSize));
537 return PropertyArrayView<std::string_view>(
541 static_cast<int64_t
>(arraySize) / _stringOffsetTypeSize);
544 PropertyArrayView<bool> getBooleanArrayValues(int64_t index)
const noexcept {
545 size_t count =
static_cast<size_t>(this->arrayCount());
548 const size_t offsetBits = count *
static_cast<size_t>(index);
549 const size_t nextOffsetBits = count *
static_cast<size_t>(index + 1);
550 const std::span<const std::byte> buffer(
551 _values.data() + offsetBits / 8,
552 (nextOffsetBits / 8 - offsetBits / 8 + 1));
553 return PropertyArrayView<bool>(
556 static_cast<int64_t
>(count));
560 const size_t currentOffset = getOffsetFromOffsetsBuffer(
561 static_cast<size_t>(index),
564 const size_t nextOffset = getOffsetFromOffsetsBuffer(
565 static_cast<size_t>(index + 1),
568 const size_t totalBits = nextOffset - currentOffset;
569 const std::span<const std::byte> buffer(
570 _values.data() + currentOffset / 8,
571 (nextOffset / 8 - currentOffset / 8 + 1));
572 return PropertyArrayView<bool>(
575 static_cast<int64_t
>(totalBits));
578 std::span<const std::byte> _values;
581 std::span<const std::byte> _arrayOffsets;
583 int64_t _arrayOffsetTypeSize;
585 std::span<const std::byte> _stringOffsets;
587 int64_t _stringOffsetTypeSize;
604template <
typename ElementType>
620 _arrayOffsetTypeSize{0} {}
633 _arrayOffsetTypeSize{0} {
636 "An empty property view should not be constructed with a valid status");
654 _arrayOffsetTypeSize{0} {
665 this->_status = PropertyTablePropertyViewStatus::ErrorNonexistentProperty;
686 std::span<const std::byte> values) noexcept
693 _arrayOffsetTypeSize{0} {}
710 std::span<const std::byte> values,
711 std::span<const std::byte> arrayOffsets,
717 _arrayOffsets{arrayOffsets},
718 _arrayOffsetType{arrayOffsetType},
736 std::optional<PropertyValueViewToCopy<NormalizedType>>
737 get(int64_t index)
const noexcept {
740 CESIUM_ASSERT(index >= 0 &&
"index must be non-negative");
741 CESIUM_ASSERT(index < size() &&
"index must be less than size");
743 return propertyValueViewToCopy(this->defaultValue());
746 ElementType value = getRaw(index);
747 if (this->noData() && value == *(this->noData())) {
748 return propertyValueViewToCopy(this->defaultValue());
755 constexpr glm::length_t N = ElementType::length();
756 using T =
typename ElementType::value_type;
757 using NormalizedT =
typename NormalizedType::value_type;
763 constexpr glm::length_t N = ElementType::length();
764 using T =
typename ElementType::value_type;
765 using NormalizedT =
typename NormalizedType::value_type;
778 constexpr glm::length_t N = ArrayElementType::length();
779 using T =
typename ArrayElementType::value_type;
785 constexpr glm::length_t N = ArrayElementType::length();
786 using T =
typename ArrayElementType::value_type;
737 get(int64_t index)
const noexcept {
…}
805 ElementType
getRaw(int64_t index)
const noexcept {
808 "Check the status() first to make sure view is valid");
811 "Check the size() of the view to make sure it's not empty");
812 CESIUM_ASSERT(index >= 0 &&
"index must be non-negative");
813 CESIUM_ASSERT(index < size() &&
"index must be less than size");
816 return getValue(index);
820 return getArrayValues<typename MetadataArrayType<ElementType>::type>(
805 ElementType
getRaw(int64_t index)
const noexcept {
…}
832 int64_t
size() const noexcept {
837 ElementType getValue(int64_t index)
const noexcept {
838 return reinterpret_cast<const ElementType*
>(_values.data())[index];
841 template <
typename T>
842 PropertyArrayView<T> getArrayValues(int64_t index)
const noexcept {
843 size_t count =
static_cast<size_t>(this->arrayCount());
846 size_t arraySize = count *
sizeof(T);
847 const std::span<const std::byte> values(
848 _values.data() +
static_cast<size_t>(index) * arraySize,
850 return PropertyArrayView<T>{values};
855 const size_t currentOffset = getOffsetFromOffsetsBuffer(
856 static_cast<size_t>(index),
860 const size_t nextOffset = getOffsetFromOffsetsBuffer(
861 static_cast<size_t>(index + 1),
865 const std::span<const std::byte> values(
866 _values.data() + currentOffset,
867 nextOffset - currentOffset);
868 return PropertyArrayView<T>{values};
871 std::span<const std::byte> _values;
874 std::span<const std::byte> _arrayOffsets;
876 int64_t _arrayOffsetTypeSize;
Indicates the status of a property table property view.
static const PropertyViewStatusType ErrorBufferViewSizeDoesNotMatchPropertyTableCount
This property view has an invalid buffer view; its length does not match the size of the property tab...
static const PropertyViewStatusType ErrorInvalidArrayOffsetBufferView
This array property view does not have a valid array offset buffer view index.
static const PropertyViewStatusType ErrorBufferViewOutOfBounds
This property view has a buffer view that points outside the bounds of its target buffer.
static const PropertyViewStatusType ErrorArrayCountAndOffsetBufferCoexist
This array property view has both a fixed length and an offset buffer view defined.
static const PropertyViewStatusType ErrorInvalidValueBufferView
This property view does not have a valid value buffer view index.
static const PropertyViewStatusType ErrorInvalidStringOffsetBuffer
This property view has a valid string offset buffer view, but the buffer view specifies an invalid bu...
static const PropertyViewStatusType ErrorInvalidStringOffsetType
This property view has an unknown string offset type.
static const PropertyViewStatusType ErrorArrayCountAndOffsetBufferDontExist
This array property view has neither a fixed length nor an offset buffer view defined.
static const PropertyViewStatusType ErrorArrayOffsetsNotSorted
This property view's array offset values are not sorted in ascending order.
static const PropertyViewStatusType ErrorInvalidArrayOffsetBuffer
This property view has a valid array string buffer view, but the buffer view specifies an invalid buf...
static const PropertyViewStatusType ErrorArrayOffsetOutOfBounds
This property view has an array offset that is out of bounds.
static const PropertyViewStatusType ErrorInvalidPropertyTable
This property view was initialized from an invalid PropertyTable.
static const PropertyViewStatusType ErrorInvalidValueBuffer
This property view has a valid value buffer view, but the buffer view specifies an invalid buffer ind...
static const PropertyViewStatusType ErrorInvalidStringOffsetBufferView
This string property view does not have a valid string offset buffer view index.
static const PropertyViewStatusType ErrorInvalidArrayOffsetType
This property view has an unknown array offset type.
static const PropertyViewStatusType ErrorStringOffsetsNotSorted
This property view's string offset values are not sorted in ascending order.
static const PropertyViewStatusType ErrorStringOffsetOutOfBounds
This property view has a string offset that is out of bounds.
static const PropertyViewStatusType ErrorBufferViewSizeNotDivisibleByTypeSize
This property view has an invalid buffer view; its length is not a multiple of the size of its type /...
PropertyTablePropertyView(const ClassProperty &classProperty, int64_t size)
Constructs an instance of an empty property that specifies a default value. Although this property ha...
PropertyTablePropertyView(const PropertyTableProperty &property, const ClassProperty &classProperty, int64_t size, std::span< const std::byte > values, std::span< const std::byte > arrayOffsets, std::span< const std::byte > stringOffsets, PropertyComponentType arrayOffsetType, PropertyComponentType stringOffsetType) noexcept
Construct an instance pointing to the data specified by a PropertyTableProperty.
PropertyTablePropertyView()
Constructs an invalid instance for a non-existent property.
std::optional< PropertyValueViewToCopy< ElementType > > get(int64_t index) const noexcept
Get the value of an element in the PropertyTable, with all value transforms applied....
PropertyTablePropertyView(const PropertyTableProperty &property, const ClassProperty &classProperty, const CesiumGltf::Enum *pEnumDefinition, int64_t size, std::span< const std::byte > values, std::span< const std::byte > arrayOffsets, std::span< const std::byte > stringOffsets, PropertyComponentType arrayOffsetType, PropertyComponentType stringOffsetType) noexcept
Construct an instance pointing to the data specified by a PropertyTableProperty, with an enum definit...
ElementType getRaw(int64_t index) const noexcept
Get the raw value of an element of the PropertyTable, without offset or scale applied.
PropertyTablePropertyView(PropertyViewStatusType status)
Constructs an invalid instance for an erroneous property.
int64_t size() const noexcept
Get the number of elements in this PropertyTablePropertyView. If the view is valid,...
PropertyTablePropertyView(const PropertyTableProperty &property, const ClassProperty &classProperty, int64_t size, std::span< const std::byte > values) noexcept
Construct an instance pointing to data specified by a PropertyTableProperty. Used for non-array or fi...
PropertyTablePropertyView(const PropertyTableProperty &property, const ClassProperty &classProperty, const CesiumGltf::Enum *pEnumDefinition, int64_t size, std::span< const std::byte > values) noexcept
Construct an instance pointing to data specified by a PropertyTableProperty, with an enum definition ...
PropertyTablePropertyView()
Constructs an invalid instance for a non-existent property.
std::optional< PropertyValueViewToCopy< NormalizedType > > get(int64_t index) const noexcept
Get the value of an element of the PropertyTable, with normalization and other value transforms appli...
ElementType getRaw(int64_t index) const noexcept
Get the raw value of an element of the PropertyTable, without offset, scale, or normalization applied...
PropertyTablePropertyView(const PropertyTableProperty &property, const ClassProperty &classProperty, int64_t size, std::span< const std::byte > values) noexcept
Construct an instance pointing to data specified by a PropertyTableProperty. Used for non-array or fi...
PropertyTablePropertyView(PropertyViewStatusType status)
Constructs an invalid instance for an erroneous property.
PropertyTablePropertyView(const PropertyTableProperty &property, const ClassProperty &classProperty, int64_t size, std::span< const std::byte > values, std::span< const std::byte > arrayOffsets, PropertyComponentType arrayOffsetType) noexcept
Construct an instance pointing to the data specified by a PropertyTableProperty.
int64_t size() const noexcept
Get the number of elements in this PropertyTablePropertyView. If the view is valid,...
PropertyTablePropertyView(const ClassProperty &classProperty, int64_t size)
Constructs an instance of an empty property that specifies a default value. Although this property ha...
A view on the data of the PropertyTableProperty that is created by a PropertyTableView.
Indicates the status of a property view.
static const PropertyViewStatusType Valid
This property view is valid and ready to use.
static const PropertyViewStatusType EmptyPropertyWithDefault
This property view does not contain any data, but specifies a default value. This happens when a clas...
Represents a metadata property in EXT_structural_metadata.
Classes for working with glTF models.
PropertyComponentType
The possible types of a property component.
PropertyArrayCopy< glm::mat< N, N, double > > transformNormalizedMatNArray(const PropertyArrayView< glm::mat< N, N, T > > &value, const std::optional< PropertyArrayView< glm::mat< N, N, double > > > &offset, const std::optional< PropertyArrayView< glm::mat< N, N, double > > > &scale)
Normalizes each element of an array of matrices and transforms them by optional offset and scale fact...
PropertyArrayCopy< glm::vec< N, double > > transformNormalizedVecNArray(const PropertyArrayView< glm::vec< N, T > > &value, const std::optional< PropertyArrayView< glm::vec< N, double > > > &offset, const std::optional< PropertyArrayView< glm::vec< N, double > > > &scale)
Normalizes each element of an array of vectors and transforms them by optional offset and scale facto...
PropertyArrayCopy< NormalizedType > transformNormalizedArray(const PropertyArrayView< T > &value, const std::optional< PropertyArrayView< NormalizedType > > &offset, const std::optional< PropertyArrayView< NormalizedType > > &scale)
Normalizes each element of an array of values and transforms them by optional offset and scale factor...
T transformValue(const T &value, const std::optional< T > &offset, const std::optional< T > &scale)
Transforms the value by optional offset and scale factors.
double normalize(T value)
Normalizes the given value between [0, 1] if unsigned or [-1, 1] if signed, based on the type's maxim...
int64_t getOffsetTypeSize(PropertyComponentType offsetType) noexcept
Returns the size in bytes of a PropertyComponentType used as the arrayOffsetType in the constructor o...
PropertyArrayCopy< T > transformArray(const PropertyArrayView< T > &value, const std::optional< PropertyArrayView< T > > &offset, const std::optional< PropertyArrayView< T > > &scale)
Transforms each element of an array of values by optional offset and scale factors....
int32_t PropertyViewStatusType
The type used for fields of PropertyViewStatus.
std::optional< CesiumUtility::JsonValue > defaultProperty
A default value to use when encountering a noData value or an omitted property. The value is given in...
This class is not meant to be instantiated directly. Use Enum instead.
An array of binary property values.
Convert an integer numeric type to the corresponding representation as a double type....