[vtkusers] add or copy polydata to an other
Frederic Danesi
frederic.danesi at dinccs.com
Sat Feb 16 13:48:02 EST 2008
Hi,
The problem is here : first->GetPolys()->InsertNextCell(tempD->GetCell(i));
tempD->GetCell(i) return a cell that includes pointsIds from tempD ... which
do not match to pointsIds in "first" ...
A simple way to do that is to use vtkAppendPolyData. It will do the work for
you ...
You may try something like this :
> vtkCollectionIterator* iter = vtkCollectionIterator::New();
> iter->SetCollection(importer->GetRenderer()->GetActors());
> iter->InitTraversal();
vtkAppendPolyData *allInOne = vtkAppendPolyData::New();
> while (!iter->IsDoneWithTraversal())
> {
> vtkPolyData* tempD =
(vtkPolyData*)((vtkActor*)iter->GetCurrentObject())->GetMapper()->GetInput()
;
> allInOne->AddInput(tempD);
> iter->GoToNextItem();
> }
vtkPolyData *allMyPolyData = allInOne->GetOutput();
If you really want to do it by yourself, you have to rebuild the point Ids,
for example by managing a correspondence table between point's Id in tempD
and the matching Id in firstPolyData after inserting the point...
Be careful, this will not merge duplicate points ...
Fred.
Cordialement,
F.Danesi.
--
Département DINCCS (Département Ingénierie Numérique, Conception
Collaborative et Simulation)
MICADO / DINCCS
Pole de Haute Technologie, 7 boulevard Jean Delautre (IFTS)
08000 Charleville-Mézières
Tel. : 03.24.41.69.55 / 06.62.76.13.32
Email : frederic.danesi at dinccs.com
Web: www.afmicado.com / www.dinccs.com
> -----Message d'origine-----
> De : Marian Panten [mailto:usted_y_yo at web.de]
> Envoyé : samedi 16 février 2008 16:06
> À : vtkusers at vtk.org
> Objet : [vtkusers] add or copy polydata to an other
>
> 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