External neighbors.

I have this mesh with vertices selected :


I want to do a script that automatically gives for each vertice selected the neighbors (vertices’ indices) that are external to this selection. For example :


Red circles = vertices that are part of the script’s result (external neighbors of selected vertices)

BMesh api is what you need. Loop over your selected verts, check each vert’s “link_edges” and get the “other_vert” of each link_edge. Then use a “set” to clean out any doubles or just select them as you find them. Let me know if you need more explicit code example. if this is enough, please post your results and mark as solved!

Best,
Patrick

vert.link_edges
edge.other_vert

http://www.blender.org/api/blender_python_api_2_74_release/bmesh.types.html?highlight=other_ver#bmesh.types.BMVert.link_edges
http://www.blender.org/api/blender_python_api_2_74_release/bmesh.types.html?highlight=other_ver#bmesh.types.BMEdge.other_vert

EDIT: I’m looking more closely at your picture, do you want the verts outside the overall ring? or just one vert neighbors on either side of the edge loop?

If indeed you are looking for the “external” relative to the macro shape of the edge loop, there are a couple of ways you can do it.

1). If you mesh is guaranteed only triangles, then the 1 edge neighbor of the edge loop will be another edge loop. You can find the 2 edge loops, and then compare circumfrences. If there are quads involved, and some verts have >4 edges, then you might end up with some diamond situations what don’t make a nice edge loop.

2). If the loop is always fairly close to planar, you can easily define a direction around the loop, making it easy to decide which way is “outward” and “inward” even if the loop is not convex like a nice circle and is L shapped or T shaped.

  1. If your surface shape is fairly regular without too much noise, you can use the surface normal, crossed with an edge vector to test “inside the loo” vs “outside” the loop.

P.S. What is that a model of? Is it a scan or an isosurface extracted from volumetric data?

There’s a contrib add-on “Mesh Select Tools” (should be in Blender, Testing category) that might already allow for this type of selection (check for Connected selection). I’m also working on an update for that add-on that will let you select elements adjacent to current selection, it should be up soon.

I know how to get vertice’s neighbors with BMesh, that’s not the problem. But the add-on would be a great thing Stan Pancakes !

The thing is that I have a part of a skull mesh (stl file extracted from a CT scan, only triangles) with a hole in it as you can see. The user has to select approximatively the border of the hole (ring).
For each vertice in this selection, I have to give his neighbors that respect a criterion. The criterion is for the neighbor to not be on the same side of the hole, to be “outside” of the ring.

@patmo : I thought about your ideas.

  • Point 1 : I don’t think it works all the time because the user can choose a ring that is too close to the innermost hole’s border (or some parts of it). But let’s say that the ring is mostly not on the innermost border (where curvature is null).
  • Points 2 & 3 : We can differentiate two types of neighbors but how can I know which one it is (inside or outside) ? I think I need to work with the center of the selection ?

Will it always be a convex edge loop eg, a line from center of mass to any point on the ring will never cross anogher part of the edge loop? If so, then a center of mass approach will work.

-patrick

Yeah but what is the approach ? How can I know which neighbor is outside or inside with the center of mass ?