GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
float_points_tree_encoder.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_FLOAT_POINTS_TREE_ENCODER_H_
16#define DRACO_COMPRESSION_POINT_CLOUD_ALGORITHMS_FLOAT_POINTS_TREE_ENCODER_H_
17
18#include <memory>
19#include <vector>
20
25
26namespace draco {
27
28// This class encodes a given point cloud based on the point cloud compression
29// algorithm in:
30// Olivier Devillers and Pierre-Marie Gandoin
31// "Geometric compression for interactive transmission"
32//
33// In principle the algorithm keeps on splitting the point cloud in the middle
34// while alternating the axes. For 3D this results in an Octree like structure.
35// In each step we encode the number of points in the first half.
36// The algorithm uses quantization and does not preserve the order of points.
37//
38// However, the algorithm here differs from the original as follows:
39// The algorithm keeps on splitting the point cloud in the middle of the axis
40// that keeps the point cloud as clustered as possible, which gives a better
41// compression rate.
42// The number of points is encode by the deviation from the half of the points
43// in the smaller half of the two. This results in a better compression rate as
44// there are more leading zeros, which is then compressed better by the
45// arithmetic encoding.
46
47// TODO(b/199760123): Remove class because it duplicates quantization code.
49 public:
52 uint32_t quantization_bits,
53 uint32_t compression_level);
54
55 template <class InputIteratorT>
56 bool EncodePointCloud(InputIteratorT points_begin, InputIteratorT points_end);
57 EncoderBuffer *buffer() { return &buffer_; }
58
59 uint32_t version() const { return version_; }
60 uint32_t quantization_bits() const { return qinfo_.quantization_bits; }
61 uint32_t &quantization_bits() { return qinfo_.quantization_bits; }
62 uint32_t compression_level() const { return compression_level_; }
63 uint32_t &compression_level() { return compression_level_; }
64 float range() const { return qinfo_.range; }
65 uint32_t num_points() const { return num_points_; }
66 std::string identification_string() const {
67 if (method_ == KDTREE) {
68 return "FloatPointsTreeEncoder: IntegerPointsKDTreeEncoder";
69 } else {
70 return "FloatPointsTreeEncoder: Unsupported Method";
71 }
72 }
73
74 private:
75 void Clear() { buffer_.Clear(); }
76 bool EncodePointCloudKdTreeInternal(std::vector<Point3ui> *qpoints);
77
78 static const uint32_t version_;
79 QuantizationInfo qinfo_;
81 uint32_t num_points_;
82 EncoderBuffer buffer_;
83 uint32_t compression_level_;
84};
85
86template <class InputIteratorT>
87bool FloatPointsTreeEncoder::EncodePointCloud(InputIteratorT points_begin,
88 InputIteratorT points_end) {
89 Clear();
90
91 // Collect necessary data for encoding.
92 num_points_ = std::distance(points_begin, points_end);
93
94 // TODO(b/199760123): Extend quantization tools to make this more automatic.
95 // Compute range of points for quantization
96 std::vector<Point3ui> qpoints;
97 qpoints.reserve(num_points_);
98 QuantizePoints3(points_begin, points_end, &qinfo_,
99 std::back_inserter(qpoints));
100
101 // Encode header.
102 buffer()->Encode(version_);
103 buffer()->Encode(static_cast<int8_t>(method_));
104 buffer()->Encode(qinfo_.quantization_bits);
105 buffer()->Encode(qinfo_.range);
106 buffer()->Encode(num_points_);
107
108 if (method_ == KDTREE) {
109 buffer()->Encode(compression_level_);
110 }
111
112 if (num_points_ == 0) {
113 return true;
114 }
115
116 if (method_ == KDTREE) {
117 return EncodePointCloudKdTreeInternal(&qpoints);
118 } else { // Unsupported method.
119 fprintf(stderr, "Method not supported. \n");
120 return false;
121 }
122}
123
124} // namespace draco
125
126#endif // DRACO_COMPRESSION_POINT_CLOUD_ALGORITHMS_FLOAT_POINTS_TREE_ENCODER_H_
Definition encoder_buffer.h:29
void Clear()
Definition encoder_buffer.cc:26
bool Encode(const T &data)
Definition encoder_buffer.h:60
EncoderBuffer * buffer()
Definition float_points_tree_encoder.h:57
uint32_t version() const
Definition float_points_tree_encoder.h:59
uint32_t compression_level() const
Definition float_points_tree_encoder.h:62
std::string identification_string() const
Definition float_points_tree_encoder.h:66
uint32_t num_points() const
Definition float_points_tree_encoder.h:65
float range() const
Definition float_points_tree_encoder.h:64
uint32_t & quantization_bits()
Definition float_points_tree_encoder.h:61
FloatPointsTreeEncoder(PointCloudCompressionMethod method)
Definition float_points_tree_encoder.cc:29
uint32_t quantization_bits() const
Definition float_points_tree_encoder.h:60
bool EncodePointCloud(InputIteratorT points_begin, InputIteratorT points_end)
Definition float_points_tree_encoder.h:87
uint32_t & compression_level()
Definition float_points_tree_encoder.h:63
Definition attribute_octahedron_transform.cc:21
PointCloudCompressionMethod
Definition point_cloud_compression_method.h:21
@ KDTREE
Definition point_cloud_compression_method.h:27
OutputIterator QuantizePoints3(const PointIterator &begin, const PointIterator &end, QuantizationInfo *info, OutputIterator oit)
Definition quantize_points_3.h:32