Hello guys,
In my script, I’m applying a texture to a terrain that I’ve created using points. The issue is that when I’ve elevation (z > 0) the texture is flipped by Z as you can see on the attached image (left is the original image and right is the VTK result).
Anyone knows why this is happening and how to fix this?
My script:
Hello guys,
In my script, I’m applying a texture to a terrain that I’ve created using points. The issue is that when I’ve elevation (z > 0) the texture is flipped by Z as you can see on the attached image (left is the original image and right is the VTK result).
Anyone knows why this is happening and how to fix this?
Thank you,
Thiago
My script:
import vtk
image_name = 'C:/VTK/Data/normalMapping.png'
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, 10)
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,0)
points.InsertNextPoint(200,200,0)
points.InsertNextPoint(300,200,0)
points.InsertNextPoint(400,200,0)
points.InsertNextPoint(0,300, 10)
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())
xform.SetScale(1, 1, 1)
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()