UserAssistedSegmenterGuiWidgetController.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 SceneUnderstanding::gui-plugins::UserAssistedSegmenterGuiWidgetController
17  * @author Rainer Kartmann ( rainer dot kartmann at student dot 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 #pragma once
24 
25 #include <VisionX/gui-plugins/UserAssistedSegmenterGui/ui_UserAssistedSegmenterGuiWidget.h>
27 
28 #include <Eigen/Dense>
29 
30 #include <pcl/point_cloud.h>
31 #include <pcl/point_types.h>
32 #include <pcl/PointIndices.h>
33 
35 
38 
40 
41 #include <VisionX/interface/components/UserAssistedSegmenter.h>
42 
44 
45 
46 namespace visionx
47 {
48  class UserAssistedSegmenterConfigDialog;
49 
50  /**
51  \page VisionX-GuiPlugins-UserAssistedSegmenterGui UserAssistedSegmenterGui
52  \brief The UserAssistedSegmenterGui allows manually grouping segments of
53  an input oversegmentation to objects.
54 
55  \image html UserAssistedSegmenterGui.png
56  The user can see the segment IDs of the input oversegmentation and
57  visualize the segments in the Debug Drawer View.
58  The user can then choose the target number of objects and assign each
59  object the segment IDs of segments which are part of this object.
60  Once all objects have been assigned segments, the point cloud can be
61  published. Once publushed, it will be provided at constant frequency.
62 
63  API Documentation \ref UserAssistedSegmenterGuiWidgetController
64 
65  \see UserAssistedSegmenterGuiGuiPlugin
66  */
67 
68  /**
69  * \class UserAssistedSegmenterGuiWidgetController
70  * \brief UserAssistedSegmenterGuiWidgetController brief one line description
71  *
72  * Detailed description
73  */
76  public armarx::ArmarXComponentWidgetControllerTemplate<UserAssistedSegmenterGuiWidgetController>,
77  public visionx::UserAssistedSegmenterListener
78  {
79  Q_OBJECT
80 
81  using PointT = pcl::PointXYZRGBL;
82  using PointCloudT = pcl::PointCloud<PointT>;
83 
84 
85  public:
86 
87  /// Controller Constructor
89 
90  /// Controller destructor
91  virtual ~UserAssistedSegmenterGuiWidgetController() override;
92 
93 
94  /// @see ArmarXWidgetController::loadSettings()
95  virtual void loadSettings(QSettings* settings) override;
96 
97  /// @see ArmarXWidgetController::saveSettings()
98  virtual void saveSettings(QSettings* settings) override;
99 
100 
101  virtual QPointer<QDialog> getConfigDialog(QWidget* parent) override;
102 
103  virtual void configured() override;
104 
105 
106  /// Returns the Widget name displayed in the ArmarXGui to create an instance of this class.
107  static QString GetWidgetName();
108 
109 
110  /// @see armarx::Component::onInitComponent()
111  virtual void onInitComponent() override;
112 
113  /// @see armarx::Component::onConnectComponent()
114  virtual void onConnectComponent() override;
115 
116 
117  // UserAssistedSegmenterListener interface
118  virtual void reportSegmentation(const visionx::ColoredLabeledPointCloud& pointCloud, const Ice::Current&) override;
119 
120 
121  public slots:
122  /* QT slot declarations */
123 
124  /// @brief Handles an incoming segmented point cloud by reportReceivedSegmentation().
125  void onNewSourcePointCloud();
126 
127  // Filters
128  void onFilterSmallSegmentsNumEdited();
129  void updateFilters();
130 
131  // Visualization
132  void onRadioButtonShowInputToggled(bool checked);
133  void onRadioButtonShowResultToggle(bool checked);
134 
135  // IDs
136  void onShowIDsToggled(bool checked);
137  void updateSegmentIDs();
138 
139  void clearVisualization();
140 
141  // Grouping
142  void updateUserGroupingRows(int numRows);
143  void onUserGroupingChanged(uint32_t groupID, std::vector<uint32_t> segmentIDs);
144  void onTableGroupingCellChanged(int row, int col);
145 
146  void publishSegmentation();
147 
148 
149  signals:
150  /* QT signal declarations */
151  void newSourcePointCloud();
152 
153 
154  private:
155 
156  static std::vector<armarx::DrawColor> makeColorList();
157 
158 
159  private:
160 
161  void applyFilters(PointCloudT& pointCloud,
162  std::map<uint32_t, pcl::PointIndices>& segmentIndex);
163 
164  /// To be called when pointCloud has been modified.
165  void updatePointCloud(const PointCloudT& pointCloud,
166  const std::map<uint32_t, pcl::PointIndices>& segmentIndex);
167 
168  void computeSegmentIndex(const PointCloudT& pointCloud);
169  void computeCenters(const PointCloudT& pointCloud,
170  const std::map<uint32_t, pcl::PointIndices>& segmentIndex);
171 
172  void updateTableOverview();
173  void drawSegmentIDs(bool onlyIfChecked = false);
174  void drawInputPointCloud(bool onlyIfChecked = false);
175  void drawResultPointCloud(bool onlyIfChecked = false);
176 
177  armarx::DrawColor dcolor(std::size_t id) const;
178  QColor qcolor(std::size_t id) const;
179 
180 
181  private:
182 
183  /// Widget Form
184  Ui::UserAssistedSegmenterGuiWidget widget;
185  QPointer<UserAssistedSegmenterConfigDialog> configDialog;
186 
187  PointCloudSegmentsTable* segmentsOverviewTable;
188 
189 
190  std::string userAssistedSegmenterProxyName = "UserAssistedSegmenter";
191  std::string userAssistedSegmenterTopicName = "UserAssistedSegmenterUpdates";
192 
193 
195  visionx::UserAssistedSegmenterInterfacePrx segmenterProxy;
196 
197 
198  PointCloudT sourcePointCloud;
199  PointCloudT pointCloud;
200 
201  std::map<uint32_t, pcl::PointIndices> segmentIndex;
202  std::map<uint32_t, Eigen::Vector3f> centers;
203 
204 
205  std::vector<std::vector<std::uint32_t>> userGrouping;
206 
207  std::string layerPointCloud = "UserAssistedSegmenter_PointCloud";
208  std::string layerSegmentIDs = "UserAssistedSegmenter_SegmentIDs";
209 
210  };
211 }
212 
armarx::DebugDrawerTopic
The DebugDrawerTopic wraps a DebugDrawerInterfacePrx and provides a more useful interface than the Ic...
Definition: DebugDrawerTopic.h:152
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
PointCloudSegmentsTable.h
armarx::ArmarXComponentWidgetControllerTemplate
Definition: ArmarXComponentWidgetController.h:69
ArmarXGuiPlugin.h
DebugDrawerTopic.h
ArmarXComponentWidgetController.h
ARMARXCOMPONENT_IMPORT_EXPORT
#define ARMARXCOMPONENT_IMPORT_EXPORT
Definition: ImportExportComponent.h:38
visionx::PointCloudSegmentsTable
Definition: PointCloudSegmentsTable.h:23
visionx::UserAssistedSegmenterGuiWidgetController
UserAssistedSegmenterGuiWidgetController brief one line description.
Definition: UserAssistedSegmenterGuiWidgetController.h:74
UserAssistedSegmenterConfigDialog.h
ImportExportComponent.h