vtkTextureMapToPlane inverting the texture image.
Hi all,
I have found an issue using vtkTextureMapToPlane that is simulated by the script below. The script creates a plane with elevations and texture, the issue is, depending on the points that have the elevation, it inverts the texture image, as you can see on the images that I've attached.
For example, on this script, if we insert a point as (0, 100, 0) it works normally, but if we insert (0, 100, 50) instead, it inverts the image.
Script:
import vtk
image_name = 'C:/VTK/Data/normalMapping.png'
elev = 50
points = vtk.vtkPoints()
points.InsertNextPoint(0, 0, 0)
points.InsertNextPoint(100, 0, 0)
points.InsertNextPoint(200, 0, 0)
points.InsertNextPoint(300, 0, 0)
points.InsertNextPoint(400, 0, 0)
# points.InsertNextPoint(0, 100, 0) # OK
points.InsertNextPoint(0, 100, elev) # here is the issue
points.InsertNextPoint(100, 100, 0)
points.InsertNextPoint(200, 100, 0)
points.InsertNextPoint(300, 100, 0)
points.InsertNextPoint(400, 100, 0)
points.InsertNextPoint(0, 200, 0)
points.InsertNextPoint(100, 200, elev)
points.InsertNextPoint(200, 200, 0)
points.InsertNextPoint(300, 200, elev)
points.InsertNextPoint(400, 200, 0)
points.InsertNextPoint(0, 300, 0)
points.InsertNextPoint(100, 300, 0)
points.InsertNextPoint(200, 300, 0)
points.InsertNextPoint(300, 300, 0)
points.InsertNextPoint(400, 300, 0)
points.InsertNextPoint(0, 400, 0)
points.InsertNextPoint(100, 400, 0)
points.InsertNextPoint(200, 400, 0)
points.InsertNextPoint(300, 400, 0)
points.InsertNextPoint(400, 400, 0)
polydata = vtk.vtkPolyData()
polydata.SetPoints(points)
delny = vtk.vtkDelaunay2D()
delny.SetInputData(polydata)
delny.Update()
delny.SetTolerance(0.01)
tmapper = vtk.vtkTextureMapToPlane()
tmapper.SetInputConnection(delny.GetOutputPort())
xform = vtk.vtkTransformTextureCoords()
xform.SetInputConnection(tmapper.GetOutputPort())
mapper = vtk.vtkDataSetMapper()
mapper.SetInputConnection(xform.GetOutputPort())
bmpReader = vtk.vtkPNGReader()
bmpReader.SetFileName(image_name)
bmpReader.Update()
atext = vtk.vtkTexture()
atext.SetInputConnection(bmpReader.GetOutputPort())
atext.InterpolateOn()
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.SetTexture(atext)
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
ren.AddActor(actor)
ren.SetBackground(1, 1, 1)
renWin.SetSize(1000, 1000)
iren.Initialize()
renWin.Render()
iren.Start()
I'm trying to create a terrain with texture and found this issue, can I achieve this by another way? Is there any workaround?
Thank you, Thiago