libigl是一个很方便的几何网格处理库
可以计算出Gaussian Curvature、Principle Curvature等基础信息。
python 基础代码如下:
from scipy.sparse.linalg import spsolve
import igl
import os
import numpy as np
import igl
import scipy as sp
from meshplot import plot, subplot, interact
import meshplot
meshplot.jupyter()
meshplot.offline()
v, f = igl.read_triangle_mesh("data/******.obj")
l = igl.cotmatrix(v, f)
n = igl.per_vertex_normals(v, f)*0.5+0.5
c = np.linalg.norm(n, axis=1)
vs = [v]
cs = [c]
for i in range(10):
m = igl.massmatrix(v, f, igl.MASSMATRIX_TYPE_BARYCENTRIC)
s = (m - 0.001 * l)
b = m.dot(v)
v = spsolve(s, m.dot(v))
n = igl.per_vertex_normals(v, f)*0.5+0.5
c = np.linalg.norm(n, axis=1)
vs.append(v)
cs.append(c)
# plot(v, f)
# plot(vs[0], f, c, shading={"wireframe": False}, s=[1, 4, 0])
p = subplot(vs[0], f, c, shading={"wireframe": False}, s=[1, 4, 0])
subplot(vs[3], f, c, shading={"wireframe": False}, s=[1, 4, 1], data=p)
subplot(vs[6], f, c, shading={"wireframe": False}, s=[1, 4, 2], data=p)
subplot(vs[9], f, c, shading={"wireframe": False}, s=[1, 4, 3], data=p)
p.save("subplot.html")
# @interact(level=(0, 9))
# def mcf(level=0):
# p.update_object(vertices=vs[level], colors=cs[level])
k = igl.gaussian_curvature(v, f)
p = plot(v, f, k, return_plot=True)
p.save("gaussian_curvature.html")
m = igl.massmatrix(v, f, igl.MASSMATRIX_TYPE_VORONOI)
minv = sp.sparse.diags(1 / m.diagonal())
kn = minv.dot(k)
p = plot(v, f, kn, return_plot=True)
p.save("igl.massmatrix2222.html")
l = igl.cotmatrix(v, f)
m = igl.massmatrix(v, f, igl.MASSMATRIX_TYPE_VORONOI)
minv = sp.sparse.diags(1 / m.diagonal())
hn = -minv.dot(l.dot(v))
h = np.linalg.norm(hn, axis=1)
p = plot(v, f, h, return_plot=True)
p.save("igl.massmatrix.html")
v1, v2, k1, k2 = igl.principal_curvature(v, f)
h2 = 0.5 * (k1 + k2)
p = plot(v, f, h2, shading={"wireframe": False}, return_plot=True)
p.save("principal_curvature.html")
avg = igl.avg_edge_length(v, f) / 2.0
p.add_lines(v + v1 * avg, v - v1 * avg, shading={"line_color": "red"})
p.add_lines(v + v2 * avg, v - v2 * avg, shading={"line_color": "green"})
p.save("principal_curvature_line.html")
## Select a vertex from which the distances should be calculated
vs = np.array([0])
##All vertices are the targets
vt = np.arange(v.shape[0])
d = igl.exact_geodesic(v, f, vs, vt)#, fs, ft)
strip_size = 0.02
##The function should be 1 on each integer coordinate
c = np.abs(np.sin((d / strip_size * np.pi)))
p = plot(v, f, c, shading={"wireframe": False}, return_plot=True)
p.save("exact_geodesic.html")
import pdb
pdb.set_trace()