40 #include <pcl/pcl_config.h>
42 #include <pcl/common/io.h>
43 #include <pcl/io/grabber.h>
44 #include <pcl/io/file_grabber.h>
45 #include <pcl/common/time_trigger.h>
46 #include <pcl/conversions.h>
50 #include <pcl/io/openni_camera/openni_image.h>
51 #include <pcl/io/openni_camera/openni_image_rgb24.h>
52 #include <pcl/io/openni_camera/openni_depth_image.h>
72 PCDGrabberBase (
const std::string& pcd_file,
float frames_per_second,
bool repeat);
79 PCDGrabberBase (
const std::vector<std::string>& pcd_files,
float frames_per_second,
bool repeat);
100 isRunning () const override;
104 getName () const override;
112 getFramesPerSecond () const override;
120 getCloudAt (std::
size_t idx,
122 Eigen::Vector4f &origin,
123 Eigen::Quaternionf &orientation) const;
131 publish (const
pcl::
PCLPointCloud2& blob, const
Eigen::Vector4f& origin, const
Eigen::Quaternionf& orientation, const std::
string& file_name) const = 0;
134 struct PCDGrabberImpl;
135 PCDGrabberImpl* impl_;
143 using Ptr = shared_ptr<PCDGrabber>;
146 PCDGrabber (
const std::string& pcd_path,
float frames_per_second = 0,
bool repeat =
false);
147 PCDGrabber (
const std::vector<std::string>& pcd_files,
float frames_per_second = 0,
bool repeat =
false);
157 operator[] (std::size_t idx)
const override;
161 size ()
const override;
165 publish (
const pcl::PCLPointCloud2& blob,
const Eigen::Vector4f& origin,
const Eigen::Quaternionf& orientation,
const std::string& file_name)
const override;
178 template<
typename Po
intT>
186 image_signal_ = createSignal <void (const openni_wrapper::Image::Ptr&)> ();
187 image_depth_image_signal_ = createSignal <void (const openni_wrapper::Image::Ptr&, const openni_wrapper::DepthImage::Ptr&, float constant)> ();
192 template<
typename Po
intT>
194 :
PCDGrabberBase (pcd_files, frames_per_second, repeat), signal_ ()
200 image_signal_ = createSignal <void (const openni_wrapper::Image::Ptr&)> ();
201 image_depth_image_signal_ = createSignal <void (const openni_wrapper::Image::Ptr&, const openni_wrapper::DepthImage::Ptr&, float constant)> ();
210 Eigen::Vector4f origin;
211 Eigen::Quaternionf orientation;
212 getCloudAt (idx, blob, origin, orientation);
221 template <
typename Po
intT> std::size_t
224 return (numFrames ());
228 template<
typename Po
intT>
void
236 signal_->operator () (cloud);
237 if (file_name_signal_->num_slots() > 0)
238 file_name_signal_->operator()(file_name);
245 shared_ptr<xn::DepthMetaData> depth_meta_data (
new xn::DepthMetaData);
246 depth_meta_data->AllocateData (cloud->
width, cloud->
height);
247 XnDepthPixel* depth_map = depth_meta_data->WritableData ();
249 for (std::uint32_t i = 0; i < cloud->
height; ++i)
250 for (std::uint32_t j = 0; j < cloud->
width; ++j)
252 depth_map[k] =
static_cast<XnDepthPixel
> ((*cloud)[k].z * 1000);
257 if (depth_image_signal_->num_slots() > 0)
258 depth_image_signal_->operator()(depth_image);
261 std::vector<pcl::PCLPointField> fields;
262 int rgba_index = pcl::getFieldIndex<PointT> (
"rgb", fields);
263 if (rgba_index == -1)
264 rgba_index = pcl::getFieldIndex<PointT> (
"rgba", fields);
267 rgba_index = fields[rgba_index].offset;
269 shared_ptr<xn::ImageMetaData> image_meta_data (
new xn::ImageMetaData);
270 image_meta_data->AllocateData (cloud->
width, cloud->
height, XN_PIXEL_FORMAT_RGB24);
271 XnRGB24Pixel* image_map = image_meta_data->WritableRGB24Data ();
273 for (std::uint32_t i = 0; i < cloud->
height; ++i)
275 for (std::uint32_t j = 0; j < cloud->
width; ++j)
279 memcpy (&rgb,
reinterpret_cast<const char*
> (&(*cloud)[k]) + rgba_index,
sizeof (
RGB));
280 image_map[k].nRed =
static_cast<XnUInt8
> (rgb.r);
281 image_map[k].nGreen =
static_cast<XnUInt8
> (rgb.g);
282 image_map[k].nBlue =
static_cast<XnUInt8
> (rgb.b);
288 if (image_signal_->num_slots() > 0)
289 image_signal_->operator()(image);
291 if (image_depth_image_signal_->num_slots() > 0)
292 image_depth_image_signal_->operator()(image, depth_image, 1.0f / 525.0f);
This class provides methods to fill a depth or disparity image.
pcl::shared_ptr< DepthImage > Ptr
pcl::shared_ptr< Image > Ptr
This class provides methods to fill a RGB or Grayscale image buffer from underlying RGB24 image.
FileGrabber provides a container-style interface for grabbers which operate on fixed-size input.
Grabber interface for PCL 1.x device drivers.
boost::signals2::signal< T > * createSignal()
Base class for PCD file grabber.
PCDGrabberBase(const std::string &pcd_file, float frames_per_second, bool repeat)
Constructor taking just one PCD file or one TAR file containing multiple PCD files.
~PCDGrabberBase() noexcept override
Virtual destructor.
PCDGrabberBase(const std::vector< std::string > &pcd_files, float frames_per_second, bool repeat)
Constructor taking a list of paths to PCD files, that are played in the order they appear in the list...
shared_ptr< PCDGrabber > Ptr
boost::signals2::signal< void(const std::string &)> * file_name_signal_
boost::signals2::signal< void(const openni_wrapper::Image::Ptr &, const openni_wrapper::DepthImage::Ptr &, float constant)> * image_depth_image_signal_
boost::signals2::signal< void(const openni_wrapper::Image::Ptr &)> * image_signal_
const pcl::PointCloud< PointT >::ConstPtr operator[](std::size_t idx) const override
operator[] Returns the idx-th cloud in the dataset, without bounds checking.
boost::signals2::signal< void(const openni_wrapper::DepthImage::Ptr &)> * depth_image_signal_
PCDGrabber(const std::string &pcd_path, float frames_per_second=0, bool repeat=false)
void publish(const pcl::PCLPointCloud2 &blob, const Eigen::Vector4f &origin, const Eigen::Quaternionf &orientation, const std::string &file_name) const override
boost::signals2::signal< void(const typename pcl::PointCloud< PointT >::ConstPtr &)> * signal_
~PCDGrabber() noexcept override
Virtual destructor.
std::size_t size() const override
size Returns the number of clouds currently loaded by the grabber
shared_ptr< const PCDGrabber > ConstPtr
PointCloud represents the base class in PCL for storing collections of 3D points.
Eigen::Quaternionf sensor_orientation_
Sensor acquisition pose (rotation).
std::uint32_t width
The point cloud width (if organized as an image-structure).
bool isOrganized() const
Return whether a dataset is organized (e.g., arranged in a structured grid).
std::uint32_t height
The point cloud height (if organized as an image-structure).
Eigen::Vector4f sensor_origin_
Sensor acquisition pose (origin/translation).
shared_ptr< PointCloud< PointT > > Ptr
shared_ptr< const PointCloud< PointT > > ConstPtr
Defines all the PCL implemented PointT point type structures.
Defines functions, macros and traits for allocating and using memory.
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.
A structure representing RGB color information.