3#include "CesiumGltf/AccessorView.h"
4#include "CesiumGltf/PropertyAttributeProperty.h"
5#include "CesiumGltf/PropertyTransformations.h"
6#include "CesiumGltf/PropertyTypeTraits.h"
7#include "CesiumGltf/PropertyView.h"
9#include <CesiumUtility/Assert.h>
104template <
typename ElementType,
bool Normalized = false>
118template <
typename ElementType>
126 :
PropertyView<ElementType, false>(), _accessor{}, _size{0} {}
137 "An empty property view should not be constructed with a valid status");
152 int64_t size) noexcept
160 if (!classProperty.defaultProperty) {
187 _accessor{accessorView},
190 ? accessorView.size()
208 std::optional<ElementType>
get(int64_t index)
const noexcept {
211 return this->defaultValue();
214 ElementType value = getRaw(index);
216 if (value == this->noData()) {
217 return this->defaultValue();
233 ElementType
getRaw(int64_t index)
const noexcept {
236 "Check the status() first to make sure view is valid");
239 "Check the size() of the view to make sure it's not empty");
240 CESIUM_ASSERT(index >= 0 &&
"index must be non-negative");
241 CESIUM_ASSERT(index < size() &&
"index must be less than size");
243 return _accessor[index];
253 int64_t
size() const noexcept {
return _size; }
271template <
typename ElementType>
282 :
PropertyView<ElementType, true>(), _accessor{}, _size{0} {}
293 "An empty property view should not be constructed with a valid status");
307 int64_t size) noexcept
315 if (!classProperty.defaultProperty) {
342 _accessor{accessorView},
345 ? accessorView.size()
363 std::optional<NormalizedType>
get(int64_t index)
const noexcept {
366 return this->defaultValue();
369 ElementType value = getRaw(index);
371 if (value == this->noData()) {
372 return this->defaultValue();
383 constexpr glm::length_t N = ElementType::length();
384 using T =
typename ElementType::value_type;
385 using NormalizedT =
typename NormalizedType::value_type;
393 constexpr glm::length_t N = ElementType::length();
394 using T =
typename ElementType::value_type;
395 using NormalizedT =
typename NormalizedType::value_type;
413 ElementType
getRaw(int64_t index)
const noexcept {
416 "Check the status() first to make sure view is valid");
419 "Check the size() of the view to make sure it's not empty");
420 CESIUM_ASSERT(index >= 0 &&
"index must be non-negative");
421 CESIUM_ASSERT(index < size() &&
"index must be less than size");
423 return _accessor[index];
433 int64_t
size() const noexcept {
return _size; }
A view on the data of one accessor of a glTF asset.
Indicates the status of a property attribute property view.
static const int ErrorInvalidBufferView
This property view uses an accessor that does not have a valid buffer view index.
static const int ErrorInvalidBuffer
This property view uses a buffer view that does not have a valid buffer index.
static const int ErrorAccessorNormalizationMismatch
This property view's normalization does not match the normalization of the accessor it uses.
static const int ErrorInvalidAccessor
This property view's attribute does not have a valid accessor index.
static const int ErrorMissingAttribute
This property view was initialized with a primitive that does not contain the specified attribute.
static const int ErrorAccessorComponentTypeMismatch
This property view's component type does not match the type of the accessor it uses.
static const int ErrorUnsupportedProperty
This property view is associated with a ClassProperty of an unsupported type.
static const int ErrorAccessorTypeMismatch
This property view's type does not match the type of the accessor it uses.
static const int ErrorInvalidPropertyAttribute
This property view was initialized from an invalid PropertyAttribute.
static const PropertyViewStatusType ErrorAccessorOutOfBounds
This property view uses an accessor that points outside the bounds of its target buffer view.
static const PropertyViewStatusType ErrorBufferViewOutOfBounds
This property view uses a buffer view that points outside the bounds of its target buffer.
std::optional< ElementType > get(int64_t index) const noexcept
Gets the value of the property for the given vertex index with all value transforms applied....
PropertyAttributePropertyView(PropertyViewStatusType status) noexcept
Constructs an invalid instance for an erroneous property.
ElementType getRaw(int64_t index) const noexcept
Gets the raw value of the property for the given vertex index.
PropertyAttributePropertyView() noexcept
Constructs an invalid instance for a non-existent property.
PropertyAttributePropertyView(const ClassProperty &classProperty, int64_t size) noexcept
Constructs an instance of an empty property that specifies a default value. Although this property ha...
int64_t size() const noexcept
Get the number of elements in this PropertyAttributePropertyView. If the view is valid,...
PropertyAttributePropertyView(const PropertyAttributeProperty &property, const ClassProperty &classProperty, const AccessorView< ElementType > &accessorView) noexcept
Construct a view of the data specified by a PropertyAttributeProperty.
ElementType getRaw(int64_t index) const noexcept
Gets the raw value of the property for the given vertex index.
PropertyAttributePropertyView(const PropertyAttributeProperty &property, const ClassProperty &classProperty, const AccessorView< ElementType > &accessorView) noexcept
Construct a view of the data specified by a PropertyAttributeProperty.
int64_t size() const noexcept
Get the number of elements in this PropertyAttributePropertyView. If the view is valid,...
std::optional< NormalizedType > get(int64_t index) const noexcept
Gets the value of the property for the given vertex index with all value transforms applied....
PropertyAttributePropertyView(PropertyViewStatusType status) noexcept
Constructs an invalid instance for an erroneous property.
PropertyAttributePropertyView() noexcept
Constructs an invalid instance for a non-existent property.
PropertyAttributePropertyView(const ClassProperty &classProperty, int64_t size) noexcept
Constructs an instance of an empty property that specifies a default value. Although this property ha...
A view of the data specified by a PropertyAttributeProperty.
Indicates the status of a property view.
static const PropertyViewStatusType Valid
This property view is valid and ready to use.
static const PropertyViewStatusType ErrorNonexistentProperty
This property view is trying to view a property that does not exist.
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.
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...
int32_t PropertyViewStatusType
The type used for fields of PropertyViewStatus.
An attribute containing property values.
Convert an integer numeric type to the corresponding representation as a double type....