# Copying geometry from poly data clipper to another polydata using original IDs from ID filter

**URL:** https://discourse.vtk.org/t/copying-geometry-from-poly-data-clipper-to-another-polydata-using-original-ids-from-id-filter/15451
**Category:** Support
**Tags:** code
**Created:** [March 31, 2025, 9:32am UTC](https://discourse.vtk.org/t/copying-geometry-from-poly-data-clipper-to-another-polydata-using-original-ids-from-id-filter/15451 "2025-03-31T09:32:54Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![jimiheinonen](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/j/22d042/32.png) [@jimiheinonen](https://discourse.vtk.org/u/jimiheinonen)
#### Post date: [March 31, 2025, 9:32am UTC](https://discourse.vtk.org/t/copying-geometry-from-poly-data-clipper-to-another-polydata-using-original-ids-from-id-filter/15451/1 "2025-03-31T09:32:54Z")

</div>

Hey! I am looking to copy existing geometry inside a clipper from one polydata to another polydata, using original IDs from vtkIdFilter. I can get the original Ids from the filter, but how would I get around to copying the geometry inside the clipper to the second polydata? All my attempts at iterating over the cells or points are causing the program to crash (i.e. I can’t even create new cells and points into the other polydata so it may be I’m doing something fundamentally wrong). Is there a way to use DeepCopy or ShallowCopy so that it does not reset the second polydata when copying from first to second polydata?

---

<div class="post-metadata">

### Author: ![jimiheinonen](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/j/22d042/32.png) [@jimiheinonen](https://discourse.vtk.org/u/jimiheinonen)
#### Post date: [April 1, 2025, 6:39am UTC](https://discourse.vtk.org/t/copying-geometry-from-poly-data-clipper-to-another-polydata-using-original-ids-from-id-filter/15451/2 "2025-04-01T06:39:24Z")

</div>

Hey, I have gotten one version partially working. Problem is, it only copies the geometry on the first click - if I click again no new geometry copied is visible. Number of points and cells does grow in the poly data to be copied to. Any help would be greatly appreciated!

```auto
if (this->selectionModelPolyData->GetPoints() == 0) {
    vtkNew<vtkPoints> initialPoints;
    this->selectionModelPolyData->SetPoints(initialPoints);
}

if (this->selectionModelPolyData->GetNumberOfCells() == 0) {
    vtkNew<vtkCellArray> initialArray;
    this->selectionModelPolyData->SetPolys(initialArray);
}

// Copy new cells from clipped area
this->selectionModelPolyData->BuildLinks();
vtkSmartPointer<vtkCellIterator> iter = clipped->NewCellIterator();

for (iter->InitTraversal(); !iter->IsDoneWithTraversal(); iter->GoToNextCell())
{
    vtkNew<vtkGenericCell> cell;
    iter->GetCell(cell);

    vtkSmartPointer<vtkPoints> iter_points = iter->GetPoints();
    vtkNew<vtkTriangle> tri;
    vtkNew<vtkIdList> temp_pts;

    // Set new IDs for triangle
    for (vtkIdType i = 0; i < iter_points->GetNumberOfPoints(); i++) {
        double pos[3];
        iter_points->GetPoint(i, pos);

        vtkIdType id = this->selectionModelPolyData->GetPoints()->InsertNextPoint(pos);
        
        // Insert point ids for cell
        for (vtkIdType y = 0; y < iter_points->GetNumberOfPoints(); y++) {
            tri->GetPointIds()->SetId(y, id);
        }
        temp_pts->InsertNextId(id);
    }
    
    this->selectionModelPolyData->InsertNextCell(VTKCellType::VTK_TRIANGLE, temp_pts);
}

this->selectionModelPolyData->Modified();

```
