# Write vtk file from mha volume input

**URL:** <https://discourse.slicer.org/t/write-vtk-file-from-mha-volume-input/2684>\
**Category:** Development\
**Created:** [April 25, 2018, 12:45pm UTC](https://discourse.slicer.org/t/write-vtk-file-from-mha-volume-input/2684 "2018-04-25T12:45:12Z")\
**Posts on this page:** 1\
**Page:** 1

<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:** [April 25, 2018, 12:45pm UTC](https://discourse.slicer.org/t/write-vtk-file-from-mha-volume-input/2684/1 "2018-04-25T12:45:13Z")

</div>

Hi

I have a little question on vtk development

My input file is mha volume

```
char volume_i[50];
char reader_i[50];
char writerVTK_i[50];
char out_file[50];

      sprintf(volume_i, "\nVolume %d", i);  
        printf("%s : %s \n", volume_i, argv[1]);

        vtkSmartPointer<vtkImageData> volume_i = vtkSmartPointer<vtkImageData>::New();

        sprintf(reader_i, "Reader %d", i); 

        vtkSmartPointer<vtkMetaImageReader> reader_i = vtkSmartPointer<vtkMetaImageReader>::New();

        reader_i->SetFileName(argv[1]);
        reader_i->Update();

        volume_i->DeepCopy(reader_i->GetOutput());

```

I would like to write vtk file as an output.

I tried this code :

```
vtkSmartPointer<vtkPolyDataWriter> writerVTK_i = vtkSmartPointer<vtkPolyDataWriter>::New();

sprintf(out_file, "%d.vtk", i);  
printf("%s\n", out_file);
writerVTK_i->SetFileName(out_file);
writerVTK_i->SetInputConnection(volume_i->GetOutputPort());
writerVTK_i->Write();

```

Should I use vtkMetaImageWriter ?

Thank you
