Point Cloud Library (PCL)  1.9.1
range_image_spherical.hpp
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2012-, Open Perception, 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 the copyright holder(s) 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 
42 /////////////////////////////////////////////////////////////////////////
43 void
44 RangeImageSpherical::calculate3DPoint (float image_x, float image_y, float range, Eigen::Vector3f& point) const
45 {
46  float angle_x, angle_y;
47  getAnglesFromImagePoint (image_x, image_y, angle_x, angle_y);
48 
49  float cosY = cosf (angle_y);
50  point = Eigen::Vector3f (range * sinf (angle_x) * cosY, range * sinf (angle_y), range * cosf (angle_x)*cosY);
51  point = to_world_system_ * point;
52 }
53 
54 /////////////////////////////////////////////////////////////////////////
55 inline void
56 RangeImageSpherical::getImagePoint (const Eigen::Vector3f& point, float& image_x, float& image_y, float& range) const
57 {
58  Eigen::Vector3f transformedPoint = to_range_image_system_ * point;
59  range = transformedPoint.norm ();
60  float angle_x = atan2LookUp (transformedPoint[0], transformedPoint[2]),
61  angle_y = asinLookUp (transformedPoint[1]/range);
62  getImagePointFromAngles (angle_x, angle_y, image_x, image_y);
63 }
64 /////////////////////////////////////////////////////////////////////////
65 void
66 RangeImageSpherical::getAnglesFromImagePoint (float image_x, float image_y, float& angle_x, float& angle_y) const
67 {
68  angle_y = (image_y+static_cast<float> (image_offset_y_))*angular_resolution_y_ - 0.5f*static_cast<float> (M_PI);
69  angle_x = ((image_x+ static_cast<float> (image_offset_x_))*angular_resolution_x_ - static_cast<float> (M_PI));
70 }
71 /////////////////////////////////////////////////////////////////////////
72 void
73 RangeImageSpherical::getImagePointFromAngles (float angle_x, float angle_y, float& image_x, float& image_y) const
74 {
75  image_x = (angle_x + static_cast<float> (M_PI))*angular_resolution_x_reciprocal_ - static_cast<float> (image_offset_x_);
76  image_y = (angle_y + 0.5f*static_cast<float> (M_PI))*angular_resolution_y_reciprocal_ - static_cast<float> (image_offset_y_);
77 }
78 } // namespace end
float angular_resolution_x_
Angular resolution of the range image in x direction in radians per pixel.
Definition: range_image.h:772
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
int image_offset_y_
Position of the top left corner of the range image compared to an image of full size (360x180 degrees...
Definition: range_image.h:778
void getAnglesFromImagePoint(float image_x, float image_y, float &angle_x, float &angle_y) const
Get the angles corresponding to the given image point.
static float atan2LookUp(float y, float x)
Query the atan2 lookup table.
Definition: range_image.hpp:60
void getImagePointFromAngles(float angle_x, float angle_y, float &image_x, float &image_y) const
Get the image point corresponding to the given ranges.
virtual void calculate3DPoint(float image_x, float image_y, float range, Eigen::Vector3f &point) const
Calculate the 3D point according to the given image point and range.
float angular_resolution_y_reciprocal_
1.0/angular_resolution_y_ - provided for better performance of multiplication compared to division
Definition: range_image.h:776
float angular_resolution_x_reciprocal_
1.0/angular_resolution_x_ - provided for better performance of multiplication compared to division
Definition: range_image.h:774
Eigen::Affine3f to_range_image_system_
Inverse of to_world_system_.
Definition: range_image.h:770
Eigen::Affine3f to_world_system_
Inverse of to_range_image_system_.
Definition: range_image.h:771
virtual void getImagePoint(const Eigen::Vector3f &point, float &image_x, float &image_y, float &range) const
Calculate the image point and range from the given 3D point.
static float asinLookUp(float value)
Query the asin lookup table.
Definition: range_image.hpp:50
float angular_resolution_y_
Angular resolution of the range image in y direction in radians per pixel.
Definition: range_image.h:773