GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
mesh_edgebreaker_traversal_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_MESH_MESH_EDGEBREAKER_TRAVERSAL_ENCODER_H_
16#define DRACO_COMPRESSION_MESH_MESH_EDGEBREAKER_TRAVERSAL_ENCODER_H_
17
21#include "draco/core/macros.h"
22
23namespace draco {
24
26
27// Default implementation of the edgebreaker traversal encoder. Face
28// configurations are stored directly into the output buffer and the symbols
29// are first collected and then encoded in the reverse order to make the
30// decoding faster.
32 public:
34 : encoder_impl_(nullptr),
35 attribute_connectivity_encoders_(nullptr),
36 num_attribute_data_(0) {}
38 encoder_impl_ = encoder;
39 return true;
40 }
41
42 // Set the number of non-position attribute data for which we need to encode
43 // the connectivity.
44 void SetNumAttributeData(int num_data) { num_attribute_data_ = num_data; }
45
46 // Called before the traversal encoding is started.
47 void Start() {
48 start_face_encoder_.StartEncoding();
49 if (num_attribute_data_ > 0) {
50 // Init and start arithmetic encoders for storing configuration types
51 // of non-position attributes.
52 attribute_connectivity_encoders_ = std::unique_ptr<BinaryEncoder[]>(
53 new BinaryEncoder[num_attribute_data_]);
54 for (int i = 0; i < num_attribute_data_; ++i) {
55 attribute_connectivity_encoders_[i].StartEncoding();
56 }
57 }
58 }
59
60 // Called when a traversal starts from a new initial face.
61 inline void EncodeStartFaceConfiguration(bool interior) {
62 start_face_encoder_.EncodeBit(interior);
63 }
64
65 // Called when a new corner is reached during the traversal. No-op for the
66 // default encoder.
67 inline void NewCornerReached(CornerIndex /* corner */) {}
68
69 // Called whenever a new symbol is reached during the edgebreaker traversal.
71 // Store the symbol. It will be encoded after all symbols are processed.
72 symbols_.push_back(symbol);
73 }
74
75 // Called for every pair of connected and visited faces. |is_seam| specifies
76 // whether there is an attribute seam between the two faces.
77
78 inline void EncodeAttributeSeam(int attribute, bool is_seam) {
79 attribute_connectivity_encoders_[attribute].EncodeBit(is_seam ? 1 : 0);
80 }
81
82 // Called when the traversal is finished.
88
89 // Returns the number of encoded symbols.
90 int NumEncodedSymbols() const { return static_cast<int>(symbols_.size()); }
91
92 const EncoderBuffer &buffer() const { return traversal_buffer_; }
93
94 protected:
96 // Bit encode the collected symbols.
97 // Allocate enough storage for the bit encoder.
98 // It's guaranteed that each face will need only up to 3 bits.
99 traversal_buffer_.StartBitEncoding(
100 encoder_impl_->GetEncoder()->mesh()->num_faces() * 3, true);
101 for (int i = static_cast<int>(symbols_.size() - 1); i >= 0; --i) {
102 traversal_buffer_.EncodeLeastSignificantBits32(
103 edge_breaker_topology_bit_pattern_length[symbols_[i]], symbols_[i]);
104 }
105 traversal_buffer_.EndBitEncoding();
106 }
107
109 start_face_encoder_.EndEncoding(&traversal_buffer_);
110 }
111
113 if (attribute_connectivity_encoders_ != nullptr) {
114 for (int i = 0; i < num_attribute_data_; ++i) {
115 attribute_connectivity_encoders_[i].EndEncoding(&traversal_buffer_);
116 }
117 }
118 }
119
120 EncoderBuffer *GetOutputBuffer() { return &traversal_buffer_; }
122 return encoder_impl_;
123 }
124
125 private:
126 BinaryEncoder start_face_encoder_;
127 EncoderBuffer traversal_buffer_;
128 const MeshEdgebreakerEncoderImplInterface *encoder_impl_;
129 // Symbols collected during the traversal.
130 std::vector<EdgebreakerTopologyBitPattern> symbols_;
131 // Arithmetic encoder for encoding attribute seams.
132 // One context for each non-position attribute.
133 std::unique_ptr<BinaryEncoder[]> attribute_connectivity_encoders_;
134 int num_attribute_data_;
135};
136
137} // namespace draco
138
139#endif // DRACO_COMPRESSION_MESH_MESH_EDGEBREAKER_TRAVERSAL_ENCODER_H_
Definition encoder_buffer.h:29
Definition mesh_edgebreaker_encoder_impl_interface.h:33
const EncoderBuffer & buffer() const
Definition mesh_edgebreaker_traversal_encoder.h:92
void Done()
Definition mesh_edgebreaker_traversal_encoder.h:83
void SetNumAttributeData(int num_data)
Definition mesh_edgebreaker_traversal_encoder.h:44
void Start()
Definition mesh_edgebreaker_traversal_encoder.h:47
EncoderBuffer * GetOutputBuffer()
Definition mesh_edgebreaker_traversal_encoder.h:120
const MeshEdgebreakerEncoderImplInterface * encoder_impl() const
Definition mesh_edgebreaker_traversal_encoder.h:121
MeshEdgebreakerTraversalEncoder()
Definition mesh_edgebreaker_traversal_encoder.h:33
void EncodeStartFaces()
Definition mesh_edgebreaker_traversal_encoder.h:108
void EncodeAttributeSeam(int attribute, bool is_seam)
Definition mesh_edgebreaker_traversal_encoder.h:78
int NumEncodedSymbols() const
Definition mesh_edgebreaker_traversal_encoder.h:90
bool Init(MeshEdgebreakerEncoderImplInterface *encoder)
Definition mesh_edgebreaker_traversal_encoder.h:37
void EncodeSymbol(EdgebreakerTopologyBitPattern symbol)
Definition mesh_edgebreaker_traversal_encoder.h:70
void EncodeStartFaceConfiguration(bool interior)
Definition mesh_edgebreaker_traversal_encoder.h:61
void NewCornerReached(CornerIndex)
Definition mesh_edgebreaker_traversal_encoder.h:67
void EncodeTraversalSymbols()
Definition mesh_edgebreaker_traversal_encoder.h:95
void EncodeAttributeSeams()
Definition mesh_edgebreaker_traversal_encoder.h:112
Definition rans_bit_encoder.h:28
Definition attribute_octahedron_transform.cc:21
constexpr int32_t edge_breaker_topology_bit_pattern_length[]
Definition mesh_edgebreaker_shared.h:78
RAnsBitEncoder BinaryEncoder
Definition mesh_edgebreaker_traversal_encoder.h:25
CornerIndex CornerIndex
Definition mesh_edgebreaker_encoder_impl.cc:35
EdgebreakerTopologyBitPattern
Definition mesh_edgebreaker_shared.h:53