GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
mesh_attribute_corner_table.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_MESH_MESH_ATTRIBUTE_CORNER_TABLE_H_
16#define DRACO_MESH_MESH_ATTRIBUTE_CORNER_TABLE_H_
17
18#include "draco/core/macros.h"
20#include "draco/mesh/mesh.h"
22
23namespace draco {
24
25// Class for storing connectivity of mesh attributes. The connectivity is stored
26// as a difference from the base mesh's corner table, where the differences are
27// represented by attribute seam edges. This class provides a basic
28// functionality for detecting the seam edges for a given attribute and for
29// traversing the constrained corner table with the seam edges.
31 public:
33 bool InitEmpty(const CornerTable *table);
34 bool InitFromAttribute(const Mesh *mesh, const CornerTable *table,
35 const PointAttribute *att);
36
37 void AddSeamEdge(CornerIndex opp_corner);
38
39 // Recomputes vertices using the newly added seam edges (needs to be called
40 // whenever the seam edges are updated).
41 // |mesh| and |att| can be null, in which case mapping between vertices and
42 // attribute value ids is set to identity.
43 bool RecomputeVertices(const Mesh *mesh, const PointAttribute *att);
44
45 inline bool IsCornerOppositeToSeamEdge(CornerIndex corner) const {
46 return is_edge_on_seam_[corner.value()];
47 }
48
49 inline CornerIndex Opposite(CornerIndex corner) const {
50 if (corner == kInvalidCornerIndex || IsCornerOppositeToSeamEdge(corner)) {
51 return kInvalidCornerIndex;
52 }
53 return corner_table_->Opposite(corner);
54 }
55
56 inline CornerIndex Next(CornerIndex corner) const {
57 return corner_table_->Next(corner);
58 }
59
60 inline CornerIndex Previous(CornerIndex corner) const {
61 return corner_table_->Previous(corner);
62 }
63
64 // Returns true when a corner is attached to any attribute seam.
65 inline bool IsCornerOnSeam(CornerIndex corner) const {
66 return is_vertex_on_seam_[corner_table_->Vertex(corner).value()];
67 }
68
69 // Similar to CornerTable::GetLeftCorner and CornerTable::GetRightCorner, but
70 // does not go over seam edges.
71 inline CornerIndex GetLeftCorner(CornerIndex corner) const {
72 return Opposite(Previous(corner));
73 }
74 inline CornerIndex GetRightCorner(CornerIndex corner) const {
75 return Opposite(Next(corner));
76 }
77
78 // Similar to CornerTable::SwingRight, but it does not go over seam edges.
79 inline CornerIndex SwingRight(CornerIndex corner) const {
80 return Previous(Opposite(Previous(corner)));
81 }
82
83 // Similar to CornerTable::SwingLeft, but it does not go over seam edges.
84 inline CornerIndex SwingLeft(CornerIndex corner) const {
85 return Next(Opposite(Next(corner)));
86 }
87
88 int num_vertices() const {
89 return static_cast<int>(vertex_to_attribute_entry_id_map_.size());
90 }
91 int num_faces() const { return static_cast<int>(corner_table_->num_faces()); }
92 int num_corners() const { return corner_table_->num_corners(); }
93
95 DRACO_DCHECK_LT(corner.value(), corner_to_vertex_map_.size());
96 return ConfidentVertex(corner);
97 }
99 return corner_to_vertex_map_[corner.value()];
100 }
101 // Returns the attribute entry id associated to the given vertex.
103 return VertexIndex(vertex_to_attribute_entry_id_map_[vert.value()].value());
104 }
105
107 return vertex_to_left_most_corner_map_[v.value()];
108 }
109
110 inline FaceIndex Face(CornerIndex corner) const {
111 return corner_table_->Face(corner);
112 }
113
114 inline CornerIndex FirstCorner(FaceIndex face) const {
115 return corner_table_->FirstCorner(face);
116 }
117
118 inline std::array<CornerIndex, 3> AllCorners(FaceIndex face) const {
119 return corner_table_->AllCorners(face);
120 }
121
122 inline bool IsOnBoundary(VertexIndex vert) const {
123 const CornerIndex corner = LeftMostCorner(vert);
124 if (corner == kInvalidCornerIndex) {
125 return true;
126 }
127 if (SwingLeft(corner) == kInvalidCornerIndex) {
128 return true;
129 }
130 return false;
131 }
132
133 bool IsDegenerated(FaceIndex face) const {
134 // Introducing seams can't change the degeneracy of the individual faces,
135 // therefore we can delegate the check to the original |corner_table_|.
136 return corner_table_->IsDegenerated(face);
137 }
138
139 bool no_interior_seams() const { return no_interior_seams_; }
140 const CornerTable *corner_table() const { return corner_table_; }
141
142 // TODO(draco-eng): extract valence functions into a reusable class/object
143 // also from 'corner_table.*'
144
145 // Returns the valence (or degree) of a vertex.
146 // Returns -1 if the given vertex index is not valid.
147 int Valence(VertexIndex v) const;
148 // Same as above but does not check for validity and does not return -1
149 int ConfidentValence(VertexIndex v) const;
150 // Returns the valence of the vertex at the given corner.
151 inline int Valence(CornerIndex c) const {
152 DRACO_DCHECK_LT(c.value(), corner_table_->num_corners());
153 if (c == kInvalidCornerIndex) {
154 return -1;
155 }
156 return ConfidentValence(c);
157 }
158 inline int ConfidentValence(CornerIndex c) const {
159 DRACO_DCHECK_LT(c.value(), corner_table_->num_corners());
160 return ConfidentValence(Vertex(c));
161 }
162
163 // Allows access to an internal object for caching valences. The object can
164 // be instructed to cache or uncache all valences and then its interfaces
165 // queried directly for valences with differing performance/confidence
166 // qualities. If the mesh or table is modified the cache should be discarded
167 // and not relied on as it does not automatically update or invalidate for
168 // performance reasons.
170 return valence_cache_;
171 }
172
173 private:
174 template <bool init_vertex_to_attribute_entry_map>
175 bool RecomputeVerticesInternal(const Mesh *mesh, const PointAttribute *att);
176
177 std::vector<bool> is_edge_on_seam_;
178 std::vector<bool> is_vertex_on_seam_;
179
180 // If this is set to true, it means that there are no attribute seams between
181 // two faces. This can be used to speed up some algorithms.
182 bool no_interior_seams_;
183
184 std::vector<VertexIndex> corner_to_vertex_map_;
185
186 // Map between vertices and their associated left most corners. A left most
187 // corner is a corner that is adjacent to a boundary or an attribute seam from
188 // right (i.e., SwingLeft from that corner will return an invalid corner). If
189 // no such corner exists for a given vertex, then any corner attached to the
190 // vertex can be used.
191 std::vector<CornerIndex> vertex_to_left_most_corner_map_;
192
193 // Map between vertex ids and attribute entry ids (i.e. the values stored in
194 // the attribute buffer). The attribute entry id can be retrieved using the
195 // VertexParent() method.
196 std::vector<AttributeValueIndex> vertex_to_attribute_entry_id_map_;
197 const CornerTable *corner_table_;
199};
200
201} // namespace draco
202#endif // DRACO_MESH_MESH_ATTRIBUTE_CORNER_TABLE_H_
Definition corner_table.h:53
int ConfidentValence(CornerIndex c) const
Definition mesh_attribute_corner_table.h:158
const ValenceCache< MeshAttributeCornerTable > & GetValenceCache() const
Definition mesh_attribute_corner_table.h:169
FaceIndex Face(CornerIndex corner) const
Definition mesh_attribute_corner_table.h:110
MeshAttributeCornerTable()
Definition mesh_attribute_corner_table.cc:22
CornerIndex FirstCorner(FaceIndex face) const
Definition mesh_attribute_corner_table.h:114
const CornerTable * corner_table() const
Definition mesh_attribute_corner_table.h:140
CornerIndex Next(CornerIndex corner) const
Definition mesh_attribute_corner_table.h:56
std::array< CornerIndex, 3 > AllCorners(FaceIndex face) const
Definition mesh_attribute_corner_table.h:118
bool RecomputeVertices(const Mesh *mesh, const PointAttribute *att)
Definition mesh_attribute_corner_table.cc:129
VertexIndex VertexParent(VertexIndex vert) const
Definition mesh_attribute_corner_table.h:102
CornerIndex SwingRight(CornerIndex corner) const
Definition mesh_attribute_corner_table.h:79
int num_vertices() const
Definition mesh_attribute_corner_table.h:88
bool InitFromAttribute(const Mesh *mesh, const CornerTable *table, const PointAttribute *att)
Definition mesh_attribute_corner_table.cc:41
void AddSeamEdge(CornerIndex opp_corner)
Definition mesh_attribute_corner_table.cc:108
CornerIndex GetRightCorner(CornerIndex corner) const
Definition mesh_attribute_corner_table.h:74
VertexIndex ConfidentVertex(CornerIndex corner) const
Definition mesh_attribute_corner_table.h:98
bool IsCornerOppositeToSeamEdge(CornerIndex corner) const
Definition mesh_attribute_corner_table.h:45
int num_faces() const
Definition mesh_attribute_corner_table.h:91
int Valence(CornerIndex c) const
Definition mesh_attribute_corner_table.h:151
bool no_interior_seams() const
Definition mesh_attribute_corner_table.h:139
CornerIndex GetLeftCorner(CornerIndex corner) const
Definition mesh_attribute_corner_table.h:71
CornerIndex LeftMostCorner(VertexIndex v) const
Definition mesh_attribute_corner_table.h:106
int ConfidentValence(VertexIndex v) const
Definition mesh_attribute_corner_table.cc:207
int Valence(VertexIndex v) const
Definition mesh_attribute_corner_table.cc:200
bool IsDegenerated(FaceIndex face) const
Definition mesh_attribute_corner_table.h:133
VertexIndex Vertex(CornerIndex corner) const
Definition mesh_attribute_corner_table.h:94
bool IsOnBoundary(VertexIndex vert) const
Definition mesh_attribute_corner_table.h:122
bool IsCornerOnSeam(CornerIndex corner) const
Definition mesh_attribute_corner_table.h:65
CornerIndex Opposite(CornerIndex corner) const
Definition mesh_attribute_corner_table.h:49
bool InitEmpty(const CornerTable *table)
Definition mesh_attribute_corner_table.cc:25
int num_corners() const
Definition mesh_attribute_corner_table.h:92
CornerIndex Previous(CornerIndex corner) const
Definition mesh_attribute_corner_table.h:60
CornerIndex SwingLeft(CornerIndex corner) const
Definition mesh_attribute_corner_table.h:84
Definition mesh.h:52
Definition point_attribute.h:33
Definition valence_cache.h:31
#define DRACO_DCHECK_LT(a, b)
Definition macros.h:86
Definition attribute_octahedron_transform.cc:21
VertexIndex VertexIndex
Definition mesh_edgebreaker_encoder_impl.cc:37
CornerIndex CornerIndex
Definition mesh_edgebreaker_encoder_impl.cc:35
FaceIndex FaceIndex
Definition mesh_edgebreaker_encoder_impl.cc:36