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 Willow Garage, Inc. 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_exception.h"
00046 #include "openni_device.h"
00047 #include <boost/shared_ptr.hpp>
00048 #include <boost/weak_ptr.hpp>
00049 #include <XnCppWrapper.h>
00050 
00051 #include <pcl/pcl_macros.h>
00052 
00053 namespace openni_wrapper
00054 {
00055   //class OpenNIDevice;
00056 
00064   class PCL_EXPORTS OpenNIDriver
00065   {
00066   public:
00071     ~OpenNIDriver () throw ();
00072 
00078     inline static OpenNIDriver& getInstance ();
00079 
00085     unsigned updateDeviceList ();
00086 
00091     inline unsigned getNumberDevices () const throw ();
00092 
00101     boost::shared_ptr<OpenNIDevice> createVirtualDevice (const std::string& path, bool repeat, bool stream) const;
00102 
00109     boost::shared_ptr<OpenNIDevice> getDeviceByIndex (unsigned index) const;
00110 
00117     boost::shared_ptr<OpenNIDevice> getDeviceBySerialNumber (const std::string& serial_number) const;
00118     
00119 #ifndef _WIN32
00120 
00127     boost::shared_ptr<OpenNIDevice> getDeviceByAddress (unsigned char bus, unsigned char address) const;
00128 #endif
00129 
00136     const char* getSerialNumber (unsigned index) const throw ();
00137 
00144     const char* getConnectionString (unsigned index) const throw ();
00145 
00152     const char* getVendorName (unsigned index) const throw ();
00153 
00160     const char* getProductName (unsigned index) const throw ();
00161 
00168     unsigned short getVendorID (unsigned index) const throw ();
00169 
00176     unsigned short getProductID (unsigned index) const throw ();
00177 
00184     unsigned char  getBus (unsigned index) const throw ();
00185 
00192     unsigned char  getAddress (unsigned index) const throw ();
00193 
00198     void stopAll ();
00199 
00207     static void
00208     getDeviceType (const std::string& connection_string, unsigned short& vendorId, unsigned short& productId);
00209   protected:
00210 
00211     struct PCL_EXPORTS DeviceContext
00212     {
00213       DeviceContext (const xn::NodeInfo& device_node, xn::NodeInfo* image_node, xn::NodeInfo* depth_node, xn::NodeInfo * ir_node);
00214       DeviceContext (const xn::NodeInfo & device_node);
00215       DeviceContext (const DeviceContext&);
00216       xn::NodeInfo device_node;
00217       boost::shared_ptr<xn::NodeInfo> image_node;
00218       boost::shared_ptr<xn::NodeInfo> depth_node;
00219       boost::shared_ptr<xn::NodeInfo> ir_node;
00220       boost::weak_ptr<OpenNIDevice> device;
00221     } ;
00222 
00223     OpenNIDriver ();
00224     boost::shared_ptr<OpenNIDevice> getDevice (unsigned index) const;
00225 
00226 #ifndef _WIN32
00227     // workaround to get additional device nformation like serial number, vendor and product name, until Primesense fix this
00228     void getDeviceInfos () throw ();
00229 #endif
00230 
00231     mutable std::vector<DeviceContext> device_context_;
00232     mutable xn::Context context_;
00233 
00234     std::map< unsigned char, std::map<unsigned char, unsigned > > bus_map_;
00235     std::map< std::string, unsigned > serial_map_;
00236     std::map< std::string, unsigned > connection_string_map_;
00237   } ;
00238 
00239   OpenNIDriver&
00240   OpenNIDriver::getInstance ()
00241   {
00242     static OpenNIDriver driver;
00243     return driver;
00244   }
00245 
00246   unsigned
00247   OpenNIDriver::getNumberDevices () const throw ()
00248   {
00249     return static_cast<unsigned> (device_context_.size ());
00250   }
00251 } // namespace
00252 #endif
00253 #endif


pcl
Author(s): Open Perception
autogenerated on Mon Oct 6 2014 03:16:00