MRPT  1.9.9
CObservation3DRangeScan.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
12 #include <mrpt/img/CImage.h>
13 #include <mrpt/obs/CObservation.h>
16 #include <mrpt/poses/CPose3D.h>
17 #include <mrpt/poses/CPose2D.h>
18 #include <mrpt/math/CPolygon.h>
19 #include <mrpt/math/CMatrix.h>
24 
25 namespace mrpt
26 {
27 namespace obs
28 {
29 /** Used in CObservation3DRangeScan::project3DPointsFromDepthImageInto() */
31 {
32  /** (Default: false) If false, local (sensor-centric) coordinates of points
33  * are generated. Otherwise, points are transformed with \a sensorPose.
34  * Furthermore, if provided, those coordinates are transformed with \a
35  * robotPoseInTheWorld */
37  /** (Default: nullptr) Read takeIntoAccountSensorPoseOnRobot */
39  /** (Default:true) [Only used when `range_is_depth`=true] Whether to use a
40  * Look-up-table (LUT) to speed up the conversion. It's thread safe in all
41  * situations <b>except</b> when you call this method from different threads
42  * <b>and</b> with different camera parameter matrices. In all other cases,
43  * it is a good idea to left it enabled. */
45  /** (Default:true) If possible, use SSE2 optimized code. */
46  bool USE_SSE2;
47  /** (Default:true) set to false if your point cloud can contain undefined values */
48  bool MAKE_DENSE;
49  /** (Default:false) set to true if you want an organized point cloud */
51 
54  robotPoseInTheWorld(nullptr),
55  PROJ3D_USE_LUT(true),
56  USE_SSE2(true),
57  MAKE_DENSE(true),
58  MAKE_ORGANIZED(false)
59  {
60  }
61 };
62 /** Used in CObservation3DRangeScan::convertTo2DScan() */
64 {
65  /** The sensor label that will have the newly created observation. */
67  /** (Default=5 degrees) [Only if use_origin_sensor_pose=false] The upper &
68  * lower half-FOV angle (in radians). */
70  /** (Default:-inf, +inf) [Only if use_origin_sensor_pose=true] Only obstacle
71  * points with Z coordinates within the range [z_min,z_max] will be taken
72  * into account. */
73  double z_min, z_max;
74  /** (Default=1.2=120%) How many more laser scans rays to create (read docs
75  * for CObservation3DRangeScan::convertTo2DScan()). */
77 
78  /** (Default:false) If `false`, the conversion will be such that the 2D
79  * observation pose on the robot coincides with that in the original 3D
80  * range scan.
81  * If `true`, the sensed points will be "reprojected" as seen from a sensor
82  * pose at the robot/vehicle frame origin (and angle_sup, angle_inf will be
83  * ignored) */
85 
87 };
88 
89 namespace detail
90 {
91 // Implemented in CObservation3DRangeScan_project3D_impl.h
92 template <class POINTMAP>
94  mrpt::obs::CObservation3DRangeScan& src_obs, POINTMAP& dest_pointcloud,
95  const mrpt::obs::T3DPointsProjectionParams& projectParams,
96  const mrpt::obs::TRangeImageFilterParams& filterParams);
97 } // namespace detail
98 
99 /** Declares a class derived from "CObservation" that encapsules a 3D range scan
100  *measurement, as from a time-of-flight range camera or any other RGBD sensor.
101  *
102  * This kind of observations can carry one or more of these data fields:
103  * - 3D point cloud (as float's).
104  * - Each 3D point has its associated (u,v) pixel coordinates in \a
105  *points3D_idxs_x & \a points3D_idxs_y (New in MRPT 1.4.0)
106  * - 2D range image (as a matrix): Each entry in the matrix
107  *"rangeImage(ROW,COLUMN)" contains a distance or a depth (in meters), depending
108  *on \a range_is_depth.
109  * - 2D intensity (grayscale or RGB) image (as a mrpt::img::CImage): For
110  *SwissRanger cameras, a logarithmic A-law compression is used to convert the
111  *original 16bit intensity to a more standard 8bit graylevel.
112  * - 2D confidence image (as a mrpt::img::CImage): For each pixel, a 0x00
113  *and a 0xFF mean the lowest and highest confidence levels, respectively.
114  * - Semantic labels: Stored as a matrix of bitfields, each bit having a
115  *user-defined meaning.
116  *
117  * The coordinates of the 3D point cloud are in meters with respect to the
118  *depth camera origin of coordinates
119  * (in SwissRanger, the front face of the camera: a small offset ~1cm in
120  *front of the physical focal point),
121  * with the +X axis pointing forward, +Y pointing left-hand and +Z pointing
122  *up. By convention, a 3D point with its coordinates set to (0,0,0), will be
123  *considered as invalid.
124  * The field CObservation3DRangeScan::relativePoseIntensityWRTDepth describes
125  *the change of coordinates from
126  * the depth camera to the intensity (RGB or grayscale) camera. In a
127  *SwissRanger camera both cameras coincide,
128  * so this pose is just a rotation (0,0,0,-90deg,0,-90deg). But in
129  * Microsoft Kinect there is also an offset, as shown in this figure:
130  *
131  * <div align=center>
132  * <img src="CObservation3DRangeScan_figRefSystem.png">
133  * </div>
134  *
135  * In any case, check the field \a relativePoseIntensityWRTDepth, or the method
136  *\a doDepthAndIntensityCamerasCoincide()
137  * to determine if both frames of reference coincide, since even for Kinect
138  *cameras both can coincide if the images
139  * have been rectified.
140  *
141  * The 2D images and matrices are stored as common images, with an up->down
142  *rows order and left->right, as usual.
143  * Optionally, the intensity and confidence channels can be set to
144  *delayed-load images for off-rawlog storage so it saves
145  * memory by having loaded in memory just the needed images. See the methods
146  *load() and unload().
147  * Due to the intensive storage requirements of this kind of observations, this
148  *observation is the only one in MRPT
149  * for which it's recommended to always call "load()" and "unload()" before
150  *and after using the observation, *ONLY* when
151  * the observation was read from a rawlog dataset, in order to make sure that
152  *all the externally stored data fields are
153  * loaded and ready in memory.
154  *
155  * Classes that grab observations of this type are:
156  * - mrpt::hwdrivers::CSwissRanger3DCamera
157  * - mrpt::hwdrivers::CKinect
158  * - mrpt::hwdrivers::COpenNI2Sensor
159  *
160  * There are two sets of calibration parameters (see
161  *mrpt::vision::checkerBoardStereoCalibration() or the ready-to-use GUI program
162  *<a href="http://www.mrpt.org/Application:kinect-calibrate"
163  *>kinect-calibrate</a>):
164  * - cameraParams: Projection parameters of the depth camera.
165  * - cameraParamsIntensity: Projection parameters of the intensity
166  *(gray-level or RGB) camera.
167  *
168  * In some cameras, like SwissRanger, both are the same. It is possible in
169  *Kinect to rectify the range images such both cameras
170  * seem to coincide and then both sets of camera parameters will be identical.
171  *
172  * Range data can be interpreted in two different ways depending on the 3D
173  *camera (this field is already set to the
174  * correct setting when grabbing observations from an mrpt::hwdrivers
175  *sensor):
176  * - range_is_depth=true -> Kinect-like ranges: entries of \a rangeImage
177  *are
178  *distances along the +X axis
179  * - range_is_depth=false -> Ranges in \a rangeImage are actual distances
180  *in
181  *3D.
182  *
183  * The "intensity" channel may come from different channels in sesnsors as
184  *Kinect. Look at field \a intensityImageChannel to
185  * find out if the image was grabbed from the visible (RGB) or IR channels.
186  *
187  * 3D point clouds can be generated at any moment after grabbing with
188  *CObservation3DRangeScan::project3DPointsFromDepthImage() and
189  *CObservation3DRangeScan::project3DPointsFromDepthImageInto(), provided the
190  *correct
191  * calibration parameters. Note that project3DPointsFromDepthImage() will
192  *store the point cloud in sensor-centric local coordinates. Use
193  *project3DPointsFromDepthImageInto() to directly obtain vehicle or world
194  *coordinates.
195  *
196  * Example of how to assign labels to pixels (for object segmentation, semantic
197  *information, etc.):
198  *
199  * \code
200  * // Assume obs of type CObservation3DRangeScan::Ptr
201  * obs->pixelLabels = CObservation3DRangeScan::TPixelLabelInfo::Ptr( new
202  *CObservation3DRangeScan::TPixelLabelInfo<NUM_BYTES>() );
203  * obs->pixelLabels->setSize(ROWS,COLS);
204  * obs->pixelLabels->setLabel(col,row, label_idx); // label_idxs =
205  *[0,2^NUM_BYTES-1]
206  * //...
207  * \endcode
208  *
209  * \note Starting at serialization version 2 (MRPT 0.9.1+), the confidence
210  *channel is stored as an image instead of a matrix to optimize memory and disk
211  *space.
212  * \note Starting at serialization version 3 (MRPT 0.9.1+), the 3D point cloud
213  *and the rangeImage can both be stored externally to save rawlog space.
214  * \note Starting at serialization version 5 (MRPT 0.9.5+), the new field \a
215  *range_is_depth
216  * \note Starting at serialization version 6 (MRPT 0.9.5+), the new field \a
217  *intensityImageChannel
218  * \note Starting at serialization version 7 (MRPT 1.3.1+), new fields for
219  *semantic labeling
220  * \note Since MRPT 1.5.0, external files format can be selected at runtime
221  *with `CObservation3DRangeScan::EXTERNALS_AS_TEXT`
222  *
223  * \sa mrpt::hwdrivers::CSwissRanger3DCamera, mrpt::hwdrivers::CKinect,
224  *CObservation
225  * \ingroup mrpt_obs_grp
226  */
228 {
230 
231  protected:
232  /** If set to true, m_points3D_external_file is valid. */
234  /** 3D points are in CImage::getImagesPathBase()+<this_file_name> */
236 
237  /** If set to true, m_rangeImage_external_file is valid. */
239  /** rangeImage is in CImage::getImagesPathBase()+<this_file_name> */
241 
242  public:
243  /** Default constructor */
245  /** Destructor */
246  virtual ~CObservation3DRangeScan();
247 
248  /** @name Delayed-load manual control methods.
249  @{ */
250  /** Makes sure all images and other fields which may be externally stored
251  * are loaded in memory.
252  * Note that for all CImages, calling load() is not required since the
253  * images will be automatically loaded upon first access, so load()
254  * shouldn't be needed to be called in normal cases by the user.
255  * If all the data were alredy loaded or this object has no externally
256  * stored data fields, calling this method has no effects.
257  * \sa unload
258  */
259  virtual void load() const override;
260  /** Unload all images, for the case they being delayed-load images stored in
261  * external files (othewise, has no effect).
262  * \sa load
263  */
264  virtual void unload() override;
265  /** @} */
266 
267  /** Project the RGB+D images into a 3D point cloud (with color if the target
268  * map supports it) and optionally at a given 3D pose.
269  * The 3D point coordinates are computed from the depth image (\a
270  * rangeImage) and the depth camera camera parameters (\a cameraParams).
271  * There exist two set of formulas for projecting the i'th point,
272  * depending on the value of "range_is_depth".
273  * In all formulas below, "rangeImage" is the matrix of ranges and the
274  * pixel coordinates are (r,c).
275  *
276  * 1) [range_is_depth=true] With "range equals depth" or "Kinect-like
277  * depth mode": the range values
278  * are in fact distances along the "+X" axis, not real 3D ranges (this
279  * is the way Kinect reports ranges):
280  *
281  * \code
282  * x(i) = rangeImage(r,c)
283  * y(i) = (r_cx - c) * x(i) / r_fx
284  * z(i) = (r_cy - r) * x(i) / r_fy
285  * \endcode
286  *
287  *
288  * 2) [range_is_depth=false] With "normal ranges": range means distance in
289  * 3D. This must be set when
290  * processing data from the SwissRange 3D camera, among others.
291  *
292  * \code
293  * Ky = (r_cx - c)/r_fx
294  * Kz = (r_cy - r)/r_fy
295  *
296  * x(i) = rangeImage(r,c) / sqrt( 1 + Ky^2 + Kz^2 )
297  * y(i) = Ky * x(i)
298  * z(i) = Kz * x(i)
299  * \endcode
300  *
301  * The color of each point is determined by projecting the 3D local point
302  * into the RGB image using \a cameraParamsIntensity.
303  *
304  * By default the local (sensor-centric) coordinates of points are
305  * directly stored into the local map, but if indicated so in \a
306  * takeIntoAccountSensorPoseOnRobot
307  * the points are transformed with \a sensorPose. Furthermore, if
308  * provided, those coordinates are transformed with \a robotPoseInTheWorld
309  *
310  * \tparam POINTMAP Supported maps are all those covered by
311  * mrpt::opengl::PointCloudAdapter (mrpt::maps::CPointsMap and derived,
312  * mrpt::opengl::CPointCloudColoured, PCL point clouds,...)
313  *
314  * \note In MRPT < 0.9.5, this method always assumes that ranges were in
315  * Kinect-like format.
316  */
317  template <class POINTMAP>
319  POINTMAP& dest_pointcloud,
320  const T3DPointsProjectionParams& projectParams,
321  const TRangeImageFilterParams& filterParams = TRangeImageFilterParams())
322  {
323  detail::project3DPointsFromDepthImageInto<POINTMAP>(
324  *this, dest_pointcloud, projectParams, filterParams);
325  }
326 
327  /** This method is equivalent to \c project3DPointsFromDepthImageInto()
328  * storing the projected 3D points (without color, in local sensor-centric
329  * coordinates) in this same class.
330  * For new code it's recommended to use instead \c
331  * project3DPointsFromDepthImageInto() which is much more versatile. */
332  inline void project3DPointsFromDepthImage(const bool PROJ3D_USE_LUT = true)
333  {
335  p.takeIntoAccountSensorPoseOnRobot = false;
336  p.PROJ3D_USE_LUT = PROJ3D_USE_LUT;
337  this->project3DPointsFromDepthImageInto(*this, p);
338  }
339 
340  /** Convert this 3D observation into an "equivalent 2D fake laser scan",
341  * with a configurable vertical FOV.
342  *
343  * The result is a 2D laser scan with more "rays" (N) than columns has the
344  * 3D observation (W), exactly: N = W * oversampling_ratio.
345  * This oversampling is required since laser scans sample the space at
346  * evenly-separated angles, while
347  * a range camera follows a tangent-like distribution. By oversampling we
348  * make sure we don't leave "gaps" unseen by the virtual "2D laser".
349  *
350  * All obstacles within a frustum are considered and the minimum distance
351  * is kept in each direction.
352  * The horizontal FOV of the frustum is automatically computed from the
353  * intrinsic parameters, but the
354  * vertical FOV must be provided by the user, and can be set to be
355  * assymetric which may be useful
356  * depending on the zone of interest where to look for obstacles.
357  *
358  * All spatial transformations are riguorosly taken into account in this
359  * class, using the depth camera
360  * intrinsic calibration parameters.
361  *
362  * The timestamp of the new object is copied from the 3D object.
363  * Obviously, a requisite for calling this method is the 3D observation
364  * having range data,
365  * i.e. hasRangeImage must be true. It's not needed to have RGB data nor
366  * the raw 3D point clouds
367  * for this method to work.
368  *
369  * If `scanParams.use_origin_sensor_pose` is `true`, the points will be
370  * projected to 3D and then reprojected
371  * as seen from a different sensorPose at the vehicle frame origin.
372  * Otherwise (the default), the output 2D observation will share the
373  * sensorPose of the input 3D scan
374  * (using a more efficient algorithm that avoids trigonometric functions).
375  *
376  * \param[out] out_scan2d The resulting 2D equivalent scan.
377  *
378  * \sa The example in
379  * http://www.mrpt.org/tutorials/mrpt-examples/example-kinect-to-2d-laser-demo/
380  */
381  void convertTo2DScan(
383  const T3DPointsTo2DScanParams& scanParams,
384  const TRangeImageFilterParams& filterParams =
386 
387  /** Whether external files (3D points, range and confidence) are to be
388  * saved as `.txt` text files (MATLAB compatible) or `*.bin` binary
389  *(faster).
390  * Loading always will determine the type by inspecting the file extension.
391  * \note Default=false
392  **/
393  static void EXTERNALS_AS_TEXT(bool value);
394  static bool EXTERNALS_AS_TEXT();
395 
396  /** \name Point cloud
397  * @{ */
398  /** true means the field points3D contains valid data. */
400  /** If hasPoints3D=true, the (X,Y,Z) coordinates of the 3D point cloud
401  * detected by the camera. \sa resizePoints3DVectors */
402  std::vector<float> points3D_x, points3D_y, points3D_z;
403  /** If hasPoints3D=true, the (x,y) pixel coordinates for each (X,Y,Z) point
404  * in \a points3D_x, points3D_y, points3D_z */
405  std::vector<uint16_t> points3D_idxs_x, points3D_idxs_y; //!<
406 
407  /** Use this method instead of resizing all three \a points3D_x, \a
408  * points3D_y & \a points3D_z to allow the usage of the internal memory
409  * pool. */
410  void resizePoints3DVectors(const size_t nPoints);
411 
412  /** Get the size of the scan pointcloud. \note Method is added for
413  * compatibility with its CObservation2DRangeScan counterpart */
414  size_t getScanSize() const;
415  /** @} */
416 
417  /** \name Point cloud external storage functions
418  * @{ */
419  inline bool points3D_isExternallyStored() const
420  {
422  }
424  {
426  }
428  std::string& out_path) const;
430  {
431  std::string tmp;
433  return tmp;
434  }
435  /** Users won't normally want to call this, it's only used from internal
436  * MRPT programs. \sa EXTERNALS_AS_TEXT */
438  const std::string& fileName, const std::string& use_this_base_dir);
439  /** @} */
440 
441  /** \name Range (depth) image
442  * @{ */
443  /** true means the field rangeImage contains valid data */
445  /** If hasRangeImage=true, a matrix of floats with the range data as
446  * captured by the camera (in meters) \sa range_is_depth */
448  /** true: Kinect-like ranges: entries of \a rangeImage are distances along
449  * the +X axis; false: Ranges in \a rangeImage are actual distances in 3D.
450  */
452 
453  /** Similar to calling "rangeImage.setSize(H,W)" but this method provides
454  * memory pooling to speed-up the memory allocation. */
455  void rangeImage_setSize(const int HEIGHT, const int WIDTH);
456  /** @} */
457 
458  /** \name Range Matrix external storage functions
459  * @{ */
460  inline bool rangeImage_isExternallyStored() const
461  {
463  }
465  {
467  }
469  std::string& out_path) const;
471  {
472  std::string tmp;
474  return tmp;
475  }
476  /** Users won't normally want to call this, it's only used from internal
477  * MRPT programs. \sa EXTERNALS_AS_TEXT */
479  const std::string& fileName, const std::string& use_this_base_dir);
480  /** Forces marking this observation as non-externally stored - it doesn't
481  * anything else apart from reseting the corresponding flag (Users won't
482  * normally want to call this, it's only used from internal MRPT programs)
483  */
485  {
487  }
488  /** @} */
489 
490  /** \name Intensity (RGB) channels
491  * @{ */
492  /** Enum type for intensityImageChannel */
494  {
495  /** Grayscale or RGB visible channel of the camera sensor. */
497  /** Infrarred (IR) channel */
498  CH_IR = 1
499  };
500 
501  /** true means the field intensityImage contains valid data */
503  /** If hasIntensityImage=true, a color or gray-level intensity image of the
504  * same size than "rangeImage" */
506  /** The source of the intensityImage; typically the visible channel \sa
507  * TIntensityChannelID */
509  /** @} */
510 
511  /** \name Confidence "channel"
512  * @{ */
513  /** true means the field confidenceImage contains valid data */
515  /** If hasConfidenceImage=true, an image with the "confidence" value [range
516  * 0-255] as estimated by the capture drivers. */
518  /** @} */
519 
520  /** \name Pixel-wise classification labels (for semantic labeling, etc.)
521  * @{ */
522  /** Returns true if the field CObservation3DRangeScan::pixelLabels contains
523  * a non-NULL smart pointer.
524  * To enhance a 3D point cloud with labeling info, just assign an
525  * appropiate object to \a pixelLabels
526  */
527  bool hasPixelLabels() const { return pixelLabels ? true : false; }
528  /** Virtual interface to all pixel-label information structs. See
529  * CObservation3DRangeScan::pixelLabels */
531  {
532  /** Used in CObservation3DRangeScan::pixelLabels */
534  using TMapLabelID2Name = std::map<uint32_t, std::string>;
535 
536  /** The 'semantic' or human-friendly name of the i'th bit in
537  * pixelLabels(r,c) can be found in pixelLabelNames[i] as a std::string
538  */
540 
541  const std::string& getLabelName(unsigned int label_idx) const
542  {
544  pixelLabelNames.find(label_idx);
545  if (it == pixelLabelNames.end())
546  throw std::runtime_error(
547  "Error: label index has no defined name");
548  return it->second;
549  }
550  void setLabelName(unsigned int label_idx, const std::string& name)
551  {
552  pixelLabelNames[label_idx] = name;
553  }
554  /** Check the existence of a label by returning its associated index.
555  * -1 if it does not exist. */
557  {
559  for (it = pixelLabelNames.begin(); it != pixelLabelNames.end();
560  it++)
561  if (it->second == name) return it->first;
562  return -1;
563  }
564 
565  /** Resizes the matrix pixelLabels to the given size, setting all
566  * bitfields to zero (that is, all pixels are assigned NONE category).
567  */
568  virtual void setSize(const int NROWS, const int NCOLS) = 0;
569  /** Mark the pixel(row,col) as classified in the category \a label_idx,
570  * which may be in the range 0 to MAX_NUM_LABELS-1
571  * Note that 0 is a valid label index, it does not mean "no label" \sa
572  * unsetLabel, unsetAll */
573  virtual void setLabel(
574  const int row, const int col, uint8_t label_idx) = 0;
575  virtual void getLabels(
576  const int row, const int col, uint8_t& labels) = 0;
577  /** For the pixel(row,col), removes its classification into the category
578  * \a label_idx, which may be in the range 0 to 7
579  * Note that 0 is a valid label index, it does not mean "no label" \sa
580  * setLabel, unsetAll */
581  virtual void unsetLabel(
582  const int row, const int col, uint8_t label_idx) = 0;
583  /** Removes all categories for pixel(row,col) \sa setLabel, unsetLabel
584  */
585  virtual void unsetAll(
586  const int row, const int col, uint8_t label_idx) = 0;
587  /** Checks whether pixel(row,col) has been clasified into category \a
588  * label_idx, which may be in the range 0 to 7
589  * \sa unsetLabel, unsetAll */
590  virtual bool checkLabel(
591  const int row, const int col, uint8_t label_idx) const = 0;
592 
596 
597  /// std stream interface
598  friend std::ostream& operator<<(
599  std::ostream& out, const TPixelLabelInfoBase& obj)
600  {
601  obj.Print(out);
602  return out;
603  }
604 
605  TPixelLabelInfoBase(unsigned int BITFIELD_BYTES_)
606  : BITFIELD_BYTES(BITFIELD_BYTES_)
607  {
608  }
609 
610  virtual ~TPixelLabelInfoBase() {}
611  /** Minimum number of bytes required to hold MAX_NUM_DIFFERENT_LABELS
612  * bits. */
614 
615  protected:
616  virtual void internal_readFromStream(
618  virtual void internal_writeToStream(
619  mrpt::serialization::CArchive& out) const = 0;
620  virtual void Print(std::ostream&) const = 0;
621  };
622 
623  template <unsigned int BYTES_REQUIRED_>
625  {
627  enum
628  {
629  BYTES_REQUIRED = BYTES_REQUIRED_ // ((MAX_LABELS-1)/8)+1
630  };
631 
632  /** Automatically-determined integer type of the proper size such that
633  * all labels fit as one bit (max: 64) */
634  using bitmask_t =
636 
637  /** Each pixel may be assigned between 0 and MAX_NUM_LABELS-1 'labels'
638  * by
639  * setting to 1 the corresponding i'th bit [0,MAX_NUM_LABELS-1] in the
640  * byte in pixelLabels(r,c).
641  * That is, each pixel is assigned an 8*BITFIELD_BYTES bit-wide
642  * bitfield of possible categories.
643  * \sa hasPixelLabels
644  */
645  using TPixelLabelMatrix =
646  Eigen::Matrix<bitmask_t, Eigen::Dynamic, Eigen::Dynamic>;
648 
649  void setSize(const int NROWS, const int NCOLS) override
650  {
651  pixelLabels = TPixelLabelMatrix::Zero(NROWS, NCOLS);
652  }
653  void setLabel(const int row, const int col, uint8_t label_idx) override
654  {
655  pixelLabels(row, col) |= static_cast<bitmask_t>(1) << label_idx;
656  }
657  void getLabels(const int row, const int col, uint8_t& labels) override
658  {
659  labels = pixelLabels(row, col);
660  }
661 
663  const int row, const int col, uint8_t label_idx) override
664  {
665  pixelLabels(row, col) &= ~(static_cast<bitmask_t>(1) << label_idx);
666  }
667  void unsetAll(const int row, const int col, uint8_t label_idx) override
668  {
669  pixelLabels(row, col) = 0;
670  }
672  const int row, const int col, uint8_t label_idx) const override
673  {
674  return (pixelLabels(row, col) &
675  (static_cast<bitmask_t>(1) << label_idx)) != 0;
676  }
677 
678  // Ctor: pass identification to parent for deserialization
679  TPixelLabelInfo() : TPixelLabelInfoBase(BYTES_REQUIRED_) {}
680 
681  protected:
685  mrpt::serialization::CArchive& out) const override;
686  void Print(std::ostream& out) const override
687  {
688  {
689  const uint32_t nR = static_cast<uint32_t>(pixelLabels.rows());
690  const uint32_t nC = static_cast<uint32_t>(pixelLabels.cols());
691  out << "Number of rows: " << nR << std::endl;
692  out << "Number of cols: " << nC << std::endl;
693  out << "Matrix of labels: " << std::endl;
694  for (uint32_t c = 0; c < nC; c++)
695  {
696  for (uint32_t r = 0; r < nR; r++)
697  out << pixelLabels.coeff(r, c) << " ";
698 
699  out << std::endl;
700  }
701  }
702  out << std::endl;
703  out << "Label indices and names: " << std::endl;
705  for (it = pixelLabelNames.begin(); it != pixelLabelNames.end();
706  it++)
707  out << it->first << " " << it->second << std::endl;
708  }
709  }; // end TPixelLabelInfo
710 
711  /** All information about pixel labeling is stored in this (smart pointer
712  * to) structure; refer to TPixelLabelInfo for details on the contents
713  * User is responsible of creating a new object of the desired data type.
714  * It will be automatically (de)serialized no matter its specific type. */
716 
717  /** @} */
718 
719  /** \name Sensor parameters
720  * @{ */
721  /** Projection parameters of the depth camera. */
723  /** Projection parameters of the intensity (graylevel or RGB) camera. */
725 
726  /** Relative pose of the intensity camera wrt the depth camera (which is the
727  * coordinates origin for this observation).
728  * In a SwissRanger camera, this will be (0,0,0,-90deg,0,-90deg) since
729  * both cameras coincide.
730  * In a Kinect, this will include a small lateral displacement and a
731  * rotation, according to the drawing on the top of this page.
732  * \sa doDepthAndIntensityCamerasCoincide
733  */
735 
736  /** Return true if \a relativePoseIntensityWRTDepth equals the pure rotation
737  * (0,0,0,-90deg,0,-90deg) (with a small comparison epsilon)
738  * \sa relativePoseIntensityWRTDepth
739  */
741 
742  /** The maximum range allowed by the device, in meters (e.g. 8.0m, 5.0m,...)
743  */
744  float maxRange;
745  /** The 6D pose of the sensor on the robot. */
747  /** The "sigma" error of the device in meters, used while inserting the scan
748  * in an occupancy grid. */
749  float stdError;
750 
751  // See base class docs
752  void getSensorPose(mrpt::poses::CPose3D& out_sensorPose) const override
753  {
754  out_sensorPose = sensorPose;
755  }
756  // See base class docs
757  void setSensorPose(const mrpt::poses::CPose3D& newSensorPose) override
758  {
759  sensorPose = newSensorPose;
760  }
761 
762  /** @} */ // end sensor params
763 
764  // See base class docs
765  void getDescriptionAsText(std::ostream& o) const override;
766 
767  /** Very efficient method to swap the contents of two observations. */
768  void swap(CObservation3DRangeScan& o);
769  /** Extract a ROI of the 3D observation as a new one. \note PixelLabels are
770  * *not* copied to the output subimage. */
771  void getZoneAsObs(
772  CObservation3DRangeScan& obs, const unsigned int& r1,
773  const unsigned int& r2, const unsigned int& c1, const unsigned int& c2);
774 
775  /** A Levenberg-Marquart-based optimizer to recover the calibration
776  * parameters of a 3D camera given a range (depth) image and the
777  * corresponding 3D point cloud.
778  * \param camera_offset The offset (in meters) in the +X direction of the
779  * point cloud. It's 1cm for SwissRanger SR4000.
780  * \return The final average reprojection error per pixel (typ <0.05 px)
781  */
783  const CObservation3DRangeScan& in_obs,
784  mrpt::img::TCamera& out_camParams, const double camera_offset = 0.01);
785 
786  /** Look-up-table struct for project3DPointsFromDepthImageInto() */
788  {
791  };
792  /** 3D point cloud projection look-up-table \sa
793  * project3DPointsFromDepthImage */
795 
796 }; // End of class def.
797 
798 } // namespace obs
799 namespace opengl
800 {
801 /** Specialization mrpt::opengl::PointCloudAdapter<CObservation3DRangeScan>
802  * \ingroup mrpt_adapters_grp */
803 template <>
806  mrpt::obs::CObservation3DRangeScan, float>
807 {
808  private:
810 
811  public:
812  /** The type of each point XYZ coordinates */
813  using coords_t = float;
814  /** Has any color RGB info? */
815  static const int HAS_RGB = 0;
816  /** Has native RGB info (as floats)? */
817  static const int HAS_RGBf = 0;
818  /** Has native RGB info (as uint8_t)? */
819  static const int HAS_RGBu8 = 0;
820 
821  /** Constructor (accept a const ref for convenience) */
823  : m_obj(*const_cast<mrpt::obs::CObservation3DRangeScan*>(&obj))
824  {
825  }
826  /** Get number of points */
827  inline size_t size() const { return m_obj.points3D_x.size(); }
828  /** Set number of points (to uninitialized values) */
829  inline void resize(const size_t N)
830  {
831  if (N) m_obj.hasPoints3D = true;
832  m_obj.resizePoints3DVectors(N);
833  }
834  /** Does nothing as of now */
835  inline void setDimensions(const size_t& height, const size_t& width)
836  {
837  }
838 
839 
840  /** Get XYZ coordinates of i'th point */
841  template <typename T>
842  inline void getPointXYZ(const size_t idx, T& x, T& y, T& z) const
843  {
844  x = m_obj.points3D_x[idx];
845  y = m_obj.points3D_y[idx];
846  z = m_obj.points3D_z[idx];
847  }
848  /** Set XYZ coordinates of i'th point */
849  inline void setPointXYZ(
850  const size_t idx, const coords_t x, const coords_t y, const coords_t z)
851  {
852  m_obj.points3D_x[idx] = x;
853  m_obj.points3D_y[idx] = y;
854  m_obj.points3D_z[idx] = z;
855  }
856  /** Set XYZ coordinates of i'th point */
857  inline void setInvalidPoint(const size_t idx)
858  {
860  "mrpt::obs::CObservation3DRangeScan requires needs to be dense");
861  }
862 
863 }; // end of PointCloudAdapter<CObservation3DRangeScan>
864 } // namespace opengl
865 } // namespace mrpt
870 
871 #include "CObservation3DRangeScan_project3D_impl.h"
bool m_points3D_external_stored
If set to true, m_points3D_external_file is valid.
Eigen::Matrix< bitmask_t, Eigen::Dynamic, Eigen::Dynamic > TPixelLabelMatrix
Each pixel may be assigned between 0 and MAX_NUM_LABELS-1 &#39;labels&#39; by setting to 1 the corresponding ...
std::string m_rangeImage_external_file
rangeImage is in CImage::getImagesPathBase()+<this_file_name>
mrpt::img::TCamera cameraParams
Projection parameters of the depth camera.
void setDimensions(const size_t &height, const size_t &width)
Does nothing as of now.
const std::string & getLabelName(unsigned int label_idx) const
void writeToStream(mrpt::serialization::CArchive &out) const
GLdouble GLdouble z
Definition: glext.h:3872
void getZoneAsObs(CObservation3DRangeScan &obs, const unsigned int &r1, const unsigned int &r2, const unsigned int &c1, const unsigned int &c2)
Extract a ROI of the 3D observation as a new one.
TIntensityChannelID
Enum type for intensityImageChannel.
void resizePoints3DVectors(const size_t nPoints)
Use this method instead of resizing all three points3D_x, points3D_y & points3D_z to allow the usage ...
virtual void setSize(const int NROWS, const int NCOLS)=0
Resizes the matrix pixelLabels to the given size, setting all bitfields to zero (that is...
const mrpt::poses::CPose3D * robotPoseInTheWorld
(Default: nullptr) Read takeIntoAccountSensorPoseOnRobot
#define THROW_EXCEPTION(msg)
Definition: exceptions.h:41
MRPT_FILL_ENUM_MEMBER(mrpt::obs::CObservation3DRangeScan, CH_VISIBLE)
void setLabelName(unsigned int label_idx, const std::string &name)
static double recoverCameraCalibrationParameters(const CObservation3DRangeScan &in_obs, mrpt::img::TCamera &out_camParams, const double camera_offset=0.01)
A Levenberg-Marquart-based optimizer to recover the calibration parameters of a 3D camera given a ran...
std::string sensorLabel
The sensor label that will have the newly created observation.
void project3DPointsFromDepthImage(const bool PROJ3D_USE_LUT=true)
This method is equivalent to project3DPointsFromDepthImageInto() storing the projected 3D points (wit...
std::vector< uint16_t > points3D_idxs_x
If hasPoints3D=true, the (x,y) pixel coordinates for each (X,Y,Z) point in points3D_x, points3D_y, points3D_z.
double oversampling_ratio
(Default=1.2=120%) How many more laser scans rays to create (read docs for CObservation3DRangeScan::c...
double angle_sup
(Default=5 degrees) [Only if use_origin_sensor_pose=false] The upper & lower half-FOV angle (in radia...
bool m_rangeImage_external_stored
If set to true, m_rangeImage_external_file is valid.
virtual void internal_readFromStream(mrpt::serialization::CArchive &in)=0
void getDescriptionAsText(std::ostream &o) const override
Build a detailed, multi-line textual description of the observation contents and dump it to the outpu...
Declares a class derived from "CObservation" that encapsules a 3D range scan measurement, as from a time-of-flight range camera or any other RGBD sensor.
Look-up-table struct for project3DPointsFromDepthImageInto()
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction...
Definition: eigen_frwds.h:44
static TPixelLabelInfoBase * readAndBuildFromStream(mrpt::serialization::CArchive &in)
friend std::ostream & operator<<(std::ostream &out, const TPixelLabelInfoBase &obj)
std stream interface
double z_min
(Default:-inf, +inf) [Only if use_origin_sensor_pose=true] Only obstacle points with Z coordinates wi...
virtual void unsetLabel(const int row, const int col, uint8_t label_idx)=0
For the pixel(row,col), removes its classification into the category label_idx, which may be in the r...
GLsizei GLsizei GLuint * obj
Definition: glext.h:4070
virtual void setLabel(const int row, const int col, uint8_t label_idx)=0
Mark the pixel(row,col) as classified in the category label_idx, which may be in the range 0 to MAX_N...
void resize(const size_t N)
Set number of points (to uninitialized values)
Used in CObservation3DRangeScan::project3DPointsFromDepthImageInto()
GLenum GLsizei width
Definition: glext.h:3531
Usage: uint_select_by_bytecount<N>type var; allows defining var as a unsigned integer with...
void setSensorPose(const mrpt::poses::CPose3D &newSensorPose) override
A general method to change the sensor pose on the robot.
void rangeImage_convertToExternalStorage(const std::string &fileName, const std::string &use_this_base_dir)
Users won&#39;t normally want to call this, it&#39;s only used from internal MRPT programs.
mrpt::math::CMatrix rangeImage
If hasRangeImage=true, a matrix of floats with the range data as captured by the camera (in meters) ...
unsigned char uint8_t
Definition: rptypes.h:41
const uint8_t BITFIELD_BYTES
Minimum number of bytes required to hold MAX_NUM_DIFFERENT_LABELS bits.
void internal_writeToStream(mrpt::serialization::CArchive &out) const override
PointCloudAdapter(const mrpt::obs::CObservation3DRangeScan &obj)
Constructor (accept a const ref for convenience)
std::string rangeImage_getExternalStorageFileAbsolutePath() const
void internal_readFromStream(mrpt::serialization::CArchive &in) override
mrpt::poses::CPose3D relativePoseIntensityWRTDepth
Relative pose of the intensity camera wrt the depth camera (which is the coordinates origin for this ...
An adapter to different kinds of point cloud object.
virtual bool checkLabel(const int row, const int col, uint8_t label_idx) const =0
Checks whether pixel(row,col) has been clasified into category label_idx, which may be in the range 0...
TMapLabelID2Name pixelLabelNames
The &#39;semantic&#39; or human-friendly name of the i&#39;th bit in pixelLabels(r,c) can be found in pixelLabelN...
const GLubyte * c
Definition: glext.h:6313
virtual void unload() override
Unload all images, for the case they being delayed-load images stored in external files (othewise...
void swap(CObservation3DRangeScan &o)
Very efficient method to swap the contents of two observations.
void project3DPointsFromDepthImageInto(mrpt::obs::CObservation3DRangeScan &src_obs, POINTMAP &dest_pointcloud, const mrpt::obs::T3DPointsProjectionParams &projectParams, const mrpt::obs::TRangeImageFilterParams &filterParams)
typename mrpt::uint_select_by_bytecount< BYTES_REQUIRED >::type bitmask_t
Automatically-determined integer type of the proper size such that all labels fit as one bit (max: 64...
mrpt::img::CImage intensityImage
If hasIntensityImage=true, a color or gray-level intensity image of the same size than "rangeImage"...
Used in CObservation3DRangeScan::convertTo2DScan()
int checkLabelNameExistence(const std::string &name) const
Check the existence of a label by returning its associated index.
std::string m_points3D_external_file
3D points are in CImage::getImagesPathBase()+<this_file_name>
bool hasRangeImage
true means the field rangeImage contains valid data
Structure to hold the parameters of a pinhole camera model.
Definition: TCamera.h:27
void convertTo2DScan(mrpt::obs::CObservation2DRangeScan &out_scan2d, const T3DPointsTo2DScanParams &scanParams, const TRangeImageFilterParams &filterParams=TRangeImageFilterParams())
Convert this 3D observation into an "equivalent 2D fake laser scan", with a configurable vertical FOV...
TIntensityChannelID intensityImageChannel
The source of the intensityImage; typically the visible channel.
#define MRPT_ENUM_TYPE_END()
Definition: TEnumType.h:78
void rangeImage_forceResetExternalStorage()
Forces marking this observation as non-externally stored - it doesn&#39;t anything else apart from reseti...
void setPointXYZ(const size_t idx, const coords_t x, const coords_t y, const coords_t z)
Set XYZ coordinates of i&#39;th point.
mrpt::img::CImage confidenceImage
If hasConfidenceImage=true, an image with the "confidence" value [range 0-255] as estimated by the ca...
std::string points3D_getExternalStorageFileAbsolutePath() const
bool hasPoints3D
true means the field points3D contains valid data.
GLsizei const GLchar ** string
Definition: glext.h:4101
float stdError
The "sigma" error of the device in meters, used while inserting the scan in an occupancy grid...
bool USE_SSE2
(Default:true) If possible, use SSE2 optimized code.
void getSensorPose(mrpt::poses::CPose3D &out_sensorPose) const override
A general method to retrieve the sensor pose on the robot.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
void setSize(const int NROWS, const int NCOLS) override
Resizes the matrix pixelLabels to the given size, setting all bitfields to zero (that is...
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:52
bool MAKE_ORGANIZED
(Default:false) set to true if you want an organized point cloud
GLdouble GLdouble GLdouble r
Definition: glext.h:3705
mrpt::poses::CPose3D sensorPose
The 6D pose of the sensor on the robot.
void getPointXYZ(const size_t idx, T &x, T &y, T &z) const
Get XYZ coordinates of i&#39;th point.
void getLabels(const int row, const int col, uint8_t &labels) override
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:86
Declares a class that represents any robot&#39;s observation.
Definition: CObservation.h:43
TPixelLabelInfoBase::Ptr pixelLabels
All information about pixel labeling is stored in this (smart pointer to) structure; refer to TPixelL...
static TCached3DProjTables & get_3dproj_lut()
3D point cloud projection look-up-table
GLenum GLenum GLvoid * row
Definition: glext.h:3576
Used in CObservation3DRangeScan::project3DPointsFromDepthImageInto()
virtual void internal_writeToStream(mrpt::serialization::CArchive &out) const =0
bool hasIntensityImage
true means the field intensityImage contains valid data
void setInvalidPoint(const size_t idx)
Set XYZ coordinates of i&#39;th point.
bool checkLabel(const int row, const int col, uint8_t label_idx) const override
Checks whether pixel(row,col) has been clasified into category label_idx, which may be in the range 0...
GLuint in
Definition: glext.h:7274
std::vector< float > points3D_x
If hasPoints3D=true, the (X,Y,Z) coordinates of the 3D point cloud detected by the camera...
GLuint const GLchar * name
Definition: glext.h:4054
void rangeImage_setSize(const int HEIGHT, const int WIDTH)
Similar to calling "rangeImage.setSize(H,W)" but this method provides memory pooling to speed-up the ...
bool hasPixelLabels() const
Returns true if the field CObservation3DRangeScan::pixelLabels contains a non-NULL smart pointer...
void project3DPointsFromDepthImageInto(POINTMAP &dest_pointcloud, const T3DPointsProjectionParams &projectParams, const TRangeImageFilterParams &filterParams=TRangeImageFilterParams())
Project the RGB+D images into a 3D point cloud (with color if the target map supports it) and optiona...
virtual void Print(std::ostream &) const =0
GLenum GLint GLint y
Definition: glext.h:3538
void points3D_convertToExternalStorage(const std::string &fileName, const std::string &use_this_base_dir)
Users won&#39;t normally want to call this, it&#39;s only used from internal MRPT programs.
bool PROJ3D_USE_LUT
(Default:true) [Only used when range_is_depth=true] Whether to use a Look-up-table (LUT) to speed up ...
bool doDepthAndIntensityCamerasCoincide() const
Return true if relativePoseIntensityWRTDepth equals the pure rotation (0,0,0,-90deg,0,-90deg) (with a small comparison epsilon)
void unsetLabel(const int row, const int col, uint8_t label_idx) override
For the pixel(row,col), removes its classification into the category label_idx, which may be in the r...
GLsizei const GLfloat * value
Definition: glext.h:4117
virtual void unsetAll(const int row, const int col, uint8_t label_idx)=0
Removes all categories for pixel(row,col)
A helper base class for those PointCloudAdapter<> which do not handle RGB data; it declares needed in...
GLenum GLint x
Definition: glext.h:3538
mrpt::img::TCamera cameraParamsIntensity
Projection parameters of the intensity (graylevel or RGB) camera.
bool MAKE_DENSE
(Default:true) set to false if your point cloud can contain undefined values
This class is a "CSerializable" wrapper for "CMatrixFloat".
Definition: CMatrix.h:22
GLenum GLsizei GLsizei height
Definition: glext.h:3554
size_t getScanSize() const
Get the size of the scan pointcloud.
#define MRPT_ENUM_TYPE_BEGIN(_ENUM_TYPE_WITH_NS)
Definition: TEnumType.h:62
unsigned __int32 uint32_t
Definition: rptypes.h:47
bool range_is_depth
true: Kinect-like ranges: entries of rangeImage are distances along the +X axis; false: Ranges in ran...
void setLabel(const int row, const int col, uint8_t label_idx) override
Mark the pixel(row,col) as classified in the category label_idx, which may be in the range 0 to MAX_N...
GLfloat GLfloat p
Definition: glext.h:6305
const Scalar * const_iterator
Definition: eigen_plugins.h:27
Virtual interface to all pixel-label information structs.
void unsetAll(const int row, const int col, uint8_t label_idx) override
Removes all categories for pixel(row,col)
Grayscale or RGB visible channel of the camera sensor.
bool takeIntoAccountSensorPoseOnRobot
(Default: false) If false, local (sensor-centric) coordinates of points are generated.
virtual void load() const override
Makes sure all images and other fields which may be externally stored are loaded in memory...
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:130
virtual void getLabels(const int row, const int col, uint8_t &labels)=0
bool use_origin_sensor_pose
(Default:false) If false, the conversion will be such that the 2D observation pose on the robot coinc...
float maxRange
The maximum range allowed by the device, in meters (e.g.
bool hasConfidenceImage
true means the field confidenceImage contains valid data



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020