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
60namespace 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
76
77 /**
78 * @class PointCloudSegmenterPropertyDefinitions
79 * @brief
80 */
83 {
84 public:
87 {
88 // General parameters
90 "DebugDrawerTopicName", "DebugDrawerUpdates", "Name of the debug drawer topic");
91 defineOptionalProperty<std::string>("DeepSegmenterTopicName",
92 "DeepSegmenterPythonUpdates",
93 "Name of the deep segmenter topic");
95 "segmentationMethod",
96 "EC",
97 "Name of the offered segmentation method (EC, LCCP or RG)");
99 "StartEnabled", true, "Enable or disable the segmentation by default");
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");
108 "lccpVoxelResolution",
109 25,
110 "Supervoxel resolution required for the lccp segmentation");
112 "lccpSeedResolution", 80, "Seed resolution required for the lccp segmentation");
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");
125 "lccpSmoothnessThreshold",
126 0.1,
127 "Smoothness threshold required for the lccp segmentation");
128
129 // RG parameters
131 "rgSmoothnessThreshold",
132 6.0,
133 "Smoothness threshold required for the region growing segmentation");
135 "rgCurvatureThreshold",
136 50.0,
137 "Curvature threshold required for the region growing segmentation");
138
139 // Debug parameters
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 */
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
constexpr T c
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)
The PointCloudProcessor class provides an interface for access to PointCloudProviders via Ice and sha...
void loadLccpParametersFromFile(const std::string &filename, const Ice::Current &c=Ice::emptyCurrent) override
LccpParameters getLccpParameters(const Ice::Current &c=Ice::emptyCurrent) override
void enablePipelineStep(const Ice::Current &c=Ice::emptyCurrent) override
void disablePipelineStep(const Ice::Current &c=Ice::emptyCurrent) override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void changePointCloudProvider(const std::string &providerName, const Ice::Current &c=Ice::emptyCurrent) override
void setRgParameters(float smoothnessThreshold, float curvatureThreshold, const Ice::Current &c=Ice::emptyCurrent) override
void setLccpParameters(const LccpParameters &parameters, const Ice::Current &c=Ice::emptyCurrent) override
void loadRgParametersFromFile(const std::string &filename, const Ice::Current &c=Ice::emptyCurrent) override
armarx::TimestampBasePtr getLastProcessedTimestamp(const Ice::Current &c=Ice::emptyCurrent) override
std::string getDefaultName() const override
bool isPipelineStepEnabled(const Ice::Current &c=Ice::emptyCurrent) override
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface > DebugDrawerInterfacePrx
ArmarX headers.
pcl::PointCloud< PointO >::Ptr PointOPtr
pcl::PointCloud< PointL >::Ptr PointLPtr
pcl::PointXYZRGBL PointRGBL
pcl::PointXYZRGBA PointO
pcl::PointCloud< PointRGBL >::Ptr PointRGBLPtr