MCPcopy Create free account
hub / github.com/PyMesh/PyMesh / refine

Method refine

tools/Triangulation/MMG/Delaunay.cpp:125–253  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

123}
124
125void MMG::Delaunay::refine(const MatrixFr& metric) {
126 const size_t num_input_vertices = m_vertices.rows();
127 const size_t num_input_faces = m_faces.rows();
128
129 if (num_input_vertices == 0) {
130 return;
131 }
132
133 MMG5_pMesh mmgMesh;
134 MMG5_pSol mmgSol;
135
136 mmgMesh = NULL;
137 mmgSol = NULL;
138 if (MMG2D_Init_mesh(MMG5_ARG_start,
139 MMG5_ARG_ppMesh, &mmgMesh,
140 MMG5_ARG_ppMet, &mmgSol,
141 MMG5_ARG_end) != 1) {
142 throw RuntimeError("MMG2D_Init_mesh failed.");
143 }
144
145 const Vector2F bbox_min = m_vertices.colwise().minCoeff();
146 const Vector2F bbox_max = m_vertices.colwise().maxCoeff();
147 const Float tol = (bbox_max - bbox_min).norm() / 20.0;
148
149 if (MMG2D_Set_iparameter(mmgMesh, mmgSol, MMG2D_IPARAM_verbose, 1) != 1) {
150 throw RuntimeError("Setting MMG2D_IPARAM_verbose failed.");
151 }
152 if (MMG2D_Set_dparameter(mmgMesh, mmgSol, MMG2D_DPARAM_hmax, tol) != 1) {
153 throw RuntimeError("Setting MMG2D_DPARAM_hmax failed.");
154 }
155
156 if (MMG2D_Set_meshSize(mmgMesh,num_input_vertices,num_input_faces,0) != 1) {
157 throw RuntimeError("MMG2D_Set_meshSize failed.");
158 }
159
160 for (size_t i=0; i<num_input_vertices; i++) {
161 if (MMG2D_Set_vertex(mmgMesh, m_vertices(i,0), m_vertices(i, 1), i+1, i+1) != 1) {
162 throw RuntimeError("MMG2D_Set_vertex failed for vertex "
163 + std::to_string(i) + ".");
164 }
165 }
166
167 for (size_t i=0; i<num_input_faces; i++) {
168 if (MMG2D_Set_triangle(mmgMesh,
169 m_faces(i, 0) + 1,
170 m_faces(i, 1) + 1,
171 m_faces(i, 2) + 1,
172 i+1, i+1) != 1 ) {
173 throw RuntimeError("MMG2D_Set_edge failed for edge "
174 + std::to_string(i) + ".");
175 }
176 }
177
178 // Set per-vertex metric. This must be done after mmgMesh is initialized.
179 const size_t num_metrics = metric.rows();
180 if (num_metrics == 0) {
181 if (MMG2D_Set_solSize(mmgMesh, mmgSol, MMG5_Vertex, 0, MMG5_Scalar) != 1) {
182 throw RuntimeError("MMG2D_Set_solSize failed.");

Callers 1

refine_triangulationFunction · 0.45

Calls 3

RuntimeErrorClass · 0.85
NotImplementedErrorClass · 0.85
normMethod · 0.80

Tested by

no test coverage detected