Go to the documentation of this file.00001 #include "average_point_cloud_alg_node.h"
00002 #include <boost/foreach.hpp>
00003
00004
00005 AveragePointCloudAlgNode::AveragePointCloudAlgNode(void) :iBuffer_ (5), iCurrent_ (0), init_ (false)
00006 {
00007
00008
00009
00010
00011 cloudBuffer_.resize(iBuffer_);
00012
00013 pcl2_pub_ = public_node_handle_.advertise<sensor_msgs::PointCloud2>("output", 1);
00014
00015
00016 pcl2_sub_ = public_node_handle_.subscribe<sensor_msgs::PointCloud2>("input", 10, &AveragePointCloudAlgNode::input_callback, this);
00017
00018
00019
00020
00021
00022
00023
00024
00025 }
00026
00027 AveragePointCloudAlgNode::~AveragePointCloudAlgNode(void)
00028 {
00029
00030 }
00031
00032 void AveragePointCloudAlgNode::mainNodeThread(void)
00033 {
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 }
00045
00046
00047 void AveragePointCloudAlgNode::input_callback(const sensor_msgs::PointCloud2::ConstPtr& msg)
00048 {
00049
00050 if (pcl2_pub_.getNumSubscribers () > 0)
00051 {
00052
00053
00054
00055
00056 pcl2_final_msg_ = *msg;
00057 pcl2_current_msg_ = *msg;
00058
00059 if (!init_) {
00060
00061 alg_.lock();
00062 input_mutex_.enter();
00063
00064 cloudBuffer_.push_back(pcl2_current_msg_);
00065 if (++iCurrent_ == iBuffer_ - 1 ) {
00066 init_ = true;
00067 iCurrent_ = 0;
00068 }
00069 alg_.unlock();
00070 input_mutex_.exit();
00071 } else {
00072
00073 alg_.lock();
00074 input_mutex_.enter();
00075
00076 cloudBuffer_.push_back(pcl2_current_msg_);
00077
00078
00079 for (unsigned int rr=0; rr < msg->height; rr++){
00080 for (unsigned int cc=0; cc < msg->width; cc++){
00081 int index = rr * pcl2_final_msg_.width + cc;
00082 float *pstep = (float*)&pcl2_final_msg_.data[(index) * pcl2_final_msg_.point_step];
00083 pstep[0] = 0;
00084 pstep[1] = 0;
00085 pstep[2] = 0;
00086 pstep[3] = 0;
00087 }
00088 }
00089
00090
00091 for (int k=0; k < iBuffer_; k++){
00092 for (unsigned int rr=0; rr < msg->height; rr++){
00093 for (unsigned int cc=0; cc < msg->width; cc++){
00094 int index = rr * pcl2_final_msg_.width + cc;
00095 float *pstep_final = (float*)&pcl2_final_msg_.data[(index) * pcl2_final_msg_.point_step];
00096 float *pstep_current =(float*)&cloudBuffer_[k].data[(index) * cloudBuffer_[k].point_step];
00097 pstep_final[0] += pstep_current[0]/(iBuffer_);
00098 pstep_final[1] += pstep_current[1]/(iBuffer_);
00099 pstep_final[2] += pstep_current[2]/(iBuffer_);
00100 pstep_final[3] += pstep_current[3]/(iBuffer_);
00101 }
00102 }
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 }
00113
00114 alg_.unlock();
00115 input_mutex_.exit();
00116 pcl2_pub_.publish(pcl2_final_msg_);
00117 }
00118 }
00119
00120 }
00121
00122
00123
00124
00125
00126
00127
00128 void AveragePointCloudAlgNode::node_config_update(Config &config, uint32_t level)
00129 {
00130
00131 alg_.lock();
00132 ROS_INFO ("Reconfigure request :%d, level %d", config.iBuffer, level);
00133 try
00134 {
00135 iBuffer_ = config.iBuffer;
00136 cloudBuffer_.resize(iBuffer_);
00137 init_ =false;
00138 }
00139 catch (CException & e)
00140 {
00141 std::cout << e.what () << std::endl;
00142 }
00143 alg_.unlock();
00144
00145
00146 }
00147
00148 void AveragePointCloudAlgNode::addNodeDiagnostics(void)
00149 {
00150 }
00151
00152
00153 int main(int argc,char *argv[])
00154 {
00155 return algorithm_base::main<AveragePointCloudAlgNode>(argc, argv, "average_point_cloud_alg_node");
00156 }