色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術文章
文章詳情頁

Python利用PyVista進行mesh的色彩映射的實現

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

最近項目中需要對mesh做一個色彩映射,無意間發現vtk的封裝庫pyvista相當好用,就試了試,在此做一個總結。

PyVista簡介PyVista是什么

PyVista 是一個:

VTK for humans”, 可視化工具包(VTK)的高級API 空間數據的網格數據結構與濾波方法 使3D繪圖更加簡單,可用于大型/復雜數據的圖像化

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

該模塊可用于演示文稿和研究論文的科學繪圖,以及其他依賴網格的Python模塊的支持模塊。

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

github

官方教程

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

Python利用PyVista進行mesh的色彩映射的實現

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

pyvista使用安裝

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

mesh類型

pyvista支持讀取大多數常見的mesh文件類型,比如PLY,VTK,STL ,OBJ ,BYU 等,一些不常見的mesh文件類型,比如FEniCS/Dolfin_ XML format

(很遺憾,pyvista不支持點云PCD格式,不過可以通過pcdpy、pclpy、python-pcl等庫來讀取pcd文件)

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

支持讀取圖片類型數據JPEG, TIFF, PNG等

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

項目中需要用到根據高度來對mesh進行彩色映射,在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: 比較數據的名字 :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進行mesh的色彩映射的實現

使用pyvista自帶的cmp

函數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’, ‘afmhot’, ‘afmhot_r’, ‘autumn’, ‘autumn_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): ''' 使用進行plot自帶的色彩映射 :param mesh: 輸入mesh :param name: 比較數據的名字 :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進行mesh的色彩映射的實現

使用Matplotlib的cmp

代碼

import pyvista as pvimport matplotlib.pyplot as pltdef mesh_cmp_mpl(mesh, name): ''' 使用Matplotlib進行色彩映射 :param mesh: 輸入mesh :param name: 比較數據的名字 :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進行mesh的色彩映射的實現

使用colorcet的cmp

需要先安裝colorcet:

pip install colorcet

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

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

代碼

def mesh_cmp_colorcet(mesh, name): ''' 使用進行colorcet進行色彩映射 :param mesh: 輸入mesh :param name: 比較數據的名字 :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進行mesh的色彩映射的實現

總結

pyvista相當強大,而且比直接用vtk更加方便(代碼量肉眼可見的降低!)

到此這篇關于Python利用PyVista進行mesh的色彩映射的實現的文章就介紹到這了,更多相關PyVista mesh色彩映射內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 国产精品亚洲高清一区二区 | 国产精品三级国语在线看 | 男人的天堂在线观看入口 | 久久这里只有精品免费视频 | 91久久国产精品视频 | 欧美一区二区三区视频在线 | 欧美成人一级片 | 中文字幕在线看视频一区二区三区 | 亚洲视频国产精品 | 亚洲成a人片毛片在线 | 国产精品自在自线亚洲 | 国产免费一级精品视频 | 免费逼片 | 国产99视频精品免视看7 | 成年网站免费视频黄 | 91看片淫黄大片.在线天堂 | 日韩a一级欧美一级在线播放 | 一级在线视频 | 成 人 在 线 免费 8888 www | 日韩精品欧美激情国产一区 | 国产成人一区二区在线不卡 | 国产亚洲综合精品一区二区三区 | 国产精品久久久久一区二区三区 | 狠狠色综合网站久久久久久久 | 九九九热视频 | 日本阿v精品视频在线观看 日本阿v视频在线观看高清 | 欧美日韩一区二区三区高清不卡 | 久久中文字幕日韩精品 | 真人真实毛片免费观看 | 中文字幕日韩国产 | 中文字幕一区中文亚洲 | 欧美日韩国产一区二区三区在线观看 | 亚洲国产高清人在线 | 日本xxxxx久色视频在线观看 | 在线黄色影院 | 看三级毛片 | 亚洲视频在线播放 | 国产精品久久久久久久久免费观看 | 日韩欧一级毛片在线播无遮挡 | 成人怡红院 | 欧美一级特黄刺激爽大片 |