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 
49 namespace 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");
89  defineOptionalProperty<std::string>(
90  "DebugDrawerTopicName", "DebugDrawerUpdates", "Name of the DebugDrawerTopic");
91  defineOptionalProperty<std::string>(
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 
99  defineOptionalProperty<double>(
100  "DistanceThreshold", 20.0, "The distance threshold for the plane.");
101  defineOptionalProperty<double>(
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 
113  defineOptionalProperty<double>(
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.");
119  defineOptionalProperty<double>(
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
armarx::TabletopSegmentation::onDisconnectPointCloudProcessor
void onDisconnectPointCloudProcessor() override
Definition: TabletopSegmentation.cpp:108
armarx::ServiceProvider::ServiceProvider
ServiceProvider(const std::string &serviceName, const std::function< void(int)> &callback)
Definition: TabletopSegmentation.cpp:431
armarx::StringVariantBaseMap
std::map< std::string, VariantBasePtr > StringVariantBaseMap
Definition: ManagedIceObject.h:110
armarx::ServiceProvider::setServiceConfig
void setServiceConfig(const std::string &, const StringVariantBaseMap &, const Ice::Current &)
Definition: TabletopSegmentation.h:61
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
armarx::ServiceProvider
Definition: TabletopSegmentation.h:52
armarx::TabletopSegmentation
Brief description of class TabletopSegmentation.
Definition: TabletopSegmentation.h:136
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:345
armarx::TabletopSegmentationPropertyDefinitions
Definition: TabletopSegmentation.h:79
visionx::PointCloudProcessorPropertyDefinitions::PointCloudProcessorPropertyDefinitions
PointCloudProcessorPropertyDefinitions(std::string prefix)
Definition: PointCloudProcessor.cpp:121
armarx::RemoteGui::TabProxy
Definition: WidgetProxy.h:17
armarx::TabletopSegmentation::getTablePlane
visionx::TabletopSegmentationPlanePtr getTablePlane(const Ice::Current &) override
Definition: TabletopSegmentation.cpp:425
armarx::TabletopSegmentation::process
void process() override
Definition: TabletopSegmentation.cpp:123
visionx::PointCloudProcessor
The PointCloudProcessor class provides an interface for access to PointCloudProviders via Ice and sha...
Definition: PointCloudProcessor.h:177
armarx::TabletopSegmentation::onConnectPointCloudProcessor
void onConnectPointCloudProcessor() override
Definition: TabletopSegmentation.cpp:76
armarx::PointT
pcl::PointXYZRGBL PointT
Definition: Common.h:30
WidgetProxy.h
armarx::TabletopSegmentation::getDefaultName
std::string getDefaultName() const override
Definition: TabletopSegmentation.h:145
visionx::PointCloudProcessorPropertyDefinitions
Properties of PointCloudProcessor.
Definition: PointCloudProcessor.h:166
PointCloudProcessor.h
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::TabletopSegmentation::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: TabletopSegmentation.cpp:51
Component.h
armarx::TabletopSegmentation::onInitPointCloudProcessor
void onInitPointCloudProcessor() override
Definition: TabletopSegmentation.cpp:58
armarx::ServiceProvider::requestService
void requestService(const std::string &, Ice::Int relativeTimeoutMs, const Ice::Current &)
Definition: TabletopSegmentation.cpp:438
IceUtil::Handle< ServiceProvider >
armarx::TabletopSegmentation::onExitPointCloudProcessor
void onExitPointCloudProcessor() override
Definition: TabletopSegmentation.cpp:118
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
armarx::VariantType::Int
const VariantTypeId Int
Definition: Variant.h:917
armarx::PropertyDefinitionBase::eModifiable
@ eModifiable
Definition: PropertyDefinitionInterface.h:57
armarx::TabletopSegmentationPropertyDefinitions::TabletopSegmentationPropertyDefinitions
TabletopSegmentationPropertyDefinitions(std::string prefix)
Definition: TabletopSegmentation.h:83
armarx::PointL
pcl::PointXYZRGBL PointL
Definition: TabletopSegmentation.h:73
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27