base
DistanceImage.hpp
Go to the documentation of this file.
1 #ifndef __BASE_SAMPLES_DISTANCE_IMAGE_H__
2 #define __BASE_SAMPLES_DISTANCE_IMAGE_H__
3 
4 #include <base/Time.hpp>
5 #include <base/Eigen.hpp>
6 #include "Pointcloud.hpp"
7 #include <vector>
8 #include <boost/math/special_functions/fpclassify.hpp>
9 
10 namespace base
11 {
12 namespace samples
13 {
33  {
36 
38  uint16_t width;
40  uint16_t height;
41 
42  typedef float scalar;
44  scalar scale_x;
46  scalar scale_y;
47 
49  scalar center_x;
51  scalar center_y;
52 
54  std::vector<scalar> data;
55 
56  DistanceImage(): width(0), height(0), scale_x(1.0), scale_y(1.0), center_x(0.0), center_y(0.0)
57  {
58  }
59 
60  DistanceImage(uint16_t width, uint16_t height): width(width), height(height), scale_x(1.0), scale_y(1.0), center_x(0.0), center_y(0.0)
61  {
62  }
63 
64 
68  void clear();
69 
79  template <class Scalar_>
80  bool getScenePoint( size_t x, size_t y, Eigen::Matrix<Scalar_,3,1>& point ) const
81  {
82  // check bounds. x and y are always positive
83  if( (x >= width) || (y >= height) )
84  return false;
85 
86  // only process vector if distance value is not NaN or inf
87  const scalar d = data[width*y+x];
88  if( boost::math::isnormal( d ) )
89  {
90  point = Eigen::Matrix<Scalar_,3,1>( (x*scale_x)+center_x, (y*scale_y)+center_y, 1.0 );
91  point *= d;
92  return true;
93  }
94  return false;
95  }
96 
103  template <class Scalar_>
104  bool getImagePoint( const Eigen::Matrix<Scalar_,3,1>& point, size_t &x, size_t &y ) const
105  {
106  if( point.z() <= 0 )
107  return false;
108 
109  size_t u = ((point.x() / point.z()) - center_x) / scale_x;
110  size_t v = ((point.y() / point.z()) - center_y) / scale_y;
111 
112  // check bounds. u and v are always positive
113  if( (u >= width) || (v >= height) )
114  return false;
115 
116  x = u;
117  y = v;
118 
119  return true;
120  }
121 
123 
142  template <class Scalar_>
143  Eigen::Matrix<Scalar_,3,3> getIntrinsic() const
144  {
145  // parameters in this class give the inverse
146  // so, we need to invert them
147  Eigen::Matrix<Scalar_,3,3> result;
148  result <<
149  1.0/scale_x, 0, -center_x/scale_x,
150  0, 1.0/scale_y, -center_y/scale_y,
151  0, 0, 1;
152 
153  return result;
154  }
155 
165  void setIntrinsic( double f_x, double f_y, double c_x, double c_y );
166 
175  void setSize( uint16_t width, uint16_t height );
176  };
177 }
178 }
179 #endif
DistanceImage(uint16_t width, uint16_t height)
Definition: DistanceImage.hpp:60
bool getScenePoint(size_t x, size_t y, Eigen::Matrix< Scalar_, 3, 1 > &point) const
Definition: DistanceImage.hpp:80
bool getImagePoint(const Eigen::Matrix< Scalar_, 3, 1 > &point, size_t &x, size_t &y) const
Definition: DistanceImage.hpp:104
uint16_t height
height (y) value in pixels
Definition: DistanceImage.hpp:40
scalar scale_y
scale value to apply to the y axis
Definition: DistanceImage.hpp:46
Definition: Pointcloud.hpp:13
void setSize(uint16_t width, uint16_t height)
set the size of the distance image
Definition: DistanceImage.cpp:39
void clear()
Definition: DistanceImage.cpp:8
Eigen::Matrix< Scalar_, 3, 3 > getIntrinsic() const
Definition: DistanceImage.hpp:143
void setIntrinsic(double f_x, double f_y, double c_x, double c_y)
set the intrinsic camera parameters.
Definition: DistanceImage.cpp:31
uint16_t width
width (x) value in pixels
Definition: DistanceImage.hpp:38
Definition: Time.hpp:11
scalar scale_x
scale value to apply to the x axis
Definition: DistanceImage.hpp:44
scalar center_x
center offset to apply to the x axis
Definition: DistanceImage.hpp:49
base::Time time
original timestamp of the camera image
Definition: DistanceImage.hpp:35
DistanceImage()
Definition: DistanceImage.hpp:56
Definition: LinearAngular6DCommand.hpp:8
scalar center_y
center offset to apply to the y axis
Definition: DistanceImage.hpp:51
std::vector< scalar > data
distance values stored in row major order. NaN is used as the no value type.
Definition: DistanceImage.hpp:54
Definition: DistanceImage.hpp:32
float scalar
Definition: DistanceImage.hpp:42
base::samples::Pointcloud getPointCloud() const
Definition: DistanceImage.cpp:13