[vtkusers] add or copy polydata to an other

Marian Panten usted_y_yo at web.de
Sat Feb 16 10:05:39 EST 2008


Hi,

I've got a collection of actors and am trying to copy/add the point and 
cell data of the collection into the polydata of the first actor. I have 
tried something like this.

        vtkCollectionIterator* iter = vtkCollectionIterator::New();
        iter->SetCollection(importer->GetRenderer()->GetActors());
        iter->InitTraversal();
        vtkActor* fristActor = (vtkActor*) iter->GetCurrentObject();
        vtkPolyData* firstPolyData = (vtkPolyData*) 
temp->GetMapper()->GetInput(); 
        iter->GoToNextItem();

        while (!iter->IsDoneWithTraversal())
        {
            vtkPolyData* tempD = (vtkPolyData*) 
((vtkActor*)iter->GetCurrentObject())->GetMapper()->GetInput();
            vtkIdType nPts = tempD->GetPoints()->GetNumberOfPoints();
            vtkIdType nCells = tempD->GetPolys()->GetNumberOfCells();
            for (vtkIdType i = 0; i<nPts; i++)
            {
               
 first->GetPoints()->InsertNextPoint(tempD->GetPoints()->GetPoint(i));
            }
            for (vtkIdType i = 0; i<nCells; i++)
            {
                vtkIdType nCout  = first->GetPolys()->GetNumberOfCells();
                first->GetPolys()->InsertNextCell(tempD->GetCell(i));
                first->GetPolys()->UpdateCellCount(nCout+1);
                first->GetPolys()->Modified();
            }
            iter->GoToNextItem();
        }

The adding of the points seems to work, but I've got problems with the 
cell data, resulting in a runtime error. I've tried a lot, but can't 
find a solution.
Does anyone have any idea? I must say I am new in vtk and maybe I have 
overseen an easier way to do this. I would be very glad if someone could 
send me a code snippet.

Thanks a lot
Marian



More information about the vtkusers mailing list