Go to the documentation of this file.00001
00002 #include <blort/Tracker/Predictor.h>
00003 #include <blort/Tracker/Noise.h>
00004 #include <ros/console.h>
00005
00006 using namespace Tracking;
00007
00008 Predictor::Predictor(){
00009 m_dTime = 0.0;
00010 c_pred = 0.0;
00011 m_noConvergence = 0.0f;
00012 }
00013
00014
00015 float Predictor::noise(float sigma, unsigned int type){
00016 float random = 0.0f;
00017
00018
00019 if(type == GAUSS){
00020 for(unsigned i=0; i<10; i++){
00021 random += float(rand())/RAND_MAX;
00022 }
00023 random = 2.0f * (random / 10.0f - 0.5f);
00024 }
00025
00026
00027 if(type == NORMAL){
00028 random = 2.0f * (float(rand())/RAND_MAX - 0.5f);
00029 }
00030
00031
00032 random = random * sigma;
00033
00034 return random;
00035 }
00036
00037 Particle Predictor::genNoise(float sigma, Particle pConstraint, unsigned int type){
00038 if(sigma == 0.0f)
00039 ROS_DEBUG("[Predictor::genNoise] Warning standard deviation sigma is 0.0");
00040
00041 Particle epsilon;
00042 Noise N;
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 epsilon.r.x = N.randn_notrig(0.0f, sigma * pConstraint.r.x);
00054 epsilon.r.y = N.randn_notrig(0.0f, sigma * pConstraint.r.y);
00055 epsilon.r.z = N.randn_notrig(0.0f, sigma * pConstraint.r.z);
00056 epsilon.t.x = N.randn_notrig(0.0f, sigma * pConstraint.t.x);
00057 epsilon.t.y = N.randn_notrig(0.0f, sigma * pConstraint.t.y);
00058 epsilon.t.z = N.randn_notrig(0.0f, sigma * pConstraint.t.z);
00059
00060 epsilon.z = N.randn_notrig(0.0f, sigma * pConstraint.z);
00061
00062 return epsilon;
00063 }
00064
00065 void Predictor::sampleFromGaussian(Distribution& d, int num_particles, Particle mean, Particle variance, float sigma){
00066 Particle p;
00067 Particle epsilon;
00068
00069 d.push_back(mean);
00070 for(int i=1; i<num_particles; i++){
00071
00072
00073 p = mean;
00074
00075
00076 epsilon = genNoise(sigma, variance);
00077
00078
00079 p.Translate(epsilon.t);
00080 p.RotateAxis(epsilon.r);
00081 p.Translate( m_cam_view.x * epsilon.z, m_cam_view.y * epsilon.z, m_cam_view.z * epsilon.z);
00082
00083
00084 d.push_back(p);
00085 }
00086 }
00087
00088 void Predictor::movePredicted(const TomGine::tgPose& poseIn, TomGine::tgPose& poseOut, float &c){
00089 poseOut = poseIn;
00090 c = 0.0;
00091 }
00092
00093
00094
00095 void Predictor::resample(Distribution& d, int num_particles, Particle variance, bool useMotion){
00096
00097 if(d.size() <= 0)
00098 return;
00099
00100 unsigned n, id;
00101
00102 float sigma = 0.01f;
00103 float c=0.0f;
00104
00105
00106
00107
00108 if(num_particles<=0){
00109 ROS_DEBUG("[Distribution::resample] Warning number of particles to low (0)");
00110 num_particles = d.size();
00111 }
00112
00113 ParticleList particlelist_tmp;
00114 d.copy(particlelist_tmp);
00115 d.clear();
00116
00117
00118
00119
00120 for( id=0;
00121 id<particlelist_tmp.size() &&
00122 d.size()<(int)(num_particles*(1.0f - m_noConvergence));
00123 id++)
00124 {
00125
00126
00127 n = (unsigned)round(particlelist_tmp[id].w * num_particles);
00128 c = particlelist_tmp[id].c;
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 sigma = 1.0f - c;
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161 if(sigma==0.0) sigma = 0.001f;
00162 if(sigma>1.0) sigma = 1.0f;
00163 sampleFromGaussian(d, n, particlelist_tmp[id], variance, sigma);
00164 }
00165
00167
00168
00169
00170
00171
00172
00173
00174
00176 if(m_noConvergence > 0.0f){
00177 n = num_particles - d.size();
00178
00179 Particle p = particlelist_tmp[0];
00180 sampleFromGaussian(d, n, p, variance, 1.0f);
00181 }
00182 }
00183
00184 void Predictor::sample(Distribution& d, int num_particles, Particle mean, Particle variance){
00185 d.clear();
00186 sampleFromGaussian(d, num_particles, mean, variance);
00187 }
00188
00189 void Predictor::updateTime(double dTime){
00190 m_dTime = dTime;
00191 }