Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_assign_elements(tet_ply_txt):
test = PlyElement.describe(numpy.zeros(1, dtype=[('a', 'i4')]),
'test')
tet_ply_txt.elements = [test]
assert len(tet_ply_txt.elements) == 1
assert len(tet_ply_txt) == 1
assert 'vertex' not in tet_ply_txt
assert 'face' not in tet_ply_txt
assert 'test' in tet_ply_txt
for (k, elt) in enumerate(tet_ply_txt):
assert elt.name == 'test'
assert k == 0
'''
import voxel_globe.tools
with voxel_globe.tools.storage_dir('event_trigger_ply') as ply_dir:
num_files = len([name for name in os.listdir(ply_dir)])
filepath = os.path.join(ply_dir, 'mesh_%d.ply' % num_files)
import numpy
import plyfile
from plyfile import PlyData, PlyElement
vertex = numpy.array(points,
dtype=[('x', 'double'), ('y', 'double'),
('z', 'double')])
face = numpy.array([(range(len(points)),)], [('vertex_indices', '|O')])
el1 = PlyElement.describe(vertex, 'vertex')
el2 = PlyElement.describe(face, 'face')
PlyData([el1, el2], text=True, comments=['mesh-feature'],
obj_info=['a bmsh3d_mesh object']).write(filepath)
return filepath
desc = desc + vertex_color.dtype.descr
vertex_all = np.empty(n, dtype=desc)
for prop in vertex.dtype.names:
vertex_all[prop] = vertex[prop]
if normals is not None:
for prop in vertex_normal.dtype.names:
vertex_all[prop] = vertex_normal[prop]
if colors is not None:
for prop in vertex_color.dtype.names:
vertex_all[prop] = vertex_color[prop]
ply = plyfile.PlyData([plyfile.PlyElement.describe(vertex_all, 'vertex')], text=False)
if not os.path.exists(os.path.dirname(filename)):
os.makedirs(os.path.dirname(filename))
ply.write(filename)
(-pointr1[2]*2/3, pointr1[0]*2/3, -pointr1[1]*2/3),
(-pointo1[2]*2/3, pointo1[0]*2/3, -pointo1[1]*2/3),
(((-pointt1[2]*2/3)+(-pointr1[2]*2/3)+(-pointo1[2]*2/3))/3 - 0.001,((pointt1[0]*2/3)+(pointr1[0]*2/3)+(pointo1[0]*2/3))/3,((-pointt1[1]*2/3)+(-pointr1[1]*2/3)+(-pointo1[1]*2/3))/3)],
dtype=[('x', 'f4'), ('y', 'f4'), ('z', 'f4')])
face6 = np.array([([0, 1, 2], 0, 0, 0),#black face
([0, 2, 3], 0, 255, 255),
([0, 1, 3], 255, 0, 0),
([1, 2, 3], 255, 140, 0)],
dtype=[('vertex_indices', 'i4', (3,)),
('red', 'u1'), ('green', 'u1'),
('blue', 'u1')])
# Saves Point Cloud files under the given names (I have been changing it every time I want to make a new set of Point Clouds, otherwise it overwrites the previous file with the same name)
PlyData([PlyElement.describe(vertex1, 'vertex'),PlyElement.describe(face1, 'face')]).write(bone1FileName)
PlyData([PlyElement.describe(vertex2, 'vertex'),PlyElement.describe(face2, 'face')]).write(bone2FileName)
PlyData([PlyElement.describe(vertex3, 'vertex'),PlyElement.describe(face3, 'face')]).write(bone3FileName)
PlyData([PlyElement.describe(vertex4, 'vertex'),PlyElement.describe(face4, 'face')]).write(bone4FileName)
PlyData([PlyElement.describe(vertex5, 'vertex'),PlyElement.describe(face5, 'face')]).write(bone5FileName)
PlyData([PlyElement.describe(vertex6, 'vertex'),PlyElement.describe(face6, 'face')]).write(bone6FileName)
vertex6 = np.array([(-pointt1[2]*2/3, pointt1[0]*2/3, -pointt1[1]*2/3),
(-pointr1[2]*2/3, pointr1[0]*2/3, -pointr1[1]*2/3),
(-pointo1[2]*2/3, pointo1[0]*2/3, -pointo1[1]*2/3),
(((-pointt1[2]*2/3)+(-pointr1[2]*2/3)+(-pointo1[2]*2/3))/3 - 0.001,((pointt1[0]*2/3)+(pointr1[0]*2/3)+(pointo1[0]*2/3))/3,((-pointt1[1]*2/3)+(-pointr1[1]*2/3)+(-pointo1[1]*2/3))/3)],
dtype=[('x', 'f4'), ('y', 'f4'), ('z', 'f4')])
face6 = np.array([([0, 1, 2], 0, 0, 0),#black face
([0, 2, 3], 0, 255, 255),
([0, 1, 3], 255, 0, 0),
([1, 2, 3], 255, 140, 0)],
dtype=[('vertex_indices', 'i4', (3,)),
('red', 'u1'), ('green', 'u1'),
('blue', 'u1')])
# Saves Point Cloud files under the given names (I have been changing it every time I want to make a new set of Point Clouds, otherwise it overwrites the previous file with the same name)
PlyData([PlyElement.describe(vertex1, 'vertex'),PlyElement.describe(face1, 'face')]).write(bone1FileName)
PlyData([PlyElement.describe(vertex2, 'vertex'),PlyElement.describe(face2, 'face')]).write(bone2FileName)
PlyData([PlyElement.describe(vertex3, 'vertex'),PlyElement.describe(face3, 'face')]).write(bone3FileName)
PlyData([PlyElement.describe(vertex4, 'vertex'),PlyElement.describe(face4, 'face')]).write(bone4FileName)
PlyData([PlyElement.describe(vertex5, 'vertex'),PlyElement.describe(face5, 'face')]).write(bone5FileName)
PlyData([PlyElement.describe(vertex6, 'vertex'),PlyElement.describe(face6, 'face')]).write(bone6FileName)
vertex6 = np.array([(-pointt1[2]*2/3, pointt1[0]*2/3, -pointt1[1]*2/3),
(-pointr1[2]*2/3, pointr1[0]*2/3, -pointr1[1]*2/3),
(-pointo1[2]*2/3, pointo1[0]*2/3, -pointo1[1]*2/3),
(((-pointt1[2]*2/3)+(-pointr1[2]*2/3)+(-pointo1[2]*2/3))/3 - 0.001,((pointt1[0]*2/3)+(pointr1[0]*2/3)+(pointo1[0]*2/3))/3,((-pointt1[1]*2/3)+(-pointr1[1]*2/3)+(-pointo1[1]*2/3))/3)],
dtype=[('x', 'f4'), ('y', 'f4'), ('z', 'f4')])
face6 = np.array([([0, 1, 2], 0, 0, 0),#black face
([0, 2, 3], 0, 255, 255),
([0, 1, 3], 255, 0, 0),
([1, 2, 3], 255, 140, 0)],
dtype=[('vertex_indices', 'i4', (3,)),
('red', 'u1'), ('green', 'u1'),
('blue', 'u1')])
# Saves Point Cloud files under the given names (I have been changing it every time I want to make a new set of Point Clouds, otherwise it overwrites the previous file with the same name)
PlyData([PlyElement.describe(vertex1, 'vertex'),PlyElement.describe(face1, 'face')]).write(bone1FileName)
PlyData([PlyElement.describe(vertex2, 'vertex'),PlyElement.describe(face2, 'face')]).write(bone2FileName)
PlyData([PlyElement.describe(vertex3, 'vertex'),PlyElement.describe(face3, 'face')]).write(bone3FileName)
PlyData([PlyElement.describe(vertex4, 'vertex'),PlyElement.describe(face4, 'face')]).write(bone4FileName)
PlyData([PlyElement.describe(vertex5, 'vertex'),PlyElement.describe(face5, 'face')]).write(bone5FileName)
PlyData([PlyElement.describe(vertex6, 'vertex'),PlyElement.describe(face6, 'face')]).write(bone6FileName)
def write_ply(filename, xyz, rgb):
"""write into a ply file"""
prop = [('x', 'f4'), ('y', 'f4'), ('z', 'f4'), ('red', 'u1'), ('green', 'u1'), ('blue', 'u1')]
vertex_all = np.empty(len(xyz), dtype=prop)
for i_prop in range(0, 3):
vertex_all[prop[i_prop][0]] = xyz[:, i_prop]
for i_prop in range(0, 3):
vertex_all[prop[i_prop+3][0]] = rgb[:, i_prop]
ply = PlyData([PlyElement.describe(vertex_all, 'vertex')], text=True)
ply.write(filename)
#------------------------------------------------------------------------------
else:
if points_3d.shape[1] == 3:
gray_concat = np.tile(np.array([128], dtype=np.uint8), (points_3d.shape[0], 3))
points_3d = np.hstack((points_3d, gray_concat))
assert points_3d.shape[1] == 6
python_types = (float, float, float, int, int, int)
npy_types = [('x', 'f4'), ('y', 'f4'), ('z', 'f4'), ('red', 'u1'), ('green', 'u1'),
('blue', 'u1')]
if binary is True:
# Format into NumPy structured array
vertices = []
for row_idx in range(points_3d.shape[0]):
cur_point = points_3d[row_idx]
vertices.append(tuple(dtype(point) for dtype, point in zip(python_types, cur_point)))
vertices_array = np.array(vertices, dtype=npy_types)
el = PlyElement.describe(vertices_array, 'vertex')
# Write
PlyData([el]).write(filename)
else:
# PlyData([el], text=True).write(filename)
with open(filename, 'w') as f:
f.write('ply\n'
'format ascii 1.0\n'
'element vertex %d\n'
'property float x\n'
'property float y\n'
'property float z\n'
'property uchar red\n'
'property uchar green\n'
'property uchar blue\n'
'property uchar alpha\n'