/*
 * Software License Agreement (BSD License)
 *
 *  Copyright (c) 2017, 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 ROBOT_NAV_2D_UTILS_CONVERSIONS_H
#define ROBOT_NAV_2D_UTILS_CONVERSIONS_H

#include <robot_geometry_msgs/Point.h>
#include <robot_geometry_msgs/Pose.h>
#include <robot_geometry_msgs/Twist.h>
#include <robot_geometry_msgs/PolygonStamped.h>
#include <robot_nav_2d_msgs/Twist2D.h>
#include <robot_nav_2d_msgs/Path2D.h>
#include <robot_nav_2d_msgs/Point2D.h>
#include <robot_nav_2d_msgs/Polygon2D.h>
#include <robot_nav_2d_msgs/Polygon2DStamped.h>
#include <robot_nav_2d_msgs/Pose2DStamped.h>
#include <robot_nav_2d_msgs/NavGridInfo.h>
#include <robot_nav_2d_msgs/UIntBounds.h>
#include <robot_nav_msgs/MapMetaData.h>
#include <robot_nav_msgs/Path.h>
#include <nav_grid/nav_grid.h>
#include <robot_nav_core2/bounds.h>
// #include <tf/tf.h>
#include <vector>
#include <string>

namespace robot_nav_2d_utils
{
  // Twist Transformations
  ::robot_geometry_msgs::Twist twist2Dto3D(const ::robot_nav_2d_msgs::Twist2D &cmd_vel_2d);
  ::robot_nav_2d_msgs::Twist2D twist3Dto2D(const ::robot_geometry_msgs::Twist &cmd_vel);

  // Point Transformations
  ::robot_nav_2d_msgs::Point2D pointToPoint2D(const ::robot_geometry_msgs::Point &point);
  ::robot_nav_2d_msgs::Point2D pointToPoint2D(const ::robot_geometry_msgs::Point32 &point);
  ::robot_geometry_msgs::Point pointToPoint3D(const ::robot_nav_2d_msgs::Point2D &point);
  ::robot_geometry_msgs::Point32 pointToPoint32(const ::robot_nav_2d_msgs::Point2D &point);

  // Pose Transformations
  // ::robot_nav_2d_msgs::Pose2DStamped stampedPoseToPose2D(const tf::Stamped<tf::Pose>& pose);
  ::robot_nav_2d_msgs::Pose2DStamped poseStampedToPose2D(const ::robot_geometry_msgs::PoseStamped &pose);
  ::robot_geometry_msgs::Pose pose2DToPose(const ::robot_geometry_msgs::Pose2D &pose2d);
  ::robot_geometry_msgs::PoseStamped pose2DToPoseStamped(const ::robot_nav_2d_msgs::Pose2DStamped &pose2d);
  ::robot_geometry_msgs::PoseStamped pose2DToPoseStamped(const ::robot_geometry_msgs::Pose2D &pose2d,
                                                   const ::std::string &frame, const robot::Time &stamp);

  // Path Transformations
  ::robot_nav_2d_msgs::Path2D pathToPath(const robot_nav_msgs::Path &path);
  robot_nav_msgs::Path posesToPath(const ::std::vector<::robot_geometry_msgs::PoseStamped> &poses);
  ::robot_nav_2d_msgs::Path2D posesToPath2D(const ::std::vector<::robot_geometry_msgs::PoseStamped> &poses);
  robot_nav_msgs::Path poses2DToPath(const ::std::vector<::robot_geometry_msgs::Pose2D> &poses,
                               const ::std::string &frame, const robot::Time &stamp);
  robot_nav_msgs::Path pathToPath(const ::robot_nav_2d_msgs::Path2D &path2d);

  // Polygon Transformations
  ::robot_geometry_msgs::Polygon polygon2Dto3D(const ::robot_nav_2d_msgs::Polygon2D &polygon_2d);
  ::robot_nav_2d_msgs::Polygon2D polygon3Dto2D(const ::robot_geometry_msgs::Polygon &polygon_3d);
  ::robot_geometry_msgs::PolygonStamped polygon2Dto3D(const ::robot_nav_2d_msgs::Polygon2DStamped &polygon_2d);
  ::robot_nav_2d_msgs::Polygon2DStamped polygon3Dto2D(const ::robot_geometry_msgs::PolygonStamped &polygon_3d);

  // Info Transformations
  ::robot_nav_2d_msgs::NavGridInfo toMsg(const nav_grid::NavGridInfo &info);
  nav_grid::NavGridInfo fromMsg(const ::robot_nav_2d_msgs::NavGridInfo &msg);
  ::robot_geometry_msgs::Pose getOrigin3D(const nav_grid::NavGridInfo &info);
  ::robot_geometry_msgs::Pose2D getOrigin2D(const nav_grid::NavGridInfo &info);
  nav_grid::NavGridInfo infoToInfo(const robot_nav_msgs::MapMetaData &metadata, const ::std::string &frame);
  robot_nav_msgs::MapMetaData infoToInfo(const nav_grid::NavGridInfo &info);

  // Bounds Transformations
  robot_nav_2d_msgs::UIntBounds toMsg(const robot_nav_core2::UIntBounds &bounds);
  robot_nav_core2::UIntBounds fromMsg(const robot_nav_2d_msgs::UIntBounds &msg);

} // namespace robot_nav_2d_utils

#endif // ROBOT_NAV_2D_UTILS_CONVERSIONS_H
