38 #include <pcl/common/angles.h>
39 #include <pcl/common/geometry.h>
40 #include <pcl/common/intersections.h>
41 #include <pcl/features/moment_of_inertia_estimation.h>
42 #include <pcl/kdtree/kdtree.h>
43 #include <pcl/kdtree/kdtree_flann.h>
45 #include <IceUtil/IceUtil.h>
47 #include <SimoxUtility/algorithm/string/string_tools.h>
51 #include <RobotAPI/interface/core/PoseBase.h>
52 #include <RobotAPI/interface/core/RobotState.h>
53 #include <RobotAPI/interface/visualization/DebugDrawerInterface.h>
58 #include <VisionX/interface/components/PointCloudSegmenter.h>
59 #include <VisionX/interface/components/PrimitiveExtractor.h>
60 #include <VisionX/interface/components/PrimitiveMapper.h>
65 #include <MemoryX/interface/components/WorkingMemoryInterface.h>
74 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);
110 class PrimitiveExtractor;
126 defineOptionalProperty<std::string>(
"segmenterName",
127 "PointCloudSegmenterResult",
128 "name of the segmented point cloud data processor");
131 defineOptionalProperty<double>(
132 "minimumSegmentSize",
134 "Minimum segment size to be considered in the primitive extraction");
135 defineOptionalProperty<double>(
136 "maximumSegmentSize",
138 "Maximum segment size to be considered in the primitive extraction");
139 defineOptionalProperty<double>(
140 "planeMaximumIteration", 100,
"Maximum ransac iteration for plane estimation");
141 defineOptionalProperty<float>(
142 "planeDistanceThreshold", 10.0,
"Distance threshold for plane estimation");
143 defineOptionalProperty<float>(
144 "planeNormalDistance", 0.10,
"Normal distance for plane estimation");
145 defineOptionalProperty<double>(
"cylinderMaximumIteration",
147 "Maximum ransac iteration for cylinder estimation");
148 defineOptionalProperty<float>(
149 "cylinderDistanceThreshold", 0.1,
"Distance threshold for cylinder estimation");
150 defineOptionalProperty<float>(
151 "cylinderRadiousLimit", 0.1,
"Radious limit for cylinder estimation");
152 defineOptionalProperty<double>(
153 "sphereMaximumIteration", 100,
"Maximum ransac iteration for sphere estimation");
154 defineOptionalProperty<float>(
155 "sphereDistanceThreshold", 0.9,
"Distance threshold for sphere estimation");
156 defineOptionalProperty<float>(
157 "sphereNormalDistance", 0.1,
"Normal distance for sphere estimation");
158 defineOptionalProperty<bool>(
159 "vebose",
false,
"Required for debugging the primitive engine");
160 defineOptionalProperty<float>(
"euclideanClusteringTolerance",
162 "Euclidean distance threshold for fine clustering");
163 defineOptionalProperty<float>(
164 "outlierThreshold", 50.0,
"Outlier threshold for computing model outliers");
165 defineOptionalProperty<float>(
166 "circularDistanceThreshold", 0.01,
"Distance threshold for circle estimation");
167 defineOptionalProperty<bool>(
168 "enablePrimitiveFusion",
false,
"Fuse new primitives with existing ones");
169 defineOptionalProperty<bool>(
"UseAffordanceExtractionLibExport",
171 "Use export functionality of affordance extraction lib");
172 defineOptionalProperty<float>(
173 "SpatialSamplingDistance", 50,
"Distance between two spatial samplings in mm");
174 defineOptionalProperty<int>(
175 "NumOrientationalSamplings", 4,
"Number of orientational samplings");
176 defineOptionalProperty<bool>(
177 "EnableBoxPrimitives",
false,
"Toggle detection of box primitives");
179 defineOptionalProperty<std::string>(
182 "the robot node to use as source coordinate system for the captured point clouds");
183 defineOptionalProperty<std::string>(
"SegmentedPointCloudTopicName",
184 "SegmentedPointCloud",
185 "name of SegmentedPointCloud topic");
186 defineOptionalProperty<std::string>(
187 "RobotStateComponentName",
188 "RobotStateComponent",
189 "Name of the robot state component that should be used");
191 defineOptionalProperty<std::string>(
192 "PriorKnowledgeProxyName",
"PriorKnowledge",
"name of prior memory proxy");
193 defineOptionalProperty<std::string>(
194 "WorkingMemoryName",
"WorkingMemory",
"name of WorkingMemory component");
195 defineOptionalProperty<std::string>(
196 "DebugDrawerTopicName",
"DebugDrawerUpdates",
"name of DebugDrawer topic");
197 defineOptionalProperty<std::string>(
"DebugObserverName",
199 "Name of the topic the DebugObserver listens on");
213 virtual public visionx::PrimitiveMapperInterface,
223 return "PrimitiveExtractor";
255 armarx::TimestampBasePtr
258 void setParameters(
const visionx::PrimitiveExtractorParameters& parameters,
259 const Ice::Current&
c = Ice::emptyCurrent)
override;
261 const Ice::Current&
c = Ice::emptyCurrent)
override;
263 visionx::PrimitiveExtractorParameters
264 getParameters(
const Ice::Current&
c = Ice::emptyCurrent)
override;
272 void fusePrimitives(std::vector<memoryx::EntityBasePtr>& newPrimitives,
long timestamp);
274 void extractPrimitives();
275 float getGraspPointInlierRatio(memoryx::EnvironmentalPrimitiveBasePtr leftPrimitive,
276 memoryx::EnvironmentalPrimitiveBasePtr rightPrimitive);
278 void pushPrimitivesToMemory(IceUtil::Int64 originalTimestamp);
279 void pushPrimitivesToMemoryAffordanceKit(IceUtil::Int64 originalTimestamp);
284 bool isConnectedtoExtractor;
285 double minSegmentSize;
286 double maxSegmentSize;
297 float euclideanClusteringTolerance;
298 float outlierThreshold;
299 float circleDistThres;
302 pcl::PointCloud<pcl::PointXYZL>::Ptr labeledCloudPtr;
303 pcl::PointCloud<pcl::PointXYZL>::Ptr inliersCloudPtr;
304 pcl::PointCloud<pcl::PointXYZL>::Ptr graspCloudPtr;
306 std::mutex mutexPushing;
307 std::mutex pointCloudMutex;
308 std::mutex enableMutex;
310 std::mutex timestampMutex;
311 long lastProcessedTimestamp;
313 bool isConnectedtoSegmenter;
315 std::string providerName;
317 memoryx::WorkingMemoryInterfacePrx workingMemory;
318 memoryx::EnvironmentalPrimitiveSegmentBasePrx environmentalPrimitiveSegment;
319 visionx::PointCloudSegmentationListenerPrx pointCloudSegmentationPrx;
321 std::string sourceFrameName;
322 std::string agentName;
329 bool enablePrimitiveFusion;
338 float spatialSamplingDistance;
339 int numOrientationalSamplings;