SORFilter.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
10 #include <pcl/io/pcd_io.h>
11 #include <pcl/point_types.h>
12 #include <pcl/filters/statistical_outlier_removal.h>
13 #include "SORFilter.h"
14 #include "hrpsys/idl/pointcloud.hh"
15 
16 // Module specification
17 // <rtc-template block="module_spec">
18 static const char* spec[] =
19  {
20  "implementation_id", "SORFilter",
21  "type_name", "SORFilter",
22  "description", "Statistical Outlier Removal Filter",
23  "version", HRPSYS_PACKAGE_VERSION,
24  "vendor", "AIST",
25  "category", "example",
26  "activity_type", "DataFlowComponent",
27  "max_instance", "10",
28  "language", "C++",
29  "lang_type", "compile",
30  // Configuration variables
31  "conf.default.meanK", "50",
32  "conf.default.stddevMulThresh", "1.0",
33 
34  ""
35  };
36 // </rtc-template>
37 
39  : RTC::DataFlowComponentBase(manager),
40  // <rtc-template block="initializer">
41  m_originalIn("original", m_original),
42  m_filteredOut("filtered", m_filtered),
43  // </rtc-template>
44  dummy(0)
45 {
46 }
47 
49 {
50 }
51 
52 
53 
54 RTC::ReturnCode_t SORFilter::onInitialize()
55 {
56  //std::cout << m_profile.instance_name << ": onInitialize()" << std::endl;
57  // <rtc-template block="bind_config">
58  // Bind variables and configuration variable
59  bindParameter("meanK", m_meanK, "50");
60  bindParameter("stddevMulThresh", m_stddevMulThresh, "1.0");
61 
62  // </rtc-template>
63 
64  // Registration: InPort/OutPort/Service
65  // <rtc-template block="registration">
66  // Set InPort buffers
67  addInPort("originalIn", m_originalIn);
68 
69  // Set OutPort buffer
70  addOutPort("filteredOut", m_filteredOut);
71 
72  // Set service provider to Ports
73 
74  // Set service consumers to Ports
75 
76  // Set CORBA Service Ports
77 
78  // </rtc-template>
79 
81 
82  m_filtered.height = 1;
83  m_filtered.type = "xyz";
84  m_filtered.fields.length(3);
85  m_filtered.fields[0].name = "x";
86  m_filtered.fields[0].offset = 0;
87  m_filtered.fields[0].data_type = PointCloudTypes::FLOAT32;
88  m_filtered.fields[0].count = 4;
89  m_filtered.fields[1].name = "y";
90  m_filtered.fields[1].offset = 4;
91  m_filtered.fields[1].data_type = PointCloudTypes::FLOAT32;
92  m_filtered.fields[1].count = 4;
93  m_filtered.fields[2].name = "z";
94  m_filtered.fields[2].offset = 8;
95  m_filtered.fields[2].data_type = PointCloudTypes::FLOAT32;
96  m_filtered.fields[2].count = 4;
97  m_filtered.is_bigendian = false;
98  m_filtered.point_step = 16;
99  m_filtered.is_dense = true;
100 
101  return RTC::RTC_OK;
102 }
103 
104 
105 
106 /*
107 RTC::ReturnCode_t SORFilter::onFinalize()
108 {
109  return RTC::RTC_OK;
110 }
111 */
112 
113 /*
114 RTC::ReturnCode_t SORFilter::onStartup(RTC::UniqueId ec_id)
115 {
116  return RTC::RTC_OK;
117 }
118 */
119 
120 /*
121 RTC::ReturnCode_t SORFilter::onShutdown(RTC::UniqueId ec_id)
122 {
123  return RTC::RTC_OK;
124 }
125 */
126 
127 RTC::ReturnCode_t SORFilter::onActivated(RTC::UniqueId ec_id)
128 {
129  std::cout << m_profile.instance_name<< ": onActivated(" << ec_id << ")" << std::endl;
130  return RTC::RTC_OK;
131 }
132 
133 RTC::ReturnCode_t SORFilter::onDeactivated(RTC::UniqueId ec_id)
134 {
135  std::cout << m_profile.instance_name<< ": onDeactivated(" << ec_id << ")" << std::endl;
136  return RTC::RTC_OK;
137 }
138 
139 RTC::ReturnCode_t SORFilter::onExecute(RTC::UniqueId ec_id)
140 {
141  //std::cout << m_profile.instance_name<< ": onExecute(" << ec_id << ")" << std::endl;
142 
143  if (m_originalIn.isNew()){
144  m_originalIn.read();
145 
146  if (!m_original.data.length()){
147  m_filtered.width = m_filtered.row_step = 0;
148  m_filtered.data.length(0);
149  return RTC::RTC_OK;
150  }
151 
152  pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
153  pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered (new pcl::PointCloud<pcl::PointXYZ>);
154 
155  cloud->points.resize(m_original.width*m_original.height);
156  float *src = (float *)m_original.data.get_buffer();
157  for (unsigned int i=0; i<cloud->points.size(); i++){
158  cloud->points[i].x = src[0];
159  cloud->points[i].y = src[1];
160  cloud->points[i].z = src[2];
161  src += 4;
162  }
163 
164  pcl::StatisticalOutlierRemoval<pcl::PointXYZ> sor;
165  sor.setInputCloud (cloud);
166  sor.setMeanK (m_meanK);
167  sor.setStddevMulThresh (m_stddevMulThresh);
168  sor.filter (*cloud_filtered);
169 
170  m_filtered.width = cloud_filtered->points.size();
171  m_filtered.row_step = m_filtered.point_step*m_filtered.width;
172  m_filtered.data.length(m_filtered.height*m_filtered.row_step);
173  float *dst = (float *)m_filtered.data.get_buffer();
174  for (unsigned int i=0; i<cloud_filtered->points.size(); i++){
175  dst[0] = cloud_filtered->points[i].x;
176  dst[1] = cloud_filtered->points[i].y;
177  dst[2] = cloud_filtered->points[i].z;
178  dst += 4;
179  }
181  }
182 
183  return RTC::RTC_OK;
184 }
185 
186 /*
187 RTC::ReturnCode_t SORFilter::onAborting(RTC::UniqueId ec_id)
188 {
189  return RTC::RTC_OK;
190 }
191 */
192 
193 /*
194 RTC::ReturnCode_t SORFilter::onError(RTC::UniqueId ec_id)
195 {
196  return RTC::RTC_OK;
197 }
198 */
199 
200 /*
201 RTC::ReturnCode_t SORFilter::onReset(RTC::UniqueId ec_id)
202 {
203  return RTC::RTC_OK;
204 }
205 */
206 
207 /*
208 RTC::ReturnCode_t SORFilter::onStateUpdate(RTC::UniqueId ec_id)
209 {
210  return RTC::RTC_OK;
211 }
212 */
213 
214 /*
215 RTC::ReturnCode_t SORFilter::onRateChanged(RTC::UniqueId ec_id)
216 {
217  return RTC::RTC_OK;
218 }
219 */
220 
221 
222 
223 extern "C"
224 {
225 
227  {
229  manager->registerFactory(profile,
230  RTC::Create<SORFilter>,
231  RTC::Delete<SORFilter>);
232  }
233 
234 };
235 
236 
ComponentProfile m_profile
png_infop png_charpp int png_charpp profile
Statistical Outlier Removal Filter.
SORFilter(RTC::Manager *manager)
Constructor.
Definition: SORFilter.cpp:38
virtual RTC::ReturnCode_t onInitialize()
Definition: SORFilter.cpp:54
png_uint_32 i
coil::Properties & getProperties()
bool addOutPort(const char *name, OutPortBase &outport)
static const char * spec[]
Definition: SORFilter.cpp:18
int m_meanK
Definition: SORFilter.h:138
virtual ~SORFilter()
Destructor.
Definition: SORFilter.cpp:48
ExecutionContextHandle_t UniqueId
bool bindParameter(const char *param_name, VarType &var, const char *def_val, bool(*trans)(VarType &, const char *)=coil::stringTo)
virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id)
Definition: SORFilter.cpp:133
void SORFilterInit(RTC::Manager *manager)
Definition: SORFilter.cpp:226
prop
OutPort< PointCloudTypes::PointCloud > m_filteredOut
Definition: SORFilter.h:117
PointCloudTypes::PointCloud m_original
Definition: SORFilter.h:106
virtual bool isNew()
virtual bool write(DataType &value)
virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id)
Definition: SORFilter.cpp:127
InPort< PointCloudTypes::PointCloud > m_originalIn
Definition: SORFilter.h:111
bool addInPort(const char *name, InPortBase &inport)
PointCloudTypes::PointCloud m_filtered
Definition: SORFilter.h:107
bool registerFactory(coil::Properties &profile, RtcNewFunc new_func, RtcDeleteFunc delete_func)
double m_stddevMulThresh
Definition: SORFilter.h:139
virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id)
Definition: SORFilter.cpp:139


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Thu May 6 2021 02:41:51