[vtkusers] Displaying 2d image in 3d scene using vtkImageActor/vtkTexture

Jonas jonas.email at gmail.com
Thu Sep 14 10:31:31 EDT 2006


I am using vtk 4.4.2, CygWin and wxWidgets.

I am trying to display an 2d image in the 3d scene, first by using vtkImageActor
and then vtkTexture - but none of them works.
(I have tested it with the vtkImageMapper first and the image is displayed just
fine, but this only works for 2d.)

Note: Since there is no SetPosition in vtkImageActor in vtk 4.4.2, i have copied
vtkImageActor from CVS (vtkImageActor.h revision: 1.22 and vtkImageActor.cxx
revision 1.21) and used this instead of the old one.

1) Using vtkImageActor

	imageFilter = vtkImageShiftScale::New();
	imageActor3d = vtkImageActor::New();
	
	imageActor3d->SetInput(imageFilter->GetOutput());
	imageActor3d->VisibilityOff();
	
	imageFilter->SetOutputScalarTypeToUnsignedChar();
	imageActor2d->SetMapper(imageMapper2d);
	
 When user selects an image this is executed:

	float x, y, z; // just some abritrary 3d coordinates

	imageFilter->SetInput(image); // image is of type vtkImageData
	imageActor3d->SetPosition(x, y, z);
	imageActor3d->VisibilityOn();
	
2) Using vtkTexture	
		
	texturePlane = vtkPlaneSource::New();
	texture = vtkTexture::New();
	textureTransform = vtkTransform::New();
	textureTransformFilter = vtkTransformPolyDataFilter::New();
	textureMapper = vtkPolyDataMapper::New();
	textureActor = vtkActor::New();
	
	textureTransformFilter->SetInput(texturePlane->GetOutput());
	textureTransformFilter->SetTransform(textureTransform);
	textureMapper->SetInput(textureTransformFilter->GetOutput());
	textureActor->SetMapper(textureMapper);
	textureActor->SetTexture(texture);
	textureActor->VisibilityOff();
	
 When user selects an image this is executed:

	float x, y, z; // just some abritrary 3d coordinates
	int pixelWidth = 512, pixelHeight = 512;
	
	texture->SetInput(image); // image is of type vtkImageData
	texturePlane->SetXResolution(pixelWidth);
	texturePlane->SetYResolution(pixelHeight);
	textureTransform->Identity();
	textureTransform->Translate(x, y, z);
	textureActor->SetTexture(texture);
	textureActor->VisibilityOn();
	
	
Now, the problem is that i can not see the image in any of two cases - it seams
like it is only 1x1 in size in the scene!

Any comment would be nice!

 - Jonas, Denmark




More information about the vtkusers mailing list