In-Place Modification of PointCloud2 message?
I am subscribing to a sensor_msgs/PointCloud2
message (points with: x,y,z,intensity) and I would like to change the intensity value based on some heuristic in my code.
In principle the code looks like this:
import sensor_msgs.point_cloud2
def handle_cloud(self, msg):
field_names = ("x", "y", "z", "intensity")
reader = sensor_msgs.point_cloud2.read_points(msg, field_names)
for p in reader:
new_intensity = some_code(p)
# assign new intensity to point
p[3] = new_intensity # TODO: is this possible somehow?
# republish with new intensity values
publisher.publish(msg)
Can I do this in-place, similarly to the code above? Or do I need to build a new message, using sensor_msgs.point_cloud2.create_cloud()
?