国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

Python利用PyVista進(jìn)行mesh的色彩映射的實(shí)現(xiàn)

瀏覽:79日期:2022-06-23 15:11:40

最近項(xiàng)目中需要對(duì)mesh做一個(gè)色彩映射,無(wú)意間發(fā)現(xiàn)vtk的封裝庫(kù)pyvista相當(dāng)好用,就試了試,在此做一個(gè)總結(jié)。

PyVista簡(jiǎn)介PyVista是什么

PyVista 是一個(gè):

VTK for humans”, 可視化工具包(VTK)的高級(jí)API 空間數(shù)據(jù)的網(wǎng)格數(shù)據(jù)結(jié)構(gòu)與濾波方法 使3D繪圖更加簡(jiǎn)單,可用于大型/復(fù)雜數(shù)據(jù)的圖像化

PyVista(以前的vtki)是可視化工具包(VTK)的一個(gè)助手模塊,它采用了一種不同的方法,通過(guò)NumPy和直接數(shù)組訪問(wèn)與VTK進(jìn)行接口。這個(gè)包提供了一個(gè)python化的、文檔化良好的接口,展示了VTK強(qiáng)大的可視化后端,以方便對(duì)空間引用的數(shù)據(jù)集進(jìn)行快速原型化、分析和可視化集成。

該模塊可用于演示文稿和研究論文的科學(xué)繪圖,以及其他依賴(lài)網(wǎng)格的Python模塊的支持模塊。

參考:https://docs.pyvista.org/index.html

github

官方教程

pyvista和其他3D可視化工具比較

Python利用PyVista進(jìn)行mesh的色彩映射的實(shí)現(xiàn)

參考:https://github.com/pyvista/pyvista/issues/146

pyvista使用安裝

pip install pyvista -i https://pypi.tuna.tsinghua.edu.cn/simpleI/O讀取及可視化

mesh類(lèi)型

pyvista支持讀取大多數(shù)常見(jiàn)的mesh文件類(lèi)型,比如PLY,VTK,STL ,OBJ ,BYU 等,一些不常見(jiàn)的mesh文件類(lèi)型,比如FEniCS/Dolfin_ XML format

(很遺憾,pyvista不支持點(diǎn)云PCD格式,不過(guò)可以通過(guò)pcdpy、pclpy、python-pcl等庫(kù)來(lái)讀取pcd文件)

import pyvista as pv# 讀取mesh = pv.read(’pointCloudData/data.vtk’)# 顯示mesh.plot()# 其他類(lèi)似mesh = pv.read(’pointCloudData/data.ply’)……圖片類(lèi)型

支持讀取圖片類(lèi)型數(shù)據(jù)JPEG, TIFF, PNG等

# 讀取image = pv.read(’my_image.jpg’)# 顯示image.plot(rgb=True, cpos='xy')# 其余圖片類(lèi)型類(lèi)似……mesh彩色映射

項(xiàng)目中需要用到根據(jù)高度來(lái)對(duì)mesh進(jìn)行彩色映射,在pyvista中大概有四種方法

自定義

代碼

import pyvista as pvimport matplotlib.pyplot as pltfrom matplotlib.colors import ListedColormapimport numpy as npdef mesh_cmp_custom(mesh, name): ''' 自定義色彩映射 :param mesh: 輸入mesh :param name: 比較數(shù)據(jù)的名字 :return: ''' pts = mesh.points mesh[name] = pts[:, 1] # Define the colors we want to use blue = np.array([12 / 256, 238 / 256, 246 / 256, 1]) black = np.array([11 / 256, 11 / 256, 11 / 256, 1]) grey = np.array([189 / 256, 189 / 256, 189 / 256, 1]) yellow = np.array([255 / 256, 247 / 256, 0 / 256, 1]) red = np.array([1, 0, 0, 1]) c_min = mesh[name].min() c_max = mesh[name].max() c_scale = c_max - c_min mapping = np.linspace(c_min, c_max, 256) newcolors = np.empty((256, 4)) newcolors[mapping >= (c_scale * 0.8 + c_min)] = red newcolors[mapping < (c_scale * 0.8 + c_min)] = grey newcolors[mapping < (c_scale * 0.55 + c_min)] = yellow newcolors[mapping < (c_scale * 0.3 + c_min)] = blue newcolors[mapping < (c_scale * 0.1 + c_min)] = black # Make the colormap from the listed colors my_colormap = ListedColormap(newcolors) mesh.plot(scalars=name, cmap=my_colormap)if __name__ == ’__main__’: mesh = pv.read(’pointCloudData/1.ply’) mesh_cmp_custom(mesh, ’y_height’)

效果:

Python利用PyVista進(jìn)行mesh的色彩映射的實(shí)現(xiàn)

使用pyvista自帶的cmp

函數(shù)mesh.plot(scalars=name, cmap=’viridis_r’)

其中cmap支持的樣式:

‘Accent’, ‘Accent_r’, ‘Blues’, ‘Blues_r’, ‘BrBG’, ‘BrBG_r’, ‘BuGn’, ‘BuGn_r’, ‘BuPu’, ‘BuPu_r’, ‘CMRmap’, ‘CMRmap_r’, ‘Dark2’, ‘Dark2_r’, ‘GnBu’, ‘GnBu_r’, ‘Greens’, ‘Greens_r’, ‘Greys’, ‘Greys_r’, ‘OrRd’, ‘OrRd_r’, ‘Oranges’, ‘Oranges_r’, ‘PRGn’, ‘PRGn_r’, ‘Paired’, ‘Paired_r’, ‘Pastel1’, ‘Pastel1_r’, ‘Pastel2’, ‘Pastel2_r’, ‘PiYG’, ‘PiYG_r’, ‘PuBu’, ‘PuBuGn’, ‘PuBuGn_r’, ‘PuBu_r’, ‘PuOr’, ‘PuOr_r’, ‘PuRd’, ‘PuRd_r’, ‘Purples’, ‘Purples_r’, ‘RdBu’, ‘RdBu_r’, ‘RdGy’, ‘RdGy_r’, ‘RdPu’, ‘RdPu_r’, ‘RdYlBu’, ‘RdYlBu_r’, ‘RdYlGn’, ‘RdYlGn_r’, ‘Reds’, ‘Reds_r’, ‘Set1’, ‘Set1_r’, ‘Set2’, ‘Set2_r’, ‘Set3’, ‘Set3_r’, ‘Spectral’, ‘Spectral_r’, ‘Wistia’, ‘Wistia_r’, ‘YlGn’, ‘YlGnBu’, ‘YlGnBu_r’, ‘YlGn_r’, ‘YlOrBr’, ‘YlOrBr_r’, ‘YlOrRd’, ‘YlOrRd_r’, ‘a(chǎn)fmhot’, ‘a(chǎn)fmhot_r’, ‘a(chǎn)utumn’, ‘a(chǎn)utumn_r’, ‘binary’, ‘binary_r’, ‘bone’, ‘bone_r’, ‘brg’, ‘brg_r’, ‘bwr’, ‘bwr_r’, ‘cividis’, ‘cividis_r’, ‘cool’, ‘cool_r’, ‘coolwarm’, ‘coolwarm_r’, ‘copper’, ‘copper_r’, ‘cubehelix’, ‘cubehelix_r’, ‘flag’, ‘flag_r’, ‘gist_earth’, ‘gist_earth_r’, ‘gist_gray’, ‘gist_gray_r’, ‘gist_heat’, ‘gist_heat_r’, ‘gist_ncar’, ‘gist_ncar_r’, ‘gist_rainbow’, ‘gist_rainbow_r’, ‘gist_stern’, ‘gist_stern_r’, ‘gist_yarg’, ‘gist_yarg_r’, ‘gnuplot’, ‘gnuplot2’, ‘gnuplot2_r’, ‘gnuplot_r’, ‘gray’, ‘gray_r’, ‘hot’, ‘hot_r’, ‘hsv’, ‘hsv_r’, ‘inferno’, ‘inferno_r’, ‘jet’, ‘jet_r’, ‘magma’, ‘magma_r’, ‘nipy_spectral’, ‘nipy_spectral_r’, ‘ocean’, ‘ocean_r’, ‘pink’, ‘pink_r’, ‘plasma’, ‘plasma_r’, ‘prism’, ‘prism_r’, ‘rainbow’, ‘rainbow_r’, ‘seismic’, ‘seismic_r’, ‘spring’, ‘spring_r’, ‘summer’, ‘summer_r’, ‘tab10’, ‘tab10_r’, ‘tab20’, ‘tab20_r’, ‘tab20b’, ‘tab20b_r’, ‘tab20c’, ‘tab20c_r’, ‘terrain’, ‘terrain_r’, ‘turbo’, ‘turbo_r’, ‘twilight’, ‘twilight_r’, ‘twilight_shifted’, ‘twilight_shifted_r’, ‘viridis’, ‘viridis_r’, ‘winter’, ‘winter_r’

代碼

import pyvista as pvdef mesh_cmp(mesh, name): ''' 使用進(jìn)行plot自帶的色彩映射 :param mesh: 輸入mesh :param name: 比較數(shù)據(jù)的名字 :return: ''' pts = mesh.points mesh[name] = pts[:, 1] mesh.plot(scalars=name, cmap=’viridis_r’) if __name__ == ’__main__’: mesh = pv.read(’vtkData/airplane.ply’) mesh_cmp(mesh, ’y_height’)

效果

Python利用PyVista進(jìn)行mesh的色彩映射的實(shí)現(xiàn)

使用Matplotlib的cmp

代碼

import pyvista as pvimport matplotlib.pyplot as pltdef mesh_cmp_mpl(mesh, name): ''' 使用Matplotlib進(jìn)行色彩映射 :param mesh: 輸入mesh :param name: 比較數(shù)據(jù)的名字 :return: ''' pts = mesh.points mesh[name] = pts[:, 1] mlp_cmap = plt.cm.get_cmap('viridis', 25) mesh.plot(scalars=name, cmap=mlp_cmap) if __name__ == ’__main__’: mesh = pv.read(’vtkData/airplane.ply’) mesh_cmp_mpl(mesh, ’y_height’)

效果

Python利用PyVista進(jìn)行mesh的色彩映射的實(shí)現(xiàn)

使用colorcet的cmp

需要先安裝colorcet:

pip install colorcet

使用方法和上面幾種方法類(lèi)似,若想使用colorcet的colormaps中的hot:

mesh.plot(scalars=name, cmap=“hot”)

代碼

def mesh_cmp_colorcet(mesh, name): ''' 使用進(jìn)行colorcet進(jìn)行色彩映射 :param mesh: 輸入mesh :param name: 比較數(shù)據(jù)的名字 :return: ''' pts = mesh.points mesh[name] = pts[:, 1] mesh.plot(scalars=name, cmap=colorcet.fire) if __name__ == ’__main__’: mesh = pv.read(’vtkData/airplane.ply’) mesh_cmp_colorcet(mesh, ’y_height’)

效果:

Python利用PyVista進(jìn)行mesh的色彩映射的實(shí)現(xiàn)

總結(jié)

pyvista相當(dāng)強(qiáng)大,而且比直接用vtk更加方便(代碼量肉眼可見(jiàn)的降低!)

到此這篇關(guān)于Python利用PyVista進(jìn)行mesh的色彩映射的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)PyVista mesh色彩映射內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 免费视频18 | 精品国产欧美精品v | 国产精品日韩欧美在线第3页 | 亚洲精品美女国产一区 | 日本欧美韩国一区二区三区 | 在线观看毛片视频 | 黄色美女网站在线观看 | 国产精品久久久久久小说 | 九九色综合 | 日本www免费 | 欧美一区二区视频在线观看 | 午夜日本一区二区三区 | 亚洲国产精品第一区二区 | 国产精品欧美日韩一区二区 | 黄色w站| 中文字幕最新中文字幕中文字幕 | 国产亚洲国产bv网站在线 | 美女mm131爽爽爽免费视色 | 国产三级在线 | 久草中文网 | 寡妇一级a毛片免费播放 | 婷婷尹人香蕉久久天堂 | 一级黄色毛片播放 | 一级片成人 | 夜色www| 久久国产亚洲欧美日韩精品 | 精品国产成人高清在线 | 亚洲国产激情一区二区三区 | 欧美综合一区 | 成人午夜在线观看国产 | 国产91成人精品亚洲精品 | 男女男精品视频网站在线观看 | 国产在线一区观看 | 成人精品一区二区久久久 | 成人全黄三级视频在线观看 | 精品久久久久久中文字幕 | 日本久操| 亚洲 欧美 成人 | 亚洲精品二区中文字幕 | 国产三级精品三级 | 国产一区二区三区成人久久片 |