libvisiontransfer  10.6.0
reconstruct3d.h
1 /*******************************************************************************
2  * Copyright (c) 2023 Allied Vision Technologies GmbH
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *******************************************************************************/
14 
15 #ifndef VISIONTRANSFER_RECONSTRUCT3D_H
16 #define VISIONTRANSFER_RECONSTRUCT3D_H
17 
18 #include <limits>
19 #include <stdexcept>
20 #include "visiontransfer/common.h"
21 #include "visiontransfer/imageset.h"
22 
23 #ifdef OPEN3D_VERSION
24 # include <memory>
25 #endif
26 
27 namespace visiontransfer {
28 
35 class VT_EXPORT Reconstruct3D {
36 public:
37 
41  enum ColorSource {
43  COLOR_NONE,
45  COLOR_AUTO,
47  COLOR_LEFT,
49  COLOR_THIRD_COLOR,
50  };
51 
55  Reconstruct3D();
56 
57  ~Reconstruct3D();
58 
59 #ifndef DOXYGEN_SHOULD_SKIP_THIS
60 
84  DEPRECATED("Use createPointMap(const ImageSet&, ...) instead.")
85  float* createPointMap(const unsigned short* dispMap, int width, int height,
86  int rowStride, const float* q, unsigned short minDisparity = 0,
87  int subpixelFactor = 16, unsigned short maxDisparity = 0xFFF);
88 #endif
89 
111  float* createPointMap(const ImageSet& imageSet, unsigned short minDisparity = 0,
112  unsigned short maxDisparity = 0xFFF);
113 
137  float* createZMap(const ImageSet& imageSet, unsigned short minDisparity = 0,
138  unsigned short maxDisparity = 0xFFF);
139 
162  void projectSinglePoint(int imageX, int imageY, unsigned short disparity, const float* q,
163  float& pointX, float& pointY, float& pointZ, int subpixelFactor = 16);
164 
165 #ifndef DOXYGEN_SHOULD_SKIP_THIS
166 
195  DEPRECATED("Use writePlyFile(const char*, const ImageSet&, ...) instead.")
196  void writePlyFile(const char* file, const unsigned short* dispMap,
197  const unsigned char* image, int width, int height, ImageSet::ImageFormat format,
198  int dispRowStride, int imageRowStride, const float* q,
199  double maxZ = (std::numeric_limits<double>::max)(),
200  bool binary = false, int subpixelFactor = 16, unsigned short maxDisparity = 0xFFF);
201 #endif
202 
216  void writePlyFile(const char* file, const ImageSet& imageSet,
217  double maxZ = (std::numeric_limits<double>::max)(),
218  bool binary = false,
219  ColorSource colSource = COLOR_AUTO,
220  unsigned short maxDisparity = 0xFFF);
221 
222 #ifdef PCL_MAJOR_VERSION
223 
238  inline pcl::PointCloud<pcl::PointXYZ>::Ptr createXYZCloud(const ImageSet& imageSet,
239  const char* frameId, unsigned short minDisparity = 0);
240 
246  inline pcl::PointCloud<pcl::PointXYZI>::Ptr createXYZICloud(const ImageSet& imageSet,
247  const char* frameId, unsigned short minDisparity = 0);
248 
254  inline pcl::PointCloud<pcl::PointXYZRGB>::Ptr createXYZRGBCloud(const ImageSet& imageSet,
255  const char* frameId, unsigned short minDisparity = 0);
256 #endif
257 
258 #ifdef OPEN3D_VERSION
259 
276  inline std::shared_ptr<open3d::geometry::PointCloud> createOpen3DCloud(const ImageSet& imageSet,
277  ColorSource colSource = COLOR_AUTO, unsigned short minDisparity = 0, unsigned short maxDisparity = 0xFFF);
292  inline std::shared_ptr<open3d::geometry::RGBDImage> createOpen3DImageRGBD(const ImageSet& imageSet,
293  ColorSource colSource = COLOR_AUTO, unsigned short minDisparity = 0);
294 #endif
295 
296 private:
297  // We follow the pimpl idiom
298  class Pimpl;
299  Pimpl* pimpl;
300 
301  // This class cannot be copied
302  Reconstruct3D(const Reconstruct3D& other);
303  Reconstruct3D& operator=(const Reconstruct3D&);
304 
305 #ifdef PCL_MAJOR_VERSION
306  // Initializes a PCL point cloud
307  template <typename T>
308  typename pcl::PointCloud<T>::Ptr initPointCloud(const ImageSet& imageSet, const char* frameId);
309 #endif
310 
311  // Inlined code, as it is needed by PCL and Open3D bindings
312  static ImageSet::ImageType getColorImage(const ImageSet& imageSet, ColorSource colSource) {
313  switch(colSource) {
314  case COLOR_AUTO:
315  if(imageSet.hasImageType(ImageSet::IMAGE_COLOR)) {
316  return ImageSet::IMAGE_COLOR;
317  } else {
318  return ImageSet::IMAGE_LEFT;
319  }
320  case COLOR_LEFT:
321  return ImageSet::IMAGE_LEFT;
322  case COLOR_THIRD_COLOR:
323  return ImageSet::IMAGE_COLOR;
324  break;
325  default:
326  return ImageSet::IMAGE_UNDEFINED;
327  }
328  }
329 };
330 
331 } // namespace
332 
333 #include "visiontransfer/reconstruct3d-pcl.h"
334 #include "visiontransfer/reconstruct3d-open3d.h"
335 
336 #endif
visiontransfer::Reconstruct3D::ColorSource
ColorSource
Source channel selection for color information.
Definition: reconstruct3d.h:65
visiontransfer::ImageSet
A set of one to three images, but usually two (the left camera image and the disparity map)....
Definition: imageset.h:50
visiontransfer::Reconstruct3D
Transforms a disparity map into a set of 3D points.
Definition: reconstruct3d.h:47
visiontransfer::ImageSet::ImageType
ImageType
Supported image types.
Definition: imageset.h:91
visiontransfer::ImageSet::hasImageType
bool hasImageType(ImageType what) const
Returns whether a left camera image is included in the enabled data.
Definition: imageset.h:461
visiontransfer::ImageSet::IMAGE_COLOR
@ IMAGE_COLOR
3rd color camera for devices where this is supported
Definition: imageset.h:98
Allied Vision