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 RotationProperty::RotationProperty(Property* parent,
39  const QString& name,
40  const Eigen::Quaterniond& value,
41  const char* changed_slot,
42  QObject* receiver)
43  : StringProperty(name,
44  "",
45  "Orientation specification using Euler angles or a quaternion.",
46  parent,
47  changed_slot,
48  receiver)
49  , ignore_quaternion_property_updates_(false)
50  , show_euler_string_(true) {
51  euler_property_ = new EulerProperty(this, "Euler angles", value);
53  new rviz::QuaternionProperty("quaternion",
54  Ogre::Quaternion(value.w(), value.x(), value.y(), value.z()),
55  "order: x, y, z, w", this);
56  connect(euler_property_, &EulerProperty::changed, this, &RotationProperty::updateFromEuler);
57  connect(quaternion_property_, &QuaternionProperty::changed, this,
59  // forward status signal from EulerProperty
60  connect(euler_property_, &EulerProperty::statusUpdate, this, &RotationProperty::statusUpdate);
61  // forward quaternion updates
62  connect(euler_property_, &EulerProperty::quaternionChanged, this, &RotationProperty::quaternionChanged);
63  updateString();
64 }
65 
66 Eigen::Quaterniond RotationProperty::getQuaternion() const {
68 }
69 
70 void RotationProperty::setQuaternion(const Eigen::Quaterniond& q) {
71  Eigen::Quaterniond qn = q.normalized();
72  if (getQuaternion().isApprox(qn))
73  return;
74  // EulerProperty is considered "master".
75  // EulerProperty update will trigger QuaternionProperty update too
77 }
78 
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  // protect from infinite update loop
92  return;
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>()))
99  return;
100 
102  setQuaternion(eigen_q.cast<double>());
104 
105  show_euler_string_ = false;
106  updateString();
107 }
108 
109 void RotationProperty::setEulerAngles(double euler[], bool normalize) {
110  euler_property_->setEulerAngles(euler, normalize);
111 }
112 
113 void RotationProperty::setEulerAngles(double e1, double e2, double e3, bool normalize) {
114  euler_property_->setEulerAngles(e1, e2, e3, normalize);
115 }
116 
117 void RotationProperty::setEulerAxes(const QString& axes_spec) {
118  euler_property_->setEulerAxes(axes_spec);
119 }
120 
121 bool RotationProperty::setValue(const QVariant& value) {
122  // forward parsing to either Quaternion- or EulerProperty
123  const QRegExp quatSpec("\\s*(quat:)?([^;]+;){3}");
124  QString s = value.toString();
125  if (quatSpec.indexIn(s) != -1) {
126  s = s.mid(quatSpec.cap(1).length());
127  return quaternion_property_->setValue(s);
128  }
129  return euler_property_->setValue(value);
130 }
131 
133  QString euler = euler_property_->getValue().toString();
134  QString quat = QString("quat: ") + quaternion_property_->getValue().toString();
135  QString s = show_euler_string_ ? euler : quat;
136  if (getString() != s) {
137  Q_EMIT aboutToChange();
138  value_ = s;
139  Q_EMIT changed();
140  }
141 }
142 
143 void RotationProperty::load(const Config& config) {
144  // save/load from EulerProperty. This handles both, quaternion and euler axes.
145  euler_property_->load(config);
146 }
147 
148 void RotationProperty::save(Config config) const {
149  // save/load from EulerProperty. This handles both, quaternion and euler axes.
150  euler_property_->save(config);
151 }
152 
153 void RotationProperty::setReadOnly(bool read_only) {
154  euler_property_->setReadOnly(read_only);
155  quaternion_property_->setReadOnly(read_only);
156 }
157 
158 } // namespace agni_tf_tools
virtual Ogre::Quaternion getQuaternion() const
Eigen::Quaterniond getQuaternion() const
void setReadOnly(bool read_only) override
Overridden from Property to propagate read-only-ness to children.
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 bool setValue(const QVariant &new_value)
rviz::QuaternionProperty * quaternion_property_
void save(Config config) const override
void load(const Config &config) override
Load the value of this property and/or its children from the given Config node.
Eigen::Quaterniond getQuaternion() const
bool setValue(const QVariant &value) override
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)
void statusUpdate(rviz::StatusProperty::Level, const QString &, const QString &)
TFSIMD_FORCE_INLINE Vector3 & normalize()
void save(rviz::Config config) const override
void load(const rviz::Config &config) override
Load the value of this property and/or its children from the given Config node.
void aboutToChange()
void setEulerAxes(const QString &axes)
virtual QVariant getValue() const
bool setValue(const QVariant &value) override
void setEulerAngles(double euler[3], bool normalize)
void setReadOnly(bool read_only) override
Overridden from Property to propagate read-only-ness to children.


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