TabletopSegmentation.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package ActiveVision::ArmarXObjects::TabletopSegmentation
17 * @author Markus Grotz ( markus dot grotz at kit dot edu )
18 * @date 2018
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23#ifndef _ARMARX_COMPONENT_ActiveVision_TabletopSegmentation_H
24#define _ARMARX_COMPONENT_ActiveVision_TabletopSegmentation_H
25
26
27#include <pcl/ModelCoefficients.h>
28#include <pcl/common/angles.h>
29#include <pcl/filters/extract_indices.h>
30#include <pcl/filters/passthrough.h>
31#include <pcl/point_types.h>
32#include <pcl/segmentation/extract_clusters.h>
33#include <pcl/segmentation/extract_polygonal_prism_data.h>
34#include <pcl/segmentation/sac_segmentation.h>
35#include <pcl/surface/convex_hull.h>
36
38#include <ArmarXCore/interface/observers/ObserverInterface.h>
39#include <ArmarXCore/interface/observers/RequestableService.h>
40
41#include <ArmarXGui/interface/RemoteGuiInterface.h>
43
44#include <RobotAPI/interface/visualization/DebugDrawerInterface.h>
45
47#include <VisionX/interface/components/TabletopSegmentationInterface.h>
48
49namespace armarx
50{
51
52 class ServiceProvider : public armarx::RequestableServiceListenerInterface
53 {
54 public:
55 ServiceProvider(const std::string& serviceName, const std::function<void(int)>& callback);
56
57 // RequestableServiceListenerInterface interface
58 void requestService(const std::string&, Ice::Int relativeTimeoutMs, const Ice::Current&);
59
60 void
61 setServiceConfig(const std::string&, const StringVariantBaseMap&, const Ice::Current&)
62 {
63 }
64
65 private:
66 std::string serviceName;
67 std::function<void(int)> callback;
68 };
69
71
72 typedef pcl::PointXYZRGBA PointT;
73 typedef pcl::PointXYZRGBL PointL;
74
75 /**
76 * @class TabletopSegmentationPropertyDefinitions
77 * @brief
78 */
81 {
82 public:
85 {
86 defineOptionalProperty<std::string>("DebugObserverName",
87 "DebugObserver",
88 "Name of the topic the DebugObserver listens on");
90 "DebugDrawerTopicName", "DebugDrawerUpdates", "Name of the DebugDrawerTopic");
92 "RemoteGuiName", "RemoteGuiProvider", "Name of the remote gui provider");
93 defineOptionalProperty<bool>("AlwaysActive",
94 true,
95 "If enabled the component runs always. Otherwise only "
96 "when requested via the requestable service interface.",
98
100 "DistanceThreshold", 20.0, "The distance threshold for the plane.");
102 "EpsAngle",
103 pcl::deg2rad(10.0),
104 "The eps angle (in rad) for the plane perpendicular to the z-axis. If zero the "
105 "perpendicular constraint is removed.");
106
107 defineOptionalProperty<bool>("IncludeTabletopPlane",
108 false,
109 "If enabled the points from the tabletop plane will be "
110 "added as a separate cluster.");
111 defineOptionalProperty<bool>("CalculatePlane", true, "Calculate plane");
112
114 "ClusterTolerance", 20.0, "the tolerance used for euclidean cluster extraction.");
115 defineOptionalProperty<int>("MinClusterSize", 100, "The minimum size of a cluster.");
116 defineOptionalProperty<int>("MaxClusterSize", 25000, "The maximum size of a cluster.");
117
118 defineOptionalProperty<double>("HeightMin", 0.0, "The minimum distance to the plane.");
120 "HeightMax", 500.0, "The maximum distance to the plane.");
121 }
122 };
123
124 /**
125 * @defgroup Component-TabletopSegmentation TabletopSegmentation
126 * @ingroup VisionX-Components
127 * A description of the component TabletopSegmentation.
128 *
129 * @class TabletopSegmentation
130 * @ingroup Component-TabletopSegmentation
131 * @brief Brief description of class TabletopSegmentation.
132 *
133 * Detailed description of class TabletopSegmentation.
134 */
135
137 virtual public visionx::TabletopSegmentationInterface,
138 virtual public visionx::PointCloudProcessor
139 {
140 public:
141 /**
142 * @see armarx::ManagedIceObject::getDefaultName()
143 */
144 static std::string GetDefaultName();
145 std::string getDefaultName() const override;
146
147 protected:
148 /**
149 * @see visionx::PointCloudProcessor::onInitPointCloudProcessor()
150 */
151 void onInitPointCloudProcessor() override;
152
153 /**
154 * @see visionx::PointCloudProcessor::onConnectPointCloudProcessor()
155 */
156 void onConnectPointCloudProcessor() override;
157
158 /**
159 * @see visionx::PointCloudProcessor::onDisconnectPointCloudProcessor()
160 */
161 void onDisconnectPointCloudProcessor() override;
162
163 /**
164 * @see visionx::PointCloudProcessor::onExitPointCloudProcessor()
165 */
166 void onExitPointCloudProcessor() override;
167
168 /**
169 * @see visionx::PointCloudProcessor::process()
170 */
171 void process() override;
172
173 /**
174 * @see PropertyUser::createPropertyDefinitions()
175 */
177
178 // TabletopSegmentationInterface interface
179 public:
180 visionx::TabletopSegmentationPlanePtr getTablePlane(const Ice::Current&) override;
181
182 private:
183 void extractEuclideanClusters(const pcl::PointCloud<PointT>::ConstPtr& inputCloud,
184 const pcl::PointCloud<PointL>::Ptr& resultCloud);
185
186 void guiTask();
187 void guiCreate();
188 void guiUpdate(armarx::RemoteGui::TabProxy& tab);
189
190 private:
191 DebugDrawerInterfacePrx debugDrawer;
192 DebugObserverInterfacePrx debugObserver;
193 RemoteGuiInterfacePrx remoteGui;
195
196 pcl::SACSegmentation<PointT> seg;
197
198 bool includeTabletopPlane;
199 pcl::EuclideanClusterExtraction<PointT> ec;
200
201 pcl::ExtractIndices<PointT> extract;
202
203 pcl::ExtractPolygonalPrismData<PointT> prism;
204 pcl::ConvexHull<PointT> hull;
205
206 ServiceProviderPtr serviceProvider;
207 IceUtil::Time nextTimeoutAbs;
208
209 std::mutex tablePlaneMutex;
210 visionx::TabletopSegmentationPlanePtr tablePlane;
211
212 private: // properties
213 std::mutex prop_mutex;
214
215 float prop_DistanceThreshold = 20.0;
216 float prop_EpsAngle = pcl::deg2rad(10.0);
217
218 float prop_ClusterTolerance = 20.0;
219 int prop_MinClusterSize = 100;
220 int prop_MaxClusterSize = 25000;
221
222 float prop_HeightMin = 0.0;
223 float prop_HeightMax = 500.0;
224
225 bool prop_IncludeTabletopPlane = false;
226 bool prop_CalculatePlane = true;
227 };
228} // namespace armarx
229
230#endif
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)
IceUtil::Handle< RunningTask< T > > pointer_type
Shared pointer type for convenience.
void setServiceConfig(const std::string &, const StringVariantBaseMap &, const Ice::Current &)
ServiceProvider(const std::string &serviceName, const std::function< void(int)> &callback)
void requestService(const std::string &, Ice::Int relativeTimeoutMs, const Ice::Current &)
Brief description of class TabletopSegmentation.
visionx::TabletopSegmentationPlanePtr getTablePlane(const Ice::Current &) override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
std::string getDefaultName() const override
Retrieve default name of component.
The PointCloudProcessor class provides an interface for access to PointCloudProviders via Ice and sha...
This file offers overloads of toIce() and fromIce() functions for STL container types.
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugObserverInterface > DebugObserverInterfacePrx
std::map< std::string, VariantBasePtr > StringVariantBaseMap
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
IceUtil::Handle< ServiceProvider > ServiceProviderPtr
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface > DebugDrawerInterfacePrx
pcl::PointXYZRGBL PointL
pcl::PointXYZRGBL PointT
Definition Common.h:30
ArmarX headers.