| Bsoft 2.0.5 Bernard's software package

tcltk_bmarker.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_bmarker.h"
13 #include "mg_img_proc.h"
14 #include "mg_extract.h"
15 #include "mg_tomography.h"
16 #include "mg_tomo_track.h"
17 #include "rwmg.h"
18 #include "mg_tomography.h"
19 #include "linked_list.h"
20 #include "timer.h"
21 #include "utilities.h"
22
23 #include <sys/stat.h>
24
25 // Declaration of global variables
26 extern int verbose; // Level of output to the screen
27 extern Bimage* imglist;
28
29 // Internal function prototypes
30 Tcl_Obj* marker_count(Bproject* project);
31 Tcl_Obj* marker_count(Bfield* field);
32 Tcl_Obj* marker_count(Bmicrograph* mg);
33 Tcl_Obj* marker_count(Breconstruction* rec);
34 Tcl_Obj* marker_ids(Bproject* project, double fom_cut);
35 Tcl_Obj* marker_ids(Bfield* field, double fom_cut);
36 Tcl_Obj* marker_ids(Bmicrograph* mg, double fom_cut);
37 Tcl_Obj* marker_ids(Breconstruction* rec, double fom_cut);
38 Tcl_Obj* marker_list(Bproject* project);
39 Tcl_Obj* marker_list(Bfield* field);
40 Tcl_Obj* marker_list(Bmicrograph* mg);
41 Tcl_Obj* marker_list(Breconstruction* rec);
42 Tcl_Obj* marker_location(Bmarker* mark);
43 Tcl_Obj* marker_residual(Bproject* project);
44 Tcl_Obj* marker_residual(Bmarker* mark);
45 Tcl_Obj* marker_fom(Bmarker* mark);
46 Tcl_Obj* marker_fom_maximum(Bmarker* mark);
47 Tcl_Obj* marker_select(Bmarker* marklist, double rad, int objc, Tcl_Obj *CONST objv[]);
48 Tcl_Obj* marker_select_rectangle(Bmarker* marklist, int objc, Tcl_Obj *CONST objv[]);
49 Tcl_Obj* marker_get_selection_flag(Bmarker* marklist, int objc, Tcl_Obj *CONST objv[]);
50 Tcl_Obj* marker_set_selection_flag(Bmarker* marklist, int objc, Tcl_Obj *CONST objv[]);
51 Tcl_Obj* marker_clear_selection_flag(Bmarker* marklist, int objc, Tcl_Obj *CONST objv[]);
52 Tcl_Obj* marker_move(Bmarker* marklist, int objc, Tcl_Obj *CONST objv[]);
53 Tcl_Obj* marker_create(Bmicrograph* mg, int objc, Tcl_Obj *CONST objv[]);
54 Tcl_Obj* marker_create(Breconstruction* rec, int objc, Tcl_Obj *CONST objv[]);
55 Tcl_Obj* marker_center(Bmarker* mark, Bimage* p, int objc, Tcl_Obj *CONST objv[]);
56 Tcl_Obj* marker_generate_from_seed(Bproject* project);
57 Tcl_Obj* marker_find(Bmicrograph* mg, Bimage* p, int objc, Tcl_Obj *CONST objv[]);
58 Tcl_Obj* marker_snap(Bmicrograph* mg, Bimage* p, long mid, int objc, Tcl_Obj *CONST objv[]);
59 Tcl_Obj* marker_extract(Bmicrograph* mg, Bimage* p, int objc, Tcl_Obj *CONST objv[]);
60 Tcl_Obj* marker_extract(Breconstruction* rec, Bimage* p, int objc, Tcl_Obj *CONST objv[]);
61 Tcl_Obj* marker_delete(Bproject* project, int objc, Tcl_Obj *CONST objv[]);
62 Tcl_Obj* marker_delete(Bfield* field, int objc, Tcl_Obj *CONST objv[]);
63 Tcl_Obj* marker_delete(Bmicrograph* mg, int objc, Tcl_Obj *CONST objv[]);
64 Tcl_Obj* marker_delete(Breconstruction* rec, int objc, Tcl_Obj *CONST objv[]);
65 Tcl_Obj* marker_edge(Bmarker* mark, Bimage* p, int objc, Tcl_Obj *CONST objv[]);
66 Tcl_Obj* marker_accept(Bmarker* mark, int objc, Tcl_Obj *CONST objv[]);
67
68 int do_tomo_transfer_seed(Bproject* project, int objc, Tcl_Obj *CONST objv[])
69 {
70 double rot_start(-180), rot_end(180); // Rotation search limits
71 double rot_step(0); // Rotation search step size for seed transfer
72 double hi_res(0), lo_res(1000); // Default resolution range
73 double shift_limit(-1); // Micrograph shift search limit
74 int refine(0);
75
76 if ( objc > 2 ) Tcl_GetDoubleFromObj(NULL, objv[2], &rot_start);
77 if ( objc > 3 ) Tcl_GetDoubleFromObj(NULL, objv[3], &rot_end);
78 if ( objc > 4 ) Tcl_GetDoubleFromObj(NULL, objv[4], &rot_step);
79 if ( objc > 5 ) Tcl_GetDoubleFromObj(NULL, objv[5], &hi_res);
80 if ( objc > 6 ) Tcl_GetDoubleFromObj(NULL, objv[6], &lo_res);
81 if ( objc > 7 ) Tcl_GetDoubleFromObj(NULL, objv[7], &shift_limit);
82 if ( objc > 8 ) Tcl_GetIntFromObj(NULL, objv[8], &refine);
83
84 rot_step *= M_PI/180.0;
85 rot_start *= M_PI/180.0;
86 rot_end *= M_PI/180.0;
87
88 if ( rot_step > 0 ) {
89 project_transfer_seed(project, rot_start, rot_end, rot_step, hi_res, lo_res, shift_limit);
90 if ( refine )
91 project_refine_markers(project, hi_res, lo_res);
92 }
93
94 return 0;
95 }
96
97 int do_tomo_findaxis(Bproject* project, int objc, Tcl_Obj *CONST objv[])
98 {
99 double axis(0), axis_start(-180), axis_end(180), axis_step(1);
100 double hi_res(0), lo_res(1000), shift_limit(-1);
101
102 if ( objc > 2 ) Tcl_GetDoubleFromObj(NULL, objv[2], &axis); // Target tilt axis
103 if ( objc > 3 ) Tcl_GetDoubleFromObj(NULL, objv[3], &axis_start); // Starting angle to test
104 if ( objc > 4 ) Tcl_GetDoubleFromObj(NULL, objv[4], &axis_end); // Ending angle to test
105 if ( objc > 5 ) Tcl_GetDoubleFromObj(NULL, objv[5], &axis_step); // Angular step size
106 if ( objc > 6 ) Tcl_GetDoubleFromObj(NULL, objv[6], &hi_res); // High resolution limit
107 if ( objc > 7 ) Tcl_GetDoubleFromObj(NULL, objv[7], &lo_res); // Low resolution limit
108 if ( objc > 8 ) Tcl_GetDoubleFromObj(NULL, objv[8], &shift_limit); // Maximum shift limit
109
110 axis *= M_PI/180.0;
111 axis_start *= M_PI/180.0;
112 axis_end *= M_PI/180.0;
113 axis_step *= M_PI/180.0;
114
115 project_find_tilt_axis(project, axis, axis_start, axis_end, axis_step, hi_res, lo_res, shift_limit);
116
117 return 0;
118 }
119
120 int do_tomo_track(Bproject* project, int objc, Tcl_Obj *CONST objv[])
121 {
122 int iter(5), thickness(500), cc_type(0), recenter(0);
123 double hi_res(0), lo_res(500), shift_limit(-1);
124 Bstring paramfile("track.star");
125
126 if ( objc > 2 ) Tcl_GetIntFromObj(NULL, objv[2], &iter); // Maximum number of iterations
127 if ( objc > 3 ) Tcl_GetDoubleFromObj(NULL, objv[3], &hi_res); // High resolution limit
128 if ( objc > 4 ) Tcl_GetDoubleFromObj(NULL, objv[4], &lo_res); // Low resolution limit
129 if ( objc > 5 ) Tcl_GetDoubleFromObj(NULL, objv[5], &shift_limit); // Maximum shift limit
130 if ( objc > 6 ) Tcl_GetIntFromObj(NULL, objv[6], &thickness); // Maximum thickness
131 if ( objc > 7 ) Tcl_GetIntFromObj(NULL, objv[7], &cc_type); // Flag to cross correlate
132 if ( objc > 8 ) Tcl_GetIntFromObj(NULL, objv[8], &recenter); // Flag to recenter z coordinates
133
134 ofstream out("track.log");
135 streambuf *coutbuf = cout.rdbuf(); //save old buf
136 cout.rdbuf(out.rdbuf()); //redirect std::cout to out!
137
138 project_track_markers(project, hi_res, lo_res, shift_limit, thickness, cc_type, iter, 1, recenter, paramfile);
139
140 cout.rdbuf(coutbuf); //reset to standard output again
141
142 return 0;
143 }
144
145 int do_tomo_refine(Bproject* project, int objc, Tcl_Obj *CONST objv[])
146 {
147 int ref_view(0), ref_ori(0), ref_scale(0);
148 double hi_res(20), lo_res(1000);
149 Bstring refop;
150
151 project_check_markers(project, 14);
152 project_tomo_residuals(project, 0);
153 project_sort_markers_by_id(project);
154
155 /* Type of operations */
156 if ( objc > 2 ) refop = Tcl_GetStringFromObj(objv[2], NULL);
157
158 if ( refop[0] == 'm' ) {
159 if ( objc > 3 ) Tcl_GetDoubleFromObj(NULL, objv[3], &hi_res); /* High resolution limit */
160 if ( objc > 4 ) Tcl_GetDoubleFromObj(NULL, objv[4], &lo_res); /* Low resolution limit */
161 project_refine_markers(project, hi_res, lo_res);
162 } else if ( refop[0] == 'z' ) {
163 project_refine_z(project);
164 } else {
165 if ( objc > 3 ) Tcl_GetIntFromObj(NULL, objv[3], &ref_view); /* Do views */
166 if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &ref_ori); /* Do origins */
167 if ( objc > 5 ) Tcl_GetIntFromObj(NULL, objv[5], &ref_scale); /* Do scales */
168 project_refine(project, ref_view, ref_ori, ref_scale);
169 }
170
171 project_check_markers(project, 14);
172 project_tomo_residuals(project, 0);
173 project_calculate_angles(project);
174
175 return 0;
176 }
177
178 int do_tomo_refine_one(Bproject* project, int objc, Tcl_Obj *CONST objv[])
179 {
180 int id(0);
181 double hi_res(20), lo_res(1000);
182
183 /* Type of operations */
184 if ( objc > 2 ) Tcl_GetIntFromObj(NULL, objv[2], &id);
185 if ( id < 1 ) return 0;
186
187 if ( objc > 3 ) Tcl_GetDoubleFromObj(NULL, objv[3], &hi_res); /* High resolution limit */
188 if ( objc > 4 ) Tcl_GetDoubleFromObj(NULL, objv[4], &lo_res); /* Low resolution limit */
189 project_refine_one_marker(project, id, hi_res, lo_res);
190
191 project_check_markers(project, 14);
192 project_tomo_residuals(project, 0);
193
194 return 0;
195 }
196
197
198
199 /*
200 @brief Functions for tomographic marker manipulation.
201 Marker interface syntax:
202 Bmg marker [item] [action] [params]
203 Actions:
204 count counts the number of markers
205 ids [f] returns the identifiers of markers selected above the given FOM cutoff
206 list returns a list of markers
207 location [id] returns the location and error vector of a marker
208 residual [id] returns marker residual or residual of all markers
209 fom [id] returns the FOM of a marker
210 select [x] [y] [z] returns the identifier at the given location
211 selectrect [x1] [y1] [x2] [y2] returns a list of identifiers within the rectangle
212 getflag [id] sets the selection flag of a marker
213 setflag [id] [s] sets the selection flag of a marker
214 clearflag [id] clears the selection flag of a marker
215 move [id] [dx] [dy] [dz] updates a marker location by the given vector
216 create [x] [y] [z] creates a new marker at the given location
217 renumber renumbers markers
218 center centers markers
219 generate generates missing markers from an existing seed
220 find [r] finds markers
221 snap [id] snaps a marker to a low density center
222 extract [fn] extracts markers
223 delete [all|fom|id] [f] deletes markers
224 edge [e] sets FOM based on edge parameter
225 accept [id] accept model location for marker
226 Parameters:
227 id identifier
228 x x location
229 y y location
230 z z location
231 f FOM cutoff
232 s selection flag
233 dx change in x
234 dy change in y
235 dz change in z
236 r marker radius
237 fn new file name
238 e edge for marker selection
239 */
240 Tcl_Obj* do_marker(Bproject* project, int objc, Tcl_Obj *CONST objv[])
241 {
242 Tcl_Obj* returnObj = NULL;
243
244 Bstring item = Tcl_GetStringFromObj(objv[2], NULL);
245 if ( verbose & VERB_DEBUG )
246 cout << "DEBUG do_marker: Item: " << item << " (" << item.length() << ")" << endl;
247
248 Bstring id = item.post(':');
249 id = id.remove(' ');
250 item = item.pre(':');
251
252 Bfield* field = NULL;
253 Bmicrograph* mg = NULL;
254 Breconstruction* rec = NULL;
255 Bmarker* mark = NULL;
256 Bimage* p = NULL;
257 Bstring filename, filename2, base, delete_what;
258 int mid(-1);
259 double radius(0), fom_cut(0);
260
261 if ( item.contains("Field") ) {
262 for ( field = project->field; field && field->id != id; field = field->next ) ;
263 if ( field )
264 filename = field->mg->fmg;
265 else
266 cerr << "Error in do_marker: Field " << id << " not found!" << endl;
267 } else if ( item.contains("Micrograph") ) {
268 for ( field = project->field; field; field = field->next ) {
269 for ( mg = field->mg; mg && mg->id != id; mg = mg->next ) ;
270 if ( mg ) break;
271 }
272 if ( mg ) {
273 if ( mg->fmg.length() )
274 filename = mg->fmg;
275 else if ( mg->fframe.length() )
276 filename = mg->fframe;
277 mark = mg->mark;
278 radius = mg->mark_radius;
279 } else
280 cerr << "Error in do_marker: Micrograph " << id << " not found!" << endl;
281 } else if ( item.contains("Reconstruction") ) {
282 for ( rec = project->rec; rec && rec->id != id; rec = rec->next ) ;
283 if ( rec ) {
284 filename = rec->frec;
285 mark = rec->mark;
286 radius = rec->mark_radius;
287 } else
288 cerr << "Error in do_marker: Reconstruction " << id << " not found!" << endl;
289 }
290
291 if ( filename.length() ) {
292 base = filename.base();
293 for ( p = imglist; p; p = p->next ) {
294 filename2 = p->file_name();
295 if ( filename2.base() == base ) break;
296 }
297 }
298
299 Bstring action = Tcl_GetStringFromObj(objv[3], NULL);
300 if ( verbose & VERB_DEBUG )
301 cout << "DEBUG do_marker: Action: " << action << " (" << action.length() << ")" << endl;
302
303 if ( action == "count" ) {
304 if ( mg ) returnObj = marker_count(mg);
305 else if ( field ) returnObj = marker_count(field);
306 else if ( rec ) returnObj = marker_count(rec);
307 else returnObj = marker_count(project);
308 } else if ( action == "ids" ) {
309 if ( objc > 4 ) Tcl_GetDoubleFromObj(NULL, objv[4], &fom_cut);
310 if ( mg ) returnObj = marker_ids(mg, fom_cut);
311 else if ( field ) returnObj = marker_ids(field, fom_cut);
312 else if ( rec ) returnObj = marker_ids(rec, fom_cut);
313 else returnObj = marker_ids(project, fom_cut);
314 } else if ( action == "list" ) {
315 if ( mg ) returnObj = marker_list(mg);
316 else if ( field ) returnObj = marker_list(field);
317 else if ( rec ) returnObj = marker_list(rec);
318 else returnObj = marker_list(project);
319 } else if ( action == "location" ) {
320 if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &mid);
321 for ( ; mark && mark->id != mid; mark = mark->next ) ;
322 if ( mark ) returnObj = marker_location(mark);
323 } else if ( action == "residual" ) {
324 if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &mid);
325 if ( mid < 0 ) {
326 returnObj = marker_residual(project);
327 } else {
328 for ( ; mark && mark->id != mid; mark = mark->next ) ;
329 if ( mark ) returnObj = marker_residual(mark);
330 }
331 } else if ( action == "fom" ) {
332 if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &mid);
333 for ( ; mark && mark->id != mid; mark = mark->next ) ;
334 returnObj = marker_fom(mark);
335 } else if ( action == "fom_maximum" ) {
336 returnObj = marker_fom_maximum(mark);
337 } else if ( action == "select" ) {
338 if ( mark ) returnObj = marker_select(mark, radius, objc, objv);
339 } else if ( action == "selectrect" ) {
340 if ( mark ) returnObj = marker_select_rectangle(mark, objc, objv);
341 } else if ( action == "getflag" ) {
342 if ( mark ) returnObj = marker_get_selection_flag(mark, objc, objv);
343 } else if ( action == "setflag" ) {
344 if ( mark ) returnObj = marker_set_selection_flag(mark, objc, objv);
345 } else if ( action == "clearflag" ) {
346 if ( mark ) returnObj = marker_clear_selection_flag(mark, objc, objv);
347 } else if ( action == "move" ) {
348 if ( mark ) returnObj = marker_move(mark, objc, objv);
349 } else if ( action == "create" ) {
350 if ( mg ) returnObj = marker_create(mg, objc, objv);
351 else if ( rec ) returnObj = marker_create(rec, objc, objv);
352 } else if ( action == "renumber" ) {
353 if ( mark ) markers_renumber(mark);
354 else project_renumber_markers(project);
355 } else if ( action == "center" ) {
356 if ( mark ) returnObj = marker_center(mark, p, objc, objv);
357 } else if ( action == "generate" ) {
358 returnObj = marker_generate_from_seed(project);
359 } else if ( action == "find" ) {
360 if ( mg ) returnObj = marker_find(mg, p, objc, objv);
361 } else if ( action == "snap" ) {
362 if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &mid);
363 if ( mg ) returnObj = marker_snap(mg, p, mid, objc, objv);
364 } else if ( action == "extract" ) {
365 if ( mg ) returnObj = marker_extract(mg, p, objc, objv);
366 else if ( rec ) returnObj = marker_extract(rec, p, objc, objv);
367 } else if ( action == "delete" ) {
368 if ( mg ) returnObj = marker_delete(mg, objc, objv);
369 else if ( field ) returnObj = marker_delete(field, objc, objv);
370 else if ( rec ) returnObj = marker_delete(rec, objc, objv);
371 else returnObj = marker_delete(project, objc, objv);
372 } else if ( action == "edge" ) {
373 if ( mark ) returnObj = marker_edge(mark, p, objc, objv);
374 } else if ( action == "accept" ) {
375 if ( mark ) returnObj = marker_accept(mark, objc, objv);
376 } else {
377 cerr << "Error: Action " << action << " not recognized!" << endl;
378 }
379
380 if ( !returnObj ) {
381 returnObj = Tcl_NewObj();
382 Tcl_SetIntObj(returnObj, 0);
383 }
384
385 return returnObj;
386 }
387
388 Tcl_Obj* marker_count(Bproject* project)
389 {
390 Tcl_Obj* returnObj = Tcl_NewObj();
391
392 int nmark(0);
393 Bfield* field;
394 Bmicrograph* mg;
395 Breconstruction* rec;
396 Bmarker* mark;
397
398 if ( project->select < 1 ) {
399 for ( field = project->field; field; field = field->next )
400 for ( mg = field->mg; mg; mg = mg->next )
401 for ( mark = mg->mark; mark; mark = mark->next ) nmark++;
402 } else {
403 for ( rec = project->rec; rec; rec = rec->next )
404 for ( mark = rec->mark; mark; mark = mark->next ) nmark++;
405 }
406
407 Tcl_SetIntObj(returnObj, nmark);
408
409 return returnObj;
410 }
411
412 Tcl_Obj* marker_count(Bfield* field)
413 {
414 Tcl_Obj* returnObj = Tcl_NewObj();
415
416 int nmark(0);
417 Bmicrograph* mg;
418 Bmarker* mark;
419
420 for ( mg = field->mg; mg; mg = mg->next )
421 for ( mark = mg->mark; mark; mark = mark->next ) nmark++;
422
423 Tcl_SetIntObj(returnObj, nmark);
424
425 return returnObj;
426 }
427
428 Tcl_Obj* marker_count(Bmicrograph* mg)
429 {
430 Tcl_Obj* returnObj = Tcl_NewObj();
431
432 int nmark(0);
433 Bmarker* mark;
434
435 for ( mark = mg->mark; mark; mark = mark->next ) nmark++;
436
437 Tcl_SetIntObj(returnObj, nmark);
438
439 return returnObj;
440 }
441
442 Tcl_Obj* marker_count(Breconstruction* rec)
443 {
444 Tcl_Obj* returnObj = Tcl_NewObj();
445
446 int nmark(0);
447 Bmarker* mark;
448
449 for ( mark = rec->mark; mark; mark = mark->next ) nmark++;
450
451 Tcl_SetIntObj(returnObj, nmark);
452
453 return returnObj;
454 }
455
456 Tcl_Obj* marker_ids(Bproject* project, double fom_cut)
457 {
458 Tcl_Obj* returnObj = Tcl_NewObj();
459
460 char string[MAXLINELEN] = "";
461 Bfield* field = project->field;
462 Bmicrograph* mg = NULL;
463 Breconstruction* rec = project->rec;
464 Bmarker* mark = NULL;
465
466 if ( project->select < 1 ) {
467 if ( field ) for ( mg = field->mg; mg && !mg->mark; mg = mg->next ) ;
468 if ( mg ) {
469 for ( mark = mg->mark; mark; mark = mark->next ) if ( mark->fom >= fom_cut ) {
470 sprintf(string, " %d", mark->id);
471 Tcl_AppendToObj(returnObj, string, strlen(string));
472 }
473 }
474 } else {
475 if ( rec ) {
476 for ( mark = rec->mark; mark; mark = mark->next ) if ( mark->fom >= fom_cut ) {
477 sprintf(string, " %d", mark->id);
478 Tcl_AppendToObj(returnObj, string, strlen(string));
479 }
480 }
481 }
482
483 return returnObj;
484 }
485
486 Tcl_Obj* marker_ids(Bfield* field, double fom_cut)
487 {
488 Tcl_Obj* returnObj = Tcl_NewObj();
489
490 char string[MAXLINELEN] = "";
491 Bmicrograph* mg = NULL;
492 Bmarker* mark = NULL;
493
494 for ( mg = field->mg; mg && !mg->mark; mg = mg->next ) ;
495 if ( mg ) {
496 for ( mark = mg->mark; mark; mark = mark->next ) if ( mark->fom >= fom_cut ) {
497 sprintf(string, " %d", mark->id);
498 Tcl_AppendToObj(returnObj, string, strlen(string));
499 }
500 }
501
502 return returnObj;
503 }
504
505 Tcl_Obj* marker_ids(Bmicrograph* mg, double fom_cut)
506 {
507 Tcl_Obj* returnObj = Tcl_NewObj();
508
509 char string[MAXLINELEN] = "";
510 Bmarker* mark = NULL;
511
512 for ( mark = mg->mark; mark; mark = mark->next ) if ( mark->fom >= fom_cut ) {
513 sprintf(string, " %d", mark->id);
514 Tcl_AppendToObj(returnObj, string, strlen(string));
515 }
516
517 return returnObj;
518 }
519
520 Tcl_Obj* marker_ids(Breconstruction* rec, double fom_cut)
521 {
522 Tcl_Obj* returnObj = Tcl_NewObj();
523
524 char string[MAXLINELEN] = "";
525 Bmarker* mark = NULL;
526
527 for ( mark = rec->mark; mark; mark = mark->next ) if ( mark->fom >= fom_cut ) {
528 sprintf(string, " %d", mark->id);
529 Tcl_AppendToObj(returnObj, string, strlen(string));
530 }
531
532 return returnObj;
533 }
534
535 Tcl_Obj* marker_list(Bproject* project)
536 {
537 Tcl_Obj* returnObj = Tcl_NewObj();
538
539 char string[MAXLINELEN] = "";
540 Bfield* field;
541 Bmicrograph* mg = NULL;
542 Breconstruction* rec = project->rec;
543 Bmarker* mark = NULL;
544
545 if ( project->select < 1 ) {
546 for ( field = project->field; field; field = field->next )
547 for ( mg = field->mg; mg; mg = mg->next )
548 for ( mark = mg->mark; mark; mark = mark->next ) {
549 sprintf(string, " %d %d %20.16f %20.16f %d", mg->img_num, mark->id, mark->res, mark->fom, mark->sel);
550 Tcl_AppendToObj(returnObj, string, strlen(string));
551 }
552 } else {
553 if ( rec ) {
554 for ( mark = rec->mark; mark; mark = mark->next ) {
555 sprintf(string, " 0 %d %20.16f %20.16f %d", mark->id, mark->res, mark->fom, mark->sel);
556 Tcl_AppendToObj(returnObj, string, strlen(string));
557 }
558 }
559 }
560
561 return returnObj;
562 }
563
564 Tcl_Obj* marker_list(Bfield* field)
565 {
566 Tcl_Obj* returnObj = Tcl_NewObj();
567
568 char string[MAXLINELEN] = "";
569 Bmicrograph* mg = NULL;
570 Bmarker* mark = NULL;
571
572 for ( mg = field->mg; mg; mg = mg->next )
573 for ( mark = mg->mark; mark; mark = mark->next ) {
574 sprintf(string, " %d %d %20.16f %20.16f %d", mg->img_num, mark->id, mark->res, mark->fom, mark->sel);
575 Tcl_AppendToObj(returnObj, string, strlen(string));
576 }
577
578 return returnObj;
579 }
580
581 Tcl_Obj* marker_list(Bmicrograph* mg)
582 {
583 Tcl_Obj* returnObj = Tcl_NewObj();
584
585 char string[MAXLINELEN] = "";
586 Bmarker* mark = NULL;
587
588 for ( mark = mg->mark; mark; mark = mark->next ) {
589 sprintf(string, " %d %d %20.16f %20.16f %d", mg->img_num, mark->id, mark->res, mark->fom, mark->sel);
590 Tcl_AppendToObj(returnObj, string, strlen(string));
591 }
592
593 return returnObj;
594 }
595
596 Tcl_Obj* marker_list(Breconstruction* rec)
597 {
598 Tcl_Obj* returnObj = Tcl_NewObj();
599
600 char string[MAXLINELEN] = "";
601 Bmarker* mark = NULL;
602
603 for ( mark = rec->mark; mark; mark = mark->next ) {
604 sprintf(string, " 0 %d %20.16f %20.16f %d", mark->id, mark->res, mark->fom, mark->sel);
605 Tcl_AppendToObj(returnObj, string, strlen(string));
606 }
607
608 return returnObj;
609 }
610
611 Tcl_Obj* marker_location(Bmarker* mark)
612 {
613 Tcl_Obj* returnObj = Tcl_NewObj();
614
615 char string[MAXLINELEN] = "";
616
617 if ( mark ) {
618 sprintf(string, "%f %f %f %f %f %f",
619 mark->loc[0], mark->loc[1], mark->loc[2],
620 mark->err[0], mark->err[1], mark->err[2]);
621 Tcl_SetStringObj(returnObj, string, strlen(string));
622 }
623
624 return returnObj;
625 }
626
627 Tcl_Obj* marker_residual(Bproject* project)
628 {
629 Tcl_Obj* returnObj = Tcl_NewObj();
630
631 double res = project_tomo_residuals(project, 0);
632
633 Tcl_SetDoubleObj(returnObj, res);
634
635 return returnObj;
636 }
637
638 Tcl_Obj* marker_residual(Bmarker* mark)
639 {
640 Tcl_Obj* returnObj = Tcl_NewObj();
641
642 double res(0);
643
644 if ( mark ) res = mark->res;
645
646 Tcl_SetDoubleObj(returnObj, res);
647
648 return returnObj;
649 }
650
651 Tcl_Obj* marker_fom(Bmarker* mark)
652 {
653 Tcl_Obj* returnObj = Tcl_NewObj();
654
655 double fom(0);
656
657 if ( mark ) fom = mark->fom;
658
659 Tcl_SetDoubleObj(returnObj, fom);
660
661 return returnObj;
662 }
663
664 Tcl_Obj* marker_fom_maximum(Bmarker* mark)
665 {
666 Tcl_Obj* returnObj = Tcl_NewObj();
667
668 double fom_max(0);
669
670 for ( ; mark; mark = mark->next )
671 if ( fom_max < mark->fom ) fom_max = mark->fom;
672
673 Tcl_SetDoubleObj(returnObj, fom_max);
674
675 return returnObj;
676 }
677
678 Tcl_Obj* marker_select(Bmarker* marklist, double radius, int objc, Tcl_Obj *CONST objv[])
679 {
680 Tcl_Obj* returnObj = Tcl_NewObj();
681
682 int id(0), i(-1);
683 double x(0), y(0), z(0);
684
685 if ( objc > 4 ) Tcl_GetDoubleFromObj(NULL, objv[4], &x);
686 if ( objc > 5 ) Tcl_GetDoubleFromObj(NULL, objv[5], &y);
687 if ( objc > 6 ) Tcl_GetDoubleFromObj(NULL, objv[6], &z);
688
689 double d, dmin;
690 Vector3<float> loc(x, y, z);
691 Bmarker* mark;
692
693 if ( marklist ) {
694 dmin = 2*radius;
695 for ( mark = marklist; mark; mark = mark->next ) {
696 d = loc.distance(mark->loc);
697 if ( dmin > d ) {
698 dmin = d;
699 i = mark->id;
700 }
701 }
702 if ( dmin <= radius ) id = i;
703 }
704
705 Tcl_SetIntObj(returnObj, id);
706
707 return returnObj;
708 }
709
710 Tcl_Obj* marker_select_rectangle(Bmarker* marklist, int objc, Tcl_Obj *CONST objv[])
711 {
712 Tcl_Obj* returnObj = Tcl_NewObj();
713
714 double x1(0), y1(0), x2(0), y2(0);
715
716 if ( objc > 4 ) Tcl_GetDoubleFromObj(NULL, objv[4], &x1);
717 if ( objc > 5 ) Tcl_GetDoubleFromObj(NULL, objv[5], &y1);
718 if ( objc > 6 ) Tcl_GetDoubleFromObj(NULL, objv[6], &x2);
719 if ( objc > 7 ) Tcl_GetDoubleFromObj(NULL, objv[7], &y2);
720
721 if ( x2 < x1 ) swap(x1, x2);
722 if ( y2 < y1 ) swap(y1, y2);
723
724 char string[MAXLINELEN] = "";
725 Bmarker* mark;
726
727 if ( marklist ) {
728 for ( mark = marklist; mark; mark = mark->next ) {
729 if ( mark->loc[0] >= x1 && mark->loc[0] <= x2 &&
730 mark->loc[1] >= y1 && mark->loc[1] <= y2 ) {
731 sprintf(string, " %d", mark->id);
732 Tcl_AppendToObj(returnObj, string, strlen(string));
733 }
734 }
735 }
736
737 return returnObj;
738 }
739
740 Tcl_Obj* marker_get_selection_flag(Bmarker* marklist, int objc, Tcl_Obj *CONST objv[])
741 {
742 Tcl_Obj* returnObj = Tcl_NewObj();
743
744 int id(0), sel(-1);
745
746 if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &id);
747
748 Bmarker* mark;
749
750 for ( mark = marklist; mark && mark->id != id; mark = mark->next ) ;
751
752 if ( mark ) sel = mark->sel;
753
754 Tcl_SetIntObj(returnObj, sel);
755
756 return returnObj;
757 }
758
759 Tcl_Obj* marker_set_selection_flag(Bmarker* marklist, int objc, Tcl_Obj *CONST objv[])
760 {
761 Tcl_Obj* returnObj = Tcl_NewObj();
762
763 int id(0), sel(1), found(0);
764
765 if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &id);
766 if ( objc > 5 ) Tcl_GetIntFromObj(NULL, objv[5], &sel);
767
768 Bmarker* mark;
769
770 for ( mark = marklist; mark && mark->id != id; mark = mark->next ) ;
771
772 if ( mark ) mark->sel = found = sel;
773
774 Tcl_SetIntObj(returnObj, found);
775
776 return returnObj;
777 }
778
779 Tcl_Obj* marker_clear_selection_flag(Bmarker* marklist, int objc, Tcl_Obj *CONST objv[])
780 {
781 Tcl_Obj* returnObj = Tcl_NewObj();
782
783 int id(0), found(0);
784
785 if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &id);
786
787 Bmarker* mark;
788
789 for ( mark = marklist; mark && mark->id != id; mark = mark->next ) ;
790
791 if ( mark ) {
792 mark->sel = 0;
793 found = 1;
794 }
795
796 Tcl_SetIntObj(returnObj, found);
797
798 return returnObj;
799 }
800
801 Tcl_Obj* marker_move(Bmarker* marklist, int objc, Tcl_Obj *CONST objv[])
802 {
803 Tcl_Obj* returnObj = Tcl_NewObj();
804
805 int id(0);
806 double dx(0), dy(0), dz(0);
807
808 if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &id);
809 if ( objc > 5 ) Tcl_GetDoubleFromObj(NULL, objv[5], &dx);
810 if ( objc > 6 ) Tcl_GetDoubleFromObj(NULL, objv[6], &dy);
811 if ( objc > 7 ) Tcl_GetDoubleFromObj(NULL, objv[7], &dz);
812
813 Bmarker* mark;
814 Vector3<float> d = Vector3<float>(dx, dy, dz);
815
816 if ( marklist ) {
817 for ( mark = marklist; mark && mark->id != id; mark = mark->next ) ;
818 if ( mark ) {
819 mark->loc += d;
820 mark->err -= d;
821 }
822 }
823
824 Tcl_SetIntObj(returnObj, id);
825
826 return returnObj;
827 }
828
829 int marker_create(Bmarker* mark, int objc, Tcl_Obj *CONST objv[])
830 {
831 // Tcl_Obj* returnObj = Tcl_NewObj();
832
833 double x, y, z;
834
835 if ( objc > 4 ) Tcl_GetDoubleFromObj(NULL, objv[4], &x);
836 if ( objc > 5 ) Tcl_GetDoubleFromObj(NULL, objv[5], &y);
837 if ( objc > 6 ) Tcl_GetDoubleFromObj(NULL, objv[6], &z);
838
839 if ( mark ) {
840 mark->loc = Vector3<float>(x, y, z);
841 mark->fom = 1;
842 mark->sel = 1;
843 }
844
845 return 0;
846 }
847
848 Tcl_Obj* marker_create(Bmicrograph* mg, int objc, Tcl_Obj *CONST objv[])
849 {
850 Tcl_Obj* returnObj = Tcl_NewObj();
851
852 int id(0);
853
854 Bmarker* mark = NULL;
855
856 if ( mg ) {
857 for ( mark = mg->mark; mark; mark = mark->next )
858 if ( id < mark->id ) id = mark->id;
859 mark = (Bmarker *) add_item((char **) &mg->mark, sizeof(Bmarker));
860 }
861
862 if ( mark ) {
863 mark->id = ++id;
864 mark->img_num = mg->img_num;
865 marker_create(mark, objc, objv);
866 }
867
868 Tcl_SetIntObj(returnObj, id);
869
870 return returnObj;
871 }
872
873 Tcl_Obj* marker_create(Breconstruction* rec, int objc, Tcl_Obj *CONST objv[])
874 {
875 Tcl_Obj* returnObj = Tcl_NewObj();
876
877 int id(0);
878
879 Bmarker* mark = NULL;
880
881 if ( rec ) {
882 for ( mark = rec->mark; mark; mark = mark->next )
883 if ( id < mark->id ) id = mark->id;
884 mark = (Bmarker *) add_item((char **) &rec->mark, sizeof(Bmarker));
885 }
886
887 if ( mark ) {
888 mark->id = ++id;
889 mark->img_num = 0;
890 marker_create(mark, objc, objv);
891 }
892
893 Tcl_SetIntObj(returnObj, id);
894
895 return returnObj;
896 }
897
898 Tcl_Obj* marker_center(Bmarker* mark, Bimage* p, int objc, Tcl_Obj *CONST objv[])
899 {
900 Tcl_Obj* returnObj = Tcl_NewObj();
901
902 Vector3<float> center(p->sizeX()/2, p->sizeY()/2, p->sizeZ()/2);
903
904 if ( mark ) markers_center(mark, center);
905
906 return returnObj;
907 }
908
909 Tcl_Obj* marker_generate_from_seed(Bproject* project)
910 {
911 Tcl_Obj* returnObj = Tcl_NewObj();
912
913 if ( !project ) return returnObj;
914 if ( !project->field ) return returnObj;
915 if ( !project->field->mg ) return returnObj;
916
917 if ( project->field->mg->origin[0] < 1 || project->field->mg->origin[1] < 1 )
918 project_set_nominal_mg_origins(project);
919
920 project_mg_tilt_to_matrix(project);
921
922 // if ( !project->rec || !project->rec->mark )
923 project_calculate_model(project);
924
925 project_generate_markers(project);
926
927 return returnObj;
928 }
929
930 Tcl_Obj* marker_find(Bmicrograph* mg, Bimage* p, int objc, Tcl_Obj *CONST objv[])
931 {
932 Tcl_Obj* returnObj = Tcl_NewObj();
933
934 double r(0);
935
936 if ( objc > 4 ) Tcl_GetDoubleFromObj(NULL, objv[4], &r);
937
938 Bmarker* mark = NULL;
939
940 if ( mg ) {
941 mark = img_find_gold_particles(p, mg->img_num, r, 0, 0);
942 if ( mark ) {
943 if ( !mg->mark ) mg->mark = mark;
944 else markers_add(&mg->mark, mark, 2*mg->mark_radius, 2);
945 }
946 }
947
948 int nmark = count_list((char *) mg->mark);
949
950 Tcl_SetIntObj(returnObj, nmark);
951
952 return returnObj;
953 }
954
955 Tcl_Obj* marker_snap(Bmicrograph* mg, Bimage* p, long mid, int objc, Tcl_Obj *CONST objv[])
956 {
957 Tcl_Obj* returnObj = Tcl_NewObj();
958
959 if ( mg ) {
960 Bmarker* mark = NULL;
961 for ( mark = mg->mark; mark && mark->id != mid; mark = mark->next ) ;
962 if ( mark ) {
963 long i(0);
964 double v, avg(0), wcoor(0);
965 Vector3<float> acoor;
966 Vector3<long> size = Vector3<long>(6*mg->mark_radius, 6*mg->mark_radius, 1);
967 Vector3<long> coor = mark->loc - size/2;
968 Bimage* pm = p->extract(mg->img_num, coor, size, 0, 0);
969 for ( i=0; i<pm->image_size(); ++i ) avg += (*pm)[i];
970 avg /= pm->image_size();
971 for ( i=0; i<pm->image_size(); ++i ) {
972 v = (*pm)[i];
973 if ( (*pm)[i] < avg ) {
974 acoor += pm->coordinates(i) * v;
975 wcoor += v;
976 }
977 }
978 acoor /= wcoor;
979 mark->loc = acoor + coor;
980 delete pm;
981 }
982 }
983
984 Tcl_SetDoubleObj(returnObj, 0);
985
986 return returnObj;
987 }
988
989 Tcl_Obj* marker_extract(Bmicrograph* mg, Bimage* p, int objc, Tcl_Obj *CONST objv[])
990 {
991 Tcl_Obj* returnObj = Tcl_NewObj();
992
993 if ( !p ) return returnObj;
994
995 Bstring filename;
996 float box_radius(0);
997 Bimage* part = NULL;
998
999 /* Particle image file name */
1000 if ( objc > 4 ) filename = Tcl_GetStringFromObj(objv[4], NULL);
1001
1002 if ( filename.length() ) {
1003 if ( mg ) {
1004 part = micrograph_extract_gold(mg, p, box_radius);
1005 if ( part ) {
1006 mg->fpart = filename;
1007 write_img(filename, part, 0);
1008 delete part;
1009 }
1010 }
1011 }
1012
1013 return returnObj;
1014 }
1015
1016 Tcl_Obj* marker_extract(Breconstruction* rec, Bimage* p, int objc, Tcl_Obj *CONST objv[])
1017 {
1018 Tcl_Obj* returnObj = Tcl_NewObj();
1019
1020 if ( !p ) return returnObj;
1021
1022 Bstring filename;
1023 float box_radius(0);
1024 Bimage* part = NULL;
1025
1026 /* Particle image file name */
1027 if ( objc > 4 ) filename = Tcl_GetStringFromObj(objv[4], NULL);
1028
1029 if ( filename.length() ) {
1030 if ( rec ) {
1031 part = reconstruction_extract_gold(rec, p, box_radius);
1032 if ( part ) {
1033 rec->fpart = filename;
1034 write_img(filename, part, 0);
1035 delete part;
1036 }
1037 }
1038 }
1039
1040 return returnObj;
1041 }
1042
1043 Tcl_Obj* marker_delete(Bproject* project, int objc, Tcl_Obj *CONST objv[])
1044 {
1045 Tcl_Obj* returnObj = Tcl_NewObj();
1046
1047 int id(0);
1048 double fom_cut(0);
1049
1050 Bstring action = Tcl_GetStringFromObj(objv[4], NULL);
1051
1052 Bfield* field;
1053 Bmicrograph* mg = NULL;
1054 Breconstruction* rec;
1055 Bmarker* mark;
1056
1057 if ( action == "all" ) {
1058 for ( field = project->field; field; field = field->next ) {
1059 for ( mg = field->mg; mg; mg = mg->next ) {
1060 kill_list((char *) mg->mark, sizeof(Bmarker));
1061 mg->mark = NULL;
1062 }
1063 }
1064 for ( rec = project->rec; rec; rec = rec->next ) {
1065 kill_list((char *) rec->mark, sizeof(Bmarker));
1066 rec->mark = NULL;
1067 }
1068 } else if ( action == "fom" ) {
1069 if ( objc > 5 ) Tcl_GetDoubleFromObj(NULL, objv[5], &fom_cut);
1070 for ( field = project->field; field; field = field->next ) {
1071 for ( mg = field->mg; mg; mg = mg->next ) {
1072 for ( mark = mg->mark; mark; mark = mark->next )
1073 if ( mark->fom < fom_cut ) mark->sel = 0;
1074 else if ( mark->sel < 1 ) mark->sel = 1;
1075 markers_delete_non_selected(&mg->mark);
1076 }
1077 }
1078 for ( rec = project->rec; rec; rec = rec->next ) {
1079 for ( mark = rec->mark; mark; mark = mark->next )
1080 if ( mark->fom < fom_cut ) mark->sel = 0;
1081 else if ( mark->sel < 1 ) mark->sel = 1;
1082 markers_delete_non_selected(&rec->mark);
1083 }
1084 } else {
1085 if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &id);
1086 if ( id > 0 ) { // Delete all markers with this id for both micrographs and reconstructions
1087 for ( field = project->field; field; field = field->next ) {
1088 for ( mg = field->mg; mg; mg = mg->next ) {
1089 for ( mark = mg->mark; mark && mark->id != id; mark = mark->next ) ;
1090 if ( mark )
1091 remove_item((char **)&mg->mark, (char *)mark, sizeof(Bmarker));
1092 }
1093 }
1094 for ( rec = project->rec; rec; rec = rec->next ) {
1095 for ( mark = rec->mark; mark && mark->id != id; mark = mark->next ) ;
1096 if ( mark )
1097 remove_item((char **)&rec->mark, (char *)mark, sizeof(Bmarker));
1098 }
1099 }
1100 }
1101
1102 Tcl_SetIntObj(returnObj, id);
1103
1104 return returnObj;
1105 }
1106
1107 Tcl_Obj* marker_delete(Bfield* field, int objc, Tcl_Obj *CONST objv[])
1108 {
1109 Tcl_Obj* returnObj = Tcl_NewObj();
1110
1111 if ( !field ) return returnObj;
1112
1113 int id(0);
1114 double fom_cut(0);
1115
1116 Bstring action = Tcl_GetStringFromObj(objv[4], NULL);
1117
1118 Bmicrograph* mg = NULL;
1119 Bmarker* mark;
1120
1121 if ( action == "all" ) {
1122 for ( mg = field->mg; mg; mg = mg->next ) {
1123 kill_list((char *) mg->mark, sizeof(Bmarker));
1124 mg->mark = NULL;
1125 }
1126 } else if ( action == "fom" ) {
1127 if ( objc > 5 ) Tcl_GetDoubleFromObj(NULL, objv[5], &fom_cut);
1128 for ( mg = field->mg; mg; mg = mg->next ) {
1129 for ( mark = mg->mark; mark; mark = mark->next )
1130 if ( mark->fom < fom_cut ) mark->sel = 0;
1131 else if ( mark->sel < 1 ) mark->sel = 1;
1132 markers_delete_non_selected(&mg->mark);
1133 }
1134 } else {
1135 if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &id);
1136 if ( id > 0 ) {
1137 for ( mg = field->mg; mg; mg = mg->next ) {
1138 for ( mark = mg->mark; mark && mark->id != id; mark = mark->next ) ;
1139 if ( mark )
1140 remove_item((char **)&mg->mark, (char *)mark, sizeof(Bmarker));
1141 }
1142 }
1143 }
1144
1145 Tcl_SetIntObj(returnObj, id);
1146
1147 return returnObj;
1148 }
1149
1150 Tcl_Obj* marker_delete(Bmicrograph* mg, int objc, Tcl_Obj *CONST objv[])
1151 {
1152 Tcl_Obj* returnObj = Tcl_NewObj();
1153
1154 if ( !mg ) return returnObj;
1155
1156 int id(0);
1157 double fom_cut(0);
1158
1159 Bstring action = Tcl_GetStringFromObj(objv[4], NULL);
1160
1161 Bmarker* mark;
1162
1163 if ( action == "all" ) {
1164 kill_list((char *) mg->mark, sizeof(Bmarker));
1165 mg->mark = NULL;
1166 } else if ( action == "fom" ) {
1167 if ( objc > 5 ) Tcl_GetDoubleFromObj(NULL, objv[5], &fom_cut);
1168 for ( mark = mg->mark; mark; mark = mark->next )
1169 if ( mark->fom < fom_cut ) mark->sel = 0;
1170 else if ( mark->sel < 1 ) mark->sel = 1;
1171 // mark = mg->mark;
1172 // mg->mark = markers_copy_selected(mark);
1173 // kill_list((char *) mark, sizeof(Bmarker));
1174 markers_delete_non_selected(&mg->mark);
1175 } else {
1176 if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &id);
1177 if ( id > 0 ) {
1178 for ( mark = mg->mark; mark && mark->id != id; mark = mark->next ) ;
1179 if ( mark ) remove_item((char **)&mg->mark, (char *)mark, sizeof(Bmarker));
1180 }
1181 }
1182
1183 Tcl_SetIntObj(returnObj, id);
1184
1185 return returnObj;
1186 }
1187
1188 Tcl_Obj* marker_delete(Breconstruction* rec, int objc, Tcl_Obj *CONST objv[])
1189 {
1190 Tcl_Obj* returnObj = Tcl_NewObj();
1191
1192 if ( !rec ) return returnObj;
1193
1194 int id(0);
1195 double fom_cut(0);
1196
1197 Bstring action = Tcl_GetStringFromObj(objv[4], NULL);
1198
1199 Bmarker* mark;
1200
1201 if ( action == "all" ) {
1202 kill_list((char *) rec->mark, sizeof(Bmarker));
1203 rec->mark = NULL;
1204 } else if ( action == "fom" ) {
1205 if ( objc > 5 ) Tcl_GetDoubleFromObj(NULL, objv[5], &fom_cut);
1206 for ( mark = rec->mark; mark; mark = mark->next )
1207 if ( mark->fom < fom_cut ) mark->sel = 0;
1208 else if ( mark->sel < 1 ) mark->sel = 1;
1209 markers_delete_non_selected(&rec->mark);
1210 } else {
1211 if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &id);
1212 if ( id > 0 ) {
1213 for ( mark = rec->mark; mark && mark->id != id; mark = mark->next ) ;
1214 if ( mark ) remove_item((char **)&rec->mark, (char *)mark, sizeof(Bmarker));
1215 }
1216 }
1217
1218 Tcl_SetIntObj(returnObj, id);
1219
1220 return returnObj;
1221 }
1222
1223 Tcl_Obj* marker_edge(Bmarker* mark, Bimage* p, int objc, Tcl_Obj *CONST objv[])
1224 {
1225 Tcl_Obj* returnObj = Tcl_NewObj();
1226
1227 int edge(0);
1228
1229 if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &edge);
1230
1231 float xmin, xmax, ymin, ymax;
1232
1233 if ( mark ) {
1234 xmin = edge;
1235 xmax = p->sizeX() - edge;
1236 ymin = edge;
1237 ymax = p->sizeY() - edge;
1238 for ( ; mark && mark->id; mark = mark->next ) {
1239 if ( mark->loc[0] < xmin || mark->loc[0] > xmax || mark->loc[1] < ymin || mark->loc[1] > ymax )
1240 mark->fom = -fabs(mark->fom);
1241 else
1242 mark->fom = fabs(mark->fom);
1243 }
1244 }
1245
1246 return returnObj;
1247 }
1248
1249 Tcl_Obj* marker_accept(Bmarker* mark, int objc, Tcl_Obj *CONST objv[])
1250 {
1251 Tcl_Obj* returnObj = Tcl_NewObj();
1252
1253 int id(0);
1254
1255 if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &id);
1256
1257 for ( ; mark && mark->id != id; mark = mark->next ) ;
1258
1259 if ( mark ) {
1260 mark->loc += mark->err;
1261 mark->err = 0;
1262 }
1263
1264 return returnObj;
1265 }
1266
1267
1268
marker_find
Tcl_Obj * marker_find(Bmicrograph *mg, Bimage *p, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmarker.cpp:930
rwmg.h
Header file for reading and writing micrograph parameters.
project_track_markers
int project_track_markers(Bproject *project, double hi_res, double lo_res, double shift_limit, double thickness, int max_cycle, double target, int cc_type, int recenter, Bstring paramfile)
Aligns markers in a tomographic series.
Definition: mg_tomo_track.cpp:313
do_tomo_transfer_seed
int do_tomo_transfer_seed(Bproject *project, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmarker.cpp:68
Bproject::rec
Breconstruction * rec
Definition: mg_processing.h:344
Bstring::post
Bstring post(char c)
Definition: Bstring.cpp:394
reconstruction_extract_gold
Bimage * reconstruction_extract_gold(Breconstruction *rec, Bimage *p, double radius)
Extracts gold particle images from a reconstruction.
Definition: mg_extract.cpp:591
Breconstruction::mark
Bmarker * mark
Definition: mg_processing.h:307
markers_delete_non_selected
long markers_delete_non_selected(Bmarker **mark)
Deletes markers not selected.
Definition: marker.cpp:159
Breconstruction::fpart
Bstring fpart
Definition: mg_processing.h:288
project_set_nominal_mg_origins
int project_set_nominal_mg_origins(Bproject *project)
Sets micrograph origins to the centers of the micrographs.
Definition: mg_img_proc.cpp:660
project_transfer_seed
int project_transfer_seed(Bproject *project, double rot_start, double rot_end, double rot_step, double hi_res, double lo_res, double shift_limit)
Transfers the seed markers from the first to the second project.
Definition: mg_tomo_track.cpp:1418
Bmicrograph::id
Bstring id
Definition: mg_processing.h:202
marker_count
Tcl_Obj * marker_count(Bproject *project)
Definition: tcltk_bmarker.cpp:388
Bmicrograph::img_num
int img_num
Definition: mg_processing.h:211
Bimage::image_size
long image_size()
Definition: Bimage.h:267
utilities.h
Header file for general utilities.
marker_clear_selection_flag
Tcl_Obj * marker_clear_selection_flag(Bmarker *marklist, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmarker.cpp:779
project_refine
double project_refine(Bproject *project, int iter, double tol, Bstring refop)
Refines all the alignment parameters.
Definition: mg_tomo_track.cpp:868
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:112
Breconstruction
Definition: mg_processing.h:280
marker_ids
Tcl_Obj * marker_ids(Bproject *project, double fom_cut)
Definition: tcltk_bmarker.cpp:456
mg_img_proc.h
Header file for image processing from micrograph structures.
micrograph_extract_gold
Bimage * micrograph_extract_gold(Bmicrograph *mg, Bimage *p, double radius)
Extracts gold particle images from a micrograph.
Definition: mg_extract.cpp:573
verbose
int verbose
do_tomo_findaxis
int do_tomo_findaxis(Bproject *project, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmarker.cpp:97
kill_list
long kill_list(char *list, unsigned long size)
Frees all the items in a linked list.
Definition: linked_list.cpp:214
Bmarker
Definition: marker.h:21
add_item
char * add_item(char **list, unsigned long size)
Adds an item to a linked list.
Definition: linked_list.cpp:26
Bstring::length
long length() const
Definition: Bstring.cpp:263
project
Bproject * project
Definition: bshow.cpp:31
count_list
long count_list(char *list)
Counts the number of items in a linked list.
Definition: linked_list.cpp:235
marker_list
Tcl_Obj * marker_list(Bproject *project)
Definition: tcltk_bmarker.cpp:535
Bstring::remove
Bstring remove(const char c)
Definition: Bstring.cpp:465
img_find_gold_particles
Bmarker * img_find_gold_particles(Bimage *p, int img_select, double radius, long edge, double cutoff)
Finds gold particles in micrograph images.
Definition: mg_tomography.cpp:227
project_refine_one_marker
int project_refine_one_marker(Bproject *project, int id, double hi_res, double lo_res)
Refines marker positions in a tomographic series.
Definition: mg_tomo_track.cpp:768
markers_center
long markers_center(Bmarker *mark, Vector3< double > center)
Centers a set of markers.
Definition: marker.cpp:1176
MAXLINELEN
#define MAXLINELEN
Definition: utilities.h:44
marker_residual
Tcl_Obj * marker_residual(Bproject *project)
Definition: tcltk_bmarker.cpp:627
Bimage::file_name
void file_name(string s)
Definition: Bimage.h:230
project_refine_z
double project_refine_z(Bproject *project)
Refines the z coordinates of the marker model.
Definition: mg_tomo_track.cpp:948
markers_renumber
long markers_renumber(Bmarker *mark)
Renumbers a set of markers.
Definition: marker.cpp:1150
do_tomo_refine_one
int do_tomo_refine_one(Bproject *project, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmarker.cpp:178
Vector3::distance
double distance(const Vector3 &v)
Definition: Vector3.h:227
Bfield::next
Bfield * next
Definition: mg_processing.h:258
marker_extract
Tcl_Obj * marker_extract(Bmicrograph *mg, Bimage *p, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmarker.cpp:989
timer.h
Utilities for timing functions.
Breconstruction::mark_radius
double mark_radius
Definition: mg_processing.h:301
marker_edge
Tcl_Obj * marker_edge(Bmarker *mark, Bimage *p, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmarker.cpp:1223
Bimage
General image parameter class.
Definition: Bimage.h:163
Bmicrograph::fpart
Bstring fpart
Definition: mg_processing.h:207
Bstring::contains
bool contains(const Bstring &s)
Definition: Bstring.cpp:584
Bfield
Definition: mg_processing.h:257
project_check_markers
int project_check_markers(Bproject *project, int flags)
Checks if the markers in a project parameter structure fall within micrographs.
Definition: mg_tomography.cpp:1891
M_PI
#define M_PI
Definition: utilities.h:59
linked_list.h
Header file for generalized linked list functions.
Bimage::extract
Bimage * extract(long nn)
Extracts one sub-image into new image structure.
Definition: Bimage_extract.cpp:21
base
string base(string &filename)
Definition: string_util.cpp:28
project_generate_markers
int project_generate_markers(Bproject *project)
Generates missing micrograph and model markers.
Definition: mg_tomography.cpp:1007
Bmicrograph::fframe
Bstring fframe
Definition: mg_processing.h:206
Bfield::id
Bstring id
Definition: mg_processing.h:259
Bmicrograph::mark_radius
double mark_radius
Definition: mg_processing.h:235
marker_location
Tcl_Obj * marker_location(Bmarker *mark)
Definition: tcltk_bmarker.cpp:611
Bstring::pre
Bstring pre(char c)
Definition: Bstring.cpp:381
Bproject::field
Bfield * field
Definition: mg_processing.h:343
imglist
Bimage * imglist
Definition: bshow.cpp:30
marker_get_selection_flag
Tcl_Obj * marker_get_selection_flag(Bmarker *marklist, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmarker.cpp:740
project_mg_tilt_to_matrix
int project_mg_tilt_to_matrix(Bproject *project)
Sets the matrix from the tilt and axis angles for each micrograph.
Definition: mg_tomography.cpp:1960
Bmicrograph
Definition: mg_processing.h:200
mg_extract.h
Header file for functions to extract particles from micrographs.
project_tomo_residuals
double project_tomo_residuals(Bproject *project, int show)
Calculates the residuals for an alignment solution.
Definition: mg_tomography.cpp:671
mg_tomography.h
Header file for single particle image processing in Bsoft.
Bmicrograph::origin
Vector3< double > origin
Definition: mg_processing.h:220
Bmarker::fom
float fom
Definition: marker.h:28
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:280
project_find_tilt_axis
double project_find_tilt_axis(Bproject *project, double tilt, double axis_start, double axis_end, double axis_step, double hi_res, double lo_res, double shift_limit)
Finds the tilt axis for a tomographic tilt series.
Definition: mg_tomo_track.cpp:153
Bmarker::id
int id
Definition: marker.h:23
mg_tomo_track.h
Functions to track fiducial markers in a tomographic series of images.
remove_item
char * remove_item(char **list, char *item, unsigned long size)
Finds the given item and deletes it from the linked list.
Definition: linked_list.cpp:114
Bmicrograph::mark
Bmarker * mark
Definition: mg_processing.h:242
Bmarker::next
Bmarker * next
Definition: marker.h:22
Bfield::mg
Bmicrograph * mg
Definition: mg_processing.h:264
Bimage::next
Bimage * next
Definition: Bimage.h:165
project_sort_markers_by_id
int project_sort_markers_by_id(Bproject *project)
Sorts markers for each micrograph by ID number.
Definition: mg_tomography.cpp:647
Bstring::base
Bstring base()
Definition: Bstring.cpp:508
project_renumber_markers
long project_renumber_markers(Bproject *project)
Renumbers the markers in a project hierarchy.
Definition: mg_tomography.cpp:1516
marker_set_selection_flag
Tcl_Obj * marker_set_selection_flag(Bmarker *marklist, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmarker.cpp:759
Bstring
Definition: Bstring.h:29
Bimage::sizeX
void sizeX(long nx)
Definition: Bimage.h:377
Bproject::select
int select
Definition: mg_processing.h:339
do_tomo_track
int do_tomo_track(Bproject *project, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmarker.cpp:120
Bmarker::img_num
int img_num
Definition: marker.h:24
do_tomo_refine
int do_tomo_refine(Bproject *project, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmarker.cpp:145
tcltk_bmarker.h
A shared object to manage markers in micrograph parameter files in TCL/Tk.
Bimage::sizeZ
void sizeZ(long nz)
Definition: Bimage.h:379
Vector3< float >
Bmicrograph::fmg
Bstring fmg
Definition: mg_processing.h:205
project_refine_markers
int project_refine_markers(Bproject *project, double hi_res, double lo_res)
Refines marker positions in a tomographic series.
Definition: mg_tomo_track.cpp:683
marker_fom
Tcl_Obj * marker_fom(Bmarker *mark)
Definition: tcltk_bmarker.cpp:651
marker_accept
Tcl_Obj * marker_accept(Bmarker *mark, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmarker.cpp:1249
Bmarker::err
Vector3< float > err
Definition: marker.h:26
Bmarker::loc
Vector3< float > loc
Definition: marker.h:25
marker_move
Tcl_Obj * marker_move(Bmarker *marklist, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmarker.cpp:801
do_marker
Tcl_Obj * do_marker(Bproject *project, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmarker.cpp:240
marker_select
Tcl_Obj * marker_select(Bmarker *marklist, double rad, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmarker.cpp:678
project_calculate_angles
int project_calculate_angles(Bproject *project)
Calculates tilt and tilt axis angles from matrices in a project parameter structure.
Definition: mg_tomography.cpp:1749
Breconstruction::frec
Bstring frec
Definition: mg_processing.h:287
marker_fom_maximum
Tcl_Obj * marker_fom_maximum(Bmarker *mark)
Definition: tcltk_bmarker.cpp:664
marker_delete
Tcl_Obj * marker_delete(Bproject *project, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmarker.cpp:1043
project_calculate_model
int project_calculate_model(Bproject *project)
Calculates the z-coordinates of the marker model.
Definition: mg_tomography.cpp:886
marker_create
Tcl_Obj * marker_create(Bmicrograph *mg, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmarker.cpp:848
Bimage::coordinates
void coordinates(long i, long &nx, long &ny, long &nz)
Definition: Bimage.h:416
marker_select_rectangle
Tcl_Obj * marker_select_rectangle(Bmarker *marklist, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmarker.cpp:710
marker_center
Tcl_Obj * marker_center(Bmarker *mark, Bimage *p, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmarker.cpp:898
markers_add
long markers_add(Bmarker **mark, Bmarker *mark2, double mindist, int sel)
Adds a set of markers to another.
Definition: marker.cpp:120
Bimage::sizeY
void sizeY(long ny)
Definition: Bimage.h:378
marker_generate_from_seed
Tcl_Obj * marker_generate_from_seed(Bproject *project)
Definition: tcltk_bmarker.cpp:909
Bmarker::res
float res
Definition: marker.h:27
marker_snap
Tcl_Obj * marker_snap(Bmicrograph *mg, Bimage *p, long mid, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmarker.cpp:955
Breconstruction::next
Breconstruction * next
Definition: mg_processing.h:281
Bmarker::sel
int sel
Definition: marker.h:29
Bproject
Definition: mg_processing.h:333
Breconstruction::id
Bstring id
Definition: mg_processing.h:282
Bmicrograph::next
Bmicrograph * next
Definition: mg_processing.h:201