10 #include <pcl/point_types.h> 11 #include <pcl/filters/statistical_outlier_removal.h> 13 #include "hrpsys/idl/pointcloud.hh" 17 static const char*
spec[] =
19 "implementation_id",
"PCDLoader",
20 "type_name",
"PCDLoader",
21 "description",
"PCD file loader",
22 "version", HRPSYS_PACKAGE_VERSION,
24 "category",
"example",
25 "activity_type",
"DataFlowComponent",
28 "lang_type",
"compile",
30 "conf.default.path",
"",
31 "conf.default.fields",
"XYZ",
40 m_offsetIn(
"offset", m_offset),
41 m_isOutputOut(
"isOutput", m_isOutput),
42 m_cloudOut(
"cloud", m_cloud),
44 m_PCDLoaderServicePort(
"PCDLoaderService"),
93 int npoint = cloud_raw->points.size();
96 cloud.fields.length(3);
97 cloud.fields[0].name =
"x";
98 cloud.fields[0].offset = 0;
99 cloud.fields[0].data_type = PointCloudTypes::FLOAT32;
100 cloud.fields[0].count = 4;
101 cloud.fields[1].name =
"y";
102 cloud.fields[1].offset = 4;
103 cloud.fields[1].data_type = PointCloudTypes::FLOAT32;
104 cloud.fields[1].count = 4;
105 cloud.fields[2].name =
"z";
106 cloud.fields[2].offset = 8;
107 cloud.fields[2].data_type = PointCloudTypes::FLOAT32;
108 cloud.fields[2].count = 4;
109 cloud.is_bigendian =
false;
110 cloud.point_step = 16;
111 cloud.width = cloud_raw->width;
112 cloud.height = cloud_raw->height;
113 cloud.data.length(npoint*cloud.point_step);
114 cloud.row_step = cloud.width*cloud.point_step;
115 cloud.is_dense = cloud_raw->is_dense;
116 float *
ptr = (
float *)cloud.data.get_buffer();
117 std::cout <<
"npoint = " << npoint << std::endl;
118 for (
int i=0;
i<npoint;
i++){
119 ptr[0] = cloud_raw->points[
i].x;
120 ptr[1] = cloud_raw->points[
i].y;
121 ptr[2] = cloud_raw->points[
i].z;
128 int npoint = cloud_raw->points.size();
130 cloud.type =
"xyzrgb";
131 cloud.fields.length(6);
132 cloud.fields[0].name =
"x";
133 cloud.fields[0].offset = 0;
134 cloud.fields[0].data_type = PointCloudTypes::FLOAT32;
135 cloud.fields[0].count = 4;
136 cloud.fields[1].name =
"y";
137 cloud.fields[1].offset = 4;
138 cloud.fields[1].data_type = PointCloudTypes::FLOAT32;
139 cloud.fields[1].count = 4;
140 cloud.fields[2].name =
"z";
141 cloud.fields[2].offset = 8;
142 cloud.fields[2].data_type = PointCloudTypes::FLOAT32;
143 cloud.fields[2].count = 4;
144 cloud.fields[3].name =
"r";
145 cloud.fields[3].offset = 12;
146 cloud.fields[3].data_type = PointCloudTypes::UINT8;
147 cloud.fields[3].count = 1;
148 cloud.fields[4].name =
"g";
149 cloud.fields[4].offset = 13;
150 cloud.fields[4].data_type = PointCloudTypes::UINT8;
151 cloud.fields[4].count = 1;
152 cloud.fields[5].name =
"b";
153 cloud.fields[5].offset = 14;
154 cloud.fields[5].data_type = PointCloudTypes::UINT8;
155 cloud.fields[5].count = 1;
156 cloud.is_bigendian =
false;
157 cloud.point_step = 16;
158 cloud.width = cloud_raw->width;
159 cloud.height = cloud_raw->height;
160 cloud.data.length(npoint*cloud.point_step);
161 cloud.row_step = cloud.width*cloud.point_step;
162 cloud.is_dense = cloud_raw->is_dense;
163 float *
ptr = (
float *)cloud.data.get_buffer();
164 std::cout <<
"npoint = " << npoint << std::endl;
165 for (
int i=0;
i<npoint;
i++){
166 ptr[0] = cloud_raw->points[
i].x;
167 ptr[1] = cloud_raw->points[
i].y;
168 ptr[2] = cloud_raw->points[
i].z;
169 unsigned char *rgb = (
unsigned char *)(ptr+3);
170 rgb[0] = cloud_raw->points[
i].r;
171 rgb[1] = cloud_raw->points[
i].g;
172 rgb[2] = cloud_raw->points[
i].b;
179 pcl::PointCloud<pcl::PointXYZ>::Ptr
clouds(
new pcl::PointCloud<pcl::PointXYZ>);
181 const OpenHRP::PCDOffset& offset =
m_offset[
i];
182 const std::string label(offset.label);
184 const hrp::Vector3 center(offset.center.x, offset.center.y, offset.center.z);
185 const hrp::Vector3 offsetP(offset.data.position.x, offset.data.position.y, offset.data.position.z);
187 offset.data.orientation.p,
188 offset.data.orientation.y));
190 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_raw =
m_clouds_xyz[label];
191 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_new(
new pcl::PointCloud<pcl::PointXYZ>);
192 int npoint = cloud_raw->points.size();
193 cloud_new->points.resize(npoint);
194 cloud_new->width = cloud_raw->width;
195 cloud_new->height = cloud_raw->height;
196 cloud_new->is_dense = cloud_raw->is_dense;
198 for(
int j = 0 ;
j < npoint ;
j++){
199 point << cloud_raw->points[
j].x, cloud_raw->points[
j].y, cloud_raw->points[
j].z;
200 point_new = offsetR * (point - center) + center + offsetP;
201 cloud_new->points[
j].x = point_new[0];
202 cloud_new->points[
j].y = point_new[1];
203 cloud_new->points[
j].z = point_new[2];
205 *clouds += *cloud_new;
213 pcl::PointCloud<pcl::PointXYZRGB>::Ptr
clouds(
new pcl::PointCloud<pcl::PointXYZRGB>);
215 const OpenHRP::PCDOffset& offset =
m_offset[
i];
216 const std::string label(offset.label);
218 const hrp::Vector3 center(offset.center.x, offset.center.y, offset.center.z);
219 const hrp::Vector3 offsetP(offset.data.position.x, offset.data.position.y, offset.data.position.z);
221 offset.data.orientation.p,
222 offset.data.orientation.y));
224 pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_raw =
m_clouds_xyzrgb[label];
225 pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_new(
new pcl::PointCloud<pcl::PointXYZRGB>);
226 int npoint = cloud_raw->points.size();
227 cloud_new->points.resize(npoint);
228 cloud_new->width = cloud_raw->width;
229 cloud_new->height = cloud_raw->height;
230 cloud_new->is_dense = cloud_raw->is_dense;
232 for(
int j = 0 ;
j < npoint ;
j++){
233 point << cloud_raw->points[
j].x, cloud_raw->points[
j].y, cloud_raw->points[
j].z;
234 point_new = offsetR * (point - center) + center + offsetP;
235 cloud_new->points[
j].x = point_new[0];
236 cloud_new->points[
j].y = point_new[1];
237 cloud_new->points[
j].z = point_new[2];
239 *clouds += *cloud_new;
268 std::cout <<
m_profile.instance_name<<
": onActivated(" << ec_id <<
")" << std::endl;
274 std::cout <<
m_profile.instance_name<<
": onDeactivated(" << ec_id <<
")" << std::endl;
285 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(
new pcl::PointCloud<pcl::PointXYZ>);
286 if (reader.read (
m_path, *cloud)){
287 std::cerr <<
m_profile.instance_name <<
": failed to load(" 288 <<
m_path <<
")" << std::endl;
294 pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(
new pcl::PointCloud<pcl::PointXYZRGB>);
295 if (reader.read (
m_path, *cloud)){
296 std::cerr <<
m_profile.instance_name <<
": failed to load(" 297 <<
m_path <<
")" << std::endl;
303 std::cerr <<
"fields[" <<
m_fields <<
"] is not supported" << std::endl;
367 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(
new pcl::PointCloud<pcl::PointXYZ>);
368 if (reader.read (filename, *cloud)){
369 std::cerr <<
m_profile.instance_name <<
": failed to load(" 370 << filename <<
")" << std::endl;
374 std::cout <<
"Loading " << filename <<
" with XYZ fields." << std::endl;
378 pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(
new pcl::PointCloud<pcl::PointXYZRGB>);
379 if (reader.read (filename, *cloud)){
380 std::cerr <<
m_profile.instance_name <<
": failed to load(" 381 << filename <<
")" << std::endl;
385 std::cout <<
"Loading " << filename <<
" with XYZRGB fields." << std::endl;
388 std::cerr <<
"fields[" <<
m_fields <<
"] is not supported" << std::endl;
399 RTC::Create<PCDLoader>,
400 RTC::Delete<PCDLoader>);
ComponentProfile m_profile
png_infop png_charpp int png_charpp profile
std::vector< pcl::PointCloud< pcl::PointXYZRGB >::Ptr > clouds
boost::unordered_map< std::string, pcl::PointCloud< pcl::PointXYZ >::Ptr > m_clouds_xyz
void setCloudXYZRGB(PointCloudTypes::PointCloud &cloud, const pcl::PointCloud< pcl::PointXYZRGB >::Ptr cloud_raw)
virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id)
void updateOffsetToCloudXYZRGB(void)
static const char * spec[]
void PCDLoaderInit(RTC::Manager *manager)
void setCloudXYZ(PointCloudTypes::PointCloud &cloud, const pcl::PointCloud< pcl::PointXYZ >::Ptr cloud_raw)
virtual RTC::ReturnCode_t onInitialize()
coil::Properties & getProperties()
boost::unordered_map< std::string, pcl::PointCloud< pcl::PointXYZRGB >::Ptr > m_clouds_xyzrgb
bool addOutPort(const char *name, OutPortBase &outport)
PCDLoader(RTC::Manager *manager)
Constructor.
PCDLoaderService_impl m_service0
Matrix33 rotFromRpy(const Vector3 &rpy)
InPort< OpenHRP::PCDOffsetSeq > m_offsetIn
virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id)
ExecutionContextHandle_t UniqueId
bool bindParameter(const char *param_name, VarType &var, const char *def_val, bool(*trans)(VarType &, const char *)=coil::stringTo)
OutPort< PointCloudTypes::PointCloud > m_cloudOut
def j(str, encoding="cp932")
OutPort< RTC::TimedBoolean > m_isOutputOut
virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id)
void setComp(PCDLoader *i_comp)
OpenHRP::PCDOffsetSeq m_offset
void updateOffsetToCloudXYZ(void)
RTC::CorbaPort m_PCDLoaderServicePort
bool addPort(PortBase &port)
virtual bool write(DataType &value)
PointCloudTypes::PointCloud m_cloud
RTC::TimedBoolean m_isOutput
bool addInPort(const char *name, InPortBase &inport)
bool registerFactory(coil::Properties &profile, RtcNewFunc new_func, RtcDeleteFunc delete_func)
bool load(const std::string &filename, const std::string &label)
virtual ~PCDLoader()
Destructor.
bool registerProvider(const char *instance_name, const char *type_name, PortableServer::RefCountServantBase &provider)