Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions sensor_msgs_py/sensor_msgs_py/point_cloud2.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ def create_cloud(
for each point, with the elements of each iterable being the
values of the fields for that point (in the same order as
the fields parameter)
:param point_step: Point step size in bytes. Calculated from the given fields by default.
:param point_step: Point step size in bytes. If not provided, it is calculated
from the given fields, except when 'points' is a structured
NumPy array, in which case points.dtype.itemsize is used.
(Type: optional of integer)
:return: The point cloud as sensor_msgs.msg.PointCloud2
"""
Expand All @@ -266,7 +268,9 @@ def create_cloud(
points,
dtype=dtype_from_fields(fields, point_step))
else:
assert points.dtype == dtype_from_fields(fields, point_step), \
assert points.dtype == dtype_from_fields(
fields,
point_step or points.dtype.itemsize), \
'PointFields and structured NumPy array dtype do not match for all fields! \
Check their field order, names and types.'
else:
Expand Down
8 changes: 8 additions & 0 deletions sensor_msgs_py/test/test_point_cloud2.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,18 @@ def test_create_cloud(self):
def test_create_cloud_itemsize(self):

with self.assertRaises(AssertionError):
dtype_from_fields = point_cloud2.dtype_from_fields(fields)
point_cloud2.create_cloud(
Header(frame_id='frame'),
fields,
points_end_padding,
dtype_from_fields.itemsize)

thispcd = point_cloud2.create_cloud(
Header(frame_id='frame'),
fields,
points_end_padding)
self.assertEqual(thispcd.point_step, itemsize_end_padding)

thispcd = point_cloud2.create_cloud(
Header(frame_id='frame'),
Expand Down