# How to render an ITK spatial object?

**URL:** <https://discourse.itk.org/t/how-to-render-an-itk-spatial-object/1516>\
**Category:** Algorithms\
**Created:** [January 11, 2019, 11:38am UTC](https://discourse.itk.org/t/how-to-render-an-itk-spatial-object/1516 "2019-01-11T11:38:45Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![TaoH](https://discourse.itk.org/user_avatar/discourse.itk.org/taoh/32/1374_2.png) [@TaoH](https://discourse.itk.org/u/TaoH)\
**Post date:** [January 11, 2019, 11:38am UTC](https://discourse.itk.org/t/how-to-render-an-itk-spatial-object/1516/1 "2019-01-11T11:38:45Z")

</div>

Dear everyone,

I want to render an ITK spatial object. Is there a convenient to make it?

Best and thanks,  
Tao Han

---

<div class="post-metadata">

**Author:** ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)\
**Post date:** [January 11, 2019, 1:58pm UTC](https://discourse.itk.org/t/how-to-render-an-itk-spatial-object/1516/2 "2019-01-11T13:58:34Z")

</div>

Hi @TaoH,

Which type of _SpatialObject_ would you like to render?

Matt

---

<div class="post-metadata">

**Author:** ![TaoH](https://discourse.itk.org/user_avatar/discourse.itk.org/taoh/32/1374_2.png) [@TaoH](https://discourse.itk.org/u/TaoH)\
**Post date:** [January 12, 2019, 12:38pm UTC](https://discourse.itk.org/t/how-to-render-an-itk-spatial-object/1516/3 "2019-01-12T12:38:26Z")

</div>

Hi @matt.mccormick,  
Thank you for your reply.  
I want to render ITK spatial objects such as TubeSpatialObject, CylinderSpatialObject or ArrowSpatialObject. Is there any interface depending on ITK and VTK?  
Best wishes,  
TaoH

---

<div class="post-metadata">

**Author:** ![jhlegarreta](https://discourse.itk.org/user_avatar/discourse.itk.org/jhlegarreta/32/476_2.png) [@jhlegarreta](https://discourse.itk.org/u/jhlegarreta)\
**Post date:** [January 13, 2019, 12:10am UTC](https://discourse.itk.org/t/how-to-render-an-itk-spatial-object/1516/4 "2019-01-13T00:10:02Z")

</div>

May be Chapter 5 in the [ITK Software Guide](https://itk.org/ItkSoftwareGuide.pdf) can be of help.

An `itk::Image` instance can be visualized directly using the [VtkGlue](https://github.com/InsightSoftwareConsortium/ITK/tree/master/Modules/Bridge/VtkGlue) bridge, where Pablo’s `runViewImage` [example](https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/Bridge/VtkGlue/test/runViewImage.cxx) becomes very handy. So you may need to translate your `itk::SpatialObject` to an `itk::Image` using the [itk::SpatialObjectToImageFilter](https://itk.org/Doxygen/html/classitk_1_1SpatialObjectToImageFilter.html).

If any of your objects contains a mesh, you can write it to file and then read it with VTK as a [vtk::PolyData](https://vtk.org/doc/nightly/html/classvtkPolyData.html) in order to render it.

---

<div class="post-metadata">

**Author:** ![TaoH](https://discourse.itk.org/user_avatar/discourse.itk.org/taoh/32/1374_2.png) [@TaoH](https://discourse.itk.org/u/TaoH)\
**Post date:** [January 17, 2019, 8:44am UTC](https://discourse.itk.org/t/how-to-render-an-itk-spatial-object/1516/5 "2019-01-17T08:44:07Z")

</div>

Thanks for your advice! However, A 3D itk::Image instance can not be visualized with runViewImage. Is there any handy way to render 3D ITK spatial objects?

---

<div class="post-metadata">

**Author:** ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)\
**Post date:** [January 17, 2019, 1:57pm UTC](https://discourse.itk.org/t/how-to-render-an-itk-spatial-object/1516/6 "2019-01-17T13:57:03Z")

</div>

Hi @TaoH,

I am looking at adding support for ITK spatial objects to the ITKVTKGlue module.

Which specific spatial objects are you interested in?

---

<div class="post-metadata">

**Author:** ![phcerdan](https://discourse.itk.org/user_avatar/discourse.itk.org/phcerdan/32/286_2.png) [@phcerdan](https://discourse.itk.org/u/phcerdan)\
**Post date:** [January 17, 2019, 3:34pm UTC](https://discourse.itk.org/t/how-to-render-an-itk-spatial-object/1516/7 "2019-01-17T15:34:06Z")

</div>

> [@TaoH](#):
>
> However, A 3D itk::Image instance can not be visualized with runViewImage

`runViewImage` is a CLI script wrapping around `itk::ViewImage`. You can use that function directly in your c++ code to visualize any image instance with:

```cpp
#include "itkViewImage.h"
...
itk::ViewImage<ImageType>::View(filterToImage->GetOutput());

```

It works with 2D and 3D images.

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [January 17, 2019, 4:25pm UTC](https://discourse.itk.org/t/how-to-render-an-itk-spatial-object/1516/8 "2019-01-17T16:25:00Z")

</div>

@matt.mccormick He already mentioned the spatial objects he is interested in:

> [@TaoH](#):
>
> TubeSpatialObject, CylinderSpatialObject or ArrowSpatialObject

---

<div class="post-metadata">

**Author:** ![TaoH](https://discourse.itk.org/user_avatar/discourse.itk.org/taoh/32/1374_2.png) [@TaoH](https://discourse.itk.org/u/TaoH)\
**Post date:** [January 18, 2019, 1:53am UTC](https://discourse.itk.org/t/how-to-render-an-itk-spatial-object/1516/9 "2019-01-18T01:53:50Z")

</div>

Thank you for your reply! This function just visualizes 3D images with three planes. However, I want to render the spatial object. Could you provide a handy advice for me? Thanks again.

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [January 18, 2019, 3:07pm UTC](https://discourse.itk.org/t/how-to-render-an-itk-spatial-object/1516/10 "2019-01-18T15:07:17Z")

</div>

> [@jhlegarreta](#):
>
> translate your `itk::SpatialObject` to an `itk::Image` using the [itk::SpatialObjectToImageFilter](https://itk.org/Doxygen/html/classitk_1_1SpatialObjectToImageFilter.html).

and then visualize it.

---

<div class="post-metadata">

**Author:** ![phcerdan](https://discourse.itk.org/user_avatar/discourse.itk.org/phcerdan/32/286_2.png) [@phcerdan](https://discourse.itk.org/u/phcerdan)\
**Post date:** [January 18, 2019, 4:28pm UTC](https://discourse.itk.org/t/how-to-render-an-itk-spatial-object/1516/11 "2019-01-18T16:28:34Z")

</div>

With the tools available in ITKVtkGlue right now you have to go with transforming a SpatialObject to an Image, as @jhlegarreta suggested. But it seems that the capability to render Spatial Objects is in the roadmap!

> [@matt.mccormick](#):
>
> I am looking at adding support for ITK spatial objects to the ITKVTKGlue module.

🥳 🥁
