RecognitionAttributesEditTab.cpp
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 ArmarX::MemoryX::PriorMemoryEditorPlugin
17 * @author Kai Welke (welke at kit dot edu)
18 * @date 2013
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
24 
25 #include <MemoryX/gui-plugins/PriorMemoryEditor/ui_RecognitionAttributesEditTab.h>
28 
29 // ArmarXCore
31 
32 using namespace memoryx;
33 using namespace memoryx::EntityWrappers;
34 
38  texturedRecognition("TexturedObjectRecognition"),
39  segmentableRecognition("SegmentableObjectRecognition"),
40  handMarkerRecognition("HandMarkerLocalization"),
41  arMarkerRecognition("ArMarkerLocalization"),
42  otherRecognitionMethod("Other")
43 {
44  ui->setupUi(this);
45 
46  // init feature file dialog
47  connect(ui->comboBoxRecognitionMethod,
48  SIGNAL(currentIndexChanged(const QString&)),
49  this,
50  SLOT(recognitionMethodChanged(const QString&)));
51 
52  texturedFeatureFileDialog = new QFileDialog(parent);
53  texturedFeatureFileDialog->setModal(true);
54  texturedFeatureFileDialog->setFileMode(QFileDialog::ExistingFiles);
55  texturedFeatureFileDialog->setNameFilter(tr("IVT data files (*.dat)"));
56  connect(ui->btnSelectTexturedFeatureFile,
57  SIGNAL(clicked()),
58  texturedFeatureFileDialog,
59  SLOT(show()));
60  connect(
61  texturedFeatureFileDialog, SIGNAL(accepted()), this, SLOT(texturedFeatureFileSelected()));
62 
63  segmentableFeatureFileDialog = new QFileDialog(parent);
64  segmentableFeatureFileDialog->setModal(true);
65  segmentableFeatureFileDialog->setFileMode(QFileDialog::ExistingFiles);
66  segmentableFeatureFileDialog->setNameFilter(tr("IVT config files (config.txt)"));
67  connect(ui->btnSelectSegmentableFeatureFile,
68  SIGNAL(clicked()),
69  segmentableFeatureFileDialog,
70  SLOT(show()));
71  connect(segmentableFeatureFileDialog,
72  SIGNAL(accepted()),
73  this,
75 
77 }
78 
80 {
81  delete ui;
82 }
83 
84 void
86 {
87  ObjectClassPtr objectClass = ObjectClassPtr::dynamicCast(entity);
88 
89  ObjectRecognitionWrapperPtr objectRecognitionWrapper =
90  objectClass->getWrapper<ObjectRecognitionWrapper>();
91  TexturedRecognitionWrapperPtr texturedRecognitionWrapper =
92  objectClass->getWrapper<TexturedRecognitionWrapper>();
93  SegmentableRecognitionWrapperPtr segmentableRecognitionWrapper =
94  objectClass->getWrapper<SegmentableRecognitionWrapper>();
95  HandMarkerBallWrapperPtr handMarkerBallWrapper =
96  objectClass->getWrapper<HandMarkerBallWrapper>();
97  ArMarkerWrapperPtr arMarkerWrapper = objectClass->getWrapper<ArMarkerWrapper>();
98 
99  // fill dialog (with ivt recognition wrapper attributes)
100  std::string recognitionMethod = objectRecognitionWrapper->getRecognitionMethod();
101  int index = ui->comboBoxRecognitionMethod->findText(QString(recognitionMethod.c_str()));
102 
103  if (index != -1)
104  {
105  ui->comboBoxRecognitionMethod->setCurrentIndex(index);
106  }
107  else if (recognitionMethod != "")
108  {
109  index = ui->comboBoxRecognitionMethod->findText(QString(otherRecognitionMethod.c_str()));
110 
111  if (index != -1)
112  {
113  ui->comboBoxRecognitionMethod->setCurrentIndex(index);
114  recognitionMethod = otherRecognitionMethod;
115  }
116  else
117  {
118  ARMARX_WARNING_S << "Something is wrong with the ComboBox for the recognition methods";
119  }
120  }
121 
122  if (recognitionMethod == texturedRecognition)
123  {
124  ui->editTexturedFeatureFile->setText(
125  QString(texturedRecognitionWrapper->getFeatureFile().c_str()));
126  }
127  else if (recognitionMethod == segmentableRecognition)
128  {
129  std::string configName = segmentableRecognitionWrapper->getDataFiles() + "/config.txt";
130  ui->editSegmentableFeatureFile->setText(QString(configName.c_str()));
131  ui->comboBoxObjectColor->setCurrentIndex(
132  int(segmentableRecognitionWrapper->getObjectColor()));
133  }
134  else if (recognitionMethod == handMarkerRecognition)
135  {
136  ui->comboBoxMarkerColor->setCurrentIndex(int(handMarkerBallWrapper->getObjectColor()));
137  }
138  else if (recognitionMethod == arMarkerRecognition)
139  {
140  std::vector<int> ids = arMarkerWrapper->getArMarkerIDs();
141  std::vector<float> sizes = arMarkerWrapper->getArMarkerSizes();
142  std::vector<Eigen::Vector3f> translations =
143  arMarkerWrapper->getTransformationToCenterTranslations();
144  std::vector<Eigen::Vector3f> rotations =
145  arMarkerWrapper->getTransformationToCenterRotationsRPY();
146 
147  if (ids.size() != 2 || sizes.size() != 2 || translations.size() != 2 ||
148  rotations.size() != 2)
149  {
150  ARMARX_WARNING_S << "ArMarker entity has an invalid number of markers";
151  }
152  else
153  {
154  ui->editArMarkerID->setText(QString(std::to_string(ids.at(0)).c_str()));
155  ui->editArMarkerID_2->setText(QString(std::to_string(ids.at(1)).c_str()));
156 
157  ui->editArMarkerSize->setText(QString(std::to_string(sizes.at(0)).c_str()));
158  ui->editArMarkerSize_2->setText(QString(std::to_string(sizes.at(1)).c_str()));
159 
160  ui->editArMarkerTrafoX->setText(QString(std::to_string(translations.at(0)(0)).c_str()));
161  ui->editArMarkerTrafoY->setText(QString(std::to_string(translations.at(0)(1)).c_str()));
162  ui->editArMarkerTrafoZ->setText(QString(std::to_string(translations.at(0)(2)).c_str()));
163  ui->editArMarkerTrafoX_2->setText(
164  QString(std::to_string(translations.at(1)(0)).c_str()));
165  ui->editArMarkerTrafoY_2->setText(
166  QString(std::to_string(translations.at(1)(1)).c_str()));
167  ui->editArMarkerTrafoZ_2->setText(
168  QString(std::to_string(translations.at(1)(2)).c_str()));
169 
170  ui->editArMarkerTrafoR->setText(QString(std::to_string(rotations.at(0)(0)).c_str()));
171  ui->editArMarkerTrafoP->setText(QString(std::to_string(rotations.at(0)(1)).c_str()));
172  ui->editArMarkerTrafoYaw->setText(QString(std::to_string(rotations.at(0)(2)).c_str()));
173  ui->editArMarkerTrafoR_2->setText(QString(std::to_string(rotations.at(1)(0)).c_str()));
174  ui->editArMarkerTrafoP_2->setText(QString(std::to_string(rotations.at(1)(1)).c_str()));
175  ui->editArMarkerTrafoYaw_2->setText(
176  QString(std::to_string(rotations.at(1)(2)).c_str()));
177  }
178  }
179  else if (recognitionMethod == otherRecognitionMethod)
180  {
181  ui->editOtherRecogMethodName->setText(
182  QString(objectRecognitionWrapper->getRecognitionMethod().c_str()));
183  }
184  else if (recognitionMethod != "")
185  {
186  ARMARX_WARNING_S << "Recognition method " << recognitionMethod << " not handled here";
187  }
188 }
189 
190 void
191 RecognitionAttributesEditTab::updateEntity(const EntityPtr& entity, std::string filesDBName)
192 {
193  ObjectClassPtr objectClass = ObjectClassPtr::dynamicCast(entity);
194 
195  ObjectRecognitionWrapperPtr objectRecognitionWrapper =
196  objectClass->getWrapper<ObjectRecognitionWrapper>();
197  TexturedRecognitionWrapperPtr texturedRecognitionWrapper =
198  objectClass->getWrapper<TexturedRecognitionWrapper>();
199  SegmentableRecognitionWrapperPtr segmentableRecognitionWrapper =
200  objectClass->getWrapper<SegmentableRecognitionWrapper>();
201  HandMarkerBallWrapperPtr handMarkerBallWrapper =
202  objectClass->getWrapper<HandMarkerBallWrapper>();
203  ArMarkerWrapperPtr arMarkerWrapper = objectClass->getWrapper<ArMarkerWrapper>();
204 
205  // update IVT recognition wrapper specific attributes
206  std::string recognitionMethod = ui->comboBoxRecognitionMethod->currentText().toStdString();
207 
208  if (recognitionMethod == otherRecognitionMethod)
209  {
210  recognitionMethod = ui->editOtherRecogMethodName->text().toStdString();
211  }
212  else if (recognitionMethod == texturedRecognition)
213  {
214  texturedRecognitionWrapper->setFeatureFile(
215  ui->editTexturedFeatureFile->text().toStdString(), filesDBName);
216  }
217  else if (recognitionMethod == segmentableRecognition)
218  {
219  std::string dataPath = ui->editSegmentableFeatureFile->text().toStdString();
220  dataPath = dataPath.substr(0, dataPath.length() - 11);
221  segmentableRecognitionWrapper->setDataFiles(dataPath, filesDBName);
222  segmentableRecognitionWrapper->setObjectColor(
223  (ObjectColor)ui->comboBoxObjectColor->currentIndex());
224  }
225  else if (recognitionMethod == handMarkerRecognition)
226  {
227  handMarkerBallWrapper->setObjectColor((ObjectColor)ui->comboBoxMarkerColor->currentIndex());
228  }
229  else if (recognitionMethod == arMarkerRecognition)
230  {
231  std::vector<int> ids;
232  ids.push_back(std::stoi(ui->editArMarkerID->text().toStdString()));
233  ids.push_back(std::stoi(ui->editArMarkerID_2->text().toStdString()));
234  arMarkerWrapper->setArMarkerIDs(ids);
235 
236  std::vector<float> sizes;
237  sizes.push_back(std::stof(ui->editArMarkerSize->text().toStdString()));
238  sizes.push_back(std::stof(ui->editArMarkerSize_2->text().toStdString()));
239  arMarkerWrapper->setArMarkerSizes(sizes);
240 
241  Eigen::Vector3f tempVec;
242  std::vector<Eigen::Vector3f> translations;
243  tempVec(0) = std::stof(ui->editArMarkerTrafoX->text().toStdString());
244  tempVec(1) = std::stof(ui->editArMarkerTrafoY->text().toStdString());
245  tempVec(2) = std::stof(ui->editArMarkerTrafoZ->text().toStdString());
246  translations.push_back(tempVec);
247  tempVec(0) = std::stof(ui->editArMarkerTrafoX_2->text().toStdString());
248  tempVec(1) = std::stof(ui->editArMarkerTrafoY_2->text().toStdString());
249  tempVec(2) = std::stof(ui->editArMarkerTrafoZ_2->text().toStdString());
250  translations.push_back(tempVec);
251  arMarkerWrapper->setTransformationToCenterTranslations(translations);
252 
253  std::vector<Eigen::Vector3f> rotations;
254  tempVec(0) = std::stof(ui->editArMarkerTrafoR->text().toStdString());
255  tempVec(1) = std::stof(ui->editArMarkerTrafoP->text().toStdString());
256  tempVec(2) = std::stof(ui->editArMarkerTrafoYaw->text().toStdString());
257  rotations.push_back(tempVec);
258  tempVec(0) = std::stof(ui->editArMarkerTrafoR_2->text().toStdString());
259  tempVec(1) = std::stof(ui->editArMarkerTrafoP_2->text().toStdString());
260  tempVec(2) = std::stof(ui->editArMarkerTrafoYaw_2->text().toStdString());
261  rotations.push_back(tempVec);
262  arMarkerWrapper->setTransformationToCenterRotationsRPY(rotations);
263  }
264  else
265  {
266  ARMARX_WARNING_S << "Recognition method " << recognitionMethod << " not handled here";
267  }
268 
269  objectRecognitionWrapper->setRecognitionMethod(recognitionMethod);
270 }
271 
272 void
274 {
275  ui->editTexturedFeatureFile->setText(texturedFeatureFileDialog->selectedFiles()[0]);
276 }
277 
278 void
280 {
281  ui->editSegmentableFeatureFile->setText(segmentableFeatureFileDialog->selectedFiles()[0]);
282 }
283 
284 void
286 {
287  bool enableTextured = (method.toStdString() == texturedRecognition);
288  bool enableSegmentable = (method.toStdString() == segmentableRecognition);
289  bool enableHandMarker = (method.toStdString() == handMarkerRecognition);
290  bool enableArMarker = (method.toStdString() == arMarkerRecognition);
291  bool enableOtherRecogMethod = (method.toStdString() == otherRecognitionMethod);
292 
293  ui->btnSelectTexturedFeatureFile->setEnabled(enableTextured);
294  ui->editTexturedFeatureFile->setEnabled(enableTextured);
295 
296  ui->btnSelectSegmentableFeatureFile->setEnabled(enableSegmentable);
297  ui->editSegmentableFeatureFile->setEnabled(enableSegmentable);
298  ui->comboBoxObjectColor->setEnabled(enableSegmentable);
299 
300  ui->comboBoxMarkerColor->setEnabled(enableHandMarker);
301 
302  ui->editArMarkerID->setEnabled(enableArMarker);
303  ui->editArMarkerSize->setEnabled(enableArMarker);
304  ui->editArMarkerTrafoX->setEnabled(enableArMarker);
305  ui->editArMarkerTrafoY->setEnabled(enableArMarker);
306  ui->editArMarkerTrafoZ->setEnabled(enableArMarker);
307  ui->editArMarkerTrafoR->setEnabled(enableArMarker);
308  ui->editArMarkerTrafoP->setEnabled(enableArMarker);
309  ui->editArMarkerTrafoYaw->setEnabled(enableArMarker);
310  ui->editArMarkerID_2->setEnabled(enableArMarker);
311  ui->editArMarkerSize_2->setEnabled(enableArMarker);
312  ui->editArMarkerTrafoX_2->setEnabled(enableArMarker);
313  ui->editArMarkerTrafoY_2->setEnabled(enableArMarker);
314  ui->editArMarkerTrafoZ_2->setEnabled(enableArMarker);
315  ui->editArMarkerTrafoR_2->setEnabled(enableArMarker);
316  ui->editArMarkerTrafoP_2->setEnabled(enableArMarker);
317  ui->editArMarkerTrafoYaw_2->setEnabled(enableArMarker);
318 
319  ui->editOtherRecogMethodName->setEnabled(enableOtherRecogMethod);
320 }
memoryx::RecognitionAttributesEditTab::~RecognitionAttributesEditTab
~RecognitionAttributesEditTab() override
Definition: RecognitionAttributesEditTab.cpp:79
index
uint8_t index
Definition: EtherCATFrame.h:59
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
ObjectRecognitionWrapper.h
memoryx::RecognitionAttributesEditTab::RecognitionAttributesEditTab
RecognitionAttributesEditTab(QWidget *parent=0)
Definition: RecognitionAttributesEditTab.cpp:35
ObjectClass.h
memoryx::EntityWrappers::SegmentableRecognitionWrapper
SegmentableRecognitionWrapper offers a simplified access to the data of an object class or instance r...
Definition: ObjectRecognitionWrapper.h:85
memoryx::RecognitionAttributesEditTab::updateEntity
void updateEntity(const EntityPtr &entity, std::string filesDBName) override
Pure virtual method.
Definition: RecognitionAttributesEditTab.cpp:191
IceInternal::Handle
Definition: forward_declarations.h:8
Ui
ArmarX Headers.
Definition: ArmarXMainWindow.h:54
RecognitionAttributesEditTab.h
memoryx::EntityWrappers::TexturedRecognitionWrapper
TexturedRecognitionWrapper offers a simplified access to the data of an object class or instance rela...
Definition: ObjectRecognitionWrapper.h:63
memoryx::RecognitionAttributesEditTab::texturedFeatureFileSelected
void texturedFeatureFileSelected()
Definition: RecognitionAttributesEditTab.cpp:273
ARMARX_WARNING_S
#define ARMARX_WARNING_S
Definition: Logging.h:213
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:41
memoryx::RecognitionAttributesEditTab::recognitionMethodChanged
void recognitionMethodChanged(const QString &method)
Definition: RecognitionAttributesEditTab.cpp:285
memoryx::EntityWrappers
Definition: AbstractEntityWrapper.cpp:30
memoryx::EntityWrappers::ObjectRecognitionWrapper
Definition: ObjectRecognitionWrapper.h:40
memoryx::RecognitionAttributesEditTab::updateGui
void updateGui(const EntityPtr &entity) override
Pure virtual method.
Definition: RecognitionAttributesEditTab.cpp:85
Logging.h
memoryx::EntityAttributesEditTab
The entity edit dialog is a superclass for all edit dialogs used to set attributes of entites.
Definition: EntityAttributesEditTab.h:37
memoryx::EntityWrappers::ArMarkerWrapper
ArMarkerWrapper offers a simplified access to the necessary information for localization of AR marker...
Definition: ObjectRecognitionWrapper.h:131
memoryx::RecognitionAttributesEditTab::segmentableFeatureFileSelected
void segmentableFeatureFileSelected()
Definition: RecognitionAttributesEditTab.cpp:279
memoryx::RecognitionAttributesEditTab
This tab allows to change the recognition attributes of an objectclass entity.
Definition: RecognitionAttributesEditTab.h:41
memoryx::EntityWrappers::HandMarkerBallWrapper
HandMarkerBallWrapper offers a simplified access to the necessary information for localization of the...
Definition: ObjectRecognitionWrapper.h:110