Point Cloud Library (PCL)  1.10.0-dev
stereo_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 #pragma once
39 
40 #include <pcl/common/time_trigger.h>
41 #include <pcl/conversions.h>
42 #include <pcl/io/grabber.h>
43 #include <pcl/point_cloud.h>
44 #include <pcl/stereo/stereo_matching.h>
45 
46 namespace pcl {
47 
48 /** \brief Base class for Stereo file grabber.
49  * \ingroup io
50  */
52 public:
53  /** \brief Constructor taking just one Stereo pair.
54  * \param[in] pair_files the name of the the stereo (left + right) images.
55  * \param[in] frames_per_second frames per second. If 0, start() functions like a
56  * trigger, publishing the next pair in the list.
57  * \param[in] repeat whether to play files in an endless loop or not.
58  */
59  StereoGrabberBase(const std::pair<std::string, std::string>& pair_files,
60  float frames_per_second,
61  bool repeat);
62 
63  /** \brief Constructor taking a list of paths to Stereo pair files, that are played in
64  * the order they appear in the list.
65  *
66  * \param[in] files vector of paths to stereo (left+right) images.
67  * \param[in] frames_per_second frames per second. If 0, start() functions like a
68  * trigger, publishing the next pair in the list.
69  * \param[in] repeat whether to play files in an endless loop or not.
70  */
71  StereoGrabberBase(const std::vector<std::pair<std::string, std::string>>& files,
72  float frames_per_second,
73  bool repeat);
74 
75  /** \brief Copy constructor.
76  * \param[in] src the Stereo Grabber base object to copy into this
77  */
78  StereoGrabberBase(const StereoGrabberBase& src) : impl_() { *this = src; }
79 
80  /** \brief Copy operator.
81  * \param[in] src the Stereo Grabber base object to copy into this
82  */
85  {
86  impl_ = src.impl_;
87  return (*this);
88  }
89 
90  /** \brief Virtual destructor. */
91  ~StereoGrabberBase() noexcept;
92 
93  /** \brief Starts playing the list of Stereo images if frames_per_second is > 0.
94  * Otherwise it works as a trigger: publishes only the next pair in the list. */
95  void
96  start() override;
97 
98  /** \brief Stops playing the list of Stereo images if frames_per_second is > 0.
99  * Otherwise the method has no effect. */
100  void
101  stop() override;
102 
103  /** \brief Triggers a callback with new data */
104  virtual void
105  trigger();
106 
107  /** \brief whether the grabber is started (publishing) or not.
108  * \return true only if publishing.
109  */
110  bool
111  isRunning() const override;
112 
113  /** \return The name of the grabber */
114  std::string
115  getName() const override;
116 
117  /** \brief Rewinds to the first pair of files in the list.*/
118  virtual void
119  rewind();
120 
121  /** \brief Returns the frames_per_second. 0 if grabber is trigger-based */
122  float
123  getFramesPerSecond() const override;
124 
125  /** \brief Returns whether the repeat flag is on */
126  bool
127  isRepeatOn() const;
128 
129 private:
130  virtual void
131  publish(const pcl::PCLPointCloud2& blob,
132  const Eigen::Vector4f& origin,
133  const Eigen::Quaternionf& orientation) const = 0;
134 
135  // to separate and hide the implementation from interface: PIMPL
136  struct StereoGrabberImpl;
137  StereoGrabberImpl* impl_;
138 };
139 
140 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
141 template <typename PointT>
143 public:
144  StereoGrabber(const std::pair<std::string, std::string>& pair_files,
145  float frames_per_second = 0,
146  bool repeat = false);
147  StereoGrabber(const std::vector<std::pair<std::string, std::string>>& files,
148  float frames_per_second = 0,
149  bool repeat = false);
150 
151 protected:
152  void
153  publish(const pcl::PCLPointCloud2& blob,
154  const Eigen::Vector4f& origin,
155  const Eigen::Quaternionf& orientation) const override;
156 
157  boost::signals2::signal<void(const typename pcl::PointCloud<PointT>::ConstPtr&)>*
158  signal_;
159 };
160 
161 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
162 template <typename PointT>
164  const std::pair<std::string, std::string>& pair_files,
165  float frames_per_second,
166  bool repeat)
167 : StereoGrabberBase(pair_files, frames_per_second, repeat)
168 {
169  signal_ = createSignal<void(const typename pcl::PointCloud<PointT>::ConstPtr&)>();
170 }
171 
172 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
173 template <typename PointT>
175  const std::vector<std::pair<std::string, std::string>>& files,
176  float frames_per_second,
177  bool repeat)
178 : StereoGrabberBase(files, frames_per_second, repeat), signal_()
179 {
180  signal_ = createSignal<void(const typename pcl::PointCloud<PointT>::ConstPTr&)>();
181 }
182 
183 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
184 template <typename PointT>
185 void
187  const Eigen::Vector4f& origin,
188  const Eigen::Quaternionf& orientation) const
189 {
191  pcl::fromPCLPointCloud2(blob, *cloud);
192  cloud->sensor_origin_ = origin;
193  cloud->sensor_orientation_ = orientation;
194 
195  signal_->operator()(cloud);
196 }
197 
198 } // namespace pcl
void fromPCLPointCloud2(const pcl::PCLPointCloud2 &msg, pcl::PointCloud< PointT > &cloud, const MsgFieldMap &field_map)
Convert a PCLPointCloud2 binary data blob into a pcl::PointCloud<T> object using a field_map...
Definition: conversions.h:168
StereoGrabber(const std::pair< std::string, std::string > &pair_files, float frames_per_second=0, bool repeat=false)
void publish(const pcl::PCLPointCloud2 &blob, const Eigen::Vector4f &origin, const Eigen::Quaternionf &orientation) const override
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:415
StereoGrabberBase(const StereoGrabberBase &src)
Copy constructor.
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
Grabber interface for PCL 1.x device drivers.
Definition: grabber.h:57
boost::signals2::signal< void(const typename pcl::PointCloud< PointT >::ConstPtr &)> * signal_
Eigen::Vector4f sensor_origin_
Sensor acquisition pose (origin/translation).
Definition: point_cloud.h:408
StereoGrabberBase & operator=(const StereoGrabberBase &src)
Copy operator.
Eigen::Quaternionf sensor_orientation_
Sensor acquisition pose (rotation).
Definition: point_cloud.h:410
PointCloud represents the base class in PCL for storing collections of 3D points. ...
Base class for Stereo file grabber.
#define PCL_EXPORTS
Definition: pcl_macros.h:253