Use segmentations in CAD or FEM software

Thanks for the additional information. What is still not clear for me that if you can do all compositing of CAD models with anatomical structures in Slicer then why do you need NURBS export? Why cannot you use the volumetric mesh that Slicer generates directly in the FEM solver? I don’t think that FEM solvers represent structures as NURBS. Modeling programs do, but the idea is that the output of Slicer does not need further modeling.

@gregorio and @moondrake99

is it possible to provide some images/videos showing comparison cases e.g slicer output and output from other tools.

By FEM package, do you mean modeling tool, where you edit/combine 3D models? It is their limitation that they can only work with NURBS representation, and not with arbitrary segmented labelmaps (and not very well with complex triangle meshes).

This is the problem that Slicer solves, as it can edit/combine surface meshes and arbitrarily complex segmented labelmaps. Of course, modeling capabilities of Slicer are very limited compared to what modeling tools can do, but should be powerful enough so that you can use it as the last step of your workflow. Slicer’s output should not need further editing (so no NURBS representation is needed), you can feed it directly into FEM solvers/pre-processors.

It could be still nice to have NURBS-based editing in Slicer for simple, smooth shapes; but this is a special case and it is not very high on the priority list.

brhoom: yes. But this will take me some time (which I am rather short of atm). Will try.
lassoan:

By FEM package i mean a tool that does both the solving, but also preprocessing. And yes, it has some CAD ability in that it can edit and combine models. This has good reasons. One could for example examine the effect of a change in structure on whatever physics one is interested in. To change the structure, it helps tremedously to have some 3D processing in this package. You can also use solver approaches that can refine the mesh based on the model solution (finer mesh in areas with steep gradients).

I have needed to use both things in the past. But the current problem is perhaps simpler:

A typical but simplified example would be to do a diffusion model inside a single cell. Images are e.g. from SBF-SEM. Imagine I have a cytoplasm and many mitochondria. I segment the cells and the mitochondria.

The main problem now is that for the FEM analysis, I need to define the surface of the mitochondria (the membrane) as a kind of flux discontinuity as it’s permeability is quite low, but it is only very thin. A way to deal with such thin elastic layers is to have a surface mesh on the outside of the mitochondria and on the “inside” of the cell (basically the holes you would get if you would substract the mito-volume from the cellular volume). These two meshes can be coupled (sometimes called contact or identity pairs) and given a simple relation (in this case, something like C1-C2=F/G, where C are concentrations on the contact mesh sides, G is a conductance and F is a normal diffusive flux). Such couplings put some constraints on the 2 surface meshes (I forgot the details, but I assume they have to be roughly matching to prevent errors).

The whole thing is than solved in what my current favourite FEM package calls “assembly mode”. It roughly means you actually have 2 separate FEM models that are coupled with some equation(the simple 1D permeability above). These may even be different physics.

I have not found a way to create such meshes with other tools. And if I had, I am not sure I could make my current FEM package use such mesh in assembly mode (as it would not know elements of the mesh are to be coupled without doing the operation itself or an exchange file-format that lists them).

A second problem is that a mesh of a blobby object like a cell is quite irregular. Now, I may want to define a boundary condition (e.g. an influx of stuff) on only part of this cell surface (for example, where it intersects with another shape). You are right I can do the compositing in Slicer, but a mesh is just a mesh and I have no idea what mesh elements are the ones that I need to define different boundary conditions on.

If I do the compositing in the FEM package, it keeps track of such boundaries and I can set different conditions on that.

The physics coupling and separation of mesh and geometry is the whole reason I use a bloody expensive FEM package instead of the quite good free solvers. But the disadvantage is that I have to use THEIR compositing (which is not that good). And you are right that it is their limitation that the compositing works with NURBS. The solution some people found is to pay even more and buy simpleware or mimics who are apparently good at creating a NURBS representation out of meshes. To be fair, even comsol provides a mesh->nurbs converter, but it is not an easy problem and does not work perfect for me (it is my main time sink).

A post was merged into an existing topic: Panoramic image/view

Thank you for the detailed explanation. I think I now understand your needs better.

  1. Updating of CAD models

It can be certainly useful to update your CAD model as you combine it with anatomical shapes. We plan to implement real-time synchronization with selected modeling software (Blender and FreeCAD) so that if you modify your CAD model, the changes show up immediately in Slicer. This would make it easier to create an updated volumetric mesh whenever you adjust your CAD model.

  1. Mesh generation

COMSOL’s mesh generation capabilities are very nice, but you don’t need to use them, if you generate your volumetric mesh in another software. COMSOL can load volumetric meshes in COMSOL or NASTRAN format (see “Importing COMSOL Meshes” slide here). This is the approach that Materialise Mimics and Simpleware ScanFE use and you can do it with Slicer, too: save the volumetric mesh as a VTK unstructured grid file (.vtu) and convert it to COMSOL or NASTRAN using FEconv. With a little work, FEconv could be added to Slicer as an extension and then you could save the volumetric mesh directly from Slicer to a variety of FE mesh file formats.

  1. Converting surface meshes NURBS/BRep solids

We are using SolidWorks and Autodesk Fusion 360 and they of course cannot automatically convert meshes to solids (NURBS or BRep). This is similar to how vector graphics programs deal with bitmap images: they can load them, nicely display them, and can convert to vector graphics - kind of, with some data loss.

Reverse engineering tools sometimes work for simple geometric shapes (Fusion 360 sets the limit at about 10000 facets), but if you want to have usable result then you have to re-create the object manually (see for example this tutorial).

2 Likes

@moondrake99 thank you very much for the way you carried out the discussion. I’m sorry for my absence in the meantime, but I found you highlighted the problem in a more exhaustive way than I can.

I try to explain again my simplier challenge, the reason why I need geometry: with anatomical structures, in particular in the knee and with contact problems in FEM, it would be better to have volumetric HEXAHEDRAL meshes than tetrahedral meshes. More in general, to have a certain control on mesh process (number and TYPE of elements): with free softwares, I am finding problems in converting native trianglular (tetrahedral) meshes into smooth surfaces (CAD geometries, i.e. nurbs) that I can mesh in the way I want (possibly hexhaedral meshes and in an automatic way: “I.A.FEMesh” software makes it but meanly manually).

Here a recent reference strictly related to my problem:
“Automated hexahedral meshing of knee cartilage structures – application to data from the osteoarthritis initiative”

https://www.tandfonline.com/doi/abs/10.1080/10255842.2017.1383984?journalCode=gcmb20

1 Like

Hi Andras,
I was looking at this extension. Does it need a segmented image as input to produce mesh? is there any explanation on how to use segment mesher extension? Is there any extension available that can create volumetric tetrahedral meshes directly form images in 3-d slicer?

You need a segmentation node as input. You can create segmentation node from an existing labelmap volume or model node (surface mesh). If all you have is an grayscale input volume, then you can create a segmentation node using Segment editor module.

Yes. See documentation here: GitHub - lassoan/SlicerSegmentMesher: Create volumetric mesh from segmentation using Cleaver2 or TetGen

Without segmentation? Would you like to fill the image volume with uniformly sized tetrahedra? If you segment structures then you can create a volumetric mesh for those using Segment mesher extension.

2 Likes

Dear Lasso,
I tried to use the segment mesher extension. Followed these steps:

Downloaded Braintumor data
Labeled tumor and brain using editor in segmentation


Mesh generation >> Clever

Settings
Selected labels as inputs
Output models new >> output model1 and output model 2


Apply and got the results you can see in the image in 3D view.

Can I get mesh generation for each of the label separately?
How to extract the nodes of the mesh generated for the structure in python?

In segmentMesher I did the following. Please see the screen shot.
In segmentation I can only select segmentation. I do not see any other option.

What I am doing wrong. Please tell me.
Thank you
REgards,
Saima Safdar

Use recent nightly version of Slicer. You can Segment using Segment Editor module and create volumetric mesh using Segment mesher extension.

Did segmentation with segment editor for brain portion.
Then using Segment Mesher it generated the following.

How to access all the nodes(points) for the mesh generated for the brain portion?

Thank you

Regards,
Saima Safdar

Segment index is stored in the mesh for each cell as cell scalar data.

mesh = n.GetMesh()

mesh
(vtkCommonDataModelPython.vtkUnstructuredGrid)

Dear Lasso I need to understand its architecture.

Aim is to extract the vertexes and its x, y, z locations of only the brain portion of the mesh generated. Please help.
Any way to get the description for the methods and the pipeline to use.

Regards,
Saima Safdar

You can extract any portion of the mesh by using Slicer’s Python console, using VTK filters that extract cells that have scalars in the specified range. Probably threshold filter would work and it takes only a few lines of Python code.

If you are not familiar with VTK then read the VTK textbook (https://blog.kitware.com/vtk-textbook-and-users-guide-now-available-for-download/) or use other mesh pre-processing software that can extract sub-meshes, such as Paraview or MeshLab.

thank you Andras. I will contact you once I done.

1 Like
for j in range(mesh.GetNumberOfCells()):
...  cellObject = mesh.GetCell(j)
...  pts = cellObject.GetPoints()
...  data = pts.GetData()
...  for i in range(data.GetNumberOfTuples()):
...   print("%s",data.GetTuple(i))
... 
('%s', (-72.65650177001953, 62.96849822998047, 56.67499923706055))
('%s', (-72.65650177001953, 89.84349822998047, 56.67499923706055))
('%s', (-91.40650177001953, 89.84349822998047, 56.67499923706055))
('%s', (-72.65650177001953, 68.21849822998047, 78.30000305175781))
('%s', (-72.65650177001953, 116.71849822998047, 56.67499923706055))
('%s', (-72.65650177001953, 116.71849822998047, 29.799999237060547))
('%s', (-91.40650177001953, 97.96849822998047, 48.54999923706055))
('%s', (-91.40650177001953, 116.71849822998047, 48.54999923706055))

Dear Andras is this right?
These are points locations x,y,z for every tetra. which I understand.

Please tell me if I am doing anything wrong.
Another thing is I want to color a specific cell in the generated mesh. How to do this?

I am also looking into vtkextractcells.

Thank you

Regards,
Saima Safdar

I cannot really follow what you are trying to do, but you can find complete example of extracting submesh corresponding to a specific material here:

# Extract submeshes corresponding to 2 different material Ids
cellData.SetActiveScalars( "Material Id" )
threshold2 = vtkThreshold()
threshold2.SetInputData( mesh )
threshold2.SetInputArrayToProcess(0, 0, 0, vtkDataObject.FIELD_ASSOCIATION_CELLS, vtkDataSetAttributes.SCALARS );
threshold2.ThresholdByLower( 2 )
threshold2.Update()
meshMat2 = threshold2.GetOutput()
threshold3 = vtkThreshold()
threshold3.SetInputData( mesh )
threshold3.SetInputArrayToProcess(0, 0, 0, vtkDataObject.FIELD_ASSOCIATION_CELLS, vtkDataSetAttributes.SCALARS );
threshold3.ThresholdByUpper( 3 )
threshold3.Update()
meshMat3 = threshold3.GetOutput()

I am trying to extract every point id along with its x,y,z coordinates.

Specifically, the aim is to extract locations of all the cells of the segmented portion of the mesh

You can extract sub-mesh using VTK threshold filter and then access all the point coordinates in a numpy array by calling slicer.util.arrayFromModelPoints().