# vtk polydata file

**URL:** https://discourse.itk.org/t/vtk-polydata-file/2558
**Category:** Beginner Questions
**Created:** [December 20, 2019, 3:50pm UTC](https://discourse.itk.org/t/vtk-polydata-file/2558 "2019-12-20T15:50:28Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![nour](https://discourse.itk.org/user_avatar/discourse.itk.org/nour/32/1145_2.png) [@nour](https://discourse.itk.org/u/nour)
#### Post date: [December 20, 2019, 3:50pm UTC](https://discourse.itk.org/t/vtk-polydata-file/2558/1 "2019-12-20T15:50:29Z")

</div>

I used to convert nifti file to .vtk file but what I noticed that there are many versions.  
I need `# vtk DataFile Version 3.0` but this code gives me `# vtk DataFile Version 4.2`.

```auto
import vtk
import sys

reader = vtk.vtkNIFTIImageReader()
reader.SetFileName(sys.argv[1])
reader.Update()
print (reader)

contour=vtk.vtkMarchingCubes()  
contour.SetInputData(reader.GetOutput())
contour.ComputeNormalsOn()
contour.ComputeGradientsOn()
contour.SetValue(0,0.1)
contour.Update()
 
# Write in vtk
triangle = vtk.vtkTriangleFilter()
triangle.SetInputConnection(contour.GetOutputPort())
triangle.PassVertsOff()
triangle.PassLinesOff()
 
decimation=vtk.vtkQuadricDecimation()
decimation.SetInputConnection(triangle.GetOutputPort())
 
clean=vtk.vtkCleanPolyData()
clean.SetInputConnection(triangle.GetOutputPort())
 
triangle2 = vtk.vtkTriangleFilter()
triangle2.SetInputConnection(clean.GetOutputPort())
triangle2.PassVertsOff()
triangle2.PassLinesOff()

#save .vtk polydata
writer = vtk.vtkPolyDataWriter()
writer.SetFileTypeToASCII()
writer.SetInputConnection(contour.GetOutputPort())
writer.SetFileName("1.vtk")
writer.Write()

```

what I get after runnig this code :  
 ![80367805_557148228180036_6815696929305919488_n](https://discourse.itk.org/uploads/default/original/2X/e/e54587d93c293a4f649283f8b6f3dc1af2a9bfb6.png)

what I need

![80358453_747858695691280_844619938827075584_n](https://discourse.itk.org/uploads/default/original/2X/7/7c9f7e5302f5a632a6d6db3b86ca6696d58aad68.png)

could someone help me

---

<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: [December 20, 2019, 4:29pm UTC](https://discourse.itk.org/t/vtk-polydata-file/2558/2 "2019-12-20T16:29:19Z")

</div>

A sure way is to use a very old version of VTK, which writes DataFile Version 3.0.

For basic features (like simple geometry), the files format versions 3.0 and 4.2 might be identical, so just changing the comment in the first line using a text editor could be enough.

There might be a way to force VTK to write the older version of the format. To find out, ask on the [VTK forum](https://discourse.vtk.org/).

---

<div class="post-metadata">

### Author: ![dchen](https://discourse.itk.org/user_avatar/discourse.itk.org/dchen/32/34_2.png) [@dchen](https://discourse.itk.org/u/dchen)
#### Post date: [December 20, 2019, 5:54pm UTC](https://discourse.itk.org/t/vtk-polydata-file/2558/3 "2019-12-20T17:54:16Z")

</div>

I’d guess with a basic ASCII PolyData mesh, you can just edit the header with a text editor to change the 4.2 to 3.0.

---

<div class="post-metadata">

### Author: ![nour](https://discourse.itk.org/user_avatar/discourse.itk.org/nour/32/1145_2.png) [@nour](https://discourse.itk.org/u/nour)
#### Post date: [December 20, 2019, 9:28pm UTC](https://discourse.itk.org/t/vtk-polydata-file/2558/4 "2019-12-20T21:28:35Z")

</div>

no if you have noticed : the 4.2 file has 9 numbers as points but the other one 3.0 has only 3 which I have this error \<\<Details: cannot copy sequence with size 9 to array axis with dimension 3 \>\> when I want to display the image.  
Did you understand me ??
