25 #include <pcl/common/transforms.h>
26 #include <pcl/impl/point_types.hpp>
27 #include <pcl/point_types.h>
43 defineOptionalProperty<int>(
44 "ProviderWaitMs", 100,
"Time to wait for each point cloud provider [ms].");
54 params.pointSizeInPixels,
"viz.pointSizeInPixels",
"The point size in pixels.");
55 defs->optional(params.checkFinite,
57 "Enable to check points for being finite. "
58 "\nEnable this option if the drawn point cloud causes the screen to become "
60 defs->optional(params.labeled,
62 "If true and point cloud is labeled, draw colors according to labels.");
63 defs->optional(params.alsoVisualizeNode,
65 "If true also the node's coordinate systems is shown.");
67 defs->optional(params.robotName,
"robotName",
"");
69 params.pointCloudNodeName,
71 " If the point cloud header does not provide a frame id, this info is used.");
84 return "PointCloudToArViz";
90 params.providerWaitTime =
91 IceUtil::Time::milliSeconds(getProperty<int>(
"ProviderWaitMs").getValue());
99 robot = virtualRobotReaderPlugin->
get().
getRobot(params.robotName);
124 static_cast<int>(params.providerWaitTime.toMilliSeconds())))
126 auto it = cache.find(providerName);
127 if (it == cache.end())
135 std::scoped_lock lock(paramMutex);
136 params = this->params;
143 std::optional<PointCloudToArViz::OriginInfo> originInfo;
147 pcl::PointCloud<pcl::PointXYZRGBL>::Ptr inputCloud(
148 new pcl::PointCloud<pcl::PointXYZRGBL>);
150 originInfo = applyCustomTransform(*inputCloud);
151 vizCloud.
pointCloud(*inputCloud, params.labeled);
155 pcl::PointCloud<pcl::PointXYZRGBA>::Ptr inputCloud(
156 new pcl::PointCloud<pcl::PointXYZRGBA>);
158 originInfo = applyCustomTransform(*inputCloud);
163 if (params.alsoVisualizeNode && originInfo.has_value())
166 originPose.pose(originInfo->pose);
168 layer.
add(originPose);
176 ARMARX_VERBOSE <<
"Timeout waiting for point cloud provider " << providerName
185 std::scoped_lock lock(paramMutex);
186 params.pointSizeInPixels = pointSizeInPixels;
203 template <
class Po
intT>
204 std::optional<PointCloudToArViz::OriginInfo>
205 PointCloudToArViz::applyCustomTransform(pcl::PointCloud<PointT>& pointCloud)
211 <<
"The robot reader plugin is deactivated. Won't transform point cloud";
219 const auto pointCloudNodeName = [&]() -> std::string
222 if (not pointCloud.header.frame_id.empty())
224 return pointCloud.header.frame_id;
230 <<
"The point cloud header does not provide a frame_id. Using property instead";
233 <<
"The `pointCloudNodeName` property must be provided as the point cloud "
235 "frame id is not set!";
237 return params.pointCloudNodeName;
243 <<
"The robot is not available. Won't transform point cloud";
251 const auto node = robot->getRobotNode(pointCloudNodeName);
254 globalSensorPose = node->getGlobalPose();
256 pcl::transformPointCloud(pointCloud, pointCloud, globalSensorPose);
261 return OriginInfo{.name = pointCloudNodeName, .pose = globalSensorPose};
272 tab.checkFinite.
setName(
"Check Finite");
273 tab.checkFinite.setValue(params.checkFinite);
275 tab.pointSizeInPixels.setName(
"Point Size [pixels]");
276 tab.pointSizeInPixels.setDecimals(2);
277 tab.pointSizeInPixels.setRange(0, 100);
278 tab.pointSizeInPixels.setSteps(100);
279 tab.pointSizeInPixels.setValue(params.pointSizeInPixels);
281 tab.labeled.setName(
"Color by Labels");
282 tab.labeled.setValue(params.labeled);
284 grid.
add(
Label(tab.checkFinite.getName()), {row, 0}).
add(tab.checkFinite, {row, 1});
286 grid.
add(
Label(tab.pointSizeInPixels.getName()), {row, 0})
287 .
add(tab.pointSizeInPixels, {row, 1});
289 grid.
add(
Label(tab.labeled.getName()), {row, 0}).
add(tab.labeled, {row, 1});
299 std::scoped_lock lock(paramMutex);
300 if (tab.checkFinite.hasValueChanged())
302 params.checkFinite = tab.checkFinite.getValue();
304 if (tab.pointSizeInPixels.hasValueChanged())
306 params.pointSizeInPixels = tab.pointSizeInPixels.getValue();
308 if (tab.labeled.hasValueChanged())
310 params.labeled = tab.labeled.getValue();