tf2_sensor_msgs.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, Willow Garage, Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #ifndef TF2_SENSOR_MSGS_H
00031 #define TF2_SENSOR_MSGS_H
00032 
00033 #include <tf2/convert.h>
00034 #include <sensor_msgs/PointCloud2.h>
00035 #include <sensor_msgs/point_cloud2_iterator.h>
00036 #include <Eigen/Eigen>
00037 #include <Eigen/Geometry>
00038 
00039 namespace tf2
00040 {
00041 
00042 /********************/
00044 /********************/
00045 
00052 template <>
00053 inline
00054 const ros::Time& getTimestamp(const sensor_msgs::PointCloud2& p) {return p.header.stamp;}
00055 
00062 template <>
00063 inline
00064 const std::string& getFrameId(const sensor_msgs::PointCloud2 &p) {return p.header.frame_id;}
00065 
00066 // this method needs to be implemented by client library developers
00067 template <>
00068 inline
00069 void doTransform(const sensor_msgs::PointCloud2 &p_in, sensor_msgs::PointCloud2 &p_out, const geometry_msgs::TransformStamped& t_in)
00070 {
00071   p_out = p_in;
00072   p_out.header = t_in.header;
00073   Eigen::Transform<float,3,Eigen::Affine> t = Eigen::Translation3f(t_in.transform.translation.x, t_in.transform.translation.y,
00074                                                                    t_in.transform.translation.z) * Eigen::Quaternion<float>(
00075                                                                      t_in.transform.rotation.w, t_in.transform.rotation.x,
00076                                                                      t_in.transform.rotation.y, t_in.transform.rotation.z);
00077 
00078   sensor_msgs::PointCloud2ConstIterator<float> x_in(p_in, "x");
00079   sensor_msgs::PointCloud2ConstIterator<float> y_in(p_in, "y");
00080   sensor_msgs::PointCloud2ConstIterator<float> z_in(p_in, "z");
00081 
00082   sensor_msgs::PointCloud2Iterator<float> x_out(p_out, "x");
00083   sensor_msgs::PointCloud2Iterator<float> y_out(p_out, "y");
00084   sensor_msgs::PointCloud2Iterator<float> z_out(p_out, "z");
00085 
00086   Eigen::Vector3f point;
00087   for(; x_in != x_in.end(); ++x_in, ++y_in, ++z_in, ++x_out, ++y_out, ++z_out) {
00088     point = t * Eigen::Vector3f(*x_in, *y_in, *z_in);
00089     *x_out = point.x();
00090     *y_out = point.y();
00091     *z_out = point.z();
00092   }
00093 }
00094 inline
00095 sensor_msgs::PointCloud2 toMsg(const sensor_msgs::PointCloud2 &in)
00096 {
00097   return in;
00098 }
00099 inline
00100 void fromMsg(const sensor_msgs::PointCloud2 &msg, sensor_msgs::PointCloud2 &out)
00101 {
00102   out = msg;
00103 }
00104 
00105 } // namespace
00106 
00107 #endif // TF2_SENSOR_MSGS_H


tf2_sensor_msgs
Author(s): Vincent Rabaud
autogenerated on Thu Jun 6 2019 20:23:17