Performance: Point cloud processing basics
This affects how quickly and smoothly 3D point cloud data is processed and visualized in robotic applications.
pcl::PointCloud<pcl::PointXYZ> cloud; pcl::fromROSMsg(cloud_msg, cloud); pcl::VoxelGrid<pcl::PointXYZ> sor; sor.setInputCloud(cloud.makeShared()); sor.setLeafSize(0.01f, 0.01f, 0.01f); sor.filter(cloud_filtered);
pcl::PointCloud<pcl::PointXYZ> cloud; pcl::fromROSMsg(cloud_msg, cloud); pcl::VoxelGrid<pcl::PointXYZ> sor; sor.setInputCloud(cloud.makeShared()); sor.setLeafSize(0.001f, 0.001f, 0.001f); sor.filter(cloud_filtered);
| Pattern | CPU Usage | Latency | Memory Usage | Verdict |
|---|---|---|---|---|
| No downsampling, dense cloud | High CPU | High latency | High memory | [X] Bad |
| Downsampling with reasonable voxel size | Low CPU | Low latency | Moderate memory | [OK] Good |
import sensor_msgs.point_cloud2 as pc2
from sensor_msgs.msg import PointCloud2
cloud = PointCloud2()
points = [(1, 2, 3), (4, 5, 6), (7, 8, 9)]
for point in pc2.read_points(cloud, field_names=("x", "y", "z")):
print(point)import sensor_msgs.point_cloud2 as pc2
from sensor_msgs.msg import PointCloud2
cloud = PointCloud2()
filtered_points = []
for point in pc2.read_points(cloud, field_names=("x", "y", "z")):
dist = (point[0]**2 + point[1]**2 + point[2]**2)**0.5
if dist > 5:
filtered_points.append(point)
print(filtered_points)Pass the test and this pattern moves unknown