34 #include <IceUtil/IceUtil.h>
40 #include <RobotAPI/interface/core/PoseBase.h>
41 #include <RobotAPI/interface/core/RobotState.h>
43 #include <RobotAPI/interface/visualization/DebugDrawerInterface.h>
46 #include <MemoryX/interface/components/WorkingMemoryInterface.h>
52 #include <VisionX/interface/components/PointCloudSegmenter.h>
53 #include <VisionX/interface/components/PrimitiveExtractor.h>
54 #include <VisionX/interface/components/PrimitiveMapper.h>
56 #include <pcl/features/moment_of_inertia_estimation.h>
57 #include <pcl/common/angles.h>
58 #include <pcl/kdtree/kdtree.h>
59 #include <pcl/kdtree/kdtree_flann.h>
60 #include <pcl/common/intersections.h>
61 #include <pcl/common/geometry.h>
66 #include <SimoxUtility/algorithm/string/string_tools.h>
74 void print(pcl::console::VERBOSITY_LEVEL level,
const char* format, ...)
78 va_list args, args_copy;
79 va_start(args, format);
80 va_copy(args_copy, args);
82 int size = std::vsnprintf(
nullptr, 0, format, args) + 1;
83 message = std::string(size,
' ');
84 std::vsnprintf(&
message.front(), size, format, args_copy);
111 class PrimitiveExtractor;
128 defineOptionalProperty<std::string>(
"segmenterName",
"PointCloudSegmenterResult",
"name of the segmented point cloud data processor");
131 defineOptionalProperty<double>(
"minimumSegmentSize", 100,
"Minimum segment size to be considered in the primitive extraction");
132 defineOptionalProperty<double>(
"maximumSegmentSize", 75000,
"Maximum segment size to be considered in the primitive extraction");
133 defineOptionalProperty<double>(
"planeMaximumIteration", 100,
"Maximum ransac iteration for plane estimation");
134 defineOptionalProperty<float>(
"planeDistanceThreshold", 10.0,
"Distance threshold for plane estimation");
135 defineOptionalProperty<float>(
"planeNormalDistance", 0.10,
"Normal distance for plane estimation");
136 defineOptionalProperty<double>(
"cylinderMaximumIteration", 100,
"Maximum ransac iteration for cylinder estimation");
137 defineOptionalProperty<float>(
"cylinderDistanceThreshold", 0.1,
"Distance threshold for cylinder estimation");
138 defineOptionalProperty<float>(
"cylinderRadiousLimit", 0.1,
"Radious limit for cylinder estimation");
139 defineOptionalProperty<double>(
"sphereMaximumIteration", 100,
"Maximum ransac iteration for sphere estimation");
140 defineOptionalProperty<float>(
"sphereDistanceThreshold", 0.9,
"Distance threshold for sphere estimation");
141 defineOptionalProperty<float>(
"sphereNormalDistance", 0.1,
"Normal distance for sphere estimation");
142 defineOptionalProperty<bool>(
"vebose",
false,
"Required for debugging the primitive engine");
143 defineOptionalProperty<float>(
"euclideanClusteringTolerance", 50.0,
"Euclidean distance threshold for fine clustering");
144 defineOptionalProperty<float>(
"outlierThreshold", 50.0,
"Outlier threshold for computing model outliers");
145 defineOptionalProperty<float>(
"circularDistanceThreshold", 0.01,
"Distance threshold for circle estimation");
146 defineOptionalProperty<bool>(
"enablePrimitiveFusion",
false,
"Fuse new primitives with existing ones");
147 defineOptionalProperty<bool>(
"UseAffordanceExtractionLibExport",
false,
"Use export functionality of affordance extraction lib");
148 defineOptionalProperty<float>(
"SpatialSamplingDistance", 50,
"Distance between two spatial samplings in mm");
149 defineOptionalProperty<int>(
"NumOrientationalSamplings", 4,
"Number of orientational samplings");
150 defineOptionalProperty<bool>(
"EnableBoxPrimitives",
false,
"Toggle detection of box primitives");
152 defineOptionalProperty<std::string>(
"sourceFrameName",
"DepthCamera",
"the robot node to use as source coordinate system for the captured point clouds");
153 defineOptionalProperty<std::string>(
"SegmentedPointCloudTopicName",
"SegmentedPointCloud",
"name of SegmentedPointCloud topic");
154 defineOptionalProperty<std::string>(
"RobotStateComponentName",
"RobotStateComponent",
"Name of the robot state component that should be used");
156 defineOptionalProperty<std::string>(
"PriorKnowledgeProxyName",
"PriorKnowledge",
"name of prior memory proxy");
157 defineOptionalProperty<std::string>(
"WorkingMemoryName",
"WorkingMemory",
"name of WorkingMemory component");
158 defineOptionalProperty<std::string>(
"DebugDrawerTopicName",
"DebugDrawerUpdates",
"name of DebugDrawer topic");
159 defineOptionalProperty<std::string>(
"DebugObserverName",
"DebugObserver",
"Name of the topic the DebugObserver listens on");
173 virtual public visionx::PrimitiveMapperInterface,
182 return "PrimitiveExtractor";
216 void setParameters(
const visionx::PrimitiveExtractorParameters& parameters,
const Ice::Current&
c = Ice::emptyCurrent)
override;
219 visionx::PrimitiveExtractorParameters
getParameters(
const Ice::Current&
c = Ice::emptyCurrent)
override;
228 void fusePrimitives(std::vector<memoryx::EntityBasePtr>& newPrimitives,
long timestamp);
230 void extractPrimitives();
231 float getGraspPointInlierRatio(memoryx::EnvironmentalPrimitiveBasePtr leftPrimitive, memoryx::EnvironmentalPrimitiveBasePtr rightPrimitive);
233 void pushPrimitivesToMemory(IceUtil::Int64 originalTimestamp);
234 void pushPrimitivesToMemoryAffordanceKit(IceUtil::Int64 originalTimestamp);
239 bool isConnectedtoExtractor;
240 double minSegmentSize;
241 double maxSegmentSize;
252 float euclideanClusteringTolerance;
253 float outlierThreshold;
254 float circleDistThres;
257 pcl::PointCloud<pcl::PointXYZL>::Ptr labeledCloudPtr;
258 pcl::PointCloud<pcl::PointXYZL>::Ptr inliersCloudPtr;
259 pcl::PointCloud<pcl::PointXYZL>::Ptr graspCloudPtr;
261 std::mutex mutexPushing;
262 std::mutex pointCloudMutex;
263 std::mutex enableMutex;
265 std::mutex timestampMutex;
266 long lastProcessedTimestamp;
268 bool isConnectedtoSegmenter;
270 std::string providerName;
272 memoryx::WorkingMemoryInterfacePrx workingMemory;
273 memoryx::EnvironmentalPrimitiveSegmentBasePrx environmentalPrimitiveSegment;
274 visionx::PointCloudSegmentationListenerPrx pointCloudSegmentationPrx;
276 std::string sourceFrameName;
277 std::string agentName;
284 bool enablePrimitiveFusion;
293 float spatialSamplingDistance;
294 int numOrientationalSamplings;