Point Cloud Library (PCL)
1.7.0
|
00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Point Cloud Library (PCL) - www.pointclouds.org 00005 * Copyright (c) 2010, Willow Garage, Inc. 00006 * Copyright (c) 2012-, Open Perception, Inc. 00007 * 00008 * All rights reserved. 00009 * 00010 * Redistribution and use in source and binary forms, with or without 00011 * modification, are permitted provided that the following conditions 00012 * are met: 00013 * 00014 * * Redistributions of source code must retain the above copyright 00015 * notice, this list of conditions and the following disclaimer. 00016 * * Redistributions in binary form must reproduce the above 00017 * copyright notice, this list of conditions and the following 00018 * disclaimer in the documentation and/or other materials provided 00019 * with the distribution. 00020 * * Neither the name of the copyright holder(s) nor the names of its 00021 * contributors may be used to endorse or promote products derived 00022 * from this software without specific prior written permission. 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00025 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00026 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00027 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00028 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00029 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00030 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00031 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00032 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00033 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00034 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00035 * POSSIBILITY OF SUCH DAMAGE. 00036 * 00037 */ 00038 00039 #ifndef PCL_RANGE_IMAGE_PLANAR_IMPL_HPP_ 00040 #define PCL_RANGE_IMAGE_PLANAR_IMPL_HPP_ 00041 00042 #include <pcl/pcl_macros.h> 00043 #include <pcl/common/eigen.h> 00044 00045 namespace pcl 00046 { 00047 00048 ///////////////////////////////////////////////////////////////////////// 00049 template <typename PointCloudType> void 00050 RangeImagePlanar::createFromPointCloudWithFixedSize (const PointCloudType& point_cloud, 00051 int di_width, int di_height, 00052 float di_center_x, float di_center_y, 00053 float di_focal_length_x, float di_focal_length_y, 00054 const Eigen::Affine3f& sensor_pose, 00055 CoordinateFrame coordinate_frame, float noise_level, 00056 float min_range) 00057 { 00058 //std::cout << "Starting to create range image from "<<point_cloud.points.size ()<<" points.\n"; 00059 00060 width = di_width; 00061 height = di_height; 00062 center_x_ = di_center_x; 00063 center_y_ = di_center_y; 00064 focal_length_x_ = di_focal_length_x; 00065 focal_length_y_ = di_focal_length_y; 00066 focal_length_x_reciprocal_ = 1 / focal_length_x_; 00067 focal_length_y_reciprocal_ = 1 / focal_length_y_; 00068 00069 is_dense = false; 00070 00071 getCoordinateFrameTransformation (coordinate_frame, to_world_system_); 00072 to_world_system_ = sensor_pose * to_world_system_; 00073 00074 to_range_image_system_ = to_world_system_.inverse (Eigen::Isometry); 00075 00076 unsigned int size = width*height; 00077 points.clear (); 00078 points.resize (size, unobserved_point); 00079 00080 int top=height, right=-1, bottom=-1, left=width; 00081 doZBuffer (point_cloud, noise_level, min_range, top, right, bottom, left); 00082 00083 // Do not crop 00084 //cropImage (border_size, top, right, bottom, left); 00085 00086 recalculate3DPointPositions (); 00087 } 00088 00089 00090 ///////////////////////////////////////////////////////////////////////// 00091 void 00092 RangeImagePlanar::calculate3DPoint (float image_x, float image_y, float range, Eigen::Vector3f& point) const 00093 { 00094 //cout << __PRETTY_FUNCTION__ << " called.\n"; 00095 float delta_x = (image_x+static_cast<float> (image_offset_x_)-center_x_)*focal_length_x_reciprocal_, 00096 delta_y = (image_y+static_cast<float> (image_offset_y_)-center_y_)*focal_length_y_reciprocal_; 00097 point[2] = range / (sqrtf (delta_x*delta_x + delta_y*delta_y + 1)); 00098 point[0] = delta_x*point[2]; 00099 point[1] = delta_y*point[2]; 00100 point = to_world_system_ * point; 00101 } 00102 00103 ///////////////////////////////////////////////////////////////////////// 00104 inline void 00105 RangeImagePlanar::getImagePoint (const Eigen::Vector3f& point, float& image_x, float& image_y, float& range) const 00106 { 00107 Eigen::Vector3f transformedPoint = to_range_image_system_ * point; 00108 if (transformedPoint[2]<=0) // Behind the observer? 00109 { 00110 image_x = image_y = range = -1.0f; 00111 return; 00112 } 00113 range = transformedPoint.norm (); 00114 00115 image_x = center_x_ + focal_length_x_*transformedPoint[0]/transformedPoint[2] - static_cast<float> (image_offset_x_); 00116 image_y = center_y_ + focal_length_y_*transformedPoint[1]/transformedPoint[2] - static_cast<float> (image_offset_y_); 00117 } 00118 00119 } // namespace end 00120 00121 #endif 00122