# Use segmentations in CAD or FEM software

**URL:** <https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626>\
**Category:** Support\
**Tags:** segmentation\
**Created:** [December 9, 2017, 1:21pm UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626 "2017-12-09T13:21:31Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [March 2, 2018, 1:54pm UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/21 "2018-03-02T13:54:40Z")

</div>

Split this topic on March 2, 2018, 1:54pm UTC

A post was merged into an existing topic: [Panoramic image/view](https://discourse.slicer.org/t/panoramic-image-view/2203)

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [March 2, 2018, 4:44pm UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/22 "2018-03-02T16:44:02Z")

</div>

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](http://www.michelsencentre.com/doc/meshing_general_introduction_V3a.pdf)). 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](https://github.com/victorsndvg/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](https://knowledge.autodesk.com/support/fusion-360/learn-explore/caas/sfdcarticles/sfdcarticles/How-to-Convert-a-Mesh-to-a-BRep-in-Fusion-360.html)), but if you want to have usable result then you have to re-create the object manually (see for example [this tutorial](https://www.youtube.com/watch?v=8Z0IiVKt5Hg)).

---

<div class="post-metadata">

**Author:** ![gregorio](https://avatars.discourse-cdn.com/v4/letter/g/fbc32d/32.png) [@gregorio](https://discourse.slicer.org/u/gregorio)\
**Post date:** [March 19, 2018, 3:31pm UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/23 "2018-03-19T15:31:42Z")

</div>

@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](https://www.tandfonline.com/doi/abs/10.1080/10255842.2017.1383984?journalCode=gcmb20)

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [July 10, 2018, 7:42am UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/24 "2018-07-10T07:42:45Z")

</div>

> [@gregorio](#):
>
> D models are surface meshes,

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?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [July 10, 2018, 2:43pm UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/25 "2018-07-10T14:43:36Z")

</div>

> [@Saima](#):
>
> Does it need a segmented image as input to produce mesh?

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.

> [@Saima](#):
>
> is there any explanation on how to use segment mesher extension?

Yes. See documentation here: [GitHub - lassoan/SlicerSegmentMesher: Create volumetric mesh from segmentation using Cleaver2 or TetGen](https://github.com/lassoan/SlicerSegmentMesher)

> [@Saima](#):
>
> Is there any extension available that can create volumetric tetrahedral meshes directly form images in 3-d slicer?

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.

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [July 30, 2018, 9:16am UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/26 "2018-07-30T09:16:56Z")

</div>

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

Downloaded Braintumor data  
Labeled tumor and brain using editor in segmentation

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/b/4b06a27a99bb7f4cb52a21ad4cf1f5a05f27426c.jpeg)  
Mesh generation \>\> Clever

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/8/9/897f255008effc6197689caa52c544a760801366.jpeg)

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

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/a/ba714312ea8444e6642bfdc342935a313a47425b.jpeg)  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/9/3/9391af0a8b1973144d86475a8d1ab7dfbbe08b63.jpeg)

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.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/c/ec768406a14d520e39041cb99d4c6046ef97144f.jpeg)

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

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [July 30, 2018, 10:09am UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/27 "2018-07-30T10:09:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [July 30, 2018, 12:17pm UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/28 "2018-07-30T12:17:04Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/c/0/c0ee4ff1104c8508ddd61b3dcce471fbd77ad4d9.jpeg)

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

Thank you

Regards,  
Saima Safdar

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [July 30, 2018, 12:30pm UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/29 "2018-07-30T12:30:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [July 31, 2018, 7:33am UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/30 "2018-07-31T07:33:22Z")

</div>

> [@lassoan](#):
>
> ent 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

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [July 31, 2018, 8:00am UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/31 "2018-07-31T08:00:12Z")

</div>

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/](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.

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [July 31, 2018, 10:52am UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/32 "2018-07-31T10:52:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [August 2, 2018, 6:03am UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/33 "2018-08-02T06:03:16Z")

</div>

> [@lassoan](#):
>
> filters t

```
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

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [August 2, 2018, 7:26am UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/34 "2018-08-02T07:26:52Z")

</div>

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](https://www.vtk.org/gitweb?p=VTK.git;a=blob;f=Examples/Graphics/Python/SingleYoungsMaterialInterface.py):

```
# 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()
```

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [August 2, 2018, 8:09am UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/35 "2018-08-02T08:09:34Z")

</div>

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

 ![IMG_20180802_160424](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/9/2/92e86bd9d454b885a82813a1f2071e140a75bead.jpeg)

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [August 2, 2018, 8:45am UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/36 "2018-08-02T08:45:00Z")

</div>

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()`](https://slicer.readthedocs.io/en/latest/developer_guide/slicer.html).

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [August 3, 2018, 9:34am UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/37 "2018-08-03T09:34:30Z")

</div>

Split this topic on August 3, 2018, 9:34am UTC

A post was split to a new topic: [Python debugging in Eclipse](https://discourse.slicer.org/t/python-debugging-in-eclipse/3644)

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [August 11, 2018, 5:13am UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/38 "2018-08-11T05:13:14Z")

</div>

Dear Andras,  
Is it possible to generate surface mesh for brain using segment mesher. What will be the steps for doing it?

Thank you

Regards,  
Saima Safdar

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [August 11, 2018, 8:44am UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/39 "2018-08-11T08:44:23Z")

</div>

You can get a surface mesh by exporting segmentation to model node. If you need the surface mesh corresponding to the volumetric mesh with direct correspondence to volumetric mesh point IDs, then you can use VTK geometry filter on the volumetric mesh.

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [August 15, 2018, 4:56am UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/40 "2018-08-15T04:56:58Z")

</div>

Dear Andras,  
Yes I need to generate a surface mesh corresponding to the volumetric mesh. Can you please give details on how to do it?  
getnode-\>getmesh\>setoutputdata for extract filter = mesh\>extactinsideon\> ???\>mapper\>actor\>renderer\>renderwindow\>render windowinteractor

everytime when mesher is used cube is generated within which the geometry of interest(brain) exists. is it possible to have the volumetric mesh for only the segmented portion of the geometry or you have to extract it from cube?

Regards  
Saima Safdar

[Previous page](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626.md?page=1)

[Next page](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626.md?page=3)
