[vtkusers] HELP!! vtkActorCollection
N Smethurst
nick.smethurst at free.fr
Sun Jun 29 18:31:40 EDT 2003
Hi
The problem with your code isn't that the collection is overwriting the
first actor with the second as in your first example. The problem seems to
be (it is not possble to know for sure since you have not posted the full
code) that you don't seem to be creating separate objects. You seem to be
adding the same actor to the collection lots of times and thus when adding
the actors of the collection to the renderer, only one actor will be added
(as there is only one object).
You need to create separate objects for each pipeline and add the actors to
the collection:
vtkMarchingSquares *imageSquares;
vtkPolyDataMapper *imageMapper;
vtkActor *imageActor;
for(int i = 0; i < ImageNumber; i++)
{
imageSquares = vtkMarchingSquares::New();
imageMapper = vtkPolyDataMapper::New();
imageActor = vtkActor::New();
// unknown code to do contour..
imageSquares->SetInput(unknownContourObjectThing->GetOutput());
imageSquares->SetValue(0,63);
imageSquares->Update();
imageMapper->SetInput(imageSquares->GetOutput());
imageMapper->ScalarVisibilityOff();
imageActor->SetMapper(imageMapper);
imageActorCollection->AddItem(imageActor);
// Reduce reference counts.
imageSquares->Delete();
imageMapper->Delete();
imageActor->Delete();
}
When you subsequently delete the renderer and the collection, the objects
will self destruct.
Le Dimanche 29 Juin 2003 20:30, marisa aurelio a écrit :
> So I create a list that keeps the images. Than I obtained the contour
> and kept it in a vtkActor which I add to vtkActorCollection. For this I
> use a cicle 'for', that do this for all the images:
>
> for(int i = 0; i < ImageNumber; i++)
> {
> // some code...............
>
> //vtkImporter - contain the image
>
> imageSquares->SetInput(vtkImporter->GetOutput());
> imageSquares->SetValue(0,63);
> imageSquares->Update();
>
> vtkPolyData *maskMesh = imageSquares->GetOutput();
>
> imageMapper->SetInput(maskMesh );
> imageMapper->ScalarVisibilityOff();
>
> imageActor->SetMapper(imageMapper);
>
> imageActorCollection->AddItem(imageActor);
> }
>
> But, when I ask to show the contours it just shows the contour of the
> last image from the list.
>
> vtkRenderer* renderer = vtkRenderer::New();
> vtkRenderWindow* renWin = vtkRenderWindow::New();
>
> imageActorCollection ->InitTraversal();
> while (imageActor = imageActorCollection ->GetNextActor())
> {
> renderer->AddActor(imageActor);
> }
>
> renWin->AddRenderer(renderer);
>
> Why???
>
>
More information about the vtkusers
mailing list