Exemplo n.º 1
0
    def test_lloyd_relaxation(self):
        import point_cloud_utils as pcu

        # v is a nv by 3 NumPy array of vertices
        # f is an nf by 3 NumPy array of face indexes into v
        v, f, n = pcu.read_obj(os.path.join(self.test_path, "cube_twist.obj"))

        # Generate 1000 points on the mesh with Lloyd's algorithm
        samples = pcu.sample_mesh_lloyd(v, f, 1000)

        # Generate 100 points on the unit square with Lloyd's algorithm
        samples_2d = pcu.lloyd_2d(100)
Exemplo n.º 2
0
def file_to_pointcloud(filename, type, args):
    if type == 'shapenet':
        points, triangles, quads = read_obj_file(filename)
    elif type == 'modelnet':
        points, triangles, quads = read_off_file(filename)
    else:
        print("bad dataset type")
    if args.normal:
        return mesh_to_point_cloud(points,
                                   triangles,
                                   args.num_points,
                                   mode,
                                   normal=True)
    if args.mode == 'lloyd':
        return pcu.sample_mesh_lloyd(points, triangles, args.num_points)
    #return pcu.sample_mesh_random(points, triangles,np.array([]), args.num_points)
    return mesh_to_point_cloud(points, triangles, args.num_points, args.mode)
Exemplo n.º 3
0
def generateSamples(mesh, num):
    vertices = mesh.points()
    faces = np.asarray(mesh.faces())
    samples = pcu.sample_mesh_lloyd(vertices, faces, num)
    return samples
Exemplo n.º 4
0
filenames = [f for f in files_in_subdirs(args.dataset_path, args.termination)]
for i, fi in enumerate(filenames):
    path = os.path.split(fi)[0]
    foldername = path.replace(args.dataset_path + '/', '')
    name = os.path.split(fi)[-1].split('.')[0]
    if args.save_path == 'None':
        args.save_path = os.path.split(
            args.dataset_path)[0] + '/' + os.path.split(
                args.dataset_path)[1] + '_resampled'

    if not os.path.exists(args.save_path): os.makedirs(args.save_path)
    if os.path.split(foldername)[-1] == args.dataset_path.split(
            '/')[-1]:  #Single folder structure
        destination_filename = args.save_path + '/' + name
    else:
        if not os.path.exists(args.save_path + '/' + foldername):
            os.makedirs(args.save_path + '/' + foldername)
        destination_filename = args.save_path + '/' + foldername + '/' + name

    if args.termination == '.off':
        v, f, n = pcu.read_off(fi)
    elif args.termination == '.obj':
        v, f, n = pcu.read_obj(fi)
    else:
        print('Invalid termination')
        sys.exit(1)
    if len(f) != 0:
        samples = pcu.sample_mesh_lloyd(
            v, f, args.n_points)  #normals inside v, poorly saved
        np.save(destination_filename + '.npy', samples)