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 
28 
30 
31 #include <ArmarXCore/interface/observers/ObserverInterface.h>
32 #include <ArmarXCore/interface/observers/RequestableService.h>
33 #include <ArmarXGui/interface/RemoteGuiInterface.h>
35 #include <RobotAPI/interface/visualization/DebugDrawerInterface.h>
36 #include <VisionX/interface/components/TabletopSegmentationInterface.h>
37 
39 
40 #include <pcl/point_types.h>
41 
42 #include <pcl/ModelCoefficients.h>
43 
44 
45 #include <pcl/common/angles.h>
46 
47 #include <pcl/segmentation/sac_segmentation.h>
48 #include <pcl/segmentation/extract_clusters.h>
49 #include <pcl/filters/extract_indices.h>
50 #include <pcl/filters/passthrough.h>
51 
52 #include <pcl/segmentation/extract_polygonal_prism_data.h>
53 #include <pcl/surface/convex_hull.h>
54 
55 
56 
57 namespace armarx
58 {
59 
60  class ServiceProvider : public armarx::RequestableServiceListenerInterface
61  {
62  public:
63  ServiceProvider(const std::string& serviceName, const std::function<void(int)>& callback);
64 
65  // RequestableServiceListenerInterface interface
66  void requestService(const std::string&, Ice::Int relativeTimeoutMs, const Ice::Current&);
67  void setServiceConfig(const std::string&, const StringVariantBaseMap&, const Ice::Current&) {}
68  private:
69  std::string serviceName;
70  std::function<void(int)> callback;
71  };
73 
74  typedef pcl::PointXYZRGBA PointT;
75  typedef pcl::PointXYZRGBL PointL;
76 
77  /**
78  * @class TabletopSegmentationPropertyDefinitions
79  * @brief
80  */
83  {
84  public:
87  {
88  defineOptionalProperty<std::string>("DebugObserverName", "DebugObserver", "Name of the topic the DebugObserver listens on");
89  defineOptionalProperty<std::string>("DebugDrawerTopicName", "DebugDrawerUpdates", "Name of the DebugDrawerTopic");
90  defineOptionalProperty<std::string>("RemoteGuiName", "RemoteGuiProvider", "Name of the remote gui provider");
91  defineOptionalProperty<bool>("AlwaysActive", true, "If enabled the component runs always. Otherwise only when requested via the requestable service interface.", armarx::PropertyDefinitionBase::eModifiable);
92 
93  defineOptionalProperty<double>("DistanceThreshold", 20.0, "The distance threshold for the plane.");
94  defineOptionalProperty<double>("EpsAngle", pcl::deg2rad(10.0), "The eps angle (in rad) for the plane perpendicular to the z-axis. If zero the perpendicular constraint is removed.");
95 
96  defineOptionalProperty<bool>("IncludeTabletopPlane", false, "If enabled the points from the tabletop plane will be added as a separate cluster.");
97  defineOptionalProperty<bool>("CalculatePlane", true, "Calculate plane");
98 
99  defineOptionalProperty<double>("ClusterTolerance", 20.0, "the tolerance used for euclidean cluster extraction.");
100  defineOptionalProperty<int>("MinClusterSize", 100, "The minimum size of a cluster.");
101  defineOptionalProperty<int>("MaxClusterSize", 25000, "The maximum size of a cluster.");
102 
103  defineOptionalProperty<double>("HeightMin", 0.0, "The minimum distance to the plane.");
104  defineOptionalProperty<double>("HeightMax", 500.0, "The maximum distance to the plane.");
105  }
106  };
107 
108  /**
109  * @defgroup Component-TabletopSegmentation TabletopSegmentation
110  * @ingroup VisionX-Components
111  * A description of the component TabletopSegmentation.
112  *
113  * @class TabletopSegmentation
114  * @ingroup Component-TabletopSegmentation
115  * @brief Brief description of class TabletopSegmentation.
116  *
117  * Detailed description of class TabletopSegmentation.
118  */
119 
121  : virtual public visionx::TabletopSegmentationInterface
122  , virtual public visionx::PointCloudProcessor
123  {
124  public:
125  /**
126  * @see armarx::ManagedIceObject::getDefaultName()
127  */
128  std::string getDefaultName() const override
129  {
130  return "TabletopSegmentation";
131  }
132 
133  protected:
134  /**
135  * @see visionx::PointCloudProcessor::onInitPointCloudProcessor()
136  */
137  void onInitPointCloudProcessor() override;
138 
139  /**
140  * @see visionx::PointCloudProcessor::onConnectPointCloudProcessor()
141  */
142  void onConnectPointCloudProcessor() override;
143 
144  /**
145  * @see visionx::PointCloudProcessor::onDisconnectPointCloudProcessor()
146  */
147  void onDisconnectPointCloudProcessor() override;
148 
149  /**
150  * @see visionx::PointCloudProcessor::onExitPointCloudProcessor()
151  */
152  void onExitPointCloudProcessor() override;
153 
154  /**
155  * @see visionx::PointCloudProcessor::process()
156  */
157  void process() override;
158 
159  /**
160  * @see PropertyUser::createPropertyDefinitions()
161  */
163 
164  // TabletopSegmentationInterface interface
165  public:
166  visionx::TabletopSegmentationPlanePtr getTablePlane(const Ice::Current&) override;
167 
168  private:
169  void extractEuclideanClusters(const pcl::PointCloud<PointT>::ConstPtr& inputCloud, const pcl::PointCloud<PointL>::Ptr& resultCloud);
170 
171  void guiTask();
172  void guiCreate();
173  void guiUpdate(armarx::RemoteGui::TabProxy& tab);
174 
175  private:
176  DebugDrawerInterfacePrx debugDrawer;
177  DebugObserverInterfacePrx debugObserver;
178  RemoteGuiInterfacePrx remoteGui;
180 
181  pcl::SACSegmentation<PointT> seg;
182 
183  bool includeTabletopPlane;
184  pcl::EuclideanClusterExtraction<PointT> ec;
185 
186  pcl::ExtractIndices<PointT> extract;
187 
188  pcl::ExtractPolygonalPrismData<PointT> prism;
189  pcl::ConvexHull<PointT> hull;
190 
191  ServiceProviderPtr serviceProvider;
192  IceUtil::Time nextTimeoutAbs;
193 
194  std::mutex tablePlaneMutex;
195  visionx::TabletopSegmentationPlanePtr tablePlane;
196 
197  private: // properties
198  std::mutex prop_mutex;
199 
200  float prop_DistanceThreshold = 20.0;
201  float prop_EpsAngle = pcl::deg2rad(10.0);
202 
203  float prop_ClusterTolerance = 20.0;
204  int prop_MinClusterSize = 100;
205  int prop_MaxClusterSize = 25000;
206 
207  float prop_HeightMin = 0.0;
208  float prop_HeightMax = 500.0;
209 
210  bool prop_IncludeTabletopPlane = false;
211  bool prop_CalculatePlane = true;
212  };
213 }
214 
215 #endif
armarx::TabletopSegmentation::onDisconnectPointCloudProcessor
void onDisconnectPointCloudProcessor() override
Definition: TabletopSegmentation.cpp:109
armarx::ServiceProvider::ServiceProvider
ServiceProvider(const std::string &serviceName, const std::function< void(int)> &callback)
Definition: TabletopSegmentation.cpp:421
armarx::StringVariantBaseMap
std::map< std::string, VariantBasePtr > StringVariantBaseMap
Definition: ManagedIceObject.h:111
armarx::ServiceProvider::setServiceConfig
void setServiceConfig(const std::string &, const StringVariantBaseMap &, const Ice::Current &)
Definition: TabletopSegmentation.h:67
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
armarx::ServiceProvider
Definition: TabletopSegmentation.h:60
armarx::TabletopSegmentation
Brief description of class TabletopSegmentation.
Definition: TabletopSegmentation.h:120
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
armarx::TabletopSegmentationPropertyDefinitions
Definition: TabletopSegmentation.h:81
visionx::PointCloudProcessorPropertyDefinitions::PointCloudProcessorPropertyDefinitions
PointCloudProcessorPropertyDefinitions(std::string prefix)
Definition: PointCloudProcessor.cpp:111
armarx::RemoteGui::TabProxy
Definition: WidgetProxy.h:17
armarx::TabletopSegmentation::getTablePlane
visionx::TabletopSegmentationPlanePtr getTablePlane(const Ice::Current &) override
Definition: TabletopSegmentation.cpp:415
armarx::TabletopSegmentation::process
void process() override
Definition: TabletopSegmentation.cpp:122
visionx::PointCloudProcessor
The PointCloudProcessor class provides an interface for access to PointCloudProviders via Ice and sha...
Definition: PointCloudProcessor.h:186
armarx::TabletopSegmentation::onConnectPointCloudProcessor
void onConnectPointCloudProcessor() override
Definition: TabletopSegmentation.cpp:79
armarx::PointT
pcl::PointXYZRGBL PointT
Definition: Common.h:28
WidgetProxy.h
armarx::TabletopSegmentation::getDefaultName
std::string getDefaultName() const override
Definition: TabletopSegmentation.h:128
visionx::PointCloudProcessorPropertyDefinitions
Properties of PointCloudProcessor.
Definition: PointCloudProcessor.h:173
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:56
Component.h
armarx::TabletopSegmentation::onInitPointCloudProcessor
void onInitPointCloudProcessor() override
Definition: TabletopSegmentation.cpp:64
armarx::ServiceProvider::requestService
void requestService(const std::string &, Ice::Int relativeTimeoutMs, const Ice::Current &)
Definition: TabletopSegmentation.cpp:428
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:916
armarx::PropertyDefinitionBase::eModifiable
@ eModifiable
Definition: PropertyDefinitionInterface.h:57
armarx::TabletopSegmentationPropertyDefinitions::TabletopSegmentationPropertyDefinitions
TabletopSegmentationPropertyDefinitions(std::string prefix)
Definition: TabletopSegmentation.h:85
armarx::PointL
pcl::PointXYZRGBL PointL
Definition: TabletopSegmentation.h:75
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28