GraspCandidateViewerWidgetController.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 RobotAPI::gui-plugins::GraspCandidateViewerWidgetController
17 * \author Raphael Grimm ( raphael dot grimm at kit dot edu )
18 * \date 2020
19 * \copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
24
25#include <string>
26
27#include <SimoxUtility/math/convert/quat_to_rpy.h>
28
30
31//setting management
32namespace armarx
33{
34 void
36 {
38 std::lock_guard g{_mutex};
40 settings->value("rsc", "Armar6StateComponent").toString().toStdString());
42 settings->value("gco", "GraspCandidateObserver").toString().toStdString());
43 }
44
45 void
47 {
49 std::lock_guard g{_mutex};
50 settings->setValue(
51 "rsc",
52 QString::fromStdString(getRobotStateComponentPlugin().getRobotStateComponentName()));
53 settings->setValue(
54 "rsc",
55 QString::fromStdString(
56 getGraspCandidateObserverComponentPlugin().getGraspCandidateObserverName()));
57 }
58
59 QPointer<QDialog>
61 {
63 std::lock_guard g{_mutex};
64 if (!_dialog)
65 {
66 _dialog = new SimpleConfigDialog(parent);
67 _dialog->addProxyFinder<RobotStateComponentInterfacePrx>(
68 "rsc", "Robot State Component", "*Component");
69 _dialog->addProxyFinder<grasping::GraspCandidateObserverInterfacePrx>(
70 "gco", "Grasp Candidate Observer", "*Observer");
71 }
72 return qobject_cast<SimpleConfigDialog*>(_dialog);
73 }
74
75 void
77 {
79 std::lock_guard g{_mutex};
80 getRobotStateComponentPlugin().setRobotStateComponentName(_dialog->getProxyName("rsc"));
82 _dialog->getProxyName("gco"));
83 }
84} // namespace armarx
85
86//ctor
87namespace armarx
88{
90 {
92 std::lock_guard g{_mutex};
93 _ui.setupUi(getWidget());
94
95 connect(_ui.pushButtonUpdateGC,
96 &QPushButton::clicked,
97 this,
99 connect(_ui.treeWidgetGC,
100 &QTreeWidget::itemSelectionChanged,
101 this,
103
104 connect(_ui.treeWidgetGC,
105 SIGNAL(itemChanged(QTreeWidgetItem*, int)),
106 this,
107 SLOT(check_state_changed()));
108 }
109
113
114 void
116 {
118 std::lock_guard g{_mutex};
120 {
121 return;
122 }
123 //clean
124 {
125 _ui.treeWidgetGC->clear();
126 for (auto& [prname, pr] : _providers)
127 {
128 pr.candidates.clear();
129 pr.item = nullptr;
130 }
131 _tree_item_to_gc.clear();
132 }
133 //fill
134 {
135 for (const auto& gc : getGraspCandidateObserver()->getAllCandidates())
136 {
138 const auto& pname = gc->providerName;
139 auto& pr = _providers[pname];
140 pr.provider_name = pname;
141 if (!pr.item)
142 {
143 pr.item = new QTreeWidgetItem;
144 pr.item->setCheckState(0, Qt::Unchecked);
145 _ui.treeWidgetGC->addTopLevelItem(pr.item);
146 pr.item->setText(0, QString::fromStdString(pname));
147 }
148
149 auto& gcdata = pr.candidates.emplace_back();
150 gcdata.gc = gc;
151 gcdata.idx = pr.candidates.size() - 1;
152 gcdata.provider = &pr;
153 gcdata.item = new QTreeWidgetItem;
154 gcdata.item->setCheckState(0, Qt::Unchecked);
155 pr.item->addChild(gcdata.item);
156 gcdata.item->setText(0, QString::fromStdString(gcdata.name()));
157 _tree_item_to_gc[gcdata.item] = &gcdata;
158 }
159 }
160 }
161
162 void
164 {
166 std::lock_guard g{_mutex};
167 synchronizeLocalClone(_robot);
169
170 std::vector<viz::Layer> layers;
171 for (const auto& [pname, pr] : _providers)
172 {
173 layers.emplace_back(getArvizClient().layer(pname));
174 auto& l = layers.back();
175 for (const auto& gc : pr.candidates)
176 {
177 if (gc.item->checkState(0) == Qt::Unchecked)
178 {
179 gc_drawer.draw(gc.gc, l);
180 }
181 }
182 }
183 getArvizClient().commit(layers);
184 }
185
186 void
188 {
190 std::lock_guard g{_mutex};
191 const auto& selected = _ui.treeWidgetGC->selectedItems();
192 ARMARX_CHECK_GREATER(2, selected.size());
193 if (selected.empty())
194 {
195 show_entry(nullptr);
196 //clear
197 }
198 else if (_tree_item_to_gc.count(selected.value(0)))
199 {
200 show_entry(_tree_item_to_gc.at(selected.value(0)));
201 }
202 //provider item selected -> do nothing
203 }
204
205 void
206 GraspCandidateViewerWidgetController::show_entry(entry_gc* e)
207 {
208 if (!e)
209 {
210 _ui.labelGCIdx->setText("-");
211 _ui.labelNumGC->setText("-");
212
213 _ui.labelGPoseTX->setText("-");
214 _ui.labelGPoseTY->setText("-");
215 _ui.labelGPoseTZ->setText("-");
216 _ui.labelGPoseRX->setText("-");
217 _ui.labelGPoseRY->setText("-");
218 _ui.labelGPoseRZ->setText("-");
219
220 _ui.labelRPoseTX->setText("-");
221 _ui.labelRPoseTY->setText("-");
222 _ui.labelRPoseTZ->setText("-");
223 _ui.labelRPoseRX->setText("-");
224 _ui.labelRPoseRY->setText("-");
225 _ui.labelRPoseRZ->setText("-");
226
227 _ui.labelGApprTX->setText("-");
228 _ui.labelGApprTY->setText("-");
229 _ui.labelGApprTZ->setText("-");
230
231 _ui.labelSrcFrame->setText("-");
232 _ui.labelTrgFrame->setText("-");
233 _ui.labelSide->setText("-");
234 _ui.labelGraspProb->setText("-");
235 _ui.labelGraspgroupNr->setText("-");
236 _ui.labelGraspObjType->setText("-");
237 _ui.labelGraspProviderName->setText("-");
238 return;
239 }
241 ARMARX_CHECK_NOT_NULL(e->gc->graspPose->position);
242 ARMARX_CHECK_NOT_NULL(e->gc->robotPose->position);
243 ARMARX_CHECK_NOT_NULL(e->gc->graspPose->orientation);
244 ARMARX_CHECK_NOT_NULL(e->gc->robotPose->orientation);
245 ARMARX_CHECK_NOT_NULL(e->gc->approachVector);
246 _ui.labelGCIdx->setText(QString::number(e->idx + 1));
247 _ui.labelNumGC->setText(QString::number(e->provider->candidates.size()));
248
249 _ui.labelGPoseTX->setText(QString::number(e->gc->graspPose->position->x));
250 _ui.labelGPoseTY->setText(QString::number(e->gc->graspPose->position->y));
251 _ui.labelGPoseTZ->setText(QString::number(e->gc->graspPose->position->z));
252 const Eigen::Vector3f vec_g = simox::math::quat_to_rpy({e->gc->graspPose->orientation->qw,
253 e->gc->graspPose->orientation->qx,
254 e->gc->graspPose->orientation->qy,
255 e->gc->graspPose->orientation->qz
256
257 });
258 _ui.labelGPoseRX->setText(QString::number(vec_g(0)));
259 _ui.labelGPoseRY->setText(QString::number(vec_g(1)));
260 _ui.labelGPoseRZ->setText(QString::number(vec_g(2)));
261
262 _ui.labelRPoseTX->setText(QString::number(e->gc->robotPose->position->x));
263 _ui.labelRPoseTY->setText(QString::number(e->gc->robotPose->position->y));
264 _ui.labelRPoseTZ->setText(QString::number(e->gc->robotPose->position->z));
265 const Eigen::Vector3f vec_r = simox::math::quat_to_rpy({e->gc->robotPose->orientation->qw,
266 e->gc->robotPose->orientation->qx,
267 e->gc->robotPose->orientation->qy,
268 e->gc->robotPose->orientation->qz
269
270 });
271 _ui.labelRPoseRX->setText(QString::number(vec_r(0)));
272 _ui.labelRPoseRY->setText(QString::number(vec_r(1)));
273 _ui.labelRPoseRZ->setText(QString::number(vec_r(2)));
274
275 _ui.labelGApprTX->setText(QString::number(e->gc->approachVector->x));
276 _ui.labelGApprTY->setText(QString::number(e->gc->approachVector->y));
277 _ui.labelGApprTZ->setText(QString::number(e->gc->approachVector->z));
278
279 _ui.labelSrcFrame->setText(QString::fromStdString(e->gc->sourceFrame));
280 _ui.labelTrgFrame->setText(QString::fromStdString(e->gc->targetFrame));
281 _ui.labelSide->setText(QString::fromStdString(e->gc->side));
282 _ui.labelGraspProb->setText(QString::number(e->gc->graspSuccessProbability));
283 _ui.labelGraspgroupNr->setText(QString::number(e->gc->groupNr));
284 switch (e->gc->objectType)
285 {
286 case objpose::ObjectType::AnyObject:
287 _ui.labelGraspObjType->setText("AnyObject");
288 break;
289 case objpose::ObjectType::KnownObject:
290 _ui.labelGraspObjType->setText("KnownObject");
291 break;
292 case objpose::ObjectType::UnknownObject:
293 _ui.labelGraspObjType->setText("UnknownObject");
294 break;
295 }
296 _ui.labelGraspProviderName->setText(QString::fromStdString(e->gc->providerName));
297 }
298
299} // namespace armarx
armarx::viz::Client & getArvizClient()
virtual QPointer< QWidget > getWidget()
getWidget returns a pointer to the a widget of this controller.
grasping::GraspCandidateObserverInterfacePrx getGraspCandidateObserver()
armarx::plugins::GraspCandidateObserverComponentPlugin & getGraspCandidateObserverComponentPlugin()
void loadSettings(QSettings *settings) override
Implement to load the settings that are part of the GUI configuration.
void saveSettings(QSettings *settings) override
Implement to save the settings as part of the GUI configuration.
void configured() override
This function must be implemented by the user, if he supplies a config dialog.
QPointer< QDialog > getConfigDialog(QWidget *parent) override
getConfigDialog returns a pointer to the a configuration widget of this controller.
bool synchronizeLocalClone(const VirtualRobot::RobotPtr &robot) const
const RobotStateComponentPlugin & getRobotStateComponentPlugin() const
A config-dialog containing one (or multiple) proxy finders.
CommitResult commit(StagedCommit const &commit)
Definition Client.cpp:89
#define ARMARX_CHECK_GREATER(lhs, rhs)
This macro evaluates whether lhs is greater (>) than rhs and if it turns out to be false it will thro...
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
This file offers overloads of toIce() and fromIce() functions for STL container types.
::IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface > RobotStateComponentInterfacePrx
#define ARMARX_TRACE
Definition trace.h:77