Go to the documentation of this file.00001
00010 #include <pcl/io/pcd_io.h>
00011 #include <pcl/point_types.h>
00012 #include <pcl/filters/statistical_outlier_removal.h>
00013 #include "SORFilter.h"
00014 #include "hrpsys/idl/pointcloud.hh"
00015
00016
00017
00018 static const char* spec[] =
00019 {
00020 "implementation_id", "SORFilter",
00021 "type_name", "SORFilter",
00022 "description", "Statistical Outlier Removal Filter",
00023 "version", HRPSYS_PACKAGE_VERSION,
00024 "vendor", "AIST",
00025 "category", "example",
00026 "activity_type", "DataFlowComponent",
00027 "max_instance", "10",
00028 "language", "C++",
00029 "lang_type", "compile",
00030
00031 "conf.default.meanK", "50",
00032 "conf.default.stddevMulThresh", "1.0",
00033
00034 ""
00035 };
00036
00037
00038 SORFilter::SORFilter(RTC::Manager* manager)
00039 : RTC::DataFlowComponentBase(manager),
00040
00041 m_originalIn("original", m_original),
00042 m_filteredOut("filtered", m_filtered),
00043
00044 dummy(0)
00045 {
00046 }
00047
00048 SORFilter::~SORFilter()
00049 {
00050 }
00051
00052
00053
00054 RTC::ReturnCode_t SORFilter::onInitialize()
00055 {
00056
00057
00058
00059 bindParameter("meanK", m_meanK, "50");
00060 bindParameter("stddevMulThresh", m_stddevMulThresh, "1.0");
00061
00062
00063
00064
00065
00066
00067 addInPort("originalIn", m_originalIn);
00068
00069
00070 addOutPort("filteredOut", m_filteredOut);
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 RTC::Properties& prop = getProperties();
00081
00082 m_filtered.height = 1;
00083 m_filtered.type = "xyz";
00084 m_filtered.fields.length(3);
00085 m_filtered.fields[0].name = "x";
00086 m_filtered.fields[0].offset = 0;
00087 m_filtered.fields[0].data_type = PointCloudTypes::FLOAT32;
00088 m_filtered.fields[0].count = 4;
00089 m_filtered.fields[1].name = "y";
00090 m_filtered.fields[1].offset = 4;
00091 m_filtered.fields[1].data_type = PointCloudTypes::FLOAT32;
00092 m_filtered.fields[1].count = 4;
00093 m_filtered.fields[2].name = "z";
00094 m_filtered.fields[2].offset = 8;
00095 m_filtered.fields[2].data_type = PointCloudTypes::FLOAT32;
00096 m_filtered.fields[2].count = 4;
00097 m_filtered.is_bigendian = false;
00098 m_filtered.point_step = 16;
00099 m_filtered.is_dense = true;
00100
00101 return RTC::RTC_OK;
00102 }
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127 RTC::ReturnCode_t SORFilter::onActivated(RTC::UniqueId ec_id)
00128 {
00129 std::cout << m_profile.instance_name<< ": onActivated(" << ec_id << ")" << std::endl;
00130 return RTC::RTC_OK;
00131 }
00132
00133 RTC::ReturnCode_t SORFilter::onDeactivated(RTC::UniqueId ec_id)
00134 {
00135 std::cout << m_profile.instance_name<< ": onDeactivated(" << ec_id << ")" << std::endl;
00136 return RTC::RTC_OK;
00137 }
00138
00139 RTC::ReturnCode_t SORFilter::onExecute(RTC::UniqueId ec_id)
00140 {
00141
00142
00143 if (m_originalIn.isNew()){
00144 m_originalIn.read();
00145
00146 if (!m_original.data.length()){
00147 m_filtered.width = m_filtered.row_step = 0;
00148 m_filtered.data.length(0);
00149 return RTC::RTC_OK;
00150 }
00151
00152 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
00153 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered (new pcl::PointCloud<pcl::PointXYZ>);
00154
00155 cloud->points.resize(m_original.width*m_original.height);
00156 float *src = (float *)m_original.data.get_buffer();
00157 for (unsigned int i=0; i<cloud->points.size(); i++){
00158 cloud->points[i].x = src[0];
00159 cloud->points[i].y = src[1];
00160 cloud->points[i].z = src[2];
00161 src += 4;
00162 }
00163
00164 pcl::StatisticalOutlierRemoval<pcl::PointXYZ> sor;
00165 sor.setInputCloud (cloud);
00166 sor.setMeanK (m_meanK);
00167 sor.setStddevMulThresh (m_stddevMulThresh);
00168 sor.filter (*cloud_filtered);
00169
00170 m_filtered.width = cloud_filtered->points.size();
00171 m_filtered.row_step = m_filtered.point_step*m_filtered.width;
00172 m_filtered.data.length(m_filtered.height*m_filtered.row_step);
00173 float *dst = (float *)m_filtered.data.get_buffer();
00174 for (unsigned int i=0; i<cloud_filtered->points.size(); i++){
00175 dst[0] = cloud_filtered->points[i].x;
00176 dst[1] = cloud_filtered->points[i].y;
00177 dst[2] = cloud_filtered->points[i].z;
00178 dst += 4;
00179 }
00180 m_filteredOut.write();
00181 }
00182
00183 return RTC::RTC_OK;
00184 }
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 extern "C"
00224 {
00225
00226 void SORFilterInit(RTC::Manager* manager)
00227 {
00228 RTC::Properties profile(spec);
00229 manager->registerFactory(profile,
00230 RTC::Create<SORFilter>,
00231 RTC::Delete<SORFilter>);
00232 }
00233
00234 };
00235
00236