Mayavi- Scale a surface without translating it -
im wondering if possible scale surface-object in mayavi without moving/translating it.
so far use surface.actor.actor.scale property , assign 3d-vector it. however, surface not keep original position scaling carried out respect origin (0,0,0) - that's why seems surface moves...
any ideas?
when asked origin
attribute on vtk actors, genuinely inquiring had been tried. have played little bit don't know details of how vtk actors decide position themselves, complicated , mathy , find easier hack , math manually (at least when math simple).
here simpler solution. note, not best solution. there may cleaner solution have not found.
the basic idea of solution simple: scrape x,y,z coordinates of surface vertices, apply correct linear translation these points, , feed them source.
surf = mlab.surf(*args) # somehow generate surface xc,yc,zc = centroid() #somehow determine x,y,z coordinates 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)
Comments
Post a Comment