Bsoft  2.1.0
Bernard's software package
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 extern string command; // Command line
23 
24 // Globals necessary to make the Tcl/Tk interface work
25 static Tcl_ObjCmdProc systemMemoryCmd;
26 static Tcl_ObjCmdProc bitSizeCmd;
27 static Tcl_ObjCmdProc fileTypeCmd;
28 static Tcl_ObjCmdProc spectrumCmd;
29 static Tcl_ObjCmdProc BimageCmd;
30 static Tcl_ObjCmdProc BmgCmd;
31 static Tcl_ObjCmdProc BmodelCmd;
32 Bimage* imglist = NULL;
33 Bproject* project = NULL;
34 Bmodel* model = NULL;
35 
36 Bimage* imgtemp = NULL;
37 
38 /* These functions are dynamically loaded by the "load" command */
39 extern "C" int Bshow_Init(Tcl_Interp *interp)
40 {
41  Tcl_CreateObjCommand(interp, "systemMemory", systemMemoryCmd, NULL, NULL);
42  Tcl_CreateObjCommand(interp, "bitSize", bitSizeCmd, NULL, NULL);
43  Tcl_CreateObjCommand(interp, "fileType", fileTypeCmd, NULL, NULL);
44  Tcl_CreateObjCommand(interp, "spectrum", spectrumCmd, NULL, NULL);
45  Tcl_CreateObjCommand(interp, "Bimage", BimageCmd, NULL, NULL);
46  Tcl_CreateObjCommand(interp, "Bmg", BmgCmd, NULL, NULL);
47  Tcl_CreateObjCommand(interp, "Bmodel", BmodelCmd, NULL, NULL);
48  return TCL_OK;
49 }
50 
51 extern "C" int Bshow_SafeInit(Tcl_Interp *interp)
52 {
53  Tcl_CreateObjCommand(interp, "systemMemory", systemMemoryCmd, NULL, NULL);
54  Tcl_CreateObjCommand(interp, "bitSize", bitSizeCmd, NULL, NULL);
55  Tcl_CreateObjCommand(interp, "fileType", fileTypeCmd, NULL, NULL);
56  Tcl_CreateObjCommand(interp, "spectrum", spectrumCmd, NULL, NULL);
57  Tcl_CreateObjCommand(interp, "Bimage", BimageCmd, NULL, NULL);
58  Tcl_CreateObjCommand(interp, "Bmg", BmgCmd, NULL, NULL);
59  Tcl_CreateObjCommand(interp, "Bmodel", BmodelCmd, NULL, NULL);
60  return TCL_OK;
61 }
62 
63 static int systemMemoryCmd(ClientData clientdata, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
64 {
65  Tcl_ResetResult(interp);
66 
67  Tcl_Obj* returnObj = Tcl_NewLongObj(system_memory());
68 
69  Tcl_SetObjResult(interp, returnObj);
70 
71  return TCL_OK;
72 }
73 
74 static int bitSizeCmd(ClientData clientdata, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
75 {
76  Tcl_ResetResult(interp);
77 
78  Tcl_Obj* returnObj = Tcl_NewObj();
79 
80  int bits = 8*sizeof(long);
81 
82  Tcl_SetIntObj(returnObj, bits);
83 
84  Tcl_SetObjResult(interp, returnObj);
85 
86  return TCL_OK;
87 }
88 
89 static int fileTypeCmd(ClientData clientdata, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
90 {
91  Tcl_ResetResult(interp);
92 
93  char* filename = Tcl_GetStringFromObj(objv[1], NULL);
94 
95  Tcl_Obj* returnObj = Tcl_NewObj();
96 
97  int ft = file_type(filename);
98 
99 // cout << "File type = " << ft << endl;
100 
101  Tcl_SetIntObj(returnObj, ft);
102 
103  Tcl_SetObjResult(interp, returnObj);
104 
105  return TCL_OK;
106 }
107 
108 static int spectrumCmd(ClientData clientdata, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
109 {
110  Tcl_ResetResult(interp);
111 
112  Tcl_Obj* returnObj = Tcl_NewObj();
113 
114  double value(0), min(0), max(1);
115  RGB<unsigned char> color;
116 
117  if ( objc > 1 ) Tcl_GetDoubleFromObj(NULL, objv[1], &value);
118  if ( objc > 2 ) Tcl_GetDoubleFromObj(NULL, objv[2], &min);
119  if ( objc > 3 ) Tcl_GetDoubleFromObj(NULL, objv[3], &max);
120 
121  color.spectrum(value, min, max);
122 
123  Bstring hexcolor(color.hex());
124  Tcl_SetStringObj(returnObj, hexcolor.c_str(), hexcolor.length());
125 
126  Tcl_SetObjResult(interp, returnObj);
127 
128  return TCL_OK;
129 }
130 
131 
143 static int BimageCmd(ClientData clientdata, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
144 {
145  return image_processing(interp, objc, objv);
146 }
147 
159 static int BmgCmd(ClientData clientdata, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
160 {
161  return project_processing(interp, objc, objv);
162 }
163 
175 static int BmodelCmd(ClientData clientdata, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
176 {
177  return model_processing(interp, objc, objv);
178 }
imgtemp
Bimage * imgtemp
Definition: bshow.cpp:36
file_util.h
Header file for file checking functions.
Bstring
Definition: Bstring.h:29
tcltk_bmodel.h
A shared object to manage model parameter files in TCL/Tk.
Bshow_SafeInit
int Bshow_SafeInit(Tcl_Interp *interp)
Definition: bshow.cpp:51
RGB
Definition: Color.h:24
project_processing
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:138
verbose
int verbose
project
Bproject * project
Definition: bshow.cpp:33
RGB::spectrum
void spectrum(double value, double cmin, double cmax)
Definition: Color.h:89
imglist
Bimage * imglist
Definition: bshow.cpp:32
Bimage
General image parameter class.
Definition: Bimage.h:177
timer.h
Utilities for timing functions.
Bproject
Definition: mg_processing.h:336
tcltk_bmg.h
A shared object to manage boxes in micrograph parameter files in TCL/Tk.
image_processing
int image_processing(Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bimage.cpp:155
Bmodel
Definition: rwmodel.h:119
tcltk_bimage.h
A shared object to load Bsoft image files in TCL/Tk.
utilities.h
Header file for general utilities.
model
Bmodel * model
Definition: bshow.cpp:34
system_memory
long system_memory()
Returns system memory size.
Definition: utilities.cpp:211
Bshow_Init
int Bshow_Init(Tcl_Interp *interp)
Definition: bshow.cpp:39
RGB::hex
Bstring hex()
Definition: Color.h:80
model_processing
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.
Definition: tcltk_bmodel.cpp:120
command
string command
Definition: utilities.cpp:20
file_type
FileType file_type(const char *filename)
Checks the file type using the extension and contents.
Definition: file_util.cpp:178