Main MRPT website > C++ reference for MRPT 1.9.9
COpenNI2Generic.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-2017, 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 #ifndef mrpt_COpenNI2Generic_H
10 #define mrpt_COpenNI2Generic_H
11 
13 
14 namespace mrpt
15 {
16 namespace hwdrivers
17 {
18 /** An abstract class for accessing OpenNI2 compatible sensors.
19  * This class permits to access several sensors simultaneously. The same
20  *options (resolution, fps, etc.) are used for every sensor.
21  *
22  * More references to read:
23  * - http://http://www.openni.org/
24  * \ingroup mrpt_hwdrivers_grp
25  */
27 {
28  public:
29  /** Default ctor (width=640, height=480, fps=30)
30  */
32  /** Ctor. \sa start()
33  */
35  int width, int height, float fps = 30.0f, bool open_streams_now = true);
36 
37  /** Default ctor
38  */
40 
41  /** The main data retrieving function, to be called after calling
42  * loadConfig() and initialize().
43  * \param out_img The output retrieved RGB image (only if
44  * there_is_obs=true).
45  * \param timestamp The timestamp of the capture (only if
46  * there_is_obs=true).
47  * \param there_is_obs If set to false, there was no new observation.
48  * \param hardware_error True on hardware/comms error.
49  * \param sensor_id The index of the sensor accessed. */
50  void getNextFrameRGB(
51  mrpt::utils::CImage& rgb_img, uint64_t& timestamp, bool& there_is_obs,
52  bool& hardware_error, unsigned sensor_id = 0);
53 
54  /** The main data retrieving function, to be called after calling
55  * loadConfig() and initialize().
56  * \param depth_img The output retrieved depth image (only if
57  * there_is_obs=true).
58  * \param timestamp The timestamp of the capture (only if
59  * there_is_obs=true).
60  * \param there_is_obs If set to false, there was no new observation.
61  * \param hardware_error True on hardware/comms error.
62  * \param sensor_id The index of the sensor accessed. */
63  void getNextFrameD(
64  mrpt::math::CMatrix& depth_img, uint64_t& timestamp, bool& there_is_obs,
65  bool& hardware_error, unsigned sensor_id = 0);
66 
67  /** The main data retrieving function, to be called after calling
68  * loadConfig() and initialize().
69  * \param out_obs The output retrieved observation (only if
70  * there_is_obs=true).
71  * \param there_is_obs If set to false, there was no new observation.
72  * \param hardware_error True on hardware/comms error.
73  * \param sensor_id The index of the sensor accessed.
74  *
75  * \sa doProcess
76  */
77  void getNextFrameRGBD(
78  mrpt::obs::CObservation3DRangeScan& out_obs, bool& there_is_obs,
79  bool& hardware_error, unsigned sensor_id = 0);
80 
81  /** @name Open/Close device methods
82  @{ */
83  /** Try to open the camera (all the parameters [resolution,fps,...] must be
84  * set before calling this) - users may also call initialize(), which in
85  * turn calls this method.
86  * Raises an exception upon error.
87  * \exception std::exception A textual description of the error.
88  */
89  void open(unsigned sensor_id = 0);
90 
91  /** Open a set of RGBD devices specified by their serial number. Raises an
92  * exception when the demanded serial numbers
93  * are not among the connected devices. This function also fills a vector
94  * with the serial numbers of the connected
95  * OpenNI2 sensors (this requires openning the sensors which are still
96  * closed to read their serial)
97  */
98  unsigned int openDevicesBySerialNum(
99  const std::set<unsigned>& vSerialRequired);
100 
101  /** Open a RGBD device specified by its serial number. This method is a
102  * wrapper for
103  * openDevicesBySerialNum(const std::set<unsigned>& vSerialRequired)
104  * This method requires to open the sensors which are still closed to read
105  * their serial.
106  */
107  unsigned int openDeviceBySerial(const unsigned int SerialRequired);
108 
109  /** Get the ID of the device corresponding to 'SerialRequired'.
110  */
112  const unsigned int SerialRequired, int& sensor_id) const;
113  /** Open all sensor streams (normally called automatically at constructor,
114  * no need to call it manually). \return false on error \sa kill() to close
115  */
116  bool start();
117  /** Kill the OpenNI2 driver \sa start()
118  */
119  void kill();
120  /** Whether there is a working connection to the sensor
121  */
122  bool isOpen(const unsigned sensor_id) const;
123  /** Close the connection to the sensor (no need to call it manually unless
124  * desired for some reason, since it's called at destructor
125  */
126  void close(unsigned sensor_id = 0);
127  /** The number of available devices at initialization
128  */
129  int getNumDevices() const;
130  /** Get a list of the connected OpenNI2 sensors.
131  */
132  int getConnectedDevices();
133 
134  /** @} */
135 
136  void setVerbose(bool verbose);
137  bool isVerbose() const;
138 
139  bool getColorSensorParam(
140  mrpt::utils::TCamera& param, unsigned sensor_id = 0) const;
141  bool getDepthSensorParam(
142  mrpt::utils::TCamera& param, unsigned sensor_id = 0) const;
143 
144  protected:
145  /** The list of available devices */
146  class CDevice;
147  static std::vector<std::shared_ptr<CDevice>> vDevices;
148  static int numInstances;
149 
150  /** A vector with the serial numbers of the available devices */
151  std::vector<int> vSerialNums;
152 
153  /** The same options (width, height and fps) are set for all the sensors.
154  * (This could be changed if necessary) */
156  float m_fps;
158  bool m_verbose;
159  void showLog(const std::string& message) const;
160  /** The data that the RGBD sensors can return */
161  /** Default: all true
162  */
164 }; // End of class
165 } // End of NS
166 } // End of NS
167 #endif
bool m_grab_image
The data that the RGBD sensors can return.
int getNumDevices() const
The number of available devices at initialization.
void getNextFrameRGB(mrpt::utils::CImage &rgb_img, uint64_t &timestamp, bool &there_is_obs, bool &hardware_error, unsigned sensor_id=0)
The main data retrieving function, to be called after calling loadConfig() and initialize().
A class for storing images as grayscale or RGB bitmaps.
Definition: CImage.h:118
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.
void getNextFrameRGBD(mrpt::obs::CObservation3DRangeScan &out_obs, bool &there_is_obs, bool &hardware_error, unsigned sensor_id=0)
The main data retrieving function, to be called after calling loadConfig() and initialize().
COpenNI2Generic()
Default ctor (width=640, height=480, fps=30)
GLenum GLsizei width
Definition: glext.h:3531
int m_width
The same options (width, height and fps) are set for all the sensors.
void kill()
Kill the OpenNI2 driver.
bool getDepthSensorParam(mrpt::utils::TCamera &param, unsigned sensor_id=0) const
unsigned int openDeviceBySerial(const unsigned int SerialRequired)
Open a RGBD device specified by its serial number.
bool start()
Open all sensor streams (normally called automatically at constructor, no need to call it manually)...
bool isOpen(const unsigned sensor_id) const
Whether there is a working connection to the sensor.
void close(unsigned sensor_id=0)
Close the connection to the sensor (no need to call it manually unless desired for some reason...
An abstract class for accessing OpenNI2 compatible sensors.
std::vector< int > vSerialNums
A vector with the serial numbers of the available devices.
GLsizei const GLchar ** string
Definition: glext.h:4101
void getNextFrameD(mrpt::math::CMatrix &depth_img, uint64_t &timestamp, bool &there_is_obs, bool &hardware_error, unsigned sensor_id=0)
The main data retrieving function, to be called after calling loadConfig() and initialize().
static std::vector< std::shared_ptr< CDevice > > vDevices
unsigned int openDevicesBySerialNum(const std::set< unsigned > &vSerialRequired)
Open a set of RGBD devices specified by their serial number.
unsigned __int64 uint64_t
Definition: rptypes.h:50
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
bool getColorSensorParam(mrpt::utils::TCamera &param, unsigned sensor_id=0) const
void open(unsigned sensor_id=0)
Try to open the camera (all the parameters [resolution,fps,...] must be set before calling this) - us...
bool getDeviceIDFromSerialNum(const unsigned int SerialRequired, int &sensor_id) const
Get the ID of the device corresponding to &#39;SerialRequired&#39;.
int getConnectedDevices()
Get a list of the connected OpenNI2 sensors.
void showLog(const std::string &message) const
This class is a "CSerializable" wrapper for "CMatrixFloat".
Definition: CMatrix.h:25
GLenum GLsizei GLsizei height
Definition: glext.h:3554
GLfloat param
Definition: glext.h:3831
Structure to hold the parameters of a pinhole camera model.
Definition: TCamera.h:32



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019