Discretise mesh but keep valid groups/topology

(Charles) #1

I have one value per vertex and based on these I’d like to split the mesh into n valid groups.There can be multiple non-connected meshes within a group.

As you can see highlighted with a black pen in the image below sometimes I get some invalid areas which I need to mitigate.

Ideally if the vertex value is high then I’d like to expand and make it valid, conversely if it’s low let the neighbors take over.

Can someone point me in the right direction?

My initial assumption is a group would be valid if:

  • All faces are connected by at least two edges
  • the total area of an “island” is greater than a threshold (two faces would be too small for an entity)

C# or Python solutions would be much appreciated!

PS: this algorithm will scale to 3D tetrahedron meshes to export watertight poly meshes.

test_two.gh (17.7 KB)

(Pfotiad0) #2

A classic KMeans clustering thingy … but working on 2 Lists: the first is the mesh Vertices. The second is the vertices colors as Point3d (in a RGB cube 256x256x256 where x coord is the color.R, y is the color.G and z is the color.B):

So let’s call the vertices List vList and the other vCList (C for color). Then you need a KMeans clustering on the vCList … PLUS … for each point sampled in a cluster you sample in another cluster the “equivalent” point from vList.

Since at the end you need to cluster faces and not vertices is imperative to use MTV indexing and get the MV indexing (used in colors, normals etc etc: that’s nerve braking and rather confusing) via the Method shown above. Why? because a conn Tree that contains the clustered vertices indices (MTV indexing) is very handy for the final phase (make the faces). Remember that a FV conn tree is using MTV indexing.

In fact you can greatly simplify the whole workflow if you use a face center and the “equivalent” centerColorPoint (so to speak) as the (vC1+vC2+vC3)/3.0 etc etc.

(Daniel Piker) #3

I wonder if switching to the dual could help you here.
I once did this to resolve non manifold boundary problems for some scalar field stuff

(You can still potentially get some isolated faces, but those might be easier to fix than the non manifold vertices)