Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
range_image_planar.hpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2010, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage, Inc. nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  */
35 
36 #include <pcl/pcl_macros.h>
37 #include <pcl/common/eigen.h>
38 
39 namespace pcl
40 {
41 
43 template <typename PointCloudType> void
44 RangeImagePlanar::createFromPointCloudWithFixedSize (const PointCloudType& point_cloud,
45  int di_width, int di_height,
46  float di_center_x, float di_center_y,
47  float di_focal_length_x, float di_focal_length_y,
48  const Eigen::Affine3f& sensor_pose,
49  CoordinateFrame coordinate_frame, float noise_level,
50  float min_range)
51 {
52  //std::cout << "Starting to create range image from "<<point_cloud.points.size ()<<" points.\n";
53 
54  width = di_width;
55  height = di_height;
56  center_x_ = di_center_x;
57  center_y_ = di_center_y;
58  focal_length_x_ = di_focal_length_x;
59  focal_length_y_ = di_focal_length_y;
60  focal_length_x_reciprocal_ = 1 / focal_length_x_;
61  focal_length_y_reciprocal_ = 1 / focal_length_y_;
62 
63  is_dense = false;
64 
65  getCoordinateFrameTransformation (coordinate_frame, to_world_system_);
66  to_world_system_ = sensor_pose * to_world_system_;
67 
68  to_range_image_system_ = to_world_system_.inverse (Eigen::Isometry);
69 
70  unsigned int size = width*height;
71  points.clear ();
72  points.resize (size, unobserved_point);
73 
74  int top=height, right=-1, bottom=-1, left=width;
75  doZBuffer (point_cloud, noise_level, min_range, top, right, bottom, left);
76 
77  // Do not crop
78  //cropImage (border_size, top, right, bottom, left);
79 
81 }
82 
83 
85 void
86 RangeImagePlanar::calculate3DPoint (float image_x, float image_y, float range, Eigen::Vector3f& point) const
87 {
88  //cout << __PRETTY_FUNCTION__ << " called.\n";
89  float delta_x = (image_x-center_x_)*focal_length_x_reciprocal_,
90  delta_y = (image_y-center_y_)*focal_length_y_reciprocal_;
91  point[2] = range / (sqrtf (delta_x*delta_x + delta_y*delta_y + 1));
92  point[0] = delta_x*point[2];
93  point[1] = delta_y*point[2];
94  point = to_world_system_ * point;
95 }
96 
98 inline void
99 RangeImagePlanar::getImagePoint (const Eigen::Vector3f& point, float& image_x, float& image_y, float& range) const
100 {
101  Eigen::Vector3f transformedPoint = to_range_image_system_ * point;
102  range = transformedPoint.norm ();
103 
104  image_x = center_x_ + focal_length_x_*transformedPoint[0]/transformedPoint[2];
105  image_y = center_y_ + focal_length_y_*transformedPoint[1]/transformedPoint[2];
106 }
107 
108 } // namespace end