00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #define _CRT_SECURE_NO_DEPRECATE
00019 #include "FAPFrame.h"
00020 #include <iostream>
00021 #include <sstream>
00022
00023 extern FILE*face_log;
00024
00025 FAPFrame::FAPFrame(void)
00026 {
00027 isKeyFrame=false;
00028
00029 this->eyesdir.h=0;
00030 this->eyesdir.v=0;
00031 this->headdir.h=0;
00032 this->headdir.v=0;
00033 this->headdir.t=0;
00034 this->headmov.type="";
00035 this->headmov.amplitude=0;
00036 this->headmov.period=0;
00037 this->eyesdir.active=false;
00038 this->headdir.active=false;
00039 this->headmov.active=false;
00040 this->probability=1;
00041 this->TCBParam[Tension]=1;
00042 this->TCBParam[Continuity]=0;
00043 this->TCBParam[Bias]=0;
00044 this->use_at=-1;
00045 this->use_before=-1;
00046 this->received_at=-1;
00047
00048 this->DeactivateAll();
00049
00050 framenumber=0;
00051
00052 id="";
00053 }
00054
00055 FAPFrame::~FAPFrame(void)
00056 {
00057 }
00058
00059 float FAPFrame::GetTCBParam(TCBParamType which)
00060 {
00061 return TCBParam[which];
00062 }
00063
00064 void FAPFrame::ActivateAllFAPs(void)
00065 {
00066 for(int i=0;i<NUMBER_OF_FAPS;i++)
00067 this->FAPs[i].active=true;
00068 }
00069
00070 void FAPFrame::DeactivateAll(void)
00071 {
00072 for(int i=0;i<NUMBER_OF_FAPS;i++)
00073 this->FAPs[i].active=false;
00074 }
00075
00076 void FAPFrame::ResetAllToZero()
00077 {
00078 for(int i=0;i<NUMBER_OF_FAPS;i++)
00079 {
00080 this->FAPs[i].active=false;
00081 this->FAPs[i].value=0;
00082 }
00083 }
00084
00085
00086
00087 void FAPFrame::ActivateAndSetAllFAPsTo(int v)
00088 {
00089 for(int i=0;i<NUMBER_OF_FAPS;i++)
00090 {
00091 this->FAPs[i].active=true;
00092 this->FAPs[i].value=v;
00093 }
00094 }
00095
00096 int FAPFrame::SetFAP(int num, int value, bool active)
00097 {
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 if((num>=NUMBER_OF_FAPS) || (num<0))
00109 return 0;
00110
00111 FAPs[num].value=value;
00112 FAPs[num].active=active;
00113
00114
00115
00116 return 1;
00117 }
00118
00119 int FAPFrame::AddToFAP(int num, int value)
00120 {
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 if((num>=NUMBER_OF_FAPS) || (num<0))
00133 return 0;
00134
00135 FAPs[num].value=FAPs[num].value+value;
00136 FAPs[num].active=true;
00137
00138 return 1;
00139 }
00140
00141 int FAPFrame::GetFAP(int num)
00142 {
00143 return FAPs[num].value;
00144 }
00145
00146 void FAPFrame::Print()
00147 {
00148 int i;
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 for(i=0;i<NUMBER_OF_FAPS;i++)
00175 {
00176 if(this->FAPs[i].active)
00177 printf("1 ");
00178 else
00179 printf("0 ");
00180 }
00181 printf("\n");
00182 for(i=0;i<NUMBER_OF_FAPS;i++)
00183 {
00184 printf("%d ",this->FAPs[i].value);
00185 }
00186 printf("\n");
00187 if(eyesdir.active)
00188 printf("eyesdir h:%f v:%f\n",this->eyesdir.h,this->eyesdir.v);
00189 if(headdir.active)
00190 printf("headdir h:%f v:%f t:%f\n",this->headdir.h,this->headdir.v,this->headdir.t);
00191 if(headmov.active)
00192 printf("headmov type:%s ampl:%f period:%f\n",this->headmov.type.c_str(),this->headmov.amplitude,this->headmov.period);
00193 printf("\n");
00194 }
00195
00196 void FAPFrame::MergeFAP(int num, int value)
00197 {
00198
00199
00200 FAPs[num].value=FAPs[num].value+value;
00201 FAPs[num].active=true;
00202
00203 }
00204
00205 void FAPFrame::CopyFrom(FAPFrame*origin)
00206 {
00207 for(int i=0;i<NUMBER_OF_FAPS;i++)
00208 {
00209 this->FAPs[i].value=origin->FAPs[i].value;
00210 this->FAPs[i].active=origin->FAPs[i].active;
00211 }
00212 }
00213
00214 void FAPFrame::MergeFrom(FAPFrame*origin)
00215 {
00216 for(int i=0;i<NUMBER_OF_FAPS;i++)
00217 {
00218 if(origin->FAPs[i].active)
00219 {
00220 this->FAPs[i].value=origin->FAPs[i].value;
00221 this->FAPs[i].active=origin->FAPs[i].active;
00222 }
00223 }
00224 }
00225
00226 FAPFrame*FAPFrame::GetCorrespondingZeroFrame()
00227 {
00228 FAPFrame*f;
00229 f=new FAPFrame();
00230 for(int i=0;i<NUMBER_OF_FAPS;i++)
00231 {
00232 if(this->FAPs[i].active)
00233 f->SetFAP(i,0);
00234 }
00235 return f;
00236 }
00237
00238 void FAPFrame::SaveToFile(FILE*f,int num)
00239 {
00240
00241 fprintf(f,"%s",WriteFAP(num));
00242 }
00243
00244 std::string FAPFrame::WriteFAP(int num)
00245 {
00246 char s[30];
00247 std::ostringstream buffer,buffer2;
00248 std::string mask("");
00249 std::string data("");
00250
00251
00252 int i = 0;
00253 for(i=1;i<NUMBER_OF_FAPS;i++)
00254 {
00255 if(this->FAPs[i].active)
00256 mask.append("1 ");
00257 else
00258 mask.append("0 ");
00259 }
00260 mask.append("\n");
00261 _itoa(num,s,10);
00262 data.append(s);
00263 data.append(" ");
00264 for(i=1;i<NUMBER_OF_FAPS;i++)
00265 {
00266 if(this->FAPs[i].active)
00267 {
00268 _itoa(FAPs[i].value,s,10);
00269 data.append(s);
00270 data.append(" ");
00271 }
00272 }
00273 data.append("\n");
00274 buffer2 << mask <<"\n"<<data<<"\n";
00275 return buffer2.str();
00276
00277 }
00278
00279 void FAPFrame::ReadFromBuffer(char*buffer)
00280 {
00281 int fapnum;
00282 for(fapnum=1;fapnum<NUMBER_OF_FAPS;fapnum++)
00283 {
00284 sscanf(buffer,"%d",&FAPs[fapnum].active);
00285 while((buffer[0]!=' ')&&(buffer[0]!=0))
00286 buffer++;
00287 if(buffer!=0)
00288 buffer++;
00289 else
00290 break;
00291 }
00292
00293 while((buffer[0]=='\n')||(buffer[0]=='\t')||(buffer[0]==' '))
00294 buffer++;
00295
00296 for(fapnum=0;fapnum<NUMBER_OF_FAPS;fapnum++)
00297 {
00298 if(fapnum==0)
00299 {
00300 sscanf(buffer,"%d",&FAPs[0].value);
00301 this->framenumber=FAPs[0].value;
00302 while((buffer[0]!=' ')&&(buffer[0]!=0))
00303 buffer++;
00304 if(buffer!=0)
00305 buffer++;
00306 else
00307 break;
00308 }
00309 else
00310 {
00311 if(FAPs[fapnum].active)
00312 {
00313 sscanf(buffer,"%d",&FAPs[fapnum].value);
00314 while((buffer[0]!=' ')&&(buffer[0]!=0))
00315 buffer++;
00316 if(buffer!=0)
00317 buffer++;
00318 else
00319 break;
00320 }
00321 }
00322 }
00323 }
00324
00325 void FAPFrame::SetTCBParam(float T, float C, float B)
00326 {
00327 TCBParam[Tension]=T;
00328 TCBParam[Continuity]=C;
00329 TCBParam[Bias]=B;
00330 }
00331
00332 void FAPFrame::SetTension(float T)
00333 {
00334 TCBParam[Tension]=T;
00335 }
00336
00337 void FAPFrame::SetContinuity(float C)
00338 {
00339 TCBParam[Continuity]=C;
00340 }
00341
00342 void FAPFrame::SetBias(float B)
00343 {
00344 TCBParam[Bias]=B;
00345 }
00346
00347 bool FAPFrame::operator<(FAPFrame& a)
00348 {
00349 if(this->use_at<a.use_at)
00350 return true;
00351 else
00352 return false;
00353 }
00354
00355 std::string FAPFrame::toString()
00356 {
00357 int fapnum;
00358 std::string ff="";
00359 char st[256];
00360
00361 for(fapnum=1;fapnum<NUMBER_OF_FAPS;fapnum++)
00362 {
00363 sprintf_s(st,256,"%d", FAPs[fapnum].active);
00364 ff+=(std::string)st + " ";
00365 }
00366 ff+="\n";
00367
00368
00369 sprintf_s(st,256,"%d", this->framenumber);
00370 ff+=(std::string)st + " ";
00371
00372
00373 for(fapnum=1;fapnum<NUMBER_OF_FAPS;fapnum++)
00374 if(FAPs[fapnum].active==true)
00375 {
00376 sprintf_s(st,256,"%d", GetFAP(fapnum));
00377 ff+=(std::string)st + " ";
00378 }
00379 ff+="\n";
00380 return ff;
00381 }
00382
00383 FAPFrame FAPFrame::clone()
00384 {
00385 FAPFrame newone;
00386
00387
00388 newone.eyesdir.h=this->eyesdir.h;
00389 newone.eyesdir.v=this->eyesdir.v;
00390
00391 newone.headdir.h=this->headdir.h;
00392 newone.headdir.v=this->headdir.v;
00393 newone.headdir.t=this->headdir.t;
00394
00395 newone.headmov.type=this->headmov.type;
00396 newone.headmov.amplitude=this->headmov.amplitude;
00397 newone.headmov.period=this->headmov.period;
00398
00399 newone.eyesdir.active=this->eyesdir.active;
00400 newone.headdir.active=this->headdir.active;
00401 newone.headmov.active=this->headmov.active;
00402
00403 newone.probability=this->probability;
00404
00405 newone.TCBParam[Tension]=this->TCBParam[Tension];
00406 newone.TCBParam[Continuity]=this->TCBParam[Continuity];
00407 newone.TCBParam[Bias]=this->TCBParam[Bias];
00408
00409 newone.use_at=this->use_at;
00410 newone.use_before=this->use_before;
00411 newone.received_at=this->received_at;
00412
00413 newone.framenumber=this->framenumber;
00414
00415 newone.id=this->id;
00416
00417 newone.isKeyFrame=this->isKeyFrame;
00418
00419 newone.FAPs[NUMBER_OF_FAPS];
00420
00421
00422 int i = 0;
00423 for (i=0;i<NUMBER_OF_FAPS;i++){
00424 newone.FAPs[i]=this->FAPs[i];
00425 }
00426 return newone;
00427 }