00001 #include <tcl.h>
00002 #include <tk.h>
00003 #include "sadie.h"
00004 #include "proto.h"
00005 #include "sadie_byte.h"
00006 #include "sadie_short.h"
00007 #include "trees.h"
00008 #include "mosaic.h"
00009 #include "chain.h"
00010 #include "histogram.h"
00011
00012
00013
00014
00015
00016
00017 extern short nlev;
00018 extern short csize;
00019 extern double weight;
00020 extern double *count;
00021 extern PIXEL gain;
00022 extern PIXEL bias;
00023 extern PIXEL gmin;
00024 extern PIXEL gmax;
00025 extern PIXEL thresh;
00026 extern PIXEL gbrk[2][4];
00027 extern PIXEL *table;
00028
00029
00030 extern PIXEL globarray_original[50][100];
00031 extern PIXEL globarray_percent[50][100];
00032 extern PIXEL globarray_normalized[50][100];
00033 extern int globframecount;
00034 extern int globfreqcount;
00035
00036
00037
00038 int Sadie_TREES_GetRangeCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
00039 {
00040 int imgaddr;
00041 IMAGE *theimg;
00042 char msg[SLEN];
00043
00044 if( argc <= 1 ) {
00045 sprintf(msg, "Usage: Sadie_General_GetRange image_address");
00046 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00047 return TCL_ERROR;
00048 }
00049
00050 sscanf(argv[1], "%x", &imgaddr);
00051 theimg = (IMAGE *) imgaddr;
00052
00053 if (!CHECKIMG(theimg)) {
00054 Tcl_AppendResult(interp, "couldn't identify SADIE image from input string.", NULL);
00055 return TCL_ERROR;
00056 }
00057
00058 RANGE(theimg);
00059
00060 sprintf(msg, "%f %f", theimg->gmin, theimg->gmax);
00061
00062 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00063
00064
00065 return TCL_OK;
00066 }
00067
00068
00069
00070 int Sadie_TREES_ByteOpenCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
00071 {
00072 int addrstr;
00073 IMAGE_BYTE *byteimg=NULL;
00074 char msg[SLEN];
00075
00076 if( argc <= 1 ) {
00077 sprintf(msg, "Usage: Sadie_TREES_ByteOpen filename");
00078 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00079 return TCL_ERROR;
00080 }
00081
00082 BYTEDISK2IMG(argv[1],&byteimg);
00083
00084 addrstr = (int) byteimg;
00085
00086 sprintf(msg, "%x", addrstr);
00087 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00088
00089 return TCL_OK;
00090 }
00091
00092
00093 int Sadie_TREES_ByteSaveCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
00094 {
00095 int imgaddr;
00096 IMAGE_BYTE *byteimg=NULL;
00097 char* name;
00098 char msg[SLEN];
00099
00100
00101 if( argc <= 2 ) {
00102 sprintf(msg, "Usage: Sadie_TREES_ByteSave image_address filename");
00103 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00104 return TCL_ERROR;
00105 }
00106
00107 sscanf(argv[1], "%x", &imgaddr);
00108 byteimg = (IMAGE_BYTE *) imgaddr;
00109
00110 name = argv[2];
00111
00112
00113 BYTEIMG2DISK (byteimg,name);
00114
00115 return TCL_OK;
00116 }
00117
00118
00119 int Sadie_TREES_ByteCloseCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
00120 {
00121 int imgaddr;
00122 IMAGE_BYTE *byteimg=NULL;
00123 char msg[SLEN];
00124
00125
00126 if( argc <= 1 ) {
00127 sprintf(msg, "Usage: Sadie_TREES_ByteClose image_address");
00128 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00129 return TCL_ERROR;
00130 }
00131
00132 sscanf(argv[1], "%x", &imgaddr);
00133 byteimg = (IMAGE_BYTE *) imgaddr;
00134
00135 RELIMG_BYTE (&byteimg);
00136
00137 return TCL_OK;
00138 }
00139
00140
00141
00142 int Sadie_TREES_MosaicIndexOpenCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
00143 {
00144 int addrstr;
00145 MOSAIC_INDEX *theindex=NULL;
00146 char msg[SLEN];
00147
00148 if( argc <= 1 ) {
00149 sprintf(msg, "Usage: Sadie_TREES_MosaicIndexOpen filename");
00150 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00151 return TCL_ERROR;
00152 }
00153
00154 MOSAIC_DISK2INDEX (argv[1],&theindex);
00155
00156 addrstr = (int) theindex;
00157
00158 sprintf(msg, "%x", addrstr);
00159 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00160
00161 return TCL_OK;
00162 }
00163
00164
00165 int Sadie_TREES_MosaicIndexSaveCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
00166 {
00167 int indexaddr;
00168 MOSAIC_INDEX *theindex=NULL;
00169 char* name;
00170 char msg[SLEN];
00171
00172
00173 if( argc <= 2 ) {
00174 sprintf(msg, "Usage: Sadie_TREES_MosaicIndexSave image_address filename");
00175 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00176 return TCL_ERROR;
00177 }
00178
00179 sscanf(argv[1], "%x", &indexaddr);
00180 theindex = (MOSAIC_INDEX *) indexaddr;
00181
00182 name = argv[2];
00183
00184 MOSAIC_INDEX2DISK (theindex,name);
00185
00186 return TCL_OK;
00187 }
00188
00189
00190 int Sadie_TREES_MosaicIndexCloseCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
00191 {
00192 int indexaddr;
00193 MOSAIC_INDEX *index=NULL;
00194 char msg[SLEN];
00195
00196
00197 if( argc <= 1 ) {
00198 sprintf(msg, "Usage: Sadie_TREES_MosaicIndexClose index_address");
00199 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00200 return TCL_ERROR;
00201 }
00202
00203 sscanf(argv[1], "%x", &indexaddr);
00204 index = (MOSAIC_INDEX *) indexaddr;
00205
00206 RELIMG_MOSAIC_INDEX (&index);
00207
00208 return TCL_OK;
00209 }
00210
00211
00212 int Sadie_TREES_ChainCloseCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
00213 {
00214 int chainaddr;
00215 char msg[SLEN];
00216 CHAIN *chainmap = NULL;
00217
00218
00219 if( argc <= 1 ) {
00220 sprintf(msg, "Usage: Sadie_TREES_ChainClose chainmap_address");
00221 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00222 return TCL_ERROR;
00223 }
00224
00225 sscanf(argv[1], "%x", &chainaddr);
00226 chainmap = (CHAIN *) chainaddr;
00227
00228 RELMEM_CHAIN (chainmap);
00229
00230 return TCL_OK;
00231 }
00232
00233
00234 int Sadie_TREES_CreateMosaicCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
00235 {
00236 int i;
00237 char* imgname[200];
00238 int width, height, nimg, camh, camw;
00239 IMAGE_BYTE *outimg=NULL;
00240 MOSAIC_INDEX *index=NULL;
00241 int yoffset[200], xoffset[200];
00242 PIXEL gain[200], bias[200];
00243 PIXEL fillvalue;
00244 PIXEL gmin,factor;
00245 int illum_adjust;
00246 char* illum_image;
00247 double tempdouble;
00248 char msg[SLEN];
00249
00250 if( argc <= 7 ) {
00251 sprintf(msg, "Usage: Sadie_TREES_CreateMosaic nimg height width ...");
00252 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00253 return TCL_ERROR;
00254 }
00255
00256 if( Tcl_GetInt (interp, argv[1], &nimg) != TCL_OK ) {
00257 return TCL_ERROR;
00258 }
00259 if( Tcl_GetInt (interp, argv[2], &height) != TCL_OK ) {
00260 return TCL_ERROR;
00261 }
00262 if( Tcl_GetInt (interp, argv[3], &width) != TCL_OK ) {
00263 return TCL_ERROR;
00264 }
00265 if( Tcl_GetInt (interp, argv[4], &camh) != TCL_OK ) {
00266 return TCL_ERROR;
00267 }
00268 if( Tcl_GetInt (interp, argv[5], &camw) != TCL_OK ) {
00269 return TCL_ERROR;
00270 }
00271 if( Tcl_GetInt (interp, argv[6], &illum_adjust) != TCL_OK ) {
00272 return TCL_ERROR;
00273 }
00274 illum_image = argv[7];
00275 if( Tcl_GetDouble (interp, argv[8], &tempdouble) != TCL_OK ) {
00276 return TCL_ERROR;
00277 }
00278 factor = (PIXEL)tempdouble;
00279
00280 if( Tcl_GetDouble (interp, argv[9], &tempdouble) != TCL_OK ) {
00281 return TCL_ERROR;
00282 }
00283 gmin = (PIXEL)tempdouble;
00284
00285
00286 if( argc <= 9 + (nimg * 5) ) {
00287 sprintf(msg, "Usage: Sadie_Proto_CreateMosaic nimg height width illum_adjust illum_image factor gmin + (5 * nimg) more entries");
00288 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00289 return TCL_ERROR;
00290 }
00291
00292 for (i=0; i<nimg; i++) {
00293 imgname[i] = argv[10 + (i*5)];
00294
00295 if( Tcl_GetInt (interp, argv[11 + (i*5)], &xoffset[i]) != TCL_OK ) {
00296 return TCL_ERROR;
00297 }
00298 if( Tcl_GetInt (interp, argv[12 + (i*5)], &yoffset[i]) != TCL_OK ) {
00299 return TCL_ERROR;
00300 }
00301 if( Tcl_GetDouble (interp, argv[13 + (i*5)], &tempdouble) != TCL_OK ) {
00302 return TCL_ERROR;
00303 }
00304 bias[i] = (PIXEL)tempdouble;
00305 if( Tcl_GetDouble (interp, argv[14 + (i*5)], &tempdouble) != TCL_OK ) {
00306 return TCL_ERROR;
00307 }
00308 gain[i] = (PIXEL)tempdouble;
00309 }
00310
00311 fillvalue = (PIXEL) 0.0;
00312
00313
00314 CREATETREESMOSAIC((char **)imgname,illum_adjust,illum_image,nimg,height,width,camh,camw,(int *)xoffset,(int *)yoffset,(PIXEL *)bias,(PIXEL *)gain,gmin,factor,fillvalue,(IMAGE_BYTE **)&outimg,(MOSAIC_INDEX **)&index);
00315
00316
00317 sprintf(msg, "%x %x", (int)outimg, (int)index);
00318 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00319
00320
00321 return TCL_OK;
00322 }
00323
00324
00325
00326 int Sadie_TREES_ByteMosaicResampCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
00327 {
00328 int inimgaddr, outimgaddr, indexaddr;
00329 int lines, pix, incrlines, incrpix;
00330 IMAGE_BYTE *inimg=NULL;
00331 MOSAIC_INDEX *index=NULL;
00332 IMAGE *outimg=NULL;
00333 char msg[SLEN];
00334
00335 if( argc <= 6 ) {
00336 return TCL_ERROR;
00337 }
00338
00339
00340 sscanf(argv[1], "%x", &inimgaddr);
00341 inimg = (IMAGE_BYTE *) inimgaddr;
00342
00343 sscanf(argv[2], "%x", &indexaddr);
00344 index = (MOSAIC_INDEX *) indexaddr;
00345
00346 if( Tcl_GetInt (interp, argv[3], &lines) != TCL_OK ) {
00347 return TCL_ERROR;
00348 }
00349
00350 if( Tcl_GetInt (interp, argv[4], &pix) != TCL_OK ) {
00351 return TCL_ERROR;
00352 }
00353
00354 if( Tcl_GetInt (interp, argv[5], &incrlines) != TCL_OK ) {
00355 return TCL_ERROR;
00356 }
00357
00358 if( Tcl_GetInt (interp, argv[6], &incrpix) != TCL_OK ) {
00359 return TCL_ERROR;
00360 }
00361
00362
00363
00364 MOSAIC_BYTE_RESAMPL (inimg, index, lines, pix, incrlines, incrpix, &outimg);
00365
00366 outimgaddr = (int) outimg;
00367 sprintf(msg, "%x", outimgaddr);
00368 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00369
00370 return TCL_OK;
00371
00372 }
00373
00374
00375 int Sadie_TREES_MosaicImportCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
00376 {
00377 int outimgaddr, indexaddr;
00378 int jbgn, jend, jinc, kbgn, kend, kinc;
00379 MOSAIC_INDEX *index=NULL;
00380 IMAGE *outimg=NULL;
00381 char msg[SLEN];
00382
00383
00384 if( argc <= 8 ) {
00385 return TCL_ERROR;
00386 }
00387
00388
00389 sscanf(argv[1], "%x", &indexaddr);
00390 index = (MOSAIC_INDEX *) indexaddr;
00391
00392 if( Tcl_GetInt (interp, argv[3], &jbgn) != TCL_OK ) {
00393 return TCL_ERROR;
00394 }
00395
00396 if( Tcl_GetInt (interp, argv[4], &jend) != TCL_OK ) {
00397 return TCL_ERROR;
00398 }
00399
00400 if( Tcl_GetInt (interp, argv[5], &jinc) != TCL_OK ) {
00401 return TCL_ERROR;
00402 }
00403
00404 if( Tcl_GetInt (interp, argv[6], &kbgn) != TCL_OK ) {
00405 return TCL_ERROR;
00406 }
00407
00408 if( Tcl_GetInt (interp, argv[7], &kend) != TCL_OK ) {
00409 return TCL_ERROR;
00410 }
00411
00412 if( Tcl_GetInt (interp, argv[8], &kinc) != TCL_OK ) {
00413 return TCL_ERROR;
00414 }
00415
00416
00417
00418 MOSAIC_IMPORT (index, argv[2], jbgn, kbgn, jinc, kinc, jend, kend, &outimg);
00419
00420 outimgaddr = (int) outimg;
00421 sprintf(msg, "%x", outimgaddr);
00422 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00423
00424 return TCL_OK;
00425
00426 }
00427
00428
00429 int Sadie_TREES_ByteMosaicExportCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
00430 {
00431 int imgaddr;
00432 IMAGE_BYTE *theimg=NULL;
00433 char* name;
00434 char msg[SLEN];
00435
00436
00437 if( argc <= 2 ) {
00438 sprintf(msg, "Usage: Sadie_TREES_ByteMosaicExport image_address filename");
00439 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00440 return TCL_ERROR;
00441 }
00442
00443 sscanf(argv[1], "%x", &imgaddr);
00444 theimg = (IMAGE_BYTE *) imgaddr;
00445
00446 name = argv[2];
00447
00448
00449 MOSAIC_BYTE_EXPORT (theimg,name);
00450
00451 return TCL_OK;
00452 }
00453
00454
00455
00456 int Sadie_TREES_Chain2DiskCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
00457 {
00458 int addrstr;
00459 CHAIN *chainmap = NULL;
00460 char *filename;
00461 char msg[SLEN];
00462
00463 if( argc <= 2 ) {
00464 sprintf(msg, "Usage: Sadie_TREES_Chain2Disk chainmap filename");
00465 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00466 return TCL_ERROR;
00467 }
00468
00469 sscanf(argv[1], "%x", &addrstr);
00470 chainmap = (CHAIN *) addrstr;
00471
00472 filename = argv[2];
00473
00474 CHAIN2DISK(chainmap, filename);
00475
00476 return TCL_OK;
00477 }
00478
00479
00480
00481 int Sadie_TREES_Disk2ChainCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
00482 {
00483 CHAIN *chainmap = NULL;
00484 char msg[SLEN];
00485
00486 if( argc <= 1 ) {
00487 sprintf(msg, "Usage: Sadie_TREES_Disk2Chain filename");
00488 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00489 return TCL_ERROR;
00490 }
00491
00492 DISK2CHAIN(argv[1], &chainmap);
00493
00494 sprintf(msg, "%x", (int) chainmap);
00495 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00496
00497 return TCL_OK;
00498 }
00499
00500
00501
00502 int Sadie_TREES_ScaleChainCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
00503 {
00504 int addrstr;
00505 int scale;
00506 CHAIN *chainmap = NULL;
00507 CHAIN *scaledChain = NULL;
00508 char msg[SLEN];
00509
00510 if( argc <= 2 ) {
00511 sprintf(msg, "Usage: Sadie_TREES_ScaleChain chainmap scale");
00512 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00513 return TCL_ERROR;
00514 }
00515
00516 sscanf(argv[1], "%x", &addrstr);
00517 chainmap = (CHAIN *) addrstr;
00518
00519 if( Tcl_GetInt (interp, argv[2], &scale) != TCL_OK ) {
00520 return TCL_ERROR;
00521 }
00522
00523 SCALE_CHAIN(chainmap, scale, &scaledChain);
00524
00525 sprintf(msg, "%x", (int) scaledChain);
00526 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00527
00528 return TCL_OK;
00529 }
00530
00531
00532
00533 int Sadie_TREES_DisplayRingsCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
00534 {
00535 int prevx,prevy,currx,curry;
00536 int addrstr;
00537 CHAIN *chainmap = NULL;
00538 CHAIN_NODE *tempCnode = NULL;
00539 LIST_NODE *tempLnode = NULL;
00540 char msg[SLEN];
00541 char *canvas = NULL;
00542 char ringcolor[50], ringtag[50];
00543
00544 if( argc <= 2 ) {
00545 sprintf(msg, "Usage: Sadie_TREES_DisplayRings chainmap canvasname");
00546 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00547 return TCL_ERROR;
00548 }
00549
00550 sscanf(argv[1], "%x", &addrstr);
00551 chainmap = (CHAIN *) addrstr;
00552
00553 canvas = argv[2];
00554
00555 tempLnode = chainmap->list;
00556 while(tempLnode != NULL) {
00557
00558 prevx = tempLnode->startk;
00559 prevy = tempLnode->startj;
00560 currx = prevx;
00561 curry = prevy;
00562
00563 switch (tempLnode->ring_type) {
00564 case NORMAL :
00565 sprintf(ringcolor, "%s", "$boundarycolor(normal)");
00566 sprintf(ringtag, "\"Boundary-%d normal\"", tempLnode->ring_id);
00567 break;
00568
00569 case ADDED :
00570 sprintf(ringcolor, "%s", "$boundarycolor(added)");
00571 sprintf(ringtag, "\"Boundary-%d added\"", tempLnode->ring_id);
00572 break;
00573
00574 case REMOVED :
00575 sprintf(ringcolor, "%s", "$boundarycolor(removed)");
00576 sprintf(ringtag, "\"Boundary-%d removed\"", tempLnode->ring_id);
00577 break;
00578 }
00579
00580 tempCnode = tempLnode->chain;
00581 while(tempCnode != NULL) {
00582
00583 CHAIN_COMPUTE_COORDINATES(currx, curry, tempCnode->code, &currx, &curry);
00584 sprintf(msg, "%s create line %d %d %d %d -width 1 -fill %s -tag %s", canvas, prevx, prevy, currx, curry, ringcolor, ringtag);
00585
00586 if( Tcl_Eval(interp, msg) != TCL_OK ) {
00587 return TCL_ERROR;
00588 }
00589
00590 prevx = currx;
00591 prevy = curry;
00592 tempCnode = (CHAIN_NODE *)tempCnode->next;
00593 }
00594 tempLnode = tempLnode->next;
00595 }
00596
00597 return TCL_OK;
00598 }
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619 int Sadie_TREES_ComputeIndicesCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
00620 {
00621 Tcl_Obj* tclobj=NULL;
00622 Tcl_Obj* tclarrayname = NULL;
00623 Tcl_Obj* tclindexname = NULL;
00624 char msg[SLEN];
00625 char* array=NULL;
00626 int i, N;
00627 float *Z, *ZF, *RZ, ZSP, ZPV;
00628 double tempval;
00629
00630 if( argc != 2 ) {
00631 Tcl_AppendResult(interp,"wrong # args: should be \"",
00632 argv[0], " arrayname\"", (char *) NULL);
00633 return TCL_ERROR;
00634 }
00635 array=argv[1];
00636
00637
00638
00639 tclarrayname = Tcl_NewStringObj(array,-1);
00640 tclindexname = Tcl_NewStringObj("count",-1);
00641 if ((tclobj = Tcl_ObjGetVar2(interp, tclarrayname , tclindexname , TCL_GLOBAL_ONLY | TCL_LEAVE_ERR_MSG))) {
00642 if (Tcl_GetIntFromObj(interp,tclobj,&N) == TCL_ERROR) return TCL_ERROR;
00643 } else {
00644 return TCL_ERROR;
00645 }
00646 Tcl_DecrRefCount(tclarrayname);
00647 Tcl_DecrRefCount(tclindexname);
00648
00649 ZSP = 12.0;
00650 ZPV = 0.5;
00651 Z = (float *)malloc(N*sizeof(float));
00652 ZF = (float *)malloc(N*sizeof(float));
00653 RZ = (float *)malloc(N*sizeof(float));
00654
00655
00656 for (i=0; i<N; i++) {
00657
00658 tclarrayname = Tcl_NewStringObj(array,-1);
00659 sprintf(msg,"%d,width",i);
00660 tclindexname = Tcl_NewStringObj(msg,-1);
00661 if ((tclobj = Tcl_ObjGetVar2(interp, tclarrayname , tclindexname , TCL_GLOBAL_ONLY | TCL_LEAVE_ERR_MSG))) {
00662 if (Tcl_GetDoubleFromObj(interp,tclobj,&tempval) == TCL_ERROR) return TCL_ERROR;
00663 } else {
00664 return TCL_ERROR;
00665 }
00666 Tcl_DecrRefCount(tclarrayname);
00667 Tcl_DecrRefCount(tclindexname);
00668
00669 Z[i] = (float) tempval;
00670 ZF[i] = 0.0;
00671 }
00672
00673 SPLINE(N, Z, ZF, ZSP, ZPV);
00674 DIVSER(N, Z, ZF, RZ);
00675 for(i = 0; i < N; i++)
00676 {
00677 tempval = (double) RZ[i];
00678
00679
00680 tclobj = Tcl_NewDoubleObj(tempval);
00681 tclarrayname = Tcl_NewStringObj(array,-1);
00682 sprintf(msg,"%d,indexval",i);
00683 tclindexname = Tcl_NewStringObj(msg,-1);
00684 Tcl_ObjSetVar2(interp, tclarrayname , tclindexname , tclobj, TCL_GLOBAL_ONLY | TCL_LEAVE_ERR_MSG);
00685 Tcl_DecrRefCount(tclarrayname);
00686 Tcl_DecrRefCount(tclindexname);
00687 }
00688
00689 if (Z) free(Z);
00690 if (ZF) free(ZF);
00691 if (RZ) free(RZ);
00692
00693 return TCL_OK;
00694 }
00695
00696
00697
00698 int Sadie_TREES_DisplayPartRingsCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
00699 {
00700 int X1, Y1, X2, Y2;
00701 int prevx,prevy,currx,curry;
00702 int addrstr;
00703 CHAIN *chainmap = NULL;
00704 CHAIN_NODE *tempCnode = NULL;
00705 LIST_NODE *tempLnode = NULL;
00706 char msg[500];
00707 char *canvas = NULL;
00708 char ringcolor[50], ringtag[50];
00709
00710 if( argc <= 6 ) {
00711 sprintf(msg, "Usage: Sadie_TREES_DisplayPartRings chainmap X1 Y1 X2 Y2 canvasname");
00712 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00713 return TCL_ERROR;
00714 }
00715
00716 sscanf(argv[1], "%x", &addrstr);
00717 chainmap = (CHAIN *) addrstr;
00718
00719 if( Tcl_GetInt (interp, argv[2], &X1) != TCL_OK ) {
00720 return TCL_ERROR;
00721 }
00722 if( Tcl_GetInt (interp, argv[3], &Y1) != TCL_OK ) {
00723 return TCL_ERROR;
00724 }
00725 if( Tcl_GetInt (interp, argv[4], &X2) != TCL_OK ) {
00726 return TCL_ERROR;
00727 }
00728 if( Tcl_GetInt (interp, argv[5], &Y2) != TCL_OK ) {
00729 return TCL_ERROR;
00730 }
00731
00732 canvas = argv[6];
00733
00734 tempLnode = chainmap->list;
00735 while(tempLnode != NULL && (int)tempLnode->startk < X1 - 100)
00736 tempLnode = tempLnode->next;
00737
00738
00739 while(tempLnode != NULL && tempLnode->startk < X2 + 100) {
00740 prevx = tempLnode->startk;
00741 prevy = tempLnode->startj;
00742 currx = prevx;
00743 curry = prevy;
00744
00745 switch (tempLnode->ring_type) {
00746 case NORMAL :
00747 sprintf(ringcolor, "%s", "$boundarycolor(normal)");
00748 sprintf(ringtag, "\"ring Boundary-%d normal\"", tempLnode->ring_id);
00749 break;
00750
00751 case ADDED :
00752 sprintf(ringcolor, "%s", "$boundarycolor(added)");
00753 sprintf(ringtag, "\"ring Boundary-%d added\"", tempLnode->ring_id);
00754 break;
00755
00756 case REMOVED :
00757 sprintf(ringcolor, "%s", "$boundarycolor(removed)");
00758 sprintf(ringtag, "\"ring Boundary-%d removed\"", tempLnode->ring_id);
00759 break;
00760 }
00761
00762 tempCnode = tempLnode->chain;
00763 while(tempCnode != NULL) {
00764
00765 CHAIN_COMPUTE_COORDINATES(currx, curry, tempCnode->code, &currx, &curry);
00766
00767 if (curry >= Y1) {
00768 sprintf(msg, "%s create line %d %d %d %d -width 1 -fill %s -tag %s", canvas, prevx - X1, prevy - Y1, currx - X1, curry - Y1, ringcolor, ringtag);
00769
00770
00771 if( Tcl_Eval(interp, msg) != TCL_OK ) {
00772 return TCL_ERROR;
00773 }
00774 }
00775
00776 prevx = currx;
00777 prevy = curry;
00778 tempCnode = (CHAIN_NODE *)tempCnode->next;
00779
00780 if (curry > Y2)
00781 break;
00782 }
00783 tempLnode = tempLnode->next;
00784 }
00785
00786 return TCL_OK;
00787 }
00788
00789
00790
00791
00792 int Sadie_TREES_SynthesizeDisplayRingCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
00793 {
00794 int ring, fracWidth, ringnum;
00795 int addrstr;
00796 int left_x, left_y, right_x, right_y;
00797 int prevx, prevy, currx, curry;
00798 int AddAfterLast = 0;
00799 CHAIN *chainmap = NULL;
00800 LIST_NODE *leftLnode = NULL;
00801 LIST_NODE *rightLnode = NULL;
00802 CHAIN_NODE *leftCnode = NULL;
00803 CHAIN_NODE *rightCnode = NULL;
00804 char msg[SLEN];
00805 char *canvas = NULL;
00806
00807 if( argc <= 5 ) {
00808 sprintf(msg, "Usage: Sadie_TREES_SynthesizeDisplayRing smallchainmap <ring_id of ring on left> <percentage of width> <ring_id of added ring> canvasname");
00809 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00810 return TCL_ERROR;
00811 }
00812
00813 sscanf(argv[1], "%x", &addrstr);
00814 chainmap = (CHAIN *) addrstr;
00815
00816 if( Tcl_GetInt (interp, argv[2], &ring) != TCL_OK ) {
00817 return TCL_ERROR;
00818 }
00819 if( Tcl_GetInt (interp, argv[3], &fracWidth) != TCL_OK ) {
00820 return TCL_ERROR;
00821 }
00822 if( Tcl_GetInt (interp, argv[4], &ringnum) != TCL_OK ) {
00823 return TCL_ERROR;
00824 }
00825 canvas = argv[5];
00826
00827 leftLnode = chainmap->list;
00828 while(leftLnode != NULL && leftLnode->ring_id != ring)
00829 leftLnode = leftLnode->next;
00830
00831
00832 if( leftLnode == NULL ) {
00833 sprintf(msg, "SynthesizeDisplayRing >>Ring %d not found", ring);
00834 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00835 return TCL_ERROR;
00836 }
00837 if( leftLnode->next == NULL ) {
00838 AddAfterLast = 1;
00839 } else if( fracWidth <= 0 || fracWidth >= 100 ) {
00840 sprintf(msg, "SynthesizeDisplayRing >> Percentage of width should be between 1 and 99");
00841 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00842 return TCL_ERROR;
00843 }
00844
00845
00846 if(AddAfterLast)
00847 rightLnode = leftLnode;
00848 else
00849 rightLnode = leftLnode->next;
00850
00851 left_x = leftLnode->startk;
00852 left_y = leftLnode->startj;
00853 right_x = rightLnode->startk;
00854 right_y = rightLnode->startj;
00855
00856
00857 leftCnode = leftLnode->chain;
00858 rightCnode = rightLnode->chain;
00859
00860 if (left_y < right_y)
00861 while(leftCnode != NULL && left_y != right_y) {
00862 CHAIN_COMPUTE_COORDINATES(left_x, left_y, leftCnode->code, &left_x, &left_y);
00863 leftCnode = (CHAIN_NODE *)leftCnode->next;
00864
00865 }
00866 else if (right_y < left_y)
00867 while(rightCnode != NULL && right_y != left_y) {
00868 CHAIN_COMPUTE_COORDINATES(right_x, right_y, rightCnode->code, &right_x, &right_y);
00869 rightCnode = (CHAIN_NODE *)rightCnode->next;
00870 }
00871
00872 prevx = (int)(left_x + (right_x - left_x) * (float)fracWidth/100.0 + (float)(AddAfterLast*fracWidth));
00873 prevy = left_y;
00874
00875 while(leftCnode != NULL && rightCnode != NULL) {
00876
00877 CHAIN_COMPUTE_COORDINATES(left_x, left_y, leftCnode->code, &left_x, &left_y);
00878 CHAIN_COMPUTE_COORDINATES(right_x, right_y, rightCnode->code, &right_x, &right_y);
00879 currx = (int)(left_x + (right_x - left_x) * (float)fracWidth/100.0 + (float)(AddAfterLast*fracWidth));
00880 curry = left_y;
00881
00882 sprintf(msg,"%s create line %d %d %d %d -width 2 -fill $boundarycolor(added) -tag \"Boundary-%d added\"",canvas,prevx,prevy,currx,curry,ringnum);
00883
00884 if( Tcl_Eval(interp, msg) != TCL_OK ) {
00885 return TCL_ERROR;
00886 }
00887
00888 prevx = currx;
00889 prevy = curry;
00890 leftCnode = (CHAIN_NODE *)leftCnode->next;
00891 rightCnode = (CHAIN_NODE *)rightCnode->next;
00892
00893 }
00894
00895 return TCL_OK;
00896 }
00897
00898
00899 int Sadie_TREES_SynthesizeZoomRingCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
00900 {
00901 int ring, fracWidth, ringnum;
00902 int addrstr;
00903 int left_x, left_y, right_x, right_y;
00904 int prevx, prevy, currx, curry;
00905 int X1, Y1;
00906 int AddAfterLast = 0;
00907 CHAIN *chainmap = NULL;
00908 LIST_NODE *leftLnode = NULL;
00909 LIST_NODE *rightLnode = NULL;
00910 CHAIN_NODE *leftCnode = NULL;
00911 CHAIN_NODE *rightCnode = NULL;
00912 char msg[SLEN];
00913 char *canvas = NULL;
00914
00915 if( argc <= 7 ) {
00916 sprintf(msg, "Usage: Sadie_TREES_SynthesizeZoomRing chainmap <ring_id of ring on left> <percentage of width> <ring_id of added ring> canvasname <zoom window X1> <zoom window Y1>");
00917 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00918 return TCL_ERROR;
00919 }
00920
00921 sscanf(argv[1], "%x", &addrstr);
00922 chainmap = (CHAIN *) addrstr;
00923
00924 if( Tcl_GetInt (interp, argv[2], &ring) != TCL_OK ) {
00925 return TCL_ERROR;
00926 }
00927 if( Tcl_GetInt (interp, argv[3], &fracWidth) != TCL_OK ) {
00928 return TCL_ERROR;
00929 }
00930 if( Tcl_GetInt (interp, argv[4], &ringnum) != TCL_OK ) {
00931 return TCL_ERROR;
00932 }
00933
00934 canvas = argv[5];
00935
00936 if( Tcl_GetInt (interp, argv[6], &X1) != TCL_OK ) {
00937 return TCL_ERROR;
00938 }
00939 if( Tcl_GetInt (interp, argv[7], &Y1) != TCL_OK ) {
00940 return TCL_ERROR;
00941 }
00942
00943
00944 leftLnode = chainmap->list;
00945 while(leftLnode != NULL && leftLnode->ring_id != ring)
00946 leftLnode = leftLnode->next;
00947
00948
00949 if( leftLnode == NULL ) {
00950 sprintf(msg, "SynthesizeZoomRing >> Ring %d not found", ring);
00951 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00952 return TCL_ERROR;
00953 }
00954 if( leftLnode->next == NULL ) {
00955 AddAfterLast = 1;
00956 } else if( fracWidth <= 0 || fracWidth >= 100 ) {
00957 sprintf(msg, "SynthesizeZoomRing >> Percentage of width should be between 1 and 99");
00958 Tcl_SetResult(interp, msg, TCL_VOLATILE);
00959 return TCL_ERROR;
00960 }
00961
00962 if(AddAfterLast)
00963 rightLnode = leftLnode;
00964 else
00965 rightLnode = leftLnode->next;
00966
00967 left_x = leftLnode->startk;
00968 left_y = leftLnode->startj;
00969 right_x = rightLnode->startk;
00970 right_y = rightLnode->startj;
00971
00972 leftCnode = leftLnode->chain;
00973 rightCnode = rightLnode->chain;
00974
00975 if (left_y < right_y)
00976 while(leftCnode != NULL && left_y != right_y) {
00977 CHAIN_COMPUTE_COORDINATES(left_x, left_y, leftCnode->code, &left_x, &left_y);
00978 leftCnode = (CHAIN_NODE *)leftCnode->next;
00979
00980 }
00981 else if (right_y < left_y)
00982 while(rightCnode != NULL && right_y != left_y) {
00983 CHAIN_COMPUTE_COORDINATES(right_x, right_y, rightCnode->code, &right_x, &right_y);
00984 rightCnode = (CHAIN_NODE *)rightCnode->next;
00985 }
00986
00987 prevx = (int)(left_x + (right_x - left_x) * (float)fracWidth/100.0 + (float)(AddAfterLast*fracWidth));
00988 prevy = left_y;
00989
00990 printf("Added Line Coordinates in Zoom Window:\n");
00991 while(leftCnode != NULL && rightCnode != NULL) {
00992
00993 CHAIN_COMPUTE_COORDINATES(left_x, left_y, leftCnode->code, &left_x, &left_y);
00994 CHAIN_COMPUTE_COORDINATES(right_x, right_y, rightCnode->code, &right_x, &right_y);
00995 currx = (int)(left_x + (right_x - left_x) * (float)fracWidth/100.0 + (float)(AddAfterLast*fracWidth));
00996 curry = left_y;
00997
00998 sprintf(msg,"%s create line %d %d %d %d -width 1 -fill $boundarycolor(added) -tag \"ring Boundary-%d added\"", canvas, prevx - X1, prevy - Y1, currx - X1, curry - Y1, ringnum);
00999
01000
01001 if( Tcl_Eval(interp, msg) != TCL_OK ) {
01002 return TCL_ERROR;
01003 }
01004
01005 prevx = currx;
01006 prevy = curry;
01007 leftCnode = (CHAIN_NODE *)leftCnode->next;
01008 rightCnode = (CHAIN_NODE *)rightCnode->next;
01009
01010 }
01011
01012 return TCL_OK;
01013 }
01014
01015 int Sadie_TREES_UpdateROICmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
01016 {
01017 short left, right, top, bottom;
01018 int hstart, hend, vtop, vbottom, zoom;
01019 int i, X[4], Y[4];
01020 int addrstr;
01021 MOSAIC_INDEX *index = NULL;
01022 char msg[SLEN];
01023
01024 if( argc <= 10 ) {
01025 sprintf(msg, "Usage: Sadie_TREES_UpdateROI index <current zoom factor> P1 P2 P4 P5");
01026 Tcl_SetResult(interp, msg, TCL_VOLATILE);
01027 return TCL_ERROR;
01028 }
01029
01030 sscanf(argv[1], "%x", &addrstr);
01031 index = (MOSAIC_INDEX *) addrstr;
01032
01033 if( Tcl_GetInt (interp, argv[2], &zoom) != TCL_OK ) {
01034 return TCL_ERROR;
01035 }
01036 if( Tcl_GetInt (interp, argv[3], &X[0]) != TCL_OK ) {
01037 return TCL_ERROR;
01038 }
01039 if( Tcl_GetInt (interp, argv[4], &Y[0]) != TCL_OK ) {
01040 return TCL_ERROR;
01041 }
01042 if( Tcl_GetInt (interp, argv[5], &X[1]) != TCL_OK ) {
01043 return TCL_ERROR;
01044 }
01045 if( Tcl_GetInt (interp, argv[6], &Y[1]) != TCL_OK ) {
01046 return TCL_ERROR;
01047 }
01048 if( Tcl_GetInt (interp, argv[7], &X[2]) != TCL_OK ) {
01049 return TCL_ERROR;
01050 }
01051 if( Tcl_GetInt (interp, argv[8], &Y[2]) != TCL_OK ) {
01052 return TCL_ERROR;
01053 }
01054 if( Tcl_GetInt (interp, argv[9], &X[3]) != TCL_OK ) {
01055 return TCL_ERROR;
01056 }
01057 if( Tcl_GetInt (interp, argv[10], &Y[3]) != TCL_OK ) {
01058 return TCL_ERROR;
01059 }
01060
01061 hstart = index->npix -1;
01062 hend = 0;
01063 vtop = index->nlin -1;
01064 vbottom = 0;
01065 left = 0;
01066 right = 0;
01067 top = 0;
01068 bottom= 0;
01069
01070 for(i = 0; i < 4; i++) {
01071 X[i] = X[i] * zoom;
01072 Y[i] = Y[i] * zoom;
01073 if (X[i] == hstart) {
01074 left = (Y[i] < Y[left]? i: left);
01075 } else if (X[i] < hstart) {
01076 hstart = X[i];
01077 left = i;
01078 }
01079 if (X[i] == hend) {
01080 right = (Y[i] > Y[right]? i: right);
01081 } else if (X[i] > hend) {
01082 hend = X[i];
01083 right = i;
01084 }
01085 if (Y[i] == vtop) {
01086 top = (X[i] > X[top]? i: top);
01087 } else if (Y[i] < vtop) {
01088 vtop = Y[i];
01089 top = i;
01090 }
01091 if (Y[i] == vbottom) {
01092 bottom = (X[i] < X[bottom]? i: bottom);
01093 } else if (Y[i] > vbottom) {
01094 vbottom = Y[i];
01095 bottom = i;
01096 }
01097 }
01098
01099
01100 index->hstart = hstart;
01101 index->hend = hend;
01102
01103
01104 index->roi->left[0] = Y[left];
01105 index->roi->left[1] = X[left];
01106
01107 index->roi->right[0] = Y[right];
01108 index->roi->right[1] = X[right];
01109
01110 index->roi->top[0] = Y[top];
01111 index->roi->top[1] = X[top];
01112
01113 index->roi->bottom[0] = Y[bottom];
01114 index->roi->bottom[1] = X[bottom];
01115
01116 printf("\n>> Sadie >> top(%d,%d), bottom(%d,%d), left(%d,%d), right(%d,%d)\n", Y[top],X[top],Y[bottom],X[bottom],Y[left],X[left],Y[right],X[right]);
01117
01118
01119 COMPUTEVSTART(index, X[top], Y[top], X[left], Y[left]);
01120
01121
01122 COMPUTEVSTART(index, X[top], Y[top], X[right], Y[right]);
01123
01124
01125 COMPUTEVEND(index, X[bottom], Y[bottom], X[right], Y[right]);
01126
01127
01128 COMPUTEVEND(index, X[bottom], Y[bottom], X[left], Y[left]);
01129
01130
01131
01132 index->vstart[hstart] = Y[left];
01133 index->vstart[hend] = Y[right];
01134 index->vend[hend] = Y[right];
01135 index->vend[hstart] = Y[left];
01136
01137 return TCL_OK;
01138 }
01139
01140
01141 int Sadie_TREES_Chain_RingWidthsCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
01142 {
01143 int i, j, npix;
01144 int addrstr;
01145 IMAGE_BYTE *mosaicimg=NULL;
01146 MOSAIC_INDEX *index=NULL;
01147 CHAIN *chainmap=NULL;
01148 IMAGE_BYTE *widthsimg=NULL;
01149 char msg[SLEN];
01150 char *widthlist=NULL;
01151 char *profilelist=NULL;
01152
01153 int numrings=0;
01154 double *ringwidths=NULL;
01155
01156 if( argc <= 4 ) {
01157 sprintf(msg, "Usage: Sadie_TREES_RingWidths mosaic index chainmap listname");
01158 Tcl_SetResult(interp, msg, TCL_VOLATILE);
01159 return TCL_ERROR;
01160 }
01161
01162 sscanf(argv[1], "%x", &addrstr);
01163 mosaicimg = (IMAGE_BYTE *) addrstr;
01164
01165 sscanf(argv[2], "%x", &addrstr);
01166 index = (MOSAIC_INDEX *) addrstr;
01167
01168 sscanf(argv[3], "%x", &addrstr);
01169 chainmap = (CHAIN *) addrstr;
01170
01171 widthlist = argv[4];
01172
01173 profilelist = argv[5];
01174
01175 CHAIN_RINGWIDTHS(mosaicimg, index, chainmap, &widthsimg, &numrings, &ringwidths);
01176
01177 sprintf(msg,"global %s\nset %s {}",widthlist,widthlist);
01178 if( Tcl_Eval(interp, msg) != TCL_OK ) {
01179 return TCL_ERROR;
01180 }
01181 sprintf(msg,"global %s\nset %s {}",profilelist,profilelist);
01182 if( Tcl_Eval(interp, msg) != TCL_OK ) {
01183 return TCL_ERROR;
01184 }
01185 for (i=0; i<numrings; i++) {
01186 sprintf(msg,"lappend %s %f",widthlist,ringwidths[i]);
01187 if( Tcl_Eval(interp, msg) != TCL_OK ) {
01188 return TCL_ERROR;
01189 }
01190 sprintf(msg,"set proftemp {}\n");
01191 if( Tcl_Eval(interp, msg) != TCL_OK ) {
01192 return TCL_ERROR;
01193 }
01194 if (ringwidths[i] < MAXPROFILE) {
01195 npix = (int)(ringwidths[i]);
01196 for (j = 0; j < npix; j++) {
01197 sprintf(msg,"lappend proftemp %f",3.14159);
01198 if( Tcl_Eval(interp, msg) != TCL_OK ) {
01199 return TCL_ERROR;
01200 }
01201 }
01202 }
01203 sprintf(msg,"lappend %s $proftemp",profilelist);
01204 if( Tcl_Eval(interp, msg) != TCL_OK ) {
01205 return TCL_ERROR;
01206 }
01207 }
01208
01209 if (ringwidths) free(ringwidths);
01210
01211 return TCL_OK;
01212 }
01213
01214
01215 int Sadie_TREES_SynthesizeInsertRingCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
01216 {
01217 int ring, fracWidth, ringnum;
01218 int addrstr;
01219 CHAIN *chainmap = NULL;
01220 char msg[SLEN];
01221
01222 if( argc <= 4 ) {
01223 sprintf(msg, "Usage: Sadie_TREES_SynthesizeInsertRing chainmap <ring_id of ring on left> <percentage of width> <ring_id of added ring>");
01224 Tcl_SetResult(interp, msg, TCL_VOLATILE);
01225 return TCL_ERROR;
01226 }
01227
01228 sscanf(argv[1], "%x", &addrstr);
01229 chainmap = (CHAIN *) addrstr;
01230
01231 if( Tcl_GetInt (interp, argv[2], &ring) != TCL_OK ) {
01232 return TCL_ERROR;
01233 }
01234 if( Tcl_GetInt (interp, argv[3], &fracWidth) != TCL_OK ) {
01235 return TCL_ERROR;
01236 }
01237 if( Tcl_GetInt (interp, argv[4], &ringnum) != TCL_OK ) {
01238 return TCL_ERROR;
01239 }
01240
01241 SYNTHESIZE_INSERT_RING(chainmap, ring, fracWidth, ringnum);
01242
01243 return TCL_OK;
01244 }
01245
01246
01247
01248 int Sadie_TREES_RemoveRingCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
01249 {
01250 int ringnum;
01251 int addrstr;
01252 CHAIN *chainmap = NULL;
01253 LIST_NODE *tempLnode;
01254 LIST_NODE **prevLnode;
01255 char msg[SLEN];
01256
01257 if( argc <= 2 ) {
01258 sprintf(msg, "Usage: Sadie_TREES_RemoveRing chainmap <ring_id of ring to be Removed>");
01259 Tcl_SetResult(interp, msg, TCL_VOLATILE);
01260 return TCL_ERROR;
01261 }
01262
01263 sscanf(argv[1], "%x", &addrstr);
01264 chainmap = (CHAIN *) addrstr;
01265
01266 if( Tcl_GetInt (interp, argv[2], &ringnum) != TCL_OK ) {
01267 return TCL_ERROR;
01268 }
01269
01270 tempLnode = chainmap->list;
01271 prevLnode = (LIST_NODE **)&(chainmap->list);
01272 while (tempLnode != NULL && tempLnode->ring_id != ringnum) {
01273 prevLnode = (LIST_NODE **)&(tempLnode->next);
01274 tempLnode = tempLnode->next;
01275 }
01276
01277 if (tempLnode == NULL) {
01278 sprintf(msg, "RemoveRing >> Ring %d not found", ringnum);
01279 Tcl_SetResult(interp, msg, TCL_VOLATILE);
01280 return TCL_ERROR;
01281 }
01282
01283 switch (tempLnode->ring_type) {
01284 case NORMAL :
01285 tempLnode->ring_type = REMOVED;
01286 break;
01287
01288 case ADDED :
01289 (*prevLnode) = tempLnode->next;
01290 break;
01291
01292 case REMOVED :
01293 sprintf(msg, "RemoveRing >> Ring %d is a REMOVED ring", ringnum);
01294 Tcl_SetResult(interp, msg, TCL_VOLATILE);
01295 return TCL_ERROR;
01296 break;
01297
01298 default :
01299 sprintf(msg, "RemoveRing >> Ring %d - unknown ring type", ringnum);
01300 Tcl_SetResult(interp, msg, TCL_VOLATILE);
01301 return TCL_ERROR;
01302 }
01303
01304 return TCL_OK;
01305 }
01306
01307
01308
01309 int Sadie_TREES_UnRemoveRingCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
01310 {
01311 int ringnum;
01312 int addrstr;
01313 CHAIN *chainmap = NULL;
01314 LIST_NODE *tempLnode;
01315 char msg[SLEN];
01316
01317 if( argc <= 2 ) {
01318 sprintf(msg, "Usage: Sadie_TREES_UnRemoveRing chainmap <ring_id of ring to be Unremoved>");
01319 Tcl_SetResult(interp, msg, TCL_VOLATILE);
01320 return TCL_ERROR;
01321 }
01322
01323 sscanf(argv[1], "%x", &addrstr);
01324 chainmap = (CHAIN *) addrstr;
01325
01326 if( Tcl_GetInt (interp, argv[2], &ringnum) != TCL_OK ) {
01327 return TCL_ERROR;
01328 }
01329
01330 tempLnode = chainmap->list;
01331 while (tempLnode != NULL && tempLnode->ring_id != ringnum)
01332 tempLnode = tempLnode->next;
01333
01334
01335 if (tempLnode == NULL) {
01336 sprintf(msg, "UnRemoveRing >> Ring %d not found", ringnum);
01337 Tcl_SetResult(interp, msg, TCL_VOLATILE);
01338 return TCL_ERROR;
01339 }
01340
01341 switch (tempLnode->ring_type) {
01342 case NORMAL :
01343 sprintf(msg, "UnRemoveRing >> Ring %d is a NORMAL ring", ringnum);
01344 Tcl_SetResult(interp, msg, TCL_VOLATILE);
01345 return TCL_ERROR;
01346 break;
01347
01348 case ADDED :
01349 sprintf(msg, "UnRemoveRing >> Ring %d is an ADDED ring", ringnum);
01350 Tcl_SetResult(interp, msg, TCL_VOLATILE);
01351 return TCL_ERROR;
01352 break;
01353
01354 case REMOVED :
01355 tempLnode->ring_type = NORMAL;
01356 break;
01357
01358 default :
01359 sprintf(msg, "UnRemoveRing >> Ring %d - unknown ring type", ringnum);
01360 Tcl_SetResult(interp, msg, TCL_VOLATILE);
01361 return TCL_ERROR;
01362 }
01363
01364 return TCL_OK;
01365 }
01366
01367
01368
01369 int Sadie_TREES_QueryRingTypeCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
01370 {
01371 int ringnum;
01372 int addrstr;
01373 CHAIN *chainmap = NULL;
01374 LIST_NODE *tempLnode;
01375 char msg[SLEN];
01376
01377 if( argc <= 2 ) {
01378 sprintf(msg, "Usage: Sadie_TREES_QueryRingType chainmap <ring_id of ring to query>");
01379 Tcl_SetResult(interp, msg, TCL_VOLATILE);
01380 return TCL_ERROR;
01381 }
01382
01383 sscanf(argv[1], "%x", &addrstr);
01384 chainmap = (CHAIN *) addrstr;
01385
01386 if( Tcl_GetInt (interp, argv[2], &ringnum) != TCL_OK ) {
01387 return TCL_ERROR;
01388 }
01389
01390 tempLnode = chainmap->list;
01391 while (tempLnode != NULL && tempLnode->ring_id != ringnum)
01392 tempLnode = tempLnode->next;
01393
01394
01395 if (tempLnode == NULL) {
01396 sprintf(msg, "QueryRingType >> Ring %d not found", ringnum);
01397 Tcl_SetResult(interp, msg, TCL_VOLATILE);
01398 return TCL_ERROR;
01399 }
01400
01401 switch (tempLnode->ring_type) {
01402 case NORMAL :
01403
01404 case ADDED :
01405
01406 case REMOVED :
01407 sprintf(msg, "%d", (int)tempLnode->ring_type);
01408 Tcl_SetResult(interp, msg, TCL_VOLATILE);
01409 break;
01410
01411 default :
01412 sprintf(msg, "QueryRingType >> Ring %d - unknown ring type", ringnum);
01413 Tcl_SetResult(interp, msg, TCL_VOLATILE);
01414 return TCL_ERROR;
01415 }
01416
01417 return TCL_OK;
01418 }
01419
01420
01421
01422 int Sadie_TREES_QueryBoundaryIdCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
01423 {
01424 int count, index;
01425 int addrstr;
01426 CHAIN *chainmap = NULL;
01427 LIST_NODE *tempLnode;
01428 char msg[SLEN];
01429
01430 if( argc <= 2 ) {
01431 sprintf(msg, "Usage: Sadie_TREES_QueryBoundaryId chainmap index");
01432 Tcl_SetResult(interp, msg, TCL_VOLATILE);
01433 return TCL_ERROR;
01434 }
01435
01436 sscanf(argv[1], "%x", &addrstr);
01437 chainmap = (CHAIN *) addrstr;
01438
01439 if( Tcl_GetInt (interp, argv[2], &index) != TCL_OK ) {
01440 return TCL_ERROR;
01441 }
01442
01443 if (index < 0) {
01444 sprintf(msg, "QueryBoundaryId >> Index is Negative");
01445 Tcl_SetResult(interp, msg, TCL_VOLATILE);
01446 return TCL_ERROR;
01447 }
01448
01449 count = 0;
01450 tempLnode = chainmap->list;
01451 while (tempLnode != NULL && count++ != index)
01452 tempLnode = tempLnode->next;
01453
01454
01455 if (tempLnode == NULL) {
01456 sprintf(msg, "QueryBoundaryId >> There are fewer than %d rings", index+1);
01457 Tcl_SetResult(interp, msg, TCL_VOLATILE);
01458 return TCL_ERROR;
01459 }
01460
01461 sprintf(msg, "%d", (int)tempLnode->ring_id);
01462 Tcl_SetResult(interp, msg, TCL_VOLATILE);
01463
01464 return TCL_OK;
01465 }
01466
01467
01468 int Sadie_TREES_Mosaic2MosaicResamplCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
01469 {
01470 int inimgaddr, outimgaddr, indexaddr;
01471 int lines, pix, incrlines, incrpix;
01472 IMAGE_BYTE *inimg=NULL;
01473 MOSAIC_INDEX *index=NULL;
01474 IMAGE_BYTE *outimg=NULL;
01475 char msg[SLEN];
01476
01477 if( argc <= 6 ) {
01478 return TCL_ERROR;
01479 }
01480
01481
01482 sscanf(argv[1], "%x", &inimgaddr);
01483 inimg = (IMAGE_BYTE *) inimgaddr;
01484
01485 sscanf(argv[2], "%x", &indexaddr);
01486 index = (MOSAIC_INDEX *) indexaddr;
01487
01488 if( Tcl_GetInt (interp, argv[3], &lines) != TCL_OK ) {
01489 return TCL_ERROR;
01490 }
01491
01492 if( Tcl_GetInt (interp, argv[4], &pix) != TCL_OK ) {
01493 return TCL_ERROR;
01494 }
01495
01496 if( Tcl_GetInt (interp, argv[5], &incrlines) != TCL_OK ) {
01497 return TCL_ERROR;
01498 }
01499
01500 if( Tcl_GetInt (interp, argv[6], &incrpix) != TCL_OK ) {
01501 return TCL_ERROR;
01502 }
01503
01504
01505
01506 MOSAIC2MOSAIC_RESAMPL (inimg, index, lines, pix, incrlines, incrpix, &outimg);
01507
01508 outimgaddr = (int) outimg;
01509 sprintf(msg, "%x", outimgaddr);
01510 Tcl_SetResult(interp, msg, TCL_VOLATILE);
01511
01512 return TCL_OK;
01513
01514 }
01515
01516 int Sadie_TREES_IndexResamplCmd(ClientData client_data, Tcl_Interp* interp, int argc, char *argv[])
01517 {
01518 int indexaddr, outindaddr;
01519 int scale;
01520 MOSAIC_INDEX *index=NULL;
01521 MOSAIC_INDEX *scaledindex=NULL;
01522 char msg[SLEN];
01523
01524 if( argc <= 2 ) {
01525 return TCL_ERROR;
01526 }
01527
01528
01529 sscanf(argv[1], "%x", &indexaddr);
01530 index = (MOSAIC_INDEX *) indexaddr;
01531
01532 if( Tcl_GetInt (interp, argv[2], &scale) != TCL_OK ) {
01533 return TCL_ERROR;
01534 }
01535
01536 INDEX_RESAMPL (index, scale, &scaledindex);
01537
01538 outindaddr = (int) scaledindex;
01539 sprintf(msg, "%x", outindaddr);
01540 Tcl_SetResult(interp, msg, TCL_VOLATILE);
01541
01542 return TCL_OK;
01543
01544 }
01545
01546
01547
01548
01549
01550
01551
01552
01553
01554 int Sadie_TREES_Init(Tcl_Interp *interp) {
01555 Tcl_CreateCommand(interp, "Sadie_TREES_CreateMosaic", Sadie_TREES_CreateMosaicCmd,
01556 (ClientData) NULL, NULL);
01557 Tcl_CreateCommand(interp, "Sadie_TREES_GetRange", Sadie_TREES_GetRangeCmd,
01558 (ClientData) NULL, NULL);
01559 Tcl_CreateCommand(interp, "Sadie_TREES_ByteSave", Sadie_TREES_ByteSaveCmd,
01560 (ClientData) NULL, NULL);
01561 Tcl_CreateCommand(interp, "Sadie_TREES_ByteOpen", Sadie_TREES_ByteOpenCmd,
01562 (ClientData) NULL, NULL);
01563 Tcl_CreateCommand(interp, "Sadie_TREES_ByteClose", Sadie_TREES_ByteCloseCmd,
01564 (ClientData) NULL, NULL);
01565 Tcl_CreateCommand(interp, "Sadie_TREES_MosaicIndexSave", Sadie_TREES_MosaicIndexSaveCmd,
01566 (ClientData) NULL, NULL);
01567 Tcl_CreateCommand(interp, "Sadie_TREES_MosaicIndexOpen", Sadie_TREES_MosaicIndexOpenCmd,
01568 (ClientData) NULL, NULL);
01569 Tcl_CreateCommand(interp, "Sadie_TREES_MosaicIndexClose", Sadie_TREES_MosaicIndexCloseCmd,
01570 (ClientData) NULL, NULL);
01571 Tcl_CreateCommand(interp, "Sadie_TREES_ChainClose", Sadie_TREES_ChainCloseCmd,
01572 (ClientData) NULL, NULL);
01573 Tcl_CreateCommand(interp, "Sadie_TREES_ByteMosaicResamp", Sadie_TREES_ByteMosaicResampCmd,
01574 (ClientData) NULL, NULL);
01575 Tcl_CreateCommand(interp, "Sadie_TREES_MosaicImport", Sadie_TREES_MosaicImportCmd,
01576 (ClientData) NULL, NULL);
01577 Tcl_CreateCommand(interp, "Sadie_TREES_ByteMosaicExport", Sadie_TREES_ByteMosaicExportCmd,
01578 (ClientData) NULL, NULL);
01579 Tcl_CreateCommand(interp, "Sadie_TREES_Chain2Disk", Sadie_TREES_Chain2DiskCmd,
01580 (ClientData) NULL, NULL);
01581 Tcl_CreateCommand(interp, "Sadie_TREES_Disk2Chain", Sadie_TREES_Disk2ChainCmd,
01582 (ClientData) NULL, NULL);
01583 Tcl_CreateCommand(interp, "Sadie_TREES_ScaleChain", Sadie_TREES_ScaleChainCmd,
01584 (ClientData) NULL, NULL);
01585 Tcl_CreateCommand(interp, "Sadie_TREES_DisplayRings", Sadie_TREES_DisplayRingsCmd,
01586 (ClientData) NULL, NULL);
01587 Tcl_CreateCommand(interp, "Sadie_TREES_ComputeIndices", Sadie_TREES_ComputeIndicesCmd,
01588 (ClientData) NULL, NULL);
01589 Tcl_CreateCommand(interp, "Sadie_TREES_DisplayPartRings", Sadie_TREES_DisplayPartRingsCmd,
01590 (ClientData) NULL, NULL);
01591 Tcl_CreateCommand(interp, "Sadie_TREES_SynthesizeDisplayRing", Sadie_TREES_SynthesizeDisplayRingCmd,
01592 (ClientData) NULL, NULL);
01593 Tcl_CreateCommand(interp, "Sadie_TREES_SynthesizeZoomRing", Sadie_TREES_SynthesizeZoomRingCmd,
01594 (ClientData) NULL, NULL);
01595 Tcl_CreateCommand(interp, "Sadie_TREES_UpdateROI", Sadie_TREES_UpdateROICmd,
01596 (ClientData) NULL, NULL);
01597 Tcl_CreateCommand(interp, "Sadie_TREES_Chain_RingWidths", Sadie_TREES_Chain_RingWidthsCmd,
01598 (ClientData) NULL, NULL);
01599 Tcl_CreateCommand(interp, "Sadie_TREES_SynthesizeInsertRing", Sadie_TREES_SynthesizeInsertRingCmd,
01600 (ClientData) NULL, NULL);
01601 Tcl_CreateCommand(interp, "Sadie_TREES_RemoveRing", Sadie_TREES_RemoveRingCmd,
01602 (ClientData) NULL, NULL);
01603 Tcl_CreateCommand(interp, "Sadie_TREES_UnRemoveRing", Sadie_TREES_UnRemoveRingCmd,
01604 (ClientData) NULL, NULL);
01605 Tcl_CreateCommand(interp, "Sadie_TREES_QueryRingType", Sadie_TREES_QueryRingTypeCmd,
01606 (ClientData) NULL, NULL);
01607 Tcl_CreateCommand(interp, "Sadie_TREES_QueryBoundaryId", Sadie_TREES_QueryBoundaryIdCmd,
01608 (ClientData) NULL, NULL);
01609 Tcl_CreateCommand(interp, "Sadie_TREES_Mosaic2MosaicResampl", Sadie_TREES_Mosaic2MosaicResamplCmd,
01610 (ClientData) NULL, NULL);
01611 Tcl_CreateCommand(interp, "Sadie_TREES_IndexResampl", Sadie_TREES_IndexResamplCmd,
01612 (ClientData) NULL, NULL);
01613
01614 Sadie_TREES_Ext_Init(interp);
01615
01616 return TCL_OK;
01617 }
01618