代码部分
import numpy as np
from mayavi import mlab
from triangle import delaunay
input_path = r"C:\Users\Huangchao\Desktop\点与特征线建模\新建文本文档.txt"
data = np.loadtxt(input_path, dtype=float)
data1 = np.delete(data, 2, axis=1)
tri = delaunay(data1)
fig = mlab.figure(1)
mesh = mlab.triangular_mesh(data[:, 0], data[:, 1], data[:, 2], tri.tolist())
def picker_callback(picker_obj):
picked = picker_obj.actors
if mesh.actor.actor._vtk_obj in [o._vtk_obj for o in picked]:
# m.mlab_source.points is the points array underlying the vtk
# dataset. GetPointId return the index in this array.
x = str(picker_obj.pick_position[0])+" "
y = str(picker_obj.pick_position[1])+" "
h = str(picker_obj.pick_position[2])
mlab.title(x + y + h)
# x_, y_ = np.lib.index_tricks.unravel_index(picker_obj.point_id, (23, 3)) 查询点的位置所在的三角形数据
# print("Data indices: %i, %i" % (x_, y_))
fig.on_mouse_pick(picker_callback)
mlab.show()
效果