[vtkusers] add or copy polydata to an other

Marian Panten usted_y_yo at web.de
Mon Feb 18 05:09:39 EST 2008


Hi Frederic, 

first thanks for the help. It almost works. But when i run an Update(), after i added all my polydata i get an error. 

vtkAppendPolyData (03573C50): Destination not big enough. 

I tried to do something with the allocate() method on the output ploydata but i allways get the same problem. Futhermore after clipping the data with vtkClipPolyData i only get the data from 
clipper->GetClippedOutputPort() not clipper->GetOutputPort().

Do you you have any idea whats going on there, and how to allocate the destination???

Thx 
Marian 

Here the code I use now, with the clipping. 

                vtkCollectionIterator* iter = vtkCollectionIterator::New();
		iter->SetCollection(importerFemur->GetRenderer()->GetActors());
		iter->InitTraversal();
		vtkAppendPolyData *allInOne = vtkAppendPolyData::New();
		while (!iter->IsDoneWithTraversal())
		{
			vtkPolyData* tempD = (vtkPolyData*)((vtkActor*)iter->GetCurrentObject())->GetMapper()->GetInput();
// Here i tried something with allocate.... 
			allInOne->AddInput(tempD);
			iter->GoToNextItem();
			tempD->Delete();
		}
// Here i tried something with allocate, too 
		allInOne->Update(); 
		vtkPolyData *allMyPolyData = allInOne->GetOutput();
		vtkPolyDataMapper* vrmlMapper = vtkPolyDataMapper::New();
			vrmlMapper->SetInput(allMyPolyData);
		leftFemurImplantActor->SetMapper(vrmlMapper);
	}

	vtkPlane* plane = vtkPlane::New();
		plane->SetOrigin(0,0,0);
		plane->SetNormal(1, 0, 0);

	vtkClipPolyData* clipper = vtkClipPolyData::New();
	clipper->SetInputConnection(leftFemurImplantActor->GetMapper()->GetInputConnection(0,0));
		clipper->SetClipFunction(plane);
		clipper->GenerateClipScalarsOn();
		clipper->GenerateClippedOutputOn();
		clipper->SetValue(0);
		clipper->Update();
	//
	vtkPolyDataMapper* leftMapper = vtkPolyDataMapper::New();
		leftMapper->SetInputConnection(clipper->GetOutputPort());
		leftMapper->ScalarVisibilityOff();
	vtkPolyDataMapper* rightMapper = vtkPolyDataMapper::New();
		rightMapper->SetInputConnection(clipper->GetClippedOutputPort());
		rightMapper->ScalarVisibilityOff();
	
	leftFemurImplantActor->SetMapper(rightMapper);
	leftFemurImplantActor->GetProperty()->SetColor(1.0,1.0,0.0);
	leftFemurImplantActor->SetScale(1000);
	leftFemurImplantActor->GetProperty()->SetInterpolation(0);

	rightFemurImplantActor->SetMapper(leftMapper);
	rightFemurImplantActor->GetProperty()->SetColor(1.0,0.0,1.0);
	rightFemurImplantActor->SetScale(1000);
	rightFemurImplantActor->GetProperty()->SetInterpolation(0);




> -----Ursprüngliche Nachricht-----
> Von: "Frederic Danesi" <frederic.danesi at dinccs.com>
> Gesendet: 16.02.08 19:48:17
> An: <vtkusers at vtk.org>
> Betreff: RE: [vtkusers] add or copy polydata to an other


> 
> 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
> 
> 
> 
> _______________________________________________
> This is the private VTK discussion list. 
> Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
> 


________________________________________________________
Bis 50 MB Dateianhänge? Kein Problem!
http://www.digitaledienste.web.de/freemail/club/lp/?lp=7




More information about the vtkusers mailing list