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/mtt_draw.h>
00033 
00034 void DrawGlobal(char key,IplImage*img,t_config*config,t_data*data,t_object**objects,int object_size,t_list*list,t_flag*flags,int laser,bool raw_only)
00035 {
00036         static bool d_help=true;
00037         static bool d_occlusionzone=false;
00038         static bool d_velocity=true;
00039         static bool d_objects=true;
00040         static bool d_raw=false;
00041         static bool d_searcharea=true;
00042         static bool d_paths=true;
00043         static bool d_ids=true;
00044         char help_msg[1024];
00045         static bool init=true;
00046         
00047         static CvFont fontTitle;
00048         static CvFont fontText;
00049         
00050         if(init)
00051         {
00052                 if(raw_only)
00053                 {
00054                         d_help=false;
00055                         d_occlusionzone=false;
00056                         d_velocity=false;
00057                         d_objects=false;
00058                         d_raw=true;
00059                         d_searcharea=false;
00060                         d_paths=false;
00061                         d_ids=false;
00062                 }
00063                 cvInitFont(&fontTitle,CV_FONT_HERSHEY_SIMPLEX ,.6,.6,0.,1,CV_AA);
00064                 cvInitFont(&fontText,CV_FONT_HERSHEY_SIMPLEX,.4,.4,0.,1,CV_AA);
00065                 init=false;
00066         }
00067         
00068         switch(key)
00069         {
00070                 case 'h':
00071                 case 'H':
00072                         d_help=!d_help;
00073                         break;
00074                 case 'z':
00075                 case 'Z':
00076                         d_occlusionzone=!d_occlusionzone;
00077                         break;
00078                 case 'v':
00079                 case 'V':
00080                         d_velocity=!d_velocity;
00081                         break;
00082                 case 'o':
00083                 case 'O':
00084                         d_objects=!d_objects;
00085                         break;
00086                 case 'r':
00087                 case 'R':
00088                         d_raw=!d_raw;
00089                         break;
00090                 case 's':
00091                 case 'S':
00092                         d_searcharea=!d_searcharea;
00093                         break;
00094                 case 'p':
00095                 case 'P':
00096                         d_paths=!d_paths;
00097                         break;
00098                 case 'i':
00099                 case 'I':
00100                         d_ids=!d_ids;
00101                         break;
00102         }
00103         
00104         draw_ambient(img,config);               
00105         
00106         if(d_occlusionzone)
00107                 draw_oclusion_area(img,objects,object_size,CV_RGB(50,50,155),config);
00108         
00109         if(d_raw)
00110                 draw_raw_data(img,data,CV_RGB(0,255,0),config,flags);
00111         
00112         if(d_objects)
00113         {
00114                 draw_objects(img,objects,object_size,CV_RGB(255,0,0),config,flags);
00115                 draw_objects_centers(img,objects,object_size,CV_RGB(0,255,0),config,flags);
00116         }       
00117         
00118         if(d_paths)
00119         {
00120                 DrawListPaths(img,list,config);
00121                 DrawListCenters(img,list,CV_RGB(255,255,255),config);
00122         }
00123         
00124         if(d_ids)
00125                 DrawListIds(img,list,CV_RGB(0,200,0),config);
00126         
00127         if(d_searcharea)
00128                 DrawSearchArea(img,list,config);
00129         
00130         if(d_velocity)
00131                 DrawVelocity(img,list,config);
00132         
00133         if(d_help)
00134         {
00135                 
00136                 
00137                 strcpy(help_msg,"Keyboard Shortcuts");
00138                 cvPutText(img,help_msg,cvPoint(10,20),&fontTitle,CV_RGB(255,120,71));
00139                 strcpy(help_msg,"h - this message");
00140                 cvPutText(img,help_msg,cvPoint(10,40),&fontText,CV_RGB(200,200,71));
00141                 strcpy(help_msg,"z - occlusion zones");
00142                 cvPutText(img,help_msg,cvPoint(10,60),&fontText,CV_RGB(200,200,71));
00143                 strcpy(help_msg,"v - velocity");
00144                 cvPutText(img,help_msg,cvPoint(10,80),&fontText,CV_RGB(200,200,71));
00145                 strcpy(help_msg,"o - objects");
00146                 cvPutText(img,help_msg,cvPoint(10,100),&fontText,CV_RGB(200,200,71));
00147                 strcpy(help_msg,"r - raw data");
00148                 cvPutText(img,help_msg,cvPoint(10,120),&fontText,CV_RGB(200,200,71));
00149                 strcpy(help_msg,"s - search zones");
00150                 cvPutText(img,help_msg,cvPoint(10,140),&fontText,CV_RGB(200,200,71));
00151                 strcpy(help_msg,"p - paths");
00152                 cvPutText(img,help_msg,cvPoint(10,160),&fontText,CV_RGB(200,200,71));
00153                 strcpy(help_msg,"i - ids");
00154                 cvPutText(img,help_msg,cvPoint(10,180),&fontText,CV_RGB(200,200,71));
00155                 strcpy(help_msg,"q - quit");
00156                 cvPutText(img,help_msg,cvPoint(10,200),&fontText,CV_RGB(200,200,71));
00157         }
00158 }
00159 
00160 void DrawListPaths(IplImage*img,t_list*list,t_config*config)
00161 {
00162         CvPoint A;
00163         CvPoint B;
00164         
00165         while(list!=null)
00166         {
00167                 if(list->timers.lifetime<config->display_min_lifetime)
00168                 {
00169                         list=list->next;
00170                         continue;
00171                 }
00172                 
00173                 if(list->classification.velocity_classification==STATIONARY)
00174                 {
00175                         list=list->next;
00176                         continue;
00177                 }
00178                 
00179                 if(list->model==CV)
00180                 {
00181                         for(unsigned int i=0;i<list->path_cv.number_points-1;i++)
00182                         {       
00183                                 if(i==list->path_cv.position-1)
00184                                         continue;
00185                                 
00186                                 A=cvPoint(real2print(list->path_cv.x[i],config),real2print(list->path_cv.y[i],config));
00187                                 B=cvPoint(real2print(list->path_cv.x[i+1],config),real2print(list->path_cv.y[i+1],config));
00188                                 
00189                                 if(A.x > img->width || A.y > img->height || A.x < 0|| A.y < 0 || B.x > img->width || B.y > img->height || B.x < 0|| B.y < 0)
00190                                 {
00191                                         
00192                                 }else
00193                                         cvLine(img,A,B,CV_RGB(220,150,50),1,8,0);
00194                         }
00195                 }
00196                 else
00197                 {
00198                         for(unsigned int i=0;i<list->path_ca.number_points-1;i++)
00199                         {       
00200                                 if(i==list->path_ca.position)
00201                                         continue;
00202                                 
00203                                 A=cvPoint(real2print(list->path_ca.x[i],config),real2print(list->path_ca.y[i],config));
00204                                 B=cvPoint(real2print(list->path_ca.x[i+1],config),real2print(list->path_ca.y[i+1],config));
00205                                 
00206                                 if(A.x > img->width || A.y > img->height || A.x < 0|| A.y < 0 || B.x > img->width || B.y > img->height || B.x < 0|| B.y < 0)
00207                                 {
00208                                         
00209                                 }else
00210                                         cvLine(img,A,B,CV_RGB(220,0,150),1,8,0);
00211                         }
00212                 }
00213                 list=list->next;
00214         }
00215 }
00216 
00217 void DrawSearchArea(IplImage*img,t_list*list,t_config*config)
00218 {
00219         CvPoint I;
00220         double px,py,ellipse_A,ellipse_B,ellipse_angle;
00221         
00222         while(list!=null)
00223         {
00224                 if(list->timers.lifetime<config->display_min_lifetime)
00225                 {
00226                         list=list->next;
00227                         continue;
00228                 }
00229                 
00230                 if(list->classification.velocity_classification==STATIONARY)
00231                 {
00232                         list=list->next;
00233                         continue;
00234                 }
00235                 
00236                 px=list->position.predicted_x;
00237                 py=list->position.predicted_y;
00238                 
00239                 I=cvPoint(real2print(px,config),real2print(py,config));
00240                 
00241                 ellipse_A=list->search_area.ellipse_A;
00242                 ellipse_B=list->search_area.ellipse_B;
00243                 ellipse_angle=list->search_area.angle;
00244                 
00245                 if(list->timers.occludedtime > 0){}
00246                 
00247                 else
00248                         cvEllipse(img,I, cvSize(real2print(ellipse_A,config),real2print(ellipse_B,config)),ellipse_angle*180./M_PI,360,0,CV_RGB(50,250,100),1,8,0);
00249                 
00250                 list=list->next;
00251         }
00252 }
00253 
00254 void DrawListCenters(IplImage*img,t_list*list,CvScalar color,t_config*config)
00255 {
00256         double x,y;
00257         CvPoint a;
00258         
00259         while(list!=null)
00260         {
00261                 if(list->timers.lifetime<config->display_min_lifetime)
00262                 {
00263                         list=list->next;
00264                         continue;
00265                 }
00266                 
00267                 x=list->position.estimated_x;
00268                 y=list->position.estimated_y;
00269                 
00270                 a=cvPoint(real2print(x,config),real2print(y,config));
00271                 
00272                 cvLine(img,a,a,color,4, 8, 0 );
00273                 
00274                 list=list->next;
00275         }
00276 }
00277 
00278 void DrawVelocity(IplImage*img,t_list*list,t_config*config)
00279 {
00280         double x,y;
00281         CvPoint a;
00282         
00283         while(list!=null)
00284         {
00285                 if(list->timers.lifetime<config->display_min_lifetime)
00286                 {
00287                         list=list->next;
00288                         continue;
00289                 }
00290                 
00291                 if(list->classification.velocity_classification==STATIONARY)
00292                 {
00293                         list=list->next;
00294                         continue;
00295                 }
00296                 
00297                 x=list->position.estimated_x;
00298                 y=list->position.estimated_y;
00299                 
00300                 a=cvPoint(real2print(x,config),real2print(y,config));
00301                 double velocity_angle=atan2(list->velocity.velocity_y,list->velocity.velocity_x);
00302                 drawarrow(a.x,a.y,velocity_angle, real2print(list->velocity.velocity_module,config), img, CV_RGB(0,100,255),2, 8, 0);
00303                 
00304                 list=list->next;
00305         }
00306 }
00307 
00308 void DrawListIds(IplImage*img,t_list*list,CvScalar color,t_config*config)
00309 {
00310         static CvFont font;
00311         double x,y;
00312         static bool initialise=true;
00313         char text[100];
00314         
00315         if(initialise)
00316         {
00317                 cvInitFont(&font,CV_FONT_HERSHEY_SIMPLEX,.5,.5,0.,1,8);
00318                 initialise=false;
00319         }
00320         
00321         while(list!=null)
00322         {
00323                 if(list->timers.lifetime<config->display_min_lifetime)
00324                 {
00325                         list=list->next;
00326                         continue;
00327                 }
00328                 
00329                 x=list->position.estimated_x;
00330                 y=list->position.estimated_y;
00331                 
00332                 
00333                 
00334                 sprintf(text,"%d",list->id);
00335                 if(list->classification.velocity_classification==STATIONARY)
00336                         cvPutText(img,text, cvPoint(real2print(x,config),real2print(y,config)),&font,color);
00337                 else
00338                         cvPutText(img,text, cvPoint(real2print(x,config),real2print(y,config)),&font,CV_RGB(255,0,0));
00339                 
00340                 list=list->next;
00341         }
00342 }
00343 
00353 void draw_objects_centers(IplImage*img,t_object**objects,int size,CvScalar color,t_config*config)
00354 {
00355         CvPoint a;
00356         int i;
00357         
00358         double x,y;
00359         
00360         for(i=0;i<size;i++)
00361         {                       
00362                 x=objects[i]->cx;
00363                 y=objects[i]->cy;
00364                 
00365                 a=cvPoint(real2print(x,config),real2print(y,config));
00366                 
00367                 if(objects[i]->object_found==true)
00368                         cvLine(img,a,a,color,4, 8, 0 );
00369                 else
00370                         cvLine(img,a,a,CV_RGB(253,0,0),4, 8, 0 );
00371         }
00372 }
00373 
00383 void draw_objects_ids(IplImage*img,t_object**objects,int size,CvScalar color,t_config*config)
00384 {
00385         static CvFont font;
00386         double x,y;
00387         static bool initialise=true;
00388         char text[100];
00389         int i;
00390         
00391         if(initialise)
00392         {
00393                 cvInitFont(&font,CV_FONT_HERSHEY_SIMPLEX,.5,.5,0.,1,8);
00394                 initialise=false;
00395         }
00396         
00397         for(i=0;i<size;i++)
00398         {
00399                 x=objects[i]->cx;
00400                 y=objects[i]->cy;
00401                 
00402                 sprintf(text,"%d",objects[i]->id);
00403                 cvPutText(img,text, cvPoint(real2print(x,config),real2print(y,config)),&font,color);
00404         }
00405 }
00406 
00417 void draw_objects(IplImage*img,t_object**objects,int size,CvScalar color,t_config*config)
00418 {
00419         CvPoint a,b;
00420         int i,e;
00421         
00422         for(i=0;i<size;i++)
00423         {       
00424                 for(e=0;e<objects[i]->n_lines;e++)
00425                 {
00426                         a=cvPoint(real2print(objects[i]->line[e]->xi,config),real2print(objects[i]->line[e]->yi,config));
00427                         b=cvPoint(real2print(objects[i]->line[e]->xf,config),real2print(objects[i]->line[e]->yf,config));
00428                         
00429                         if(objects[i]->object_found==true)
00430                                 cvLine(img,a,b,color,2, 8, 0 );
00431                         else
00432                                 cvLine(img,a,b,CV_RGB(253,156,64),2, 8, 0 );
00433                 }
00434         }
00435 }
00436 
00447 void draw_end_lines(IplImage*img,t_cluster**clusters,int size,t_data*data,t_config*config)
00448 {
00449         CvPoint O,I;
00450         int i;
00451         
00452         O=cvPoint(config->w/2,config->h/2);
00453         
00454         for(i=0;i<size;i++)
00455         {
00456                 I=cvPoint(real2print(data->x[clusters[i]->stp],config),real2print(data->y[clusters[i]->stp],config));
00457                 cvLine(img,O,I,CV_RGB(255,0,0),1, 8, 0 );
00458                 
00459                 I=cvPoint(real2print(data->x[clusters[i]->enp-1],config),real2print(data->y[clusters[i]->enp-1],config));
00460                 cvLine(img,O,I,CV_RGB(0,0,255),1, 8, 0 );
00461         }
00462 }
00463 
00474 void draw_clusters_npoints(IplImage*img,t_cluster**clusters,int size,t_data*data,t_config*config)
00475 {
00476         static char text[512];
00477         static CvFont font;
00478         static int initialise=true;
00479         
00480         if(initialise)
00481         {
00482                 cvInitFont(&font,CV_FONT_HERSHEY_SIMPLEX,.5,.5,0.,1,8);
00483                 initialise=false;
00484         }
00485         
00486         CvPoint I;
00487         int i;
00488         
00489         for(i=0;i<size;i++)
00490         {
00491                 I=cvPoint(real2print(data->x[clusters[i]->stp],config),real2print(data->y[clusters[i]->stp],config));
00492                 
00493                 sprintf(text,"NP %d",clusters[i]->n_points);
00494                 cvPutText(img,text,I,&font,CV_RGB(50,255,0));
00495         }
00496 }
00497 
00507 void draw_ambient(IplImage*img,t_config*config,enum_background_style style,int laser)
00508 {
00509         
00510         static CvPoint curve[4];
00511         static CvScalar ColorLaser,ColorBackground,ColorForeground;
00512         
00513         static bool init=true;
00514         
00515         if(init)
00516         {
00517                 if(laser==2)
00518                 {
00519                         
00520                         
00521                         
00522                         
00523                         curve[0]=cvPoint(0,config->h);
00524                         curve[1]=cvPoint(config->w/2,config->h/2);
00525                         curve[2]=cvPoint(config->w,config->h);
00526                         curve[3]=cvPoint(config->w,config->h);
00527                 }else if(laser==3)
00528                 {
00529                         curve[0]=cvPoint(0,config->h/2);
00530                         curve[1]=cvPoint(config->w/2,config->h/2);
00531                         curve[2]=cvPoint(config->w/2,config->h);        
00532                         curve[3]=cvPoint(0,config->h);
00533                 }else
00534                 {
00535                         curve[0]=cvPoint(0,config->h);
00536                         curve[1]=cvPoint(config->w/2,config->h/2);
00537                         curve[2]=cvPoint(config->w,config->h);
00538                         curve[3]=cvPoint(config->w,config->h);
00539                 }
00540                 
00541                 switch(style)
00542                 {
00543                         case STYLE_DARK:
00544                                 ColorLaser=CV_RGB(50,255,0);
00545                                 ColorBackground=CV_RGB(0,0,0);
00546                                 ColorForeground=CV_RGB(50,50,50);
00547                                 break;
00548                                 
00549                         case STYLE_LIGHT:
00550                                 ColorLaser=CV_RGB(50,255,0);
00551                                 ColorBackground=CV_RGB(255,255,255);
00552                                 ColorForeground=CV_RGB(100,100,100);
00553                                 break;
00554                                 
00555                         default:
00556                                 ColorLaser=CV_RGB(50,255,0);
00557                                 ColorBackground=CV_RGB(0,0,0);
00558                                 ColorForeground=CV_RGB(50,50,50);
00559                                 break;
00560                 }
00561                 
00562                 init=false;
00563         }
00564         
00565         
00566         
00567         cvSet( img, ColorForeground,NULL );     
00568         cvCircle(img, cvPoint(config->w/2,config->h/2),real2print(config->out_clip,config), ColorBackground,CV_FILLED );        
00569         cvCircle(img, cvPoint(config->w/2,config->h/2),real2print(config->in_clip,config), ColorForeground,CV_FILLED ); 
00570         cvFillConvexPoly(img,curve,4,ColorForeground,8,0);
00571         
00572         
00573 }
00574 
00582 void draw_midle_circle(IplImage*img,t_config*config)
00583 {
00584         cvCircle(img, cvPoint(config->w/2,config->h/2),real2print(config->in_clip,config), CV_RGB(50,50,50),CV_FILLED );        
00585 }
00586 
00596 void draw_clusters_centers(IplImage*img,t_cluster**clusters,int size,t_config*config)
00597 {
00598         int i;
00599         CvPoint a;
00600         double x,y,r,t;
00601         
00602         for(i=0;i<size;i++)
00603         {
00604                 r=clusters[i]->rmin;
00605                 t=clusters[i]->tm;
00606                 
00607                 x=config->maxr+r*cos(t);
00608                 y=config->maxr-r*sin(t);
00609                 
00610                 a=cvPoint(real2print(x,config),real2print(y,config));
00611                 cvLine(img,a,a,CV_RGB(0,255,0),6,8,0);
00612         }
00613 }
00614 
00615 
00626 void draw_oclusion_area(IplImage*img,t_object**list,int size,CvScalar color,t_config*config)
00627 {
00628         CvPoint O=cvPoint(config->w/2,config->h/2),line[4];
00629         double theta_i,theta_f;
00630         
00631         for(int i=0;i<size;i++)
00632         {
00633                 for(int e=0;e<list[i]->n_lines;e++)
00634                 {
00635                         line[0].x=real2print(list[i]->line[e]->xi,config);
00636                         line[0].y=real2print(list[i]->line[e]->yi,config);
00637                         theta_i=atan2(-(line[0].y-O.y),(line[0].x-O.x));
00638                         
00639                         line[1].x=real2print(list[i]->line[e]->xf,config);
00640                         line[1].y=real2print(list[i]->line[e]->yf,config);
00641                         theta_f=atan2(-(line[1].y-O.y),(line[1].x-O.x));
00642                         
00643                         line[3].x=config->maxr+1*config->maxr*cos(theta_i);     
00644                         line[3].y=config->maxr-1*config->maxr*sin(theta_i);     
00645                         
00646                         line[2].x=config->maxr+1*config->maxr*cos(theta_f);     
00647                         line[2].y=config->maxr-1*config->maxr*sin(theta_f);     
00648                         
00649                         for(int f=2;f<4;f++)
00650                         {
00651                                 line[f].x=real2print(line[f].x,config);
00652                                 line[f].y=real2print(line[f].y,config);
00653                         }
00654                         
00655                         cvFillConvexPoly(img,line,4,color,8,0);
00656                 }
00657         }
00658 }
00659 
00670 void draw_clusters_area(IplImage*img,t_cluster**clusters,int size,t_config*config,t_data*data)
00671 {
00672         int i,e;
00673         CvPoint a,b;
00674         static CvPoint O;
00675         
00676         CvPoint line[]={a,b,O};
00677         
00678         static bool initialise=true;
00679         
00680         if(initialise)
00681         {
00682                 O=cvPoint(config->w/2,config->h/2);
00683                 initialise=false;
00684         }
00685         
00686         for(i=0;i<size;i++)
00687                 for(e=clusters[i]->stp;e<clusters[i]->enp;e++)
00688                 {
00689                         a=cvPoint(real2print(data->x[e],config),real2print(data->y[e],config));
00690                         b=cvPoint(real2print(data->x[e+1],config),real2print(data->y[e+1],config));
00691                         
00692                         line[0]=O,line[1]=a;line[2]=b;
00693                         cvFillConvexPoly(img,line,3,CV_RGB(232,197,76),8,0);            
00694                 }       
00695 }
00696 
00707 void draw_clusters(IplImage*img,t_cluster**clusters,int size,t_data*data,t_config*config)
00708 {
00709         int i,e;
00710         CvPoint a;
00711         double R,G,B;
00712         
00713         R=255;
00714         G=255;
00715         B=255;
00716         
00717         for(e=0;e<size;e++)     
00718         {
00719 
00720 
00721 
00722         
00723         for(i=clusters[e]->stp;i<=clusters[e]->enp;i++)
00724         {
00725                 a=cvPoint(real2print(data->x[i],config),real2print(data->y[i],config));
00726                 cvLine(img,a,a,CV_RGB(R,G,B),2, 8, 0 );                 
00727         }
00728         
00729         
00730         
00731         }
00732 }
00733 
00743 void draw_raw_data(IplImage*img,t_data*data,CvScalar color,t_config*config)
00744 {
00745         int i;
00746         CvPoint a;
00747         for(i=0;i<data->n_points;i++)
00748         {
00749                 a=cvPoint(real2print(data->x[i],config),real2print(data->y[i],config));
00750                 if(data->flag[i]==false)
00751                 {
00752                         
00753                         cvLine(img,a,a,color,2,8,0);
00754                 }else
00755                         cvLine(img,a,a,CV_RGB(255,220,0),2,8,0);
00756                 
00757                 
00758                 
00759         }
00760         
00761 }
00762 
00772 void draw_raw_data_acc(IplImage*img,t_data_acc*data_acc,CvScalar color,t_config*config)
00773 {
00774         int i,e;
00775         CvPoint a;
00776         for(i=0;i<data_acc->n_scans;i++)
00777                 for(e=0;e<data_acc->data[i]->n_points;e++)
00778                 {
00779                         a=cvPoint(real2print(data_acc->data[i]->x[e],config),real2print(data_acc->data[i]->y[e],config));
00780                         cvLine(img,a,a,color,2,8,0);
00781                 }
00782 }
00783 
00798 void drawarrow(int x0, int y0, double o, double lenght, IplImage *dst, CvScalar color, int thickness, int line_type, int shift)
00799 {
00800         int x1,y1;
00801         x1 = x0 + lenght*cos(o);
00802         y1 = y0 + lenght*sin(o);
00803         
00804         CvPoint pt1 = cvPoint(x1 - lenght/3*cos(o+M_PI/4), y1 - lenght/3*sin(o+M_PI/4));
00805         CvPoint pt2 = cvPoint(x1 - lenght/3*cos(o-M_PI/4), y1 - lenght/3*sin(o-M_PI/4));
00806         
00807         cvLine( dst, cvPoint(x0,y0),cvPoint(x1,y1), color,thickness, line_type, shift);
00808         
00809         cvLine( dst, cvPoint(x1,y1),pt1, color,thickness, line_type, shift);
00810         cvLine( dst, cvPoint(x1,y1),pt2, color,thickness, line_type, shift);
00811 }