ShapeSensorModel.h
Go to the documentation of this file.00001 #ifndef _ShapeSensorModel_h_
00002 #define _ShapeSensorModel_h_
00003
00004 #include "LocalizationParticle.h"
00005
00006 class PfRoot;
00007 class PfLine;
00008
00009 namespace DualCoding {
00010 class ShapeSpace;
00011 }
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 class LocalShapeEvaluator {
00022 public:
00023
00024 LocalShapeEvaluator(DualCoding::ShapeSpace &localShS, DualCoding::ShapeSpace &worldShS);
00025 virtual ~LocalShapeEvaluator() {}
00026
00027
00028 void evaluate(LocalizationParticle& part);
00029
00030
00031 void evaluateWorkhorse (LocalizationParticle& p, const unsigned int nLocals,
00032 float particleViewX[], float particleViewY[], float particleViewX2[], float ParticleViewY2[],
00033 int localMatches[], float localScores[]);
00034
00035
00036 void updateWeight(LocalizationParticle &p, int const localMatches[], float const localScores[]);
00037
00038 std::vector<PfRoot*> localLms;
00039 std::vector<PfRoot*> worldLms;
00040
00041 static float const maxDist;
00042 static float const stdevSq;
00043
00044
00045 static float distanceFromLine(coordinate_t x0, coordinate_t y0, PfLine &wline);
00046
00047
00048
00049
00050 inline float normpdf(float const distsq) { return std::exp(-distsq/stdevSq); }
00051 };
00052
00053 class CameraShapeEvaluator {
00054 public:
00055
00056 CameraShapeEvaluator(DualCoding::ShapeSpace &camShS, DualCoding::ShapeSpace &worldShS):
00057 pRandom(0.2f), alpha(1), xvar(3000), yvar(1000), cShS(camShS), wShS(worldShS)
00058 {}
00059
00060 virtual ~CameraShapeEvaluator(){}
00061
00062
00063 virtual void computeLikelihood(LocalizationParticle& particle);
00064
00065 float pRandom;
00066 float alpha;
00067
00068 float xvar;
00069 float yvar;
00070 DualCoding::ShapeSpace &cShS;
00071 DualCoding::ShapeSpace &wShS;
00072
00073
00074
00075
00076 inline float normpdf(float const dist, float variance) { return std::exp(-dist*dist/variance); }
00077 };
00078
00079
00080
00081
00082
00083
00084
00085
00086 template<typename ParticleT>
00087 class ShapeSensorModel : public ParticleFilter<ParticleT>::SensorModel {
00088 public:
00089 typedef typename ParticleFilter<ParticleT>::SensorModel::index_t index_t;
00090 typedef typename ParticleFilter<ParticleT>::SensorModel::particle_collection particle_collection;
00091 typedef typename ParticleFilter<ParticleT>::SensorModel::particle_type particle_type;
00092
00093
00094 ShapeSensorModel(DualCoding::ShapeSpace &camShS, DualCoding::ShapeSpace &localShS, DualCoding::ShapeSpace &worldShS) :
00095 cShS(camShS), lShS(localShS), wShS(worldShS)
00096 {}
00097
00098
00099 virtual void evaluate(particle_collection& particles, particle_type &estimate) {
00100
00101 updateFromLocal(particles, estimate);
00102 }
00103
00104 virtual void updateFromLocal(particle_collection& particles, particle_type &estimate) {
00105 LocalShapeEvaluator localEval(lShS,wShS);
00106 float bestWeight = -FLT_MAX;
00107 typename particle_collection::size_type bestIndex = 0;
00108 double tx=0, ty=0, tcos=0, tsin=0;
00109 double totalWeight = 0;
00110 for(typename particle_collection::size_type p=0; p<particles.size(); ++p) {
00111 localEval.evaluate(particles[p]);
00112 if (particles[p].weight > bestWeight) {
00113 bestWeight = particles[p].weight;
00114 bestIndex = p;
00115 }
00116 double w = exp((double)particles[p].weight);
00117 totalWeight += w;
00118 tx += particles[p].x * w;
00119 ty += particles[p].y * w;
00120 tcos += cos(particles[p].theta) * w;
00121 tsin += sin(particles[p].theta) * w;
00122 }
00123 if ( totalWeight > 1e-200 ) {
00124 estimate.x = tx / totalWeight;
00125 estimate.y = ty / totalWeight;
00126 estimate.theta = atan2(tsin/totalWeight, tcos/totalWeight);
00127 } else {
00128 estimate.x = particles[bestIndex].x;
00129 estimate.y = particles[bestIndex].y;
00130 estimate.theta = particles[bestIndex].theta;
00131 }
00132 estimate.weight = bestWeight;
00133 }
00134
00135 virtual void updateFromCamera(particle_collection& particles, particle_type& estimate) {
00136 CameraShapeEvaluator cameraEval(cShS,wShS);
00137 for(typename particle_collection::size_type p=0; p<particles.size(); ++p) {
00138
00139
00140
00141
00142
00143 cameraEval.computeLikelihood(particles[p]);
00144 }
00145 }
00146
00147 DualCoding::ShapeSpace& getcamShS() const { return lShS; }
00148 DualCoding::ShapeSpace& getLocalShS() const { return lShS; }
00149 DualCoding::ShapeSpace& getWorldShS() const { return wShS; }
00150
00151 protected:
00152 DualCoding::ShapeSpace &cShS;
00153 DualCoding::ShapeSpace &lShS;
00154 DualCoding::ShapeSpace &wShS;
00155 };
00156
00157 #endif