00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00039 #include <iostream>
00040 using std::cout;
00041 using std::cerr;
00042
00043 #include <pcl/range_image/range_image_planar.h>
00044
00045 namespace pcl
00046 {
00047
00049 RangeImagePlanar::RangeImagePlanar () : RangeImage(), focal_length_x_(0.0f), focal_length_y_(0.0f),
00050 focal_length_x_reciprocal_(0.0f), focal_length_y_reciprocal_(0.0f),
00051 center_x_(0.0f), center_y_(0.0f)
00052 {
00053 }
00054
00056 RangeImagePlanar::~RangeImagePlanar ()
00057 {
00058 }
00059
00061 void
00062 RangeImagePlanar::setDisparityImage (const float* disparity_image, int di_width, int di_height,
00063 float focal_length, float base_line, float desired_angular_resolution)
00064 {
00065
00066 reset ();
00067
00068 float original_angular_resolution = asinf (0.5f*float(di_width)/float(focal_length)) / (0.5f*float(di_width));
00069 int skip = 1;
00070 if (desired_angular_resolution >= 2.0f*original_angular_resolution)
00071 {
00072 skip = lrint (floor (desired_angular_resolution/original_angular_resolution));
00073 }
00074
00075 setAngularResolution (original_angular_resolution * skip);
00076 width = di_width / skip;
00077 height = di_height / skip;
00078 focal_length_x_ = focal_length_y_ = focal_length / skip;
00079 focal_length_x_reciprocal_ = focal_length_y_reciprocal_ = 1.0f / focal_length_x_;
00080 center_x_ = float(di_width) / float(2*skip);
00081 center_y_ = float(di_height) / float(2*skip);
00082 points.resize(width*height);
00083
00084
00085
00086 float normalization_factor = skip*focal_length_x_*base_line;
00087 for (int y=0; y<(int)height; ++y)
00088 {
00089 for (int x=0; x<(int)width; ++x)
00090 {
00091 PointWithRange& point = getPointNoCheck(x,y);
00092 float disparity = disparity_image[(y*skip)*di_width + x*skip];
00093 if (disparity <= 0.0f)
00094 {
00095
00096 point = unobserved_point;
00097 continue;
00098 }
00099 point.z = normalization_factor / disparity;
00100 point.x = (x-center_x_)*point.z * focal_length_x_reciprocal_;
00101 point.y = (y-center_y_)*point.z * focal_length_y_reciprocal_;
00102 point.range = point.getVector3fMap().norm();
00103
00104
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 }
00116 }
00117 }
00118
00119
00121 void
00122 RangeImagePlanar::setDepthImage (const float* depth_image, int di_width, int di_height,
00123 float di_center_x, float di_center_y,
00124 float di_focal_length_x, float di_focal_length_y,
00125 float desired_angular_resolution)
00126 {
00127
00128 reset ();
00129
00130 float original_angular_resolution = asinf (0.5f*float(di_width)/float(di_focal_length_x)) / (0.5f*float(di_width));
00131 int skip = 1;
00132 if (desired_angular_resolution >= 2.0f*original_angular_resolution)
00133 {
00134 skip = lrint (floor (desired_angular_resolution/original_angular_resolution));
00135 }
00136
00137 setAngularResolution (original_angular_resolution * skip);
00138 width = di_width / skip;
00139 height = di_height / skip;
00140 focal_length_x_ = di_focal_length_x / skip;
00141 focal_length_x_reciprocal_ = 1.0f / focal_length_x_;
00142 focal_length_y_ = di_focal_length_y / skip;
00143 focal_length_y_reciprocal_ = 1.0f / focal_length_y_;
00144 center_x_ = float(di_center_x) / float(skip);
00145 center_y_ = float(di_center_y) / float(skip);
00146 points.resize(width*height);
00147
00148
00149
00150 for (int y=0; y<(int)height; ++y)
00151 {
00152 for (int x=0; x<(int)width; ++x)
00153 {
00154 PointWithRange& point = getPointNoCheck(x,y);
00155 float depth = depth_image[(y*skip)*di_width + x*skip];
00156 if (depth <= 0.0f || !pcl_isfinite(depth))
00157 {
00158
00159 point = unobserved_point;
00160 continue;
00161 }
00162 point.z = depth;
00163 point.x = (x-center_x_)*point.z * focal_length_x_reciprocal_;
00164 point.y = (y-center_y_)*point.z * focal_length_y_reciprocal_;
00165 point.range = point.getVector3fMap().norm();
00166 }
00167 }
00168 }
00169
00171 void
00172 RangeImagePlanar::getHalfImage(RangeImage& half_image) const
00173 {
00174
00175 if (typeid(*this) != typeid(half_image))
00176 {
00177 std::cerr << __PRETTY_FUNCTION__<<": Given range image is not a RangeImagePlanar!\n";
00178 return;
00179 }
00180 RangeImagePlanar& ret = *((RangeImagePlanar*)&half_image);
00181
00182 ret.focal_length_x_ = focal_length_x_/2;
00183 ret.focal_length_x_reciprocal_ = 1.0f/ret.focal_length_x_;
00184 ret.focal_length_y_ = focal_length_y_/2;
00185 ret.focal_length_y_reciprocal_ = 1.0f/ret.focal_length_y_;
00186 ret.center_x_ = center_x_/2;
00187 ret.center_y_ = center_y_/2;
00188 BaseClass::getHalfImage(ret);
00189 }
00190
00192 void
00193 RangeImagePlanar::getSubImage(int sub_image_image_offset_x, int sub_image_image_offset_y, int sub_image_width,
00194 int sub_image_height, int combine_pixels, RangeImage& sub_image) const
00195 {
00196 std::cerr << __PRETTY_FUNCTION__ << ": Warning, not tested properly!\n";
00197
00198 if (typeid(*this) != typeid(sub_image))
00199 {
00200 std::cerr << __PRETTY_FUNCTION__<<": Given range image is not a RangeImagePlanar!\n";
00201 return;
00202 }
00203 RangeImagePlanar& ret = *((RangeImagePlanar*)&sub_image);
00204
00205 ret.focal_length_x_ = focal_length_x_ / combine_pixels;
00206 ret.focal_length_x_reciprocal_ = 1.0f/ret.focal_length_x_;
00207 ret.focal_length_y_ = focal_length_x_ / combine_pixels;
00208 ret.focal_length_y_reciprocal_ = 1.0f/ret.focal_length_y_;
00209 ret.center_x_ = center_x_/2 - sub_image_image_offset_x;
00210 ret.center_y_ = center_y_/2 - sub_image_image_offset_y;
00211 BaseClass::getSubImage(sub_image_image_offset_x, sub_image_image_offset_y, sub_image_width,
00212 sub_image_height, combine_pixels, ret);
00213 ret.image_offset_x_ = ret.image_offset_y_ = 0;
00214 }
00215
00216 }
00217