Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
texture on mlab.surf #211
I am trying to place a texture on a surface (mlab.surf). Instead, I see a surface with the mean pixel color of that texture image. I would appreciate a confirmation that this great feature (texture on mlab.surf) should still work as advertised and my installed system is to blame.
Similar code worked for me with mayavi 4.3 and vtk5 on a debian system. I did change the arguments passed to tvtk.Texture for it to work with mayavi 4.4.2 and vtk6 (via homebrew and virtenv+pip on OS X).
Thanks in advance!
from tvtk.api import tvtk from mayavi import mlab import numpy as np mlab.clf() X,Y=np.mgrid[-1:1:20j,-1:1:20j] Z = -np.cos(Y*X)+.5 img_filename='anyimage.jpg' img=tvtk.JPEGReader(file_name=img_filename) texture=tvtk.Texture(input_connection=img.output_port, interpolate=1) # following produces a surface with a color that seems to be represent the mean img pixel. s = mlab.surf(X,Y,Z,color=(1.,1.,1.)) s.actor.actor.mapper.scalar_visibility=False s.actor.enable_texture=True s.actor.tcoord_generator_mode='plane' s.actor.actor.texture=texture # but the texture itself works! from mayavi.sources.api import BuiltinSurface p = mlab.pipeline.surface( BuiltinSurface(source='plane') ) p.actor.actor.texture=texture```
I can confirm this problem exists on Windows 7 (64-bit) as well. Textures seem to work on flat objects but I can't get them to work with objects generated using surf or mesh. Manually constructing a pipeline using
Any ideas for a workaround? I am trying to create a 3D terrain view for an Enthought customer demo next week...
I could also not get the mlab.pipeline methods to work. The issue may be related, and would explain why also the 'many lines' example is not working on affected systems (see other bug reports).
An elaborate workaround is to draw the terrain pixel by pixel, assuming your terrain map is a geoTIFF or similar 2d matrix source. For instance, as point3d (cubes with scale_factor set to the elevation map grid space, z reduced by half the scale_factor), or as triangular_mesh using two triangles per pixel.