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