34 int do_show(
Bimage* p, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[]);
35 int do_magnify(
Bimage* p, Tcl_Interp *interp,
int objc, Tcl_Obj *CONST objv[]);
39 Tcl_Obj*
do_get(
Bimage* p,
int objc, Tcl_Obj *CONST objv[]);
159 Tcl_ResetResult(interp);
164 Tcl_AppendResult(interp,
"wrong # args", (
char *)NULL);
168 Bstring action = Tcl_GetStringFromObj(objv[1], NULL);
170 cout <<
"DEBUG BimageCmd: Action: " << action <<
" (" << action.
length() <<
")" << endl;
173 Bstring photoName = Tcl_GetStringFromObj(objv[2], NULL);
175 cout <<
"DEBUG BimageCmd: Image object name: " << photoName <<
"(" << photoName.
length() <<
")" << endl;
177 Tcl_Obj* returnObj = Tcl_NewObj();
179 char string[4] =
" ";
180 Tcl_SetStringObj(returnObj,
string, 1);
194 }
else if ( photoName ==
"thetemp" ) tmp = 1;
206 if ( action ==
"exists" ) {
207 if ( p ) Tcl_SetIntObj(returnObj, 1);
208 else Tcl_SetIntObj(returnObj, 0);
209 }
else if ( action ==
"open" ) {
212 Tcl_AppendResult(interp,
"No file name given!", (
char *)NULL);
217 file_name = Tcl_GetStringFromObj(objv[3], NULL);
219 cout <<
"DEBUG BimageCmd: File name: " << file_name <<
"(" << file_name.
length() <<
")" << endl;
223 if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &img_num);
225 cout <<
"DEBUG BimageCmd: Image number: " << img_num << endl;
228 ptemp =
read_img(file_name, 0, img_num);
230 Tcl_AppendResult(interp,
"File not read!", (
char *)NULL);
237 cout <<
"DEBUG BimageCmd: list: " <<
imglist <<
" pointer: " << p << endl;
246 for ( ptemp =
imglist; ptemp; ptemp = ptemp->
next ) {
247 if ( ptemp->
next == p ) {
257 pnew =
read_img(file_name, 1, img_num);
259 cout <<
"DEBUG BimageCmd: Image pointer: " << pnew << endl;
261 Tcl_SetIntObj(returnObj, -1);
264 Tcl_AppendResult(interp,
"File not read!", (
char *)NULL);
283 Tcl_SetIntObj(returnObj, pnew->
images());
285 }
else if ( action ==
"close" ) {
288 Tcl_AppendResult(interp,
"No file name given!", (
char *)NULL);
293 file_name = Tcl_GetStringFromObj(objv[3], NULL);
295 cout <<
"DEBUG BimageCmd: File name: " << file_name <<
"(" << file_name.
length() <<
")" << endl;
301 for ( ptemp =
imglist; ptemp; ptemp = ptemp->
next ) {
302 if ( ptemp->
next == p ) {
310 cout <<
"DEBUG BimageCmd: Deleting: " << p->
file_name() << endl;
314 }
else if ( action ==
"kill" ) {
320 }
else if ( action ==
"save" ) {
322 Tcl_AppendResult(interp,
"No file name given!", (
char *)NULL);
327 file_name = Tcl_GetStringFromObj(objv[3], NULL);
329 cout <<
"DEBUG BimageCmd: File name: " << file_name <<
"(" << file_name.
length() <<
")" << endl;
332 Tcl_AppendResult(interp,
"No file in memory!", (
char *)NULL);
336 command =
"Written from bshow";
339 }
else if ( action ==
"save_montage" ) {
341 Tcl_AppendResult(interp,
"No file name given!", (
char *)NULL);
346 file_name = Tcl_GetStringFromObj(objv[3], NULL);
348 cout <<
"DEBUG BimageCmd: File name: " << file_name <<
"(" << file_name.
length() <<
")" << endl;
351 Tcl_AppendResult(interp,
"No file in memory!", (
char *)NULL);
357 command =
"Written from bshow";
362 }
else if ( action ==
"show" ) {
363 if ( p )
do_show(p, interp, objc, objv);
364 }
else if ( action ==
"template" ) {
367 }
else if ( action ==
"magnify" ) {
370 }
else if ( action ==
"montage" ) {
376 }
else if ( action ==
"delete" ) {
378 }
else if ( action ==
"statistics" ) {
380 }
else if ( action ==
"get" ) {
381 returnObj =
do_get(p, objc, objv);
382 }
else if ( action ==
"set" ) {
384 }
else if ( action ==
"switch" ) {
386 }
else if ( action ==
"fixtype" ) {
388 }
else if ( action ==
"stats" ) {
389 returnObj =
do_stats(p, objc, objv);
390 }
else if ( action ==
"center" ) {
392 }
else if ( action ==
"zero_origin" ) {
394 }
else if ( action ==
"extract" ) {
396 }
else if ( action ==
"crop" ) {
398 }
else if ( action ==
"pad" ) {
400 }
else if ( action ==
"invert" ) {
402 }
else if ( action ==
"truncate" ) {
404 }
else if ( action ==
"rescale" ) {
406 }
else if ( action ==
"reslice" ) {
408 }
else if ( action ==
"rotate" ) {
410 }
else if ( action ==
"bin" ) {
412 }
else if ( action ==
"average" ) {
414 }
else if ( action ==
"variance" ) {
416 }
else if ( action ==
"normalize" ) {
418 }
else if ( action ==
"gaussian" ) {
420 }
else if ( action ==
"histogram" ) {
422 }
else if ( action ==
"radial" ) {
424 }
else if ( action ==
"fft" ) {
426 }
else if ( action ==
"powerspec" ) {
432 }
else if ( action ==
"diffori" ) {
435 cerr <<
"Error: Action " << action <<
" not recognized!" << endl;
438 Tcl_SetObjResult(interp, returnObj);
446 Tk_PhotoHandle photoHandle = Tk_FindPhoto(interp, photoName.
c_str());
447 Tk_PhotoImageBlock block;
450 cout <<
"DEBUG image_render: photoName = " << photoName << endl;
452 #ifdef USE_PANIC_ON_PHOTO_ALLOC_FAILURE
453 Tk_PhotoSetSize(photoHandle, p->
sizeX(), p->
sizeY());
455 Tk_PhotoSetSize(interp, photoHandle, p->
sizeX(), p->
sizeY());
461 block.pixelPtr = (
unsigned char *) (p->
data_pointer() + i*imgsize);
464 block.width = p->
sizeX();
465 block.height = p->
sizeY();
468 cout <<
"DEBUG image_render: width = " << block.width <<
" height = " << block.height << endl;
477 cout <<
"DEBUG image_render: pixelSize = " << block.pixelSize <<
" pitch = " << block.pitch << endl;
480 block.offset[0] = block.offset[1] = block.offset[2] = 0;
489 if (
sizeof(block.offset) > 12 ) {
491 if ( p->
channels() == 4 ) block.offset[3] = 3;
495 cout <<
"DEBUG image_render: offset=" << block.offset[0] <<
496 "," << block.offset[1] <<
"," << block.offset[2] <<
497 "," << block.offset[3] << endl;
500 #ifdef TK_PHOTO_COMPOSITE_SET
501 # ifdef USE_PANIC_ON_PHOTO_ALLOC_FAILURE
502 Tk_PhotoPutBlock(photoHandle, &block, 0, 0, p->
sizeX(), p->
sizeY(), TK_PHOTO_COMPOSITE_SET);
505 Tk_PhotoPutBlock(interp, photoHandle, &block, 0, 0, p->
sizeX(), p->
sizeY(), TK_PHOTO_COMPOSITE_SET);
509 Tk_PhotoPutBlock(photoHandle, &block, 0, 0, p->
sizeX(), p->
sizeY());
523 Tk_PhotoHandle photoHandle;
526 Bstring photoName = Tcl_GetStringFromObj(objv[2], NULL);
529 cout <<
"DEBUG do_show: Image pointer: " << p << endl;
532 if ( objc > 3 ) Tcl_GetIntFromObj(NULL, objv[3], &img_num);
534 cout <<
"DEBUG do_show: Image number: " << img_num << endl;
536 if ( img_num < 0 || img_num >= (
long)p->
images() ) img_num = 0;
539 if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &slice_num);
541 cout <<
"DEBUG do_show: Slice number: " << slice_num << endl;
543 if ( slice_num < 0 || slice_num >= (
long)p->
sizeZ() ) slice_num = 0;
546 if ( objc > 5 ) Tcl_GetDoubleFromObj(NULL, objv[5], &dscale);
548 cout <<
"DEBUG do_show: Scale: " << dscale << endl;
550 if ( dscale < 0.1 ) dscale = 0.1;
551 if ( dscale > 10 ) dscale = 10;
554 if ( objc > 6 ) Tcl_GetIntFromObj(NULL, objv[6], &mode);
556 cout <<
"DEBUG do_show: Mode: " << mode << endl;
559 photoHandle = Tk_FindPhoto(interp, photoName.
c_str());
560 if ( photoHandle == NULL ) {
561 Tcl_AppendResult(interp,
"can't find photo named \"",
562 photoName.
c_str(),
"\"", (
char *)NULL);
593 cout <<
"Time to extract: ";
601 cout <<
"Time to render: ";
619 Bstring baseName = Tcl_GetStringFromObj(objv[2], NULL);
621 if ( objc > 3 ) Tcl_GetIntFromObj(NULL, objv[3], &img_num);
622 if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], ¢er[0]);
623 if ( objc > 5 ) Tcl_GetIntFromObj(NULL, objv[5], ¢er[1]);
624 if ( objc > 6 ) Tcl_GetIntFromObj(NULL, objv[6], ¢er[2]);
625 if ( objc > 7 ) Tcl_GetDoubleFromObj(NULL, objv[7], &scale);
626 if ( objc > 8 ) Tcl_GetIntFromObj(NULL, objv[8], &size[0]);
627 if ( objc > 9 ) Tcl_GetIntFromObj(NULL, objv[9], &size[1]);
628 if ( objc > 10 ) Tcl_GetIntFromObj(NULL, objv[10], &size[2]);
631 cout <<
"DEBUG do_magnify: img=" << img_num <<
" center=" << center << endl;
635 if ( !pmag )
return 0;
638 for ( h=0; h<pmag->
images(); h++ ) {
639 photoName = baseName +
Bstring(h,
"%d");
655 Bstring photoName = Tcl_GetStringFromObj(objv[2], NULL);
657 if ( objc > 3 ) Tcl_GetIntFromObj(NULL, objv[3], &slice_num);
658 if ( slice_num < 0 || slice_num >= p->
sizeZ() ) slice_num = p->
sizeZ()/2;
660 if ( objc > 4 ) Tcl_GetDoubleFromObj(NULL, objv[4], &dscale);
663 cout <<
"DEBUG do_template: slice_num=" << slice_num <<
" dscale=" << dscale << endl;
671 cout <<
"DEBUG do_template: slices=" << pt->
images() << endl;
696 if ( !p )
return NULL;
709 if ( pp != p )
delete pp;
718 Tcl_Obj* returnObj = Tcl_NewObj();
720 if ( !p )
return returnObj;
724 if ( objc > 3 ) delist = Tcl_GetStringFromObj(objv[3], NULL);
733 Tcl_Obj* returnObj = Tcl_NewObj();
735 if ( !p )
return returnObj;
738 int j(-1), iz(0), n(0);
744 Bstring property = Tcl_GetStringFromObj(objv[3], NULL);
746 cout <<
"DEBUG do_get: Property: " <<
property <<
" (" <<
property.length() <<
")" << endl;
749 Tcl_GetIntFromObj(NULL, objv[4], &j);
750 if ( j<0 || j>=p->
images() ) j = 0;
753 if ( !p || property.empty() ) {
754 Tcl_SetIntObj(returnObj, 0);
755 }
else if ( property ==
"info" ) {
758 Tcl_SetIntObj(returnObj, 0);
759 }
else if ( property ==
"filename" ) {
761 }
else if ( property ==
"label" ) {
762 Tcl_SetStringObj(returnObj, (
char *)p->
label().c_str(), p->
label().length());
763 }
else if ( property ==
"nimages" ) {
764 Tcl_SetIntObj(returnObj, p->
images());
765 }
else if ( property ==
"channels" ) {
766 Tcl_SetIntObj(returnObj, p->
channels());
767 }
else if ( property ==
"nslices" ) {
768 Tcl_SetIntObj(returnObj, p->
sizeZ());
769 }
else if ( property ==
"width" ) {
770 Tcl_SetIntObj(returnObj, p->
sizeX());
771 }
else if ( property ==
"height" ) {
772 Tcl_SetIntObj(returnObj, p->
sizeY());
773 }
else if ( property ==
"size" ) {
775 Tcl_AppendToObj(returnObj,
string, strlen(
string));
776 }
else if ( property ==
"center" ) {
778 Tcl_AppendToObj(returnObj,
string, strlen(
string));
779 }
else if ( property ==
"origin" ) {
782 Tcl_AppendToObj(returnObj,
string, strlen(
string));
783 }
else if ( property ==
"select" ) {
786 }
else if ( property ==
"show_image" ) {
788 }
else if ( property ==
"show_slice" ) {
790 }
else if ( property ==
"show_scale" ) {
792 }
else if ( property ==
"show_min" ) {
794 }
else if ( property ==
"show_max" ) {
796 }
else if ( property ==
"min" ) {
797 if ( j < 0 ) Tcl_SetDoubleObj(returnObj, p->
minimum());
798 else Tcl_SetDoubleObj(returnObj, p->
image[j].
minimum());
799 }
else if ( property ==
"max" ) {
800 if ( j < 0 ) Tcl_SetDoubleObj(returnObj, p->
maximum());
801 else Tcl_SetDoubleObj(returnObj, p->
image[j].
maximum());
802 }
else if ( property ==
"average" ) {
803 if ( j < 0 ) Tcl_SetDoubleObj(returnObj, p->
average());
804 else Tcl_SetDoubleObj(returnObj, p->
image[j].
average());
805 }
else if ( property ==
"standard_deviation" ) {
808 }
else if ( property ==
"background" ) {
809 if ( j < 0 ) Tcl_SetDoubleObj(returnObj, p->
background(
long(0)));
811 }
else if ( property ==
"datatype" ) {
813 Tcl_SetStringObj(returnObj, (
char *)datatype_string.
c_str(), datatype_string.
length());
814 }
else if ( property ==
"pixel_size" ) {
816 for ( i=0; i<p->
images(); ++i ) {
818 Tcl_AppendToObj(returnObj,
string, strlen(
string));
822 Tcl_AppendToObj(returnObj,
string, strlen(
string));
824 }
else if ( property ==
"pixel" ) {
827 Tcl_GetDoubleFromObj(NULL, objv[4], &x);
829 if ( ix >=0 && ix < p->sizeX() ) {
832 if ( ix < 0 ) ix += p->
sizeX();
835 Tcl_GetDoubleFromObj(NULL, objv[5], &y);
837 if ( iy >= 0 && iy < p->sizeY() ) {
838 if ( objc > 6 ) Tcl_GetIntFromObj(NULL, objv[6], &iz);
839 if ( objc > 7 ) Tcl_GetIntFromObj(NULL, objv[7], &n);
842 if ( iy < 0 ) iy += p->
sizeY();
844 if ( iz < 0 ) iz += p->
sizeZ();
846 i = p->
index(0,ix,iy,iz,n);
847 for ( c=0, j=0; c<p->
channels(); c++, i++ ) {
849 j += snprintf(&
string[j],
MAXLINELEN,
"%.0f ", (*p)[i]);
851 j += snprintf(&
string[j],
MAXLINELEN,
"%g ", (*p)[i]);
857 Tcl_AppendToObj(returnObj,
string, strlen(
string));
858 }
else if ( property ==
"line" ) {
859 returnObj =
do_line(p, objc, objv);
861 cerr <<
"Error in do_get: Property " <<
property <<
" not recognized!" << endl;
869 Tcl_Obj* returnObj = Tcl_NewObj();
871 if ( !p )
return returnObj;
877 if ( objc > 4 ) Tcl_GetDoubleFromObj(NULL, objv[4], &start[0]);
878 if ( objc > 5 ) Tcl_GetDoubleFromObj(NULL, objv[5], &start[1]);
879 if ( objc > 6 ) Tcl_GetDoubleFromObj(NULL, objv[6], &start[2]);
880 if ( objc > 7 ) Tcl_GetDoubleFromObj(NULL, objv[7], &end[0]);
881 if ( objc > 8 ) Tcl_GetDoubleFromObj(NULL, objv[8], &end[1]);
882 if ( objc > 9 ) Tcl_GetDoubleFromObj(NULL, objv[9], &end[2]);
883 if ( objc > 10 ) Tcl_GetIntFromObj(NULL, objv[10], &n);
884 if ( objc > 11 ) Tcl_GetLongFromObj(NULL, objv[11], &width);
887 long i, j, wh(width/2);
889 long len(vec.length() + 1);
895 for ( i=0; i<len; i++ ) {
896 coor = start + vec*i;
897 for ( value=0, j=-wh; j<=wh; ++j )
900 snprintf(
string, 128,
" %d %g %g %g %g", n, coor[0], coor[1], coor[2], value);
901 Tcl_AppendToObj(returnObj,
string, strlen(
string));
914 double scale(1), smin, smax;
918 Bstring property = Tcl_GetStringFromObj(objv[3], NULL);
920 cout <<
"DEBUG do_set: Property: " <<
property <<
" (" <<
property.length() <<
")" << endl;
922 if ( objc < 4 || !p )
return 0;
924 if ( property ==
"label" ) {
925 astring = Tcl_GetStringFromObj(objv[4], NULL);
927 }
else if ( property ==
"origin" ) {
929 if ( objc > 7 ) Tcl_GetIntFromObj(NULL, objv[7], &i);
931 cout <<
"DEBUG do_set: setting origin for " << i << endl;
932 if ( i < (
int)p->
images() ) {
934 Tcl_GetDoubleFromObj(NULL, objv[4], &ox);
935 if ( p->
sizeX() < 2 ) ox = 0;
938 Tcl_GetDoubleFromObj(NULL, objv[5], &oy);
939 if ( p->
sizeY() < 2 ) oy = 0;
942 Tcl_GetDoubleFromObj(NULL, objv[6], &oz);
943 if ( p->
sizeZ() < 2 ) oz = 0;
945 if ( i < 0 ) p->
origin(ox, oy, oz);
946 else p->
origin(i, ox, oy, oz);
948 cout <<
"DEBUG do_set: origin set: " << p->
image->
origin() << endl;
950 }
else if ( property ==
"select" ) {
953 if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &i);
954 if ( objc > 5 ) Tcl_GetIntFromObj(NULL, objv[5], &n);
956 cout <<
"DEBUG do_set: setting selection for " << i << endl;
958 for ( i=0; i<p->
images(); i++ )
960 else if ( i < p->images() )
962 }
else if ( property ==
"show_image" ) {
963 Tcl_GetIntFromObj(NULL, objv[4], &i);
965 }
else if ( property ==
"show_slice" ) {
966 Tcl_GetIntFromObj(NULL, objv[4], &i);
968 }
else if ( property ==
"show_scale" ) {
969 Tcl_GetDoubleFromObj(NULL, objv[4], &scale);
971 }
else if ( property ==
"show_min" ) {
972 Tcl_GetDoubleFromObj(NULL, objv[4], &smin);
974 }
else if ( property ==
"show_max" ) {
975 Tcl_GetDoubleFromObj(NULL, objv[4], &smax);
977 }
else if ( property ==
"datatype" ) {
978 astring = Tcl_GetStringFromObj(objv[4], NULL);
980 }
else if ( property ==
"pixel_size" ) {
981 if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &i);
982 if ( objc > 5 ) Tcl_GetDoubleFromObj(NULL, objv[5], &sam[0]);
983 if ( objc > 6 ) Tcl_GetDoubleFromObj(NULL, objv[6], &sam[1]);
984 if ( objc > 7 ) Tcl_GetDoubleFromObj(NULL, objv[7], &sam[2]);
987 }
else if ( property ==
"montage" ) {
988 if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &
mont.
ncol);
989 if ( objc > 5 ) Tcl_GetIntFromObj(NULL, objv[5], &
mont.
nrow);
990 if ( objc > 6 ) Tcl_GetIntFromObj(NULL, objv[6], &
mont.
first);
991 if ( objc > 7 ) Tcl_GetIntFromObj(NULL, objv[7], &
mont.
skip);
992 if ( objc > 8 ) Tcl_GetIntFromObj(NULL, objv[8], &
mont.
pad);
993 if ( objc > 9 ) Tcl_GetDoubleFromObj(NULL, objv[9], &
mont.
fill);
994 if ( objc > 10 ) Tcl_GetIntFromObj(NULL, objv[10], &
mont.
flip);
997 cerr <<
"Error in do_set: Property " <<
property <<
" not recognized!" << endl;
1005 if ( !p )
return -1;
1009 else if ( p->
sizeZ() > 1 )
1019 if ( !p )
return -1;
1030 Tcl_Obj* returnObj = Tcl_NewObj();
1032 if ( !p )
return returnObj;
1034 if ( objc < 4 )
return returnObj;
1036 int img_num(-1), type(0), nvert(0), i, k;
1037 double sum(0), avg(0), std(0);
1040 Tcl_GetIntFromObj(NULL, objv[3], &img_num);
1042 Tcl_GetIntFromObj(NULL, objv[4], &type);
1044 if ( type < 1 || type > 3 )
return returnObj;
1046 Bstring alist = Tcl_GetStringFromObj(objv[5], NULL);
1053 case 2:
if ( n > 5 ) {
1059 case 3: nvert = n/3;
1060 cout <<
"Number of vertices = " << nvert << endl;
1063 for ( i=k=0; i<nvert; i++, k+=3 ) {
1065 cout << poly[i][0] <<
" " << poly[i][1] <<
" " << poly[i][2] << endl;
1075 if ( poly )
delete[] poly;
1080 snprintf(
string,
MAXLINELEN,
"%ld %g %g %g", n, sum, avg, std);
1081 Tcl_AppendToObj(returnObj,
string, strlen(
string));
1108 if ( objc < 4 )
return 0;
1114 Bstring file_name = Tcl_GetStringFromObj(objv[3], NULL);
1115 Tcl_GetIntFromObj(NULL, objv[4], &img_num);
1118 Bstring alist = Tcl_GetStringFromObj(objv[5], NULL);
1120 if ( v.size() < 6 )
return 0;
1121 if ( v[0] > v[3] ) swap(v[0], v[3]);
1122 if ( v[1] > v[4] ) swap(v[1], v[4]);
1123 if ( v[2] > v[5] ) swap(v[2], v[5]);
1125 size =
Vector3<int>((
int) (v[3]-v[0]+1), (
int) (v[4]-v[1]+1), (
int) (v[5]-v[2]+1));
1128 start = start.
max(0);
1129 if ( size[0] < 1 || size[0] >= p->
sizeX() ) size[0] = p->
sizeX();
1130 if ( size[1] < 1 || size[1] >= p->
sizeY() ) size[1] = p->
sizeY();
1131 if ( size[2] < 1 || size[2] >= p->
sizeZ() ) size[2] = p->
sizeZ();
1152 if ( objc < 4 )
return 0;
1156 Bstring alist = Tcl_GetStringFromObj(objv[4], NULL);
1159 if ( v.size() < 6 )
return 0;
1164 if ( start[0] > end[0] ) swap(start[0], end[0]);
1165 if ( start[1] > end[1] ) swap(start[1], end[1]);
1166 if ( start[2] > end[2] ) swap(start[2], end[2]);
1168 start = start.
max(0);
1169 if ( end[0] >= p->
sizeX() ) end[0] = p->
sizeX() - 1;
1170 if ( end[1] >= p->
sizeY() ) end[1] = p->
sizeY() - 1;
1171 if ( end[2] >= p->
sizeZ() ) end[2] = p->
sizeZ() - 1;
1175 newsize += end - start;
1179 return p->
resize(newsize, translate, 0, 0);
1186 if ( objc < 4 )
return 0;
1194 if ( objc > 3 ) Tcl_GetIntFromObj(NULL, objv[3], &translate[0]);
1195 if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &translate[1]);
1196 if ( objc > 5 ) Tcl_GetIntFromObj(NULL, objv[5], &translate[2]);
1197 if ( objc > 6 ) Tcl_GetIntFromObj(NULL, objv[6], &size[0]);
1198 if ( objc > 7 ) Tcl_GetIntFromObj(NULL, objv[7], &size[1]);
1199 if ( objc > 8 ) Tcl_GetIntFromObj(NULL, objv[8], &size[2]);
1200 if ( objc > 9 ) Tcl_GetIntFromObj(NULL, objv[9], &filltype);
1201 if ( objc > 10 ) Tcl_GetDoubleFromObj(NULL, objv[10], &fill);
1205 return p->
resize(size, translate, filltype, fill);
1224 Tcl_GetDoubleFromObj(NULL, objv[3], &min);
1225 Tcl_GetDoubleFromObj(NULL, objv[4], &max);
1226 if ( fabs(min - p->
minimum()) > tol || fabs(max - p->
maximum()) > tol ) {
1241 Tcl_GetDoubleFromObj(NULL, objv[3], &avg);
1242 Tcl_GetDoubleFromObj(NULL, objv[4], &std);
1259 order = Tcl_GetStringFromObj(objv[3], NULL);
1272 if ( objc > 3 ) Tcl_GetDoubleFromObj(NULL, objv[3], &euler[0]);
1273 if ( objc > 4 ) Tcl_GetDoubleFromObj(NULL, objv[4], &euler[1]);
1274 if ( objc > 5 ) Tcl_GetDoubleFromObj(NULL, objv[5], &euler[2]);
1276 euler[0] *=
M_PI/180.0;
1277 euler[1] *=
M_PI/180.0;
1278 euler[2] *=
M_PI/180.0;
1280 if ( euler.
psi() || euler.
theta() || euler.
phi() )
1294 if ( objc > 3 ) Tcl_GetIntFromObj(NULL, objv[3], &bin[0]);
1295 if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &bin[1]);
1296 if ( objc > 5 ) Tcl_GetIntFromObj(NULL, objv[5], &bin[2]);
1298 if ( bin[0]*bin[1]*bin[2] > 1 ) p->bin(bin);
1309 if ( objc > 3 ) Tcl_GetIntFromObj(NULL, objv[3], &k[0]);
1310 if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &k[1]);
1311 if ( objc > 5 ) Tcl_GetIntFromObj(NULL, objv[5], &k[2]);
1324 if ( objc > 3 ) Tcl_GetIntFromObj(NULL, objv[3], &k);
1337 if ( objc > 3 ) Tcl_GetIntFromObj(NULL, objv[3], &k[0]);
1338 if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &k[1]);
1339 if ( objc > 5 ) Tcl_GetIntFromObj(NULL, objv[5], &k[2]);
1353 if ( objc > 3 ) Tcl_GetIntFromObj(NULL, objv[3], &k);
1354 if ( objc > 4 ) Tcl_GetDoubleFromObj(NULL, objv[4], &sigma);
1363 Tcl_Obj* returnObj = Tcl_NewObj();
1365 if ( !p )
return returnObj;
1369 if ( objc > 3 ) Tcl_GetIntFromObj(NULL, objv[3], &bins);
1371 double scale, offset;
1372 vector<long> hist = p->
histogram(bins, scale, offset);
1374 for ( i=0; i<bins*p->
channels(); i++ ) {
1375 snprintf(
string, 128,
"%ld ", hist[i]);
1376 Tcl_AppendToObj(returnObj,
string, strlen(
string));
1387 double ox(0), oy(0), oz(0), angle(0);
1388 char* maskname = NULL;
1390 Tcl_Obj* returnObj = Tcl_NewObj();
1392 if ( !p )
return returnObj;
1398 if ( objc > 3 ) Tcl_GetDoubleFromObj(NULL, objv[3], &ox);
1399 if ( objc > 4 ) Tcl_GetDoubleFromObj(NULL, objv[4], &oy);
1400 if ( objc > 5 ) Tcl_GetDoubleFromObj(NULL, objv[5], &oz);
1404 if ( objc > 6 ) Tcl_GetDoubleFromObj(NULL, objv[6], &angle);
1406 if ( objc > 7 ) maskname = Tcl_GetStringFromObj(objv[7], NULL);
1408 if ( objc > 8 ) Tcl_GetIntFromObj(NULL, objv[8], &wrap);
1410 angle *=
M_PI/180.0;
1413 if ( maskname && strlen(maskname) > 2 ) pmask =
read_img(maskname, 1, -1);
1415 long i, len(p->
sizeX()/2);
1419 for ( i=0; i<prad->
sizeX(); i++ ) {
1420 if ( !
isfinite((*prad)[i]) ) cerr <<
"Warning: Point " << i <<
" is a NaN!" << endl;
1421 snprintf(
string, 128,
" %g", (*prad)[i]);
1422 Tcl_AppendToObj(returnObj,
string, strlen(
string));
1430 for ( i=0; i<len; i++ ) {
1431 if ( !
isfinite((*prad)[i]) ) cerr <<
"Warning: Point " << i <<
" is a NaN!" << endl;
1432 snprintf(
string, 128,
" %g", (*prad)[i]);
1433 Tcl_AppendToObj(returnObj,
string, strlen(
string));
1441 for ( i=0; i<len; i++ ) {
1442 if ( !
isfinite((*prad)[i]) ) cerr <<
"Warning: Point " << i <<
" is a NaN!" << endl;
1443 snprintf(
string, 128,
" %g", (*prad)[i]);
1444 Tcl_AppendToObj(returnObj,
string, strlen(
string));
1459 double ox(0), oy(0), oz =0;
1460 char* maskname = NULL;
1462 if ( objc > 3 ) Tcl_GetDoubleFromObj(NULL, objv[3], &ox);
1464 if ( objc > 4 ) Tcl_GetDoubleFromObj(NULL, objv[4], &oy);
1466 if ( objc > 5 ) Tcl_GetDoubleFromObj(NULL, objv[5], &oz);
1468 if ( objc > 7 ) maskname = Tcl_GetStringFromObj(objv[7], NULL);
1470 if ( ox > 0 ) p->
origin(ox, oy, oz);
1473 if ( maskname && strlen(maskname) > 2 ) pmask =
read_img(maskname, 1, -1);
1476 double radius(p->
sizeX()/4.0), sigma(0);
1477 p->
find_center(pmask, hires, lores, radius, sigma, 1);
1489 if ( objc > 3 ) Tcl_GetIntFromObj(NULL, objv[3], &dir);
1493 }
else if ( dir < 0 ) {
1507 double tilt_axis(0), tilt_angle(0), tilt_offset(0);
1508 double defocus(0), Cs(2), volt(300);
1511 if ( objc > 3 ) Tcl_GetIntFromObj(NULL, objv[3], &flags);
1512 if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &tile_size[0]);
1513 if ( objc > 5 ) Tcl_GetIntFromObj(NULL, objv[5], &tile_size[1]);
1514 if ( objc > 6 ) Tcl_GetIntFromObj(NULL, objv[6], &tile_size[2]);
1515 if ( objc > 7 ) Tcl_GetDoubleFromObj(NULL, objv[7], &tilt_axis);
1516 if ( objc > 8 ) Tcl_GetDoubleFromObj(NULL, objv[8], &tilt_angle);
1517 if ( objc > 9 ) Tcl_GetDoubleFromObj(NULL, objv[9], &tilt_offset);
1518 if ( objc > 10 ) Tcl_GetDoubleFromObj(NULL, objv[10], &defocus);
1519 if ( objc > 11 ) Tcl_GetDoubleFromObj(NULL, objv[11], &Cs);
1520 if ( objc > 12 ) Tcl_GetDoubleFromObj(NULL, objv[12], &volt);
1526 tilt_axis *=
M_PI/180.0;
1527 tilt_angle *=
M_PI/180.0;
1528 if ( defocus < 100 ) defocus *= 1e4;
1529 if ( Cs < 100 ) Cs *= 1e7;
1530 if ( volt < 10000 ) volt *= 1000;
1532 double iCL2(1.0/(Cs*lamda*lamda));
1534 tilt_angle, tilt_offset, defocus, iCL2, flags);