mcreate_ima.c

00001 /*
00002 *    Copyright (c) 2007. The BATI team. All right reserved.
00003 *
00004 *    This file is part of BATI library.
00005 *
00006 *    BATI library is free software: you can redistribute it and/or modify
00007 *    it under the terms of the GNU General Public License as published by
00008 *    the Free Software Foundation, either version 3 of the License, or
00009 *    (at your option) any later version.
00010 *
00011 *    BATI library  is distributed in the hope that it will be useful,
00012 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 *    GNU General Public License for more details.
00015 *
00016 *    You should have received a copy of the GNU General Public License
00017 *    along with BATI library.  If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 /* ************************* mcreate_ima.c *******************************/
00020 /*                                                                       */
00021 /*          CREATION DE D'IMAGE TEST 8 (u1) / 16 (u2) / 32 (fl) bits)    */
00022 /*                                                                       */
00023 /*  Derniere modif : E. TROUVE, 09/07/00                                 */
00024 /* ***********************************************************************/
00025 
00042 #include "image.h"
00043 #include "proto2D.h"  /* descripteurs et prototypes des fonctions de ima2D */
00044 /* #include <stdlib.h> */
00045 
00046 int main(int argc, char *argv[]){
00047 
00048 /* DECLARATIONS */
00049 
00050   /* images */ 
00051   imau1 im0u1;          
00052   imau2 im0u2;          
00053   imau4 im0u4;          
00054   imafl im0fl;
00055           
00056   /* operateurs */
00057   write_ima_t wri;
00058 
00059   /* main */
00060   FILE *fp;
00061   char nomfich[200];
00062   int i, j, n, nbr, tmpi, *x0, *y0, *x1, *y1, dimX, dimY, t0, objet;
00063   float *tab, fond;
00064   param par0, *ptp;      /* tete et pointeur pour la chaine de parametres */
00065 
00066 
00067   /* LECTURE PARAMETRES */
00068 
00069   /* debut: OBLIGATOIRE pour compatibilite avec les 3 modes de lecture de param */
00070   param_debut(argc, argv, &par0); 
00071   ptp = &par0;      /* regle : ptp pointe sur la structure du parametre suivant */
00072 
00073   lec_param(">> Nombre de colonnes de l'image", ptp);
00074   dimX = atoi(ptp->rep);
00075   ptp = ptp->next;
00076  
00077   lec_param(">> Nombre de lignes de l'image", ptp);
00078   dimY = atoi(ptp->rep);
00079   ptp = ptp->next;
00080  
00081   ptp = write_ima_lect(&wri, ptp, 
00082               ">> Format : u1 (.ima|.ras), u2 (.imw), u4 (.iml) ou fl (.imf) :");
00083 
00084   lec_param(">> Valeur du fond", ptp);
00085   fond = (float)atof(ptp->rep);
00086   ptp = ptp->next;
00087 
00088   lec_param(">> Nom du fichier decrivant les objets", ptp);
00089   strcpy(nomfich, ptp->rep);
00090   ptp = ptp->next;  
00091 
00092   /* fin: sauvegarde des parametres utilises en mode MANUEL ou FICHIER */
00093   param_fin(argc, argv, &par0);
00094 
00095   /* INITIALISATION  */
00096   /* lecture fichier des objets */
00097   if( fp=fopen(nomfich,"r") ){
00098       fscanf(fp,"%d", &nbr);
00099       x0 = (int *)malloc(nbr*sizeof(int));
00100       y0 = (int *)malloc(nbr*sizeof(int));
00101       x1 = (int *)malloc(nbr*sizeof(int));
00102       y1 = (int *)malloc(nbr*sizeof(int));
00103       tab = (float *)malloc(nbr*sizeof(float));          
00104       if (x0==NULL || y0==NULL || x1==NULL || y1==NULL || tab==NULL ){
00105           printf("\n>> ERREUR : allocation impossible\n");
00106           exit(1);
00107       } 
00108       printf("\n>> L'image contiendra un fond a %f et %d objets : \n", fond, nbr);
00109       for(n=0; n<nbr; n++){
00110           fscanf(fp, "%d %d %d %d %f", x0+n, y0+n, x1+n, y1+n, tab+n);
00111           printf("objet %d :\t x0=%d,\t y0=%d,\t x1=%d,\t y1=%d,\t val=%f\n", 
00112                  n+1, x0[n], y0[n], x1[n], y1[n], tab[n]);
00113       }  
00114       fclose(fp);
00115   }
00116   else{
00117       printf("\n>> ERREUR : fichier %s introuvable\n", nomfich);
00118       exit(1);
00119   }
00120   /* image resultat */
00121   write_ima_init(&wri);
00122   if( !strcmp(wri.ext, "ima") || !strcmp(wri.ext, "ras")){
00123       t0 = 1;
00124       im0u1.nc = dimX;
00125       im0u1.nr = dimY;
00126       alloc_imau1(&im0u1);      
00127       for(j=0; j<dimY; j++)
00128           for(i=0; i<dimX; i++)
00129               im0u1.p[j][i] = (pixu1)fond;
00130   }
00131   else if(!strcmp(wri.ext, "imw")){
00132       t0 = 2;
00133       im0u2.nc = dimX;
00134       im0u2.nr = dimY;
00135       alloc_imau2(&im0u2);      
00136       for(j=0; j<dimY; j++)
00137           for(i=0; i<dimX; i++)
00138               im0u2.p[j][i] = (pixu2)fond;
00139   }
00140   else if(!strcmp(wri.ext, "iml")){
00141       t0 = 3;
00142       im0u4.nc = dimX;
00143       im0u4.nr = dimY;
00144       alloc_imau4(&im0u4);      
00145       for(j=0; j<dimY; j++)
00146           for(i=0; i<dimX; i++)
00147               im0u4.p[j][i] = (pixu4)fond;
00148   }
00149   else if(!strcmp(wri.ext, "imf")){
00150       t0 = 4;
00151       im0fl.nc = dimX;
00152       im0fl.nr = dimY;
00153       alloc_imafl(&im0fl);      
00154       for(j=0; j<dimY; j++)
00155           for(i=0; i<dimX; i++)
00156               im0fl.p[j][i] = (pixfl)fond;
00157   }
00158   else{
00159       printf("\n ERREUR : extension %s inconnue (.ima|.ras|.imw|.imf attendu)\n", wri.ext);
00160       exit(0);
00161   }   
00162 
00163   
00164 /* CALCUL */
00165   for(j=0; j<dimY; j++)
00166       for(i=0; i<dimX; i++){
00167           objet = -1;
00168           for(n=0; n<nbr; n++)
00169               if( j>=y0[n] && j<=y1[n] && i>=x0[n] && i<=x1[n]){
00170                   objet = n;
00171                   break;
00172               }
00173           if( objet >= 0 )
00174               switch(t0){
00175               case 1:
00176                   im0u1.p[j][i] = (pixu1)tab[objet];
00177                   break;
00178               case 2:
00179                   im0u2.p[j][i] = (pixu2)tab[objet];
00180                   break;
00181               case 3:
00182                   im0u4.p[j][i] = (pixu4)tab[objet];
00183                   break;
00184               case 4:
00185                   im0fl.p[j][i] = tab[objet];
00186                   break;
00187               default:
00188                   printf("\n  ERREUR : type (%d) image res inconnu (1|2|3|4) attendu)\n",t0);
00189                   exit(0);
00190               }
00191       }
00192 
00193   /* FREMETURE */
00194   switch(t0){
00195   case 1:
00196       write_imau1_ferm(&wri, im0u1);
00197       break;
00198   case 2:
00199       write_imau2_ferm(&wri, im0u2);
00200       break;
00201   case 3:
00202       write_imau4_ferm(&wri, im0u4);
00203       break;
00204   case 4:
00205       write_imafl_ferm(&wri, im0fl);
00206       break;
00207   default:
00208       printf("\n  ERREUR : type (%d) image res inconnu (1|2|3|4) attendu)\n",t0);
00209       exit(0);
00210   }
00211 }
00212 
00213 
00214 

Generated on Tue Apr 22 13:31:04 2008 for ima2D by  doxygen 1.5.3