# 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:** 19\
**Page:** 3

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [August 15, 2018, 12:21pm UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/41 "2018-08-15T12:21:27Z")

</div>

From [this](https://discourse.slicer.org/t/3d-model-of-only-the-outer-surface-of-a-bone-3d-model-of-a-bone/2714/6) thread:  
“Cleaver generates a “background” mesh so that you can simulate embedding your structures in some material (soft tissue, etc). If you don’t need these mesh elements, then don’t use them. Each cell is assigned to a segment, specified by `labels` cell attribute. You can use this attribute to assign material properties or remove parts of the mesh, etc.”

---

<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 20, 2018, 11:53am UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/42 "2018-08-20T11:53:41Z")

</div>

This is a simple question I am asking here. I do not know how to get going with slicer interpreter. every-time the application crashes due to some error I lost all my written code. is there any way to retrieve your last code in interpreter. I have to write again and again. How to setup environment for coding in slicer using scripting

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [August 20, 2018, 12:10pm UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/43 "2018-08-20T12:10:09Z")

</div>

I find the best thing is to create an extension with a scripted module and use the Reload buttons to execute the associated test. This way you can easily reproduce your work and add functionality incrementally.

See the slides and info here:

[https://www.slicer.org/wiki/Documentation/Nightly/Developers/Python\_scripting#Start\_Here](https://www.slicer.org/wiki/Documentation/Nightly/Developers/Python_scripting#Start_Here)

> [@Saima](#):
>
> is there any way to retrieve your last code in interpreter.

The log file has a record of everything you typed in.

---

<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 20, 2018, 12:19pm UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/44 "2018-08-20T12:19:52Z")

</div>

Thank you so much for replying. What about the edit it opens up for you in a notepad which is not good enough. What to do about this?

---

<div class="post-metadata">

**Author:** ![ihnorton](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ihnorton/32/9_2.png) [@ihnorton](https://discourse.slicer.org/u/ihnorton)\
**Post date:** [August 20, 2018, 3:46pm UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/45 "2018-08-20T15:46:13Z")

</div>

There are many editors available with good Python support – PyCharm (Community is free but does not support remote debugging), Spyder, Visual Studio Code, even Notepad++ has good basic Python highlighting and indenting.

By the way, along the lines Steve mentioned, if I don’t want to make a “full” module yet, then I usually still write my code in a file and load it with [`execfile`](https://docs.python.org/2/library/functions.html#execfile) in case there is a crash while interacting with C++ APIs.

---

<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 20, 2018, 3:52pm UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/46 "2018-08-20T15:52:32Z")

</div>

> [@Saima](#):
>
> every-time the application crashes due to some error I lost all my written code

Everything that you typed in the console are automatically saved in application logs. After you restart Slicer, in menu choose: Help / Report a bug, select any of the previous session from the list, and you’ll see the commands you typed.

Previously, when I was not developing a module, I’ve been mostly copy-pasting from editors. However, now there is a new, very nice alternative: [using Slicer from Jupyter notebooks](https://discourse.slicer.org/t/jupyter-notebooks-are-now-usable-in-3d-slicer/3438). Instead of manual copy-pasting, you enter your code as small blocks of text, which is very easy to edit and re-run.

---

<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 24, 2018, 4:59am UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/47 "2018-08-24T04:59:55Z")

</div>

Dear Andras,  
I do not understand the implicit function. If I want to get only the brain+tumur+ventricles mesh how do I define the implicit function?

Thank you

Looking forward

---

<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 24, 2018, 1:38pm UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/48 "2018-08-24T13:38:21Z")

</div>

Sorry, I don’t know what implicit function you are referring to.

---

<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 27, 2018, 2:56am UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/49 "2018-08-27T02:56:24Z")

</div>

In extract geometry filter. there is an implicit function. I do not understand the purpose of using this implicit function?  
Would you please explain what is its purpose?

---

<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 27, 2018, 3:35am UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/50 "2018-08-27T03:35:34Z")

</div>

I see, yes, vtkExtractGeometry is for extracting a sub-mesh using an implicit function, which is not what you need. I meant that you can use [vtkGeometryFilter](https://www.vtk.org/doc/nightly/html/classvtkGeometryFilter.html) to extract boundary surface of an unstructured grid.

---

<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 27, 2018, 10:55am UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/51 "2018-08-27T10:55:21Z")

</div>

Andras, would you please tell me about the purpose of setextractionmodetospecified regions().

---

<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 27, 2018, 11:48am UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/52 "2018-08-27T11:48:57Z")

</div>

To get boundary surface, you need to use [vtkGeometryFilter](https://www.vtk.org/doc/nightly/html/classvtkGeometryFilter.html), not vtkExtractGeometry.

---

<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 28, 2018, 12:10pm UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/53 "2018-08-28T12:10:08Z")

</div>

> [@lassoan](#):
>
> surface, you need

Hi Andras,  
I am using filter like this. Could you please help me in understanding the pipeline for using filters?

First I am using connectivity filter to seperate the meshes. I am not sure I am using correctly the specified regions. then vtkgeometryfilter.

```
connect = vtk.vtkConnectivityFilter()
connect.SetInputData(mesh)
connect.SetExtractionModeToSpecifiedRegions()
connect.AddSpecifiedRegion(1)
connect2 = vtk.vtkConnectivityFilter()
connect2.SetInputData(mesh)
connect2.SetExtractionModeToSpecifiedRegions()
connect2.AddSpecifiedRegion(2)
connect3 = vtk.vtkConnectivityFilter()
connect3.SetInputData(mesh)
connect3.SetExtractionModeToSpecifiedRegions()
connect3.AddSpecifiedRegion(3)

brain = vtk.vtkGeometryFilter()
brain.SetInputConnection(connect3.GetOutputPort())

brainMapper = vtk.vtkPolyDataMapper()
brainMapper.SetInputConnection(brain.GetOutputPort())

brainActor = vtk.vtkActor()
brainActor.SetMapper(brainMapper)

```

Usual stuff:

```
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

ren.AddActor(brainActor)

```

Could you please tell me what I am doing right. Am I using it correctly?  
I could not get the results (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:** ![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 28, 2018, 4:13pm UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/54 "2018-08-28T16:13:39Z")

</div>

To get help on how to use VTK, the VTK mailing list may be a better forum.

Anyway, some hints: If you need corresponding point IDs between selection/filtering input and output then read up on pedigree IDs. For example, vtkExtractSelectedThresholds may be able to extract sub-meshes defined by scalar range and provide pedigree IDs (point ID of the source mesh for each new point).

---

<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 29, 2018, 5:39am UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/55 "2018-08-29T05:39:43Z")

</div>

Dear Andras,  
I used threshold to get the geometry of interest.

Next is to get all the points corresponding to volumetric mesh with direct correspondence to volumetric mesh point ids. I will follow what you suggested me and come back again.

Thank you so much for helping.

Andras could you please tell me is there any way to get auto completion in jupyter for vtk and slicer.

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 29, 2018, 11:58am UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/56 "2018-08-29T11:58:17Z")

</div>

> [@Saima](#):
>
> Andras could you please tell me is there any way to get auto completion in jupyter for vtk and slicer.

It works in latest nightly build. If it does not work for you then please report it in a separate topic.

---

<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:** [December 19, 2018, 4:15am UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/57 "2018-12-19T04:15:27Z")

</div>

Hi Andras,  
What does cleaver meshing options represent. And what does tetGen meshing options represents.

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:** [December 19, 2018, 4:30am UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/58 "2018-12-19T04:30:36Z")

</div>

These are two volumetric mesh generator libraries. See details on their websites: [Cleaver2](https://sciinstitute.github.io/cleaver.pages), [TetGen](http://www.tetgen.org/). I would recommend Cleaver2, as it is more robust, has better support for multi-material meshes, and has free, non-restrictive license.

---

<div class="post-metadata">

**Author:** ![JonNithal](https://avatars.discourse-cdn.com/v4/letter/j/6de8d8/32.png) [@JonNithal](https://discourse.slicer.org/u/JonNithal)\
**Post date:** [May 8, 2025, 12:01pm UTC](https://discourse.slicer.org/t/use-segmentations-in-cad-or-fem-software/1626/60 "2025-05-08T12:01:51Z")

</div>

Hii @lassoan,

I was just wondering if there have been any updates or further progress on the plans you mentioned, especially around syncing CAD models with Slicer or improving mesh export workflows. I’m still exploring this area and would really appreciate hearing if anything new has come up.

Thanks!

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