# Position changed after read and write

**URL:** https://discourse.vtk.org/t/position-changed-after-read-and-write/12371
**Category:** Development
**Tags:** code
**Created:** [September 27, 2023, 2:45am UTC](https://discourse.vtk.org/t/position-changed-after-read-and-write/12371 "2023-09-27T02:45:55Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![yellowfisher](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/y/c77e96/32.png) [@yellowfisher](https://discourse.vtk.org/u/yellowfisher)
#### Post date: [September 27, 2023, 2:45am UTC](https://discourse.vtk.org/t/position-changed-after-read-and-write/12371/1 "2023-09-27T02:45:55Z")

</div>

hello everyone,  
I use the code below to read a segmentation file and then convert image data to surface polydata ,write to .vtp file. The code works fine.Then i open the origin .nii.gz file and the generated vtp file in 3DSlicer, i found there has a offset between two surface, shouldn’t them be overlapped?  
I want know what causes the offset and how to fix this problem.

```auto
    //read nii.gz segment file with vtkNIFTIImageReader
    vtkSmartPointer<vtkNIFTIImageReader> reader = vtkSmartPointer<vtkNIFTIImageReader>::New();
    reader->SetFileName("D:/proj/vmtk_out/N-1000349/N-1000349.seg.nii.gz");
    reader->Update();

    //convert to vtkPolyData and then write to file
    vtkSmartPointer<vtkMarchingCubes> surface = vtkSmartPointer<vtkMarchingCubes>::New();
    surface->SetInputConnection(reader->GetOutputPort());
    surface->ComputeNormalsOn();
    surface->ComputeGradientsOn();
    surface->SetValue(0, 0.5);
    surface->Update();

    vtkSmartPointer<vtkXMLPolyDataWriter> writer = vtkSmartPointer<vtkXMLPolyDataWriter>::New();
    writer->SetFileName("D:/proj/vmtk_out/N-1000349/surface.vtp");
    writer->SetInputData(surface->GetOutput());
    writer->SetDataModeToAscii();
    writer->Write();

```

 ![image](https://discourse.vtk.org/uploads/default/original/2X/7/746872e4ce41b68e77e13b44a88eb0e2bfa2a6c7.png)
