Skip to content

Commit 2a482ff

Browse files
authored
Merge pull request #110 from riccardodelutio/rdelutio/color-types-casting
Fix color types casting
2 parents 47b99b6 + c56df80 commit 2a482ff

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

point_cloud_utils/_mesh_io.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,23 +288,33 @@ def save(self, filename, dtype=np.float32):
288288
if wcolors.max() > 1.0 or wcolors.min() < 0.0:
289289
raise ValueError("Invalid values for wedge colors, must be between 0 and 1 (inclusive)")
290290

291+
# Meshlab expects colors to be uint8 for PLY files
292+
if filename.endswith(".ply"):
293+
vcolors = (vcolors * 255.0).astype(np.uint8)
294+
fcolors = (fcolors * 255.0).astype(np.uint8)
295+
wcolors = (wcolors * 255.0).astype(np.uint8)
296+
else:
297+
vcolors = vcolors.astype(dtype)
298+
fcolors = fcolors.astype(dtype)
299+
wcolors = wcolors.astype(dtype)
300+
291301
save_mesh_internal(filename,
292302
np.ascontiguousarray(self.vertex_data.positions.astype(dtype)),
293303
np.ascontiguousarray(self.vertex_data.normals.astype(dtype)),
294304
np.ascontiguousarray(self.vertex_data.texcoords.astype(dtype)),
295-
np.ascontiguousarray((vcolors * 255.0).astype(np.uint8)),
305+
np.ascontiguousarray(vcolors),
296306
np.ascontiguousarray(self.vertex_data.quality.astype(dtype)),
297307
np.ascontiguousarray(self.vertex_data.radius.astype(dtype)),
298308
np.ascontiguousarray(self.vertex_data.tex_ids.astype(np.int32)),
299309
np.ascontiguousarray(self.vertex_data.flags.astype(np.int32)),
300310

301311
np.ascontiguousarray(self.face_data.vertex_ids.astype(np.int32)),
302312
np.ascontiguousarray(self.face_data.normals.astype(dtype)),
303-
np.ascontiguousarray((fcolors * 255.0).astype(np.uint8)),
313+
np.ascontiguousarray(fcolors),
304314
np.ascontiguousarray(self.face_data.quality.astype(dtype)),
305315
np.ascontiguousarray(self.face_data.flags.astype(np.int32)),
306316

307-
np.ascontiguousarray((wcolors * 255.0).astype(np.uint8)),
317+
np.ascontiguousarray(wcolors),
308318
np.ascontiguousarray(self.face_data.wedge_normals.astype(dtype)),
309319
np.ascontiguousarray(self.face_data.wedge_texcoords.astype(dtype)),
310320
np.ascontiguousarray(self.face_data.wedge_tex_ids.astype(np.int32)),

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def main():
9191

9292
setuptools.setup(
9393
name="point-cloud-utils",
94-
version="0.34.0",
94+
version="0.35.0",
9595
author="Francis Williams",
9696
author_email="[email protected]",
9797
description="A Python library for common tasks on 3D point clouds and meshes",

0 commit comments

Comments
 (0)