如何select pymeshlab中的顶点数组?

How to select an array of vertices in pymeshlab?

我想从网格中删除一些存储在 NumPy 数组中的顶点。我如何根据顶点索引或坐标 select pymeshlab 中的这些顶点?谢谢!

import pymeshlab
from scipy.spatial import KDTree

def remove_background(subdir, ms):
    # load joint points
    joint_arr = load_joint_points(subdir)

    # get a reference to the current mesh
    m = ms.current_mesh()

    # get numpy arrays of vertices of the current mesh
    vertex_array_matrix = m.vertex_matrix()
    print(f'total # of vertices: {m.vertex_number()}')

    # create a KD tree of the joint points
    tree = KDTree(joint_arr)

    selected_vertices = []

    for vertex in vertex_array_matrix:
        # if the closest joint pt is farther than 500mm from the vertex, add the vertex to list
        dd, ii = tree.query(vertex, k=1)
        if(dd > 500):
            selected_vertices.append(vertex)

    print(f"delete {len(selected_vertices)} vertices")
    
    #how to select 'selected vertices' in pymeshlab?

    ms.delete_selected_vertices()

!您可以使用 conditional selection filter

有条件地 select 使用索引的顶点
import pymeshlab as ml
ms = ml.MeshSet()
# just create a simple mesh for example
ms.sphere(subdiv=0)
# select the vertex with index 0
ms.conditional_vertex_selection(condselect="vi==0") 
# delete selected stuff
ms.delete_selected_vertices() 

更好的是,您可以在 pymeshlab 中完成所有背景删除。 如果你有两个 meshes/pointclouds A B 并且你想从 B 所有靠近 A 小于给定阈值的顶点你可以只加载两个网格,使用 Hausdorff Distance filter 将为 A 的每个顶点存储到 [= 的最近顶点的距离22=]B;那么这次您可以通过质量测试再次使用条件 select 离子过滤器。