GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
quantize_points_3.h
Go to the documentation of this file.
1// Copyright 2016 The Draco Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15#ifndef DRACO_COMPRESSION_POINT_CLOUD_ALGORITHMS_QUANTIZE_POINTS_3_H_
16#define DRACO_COMPRESSION_POINT_CLOUD_ALGORITHMS_QUANTIZE_POINTS_3_H_
17
18#include <inttypes.h>
19
22
23namespace draco {
24
25// TODO(b/199760123): Make this a stable bounding box.
28 float range;
29};
30
31template <class PointIterator, class OutputIterator>
32OutputIterator QuantizePoints3(const PointIterator &begin,
33 const PointIterator &end, QuantizationInfo *info,
34 OutputIterator oit) {
35 DRACO_DCHECK_GE(info->quantization_bits, 0);
36
37 float max_range = 0;
38 for (auto it = begin; it != end; ++it) {
39 max_range = std::max(std::fabs((*it)[0]), max_range);
40 max_range = std::max(std::fabs((*it)[1]), max_range);
41 max_range = std::max(std::fabs((*it)[2]), max_range);
42 }
43
44 const uint32_t max_quantized_value((1u << info->quantization_bits) - 1);
45 Quantizer quantize;
46 quantize.Init(max_range, max_quantized_value);
47 info->range = max_range;
48
49 Point3ui qpoint;
50 for (auto it = begin; it != end; ++it) {
51 // Quantize and all positive.
52 qpoint[0] = quantize((*it)[0]) + max_quantized_value;
53 qpoint[1] = quantize((*it)[1]) + max_quantized_value;
54 qpoint[2] = quantize((*it)[2]) + max_quantized_value;
55 *oit++ = (qpoint);
56 }
57
58 return oit;
59}
60
61template <class QPointIterator, class OutputIterator>
62void DequantizePoints3(const QPointIterator &begin, const QPointIterator &end,
63 const QuantizationInfo &info, OutputIterator &oit) {
64 DRACO_DCHECK_GE(info.quantization_bits, 0);
65 DRACO_DCHECK_GE(info.range, 0);
66
67 const uint32_t quantization_bits = info.quantization_bits;
68 const float range = info.range;
69 const uint32_t max_quantized_value((1u << quantization_bits) - 1);
70 Dequantizer dequantize;
71 dequantize.Init(range, max_quantized_value);
72
73 for (auto it = begin; it != end; ++it) {
74 const float x = dequantize((*it)[0] - max_quantized_value);
75 const float y = dequantize((*it)[1] - max_quantized_value);
76 const float z = dequantize((*it)[2] - max_quantized_value);
77 *oit = Point3f(x, y, z);
78 ++oit;
79 }
80}
81
82} // namespace draco
83
84#endif // DRACO_COMPRESSION_POINT_CLOUD_ALGORITHMS_QUANTIZE_POINTS_3_H_
void info(std::string info)
Definition check.cc:24
Definition quantization_utils.h:59
bool Init(float range, int32_t max_quantized_value)
Definition quantization_utils.cc:29
Definition quantization_utils.h:42
void Init(float range, int32_t max_quantized_value)
Definition quantization_utils.cc:21
#define DRACO_DCHECK_GE(a, b)
Definition macros.h:83
Definition attribute_octahedron_transform.cc:21
void DequantizePoints3(const QPointIterator &begin, const QPointIterator &end, const QuantizationInfo &info, OutputIterator &oit)
Definition quantize_points_3.h:62
OutputIterator QuantizePoints3(const PointIterator &begin, const PointIterator &end, QuantizationInfo *info, OutputIterator oit)
Definition quantize_points_3.h:32
Vector3ui Point3ui
Definition point_cloud_types.h:29
Vector3f Point3f
Definition point_cloud_types.h:27
Definition quantize_points_3.h:26
float range
Definition quantize_points_3.h:28
uint32_t quantization_bits
Definition quantize_points_3.h:27