rotation_property.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 "rotation_property.h"
33 
34 using namespace rviz;
35 
36 namespace agni_tf_tools
37 {
38 
39 RotationProperty::RotationProperty(Property* parent, const QString& name,
40  const Eigen::Quaterniond& value,
41  const char *changed_slot,
42  QObject* receiver)
43  : StringProperty(name, "",
44  "Orientation specification using Euler angles or a quaternion.",
45  parent, changed_slot, receiver)
46  , ignore_quaternion_property_updates_(false)
47  , show_euler_string_(true)
48 {
49  euler_property_ = new EulerProperty(this, "Euler angles", value);
51  Ogre::Quaternion(value.w(), value.x(), value.y(), value.z()),
52  "order: x, y, z, w", this);
53  connect(euler_property_, SIGNAL(changed()), this, SLOT(updateFromEuler()));
54  connect(quaternion_property_, SIGNAL(changed()), this, SLOT(updateFromQuaternion()));
55  // forward status signal from EulerProperty
56  connect(euler_property_, SIGNAL(statusUpdate(int,QString,QString)),
57  this, SIGNAL(statusUpdate(int,QString,QString)));
58  // forward quaternion updates
59  connect(euler_property_, SIGNAL(quaternionChanged(Eigen::Quaterniond)),
60  this, SIGNAL(quaternionChanged(Eigen::Quaterniond)));
61  updateString();
62 }
63 
64 Eigen::Quaterniond RotationProperty::getQuaternion() const
65 {
67 }
68 
69 void RotationProperty::setQuaternion(const Eigen::Quaterniond& q)
70 {
71  Eigen::Quaterniond qn = q.normalized();
72  if (getQuaternion().isApprox(qn)) return;
73  // EulerProperty is considered "master".
74  // EulerProperty update will trigger QuaternionProperty update too
76 }
77 
79 {
80  const Eigen::Quaterniond q = euler_property_->getQuaternion();
81  // do not update QuaternionProperty
83  quaternion_property_->setQuaternion(Ogre::Quaternion(q.w(), q.x(), q.y(), q.z()));
84  }
85  show_euler_string_ = true;
86  updateString();
87 }
88 
90 {
91  // protect from infinite update loop
93 
94  const Ogre::Quaternion &q = quaternion_property_->getQuaternion();
95  Eigen::Quaternion<Ogre::Real> eigen_q(q.w, q.x, q.y, q.z);
96 
97  // only update if changes are within accuracy range
98  if (eigen_q.isApprox(getQuaternion().cast<Ogre::Real>())) return;
99 
101  setQuaternion(eigen_q.cast<double>());
103 
104  show_euler_string_ = false;
105  updateString();
106 }
107 
108 void RotationProperty::setEulerAngles(double euler[], bool normalize)
109 {
110  euler_property_->setEulerAngles(euler, normalize);
111 }
112 
113 void RotationProperty::setEulerAngles(double e1, double e2, double e3, bool normalize)
114 {
115  euler_property_->setEulerAngles(e1, e2, e3, normalize);
116 }
117 
118 void RotationProperty::setEulerAxes(const QString &axes_spec)
119 {
120  euler_property_->setEulerAxes(axes_spec);
121 }
122 
123 bool RotationProperty::setValue(const QVariant& value)
124 {
125  // forward parsing to either Quaternion- or EulerProperty
126  const QRegExp quatSpec("\\s*(quat:)?([^;]+;){3}");
127  QString s = value.toString();
128  if (quatSpec.indexIn(s) != -1)
129  {
130  s = s.mid(quatSpec.cap(1).length());
131  return quaternion_property_->setValue(s);
132  }
133  return euler_property_->setValue(value);
134 }
135 
137 {
138  QString euler = euler_property_->getValue().toString();
139  QString quat = QString("quat: ") + quaternion_property_->getValue().toString();
140  QString s = show_euler_string_ ? euler : quat;
141  if (getString() != s) {
142  Q_EMIT aboutToChange();
143  value_ = s;
144  Q_EMIT changed();
145  }
146 }
147 
148 void RotationProperty::load(const Config& config)
149 {
150  // save/load from EulerProperty. This handles both, quaternion and euler axes.
151  euler_property_->load(config);
152 }
153 
154 void RotationProperty::save(Config config) const
155 {
156  // save/load from EulerProperty. This handles both, quaternion and euler axes.
157  euler_property_->save(config);
158 }
159 
160 void RotationProperty::setReadOnly(bool read_only)
161 {
162  euler_property_->setReadOnly(read_only);
163  quaternion_property_->setReadOnly(read_only);
164 }
165 
166 } // end namespace rviz
virtual Ogre::Quaternion getQuaternion() const
virtual bool setValue(const QVariant &value)
Eigen::Quaterniond getQuaternion() const
virtual void setReadOnly(bool read_only)
Overridden from Property to propagate read-only-ness to children.
void statusUpdate(int, const QString &, const QString &)
XmlRpcServer s
void quaternionChanged(Eigen::Quaterniond q)
void setEulerAngles(double euler[3], bool normalize)
rviz::EulerProperty * euler_property_
virtual void setReadOnly(bool read_only)
QVariant value_
virtual void save(rviz::Config config) const
virtual bool setValue(const QVariant &value)
virtual bool setValue(const QVariant &new_value)
rviz::QuaternionProperty * quaternion_property_
Eigen::Quaterniond getQuaternion() const
void setQuaternion(const Eigen::Quaterniond &q)
void setEulerAxes(const QString &axes_spec)
virtual bool setQuaternion(const Ogre::Quaternion &quaternion)
void setQuaternion(const Eigen::Quaterniond &q)
TFSIMD_FORCE_INLINE Vector3 & normalize()
virtual void save(Config config) const
void aboutToChange()
virtual void setReadOnly(bool read_only)
Overridden from Property to propagate read-only-ness to children.
void setEulerAxes(const QString &axes)
virtual void load(const Config &config)
Load the value of this property and/or its children from the given Config node.
virtual QVariant getValue() const
void setEulerAngles(double euler[3], bool normalize)
virtual void load(const rviz::Config &config)
Load the value of this property and/or its children from the given Config node.


agni_tf_tools
Author(s): Robert Haschke
autogenerated on Fri Jun 7 2019 22:04:59