openni_driver.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2011 Willow Garage, Inc.
00005  *
00006  *  All rights reserved.
00007  *
00008  *  Redistribution and use in source and binary forms, with or without
00009  *  modification, are permitted provided that the following conditions
00010  *  are met:
00011  *
00012  *   * Redistributions of source code must retain the above copyright
00013  *     notice, this list of conditions and the following disclaimer.
00014  *   * Redistributions in binary form must reproduce the above
00015  *     copyright notice, this list of conditions and the following
00016  *     disclaimer in the documentation and/or other materials provided
00017  *     with the distribution.
00018  *   * Neither the name of the copyright holder(s) nor the names of its
00019  *     contributors may be used to endorse or promote products derived
00020  *     from this software without specific prior written permission.
00021  *
00022  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033  *  POSSIBILITY OF SUCH DAMAGE.
00034  *
00035  */
00036 
00037 #include <pcl/pcl_config.h>
00038 #ifdef HAVE_OPENNI
00039 
00040 #ifndef OPENNI_OPENNI_H_
00041 #define OPENNI_OPENNI_H_
00042 #include <string>
00043 #include <vector>
00044 #include <map>
00045 #include "openni.h"
00046 #include "openni_exception.h"
00047 #include "openni_device.h"
00048 #include <pcl/io/boost.h>
00049 #include <pcl/pcl_macros.h>
00050 
00051 namespace openni_wrapper
00052 {
00053   //class OpenNIDevice;
00054 
00062   class PCL_EXPORTS OpenNIDriver
00063   {
00064   public:
00069     ~OpenNIDriver () throw ();
00070 
00076     inline static OpenNIDriver& getInstance ();
00077 
00083     unsigned updateDeviceList ();
00084 
00089     inline unsigned getNumberDevices () const throw ();
00090 
00099     boost::shared_ptr<OpenNIDevice> createVirtualDevice (const std::string& path, bool repeat, bool stream) const;
00100 
00107     boost::shared_ptr<OpenNIDevice> getDeviceByIndex (unsigned index) const;
00108 
00115     boost::shared_ptr<OpenNIDevice> getDeviceBySerialNumber (const std::string& serial_number) const;
00116     
00117 #ifndef _WIN32
00118 
00125     boost::shared_ptr<OpenNIDevice> getDeviceByAddress (unsigned char bus, unsigned char address) const;
00126 #endif
00127 
00134     const char* getSerialNumber (unsigned index) const throw ();
00135 
00142     const char* getConnectionString (unsigned index) const throw ();
00143 
00150     const char* getVendorName (unsigned index) const throw ();
00151 
00158     const char* getProductName (unsigned index) const throw ();
00159 
00166     unsigned short getVendorID (unsigned index) const throw ();
00167 
00174     unsigned short getProductID (unsigned index) const throw ();
00175 
00182     unsigned char  getBus (unsigned index) const throw ();
00183 
00190     unsigned char  getAddress (unsigned index) const throw ();
00191 
00196     void stopAll ();
00197 
00205     static void
00206     getDeviceType (const std::string& connection_string, unsigned short& vendorId, unsigned short& productId);
00207   protected:
00208 
00209     struct PCL_EXPORTS DeviceContext
00210     {
00211       DeviceContext (const xn::NodeInfo& device_node, xn::NodeInfo* image_node, xn::NodeInfo* depth_node, xn::NodeInfo * ir_node);
00212       DeviceContext (const xn::NodeInfo & device_node);
00213       DeviceContext (const DeviceContext&);
00214       xn::NodeInfo device_node;
00215       boost::shared_ptr<xn::NodeInfo> image_node;
00216       boost::shared_ptr<xn::NodeInfo> depth_node;
00217       boost::shared_ptr<xn::NodeInfo> ir_node;
00218       boost::weak_ptr<OpenNIDevice> device;
00219     } ;
00220 
00221     OpenNIDriver ();
00222     boost::shared_ptr<OpenNIDevice> getDevice (unsigned index) const;
00223 
00224 #ifndef _WIN32
00225     // workaround to get additional device nformation like serial number, vendor and product name, until Primesense fix this
00226     void getDeviceInfos () throw ();
00227 #endif
00228 
00229     mutable std::vector<DeviceContext> device_context_;
00230     mutable xn::Context context_;
00231 
00232     std::map< unsigned char, std::map<unsigned char, unsigned > > bus_map_;
00233     std::map< std::string, unsigned > serial_map_;
00234     std::map< std::string, unsigned > connection_string_map_;
00235   } ;
00236 
00237   OpenNIDriver&
00238   OpenNIDriver::getInstance ()
00239   {
00240     static OpenNIDriver driver;
00241     return driver;
00242   }
00243 
00244   unsigned
00245   OpenNIDriver::getNumberDevices () const throw ()
00246   {
00247     return static_cast<unsigned> (device_context_.size ());
00248   }
00249 } // namespace
00250 #endif
00251 #endif


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:26:23