27#include <pcl/common/transforms.h>
28#include <pcl/impl/point_types.hpp>
29#include <pcl/point_types.h>
31#include <SimoxUtility/math/convert/mat4f_to_pos.h>
32#include <SimoxUtility/math/convert/mat4f_to_rpy.h>
33#include <SimoxUtility/math/convert/pos_rpy_to_mat4f.h>
50 "ProviderWaitMs", 100,
"Time to wait for each point cloud provider [ms].");
60 params.pointSizeInPixels,
"viz.pointSizeInPixels",
"The point size in pixels.");
61 defs->optional(params.checkFinite,
63 "Enable to check points for being finite. "
64 "\nEnable this option if the drawn point cloud causes the screen to become "
66 defs->optional(params.labeled,
68 "If true and point cloud is labeled, draw colors according to labels.");
69 defs->optional(params.alsoVisualizeNode,
71 "If true also the node's coordinate systems is shown.");
73 defs->optional(params.robotName,
"robotName",
"");
75 params.pointCloudNodeName,
77 " If the point cloud header does not provide a frame id, this info is used.");
90 return "PointCloudToArViz";
102 params.providerWaitTime =
109 if (virtualRobotReaderPlugin->isAvailable())
111 robot = virtualRobotReaderPlugin->get().getRobot(params.robotName);
136 static_cast<int>(params.providerWaitTime.toMilliSeconds())))
138 auto it = cache.find(providerName);
139 if (it == cache.end())
147 std::scoped_lock lock(paramMutex);
148 params = this->params;
155 std::optional<PointCloudToArViz::OriginInfo> originInfo;
159 pcl::PointCloud<pcl::PointXYZRGBL>::Ptr inputCloud(
160 new pcl::PointCloud<pcl::PointXYZRGBL>);
162 originInfo = applyCustomTransform(*inputCloud);
163 vizCloud.
pointCloud(*inputCloud, params.labeled);
167 pcl::PointCloud<pcl::PointXYZRGBA>::Ptr inputCloud(
168 new pcl::PointCloud<pcl::PointXYZRGBA>);
170 originInfo = applyCustomTransform(*inputCloud);
175 if (params.alsoVisualizeNode && originInfo.has_value())
178 originPose.pose(originInfo->pose);
180 layer.
add(originPose);
184 arviz.commit({layer});
188 ARMARX_VERBOSE <<
"Timeout waiting for point cloud provider " << providerName
197 std::scoped_lock lock(paramMutex);
198 params.pointSizeInPixels = pointSizeInPixels;
215 template <
class Po
intT>
216 std::optional<PointCloudToArViz::OriginInfo>
217 PointCloudToArViz::applyCustomTransform(pcl::PointCloud<PointT>& pointCloud)
223 <<
"The robot reader plugin is deactivated. Won't transform point cloud";
229 std::scoped_lock lock(robotMutex);
234 const auto pointCloudNodeName = [&]() -> std::string
237 if (not pointCloud.header.frame_id.empty())
239 return pointCloud.header.frame_id;
245 <<
"The point cloud header does not provide a frame_id. Using property instead";
248 <<
"The `pointCloudNodeName` property must be provided as the point cloud "
250 "frame id is not set!";
252 return params.pointCloudNodeName;
258 <<
"The robot is not available. Won't transform point cloud";
262 Eigen::Matrix4f globalSensorPose = Eigen::Matrix4f::Identity();
266 std::scoped_lock lock(robotMutex);
268 const auto node = robot->getRobotNode(pointCloudNodeName);
270 <<
"No robot node with name `" << pointCloudNodeName <<
"`";
271 globalSensorPose = node->getGlobalPose();
274 pcl::transformPointCloud(pointCloud, pointCloud, globalSensorPose);
276 else if (not localTransformationNodeName.empty())
279 <<
"Local transformation node cannot be set as point cloud is in global "
285 return OriginInfo{.name = pointCloudNodeName, .pose = globalSensorPose};
296 tab.checkFinite.
setName(
"Check Finite");
297 tab.checkFinite.setValue(params.checkFinite);
299 tab.pointSizeInPixels.setName(
"Point Size [pixels]");
300 tab.pointSizeInPixels.setDecimals(2);
301 tab.pointSizeInPixels.setRange(0, 100);
302 tab.pointSizeInPixels.setSteps(100);
303 tab.pointSizeInPixels.setValue(params.pointSizeInPixels);
305 tab.labeled.setName(
"Color by Labels");
306 tab.labeled.setValue(params.labeled);
308 grid.
add(
Label(tab.checkFinite.getName()), {row, 0}).
add(tab.checkFinite, {row, 1});
310 grid.
add(
Label(tab.pointSizeInPixels.getName()), {row, 0})
311 .
add(tab.pointSizeInPixels, {row, 1});
313 grid.
add(
Label(tab.labeled.getName()), {row, 0}).
add(tab.labeled, {row, 1});
316 tab.localTransformationNode =
ComboBox();
317 tab.localTransformationNode.addOption(
"");
318 for (
const std::string& nodeName : robot->getRobotNodeNames())
320 tab.localTransformationNode.addOption(nodeName);
322 grid.
add(
Label(
"Local node: "), {row, 0}).add(tab.localTransformationNode, {row, 1});
325 auto createFloatSpinBox = [&](
float min,
float max,
float value)
328 spinBox.setRange(
min,
max);
329 spinBox.setValue(value);
332 spinBox.setSteps(
max -
min);
333 spinBox.setDecimals(1);
337 spinBox.setSteps((
max -
min) * 1000);
338 spinBox.setDecimals(4);
340 tab.transfSpinBoxes.push_back(spinBox);
345 grid.
add(
Label(
"Transformation: "), {row, col++})
346 .add(
Label(
"x"), {row, col++})
347 .add(createFloatSpinBox(-5000, 5000, 0), {row, col++})
348 .add(
Label(
"y"), {row, col++})
349 .add(createFloatSpinBox(-5000, 5000, 0), {row, col++})
350 .add(
Label(
"z"), {row, col++})
351 .add(createFloatSpinBox(-5000, 5000, 0), {row, col++})
352 .add(
Label(
"roll"), {row, col++})
353 .add(createFloatSpinBox(-
M_PI,
M_PI, 0), {row, col++})
354 .add(
Label(
"pitch"), {row, col++})
355 .add(createFloatSpinBox(-
M_PI,
M_PI, 0), {row, col++})
356 .add(
Label(
"yaw"), {row, col++})
357 .add(createFloatSpinBox(-
M_PI,
M_PI, 0), {row, col++});
367 std::scoped_lock lock(paramMutex);
368 if (tab.checkFinite.hasValueChanged())
370 params.checkFinite = tab.checkFinite.getValue();
372 if (tab.pointSizeInPixels.hasValueChanged())
374 params.pointSizeInPixels = tab.pointSizeInPixels.getValue();
376 if (tab.labeled.hasValueChanged())
378 params.labeled = tab.labeled.getValue();
381 if (tab.localTransformationNode.hasValueChanged())
383 localTransformationNodeName = tab.localTransformationNode.getValue();
385 if (not localTransformationNodeName.empty())
387 const auto localTransf =
388 robot->getRobotNode(localTransformationNodeName)->getLocalTransformation();
389 const Eigen::Vector3f pos = simox::math::mat4f_to_pos(localTransf);
390 const Eigen::Vector3f rpy = simox::math::mat4f_to_rpy(localTransf);
392 for (
unsigned int i = 0; i < 3; i++)
394 tab.transfSpinBoxes.at(i).setValue(pos[i]);
396 for (
unsigned int i = 0; i < 3; i++)
398 tab.transfSpinBoxes.at(i + 3).setValue(rpy[i]);
404 for (
auto& spinBox : tab.transfSpinBoxes)
406 if (spinBox.hasValueChanged())
414 std::scoped_lock lock(robotMutex);
416 auto localTransformation =
417 simox::math::pos_rpy_to_mat4f(tab.transfSpinBoxes.at(0).getValue(),
418 tab.transfSpinBoxes.at(1).getValue(),
419 tab.transfSpinBoxes.at(2).getValue(),
420 tab.transfSpinBoxes.at(3).getValue(),
421 tab.transfSpinBoxes.at(4).getValue(),
422 tab.transfSpinBoxes.at(5).getValue());
424 robot->getRobotNode(localTransformationNodeName)
425 ->setLocalTransformation(localTransformation);
428 ARMARX_INFO <<
"Updating localTransformation of " +
429 tab.localTransformationNode.getName() +
" to "
430 << localTransformation.matrix();
int Label(int n[], int size, int *curLabel, MiscLib::Vector< std::pair< int, size_t > > *labels)
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
#define ARMARX_CHECK_NOT_EMPTY(c)
armarx::viz::Client arviz
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Property< PropertyType > getProperty(const std::string &name)
SpamFilterDataPtr deactivateSpam(float deactivationDurationSec=10.0f, const std::string &identifier="", bool deactivate=true) const
disables the logging for the current line for the given amount of seconds.
PluginT * addPlugin(const std::string prefix="", ParamsT &&... params)
std::string getName() const
Retrieve name of object.
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
bool synchronizeRobot(VirtualRobot::Robot &robot, const armem::Time ×tamp) const
Synchronize both the platform pose and the joint values of a virtual robot, according to the robot st...
static Duration MicroSeconds(std::int64_t microSeconds)
Constructs a duration in microseconds.
PointCloud & pointSizeInPixels(float s)
PointCloud & pointCloud(const PointCloudT &cloud)
Draw a point cloud.
PointCloud & checkFinite(bool enabled=true)
Enable or disable checking whether points are finite when adding them (disabled by default).
PointCloudProcessorPropertyDefinitions(std::string prefix)
int getPointClouds(const PointCloudPtrT &pointCloudPtr)
Poll PointClouds from provider.
MetaPointCloudFormatPtr getPointCloudFormat(std::string providerName)
bool waitForPointClouds(int milliseconds=1000)
Wait for new PointClouds.
std::vector< std::string > getPointCloudProviderNames() const
Get the names of providers for which usingPointCloudProvider() has been called.
Property definitions of PointCloudToArViz.
PointCloudToArVizPropertyDefinitions(std::string prefix)
Brief description of class PointCloudToArViz.
virtual void setPointSizeInPixels(float pointSizeInPixels, const Ice::Current &=Ice::emptyCurrent) override
void RemoteGui_update() override
virtual void setCustomTransform(const armarx::PoseBasePtr &transform, const Ice::Current &=Ice::emptyCurrent) override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void onExitPointCloudProcessor() override
void onConnectPointCloudProcessor() override
void onDisconnectPointCloudProcessor() override
static std::string GetDefaultName()
void onInitPointCloudProcessor() override
void createRemoteGuiTab()
std::string getDefaultName() const override
Retrieve default name of component.
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
#define ARMARX_INFO
The normal logging level.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
#define ARMARX_VERBOSE
The logging level for verbose information.
std::string const GlobalFrame
Variable of the global coordinate system.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
void RemoteGui_startRunningTask()
void RemoteGui_createTab(std::string const &name, RemoteGui::Client::Widget const &rootWidget, RemoteGui::Client::Tab *tab)
GridLayout & add(Widget const &child, Pos pos, Span span=Span{1, 1})
void add(ElementT const &element)