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