PointCloudSegmenter.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package VisionX
19  * @author Eren Aksoy ( eren dot aksoy at kit dot edu )
20  * @date 2015
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 #pragma once
26 
27 #include <mutex>
28 
29 #include <Eigen/Core>
30 
31 #include <pcl/common/transforms.h>
32 #include <pcl/correspondence.h>
33 #include <pcl/features/fpfh_omp.h>
34 #include <pcl/features/normal_3d_omp.h>
35 #include <pcl/filters/filter.h>
36 #include <pcl/filters/passthrough.h>
37 #include <pcl/io/pcd_io.h>
38 #include <pcl/kdtree/kdtree_flann.h>
39 #include <pcl/point_types.h>
40 #include <pcl/recognition/cg/geometric_consistency.h>
41 #include <pcl/search/kdtree.h>
42 
45 
47 
48 #include <RobotAPI/interface/visualization/DebugDrawerInterface.h>
49 
51 #include <VisionX/interface/components/DeepSegmenterInterface.h>
52 #include <VisionX/interface/components/PointCloudSegmenter.h>
53 
54 #include "Deep_Segmenter.h"
56 #include "LCCP_Segmenter.h"
57 #include "RG_Segmenter.h"
58 #include <Image/ByteImage.h>
59 
60 namespace visionx
61 {
62  using PointO = pcl::PointXYZRGBA;
63  using PointOPtr = pcl::PointCloud<PointO>::Ptr;
64  using PointL = pcl::PointXYZL;
65  using PointLPtr = pcl::PointCloud<PointL>::Ptr;
66  using PointRGBL = pcl::PointXYZRGBL;
67  using PointRGBLPtr = pcl::PointCloud<PointRGBL>::Ptr;
68 
69  using namespace armarx::RemoteGui::Client;
70 
72  {
75  };
76 
77  /**
78  * @class PointCloudSegmenterPropertyDefinitions
79  * @brief
80  */
83  {
84  public:
87  {
88  // General parameters
89  defineOptionalProperty<std::string>(
90  "DebugDrawerTopicName", "DebugDrawerUpdates", "Name of the debug drawer topic");
91  defineOptionalProperty<std::string>("DeepSegmenterTopicName",
92  "DeepSegmenterPythonUpdates",
93  "Name of the deep segmenter topic");
94  defineOptionalProperty<std::string>(
95  "segmentationMethod",
96  "EC",
97  "Name of the offered segmentation method (EC, LCCP or RG)");
98  defineOptionalProperty<bool>(
99  "StartEnabled", true, "Enable or disable the segmentation by default");
100  defineOptionalProperty<bool>(
101  "SingleRun", false, "Segment only one scene after each enable call");
102 
103  // LCCP parameters
104  defineOptionalProperty<int>("lccpMinimumSegmentSize",
105  10,
106  "Minimum segment size required for the lccp segmentation");
107  defineOptionalProperty<float>(
108  "lccpVoxelResolution",
109  25,
110  "Supervoxel resolution required for the lccp segmentation");
111  defineOptionalProperty<float>(
112  "lccpSeedResolution", 80, "Seed resolution required for the lccp segmentation");
113  defineOptionalProperty<float>(
114  "lccpColorImportance", 0.0, "Color importance required for the lccp segmentation");
115  defineOptionalProperty<float>("lccpSpatialImportance",
116  1.0,
117  "Spatial importance required for the lccp segmentation");
118  defineOptionalProperty<float>("lccpNormalImportance",
119  4.0,
120  "Normal importance required for the lccp segmentation");
121  defineOptionalProperty<float>("lccpConcavityThreshold",
122  10.0,
123  "Concavity threshold required for the lccp segmentation");
124  defineOptionalProperty<float>(
125  "lccpSmoothnessThreshold",
126  0.1,
127  "Smoothness threshold required for the lccp segmentation");
128 
129  // RG parameters
130  defineOptionalProperty<float>(
131  "rgSmoothnessThreshold",
132  6.0,
133  "Smoothness threshold required for the region growing segmentation");
134  defineOptionalProperty<float>(
135  "rgCurvatureThreshold",
136  50.0,
137  "Curvature threshold required for the region growing segmentation");
138 
139  // Debug parameters
140  defineOptionalProperty<bool>(
141  "VisualizeCropBox", false, "Visualize crop box via debug drawer");
142  }
143  };
144 
145  /**
146  * @class PointCloudSegmenter
147  *
148  * @ingroup VisionX-Components
149  * @brief A brief description
150  *
151  *
152  * Detailed Description
153  */
155  virtual public PointCloudSegmenterInterface,
156  virtual public PointCloudProcessor,
158  {
159  public:
161 
162  /**
163  * @see armarx::ManagedIceObject::getDefaultName()
164  */
165  std::string
166  getDefaultName() const override
167  {
168  return "PointCloudSegmenter";
169  }
170 
171  void changePointCloudProvider(const std::string& providerName,
172  const Ice::Current& c = Ice::emptyCurrent) override;
173 
174  protected:
175  /**
176  * @see visionx::PointCloudProcessor::onInitPointCloudProcessor()
177  */
178  void onInitPointCloudProcessor() override;
179 
180  /**
181  * @see visionx::PointCloudProcessor::onConnectPointCloudProcessor()
182  */
183  void onConnectPointCloudProcessor() override;
184 
185  /**
186  * @see visionx::PointCloudProcessor::onDisconnectPointCloudProcessor()
187  */
188  void onDisconnectPointCloudProcessor() override;
189 
190  /**
191  * @see visionx::PointCloudProcessor::onExitPointCloudProcessor()
192  */
193  void onExitPointCloudProcessor() override;
194 
195  /**
196  * @see visionx::PointCloudProcessor::process()
197  */
198  void process() override;
199 
200  /**
201  * @see PropertyUser::createPropertyDefinitions()
202  */
203  armarx::PropertyDefinitionsPtr createPropertyDefinitions() override;
204 
205  void enablePipelineStep(const Ice::Current& c = Ice::emptyCurrent) override;
206  void disablePipelineStep(const Ice::Current& c = Ice::emptyCurrent) override;
207  bool isPipelineStepEnabled(const Ice::Current& c = Ice::emptyCurrent) override;
208  armarx::TimestampBasePtr
209  getLastProcessedTimestamp(const Ice::Current& c = Ice::emptyCurrent) override;
210 
211  void setLccpParameters(const LccpParameters& parameters,
212  const Ice::Current& c = Ice::emptyCurrent) override;
213  void loadLccpParametersFromFile(const std::string& filename,
214  const Ice::Current& c = Ice::emptyCurrent) override;
215 
216  LccpParameters getLccpParameters(const Ice::Current& c = Ice::emptyCurrent) override;
217 
218  void setRgParameters(float smoothnessThreshold,
219  float curvatureThreshold,
220  const Ice::Current& c = Ice::emptyCurrent) override;
221  void loadRgParametersFromFile(const std::string& filename,
222  const Ice::Current& c = Ice::emptyCurrent) override;
223 
224  void createRemoteGuiTab();
225  void RemoteGui_update() override;
226 
227  private:
228  void convertFromXYZRGBAtoXYZL(pcl::PointCloud<pcl::PointXYZRGBA>::Ptr& sourceCloudPtr,
229  pcl::PointCloud<pcl::PointXYZL>::Ptr& targetCloudPtr);
230  void pushColoredLabeledCloudtoBuffer();
231 
232  private:
233  LCCPSegClass* pLCCP;
234  RGSegClass* pRGSegmenter;
235  EuclideanBasedClustering* pECSegmenter;
236  DeepSegClass* pDeepSegmenter;
237 
238  PointOPtr inputCloudPtr;
239  PointRGBLPtr labeledColoredCloudPtr;
240 
241  std::mutex timestampMutex;
242  long lastProcessedTimestamp;
243 
244  std::mutex enableMutex;
245  bool enabled;
246 
247  std::mutex providerMutex;
248  std::string providerName;
249  std::string segmentationMethod;
250 
251  // LCCP segmentation parameters
252  uint32_t minSegSize;
253  float voxelRes;
254  float seedRes;
255  float colorImp;
256  float spatialImp;
257  float normalImp;
258  float concavityThres;
259  float smoothnessThes;
260 
261  // RG segmentation parameters
262  float rgSmoothnessThes;
263  float rgCurvatureThres;
264 
265  void colorizeLabeledCloud();
266 
267  armarx::DebugDrawerInterfacePrx debugDrawerTopic;
268  armarx::DeepSegmenterInterfacePrx deepSegmenterTopic;
269  armarx::Blob rgbImage;
270 
272  };
273 } // namespace visionx
EuclideanBasedClustering
Definition: EuclideanBasedClustering.h:41
visionx::PointCloudSegmenter
A brief description.
Definition: PointCloudSegmenter.h:154
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::PointCloudSegmenterPropertyDefinitions
Definition: PointCloudSegmenter.h:81
LCCP_Segmenter.h
visionx::PointLPtr
pcl::PointCloud< PointL >::Ptr PointLPtr
Definition: PointCloudSegmenter.h:65
armarx::RemoteGui::Client::Tab
Definition: Tab.h:15
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
visionx::PointRGBL
pcl::PointXYZRGBL PointRGBL
Definition: PointCloudSegmenter.h:66
visionx::PointOPtr
pcl::PointCloud< PointO >::Ptr PointOPtr
Definition: PointCloudSegmenter.h:63
RGSegClass
Definition: RG_Segmenter.h:38
visionx::PointCloudSegmenterTab::rgSmoothnessThreshold
FloatSpinBox rgSmoothnessThreshold
Definition: PointCloudSegmenter.h:73
LightweightRemoteGuiComponentPlugin.h
visionx::PointCloudProcessor
The PointCloudProcessor class provides an interface for access to PointCloudProviders via Ice and sha...
Definition: PointCloudProcessor.h:177
enabled
std::atomic< bool > * enabled
Definition: RemoteGuiWidgetController.cpp:75
filename
std::string filename
Definition: VisualizationRobot.cpp:86
DeepSegClass
Definition: Deep_Segmenter.h:40
visionx::PointCloudProcessorPropertyDefinitions
Properties of PointCloudProcessor.
Definition: PointCloudProcessor.h:166
PointCloudProcessor.h
visionx::PointCloudSegmenterPropertyDefinitions::PointCloudSegmenterPropertyDefinitions
PointCloudSegmenterPropertyDefinitions(std::string prefix)
Definition: PointCloudSegmenter.h:85
armarx::LightweightRemoteGuiComponentPluginUser
Definition: LightweightRemoteGuiComponentPlugin.h:72
LCCPSegClass
Definition: LCCP_Segmenter.h:49
Component.h
RG_Segmenter.h
visionx::PointL
pcl::PointXYZRGBL PointL
Definition: MaskRCNNPointCloudObjectLocalizer.h:78
IceUtil::Handle< class PropertyDefinitionContainer >
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
visionx::PointCloudSegmenterTab::rgCurvatureThreshold
FloatSpinBox rgCurvatureThreshold
Definition: PointCloudSegmenter.h:74
Deep_Segmenter.h
visionx::PointCloudSegmenter::getDefaultName
std::string getDefaultName() const override
Definition: PointCloudSegmenter.h:166
visionx::PointO
pcl::PointXYZRGBA PointO
Definition: PointCloudSegmenter.h:62
armarx::RemoteGui::Client
Definition: EigenWidgets.cpp:8
ArmarXDataPath.h
armarx::RemoteGui::Client::FloatSpinBox
Definition: Widgets.h:93
visionx::PointCloudSegmenterTab
Definition: PointCloudSegmenter.h:71
EuclideanBasedClustering.h
visionx::PointRGBLPtr
pcl::PointCloud< PointRGBL >::Ptr PointRGBLPtr
Definition: PointCloudSegmenter.h:67