FeatureLearningWidgetController.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 VisionX::gui-plugins::FeatureLearningWidgetController
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_VisionX_FeatureLearning_WidgetController_H
24 #define _ARMARX_VisionX_FeatureLearning_WidgetController_H
25 
26 #include <math.h>
27 
28 #include <QDir>
29 #include <QFileDialog>
30 #include <QMessageBox>
31 #include <QSettings>
32 
33 #include <Eigen/Core>
34 
37 
41 
43 #include <VisionX/gui-plugins/FeatureLearning/ui_FeatureLearningWidget.h>
46 
47 #include <Features/HarrisSIFTFeatures/HarrisSIFTFeatureCalculator.h>
48 #include <Features/SIFTFeatures/SIFTFeatureEntry.h>
49 #include <Math/FloatMatrix.h>
50 #include <Math/LinearAlgebra.h>
51 #include <TexturedRecognition/TexturedFeatureSet.h>
52 
53 namespace armarx
54 {
55 
56  //class FeatureLearningObjectChooserWidget;
57 
58  /**
59  \page VisionX-GuiPlugins-FeatureLearning FeatureLearning
60  \brief The FeatureLearning allows connecting to ArmarX ImageProviders and extract features from their images.
61 
62  \image html FeatureLearning.png
63  The user can connect and disconnect ImageProviders easily. By clicking on the image, a region can be chosen. SIFT features are calculated within the region. After features have been added to the selection, they can be saved to a file. Additionally, the features can be saved to an object in the PriorMemory, if it is available. Loading from the memory or a file is also supported.
64 
65  API Documentation \ref FeatureLearningWidgetController
66 
67  \see FeatureLearningGuiPlugin
68  */
69 
70  /**
71  * \class FeatureLearningWidgetController
72  * \brief FeatureLearningWidgetController brief one line description
73  *
74  * Detailed description
75  */
77  public armarx::ArmarXComponentWidgetControllerTemplate<FeatureLearningWidgetController>,
79  {
80  Q_OBJECT
81 
82  public:
83  /**
84  * Controller Constructor
85  */
87 
88  /**
89  * Controller destructor
90  */
92 
93  /**
94  * @see ArmarXWidgetController::loadSettings()
95  */
96  virtual void loadSettings(QSettings* settings) override;
97 
98  /**
99  * @see ArmarXWidgetController::saveSettings()
100  */
101  virtual void saveSettings(QSettings* settings) override;
102 
103  /**
104  * Returns the Widget name displayed in the ArmarXGui to create an
105  * instance of this class.
106  */
107  static QString
109  {
110  return "VisionX.FeatureLearning";
111  }
112 
113  void reconnect();
114 
115  /**
116  * @see visionx::ImageProcessor::onInitImageProcessor()
117  */
118  virtual void onInitImageProcessor() override;
119 
120  /**
121  * @see visionx::ImageProcessor::onConnectImageProcessor()
122  */
123  virtual void onConnectImageProcessor() override;
124 
125  /**
126  * @see visionx::ImageProcessor::onDisconnectImageProcessor()
127  */
128  virtual void onDisconnectImageProcessor() override;
129 
130  /**
131  * @see visionx::ImageProcessor::onExitImageProcessor()
132  */
133  virtual void onExitImageProcessor() override;
134 
135  /**
136  * @see visionx::ImageProcessor::process()
137  */
138  virtual void process() override;
139 
140  public slots:
141  /* QT slot declarations */
142 
143  void addPolygonPoint(int, float x, float y);
144  void connectButtonClicked(bool toggled);
145  void disconnectButtonClicked(bool toggled);
146  void loadFeaturesButtonClicked(bool toggled);
147  void saveFeaturesButtonClicked(bool toggled);
148  void pausePlayButtonClicked(bool toggled);
149  void addFeaturesButtonClicked(bool toggled);
150  void clearFeaturesButtonClicked(bool toggled);
151 
152  void thresholdChanged(double threshold);
153 
154  void maxFeaturesChanged(int maxFeatures);
155 
156  signals:
157  /* QT signal declarations */
158  void imageProviderConnected(bool connected);
159 
160  private:
161  /**
162  * Widget Form
163  */
164  Ui::FeatureLearningWidget widget;
165  QWidget* widgetPointer;
166 
167  void loadFeatureSet(QString filePath);
168  void saveFeatureSet(QString filePath, float w, float h, float d);
169  void updateFeatures();
170  int addFeatures();
171  void clearFeatures();
172 
173  void updateSelection();
174 
175  void connectToProvider();
176  void disconnectFromProvider();
177 
178  void updatePausePlayButtonText();
179  void updateImageMonitorUI();
180  void updateFeaturesUI();
181 
182  static CFloatMatrix* createCuboid(float w, float h, float d);
183  static void addRectangle(CFloatMatrix* object,
184  int& offset,
185  float x1,
186  float y1,
187  float z1,
188  float x2,
189  float y2,
190  float z2,
191  float x3,
192  float y3,
193  float z3,
194  float x4,
195  float y4,
196  float z4,
197  float n1,
198  float n2,
199  float n3);
200  static void addTriangle(CFloatMatrix* object,
201  int& offset,
202  float x1,
203  float y1,
204  float z1,
205  float x2,
206  float y2,
207  float z2,
208  float x3,
209  float y3,
210  float z3,
211  float n1,
212  float n2,
213  float n3);
214 
215 
216  // provider
217  visionx::ImageProviderInterfacePrx imageProviderPrx;
218  visionx::ImageProviderInfo imageProviderInfo;
219 
220 
221  SelectableImageViewer* imageViewer;
222 
223  int numSelectedPoints;
224 
225  CByteImage** cameraImages;
226  CByteImage* visualizationImage;
227  CByteImage* grayImage;
228 
229  int numImages;
230 
231  bool isPaused;
232 
233  std::string imageProviderName;
234 
235  CHarrisSIFTFeatureCalculator* featureCalculator;
236  CTexturedFeatureSet* objectFeatureSet;
237  CTexturedFeatureSet* viewFeatureSet;
238 
239  bool undistortImages;
240  std::recursive_mutex imageMutex;
241 
242  //contains relative position of the mouse clicks on the image
243  Eigen::ArrayX2f points;
244  Mat3d homography;
245 
247 
248  bool connected;
249  IceUtil::Time timeProvided;
250 
251  QSettings mySettings;
252 
253  std::mutex featureCalculatorMutex;
254  };
255 } // namespace armarx
256 
257 #endif
armarx::FeatureLearningWidgetController::GetWidgetName
static QString GetWidgetName()
Returns the Widget name displayed in the ArmarXGui to create an instance of this class.
Definition: FeatureLearningWidgetController.h:108
visionx::ImageProcessor
The ImageProcessor class provides an interface for access to ImageProviders via Ice and shared memory...
Definition: ImageProcessor.h:98
armarx::ArmarXComponentWidgetControllerTemplate
Definition: ArmarXComponentWidgetController.h:69
visionx::ImageProviderInfo
Definition: ImageProcessor.h:479
ArmarXGuiPlugin.h
ArmarXComponentWidgetController.h
ARMARXCOMPONENT_IMPORT_EXPORT
#define ARMARXCOMPONENT_IMPORT_EXPORT
Definition: ImportExportComponent.h:38
ImageProcessor.h
IceProxyFinder.h
ImageViewerArea.h
IceManager.h
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::SelectableImageViewer
A clickable, i.e. selectable, visionx::ImageViewerArea.
Definition: SelectableImageViewer.h:44
SelectableImageViewer.h
armarx::IceProxyFinder< visionx::ImageProviderInterfacePrx >
armarx::FeatureLearningWidgetController
FeatureLearningWidgetController brief one line description.
Definition: FeatureLearningWidgetController.h:76
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
ImportExportComponent.h