# Error exporting and importing .vtk

**URL:** <https://discourse.slicer.org/t/error-exporting-and-importing-vtk/30733>\
**Category:** Support\
**Created:** [July 21, 2023, 7:36pm UTC](https://discourse.slicer.org/t/error-exporting-and-importing-vtk/30733 "2023-07-21T19:36:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gches](https://avatars.discourse-cdn.com/v4/letter/g/3ec8ea/32.png) [@gches](https://discourse.slicer.org/u/gches)\
**Post date:** [July 21, 2023, 7:36pm UTC](https://discourse.slicer.org/t/error-exporting-and-importing-vtk/30733/1 "2023-07-21T19:36:07Z")

</div>

Hello,

I am trying to save the centerline of a model to .vtk. I receive no errors when exporting, however, when importing the centerline into 3D slicer, I receive an error.

I received this error on both Slicer versions 4.11 and 5.2.2

The workflow is as follows:

1. Import the model that I want to find the centerline of (.vtk file format)
2. Use the extract centerline tool to obtain the centerline (using the network model output)
3. Export the centerline model as a .vtk file (unselected the compress option)
4. Importing that same centerline model back into the scene
5. An error is obtained and it failed to import

The error is as follows

- Error: Loading bifurCenterline.vtk - ERROR: In D:\D\S\S-0-build\VTK\IO\Legacy\vtkDataReader.cxx, line 1974  
vtkPolyDataReader (0000028B8AE06190): Unsupported data type:
- Error: Loading bifurCenterline.vtk - Failed to read node bifurCenterline\_1 (vtkMRMLModelNode11) from filename=‘bifurCenterline.vtk’

For reference, the bifurCenterline is the file name for the centerline .vtk file  
Thank you for any help.

---

<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 22, 2023, 1:23pm UTC](https://discourse.slicer.org/t/error-exporting-and-importing-vtk/30733/2 "2023-07-22T13:23:38Z")

</div>

.vtk files can store either a mesh or an image. It is used for meshes more commonly. It is not suitable for storing medical images, because it cannot store the patient orientation (if you use this format then your images may be rotated after saving into and loading from this format).

If you have want to load an image from .vtk format anyway then in the “Add data” window, choose “Volume” in the “Description” column.

---

<div class="post-metadata">

**Author:** ![gches](https://avatars.discourse-cdn.com/v4/letter/g/3ec8ea/32.png) [@gches](https://discourse.slicer.org/u/gches)\
**Post date:** [July 22, 2023, 5:42pm UTC](https://discourse.slicer.org/t/error-exporting-and-importing-vtk/30733/3 "2023-07-22T17:42:28Z")

</div>

I think the problem lies with slicer saving a corrupt or incorrectly formatted .vtk file for the centerline. I followed the steps from [this previous thread](https://discourse.slicer.org/t/how-to-export-centerline-generated-by-the-vmtk/22735/3) , but when I go to reopen the saved centerline I received the error I pasted above. I also receive an error when opening it in other .vtk file viewers such as paraview.

I’d be more than happy to provide the files for the model and the centerline if there is a way to do that.

---

<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 23, 2023, 3:10pm UTC](https://discourse.slicer.org/t/error-exporting-and-importing-vtk/30733/4 "2023-07-23T15:10:55Z")

</div>

Can you upload a problematic .vtk file somewhere and post the link here?

---

<div class="post-metadata">

**Author:** ![gches](https://avatars.discourse-cdn.com/v4/letter/g/3ec8ea/32.png) [@gches](https://discourse.slicer.org/u/gches)\
**Post date:** [July 23, 2023, 5:57pm UTC](https://discourse.slicer.org/t/error-exporting-and-importing-vtk/30733/5 "2023-07-23T17:57:48Z")

</div>

I attached two files:

bifurModel.vtk: The .vtk file I am attempting to find the centerline of using the extract centerline module. I have no issue importing and exporting this file. Here is a [google drive link](https://drive.google.com/file/d/1wW0KGUpPNTCSyx9ot3NJAlwp1-hWBu9S/view?usp=sharing).

bifurModelCenterline.vtk: This is the centerline generated by the extract centerline module. I exported it in .vtk file format without compression. However, I am unable to import it back into 3D slicer or view it in any other .vtk file viewers. Here is a [google drive link](https://drive.google.com/file/d/1H0-S91PZqFuAD4RogRjiFjKbrqH1tJNq/view?usp=sharing).

---

<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 24, 2023, 4:12am UTC](https://discourse.slicer.org/t/error-exporting-and-importing-vtk/30733/6 "2023-07-24T04:12:05Z")

</div>

One of values in the `Torsion` array contains an invalid value, which VTK saves as `-nan(ind)`. However, VTK cannot save and load such values in non-compressed (ASCII) .vtk file format. This is a bug in VTK and I’ve filed a bug report for you:

> **[Fail to load polydata from ASCII .vtk file if any array contain a nan value...](https://gitlab.kitware.com/vtk/vtk/-/issues/19028)**
>
> If there is an invalid value in any of the data arrays then the saved an ASCII .vtk file then VTK cannot read the file that it has...

To avoid running into this issue, you can save the centerline as .vtp file or binary .vtk file, or export the centerline into markup node and save as JSON.
