How to modify a vts file using another vts file! (structuredGrid)

Hi :slight_smile:

I am new to the community here, and I know that my question could be stupid :frowning:

The problem: I want to open a “file1.vts” file and modify the “vtkPoints” using another “file2.vts” file. After that, I want to update “file1.vts” and save it.

my approach: I tried to use the documentation as follow

    std::string inputFilename1 = "file1.vts";
    std::string inputFilename2 = "file2.vts";

    // Read the file 1
    vtkNew<vtkXMLStructuredGridReader> reader1;
    reader1->SetFileName(inputFilename1.c_str());
    reader1->Update();

    vtkNew<vtkStructuredGridGeometryFilter> geometryFilter1;
    geometryFilter1->SetInputConnection(reader1->GetOutputPort());
    geometryFilter1->Update();

    // Read the file 2
    vtkNew<vtkXMLStructuredGridReader> reader2;
    reader2->SetFileName(inputFilename2.c_str());
    reader2->Update();

    vtkNew<vtkStructuredGridGeometryFilter> geometryFilter2;
    geometryFilter2->SetInputConnection(reader2->GetOutputPort());
    geometryFilter2->Update();

    vtkPolyData* polydata1 = geometryFilter1->GetOutput();
    vtkPolyData* polydata2 = geometryFilter2->GetOutput();

    double p[3];

    vtkNew<vtkPoints> points;
    polydata2 = polydata1;

    for (vtkIdType i = 0; i < polydata2->GetNumberOfPoints(); i++)
    {
        polydata2->GetPoint(i, p);
        points->InsertNextPoint(p[0], p[1], p[2]);
    }
    polydata2->SetPoints(points);
    geometryFilter2->SetOutput(polydata2);

The question: What is missing, what is next? I tried different solutions but I did not work!

Any ideas?

reader.SetFileName("file1")
reader.Update()
ds1 = reader.GetOutput()

reader.SetFileName("file2")
reader.Update()
ds2 = reader.GetOutput()

ds1.SetPoints(ds2.GetPoints())

writer = vtkXMLStructuredGridWriter()
writer.SetInputData(ds1)
writer.SetFileName("file1")
writer.Update()
1 Like

Thanks a lot for your kind reply, but what is ds stands for? polydata? I am using C++

ds1 = DataSet 1 (Your VTS mesh)