Skip to content

Commit 6ab7170

Browse files
Usable callable object to avoid silly sintax issues for the user (#441)
1 parent 07c893b commit 6ab7170

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

python/kiss_icp/datasets/generic.py

+20-7
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,12 @@ def _get_point_cloud_reader(self):
7575
# This is easy, the old KITTI format
7676
if self.file_extension == "bin":
7777
print("[WARNING] Reading .bin files, the only format supported is the KITTI format")
78-
return lambda file: np.fromfile(file, dtype=np.float32).reshape((-1, 4))[
79-
:, :3
80-
], np.array([])
78+
79+
class ReadKITTI:
80+
def __call__(self, file):
81+
return np.fromfile(file, dtype=np.float32).reshape((-1, 4))[:, :3], np.array([])
82+
83+
return ReadKITTI()
8184

8285
print('Trying to guess how to read your data: `pip install "kiss-icp[all]"` is required')
8386
first_scan_file = self.scan_files[0]
@@ -118,17 +121,27 @@ def __call__(self, file):
118121
import trimesh
119122

120123
trimesh.load(first_scan_file)
121-
return lambda file: np.asarray(trimesh.load(file).vertices), np.array([])
124+
125+
class ReadTriMesh:
126+
def __call__(self, file):
127+
return np.asarray(trimesh.load(file).vertices), np.array([])
128+
129+
return ReadTriMesh()
122130
except:
123131
pass
124132

125133
try:
126134
from pyntcloud import PyntCloud
127135

128136
PyntCloud.from_file(first_scan_file)
129-
return lambda file: PyntCloud.from_file(file).points[
130-
["x", "y", "z"]
131-
].to_numpy(), np.array([])
137+
138+
class ReadPynt:
139+
def __call__(self, file):
140+
return PyntCloud.from_file(file).points[["x", "y", "z"]].to_numpy(), np.array(
141+
[]
142+
)
143+
144+
return ReadPynt()
132145
except:
133146
print("[ERROR], File format not supported")
134147
sys.exit(1)

0 commit comments

Comments
 (0)