Marching Cube算法提取网格

PyMesh3D

Basic Installation

This project for mesh render in data science.

1
2
pip install --upgrade pip
pip install pymesh3d

If you need mayavi backend.

1
2
pip install mayavi
pip install pyqt

Quick Start

1
2
3
import pymesh
import numpy as np
import matplotlib.pyplot as plt

Look at the directory example for full example.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
##########################################
############ Rotate Mesh Data ############
##########################################

wkdir = "../../Render"

ey = np.load(wkdir + "/Ez.npy")[::2, ::50]

m, n = ey.shape[0], ey.shape[1]
res = np.zeros([m, n, n])
pymesh.rotate(ey, res, ifhalf = False)

fig = plt.figure(figsize=(4, 3))
plt.contourf(res[:, int(n/2), :].T)
cbar = plt.colorbar()

png

1
2
3
4
5
6
7
##########################################
############# Save Mesh Data #############
##########################################

mesh = pymesh.get_iso_surf(res, contours_number = 4, cmap = "jet")
color = pymesh.interp_color(mesh.iso_vals, cmap = "jet")
mesh.export(wkdir + "test", "obj")
1
2
3
4
5
##########################################
############# Load Mesh Data #############
##########################################

mesh = pymesh.Mesh.load(wkdir + "test", "obj")
1
2
3
##########################################
############# Plot Mesh Data #############
##########################################
1
2
3
4
5
from mayavi import mlab

mlab_mesh = pymesh.iso_surface(mesh, colormap = "RdBu")
mlab.colorbar()
mlab.show()

png

1
2
3
4
5
################ plt example #################

surf = mesh.plt_trisurf(cmap = "jet")
plt.colorbar(surf, orientation = 'horizontal')
plt.tight_layout()

png


Marching Cube算法提取网格
https://zhazhajust.github.io/2022/08/15/pymesh/
作者
JayZz
发布于
2022年8月15日
许可协议