Differential D9642 Diff 31360 extern/draco/draco/src/draco/compression/attributes/normal_compression_utils.h
Changeset View
Changeset View
Standalone View
Standalone View
extern/draco/draco/src/draco/compression/attributes/normal_compression_utils.h
- This file was moved from extern/draco/dracoenc/src/draco/compression/attributes/normal_compression_utils.h.
| Show All 33 Lines | |||||
| // Note that the parameter space is somewhat periodic, e.g. (0, 0) == | // Note that the parameter space is somewhat periodic, e.g. (0, 0) == | ||||
| // (max_value, max_value), which is also why the diamond is one smaller than the | // (max_value, max_value), which is also why the diamond is one smaller than the | ||||
| // maximal representable value in order to have an odd range of values. | // maximal representable value in order to have an odd range of values. | ||||
| #ifndef DRACO_COMPRESSION_ATTRIBUTES_NORMAL_COMPRESSION_UTILS_H_ | #ifndef DRACO_COMPRESSION_ATTRIBUTES_NORMAL_COMPRESSION_UTILS_H_ | ||||
| #define DRACO_COMPRESSION_ATTRIBUTES_NORMAL_COMPRESSION_UTILS_H_ | #define DRACO_COMPRESSION_ATTRIBUTES_NORMAL_COMPRESSION_UTILS_H_ | ||||
| #include <inttypes.h> | #include <inttypes.h> | ||||
| #include <algorithm> | #include <algorithm> | ||||
| #include <cmath> | #include <cmath> | ||||
| #include "draco/core/macros.h" | #include "draco/core/macros.h" | ||||
| namespace draco { | namespace draco { | ||||
| class OctahedronToolBox { | class OctahedronToolBox { | ||||
| public: | public: | ||||
| OctahedronToolBox() | OctahedronToolBox() | ||||
| : quantization_bits_(-1), | : quantization_bits_(-1), | ||||
| max_quantized_value_(-1), | max_quantized_value_(-1), | ||||
| max_value_(-1), | max_value_(-1), | ||||
| center_value_(-1) {} | center_value_(-1) {} | ||||
| bool SetQuantizationBits(int32_t q) { | bool SetQuantizationBits(int32_t q) { | ||||
| if (q < 2 || q > 30) | if (q < 2 || q > 30) { | ||||
| return false; | return false; | ||||
| } | |||||
| quantization_bits_ = q; | quantization_bits_ = q; | ||||
| max_quantized_value_ = (1 << quantization_bits_) - 1; | max_quantized_value_ = (1 << quantization_bits_) - 1; | ||||
| max_value_ = max_quantized_value_ - 1; | max_value_ = max_quantized_value_ - 1; | ||||
| center_value_ = max_value_ / 2; | center_value_ = max_value_ / 2; | ||||
| return true; | return true; | ||||
| } | } | ||||
| bool IsInitialized() const { return quantization_bits_ != -1; } | bool IsInitialized() const { return quantization_bits_ != -1; } | ||||
| ▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | if (int_vec[2] < 0) { | ||||
| if (int_vec[1] > 0) { | if (int_vec[1] > 0) { | ||||
| int_vec[1] += int_vec[2]; | int_vec[1] += int_vec[2]; | ||||
| } else { | } else { | ||||
| int_vec[1] -= int_vec[2]; | int_vec[1] -= int_vec[2]; | ||||
| } | } | ||||
| int_vec[2] = 0; | int_vec[2] = 0; | ||||
| } | } | ||||
| // Take care of the sign. | // Take care of the sign. | ||||
| if (scaled_vector[2] < 0) | if (scaled_vector[2] < 0) { | ||||
| int_vec[2] *= -1; | int_vec[2] *= -1; | ||||
| } | |||||
| IntegerVectorToQuantizedOctahedralCoords(int_vec, out_s, out_t); | IntegerVectorToQuantizedOctahedralCoords(int_vec, out_s, out_t); | ||||
| } | } | ||||
| // Normalize |vec| such that its abs sum is equal to the center value; | // Normalize |vec| such that its abs sum is equal to the center value; | ||||
| template <class T> | template <class T> | ||||
| void CanonicalizeIntegerVector(T *vec) const { | void CanonicalizeIntegerVector(T *vec) const { | ||||
| static_assert(std::is_integral<T>::value, "T must be an integral type."); | static_assert(std::is_integral<T>::value, "T must be an integral type."); | ||||
| Show All 14 Lines | if (abs_sum == 0) { | ||||
| if (vec[2] >= 0) { | if (vec[2] >= 0) { | ||||
| vec[2] = center_value_ - std::abs(vec[0]) - std::abs(vec[1]); | vec[2] = center_value_ - std::abs(vec[0]) - std::abs(vec[1]); | ||||
| } else { | } else { | ||||
| vec[2] = -(center_value_ - std::abs(vec[0]) - std::abs(vec[1])); | vec[2] = -(center_value_ - std::abs(vec[0]) - std::abs(vec[1])); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| // TODO(b/149328891): Change function to not use templates as |T| is only | |||||
| // float. | |||||
| template <typename T> | template <typename T> | ||||
| void OctaherdalCoordsToUnitVector(T in_s, T in_t, T *out_vector) const { | void OctaherdalCoordsToUnitVector(T in_s, T in_t, T *out_vector) const { | ||||
| DRACO_DCHECK_GE(in_s, 0); | DRACO_DCHECK_GE(in_s, 0); | ||||
| DRACO_DCHECK_GE(in_t, 0); | DRACO_DCHECK_GE(in_t, 0); | ||||
| DRACO_DCHECK_LE(in_s, 1); | DRACO_DCHECK_LE(in_s, 1); | ||||
| DRACO_DCHECK_LE(in_t, 1); | DRACO_DCHECK_LE(in_t, 1); | ||||
| T s = in_s; | T s = in_s; | ||||
| T t = in_t; | T t = in_t; | ||||
| ▲ Show 20 Lines • Show All 99 Lines • ▼ Show 20 Lines | void InvertDirection(int32_t *s, int32_t *t) const { | ||||
| DRACO_DCHECK_GE(*t, -center_value_); | DRACO_DCHECK_GE(*t, -center_value_); | ||||
| *s *= -1; | *s *= -1; | ||||
| *t *= -1; | *t *= -1; | ||||
| this->InvertDiamond(s, t); | this->InvertDiamond(s, t); | ||||
| } | } | ||||
| // For correction values. | // For correction values. | ||||
| int32_t ModMax(int32_t x) const { | int32_t ModMax(int32_t x) const { | ||||
| if (x > this->center_value()) | if (x > this->center_value()) { | ||||
| return x - this->max_quantized_value(); | return x - this->max_quantized_value(); | ||||
| if (x < -this->center_value()) | } | ||||
| if (x < -this->center_value()) { | |||||
| return x + this->max_quantized_value(); | return x + this->max_quantized_value(); | ||||
| } | |||||
| return x; | return x; | ||||
| } | } | ||||
| // For correction values. | // For correction values. | ||||
| int32_t MakePositive(int32_t x) const { | int32_t MakePositive(int32_t x) const { | ||||
| DRACO_DCHECK_LE(x, this->center_value() * 2); | DRACO_DCHECK_LE(x, this->center_value() * 2); | ||||
| if (x < 0) | if (x < 0) { | ||||
| return x + this->max_quantized_value(); | return x + this->max_quantized_value(); | ||||
| } | |||||
| return x; | return x; | ||||
| } | } | ||||
| int32_t quantization_bits() const { return quantization_bits_; } | int32_t quantization_bits() const { return quantization_bits_; } | ||||
| int32_t max_quantized_value() const { return max_quantized_value_; } | int32_t max_quantized_value() const { return max_quantized_value_; } | ||||
| int32_t max_value() const { return max_value_; } | int32_t max_value() const { return max_value_; } | ||||
| int32_t center_value() const { return center_value_; } | int32_t center_value() const { return center_value_; } | ||||
| Show All 9 Lines | |||||