pypcd4


Namepypcd4 JSON
Version 1.2.0 PyPI version JSON
download
home_pageNone
SummaryRead and write PCL .pcd files in python
upload_time2025-02-19 06:35:48
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8.2
licenseBSD 3-Clause License Copyright (c) 2018, Daniel Maturana Copyright (c) 2023-present, MAP IV, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of wsrv.nl and images.weserv.nl nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pypcd4

[![Test](https://github.com/MapIV/pypcd4/actions/workflows/test.yaml/badge.svg)](https://github.com/MapIV/pypcd4/actions/workflows/test.yaml)
![PyPI - Version](https://img.shields.io/pypi/v/pypcd4)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pypcd4)
![GitHub License](https://img.shields.io/github/license/MapIV/pypcd4)
![PyPI - Downloads](https://img.shields.io/pypi/dm/pypcd4)

## Table of Contents

- [pypcd4](#pypcd4)
  - [Table of Contents](#table-of-contents)
  - [Description](#description)
  - [Installation](#installation)
  - [Usage](#usage)
    - [Getting Started](#getting-started)
    - [Working with .pcd Files](#working-with-pcd-files)
    - [Converting Between PointCloud and NumPy Array](#converting-between-pointcloud-and-numpy-array)
      - [Creating Custom Conversion Methods](#creating-custom-conversion-methods)
    - [Working with ROS PointCloud2 Messages](#working-with-ros-pointcloud2-messages)
    - [Concatenating PointClouds](#concatenating-pointclouds)
    - [Filtering a PointCloud](#filtering-a-pointcloud)
      - [Using a Slice](#using-a-slice)
      - [Using a Boolean Mask](#using-a-boolean-mask)
      - [Using Field Names](#using-field-names)
    - [Saving Your Work](#saving-your-work)
  - [Contributing](#contributing)
    - [Using Rye (Recommended)](#using-rye-recommended)
    - [Using pip](#using-pip)
  - [License](#license)

## Description

pypcd4 is a modern reimagining of the original [pypcd](https://github.com/dimatura/pypcd) library,
offering enhanced capabilities and performance for working with Point Cloud Data (PCD) files.

This library builds upon the foundation laid by the original pypcd while incorporating modern
Python3 syntax and methodologies to provide a more efficient and user-friendly experience.

## Installation

To get started with `pypcd4`, install it using pip:

```shell
pip install pypcd4
```

## Usage

Let’s walk through some examples of how you can use pypcd4:

### Getting Started

First, import the PointCloud class from pypcd4:

```python
from pypcd4 import PointCloud
```

### Working with .pcd Files

If you have a .pcd file, you can read it into a PointCloud object:

```python
pc: PointCloud = PointCloud.from_path("point_cloud.pcd")

pc.fields
# ('x', 'y', 'z', 'intensity')
```

### Converting Between PointCloud and NumPy Array

You can convert a PointCloud to a NumPy array:

```python
array: np.ndarray = pc.numpy()

array.shape
# (1000, 4)
```

You can also specify the fields you want to include in the conversion:

```python
array: np.ndarray = pc.numpy(("x", "y", "z"))

array.shape
# (1000, 3)
```

And you can convert a NumPy array back to a PointCloud.
The method you use depends on the fields in your array:

```python
# If the array has x, y, z, and intensity fields,
pc = PointCloud.from_xyzi_points(array)

# Or if the array has x, y, z, and label fields,
pc = PointCloud.from_xyzl_points(array, label_type=np.uint32)
```

#### Creating Custom Conversion Methods

If you can’t find your preferred point type in the pre-defined conversion methods,
you can create your own:

```python
fields = ("x", "y", "z", "intensity", "new_field")
types = (np.float32, np.float32, np.float32, np.float32, np.float64)

pc = PointCloud.from_points(array, fields, types)
```

### Working with ROS PointCloud2 Messages

You can convert a ROS PointCloud2 Message to a PointCloud and vice versa. This requires ROS installed and sourced, or [rosbags](https://ternaris.gitlab.io/rosbags/index.html) to be installed. To publish the converted message, ROS is required:

```python
def callback(in_msg: sensor_msgs.msg.PointCloud2):
    # Convert ROS PointCloud2 Message to a PointCloud
    pc = PointCloud.from_msg(in_msg)

    pc.fields
    # ("x", "y", "z", "intensity", "ring", "time")

    # Convert PointCloud to ROS PointCloud2 Message with the input message header
    out_msg = pc.to_msg(in_msg.header)

    # Publish using ROS (or e.g. write to a rosbag)
    publisher.publish(out_msg)
```

### Concatenating PointClouds

The `pypcd4` supports concatenating `PointCloud` objects together using the `+` operator.
This can be useful when you want to merge two point clouds into one.

Here's how you can use it:

```python
pc1: PointCloud = PointCloud.from_path("xyzi1.pcd")
pc2: PointCloud = PointCloud.from_path("xyzi2.pcd")

# Concatenate two PointClouds
pc3: PointCloud = pc1 + pc2
```

Concatenating many PointClouds in sequence can become slow, especially for large point counts. Using `PointCloud.from_list()` will be faster for those use cases:

```python
pc_list = []
for i in range(10):
    pc_list.append(PointCloud.from_path(f"xyzi{i}.pcd"))

pc: PointCloud = PointCloud.from_list(pc_list)
```

Please note that to concatenate PointCloud objects, they must have the exact same fields and types. If they don’t, a `ValueError` will be raised.

### Filtering a PointCloud

The `pypcd4` library provides a convenient way to filter a `PointCloud` using a subscript.

#### Using a Slice

You can use a slice to access a range of points in the point cloud. Here’s an example:

```python
# Create a point cloud with random points
pc = PointCloud.from_xyz_points(np.random.rand(10, 3))

# Access points using a slice
subset = pc[3:8]
```

In this case, subset will be a new PointCloud object containing only the points from index 3 to 7.

#### Using a Boolean Mask

You can use a boolean mask to access points that satisfy certain conditions. Here’s an example:

```python
# Create a point cloud with random points
pc = PointCloud.from_xyz_points(np.random.rand(10000, 3))

# Create a boolean mask
mask = (pc.pc_data["x"] > 0.5) & (pc.pc_data["y"] < 0.5)

# Access points using the mask
subset = pc[mask]
```

In this case, subset will be a new PointCloud object containing only the points where the x-coordinate is greater than 0.5 and the y-coordinate is less than 0.5.

#### Using Field Names

You can use a field name or a sequence of field names to access specific fields in the point cloud. Here’s an example:

```python
# Create a point cloud with random points
pc = PointCloud.from_xyz_points(np.random.rand(100, 3))

# Access specific fields
subset = pc[("x", "y")]
```

In this case, subset will be a new PointCloud object containing only the x and y coordinates of the points.
The z-coordinate will not be included.

### Saving Your Work

Finally, you can save your PointCloud as a .pcd file:

```python
pc.save("nice_point_cloud.pcd")
```

## Contributing

We are always looking for contributors. If you are interested in contributing,
please run the lint and test before submitting a pull request:

### Using Rye (Recommended)

Just run the following command:

```bash
rye sync
rye run lint
```

### Using pip

Install the testing dependencies by the following command:

```bash
pip install mypy pytest ruff
```

Then run the following command:

```bash
ruff check --fix src
ruff format src
mypy src
pytest
```

Make sure all lints and tests pass before submitting a pull request.

## License

The library was rewritten and does not borrow any code from the original [pypcd](https://github.com/dimatura/pypcd) library.
Since it was heavily inspired by the original author's work, we extend his original BSD 3-Clause License and include his Copyright notice.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pypcd4",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8.2",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": "urasakikeisuke <keisuke.urasaki@map4.jp>",
    "download_url": "https://files.pythonhosted.org/packages/d8/d1/29d66115466c44a0be49db0daf611bd08c765a2f18e4a274a7e014561e8e/pypcd4-1.2.0.tar.gz",
    "platform": null,
    "description": "# pypcd4\n\n[![Test](https://github.com/MapIV/pypcd4/actions/workflows/test.yaml/badge.svg)](https://github.com/MapIV/pypcd4/actions/workflows/test.yaml)\n![PyPI - Version](https://img.shields.io/pypi/v/pypcd4)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pypcd4)\n![GitHub License](https://img.shields.io/github/license/MapIV/pypcd4)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/pypcd4)\n\n## Table of Contents\n\n- [pypcd4](#pypcd4)\n  - [Table of Contents](#table-of-contents)\n  - [Description](#description)\n  - [Installation](#installation)\n  - [Usage](#usage)\n    - [Getting Started](#getting-started)\n    - [Working with .pcd Files](#working-with-pcd-files)\n    - [Converting Between PointCloud and NumPy Array](#converting-between-pointcloud-and-numpy-array)\n      - [Creating Custom Conversion Methods](#creating-custom-conversion-methods)\n    - [Working with ROS PointCloud2 Messages](#working-with-ros-pointcloud2-messages)\n    - [Concatenating PointClouds](#concatenating-pointclouds)\n    - [Filtering a PointCloud](#filtering-a-pointcloud)\n      - [Using a Slice](#using-a-slice)\n      - [Using a Boolean Mask](#using-a-boolean-mask)\n      - [Using Field Names](#using-field-names)\n    - [Saving Your Work](#saving-your-work)\n  - [Contributing](#contributing)\n    - [Using Rye (Recommended)](#using-rye-recommended)\n    - [Using pip](#using-pip)\n  - [License](#license)\n\n## Description\n\npypcd4 is a modern reimagining of the original [pypcd](https://github.com/dimatura/pypcd) library,\noffering enhanced capabilities and performance for working with Point Cloud Data (PCD) files.\n\nThis library builds upon the foundation laid by the original pypcd while incorporating modern\nPython3 syntax and methodologies to provide a more efficient and user-friendly experience.\n\n## Installation\n\nTo get started with `pypcd4`, install it using pip:\n\n```shell\npip install pypcd4\n```\n\n## Usage\n\nLet\u2019s walk through some examples of how you can use pypcd4:\n\n### Getting Started\n\nFirst, import the PointCloud class from pypcd4:\n\n```python\nfrom pypcd4 import PointCloud\n```\n\n### Working with .pcd Files\n\nIf you have a .pcd file, you can read it into a PointCloud object:\n\n```python\npc: PointCloud = PointCloud.from_path(\"point_cloud.pcd\")\n\npc.fields\n# ('x', 'y', 'z', 'intensity')\n```\n\n### Converting Between PointCloud and NumPy Array\n\nYou can convert a PointCloud to a NumPy array:\n\n```python\narray: np.ndarray = pc.numpy()\n\narray.shape\n# (1000, 4)\n```\n\nYou can also specify the fields you want to include in the conversion:\n\n```python\narray: np.ndarray = pc.numpy((\"x\", \"y\", \"z\"))\n\narray.shape\n# (1000, 3)\n```\n\nAnd you can convert a NumPy array back to a PointCloud.\nThe method you use depends on the fields in your array:\n\n```python\n# If the array has x, y, z, and intensity fields,\npc = PointCloud.from_xyzi_points(array)\n\n# Or if the array has x, y, z, and label fields,\npc = PointCloud.from_xyzl_points(array, label_type=np.uint32)\n```\n\n#### Creating Custom Conversion Methods\n\nIf you can\u2019t find your preferred point type in the pre-defined conversion methods,\nyou can create your own:\n\n```python\nfields = (\"x\", \"y\", \"z\", \"intensity\", \"new_field\")\ntypes = (np.float32, np.float32, np.float32, np.float32, np.float64)\n\npc = PointCloud.from_points(array, fields, types)\n```\n\n### Working with ROS PointCloud2 Messages\n\nYou can convert a ROS PointCloud2 Message to a PointCloud and vice versa. This requires ROS installed and sourced, or [rosbags](https://ternaris.gitlab.io/rosbags/index.html) to be installed. To publish the converted message, ROS is required:\n\n```python\ndef callback(in_msg: sensor_msgs.msg.PointCloud2):\n    # Convert ROS PointCloud2 Message to a PointCloud\n    pc = PointCloud.from_msg(in_msg)\n\n    pc.fields\n    # (\"x\", \"y\", \"z\", \"intensity\", \"ring\", \"time\")\n\n    # Convert PointCloud to ROS PointCloud2 Message with the input message header\n    out_msg = pc.to_msg(in_msg.header)\n\n    # Publish using ROS (or e.g. write to a rosbag)\n    publisher.publish(out_msg)\n```\n\n### Concatenating PointClouds\n\nThe `pypcd4` supports concatenating `PointCloud` objects together using the `+` operator.\nThis can be useful when you want to merge two point clouds into one.\n\nHere's how you can use it:\n\n```python\npc1: PointCloud = PointCloud.from_path(\"xyzi1.pcd\")\npc2: PointCloud = PointCloud.from_path(\"xyzi2.pcd\")\n\n# Concatenate two PointClouds\npc3: PointCloud = pc1 + pc2\n```\n\nConcatenating many PointClouds in sequence can become slow, especially for large point counts. Using `PointCloud.from_list()` will be faster for those use cases:\n\n```python\npc_list = []\nfor i in range(10):\n    pc_list.append(PointCloud.from_path(f\"xyzi{i}.pcd\"))\n\npc: PointCloud = PointCloud.from_list(pc_list)\n```\n\nPlease note that to concatenate PointCloud objects, they must have the exact same fields and types. If they don\u2019t, a `ValueError` will be raised.\n\n### Filtering a PointCloud\n\nThe `pypcd4` library provides a convenient way to filter a `PointCloud` using a subscript.\n\n#### Using a Slice\n\nYou can use a slice to access a range of points in the point cloud. Here\u2019s an example:\n\n```python\n# Create a point cloud with random points\npc = PointCloud.from_xyz_points(np.random.rand(10, 3))\n\n# Access points using a slice\nsubset = pc[3:8]\n```\n\nIn this case, subset will be a new PointCloud object containing only the points from index 3 to 7.\n\n#### Using a Boolean Mask\n\nYou can use a boolean mask to access points that satisfy certain conditions. Here\u2019s an example:\n\n```python\n# Create a point cloud with random points\npc = PointCloud.from_xyz_points(np.random.rand(10000, 3))\n\n# Create a boolean mask\nmask = (pc.pc_data[\"x\"] > 0.5) & (pc.pc_data[\"y\"] < 0.5)\n\n# Access points using the mask\nsubset = pc[mask]\n```\n\nIn this case, subset will be a new PointCloud object containing only the points where the x-coordinate is greater than 0.5 and the y-coordinate is less than 0.5.\n\n#### Using Field Names\n\nYou can use a field name or a sequence of field names to access specific fields in the point cloud. Here\u2019s an example:\n\n```python\n# Create a point cloud with random points\npc = PointCloud.from_xyz_points(np.random.rand(100, 3))\n\n# Access specific fields\nsubset = pc[(\"x\", \"y\")]\n```\n\nIn this case, subset will be a new PointCloud object containing only the x and y coordinates of the points.\nThe z-coordinate will not be included.\n\n### Saving Your Work\n\nFinally, you can save your PointCloud as a .pcd file:\n\n```python\npc.save(\"nice_point_cloud.pcd\")\n```\n\n## Contributing\n\nWe are always looking for contributors. If you are interested in contributing,\nplease run the lint and test before submitting a pull request:\n\n### Using Rye (Recommended)\n\nJust run the following command:\n\n```bash\nrye sync\nrye run lint\n```\n\n### Using pip\n\nInstall the testing dependencies by the following command:\n\n```bash\npip install mypy pytest ruff\n```\n\nThen run the following command:\n\n```bash\nruff check --fix src\nruff format src\nmypy src\npytest\n```\n\nMake sure all lints and tests pass before submitting a pull request.\n\n## License\n\nThe library was rewritten and does not borrow any code from the original [pypcd](https://github.com/dimatura/pypcd) library.\nSince it was heavily inspired by the original author's work, we extend his original BSD 3-Clause License and include his Copyright notice.\n",
    "bugtrack_url": null,
    "license": "BSD 3-Clause License  Copyright (c) 2018, Daniel Maturana Copyright (c) 2023-present, MAP IV, Inc.  All rights reserved.  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:  * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.  * Neither the name of wsrv.nl and images.weserv.nl nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.",
    "summary": "Read and write PCL .pcd files in python",
    "version": "1.2.0",
    "project_urls": {
        "Release Notes": "https://github.com/MapIV/pypcd4/releases",
        "Source": "https://github.com/MapIV/pypcd4",
        "Tracker": "https://github.com/MapIV/pypcd4/issues"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a89b8ab5b9f72d74dc24676e9cbb56090aa421149f3f4a0320135a29175142da",
                "md5": "dc4f2c808e8bd9d6598ae01d5edb0fd7",
                "sha256": "156553ccf7b3fde8027294f7e83559bec961e7f838d6eb56228e24c4da55229c"
            },
            "downloads": -1,
            "filename": "pypcd4-1.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "dc4f2c808e8bd9d6598ae01d5edb0fd7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8.2",
            "size": 14492,
            "upload_time": "2025-02-19T06:35:45",
            "upload_time_iso_8601": "2025-02-19T06:35:45.655365Z",
            "url": "https://files.pythonhosted.org/packages/a8/9b/8ab5b9f72d74dc24676e9cbb56090aa421149f3f4a0320135a29175142da/pypcd4-1.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d8d129d66115466c44a0be49db0daf611bd08c765a2f18e4a274a7e014561e8e",
                "md5": "8fe9299757a2cc0dec0373d4b68312dc",
                "sha256": "f33274ebe706a680e238cbe46cac746fa380bdffdb79609e0b3ceed1c2efb033"
            },
            "downloads": -1,
            "filename": "pypcd4-1.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "8fe9299757a2cc0dec0373d4b68312dc",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8.2",
            "size": 27234,
            "upload_time": "2025-02-19T06:35:48",
            "upload_time_iso_8601": "2025-02-19T06:35:48.844096Z",
            "url": "https://files.pythonhosted.org/packages/d8/d1/29d66115466c44a0be49db0daf611bd08c765a2f18e4a274a7e014561e8e/pypcd4-1.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-19 06:35:48",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "MapIV",
    "github_project": "pypcd4",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pypcd4"
}
        
Elapsed time: 4.26481s