Mayavi:绕y轴旋转 [英] Mayavi: rotate around y axis

查看:184
本文介绍了Mayavi:绕y轴旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用mayavi的 triangular_mesh 方法绘制3D网格。数据描述了一个朝下放置在3D空间中的人体轮廓(因此 cmap 可用于表示距相机的距离)。



以下是用于生成绘图的代码(面和顶点来自外部对象,此处显示的内容太多了):

  from mayavi import mlab 

import math
import numpy as np
import sys
import os


图= mlab.figure(fgcolor = {0,0,0),bgcolor = {1,1,1),size =(1920,980))

a = np .array(this_mesh.vertices-refC.conj()。transpose())#this_mesh是根据外部数据文件创建的对象

this_mesh.faces = this_mesh.faces.astype(int)-1#网格数据是由matlab生成的,它是1索引的

m = mlab.triangular_mesh(x,y,z,this_mesh.faces,opacity = 0.75)

mlab.axes (范围= [-1100、1100,-1100、1100,-1100、1100])

无移动相机,轮廓朝下放置。为了正面查看模型,我正在更改摄像头的方位角和仰角,以便从上至下查看图形。

  mlab.view(方位角= 0,海拔= 180)
mlab.show ()

我的下一个任务是创建一系列图像,使相机在绘图周围平移,开始



复杂之处在于,为了获得深度信息的颜色图,我已经移动了视图的方位角和高程(如上面的代码所示)。 Mayavi比matplotlib拥有更多移动摄像机的选项,但是它似乎没有绕Y轴旋转的方法,因此我想我需要对方位角和仰角执行一些复杂的计算才能实现结果相同-但我对从何处开始感到迷茫(我是3D空间领域的新手,而我的大脑还不这么认为)。



有人能指出我正确的方向吗?

解决方案

事实证明,有一些解决方法。 / p>

您可以独立于摄影机在其轴上旋转actor。 (这使可视化与数据标签不一致,但是由于我实际上隐藏了图形的轴,因此在这种情况下无关紧要。)



您所需要做的就是:

  m.actor.actor.rotate_y(desired_angle)

...而且您很高兴。


I'm plotting a 3D mesh using mayavi's triangular_mesh method. The data describes a human silhouette laying face-down in 3D space (so the cmap can be used to denote distance from the camera).

Here's the code used to generate the plot (the faces and vertices come from an external object, and there are far too many to show here):

from mayavi import mlab

import math
import numpy as np
import sys
import os


fig = mlab.figure(fgcolor=(0, 0, 0), bgcolor=(1, 1, 1), size=(1920, 980))

a = np.array(this_mesh.vertices - refC.conj().transpose())  # this_mesh is an object created from external data files 

this_mesh.faces = this_mesh.faces.astype(int) -1  # mesh data is generated by matlab, which is 1-indexed

m = mlab.triangular_mesh(x, y, z, this_mesh.faces, opacity=0.75)

mlab.axes(extent=[-1100, 1100, -1100, 1100, -1100, 1100])

Without moving the camera, the silhouette lays face-down. In order to view the model face-on, I'm altering the azimuth and elevation of the camera to look at the graph top-down. This shows the silhouette as intended.

mlab.view(azimuth=0, elevation=180)
mlab.show()

My next task is to create a series of images where the camera pans around the plot, starting with the silhouette facing to the right, and finishing with it facing to the left.

The complication is that in order to get the colormap for the depth information, I'm already moving the view's azimuth and elevation (as shown in the code above). Mayavi has more options for moving the camera than matplotlib, but it doesn't seem to have a way to rotate around the Y axis, so I'm guessing I'll need to perform some complex calculations on the azimuth and elevation to achieve the same result - but I'm at a loss as to where to start (I'm new to working in 3D space, and my brain doesn't think that way yet).

Can anyone point me in the right direction?

解决方案

It turns out there's a bit of a workaround for this.

You can rotate the actors on their axes independently of the camera. (This throws the visualization out of step with the data labeling, but as I'm actually hiding the axes of the figure it doesn't matter in this case.)

All you need to do is:

m.actor.actor.rotate_y(desired_angle)

...and you're good to go.

这篇关于Mayavi:绕y轴旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆