Point Cloud Library (PCL)  1.9.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
real_sense_device_manager.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2015-, Open Perception, Inc.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of the copyright holder(s) nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  */
37 
38 #ifndef PCL_IO_REAL_SENSE_DEVICE_MANAGER_H
39 #define PCL_IO_REAL_SENSE_DEVICE_MANAGER_H
40 
41 #include <boost/thread.hpp>
42 #include <boost/utility.hpp>
43 #include <boost/weak_ptr.hpp>
44 #include <boost/shared_ptr.hpp>
45 #include <boost/thread/mutex.hpp>
46 
47 #include <pcl/pcl_exports.h>
48 
49 #include <pxcsession.h>
50 #include <pxccapture.h>
51 #include <pxccapturemanager.h>
52 
53 namespace pcl
54 {
55 
56  class RealSenseGrabber;
57 
58  namespace io
59  {
60 
61  namespace real_sense
62  {
63 
64  class RealSenseDevice;
65 
66  class PCL_EXPORTS RealSenseDeviceManager : boost::noncopyable
67  {
68 
69  public:
70 
71  typedef boost::shared_ptr<RealSenseDeviceManager> Ptr;
72 
73  static Ptr&
75  {
76  static Ptr instance;
77  if (!instance)
78  {
79  boost::mutex::scoped_lock lock (mutex_);
80  if (!instance)
81  instance.reset (new RealSenseDeviceManager);
82  }
83  return (instance);
84  }
85 
86  inline size_t
88  {
89  return (device_list_.size ());
90  }
91 
92  boost::shared_ptr<RealSenseDevice>
93  captureDevice ();
94 
95  boost::shared_ptr<RealSenseDevice>
96  captureDevice (size_t index);
97 
98  boost::shared_ptr<RealSenseDevice>
99  captureDevice (const std::string& sn);
100 
102 
103  private:
104 
105  struct DeviceInfo
106  {
107  pxcUID iuid;
108  pxcI32 didx;
109  std::string serial;
110  boost::weak_ptr<RealSenseDevice> device_ptr;
111  inline bool isCaptured () { return (!device_ptr.expired ()); }
112  };
113 
114  /** If the device is already captured returns a pointer. */
115  boost::shared_ptr<RealSenseDevice>
116  capture (DeviceInfo& device_info);
117 
118  RealSenseDeviceManager ();
119 
120  /** This function discovers devices that are capable of streaming
121  * depth data. */
122  void
123  populateDeviceList ();
124 
125  boost::shared_ptr<PXCSession> session_;
126  boost::shared_ptr<PXCCaptureManager> capture_manager_;
127 
128  std::vector<DeviceInfo> device_list_;
129 
130  static boost::mutex mutex_;
131 
132  };
133 
134  class PCL_EXPORTS RealSenseDevice : boost::noncopyable
135  {
136 
137  public:
138 
139  typedef boost::shared_ptr<RealSenseDevice> Ptr;
140 
141  inline const std::string&
142  getSerialNumber () { return (device_id_); }
143 
144  inline PXCCapture::Device&
145  getPXCDevice () { return (*device_); }
146 
147  /** Reset the state of given device by releasing and capturing again. */
148  static void
150  {
151  std::string id = device->getSerialNumber ();
152  device.reset ();
153  device = RealSenseDeviceManager::getInstance ()->captureDevice (id);
154  }
155 
156  private:
157 
159 
160  std::string device_id_;
161  boost::shared_ptr<PXCCapture> capture_;
162  boost::shared_ptr<PXCCapture::Device> device_;
163 
164  RealSenseDevice (const std::string& id) : device_id_ (id) { };
165 
166  };
167 
168  } // namespace real_sense
169 
170  } // namespace io
171 
172 } // namespace pcl
173 
174 #endif /* PCL_IO_REAL_SENSE_DEVICE_MANAGER_H */
175 
boost::shared_ptr< RealSenseDevice > Ptr
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
static void reset(RealSenseDevice::Ptr &device)
Reset the state of given device by releasing and capturing again.
boost::shared_ptr< RealSenseDeviceManager > Ptr