pointcloudset.pointcloud module
- class pointcloudset.pointcloud.PointCloud(data: DataFrame = None, orig_file: str = '', timestamp: datetime = None, columns: list = ['x', 'y', 'z'])
Bases:
PointCloudCorePointCloud Class with one pointcloud of lidar measurements, laser scanning, photogrammetry or simular.
One PointCloud consists mainly of a pandas.DataFrame (.data) with the point coordinates and all associated per-point attributes.
Note that the index of the points is not preserved when applying processing. Therefore, a new PointCloud object is generated at each processing stage.
- Developer notes:
All operations have to act on both, pointcloud, data and keep the timestamp.
All processing methods need to return another PointCloud.
Examples
testbag = Path().cwd().parent.joinpath("tests/testdata/test.bag") testset = pointcloudset.Dataset(testbag,topic="/os1_cloud_node/points", keep_zeros=False) testpointcloud = testset[0]
- classmethod from_file(file_path: Path, timestamp: str | datetime = 'from_file', **kwargs)
Extract data from file and construct a PointCloud with it.
- Parameters:
file_path (pathlib.Path) – Path of file to read.
use_file_timestamp (bool) – use the file creation date as timestamp. Defaults to True.
timestamp (str | datetime.datetime) – timestamp of pointcloud. If “from_file” then the timesamp is taken from file creation datetimne. (Defaults to “from_file”)
**kwargs – Keyword arguments to pass to func.
- Returns:
PointCloud with timestamp last modified.
- Return type:
- Raises:
ValueError – If file format is not supported.
TypeError – If file_path is no Path object.
- to_file(file_path: Path = PosixPath('.'), **kwargs) None
Exports the pointcloud as to a file for use with CloudCompare or similar tools. Currently not all attributes of a pointcloud are saved so some information is lost when using this function. Uses the format-specific native IO backend.
- Parameters:
file_path (pathlib.Path, optional) – Destination. Defaults to the folder of the bag file and csv with the timestamp of the pointcloud.
**kwargs – Keyword arguments to pass to func.
- Raises:
ValueError – If file format is not supported.
- classmethod from_instance(library: ~typing.Literal['PANDAS', 'DATAFRAME'] = 'PANDAS', instance: ~pandas.core.frame.DataFrame = Empty DataFrame Columns: [] Index: [], **kwargs) PointCloud
Converts a library instance to a pointcloudset PointCloud.
- Parameters:
library (str) –
Name of the library.
If DATAFRAME:
pointcloudset.io.pointcloud.pandas.from_dataframe()If PANDAS:
pointcloudset.io.pointcloud.pandas.from_dataframe()instance (pandas.DataFrame) – Library instance to convert.
**kwargs – Keyword arguments to pass to func.
- Returns:
Derived from the instance.
- Return type:
- Raises:
ValueError – If instance is not supported.
- to_instance(library: Literal['DATAFRAME', 'PANDAS'], **kwargs) DataFrame
Convert PointCloud to another library instance.
- Parameters:
library (str) –
Name of the library.
If DATAFRAME:
pointcloudset.io.pointcloud.pandas.to_dataframe()If PANDAS:
pointcloudset.io.pointcloud.pandas.to_dataframe()**kwargs – Keyword arguments to pass to func.
- Returns:
The derived instance.
- Return type:
- Raises:
ValueError – If library is not suppored.
- plot(color: None | str = None, overlay: dict | None = None, point_size: float = 2, prepend_id: str = '', hover_data: Union(list[str], bool) = None, **kwargs) plotly.graph_objs.Figure
Plot a PointCloud as a 3D scatter plot with Plotly. It handles plots of single pointclouds and overlay with other objects, such as other pointclouds from clustering or planes from plane segmentation.
You can also pass arguments to the Plotly express function
plotly.express.scatter_3d().- Parameters:
pointcloud (PointCloud) – The pointcloud to plot.
color (str or None) – Which column to plot. For example “intensity”. Defaults to None.
overlay (dict, optional) –
Dict with PointClouds to overlay. {“Cluster 1”: cluster1,”Plane 1”: plane_model}
See also:
pointcloudset.plot.pointcloud.plot_overlay()Defaults to empty.
point_size (float, optional) – Size of each point. Defaults to 2.
prepend_id (str, optional) – String before point id to display in hover. Defaults to empty.
hover_data (list(str) or True, optional) – Data columns to display in hover. If True then all the columns are are show in the hover. Defaults to None.
**kwargs – Keyword arguments to pass to func.
- Returns:
The interactive Plotly plot, best used inside a Jupyter Notebook.
- Return type:
- Raises:
ValueError – If the color column name is not in the data.
- diff(name: Literal['origin', 'plane', 'pointcloud', 'point', 'nearest'], target: None | PointCloud | ndarray = None, **kwargs) PointCloud
Calculate differences and distances to the origin, plane, point and pointcloud.
- Parameters:
name (str) –
“origin”:
pointcloudset.diff.origin.calculate_distance_to_origin()”plane”:
pointcloudset.diff.plane.calculate_distance_to_plane()”pointcloud”:
pointcloudset.diff.pointcloud.calculate_distance_to_pointcloud()”point”:
pointcloudset.diff.point.calculate_distance_to_point()”nearest”:
pointcloudset.diff.point.calculate_distance_to_nearest()target (Union[None, PointCloud, numpy.ndarray], optional) – Pass argument according to chosen object. Defaults to None.
**kwargs – Keyword arguments to pass to func.
- Returns:
New PointCloud with added column of the differences.
- Return type:
- Raises:
ValueError – If name is not supported.
Examples
newpointcloud = testpointcloud.diff("pointcloud", targetpointcloud)
- filter(name: Literal['quantile', 'value', 'radiusoutlier'], *args, **kwargs) PointCloud
Filters a PointCloud according to criteria.
- Parameters:
name (str) –
“quantile”:
pointcloudset.filter.stat.quantile_filter()”value”:
pointcloudset.filter.stat.value_filter()”radiusoutlier”:
pointcloudset.filter.stat.remove_radius_outlier()*args – Positional arguments to pass to func.
**kwargs – Keyword arguments to pass to func.
- Returns:
PointCloud which fullfils the criteria.
- Return type:
- Raises:
ValueError – If name is not supported.
Examples
filteredpointcloud = testpointcloud.filter("quantile","intensity","==",0.5)
filteredpointcloud = testpointcloud.filter("value","intensity",">",100)
- limit(dim: str, minvalue: float, maxvalue: float) PointCloud
Limit the range of certain values in pointcloudset PointCloud. Can be chained together.
- Parameters:
- Returns:
Limited pointcloud, where rows which did not match the criteria were dropped.
- Return type:
Examples
limitedpointcloud = testpointcloud.limit("x", -1.0, 1.0).limit("intensity", 0.0, 50.0)
- limit_less(dim: str, value: float) PointCloud
- Limit the range if a diminsion to a value.
Same as filter(“value”, dim, “<”, value)
- Parameters:
- Returns:
Limited pointcloud, where rows which did not match the criteria were dropped.
- Return type:
Examples
limitedpointcloud = testpointcloud.limit_less("x",1.0)
- limit_greater(dim: str, value: float) PointCloud
- Limit the range if a diminsion to a value.
Same as filter(“value”, dim, “>”, value)
- Parameters:
- Returns:
Limited pointcloud, where rows which did not match the criteria were dropped.
- Return type:
Examples
limitedpointcloud = testpointcloud.limit_greater("x",10.0)
- apply_filter(filter_result: ndarray | list[int]) PointCloud
Generating a new PointCloud by removing points according to a call of the filter method.
- Parameters:
filter_result (Union[numpy.ndarray, list[int]]) – Filter result.
- Returns:
PointCloud with filtered rows and reindexed data and points.
- Return type:
- Raises:
TypeError – If the filter_result has the wrong type.
- get_cluster(eps: float, min_points: int) DataFrame
Cluster the PointCloud using DBSCAN.
This method validates inputs and delegates the clustering implementation to
pointcloudset.cluster.get_cluster_labels().- Parameters:
- Returns:
One row per point with column
cluster. Noise points receive label-1and can be retrieved withtake_cluster(-1, labels).- Return type:
- Raises:
ValueError – If
epsis not positive,min_pointsis less than 1, or the point cloud is empty.
- take_cluster(cluster_number: int, cluster_labels: DataFrame) PointCloud
Takes only the points belonging to the cluster_number.
Use
cluster_number=-1to retrieve noise points.- Parameters:
cluster_number (int) – Cluster ID to keep. Use
-1for noise points.cluster_labels (pandas.DataFrame) – Clusters generated with
pointcloudset.pointcloud.PointCloud.get_cluster().
- Returns:
PointCloud with selected cluster.
- Return type:
- Raises:
ValueError – If
cluster_labelslength does not match this PointCloud.
- plane_segmentation(distance_threshold: float, ransac_n: int, num_iterations: int, return_plane_model: bool = False, seed: int = 42) PointCloud | dict
Segments a plane in the point cloud using the RANSAC algorithm.
After finding the best consensus set the plane is refit via SVD on all inliers, so the returned model is more accurate than the initial sample.
- Parameters:
distance_threshold (float) – Max distance a point can be from the plane model, and still be considered as an inlier.
ransac_n (int) – Number of points sampled per iteration to fit a candidate plane. Must be >= 3.
num_iterations (int) – Number of RANSAC iterations. Must be >= 1.
return_plane_model (bool, optional) – Return also plane model parameters if
True. Defaults toFalse.seed (int, optional) – Random seed for reproducibility. Defaults to 42.
- Returns:
PointCloud with inliers or a dict of PointCloud with inliers and the plane parameters. The plane model is [a, b, c, d] for ax+by+cz+d=0 (normalised).
- Return type:
PointCloud or dict
- Raises:
ValueError – If the point cloud is empty,
distance_thresholdis not positive,ransac_nis less than 3 or exceeds the number of points, ornum_iterationsis less than 1.
- random_down_sample(number_of_points: int) PointCloud
Function to downsample input pointcloud into output pointcloud randomly. Made
- Parameters:
number_of_points ([int]) – number_of_points
- Returns:
subsampled PointCloud
- Return type: