Go to the documentation of this file.00001 #ifndef SWISSRANGERREADING_H
00002 #define SWISSRANGERREADING_H
00003
00004 #define XML_NODE_SWISSRANGER "SwissRangerRemoteSensor"
00005 #define XML_PROPERTY_TOPIC "Topic"
00006
00007 #include <sensor_msgs/PointCloud.h>
00008
00009 #include <sstream>
00010
00011 #include <XMLTag.h>
00012
00013 extern bool s_initedPCDPublisher;
00014 extern ros::Publisher s_sensorPublisher;
00015
00016
00017 class SwissRangerReading : public cop::Reading
00018 {
00019 public:
00020 SwissRangerReading(const sensor_msgs::PointCloudConstPtr& pcdcloud, SwissRangerReading* integrate_with, cop::RelPose* parent) :
00021 Reading(ReadingType_PointCloud),
00022 m_integrationcounter(0)
00023 {
00024 if(parent != NULL)
00025 SetPose(parent);
00026 if(integrate_with != NULL && m_relPose != NULL && integrate_with->m_relPose != NULL)
00027 {
00028 double dist = m_relPose->DistanceTo(integrate_with->m_relPose->m_uniqueID);
00029 if(dist < 0.0005)
00030 {
00031 IntegratePointCloud( *pcdcloud, integrate_with->m_image, integrate_with->m_integrationcounter);
00032 }
00033 else
00034 {
00035 m_image = (*pcdcloud);
00036 }
00037 }
00038 else
00039 {
00040 m_image = (*pcdcloud);
00041 }
00042
00043
00044 }
00045
00046 SwissRangerReading(const sensor_msgs::PointCloud& pcdcloud, SwissRangerReading* integrate_with, cop::RelPose* parent) :
00047 Reading(ReadingType_PointCloud),
00048 m_integrationcounter(0)
00049 {
00050 if(parent != NULL)
00051 SetPose(parent);
00052 if(integrate_with != NULL && m_relPose != NULL && integrate_with->m_relPose != NULL)
00053 {
00054 double dist = m_relPose->DistanceTo(integrate_with->m_relPose->m_uniqueID);
00055 if(dist < 0.0005)
00056 {
00057 IntegratePointCloud( pcdcloud, integrate_with->m_image, integrate_with->m_integrationcounter);
00058 }
00059 else
00060 {
00061 m_image = (pcdcloud);
00062 }
00063 }
00064 else
00065 {
00066 m_image = (pcdcloud);
00067 }
00068
00069
00070 }
00071
00072 SwissRangerReading() :
00073 Reading(ReadingType_PointCloud),
00074 m_integrationcounter(0)
00075 {
00076 }
00077 #define min_l(A, B) (((A) < (B)) ? (A) : (B))
00078 void IntegratePointCloud (const sensor_msgs::PointCloud& p_new, const sensor_msgs::PointCloud p_old, int count_old)
00079 {
00084 double weight_new = (10.0 - min_l(count_old, 9.0)) / 10.0;
00085 double weight_old = 1.0 - weight_new;
00086
00087 if(p_new.points.size() == p_old.points.size() && p_new.channels.size() > 0 &&
00088 p_old.channels.size() > 0 && p_new.channels[0].values.size() ==
00089 p_old.channels[0].values.size())
00090 {
00091 m_image.header = p_new.header;
00092 m_image.points.resize(p_new.points.size());
00093 m_image.channels.resize(1);
00094 m_image.channels[0].values.resize( p_new.channels[0].values.size());
00095 for(size_t i = 0; i < p_new.points.size(); i++)
00096 {
00097 if( p_new.points[i].z != p_new.points[i].z || p_old.points[i].z != p_old.points[i].z)
00098 {
00099 if(p_new.points[i].z == p_new.points[i].z)
00100 {
00101 m_image.points[i].x = p_new.points[i].x;
00102 m_image.points[i].y = p_new.points[i].y;
00103 m_image.points[i].z = p_new.points[i].z;
00104 m_image.channels[0].values[i] = weight_new * p_new.channels[0].values[i] + weight_old * p_old.channels[0].values[i];
00105 }
00106 else if(p_old.points[i].z == p_old.points[i].z)
00107 {
00108 m_image.points[i].x = p_old.points[i].x;
00109 m_image.points[i].y = p_old.points[i].y;
00110 m_image.points[i].z = p_old.points[i].z;
00111 m_image.channels[0].values[i] = weight_new * p_new.channels[0].values[i] + weight_old * p_old.channels[0].values[i];
00112 }
00113 else
00114 {
00115 m_image.points[i].x = 0.0;
00116 m_image.points[i].y = 0.0;
00117 m_image.points[i].z = 0.0;
00118 m_image.channels[0].values[i] = weight_new * p_new.channels[0].values[i] + weight_old * p_old.channels[0].values[i];
00119 }
00120 }
00121 else
00122 {
00123 m_image.points[i].x = weight_new * p_new.points[i].x + weight_old * p_old.points[i].x;
00124 m_image.points[i].y = weight_new * p_new.points[i].y + weight_old * p_old.points[i].y;
00125 m_image.points[i].z = weight_new * p_new.points[i].z + weight_old * p_old.points[i].z;
00126 m_image.channels[0].values[i] = weight_new * p_new.channels[0].values[i] + weight_old * p_old.channels[0].values[i];
00127 }
00128 }
00129 m_integrationcounter = count_old + 1;
00130 }
00131 else
00132 {
00133 m_integrationcounter = 1;
00134 }
00135 }
00136 ~SwissRangerReading()
00137 {
00138 }
00139
00143 virtual cop::XMLTag* Save()
00144 {
00145 using namespace cop;
00146
00147 XMLTag* tag = new XMLTag("PointCloud");
00148
00149 std::ostringstream os;
00150 os << "pcd_"<< tag->date() << ".pcd";
00151 tag->AddProperty("FileName", os.str());
00152
00153
00154
00155 return tag;
00156 }
00160 virtual cop::Reading* Clone()
00161 {
00162
00163 return NULL;
00164 }
00165 sensor_msgs::PointCloud m_image;
00166 int m_integrationcounter;
00167 };
00168
00169 #endif