I have a structured points data that I have prepared in such a way that my actual simulation data is in the middle surrounded by boundary points that all have the value of 0. My idea is that once I applied marching cube on it, I will get a mesh that is closed. The idea kind of work, and I indeed get a mesh that is closed around the boundary as expected. However, there seems to be a problem with manifold, with some triangle intersect with others. An image showing the orientation of faces is shown below (blue is outside and red is inside which is incorrect).
I have no idea how could this happen. From my understanding it should be impossible for marching cube algorithm to generate defective mesh. The code I use is very straightforward.
mc = vtkMarchingCubes()
reader = vtkStructuredPointsReader()
reader.SetFileName(Input_name + ".vtk")
mc.SetInputConnection(reader.GetOutputPort())
mc.ComputeNormalsOn()
mc.ComputeGradientsOn()
mc.SetValue(0, threshold)
mc.Update()
readerMC = mc.GetOutput()
stlWriter = vtkSTLWriter()
stlWriter.SetFileName(Output_name + ".stl")
stlWriter.SetInputData(readerMC)
stlWriter.Write()
I have tried vtkFlyingEdges3D and vtkCleanPolyData with not much luck. I also tried clipping these parts out and hopefully fix them with vtkClipClosedSurface which to my surprise, still have this non-manifold problem. The code I use is something along this line,
TinyVal = 0.01
BoundarySize = 255.0
plane1 = vtk.vtkPlane()
plane1.SetNormal(1, 0, 0)
plane1.SetOrigin(TinyVal, TinyVal, TinyVal)
plane2 = vtk.vtkPlane()
plane2.SetNormal(0, 1, 0)
plane2.SetOrigin(TinyVal, TinyVal, TinyVal)
plane3 = vtk.vtkPlane()
plane3.SetNormal(0, 0, 1)
plane3.SetOrigin(TinyVal, TinyVal, TinyVal)
plane4 = vtk.vtkPlane()
plane4.SetNormal(-1, 0, 0)
plane4.SetOrigin(BoundarySize - TinyVal, BoundarySize - TinyVal, BoundarySize - TinyVal)
plane5 = vtk.vtkPlane()
plane5.SetNormal(0, -1, 0)
plane5.SetOrigin(BoundarySize - TinyVal, BoundarySize - TinyVal, BoundarySize - TinyVal)
plane6 = vtk.vtkPlane()
plane6.SetNormal(0, 0, -1)
plane6.SetOrigin(BoundarySize - TinyVal, BoundarySize - TinyVal, BoundarySize - TinyVal)
coll = vtk.vtkPlaneCollection()
coll.AddItem(plane1)
coll.AddItem(plane2)
coll.AddItem(plane3)
coll.AddItem(plane4)
coll.AddItem(plane5)
coll.AddItem(plane6)
clip = vtk.vtkClipClosedSurface()
clip.SetClippingPlanes(coll)
clip.SetInputData(readerMC)
clip.Update()
I should also add that until now I haven’t “pad” my simulation results with 0 and left the mesh open, in such cases marching cube works like a charm, but for my current situation I really need it to close so here we are. I am completely new to vtk so this is probably a very beginner question, but I would really appreciate any helps that you can provide.