本文整理匯總了Python中pymesh.load_mesh方法的典型用法代碼示例。如果您正苦於以下問題:Python pymesh.load_mesh方法的具體用法?Python pymesh.load_mesh怎麽用?Python pymesh.load_mesh使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pymesh
的用法示例。
在下文中一共展示了pymesh.load_mesh方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: load_point_input
# 需要導入模塊: import pymesh [as 別名]
# 或者: from pymesh import load_mesh [as 別名]
def load_point_input(self, path):
ext = path.split('.')[-1]
if ext == "npy":
points = np.load(path)
elif ext == "ply" or ext == "obj":
import pymesh
points = pymesh.load_mesh(path).vertices
else:
print("invalid file extension")
points = torch.from_numpy(points).float()
operation = pointcloud_processor.Normalization(points, keep_track=True)
if self.opt.normalization == "UnitBall":
operation.normalize_unitL2ball()
elif self.opt.normalization == "BoundingBox":
operation.normalize_bounding_box()
else:
pass
return_dict = {
'points': points,
'operation': operation,
'path': path,
}
return return_dict
示例2: isolate_files
# 需要導入模塊: import pymesh [as 別名]
# 或者: from pymesh import load_mesh [as 別名]
def isolate_files():
"""
Utility fonction to generate the metro_file archive. Useless to all users but the author.
"""
with open('./dataset/data/metro_files/files-metro.txt', 'r') as file:
files = file.read().split('\n')
for file in files:
if file[-3:] == "ply":
cat = file.split('/')[0]
name = file.split('/')[1][:-4]
path_points = '/'.join(['.', 'dataset', 'data', 'ShapeNetV1PointCloud', cat, name + '.points.ply.npy'])
path_png = '/'.join(['.', 'dataset', 'data', 'ShapeNetV1Renderings', cat, name, "rendering", '00.png'])
path_obj = '/'.join(['', 'home', 'thibault', 'hdd', 'data', 'ShapeNetCore.v1', cat, name, 'model.obj'])
mesh = pymesh.load_mesh(path_obj)
points = np.load((path_points))
if not exists('/'.join(['.', 'dataset', 'data', 'metro_files', cat])):
os.mkdir('/'.join(['.', 'dataset', 'data', 'metro_files', cat]))
pymesh.save_mesh('/'.join(['.', 'dataset', 'data', 'metro_files', cat, name + '.ply']), mesh, ascii=True)
np.save('/'.join(['.', 'dataset', 'data', 'metro_files', cat, name + '.npy']), points)
copy(path_png, '/'.join(['.', 'dataset', 'data', 'metro_files', cat, name + '.png']))
示例3: shuffle_pc
# 需要導入模塊: import pymesh [as 別名]
# 或者: from pymesh import load_mesh [as 別名]
def shuffle_pc(file, output_path):
"""
Function to shuffle a point cloud produced by virtual scanner.
"""
mesh = pymesh.load_mesh(file)
vertices = copy.deepcopy(mesh.vertices)
permutation = np.random.permutation(len(vertices))
vertices = vertices[permutation]
new_mesh = pymesh.meshio.form_mesh(vertices, mesh.faces)
new_mesh.add_attribute("vertex_nx")
new_mesh.set_attribute("vertex_nx", mesh.get_vertex_attribute("vertex_nx")[permutation])
new_mesh.add_attribute("vertex_ny")
new_mesh.set_attribute("vertex_ny", mesh.get_vertex_attribute("vertex_ny")[permutation])
new_mesh.add_attribute("vertex_nz")
new_mesh.set_attribute("vertex_nz", mesh.get_vertex_attribute("vertex_nz")[permutation])
pymesh.save_mesh(output_path, new_mesh, ascii=True, anonymous=True, use_float=True, *new_mesh.get_attribute_names())
示例4: read_trimesh
# 需要導入模塊: import pymesh [as 別名]
# 或者: from pymesh import load_mesh [as 別名]
def read_trimesh(path, normal=False, clean=True):
mesh = pymesh.load_mesh(path)
if clean:
mesh, info = pymesh.remove_isolated_vertices(mesh)
print("Removed {} isolated vertices".format(info["num_vertex_removed"]))
mesh, info = pymesh.remove_duplicated_vertices(mesh)
print("Merged {} duplicated vertices".format(info["num_vertex_merged"]))
mesh, info = pymesh.remove_degenerated_triangles(mesh)
mesh = pymesh.form_mesh(mesh.vertices, mesh.faces)
vertices = mesh.vertices
if normal:
mesh.add_attribute("vertex_normal")
vertex_normals = mesh.get_attribute("vertex_normal").reshape(-1, 3)
vertices = np.concatenate([vertices, vertex_normals], axis=-1)
return vertices, mesh.faces
示例5: downsample_pointcloud
# 需要導入模塊: import pymesh [as 別名]
# 或者: from pymesh import load_mesh [as 別名]
def downsample_pointcloud(pc_path, point_num):
mesh_raw = pymesh.load_mesh(pc_path)
points_raw = mesh_raw.vertices
if points_raw.shape[0] > point_num:
point_subset = np.random.choice(points_raw.shape[0], point_num, replace=False)
points = points_raw[point_subset]
else:
points = points_raw
mesh = pymesh.form_mesh(points, np.ones((0, 3)))
pymesh.save_mesh(join(dirname(pc_path), 'compressed.ply'), mesh)
示例6: __init__
# 需要導入模塊: import pymesh [as 別名]
# 或者: from pymesh import load_mesh [as 別名]
def __init__(self, mesh_file):
super(MeshView, self).__init__();
self.mesh = pymesh.load_mesh(mesh_file);
self.__init_mesh();
示例7: create_from_setting
# 需要導入模塊: import pymesh [as 別名]
# 或者: from pymesh import load_mesh [as 別名]
def create_from_setting(cls, setting):
""" Syntax:
{
"type": "boundary",
"mesh": mesh_file,
"color": color_name,
"radius": radius
}
"""
mesh = pymesh.load_mesh(setting["mesh"]);
vertices = mesh.vertices;
bd_edges = mesh.boundary_edges;
vertices, bd_edges, __ = pymesh.remove_isolated_vertices_raw(vertices, bd_edges);
wires = pymesh.wires.WireNetwork();
if len(bd_edges) > 0:
wires.load(vertices, bd_edges);
else:
logger = logging.getLogger(__name__);
logger.warning("Mesh ({}) contains no boundary.".format(
setting["mesh"]));
tmp_dir = tempfile.gettempdir();
stamp = datetime.datetime.now().isoformat();
wire_file = os.path.join(tmp_dir, "{}.wire".format(stamp));
wires.write_to_file(wire_file);
wire_setting = {
"type": "wire_network",
"wire_network": wire_file,
"color": setting.get("color", None),
"radius": setting.get("radius", 0.1),
"bbox": mesh.bbox,
};
return WireView.create_from_setting(wire_setting);
示例8: shuffle_pc
# 需要導入模塊: import pymesh [as 別名]
# 或者: from pymesh import load_mesh [as 別名]
def shuffle_pc(file, output_path):
mesh = pymesh.load_mesh(file)
vertices = copy.deepcopy(mesh.vertices)
permutation = np.random.permutation(len(vertices))
vertices = vertices[permutation]
new_mesh = pymesh.meshio.form_mesh(vertices, mesh.faces)
new_mesh.add_attribute("vertex_nx")
new_mesh.set_attribute("vertex_nx", mesh.get_vertex_attribute("vertex_nx")[permutation])
new_mesh.add_attribute("vertex_ny")
new_mesh.set_attribute("vertex_ny", mesh.get_vertex_attribute("vertex_ny")[permutation])
new_mesh.add_attribute("vertex_nz")
new_mesh.set_attribute("vertex_nz", mesh.get_vertex_attribute("vertex_nz")[permutation])
pymesh.save_mesh(output_path, new_mesh, ascii=True, anonymous=True, use_float=True, *new_mesh.get_attribute_names())
示例9: remesh
# 需要導入模塊: import pymesh [as 別名]
# 或者: from pymesh import load_mesh [as 別名]
def remesh(path1):
"""
This function takes a path to the orginal shapenet model and subsample it nicely
"""
obj1 = pymesh.load_mesh(path1)
obj1, info = pymesh.remove_isolated_vertices(obj1)
print("Removed {} isolated vertices".format(info["num_vertex_removed"]))
obj1, info = pymesh.remove_duplicated_vertices(obj1)
print("Merged {} duplicated vertices".format(info["num_vertex_merged"]))
obj1, _ = pymesh.remove_degenerated_triangles(obj1)
if len(obj1.vertices)<5000:
while len(obj1.vertices)<5000:
obj1 = pymesh.subdivide(obj1)
obj1 = pymesh.form_mesh(obj1.vertices, obj1.faces)
return obj1
示例10: read_pointcloud
# 需要導入模塊: import pymesh [as 別名]
# 或者: from pymesh import load_mesh [as 別名]
def read_pointcloud(model_path, point_num, rotation=0):
"""
Read point cloud from the target path
:param model_path: file path for the point cloud
:param point_num: input point number of the point cloud
:param rotation: randomization with respect to the canonical view in term of azimuth
:return: shape tensor
"""
# read in original point cloud
point_cloud_raw = pymesh.load_mesh(model_path).vertices
# randomly select a fix number of points on the surface
point_subset = np.random.choice(point_cloud_raw.shape[0], point_num, replace=False)
point_cloud = point_cloud_raw[point_subset]
# apply the random rotation on the point cloud
if rotation != 0:
alpha = math.radians(rotation)
rot_matrix = np.array([[np.cos(alpha), -np.sin(alpha), 0.],
[np.sin(alpha), np.cos(alpha), 0.],
[0., 0., 1.]])
point_cloud = np.matmul(point_cloud, rot_matrix.transpose())
point_cloud = torch.from_numpy(point_cloud.transpose()).float()
# normalize the point cloud into [0, 1]
point_cloud = point_cloud - torch.min(point_cloud)
point_cloud = point_cloud / torch.max(point_cloud)
return point_cloud
# ================================================= #
# Datasets used for training
# ================================================= #
示例11: read_ply
# 需要導入模塊: import pymesh [as 別名]
# 或者: from pymesh import load_mesh [as 別名]
def read_ply(filename):
# Read a ply file from disk using pymesh and load the attributes used by MaSIF.
# filename: the input ply file.
# returns data as tuple.
mesh = pymesh.load_mesh(filename)
attributes = mesh.get_attribute_names()
if "vertex_nx" in attributes:
nx = mesh.get_attribute("vertex_nx")
ny = mesh.get_attribute("vertex_ny")
nz = mesh.get_attribute("vertex_nz")
normals = numpy.column_stack((nx, ny, nz))
else:
normals = None
if "vertex_charge" in attributes:
charge = mesh.get_attribute("vertex_charge")
else:
charge = numpy.array([0.0] * len(mesh.vertices))
if "vertex_cb" in attributes:
vertex_cb = mesh.get_attribute("vertex_cb")
else:
vertex_cb = numpy.array([0.0] * len(mesh.vertices))
if "vertex_hbond" in attributes:
vertex_hbond = mesh.get_attribute("vertex_hbond")
else:
vertex_hbond = numpy.array([0.0] * len(mesh.vertices))
if "vertex_hphob" in attributes:
vertex_hphob = mesh.get_attribute("vertex_hphob")
else:
vertex_hphob = numpy.array([0.0] * len(mesh.vertices))
return (
mesh.vertices,
mesh.faces,
normals,
charge,
vertex_cb,
vertex_hbond,
vertex_hphob,
)
示例12: getAnItem
# 需要導入模塊: import pymesh [as 別名]
# 或者: from pymesh import load_mesh [as 別名]
def getAnItem(self, index):
"""
returns:
points : float (N,6) positions and normals
cat : string category
file_path : string
"""
# ----------------------------------------------------------#
points, cat, file_path = self.datas[index]
file_name = os.path.splitext(os.path.basename(file_path))[0]
if points is None or not self.use_preprocessed:
found = glob(os.path.splitext(file_path)[0]+".*")
if len(found) == 0:
# use mesh
mesh_path = os.path.join(self.mesh_dir, self.namecat2numbercat[cat], file_name, "model.obj")
mesh = pymesh.load_mesh(mesh_path)
mesh = pymesh.split_long_edges(mesh, 0.02)[0]
points = mesh.vertices
else:
points = pc_utils.load(found[0])
points = self.normalize(points[:,:3])
points = torch.from_numpy(points).float()
points = points.clone()
# Resample
if self.sample:
choice = np.random.choice(points.size(0), self.npoints, replace=True)
points = points[choice, :]
rot_matrix = pc_utils.uniform_rotation_axis_matrix(axis=1, range_rot=self.data_augmentation_Z_rotation_range)
if self.data_augmentation_Z_rotation:
# Uniform random Rotation of axis Y
points, rot_matrix = pc_utils.uniform_rotation_axis(points, axis=1, normals=self.normal,
range_rot=self.data_augmentation_Z_rotation_range)
if self.anisotropic_scaling:
# Data augmentation : anisotropic scaling
points[:, :3] = pc_utils.anisotropic_scaling(points[:, :3]).contiguous()
points[:, :3] = self.normalize(points[:, :3])
if self.data_augmentation_3D_rotation:
# Uniform random 3D rotation of the sphere.
points, rot_matrix = pc_utils.uniform_rotation_sphere(points, normals=self.normal)
# Remark : if input of data_augmentation is normalized to unit ball and centered, the output rotated is as well.
if self.random_translation:
points = pc_utils.add_random_translation(points, scale=0.03)
# also load mesh during test
if self.phase == "test" and self.mesh_dir is not None:
mesh_path = os.path.join(self.mesh_dir, self.namecat2numbercat[cat], file_name, "model.obj")
V_mesh, F_mesh = read_trimesh(mesh_path)
V_mesh = V_mesh[:,:3]
F_mesh = F_mesh[:,:3]
# V_mesh = (V_mesh - center)/scale
V_mesh = self.normalize(V_mesh)
V_mesh = torch.from_numpy(V_mesh).to(dtype=torch.float)
F_mesh = torch.from_numpy(F_mesh).to(dtype=torch.int64)
return points, V_mesh, F_mesh, cat, file_name
else:
return points, cat, file_name
# ----------------------------------------------------------#