1

我想从网格中删除存储在 NumPy 数组中的一些顶点。如何根据顶点索引或坐标在 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()
4

1 回答 1

1

是的您可以使用条件选择过滤器使用索引有条件地选择顶点

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 中完成所有背景删除。如果您有两个网格/点云AB,并且您想从B中删除所有接近A且小于给定阈值的顶点,您可以只加载两个网格,使用Hausdorff 距离过滤器,该过滤器将存储到每个顶点的“质量”中A的距离B的最近顶点的距离;那么这次您可以通过质量测试再次使用条件选择过滤器。

于 2021-07-21T08:18:14.957 回答