Mesh multiple objects

Hello all,
I have multiple parts of an organ (which are in contact with each other) and I want to mesh them in a way that they be conformal (having same nodes on their contact region). I can generate separate meshes for each part separately but they are not conformal.
I do not want to use segmentmesher because it gives me volumetric mesh and I do not want it. Can any body help me with it?
Thanks

Segment mesher is your best bet for a smooth conformal mesh that actually share node IDs. You can run the volumetric mesh through a geometry filter to keep only surface elements.

You can get conformal meshes from Segmentations if you disable surface smoothing before export (but the result will be non-smooth mesh) and somewhat more smooth and still mostly conformal meshes using Model Maker module.

1 Like

Thank you very much for your response. Can you please tell me how should I convert volumetric mesh to surface through geometry filter?
Thank you in advance.

You can copy-paste this code to the Python console to extract the surface and put it into a new mode node.

volMesh=getNode('Model').GetMesh()
extractSurface=vtk.vtkGeometryFilter()
extractSurface.SetInputData(volMesh)
extractSurface.Update()
slicer.modules.models.logic().AddModel(extractSurface.GetOutput())

You can extract a specific material by adding vtkThreshold filter before vtkGeometryFilter.

1 Like

Thank you very much for your response. I was able to convert it to the surface. Is there any way to just keep the parts of the shapes which are in contact. I mean now I have some surfaces which inside is empty but for a very thin tissue (Like eardrum) what I need is just a surface not a close region that I have in my model or segmentation. Thank you in advance

With latest “curve drawing on surface” feature (to be announced next week, but already available in latest Slicer Preview Release) you can extract one side of a surface very easily:

  • Draw a closed curve on the surface
  • Make the curve snap to surface (enable Markups module / Curve settings / Curve type → shortest distance on surface, model node → model node that you would like to cut)
  • Copy-paste this code snippet to the Python console
# Get input data
curveNode = getNode('C')
modelNode = getNode('Segment_1')
extractLargestPart = False

# Get VTK data objects from MRML nodes
curvePoints = curveNode.GetCurvePointsWorld()
meshToClip = modelNode.GetMesh()  # we should apply transform to World

# Clip model with curve
loop = vtk.vtkSelectPolyData()
loop.SetLoop(curvePoints)
loop.GenerateSelectionScalarsOn()
loop.SetInputData(meshToClip)
loop.SetSelectionModeToLargestRegion()
clip = vtk.vtkClipPolyData()
clip.InsideOutOn()
clip.SetInputConnection(loop.GetOutputPort())
clip.GenerateClippedOutputOn()
clip.Update()
clippedOutput = clip.GetOutput() if extractLargestPart else clip.GetClippedOutput()

# Remove unused points
cleaner = vtk.vtkCleanPolyData()
cleaner.SetInputData(clippedOutput)
cleaner.Update()
cleanedClippedOutput = cleaner.GetOutput()

# Save result to new node
clippedModel = slicer.modules.models.logic().AddModel(cleanedClippedOutput)
clippedModel.GetDisplayNode().SetActiveScalarName("")
clippedModel.GetDisplayNode().BackfaceCullingOff()

There are of course many alternative methods to edit and combine meshes - using VTK filters and/or using numpy.

3 Likes

Thank you very much for your response.

Hello,
Should the curve have specific properties? I tried the code with some simple geometries and it worked, but when I try it with a more complex medel, it does not work. Here is my model and the fitted curve:

And the result I get is:


I tried to change “extractLargestPart” to true in the code but in that case, what I get is the whole model without any cut. Do you have any idea about what should I do regarding this problem?
Thanks

We experienced it, too, that vtkSelectPolyData filter was “not robust” (behavior might have been correct, but not what we expected) when there were holes or other errors in the mesh.

Holes can easily break selection of “one side” of the surface, because a hole connects the two sides of a surface, so you actually don’t have two separate sides of the surface anymore. This is the correct behavior, but maybe it would result in a more intuitive behavior if an option was added to the selection filter to stop at feature edges (where there is a sudden change in cell normals).

Thank you very much. So for now you think the best way is to smooth the model as much as possible? and is there anyway to fill the holes in an existing model or I should do the segmentation from beginning?
Thanks.

Yes, smoothing and hole filling should make the surfaces closed and manifold. You can use Segment Editor’s Smoothing effect.

If you don’t have a segmentation just a model (surface mesh) then you can try Surface Toolbox module’s smoothing, cleaning, hole filling functions. If they are not effective then you can import the model into a segmentation node and use Segment Editor.

1 Like

Thank you very much for your help.