Point Cloud Library (PCL) 1.15.0
Loading...
Searching...
No Matches
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/io/grabber.h>
42#include <pcl/stereo/stereo_matching.h>
43#include <pcl/conversions.h>
44#include <pcl/point_cloud.h>
45
46namespace pcl {
47
48/** \brief Base class for Stereo file grabber.
49 * \ingroup io
50 */
51class PCL_EXPORTS StereoGrabberBase : public Grabber {
52public:
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 Virtual destructor. */
76 ~StereoGrabberBase() noexcept override;
77
78 /** \brief Starts playing the list of Stereo images if frames_per_second is > 0.
79 * Otherwise it works as a trigger: publishes only the next pair in the list. */
80 void
81 start() override;
82
83 /** \brief Stops playing the list of Stereo images if frames_per_second is > 0.
84 * Otherwise the method has no effect. */
85 void
86 stop() override;
87
88 /** \brief Triggers a callback with new data */
89 virtual void
90 trigger();
91
92 /** \brief whether the grabber is started (publishing) or not.
93 * \return true only if publishing.
94 */
95 bool
96 isRunning() const override;
97
98 /** \return The name of the grabber */
99 std::string
100 getName() const override;
101
102 /** \brief Rewinds to the first pair of files in the list.*/
103 virtual void
104 rewind();
105
106 /** \brief Returns the frames_per_second. 0 if grabber is trigger-based */
107 float
108 getFramesPerSecond() const override;
109
110 /** \brief Returns whether the repeat flag is on */
111 bool
112 isRepeatOn() const;
113
114private:
115 virtual void
116 publish(const pcl::PCLPointCloud2& blob,
117 const Eigen::Vector4f& origin,
118 const Eigen::Quaternionf& orientation) const = 0;
119
120 // to separate and hide the implementation from interface: PIMPL
121 struct StereoGrabberImpl;
122 StereoGrabberImpl* impl_;
123};
124
125////////////////////////////////////////////////////////////////////////////////////////////////////////////////
126template <typename PointT>
128public:
129 StereoGrabber(const std::pair<std::string, std::string>& pair_files,
130 float frames_per_second = 0,
131 bool repeat = false);
132 StereoGrabber(const std::vector<std::pair<std::string, std::string>>& files,
133 float frames_per_second = 0,
134 bool repeat = false);
135
136protected:
137 void
138 publish(const pcl::PCLPointCloud2& blob,
139 const Eigen::Vector4f& origin,
140 const Eigen::Quaternionf& orientation) const override;
141
142 boost::signals2::signal<void(const typename pcl::PointCloud<PointT>::ConstPtr&)>*
144};
145
146////////////////////////////////////////////////////////////////////////////////////////////////////////////////
147template <typename PointT>
149 const std::pair<std::string, std::string>& pair_files,
150 float frames_per_second,
151 bool repeat)
152: StereoGrabberBase(pair_files, frames_per_second, repeat)
153{
154 signal_ = createSignal<void(const typename pcl::PointCloud<PointT>::ConstPtr&)>();
155}
156
157////////////////////////////////////////////////////////////////////////////////////////////////////////////////
158template <typename PointT>
160 const std::vector<std::pair<std::string, std::string>>& files,
161 float frames_per_second,
162 bool repeat)
163: StereoGrabberBase(files, frames_per_second, repeat), signal_()
164{
165 signal_ = createSignal<void(const typename pcl::PointCloud<PointT>::ConstPTr&)>();
166}
167
168////////////////////////////////////////////////////////////////////////////////////////////////////////////////
169template <typename PointT>
170void
172 const Eigen::Vector4f& origin,
173 const Eigen::Quaternionf& orientation) const
174{
176 pcl::fromPCLPointCloud2(blob, *cloud);
177 cloud->sensor_origin_ = origin;
178 cloud->sensor_orientation_ = orientation;
179
180 signal_->operator()(cloud);
181}
182
183} // namespace pcl
Grabber interface for PCL 1.x device drivers.
Definition grabber.h:60
boost::signals2::signal< T > * createSignal()
Definition grabber.h:252
PointCloud represents the base class in PCL for storing collections of 3D points.
Eigen::Quaternionf sensor_orientation_
Sensor acquisition pose (rotation).
Eigen::Vector4f sensor_origin_
Sensor acquisition pose (origin/translation).
shared_ptr< PointCloud< PointT > > Ptr
shared_ptr< const PointCloud< PointT > > ConstPtr
Base class for Stereo file grabber.
StereoGrabberBase(const std::vector< std::pair< std::string, std::string > > &files, float frames_per_second, bool repeat)
Constructor taking a list of paths to Stereo pair files, that are played in the order they appear in ...
~StereoGrabberBase() noexcept override
Virtual destructor.
StereoGrabberBase(const std::pair< std::string, std::string > &pair_files, float frames_per_second, bool repeat)
Constructor taking just one Stereo pair.
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
boost::signals2::signal< void(const typename pcl::PointCloud< PointT >::ConstPtr &)> * signal_
Definition bfgs.h:10
void fromPCLPointCloud2(const pcl::PCLPointCloud2 &msg, pcl::PointCloud< PointT > &cloud, const MsgFieldMap &field_map, const std::uint8_t *msg_data)
Convert a PCLPointCloud2 binary data blob into a pcl::PointCloud<T> object using a field_map.
A point structure representing Euclidean xyz coordinates, and the RGB color.