-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from ch-sa/ch-sa/pcd-loader
Add point cloud handlers
- Loading branch information
Showing
25 changed files
with
401 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.7.4" | ||
__version__ = "0.7.5" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from .base import ( | ||
BaseLabelFormat, | ||
abs2rel_rotation, | ||
rel2abs_rotation, | ||
) | ||
from .centroid import CentroidFormat | ||
from .kitti import KittiFormat | ||
from .vertices import VerticesFormat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
|
||
import numpy as np | ||
|
||
from ..model import BBox | ||
from ...model import BBox | ||
|
||
|
||
class BaseLabelFormat(ABC): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .base import BasePointCloudHandler | ||
from .numpy import NumpyHandler | ||
from .open3d import Open3DHandler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import logging | ||
from abc import abstractmethod | ||
from pathlib import Path | ||
from typing import TYPE_CHECKING, Optional, Set, Tuple | ||
|
||
import numpy as np | ||
|
||
from ...utils.logger import blue | ||
from ...utils.singleton import SingletonABCMeta | ||
|
||
if TYPE_CHECKING: | ||
from ...model import PointCloud | ||
|
||
|
||
class BasePointCloudHandler(object, metaclass=SingletonABCMeta): | ||
EXTENSIONS = set() # should be set in subclasses | ||
|
||
@abstractmethod | ||
def read_point_cloud(self, path: Path) -> Tuple[np.ndarray, Optional[np.ndarray]]: | ||
"""Read a point cloud file and return only the points and colors as array.""" | ||
logging.info( | ||
blue("Loading point cloud from %s using %s."), path, self.__class__.__name__ | ||
) | ||
pass | ||
|
||
@abstractmethod | ||
def write_point_cloud(self, path: Path, pointcloud: "PointCloud") -> None: | ||
logging.info( | ||
blue("Writing point cloud to %s using %s."), path, self.__class__.__name__ | ||
) | ||
pass | ||
|
||
@classmethod | ||
def get_supported_extensions(cls) -> Set[str]: | ||
return set().union(*[handler.EXTENSIONS for handler in cls.__subclasses__()]) | ||
|
||
@classmethod | ||
def get_handler(cls, file_extension: str) -> "BasePointCloudHandler": | ||
"""Return a point cloud handler for the given file extension.""" | ||
for subclass in cls.__subclasses__(): | ||
if file_extension in subclass.EXTENSIONS: | ||
return subclass() | ||
|
||
logging.error( | ||
"No point cloud handler found for file extension %s.", file_extension | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import logging | ||
from pathlib import Path | ||
from typing import TYPE_CHECKING, Tuple | ||
|
||
import numpy as np | ||
|
||
from . import BasePointCloudHandler | ||
|
||
if TYPE_CHECKING: | ||
from ...model import PointCloud | ||
|
||
|
||
class NumpyHandler(BasePointCloudHandler): | ||
EXTENSIONS = {".bin"} | ||
|
||
def __init__(self) -> None: | ||
super().__init__() | ||
|
||
def read_point_cloud(self, path: Path) -> Tuple[np.ndarray, None]: | ||
"""Read point cloud file as array and drop reflection and nan values.""" | ||
super().read_point_cloud(path) | ||
points = np.fromfile(path, dtype=np.float32) | ||
points = points.reshape((-1, 4 if len(points) % 4 == 0 else 3))[:, 0:3] | ||
return (points[~np.isnan(points).any(axis=1)], None) | ||
|
||
def write_point_cloud(self, path: Path, pointcloud: "PointCloud") -> None: | ||
"""Write point cloud points into binary file.""" | ||
super().write_point_cloud(path, pointcloud) | ||
logging.warning( | ||
"Only writing point coordinates, any previous reflection values will be dropped." | ||
) | ||
pointcloud.points.tofile(path) |
Oops, something went wrong.