util3d_transforms.cpp
Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
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     * Redistributions of source code must retain the above copyright
00008       notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright
00010       notice, this list of conditions and the following disclaimer in the
00011       documentation and/or other materials provided with the distribution.
00012     * Neither the name of the Universite de Sherbrooke nor the
00013       names of its contributors may be used to endorse or promote products
00014       derived from this software without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00017 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
00020 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00021 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00022 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00023 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00025 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 */
00027 
00028 #include "rtabmap/core/util3d_transforms.h"
00029 
00030 #include <pcl/common/transforms.h>
00031 
00032 namespace rtabmap
00033 {
00034 
00035 namespace util3d
00036 {
00037 
00038 pcl::PointCloud<pcl::PointXYZ>::Ptr transformPointCloud(
00039                 const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud,
00040                 const Transform & transform)
00041 {
00042         pcl::PointCloud<pcl::PointXYZ>::Ptr output(new pcl::PointCloud<pcl::PointXYZ>);
00043         pcl::transformPointCloud(*cloud, *output, transform.toEigen4f());
00044         return output;
00045 }
00046 pcl::PointCloud<pcl::PointXYZRGB>::Ptr transformPointCloud(
00047                 const pcl::PointCloud<pcl::PointXYZRGB>::Ptr & cloud,
00048                 const Transform & transform)
00049 {
00050         pcl::PointCloud<pcl::PointXYZRGB>::Ptr output(new pcl::PointCloud<pcl::PointXYZRGB>);
00051         pcl::transformPointCloud(*cloud, *output, transform.toEigen4f());
00052         return output;
00053 }
00054 pcl::PointCloud<pcl::PointNormal>::Ptr transformPointCloud(
00055                 const pcl::PointCloud<pcl::PointNormal>::Ptr & cloud,
00056                 const Transform & transform)
00057 {
00058         pcl::PointCloud<pcl::PointNormal>::Ptr output(new pcl::PointCloud<pcl::PointNormal>);
00059         pcl::transformPointCloudWithNormals(*cloud, *output, transform.toEigen4f());
00060         return output;
00061 }
00062 pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr transformPointCloud(
00063                 const pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr & cloud,
00064                 const Transform & transform)
00065 {
00066         pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr output(new pcl::PointCloud<pcl::PointXYZRGBNormal>);
00067         pcl::transformPointCloudWithNormals(*cloud, *output, transform.toEigen4f());
00068         return output;
00069 }
00070 
00071 cv::Point3f transformPoint(
00072                 const cv::Point3f & point,
00073                 const Transform & transform)
00074 {
00075         cv::Point3f ret = point;
00076         ret.x = transform (0, 0) * point.x + transform (0, 1) * point.y + transform (0, 2) * point.z + transform (0, 3);
00077         ret.y = transform (1, 0) * point.x + transform (1, 1) * point.y + transform (1, 2) * point.z + transform (1, 3);
00078         ret.z = transform (2, 0) * point.x + transform (2, 1) * point.y + transform (2, 2) * point.z + transform (2, 3);
00079         return ret;
00080 }
00081 pcl::PointXYZ transformPoint(
00082                 const pcl::PointXYZ & pt,
00083                 const Transform & transform)
00084 {
00085         return pcl::transformPoint(pt, transform.toEigen3f());
00086 }
00087 pcl::PointXYZRGB transformPoint(
00088                 const pcl::PointXYZRGB & pt,
00089                 const Transform & transform)
00090 {
00091         return pcl::transformPoint(pt, transform.toEigen3f());
00092 }
00093 pcl::PointNormal transformPoint(
00094                 const pcl::PointNormal & point,
00095                 const Transform & transform)
00096 {
00097         pcl::PointNormal ret;
00098         Eigen::Matrix<float, 3, 1> pt (point.x, point.y, point.z);
00099         ret.x = static_cast<float> (transform (0, 0) * pt.coeffRef (0) + transform (0, 1) * pt.coeffRef (1) + transform (0, 2) * pt.coeffRef (2) + transform (0, 3));
00100         ret.y = static_cast<float> (transform (1, 0) * pt.coeffRef (0) + transform (1, 1) * pt.coeffRef (1) + transform (1, 2) * pt.coeffRef (2) + transform (1, 3));
00101         ret.z = static_cast<float> (transform (2, 0) * pt.coeffRef (0) + transform (2, 1) * pt.coeffRef (1) + transform (2, 2) * pt.coeffRef (2) + transform (2, 3));
00102 
00103         // Rotate normals
00104         Eigen::Matrix<float, 3, 1> nt (point.normal_x, point.normal_y, point.normal_z);
00105         ret.normal_x = static_cast<float> (transform (0, 0) * nt.coeffRef (0) + transform (0, 1) * nt.coeffRef (1) + transform (0, 2) * nt.coeffRef (2));
00106         ret.normal_y = static_cast<float> (transform (1, 0) * nt.coeffRef (0) + transform (1, 1) * nt.coeffRef (1) + transform (1, 2) * nt.coeffRef (2));
00107         ret.normal_z = static_cast<float> (transform (2, 0) * nt.coeffRef (0) + transform (2, 1) * nt.coeffRef (1) + transform (2, 2) * nt.coeffRef (2));
00108         return ret;
00109 }
00110 
00111 }
00112 
00113 }


rtabmap
Author(s): Mathieu Labbe
autogenerated on Sat Jul 23 2016 11:44:28