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