Point Cloud Library (PCL)  1.8.0
depth_sense_device_manager.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2014-, 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_DEPTH_SENSE_DEVICE_MANAGER_H
39 #define PCL_IO_DEPTH_SENSE_DEVICE_MANAGER_H
40 
41 #include <boost/utility.hpp>
42 #include <boost/shared_ptr.hpp>
43 #include <boost/thread/mutex.hpp>
44 #include <boost/thread.hpp>
45 
46 #include <pcl/pcl_exports.h>
47 
48 #include <DepthSense.hxx>
49 
50 namespace pcl
51 {
52 
53  namespace io
54  {
55 
56  namespace depth_sense
57  {
58 
59  struct DepthSenseGrabberImpl;
60 
61  /** A helper class for enumerating and managing access to DepthSense
62  * devices. */
63  class PCL_EXPORTS DepthSenseDeviceManager : boost::noncopyable
64  {
65 
66  public:
67 
68  typedef boost::shared_ptr<DepthSenseDeviceManager> Ptr;
69 
70  static Ptr&
72  {
73  static Ptr instance;
74  if (!instance)
75  {
76  boost::mutex::scoped_lock lock (mutex_);
77  if (!instance)
78  instance.reset (new DepthSenseDeviceManager);
79  }
80  return (instance);
81  }
82 
83  /** Get the number of connected DepthSense devices. */
84  inline size_t
86  {
87  return (context_.getDevices ().size ());
88  }
89 
90  /** Capture first available device and associate it with a given
91  * grabber instance. */
92  std::string
93  captureDevice (DepthSenseGrabberImpl* grabber);
94 
95  /** Capture the device with given index and associate it with a given
96  * grabber instance. */
97  std::string
98  captureDevice (DepthSenseGrabberImpl* grabber, size_t index);
99 
100  /** Capture the device with given serial number and associate it with
101  * a given grabber instance. */
102  std::string
103  captureDevice (DepthSenseGrabberImpl* grabber, const std::string& sn);
104 
105  /** Release DepthSense device with given serial number. */
106  void
107  releaseDevice (const std::string& sn);
108 
109  /** Reconfigure DepthSense device with given serial number. */
110  void
111  reconfigureDevice (const std::string& sn);
112 
113  /** Start data capturing for a given device. */
114  void
115  startDevice (const std::string& sn);
116 
117  /** Stop data capturing for a given device. */
118  void
119  stopDevice (const std::string& sn);
120 
122 
123  private:
124 
126 
127  std::string
128  captureDevice (DepthSenseGrabberImpl* grabber, DepthSense::Device device);
129 
130  inline bool
131  isCaptured (const std::string& sn) const
132  {
133  return (captured_devices_.count (sn) != 0);
134  }
135 
136  DepthSense::Context context_;
137 
138  static boost::mutex mutex_;
139 
140  /// Thread where the grabbing takes place.
141  boost::thread depth_sense_thread_;
142 
143  struct CapturedDevice
144  {
145  DepthSenseGrabberImpl* grabber;
146  DepthSense::DepthNode depth_node;
147  DepthSense::ColorNode color_node;
148  };
149 
150  std::map<std::string, CapturedDevice> captured_devices_;
151 
152  };
153 
154  } // namespace depth_sense
155 
156  } // namespace io
157 
158 } // namespace pcl
159 
160 #endif /* PCL_IO_DEPTH_SENSE_DEVICE_MANAGER_H */
161 
A helper class for enumerating and managing access to DepthSense devices.
boost::shared_ptr< DepthSenseDeviceManager > Ptr
size_t getNumDevices()
Get the number of connected DepthSense devices.