MCPcopy Create free account
hub / github.com/OpenMeshLab/MeshXL / write_lines_as_cylinders

Function write_lines_as_cylinders

utils/pc_util.py:272–294  ·  view source on GitHub ↗

Create lines represented as cylinders connecting pairs of 3D points Args: pcl: (N x 2 x 3 numpy array): N pairs of xyz pos filename: (string) filename for the output mesh (ply) file rad: radius for the cylinder res: number of sections used to create the cylinder

(pcl, filename, rad=0.005, res=64)

Source from the content-addressed store, hash-verified

270
271
272def write_lines_as_cylinders(pcl, filename, rad=0.005, res=64):
273 """Create lines represented as cylinders connecting pairs of 3D points
274 Args:
275 pcl: (N x 2 x 3 numpy array): N pairs of xyz pos
276 filename: (string) filename for the output mesh (ply) file
277 rad: radius for the cylinder
278 res: number of sections used to create the cylinder
279 """
280 scene = trimesh.scene.Scene()
281 for src, tgt in pcl:
282 # compute line
283 vec = tgt - src
284 M = trimesh.geometry.align_vectors([0, 0, 1], vec, False)
285 vec = tgt - src # compute again since align_vectors modifies vec in-place!
286 M[:3, 3] = 0.5 * src + 0.5 * tgt
287 height = np.sqrt(np.dot(vec, vec))
288 scene.add_geometry(
289 trimesh.creation.cylinder(
290 radius=rad, height=height, sections=res, transform=M
291 )
292 )
293 mesh_list = trimesh.util.concatenate(scene.dump())
294 trimesh.io.export.export_mesh(mesh_list, "%s.ply" % (filename), file_type="ply")

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected