Question

im wondering if its possible to scale an surface-object in mayavi without moving/translating it.

So far I just use the surface.actor.actor.scale property and assign a 3D-vector to it. However, the surface does not Keep its original Position but the scaling is carried out with respect to the origin (0,0,0) - That's why it seems like the surface moves...

Any ideas?

Was it helpful?

Solution

When I asked about the origin attribute on the vtk actors, I was genuinely inquiring as to what had been tried. I have played a little bit with that but I don't know all the details of how vtk actors decide to position themselves, it is very complicated and mathy and I find it mostly easier to just hack it and do the math manually (at least when the math is simple).

Here is a much simpler solution. Note, it is not necessarily the best solution. There may be a much cleaner solution that I have just not found.

The basic idea of this solution is really simple: scrape the x,y,z coordinates of the surface vertices, apply the correct linear translation to these points, and feed them back to the source.

surf = mlab.surf(*args) # somehow generate a surface
xc,yc,zc = centroid() #somehow determine the x,y,z coordinates to stabilize towards
scale_factor = 2.8

tx,ty,tz = surf.mlab_source.x, surf.mlab_source.y, surf.mlab_source.z
aff = np.eye(4)*scale_factor
aff[:,3] = (-xc,-yc,-zc,1)

dat = np.array(zip(tx,ty,tz,np.ones(len(tx))))
surf.mlab_source.x, surf.mlab_source.y, surf.mlab_source.z,_ = np.dot(aff, dat.T)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top