student
student

Reputation: 21

Openmesh: How to modify mesh faces? (And how to random access component handles?)

I just started using OpenMesh in Python. I started off by trying to make a PolyMesh consisting of a single quad. This is what I did:

from openmesh import *
mesh = PolyMesh();
vh0 = mesh.add_vertex(PolyMesh.Point(0,0,0));
vh1 = mesh.add_vertex(PolyMesh.Point(1,0,0));
vh2 = mesh.add_vertex(PolyMesh.Point(1,1,0));
vh3 = mesh.add_vertex(PolyMesh.Point(0,1,0));
vh_list = [vh0, vh1, vh2, vh3];
fh0 = mesh.add_face(vh_list);

This creates a single quad mesh. Then, wanting to refine the quad once, I thought to try:

vh4 = mesh.add_vertex(PolyMesh.Point(0.5,0,0));
vh5 = mesh.add_vertex(PolyMesh.Point(0.5,1,0));
vh_list = [vh4, vh1, vh2, vh5];
fh1 = mesh.add_face(vh_list);

The above gives me a complex edge error. I understand from one of the other questions on SO that this is because vh_list in the second case does not define a consistent orientation wrt the first face. However, I did not want to add a new face. That is, I thought the operation would simply split fh0 at x = 0.5 and not create a new face attached to fh0 at edge index 1. Can someone say something about how this can be done? I could not find a "split_face" function in the documentation.

Also, how do I access handles of particular edges/mesh components in Python? (I found answers only for C++.) For instance, I know that I can iterate over the edges with,

for eh in mesh.edges():

but how can I directly get the handle for edge 2 and use it as follows, for example?

mesh.split_edge(eh,vh5)

Thank you!

Edit 1

I found the function split in OpenMesh documentation, but it takes as input a single vertexhandle at which I can split the face. And post-splitting, it converts the mesh to a mesh of triangles. I do not want this. I want to split the quadrilateral into two quadrilaterals at x = 0.5. Thank you.

Edit 2

I tried an alternate approach: first delete fh0, and then add two new faces fh0 and fh1 based on the refinement I want. I tried doing

mesh.delete_face(fh0)

and Python segfaulted and exited.

Upvotes: 2

Views: 1950

Answers (1)

CDuvert
CDuvert

Reputation: 387

If you want to split the face fh0 into two faces you should delete fh0 first and then create the two new faces. This should do the job :

mesh.delete_face(fh0, deleted_isolated_vertices = False)
mesh.garbage_collection()

fh0 = mesh.add_face(vh0,vh4,vh5,vh3)
fh1 = mesh.add_face(vh4,vh1,vh2,vh5)

To verify you get what you want, ask for print(mesh.face_vertex_indices()), you should get two lists listing indices of vertices of each face.

Also, to access a known edge handle you can use

eh = mesh.edge_handle(edge_index)

where edge_index is int, index of your edge of interest.

Hope this helps,

Charles.

Upvotes: 2

Related Questions