Esempio n. 1
0
def pc_sampler(mesh_file, n_samples, save_file=None, dtype=np.float32):
    in_mesh = Mesh(file_name=mesh_file)
    in_mesh = cleaning.clean_mesh(in_mesh)
    in_mesh.swap_axes_of_vertices([0, 2, 1])
    ss_points, _ = in_mesh.sample_faces(n_samples)
    pc = Point_Cloud(points=ss_points.astype(dtype))
    pc.center_in_unit_sphere()
    pc, _ = pc.lex_sort()
    if save_file is not None:
        pc.save_as_ply(save_file)
    return pc
Esempio n. 2
0
def main_Mesh():
    off_file = '/Users/optas/DATA/Shapes/Model_Net_10/OFF_Original/bathtub/train/bathtub_0001.off'

    in_mesh = Mesh(off_file=off_file)
    in_mesh.center_in_unit_sphere()
    cleaning.clean_mesh(in_mesh, level=3, verbose=True)

    in_lb = Laplace_Beltrami(in_mesh)
    n_cc, node_labels = in_mesh.connected_components()
    parts_id = Graph.largest_connected_components_at_thres(node_labels, 1)
    print 'Number of connected components = %d.' % (n_cc)

    percent_of_eigs = 1
    min_eigs = None
    max_eigs = None
    min_vertices = None
    time_horizon = 10
    area_type = 'barycentric'

    v_color = ns.hks_of_component_spectra(in_mesh, in_lb, area_type, percent_of_eigs, \
                                      time_horizon, min_vertices, min_eigs, max_eigs)[0]

    in_mesh.plot(vertex_function=v_color)
Esempio n. 3
0
def pc_uniform_sampler(mesh_file, n_samples, swap_y_z=True, save_file=None, dtype=np.float32, out_folder=None):
    ''' Given a mesh, it computes a point-cloud that is uniformly sampled
    from its area elements.
    '''
    in_mesh = Mesh(file_name=mesh_file)
    if swap_y_z:
        in_mesh.swap_axes_of_vertices([0, 2, 1])
    in_mesh = cleaning.clean_mesh(in_mesh)
    ss_points, _ = in_mesh.sample_faces(n_samples)
    pc = Point_Cloud(points=ss_points.astype(dtype))
    pc.center_in_unit_sphere()
    pc, _ = pc.lex_sort()
    if save_file is not None:
        pc.save_as_ply(save_file)
    return pc
Esempio n. 4
0
def pc_sampler(mesh_file,
               n_samples,
               save_file=None,
               rotate=False,
               dtype=np.float32):
    category = file_to_category(mesh_file)
    if rotate:
        rotate_deg = rotation_angles[category]
    in_mesh = Mesh(file_name=mesh_file)
    in_mesh = cleaning.clean_mesh(in_mesh)
    ss_points, _ = in_mesh.sample_faces(n_samples)
    pc = Point_Cloud(points=ss_points.astype(dtype))
    if rotate:
        pc.rotate_z_axis_by_degrees(rotate_deg)
    pc.center_in_unit_sphere()
    pc, _ = pc.lex_sort()
    if save_file is not None:
        pc.save_as_ply(save_file)
    return pc
Esempio n. 5
0
        if laplacian_type == 'comb':
            L = -A + D
        elif laplacian_type == 'norm':
            total_weight = (1 / np.sqrt(total_weight)).squeeze()
            Dn = sparse.spdiags(total_weight, 0, n, n)
            L = Dn.dot(-A + D).dot(Dn)
        elif laplacian_type == 'sign':
            L = A + D
        else:
            raise ValueError('Please provide a valid argument for the type of laplacian.')
        return L

if __name__ == '__main__':
    from geo_tool.solids import mesh_cleaning as cleaning
    from geo_tool.solids.mesh import Mesh

    off_file = '/Users/t_achlp/Documents/DATA/ModelNet10/OFF_Original/bathtub/train/bathtub_0001.off'
    in_mesh = Mesh(off_file)
    in_mesh.center_in_unit_sphere()
    cleaning.clean_mesh(in_mesh, level=3, verbose=False)

    cloud_points, face_ids = in_mesh.sample_faces(2000)
    from scipy import spatial
    tree = spatial.KDTree(cloud_points, leafsize=100)
    weights, neighbors = tree.query(cloud_points, 10)
    weights = weights[:, 1:]
    neighbors = neighbors[:, 1:]
    weights = np.exp(- weights**2 / (2 * np.median(weights)))
    A = Graph.knn_to_adjacency(neighbors, weights)