3#include "CesiumGltf/PropertyArrayView.h"
4#include "CesiumGltf/PropertyTypeTraits.h"
6#include <glm/common.hpp>
20 constexpr double max =
static_cast<double>(std::numeric_limits<T>::max());
21 if constexpr (std::is_signed_v<T>) {
22 return std::max(
static_cast<double>(value) / max, -1.0);
24 return static_cast<double>(value) / max;
34template <glm::length_t N,
typename T>
35glm::vec<N, double>
normalize(glm::vec<N, T> value) {
36 constexpr double max =
static_cast<double>(std::numeric_limits<T>::max());
37 if constexpr (std::is_signed_v<T>) {
38 return glm::max(
static_cast<glm::vec<N, double>
>(value) / max, -1.0);
40 return static_cast<glm::vec<N, double>
>(value) / max;
50template <glm::length_t N,
typename T>
51glm::mat<N, N, double>
normalize(glm::mat<N, N, T> value) {
52 constexpr double max =
static_cast<double>(std::numeric_limits<T>::max());
54 glm::mat<N, N, double> result;
55 for (glm::length_t i = 0; i < N; i++) {
56 for (glm::length_t j = 0; j < N; j++) {
57 if constexpr (std::is_signed_v<T>) {
58 result[i][j] = glm::max(
static_cast<double>(value[i][j]) / max, -1.0);
60 result[i][j] =
static_cast<double>(value[i][j]) / max;
73template <
typename T> T
applyScale(
const T& value,
const T& scale) {
78 constexpr glm::length_t N = T::length();
79 for (glm::length_t i = 0; i < N; i++) {
80 matN[i] = value[i] * scale[i];
100 const std::optional<T>& offset,
101 const std::optional<T>& scale) {
130 std::vector<T> result(
static_cast<size_t>(value.
size()));
131 for (int64_t i = 0; i < value.
size(); i++) {
132 result[i] = value[i];
139 result[i] = result[i] + (*offset)[i];
160 typename NormalizedType =
typename TypeToNormalizedType<T>::type>
165 std::vector<NormalizedType> result(
static_cast<size_t>(value.
size()));
166 for (int64_t i = 0; i < value.
size(); i++) {
170 result[i] = result[i] * (*scale)[i];
174 result[i] = result[i] + (*offset)[i];
192template <glm::length_t N,
typename T>
197 std::vector<glm::vec<N, double>> result(
static_cast<size_t>(value.size()));
198 for (int64_t i = 0; i < value.size(); i++) {
202 result[i] = result[i] * (*scale)[i];
206 result[i] = result[i] + (*offset)[i];
224template <glm::length_t N,
typename T>
229 std::vector<glm::mat<N, N, double>> result(
static_cast<size_t>(value.size()));
230 for (int64_t i = 0; i < value.size(); i++) {
238 result[i] = result[i] + (*offset)[i];
A copy of an array element of a PropertyTableProperty or PropertyTextureProperty.
A view on an array element of a PropertyTableProperty or PropertyTextureProperty.
int64_t size() const noexcept
The number of elements in this array.
Classes for working with glTF models.
T applyScale(const T &value, const T &scale)
Multiplies each component of the value by the given scale factor.
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...
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....