# Issue loading VTK file

**URL:** https://discourse.slicer.org/t/issue-loading-vtk-file/24469
**Category:** Support
**Tags:** vtk, matlab
**Created:** [July 24, 2022, 5:04pm UTC](https://discourse.slicer.org/t/issue-loading-vtk-file/24469 "2022-07-24T17:04:30Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![jsalas424](https://avatars.discourse-cdn.com/v4/letter/j/a87d85/32.png) [@jsalas424](https://discourse.slicer.org/u/jsalas424)
#### Post date: [July 24, 2022, 5:04pm UTC](https://discourse.slicer.org/t/issue-loading-vtk-file/24469/1 "2022-07-24T17:04:30Z")

</div>

Hello,

I generated a VTK file matlab using [vtkwrite](https://www.mathworks.com/matlabcentral/fileexchange/47814-vtkwrite-exports-various-2d-3d-data-to-paraview-in-vtk-file-format) from triangle mesh data.

The raw data looks like this:

```auto
16.2150000000000	13.2360000000000	126.065000000000
16.1490000000000	14.2370000000000	125.708000000000
16.8430000000000	13.7070000000000	125.851000000000
15.1780000000000	14.2980000000000	127.202000000000
16.7530000000000	14.3570000000000	125.554000000000
17.0650000000000	12.6940000000000	126.724000000000
16.1660000000000	12.0880000000000	126.873000000000
...............

```

Here’s the VTK exported file: [# vtk DataFile Version 2.0VTK from MatlabASCIIDATASET POLYDATAPOINTS 100 - Pastebin.com](https://pastebin.com/E9YH6KLq)

When I load this into Slicer 5.0.3 it just crashes immediately

So I opened up Slicer 4.11.20210226 and got the following error:

```auto
- Error: Loading C:/.../mesh.vtk - ERROR: In D:\D\S\Slicer-1-build\VTK\IO\Legacy\vtkDataReader.cxx, line 3177
vtkPolyDataReader (000001BD00FACD60): Error reading ascii cell data! for file: C:/..../mesh.vtk
- Error: Loading C:/.../mesh.vtk - Failed to read node mesh_1 (vtkMRMLModelNode5) from filename='C:/.../mesh.vtk'

```

---

<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: [July 24, 2022, 5:47pm UTC](https://discourse.slicer.org/t/issue-loading-vtk-file/24469/2 "2022-07-24T17:47:56Z")

</div>

Someone here may be able to help, but this question would be better directed to a matlab forum (or if you really think the file is correct then the vtk forum, but I suspect the issue is how the matlab code created the file).

---

<div class="post-metadata">

### Author: ![jsalas424](https://avatars.discourse-cdn.com/v4/letter/j/a87d85/32.png) [@jsalas424](https://discourse.slicer.org/u/jsalas424)
#### Post date: [July 24, 2022, 7:15pm UTC](https://discourse.slicer.org/t/issue-loading-vtk-file/24469/3 "2022-07-24T19:15:07Z")

</div>

I opened an issue with the vtkwrite Git here: [Issue loading vtkwrite-generated file into 3D Slicer · Issue #5 · joe-of-all-trades/vtkwrite · GitHub](https://github.com/joe-of-all-trades/vtkwrite/issues/5)

Any other suggestions about how to generate a slicer-compatible VTK given x, y, z vertex coordinate data?

---

<div class="post-metadata">

### Author: ![jsalas424](https://avatars.discourse-cdn.com/v4/letter/j/a87d85/32.png) [@jsalas424](https://discourse.slicer.org/u/jsalas424)
#### Post date: [July 24, 2022, 9:46pm UTC](https://discourse.slicer.org/t/issue-loading-vtk-file/24469/4 "2022-07-24T21:46:48Z")

</div>

This is solved. It was an issue with the VTK file. I’ve figured it out!

I was using the OpenEP platform to import CARTO data, so the following solution will be how to generate VTK’s from OpenEP using vtkwrite in Matlab.

```auto
x = userdata.surface.triRep.X(1:end,1);
y = userdata.surface.triRep.X(1:end,2);
z = userdata.surface.triRep.X(1:end,3);
vtkwrite('mesh.vtk','polydata','triangle',x,y,z,userdata.surface.triRep.Triangulation);

```
