Blender  V3.3
mesh_topology.h
Go to the documentation of this file.
1 // Copyright 2020 Blender Foundation. All rights reserved.
2 //
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License
5 // as published by the Free Software Foundation; either version 2
6 // of the License, or (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software Foundation,
15 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 //
17 // Author: Sergey Sharybin
18 
19 #ifndef OPENSUBDIV_MESH_TOPOLOGY_H_
20 #define OPENSUBDIV_MESH_TOPOLOGY_H_
21 
22 #include <cstring>
23 
24 #include "internal/base/memory.h"
25 #include "internal/base/type.h"
26 
28 
29 namespace blender {
30 namespace opensubdiv {
31 
32 // Simplified representation of mesh topology.
33 // Only includes parts of actual mesh topology which is needed to perform
34 // comparison between Application side and OpenSubddiv side.
35 //
36 // NOTE: It is an optimized storage which requires special order of topology
37 // specification. Basically, counters is to be set prior to anything else, in
38 // the following manner:
39 //
40 // MeshTopology mesh_topology;
41 //
42 // mesh_topology.setNumVertices(...);
43 // mesh_topology.setNumEdges(...);
44 // mesh_topology.setNumFaces(...);
45 //
46 // for (...) {
47 // mesh_topology.setNumFaceVertices(...);
48 // }
49 //
50 // mesh_topology.finishResizeTopology();
51 //
52 // /* it is now possible to set vertices of edge, vertices of face, and
53 // * sharpness. */
54 class MeshTopology {
55  public:
56  MeshTopology();
57  MeshTopology(const MeshTopology &other) = default;
58  MeshTopology(MeshTopology &&other) noexcept = default;
59  ~MeshTopology();
60 
61  MeshTopology &operator=(const MeshTopology &other) = default;
62  MeshTopology &operator=(MeshTopology &&other) = default;
63 
65  // Vertices.
66 
67  void setNumVertices(int num_vertices);
68  int getNumVertices() const;
69 
70  void setVertexSharpness(int vertex_index, float sharpness);
71  float getVertexSharpness(int vertex_index) const;
72 
74  // Edges.
75 
76  void setNumEdges(int num_edges);
77 
78  // NOTE: Unless full topology was specified will return number of edges based
79  // on last edge index for which topology tag was specified.
80  int getNumEdges() const;
81 
82  void setEdgeVertexIndices(int edge_index, int v1, int v2);
83  void getEdgeVertexIndices(int edge_index, int *v1, int *v2) const;
84 
85  bool isEdgeEqual(int edge_index, int expected_v1, int expected_v2) const;
86 
87  void setEdgeSharpness(int edge_index, float sharpness);
88  float getEdgeSharpness(int edge_index) const;
89 
91  // Faces.
92 
93  void setNumFaces(int num_faces);
94 
95  int getNumFaces() const;
96 
97  void setNumFaceVertices(int face_index, int num_face_vertices);
98  int getNumFaceVertices(int face_index) const;
99 
100  void setFaceVertexIndices(int face_index,
101  int num_face_vertex_indices,
102  const int *face_vertex_indices);
103 
104  bool isFaceVertexIndicesEqual(int face_index,
105  int num_expected_face_vertex_indices,
106  const int *expected_face_vertex_indices) const;
107  bool isFaceVertexIndicesEqual(int face_index,
108  const vector<int> &expected_face_vertex_indices) const;
109 
111  // Pipeline related.
112 
113  // This function is to be called when number of vertices, edges, faces, and
114  // face-vertices are known.
115  //
116  // Usually is called from the end of topology refiner factory's
117  // resizeComponentTopology().
118  void finishResizeTopology();
119 
121  // Comparison.
122 
123  // Check whether this topology refiner defines same topology as the given
124  // converter.
125  bool isEqualToConverter(const OpenSubdiv_Converter *converter) const;
126 
127  protected:
128  // Edges are allowed to be stored sparsly, to save memory used by
129  // non-semi-sharp edges.
130  void ensureNumEdgesAtLeast(int num_edges);
131 
132  // Geometry tags are stored sparsly.
133  //
134  // These functions ensures that the storage can be addressed by an index which
135  // corresponds to the given size.
136  void ensureVertexTagsSize(int num_vertices);
137  void ensureEdgeTagsSize(int num_edges);
138 
139  // Get pointer to the memory where face vertex indices are stored.
140  int *getFaceVertexIndicesStorage(int face_index);
141  const int *getFaceVertexIndicesStorage(int face_index) const;
142 
143  struct VertexTag {
144  float sharpness = 0.0f;
145  };
146 
147  struct Edge {
148  int v1 = -1;
149  int v2 = -1;
150  };
151 
152  struct EdgeTag {
153  float sharpness = 0.0f;
154  };
155 
157  vector<VertexTag> vertex_tags_;
158 
160  vector<Edge> edges_;
161  vector<EdgeTag> edge_tags_;
162 
164 
165  // Continuous array of all vertices of all faces:
166  // [vertex indices of face 0][vertex indices of face 1] .. [vertex indices of face n].
168 
169  // Indexed by face contains index within face_vertex_indices_ which corresponds
170  // to the element which contains first vertex of the face.
172 
173  MEM_CXX_CLASS_ALLOC_FUNCS("MeshTopology");
174 };
175 
176 } // namespace opensubdiv
177 } // namespace blender
178 
179 #endif // OPENSUBDIV_MESH_TOPOLOGY_H_
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble v1
ATTR_WARN_UNUSED_RESULT const BMVert * v2
int * getFaceVertexIndicesStorage(int face_index)
MeshTopology & operator=(const MeshTopology &other)=default
void ensureNumEdgesAtLeast(int num_edges)
void ensureVertexTagsSize(int num_vertices)
void getEdgeVertexIndices(int edge_index, int *v1, int *v2) const
MEM_CXX_CLASS_ALLOC_FUNCS("MeshTopology")
MeshTopology(MeshTopology &&other) noexcept=default
void setEdgeSharpness(int edge_index, float sharpness)
bool isEqualToConverter(const OpenSubdiv_Converter *converter) const
bool isEdgeEqual(int edge_index, int expected_v1, int expected_v2) const
float getEdgeSharpness(int edge_index) const
void setNumVertices(int num_vertices)
void setFaceVertexIndices(int face_index, int num_face_vertex_indices, const int *face_vertex_indices)
void ensureEdgeTagsSize(int num_edges)
void setVertexSharpness(int vertex_index, float sharpness)
int getNumFaceVertices(int face_index) const
bool isFaceVertexIndicesEqual(int face_index, int num_expected_face_vertex_indices, const int *expected_face_vertex_indices) const
void setEdgeVertexIndices(int edge_index, int v1, int v2)
vector< VertexTag > vertex_tags_
float getVertexSharpness(int vertex_index) const
MeshTopology(const MeshTopology &other)=default
MeshTopology & operator=(MeshTopology &&other)=default
void setNumFaceVertices(int face_index, int num_face_vertices)