29#include <pcl/common/colors.h>
30#include <pcl/filters/crop_box.h>
52 lastProcessedTimestamp = 0;
61 ARMARX_INFO <<
"Using the segmentation method " << segmentationMethod <<
flush;
66 ARMARX_INFO <<
"Starting " << (enabled ?
"Enabled" :
"Disabled");
83 if (segmentationMethod ==
"LCCP")
86 pLCCP->UpdateParameters(voxelRes,
95 else if (segmentationMethod ==
"RG")
98 pRGSegmenter->UpdateRegionGrowingSegmentationParameters(rgSmoothnessThes,
101 else if (segmentationMethod ==
"EC")
105 else if (segmentationMethod ==
"DS")
117 if (!debugDrawerTopic)
122 if (segmentationMethod ==
"DS")
126 if (!deepSegmenterTopic)
163 delete pDeepSegmenter;
171 std::unique_lock lock(enableMutex);
181 ARMARX_WARNING <<
"Timeout or error while waiting for point cloud data"
205 ARMARX_INFO <<
"Point cloud received (size: " << inputCloudPtr->points.size()
206 <<
", providerName: " << providerName <<
")";
210 IceUtil::Int64 originalTimestamp = info->timeProvided;
212 IceUtil::Time ts = IceUtil::Time::microSeconds(originalTimestamp);
213 std::string timestampString = ts.toDateTime().substr(ts.toDateTime().find(
' ') + 1);
215 IceUtil::Time start_ts = IceUtil::Time::now();
217 ARMARX_INFO <<
"Point cloud received (timestamp: " << timestampString
218 <<
", size: " << inputCloudPtr->points.size()
219 <<
", providerName: " << providerName <<
")";
220 if (inputCloudPtr->points.size() == 0)
225 if (segmentationMethod ==
"LCCP")
227 pcl::PointCloud<pcl::PointXYZL>::Ptr labeledPCPtr =
228 pLCCP->GetLabeledPointCloud(inputCloudPtr);
229 labeledColoredCloudPtr.reset(
230 new pcl::PointCloud<PointRGBL>());
232 if (inputCloudPtr->size() != labeledPCPtr->size())
234 ARMARX_WARNING <<
"Point cloud size mismatch (RGB: " << inputCloudPtr->size()
235 <<
", XYZL: " << labeledPCPtr->size() <<
"), skipping current frame";
240 pcl::concatenateFields(*inputCloudPtr, *labeledPCPtr, *labeledColoredCloudPtr);
241 ARMARX_INFO <<
" computed supervoxelcluster size: "
242 << pLCCP->GetSuperVoxelClusterSize();
244 << labeledColoredCloudPtr->points.size();
246 else if (segmentationMethod ==
"RG")
248 pRGSegmenter->UpdateRegionGrowingSegmentationParameters(rgSmoothnessThes,
250 auto colorizedLabeledCloudPtr = pRGSegmenter->ApplyRegionGrowingSegmentation(
252 pcl::PointCloud<pcl::PointXYZL>::Ptr labeledPCPtr(
253 new pcl::PointCloud<pcl::PointXYZL>());
254 convertFromXYZRGBAtoXYZL(
255 colorizedLabeledCloudPtr,
257 labeledColoredCloudPtr.reset(
new pcl::PointCloud<PointRGBL>());
258 pcl::concatenateFields(*inputCloudPtr, *labeledPCPtr, *labeledColoredCloudPtr);
260 else if (segmentationMethod ==
"EC")
262 labeledColoredCloudPtr = pECSegmenter->GetLabeledPointCloud(inputCloudPtr);
264 else if (segmentationMethod ==
"DS")
266 if (!deepSegmenterTopic)
272 if (!inputCloudPtr->isOrganized())
279 rgbImage = pDeepSegmenter->GetImageFromPointCloud(inputCloudPtr);
281 deepSegmenterTopic->setImageDimensions(inputCloudPtr->width, inputCloudPtr->height);
282 armarx::Blob deepSegmentImage = deepSegmenterTopic->segmentImage(rgbImage);
284 labeledColoredCloudPtr =
285 pDeepSegmenter->GetLabeledPointCloud(inputCloudPtr, deepSegmentImage);
289 labeledColoredCloudPtr->header.stamp = originalTimestamp;
292 std::unique_lock lock(enableMutex);
300 std::unique_lock lock(timestampMutex);
301 lastProcessedTimestamp = originalTimestamp;
307 << (IceUtil::Time::now() - start_ts).toSecondsDouble() <<
" secs";
311 ARMARX_WARNING <<
"PointCloudSegmenter configured to run only once";
326 std::unique_lock lock(enableMutex);
335 std::unique_lock lock(enableMutex);
343 const Ice::Current&
c)
345 std::unique_lock lock(providerMutex);
347 ARMARX_INFO <<
"Changing point cloud provider to '" << providerName <<
"'";
352 this->providerName = providerName;
359 PointCloudSegmenter::convertFromXYZRGBAtoXYZL(
360 pcl::PointCloud<pcl::PointXYZRGBA>::Ptr& sourceCloudPtr,
361 pcl::PointCloud<pcl::PointXYZL>::Ptr& targetCloudPtr)
363 targetCloudPtr->resize(sourceCloudPtr->points.size());
364 uint32_t newLabel = 1;
373 std::map<uint32_t, rgbValues> colorMap;
376 for (
size_t i = 0; i < sourceCloudPtr->points.size(); i++)
379 currRGB.rVal = (int)sourceCloudPtr->points[i].r;
380 currRGB.gVal = (int)sourceCloudPtr->points[i].g;
381 currRGB.bVal = (int)sourceCloudPtr->points[i].b;
383 bool isFound =
false;
384 uint32_t foundLabel = 0;
387 std::map<uint32_t, rgbValues>::iterator iter_i;
389 for (iter_i = colorMap.begin(); iter_i != colorMap.end(); iter_i++)
391 if (currRGB.rVal == iter_i->second.rVal && currRGB.gVal == iter_i->second.gVal &&
392 currRGB.bVal == iter_i->second.bVal)
394 foundLabel = iter_i->first;
402 colorMap[newLabel] = currRGB;
403 foundLabel = newLabel;
407 targetCloudPtr->points[i].x = sourceCloudPtr->points[i].x;
408 targetCloudPtr->points[i].y = sourceCloudPtr->points[i].y;
409 targetCloudPtr->points[i].z = sourceCloudPtr->points[i].z;
410 targetCloudPtr->points[i].label = foundLabel;
417 std::unique_lock lock(enableMutex);
421 armarx::TimestampBasePtr
424 std::unique_lock lock(timestampMutex);
431 ARMARX_INFO <<
"Updating LCCP parameter setup (current segmentation method is "
432 << segmentationMethod <<
")";
433 pLCCP->UpdateParameters(parameters.voxelResolution,
434 parameters.seedResolution,
435 parameters.colorImportance,
436 parameters.spatialImportance,
437 parameters.normalImportance,
438 parameters.concavityThreshold,
439 parameters.smoothnessThreshold,
440 parameters.minSegmentSize);
445 const Ice::Current&
c)
447 std::string absolute_filename;
450 ARMARX_INFO <<
"Loading LCCP parameter setup from " << absolute_filename;
451 QSettings config(QString::fromStdString(absolute_filename), QSettings::IniFormat);
453 config.beginGroup(
"LCCP");
454 pLCCP->UpdateParameters(
464 config.value(
"NormalImportance",
getProperty<float>(
"lccpNormalImportance").getValue())
467 .value(
"ConcavityThreshold",
471 .value(
"SmoothnessThreshold",
474 config.value(
"MinSegmentSize",
getProperty<int>(
"lccpMinimumSegmentSize").getValue())
482 LccpParameters parameters;
484 parameters.voxelResolution = pLCCP->voxel_resolution;
485 parameters.seedResolution = pLCCP->seed_resolution;
486 parameters.colorImportance = pLCCP->color_importance;
487 parameters.spatialImportance = pLCCP->spatial_importance;
488 parameters.normalImportance = pLCCP->normal_importance;
489 parameters.concavityThreshold = pLCCP->concavity_tolerance_threshold;
490 parameters.smoothnessThreshold = pLCCP->smoothness_threshold;
491 parameters.minSegmentSize = pLCCP->min_segment_size;
499 float curvatureThreshold,
500 const Ice::Current&
c)
503 pRGSegmenter->UpdateRegionGrowingSegmentationParameters(smoothnessThreshold,
509 const Ice::Current&
c)
511 std::string absolute_filename;
514 ARMARX_INFO <<
"Loading RG parameter setup from " << absolute_filename;
515 QSettings config(QString::fromStdString(absolute_filename), QSettings::IniFormat);
517 config.beginGroup(
"RG");
518 pRGSegmenter->UpdateRegionGrowingSegmentationParameters(
520 .value(
"SmoothnessThreshold",
535 tab.rgSmoothnessThreshold.setRange(1.0, 20.0);
536 tab.rgSmoothnessThreshold.setSteps(200);
537 tab.rgSmoothnessThreshold.setValue(rgSmoothnessThes);
538 tab.rgSmoothnessThreshold.setDecimals(3);
539 grid.
add(
Label(
"rgSmoothnessThreshold:"),
Pos{row, 0});
540 grid.
add(tab.rgSmoothnessThreshold,
Pos{row, 1});
544 tab.rgCurvatureThreshold.setRange(1.0, 50.0);
545 tab.rgCurvatureThreshold.setSteps(200);
546 tab.rgCurvatureThreshold.setValue(rgCurvatureThres);
547 tab.rgCurvatureThreshold.setDecimals(3);
548 grid.
add(
Label(
"rgCurvatureThreshold:"),
Pos{row, 0});
549 grid.
add(tab.rgCurvatureThreshold,
Pos{row, 1});
559 rgSmoothnessThes = tab.rgSmoothnessThreshold.getValue();
560 rgCurvatureThres = tab.rgCurvatureThreshold.getValue();
int Label(int n[], int size, int *curLabel, MiscLib::Vector< std::pair< int, size_t > > *labels)
static bool getAbsolutePath(const std::string &relativeFilename, std::string &storeAbsoluteFilename, const std::vector< std::string > &additionalSearchPaths={}, bool verbose=true)
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Property< PropertyType > getProperty(const std::string &name)
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
TopicProxyType getTopic(const std::string &name)
Returns a proxy of the specified topic.
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
Implements a Variant type for timestamps.
void releasePointCloudProvider(std::string providerName)
Removes topic subscription and provider proxy dependency to release a point cloud provider.
void enableResultPointClouds(std::string resultProviderName="")
Enables visualization.
virtual void onDisconnectComponent() override
int getPointClouds(const PointCloudPtrT &pointCloudPtr)
Poll PointClouds from provider.
MetaPointCloudFormatPtr getPointCloudFormat(std::string providerName)
void usingPointCloudProvider(std::string providerName)
Registers a delayed topic subscription and a delayed provider proxy retrieval which will be available...
virtual void onConnectComponent() override
bool waitForPointClouds(int milliseconds=1000)
Wait for new PointClouds.
void provideResultPointClouds(const PointCloudPtrT &pointClouds, std::string providerName="")
sends result PointClouds for visualization
void loadLccpParametersFromFile(const std::string &filename, const Ice::Current &c=Ice::emptyCurrent) override
void RemoteGui_update() override
void onExitPointCloudProcessor() override
LccpParameters getLccpParameters(const Ice::Current &c=Ice::emptyCurrent) override
void enablePipelineStep(const Ice::Current &c=Ice::emptyCurrent) override
void onConnectPointCloudProcessor() override
void disablePipelineStep(const Ice::Current &c=Ice::emptyCurrent) override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void onDisconnectPointCloudProcessor() override
void changePointCloudProvider(const std::string &providerName, const Ice::Current &c=Ice::emptyCurrent) override
void setRgParameters(float smoothnessThreshold, float curvatureThreshold, const Ice::Current &c=Ice::emptyCurrent) override
void setLccpParameters(const LccpParameters ¶meters, const Ice::Current &c=Ice::emptyCurrent) override
void loadRgParametersFromFile(const std::string &filename, const Ice::Current &c=Ice::emptyCurrent) override
void onInitPointCloudProcessor() override
void createRemoteGuiTab()
armarx::TimestampBasePtr getLastProcessedTimestamp(const Ice::Current &c=Ice::emptyCurrent) override
bool isPipelineStepEnabled(const Ice::Current &c=Ice::emptyCurrent) override
#define ARMARX_INFO
The normal logging level.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
const LogSender::manipulator flush
pcl::PointXYZRGBL PointRGBL
pcl::PointCloud< Point > PointCloud
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})