[vtkusers] The orientation of 2D texture

Xiaoxu Wang xiwang at dragon.rutgers.edu
Wed Oct 18 23:50:41 EDT 2006


Dear VTK users,

    I want to put a 2D image in a 3D space. The origin and the 
orientation of the image are known. The only way I know so far is to 
make a vtkPlaneSource and map the image as texture onto the 
vtkPlaneSource. But I am very confused on the orientations. If I rotate 
the vtkPlaneSource and vtkImageData with the same orientation, the 
texture is gone. If I did not rotate the texture and only rotate the 
vtkPlaneSource, the texture is still on the plane, but seems that it has 
a 2D rotation. Does anybody know how to get this 2D angle?
The code is as following.

origin=[-92.5221,-206.5797,33.2022]
dir1=[0.7736, 0.2192, 0.5945]
dir2=[0.2601, 0.7457, -0.6135]
normal=CrossMultiply(dir1,dir2)

reader=vtk.vtkPNGReader()
reader.SetFileDimensionality(3)
reader.SetDataExtent(0,extent[0]-1,0,extent[1]-1,0,0)
reader.SetFilePrefix(sys.argv[1])
reader.SetFilePattern("%s%d.png")
reader.UpdateWholeExtent()

wl = vtkImageMapToWindowLevelColors()
imin,imax = reader.GetOutput().GetScalarRange()
wl.SetWindow(imax-imin)
wl.SetLevel((imax-imin)/2)
planesource=vtkPlaneSource()

planesource.SetOrigin(origin)
point1=[dir1[0]*extent[1],dir1[1]*extent[1],dir1[2]*extent[1]]
print point1
planesource.SetPoint1(point1)
point2=[dir2[0]*extent[0],dir2[1]*extent[0],dir2[2]*extent[0]]
print point2
planesource.SetPoint2(point2)

mat = vtkMatrix4x4()
mat.SetElement(0,0,dir1[0])
mat.SetElement(0,1,dir1[1])
mat.SetElement(0,2,dir1[2])
mat.SetElement(0,3,0)
mat.SetElement(1,0,dir2[0])
mat.SetElement(1,1,dir2[1])
mat.SetElement(1,2,dir2[2])
mat.SetElement(1,3,0)
mat.SetElement(2,0,normal[0])
mat.SetElement(2,1,normal[1])
mat.SetElement(2,2,normal[2])
mat.SetElement(2,3,0)
mat.SetElement(3,0,0)
mat.SetElement(3,1,0)
mat.SetElement(3,2,0)
mat.SetElement(3,3,1)
trans = vtkTransform()
trans.SetMatrix(mat)


reslice = vtkImageReslice()
reslice.SetOutputDimensionality(2)
reslice.SetAutoCropOutput(1)
reslice.SetResliceTransform(trans)
reslice.SetInput(reader.GetOutput())

texture=vtkTexture() #tweak to change settings such as interpolation
wl.SetInput(reslice.GetOutput())
texture.SetInput(wl.GetOutput())
t=vtkTextureMapToPlane()
d=vtkDataSetMapper()
t.SetInput(planesource.GetOutput())
d.SetInput(t.GetOutput())
act=vtkActor()
act.SetMapper(d)
act.SetTexture(texture)
ren = vtkRenderer()
ren.AddActor(act)


Thanks for any suggestion in advance
Xiaoxu



More information about the vtkusers mailing list