Mayavi中的基本3D体素网格 [英] Basic 3D voxel grid in Mayavi

查看:139
本文介绍了Mayavi中的基本3D体素网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过Python中的Mayavi可视化3D数组.我只想创建一个结构化的3D体素网格,在其中可以显示一些预先指定的体素空间填充点.我不认为我要

我发现我认为相对相关的唯一示例是如您所见,即使这些点与所生成的框的边具有相同的值,也不会生成所有框的边.

是否有一种方法可以可视化numpy数组中值等于1的每个点?如果没有等值面可视化,我很好-实际上,我更喜欢Minecraft风格的块状体素可视化.

解决方案

 导入mayavi.mlab导入numpy数据=(100,100,100)数据= numpy.zeros(数据)数据[0:50,50:70,0:50] = 1数据[0:50,0:20,0:50] = 1xx,yy,zz = numpy.where(数据== 1)mayavi.mlab.points3d(xx,yy,zz,mode ="cube",颜色=(0,1,0),scale_factor = 1)mayavi.mlab.show() 

I'm trying to visualize a 3D array through Mayavi in Python. I simply want to create a structured 3D voxel grid in which I can show some pre-specified voxel-space-filling points. I do not think that I want

The only example that I can find that I think is relatively relevant is this MRI example. I can use the following code to get a somewhat workable example:

import numpy as np
from mayavi import mlab

data = (100, 100, 100)
data = np.zeros(data)
data[0:50, 50:70, 0:50] = 1
data[0:50, 0:20, 0:50] = 1

src = mlab.pipeline.scalar_field(data)
outer = mlab.pipeline.iso_surface(src)

mlab.show()

This is able to generate the following images: As you can see, not all sides of the boxes are generated, even though those points have the same value as the sides of the boxes that are generated.

Is there a way to visualize every single point in the numpy array that has value equal to 1? I am fine if there is no iso-surface visualization -- in fact, I would prefer some Minecraft-esque blocky voxel visualization.

解决方案

Hi

import mayavi.mlab
import numpy

data = (100, 100, 100)
data = numpy.zeros(data)
data[0:50, 50:70, 0:50] = 1
data[0:50, 0:20, 0:50] = 1

xx, yy, zz = numpy.where(data == 1)

mayavi.mlab.points3d(xx, yy, zz,
                     mode="cube",
                     color=(0, 1, 0),
                     scale_factor=1)

mayavi.mlab.show()

这篇关于Mayavi中的基本3D体素网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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