TransformWidget.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016, Bielefeld University, CITEC
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  * Author: Robert Haschke <rhaschke@techfak.uni-bielefeld.de>
30  */
31 
32 #include "TransformWidget.h"
33 #include "EulerWidget.h"
34 
35 #include "ui_transform.h"
36 
37 #include <QMetaType>
38 
39 TransformWidget::TransformWidget(QWidget* parent) : QWidget(parent), ui_(new Ui::TransformWidget) {
40  qRegisterMetaType<Eigen::Quaterniond>("Eigen::Vector3d");
41  qRegisterMetaType<Eigen::Quaterniond>("Eigen::Quaterniond");
42  pos_.setZero();
43 
44  ui_->setupUi(this);
45 
46  auto valueChanged = static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged);
47  auto changePos = static_cast<void (TransformWidget::*)(double)>(&TransformWidget::changePos);
48  connect(ui_->pos_x, valueChanged, this, changePos);
49  connect(ui_->pos_y, valueChanged, this, changePos);
50  connect(ui_->pos_z, valueChanged, this, changePos);
51  connect(ui_->euler_widget_, &EulerWidget::valueChanged, this, &TransformWidget::quaternionChanged);
52 }
53 
54 const Eigen::Vector3d& TransformWidget::position() const {
55  return pos_;
56 }
57 
58 const Eigen::Quaterniond& TransformWidget::quaternion() const {
59  return ui_->euler_widget_->value();
60 }
61 
62 void TransformWidget::setPosition(const Eigen::Vector3d& p) {
63  if (pos_.isApprox(p))
64  return;
65  pos_ = p;
66 
67  // do not trigger posChanged() signals
68  ui_->pos_x->blockSignals(true);
69  ui_->pos_y->blockSignals(true);
70  ui_->pos_z->blockSignals(true);
71 
72  ui_->pos_x->setValue(p.x());
73  ui_->pos_y->setValue(p.y());
74  ui_->pos_z->setValue(p.z());
75 
76  ui_->pos_x->blockSignals(false);
77  ui_->pos_y->blockSignals(false);
78  ui_->pos_z->blockSignals(false);
79 
80  emit positionChanged(pos_);
81 }
82 
83 void TransformWidget::setQuaternion(const Eigen::Quaterniond& q) {
84  ui_->euler_widget_->setValue(q);
85 }
86 
87 void TransformWidget::changePos(double value) {
88  QDoubleSpinBox* s = qobject_cast<QDoubleSpinBox*>(sender());
89  if (s == ui_->pos_x)
90  changePos(0, value);
91  if (s == ui_->pos_y)
92  changePos(1, value);
93  if (s == ui_->pos_z)
94  changePos(2, value);
95 }
96 
97 void TransformWidget::changePos(unsigned int i, double value) {
98  if (Eigen::internal::isApprox(pos_[i], value))
99  return;
100  pos_[i] = value;
101  emit positionChanged(pos_);
102 }
const Eigen::Vector3d & position() const
const Eigen::Quaterniond & quaternion() const
Definition: EulerWidget.h:37
XmlRpcServer s
void quaternionChanged(const Eigen::Quaterniond &q)
void changePos(unsigned int i, double value)
void valueChanged(const Eigen::Quaterniond &q)
quaternion value has changed
void setPosition(const Eigen::Vector3d &p)
Ui::TransformWidget * ui_
void setQuaternion(const Eigen::Quaterniond &q)
TransformWidget(QWidget *parent=nullptr)
void positionChanged(const Eigen::Vector3d &p)
Eigen::Vector3d pos_


agni_tf_tools
Author(s): Robert Haschke
autogenerated on Tue Apr 13 2021 02:29:55