map-closures 1.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. map_closures-1.0.1/CMakeLists.txt +37 -0
  2. map_closures-1.0.1/LICENSE +21 -0
  3. map_closures-1.0.1/MANIFEST.in +7 -0
  4. map_closures-1.0.1/PKG-INFO +29 -0
  5. map_closures-1.0.1/README.md +0 -0
  6. map_closures-1.0.1/map_closures/__init__.py +24 -0
  7. map_closures-1.0.1/map_closures/config/__init__.py +24 -0
  8. map_closures-1.0.1/map_closures/config/config.py +68 -0
  9. map_closures-1.0.1/map_closures/datasets/__init__.py +78 -0
  10. map_closures-1.0.1/map_closures/datasets/apollo.py +73 -0
  11. map_closures-1.0.1/map_closures/datasets/generic.py +108 -0
  12. map_closures-1.0.1/map_closures/datasets/helipr.py +111 -0
  13. map_closures-1.0.1/map_closures/datasets/kitti.py +108 -0
  14. map_closures-1.0.1/map_closures/datasets/mcap.py +111 -0
  15. map_closures-1.0.1/map_closures/datasets/mulran.py +102 -0
  16. map_closures-1.0.1/map_closures/datasets/ncd.py +109 -0
  17. map_closures-1.0.1/map_closures/datasets/ouster.py +158 -0
  18. map_closures-1.0.1/map_closures/datasets/rosbag.py +125 -0
  19. map_closures-1.0.1/map_closures/map_closures.py +45 -0
  20. map_closures-1.0.1/map_closures/pipeline.py +282 -0
  21. map_closures-1.0.1/map_closures/tools/__init__.py +22 -0
  22. map_closures-1.0.1/map_closures/tools/cmd.py +210 -0
  23. map_closures-1.0.1/map_closures/tools/evaluation.py +199 -0
  24. map_closures-1.0.1/map_closures/tools/gt_closures.py +167 -0
  25. map_closures-1.0.1/map_closures/visualizer/closures_visualizer.py +227 -0
  26. map_closures-1.0.1/map_closures/visualizer/local_maps_visualizer.py +124 -0
  27. map_closures-1.0.1/map_closures/visualizer/registration_visualizer.py +150 -0
  28. map_closures-1.0.1/map_closures/visualizer/visualizer.py +310 -0
  29. map_closures-1.0.1/pyproject.toml +69 -0
@@ -0,0 +1,37 @@
1
+ # MIT License
2
+ #
3
+ # Copyright (c) 2022 Ignacio Vizzo, Tiziano Guadagnino, Benedikt Mersch, Cyrill
4
+ # Stachniss.
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+ cmake_minimum_required(VERSION 3.16...3.26)
24
+ project(map_closure_pybind VERSION 1.0.1 LANGUAGES CXX)
25
+
26
+ # Set build type
27
+ set(CMAKE_BUILD_TYPE Release)
28
+ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
29
+ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
30
+
31
+ set(PYBIND11_NEWPYTHON ON)
32
+ find_package(Python COMPONENTS Interpreter Development.Module REQUIRED)
33
+ find_package(pybind11 CONFIG REQUIRED)
34
+
35
+ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../cpp/ ${CMAKE_CURRENT_BINARY_DIR}/map_closures)
36
+
37
+ add_subdirectory(map_closures/pybind)
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Saurabh Gupta, Tiziano Guadagnino, Benedikt Mersch, Ignacio Vizzo, Cyrill Stachniss
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,7 @@
1
+ recursive-include map_closures *.py
2
+ recursive-include map_closures *.cpp
3
+ recursive-include map_closures *.hpp
4
+ recursive-include map_closures *.h
5
+ global-include CMakeLists.txt
6
+ global-include LICENSE
7
+ global-include *.cmake
@@ -0,0 +1,29 @@
1
+ Metadata-Version: 2.1
2
+ Name: map_closures
3
+ Version: 1.0.1
4
+ Summary: Effectively Detecting Loop Closures using Point Cloud Density Maps
5
+ Keywords: Loop Closures,Localization,SLAM,LiDAR
6
+ Author: Saurabh Gupta, Tiziano Guadagnino
7
+ Project-URL: Homepage, https://github.com/PRBonn/MapClosures
8
+ Requires-Python: >=3.8
9
+ Requires-Dist: kiss-icp>=1.0.0
10
+ Requires-Dist: numpy<2.0.0
11
+ Requires-Dist: pyquaternion
12
+ Requires-Dist: pydantic>=2
13
+ Requires-Dist: pydantic-settings
14
+ Requires-Dist: tqdm
15
+ Requires-Dist: typer[all]>=0.6.0
16
+ Requires-Dist: rich
17
+ Requires-Dist: typing_extensions
18
+ Requires-Dist: open3d>0.13; extra == "all"
19
+ Requires-Dist: PyYAML; extra == "all"
20
+ Requires-Dist: mcap-ros2-support; extra == "all"
21
+ Requires-Dist: rosbags; extra == "all"
22
+ Requires-Dist: trimesh; extra == "all"
23
+ Requires-Dist: ouster-sdk; extra == "all"
24
+ Requires-Dist: pyntcloud; extra == "all"
25
+ Requires-Dist: polyscope; extra == "visualizer"
26
+ Requires-Dist: matplotlib>3.9.2; extra == "visualizer"
27
+ Provides-Extra: all
28
+ Provides-Extra: visualizer
29
+ Description-Content-Type: text/markdown
File without changes
@@ -0,0 +1,24 @@
1
+ # MIT License
2
+ #
3
+ # Copyright (c) 2024 Saurabh Gupta, Tiziano Guadagnino, Benedikt Mersch,
4
+ # Ignacio Vizzo, Cyrill Stachniss.
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+
24
+ __version__ = "1.0.1"
@@ -0,0 +1,24 @@
1
+ # MIT License
2
+ #
3
+ # Copyright (c) 2023 Saurabh Gupta, Ignacio Vizzo, Tiziano Guadagnino, Benedikt Mersch,
4
+ # Cyrill Stachniss.
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+
24
+ from .config import MapClosuresConfig, load_config, write_config
@@ -0,0 +1,68 @@
1
+ # MIT License
2
+ #
3
+ # Copyright (c) 2023 Saurabh Gupta, Ignacio Vizzo, Tiziano Guadagnino, Benedikt Mersch,
4
+ # Cyrill Stachniss.
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+ from __future__ import annotations
24
+
25
+ import importlib
26
+ import sys
27
+ from pathlib import Path
28
+ from typing import Optional
29
+
30
+ from pydantic import BaseModel
31
+
32
+
33
+ class MapClosuresConfig(BaseModel):
34
+ density_map_resolution: float = 0.5
35
+ density_threshold: float = 0.05
36
+ hamming_distance_threshold: int = 50
37
+ inliers_threshold: int = 10
38
+ local_map_factor: float = 1.0
39
+
40
+
41
+ def load_config(config_file: Optional[Path]) -> MapClosuresConfig:
42
+ """Load configuration from an Optional yaml file. Additionally, deskew and max_range can be
43
+ also specified from the CLI interface"""
44
+
45
+ config = None
46
+ if config_file is not None:
47
+ try:
48
+ yaml = importlib.import_module("yaml")
49
+ except ModuleNotFoundError:
50
+ print(
51
+ "[ERROR] Custom configuration file specified but PyYAML is not installed on your system,"
52
+ " run `pip install pyyaml`"
53
+ )
54
+ sys.exit(1)
55
+ with open(config_file) as cfg_file:
56
+ config = yaml.safe_load(cfg_file)
57
+ return MapClosuresConfig(**config)
58
+ else:
59
+ return MapClosuresConfig()
60
+
61
+
62
+ def write_config(config: MapClosuresConfig, filename: str):
63
+ with open(filename, "w") as outfile:
64
+ try:
65
+ yaml = importlib.import_module("yaml")
66
+ yaml.dump(config.model_dump(), outfile, default_flow_style=False)
67
+ except ModuleNotFoundError:
68
+ outfile.write(str(config.model_dump()))
@@ -0,0 +1,78 @@
1
+ # MIT License
2
+ #
3
+ # Copyright (c) 2022 Ignacio Vizzo, Tiziano Guadagnino, Benedikt Mersch, Cyrill
4
+ # Stachniss.
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+ from pathlib import Path
24
+ from typing import Dict, List
25
+
26
+
27
+ def supported_file_extensions():
28
+ return [
29
+ "bin",
30
+ "pcd",
31
+ "ply",
32
+ "xyz",
33
+ "obj",
34
+ "ctm",
35
+ "off",
36
+ "stl",
37
+ ]
38
+
39
+
40
+ def sequence_dataloaders():
41
+ return ["kitti", "helipr"]
42
+
43
+
44
+ def eval_dataloaders():
45
+ return ["kitti", "helipr", "mulran", "ncd", "apollo"]
46
+
47
+
48
+ def available_dataloaders() -> List:
49
+ import os.path
50
+ import pkgutil
51
+
52
+ pkgpath = os.path.dirname(__file__)
53
+ return [name for _, name, _ in pkgutil.iter_modules([pkgpath])]
54
+
55
+
56
+ def dataloader_types() -> Dict:
57
+ import ast
58
+ import importlib
59
+
60
+ dataloaders = available_dataloaders()
61
+ _types = {}
62
+ for dataloader in dataloaders:
63
+ script = importlib.util.find_spec(f".{dataloader}", __name__).origin
64
+ with open(script) as f:
65
+ tree = ast.parse(f.read(), script)
66
+ classes = [cls for cls in tree.body if isinstance(cls, ast.ClassDef)]
67
+ _types[dataloader] = classes[0].name # assuming there is only 1 class
68
+ return _types
69
+
70
+
71
+ def dataset_factory(dataloader: str, data_dir: Path, *args, **kwargs):
72
+ import importlib
73
+
74
+ dataloader_type = dataloader_types()[dataloader]
75
+ module = importlib.import_module(f".{dataloader}", __name__)
76
+ assert hasattr(module, dataloader_type), f"{dataloader_type} is not defined in {module}"
77
+ dataset = getattr(module, dataloader_type)
78
+ return dataset(data_dir=data_dir, *args, **kwargs)
@@ -0,0 +1,73 @@
1
+ # MIT License
2
+ #
3
+ # Copyright (c) 2022 Ignacio Vizzo, Tiziano Guadagnino, Benedikt Mersch, Cyrill
4
+ # Stachniss.
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+ import glob
24
+ import importlib
25
+ import os
26
+ import sys
27
+ from pathlib import Path
28
+
29
+ import natsort
30
+ import numpy as np
31
+
32
+
33
+ class ApolloDataset:
34
+ def __init__(self, data_dir: Path, *_, **__):
35
+ try:
36
+ self.o3d = importlib.import_module("open3d")
37
+ except ModuleNotFoundError:
38
+ print(
39
+ '[ERROR] This dataloader requires open3d but is not installed on your system run "pip install open3d"'
40
+ )
41
+ sys.exit(1)
42
+
43
+ self.scan_files = natsort.natsorted(glob.glob(f"{data_dir}/pcds/*.pcd"))
44
+ self.gt_poses = self.read_poses(f"{data_dir}/poses/gt_poses.txt")
45
+ self.sequence_id = os.path.basename(data_dir)
46
+ self.sequence_dir = os.path.realpath(data_dir)
47
+
48
+ def __len__(self):
49
+ return len(self.scan_files)
50
+
51
+ def __getitem__(self, idx):
52
+ return self.get_scan(self.scan_files[idx])
53
+
54
+ def get_scan(self, scan_file: str):
55
+ points = np.asarray(self.o3d.io.read_point_cloud(scan_file).points, dtype=np.float64)
56
+ return points.astype(np.float64)
57
+
58
+ @staticmethod
59
+ def read_poses(file):
60
+ from pyquaternion import Quaternion
61
+
62
+ data = np.loadtxt(file)
63
+ _, _, translations, qxyzw = np.split(data, [1, 2, 5], axis=1)
64
+ rotations = np.array(
65
+ [Quaternion(x=x, y=y, z=z, w=w).rotation_matrix for x, y, z, w in qxyzw]
66
+ )
67
+ poses = np.zeros([rotations.shape[0], 4, 4])
68
+ poses[:, :3, -1] = translations
69
+ poses[:, :3, :3] = rotations
70
+ poses[:, -1, -1] = 1
71
+ # Convert from global coordinate poses to local poses
72
+ first_pose = poses[0, :, :]
73
+ return np.linalg.inv(first_pose) @ poses
@@ -0,0 +1,108 @@
1
+ # MIT License
2
+ #
3
+ # Copyright (c) 2022 Ignacio Vizzo, Tiziano Guadagnino, Benedikt Mersch, Cyrill
4
+ # Stachniss.
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+ import os
24
+ import sys
25
+ from pathlib import Path
26
+
27
+ import natsort
28
+ import numpy as np
29
+
30
+ from map_closures.datasets import supported_file_extensions
31
+
32
+
33
+ class GenericDataset:
34
+ def __init__(self, data_dir: Path, *_, **__):
35
+ # Config stuff
36
+ self.sequence_id = os.path.basename(data_dir)
37
+ self.scans_dir = os.path.join(os.path.realpath(data_dir), "")
38
+ self.scan_files = np.array(
39
+ natsort.natsorted(
40
+ [
41
+ os.path.join(self.scans_dir, fn)
42
+ for fn in os.listdir(self.scans_dir)
43
+ if any(fn.endswith(ext) for ext in supported_file_extensions())
44
+ ]
45
+ ),
46
+ dtype=str,
47
+ )
48
+ if len(self.scan_files) == 0:
49
+ raise ValueError(f"Tried to read point cloud files in {self.scans_dir} but none found")
50
+ self.file_extension = self.scan_files[0].split(".")[-1]
51
+ if self.file_extension not in supported_file_extensions():
52
+ raise ValueError(f"Supported formats are: {supported_file_extensions()}")
53
+
54
+ # Obtain the pointcloud reader for the given data folder
55
+ self._read_point_cloud = self._get_point_cloud_reader()
56
+
57
+ def __len__(self):
58
+ return len(self.scan_files)
59
+
60
+ def __getitem__(self, idx):
61
+ return self.read_point_cloud(self.scan_files[idx])
62
+
63
+ def read_point_cloud(self, file_path: str):
64
+ points = self._read_point_cloud(file_path)
65
+ return points.astype(np.float64)
66
+
67
+ def _get_point_cloud_reader(self):
68
+ """Attempt to guess with try/catch blocks which is the best point cloud reader to use for
69
+ the given dataset folder. Supported readers so far are:
70
+ - np.fromfile
71
+ - trimesh.load
72
+ - PyntCloud
73
+ - open3d[optional]
74
+ """
75
+ # This is easy, the old KITTI format
76
+ if self.file_extension == "bin":
77
+ 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))[:, :3]
79
+
80
+ first_scan_file = self.scan_files[0]
81
+
82
+ # first try trimesh
83
+ try:
84
+ import trimesh
85
+
86
+ trimesh.load(first_scan_file)
87
+ return lambda file: np.asarray(trimesh.load(file).vertices)
88
+ except:
89
+ pass
90
+
91
+ # then try pyntcloud
92
+ try:
93
+ from pyntcloud import PyntCloud
94
+
95
+ PyntCloud.from_file(first_scan_file)
96
+ return lambda file: PyntCloud.from_file(file).points[["x", "y", "z"]].to_numpy()
97
+ except:
98
+ pass
99
+
100
+ # lastly with open3d
101
+ try:
102
+ import open3d as o3d
103
+
104
+ o3d.io.read_point_cloud(first_scan_file)
105
+ return lambda file: np.asarray(o3d.io.read_point_cloud(file).points, dtype=np.float64)
106
+ except:
107
+ print("[ERROR], File format not supported")
108
+ sys.exit(1)
@@ -0,0 +1,111 @@
1
+ # MIT License
2
+ #
3
+ # Copyright (c) 2024 Saurabh Gupta, Ignacio Vizzo, Tiziano Guadagnino,
4
+ # Benedikt Mersch, Cyrill Stachniss.
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+ import glob
24
+ import os
25
+ import struct
26
+ import sys
27
+ from pathlib import Path
28
+
29
+ import numpy as np
30
+
31
+
32
+ class HeLiPRDataset:
33
+ def __init__(self, data_dir: Path, sequence: str, *_, **__):
34
+ self.sequence_id = sequence
35
+ self.sequence_dir = os.path.realpath(data_dir)
36
+ self.scans_dir = os.path.join(self.sequence_dir, "LiDAR", self.sequence_id)
37
+ self.scan_files = sorted(glob.glob(self.scans_dir + "/*.bin"))
38
+
39
+ self.gt_file = os.path.join(
40
+ self.sequence_dir, "LiDAR_GT", f"global_{self.sequence_id}_gt.txt"
41
+ )
42
+ self.gt_poses = self.load_poses(self.gt_file)
43
+
44
+ if len(self.scan_files) == 0:
45
+ raise ValueError(f"Tried to read point cloud files in {data_dir} but none found")
46
+
47
+ # Obtain the pointcloud reader for the given data folder
48
+ if self.sequence_id == "Avia":
49
+ self.format_string = "fffBBBL"
50
+ self.intensity_channel = None
51
+ elif self.sequence_id == "Aeva":
52
+ self.format_string = "ffffflBf"
53
+ self.format_string_no_intensity = "ffffflB"
54
+ self.intensity_channel = 7
55
+ elif self.sequence_id == "Ouster":
56
+ self.format_string = "ffffIHHH"
57
+ self.intensity_channel = 3
58
+ elif self.sequence_id == "Velodyne":
59
+ self.format_string = "ffffHf"
60
+ self.intensity_channel = 3
61
+ else:
62
+ print("[ERROR] Unsupported LiDAR Type")
63
+ sys.exit(1)
64
+
65
+ def __len__(self):
66
+ return len(self.scan_files)
67
+
68
+ def __getitem__(self, idx):
69
+ return self.read_point_cloud(idx)
70
+
71
+ def get_data(self, idx: int):
72
+ file_path = self.scan_files[idx]
73
+ list_lines = []
74
+
75
+ # Special case, see https://github.com/minwoo0611/HeLiPR-File-Player/blob/e8d95e390454ece1415ae9deb51515f63730c10a/src/ROSThread.cpp#L632
76
+ if self.sequence_id == "Aeva" and int(Path(file_path).stem) <= 1691936557946849179:
77
+ self.intensity_channel = None
78
+ format_string = self.format_string_no_intensity
79
+ else:
80
+ format_string = self.format_string
81
+
82
+ chunk_size = struct.calcsize(f"={format_string}")
83
+ with open(file_path, "rb") as f:
84
+ binary = f.read()
85
+ offset = 0
86
+ while offset < len(binary):
87
+ list_lines.append(struct.unpack_from(f"={format_string}", binary, offset))
88
+ offset += chunk_size
89
+ data = np.stack(list_lines)
90
+ return data
91
+
92
+ def read_point_cloud(self, idx: int):
93
+ data = self.get_data(idx)
94
+ points = data[:, :3]
95
+ return points.astype(np.float64)
96
+
97
+ def load_poses(self, poses_file):
98
+ from pyquaternion import Quaternion
99
+
100
+ poses = np.loadtxt(poses_file, delimiter=" ")
101
+ n = poses.shape[0]
102
+
103
+ xyz = poses[:, 1:4]
104
+ rotations = np.array(
105
+ [Quaternion(x=x, y=y, z=z, w=w).rotation_matrix for x, y, z, w in poses[:, 4:]]
106
+ )
107
+ poses = np.eye(4, dtype=np.float64).reshape(1, 4, 4).repeat(self.__len__(), axis=0)
108
+ poses[:, :3, :3] = rotations
109
+ poses[:, :3, 3] = xyz
110
+
111
+ return poses