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 std::string
145 getDefaultName() const override
146 {
147 return "TabletopSegmentation";
148 }
149
150 protected:
151 /**
152 * @see visionx::PointCloudProcessor::onInitPointCloudProcessor()
153 */
154 void onInitPointCloudProcessor() override;
155
156 /**
157 * @see visionx::PointCloudProcessor::onConnectPointCloudProcessor()
158 */
159 void onConnectPointCloudProcessor() override;
160
161 /**
162 * @see visionx::PointCloudProcessor::onDisconnectPointCloudProcessor()
163 */
164 void onDisconnectPointCloudProcessor() override;
165
166 /**
167 * @see visionx::PointCloudProcessor::onExitPointCloudProcessor()
168 */
169 void onExitPointCloudProcessor() override;
170
171 /**
172 * @see visionx::PointCloudProcessor::process()
173 */
174 void process() override;
175
176 /**
177 * @see PropertyUser::createPropertyDefinitions()
178 */
180
181 // TabletopSegmentationInterface interface
182 public:
183 visionx::TabletopSegmentationPlanePtr getTablePlane(const Ice::Current&) override;
184
185 private:
186 void extractEuclideanClusters(const pcl::PointCloud<PointT>::ConstPtr& inputCloud,
187 const pcl::PointCloud<PointL>::Ptr& resultCloud);
188
189 void guiTask();
190 void guiCreate();
191 void guiUpdate(armarx::RemoteGui::TabProxy& tab);
192
193 private:
194 DebugDrawerInterfacePrx debugDrawer;
195 DebugObserverInterfacePrx debugObserver;
196 RemoteGuiInterfacePrx remoteGui;
198
199 pcl::SACSegmentation<PointT> seg;
200
201 bool includeTabletopPlane;
202 pcl::EuclideanClusterExtraction<PointT> ec;
203
204 pcl::ExtractIndices<PointT> extract;
205
206 pcl::ExtractPolygonalPrismData<PointT> prism;
207 pcl::ConvexHull<PointT> hull;
208
209 ServiceProviderPtr serviceProvider;
210 IceUtil::Time nextTimeoutAbs;
211
212 std::mutex tablePlaneMutex;
213 visionx::TabletopSegmentationPlanePtr tablePlane;
214
215 private: // properties
216 std::mutex prop_mutex;
217
218 float prop_DistanceThreshold = 20.0;
219 float prop_EpsAngle = pcl::deg2rad(10.0);
220
221 float prop_ClusterTolerance = 20.0;
222 int prop_MinClusterSize = 100;
223 int prop_MaxClusterSize = 25000;
224
225 float prop_HeightMin = 0.0;
226 float prop_HeightMax = 500.0;
227
228 bool prop_IncludeTabletopPlane = false;
229 bool prop_CalculatePlane = true;
230 };
231} // namespace armarx
232
233#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
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.