Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals

cntallo.c

Go to the documentation of this file.
00001 /************************************************************************* 00002 * $Id: cntallo.c,v 1.1 2005/09/09 08:22:22 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 * 00038 * Description : Allocation et liberation structure et donnee CONTOUR 00039 * 00040 **************************************************************************/ 00041 00042 #include <string.h> // For memcpy 00043 #include <stdlib.h> 00044 #include "idcnt.h" 00045 #include "idprint.h" 00046 #include "iderr.h" 00047 00048 /* FUNCTION DESCRIPTION **************************************************** 00049 00050 IdCntFree (macro) 00051 00052 RESUME: Liberation de la memoire occupee par un CONTOUR 00053 00054 DESCRIPTION: Liberation de la memoire occupee par un contour. La variable de 00055 type PCONTOUR passe en parametre est mise a zero (voir macro 00056 IdCntFree dans idcnt.h). 00057 00058 SYNTAXE: void IdCntFree(PCONTOUR contour); 00059 00060 RETOUR: 00061 Pas de valeur de retour. 00062 00063 PARAMETRES: 00064 nom : contour 00065 type : PCONTOUR 00066 role : contour a liberer. 00067 00068 FICHIER: allocnt.c 00069 00070 ********************************************************* END DESCRIPTION */ 00071 00072 void _IdCntFree(PCONTOUR *pi) 00073 { 00074 if(*pi) 00075 { 00076 if(_IdCntPrivate(*pi)->_message)free((_IdCntPrivate(*pi)->_message)); 00077 _IdCntPrivate(*pi)->_message=0; 00078 00079 if(_IdCntPrivate(*pi)->_fichier)free((_IdCntPrivate(*pi)->_fichier)); 00080 _IdCntPrivate(*pi)->_fichier=0; 00081 00082 free(_IdCntPrivate(*pi)); 00083 *pi=0; 00084 } 00085 } 00086 00087 /* FUNCTION DESCRIPTION **************************************************** 00088 00089 IdCntAlloc (function) 00090 00091 RESUME: Allocation memoire d'un objet libido de type CONTOUR 00092 00093 DESCRIPTION: Allocation memoire d'un objet libido de type CONTOUR (CNT). La 00094 taille correspond a la dimension du contour. Le type est 00095 CNT_xxx et peut prendre les valeurs du tableau des types 00096 d'elements LIBIDO, par exemple CNT_UCHAR, CNT_FLOAT, ...etc. 00097 Si l'allocation memoire a pu se faire 00098 correctement, la fonction retourne une valeur non nulle de 00099 type PCONTOUR. En cas d'erreur la fonction retourne NULL. Il 00100 est indispensable de tester cette valeur de retour avant 00101 d'utiliser le CNT. Il est conseille de faire un changement 00102 de type sur la valeur de retour pour eviter les WARNINGS des 00103 compilateurs. 00104 Voir: idcnt.h : types et constantes. 00105 00106 SYNTAXE: PCONTOUR cnt1 = IdCntAlloc ( int taille, int typeCnt); 00107 00108 RETOUR: nom : cnt1 00109 type : PCONTOUR 00110 role : pointeur sur l'objet CNT 00111 00112 PARAMETRES: 00113 nom : taille 00114 type : int 00115 role : taille du contour a creer 00116 00117 nom : typeCnt 00118 type : int 00119 role : type du contour a creer (CNT_xxx ex: CNT_FLOAT) 00120 00121 FICHIER: allocnt.c 00122 00123 ********************************************************* END DESCRIPTION */ 00124 00125 PCONTOUR IdCntAlloc(int sx, int ty) 00126 /* retourne PCONTOUR si OK, 0 si erreur */ 00127 /* ty = type de donnees: CNT_FLOAT ... */ 00128 { 00129 PRIVATE_CONTOUR *si; 00130 PCONTOUR pi; 00131 00132 if(!(ty & IDO_TYPE)==CNT) { 00133 IdErrPrintf("Allocation impossible. Objet de type incompatible."); 00134 IdErrno=IDERR_WRONG_TYPE; 00135 return((PCONTOUR)0); 00136 } 00137 00138 si=(PRIVATE_CONTOUR *)calloc(1, sizeof(PRIVATE_CONTOUR) + sx * IdTypeSize(ty)); 00139 if(si){ 00140 si->DimX=sx; 00141 si->Type=ty; 00142 si->_fichier=0; /* JPR */ 00143 si->_message=0; /* JPR */ 00144 pi=(PCONTOUR)&(si[1]); 00145 }else{ 00146 IdErrPrintf("Echec d'allocation de contour. Memoire saturee."); 00147 IdErrno=IDERR_ALLOC_CNT; 00148 return((PCONTOUR)0); /* JPR */ 00149 } 00150 00151 return(pi); 00152 } 00153 00154 /* FUNCTION DESCRIPTION ************************************************** 00155 00156 IdCntVecteurToContour (fonction) 00157 00158 RESUME: Alloc. d'1 CNT a partir d'1 morceau d'1 Vecteur de points IDXPOINT 00159 00160 DESCRIPTION: Allocation d'un CNT a partir d'une portion d'un Vecteur de points IDXPOINT. 00161 00162 SYNTAXE: PCONTOUR cnt1 = IdCntVecteurToContour (void * VectSource, int typeCnt, int origineX, int lgrX); 00163 00164 RETOUR: nom : cnt1 00165 type : PCONTOUR 00166 role : Pointeur vers le contour resultat. Zero si echec. 00167 00168 PARAMETRES: nom : VectSource 00169 type : void * 00170 role : adresse du vecteur source 00171 00172 nom : typeCnt 00173 type : int 00174 role : type du contour. 00175 00176 nom : origineX 00177 type : int 00178 role : Origine (ds le vecteur) du contour. 00179 00180 nom : lgrX 00181 type : int 00182 role : nb de points du contour. 00183 00184 FICHIER: allocnt.c 00185 00186 EXEMPLE: 00187 00188 cnts=(PCONTOUR_UCHAR)IdCntVecteurToContour(im(i),CNT_UCHAR,0,IdCntDimX(im)) 00189 00190 ******************************************************** END DESCRIPTION */ 00191 00192 PCONTOUR 00193 IdCntVecteurToContour (void *vecteur, int ty, int ox, int lx) 00194 { 00195 PRIVATE_CONTOUR *si; 00196 PCONTOUR pi; 00197 00198 if(!(ty & IDO_TYPE)==CNT) { 00199 IdErrPrintf("Allocation impossible. Objet de type (%x) incompatible.",ty); 00200 IdErrno=IDERR_WRONG_TYPE; 00201 return((PCONTOUR)0); 00202 } 00203 00204 si=(PRIVATE_CONTOUR *)calloc(1, sizeof(PRIVATE_CONTOUR) + lx * IdTypeSize(ty)); 00205 if(si){ 00206 si->DimX=lx; 00207 si->Type=ty; 00208 pi=(PCONTOUR)&(si[1]); 00209 memcpy(&si[1],((char*)vecteur)+ox* IdTypeSize(ty), 00210 lx * IdTypeSize(ty)); 00211 } else { 00212 IdErrPrintf("Echec d'allocation de contour. Memoire saturee."); 00213 IdErrno=IDERR_ALLOC_CNT; 00214 return((PCONTOUR)0); 00215 } 00216 return(pi); 00217 } 00218 00219 /* FUNCTION DESCRIPTION **************************************************** 00220 * 00221 * IdCntModifLongueur (function) 00222 * 00223 * RESUME: Modif longueur d'un objet libido de type CONTOUR 00224 * 00225 * DESCRIPTION: CETTE FONCTION NE DOIT PAS ETRE UTILISEE 00226 * (IdCntAddPoint modifie la longueur du CNT s'il y a besoin 00227 * et met a jour le nb de points utilises !!!) 00228 * 00229 * Modif longueur d'un objet libido de type CONTOUR. 00230 * Si la nouvelle longueur est < a l'ancienne, la fin est perdue. 00231 * Si la nouvelle longueur est > a l'ancienne, la partie rajoutee 00232 * n'EST PAS initialisee 00233 * 00234 * Si l'allocation de la memoire supplementaire a pu se faire 00235 * correctement, la fonction retourne une valeur non nulle de 00236 * type PCONTOUR. En cas d'erreur la fonction retourne 0. Il 00237 * est indispensable de tester cette valeur de retour avant 00238 * d'utiliser l'image. Il est conseille de faire un changement 00239 * de type sur la valeur de retour pour eviter les WARNINGS des 00240 * compilateurs. 00241 * 00242 * SYNTAXE: PCONTOUR cnt = IdCntModifLongueur ( PCONTOUR cnt,int nouvelleTaille); 00243 * 00244 * RETOUR: 00245 * nom : cnt 00246 * type : PCONTOUR 00247 * role : pointeur sur l'objet CNT 00248 * NULL si echec 00249 * 00250 * PARAMETRES: 00251 * nom : cnt 00252 * type : PCONTOUR 00253 * role : Pointeur vers le contour dont on veut modifier la taille. 00254 * 00255 * nom : nouvelleTaille 00256 * type : int 00257 * role : nouvelle taille du contour 00258 * 00259 * FICHIER: allocnt.c 00260 * 00261 ********************************************************* END DESCRIPTION */ 00262 00263 PCONTOUR IdCntModifLongueur (PCONTOUR cnt, int nouvLong) 00264 /* retourne PCONTOUR si OK 0 si erreur */ 00265 { 00266 PRIVATE_CONTOUR *si; 00267 PCONTOUR pi; 00268 00269 if(IdLibidoType(cnt)!=CNT) { 00270 IdErrPrintf("Modif Longueur impossible. Objet non CONTOUR."); 00271 IdErrno=IDERR_WRONG_TYPE; 00272 return((PCONTOUR)0); 00273 } 00274 00275 si=(PRIVATE_CONTOUR *)realloc( 00276 (void *)( _IdCntPrivate(cnt)), 00277 sizeof(PRIVATE_CONTOUR) + nouvLong * IdSizeOfType(cnt) 00278 ); 00279 00280 if(si){ 00281 si->DimX=nouvLong; 00282 pi=(PCONTOUR)&(si[1]); 00283 00284 }else{ 00285 IdErrPrintf("Echec Modif Longueur contour. Memoire saturee."); 00286 IdErrno=IDERR_ALLOC_CNT; 00287 return((PCONTOUR)0); 00288 } 00289 00290 return(pi); 00291 }

Generated on Wed Oct 19 09:28:32 2005 for SIMRI3D by doxygen 1.3.7