| Bsoft 2.0.5 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
23 long project_marker_lists(Bproject* project)
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
72 long project_marker_in_particle(Bproject* project)
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
135 long project_marker_in_particle_image(Bproject* project, double marker_radius)
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
Bimage::replace
int replace(Bimage *img)
Replaces the data with that from the given image.
Definition: Bimage.cpp:2828
Bproject::rec
Breconstruction * rec
Definition: mg_processing.h:344
verbose
int verbose
Breconstruction::part
Bparticle * part
Definition: mg_processing.h:304
Breconstruction::mark
Bmarker * mark
Definition: mg_processing.h:307
Bmicrograph::id
Bstring id
Definition: mg_processing.h:202
utilities.h
Header file for general utilities.
Breconstruction
Definition: mg_processing.h:280
Bmarker
Definition: marker.h:21
project
Bproject * project
Definition: bshow.cpp:31
Vector3::distance
double distance(const Vector3 &v)
Definition: Vector3.h:227
Breconstruction::box_size
Vector3< long > box_size
Definition: mg_processing.h:296
project_marker_lists
long project_marker_lists(Bproject *project)
Lists micrograph markers.
Definition: mg_marker.cpp:23
Bfield::next
Bfield * next
Definition: mg_processing.h:258
Bmicrograph::part
Bparticle * part
Definition: mg_processing.h:239
TSimple
Definition: Bimage.h:58
timer.h
Utilities for timing functions.
Float
Definition: utilities.h:157
Bimage
General image parameter class.
Definition: Bimage.h:163
Bmicrograph::fpart
Bstring fpart
Definition: mg_processing.h:207
Bparticle::sel
long sel
Definition: mg_processing.h:103
Bfield
Definition: mg_processing.h:257
project_marker_in_particle
long project_marker_in_particle(Bproject *project)
Enumerates markers within particles.
Definition: mg_marker.cpp:72
Bfield::id
Bstring id
Definition: mg_processing.h:259
Bmicrograph::mark_radius
double mark_radius
Definition: mg_processing.h:235
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:438
Bproject::field
Bfield * field
Definition: mg_processing.h:343
Bmicrograph
Definition: mg_processing.h:200
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:280
FILL_USER
#define FILL_USER
Definition: utilities.h:172
Bparticle::ori
Vector3< double > ori
Definition: mg_processing.h:100
Bmicrograph::mark
Bmarker * mark
Definition: mg_processing.h:242
Bmarker::next
Bmarker * next
Definition: marker.h:22
Bstring::post_rev
Bstring post_rev(char c)
Definition: Bstring.cpp:428
Bfield::mg
Bmicrograph * mg
Definition: mg_processing.h:264
Bparticle
Definition: mg_processing.h:89
Bimage::clear
void clear()
Definition: Bimage.h:697
Bproject::select
int select
Definition: mg_processing.h:339
Bmicrograph::box_size
Vector3< long > box_size
Definition: mg_processing.h:230
Vector3< float >
Bparticle::loc
Vector3< double > loc
Definition: mg_processing.h:99
mg_marker.h
Header file for micrograph marker functions.
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
Bmarker::loc
Vector3< float > loc
Definition: marker.h:25
rwimg.h
Header file for 2D and 3D image I/O.
Bstring::pre_rev
Bstring pre_rev(char c)
Definition: Bstring.cpp:413
Bparticle::next
Bparticle * next
Definition: mg_processing.h:90
Breconstruction::next
Breconstruction * next
Definition: mg_processing.h:281
Bmarker::sel
int sel
Definition: marker.h:29
tab
ostream & tab(ostream &out)
Definition: utilities.cpp:21
Bproject
Definition: mg_processing.h:333
Breconstruction::id
Bstring id
Definition: mg_processing.h:282
Bmicrograph::next
Bmicrograph * next
Definition: mg_processing.h:201