与mayavi和tvkt的纹理映射

时间:2015-07-02 15:23:54

标签: python 3d vtk mayavi

我正在尝试使用python在Mayavi表面覆盖一个常见的jpg图像,灵感来自this example。这是简化的代码:

from mayavi import mlab
from tvtk.api import tvtk
import numpy as np

data=np.random.random((200,200)) #The shape of the matrix fits the image size in the original code
img = tvtk.JPEGReader()
img.file_name="img.jpg"
texture=tvtk.Texture(interpolate=0)   
texture.set_input_data(bmp1.get_output())

mlab.figure(size=(300,300))  
surf = mlab.surf(data,color=(1,1,1)) 
surf.actor.enable_texture = True  
surf.actor.tcoord_generator_mode = 'plane'  
surf.actor.actor.texture = texture

但是,我得到了:

ERROR: In /tmp/vtk20150328-28275-1clyhqa/VTK-6.2.0/Rendering/OpenGL/vtkOpenGLTexture.cxx, line 200
vtkOpenGLTexture (0x7fa9c32fb590): No scalar values found for texture input!

错误与将纹理指定给actor有关。有任何想法吗?提前谢谢。

1 个答案:

答案 0 :(得分:2)

MayaVI-API中有一个补丁,请看这里: https://github.com/enthought/mayavi/issues/211

你必须替换:

texture=tvtk.Texture(interpolate=0)   
texture.set_input_data(bmp1.get_output())

使用:

texture = tvtk.Texture(input_connection=img.output_port, interpolate=0)

然后它应该工作。请注意,您撰写了bmp1而不是img