GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
mesh_edgebreaker_encoder_impl.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_ENCODER_IMPL_H_
16#define DRACO_COMPRESSION_MESH_MESH_EDGEBREAKER_ENCODER_IMPL_H_
17
18#include <unordered_map>
19
27
28namespace draco {
29
30// Class implementing the edgebreaker encoding as described in "3D Compression
31// Made Simple: Edgebreaker on a Corner-Table" by Rossignac at al.'01.
32// http://www.cc.gatech.edu/~jarek/papers/CornerTableSMI.pdf
33template <class TraversalEncoderT>
35 public:
38 const TraversalEncoderT &traversal_encoder);
39 bool Init(MeshEdgebreakerEncoder *encoder) override;
40
42 int att_id) const override;
44 int att_id) const override;
45
46 bool GenerateAttributesEncoder(int32_t att_id) override;
47 bool EncodeAttributesEncoderIdentifier(int32_t att_encoder_id) override;
48 Status EncodeConnectivity() override;
49
50 const CornerTable *GetCornerTable() const override {
51 return corner_table_.get();
52 }
53 bool IsFaceEncoded(FaceIndex fi) const override {
54 return visited_faces_[fi.value()];
55 }
56 MeshEdgebreakerEncoder *GetEncoder() const override { return encoder_; }
57
58 private:
59 // Initializes data needed for encoding non-position attributes.
60 // Returns false on error.
61 bool InitAttributeData();
62
63 // Creates a vertex traversal sequencer for the specified |TraverserT| type.
64 template <class TraverserT>
65 std::unique_ptr<PointsSequencer> CreateVertexTraversalSequencer(
67
68 // Finds the configuration of the initial face that starts the traversal.
69 // Configurations are determined by location of holes around the init face
70 // and they are described in mesh_edgebreaker_shared.h.
71 // Returns true if the face configuration is interior and false if it is
72 // exterior.
73 bool FindInitFaceConfiguration(FaceIndex face_id,
74 CornerIndex *out_corner_id) const;
75
76 // Encodes the connectivity between vertices.
77 bool EncodeConnectivityFromCorner(CornerIndex corner_id);
78
79 // Encodes all vertices of a hole starting at start_corner_id.
80 // The vertex associated with the first corner is encoded only if
81 // |encode_first_vertex| is true.
82 // Returns the number of encoded hole vertices.
83 int EncodeHole(CornerIndex start_corner_id, bool encode_first_vertex);
84
85 // Encodes topology split data.
86 // Returns nullptr on error.
87 bool EncodeSplitData();
88
89 CornerIndex GetRightCorner(CornerIndex corner_id) const;
90 CornerIndex GetLeftCorner(CornerIndex corner_id) const;
91
92 bool IsRightFaceVisited(CornerIndex corner_id) const;
93 bool IsLeftFaceVisited(CornerIndex corner_id) const;
94 bool IsVertexVisited(VertexIndex vert_id) const {
95 return visited_vertex_ids_[vert_id.value()];
96 }
97
98 // Finds and stores data about all holes in the input mesh.
99 bool FindHoles();
100
101 // For faces encoded with symbol TOPOLOGY_S (split), this method returns
102 // the encoded symbol id or -1 if the face wasn't encoded by a split symbol.
103 int GetSplitSymbolIdOnFace(int face_id) const;
104
105 // Checks whether there is a topology split event on a neighboring face and
106 // stores the event data if necessary. For more info about topology split
107 // events, see description of TopologySplitEventData in
108 // mesh_edgebreaker_shared.h.
109 void CheckAndStoreTopologySplitEvent(int src_symbol_id, int src_face_id,
110 EdgeFaceName src_edge,
111 int neighbor_face_id);
112
113 // Encodes connectivity of all attributes on a newly traversed face.
114 bool EncodeAttributeConnectivitiesOnFace(CornerIndex corner);
115
116 // This function is used to to assign correct encoding order of attributes
117 // to unprocessed corners. The encoding order is equal to the order in which
118 // the attributes are going to be processed by the decoder and it is necessary
119 // for proper prediction of attribute values.
120 bool AssignPositionEncodingOrderToAllCorners();
121
122 // This function is used to generate encoding order for all non-position
123 // attributes.
124 // Returns false when one or more attributes failed to be processed.
125 bool GenerateEncodingOrderForAttributes();
126
127 // The main encoder that owns this class.
128 MeshEdgebreakerEncoder *encoder_;
129 // Mesh that's being encoded.
130 const Mesh *mesh_;
131 // Corner table stores the mesh face connectivity data.
132 std::unique_ptr<CornerTable> corner_table_;
133 // Stack used for storing corners that need to be traversed when encoding
134 // the connectivity. New corner is added for each initial face and a split
135 // symbol, and one corner is removed when the end symbol is reached.
136 // Stored as member variable to prevent frequent memory reallocations when
137 // handling meshes with lots of disjoint components. Originally, we used
138 // recursive functions to handle this behavior, but that can cause stack
139 // memory overflow when compressing huge meshes.
140 std::vector<CornerIndex> corner_traversal_stack_;
141 // Array for marking visited faces.
142 std::vector<bool> visited_faces_;
143
144 // Attribute data for position encoding.
145 MeshAttributeIndicesEncodingData pos_encoding_data_;
146
147 // Traversal method used for the position attribute.
148 MeshTraversalMethod pos_traversal_method_;
149
150 // Array storing corners in the order they were visited during the
151 // connectivity encoding (always storing the tip corner of each newly visited
152 // face).
153 std::vector<CornerIndex> processed_connectivity_corners_;
154
155 // Array for storing visited vertex ids of all input vertices.
156 std::vector<bool> visited_vertex_ids_;
157
158 // For each traversal, this array stores the number of visited vertices.
159 std::vector<int> vertex_traversal_length_;
160 // Array for storing all topology split events encountered during the mesh
161 // traversal.
162 std::vector<TopologySplitEventData> topology_split_event_data_;
163 // Map between face_id and symbol_id. Contains entries only for faces that
164 // were encoded with TOPOLOGY_S symbol.
165 std::unordered_map<int, int> face_to_split_symbol_map_;
166
167 // Array for marking holes that has been reached during the traversal.
168 std::vector<bool> visited_holes_;
169 // Array for mapping vertices to hole ids. If a vertex is not on a hole, the
170 // stored value is -1.
171 std::vector<int> vertex_hole_id_;
172
173 // Id of the last encoded symbol.
174 int last_encoded_symbol_id_;
175
176 // The number of encoded split symbols.
177 uint32_t num_split_symbols_;
178
179 // Struct holding data used for encoding each non-position attribute.
180 struct AttributeData {
181 AttributeData() : attribute_index(-1), is_connectivity_used(true) {}
182 int attribute_index;
183 MeshAttributeCornerTable connectivity_data;
184 // Flag that can mark the connectivity_data invalid. In such case the base
185 // corner table of the mesh should be used instead.
186 bool is_connectivity_used;
187 // Data about attribute encoding order.
188 MeshAttributeIndicesEncodingData encoding_data;
189 // Traversal method used to generate the encoding data for this attribute.
190 MeshTraversalMethod traversal_method;
191 };
192 std::vector<AttributeData> attribute_data_;
193
194 // Array storing mapping between attribute encoder id and attribute data id.
195 std::vector<int32_t> attribute_encoder_to_data_id_map_;
196
197 TraversalEncoderT traversal_encoder_;
198
199 // If set, the encoder is going to use the same connectivity for all
200 // attributes. This effectively breaks the mesh along all attribute seams.
201 // In general, this approach should be much faster compared to encoding each
202 // connectivity separately, but the decoded model may contain higher number of
203 // duplicate attribute values which may decrease the compression ratio.
204 bool use_single_connectivity_;
205};
206
207} // namespace draco
208
209#endif // DRACO_COMPRESSION_MESH_MESH_EDGEBREAKER_ENCODER_IMPL_H_
Definition Effect.hh:11256
Definition corner_table.h:53
Definition mesh_attribute_corner_table.h:30
Definition mesh_edgebreaker_encoder_impl_interface.h:33
MeshEdgebreakerEncoderImpl()
Definition mesh_edgebreaker_encoder_impl.cc:40
const MeshAttributeIndicesEncodingData * GetAttributeEncodingData(int att_id) const override
Definition mesh_edgebreaker_encoder_impl.cc:83
bool GenerateAttributesEncoder(int32_t att_id) override
Definition mesh_edgebreaker_encoder_impl.cc:117
const CornerTable * GetCornerTable() const override
Definition mesh_edgebreaker_encoder_impl.h:50
Status EncodeConnectivity() override
Definition mesh_edgebreaker_encoder_impl.cc:271
bool Init(MeshEdgebreakerEncoder *encoder) override
Definition mesh_edgebreaker_encoder_impl.cc:48
bool IsFaceEncoded(FaceIndex fi) const override
Definition mesh_edgebreaker_encoder_impl.h:53
bool EncodeAttributesEncoderIdentifier(int32_t att_encoder_id) override
Definition mesh_edgebreaker_encoder_impl.cc:242
MeshEdgebreakerEncoder * GetEncoder() const override
Definition mesh_edgebreaker_encoder_impl.h:56
MeshEdgebreakerEncoderImpl(const TraversalEncoderT &traversal_encoder)
const MeshAttributeCornerTable * GetAttributeCornerTable(int att_id) const override
Definition mesh_edgebreaker_encoder_impl.cc:68
Definition mesh_edgebreaker_encoder.h:30
Definition status.h:25
Definition attribute_octahedron_transform.cc:21
VertexIndex VertexIndex
Definition mesh_edgebreaker_encoder_impl.cc:37
EdgeFaceName
Definition mesh_edgebreaker_shared.h:94
MeshTraversalMethod
Definition compression_shared.h:114
CornerIndex CornerIndex
Definition mesh_edgebreaker_encoder_impl.cc:35
FaceIndex FaceIndex
Definition mesh_edgebreaker_encoder_impl.cc:36
Definition mesh_attribute_indices_encoding_data.h:27