//------------------------------------------------------ // module : Tp4-IFT2425-1.c // author : // date : // version : 1.0 // language: C++ // note : //------------------------------------------------------ // //------------------------------------------------ // FICHIERS INCLUS ------------------------------- //------------------------------------------------ #include #include #include #include #include /************************************************************************/ /* WINDOWS */ /************************************************************************/ #include #include Display *display; int screen_num; int depth; Window root; Visual* visual; GC gc; //------------------------------------------------ // DEFINITIONS ----------------------------------- //------------------------------------------------ #define CARRE(X) ((X)*(X)) #define OUTPUT_FILE "Tp4-Img-I.pgm" #define VIEW_PGM "xv" #define DEBUG 0 //-Cst-Modele #define X_1 0.0 #define Y_1 1.0 #define X_2 -1.0/sqrt(2.0) #define Y_2 -1.0/2.0 #define X_3 +1.0/2*sqrt(2.0) #define Y_3 -1.0/2.0 #define C 0.25 #define R 0.1 #define D 0.3 #define X_1_INI 0.2 #define X_2_INI 0.0 #define X_3_INI -1.6 #define X_4_INI 0.0 //-Cst-Runge-Kutta #define H 0.0001 #define T_0 0.0 #define T_F 30.0 #define NB_INTERV (T_F-T_0)/H //-Cst-Image #define WIDTH 512 #define HEIGHT 512 #define MAX_X 4.0 #define MAX_Y 4.0 #define EVOL_GRAPH 3000 #define WHITE 255 #define GREYWHITE 230 #define GREY 200 #define GREYDARK 120 #define BLACK 0 //------------------------------------------------ // GLOBAL CST ------------------------------------ //------------------------------------------------ float Xmin=0.0; float Xmax=0.0; float Ymin=0.0; float Ymax=0.0; float xx_1=((WIDTH/MAX_X)*X_1)+(WIDTH/2); float yy_1=(-(HEIGHT/MAX_Y)*Y_1)+(HEIGHT/2); float xx_2=((WIDTH/MAX_X)*X_2)+(WIDTH/2); float yy_2=(-(HEIGHT/MAX_Y)*Y_2)+(HEIGHT/2); float xx_3=((WIDTH/MAX_X)*X_3)+(WIDTH/2); float yy_3=(-(HEIGHT/MAX_Y)*Y_3)+(HEIGHT/2); /************************************************************************/ /* OPEN_DISPLAY() */ /************************************************************************/ int open_display() { if ((display=XOpenDisplay(NULL))==NULL) { printf("Connection impossible\n"); return(-1); } else { screen_num=DefaultScreen(display); visual=DefaultVisual(display,screen_num); depth=DefaultDepth(display,screen_num); root=RootWindow(display,screen_num); return 0; } } /************************************************************************/ /* FABRIQUE_WINDOW() */ /* Cette fonction crée une fenetre X et l'affiche à l'écran. */ /************************************************************************/ Window fabrique_window(char *nom_fen,int x,int y,int width,int height,int zoom) { Window win; XSizeHints size_hints; XWMHints wm_hints; XClassHint class_hints; XTextProperty windowName, iconName; char *name=nom_fen; if(zoom<0) { width/=-zoom; height/=-zoom; } if(zoom>0) { width*=zoom; height*=zoom; } win=XCreateSimpleWindow(display,root,x,y,width,height,1,0,255); size_hints.flags=PPosition|PSize|PMinSize; size_hints.min_width=width; size_hints.min_height=height; XStringListToTextProperty(&name,1,&windowName); XStringListToTextProperty(&name,1,&iconName); wm_hints.initial_state=NormalState; wm_hints.input=True; wm_hints.flags=StateHint|InputHint; class_hints.res_name=nom_fen; class_hints.res_class=nom_fen; XSetWMProperties(display,win,&windowName,&iconName, NULL,0,&size_hints,&wm_hints,&class_hints); gc=XCreateGC(display,win,0,NULL); XSelectInput(display,win,ExposureMask|KeyPressMask|ButtonPressMask| ButtonReleaseMask|ButtonMotionMask|PointerMotionHintMask| StructureNotifyMask); XMapWindow(display,win); return(win); } /****************************************************************************/ /* CREE_XIMAGE() */ /* Crée une XImage à partir d'un tableau de float */ /* L'image peut subir un zoom. */ /****************************************************************************/ XImage* cree_Ximage(float** mat,int z,int length,int width) { int lgth,wdth,lig,col,zoom_col,zoom_lig; float somme; unsigned char pix; unsigned char* dat; XImage* imageX; /*Zoom positiv*/ /*------------*/ if (z>0) { lgth=length*z; wdth=width*z; dat=(unsigned char*)malloc(lgth*(wdth*4)*sizeof(unsigned char)); if (dat==NULL) { printf("Impossible d'allouer de la memoire."); exit(-1); } for(lig=0;lig0)&&(y_co>0)) MatPict[y_co][x_co]=BLACK; } } //------------------------------------------------------------------------ // Fill_Pict //------------------------------------------------------------------------ void Fill_Pict(float** MatPts,float** MatPict,int PtsNumber,int NbPts) { int i,j; int x_co,y_co; int k,k_Init,k_End; //Init for(i=0;i0)&&(y_co>0)) MatPict[y_co][x_co]=BLACK; } } //------------------------------------------------ // FONCTIONS TPs---------------------------------- //------------------------------------------------ //---------------------------------------------------------- //---------------------------------------------------------- // MAIN //---------------------------------------------------------- //---------------------------------------------------------- int main (int argc, char **argv) { int i,j,k; int flag_graph; int zoom; XEvent ev; Window win_ppicture; XImage *x_ppicture; char nomfen_ppicture[100]; char BufSystVisu[100]; //>AllocMemory float** MatPict=dmatrix_allocate_2d(HEIGHT,WIDTH); float** MatPts=dmatrix_allocate_2d((int)(NB_INTERV),2); //>Init for(i=0;iQuestion 1 //--------------------------------------------------------------------- //Il faut travailler ici ...et dans > // FONCTIONS TPs //Un exemple ou la matrice de points est remplie //par une courbe donné par l'équation d'en bas... et non pas par //la solution de l'équation différentielle for(k=0;k<(int)(NB_INTERV);k++) { MatPts[k][0]=(k/(float)(NB_INTERV))*cos((k*0.0001)*3.14159); MatPts[k][1]=(k/(float)(NB_INTERV))*sin((k*0.001)*3.14159); //>on peut essayer la ligne d'en bas aussi //MatPts[k][1]=(k/(float)(NB_INTERV))*sin((k*0.0001)*3.14159); } //--Fin Question 1----------------------------------------------------- //>Affichage des Points dans MatPict plot_point(MatPts,MatPict,(int)(NB_INTERV)); //>Save&Visu de MatPict SaveImagePgm(OUTPUT_FILE,MatPict,HEIGHT,WIDTH); strcpy(BufSystVisu,VIEW_PGM); strcat(BufSystVisu," "); strcat(BufSystVisu,OUTPUT_FILE); strcat(BufSystVisu," &"); system(BufSystVisu); //>Affiche Statistique printf("\n\n Stat: Xmin=[%.2f] Xmax=[%.2f] Ymin=[%.2f] Ymax=[%.2f]\n",Xmin,Xmax,Ymin,Ymax); //-------------------------------------------------------------------------------- //-------------- visu sous XWINDOW de l'évolution de MatPts ---------------------- //-------------------------------------------------------------------------------- if (flag_graph) { //>Uuverture Session Graphique if (open_display()<0) printf(" Impossible d'ouvrir une session graphique"); sprintf(nomfen_ppicture,"Évolution du Graphe"); win_ppicture=fabrique_window(nomfen_ppicture,10,10,HEIGHT,WIDTH,zoom); x_ppicture=cree_Ximage(MatPict,zoom,HEIGHT,WIDTH); printf("\n\n Pour quitter,appuyer sur la barre d'espace"); fflush(stdout); //>Boucle Evolution for(i=0;iwidth,x_ppicture->height); } } //>Retour printf("\n Fini... \n\n\n"); return 0; }