Skip to content

Commit

Permalink
Merge pull request #22 from mrvsht/master
Browse files Browse the repository at this point in the history
add poseToDirectionVector and poseToPositionVector
  • Loading branch information
spuetz authored May 23, 2022
2 parents a96fadf + 7605b2e commit 60c6af2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
20 changes: 20 additions & 0 deletions mesh_map/include/mesh_map/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@

#include <geometry_msgs/Point.h>
#include <geometry_msgs/Pose.h>
#include <geometry_msgs/PoseStamped.h>
#include <lvr2/geometry/Handles.hpp>
#include <lvr2/attrmaps/AttrMaps.hpp>
#include <lvr2/geometry/BaseVector.hpp>
#include <lvr2/geometry/Normal.hpp>
#include <std_msgs/ColorRGBA.h>
#include <tf2/LinearMath/Vector3.h>

namespace mesh_map
{
Expand Down Expand Up @@ -206,6 +208,24 @@ std_msgs::ColorRGBA getRainbowColor(const float value);
*/
void getRainbowColor(float value, float& r, float& g, float& b);

/**
* Converts the orientation of a geometry_msgs/PoseStamped message to a direction vector
* @param pose the pose to convert
* @return direction normal vector
*/
mesh_map::Normal poseToDirectionVector(
const geometry_msgs::PoseStamped& pose,
const tf2::Vector3& axis=tf2::Vector3(1,0,0));


/**
* Converts the position of a geometry_msgs/PoseStamped message to a position vector
* @param pose the pose to convert
* @return position vector
*/
mesh_map::Vector poseToPositionVector(
const geometry_msgs::PoseStamped& pose);

} /* namespace mesh_map */

#endif // MESH_MAP__UTIL_H
14 changes: 14 additions & 0 deletions mesh_map/src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,18 @@ void getRainbowColor(float value, float& r, float& g, float& b)
r = 1, g = n, b = 0;
}

mesh_map::Normal poseToDirectionVector(const geometry_msgs::PoseStamped& pose, const tf2::Vector3& axis)
{
tf2::Stamped<tf2::Transform> transform;
fromMsg(pose, transform);
tf2::Vector3 v = transform.getBasis() * axis;
return mesh_map::Normal(v.x(), v.y(), v.z());
}


mesh_map::Vector poseToPositionVector(const geometry_msgs::PoseStamped& pose)
{
return mesh_map::Vector(pose.pose.position.x, pose.pose.position.y, pose.pose.position.z);
}

} /* namespace mesh_map */

0 comments on commit 60c6af2

Please sign in to comment.