[vtkusers] surface texture problem

Eric E. Monson emonson at cs.duke.edu
Tue May 4 09:01:33 EDT 2010


Hey Wolfgang,

To apply the texture you need to generate texture coordinates for your geometry. Run your data through vtkTextureMapToPlane (http://www.vtk.org/doc/nightly/html/classvtkTextureMapToPlane.html) between the geometry filter and the warp:

geom = vtk.vtkImageDataGeometryFilter()
geom.SetInputConnection(reader.GetOutputPort())

toplane = vtk.vtkTextureMapToPlane()
toplane.SetInputConnection(geom.GetOutputPort())

warp = vtk.vtkWarpScalar()
warp.SetInputConnection(toplane.GetOutputPort())
warp.SetScaleFactor(heightFactor)

Talk to you later,
-Eric

On May 4, 2010, at 5:14 AM, WolfgangZ wrote:

> Hello all,
> 
> I have a problem getting a texture on my surface (vtkPolyData) generated from image data. The surface itself shows up correctly, but the texture is wrong. What I want to achieve is to have the texture once on the surface so that it fits from left to right and top to bottom.
> 
> Any help is welcome.
> 
> Best regards
> Wolfgang
> 
> PS I'm running vtk 5.4.2 from python (installation from pythonxy http://code.google.com/p/pythonxy/ )
> 
> here my code:
> 
> 
> #######
> import vtk
> heightFactor=0.1
> 
> # Texture
> tex_reader = vtk.vtkBMPReader()
> tex_reader.SetFileName("./masonry.bmp")
> 
> tex = vtk.vtkTexture()
> tex.SetInputConnection(tex_reader.GetOutputPort())
> tex.InterpolateOn()
> tex.RepeatOff()
> 
> # Height field
> reader = vtk.vtkImageReader2()
> reader.SetFileName("./dem30.raw")
> reader.SetDataByteOrderToBigEndian()
> reader.SetDataScalarTypeToFloat()
> reader.SetDataExtent(0, 266, 0, 266, 0,0)
> 
> geom = vtk.vtkImageDataGeometryFilter()
> geom.SetInputConnection(reader.GetOutputPort())
> 
> warp = vtk.vtkWarpScalar()
> warp.SetInputConnection(geom.GetOutputPort())
> warp.SetScaleFactor(heightFactor)
> 
> normals = vtk.vtkPolyDataNormals()
> normals.SetInputConnection(warp.GetOutputPort())
> normals.SetFeatureAngle(80)
> 
> # mapper, actor and rendering
> mapper = vtk.vtkPolyDataMapper()
> mapper.SetInputConnection(normals.GetOutputPort())
> mapper.ScalarVisibilityOff()
> 
> actor = vtk.vtkActor()
> actor.SetMapper(mapper)
> actor.SetTexture(tex)
> 
> ren = vtk.vtkRenderer()
> ren.AddActor(actor)
> ren.SetBackground(1, 1, 1)
> 
> renWin = vtk.vtkRenderWindow()
> renWin.AddRenderer(ren)
> renWin.SetSize(300, 300)
> 
> iren = vtk.vtkRenderWindowInteractor()
> iren.SetRenderWindow(renWin)
> 
> iren.Initialize()
> iren.Render()
> iren.Start()
> 
> <data.zip>_______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers




More information about the vtkusers mailing list