transform.h
Go to the documentation of this file.
1 // *****************************************************************************
2 //
3 // Copyright (c) 2014, Southwest Research Institute® (SwRI®)
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
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 Southwest Research Institute® (SwRI®) nor the
14 // names of its contributors may be used to endorse or promote products
15 // derived from 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 <COPYRIGHT HOLDER> BE LIABLE FOR ANY
21 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 //
28 // *****************************************************************************
29 
30 #ifndef TRANSFORM_UTIL_TRANSFORM_H_
31 #define TRANSFORM_UTIL_TRANSFORM_H_
32 
33 #include <boost/shared_ptr.hpp>
34 
35 #include <ros/ros.h>
36 
37 #include <tf/transform_datatypes.h>
38 
39 namespace swri_transform_util
40 {
50  {
51  public:
53  virtual ~TransformImpl() {}
54 
61  virtual void Transform(
62  const tf::Vector3& v_in, tf::Vector3& v_out) const = 0;
63 
72  {
73  tf::Vector3 offset;
74  Transform(tf::Vector3(1, 0, 0), offset);
75 
76  tf::Vector3 origin;
77  Transform(tf::Vector3(0, 0, 0), origin);
78 
79  tf::Vector3 vector = offset - origin;
80 
81  // Use the "half-way quaternion method" of summing and normalizing a
82  // quaternion with twice the rotation between the vector and the x-axis and
83  // the zero rotation.
84 
85  tf::Vector3 cross = tf::Vector3(1, 0, 0).cross(vector);
86  double w = vector.length() + tf::Vector3(1, 0, 0).dot(vector);
87  return tf::Quaternion(cross.x(), cross.y(), cross.z(), w).normalized();
88  }
89 
90  virtual boost::shared_ptr<TransformImpl> Inverse() const = 0;
91 
94  };
96 
105  class Transform
106  {
107  public:
111  Transform();
112 
118  explicit Transform(const tf::Transform& transform);
119 
125  explicit Transform(const tf::StampedTransform& transform);
126 
132  explicit Transform(boost::shared_ptr<TransformImpl> transform);
133 
141  Transform& operator=(const tf::Transform transform);
142 
151 
159  tf::Vector3 operator()(const tf::Vector3& v) const;
160 
168  tf::Vector3 operator*(const tf::Vector3& v) const;
169 
177  tf::Quaternion operator*(const tf::Quaternion& q) const;
178 
184  tf::Transform GetTF() const;
185 
191  Transform Inverse() const;
192 
201  tf::Vector3 GetOrigin() const;
202 
209 
214  ros::Time GetStamp() { return transform_->stamp_; }
215 
216  private:
219  };
220 
226  {
227  public:
232 
239  virtual void Transform(const tf::Vector3& v_in, tf::Vector3& v_out) const;
240  virtual TransformImplPtr Inverse() const;
241  };
242 
247  class TfTransform : public TransformImpl
248  {
249  public:
254  explicit TfTransform(const tf::Transform& transform);
255 
260  explicit TfTransform(const tf::StampedTransform& transform);
261 
268  virtual void Transform(const tf::Vector3& v_in, tf::Vector3& v_out) const;
269 
274  virtual tf::Quaternion GetOrientation() const;
275  virtual TransformImplPtr Inverse() const;
276 
277  protected:
279  };
280 }
281 
282 #endif // TRANSFORM_UTIL_TRANSFORM_H_
swri_transform_util::IdentityTransform::IdentityTransform
IdentityTransform()
Construct an identity transform.
Definition: transform.h:231
boost::shared_ptr
swri_transform_util::Transform::Transform
Transform()
Generates an identity transform.
tf::Quaternion::normalized
Quaternion normalized() const
swri_transform_util::Transform::operator()
tf::Vector3 operator()(const tf::Vector3 &v) const
Apply the transform to a vector and return the result.
swri_transform_util::TransformImpl
Base class for Transform implementations.
Definition: transform.h:49
ros.h
swri_transform_util::Transform::transform_
boost::shared_ptr< TransformImpl > transform_
Pointer to the implementation of the transform.
Definition: transform.h:218
swri_transform_util::IdentityTransform::Inverse
virtual TransformImplPtr Inverse() const
swri_transform_util::Transform::GetOrientation
tf::Quaternion GetOrientation() const
Get the orientation (rotation component) of the transform.
tf::StampedTransform
swri_transform_util::TransformImpl::TransformImpl
TransformImpl()
Definition: transform.h:52
swri_transform_util::Transform::operator*
tf::Vector3 operator*(const tf::Vector3 &v) const
Apply the transform to a vector and return the result.
swri_transform_util::Transform::GetOrigin
tf::Vector3 GetOrigin() const
Get the origin (translation component) of the transform.
swri_transform_util::IdentityTransform
Specialization of swri_transform_util::TransformImpl that represents the identity transform.
Definition: transform.h:225
swri_transform_util::Transform::Inverse
Transform Inverse() const
Return the inverse transform.
swri_transform_util::TfTransform::TfTransform
TfTransform(const tf::Transform &transform)
Construct a TfTransform from a tf::Transform.
swri_transform_util::Transform::GetTF
tf::Transform GetTF() const
Return a TF transform equivalent to this transform.
swri_transform_util
Definition: earth_constants.h:33
swri_transform_util::Transform::operator=
Transform & operator=(const tf::Transform transform)
Assignment operator for tf::Transform.
swri_transform_util::TfTransform::Inverse
virtual TransformImplPtr Inverse() const
swri_transform_util::Transform
An abstraction of the tf::Transform class to support transforms in addition to the rigid transforms s...
Definition: transform.h:105
swri_transform_util::Transform::GetStamp
ros::Time GetStamp()
Get the time stamp of the transform.
Definition: transform.h:214
swri_transform_util::TransformImpl::GetOrientation
virtual tf::Quaternion GetOrientation() const
Get the orientation of this transform.
Definition: transform.h:71
tf::Transform
swri_transform_util::TfTransform::GetOrientation
virtual tf::Quaternion GetOrientation() const
Get the orientation component of this transform using TF.
swri_transform_util::TransformImpl::stamp_
ros::Time stamp_
Time stamp for this transform.
Definition: transform.h:93
transform_datatypes.h
swri_transform_util::TfTransform::Transform
virtual void Transform(const tf::Vector3 &v_in, tf::Vector3 &v_out) const
Apply this transform to a 3D vector using TF.
ros::Time
swri_transform_util::TransformImpl::Inverse
virtual boost::shared_ptr< TransformImpl > Inverse() const =0
swri_transform_util::TransformImpl::Transform
virtual void Transform(const tf::Vector3 &v_in, tf::Vector3 &v_out) const =0
Apply this transform to a 3D vector.
swri_transform_util::TfTransform
Specialization of swri_transform_util::TransformImpl that performs TF transformation.
Definition: transform.h:247
swri_transform_util::TransformImplPtr
boost::shared_ptr< TransformImpl > TransformImplPtr
Definition: transform.h:95
swri_transform_util::IdentityTransform::Transform
virtual void Transform(const tf::Vector3 &v_in, tf::Vector3 &v_out) const
Apply the identity tranform to a 3D vector(sets v_out=v_in)
tf::Quaternion
swri_transform_util::TransformImpl::~TransformImpl
virtual ~TransformImpl()
Definition: transform.h:53
swri_transform_util::TfTransform::transform_
tf::Transform transform_
Definition: transform.h:278


swri_transform_util
Author(s): Marc Alban
autogenerated on Fri Aug 2 2024 08:39:26