-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
214 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0"?> | ||
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?> | ||
<package format="3"> | ||
<name>regpipe_ros</name> | ||
<version>0.0.0</version> | ||
<description>TODO: Package description</description> | ||
<maintainer email="[email protected]">warra</maintainer> | ||
<license>TODO: License declaration</license> | ||
|
||
<test_depend>ament_copyright</test_depend> | ||
<test_depend>ament_flake8</test_depend> | ||
<test_depend>ament_pep257</test_depend> | ||
<test_depend>python3-pytest</test_depend> | ||
|
||
<export> | ||
<build_type>ament_python</build_type> | ||
</export> | ||
</package> |
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,11 @@ | ||
import open3d | ||
import numpy as np | ||
from . import open3d_conversions | ||
|
||
|
||
def main(): | ||
print('Hi from regpipe_ros.') | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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,79 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
import numpy as np | ||
import open3d | ||
import ros2_numpy | ||
from sensor_msgs.msg import PointCloud2 as pc2 | ||
from numpy.lib import recfunctions | ||
from sensor_msgs.msg import PointField | ||
from std_msgs.msg import Header | ||
|
||
# The data structure of each point in ros PointCloud2: 16 bits = x + y + z + rgb | ||
FIELDS_XYZ = [ | ||
PointField(name='x', offset=0, datatype=PointField.FLOAT32, count=1), | ||
PointField(name='y', offset=4, datatype=PointField.FLOAT32, count=1), | ||
PointField(name='z', offset=8, datatype=PointField.FLOAT32, count=1), | ||
] | ||
FIELDS_XYZRGB = FIELDS_XYZ + \ | ||
[PointField(name='rgb', offset=12, datatype=PointField.FLOAT32, count=1)] | ||
|
||
|
||
def to_msg(open3d_cloud, frame_id=None, stamp=None): | ||
header = Header() | ||
if stamp is not None: | ||
header.stamp = stamp | ||
if frame_id is not None: | ||
header.frame_id = frame_id | ||
|
||
o3d_asarray = np.asarray(open3d_cloud.points) | ||
|
||
o3d_x = o3d_asarray[:, 0] | ||
o3d_y = o3d_asarray[:, 1] | ||
o3d_z = o3d_asarray[:, 2] | ||
|
||
cloud_data = np.core.records.fromarrays([o3d_x, o3d_y, o3d_z], names='x,y,z') | ||
|
||
if not open3d_cloud.colors: # XYZ only | ||
fields = FIELDS_XYZ | ||
else: # XYZ + RGB | ||
fields = FIELDS_XYZRGB | ||
color_array = np.array(np.floor(np.asarray(open3d_cloud.colors) * 255), dtype=np.uint8) | ||
|
||
o3d_r = color_array[:, 0] | ||
o3d_g = color_array[:, 1] | ||
o3d_b = color_array[:, 2] | ||
|
||
cloud_data = np.lib.recfunctions.append_fields(cloud_data, ['r', 'g', 'b'], [o3d_r, o3d_g, o3d_b]) | ||
|
||
cloud_data = ros_numpy.point_cloud2.merge_rgb_fields(cloud_data) | ||
|
||
return pc2.create_cloud(header, fields, cloud_data) | ||
|
||
|
||
def from_msg(ros_cloud): | ||
xyzrgb_array = ros_numpy.point_cloud2.pointcloud2_to_array(ros_cloud) | ||
|
||
mask = np.isfinite(xyzrgb_array['x']) & np.isfinite(xyzrgb_array['y']) & np.isfinite(xyzrgb_array['z']) | ||
cloud_array = xyzrgb_array[mask] | ||
|
||
open3d_cloud = open3d.PointCloud() | ||
|
||
points = np.zeros(cloud_array.shape + (3,), dtype=np.float) | ||
points[..., 0] = cloud_array['x'] | ||
points[..., 1] = cloud_array['y'] | ||
points[..., 2] = cloud_array['z'] | ||
open3d_cloud.points = open3d.Vector3dVector(points) | ||
|
||
if 'rgb' in xyzrgb_array.dtype.names: | ||
rgb_array = ros_numpy.point_cloud2.split_rgb_field(xyzrgb_array) | ||
cloud_array = rgb_array[mask] | ||
|
||
colors = np.zeros(cloud_array.shape + (3,), dtype=np.float) | ||
colors[..., 0] = cloud_array['r'] | ||
colors[..., 1] = cloud_array['g'] | ||
colors[..., 2] = cloud_array['b'] | ||
|
||
open3d_cloud.colors = open3d.Vector3dVector(colors / 255.0) | ||
|
||
return open3d_cloud |
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,4 @@ | ||
[develop] | ||
script_dir=$base/lib/regpipe_ros | ||
[install] | ||
install_scripts=$base/lib/regpipe_ros |
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,26 @@ | ||
from setuptools import find_packages, setup | ||
|
||
package_name = 'regpipe_ros' | ||
|
||
setup( | ||
name=package_name, | ||
version='0.0.0', | ||
packages=find_packages(exclude=['test']), | ||
data_files=[ | ||
('share/ament_index/resource_index/packages', | ||
['resource/' + package_name]), | ||
('share/' + package_name, ['package.xml']), | ||
], | ||
install_requires=['setuptools'], | ||
zip_safe=True, | ||
maintainer='warra', | ||
maintainer_email='[email protected]', | ||
description='TODO: Package description', | ||
license='TODO: License declaration', | ||
tests_require=['pytest'], | ||
entry_points={ | ||
'console_scripts': [ | ||
'hello_world = regpipe_ros.hello_world:main' | ||
], | ||
}, | ||
) |
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,25 @@ | ||
# Copyright 2015 Open Source Robotics Foundation, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from ament_copyright.main import main | ||
import pytest | ||
|
||
|
||
# Remove the `skip` decorator once the source file(s) have a copyright header | ||
@pytest.mark.skip(reason='No copyright header has been placed in the generated source file.') | ||
@pytest.mark.copyright | ||
@pytest.mark.linter | ||
def test_copyright(): | ||
rc = main(argv=['.', 'test']) | ||
assert rc == 0, 'Found errors' |
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,25 @@ | ||
# Copyright 2017 Open Source Robotics Foundation, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from ament_flake8.main import main_with_errors | ||
import pytest | ||
|
||
|
||
@pytest.mark.flake8 | ||
@pytest.mark.linter | ||
def test_flake8(): | ||
rc, errors = main_with_errors(argv=[]) | ||
assert rc == 0, \ | ||
'Found %d code style errors / warnings:\n' % len(errors) + \ | ||
'\n'.join(errors) |
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,23 @@ | ||
# Copyright 2015 Open Source Robotics Foundation, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from ament_pep257.main import main | ||
import pytest | ||
|
||
|
||
@pytest.mark.linter | ||
@pytest.mark.pep257 | ||
def test_pep257(): | ||
rc = main(argv=['.', 'test']) | ||
assert rc == 0, 'Found code style errors / warnings' |