00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
#include <math.h>
00042
#include <string.h>
00043
#include <stdlib.h>
00044
#include "idcnt.h"
00045
#include "idcalc.h"
00046
#include "iderr.h"
00047
#include "idprint.h"
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
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);
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
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
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
00159
00160
if (numPoint ==
IdCntUsedNbX(*contour))
00161 {
00162
00163
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
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
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
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
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
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
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
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
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
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
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.) )
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
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
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
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
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
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
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
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671 PCONTOUR IdCntClear ( cont )
00672 PCONTOUR cont;
00673 {
00674
00675
int taille_cont;
00676
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
00686 memset( cont, 0, taille_cont );
00687
00688
IdCntSetUsedNbX(cont,0);
00689
00690
return cont;
00691 }
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719 PCONTOUR IdCntCopy (ims,imd)
00720 PCONTOUR ims,imd;
00721 {
00722
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
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
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