Program Listing for File transform.hpp

Return to documentation for file (/tmp/ws/src/tf2_2d/include/tf2_2d/transform.hpp)

/*
 * Software License Agreement (BSD License)
 *
 *  Copyright (c) 2019, Locus Robotics
 *  All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above
 *     copyright notice, this list of conditions and the following
 *     disclaimer in the documentation and/or other materials provided
 *     with the distribution.
 *   * Neither the name of the copyright holder nor the names of its
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 *  POSSIBILITY OF SUCH DAMAGE.
 */
#ifndef TF2_2D__TRANSFORM_HPP_
#define TF2_2D__TRANSFORM_HPP_

#include <Eigen/Core>

#include <tf2/LinearMath/Scalar.h>
#include <tf2/LinearMath/Transform.h>
#include <tf2_2d/rotation.hpp>
#include <tf2_2d/vector2.hpp>


namespace tf2_2d
{

class Transform
{
public:
  Transform();

  Transform(const Rotation & rotation, const Vector2 & translation);

  Transform(const tf2Scalar x, const tf2Scalar y, const tf2Scalar yaw);

  explicit Transform(const tf2::Transform & transform);

  Transform & operator*=(const Transform & rhs);

  bool operator==(const Transform & rhs);

  bool operator!=(const Transform & rhs);

  Transform lerp(const Transform & other, const tf2Scalar ratio) const;

  const Rotation & getRotation() const;
  const Rotation & rotation() const {return getRotation();}

  const Vector2 & getTranslation() const;
  const Vector2 & translation() const {return getTranslation();}

  void setRotation(const Rotation & other);

  void setTranslation(const Vector2 & other);

  const tf2Scalar & getX() const;
  const tf2Scalar & x() const {return getX();}

  const tf2Scalar & getY() const;
  const tf2Scalar & y() const {return getY();}

  const tf2Scalar & getYaw() const;
  const tf2Scalar & yaw() const {return getYaw();}
  // There are a lot of common aliases for yaw
  const tf2Scalar & getAngle() const {return getYaw();}
  const tf2Scalar & angle() const {return getYaw();}
  const tf2Scalar & getHeading() const {return getYaw();}
  const tf2Scalar & heading() const {return getYaw();}
  const tf2Scalar & getTheta() const {return getYaw();}
  const tf2Scalar & theta() const {return getYaw();}

  void setX(const tf2Scalar x);

  void setY(const tf2Scalar y);

  void setYaw(const tf2Scalar yaw);
  // There are a lot of common aliases for yaw
  void setAngle(const tf2Scalar angle) {setYaw(angle);}
  void setHeading(const tf2Scalar heading) {setYaw(heading);}
  void setTheta(const tf2Scalar theta) {setYaw(theta);}

  void setIdentity();

  Transform inverse() const;

  Transform inverseTimes(const Transform & other) const;

  Eigen::Matrix3d getHomogeneousMatrix() const;

private:
  Rotation rotation_;
  Vector2 translation_;
};

Transform operator*(Transform lhs, const Transform & rhs);

Vector2 operator*(const Transform & lhs, const Vector2 & rhs);

Rotation operator*(const Transform & lhs, const Rotation & rhs);

std::ostream & operator<<(std::ostream & stream, const Transform & transform);

}  // namespace tf2_2d

#include <tf2_2d/transform_impl.hpp>

#endif  // TF2_2D__TRANSFORM_HPP_