Bsoft  1.9
Bernard's software package
tcltk_bshow.cpp
Go to the documentation of this file.
1 
9 // Tk must be included before anything else to remedy symbol conflicts
10 #include <tk.h>
11 
12 #include "tcltk_bimage.h"
13 #include "tcltk_bmg.h"
14 #include "tcltk_bmodel.h"
15 
16 #include "file_util.h"
17 #include "timer.h"
18 #include "utilities.h"
19 
20 // Declaration of global variables
21 extern int verbose; // Level of output to the screen
22 
23 // Globals necessary to make the Tcl/Tk interface work
24 static Tcl_ObjCmdProc bitSizeCmd;
25 static Tcl_ObjCmdProc fileTypeCmd;
26 static Tcl_ObjCmdProc spectrumCmd;
27 static Tcl_ObjCmdProc BimageCmd;
28 static Tcl_ObjCmdProc BmgCmd;
29 static Tcl_ObjCmdProc BmodelCmd;
30 Bimage* imglist = NULL;
31 Bproject* project = NULL;
32 Bmodel* model = NULL;
33 
34 Bimage* imgtemp = NULL;
35 
36 /* These functions are dynamically loaded by the "load" command */
37 extern "C" int Tcltk_bshow_Init(Tcl_Interp *interp)
38 {
39  Tcl_CreateObjCommand(interp, "bitSize", bitSizeCmd, NULL, NULL);
40  Tcl_CreateObjCommand(interp, "fileType", fileTypeCmd, NULL, NULL);
41  Tcl_CreateObjCommand(interp, "spectrum", spectrumCmd, NULL, NULL);
42  Tcl_CreateObjCommand(interp, "Bimage", BimageCmd, NULL, NULL);
43  Tcl_CreateObjCommand(interp, "Bmg", BmgCmd, NULL, NULL);
44  Tcl_CreateObjCommand(interp, "Bmodel", BmodelCmd, NULL, NULL);
45  return TCL_OK;
46 }
47 
48 extern "C" int Tcltk_bshow_SafeInit(Tcl_Interp *interp)
49 {
50  Tcl_CreateObjCommand(interp, "bitSize", bitSizeCmd, NULL, NULL);
51  Tcl_CreateObjCommand(interp, "fileType", fileTypeCmd, NULL, NULL);
52  Tcl_CreateObjCommand(interp, "spectrum", spectrumCmd, NULL, NULL);
53  Tcl_CreateObjCommand(interp, "Bimage", BimageCmd, NULL, NULL);
54  Tcl_CreateObjCommand(interp, "Bmg", BmgCmd, NULL, NULL);
55  Tcl_CreateObjCommand(interp, "Bmodel", BmodelCmd, NULL, NULL);
56  return TCL_OK;
57 }
58 
59 static int bitSizeCmd(ClientData clientdata, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
60 {
61  Tcl_ResetResult(interp);
62 
63  Tcl_Obj* returnObj = Tcl_NewObj();
64 
65  int bits = 8*sizeof(long);
66 
67  Tcl_SetIntObj(returnObj, bits);
68 
69  Tcl_SetObjResult(interp, returnObj);
70 
71  return TCL_OK;
72 }
73 
74 static int fileTypeCmd(ClientData clientdata, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
75 {
76  Tcl_ResetResult(interp);
77 
78  char* filename = Tcl_GetStringFromObj(objv[1], NULL);
79 
80  Tcl_Obj* returnObj = Tcl_NewObj();
81 
82  int ft = file_type(filename);
83 
84 // cout << "File type = " << ft << endl;
85 
86  Tcl_SetIntObj(returnObj, ft);
87 
88  Tcl_SetObjResult(interp, returnObj);
89 
90  return TCL_OK;
91 }
92 
93 static int spectrumCmd(ClientData clientdata, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
94 {
95  Tcl_ResetResult(interp);
96 
97  Tcl_Obj* returnObj = Tcl_NewObj();
98 
99  double value(0), min(0), max(1);
100  RGB<unsigned char> color;
101 
102  if ( objc > 1 ) Tcl_GetDoubleFromObj(NULL, objv[1], &value);
103  if ( objc > 2 ) Tcl_GetDoubleFromObj(NULL, objv[2], &min);
104  if ( objc > 3 ) Tcl_GetDoubleFromObj(NULL, objv[3], &max);
105 
106  color.spectrum(value, min, max);
107 
108  Bstring hexcolor(color.hex());
109  Tcl_SetStringObj(returnObj, hexcolor.c_str(), hexcolor.length());
110 
111  Tcl_SetObjResult(interp, returnObj);
112 
113  return TCL_OK;
114 }
115 
116 
117 /************************************************************************
118 @brief Implements the "Bimage" command in Tcl/Tk to access image files through Bsoft.
119 @param clientdata some pointer to some data structure (not used).
120 @param *interp a Tcl interpreter within Tcl.
121 @param objc number of arguments passed (+1).
122 @param *objv[] arguments passed as Tcl objects.
123 @return static int Tcl result.
124 
125  Calls the "image_processing" function.
126 
127 **/
128 static int BimageCmd(ClientData clientdata, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
129 {
130  return image_processing(interp, objc, objv);
131 }
132 
144 static int BmgCmd(ClientData clientdata, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
145 {
146  return project_processing(interp, objc, objv);
147 }
148 
160 static int BmodelCmd(ClientData clientdata, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
161 {
162  return model_processing(interp, objc, objv);
163 }
Header file for general utilities.
FileType file_type(const char *filename)
Checks the file type using the extension and contents.
Definition: file_util.cpp:104
Bmodel * model
Definition: tcltk_bshow.cpp:32
Bimage * imgtemp
Definition: tcltk_bshow.cpp:34
int project_processing(Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
Implements the "Bmg" command in Tcl/Tk to access micrograph parameter files through Bsoft...
Definition: tcltk_bmg.cpp:125
int verbose
Bstring hex()
Definition: Color.h:76
int image_processing(Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
Utilities for timing functions.
A shared object to manage boxes in micrograph parameter files in TCL/Tk.
General image parameter class.
Definition: Bimage.h:158
Bimage * imglist
Definition: tcltk_bshow.cpp:30
Definition: Color.h:24
unsigned int bits
Definition: tif_acorn.c:68
Header file for file checking functions.
A shared object to manage model parameter files in TCL/Tk.
int model_processing(Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
Implements the "Bmodel" command in Tcl/Tk to access model parameter files through Bsoft...
int Tcltk_bshow_SafeInit(Tcl_Interp *interp)
Definition: tcltk_bshow.cpp:48
A shared object to load Bsoft image files in TCL/Tk.
void spectrum(double value, double cmin, double cmax)
Definition: Color.h:84
int Tcltk_bshow_Init(Tcl_Interp *interp)
Definition: tcltk_bshow.cpp:37
Bproject * project
Definition: tcltk_bshow.cpp:31