Ok, it turns out that this is a known bug in mayavi. However, it is possible to change the orientation, position and scale of an ImageActor
object after it has been created:
obj = mlab.imshow(img) obj.actor.orientation = [0, 0, 0] # the required orientation obj.actor.position = [0, 0, 0] # the required position obj.actor.scale = [0, 0, 0] # the required scale
I have some data that consists of several 2D images that I would like to render in specific [x,y,z] positions relative to one another using mayavi2 (v4.3.0).,Ok, it turns out that this is a known bug in mayavi. However, it is possible to change the orientation, position and scale of an ImageActor object after it has been created:,From the documentation it seems that I should just be able to do this with mlab.imshow(). Unfortunately, mayavi throws an exception when I call imshow specifying the extent parameter (AttributeError: 'ImageActor' object has no attribute 'actor').,I also tried setting the x,y and z data directly by modifying im.mlab_source.x,y,z.... Weirdly, whilst this correctly changes the x and y extents, it does nothing to the z-position even though im.mlab_source.z clearly changes.
import numpy as np from scipy.misc import lena from mayavi import mlab def normal_imshow(img = lena()): return mlab.imshow(img, colormap = 'gray') def set_extent(img = lena()): return mlab.imshow(img, extent = [0, 100, 0, 100, 50, 50], colormap = 'cool') def set_xyz(img = lena()): im = mlab.imshow(img, colormap = 'hot') src = im.mlab_source print 'Old z :', src.z src.x = 100 * (src.x - src.x.min()) / (src.x.max() - src.x.min()) src.y = 100 * (src.y - src.y.min()) / (src.x.max() - src.y.min()) src.z[: ] = 50 print 'New z :', src.z return im if __name__ == '__main__': # this works normal_imshow() # # this fails(AttributeError) # set_extent() # weirdly, this seems to work for the x and y axes, but does not change # the z - postion even though data.z does change set_xyz()
obj = mlab.imshow(img) obj.actor.orientation = [0, 0, 0] # the required orientation obj.actor.position = [0, 0, 0] # the required position obj.actor.scale = [0, 0, 0] # the required scale
import numpy as np from scipy.misc import lena from mayavi import mlab def normal_imshow(img = lena()): return mlab.imshow(img, colormap = 'gray') def set_extent(img = lena()): return mlab.imshow(img, extent = [0, 100, 0, 100, 50, 50], colormap = 'cool') def set_xyz(img = lena()): im = mlab.imshow(img, colormap = 'hot') src = im.mlab_sourceprint 'Old z :', src.zsrc.x = 100 * (src.x - src.x.min()) / (src.x.max() - src.x.min()) src.y = 100 * (src.y - src.y.min()) / (src.x.max() - src.y.min()) src.z[: ] = 50 print 'New z :', src.zreturn im if __name__ == '__main__': # this worksnormal_imshow() # # this fails(AttributeError) # set_extent() # weirdly, this seems to work for the x and y axes, but does not change # the z - postion even though data.z does changeset_xyz()
obj = mlab.imshow(img) obj.actor.orientation = [0, 0, 0] # the required orientation obj.actor.position = [0, 0, 0] # the required position obj.actor.scale = [0, 0, 0] # the required scale
Plots a surface using grid-spaced data supplied as 2D arrays.,3D plotting functions Points Lines Elevation surface Arbitrary regular mesh Volumetric data ,3.5.1.1. 3D plotting functions Points Lines Elevation surface Arbitrary regular mesh Volumetric data ,x, y, z are 2D arrays, all of the same shape, giving the positions of the vertices of the surface. The connectivity between these points is implied by the connectivity on the arrays.
x, y, z, value = np.random.random((4, 40)) mlab.points3d(x, y, z, value)
mlab.clf() # Clear the figure t = np.linspace(0, 20, 200) mlab.plot3d(np.sin(t), np.cos(t), 0.1 * t, t)
mlab.clf()
x, y = np.mgrid[-10: 10: 100 j, -10: 10: 100 j]
r = np.sqrt(x ** 2 + y ** 2)
z = np.sin(r) / r
mlab.surf(z, warp_scale = 'auto')
mlab.clf()
phi, theta = np.mgrid[0: np.pi: 11 j, 0: 2 * np.pi: 11 j]
x = np.sin(phi) * np.cos(theta)
y = np.sin(phi) * np.sin(theta)
z = np.cos(phi)
mlab.mesh(x, y, z)
mlab.mesh(x, y, z, representation = 'wireframe', color = (0, 0, 0))
mlab.clf() x, y, z = np.mgrid[-5: 5: 64 j, -5: 5: 64 j, -5: 5: 64 j] values = x * x * 0.5 + y * y + z * z * 2.0 mlab.contour3d(values)
mesh(x, y, z, ...)
Ok, it turns out that this is a known bug in mayavi. However, it is possible to change the orientation, position and scale of an ImageActor object after it has been created:,Webkit browsers set the height and width property after the image is loaded. Instead of using timeouts, I'd recommend using an image's onload event. Here's a quick example:,The getSize method returns the rendered web element size and not the physical size of an image. If your goal is to get the intrinsic heigh and weight, then you could try to get the naturalWidth and naturalHeight properties:,Additionally, you might want to check if the points are in front of the camera:
private void Image_Loaded(object sender, RoutedEventArgs e) {
Debug.WriteLine($ "ActualHeight {img.ActualHeight}");
}
var image = {
url: 'image.png',
// This marker is 20 pixels wide by 32 pixels high.
size: new google.maps.Size(20, 32),
// The origin for this image is (0, 0).
origin: new google.maps.Point(0, 0),
// The anchor for this image is the base at (0, 32).
anchor: new google.maps.Point(0, 32)
};
var img = $("img")[0]; // Get my img elem
var pic_real_width, pic_real_height;
$("<img/>") // Make in memory copy of image to avoid css issues
.attr("src", $(img).attr("src"))
.load(function() {
pic_real_width = this.width; // Note: $(this).width() will not
pic_real_height = this.height; // work for in memory images.
});
window.onload = function() {
ScreenLoop();
}
width: 1360, height: 765
width: 765, height: 1360
obj = mlab.imshow(img) obj.actor.orientation = [0, 0, 0] # the required orientation obj.actor.position = [0, 0, 0] # the required position obj.actor.scale = [0, 0, 0] # the required scale