00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00032 #include <mtt/target.h>
00033
00034 ostream& operator<<(ostream& o,Target& t)
00035 {
00036 o<<"target: "<<t._id;
00037 o<<" (#"<<t._uid<<")";
00038 o<<" cluster: "<<t._cluster;
00039 o<<" hypothesis: "<<t._hypothesis;
00040 o<<" miss associations: "<<t._missed_associations;
00041 o<<" measurements size: "<<t._assigned_measurements.size();
00042 return o;
00043 }
00044
00045 void Target::incrementMissedAssociations(int inc)
00046 {
00047 stt=10;
00048
00049 _missed_associations+=inc;
00050 }
00051
00052 void Target::decrementMissedAssociations(int dec)
00053 {
00054 if(_missed_associations>0)
00055 _missed_associations-=dec;
00056 }
00057
00058 void Target::zeroMissedAssociations(void)
00059 {
00060 _missed_associations=0;
00061 }
00062
00063 double Target::getDistance(MeasurementPtr& mes,int algorithm)
00064 {
00065
00066 Vector2d measurement;
00067 Vector2d mean;
00068 Matrix2d covariance;
00069
00070
00071
00072 measurement(0)=mes->state[0];
00073 measurement(1)=mes->state[1];
00074
00075 mean(0)=_xp(0);
00076 mean(1)=_xp(1);
00077
00078 covariance(0,0)=_P(0,0);
00079 covariance(0,1)=_P(0,1);
00080
00081 covariance(1,0)=_P(1,0);
00082 covariance(1,1)=_P(1,1);
00083
00084 if(algorithm==0)
00085 {
00086 double val=mahalanobis(measurement,mean,covariance);
00087
00088 return val;
00089 }
00090 else if(algorithm==1)
00091 {
00092 double val=biVariatePDF(measurement,mean,covariance);
00093
00094 return val;
00095 }
00096 else if(algorithm==2)
00097 {
00098 double val=sqrt(pow(measurement(0)-mean(0),2)+pow(measurement(1)-mean(1),2));
00099 return val;
00100 }
00101
00102 return -1;
00103 }
00104
00105 Target::Target()
00106 {
00107 _hypothesis = -1;
00108 _cluster = -1;
00109
00110 _uid = _euid++;
00111 _missed_associations = -1;
00112 }
00113
00114 Target::~Target()
00115 {
00116
00117
00118
00119 }
00120
00121 Target::Target(TargetPtr prev_target)
00122 {
00123
00124 *this=*prev_target;
00125
00126
00127 initEstimator(prev_target->_x,prev_target->_P);
00128
00129
00130
00131
00132
00133
00134 assert(is_finite(prev_target->_x));
00135 assert(is_finite(prev_target->_P));
00136
00137 _id=prev_target->_id;
00138 _uid = _euid++;
00139
00140 Vector3d z;
00141
00142 z(0)=prev_target->_xp(0);
00143 z(1)=prev_target->_xp(1);
00144 z(2)=prev_target->_xp(3);
00145
00146 incrementMissedAssociations();
00147
00148 _estimator.miss_associations++;
00149 _estimator.life_time++;
00150
00151 _assigned_measurements.clear();
00152
00153
00154
00155 stepEstimator(z);
00156
00157
00158 if(_past_states.size()>500)
00159 _past_states.erase(_past_states.begin());
00160
00161 _past_states.push_back(_x);
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171 if(!is_finite(_xp))
00172 {
00173 const char COL_RESET[] = "\x1b[0m";
00174 const char RED[] = "\x1b[31m";
00175 cout << RED << "Error!!, Major" << COL_RESET << endl;
00176 cout<<"Bad failed target: "<<*this<<endl;
00177 }
00178
00179
00180
00181 }
00182
00183 Target::Target(TargetPtr prev_target,MeasurementPtr measurement)
00184 {
00185
00186
00187
00188 *this=*prev_target;
00189
00190 initEstimator(prev_target->_x,prev_target->_P);
00191
00192 _estimator.miss_associations=0;
00193 _estimator.life_time++;
00194
00195 _id=prev_target->_id;
00196 _uid = _euid++;
00197
00198
00199 _assigned_measurements.clear();
00200 _assigned_measurements.push_back(measurement);
00201
00202 zeroMissedAssociations();
00203
00204 assert(is_finite(measurement->state));
00205
00206
00207 stepEstimator(measurement->state);
00208
00209 if(_past_states.size()>500)
00210 _past_states.erase(_past_states.begin());
00211
00212 _past_states.push_back(_x);
00213
00214 if(!is_finite(_xp))
00215 cout<<"Bad normal target: "<<*this<<endl;
00216 }
00217
00218 Target::Target(MeasurementPtr measurement)
00219 {
00220
00221 Vector3d z = measurement->state;
00222
00223
00224 assert(is_finite(measurement->state));
00225
00226
00227 initEstimator(z);
00228
00229
00230 _past_states.clear();
00231 _past_states.push_back(_x);
00232
00233 _hypothesis = 0;
00234 _cluster = 0;
00235 _missed_associations = 0;
00236
00237 _estimator.miss_associations=0;
00238 _estimator.life_time=0;
00239
00240 if(!is_finite(_xp))
00241 cout<<"Bad new target: "<<*this<<endl;
00242
00243 _assigned_measurements.clear();
00244 _assigned_measurements.push_back(measurement);
00245
00246
00247
00248
00249
00250
00251
00252 _ntotal++;
00253 _id = _ntotal;
00254
00255
00256 _uid = _euid++;
00257
00258
00259 _exuid = measurement->id;
00260
00261
00262 cout<<"||||||||!!!!!!!!"<<endl;
00263 cout<<"_ntotal: "<<_ntotal<<endl;
00264 }
00265
00266 double Target::getDistanceToPredictedPosition(TargetPtr& target,int algorithm)
00267 {
00268
00269 Vector2d predicted_position;
00270 Vector2d mean;
00271 Matrix2d covariance;
00272
00273 predicted_position(0)=target->_xp(0);
00274 predicted_position(1)=target->_xp(1);
00275
00276 mean(0)=_xp(0);
00277 mean(1)=_xp(1);
00278
00279 covariance(0,0)=_P(0,0);
00280 covariance(0,1)=_P(0,1);
00281
00282 covariance(1,0)=_P(1,0);
00283 covariance(1,1)=_P(1,1);
00284
00285 if(algorithm==0)
00286 {
00287 double val=mahalanobis(predicted_position,mean,covariance);
00288
00289 return val;
00290 }
00291 else
00292 {
00293 double val=biVariatePDF(predicted_position,mean,covariance);
00294
00295 return val;
00296 }
00297 }
00298
00299 void Target::cleanTargetAssociations(void)
00300 {
00301 _assigned_measurements.clear();
00302 }
00303
00304 bool compareTargetsById(TargetPtr t1,TargetPtr t2)
00305 {
00306 return t1->_id<t2->_id;
00307 }
00308
00309 bool compareTargetsByAux1(TargetPtr t1,TargetPtr t2)
00310 {
00311 return t1->_aux1<t2->_aux1;
00312 }
00313
00314 bool compareTargetsByAux1Descending(TargetPtr t1,TargetPtr t2)
00315 {
00316 return t1->_aux1>t2->_aux1;
00317 }