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

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

问题描述

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

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.

复杂的是,为了获得深度信息的颜色图,我已经移动了视图的方位角和仰角(如上面的代码所示).Mayavi 比 matplotlib 有更多移动相机的选项,但它似乎没有办法绕 Y 轴旋转,所以我猜我需要对方位角和仰角执行一些复杂的计算才能实现相同的结果 - 但我不知道从哪里开始(我是 3D 空间的新手,我的大脑还不这么认为).

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.)

您需要做的就是:

m.actor.actor.rotate_y(desired_angle)

...你可以走了.

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

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