00001 #include "RangeDetector.h"
00002 #include <utils/Regression.h>
00003
00004
00005 RangeDetector::RangeDetector(const PeakFinder* peak, unsigned int scales, double sigma, double step, SmoothingFilterFamily filterType):
00006 MultiScaleDetector(peak, scales, sigma, step, filterType)
00007 {
00008 computeDifferentialBank();
00009 }
00010
00011 void RangeDetector::computeDifferentialBank(){
00012 m_differentialBank.resize(m_scaleNumber, std::vector<double>(3));
00013 for(unsigned int i = 0; i < m_differentialBank.size(); i++){
00014 m_differentialBank[i][0] = m_scales[i]*1;
00015 m_differentialBank[i][1] = -m_scales[i]*2;
00016 m_differentialBank[i][2] = m_scales[i]*1;
00017 }
00018 }
00019
00020 void RangeDetector::computeSignal(const LaserReading& reading, std::vector<double>& signal, std::vector<unsigned int>& maxRangeMapping) const{
00021 signal.reserve(reading.getRho().size());
00022 maxRangeMapping.reserve(reading.getRho().size());
00023 for(unsigned int i = 0; i < reading.getRho().size(); i++){
00024 if(reading.getRho()[i] < reading.getMaxRange()){
00025 signal.push_back(reading.getRho()[i]);
00026 maxRangeMapping.push_back(i);
00027 } else if (m_useMaxRange){
00028 signal.push_back(reading.getMaxRange());
00029 maxRangeMapping.push_back(i);
00030 }
00031 }
00032 }
00033
00034 unsigned int RangeDetector::computeInterestPoints(const LaserReading& reading, const std::vector<double>& signal, std::vector<InterestPoint*>& point,
00035 std::vector< std::vector<unsigned int> >& indexes, std::vector<unsigned int>& maxRangeMapping) const
00036 {
00037 point.clear();
00038 point.reserve(reading.getRho().size());
00039 const std::vector<Point2D>& worldPoints = reading.getWorldCartesian();
00040 for(unsigned int i = 0; i < indexes.size(); i++){
00041 for(unsigned int j = 0; j < indexes[i].size(); j++){
00042 OrientedPoint2D pose;
00043 unsigned int pointIndex = maxRangeMapping[indexes[i][j]];
00044
00045
00046 double rangeBefore = (pointIndex > 1)? reading.getRho()[pointIndex - 1] : reading.getMaxRange();
00047 double rangeAfter = (pointIndex < worldPoints.size() - 1)? reading.getRho()[pointIndex + 1] : reading.getMaxRange();
00048 double rangeCurrent = reading.getRho()[pointIndex];
00049 if(rangeBefore < rangeAfter){
00050 if(rangeBefore < rangeCurrent){
00051 pointIndex = pointIndex - 1;
00052 }
00053 } else if(rangeAfter < rangeCurrent){
00054 pointIndex = pointIndex + 1;
00055 }
00056
00057
00058 if(reading.getRho()[pointIndex] >= reading.getMaxRange()){
00059 continue;
00060 }
00061
00062 pose.x = (reading.getWorldCartesian()[pointIndex]).x;
00063 pose.y = (reading.getWorldCartesian()[pointIndex]).y;
00064 pose.theta = 0.0;
00065
00066 bool exists = false;
00067 for(unsigned int k = 0; !exists && k < point.size(); k++){
00068 exists = exists || (fabs(pose.x - point[k]->getPosition().x) <= 0.2 && fabs(pose.y - point[k]->getPosition().y) <= 0.2);
00069 }
00070 if(exists) continue;
00071
00072 unsigned int first = pointIndex - floor((int)m_filterBank[i].size()/2.0);
00073 unsigned int last = pointIndex + floor((int)m_filterBank[i].size()/2.0);
00074 std::vector<Point2D> support(reading.getWorldCartesian().begin() + first, reading.getWorldCartesian().begin() + last + 1);
00075
00076 LineParameters param = computeNormals(support);
00077 pose.theta = normAngle(param.alpha, - M_PI);
00078
00079 double maxDistance = -1e20;
00080 for(unsigned int k = 0; k < support.size(); k++){
00081 double distance = sqrt((pose.x - support[k].x)*(pose.x - support[k].x) + (pose.y - support[k].y)*(pose.y - support[k].y));
00082 maxDistance = maxDistance < distance ? distance : maxDistance;
00083 }
00084 InterestPoint *interest = new InterestPoint(pose, maxDistance);
00085
00086 interest->setScaleLevel(i);
00087 interest->setSupport(support);
00088 point.push_back(interest);
00089 }
00090 }
00091 return point.size();
00092 }
00093