[vtkusers] How to render vtkImageData with vtkActor2D?

jiang jiang at TI.Uni-Trier.DE
Wed Jan 14 09:02:56 EST 2004


Hello vtk-users,
I have one vtkImageData. It is 2D image. So I can render it as following:
	vtkImageActor *actor=vtkImageActor::New();
	actor->SetInput(ImageData);
  	int ext[6];
 	actor->GetInput()->GetExtent( ext );
	ext[4]=0;ext[5]=0;
      actor->SetDisplayExtent( ext );

      vtkRenderer *renderer=vtkRenderer::New();
	renderer->AddActor(actor);
	vtkRenderWindow *renderWin=vtkRenderWindow::New();
	renderWin->AddRenderer(renderer);

      renderWin->Render();

Now I want to use vtkActor2D instead of vtkImageData. Because I want to set
the image as semi-transparent. I have to
use ->GetProperty()->SetOpacity(0.5). vtkImageActor has not GetProperty()
member function.
I do it as following:
	vtkImageMapper ImageMapper=vtkImageMapper::New();
	ImageMapper->SetInput(ImageData);
	ImageMapper->SetZSlice(0);

	vtkActor2D *actor=vtkActor2D::New();
	actor->SetMapper(ImageMapper);
	actor->GetProperty()->SetOpacity(0.5);

      vtkRenderer *renderer=vtkRenderer::New();
	renderer->AddActor(actor);
	vtkRenderWindow *renderWin=vtkRenderWindow::New();
	renderWin->AddRenderer(renderer);

      renderWin->Render();

However it doesn't work. I can only see one black image. How should I do?

Thank you very much!

Chunyan




More information about the vtkusers mailing list