Point Cloud Library (PCL)  1.8.1
fotonic_grabber.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2012-, 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 #include <pcl/pcl_config.h>
39 #ifdef HAVE_FZAPI
40 
41 #ifndef __PCL_IO_FOTONIC_GRABBER__
42 #define __PCL_IO_FOTONIC_GRABBER__
43 
44 #include <pcl/io/eigen.h>
45 #include <pcl/io/boost.h>
46 #include <pcl/io/grabber.h>
47 #include <pcl/common/synchronizer.h>
48 
49 #include <boost/thread.hpp>
50 
51 #include <fz_api.h>
52 
53 #include <string>
54 #include <deque>
55 
56 namespace pcl
57 {
58  struct PointXYZ;
59  struct PointXYZRGB;
60  struct PointXYZRGBA;
61  struct PointXYZI;
62  template <typename T> class PointCloud;
63 
64 
65  /** \brief Grabber for Fotonic devices
66  * \author Stefan Holzer <holzers@in.tum.de>
67  * \ingroup io
68  */
69  class PCL_EXPORTS FotonicGrabber : public Grabber
70  {
71  public:
72 
73  typedef enum
74  {
75  Fotonic_Default_Mode = 0, // This can depend on the device. For now all devices (PSDK, Xtion, Kinect) its VGA@30Hz
76  } Mode;
77 
78  //define callback signature typedefs
79  typedef void (sig_cb_fotonic_point_cloud) (const boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZ> >&);
80  typedef void (sig_cb_fotonic_point_cloud_rgb) (const boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZRGB> >&);
81  typedef void (sig_cb_fotonic_point_cloud_rgba) (const boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZRGBA> >&);
82  typedef void (sig_cb_fotonic_point_cloud_i) (const boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZI> >&);
83 
84  public:
85  /** \brief Constructor
86  * \param[in] device_id ID of the device, which might be a serial number, bus@address or the index of the device.
87  * \param[in] depth_mode the mode of the depth stream
88  * \param[in] image_mode the mode of the image stream
89  */
90  FotonicGrabber (const FZ_DEVICE_INFO& device_info,
91  const Mode& depth_mode = Fotonic_Default_Mode,
92  const Mode& image_mode = Fotonic_Default_Mode);
93 
94  /** \brief virtual Destructor inherited from the Grabber interface. It never throws. */
95  virtual ~FotonicGrabber () throw ();
96 
97  /** \brief Initializes the Fotonic API. */
98  static void
99  initAPI ();
100 
101  /** \brief Exits the Fotonic API. */
102  static void
103  exitAPI ();
104 
105  /** \brief Searches for available devices. */
106  static std::vector<FZ_DEVICE_INFO>
107  enumDevices ();
108 
109  /** \brief Start the data acquisition. */
110  virtual void
111  start ();
112 
113  /** \brief Stop the data acquisition. */
114  virtual void
115  stop ();
116 
117  /** \brief Check if the data acquisition is still running. */
118  virtual bool
119  isRunning () const;
120 
121  virtual std::string
122  getName () const;
123 
124  /** \brief Obtain the number of frames per second (FPS). */
125  virtual float
126  getFramesPerSecond () const;
127 
128  protected:
129 
130  /** \brief On initialization processing. */
131  void
132  onInit (const FZ_DEVICE_INFO& device_info, const Mode& depth_mode, const Mode& image_mode);
133 
134  /** \brief Sets up an OpenNI device. */
135  void
136  setupDevice (const FZ_DEVICE_INFO& device_info, const Mode& depth_mode, const Mode& image_mode);
137 
138  /** \brief Continously asks for data from the device and publishes it if available. */
139  void
140  processGrabbing ();
141 
142  boost::signals2::signal<sig_cb_fotonic_point_cloud>* point_cloud_signal_;
143  //boost::signals2::signal<sig_cb_fotonic_point_cloud_i>* point_cloud_i_signal_;
144  boost::signals2::signal<sig_cb_fotonic_point_cloud_rgb>* point_cloud_rgb_signal_;
145  boost::signals2::signal<sig_cb_fotonic_point_cloud_rgba>* point_cloud_rgba_signal_;
146 
147  protected:
148  bool running_;
149 
150  FZ_Device_Handle_t * fotonic_device_handle_;
151 
152  boost::thread grabber_thread_;
153 
154  public:
155  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
156  };
157 
158 } // namespace pcl
159 #endif // __PCL_IO_FOTONIC_GRABBER__
160 #endif // HAVE_FOTONIC
float4 PointXYZRGB
Definition: internal.hpp:60
PointCloud represents the base class in PCL for storing collections of 3D points.