Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
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   
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 }