1. 程式人生 > >科學計算三維可視化---Mayavi入門(Mayavi管線)

科學計算三維可視化---Mayavi入門(Mayavi管線)

prope image code ati nta mod back length .sh

一:Mayavi管線

技術分享圖片

技術分享圖片

mlab.show_pipeline()  #顯示管線層級,來打開管線對話框

(一)管線中的對象scene

Mayavi Scene:處於樹的最頂層的對象,他表示場景,配置界面中可以設置場景的背景,前景色,場景中的燈光,以及其他一些選項
>>> s = mlab.gcf()  #獲取當前場景
>>> print(s)  #獲取當前場景狀態
<mayavi.core.scene.Scene object at 0x00000000014E66D0>
>>> print(s.scene.background)  #輸出管線中的背景色
(
0.5, 0.5, 0.5)

(二)GridSource網格數據源

技術分享圖片

scalars標量數據,他就是傳遞給mesh的標量數組,他表示mesh表面的每個點的數組
>>> source = s.children[0]  #獲取GridSource對象,因為scene場景中有多個數據集合sources,我們獲取當前唯一的這一個
>>> print(repr(source))  #打印返回的字符串
<mayavi.sources.vtk_data_source.VTKDataSource object at 0x0000000014117570>
>>> print(source.name)  #返回該節點的名稱
GridSource

>>> print(repr(source.data.points))  #打印GridSource的坐標(空間坐標,三維) [(0.0, 1.0852211291184772, 0.0), ..., (-0.01969313518771439, -1.5671711510166164 , -0.00024748426251406075)], length = 126504  #length說明坐標數組大小是126504 >>> print(repr(source.data.point_data.scalars))  #打印出每個點對應的標量數組 [0.0, ..., -0.00024748426251406075
], length = 126504

(三)PolyDataNormals是數據源的法向量

>>> manager = source.children[0]
>>> print(manager)
<mayavi.filters.poly_data_normals.PolyDataNormals object at 0x00000000163D1308>

(四)Colors and legends

技術分享圖片

>>> colors = manager.children[0]
>>> colors.scalar_lut_manager.lut_mode = "Blues"
>>> colors.scalar_lut_manager.show_legend = True

技術分享圖片

(五)Surface對象:將GridSource輸出的PolyData數據轉換為最終的在場景中顯示的三維實體

技術分享圖片

>>> surface = colors.children[0]    #獲得顏色的第一個子節點
>>> surface.actor.property.representation = "wireframe"
>>> surface.actor.property.opacity = 0.6

總結:程序配置屬性的步驟

1.獲取場景對象,mlab.gcf()
2.通過children屬性,在管線中找到需要修改的對象
3.當其配置窗口由多個選項卡,屬性需要一級一級獲得

技術分享圖片

Mayavi管線:是層級管線,相互嵌套,需要使用children獲取下一級
TVTK管線:分為可視化管線和圖形管線兩部分,用於將TVTK中各個對象穿連起來

科學計算三維可視化---Mayavi入門(Mayavi管線)