【mayavi建模渲染完成后,获取点击位置的坐标】

代码部分

import numpy as np
from mayavi import mlab
from triangle import delaunay

input_path = r"C:\Users\Huangchao\Desktop\点与特征线建模\新建文本文档.txt"
// 导入的数据格式为:
//495367.107 2509054.251 35.099
//495367.171 2509054.372 35.065
//495367.226 2509053.794 35.015
//495367.238 2509054.059 34.971

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()

效果

【mayavi建模渲染完成后,获取点击位置的坐标】_第1张图片

你可能感兴趣的:(python)