00001 /************************************************************************* 00002 * $Id: volrdf.c,v 1.1 2005/09/09 08:22:57 bellet Exp $ 00003 ************************************************************************** 00004 This software is governed by the CeCILL license under French law and 00005 abiding by the rules of distribution of free software. You can use, 00006 modify and/ or redistribute the software under the terms of the CeCILL 00007 license as circulated by CEA, CNRS and INRIA at the following URL 00008 "http://www.cecill.info". 00009 00010 As a counterpart to the access to the source code and rights to copy, 00011 modify and redistribute granted by the license, users are provided only 00012 with a limited warranty and the software's author, the holder of the 00013 economic rights, and the successive licensors have only limited 00014 liability. 00015 00016 In this respect, the user's attention is drawn to the risks associated 00017 with loading, using, modifying and/or developing or reproducing the 00018 software by the user in light of its specific status of free software, 00019 that may mean that it is complicated to manipulate, and that also 00020 therefore means that it is reserved for developers and experienced 00021 professionals having in-depth computer knowledge. Users are therefore 00022 encouraged to load and test the software's suitability as regards their 00023 requirements in conditions enabling the security of their systems and/or 00024 data to be ensured and, more generally, to use and operate it in the 00025 same conditions as regards security. 00026 00027 The fact that you are presently reading this means that you have had 00028 knowledge of the CeCILL license and that you accept its terms. 00029 00030 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de 00031 l'Image). All rights reserved. See License.txt for details. 00032 00033 Version 1.0 05/09/2005 00034 *************************************************************************/ 00035 00036 /* 00037 * Read a Volume out of a raw file. 00038 */ 00039 00040 #include <stdio.h> 00041 #include <stdlib.h> 00042 #include <string.h> // For strlen 00043 #include "idvol.h" 00044 #include "idio.h" 00045 #include "idprint.h" 00046 00047 /* FUNCTION DESCRIPTION ************************************************** 00048 00049 IdVolReadRawFile (fonction) 00050 00051 RESUME: Lect. d'1 fich. Volume RAW et allocation du Volume 00052 00053 DESCRIPTION: Charge en memoire un fichier Volume au format RAW. 00054 L'espace memoire est alloue par cette fonction. 00055 00056 SYNTAXE: PPPVOLUME vol = IdVolReadRawFile(char *filename, int dimx, int dimy, int dimz, int typeVol); 00057 00058 RETOUR: type : PPPVOLUME 00059 role : Pointeur vers le volume charge en memoire. 00060 00061 PARAMETRES: 00062 nom : filename 00063 type : char * 00064 role : Pointeur vers le nom complet du fichier volume 00065 a charger. 00066 00067 nom : dimx,dimy,dimz 00068 type : int 00069 role : Dimensions en x,y,z du volume a charger. 00070 00071 nom : typeVol 00072 type : int 00073 role : Type des voxels. 00074 00075 FICHIER: rdfvol.c 00076 00077 ******************************************************** END DESCRIPTION */ 00078 PPPVOLUME IdVolReadRawFile(nomfic,sx,sy,sz,ty) 00079 char *nomfic; 00080 int sx,sy,sz,ty; 00081 { 00082 int i, j; 00083 FILE * fp; 00084 PPPVOLUME vo; 00085 00086 fp=fopen(nomfic,ID_RFILE_BIN); 00087 if(fp) { 00088 vo=IdVolAlloc(sx,sy,sz,ty); 00089 if(vo){ 00090 sx = (IdVolType(vo)==VOL_BIT) /* CM V1.01 */ 00091 ? ((IdVolDimX(vo)+7)>>3) 00092 : IdVolDimX(vo); 00093 00094 for(i=0;i<sz;i++) for(j=0;j<sy;j++) 00095 if( !(fread(vo[i][j],IdSizeOfType(vo),sx,fp)) ) { 00096 IdPrintf("Echec Lecture volume : %s\n",nomfic); 00097 break; 00098 } 00099 00100 _IdVolPrivate(vo)->_fichier=(char *)malloc(strlen(nomfic)+1); 00101 strcpy(_IdVolPrivate(vo)->_fichier,nomfic); 00102 } 00103 fclose(fp); 00104 return(vo); 00105 }else 00106 return ( (PPPVOLUME )0 ); 00107 } 00108 00109 /* FUNCTION DESCRIPTION ************************************************** 00110 00111 IdVolReadRawFileToVol (fonction) 00112 00113 RESUME: Lect. d'un fichier Volume au format RAW ds un VOLUME existant. 00114 00115 DESCRIPTION: Charge en memoire un fichier Volume au format RAW. 00116 L'espace memoire n'est pas alloue par cette fonction. 00117 00118 SYNTAXE: int retCode = IdVolReadRawFileToVol(char *filename, PPPVOLUME vol); 00119 00120 RETOUR: type : int 00121 role : Indicateur d'erreur: 1 : OK 00122 0 : Pb. Volume non charge 00123 Fichier non trouve. 00124 00125 PARAMETRES: 00126 nom : filename 00127 type : char * 00128 role : Pointeur vers le nom complet du fichier volume 00129 a charger. 00130 00131 nom : vol 00132 type : PPPVOLUME 00133 role : Pointeur vers la zone et la structure de description 00134 du volume a charger. Ceci suppose que ce pointeur est 00135 le resultat de la fonction IdVolAlloc. 00136 00137 FICHIER: rdfvol.c 00138 00139 ******************************************************** END DESCRIPTION */ 00140 int IdVolReadRawFileToVol ( nomfic, vo ) 00141 char * nomfic; 00142 PPPVOLUME vo; 00143 { 00144 int i, j; 00145 FILE * fp; 00146 00147 fp=fopen(nomfic,ID_RFILE_BIN); 00148 if(fp){ 00149 if(vo){ 00150 int sx = (IdVolType(vo)==VOL_BIT) 00151 ? ((IdVolDimX(vo)+7)>>3) 00152 : IdVolDimX(vo); 00153 00154 for(i=0;i<IdVolDimZ(vo);i++)for(j=0;j<IdVolDimY(vo);j++) 00155 fread(vo[i][j],IdSizeOfType(vo),sx,fp); 00156 00157 _IdVolPrivate(vo)->_fichier=(char *)malloc(strlen(nomfic)+1); 00158 strcpy(_IdVolPrivate(vo)->_fichier,nomfic); 00159 } 00160 fclose(fp); 00161 return(1); 00162 }else 00163 return(0); 00164 } 00165 /* FUNCTION DESCRIPTION ******************************************* JPR ** 00166 00167 IdVolReadRawFileWithOffset (fonction) 00168 00169 DESCRIPTION: Lecture d'un fichier volume au format RAW 00170 avec saut d'une entete et creation de la structure VOLUME 00171 correspondante. 00172 00173 SYNTAXE: PPPVOLUME vol = IdVolReadRawFileWithOffset(char *filename, int dimx, int dimy, int dimz, int typeVol, int tailleEntete); 00174 00175 RETOUR: type : PPPVOLUME 00176 role : pointeur sur le VOLUME cree. 00177 00178 PARAMETRES: 00179 nom : nomfic 00180 type : nom de fichier 00181 role : fichier contenant le VOLUME au format RAW 00182 00183 nom : dimx 00184 type : entier 00185 role : taille en X du VOLUME 00186 00187 nom : dimy 00188 type : entier 00189 role : taille en Y du VOLUME 00190 00191 nom : dimz 00192 type : entier 00193 role : taille en Z du VOLUME 00194 00195 nom : typeVol 00196 type : entier 00197 role : type du VOLUME ( VOL_UCHAR, etc... 00198 00199 nom : tailleEntete 00200 type : entier 00201 role : taille, en octets, de l'entete de l'VOLUME 00202 00203 FICHIER: rdfvol.c 00204 00205 EXEMPLE: PPPVOLUME_UCHAR im; 00206 im=IdVolReadRawFileWithOffset("lena.vol",512,512,512,VOL_UCHAR,0); 00207 00208 00209 ******************************************************** END DESCRIPTION */ 00210 00211 #define SEEK_SET 0 00212 00213 PPPVOLUME IdVolReadRawFileWithOffset(nomfic,sx,sy,sz,ty,offset) 00214 char *nomfic; 00215 int sx,sy,sz,ty,offset; 00216 { 00217 int i,j; 00218 FILE *fp; 00219 PPPVOLUME vo; 00220 00221 /* IdPrintf("sx=%d sy=%d sz %d ty=%d offset=%d \n",sx,sy,sz,ty,offset); */ 00222 00223 fp=fopen(nomfic,ID_RFILE_BIN); 00224 if(fp) { 00225 vo=IdVolAlloc(sx,sy,sz,ty); 00226 if(vo){ 00227 if(offset) fseek(fp,offset,SEEK_SET); /* JPR V1.01_001*/ 00228 sx = (IdVolType(vo)==VOL_BIT) 00229 ? ((IdVolDimX(vo)+7)>>3) 00230 : IdVolDimX(vo); 00231 00232 for(i=0;i<sz;i++) for(j=0;j<sy;j++) 00233 fread(vo[i][j],IdSizeOfType(vo),sx,fp); 00234 00235 _IdVolPrivate(vo)->_fichier=(char *)malloc(strlen(nomfic)+1); 00236 strcpy(_IdVolPrivate(vo)->_fichier,nomfic); 00237 } 00238 fclose(fp); 00239 return(vo); 00240 }else 00241 return ( (PPPVOLUME )0 ); 00242 } 00243 00244 00245 /* FUNCTION DESCRIPTION ******************************************* JPR ** 00246 00247 IdVolReadRawFileToVolWithOffset (fonction) PAS FAIT ... 00248 00249 DESCRIPTION: Lecture d'un fichier volume au format RAW dans un PPPVOLUME existant avec saut d'une entete 00250 00251 SYNTAXE: PPPVOLUME vol = IdVolReadRawFileToVolWithOffset(char *filename, PPPPVOLUME volExist, int dimx, int dimy, int dimz, int typeVol, int tailleEntete); 00252 00253 RETOUR: type : PPPVOLUME 00254 role : pointeur sur le VOLUME cree. 00255 00256 PARAMETRES: 00257 nom : nomfic 00258 type : nom de fichier 00259 role : fichier contenant le VOLUME au format RAW 00260 00261 nom : dimx 00262 type : entier 00263 role : taille en X du VOLUME 00264 00265 nom : dimy 00266 type : entier 00267 role : taille en Y du VOLUME 00268 00269 nom : dimz 00270 type : entier 00271 role : taille en Z du VOLUME 00272 00273 nom : typeVol 00274 type : entier 00275 role : type du VOLUME ( VOL_UCHAR, etc... 00276 00277 nom : tailleEntete 00278 type : entier 00279 role : taille, en octets, de l'entete de l'VOLUME 00280 00281 FICHIER: rdfvol.c 00282 00283 EXEMPLE: PPPVOLUME_UCHAR im; 00284 im=IdVolReadRawFileWithOffset("lena.vol",512,512,512,VOL_UCHAR,0); 00285 00286 00287 ******************************************************** END DESCRIPTION */