43 #include <pcl/point_cloud.h>
44 #include <pcl/common/point_tests.h>
67 static const std::size_t
bytesPerPoint = 3 *
sizeof(float) + 3 *
sizeof(std::uint8_t);
75 static const std::size_t
bytesPerPoint = 3 *
sizeof(float) + 3 *
sizeof(std::uint8_t);
78 template <typename PointT, bool enableColor = CompressionPointTraits<PointT>::hasColor >
82 template<
typename Po
intT>
94 float focalLength_arg,
95 float disparityShift_arg,
96 float disparityScale_arg,
98 typename std::vector<std::uint16_t>& disparityData_arg,
99 typename std::vector<std::uint8_t>&)
101 const auto cloud_size = cloud_arg.
size ();
104 disparityData_arg.clear ();
106 disparityData_arg.reserve (cloud_size);
108 for (std::size_t i = 0; i < cloud_size; ++i)
111 const PointT& point = cloud_arg[i];
116 auto disparity =
static_cast<std::uint16_t
> ( focalLength_arg / (disparityScale_arg * point.z) + disparityShift_arg / disparityScale_arg);
122 disparityData_arg.push_back (0);
137 static void convert(
typename std::vector<std::uint16_t>& disparityData_arg,
138 typename std::vector<std::uint8_t>&,
140 std::size_t width_arg,
141 std::size_t height_arg,
142 float focalLength_arg,
143 float disparityShift_arg,
144 float disparityScale_arg,
147 std::size_t cloud_size = width_arg * height_arg;
149 assert(disparityData_arg.size()==cloud_size);
153 cloud_arg.
reserve (cloud_size);
156 cloud_arg.
width =
static_cast<std::uint32_t
> (width_arg);
157 cloud_arg.
height =
static_cast<std::uint32_t
> (height_arg);
161 int centerX =
static_cast<int> (width_arg / 2);
162 int centerY =
static_cast<int> (height_arg / 2);
164 const float fl_const = 1.0f / focalLength_arg;
165 static const float bad_point = std::numeric_limits<float>::quiet_NaN ();
168 for (
int y = -centerY; y < centerY; ++y )
169 for (
int x = -centerX; x < centerX; ++x )
172 const std::uint16_t& pixel_disparity = disparityData_arg[i];
178 float depth = focalLength_arg / (
static_cast<float> (pixel_disparity) * disparityScale_arg + disparityShift_arg);
181 newPoint.x =
static_cast<float> (x) * depth * fl_const;
182 newPoint.y =
static_cast<float> (y) * depth * fl_const;
189 newPoint.x = newPoint.y = newPoint.z = bad_point;
204 static void convert(
typename std::vector<float>& depthData_arg,
205 typename std::vector<std::uint8_t>&,
207 std::size_t width_arg,
208 std::size_t height_arg,
209 float focalLength_arg,
212 std::size_t cloud_size = width_arg * height_arg;
214 assert(depthData_arg.size()==cloud_size);
218 cloud_arg.
reserve (cloud_size);
221 cloud_arg.
width =
static_cast<std::uint32_t
> (width_arg);
222 cloud_arg.
height =
static_cast<std::uint32_t
> (height_arg);
226 int centerX =
static_cast<int> (width_arg / 2);
227 int centerY =
static_cast<int> (height_arg / 2);
229 const float fl_const = 1.0f / focalLength_arg;
230 static const float bad_point = std::numeric_limits<float>::quiet_NaN ();
233 for (
int y = -centerY; y < centerY; ++y )
234 for (
int x = -centerX; x < centerX; ++x )
237 const float& pixel_depth = depthData_arg[i];
243 newPoint.x =
static_cast<float> (x) * pixel_depth * fl_const;
244 newPoint.y =
static_cast<float> (y) * pixel_depth * fl_const;
245 newPoint.z = pixel_depth;
251 newPoint.x = newPoint.y = newPoint.z = bad_point;
260 template <
typename Po
intT>
274 float focalLength_arg,
275 float disparityShift_arg,
276 float disparityScale_arg,
278 typename std::vector<std::uint16_t>& disparityData_arg,
279 typename std::vector<std::uint8_t>& rgbData_arg)
281 const auto cloud_size = cloud_arg.
size ();
284 disparityData_arg.clear ();
285 rgbData_arg.clear ();
288 disparityData_arg.reserve (cloud_size);
291 rgbData_arg.reserve (cloud_size);
294 rgbData_arg.reserve (cloud_size * 3);
297 for (std::size_t i = 0; i < cloud_size; ++i)
299 const PointT& point = cloud_arg[i];
306 auto grayvalue =
static_cast<std::uint8_t
>(0.2989 * point.r
314 rgbData_arg.push_back (point.r);
315 rgbData_arg.push_back (point.g);
316 rgbData_arg.push_back (point.b);
320 auto disparity =
static_cast<std::uint16_t
> (focalLength_arg / (disparityScale_arg * point.z) + disparityShift_arg / disparityScale_arg);
323 disparityData_arg.push_back (disparity);
330 rgbData_arg.push_back (0);
333 rgbData_arg.push_back (0);
334 rgbData_arg.push_back (0);
335 rgbData_arg.push_back (0);
339 disparityData_arg.push_back (0);
356 static void convert(
typename std::vector<std::uint16_t>& disparityData_arg,
357 typename std::vector<std::uint8_t>& rgbData_arg,
359 std::size_t width_arg,
360 std::size_t height_arg,
361 float focalLength_arg,
362 float disparityShift_arg,
363 float disparityScale_arg,
366 std::size_t cloud_size = width_arg*height_arg;
367 bool hasColor = (!rgbData_arg.empty ());
370 assert (disparityData_arg.size()==cloud_size);
375 assert (rgbData_arg.size()==cloud_size);
378 assert (rgbData_arg.size()==cloud_size*3);
387 cloud_arg.
width =
static_cast<std::uint32_t
>(width_arg);
388 cloud_arg.
height =
static_cast<std::uint32_t
>(height_arg);
392 int centerX =
static_cast<int>(width_arg/2);
393 int centerY =
static_cast<int>(height_arg/2);
395 const float fl_const = 1.0f/focalLength_arg;
396 static const float bad_point = std::numeric_limits<float>::quiet_NaN ();
399 for (
int y = -centerY; y < centerY; ++y )
400 for (
int x = -centerX; x < centerX; ++x )
404 const std::uint16_t& pixel_disparity = disparityData_arg[i];
406 if (pixel_disparity && (pixel_disparity!=0x7FF))
408 float depth = focalLength_arg / (
static_cast<float> (pixel_disparity) * disparityScale_arg + disparityShift_arg);
412 newPoint.x =
static_cast<float> (x) * depth * fl_const;
413 newPoint.y =
static_cast<float> (y) * depth * fl_const;
420 newPoint.r = rgbData_arg[i];
421 newPoint.g = rgbData_arg[i];
422 newPoint.b = rgbData_arg[i];
426 newPoint.r = rgbData_arg[i*3+0];
427 newPoint.g = rgbData_arg[i*3+1];
428 newPoint.b = rgbData_arg[i*3+2];
434 newPoint.rgba = 0xffffffffu;
439 newPoint.x = newPoint.y = newPoint.z = bad_point;
460 static void convert(
typename std::vector<float>& depthData_arg,
461 typename std::vector<std::uint8_t>& rgbData_arg,
463 std::size_t width_arg,
464 std::size_t height_arg,
465 float focalLength_arg,
468 std::size_t cloud_size = width_arg*height_arg;
469 bool hasColor = (!rgbData_arg.empty ());
472 assert (depthData_arg.size()==cloud_size);
477 assert (rgbData_arg.size()==cloud_size);
480 assert (rgbData_arg.size()==cloud_size*3);
489 cloud_arg.
width =
static_cast<std::uint32_t
>(width_arg);
490 cloud_arg.
height =
static_cast<std::uint32_t
>(height_arg);
494 int centerX =
static_cast<int>(width_arg/2);
495 int centerY =
static_cast<int>(height_arg/2);
497 const float fl_const = 1.0f/focalLength_arg;
498 static const float bad_point = std::numeric_limits<float>::quiet_NaN ();
501 for (
int y = -centerY; y < centerY; ++y )
502 for (
int x = -centerX; x < centerX; ++x )
506 const float& pixel_depth = depthData_arg[i];
511 newPoint.z = pixel_depth;
512 newPoint.x =
static_cast<float> (x) * pixel_depth * fl_const;
513 newPoint.y =
static_cast<float> (y) * pixel_depth * fl_const;
520 newPoint.r = rgbData_arg[i];
521 newPoint.g = rgbData_arg[i];
522 newPoint.b = rgbData_arg[i];
526 newPoint.r = rgbData_arg[i*3+0];
527 newPoint.g = rgbData_arg[i*3+1];
528 newPoint.b = rgbData_arg[i*3+2];
534 newPoint.rgba = 0xffffffffu;
539 newPoint.x = newPoint.y = newPoint.z = bad_point;
PointCloud represents the base class in PCL for storing collections of 3D points.
void push_back(const PointT &pt)
Insert a new point in the cloud, at the end of the container.
bool is_dense
True if no points are invalid (e.g., have NaN or Inf values in any of their floating point fields).
std::uint32_t width
The point cloud width (if organized as an image-structure).
std::uint32_t height
The point cloud height (if organized as an image-structure).
void clear()
Removes all points in a cloud and sets the width and height to 0.
void reserve(std::size_t n)
static void convert(typename std::vector< float > &depthData_arg, typename std::vector< std::uint8_t > &, bool, std::size_t width_arg, std::size_t height_arg, float focalLength_arg, pcl::PointCloud< PointT > &cloud_arg)
Convert disparity image to point cloud.
static void convert(const pcl::PointCloud< PointT > &cloud_arg, float focalLength_arg, float disparityShift_arg, float disparityScale_arg, bool convertToMono, typename std::vector< std::uint16_t > &disparityData_arg, typename std::vector< std::uint8_t > &rgbData_arg)
Convert point cloud to disparity image and rgb image.
static void convert(typename std::vector< std::uint16_t > &disparityData_arg, typename std::vector< std::uint8_t > &, bool, std::size_t width_arg, std::size_t height_arg, float focalLength_arg, float disparityShift_arg, float disparityScale_arg, pcl::PointCloud< PointT > &cloud_arg)
Convert disparity image to point cloud.
static void convert(typename std::vector< std::uint16_t > &disparityData_arg, typename std::vector< std::uint8_t > &rgbData_arg, bool monoImage_arg, std::size_t width_arg, std::size_t height_arg, float focalLength_arg, float disparityShift_arg, float disparityScale_arg, pcl::PointCloud< PointT > &cloud_arg)
Convert disparity image to point cloud.
static void convert(const pcl::PointCloud< PointT > &cloud_arg, float focalLength_arg, float disparityShift_arg, float disparityScale_arg, bool, typename std::vector< std::uint16_t > &disparityData_arg, typename std::vector< std::uint8_t > &)
Convert point cloud to disparity image.
static void convert(typename std::vector< float > &depthData_arg, typename std::vector< std::uint8_t > &rgbData_arg, bool monoImage_arg, std::size_t width_arg, std::size_t height_arg, float focalLength_arg, pcl::PointCloud< PointT > &cloud_arg)
Convert disparity image to point cloud.
bool isFinite(const PointT &pt)
Tests if the 3D components of a point are all finite param[in] pt point to be tested return true if f...
Defines all the PCL and non-PCL macros used.
A point structure representing Euclidean xyz coordinates, and the RGBA color.
A point structure representing Euclidean xyz coordinates, and the RGB color.
static const unsigned int channels
static const bool hasColor
static const std::size_t bytesPerPoint