10 #include <pcl/io/pcd_io.h> 11 #include <pcl/point_types.h> 12 #include <pcl/segmentation/sac_segmentation.h> 13 #include <pcl/filters/extract_indices.h> 15 #include "hrpsys/idl/pointcloud.hh" 19 static const char*
spec[] =
21 "implementation_id",
"PlaneRemover",
22 "type_name",
"PlaneRemover",
23 "description",
"Plane Remover",
24 "version", HRPSYS_PACKAGE_VERSION,
26 "category",
"example",
27 "activity_type",
"DataFlowComponent",
30 "lang_type",
"compile",
32 "conf.default.distanceThd",
"0.02",
33 "conf.default.pointNumThd",
"500",
42 m_originalIn(
"original", m_original),
43 m_filteredOut(
"filtered", m_filtered),
88 m_filtered.fields[0].data_type = PointCloudTypes::FLOAT32;
92 m_filtered.fields[1].data_type = PointCloudTypes::FLOAT32;
96 m_filtered.fields[2].data_type = PointCloudTypes::FLOAT32;
130 std::cout <<
m_profile.instance_name<<
": onActivated(" << ec_id <<
")" << std::endl;
136 std::cout <<
m_profile.instance_name<<
": onDeactivated(" << ec_id <<
")" << std::endl;
148 pcl::PointCloud<pcl::PointXYZ>::Ptr original (
new pcl::PointCloud<pcl::PointXYZ>);
150 float *src = (
float *)
m_original.data.get_buffer();
151 for (
unsigned int i=0;
i<original->points.size();
i++){
152 original->points[
i].x = src[0];
153 original->points[
i].y = src[1];
154 original->points[
i].z = src[2];
160 pcl::ModelCoefficients::Ptr coefficients (
new pcl::ModelCoefficients);
161 pcl::PointIndices::Ptr inliers (
new pcl::PointIndices);
163 pcl::SACSegmentation<pcl::PointXYZ> seg;
165 seg.setOptimizeCoefficients (
true);
167 seg.setModelType (pcl::SACMODEL_PLANE);
168 seg.setMethodType (pcl::SAC_RANSAC);
171 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud = original;
172 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_f(
new pcl::PointCloud<pcl::PointXYZ>);
174 pcl::ExtractIndices<pcl::PointXYZ> extract;
177 seg.setInputCloud (cloud);
178 seg.segment (*inliers, *coefficients);
182 extract.setInputCloud( cloud );
183 extract.setIndices( inliers );
184 extract.setNegative(
true );
185 extract.filter( *cloud_f );
195 float *dst = (
float *)
m_filtered.data.get_buffer();
196 for (
unsigned int i=0;
i<cloud->points.size();
i++){
197 dst[0] = cloud->points[
i].x;
198 dst[1] = cloud->points[
i].y;
199 dst[2] = cloud->points[
i].z;
252 RTC::Create<PlaneRemover>,
253 RTC::Delete<PlaneRemover>);
ComponentProfile m_profile
png_infop png_charpp int png_charpp profile
virtual RTC::ReturnCode_t onInitialize()
virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id)
coil::Properties & getProperties()
bool addOutPort(const char *name, OutPortBase &outport)
virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id)
void PlaneRemoverInit(RTC::Manager *manager)
ExecutionContextHandle_t UniqueId
bool bindParameter(const char *param_name, VarType &var, const char *def_val, bool(*trans)(VarType &, const char *)=coil::stringTo)
PointCloudTypes::PointCloud m_filtered
static const char * spec[]
Statistical Outlier Removal Filter.
virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id)
InPort< PointCloudTypes::PointCloud > m_originalIn
PlaneRemover(RTC::Manager *manager)
Constructor.
virtual bool write(DataType &value)
PointCloudTypes::PointCloud m_original
OutPort< PointCloudTypes::PointCloud > m_filteredOut
virtual ~PlaneRemover()
Destructor.
bool addInPort(const char *name, InPortBase &inport)
bool registerFactory(coil::Properties &profile, RtcNewFunc new_func, RtcDeleteFunc delete_func)