MeshInspector / MeshLib

Mesh processing library
https://meshinspector.com
Other
487 stars 55 forks source link

Overlapping edges after making mesh from binary numpy array #1747

Closed NathanTambeurRelu closed 10 months ago

NathanTambeurRelu commented 10 months ago

Hey, First and foremost thanks for the amazing library, it's awesome! I had a quick question about converting a numpy array to a mesh, any help would be much appreciated. When I run the following code: ''''python

labels = np.load("broken_labels/brokenLabels_"+str(i)+".npy")
labels = labels>0
labels = labels.astype(float)

#convert 3D array to SimpleVolume data
simpleVolume = mrn.simpleVolumeFrom3Darray(labels)
#convert SimpleVolume to FloatGrid data
floatGrid = mr.simpleVolumeToDenseGrid(simpleVolume )

mesh = mr.gridToMesh(floatGrid , mr.Vector3f(0.1, 0.1, 0.1), 0.5)
mr.saveMesh(mesh, "processedMeshes/mesh_noHoles_raw"+str(i)+".stl")
self_colliding = mr.findSelfCollidingTriangles(mesh)
print("number of self colliding triangle: ", len(self_colliding))

params = mr.MeshRelaxParams()
params.iterations = 15
res = mr.relax(mesh, params)
self_colliding = mr.findSelfCollidingTriangles(mesh)
print("number of self colliding triangle after relax: ", len(self_colliding))
mr.fixSelfIntersections(mesh,0.2)
self_colliding = mr.findSelfCollidingTriangles(mesh)
print("number of self colliding triangles AFTER FIX: ", len(self_colliding))

I get the following result for 3 different input arrays:

CASE 1: number of self colliding triangle: 0 number of self colliding triangle after relax: 9 number of self colliding triangles AFTER FIX: 0 CASE 2: number of self colliding triangle: 0 number of self colliding triangle after relax: 6 number of self colliding triangles AFTER FIX: 0 CASE3 number of self colliding triangle: 0 number of self colliding triangle after relax: 12 number of self colliding triangles AFTER FIX: 0

Now I have two questions about this: First, running it trough rhino3d the very first print (unfiltered uncorrected case) does contain way more intersections ~35, all the other counts are correct however.

Second, I added "mr.fixSelfIntersections(mesh,0.2)" to fix the issue and it seems to work. However this is relatively slow. Looking into the code I see what actually happens is that the mesh is turned into voxels and than back into a mesh. Now for my question any idea why the first mesh (unfiltered numpy array to mesh) does contain overlapping edges then because the logic should be the same, no?

Grantim commented 10 months ago

Hello!

You are right about the logic, anyway it is hard to tell what is the problem without actually looking at the mesh and the initinal array. Looks correct that first making mesh from the voxels have no self-intersections

mesh = mr.gridToMesh(floatGrid , mr.Vector3f(0.1, 0.1, 0.1), 0.5)

They may occur after relax that also seams correct. Can you please attach data so we can have closer look? (if your data is private you can send it on our email: support@meshinspector.com )

NathanTambeurRelu commented 10 months ago

Email send! Thanks for the quick response.

Grantim commented 10 months ago

Closing this issue for now, please feel free to reopen it if needed