How can I maintain the size of dots in a texture image when applying a texture map

Hello everyone.

I’m encountering an issue with vtkTextureMapToPlane. When I map the texture image onto my STL model, some of the dots in the texture get resized. Since the next step is to obtain the corresponding color values of the points, I would like to ensure that these dots retain their shape, even on the curved surfaces of the model. Is this a difficult problem to address? Below are my texture image, test code, and the result.

reader = vtk.vtkSTLReader()
reader.SetFileName("model.stl")
reader.Update()

texturemap = vtk.vtkTextureMapToPlane()
texturemap.SetInputData(reader.GetOutput())
texturemap.Update()

texture = vtk.vtkTexture()
image_reader = vtk.vtkJPEGReader()
image_reader.SetFileName("texture.jpg")
image_reader.Update()
texture.SetInputConnection(image_reader.GetOutputPort())

mapper = vtk.vtkPolyDataMapper()
mapper.SetInputData(texturemap.GetOutput())
mapper.Update()

actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.SetTexture(texture)

renderer = vtk.vtkRenderer()
renderer.SetBackground(*[128,128,128])
renderer.SetBackground2(*[128,128,128]) 
renderer.GradientBackgroundOn() 

renderer.AddActor(actor)

render_window = vtk.vtkRenderWindow()
render_window.AddRenderer(renderer)

render_window_interactor = vtk.vtkRenderWindowInteractor()
render_window_interactor.SetRenderWindow(render_window)

render_window.Render()
render_window_interactor.Start()

best regards

There’s always going to be some distortion when mapping a plane to a curved surface, unless the curved surface is a cylindrical (or if all bending occurs in only two dimensions). It sounds like what you need is to have all the distortion occur within the black regions of the texture, so that the grey and white regions remain undistorted. There’s no easy way to do that, certainly vtkTextureMapToPlane isn’t capable.

If you could pre-distort the texture image so that it looks undistorted after texture mapping, the same way that video game developers create texture skins for their models, you’d be able to get a near-perfect result. This might be possible in VTK, but it would take a lot of cleverness and probably some tricky mathematics.