# Display vtkMarchingCubes in 3d view

**URL:** <https://discourse.slicer.org/t/display-vtkmarchingcubes-in-3d-view/1471>\
**Category:** Development\
**Created:** [November 16, 2017, 5:27pm UTC](https://discourse.slicer.org/t/display-vtkmarchingcubes-in-3d-view/1471 "2017-11-16T17:27:14Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![TTrambi](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ttrambi/32/894_2.png) [@TTrambi](https://discourse.slicer.org/u/TTrambi)\
**Post date:** [November 16, 2017, 5:27pm UTC](https://discourse.slicer.org/t/display-vtkmarchingcubes-in-3d-view/1471/1 "2017-11-16T17:27:14Z")

</div>

Hi I’m at slicer develoment and i got a basic question:

I’m reading in dicom data and after some processing I convert it to vtk using the vtkImageImport.  
Then I create a mesh via the vtkMarchingCubes and save it to a .stl file.

So, my question is, how can i display my vtkMarchingCube or volume in the 3d view of 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:** [November 16, 2017, 5:35pm UTC](https://discourse.slicer.org/t/display-vtkmarchingcubes-in-3d-view/1471/2 "2017-11-16T17:35:32Z")

</div>

You can use [Models module logic](http://apidocs.slicer.org/master/classvtkSlicerModelsLogic.html#a90951d618e0de9f6048efaedfc79427c) to create a model node from vtkPolyData object:

```
slicer.modules.models.logic().AddModel(myPolyData)

```

Note that you don’t need to implement low-level features such as loading image from DICOM or model generation using marching cubes. If you tell us know what the end goal of your project is then we can give you specific advice about how to achieve that in Slicer.

---

<div class="post-metadata">

**Author:** ![TTrambi](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ttrambi/32/894_2.png) [@TTrambi](https://discourse.slicer.org/u/TTrambi)\
**Post date:** [November 20, 2017, 3:06pm UTC](https://discourse.slicer.org/t/display-vtkmarchingcubes-in-3d-view/1471/3 "2017-11-20T15:06:07Z")

</div>

Hi, thanks for your helping me out.

I’m working on an automatic breast cancer segmenation module from dce-mri, using the same method as the Segment CAD module ([Documentation/Nightly/Modules/SegmentCAD - Slicer Wiki](https://www.slicer.org/wiki/Documentation/Nightly/Modules/SegmentCAD)), but my plan is to segment the tumor instead of giving a label map.

So, i have to read in the dicom data manually because of some problems with the files. The files are from the cancerwiki ([https://wiki.cancerimagingarchive.net/display/Public/Breast-MRI-NACT-Pilot](https://wiki.cancerimagingarchive.net/display/Public/Breast-MRI-NACT-Pilot)) and i dont think there is another way then read in all the dcm files manually because they are not in correct order and not sort by timepoint.

Now I’m running into some trouble with the segmentation as you can see on my appended picture. You can see the tumor on the left part, but there is a big chest part showing up and all the blood vessels.  
My idea is to remove the chest part with the by removing the largest part with vtkPolyDataConnectivityFilter and use the itk Hessian3DToVesselnessMeasureImageFilter, but i dont know how to remove one polydata from another polydata and how i can use my vtkPolyData with itk.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/1/b/1b10527f1d725eb52a98cf066175d83f289b2995.png)

---

<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:** [November 20, 2017, 3:58pm UTC](https://discourse.slicer.org/t/display-vtkmarchingcubes-in-3d-view/1471/4 "2017-11-20T15:58:09Z")

</div>

I’ve successfully loaded UCSF-BR-01 using DICOM module:

- drag-and-drop the folder to Slicer application window
- click OK to import as DICOM
- open DICOM browser module to load the imported data
- choose which data sets to show using Data module

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

It loaded everything perfectly, even segmentations and time sequences (Sagittal-IR\_3DFGRE volume). After adjusting segment colors and making 3D display semi-transparent:

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

You can very easily segment the tumor yourself, using Segment editor module. While simple thresholding is available in the module (`Threshold` effect), you probably want to use `Grow from seeds` effect for tumor segmentation. Just paint inside and outside the tumor with different segments and use `Grow from seeds` to create a complete segmentation.

---

<div class="post-metadata">

**Author:** ![TTrambi](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ttrambi/32/894_2.png) [@TTrambi](https://discourse.slicer.org/u/TTrambi)\
**Post date:** [November 21, 2017, 12:38am UTC](https://discourse.slicer.org/t/display-vtkmarchingcubes-in-3d-view/1471/5 "2017-11-21T00:38:34Z")

</div>

Thank you once again.

Further, how can i change the time point in the slice view when i’ve loaded in the 4-dimensional data?  
(drag and drop is only supported at version 4.9)

As I mentioned, i want to implement an automatic segmentation module, so i dont want to place a seed. Can you please explain to me how i can cut vktPolyData out of vtkPolydata.

---

<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:** [November 21, 2017, 2:14am UTC](https://discourse.slicer.org/t/display-vtkmarchingcubes-in-3d-view/1471/6 "2017-11-21T02:14:37Z")

</div>

> [@TTrambi](#):
>
> Can you please explain to me how i can cut vktPolyData out of vtkPolydata.

Boolean operations on meshes are extremely difficult to implement. Maybe not even possible to implement in a way that is guaranteed to work for any geometry, within reasonable time. VTK has some Boolean mesh filters, but of course they very often fail for complex geometries (and unfortunately, randomly fail even for simple ones). I would not recommend to use them.

Fortunately, you don’t need to implement vtkPolyData cutting, as your inputs are volumes, and segmentation can be represented as labelmaps. Implementing Boolean operations on labelmaps is quick and guaranteed to work correctly all the time.

You can use the `Logical operators` effect of Segment Editor as described [here](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#How_to_run_segment_editor_effects_from_a_script).

> [@TTrambi](#):
>
> i want to implement an automatic segmentation module, so i dont want to place a seed

I guess you mean you don’t want to place a seed manually. You can create seeds automatically. For example, in some cases you can create seeds by thresholding (using Thresholding effect), followed by splitting of islands to segments (using Islands effect). Or, you may defining seeds for an atlas and then registering that atlas to your patient image and generate seeds by applying the computed transform to the atlas seeds. Of course, there are many approaches to automatic segmentation - not all of them are based on region growing.

---

<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:** [November 21, 2017, 2:21am UTC](https://discourse.slicer.org/t/display-vtkmarchingcubes-in-3d-view/1471/7 "2017-11-21T02:21:53Z")

</div>

> [@TTrambi](#):
>
> how can i change the time point in the slice view when i’ve loaded in the 4-dimensional data?

If you use Slicer 4.8 or older then 4D DICOM files are always loaded as MultiVolume and you can browse time points using MultiVolumeExplorer module.

If you use a recent nightly build then in menu: Edit/Application settings/DICOM you can choose between loading 4D volumes as Multivolume nodes or as Volume Sequence nodes. Loading as Volume Sequence node requires installation of Sequences extension and you may find it slightly easier to browse the time points, as you can use the Sequence browser toolbar instead of switching between modules.

---

<div class="post-metadata">

**Author:** ![MGM](https://avatars.discourse-cdn.com/v4/letter/m/ebca7d/32.png) [@MGM](https://discourse.slicer.org/u/MGM)\
**Post date:** [March 9, 2018, 5:32pm UTC](https://discourse.slicer.org/t/display-vtkmarchingcubes-in-3d-view/1471/8 "2018-03-09T17:32:03Z")

</div>

Hi @TTrambi

I saw in your first post, that you usefully saved to .stl , using vtkMarchingCubes.  
I would like to know what method you used ?

because, I’m tried to do the same thing, just to save as vtk file.

@lassoan, any idea ?

Thank you for your time

---

<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 9, 2018, 5:45pm UTC](https://discourse.slicer.org/t/display-vtkmarchingcubes-in-3d-view/1471/9 "2018-03-09T17:45:01Z")

</div>

You can choose file format in the Save data dialog.

---

<div class="post-metadata">

**Author:** ![MGM](https://avatars.discourse-cdn.com/v4/letter/m/ebca7d/32.png) [@MGM](https://discourse.slicer.org/u/MGM)\
**Post date:** [March 13, 2018, 4:19pm UTC](https://discourse.slicer.org/t/display-vtkmarchingcubes-in-3d-view/1471/10 "2018-03-13T16:19:14Z")

</div>

Hi @lassoan

it’s working with vtkPolyDataWriter 👌

now, I’m looking for another way, so I can get a small file size.

Thanks

---

<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 15, 2018, 4:37am UTC](https://discourse.slicer.org/t/display-vtkmarchingcubes-in-3d-view/1471/11 "2018-03-15T04:37:53Z")

</div>

Typically you can reduce the number of points to 10-20% of the original number by applying decimation, without negligible visible difference. You can apply decimation in Segmentations module when you create the closed surface representation from binary labelmap representation (click Update button in Closed surface representation row in Representations section in Segmentations module); or if you already have a model node then you can use Surface Toolbox module.
