10 #include <pcl/io/pcd_io.h> 11 #include <pcl/point_types.h> 12 #include <pcl/surface/mls.h> 14 #include "hrpsys/idl/pointcloud.hh" 18 static const char*
spec[] =
20 "implementation_id",
"OpenNIGrabber",
21 "type_name",
"OpenNIGrabber",
22 "description",
"OpenNI grabber",
23 "version", HRPSYS_PACKAGE_VERSION,
25 "category",
"example",
26 "activity_type",
"DataFlowComponent",
29 "lang_type",
"compile",
31 "conf.default.outputColorImage",
"0",
32 "conf.default.outputDepthImage",
"0",
33 "conf.default.outputPointCloud",
"0",
34 "conf.default.outputPointCloudRGBA",
"0",
35 "conf.default.debugLevel",
"0",
44 m_cloudOut(
"cloud", m_cloud),
45 m_imageOut(
"image", m_image),
46 m_depthOut(
"depth", m_depth),
49 m_requestToWriteImage(false),
50 m_requestToWritePointCloud(false),
63 std::cout <<
m_profile.instance_name <<
": onInitialize()" << std::endl;
110 Img::ImageData &
id =
m_image.data.image;
111 id.width = image->getWidth();
112 id.height = image->getHeight();
113 id.format = Img::CF_RGB;
116 unsigned char *dst = (
unsigned char*)
id.raw_data.get_buffer();
117 unsigned char *src = (
unsigned char*)image->getData();
118 memcpy(dst, src,
id.raw_data.length());
136 Img::ImageData &
id =
m_depth.data.image;
137 id.width = image->getWidth();
138 id.height = image->getHeight();
139 id.format = Img::CF_DEPTH;
142 unsigned char *dst = (
unsigned char*)
id.raw_data.get_buffer();
143 unsigned char *src = (
unsigned char*)image->getData();
144 memcpy(dst, src,
id.raw_data.length());
166 m_cloud.height = cloud->height;
170 float *dst_cloud = (
float *)
m_cloud.data.get_buffer();
171 for (
unsigned int i=0;
i<cloud->points.size();
i++){
172 dst_cloud[0] = cloud->points[
i].x;
173 dst_cloud[1] = -cloud->points[
i].y;
174 dst_cloud[2] = -cloud->points[
i].z;
175 unsigned char *rgb = (
unsigned char *)(dst_cloud+3);
176 rgb[0] = cloud->points[
i].r;
177 rgb[1] = cloud->points[
i].g;
178 rgb[2] = cloud->points[
i].b;
191 m_cloud.height = cloud->height;
195 float *dst_cloud = (
float *)
m_cloud.data.get_buffer();
196 for (
unsigned int i=0;
i<cloud->points.size();
i++){
197 dst_cloud[0] = cloud->points[
i].x;
198 dst_cloud[1] = -cloud->points[
i].y;
199 dst_cloud[2] = -cloud->points[
i].z;
229 std::cout <<
m_profile.instance_name<<
": onActivated(" << ec_id <<
")" << std::endl;
249 m_cloud.fields[0].data_type = PointCloudTypes::FLOAT32;
253 m_cloud.fields[1].data_type = PointCloudTypes::FLOAT32;
257 m_cloud.fields[2].data_type = PointCloudTypes::FLOAT32;
269 m_cloud.fields[0].data_type = PointCloudTypes::FLOAT32;
273 m_cloud.fields[1].data_type = PointCloudTypes::FLOAT32;
277 m_cloud.fields[2].data_type = PointCloudTypes::FLOAT32;
281 m_cloud.fields[3].data_type = PointCloudTypes::UINT8;
285 m_cloud.fields[4].data_type = PointCloudTypes::UINT8;
289 m_cloud.fields[5].data_type = PointCloudTypes::UINT8;
299 }
catch(pcl::IOException& ex){
300 std::cerr <<
"[" <<
m_profile.instance_name <<
"] Error: " << ex.what() << std::endl;
301 return RTC::RTC_ERROR;
303 std::cerr <<
"[" <<
m_profile.instance_name
304 <<
"] Error: An exception occurred while starting grabber" << std::endl;
305 return RTC::RTC_ERROR;
313 std::cout <<
m_profile.instance_name<<
": onDeactivated(" << ec_id <<
")" << std::endl;
329 std::cerr <<
"[" <<
m_profile.instance_name
330 <<
"] grabber is running. frame rate=" <<
m_interface->getFramesPerSecond() << std::endl;
332 std::cerr <<
"[" <<
m_profile.instance_name
333 <<
"] grabber is not running" << std::endl;
386 RTC::Create<OpenNIGrabber>,
387 RTC::Delete<OpenNIGrabber>);
ComponentProfile m_profile
png_infop png_charpp int png_charpp profile
OutPort< Img::TimedCameraImage > m_depthOut
OutPort< PointCloudTypes::PointCloud > m_cloudOut
virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id)
OpenNIGrabber(RTC::Manager *manager)
Constructor.
static const char * spec[]
bool m_outputPointCloudRGBA
void grabberCallbackPointCloudRGBA(const pcl::PointCloud< pcl::PointXYZRGBA >::ConstPtr &cloud)
void outputDepthImage(const boost::shared_ptr< pcl::io::DepthImage > &image)
void outputColorImage(const boost::shared_ptr< pcl::io::Image > &image)
void grabberCallbackColorAndDepthImage(const boost::shared_ptr< pcl::io::Image > &image, const boost::shared_ptr< pcl::io::DepthImage > &depth, float reciprocalFocalLength)
coil::Properties & getProperties()
void grabberCallbackColorImage(const boost::shared_ptr< pcl::io::Image > &image)
Img::TimedCameraImage m_depth
pcl::Grabber * m_interface
bool addOutPort(const char *name, OutPortBase &outport)
png_infop png_uint_32 * width
virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id)
virtual RTC::ReturnCode_t onInitialize()
ExecutionContextHandle_t UniqueId
png_infop png_uint_32 png_uint_32 * height
bool m_requestToWritePointCloud
bool bindParameter(const char *param_name, VarType &var, const char *def_val, bool(*trans)(VarType &, const char *)=coil::stringTo)
void grabberCallbackDepthImage(const boost::shared_ptr< pcl::io::DepthImage > &image)
virtual ~OpenNIGrabber()
Destructor.
void setTimestamp(DataType &data)
virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id)
OutPort< Img::TimedCameraImage > m_imageOut
void grabberCallbackPointCloud(const pcl::PointCloud< pcl::PointXYZ >::ConstPtr &cloud)
virtual bool write(DataType &value)
bool m_requestToWriteImage
Moving Least Squares Filter.
Img::TimedCameraImage m_image
bool registerFactory(coil::Properties &profile, RtcNewFunc new_func, RtcDeleteFunc delete_func)
void OpenNIGrabberInit(RTC::Manager *manager)
PointCloudTypes::PointCloud m_cloud