GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
mesh_edgebreaker_traversal_decoder.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_MESH_MESH_EDGEBREAKER_TRAVERSAL_DECODER_H_
16#define DRACO_COMPRESSION_MESH_MESH_EDGEBREAKER_TRAVERSAL_DECODER_H_
17
23
24namespace draco {
25
27
28// Default implementation of the edgebreaker traversal decoder that reads the
29// traversal data directly from a buffer.
31 public:
33 : attribute_connectivity_decoders_(nullptr),
34 num_attribute_data_(0),
35 decoder_impl_(nullptr) {}
37 decoder_impl_ = decoder;
38 buffer_.Init(decoder->GetDecoder()->buffer()->data_head(),
39 decoder->GetDecoder()->buffer()->remaining_size(),
40 decoder->GetDecoder()->buffer()->bitstream_version());
41 }
42
43 // Returns the Draco bitstream version.
44 uint16_t BitstreamVersion() const {
45 return decoder_impl_->GetDecoder()->bitstream_version();
46 }
47
48 // Used to tell the decoder what is the number of expected decoded vertices.
49 // Ignored by default.
50 void SetNumEncodedVertices(int /* num_vertices */) {}
51
52 // Set the number of non-position attribute data for which we need to decode
53 // the connectivity.
54 void SetNumAttributeData(int num_data) { num_attribute_data_ = num_data; }
55
56 // Called before the traversal decoding is started.
57 // Returns a buffer decoder that points to data that was encoded after the
58 // traversal.
59 bool Start(DecoderBuffer *out_buffer) {
60 // Decode symbols from the main buffer decoder and face configurations from
61 // the start_face_buffer decoder.
63 return false;
64 }
65
66 if (!DecodeStartFaces()) {
67 return false;
68 }
69
70 if (!DecodeAttributeSeams()) {
71 return false;
72 }
73 *out_buffer = buffer_;
74 return true;
75 }
76
77 // Returns the configuration of a new initial face.
79 uint32_t face_configuration;
80#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
81 if (buffer_.bitstream_version() < DRACO_BITSTREAM_VERSION(2, 2)) {
82 start_face_buffer_.DecodeLeastSignificantBits32(1, &face_configuration);
83
84 } else
85#endif
86 {
87 face_configuration = start_face_decoder_.DecodeNextBit();
88 }
89 return face_configuration;
90 }
91
92 // Returns the next edgebreaker symbol that was reached during the traversal.
93 inline uint32_t DecodeSymbol() {
94 uint32_t symbol;
95 symbol_buffer_.DecodeLeastSignificantBits32(1, &symbol);
96 if (symbol == TOPOLOGY_C) {
97 return symbol;
98 }
99 // Else decode two additional bits.
100 uint32_t symbol_suffix;
101 symbol_buffer_.DecodeLeastSignificantBits32(2, &symbol_suffix);
102 symbol |= (symbol_suffix << 1);
103 return symbol;
104 }
105
106 // Called whenever a new active corner is set in the decoder.
107 inline void NewActiveCornerReached(CornerIndex /* corner */) {}
108
109 // Called whenever |source| vertex is about to be merged into the |dest|
110 // vertex.
111 inline void MergeVertices(VertexIndex /* dest */, VertexIndex /* source */) {}
112
113 // Returns true if there is an attribute seam for the next processed pair
114 // of visited faces.
115 // |attribute| is used to mark the id of the non-position attribute (in range
116 // of <0, num_attributes - 1>).
117 inline bool DecodeAttributeSeam(int attribute) {
118 return attribute_connectivity_decoders_[attribute].DecodeNextBit();
119 }
120
121 // Called when the traversal is finished.
122 void Done() {
123 if (symbol_buffer_.bit_decoder_active()) {
124 symbol_buffer_.EndBitDecoding();
125 }
126#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
127 if (buffer_.bitstream_version() < DRACO_BITSTREAM_VERSION(2, 2)) {
128 start_face_buffer_.EndBitDecoding();
129
130 } else
131#endif
132 {
133 start_face_decoder_.EndDecoding();
134 }
135 }
136
137 protected:
138 DecoderBuffer *buffer() { return &buffer_; }
139
141 uint64_t traversal_size;
142 symbol_buffer_ = buffer_;
143 if (!symbol_buffer_.StartBitDecoding(true, &traversal_size)) {
144 return false;
145 }
146 buffer_ = symbol_buffer_;
147 if (traversal_size > static_cast<uint64_t>(buffer_.remaining_size())) {
148 return false;
149 }
150 buffer_.Advance(traversal_size);
151 return true;
152 }
153
155 // Create a decoder that is set to the end of the encoded traversal data.
156#ifdef DRACO_BACKWARDS_COMPATIBILITY_SUPPORTED
157 if (buffer_.bitstream_version() < DRACO_BITSTREAM_VERSION(2, 2)) {
158 start_face_buffer_ = buffer_;
159 uint64_t traversal_size;
160 if (!start_face_buffer_.StartBitDecoding(true, &traversal_size)) {
161 return false;
162 }
163 buffer_ = start_face_buffer_;
164 if (traversal_size > static_cast<uint64_t>(buffer_.remaining_size())) {
165 return false;
166 }
167 buffer_.Advance(traversal_size);
168 return true;
169 }
170#endif
171 return start_face_decoder_.StartDecoding(&buffer_);
172 }
173
175 // Prepare attribute decoding.
176 if (num_attribute_data_ > 0) {
177 attribute_connectivity_decoders_ = std::unique_ptr<BinaryDecoder[]>(
178 new BinaryDecoder[num_attribute_data_]);
179 for (int i = 0; i < num_attribute_data_; ++i) {
180 if (!attribute_connectivity_decoders_[i].StartDecoding(&buffer_)) {
181 return false;
182 }
183 }
184 }
185 return true;
186 }
187
188 private:
189 // Buffer that contains the encoded data.
190 DecoderBuffer buffer_;
191 DecoderBuffer symbol_buffer_;
192 BinaryDecoder start_face_decoder_;
193 DecoderBuffer start_face_buffer_;
194 std::unique_ptr<BinaryDecoder[]> attribute_connectivity_decoders_;
195 int num_attribute_data_;
196 const MeshEdgebreakerDecoderImplInterface *decoder_impl_;
197};
198
199} // namespace draco
200
201#endif // DRACO_COMPRESSION_MESH_MESH_EDGEBREAKER_TRAVERSAL_DECODER_H_
Definition decoder_buffer.h:30
const char * data_head() const
Definition decoder_buffer.h:114
uint16_t bitstream_version() const
Definition decoder_buffer.h:120
int64_t remaining_size() const
Definition decoder_buffer.h:115
Definition mesh_edgebreaker_decoder_impl_interface.h:28
virtual bool Init(MeshEdgebreakerDecoder *decoder)=0
virtual MeshEdgebreakerDecoder * GetDecoder() const =0
void SetNumAttributeData(int num_data)
Definition mesh_edgebreaker_traversal_decoder.h:54
MeshEdgebreakerTraversalDecoder()
Definition mesh_edgebreaker_traversal_decoder.h:32
uint32_t DecodeSymbol()
Definition mesh_edgebreaker_traversal_decoder.h:93
void Init(MeshEdgebreakerDecoderImplInterface *decoder)
Definition mesh_edgebreaker_traversal_decoder.h:36
void MergeVertices(VertexIndex, VertexIndex)
Definition mesh_edgebreaker_traversal_decoder.h:111
bool DecodeAttributeSeams()
Definition mesh_edgebreaker_traversal_decoder.h:174
bool DecodeTraversalSymbols()
Definition mesh_edgebreaker_traversal_decoder.h:140
void Done()
Definition mesh_edgebreaker_traversal_decoder.h:122
void SetNumEncodedVertices(int)
Definition mesh_edgebreaker_traversal_decoder.h:50
bool DecodeAttributeSeam(int attribute)
Definition mesh_edgebreaker_traversal_decoder.h:117
DecoderBuffer * buffer()
Definition mesh_edgebreaker_traversal_decoder.h:138
uint16_t BitstreamVersion() const
Definition mesh_edgebreaker_traversal_decoder.h:44
bool DecodeStartFaces()
Definition mesh_edgebreaker_traversal_decoder.h:154
bool DecodeStartFaceConfiguration()
Definition mesh_edgebreaker_traversal_decoder.h:78
void NewActiveCornerReached(CornerIndex)
Definition mesh_edgebreaker_traversal_decoder.h:107
bool Start(DecoderBuffer *out_buffer)
Definition mesh_edgebreaker_traversal_decoder.h:59
DecoderBuffer * buffer()
Definition point_cloud_decoder.h:79
Definition rans_bit_decoder.h:28
#define DRACO_BITSTREAM_VERSION(MAJOR, MINOR)
Definition macros.h:114
Definition attribute_octahedron_transform.cc:21
VertexIndex VertexIndex
Definition mesh_edgebreaker_encoder_impl.cc:37
RAnsBitDecoder BinaryDecoder
Definition mesh_edgebreaker_traversal_decoder.h:26
CornerIndex CornerIndex
Definition mesh_edgebreaker_encoder_impl.cc:35
@ TOPOLOGY_C
Definition mesh_edgebreaker_shared.h:54