Skip to content

Commit

Permalink
Feature/e57 (#21)
Browse files Browse the repository at this point in the history
* feature: read e57 files

* feature: read e57 files

* style: fix linting failures

---------

Co-authored-by: Graham Knapp <[email protected]>
  • Loading branch information
dancergraham and GrahamKnappAcernis authored Sep 22, 2024
1 parent 110cc75 commit 622591e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/lidar_visualizer/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def supported_file_extensions():
"ctm",
"off",
"stl",
"e57",
]


Expand Down
55 changes: 50 additions & 5 deletions src/lidar_visualizer/datasets/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ def __getitem__(self, idx):
def _get_point_cloud_reader(self):
"""Attempt to guess with try/catch blocks which is the best point cloud reader to use for
the given dataset folder. Supported readers so far are:
File readers are functions which take a filename as an input and return a tuple of points and colors.
- np.fromfile
- pye57
- open3d
- trimesh.load
- PyntCloud
Expand All @@ -102,7 +105,49 @@ def read_kitti_scan(file):
tried_libraries = []
missing_libraries = []

# 2. Try with Open3D
# 2 Try with pye57
if self.file_extension == "e57":
try:
import pye57

def read_e57_scan(file):
e57 = pye57.E57(file)
point_data = None
color_data = None
# One e57 file can contain multiple scans, scanned from different positions
for i in range(e57.scan_count):
i = e57.read_scan(i, colors=True, ignore_missing_fields=True)
scan_data = np.stack(
[i["cartesianX"], i["cartesianY"], i["cartesianZ"]], axis=1
)
point_data = (
np.concat([point_data, scan_data])
if point_data is not None
else scan_data
)
try:
scan_color_data = np.stack(
[i["colorRed"], i["colorGreen"], i["colorBlue"]], axis=1
)
color_data = (
np.concat([color_data, scan_color_data])
if color_data is not None
else scan_color_data
)
except KeyError:
pass
# e57 file colors are in 0-255 range
color_data = color_data / 255.0 if color_data is not None else None
return point_data, color_data

return read_e57_scan
except ModuleNotFoundError:
missing_libraries.append("pye57")
print("[WARNING] pye57 not installed")
except:
tried_libraries.append("pye57")

# 3. Try with Open3D
try:
self.o3d.t.io.read_point_cloud(first_scan_file)

Expand All @@ -129,7 +174,7 @@ def read_scan_with_intensities(file):
except:
tried_libraries.append("open3d")

# 3. Try with trimesh
# 4. Try with trimesh
try:
import trimesh

Expand All @@ -140,7 +185,7 @@ def read_scan_with_intensities(file):
except:
tried_libraries.append("trimesh")

# 4. Try with PyntCloud
# 5. Try with PyntCloud
try:
from pyntcloud import PyntCloud

Expand All @@ -151,10 +196,10 @@ def read_scan_with_intensities(file):
except:
tried_libraries.append("pyntcloud")

# If reach this point means that none of the librares exist/could read the file
# If reach this point means that none of the libraries exist/could read the file
if not tried_libraries:
print(
"No 3D library is insallted in your system. Install one of the following "
"No 3D library is installed in your system. Install one of the following "
"to read the pointclouds"
)
print("\n".join(missing_libraries))
Expand Down

0 comments on commit 622591e

Please sign in to comment.