Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
openni_driver.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011 Willow Garage, Inc.
5  *
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of Willow Garage, Inc. nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *
35  */
36 
37 #include <pcl/pcl_config.h>
38 #ifdef HAVE_OPENNI
39 
40 #ifndef OPENNI_OPENNI_H_
41 #define OPENNI_OPENNI_H_
42 #include <string>
43 #include <vector>
44 #include <map>
45 #include "openni_exception.h"
46 #include "openni_device.h"
47 #include <boost/shared_ptr.hpp>
48 #include <boost/weak_ptr.hpp>
49 #include <XnCppWrapper.h>
50 
51 #include <pcl/pcl_macros.h>
52 
53 namespace openni_wrapper
54 {
55  //class OpenNIDevice;
56 
64  class PCL_EXPORTS OpenNIDriver
65  {
66  public:
71  ~OpenNIDriver () throw ();
72 
78  inline static OpenNIDriver& getInstance ();
79 
85  unsigned updateDeviceList ();
86 
91  inline unsigned getNumberDevices () const throw ();
92 
101  boost::shared_ptr<OpenNIDevice> createVirtualDevice (const std::string& path, bool repeat, bool stream) const;
102 
109  boost::shared_ptr<OpenNIDevice> getDeviceByIndex (unsigned index) const;
110 
117  boost::shared_ptr<OpenNIDevice> getDeviceBySerialNumber (const std::string& serial_number) const;
118 
119 #ifndef _WIN32
120 
127  boost::shared_ptr<OpenNIDevice> getDeviceByAddress (unsigned char bus, unsigned char address) const;
128 #endif
129 
136  const char* getSerialNumber (unsigned index) const throw ();
137 
144  const char* getConnectionString (unsigned index) const throw ();
145 
152  const char* getVendorName (unsigned index) const throw ();
153 
160  const char* getProductName (unsigned index) const throw ();
161 
168  unsigned short getVendorID (unsigned index) const throw ();
169 
176  unsigned short getProductID (unsigned index) const throw ();
177 
184  unsigned char getBus (unsigned index) const throw ();
185 
192  unsigned char getAddress (unsigned index) const throw ();
193 
198  void stopAll ();
199 
207  static void
208  getDeviceType (const std::string& connection_string, unsigned short& vendorId, unsigned short& productId);
209  protected:
210 
211  struct PCL_EXPORTS DeviceContext
212  {
213  DeviceContext (const xn::NodeInfo& device_node, xn::NodeInfo* image_node, xn::NodeInfo* depth_node, xn::NodeInfo * ir_node);
214  DeviceContext (const xn::NodeInfo & device_node);
215  DeviceContext (const DeviceContext&);
216  xn::NodeInfo device_node;
217  boost::shared_ptr<xn::NodeInfo> image_node;
218  boost::shared_ptr<xn::NodeInfo> depth_node;
219  boost::shared_ptr<xn::NodeInfo> ir_node;
220  boost::weak_ptr<OpenNIDevice> device;
221  } ;
222 
223  OpenNIDriver ();
224  boost::shared_ptr<OpenNIDevice> getDevice (unsigned index) const;
225 
226 #ifndef _WIN32
227  // workaround to get additional device nformation like serial number, vendor and product name, until Primesense fix this
228  void getDeviceInfos () throw ();
229 #endif
230 
231  mutable std::vector<DeviceContext> device_context_;
232  mutable xn::Context context_;
233 
234  std::map< unsigned char, std::map<unsigned char, unsigned > > bus_map_;
235  std::map< std::string, unsigned > serial_map_;
236  std::map< std::string, unsigned > connection_string_map_;
237  } ;
238 
239  OpenNIDriver&
240  OpenNIDriver::getInstance ()
241  {
242  static OpenNIDriver driver;
243  return driver;
244  }
245 
246  unsigned
247  OpenNIDriver::getNumberDevices () const throw ()
248  {
249  return static_cast<unsigned> (device_context_.size ());
250  }
251 } // namespace
252 #endif
253 #endif