38#ifndef DRACO_COMPRESSION_ATTRIBUTES_NORMAL_COMPRESSION_UTILS_H_
39#define DRACO_COMPRESSION_ATTRIBUTES_NORMAL_COMPRESSION_UTILS_H_
53 : quantization_bits_(-1),
54 max_quantized_value_(-1),
56 dequantization_scale_(1.f),
60 if (q < 2 || q > 30) {
63 quantization_bits_ = q;
64 max_quantized_value_ = (1u << quantization_bits_) - 1;
65 max_value_ = max_quantized_value_ - 1;
66 dequantization_scale_ = 2.f / max_value_;
67 center_value_ = max_value_ / 2;
76 int32_t *out_t)
const {
77 if ((s == 0 && t == 0) || (s == 0 && t == max_value_) ||
78 (s == max_value_ && t == 0)) {
81 }
else if (s == 0 && t > center_value_) {
82 t = center_value_ - (t - center_value_);
83 }
else if (s == max_value_ && t < center_value_) {
84 t = center_value_ + (center_value_ - t);
85 }
else if (t == max_value_ && s < center_value_) {
86 s = center_value_ + (center_value_ - s);
87 }
else if (t == 0 && s > center_value_) {
88 s = center_value_ - (s - center_value_);
99 int32_t *out_t)
const {
101 std::abs(int_vec[0]) + std::abs(int_vec[1]) + std::abs(int_vec[2]),
104 if (int_vec[0] >= 0) {
106 s = (int_vec[1] + center_value_);
107 t = (int_vec[2] + center_value_);
110 if (int_vec[1] < 0) {
111 s = std::abs(int_vec[2]);
113 s = (max_value_ - std::abs(int_vec[2]));
115 if (int_vec[2] < 0) {
116 t = std::abs(int_vec[1]);
118 t = (max_value_ - std::abs(int_vec[1]));
126 int32_t *out_t)
const {
127 const double abs_sum = std::abs(
static_cast<double>(vector[0])) +
128 std::abs(
static_cast<double>(vector[1])) +
129 std::abs(
static_cast<double>(vector[2]));
132 double scaled_vector[3];
133 if (abs_sum > 1
e-6) {
135 const double scale = 1.0 / abs_sum;
136 scaled_vector[0] = vector[0] * scale;
137 scaled_vector[1] = vector[1] * scale;
138 scaled_vector[2] = vector[2] * scale;
140 scaled_vector[0] = 1.0;
141 scaled_vector[1] = 0;
142 scaled_vector[2] = 0;
148 static_cast<int32_t
>(
floor(scaled_vector[0] * center_value_ + 0.5));
150 static_cast<int32_t
>(
floor(scaled_vector[1] * center_value_ + 0.5));
152 int_vec[2] = center_value_ - std::abs(int_vec[0]) - std::abs(int_vec[1]);
153 if (int_vec[2] < 0) {
156 if (int_vec[1] > 0) {
157 int_vec[1] += int_vec[2];
159 int_vec[1] -= int_vec[2];
164 if (scaled_vector[2] < 0) {
174 static_assert(std::is_integral<T>::value,
"T must be an integral type.");
175 static_assert(std::is_signed<T>::value,
"T must be a signed type.");
176 const int64_t abs_sum =
static_cast<int64_t
>(std::abs(vec[0])) +
177 static_cast<int64_t
>(std::abs(vec[1])) +
178 static_cast<int64_t
>(std::abs(vec[2]));
181 vec[0] = center_value_;
184 (
static_cast<int64_t
>(vec[0]) *
static_cast<int64_t
>(center_value_)) /
187 (
static_cast<int64_t
>(vec[1]) *
static_cast<int64_t
>(center_value_)) /
190 vec[2] = center_value_ - std::abs(vec[0]) - std::abs(vec[1]);
192 vec[2] = -(center_value_ - std::abs(vec[0]) - std::abs(vec[1]));
198 float *out_vector)
const {
199 OctahedralCoordsToUnitVector(in_s * dequantization_scale_ - 1.f,
200 in_t * dequantization_scale_ - 1.f,
205 inline bool IsInDiamond(
const int32_t &s,
const int32_t &t)
const {
212 static_cast<uint32_t
>(std::abs(s)) +
static_cast<uint32_t
>(std::abs(t));
213 return st <= center_value_;
224 if (*s >= 0 && *t >= 0) {
227 }
else if (*s <= 0 && *t <= 0) {
231 sign_s = (*s > 0) ? 1 : -1;
232 sign_t = (*t > 0) ? 1 : -1;
238 const uint32_t corner_point_s = sign_s * center_value_;
239 const uint32_t corner_point_t = sign_t * center_value_;
242 us = us + us - corner_point_s;
243 ut = ut + ut - corner_point_t;
244 if (sign_s * sign_t >= 0) {
251 us = us + corner_point_s;
252 ut = ut + corner_point_t;
297 inline void OctahedralCoordsToUnitVector(
float in_s_scaled,
float in_t_scaled,
298 float *out_vector)
const {
328 float y = in_s_scaled;
329 float z = in_t_scaled;
333 const float x = 1.f - std::abs(y) - std::abs(z);
342 x_offset = x_offset < 0 ? 0 : x_offset;
347 y += y < 0 ? x_offset : -x_offset;
348 z += z < 0 ? x_offset : -x_offset;
351 const float norm_squared = x * x + y * y + z * z;
352 if (norm_squared < 1
e-6) {
357 const float d = 1.0f / std::sqrt(norm_squared);
358 out_vector[0] = x *
d;
359 out_vector[1] = y *
d;
360 out_vector[2] = z *
d;
364 int32_t quantization_bits_;
365 int32_t max_quantized_value_;
367 float dequantization_scale_;
368 int32_t center_value_;
Env e
Definition Common.cc:2
void floor(const FCube &pos, FLine &l1, FLine &l2, FLine &l3, FLine &l4, FPlane &pl, FaceStore &s)
Definition Functions.cc:95
#define DRACO_DCHECK_EQ(a, b)
Definition macros.h:81
#define DRACO_DCHECK_LE(a, b)
Definition macros.h:85
#define DRACO_DCHECK_GE(a, b)
Definition macros.h:83
d
Definition meshpage.php:3895
Definition attribute_octahedron_transform.cc:21