TransformWidget.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2016, Bielefeld University, CITEC
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  *
00029  * Author: Robert Haschke <rhaschke@techfak.uni-bielefeld.de>
00030  */
00031 
00032 #include "TransformWidget.h"
00033 #include "EulerWidget.h"
00034 
00035 #include "ui_transform.h"
00036 
00037 #include <QMetaType>
00038 
00039 TransformWidget::TransformWidget(QWidget *parent) :
00040   QWidget(parent), ui_(new Ui::TransformWidget)
00041 {
00042   qRegisterMetaType<Eigen::Quaterniond>("Eigen::Vector3d");
00043   qRegisterMetaType<Eigen::Quaterniond>("Eigen::Quaterniond");
00044   pos_.setZero();
00045 
00046   ui_->setupUi(this);
00047 
00048   connect(ui_->pos_x, SIGNAL(valueChanged(double)), this, SLOT(changePos(double)));
00049   connect(ui_->pos_y, SIGNAL(valueChanged(double)), this, SLOT(changePos(double)));
00050   connect(ui_->pos_z, SIGNAL(valueChanged(double)), this, SLOT(changePos(double)));
00051   connect(ui_->euler_widget_, SIGNAL(valueChanged(Eigen::Quaterniond)),
00052           this, SIGNAL(quaternionChanged(Eigen::Quaterniond)));
00053 }
00054 
00055 const Eigen::Vector3d &TransformWidget::position() const
00056 {
00057   return pos_;
00058 }
00059 
00060 const Eigen::Quaterniond &TransformWidget::quaternion() const
00061 {
00062   return ui_->euler_widget_->value();
00063 }
00064 
00065 void TransformWidget::setPosition(const Eigen::Vector3d &p)
00066 {
00067   if (pos_.isApprox(p)) return;
00068   pos_ = p;
00069 
00070   // do not trigger posChanged() signals
00071   ui_->pos_x->blockSignals(true);
00072   ui_->pos_y->blockSignals(true);
00073   ui_->pos_z->blockSignals(true);
00074 
00075   ui_->pos_x->setValue(p.x());
00076   ui_->pos_y->setValue(p.y());
00077   ui_->pos_z->setValue(p.z());
00078 
00079   ui_->pos_x->blockSignals(false);
00080   ui_->pos_y->blockSignals(false);
00081   ui_->pos_z->blockSignals(false);
00082 
00083   emit positionChanged(pos_);
00084 }
00085 
00086 void TransformWidget::setQuaternion(const Eigen::Quaterniond &q)
00087 {
00088   ui_->euler_widget_->setValue(q);
00089 }
00090 
00091 void TransformWidget::changePos(double value)
00092 {
00093   QDoubleSpinBox *s = qobject_cast<QDoubleSpinBox*>(sender());
00094   if (s == ui_->pos_x) changePos(0, value);
00095   if (s == ui_->pos_y) changePos(1, value);
00096   if (s == ui_->pos_z) changePos(2, value);
00097 }
00098 
00099 void TransformWidget::changePos(unsigned int i, double value)
00100 {
00101   if (Eigen::internal::isApprox(pos_[i], value)) return;
00102   pos_[i] = value;
00103   emit positionChanged(pos_);
00104 }


agni_tf_tools
Author(s): Robert Haschke
autogenerated on Sat Jun 8 2019 21:01:20