Visual Servoing Platform  version 3.2.0 under development (2019-01-22)
vpRealSense2.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * librealSense2 interface.
33  *
34  *****************************************************************************/
35 
36 #ifndef _vpRealSense2_h_
37 #define _vpRealSense2_h_
38 
39 #include <visp3/core/vpConfig.h>
40 
41 #if defined(VISP_HAVE_REALSENSE2) && defined(VISP_HAVE_CPP11_COMPATIBILITY)
42 
43 #include <librealsense2/rs.hpp>
44 #include <librealsense2/rsutil.h>
45 
46 #ifdef VISP_HAVE_PCL
47 #include <pcl/common/common_headers.h>
48 #endif
49 
50 #include <visp3/core/vpCameraParameters.h>
51 #include <visp3/core/vpImage.h>
52 
281 class VISP_EXPORT vpRealSense2
282 {
283 public:
284  vpRealSense2();
285  virtual ~vpRealSense2();
286 
287  void acquire(vpImage<unsigned char> &grey);
288  void acquire(vpImage<vpRGBa> &color);
289  void acquire(unsigned char *const data_image, unsigned char *const data_depth,
290  std::vector<vpColVector> *const data_pointCloud, unsigned char *const data_infrared,
291  rs2::align *const align_to = NULL);
292 
293 #ifdef VISP_HAVE_PCL
294  void acquire(unsigned char *const data_image, unsigned char *const data_depth,
295  std::vector<vpColVector> *const data_pointCloud, pcl::PointCloud<pcl::PointXYZ>::Ptr &pointcloud,
296  unsigned char *const data_infrared = NULL, rs2::align *const align_to = NULL);
297  void acquire(unsigned char *const data_image, unsigned char *const data_depth,
298  std::vector<vpColVector> *const data_pointCloud, pcl::PointCloud<pcl::PointXYZRGB>::Ptr &pointcloud,
299  unsigned char *const data_infrared = NULL, rs2::align *const align_to = NULL);
300 #endif
301 
302  void close();
303 
304  vpCameraParameters getCameraParameters(
305  const rs2_stream &stream,
307 
308  float getDepthScale();
309 
310  rs2_intrinsics getIntrinsics(const rs2_stream &stream) const;
311 
315  inline float getInvalidDepthValue() const { return m_invalidDepthValue; }
316 
319  inline float getMaxZ() const { return m_max_Z; }
320 
322  rs2::pipeline &getPipeline() { return m_pipe; }
323 
325  rs2::pipeline_profile &getPipelineProfile() { return m_pipelineProfile; }
326 
327  vpHomogeneousMatrix getTransformation(const rs2_stream &from, const rs2_stream &to) const;
328 
329  void open(const rs2::config &cfg = rs2::config());
330 
331  friend VISP_EXPORT std::ostream &operator<<(std::ostream &os, const vpRealSense2 &rs);
332 
336  inline void setInvalidDepthValue(const float value) { m_invalidDepthValue = value; }
337 
340  inline void setMaxZ(const float maxZ) { m_max_Z = maxZ; }
341 
342 protected:
343  rs2_intrinsics m_colorIntrinsics;
344  rs2_extrinsics m_depth2ColorExtrinsics;
345  rs2_intrinsics m_depthIntrinsics;
348  float m_max_Z;
349  rs2::pipeline m_pipe;
350  rs2::pipeline_profile m_pipelineProfile;
351  rs2::pointcloud m_pointcloud;
352  rs2::points m_points;
353 
354  void getColorFrame(const rs2::frame &frame, vpImage<vpRGBa> &color);
355  void getGreyFrame(const rs2::frame &frame, vpImage<unsigned char> &grey);
356  void getNativeFrameData(const rs2::frame &frame, unsigned char *const data);
357  void getPointcloud(const rs2::depth_frame &depth_frame, std::vector<vpColVector> &pointcloud);
358 #ifdef VISP_HAVE_PCL
359  void getPointcloud(const rs2::depth_frame &depth_frame, pcl::PointCloud<pcl::PointXYZ>::Ptr &pointcloud);
360  void getPointcloud(const rs2::depth_frame &depth_frame, const rs2::frame &color_frame,
361  pcl::PointCloud<pcl::PointXYZRGB>::Ptr &pointcloud);
362 #endif
363 };
364 
365 #endif
366 #endif
rs2::pipeline_profile & getPipelineProfile()
Get a reference to rs2::pipeline_profile.
Definition: vpRealSense2.h:325
void setMaxZ(const float maxZ)
Definition: vpRealSense2.h:340
Implementation of an homogeneous matrix and operations on such kind of matrices.
float m_depthScale
Definition: vpRealSense2.h:346
void setInvalidDepthValue(const float value)
Definition: vpRealSense2.h:336
rs2_intrinsics m_depthIntrinsics
Definition: vpRealSense2.h:345
rs2_intrinsics m_colorIntrinsics
Definition: vpRealSense2.h:343
rs2::pipeline_profile m_pipelineProfile
Definition: vpRealSense2.h:350
float getMaxZ() const
Definition: vpRealSense2.h:319
Generic class defining intrinsic camera parameters.
float getInvalidDepthValue() const
Definition: vpRealSense2.h:315
rs2_extrinsics m_depth2ColorExtrinsics
Definition: vpRealSense2.h:344
rs2::pointcloud m_pointcloud
Definition: vpRealSense2.h:351
rs2::pipeline & getPipeline()
Get a reference to rs2::pipeline.
Definition: vpRealSense2.h:322
rs2::pipeline m_pipe
Definition: vpRealSense2.h:349
rs2::points m_points
Definition: vpRealSense2.h:352
float m_invalidDepthValue
Definition: vpRealSense2.h:347