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

cntutil.c

Go to the documentation of this file.
00001 /************************************************************************* 00002 * $Id: cntutil.c,v 1.1 2005/09/09 08:22:23 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 : Divers Utilitaires sur CONTOUR. 00039 * 00040 **************************************************************************/ 00041 #include <math.h> 00042 #include <string.h> // For memcpy() and memset() 00043 #include <stdlib.h> // For abs() 00044 #include "idcnt.h" 00045 #include "idcalc.h" 00046 #include "iderr.h" 00047 #include "idprint.h" 00048 00049 /* FUNCTION DESCRIPTION ************************************************** 00050 00051 IdCntAddPoint (macro) 00052 00053 RESUME: Ajoute un point a un contour USHORT 00054 00055 DESCRIPTION: ajoute un point a un contour USHORT. UsedNbX est mis a jour. 00056 Le contour est re-alloue a une longueur effective plus grande si besoin est. 00057 -- ATTENTION -- 00058 Si le CNT est associe a un Graph (LibIDO Graphique) 00059 NE PAS UTILISER cette fonction 00060 (le Graph ne sera pas informe du 'changement d'adresse' 00061 de son CNT en cas de realloc ... ) 00062 Utiliser ds ce cas la fonction LibIDO Graphique IwGraphAddPoint 00063 qui prend en compte ce genre de pb... 00064 00065 00066 SYNTAXE: int retCode = IdCntAddPoint(PCONTOUR_USHORT cnt, int x, int y); 00067 00068 RETOUR: type : int 00069 role : 00070 00071 PARAMETRES: 00072 nom : cnt 00073 type : PCONTOUR_USHORT 00074 role : contour d'origine. 00075 00076 nom : x,y 00077 type : int 00078 role : coordonnes X et Y du point a rajouter 00079 00080 FICHIER: idcnt.h 00081 00082 EXEMPLE: 00083 00084 ******************************************************** END DESCRIPTION */ 00085 00086 int _IdCntAddPoint(contour,valx,valy) 00087 PCONTOUR_USHORT *contour; 00088 int valx,valy; 00089 { 00090 if( IdCntUsedNbX(*contour) == IdCntDimX(*contour) ) 00091 *contour=(PCONTOUR_USHORT)IdCntModifLongueur(*contour, (IdCntDimX(*contour)*3)/2 +1); /* +1 .... A. ANWANDER */ 00092 00093 if (*contour==NULL) return 0; 00094 00095 IdCntSetX(*contour,IdCntUsedNbX(*contour),valx); 00096 IdCntSetY(*contour,IdCntUsedNbX(*contour),valy); 00097 00098 IdCntUsedNbX(*contour)++; 00099 00100 return(1); 00101 } 00102 00103 /* FUNCTION DESCRIPTION ************************************************** 00104 00105 IdCntInsertPoint (macro) 00106 00107 RESUME: Insere un point ds un contour USHORT 00108 00109 DESCRIPTION: Insere 1 point ds 1 contour USHORT APRES un point de numero donne. 00110 -1 signifie que l'on ajoute en tete 00111 UsedNbX est mis a jour. 00112 Le contour est re-alloue a une longueur effective plus grande si besoin est. 00113 -- ATTENTION -- 00114 Si le CNT est associe a un Graph (LibIDO Graphique) 00115 NE PAS UTILISER cette fonction 00116 (le Graph ne sera pas informe du 'changement d'adresse' 00117 de son CNT en cas de realloc ... ) 00118 Utiliser ds ce cas la fonction LibIDO Graphique IwGraphAddPoint 00119 qui prend en compte ce genre de pb... 00120 00121 SYNTAXE: int retCode = IdCntInsertPoint(PCONTOUR_USHORT cnt, int numPoint, int x, int y); 00122 00123 RETOUR: type : int 00124 role : code de retour booleen. 00125 00126 PARAMETRES: 00127 nom : cnt 00128 type : PCONTOUR_USHORT 00129 role : contour d'origine. 00130 00131 nom : numPoint 00132 type : int 00133 role : numero du point APRES lequel on veut rajouter 00134 00135 nom : x,y 00136 type : int 00137 role : coordonnes X et Y du point a rajouter 00138 00139 FICHIER: idcnt.h 00140 00141 EXEMPLE: 00142 00143 ******************************************************** END DESCRIPTION */ 00144 00145 int _IdCntInsertPoint(contour,numPoint,valx,valy) 00146 PCONTOUR_USHORT *contour; 00147 int valx,valy,numPoint; 00148 { 00149 int i; 00150 if ( !*contour ) { 00151 IdErrno = IDERR_POINTER_IS_NULL; 00152 return 0; 00153 }else if ( IdLibidoType(*contour) != CNT) { 00154 IdErrno = IDERR_WRONG_TYPE; 00155 return 0; 00156 } 00157 00158 /*IdPrintf ("numero du point apres lequel inserer :%d\n",numPoint);*/ 00159 00160 if (numPoint == IdCntUsedNbX(*contour)) 00161 { 00162 00163 /*IdPrintf("numPoint= dernier point\n");*/ 00164 i = IdCntAddPoint(*contour,valx,valy); 00165 if (i==0) { IdErrPrintf("Echec Insertion Point\n"); 00166 return(0); 00167 } 00168 return(1); 00169 } 00170 else if ( numPoint <-1) { IdErrno = IDERR_INVALID_NUMBER; 00171 return 0; 00172 } 00173 else 00174 { if ( IdCntDimX(*contour) == IdCntUsedNbX(*contour)) 00175 { 00176 /* Rallonger le Contour */ 00177 00178 *contour =(PCONTOUR_USHORT) IdCntModifLongueur( *contour,(IdCntDimX(*contour)*3)/2+1); 00179 00180 00181 } 00182 for (i=IdCntUsedNbX(*contour)-1 ; i>numPoint ; i--) 00183 00184 { 00185 IdCntSetX(*contour,i+1,IdCntGetX(*contour,i)); 00186 IdCntSetY(*contour,i+1,IdCntGetY(*contour,i)); 00187 } 00188 00189 IdCntSetX(*contour,numPoint+1,valx); 00190 IdCntSetY(*contour,numPoint+1,valy); 00191 00192 IdCntSetUsedNbX(*contour,IdCntGetUsedNbX(*contour)+1); 00193 } 00194 return(1); 00195 } 00196 00197 /* FUNCTION DESCRIPTION ************************************************** 00198 00199 IdCntMoveContour (fonction) 00200 00201 RESUME: Deplace un contour USHORT ( +DeltaX, +DeltaY sur chaque point) 00202 00203 DESCRIPTION:Deplace un contour USHORT ( +DeltaX, +DeltaY sur chaque point) 00204 00205 SYNTAXE: int retCode = IdCntMoveContour(PCONTOUR_USHORT cnt, int DeltaX, int DeltaY); 00206 00207 RETOUR: type : int 00208 role : code de retour booleen. 00209 00210 PARAMETRES: 00211 nom : cnt 00212 type : PCONTOUR_USHORT 00213 role : contour d'origine. 00214 00215 nom : DeltaX,DeltaY 00216 type : int 00217 role : deplacement, en X et Y, des points 00218 00219 FICHIER: idcnt.h 00220 00221 EXEMPLE: 00222 00223 ******************************************************** END DESCRIPTION */ 00224 int IdCntMoveContour(contour,deltaX, deltaY) 00225 PCONTOUR_USHORT contour; 00226 int deltaX, deltaY; 00227 { 00228 int i; 00229 if ( !contour ) { 00230 IdErrno = IDERR_POINTER_IS_NULL; 00231 return 0; 00232 } 00233 00234 for (i=0;i<IdCntUsedNbX(contour);i++) 00235 { 00236 IdCntSetX(contour,i,IdCntGetX(contour,i)+deltaX); 00237 IdCntSetY(contour,i,IdCntGetY(contour,i)+deltaY); 00238 } 00239 return 1; 00240 } 00241 00242 /* FUNCTION DESCRIPTION ************************************************** 00243 00244 IdCntRotateContour (fonction) 00245 00246 RESUME: Fait tourner d'un angle donne un CNT USHORT autour d'un centre 00247 00248 DESCRIPTION: Fait tourner d'un angle donne un CNT USHORT autour d'un centre 00249 00250 SYNTAXE: int retCode = IdCntRotateContour(PCONTOUR_USHORT cnt, int centreX, int centreY, double angle); 00251 00252 RETOUR: type : int 00253 role : code de retour booleen. 00254 00255 PARAMETRES: 00256 nom : cnt 00257 type : PCONTOUR_USHORT 00258 role : contour d'origine. 00259 00260 nom : centreX,centreY 00261 type : int 00262 role : coordonnees du centre de rotation 00263 00264 nom : angle 00265 type : double 00266 role : angle de rotation 00267 00268 FICHIER: cntutil.c 00269 00270 EXEMPLE: 00271 00272 ******************************************************** END DESCRIPTION */ 00273 int IdCntRotateContour(contour, centreX, centreY, angle) 00274 PCONTOUR_USHORT contour; 00275 int centreX, centreY; 00276 double angle; 00277 { 00278 double x,y; 00279 double sinAlph, cosAlph; 00280 double nouvX,nouvY; 00281 00282 int i; 00283 if ( !contour ) { 00284 IdErrno = IDERR_POINTER_IS_NULL; 00285 return 0; 00286 } 00287 sinAlph=sin(angle); 00288 cosAlph=cos(angle); 00289 00290 for (i=0;i<IdCntUsedNbX(contour);i++) 00291 { 00292 x= (double)IdCntGetX(contour,i); 00293 y= (double)IdCntGetY(contour,i); 00294 00295 nouvX= cosAlph*(x-(double)centreX) -sinAlph*(y-(double)centreY) + centreX; 00296 nouvY= sinAlph*(x-(double)centreX) +cosAlph*(y-(double)centreY) + centreY; 00297 00298 IdCntSetX(contour,i,(unsigned short)nouvX); 00299 IdCntSetY(contour,i,(unsigned short)nouvY); 00300 00301 x= (double)IdCntGetX(contour,i); 00302 y= (double)IdCntGetY(contour,i); 00303 } 00304 return 1; 00305 } 00306 00307 /* FUNCTION DESCRIPTION ************************************************** 00308 00309 IdCntRotateContourDouble (fonction) 00310 00311 RESUME: Fait tourner d'un angle donne un CNT DOUBLE autour d'un centre 00312 00313 DESCRIPTION: Fait tourner d'un angle donne un CNT DOUBLE autour d'un centre 00314 00315 SYNTAXE: int retCode = IdCntRotateContourDouble(PCONTOUR_DOUBLE cnt, int centreX, int centreY, double angle); 00316 00317 RETOUR: type : int 00318 role : code de retour booleen. 00319 00320 PARAMETRES: 00321 nom : cnt 00322 type : PCONTOUR_DOUBLE 00323 role : contour d'origine. 00324 00325 nom : centreX,centreY 00326 type : int 00327 role : coordonnees du centre de rotation 00328 00329 nom : angle 00330 type : double 00331 role : angle de rotation 00332 00333 FICHIER: cntutil.c 00334 00335 EXEMPLE: 00336 00337 ******************************************************** END DESCRIPTION */ 00338 int IdCntRotateContourDouble(contour, centreX, centreY, angle) 00339 PCONTOUR_DOUBLE contour; 00340 int centreX, centreY; 00341 double angle; 00342 { 00343 double x,y; 00344 double sinAlph, cosAlph; 00345 double nouvX,nouvY; 00346 00347 int i; 00348 if ( !contour ) { 00349 IdErrno = IDERR_POINTER_IS_NULL; 00350 return 0; 00351 } 00352 sinAlph=sin(angle); 00353 cosAlph=cos(angle); 00354 00355 /*IdPrintf ("alpha %g sinApha %g cosAlpha %g\n",angle, sinAlph, cosAlph);*/ 00356 00357 for (i=0;i<IdCntUsedNbX(contour);i++) 00358 { 00359 x= IdCntGetX(contour,i); 00360 y= IdCntGetY(contour,i); 00361 00362 nouvX= cosAlph*(x-(double)centreX) - sinAlph*(y-(double)centreY) + centreX; 00363 nouvY= sinAlph*(x-(double)centreX) + cosAlph*(y-(double)centreY) + centreY; 00364 00365 IdCntSetX(contour,i,nouvX); 00366 IdCntSetY(contour,i,nouvY); 00367 00368 x= IdCntGetX(contour,i); 00369 y= IdCntGetY(contour,i); 00370 } 00371 return 1; 00372 } 00373 00374 00375 00376 00377 /* FUNCTION DESCRIPTION ************************************************** 00378 00379 IdCntZoomContourDouble (fonction) 00380 00381 RESUME: Zoome d'un %ge donne un CNT DOUBLE autour du centre du Rect Englob 00382 00383 DESCRIPTION: Zoome d'un %ge donne un CNT DOUBLE autour du centre du Rect Englob 00384 Si on connait les coord de centre du Rect Englob, 00385 on les passe en param , 00386 sinon on passe -1., -1. et la fct les calcule 00387 00388 SYNTAXE: int retCode = IdCntZoomContourDouble(PCONTOUR_DOUBLE cnt, int centreX, int centreY, double percent); 00389 00390 RETOUR: type : int 00391 role : code de retour booleen. 00392 00393 PARAMETRES: 00394 nom : cnt 00395 type : PCONTOUR_DOUBLE 00396 role : contour d'origine. 00397 00398 nom : centreX,centreY 00399 type : int 00400 role : coordonnees du centre du Rect Englob 00401 -1.,-1. si on ne les connait pas 00402 00403 nom : percent 00404 type : double 00405 role : pourcentage de zoom 00406 00407 FICHIER: cntutil.c 00408 00409 EXEMPLE: 00410 00411 ******************************************************** END DESCRIPTION */ 00412 int IdCntZoomContourDouble(contour, centreX, centreY, percent) 00413 PCONTOUR_DOUBLE contour; 00414 int centreX, centreY; 00415 double percent; 00416 { 00417 double x,y; 00418 double angle, oldDist, newDist; 00419 double nouvX,nouvY; 00420 00421 int i; 00422 if ( !contour ) { 00423 IdErrno = IDERR_POINTER_IS_NULL; 00424 return 0; 00425 } 00426 00427 percent= 1.+ (percent/100.); 00428 00429 if ( (centreX == -1.) && (centreX == -1.) ) /* a tester ... JPR */ 00430 { 00431 int x0,y0, x1,y1; 00432 IdCntRectEnglob((PCONTOUR_USHORT)contour, &x0, &y0, &x1, &y1 ); 00433 centreX = abs( x1-x0) /2; 00434 centreY = abs( y1-y0) /2; 00435 } 00436 00437 for (i=0;i<IdCntUsedNbX(contour);i++) 00438 { 00439 00440 x= IdCntGetX(contour,i); 00441 y= IdCntGetY(contour,i); 00442 00443 angle= atan2 ((double)(y - centreY), (double)(x - centreX)); 00444 00445 oldDist=IdCalcDistance2Points((double)centreX, (double)centreY, 00446 (double)x, (double)y ); 00447 newDist=oldDist*percent; 00448 00449 nouvX= centreX + newDist*cos(angle); 00450 nouvY= centreY + newDist*sin(angle); 00451 00452 IdCntSetX(contour,i,nouvX); 00453 IdCntSetY(contour,i,nouvY); 00454 00455 } 00456 return 1; 00457 } 00458 00459 00460 /* FUNCTION DESCRIPTION ************************************************** 00461 00462 IdCntDelPoint (fonction) 00463 00464 RESUME: Supprime un point a un contour 00465 00466 DESCRIPTION: Supprime un point a un contour. UsedNbX est mis a jour. 00467 00468 SYNTAXE: int retCode = IdCntDelPoint(PCONTOUR cnt, int numPoint); 00469 00470 RETOUR: type : int 00471 role : code de retour booleen. 00472 00473 PARAMETRES: 00474 nom : cnt 00475 type : PCONTOUR 00476 role : contour d'origine. 00477 00478 nom : numPoint 00479 type : int 00480 role : numero du point a supprimer 00481 00482 FICHIER: cntutil.c 00483 00484 EXEMPLE: 00485 00486 ******************************************************** END DESCRIPTION */ 00487 00488 int IdCntDelPoint(contour,numPoint) 00489 PCONTOUR contour; 00490 int numPoint; 00491 { 00492 char * debut; 00493 00494 if ( !contour ) { 00495 IdErrno = IDERR_POINTER_IS_NULL; 00496 return 0; 00497 }else if ( IdLibidoType(contour) != CNT) { 00498 IdErrno = IDERR_WRONG_TYPE; 00499 return 0; 00500 } 00501 00502 if( (numPoint > IdCntUsedNbX(contour) ) || ( numPoint <0) ) { return 0; } 00503 00504 debut = (char*) contour + numPoint * IdSizeOfType(contour); 00505 00506 memcpy ( debut, 00507 debut+IdSizeOfType(contour), 00508 (IdCntGetUsedNbX(contour)-numPoint-1)*IdSizeOfType(contour) 00509 ); 00510 00511 IdCntSetUsedNbX(contour,IdCntGetUsedNbX(contour)-1); 00512 00513 return(1); 00514 } 00515 00516 /* FUNCTION DESCRIPTION ************************************************** 00517 00518 IdCntDelPoints (fonction) 00519 00520 RESUME: Supprime un ensemble de points a un contour 00521 00522 DESCRIPTION: Supprime un ensemble de points a un contour. UsedNbX est mis a jour. 00523 00524 SYNTAXE: int retCode = IdCntDelPoints(PCONTOUR cnt, int numPoint1, int numPoint2); 00525 00526 RETOUR: type : int 00527 role : code de retour booleen. 00528 00529 PARAMETRES: 00530 nom : cnt 00531 type : PCONTOUR 00532 role : contour d'origine. 00533 00534 nom : numPoint1 00535 type : int 00536 role : numero du premier point a supprimer 00537 00538 nom : numPoint2 00539 type : int 00540 role : numero du dernier point a supprimer 00541 00542 FICHIER: cntutil.c 00543 00544 EXEMPLE: 00545 00546 ******************************************************** END DESCRIPTION */ 00547 00548 int IdCntDelPoints(contour,numPoint1,numPoint2) 00549 PCONTOUR contour; 00550 int numPoint1,numPoint2; 00551 { 00552 char * debut; 00553 int nbpSupr; 00554 00555 if ( !contour ) { 00556 IdErrno = IDERR_POINTER_IS_NULL; 00557 return 0; 00558 }else if ( IdLibidoType(contour) != CNT) { 00559 IdErrno = IDERR_WRONG_TYPE; 00560 return 0; 00561 } 00562 if(numPoint1>numPoint2) { return 0; } 00563 00564 if( (numPoint1 > IdCntUsedNbX(contour)-1 ) || ( numPoint1 <0) ) { return 0; } 00565 if( (numPoint2 > IdCntUsedNbX(contour)-1 ) || ( numPoint2 <0) ) { return 0; } 00566 00567 nbpSupr= numPoint2-numPoint1+1; 00568 00569 debut = (char*) contour + numPoint1 * IdSizeOfType(contour); 00570 00571 memcpy ( debut, 00572 debut+IdSizeOfType(contour)*nbpSupr, 00573 (IdCntGetUsedNbX(contour)-numPoint2-1)*IdSizeOfType(contour) 00574 ); 00575 00576 IdCntSetUsedNbX(contour,IdCntGetUsedNbX(contour)-nbpSupr); 00577 00578 return(1); 00579 } 00580 00581 /* FUNCTION DESCRIPTION ************************************************** 00582 00583 IdCntConcat (fonction) 00584 00585 RESUME: Concatene 2 objets CNT. UsedNbX est mis a jour 00586 00587 DESCRIPTION: Concatene 2 objets CNT. UsedNbX est mis a jour. 00588 00589 SYNTAXE: PCONTOUR CntResult = IdCntConcat(PCONTOUR cnt1, PCONTOUR cnt2); 00590 00591 RETOUR: type : PCONTOUR 00592 role : contour concatene. 00593 00594 PARAMETRES: 00595 nom : cnt1 00596 type : PCONTOUR 00597 role : contour d'origine. 00598 00599 nom : cnt2 00600 type : PCONTOUR 00601 role : contour a rajouter 00602 00603 FICHIER: idcnt.h 00604 00605 EXEMPLE: 00606 00607 ******************************************************** END DESCRIPTION */ 00608 00609 PCONTOUR IdCntConcat(contour1,contour2) 00610 PCONTOUR contour1,contour2; 00611 { 00612 char * fin; 00613 int nouvlong; 00614 if ( !contour1 ) { 00615 IdErrno = IDERR_POINTER_IS_NULL; 00616 return 0; 00617 }else if ( IdLibidoType(contour1) != CNT) { 00618 IdErrno = IDERR_WRONG_TYPE; 00619 return 0; 00620 } 00621 00622 if ( !contour2 ) { 00623 IdErrno = IDERR_POINTER_IS_NULL; 00624 return 0; 00625 }else if ( IdLibidoType(contour2) != CNT) { 00626 IdErrno = IDERR_WRONG_TYPE; 00627 return 0; 00628 } 00629 if (!IdCntSameType(contour1,contour2)){ 00630 IdErrno = IDERR_WRONG_TYPE; 00631 return 0; 00632 } 00633 00634 nouvlong= IdCntUsedNbX(contour1)+IdCntUsedNbX(contour2); 00635 if (IdCntDimX(contour1) < nouvlong) 00636 contour1 = IdCntModifLongueur (contour1,(nouvlong*3)/2); 00637 00638 fin = (char*) contour1 + (IdCntUsedNbX(contour1))*IdSizeOfType(contour1); 00639 00640 memcpy (fin,contour2,IdCntUsedNbX(contour2)*IdSizeOfType(contour2)); 00641 00642 IdCntSetUsedNbX(contour1,nouvlong); 00643 00644 return(contour1); 00645 } 00646 00647 /* FUNCTION DESCRIPTION ************************************************** 00648 00649 IdCntClear (fonction) 00650 00651 RESUME: initialisation d'un Contour a 0 00652 00653 DESCRIPTION: Initialisation d'un Contour a 0 00654 00655 SYNTAXE: PCONTOUR CntResult = IdCntClear (PCONTOUR contResult); 00656 00657 RETOUR: type : PCONTOUR 00658 role : Pointeur vers le contour initialise. Zero si echec. 00659 00660 PARAMETRES: nom : contResult 00661 type : PCONTOUR 00662 role : Pointeur vers le contour a initialiser. 00663 00664 FICHIER: cntutil.c 00665 00666 EXEMPLE: if ( IdCntClear(contour)==0 ) 00667 IdErrPrintf("ERREUR: %s",IdErrMsg(IdErrno)); 00668 00669 ******************************************************** END DESCRIPTION */ 00670 00671 PCONTOUR IdCntClear ( cont ) 00672 PCONTOUR cont; 00673 { 00674 /* int y;*/ 00675 int taille_cont; 00676 /* Controle du contour **/ 00677 if ( !cont ) { 00678 IdErrno = IDERR_POINTER_IS_NULL; 00679 return 0; 00680 }else if ( IdLibidoType(cont) != CNT) { 00681 IdErrno = IDERR_WRONG_TYPE; 00682 return 0; 00683 } 00684 taille_cont = (IdCntDimX(cont)*IdSizeOfType(cont)) ; 00685 /* Calcul du resultat *****/ 00686 memset( cont, 0, taille_cont ); 00687 00688 IdCntSetUsedNbX(cont,0); 00689 00690 return cont; 00691 } 00692 /* FUNCTION DESCRIPTION ************************************************** 00693 00694 IdCntCopy (fonction) 00695 00696 RESUME: copie un Contour ds un autre, meme type/longueur 00697 00698 DESCRIPTION: Copie les points d'un Contour dans un autre de meme type et longueur. 00699 00700 SYNTAXE: PCONTOUR cntDest = IdCntCopy(PCONTOUR cntSource, PCONTOUR cntDest); 00701 00702 RETOUR: type : PCONTOUR 00703 role : Pointeur vers le Contour resultat (cntDest). 00704 00705 PARAMETRES: 00706 nom : cntSource 00707 type : PCONTOUR 00708 role : Contour d'origine. 00709 00710 nom : cntDest 00711 type : PCONTOUR 00712 role : Contour destination de meme type et dim. que cntSource. 00713 00714 FICHIER: cntutil.c 00715 00716 EXEMPLE: if( !IdCntCopy (ims,imd) ) IdErrPrintf(IdErrMsg(IdErrno)); 00717 00718 ******************************************************** END DESCRIPTION */ 00719 PCONTOUR IdCntCopy (ims,imd) 00720 PCONTOUR ims,imd; 00721 { 00722 /* int i;*/ 00723 if ( !IdCntSameSizeAndType(ims,imd) ) { 00724 IdErrno = IDERR_WRONG_DIM; 00725 return 0; 00726 } 00727 memcpy (imd,ims,IdCntDimX(imd)*IdSizeOfType(imd)); 00728 IdCntSetUsedNbX(imd,IdCntGetUsedNbX(ims)); 00729 return imd; 00730 } 00731 00732 /* FUNCTION DESCRIPTION ************************************************** 00733 00734 IdCntCast (fonction) 00735 00736 RESUME: converti un Contour d'un type reel ds un autre 00737 00738 DESCRIPTION: Convertit un Contour d'un type reel dans un autre. Les 00739 types sources complexes ne sont pas pris en charge. 00740 Dans ce cas, la variable IdErrno prend une valeur non-nulle. 00741 00742 SYNTAXE: PCONTOUR imDest = IdCntCast(PCONTOUR imSource, PCONTOUR imDest); 00743 00744 RETOUR: type : PCONTOUR 00745 role : Pointeur vers le Contour resultat (imd) ou zero si echec. 00746 00747 PARAMETRES: 00748 nom : imSource 00749 type : PCONTOUR 00750 role : Contour d'origine. 00751 00752 nom : imDest 00753 type : PCONTOUR 00754 role : Contour destination. Doit etre alloue en utilisant la 00755 fonction IdCntAlloc() avec le bon type CNT_???. 00756 00757 FICHIER: cntutil.c 00758 00759 EXEMPLE: if( !IdCntCast (ims,imd) ) 00760 IdErrPrintf(IdErrMsg(IdErrno)); 00761 00762 ******************************************************** END DESCRIPTION */ 00763 PCONTOUR IdCntCast (ims,imd) 00764 PCONTOUR ims,imd; 00765 { 00766 int i; 00767 if ( !IdCntSameSize (ims,imd)) 00768 { 00769 IdErrno = IDERR_WRONG_DIM; 00770 return 0; 00771 } 00772 if (IdCntType(imd)==IdCntType(ims)){ 00773 IdCntCopy(ims,imd); 00774 return imd; 00775 } 00776 00777 #define CRR(t1,t2) for(i=0;i<IdCntDimX(ims);i++) \ 00778 { ((t2)imd)[i].x = ((t1)ims)[i].x; \ 00779 ((t2)imd)[i].y = ((t1)ims)[i].y; \ 00780 } 00781 00782 #define CFR(PPt) switch ( IdCntType(imd) ) { \ 00783 case CNT_CHAR : CRR(PPt,PCONTOUR_CHAR); break; \ 00784 case CNT_UCHAR : CRR(PPt,PCONTOUR_UCHAR); break; \ 00785 case CNT_SHORT : CRR(PPt,PCONTOUR_SHORT); break; \ 00786 case CNT_USHORT : CRR(PPt,PCONTOUR_USHORT); break; \ 00787 case CNT_LONG : CRR(PPt,PCONTOUR_LONG); break; \ 00788 case CNT_ULONG : CRR(PPt,PCONTOUR_ULONG); break; \ 00789 case CNT_FLOAT : CRR(PPt,PCONTOUR_FLOAT); break; \ 00790 case CNT_DOUBLE : CRR(PPt,PCONTOUR_DOUBLE); break; \ 00791 default : IdErrno=IDERR_WRONG_TYPE; \ 00792 IdPrintf("Type non Traite1 %x\n",IdCntType(imd) ); \ 00793 return 0; } 00794 00795 switch ( IdCntType(ims) ) { 00796 case CNT_UCHAR : CFR(PCONTOUR_UCHAR); break; 00797 case CNT_CHAR : CFR(PCONTOUR_CHAR); break; 00798 case CNT_SHORT : CFR(PCONTOUR_SHORT); break; 00799 case CNT_USHORT : CFR(PCONTOUR_USHORT); break; 00800 case CNT_LONG : CFR(PCONTOUR_LONG); break; 00801 case CNT_ULONG : CFR(PCONTOUR_ULONG); break; 00802 case CNT_FLOAT : CFR(PCONTOUR_FLOAT); break; 00803 case CNT_DOUBLE : CFR(PCONTOUR_DOUBLE); break; 00804 default : IdErrno=IDERR_WRONG_TYPE; 00805 IdPrintf("Type non Traite2 %x\n",IdCntType(ims)); 00806 return 0; } 00807 IdCntSetUsedNbX(imd,IdCntGetUsedNbX(ims)); 00808 return imd; 00809 } 00810

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