Blender V4.3
mesh_topology.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2020 Blender Foundation
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later
4 *
5 * Author: Sergey Sharybin. */
6
7#ifndef OPENSUBDIV_MESH_TOPOLOGY_H_
8#define OPENSUBDIV_MESH_TOPOLOGY_H_
9
10#include <vector>
11
13
15
16namespace blender::opensubdiv {
17
18// Simplified representation of mesh topology.
19// Only includes parts of actual mesh topology which is needed to perform
20// comparison between Application side and OpenSubddiv side.
21//
22// NOTE: It is an optimized storage which requires special order of topology
23// specification. Basically, counters is to be set prior to anything else, in
24// the following manner:
25//
26// MeshTopology mesh_topology;
27//
28// mesh_topology.setNumVertices(...);
29// mesh_topology.setNumEdges(...);
30// mesh_topology.setNumFaces(...);
31//
32// for (...) {
33// mesh_topology.setNumFaceVertices(...);
34// }
35//
36// mesh_topology.finishResizeTopology();
37//
38// /* it is now possible to set vertices of edge, vertices of face, and
39// * sharpness. */
41 public:
43 MeshTopology(const MeshTopology &other) = default;
44 MeshTopology(MeshTopology &&other) noexcept = default;
46
47 MeshTopology &operator=(const MeshTopology &other) = default;
48 MeshTopology &operator=(MeshTopology &&other) = default;
49
51 // Vertices.
52
53 void setNumVertices(int num_vertices);
54 int getNumVertices() const;
55
56 void setVertexSharpness(int vertex_index, float sharpness);
57 float getVertexSharpness(int vertex_index) const;
58
60 // Edges.
61
62 void setNumEdges(int num_edges);
63
64 // NOTE: Unless full topology was specified will return number of edges based
65 // on last edge index for which topology tag was specified.
66 int getNumEdges() const;
67
68 void setEdgeVertexIndices(int edge_index, int v1, int v2);
69 void getEdgeVertexIndices(int edge_index, int *v1, int *v2) const;
70
71 bool isEdgeEqual(int edge_index, int expected_v1, int expected_v2) const;
72
73 void setEdgeSharpness(int edge_index, float sharpness);
74 float getEdgeSharpness(int edge_index) const;
75
77 // Faces.
78
79 void setNumFaces(int num_faces);
80
81 int getNumFaces() const;
82
83 void setNumFaceVertices(int face_index, int num_face_vertices);
84 int getNumFaceVertices(int face_index) const;
85
86 void setFaceVertexIndices(int face_index,
87 int num_face_vertex_indices,
88 const int *face_vertex_indices);
89
90 bool isFaceVertexIndicesEqual(int face_index,
91 int num_expected_face_vertex_indices,
92 const int *expected_face_vertex_indices) const;
93 bool isFaceVertexIndicesEqual(int face_index,
94 const std::vector<int> &expected_face_vertex_indices) const;
95
97 // Pipeline related.
98
99 // This function is to be called when number of vertices, edges, faces, and
100 // face-vertices are known.
101 //
102 // Usually is called from the end of topology refiner factory's
103 // resizeComponentTopology().
105
107 // Comparison.
108
109 // Compare given topology with converter. Returns truth if topology
110 // matches given converter, false otherwise.
111 //
112 // This allows users to construct converter (which is supposed to be cheap)
113 // and compare with existing topology before going into more computationally
114 // complicated parts of subdivision process.
115 bool isEqualToConverter(const OpenSubdiv_Converter *converter) const;
116
117 protected:
118 // Edges are allowed to be stored sparsly, to save memory used by
119 // non-semi-sharp edges.
120 void ensureNumEdgesAtLeast(int num_edges);
121
122 // Geometry tags are stored sparsly.
123 //
124 // These functions ensures that the storage can be addressed by an index which
125 // corresponds to the given size.
126 void ensureVertexTagsSize(int num_vertices);
127 void ensureEdgeTagsSize(int num_edges);
128
129 // Get pointer to the memory where face vertex indices are stored.
130 int *getFaceVertexIndicesStorage(int face_index);
131 const int *getFaceVertexIndicesStorage(int face_index) const;
132
133 struct VertexTag {
134 float sharpness = 0.0f;
135 };
136
137 struct Edge {
138 int v1 = -1;
139 int v2 = -1;
140 };
141
142 struct EdgeTag {
143 float sharpness = 0.0f;
144 };
145
147 std::vector<VertexTag> vertex_tags_;
148
150 std::vector<Edge> edges_;
151 std::vector<EdgeTag> edge_tags_;
152
154
155 // Continuous array of all vertices of all faces:
156 // [vertex indices of face 0][vertex indices of face 1] .. [vertex indices of face n].
157 std::vector<int> face_vertex_indices_;
158
159 // Indexed by face contains index within face_vertex_indices_ which corresponds
160 // to the element which contains first vertex of the face.
162
164};
165
166} // namespace blender::opensubdiv
167
168#endif // OPENSUBDIV_MESH_TOPOLOGY_H_
ATTR_WARN_UNUSED_RESULT const BMVert * v2
int * getFaceVertexIndicesStorage(int face_index)
std::vector< int > faces_first_vertex_index_
void ensureNumEdgesAtLeast(int num_edges)
void ensureVertexTagsSize(int num_vertices)
void getEdgeVertexIndices(int edge_index, int *v1, int *v2) const
std::vector< VertexTag > vertex_tags_
MEM_CXX_CLASS_ALLOC_FUNCS("MeshTopology")
MeshTopology(MeshTopology &&other) noexcept=default
void setEdgeSharpness(int edge_index, float sharpness)
MeshTopology & operator=(MeshTopology &&other)=default
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)
std::vector< int > face_vertex_indices_
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)
MeshTopology & operator=(const MeshTopology &other)=default
float getVertexSharpness(int vertex_index) const
std::vector< EdgeTag > edge_tags_
MeshTopology(const MeshTopology &other)=default
void setNumFaceVertices(int face_index, int num_face_vertices)