38 #include <pcl/pcl_config.h>
40 #ifndef PCL_IO_PCD_GRABBER_H_
41 #define PCL_IO_PCD_GRABBER_H_
43 #include <pcl/common/io.h>
44 #include <pcl/io/grabber.h>
45 #include <pcl/io/file_grabber.h>
46 #include <pcl/common/time_trigger.h>
49 #include <pcl/conversions.h>
52 #include <pcl/io/openni_camera/openni_image.h>
53 #include <pcl/io/openni_camera/openni_image_rgb24.h>
54 #include <pcl/io/openni_camera/openni_depth_image.h>
70 PCDGrabberBase (
const std::string& pcd_file,
float frames_per_second,
bool repeat);
77 PCDGrabberBase (
const std::vector<std::string>& pcd_files,
float frames_per_second,
bool repeat);
128 getFramesPerSecond () const;
136 getCloudAt (
size_t idx,
138 Eigen::Vector4f &origin,
139 Eigen::Quaternionf &orientation) const;
147 publish (const
pcl::
PCLPointCloud2& blob, const
Eigen::Vector4f& origin, const
Eigen::Quaternionf& orientation, const
std::
string& file_name) const = 0;
150 struct PCDGrabberImpl;
151 PCDGrabberImpl* impl_;
159 PCDGrabber (
const std::string& pcd_path,
float frames_per_second = 0,
bool repeat =
false);
160 PCDGrabber (
const std::vector<std::string>& pcd_files,
float frames_per_second = 0,
bool repeat =
false);
169 const boost::shared_ptr< const pcl::PointCloud<PointT> >
170 operator[] (
size_t idx)
const;
178 publish (
const pcl::PCLPointCloud2& blob,
const Eigen::Vector4f& origin,
const Eigen::Quaternionf& orientation,
const std::string& file_name)
const;
184 boost::signals2::signal<void (
const boost::shared_ptr<openni_wrapper::DepthImage>&)>*
depth_image_signal_;
185 boost::signals2::signal<void (
const boost::shared_ptr<openni_wrapper::Image>&)>*
image_signal_;
186 boost::signals2::signal<void (
const boost::shared_ptr<openni_wrapper::Image>&,
const boost::shared_ptr<openni_wrapper::DepthImage>&,
float constant)>*
image_depth_image_signal_;
191 template<
typename Po
intT>
205 template<
typename Po
intT>
207 :
PCDGrabberBase (pcd_files, frames_per_second, repeat), signal_ ()
219 template<
typename Po
intT>
const boost::shared_ptr< const pcl::PointCloud<PointT> >
223 Eigen::Vector4f origin;
224 Eigen::Quaternionf orientation;
225 getCloudAt (idx, blob, origin, orientation);
234 template <
typename Po
intT>
size_t
237 return (numFrames ());
241 template<
typename Po
intT>
void
249 signal_->operator () (cloud);
250 if (file_name_signal_->num_slots() > 0)
251 file_name_signal_->operator()(file_name);
258 boost::shared_ptr<xn::DepthMetaData> depth_meta_data (
new xn::DepthMetaData);
259 depth_meta_data->AllocateData (cloud->
width, cloud->
height);
260 XnDepthPixel* depth_map = depth_meta_data->WritableData ();
262 for (uint32_t i = 0; i < cloud->
height; ++i)
263 for (uint32_t j = 0; j < cloud->
width; ++j)
265 depth_map[k] =
static_cast<XnDepthPixel
> ((*cloud)[k].z * 1000);
269 boost::shared_ptr<openni_wrapper::DepthImage> depth_image (
new openni_wrapper::DepthImage (depth_meta_data, 0.075f, 525, 0, 0));
270 if (depth_image_signal_->num_slots() > 0)
271 depth_image_signal_->operator()(depth_image);
274 std::vector<pcl::PCLPointField> fields;
276 if (rgba_index == -1)
280 rgba_index = fields[rgba_index].offset;
282 boost::shared_ptr<xn::ImageMetaData> image_meta_data (
new xn::ImageMetaData);
283 image_meta_data->AllocateData (cloud->
width, cloud->
height, XN_PIXEL_FORMAT_RGB24);
284 XnRGB24Pixel* image_map = image_meta_data->WritableRGB24Data ();
286 for (uint32_t i = 0; i < cloud->
height; ++i)
288 for (uint32_t j = 0; j < cloud->
width; ++j)
292 memcpy (&rgb,
reinterpret_cast<const char*
> (&cloud->
points[k]) + rgba_index, sizeof (
RGB));
293 image_map[k].nRed =
static_cast<XnUInt8
> (rgb.r);
294 image_map[k].nGreen =
static_cast<XnUInt8
> (rgb.g);
295 image_map[k].nBlue =
static_cast<XnUInt8
> (rgb.b);
301 if (image_signal_->num_slots() > 0)
302 image_signal_->operator()(image);
304 if (image_depth_image_signal_->num_slots() > 0)
305 image_depth_image_signal_->operator()(image, depth_image, 1.0f / 525.0f);