Bsoft  2.1.0
Bernard's software package
mg_marker.cpp
Go to the documentation of this file.
1 
9 #include "mg_marker.h"
10 #include "rwimg.h"
11 #include "utilities.h"
12 #include "timer.h"
13 
14 // Declaration of global variables
15 extern int verbose; // Level of output to the screen
16 
17 
24 {
25  long ntot(0), ntotsel(0), n, nsel;
26  Bfield* field = project->field;
27  Breconstruction* rec = project->rec;
28  Bmicrograph* mg;
29  Bmarker* mark;
30 
31  if ( field && field->mg && field->mg->mark ) {
32  cout << "Field\tMicrograph\tMarkers\tSelected" << endl;
33  for ( field = project->field; field; field = field->next ) {
34  n = nsel = 0;
35  for ( mg = field->mg; mg; mg = mg->next ) {
36  for ( mark = mg->mark; mark; mark = mark->next ) {
37  n++;
38  if ( mark->sel ) nsel++;
39  }
40  cout << field->id << tab << mg->id << tab << n << tab << nsel << endl;
41  }
42  ntot += n;
43  ntotsel += nsel;
44  }
45  }
46 
47  if ( rec && rec->mark ) {
48  cout << "Reconstruction\tMarkers\tSelected" << endl;
49  n = nsel = 0;
50  for ( rec = project->rec; rec; rec = rec->next ) {
51  for ( mark = rec->mark; mark; mark = mark->next ) {
52  n++;
53  if ( mark->sel ) nsel++;
54  }
55  cout << rec->id << tab << n << tab << nsel << endl;
56  }
57  ntot += n;
58  ntotsel += nsel;
59  }
60 
61  cout << "Total number of markers: " << ntot << tab << ntotsel << endl;
62 
63  return ntot;
64 }
65 
66 
73 {
74  long i, n(0);
75  double maxrad, d;
76  int h[100];
77  for ( i=0; i<100; i++ ) h[i] = 0;
78 
79  Bfield* field = project->field;
80  Breconstruction* rec = project->rec;
81  Bmicrograph* mg;
82  Bparticle* part;
83  Bmarker* mark;
84 
85  if ( !project->select && field && field->mg && field->mg->mark ) {
86  for ( field = project->field; field; field = field->next ) {
87  for ( mg = field->mg; mg; mg = mg->next ) {
88  maxrad = mg->box_size[0]/2;
89  for ( part = mg->part; part; part = part->next ) {
90  part->sel = 0;
91  for ( mark = mg->mark; mark; mark = mark->next ) {
92  d = part->loc.distance(mark->loc);
93  if ( d < maxrad ) {
94  part->sel++;
95  }
96  }
97  h[part->sel]++;
98  n++;
99  }
100  }
101  }
102  }
103 
104  if ( project->select && rec && rec->mark ) {
105  for ( rec = project->rec; rec; rec = rec->next ) {
106  maxrad = rec->box_size[0]/2;
107  for ( part = rec->part; part; part = part->next ) {
108  part->sel = 0;
109  for ( mark = rec->mark; mark; mark = mark->next ) {
110  d = part->loc.distance(mark->loc);
111  if ( d < maxrad ) {
112  part->sel++;
113  }
114  }
115  h[part->sel]++;
116  n++;
117  }
118  }
119  }
120 
121  cout << "Number\tCount\t%" << endl;
122  for ( i=0; i<100; i++ ) if ( h[i] )
123  cout << i << tab << h[i] << tab << fixed << setprecision(2) << h[i]*100.0/n << endl;
124  cout << "Total" << tab << n << tab << 100 << endl;
125 
126  return n;
127 }
128 
136 {
137  long i, n(0), np, fill_type(FILL_USER);
138  double maxrad, d;
139  Vector3<float> loc, box_rad;
140  int h[100];
141  for ( i=0; i<100; i++ ) h[i] = 0;
142 
143  Bfield* field = project->field;
144  Breconstruction* rec = project->rec;
145  Bmicrograph* mg;
146  Bparticle* part;
147  Bmarker* mark;
148  Bimage* p;
149  Bimage* pt;
150 
151  if ( !project->select && field && field->mg && field->mg->mark ) {
152  for ( field = project->field; field; field = field->next ) {
153  for ( mg = field->mg; mg; mg = mg->next ) {
154  maxrad = mg->box_size[0]/2;
155  box_rad = mg->box_size/2;
156  mg->mark_radius = marker_radius;
157  for ( np=0, part = mg->part; part; part = part->next ) np++;
158  if ( np ) {
159  p = new Bimage(Float, TSimple, mg->box_size, np);
160  pt = new Bimage(Float, TSimple, mg->box_size, 1);
161  for ( i=0, part = mg->part; part; part = part->next, i++ ) {
162  pt->clear();
163  part->sel = 0;
164  for ( mark = mg->mark; mark; mark = mark->next ) {
165  d = part->loc.distance(mark->loc);
166  if ( d < maxrad ) {
167  part->sel++;
168  loc = mark->loc - part->loc + part->ori;
169  pt->sphere(loc, marker_radius, 2, fill_type, 1);
170  }
171  }
172  h[part->sel]++;
173  n++;
174  p->replace(i, pt);
175  }
176  mg->fpart = mg->fpart.pre_rev('.') + "_mark." + mg->fpart.post_rev('.');
177  cout << mg->fpart << endl;
178  write_img(mg->fpart, p, 0);
179  delete p;
180  }
181  }
182  }
183  }
184 
185  if ( project->select && rec && rec->mark ) {
186  for ( rec = project->rec; rec; rec = rec->next ) {
187  maxrad = rec->box_size[0]/2;
188  for ( part = rec->part; part; part = part->next ) {
189  part->sel = 0;
190  for ( mark = rec->mark; mark; mark = mark->next ) {
191  d = part->loc.distance(mark->loc);
192  if ( d < maxrad ) {
193  part->sel++;
194  }
195  }
196  h[part->sel]++;
197  n++;
198  }
199  }
200  }
201 
202  cout << "Number\tCount\t%" << endl;
203  for ( i=0; i<100; i++ ) if ( h[i] )
204  cout << i << tab << h[i] << tab << fixed << setprecision(2) << h[i]*100.0/n << endl;
205  cout << "Total" << tab << n << tab << 100 << endl;
206 
207  return n;
208 }
209 
Bmicrograph::id
Bstring id
Definition: mg_processing.h:203
Bmicrograph
Definition: mg_processing.h:201
Breconstruction::part
Bparticle * part
Definition: mg_processing.h:307
Breconstruction::id
Bstring id
Definition: mg_processing.h:285
Breconstruction::mark
Bmarker * mark
Definition: mg_processing.h:310
Bproject::rec
Breconstruction * rec
Definition: mg_processing.h:347
Bproject::select
int select
Definition: mg_processing.h:342
Bparticle
Definition: mg_processing.h:90
Bstring::post_rev
Bstring post_rev(char c)
Definition: Bstring.cpp:436
Bproject::field
Bfield * field
Definition: mg_processing.h:346
Vector3< float >
FILL_USER
#define FILL_USER
Definition: utilities.h:176
Breconstruction::box_size
Vector3< long > box_size
Definition: mg_processing.h:299
Bmicrograph::part
Bparticle * part
Definition: mg_processing.h:242
Bfield::id
Bstring id
Definition: mg_processing.h:262
Bmicrograph::fpart
Bstring fpart
Definition: mg_processing.h:208
Bfield
Definition: mg_processing.h:260
Bmarker
Definition: marker.h:21
Vector3::distance
double distance(const Vector3 &v)
Definition: Vector3.h:227
project
Bproject * project
Definition: bshow.cpp:33
project_marker_in_particle
long project_marker_in_particle(Bproject *project)
Enumerates markers within particles.
Definition: mg_marker.cpp:72
project_marker_lists
long project_marker_lists(Bproject *project)
Lists micrograph markers.
Definition: mg_marker.cpp:23
TSimple
@ TSimple
Definition: Bimage.h:59
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:281
Bmarker::next
Bmarker * next
Definition: marker.h:22
Bstring::pre_rev
Bstring pre_rev(char c)
Definition: Bstring.cpp:421
Bimage
General image parameter class.
Definition: Bimage.h:177
timer.h
Utilities for timing functions.
Bproject
Definition: mg_processing.h:336
Bparticle::sel
long sel
Definition: mg_processing.h:104
Bimage::replace
int replace(Bimage *img)
Replaces the data with that from the given image.
Definition: Bimage.cpp:2830
Bimage::clear
void clear()
Definition: Bimage.h:705
Bmicrograph::mark_radius
double mark_radius
Definition: mg_processing.h:238
Bparticle::loc
Vector3< double > loc
Definition: mg_processing.h:100
Bmarker::loc
Vector3< float > loc
Definition: marker.h:25
utilities.h
Header file for general utilities.
tab
ostream & tab(ostream &out)
Definition: utilities.cpp:22
Bmicrograph::box_size
Vector3< long > box_size
Definition: mg_processing.h:233
Breconstruction
Definition: mg_processing.h:283
project_marker_in_particle_image
long project_marker_in_particle_image(Bproject *project, double marker_radius)
Enumerates markers within particles.
Definition: mg_marker.cpp:135
rwimg.h
Header file for 2D and 3D image I/O.
Bfield::next
Bfield * next
Definition: mg_processing.h:261
Bmicrograph::mark
Bmarker * mark
Definition: mg_processing.h:245
Bparticle::ori
Vector3< double > ori
Definition: mg_processing.h:101
Bmarker::sel
int sel
Definition: marker.h:29
Bparticle::next
Bparticle * next
Definition: mg_processing.h:91
mg_marker.h
Header file for micrograph marker functions.
verbose
int verbose
Float
@ Float
Definition: utilities.h:161
Bmicrograph::next
Bmicrograph * next
Definition: mg_processing.h:202
Bfield::mg
Bmicrograph * mg
Definition: mg_processing.h:267
Bimage::sphere
int sphere(Vector3< double > center, double radius, double width=0, int fill_type=0, double fill=0)
Fills a sphere within an image with a uniform value.
Definition: Bimage_edit.cpp:440
Breconstruction::next
Breconstruction * next
Definition: mg_processing.h:284