Point Cloud Library (PCL)  1.7.2
pxc_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 #define HAVE_PXCAPI
40 #ifdef HAVE_PXCAPI
41 
42 #ifndef __PCL_IO_PXC_GRABBER__
43 #define __PCL_IO_PXC_GRABBER__
44 
45 #include <pcl/io/eigen.h>
46 #include <pcl/io/boost.h>
47 #include <pcl/io/grabber.h>
48 #include <pcl/common/synchronizer.h>
49 
50 #include <boost/thread.hpp>
51 
52 #include "pxcsmartptr.h"
53 #include "pxcsession.h"
54 #include "util_capture.h"
55 #include "util_pipeline.h"
56 //#include "util_pipeline_raw.h"
57 #include "util_render.h"
58 #include <util_capture.h>
59 #include <pxcprojection.h>
60 #include <pxcmetadata.h>
61 
62 #include <string>
63 #include <deque>
64 
65 namespace pcl
66 {
67  struct PointXYZ;
68  struct PointXYZRGB;
69  struct PointXYZRGBA;
70  struct PointXYZI;
71  template <typename T> class PointCloud;
72 
73 
74  /** \brief Grabber for PXC devices
75  * \author Stefan Holzer <holzers@in.tum.de>
76  * \ingroup io
77  */
78  class PCL_EXPORTS PXCGrabber : public Grabber
79  {
80  public:
81 
82  /** \brief Supported modes for grabbing from a PXC device. */
83  typedef enum
84  {
85  PXC_Default_Mode = 0,
86  } Mode;
87 
88  //define callback signature typedefs
89  typedef void (sig_cb_pxc_point_cloud) (const boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZ> >&);
90  typedef void (sig_cb_pxc_point_cloud_rgb) (const boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZRGB> >&);
91  typedef void (sig_cb_pxc_point_cloud_rgba) (const boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZRGBA> >&);
92  typedef void (sig_cb_pxc_point_cloud_i) (const boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZI> >&);
93 
94  public:
95  /** \brief Constructor */
96  PXCGrabber ();
97 
98  /** \brief virtual Destructor inherited from the Grabber interface. It never throws. */
99  virtual ~PXCGrabber () throw ();
100 
101  /** \brief Start the data acquisition. */
102  virtual void
103  start ();
104 
105  /** \brief Stop the data acquisition. */
106  virtual void
107  stop ();
108 
109  /** \brief Check if the data acquisition is still running. */
110  virtual bool
111  isRunning () const;
112 
113  /** \brief Returns the name of the grabber. */
114  virtual std::string
115  getName () const;
116 
117  /** \brief Obtain the number of frames per second (FPS). */
118  virtual float
119  getFramesPerSecond () const;
120 
121  protected:
122 
123  /** \brief Initializes the PXC grabber and the grabbing pipeline. */
124  bool
125  init ();
126 
127  /** \brief Closes the grabbing pipeline. */
128  void
129  close ();
130 
131  /** \brief Continously asks for data from the device and publishes it if available. */
132  void
133  processGrabbing ();
134 
135  // signals to indicate whether new clouds are available
136  boost::signals2::signal<sig_cb_pxc_point_cloud>* point_cloud_signal_;
137  //boost::signals2::signal<sig_cb_fotonic_point_cloud_i>* point_cloud_i_signal_;
138  boost::signals2::signal<sig_cb_pxc_point_cloud_rgb>* point_cloud_rgb_signal_;
139  boost::signals2::signal<sig_cb_pxc_point_cloud_rgba>* point_cloud_rgba_signal_;
140 
141  protected:
142  // utiliy object for accessing PXC camera
143  UtilPipeline pp_;
144  // indicates whether grabbing is running
145  bool running_;
146 
147  // FPS computation
148  mutable float fps_;
149  mutable boost::mutex fps_mutex_;
150 
151  // thread where the grabbing takes place
152  boost::thread grabber_thread_;
153 
154  public:
155  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
156  };
157 
158 } // namespace pcl
159 #endif // __PCL_IO_PXC_GRABBER__
160 #endif // HAVE_PXCAPI
Grabber for PXC devices.
Definition: pxc_grabber.h:78
Grabber interface for PCL 1.x device drivers.
Definition: grabber.h:58