I am trying to make an initial mesh from a set of input data, a bit similar to your example Mesh generation. Crucially, some of my vertices in the input data are connected (not boundary edges, but interior edges), and I’d like to preserve these edges in the final mesh. I don’t mind if additional vertices or edges are added, but I need these input edges to be remain untouched.
I figured it would be as simple as setting all edges to be MMG2D_Set_requiredEdge
. Could someone be so kind as to tell me where I have gone wrong?
in pseudo-code, I’m basically doing this:
initialize mesh
fill the vertices and edges
mark all edges (and vertices?) as required
run MMG2D_mmg2dmesh
here is my test data, vertex and edge arrays used as input to the code below
double inVertices[12] = { 2, 0, 1, 1.732, -1, 1.732, -2, 0, -1, -1.732, 1, -1.732 };
int inEdges[14] = { 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 1, 1, 3 };
that is a regular hexagon (6 vertices), with 6 boundary edges and 1 more edge that connect vertex 1-3 (edge through the interior of the hexagon).
// initialize and fill mesh
MMG5_pMesh mesh = NULL;
MMG5_pSol solution = NULL;
MMG2D_Init_mesh(MMG5_ARG_start,
MMG5_ARG_ppMesh, &mesh,
MMG5_ARG_ppMet, &solution,
MMG5_ARG_end);
MMG2D_Set_meshSize(mesh, inNumVertices, 0, 0, inNumEdges);
// set vertices
MMG2D_Set_vertices(mesh, inVertices, NULL);
// set edges
for (int i = 0; i < inNumEdges; i += 2) {
MMG2D_Set_edge(mesh, inEdges[i], inEdges[i + 1], 0, i + 1);
}
// set required components
for (int i = 0; i < inNumVertices; i += 1) { MMG2D_Set_requiredVertex(mesh, i + 1); }
for (int i = 0; i < inNumEdges; i += 1) { MMG2D_Set_requiredEdge(mesh, i + 1); }
// create the initial mesh
MMG2D_mmg2dmesh(mesh, solution);
The result is a 6-equillateral triangle hexagon (7 vertices, one vertex in the exact center). but vertices 1 and 3 are not connected like I was hoping.
I noticed that using MMG2D_Set_edge
in a loop is a bit less buggy than MMG2D_Set_edges
. Not sure why, but I don’t mind.
some things I’ve tried:
- setting the parameter
hmax
, now thousands of triangles are created, but no input edge is preserved. - setting the parameters
noinsert
,nomove
,noswap
. I can see these working, especially whenhmax
is set, but again not what I’m looking for.
Thank you!