本文整理匯總了Python中pymesh.form_mesh方法的典型用法代碼示例。如果您正苦於以下問題:Python pymesh.form_mesh方法的具體用法?Python pymesh.form_mesh怎麽用?Python pymesh.form_mesh使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pymesh
的用法示例。
在下文中一共展示了pymesh.form_mesh方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: generate_mesh
# 需要導入模塊: import pymesh [as 別名]
# 或者: from pymesh import form_mesh [as 別名]
def generate_mesh(self, latent_vector):
assert latent_vector.size(0)==1, "input should have batch size 1!"
import pymesh
input_points = [self.template[i].get_regular_points(self.nb_pts_in_primitive, latent_vector.device)
for i in range(self.opt.nb_primitives)]
input_points = [input_points[i] for i in range(self.opt.nb_primitives)]
# Deform each patch
output_points = [self.decoder[i](input_points[i], latent_vector.unsqueeze(2)).squeeze() for i in
range(0, self.opt.nb_primitives)]
output_meshes = [pymesh.form_mesh(vertices=output_points[i].transpose(1, 0).contiguous().cpu().numpy(),
faces=self.template[i].mesh.faces)
for i in range(self.opt.nb_primitives)]
# Deform return the deformed pointcloud
mesh = pymesh.merge_meshes(output_meshes)
return mesh
示例2: read_trimesh
# 需要導入模塊: import pymesh [as 別名]
# 或者: from pymesh import form_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
示例3: downsample_pointcloud
# 需要導入模塊: import pymesh [as 別名]
# 或者: from pymesh import form_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)
示例4: output_patch_coords
# 需要導入模塊: import pymesh [as 別名]
# 或者: from pymesh import form_mesh [as 別名]
def output_patch_coords(subv, subf, subn, i, neigh_i, theta, rho):
"""
For debugging purposes, save a patch to visualize it.
"""
mesh = pymesh.form_mesh(subv, subf)
n1 = subn[:,0]
n2 = subn[:,1]
n3 = subn[:,2]
mesh.add_attribute('vertex_nx')
mesh.set_attribute('vertex_nx', n1)
mesh.add_attribute('vertex_ny')
mesh.set_attribute('vertex_ny', n2)
mesh.add_attribute('vertex_nz')
mesh.set_attribute('vertex_nz', n3)
rho = np.array([rho[0,ix] for ix in range(rho.shape[1]) if ix in neigh_i])
mesh.add_attribute('rho')
mesh.set_attribute('rho', rho)
theta= np.array([theta[ix] for ix in range((theta.shape[0])) if ix in neigh_i])
mesh.add_attribute('theta')
mesh.set_attribute('theta', theta)
charge = np.zeros(len(neigh_i))
mesh.add_attribute('charge')
mesh.set_attribute('charge', charge)
pymesh.save_mesh('v{}.ply'.format(i), mesh, *mesh.get_attribute_names(), use_float=True, ascii=True)
#@jit
示例5: get_regular_points
# 需要導入模塊: import pymesh [as 別名]
# 或者: from pymesh import form_mesh [as 別名]
def get_regular_points(self, npoints=2500, device="gpu0"):
"""
Get regular points on a Square
Return Tensor of Size [x, 3]
"""
if not self.npoints == npoints:
self.npoints = npoints
vertices, faces = self.generate_square(np.sqrt(npoints))
self.mesh = pymesh.form_mesh(vertices=vertices, faces=faces) # 10k vertices
self.vertex = torch.from_numpy(self.mesh.vertices).to(device).float()
self.num_vertex = self.vertex.size(0)
self.vertex = self.vertex.transpose(0,1).contiguous().unsqueeze(0)
return Variable(self.vertex[:, :2].contiguous().to(device))
示例6: demo
# 需要導入模塊: import pymesh [as 別名]
# 或者: from pymesh import form_mesh [as 別名]
def demo(self, demo_path, input_path_points=None):
"""
This function takes an image or pointcloud path as input and save the mesh infered by Atlasnet
Extension supported are ply npy obg and png
:return: path to the generated mesh
"""
ext = demo_path.split('.')[-1]
self.data = self.datasets.dataset_train.load(demo_path)
self.data = EasyDict(self.data)
if input_path_points is None:
input_path_points = demo_path
#prepare normalization
get_normalization = self.datasets.dataset_train.load(input_path_points)
get_normalization = EasyDict(get_normalization)
self.make_network_input()
mesh = self.network.module.generate_mesh(self.data.network_input)
if get_normalization.operation is not None:
# Undo any normalization that was used to preprocess the input.
vertices = torch.from_numpy(mesh.vertices).clone().unsqueeze(0)
get_normalization.operation.invert()
unnormalized_vertices = get_normalization.operation.apply(vertices)
mesh = pymesh.form_mesh(vertices=unnormalized_vertices.squeeze().numpy(), faces=mesh.faces)
if self.opt.demo:
path = demo_path.split('.')
path[-2] += "AtlasnetReconstruction"
path[-1] = "ply"
path = ".".join(path)
else:
path = '/'.join([self.opt.training_media_path, str(self.flags.media_count)]) + ".ply"
self.flags.media_count += 1
print(f"Atlasnet generated mesh at {path}!")
mesh_processor.save(mesh, path, self.colormap)
return path
示例7: remesh
# 需要導入模塊: import pymesh [as 別名]
# 或者: from pymesh import form_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
示例8: __save_temp_mesh
# 需要導入模塊: import pymesh [as 別名]
# 或者: from pymesh import form_mesh [as 別名]
def __save_temp_mesh(self, active_view):
basename, ext = os.path.splitext(self.image_name);
path, name = os.path.split(basename);
now = datetime.datetime.now()
stamp = now.isoformat();
tmp_dir = tempfile.gettempdir();
ext = ".serialized";
tmp_mesh_name = os.path.join(tmp_dir, "{}_{}{}".format(
name, stamp, ext));
vertices = active_view.vertices;
faces = active_view.faces;
voxels = active_view.voxels;
colors = active_view.vertex_colors.reshape((-1, 4), order="C");
if self.with_texture_coordinates:
uvs = active_view.texture_coordinates;
else:
uvs = None;
dim = vertices.shape[1];
num_faces, vertex_per_face = faces.shape;
if vertex_per_face == 4:
faces = np.vstack([faces[:,[0,1,2]], faces[:,[0,2,3]]]);
vertex_per_face = 3;
num_faces *= 2;
colors = colors.reshape((-1, 4, 4), order="C");
colors = np.vstack([
colors[:,[0,1,2],:].reshape((-1, 4), order="C"),
colors[:,[0,2,3],:].reshape((-1, 4), order="C") ]);
if uvs is not None:
uvs = uvs.reshape((-1, 4, 2), order="C");
uvs = np.vstack([
uvs[:,[0,1,2],:].reshape((-1, 2), order="C"),
uvs[:,[0,2,3],:].reshape((-1, 2), order="C") ]);
vertices = vertices[faces.ravel(order="C")];
assert(len(colors) == len(vertices));
faces = np.arange(len(vertices), dtype=int).reshape(
(num_faces, vertex_per_face), order="C");
mesh = pymesh.form_mesh(vertices, faces);
if active_view.use_smooth_normal:
normals = active_view.vertex_normals;
else:
normals = None;
data = serialize_mesh(mesh, normals, colors, uvs);
with open(tmp_mesh_name, 'wb') as fout:
fout.write(data);
return tmp_mesh_name, ext;
示例9: save_ply
# 需要導入模塊: import pymesh [as 別名]
# 或者: from pymesh import form_mesh [as 別名]
def save_ply(
filename,
vertices,
faces=[],
normals=None,
charges=None,
vertex_cb=None,
hbond=None,
hphob=None,
iface=None,
normalize_charges=False,
):
""" Save vertices, mesh in ply format.
vertices: coordinates of vertices
faces: mesh
"""
mesh = pymesh.form_mesh(vertices, faces)
if normals is not None:
n1 = normals[:, 0]
n2 = normals[:, 1]
n3 = normals[:, 2]
mesh.add_attribute("vertex_nx")
mesh.set_attribute("vertex_nx", n1)
mesh.add_attribute("vertex_ny")
mesh.set_attribute("vertex_ny", n2)
mesh.add_attribute("vertex_nz")
mesh.set_attribute("vertex_nz", n3)
if charges is not None:
mesh.add_attribute("charge")
if normalize_charges:
charges = charges / 10
mesh.set_attribute("charge", charges)
if hbond is not None:
mesh.add_attribute("hbond")
mesh.set_attribute("hbond", hbond)
if vertex_cb is not None:
mesh.add_attribute("vertex_cb")
mesh.set_attribute("vertex_cb", vertex_cb)
if hphob is not None:
mesh.add_attribute("vertex_hphob")
mesh.set_attribute("vertex_hphob", hphob)
if iface is not None:
mesh.add_attribute("vertex_iface")
mesh.set_attribute("vertex_iface", iface)
pymesh.save_mesh(
filename, mesh, *mesh.get_attribute_names(), use_float=True, ascii=True
)