Skip to content

Commit 2b478da

Browse files
committed
timepoint conversion: sensor_msgs
1 parent 874e471 commit 2b478da

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

tf2_sensor_msgs/include/tf2_sensor_msgs/tf2_sensor_msgs.hpp

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
* POSSIBILITY OF SUCH DAMAGE.
2828
*/
2929

30-
#ifndef TF2_SENSOR_MSGS_HPP
31-
#define TF2_SENSOR_MSGS_HPP
30+
#ifndef TF2_SENSOR_MSGS__TF2_SENSOR_MSGS_HPP_
31+
#define TF2_SENSOR_MSGS__TF2_SENSOR_MSGS_HPP_
3232

3333
#include <tf2/convert.h>
3434
#include <tf2/time.h>
@@ -38,6 +38,8 @@
3838
#include <Eigen/Geometry>
3939
#include <tf2_ros/buffer_interface.h>
4040

41+
#include <string>
42+
4143
namespace tf2
4244
{
4345

@@ -46,19 +48,24 @@ namespace tf2
4648
/********************/
4749

4850
// method to extract timestamp from object
49-
template <>
51+
template<>
5052
inline
51-
tf2::TimePoint getTimestamp(const sensor_msgs::msg::PointCloud2& p) {return tf2_ros::fromMsg(p.header.stamp);}
53+
tf2::TimePoint getTimestamp(const sensor_msgs::msg::PointCloud2 & p)
54+
{
55+
return tf2::TimePointFromMsg(p.header.stamp);
56+
}
5257

5358
// method to extract frame id from object
54-
template <>
59+
template<>
5560
inline
56-
std::string getFrameId(const sensor_msgs::msg::PointCloud2 &p) {return p.header.frame_id;}
61+
std::string getFrameId(const sensor_msgs::msg::PointCloud2 & p) {return p.header.frame_id;}
5762

5863
// this method needs to be implemented by client library developers
59-
template <>
64+
template<>
6065
inline
61-
void doTransform(const sensor_msgs::msg::PointCloud2 &p_in, sensor_msgs::msg::PointCloud2 &p_out, const geometry_msgs::msg::TransformStamped& t_in)
66+
void doTransform(
67+
const sensor_msgs::msg::PointCloud2 & p_in, sensor_msgs::msg::PointCloud2 & p_out,
68+
const geometry_msgs::msg::TransformStamped & t_in)
6269
{
6370
p_out = p_in;
6471
p_out.header = t_in.header;
@@ -76,7 +83,7 @@ void doTransform(const sensor_msgs::msg::PointCloud2 &p_in, sensor_msgs::msg::Po
7683
static_cast<float>(t_in.transform.rotation.y),
7784
static_cast<float>(t_in.transform.rotation.z));
7885

79-
Eigen::Transform<float,3,Eigen::Affine> t = translation * quaternion;
86+
Eigen::Transform<float, 3, Eigen::Affine> t = translation * quaternion;
8087

8188
sensor_msgs::PointCloud2ConstIterator<float> x_in(p_in, std::string("x"));
8289
sensor_msgs::PointCloud2ConstIterator<float> y_in(p_in, std::string("y"));
@@ -87,24 +94,14 @@ void doTransform(const sensor_msgs::msg::PointCloud2 &p_in, sensor_msgs::msg::Po
8794
sensor_msgs::PointCloud2Iterator<float> z_out(p_out, std::string("z"));
8895

8996
Eigen::Vector3f point;
90-
for(; x_in != x_in.end(); ++x_in, ++y_in, ++z_in, ++x_out, ++y_out, ++z_out) {
97+
for (; x_in != x_in.end(); ++x_in, ++y_in, ++z_in, ++x_out, ++y_out, ++z_out) {
9198
point = t * Eigen::Vector3f(*x_in, *y_in, *z_in);
9299
*x_out = point.x();
93100
*y_out = point.y();
94101
*z_out = point.z();
95102
}
96103
}
97-
inline
98-
sensor_msgs::msg::PointCloud2 toMsg(const sensor_msgs::msg::PointCloud2 &in)
99-
{
100-
return in;
101-
}
102-
inline
103-
void fromMsg(const sensor_msgs::msg::PointCloud2 &msg, sensor_msgs::msg::PointCloud2 &out)
104-
{
105-
out = msg;
106-
}
107104

108-
} // namespace
105+
} // namespace tf2
109106

110-
#endif // TF2_SENSOR_MSGS_HPP
107+
#endif // TF2_SENSOR_MSGS__TF2_SENSOR_MSGS_HPP_

0 commit comments

Comments
 (0)