TVTK庫可視化實(shí)例

實(shí)例1:標(biāo)量數(shù)據(jù)可視化

tvtk.ContourFilter() 等值面過濾器

方法 說明
generate_values(n, grid.point_data.scalars.range) 設(shè)定n條等值線的值,一般用于重新繪制等值線
set_value() 設(shè)定一條等值線的值,一般用于覆蓋某條等值線或者新增加一條等值線
#數(shù)據(jù)讀取
from tvtk.api import tvtk
from tvtkfunc import ivtk_scene, event_loop
 
plot3d = tvtk.MultiBlockPLOT3DReader(
        xyz_file_name="combxyz.bin",
        q_file_name="combq.bin",
        scalar_function_number=100, vector_function_number=200
    ) #讀入Plot3D數(shù)據(jù)
plot3d.update() #讓plot3D計(jì)算其輸出數(shù)據(jù)
grid = plot3d.output.get_block(0) #獲取讀入的數(shù)據(jù)集對(duì)象
 
#創(chuàng)建等值面
con = tvtk.ContourFilter()#創(chuàng)建等值面對(duì)象  
con.set_input_data(grid)
con.generate_values(10, grid.point_data.scalars.range)#指定輪廓數(shù)和數(shù)據(jù)范圍
 
#繪制數(shù)據(jù)
#設(shè)定映射器的變量范圍屬性
m = tvtk.PolyDataMapper(scalar_range = grid.point_data.scalars.range,
                        input_connection=con.output_port)
a = tvtk.Actor(mapper = m)
a.property.opacity = 0.5 #設(shè)定透明度為0.5
#窗口繪制
win = ivtk_scene(a)
win.scene.isometric_view()
event_loop()

tvtkfunc.py文件百度云鏈接
combxyz.bin和combq.bin文件百度云鏈接

實(shí)例2:矢量數(shù)據(jù)可視化

tvtk.Glyph3D() 符號(hào)化技術(shù)

tvtk.MaskPoints() 降采樣

from tvtk.api import tvtk
from tvtkfunc import ivtk_scene, event_loop
 
#讀入PLot3D數(shù)據(jù)
plot3d = tvtk.MultiBlockPLOT3DReader(
        xyz_file_name="combxyz.bin",
        q_file_name="combq.bin",
        scalar_function_number=100, vector_function_number=200
    )
plot3d.update()
grid = plot3d.output.get_block(0)
 
#對(duì)數(shù)據(jù)集中的數(shù)據(jù)進(jìn)行隨機(jī)選取,每50個(gè)點(diǎn)選擇一個(gè)點(diǎn)
mask = tvtk.MaskPoints(random_mode=True, on_ratio=50)
mask.set_input_data(grid)
#創(chuàng)建表示箭頭的PolyData數(shù)據(jù)集
glyph_source = tvtk.ConeSource()
#在Mask采樣后的PolyData數(shù)據(jù)集每個(gè)點(diǎn)上放置一個(gè)箭頭
#箭頭的方向、長度和顏色由于點(diǎn)對(duì)應(yīng)的矢量和標(biāo)量數(shù)據(jù)決定
glyph = tvtk.Glyph3D(input_connection=mask.output_port,
                      scale_factor=2)
glyph.set_source_connection(glyph_source.output_port)
m = tvtk.PolyDataMapper(scalar_range=grid.point_data.scalars.range,
                        input_connection=glyph.output_port)
a = tvtk.Actor(mapper=m)
 
#窗口繪制
win = ivtk_scene(a)
win.scene.isometric_view()
event_loop()

實(shí)例3:空間輪廓線可視化

tvtk.StructuredGridOutlineFilter()
計(jì)算PolyData對(duì)象的外邊框。

from tvtk.api import tvtk
from tvtk.common import configure_input
from tvtkfunc import ivtk_scene, event_loop
 
plot3d = tvtk.MultiBlockPLOT3DReader(
        xyz_file_name="combxyz.bin",
        q_file_name="combq.bin",
        scalar_function_number=100, vector_function_number=200
    )#讀入Plot3D數(shù)據(jù)
plot3d.update()#讓plot3D計(jì)算其輸出數(shù)據(jù)
grid = plot3d.output.get_block(0)#獲取讀入的數(shù)據(jù)集對(duì)象
 
outline = tvtk.StructuredGridOutlineFilter()#計(jì)算表示外邊框的PolyData對(duì)象
configure_input(outline, grid)#調(diào)用tvtk.common.configure_input()
m = tvtk.PolyDataMapper(input_connection=outline.output_port)
a = tvtk.Actor(mapper=m)
a.property.color = 0.3, 0.3, 0.3
 
#窗口繪制
win = ivtk_scene(a)
win.scene.isometric_view()
event_loop()

Reference :
中國大學(xué)MOOC北京理工大學(xué)Python科學(xué)計(jì)算三維可視化黃天羽、嵩天老師課件
課程主頁

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,094評(píng)論 25 709
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,578評(píng)論 19 139
  • 此原創(chuàng)文章已獲得大數(shù)據(jù)文摘(微信公眾號(hào))采用,并于2017年4月29日發(fā)布(閱讀量近5K):前沿 | 國際可視化盛...
    Kayyyy閱讀 8,615評(píng)論 0 43
  • 地樁連著繩子, 繩子的那頭 牽著一頭牛。 它低著頭,從來不看天, 也忘記了 月色。 頂著,迎著烈陽,日復(fù)一日...
    腎毒閱讀 335評(píng)論 10 11
  • 是因?yàn)樽陨淼臈l件優(yōu)越?還是因?yàn)閷?duì)方對(duì)自己的關(guān)心愛護(hù)太多? 人類在愛情中總有一種很大的問題,就是受傷害的永遠(yuǎn)是投入最...
    小小話嘮子閱讀 218評(píng)論 0 0

友情鏈接更多精彩內(nèi)容