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 <Eigen/Core>
28 
31 
33 
34 #include <RobotAPI/interface/visualization/DebugDrawerInterface.h>
35 #include <VisionX/interface/components/DeepSegmenterInterface.h>
36 
38 #include <VisionX/interface/components/PointCloudSegmenter.h>
39 
40 #include <pcl/filters/filter.h>
41 #include <pcl/filters/passthrough.h>
42 #include <pcl/common/transforms.h>
43 #include <pcl/io/pcd_io.h>
44 #include <pcl/point_types.h>
45 #include <pcl/features/normal_3d_omp.h>
46 #include <pcl/features/fpfh_omp.h>
47 #include <pcl/search/kdtree.h>
48 #include <pcl/kdtree/kdtree_flann.h>
49 #include <pcl/correspondence.h>
50 #include <pcl/recognition/cg/geometric_consistency.h>
51 
52 #include "LCCP_Segmenter.h"
54 #include "RG_Segmenter.h"
55 #include "Deep_Segmenter.h"
56 
57 #include <Image/ByteImage.h>
58 
59 #include <mutex>
60 
61 namespace visionx
62 {
63  using PointO = pcl::PointXYZRGBA;
64  using PointOPtr = pcl::PointCloud<PointO>::Ptr;
65  using PointL = pcl::PointXYZL;
66  using PointLPtr = pcl::PointCloud<PointL>::Ptr;
67  using PointRGBL = pcl::PointXYZRGBL;
68  using PointRGBLPtr = pcl::PointCloud<PointRGBL>::Ptr;
69 
70  using namespace armarx::RemoteGui::Client;
72  {
75  };
76 
77  /**
78  * @class PointCloudSegmenterPropertyDefinitions
79  * @brief
80  */
83  {
84  public:
87  {
88  // General parameters
89  defineOptionalProperty<std::string>("DebugDrawerTopicName", "DebugDrawerUpdates", "Name of the debug drawer topic");
90  defineOptionalProperty<std::string>("DeepSegmenterTopicName", "DeepSegmenterPythonUpdates", "Name of the deep segmenter topic");
91  defineOptionalProperty<std::string>("segmentationMethod", "EC", "Name of the offered segmentation method (EC, LCCP or RG)");
92  defineOptionalProperty<bool>("StartEnabled", true, "Enable or disable the segmentation by default");
93  defineOptionalProperty<bool>("SingleRun", false, "Segment only one scene after each enable call");
94 
95  // LCCP parameters
96  defineOptionalProperty<int>("lccpMinimumSegmentSize", 10, "Minimum segment size required for the lccp segmentation");
97  defineOptionalProperty<float>("lccpVoxelResolution", 25, "Supervoxel resolution required for the lccp segmentation");
98  defineOptionalProperty<float>("lccpSeedResolution", 80, "Seed resolution required for the lccp segmentation");
99  defineOptionalProperty<float>("lccpColorImportance", 0.0, "Color importance required for the lccp segmentation");
100  defineOptionalProperty<float>("lccpSpatialImportance", 1.0, "Spatial importance required for the lccp segmentation");
101  defineOptionalProperty<float>("lccpNormalImportance", 4.0, "Normal importance required for the lccp segmentation");
102  defineOptionalProperty<float>("lccpConcavityThreshold", 10.0, "Concavity threshold required for the lccp segmentation");
103  defineOptionalProperty<float>("lccpSmoothnessThreshold", 0.1, "Smoothness threshold required for the lccp segmentation");
104 
105  // RG parameters
106  defineOptionalProperty<float>("rgSmoothnessThreshold", 6.0, "Smoothness threshold required for the region growing segmentation");
107  defineOptionalProperty<float>("rgCurvatureThreshold", 50.0, "Curvature threshold required for the region growing segmentation");
108 
109  // Debug parameters
110  defineOptionalProperty<bool>("VisualizeCropBox", false, "Visualize crop box via debug drawer");
111  }
112  };
113 
114  /**
115  * @class PointCloudSegmenter
116  *
117  * @ingroup VisionX-Components
118  * @brief A brief description
119  *
120  *
121  * Detailed Description
122  */
124  : virtual public PointCloudSegmenterInterface
125  , virtual public PointCloudProcessor
127  {
128  public:
130 
131  /**
132  * @see armarx::ManagedIceObject::getDefaultName()
133  */
134  std::string getDefaultName() const override
135  {
136  return "PointCloudSegmenter";
137  }
138 
139  void changePointCloudProvider(const std::string& providerName, const Ice::Current& c = Ice::emptyCurrent) override;
140 
141  protected:
142  /**
143  * @see visionx::PointCloudProcessor::onInitPointCloudProcessor()
144  */
145  void onInitPointCloudProcessor() override;
146 
147  /**
148  * @see visionx::PointCloudProcessor::onConnectPointCloudProcessor()
149  */
150  void onConnectPointCloudProcessor() override;
151 
152  /**
153  * @see visionx::PointCloudProcessor::onDisconnectPointCloudProcessor()
154  */
155  void onDisconnectPointCloudProcessor() override;
156 
157  /**
158  * @see visionx::PointCloudProcessor::onExitPointCloudProcessor()
159  */
160  void onExitPointCloudProcessor() override;
161 
162  /**
163  * @see visionx::PointCloudProcessor::process()
164  */
165  void process() override;
166 
167  /**
168  * @see PropertyUser::createPropertyDefinitions()
169  */
170  armarx::PropertyDefinitionsPtr createPropertyDefinitions() override;
171 
172  void enablePipelineStep(const Ice::Current& c = Ice::emptyCurrent) override;
173  void disablePipelineStep(const Ice::Current& c = Ice::emptyCurrent) override;
174  bool isPipelineStepEnabled(const Ice::Current& c = Ice::emptyCurrent) override;
175  armarx::TimestampBasePtr getLastProcessedTimestamp(const Ice::Current& c = Ice::emptyCurrent) override;
176 
177  void setLccpParameters(const LccpParameters& parameters, const Ice::Current& c = Ice::emptyCurrent) override;
178  void loadLccpParametersFromFile(const std::string& filename, const Ice::Current& c = Ice::emptyCurrent) override;
179 
180  LccpParameters getLccpParameters(const Ice::Current& c = Ice::emptyCurrent) override;
181 
182  void setRgParameters(float smoothnessThreshold, float curvatureThreshold, const Ice::Current& c = Ice::emptyCurrent) override;
183  void loadRgParametersFromFile(const std::string& filename, const Ice::Current& c = Ice::emptyCurrent) override;
184 
185  void createRemoteGuiTab();
186  void RemoteGui_update() override;
187 
188  private:
189  void convertFromXYZRGBAtoXYZL(pcl::PointCloud<pcl::PointXYZRGBA>::Ptr& sourceCloudPtr, pcl::PointCloud<pcl::PointXYZL>::Ptr& targetCloudPtr);
190  void pushColoredLabeledCloudtoBuffer();
191 
192  private:
193  LCCPSegClass* pLCCP;
194  RGSegClass* pRGSegmenter;
195  EuclideanBasedClustering* pECSegmenter;
196  DeepSegClass* pDeepSegmenter;
197 
198  PointOPtr inputCloudPtr;
199  PointRGBLPtr labeledColoredCloudPtr;
200 
201  std::mutex timestampMutex;
202  long lastProcessedTimestamp;
203 
204  std::mutex enableMutex;
205  bool enabled;
206 
207  std::mutex providerMutex;
208  std::string providerName;
209  std::string segmentationMethod;
210 
211  // LCCP segmentation parameters
212  uint32_t minSegSize;
213  float voxelRes;
214  float seedRes;
215  float colorImp;
216  float spatialImp;
217  float normalImp;
218  float concavityThres;
219  float smoothnessThes;
220 
221  // RG segmentation parameters
222  float rgSmoothnessThes;
223  float rgCurvatureThres;
224 
225  void colorizeLabeledCloud();
226 
227  armarx::DebugDrawerInterfacePrx debugDrawerTopic;
228  armarx::DeepSegmenterInterfacePrx deepSegmenterTopic;
229  armarx::Blob rgbImage;
230 
232  };
233 }
234 
EuclideanBasedClustering
Definition: EuclideanBasedClustering.h:44
visionx::PointCloudSegmenter
A brief description.
Definition: PointCloudSegmenter.h:123
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:66
armarx::RemoteGui::Client::Tab
Definition: Tab.h:15
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
visionx::PointRGBL
pcl::PointXYZRGBL PointRGBL
Definition: PointCloudSegmenter.h:67
visionx::PointOPtr
pcl::PointCloud< PointO >::Ptr PointOPtr
Definition: PointCloudSegmenter.h:64
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:186
enabled
std::atomic< bool > * enabled
Definition: RemoteGuiWidgetController.cpp:75
filename
std::string filename
Definition: VisualizationRobot.cpp:84
DeepSegClass
Definition: Deep_Segmenter.h:38
visionx::PointCloudProcessorPropertyDefinitions
Properties of PointCloudProcessor.
Definition: PointCloudProcessor.h:173
PointCloudProcessor.h
visionx::PointCloudSegmenterPropertyDefinitions::PointCloudSegmenterPropertyDefinitions
PointCloudSegmenterPropertyDefinitions(std::string prefix)
Definition: PointCloudSegmenter.h:85
armarx::LightweightRemoteGuiComponentPluginUser
Definition: LightweightRemoteGuiComponentPlugin.h:73
LCCPSegClass
Definition: LCCP_Segmenter.h:50
Component.h
RG_Segmenter.h
visionx::PointL
pcl::PointXYZRGBL PointL
Definition: MaskRCNNPointCloudObjectLocalizer.h:80
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:134
visionx::PointO
pcl::PointXYZRGBA PointO
Definition: PointCloudSegmenter.h:63
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:68