Point Cloud Library (PCL)  1.7.1
range_image_planar.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010, Willow Garage, Inc.
6  * Copyright (c) 2012-, Open Perception, Inc.
7  *
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * * Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  * * Redistributions in binary form must reproduce the above
17  * copyright notice, this list of conditions and the following
18  * disclaimer in the documentation and/or other materials provided
19  * with the distribution.
20  * * Neither the name of the copyright holder(s) nor the names of its
21  * contributors may be used to endorse or promote products derived
22  * from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #ifndef PCL_RANGE_IMAGE_PLANAR_H_
39 #define PCL_RANGE_IMAGE_PLANAR_H_
40 
41 #include <pcl/range_image/range_image.h>
42 
43 namespace pcl
44 {
45  /** \brief @b RangeImagePlanar is derived from the original range image and differs from it because it's not a
46  * spherical projection, but using a projection plane (as normal cameras do), therefore being better applicable
47  * for range sensors that already provide a range image by themselves (stereo cameras, ToF-cameras), so that
48  * a conversion to point cloud and then to a spherical range image becomes unnecessary.
49  * \author Bastian Steder
50  * \ingroup range_image
51  */
53  {
54  public:
55  // =====TYPEDEFS=====
57  typedef boost::shared_ptr<RangeImagePlanar> Ptr;
58  typedef boost::shared_ptr<const RangeImagePlanar> ConstPtr;
59 
60  // =====CONSTRUCTOR & DESTRUCTOR=====
61  /** Constructor */
62  PCL_EXPORTS RangeImagePlanar ();
63  /** Destructor */
64  PCL_EXPORTS virtual ~RangeImagePlanar ();
65 
66  /** Return a newly created RangeImagePlanar.
67  * Reimplmentation to return an image of the same type. */
68  virtual RangeImage*
69  getNew () const { return new RangeImagePlanar; }
70 
71  /** Copy *this to other. Derived version - also copying additonal RangeImagePlanar members */
72  PCL_EXPORTS virtual void
73  copyTo (RangeImage& other) const;
74 
75  // =====PUBLIC METHODS=====
76  /** \brief Get a boost shared pointer of a copy of this */
77  inline Ptr
78  makeShared () { return Ptr (new RangeImagePlanar (*this)); }
79 
80  /** \brief Create the image from an existing disparity image.
81  * \param disparity_image the input disparity image data
82  * \param di_width the disparity image width
83  * \param di_height the disparity image height
84  * \param focal_length the focal length of the primary camera that generated the disparity image
85  * \param base_line the baseline of the stereo pair that generated the disparity image
86  * \param desired_angular_resolution If this is set, the system will skip as many pixels as necessary to get as
87  * close to this angular resolution as possible while not going over this value (the density will not be
88  * lower than this value). The value is in radians per pixel.
89  */
90  PCL_EXPORTS void
91  setDisparityImage (const float* disparity_image, int di_width, int di_height,
92  float focal_length, float base_line, float desired_angular_resolution=-1);
93 
94  /** Create the image from an existing depth image.
95  * \param depth_image the input depth image data as float values
96  * \param di_width the disparity image width
97  * \param di_height the disparity image height
98  * \param di_center_x the x-coordinate of the camera's center of projection
99  * \param di_center_y the y-coordinate of the camera's center of projection
100  * \param di_focal_length_x the camera's focal length in the horizontal direction
101  * \param di_focal_length_y the camera's focal length in the vertical direction
102  * \param desired_angular_resolution If this is set, the system will skip as many pixels as necessary to get as
103  * close to this angular resolution as possible while not going over this value (the density will not be
104  * lower than this value). The value is in radians per pixel.
105  */
106  PCL_EXPORTS void
107  setDepthImage (const float* depth_image, int di_width, int di_height, float di_center_x, float di_center_y,
108  float di_focal_length_x, float di_focal_length_y, float desired_angular_resolution=-1);
109 
110  /** Create the image from an existing depth image.
111  * \param depth_image the input disparity image data as short values describing millimeters
112  * \param di_width the disparity image width
113  * \param di_height the disparity image height
114  * \param di_center_x the x-coordinate of the camera's center of projection
115  * \param di_center_y the y-coordinate of the camera's center of projection
116  * \param di_focal_length_x the camera's focal length in the horizontal direction
117  * \param di_focal_length_y the camera's focal length in the vertical direction
118  * \param desired_angular_resolution If this is set, the system will skip as many pixels as necessary to get as
119  * close to this angular resolution as possible while not going over this value (the density will not be
120  * lower than this value). The value is in radians per pixel.
121  */
122  PCL_EXPORTS void
123  setDepthImage (const unsigned short* depth_image, int di_width, int di_height, float di_center_x, float di_center_y,
124  float di_focal_length_x, float di_focal_length_y, float desired_angular_resolution=-1);
125 
126  /** Create the image from an existing point cloud.
127  * \param point_cloud the source point cloud
128  * \param di_width the disparity image width
129  * \param di_height the disparity image height
130  * \param di_center_x the x-coordinate of the camera's center of projection
131  * \param di_center_y the y-coordinate of the camera's center of projection
132  * \param di_focal_length_x the camera's focal length in the horizontal direction
133  * \param di_focal_length_y the camera's focal length in the vertical direction
134  * \param sensor_pose the pose of the virtual depth camera
135  * \param coordinate_frame the used coordinate frame of the point cloud
136  * \param noise_level what is the typical noise of the sensor - is used for averaging in the z-buffer
137  * \param min_range minimum range to consifder points
138  */
139  template <typename PointCloudType> void
140  createFromPointCloudWithFixedSize (const PointCloudType& point_cloud,
141  int di_width, int di_height, float di_center_x, float di_center_y,
142  float di_focal_length_x, float di_focal_length_y,
143  const Eigen::Affine3f& sensor_pose,
144  CoordinateFrame coordinate_frame=CAMERA_FRAME, float noise_level=0.0f,
145  float min_range=0.0f);
146 
147  // Since we reimplement some of these overloaded functions, we have to do the following:
150 
151  /** \brief Calculate the 3D point according to the given image point and range
152  * \param image_x the x image position
153  * \param image_y the y image position
154  * \param range the range
155  * \param point the resulting 3D point
156  * \note Implementation according to planar range images (compared to spherical as in the original)
157  */
158  virtual inline void
159  calculate3DPoint (float image_x, float image_y, float range, Eigen::Vector3f& point) const;
160 
161  /** \brief Calculate the image point and range from the given 3D point
162  * \param point the resulting 3D point
163  * \param image_x the resulting x image position
164  * \param image_y the resulting y image position
165  * \param range the resulting range
166  * \note Implementation according to planar range images (compared to spherical as in the original)
167  */
168  virtual inline void
169  getImagePoint (const Eigen::Vector3f& point, float& image_x, float& image_y, float& range) const;
170 
171  /** Get a sub part of the complete image as a new range image.
172  * \param sub_image_image_offset_x - The x coordinate of the top left pixel of the sub image.
173  * This is always according to absolute 0,0 meaning -180°,-90°
174  * and it is already in the system of the new image, so the
175  * actual pixel used in the original image is
176  * combine_pixels* (image_offset_x-image_offset_x_)
177  * \param sub_image_image_offset_y - Same as image_offset_x for the y coordinate
178  * \param sub_image_width - width of the new image
179  * \param sub_image_height - height of the new image
180  * \param combine_pixels - shrinking factor, meaning the new angular resolution
181  * is combine_pixels times the old one
182  * \param sub_image - the output image
183  */
184  PCL_EXPORTS virtual void
185  getSubImage (int sub_image_image_offset_x, int sub_image_image_offset_y, int sub_image_width,
186  int sub_image_height, int combine_pixels, RangeImage& sub_image) const;
187 
188  //! Get a range image with half the resolution
189  PCL_EXPORTS virtual void
190  getHalfImage (RangeImage& half_image) const;
191 
192  //! Getter for the focal length in X
193  inline float
194  getFocalLengthX () const { return focal_length_x_; }
195 
196  //! Getter for the focal length in Y
197  inline float
198  getFocalLengthY () const { return focal_length_y_; }
199 
200  //! Getter for the principal point in X
201  inline float
202  getCenterX () const { return center_x_; }
203 
204  //! Getter for the principal point in Y
205  inline float
206  getCenterY () const { return center_y_; }
207 
208 
209  protected:
210  float focal_length_x_, focal_length_y_; //!< The focal length of the image in pixels
211  float focal_length_x_reciprocal_, focal_length_y_reciprocal_; //!< 1/focal_length -> for internal use
212  float center_x_, center_y_; //!< The principle point of the image
213  };
214 } // namespace end
215 
216 
217 #include <pcl/range_image/impl/range_image_planar.hpp> // Definitions of templated and inline functions
218 
219 #endif //#ifndef PCL_RANGE_IMAGE_H_