Bsoft  2.1.0
Bernard's software package
model_map.cpp
Go to the documentation of this file.
1 
9 #include "rwmodel.h"
10 #include "model_transform.h"
11 #include "model_extract_build.h"
12 #include "rwimg.h"
13 #include "mg_orient.h"
14 #include "img_combine.h"
15 #include "utilities.h"
16 
17 // Declaration of global variables
18 extern int verbose; // Level of output to the screen
19 
29 {
30  long n;
31  Bimage* p = plist;
32  Bstring base, id, filename(p->file_name());
33  Bmodel* model = NULL;
34  Bmodel* mp = NULL;
35 
36  base = filename.base().alnum();
37 
38  for ( n=0; n<p->images(); n++ ) {
39  id = base;
40  if ( p->images() > 1 ) id += Bstring(n+1, "_%04d");
41  mp = model_add(&mp, id);
42  if ( !model ) model = mp;
43  mp->fmap = p->file_name();
44  mp->img_num = n;
45  }
46 
47  return model;
48 }
49 
60  Vector3<long> size, Vector3<double> sam, double sigma)
61 {
62  if ( !model ) {
63  cerr << "Error: No model selected!" << endl << endl;
64  return NULL;
65  }
66 
67  if ( sam.volume() < 1e-6 )
68  sam[0] = sam[1] = sam[2] = 1;
69  else
70  sam = sam.max(0.01);
71 
72  if ( sigma < sam[0] ) sigma = sam[0];
73 
74  long i, n;
75  long x, y, z, xlo, ylo, zlo, xhi, yhi, zhi;
76  double x2, y2, z2;
77  double pix_sigma = sigma/sam[0];
78  double pix_rad = 3*pix_sigma;
79  double nhis2 = -0.5/(pix_sigma*pix_sigma);
80  Vector3<double> min, max, c;
81  Bmodel* mp;
82  Bcomponent* comp;
83 
84  for ( n=0, mp = model; mp; mp = mp->next ) if ( mp->sel ) {
85  mp->img_num = n++;
86  for ( comp = mp->comp; comp; comp = comp->next ) if ( comp->sel ) {
87  min = min.min(comp->loc);
88  max = max.max(comp->loc);
89  }
90  }
91 
92  if ( size[0] < 1 ) size[0] = (long) ((max[0] - min[0] + 3*sigma)/sam[0]);
93  if ( size[1] < 1 ) size[1] = (long) ((max[1] - min[1] + 3*sigma)/sam[1]);
94  if ( size[2] < 1 ) size[2] = (long) ((max[2] - min[2] + 3*sigma)/sam[2]);
95  size = size.min(1024);
96  size = size.max(1);
97 
98  Bimage* p = new Bimage(Float, TSimple, size[0], size[1], size[2], n);
99  p->file_name(model->id.str());
100  p->origin(ori);
101  p->sampling(sam);
102 
103  if ( verbose & VERB_PROCESS ) {
104  cout << "Calculating density by simple gaussian expansion:" << endl;
105  cout << "Models: " << p->images() << endl;
106  cout << "Dimensions: " << p->size() << " voxels" << endl;
107  cout << "Origin: " << p->image->origin()<< endl;
108  cout << "Sampling: " << p->sampling(0) << " A/voxel" << endl;
109  cout << "Sigma: " << sigma << " A (" << pix_sigma << " pixels)" << endl << endl;
110  } else if ( verbose & VERB_LABEL )
111  cout << endl << "Calculating density" << endl << endl;
112 
113  for ( n=0, mp = model; mp; mp = mp->next ) if ( mp->sel ) {
114  for ( comp = mp->comp; comp; comp = comp->next ) if ( comp->sel ) {
115  c = comp->loc/sam + ori;
116  xlo = (long) (c[0] - pix_rad + 0.5);
117  ylo = (long) (c[1] - pix_rad + 0.5);
118  zlo = (long) (c[2] - pix_rad + 0.5);
119  if ( xlo < 0 ) xlo = 0;
120  if ( ylo < 0 ) ylo = 0;
121  if ( zlo < 0 ) zlo = 0;
122  xhi = (long) (c[0] + pix_rad + 0.5);
123  yhi = (long) (c[1] + pix_rad + 0.5);
124  zhi = (long) (c[2] + pix_rad + 0.5);
125  if ( xhi >= p->sizeX() ) xhi = p->sizeX() - 1;
126  if ( yhi >= p->sizeY() ) yhi = p->sizeY() - 1;
127  if ( zhi >= p->sizeZ() ) zhi = p->sizeZ() - 1;
128  for ( z = zlo; z <= zhi; z++ ) {
129  z2 = z - c[2];
130  z2 *= z2;
131  for ( y = ylo; y <= yhi; y++ ) {
132  y2 = y - c[1];
133  y2 *= y2;
134  for ( x = xlo; x <= xhi; x++ ) {
135  x2 = x - c[0];
136  x2 *= x2;
137  i = p->index(0, x, y, z, n);
138  p->add(i, exp(nhis2*(x2 + y2 + z2)));
139  }
140  }
141  }
142  }
143  n++;
144  }
145 
146  return p;
147 }
148 
159 {
160  long i;
161  Bmodel* mp;
162  Bstring* file_list = NULL;
163  Vector3<long> nusize;
164  Bstring rawstring;
165 
166  for ( i=0, mp = model; mp; mp = mp->next, i++ ) {
167  string_add(&file_list, mp->fmap);
168  mp->fmap = filename;
169  mp->img_num = i;
170  }
171 
172  Bimage* pc = img_catenate(file_list, rawstring, Unknown_Type, nusize, 0, 0, 0, 0, 0);
173 
174  write_img(filename, pc, 0);
175 
176  delete pc;
177 
178  return 0;
179 }
180 
192 int model_shell_fit(Bmodel* model, double hires, double lores, int neg)
193 {
194  if ( lores < 1 ) lores = 1000;
195  if ( hires > lores ) swap(hires, lores);
196 
197  Bimage* p = NULL;
198 
199  if ( ( p = read_img(model->fmap, 1, model->img_num) ) == NULL )
200  error_show("Error in model_shell_fit: No map read!", __FILE__, __LINE__);
201 
202  double sigma = hires;
203  Vector3<double> origin(p->image->origin());
204  Vector3<long> size = {p->sizeX(), p->sizeY(), p->sizeZ()};
205  Vector3<double> sam(p->sampling(0));
206 
207  Bimage* pmod = img_from_model(model, origin, size, sam, sigma);
208 
209  if ( neg ) pmod->invert();
210 
211  if ( verbose )
212  cout << "Fitting the model to the map" << endl;
213 
214  double cc(0), radius = p->sizeX()/4;
215 
216  Vector3<double> shift = p->find_shift(pmod, NULL, hires, lores, radius, 0, 1, cc);
217  model->fom = cc;
218 
219  if ( verbose ) {
220  cout << "Fit CC: " << cc << endl;
221  cout << "Shifting the model by: " << shift << endl << endl;
222  }
223 
224  model_shift(model, shift*pmod->sampling(0));
225 
226  delete p;
227  delete pmod;
228 
229  return 0;
230 }
231 
241 {
242  if ( model->fmap.length() < 1 )
243  return error_show("Error in model_shell_radial_profile: No map specified!", __FILE__, __LINE__);
244 
245  Bimage* p = NULL;
246 
247  if ( ( p = read_img(model->fmap, 1, model->img_num) ) == NULL )
248  error_show("Error in model_shell_radial_profile: No map read!", __FILE__, __LINE__);
249 
250  p->change_type(Float);
251 
252  int ncomp, ntype, n;
253  long i, j;
254  double radstep = p->sampling(0)[0];
255  int maxrad = p->sizeX()/2;
256  double d, davg, v;
257  Vector3<double> nvec, vec, origin(p->image->origin());
258 
259  Bcomponent* comp;
260  Bcomptype* ct = NULL;
261 
262  for ( ntype=0, ct = model->type; ct; ct = ct->next ) ntype++;
263 
264  if ( ntype < 1 ) ntype = 1;
265 
266  float* r = new float[ntype*maxrad];
267  float* r2 = new float[ntype*maxrad];
268  float* w = new float[ntype*maxrad];
269  for ( i=0; i<ntype*maxrad; i++ ) r[i] = r2[i] = w[i] = 0;
270 
271  for ( ncomp=0, davg=0, comp = model->comp; comp; comp = comp->next, ncomp++ )
272  davg += comp->loc.length()/radstep;
273 
274  if ( ncomp < 1 )
275  error_show("Error in model_shell_radial_profile: No components!", __FILE__, __LINE__);
276 
277  davg /= ncomp;
278 
279  if ( verbose ) {
280  cout << "Calculating a radial profile based on a shell model:" << endl;
281  cout << "Radial step size: " << radstep << endl;
282  cout << "Average component distance: " << davg << endl << endl;
283  }
284 
285  for ( comp = model->comp; comp; comp = comp->next ) {
286  ct = comp->type;
287  if ( !ct ) n = 0;
288  nvec = comp->loc/radstep;
289  d = nvec.normalize() - davg;
290  for ( j=0; j<maxrad; j++ ) {
291  i = n*maxrad + j;
292  vec = nvec*(d+j) + origin;
293  if ( vec[0]>=0 && vec[0]<=p->sizeX()-2 && vec[1]>=0 && vec[1]<=p->sizeY()-2 && vec[2]>=0 && vec[2]<=p->sizeZ()-2 ) {
294 // v = p->interpolate(vec[0], vec[1], vec[2], 0, p->image->background());
295  v = p->interpolate(vec, 0, p->background(long(0)));
296  r[i] += v;
297  r2[i] += v*v;
298  w[i] += 1;
299  }
300  }
301  }
302 
303  for ( i=0; i<ntype*maxrad; i++ ) if ( w[i] ) {
304  r[i] /= w[i];
305  r2[i] = r2[i]/w[i] - r[i]*r[i];
306  if ( r2[i] > 0 ) r2[i] = sqrt(r2[i]);
307  else r2[i] = 0;
308  }
309  if ( verbose ) {
310  for ( n=0, ct = model->type; ct && n<ntype; ct = ct->next, n++ ) {
311  if ( ct ) cout << "Component type: " << ct->id << endl;
312  cout << "#\tRadius\tDensity\tSTDev\tWeight" << endl;
313  for ( j=0, i=n*maxrad; j<maxrad; j++, i++ )
314  cout << j << tab << j*radstep << tab << r[i] << tab << r2[i] << tab << w[i] << endl;
315  cout << endl;
316  }
317  }
318 
319  delete[] r;
320  delete[] r2;
321  delete[] w;
322  delete p;
323 
324  return 0;
325 }
326 
327 
328 
345  Vector3<double> origin, int ft_size, int ann_min, int ann_max,
346  double hires, double lores)
347 {
348  if ( ft_size < size[0] ) ft_size = findNextPowerOf(size[0], 2);
349  if ( ft_size < 128 ) ft_size = 128;
350 
351 // Vector3<double> origin(size[0]/2, size[1]/2, size[2]/2);
352 
353  Bimage* p = model_extract_component_densities(model, size, origin);
354 
355  if ( ann_min < 1 ) ann_min = 1;
356  if ( ann_max < 1 ) ann_max = p->sizeX()/2;
357  if ( ann_max < ann_min ) swap(ann_min, ann_max);
358 
359  if ( lores < 1 ) lores = p->sampling(0)[0]*p->sizeX()/2;
360  if ( hires < 1 ) hires = 2*p->sampling(0)[0];
361  if ( lores < hires ) swap(hires, lores);
362 
363  p->project('z', 1);
364  size[2] = 1;
365  origin[2] = 0;
366 
367  Vector3<double> start(1,1,0);
368  Vector3<int> esize(size[0] - 2, size[1] - 2, 1);
369 
370  p->edge(1, esize, start, 1, FILL_BACKGROUND, 0);
371 
372  int i, j, k, n, jb, nmax(6);
373 
374  int nannuli = p->sizeX()/2; // Sampling same as image
375  int nangles(NPOLANG); // 0.5 degree step size
376  double cc1, ccbest(0); // Best correlation coefficient
377  double pcc(0); // Polar power spectrum correlation coefficient
378  Vector3<double> scale(1,1,1), translate, shift1;
379  Vector3<double> shift;
380  Vector3<double> axis(0,0,1);
381  Matrix3 mat;
382  View view;
383  Bcomponent* comp;
384  Bimage* pone;
385  Bimage* pol;
386  Bimage* polref;
387  Bimage* pt;
388 
389  Bcomptype* ct[6];
390  Bstring ctstr[6];
391  ctstr[0] = "MON";
392  ctstr[1] = "DI";
393  ctstr[2] = "TRI";
394  ctstr[3] = "TET";
395  ctstr[4] = "PEN";
396  ctstr[5] = "HEX";
397 
399  model->type = NULL;
400 
401  Bimage** pref = new Bimage*[nmax];
402 
403  for ( j=0; j<nmax; j++ ) {
404  pref[j] = new Bimage(Float, TSimple, size[0], size[1], size[2], 1);
405 // pref[j]->image->origin(origin);
406  pref[j]->origin(origin);
407  pref[j]->sampling(p->sampling(0));
408  ct[j] = model_add_type_by_id(model, ctstr[j]);
409  }
410 
411  int* num = new int[nmax];
412  float* cc = new float[nmax];
413  float* ccs = new float[nmax];
414  float* ccr = new float[nmax];
415  Vector3<float>* ori = new Vector3<float>[nmax];
416  for ( i=0; i<nmax; i++ ) cc[i] = ccs[i] = ccr[i] = num[i] = 0;
417 
418  cc[0] = 1;
419 
420  // Specify FFTW arrays
421  fft_plan planf = fft_setup_plan(nangles, 1, 1, FFTW_FORWARD, 1);
422  fft_plan planb = fft_setup_plan(nangles, 1, 1, FFTW_BACKWARD, 1);
423 
424  if ( verbose )
425  cout << "Comp\tOrder\tAngle\tCC" << endl;
426  for ( i=0, comp = model->comp; i<p->images() && comp; i++, comp = comp->next ) {
427  pone = p->extract(i);
428  for ( j=1; j<nmax; j++ ) {
429  n = j + 1;
430  cc[j] = ccs[j] = 0;
431  ori[j] = 0;
432  for ( k=1; k<n; k++ ) {
433  mat = Matrix3(axis, TWOPI*k*1.0L/n);
434  pt = pone->transform(size, scale, origin, translate, mat, FILL_BACKGROUND, 0);
435  shift = pone->find_shift(pt, NULL, hires, lores, pone->sizeX()/4, 0, 1, cc1);
436  delete pt;
437  cc[j] += cc1;
438  ccs[j] += cc1*cc1;
439  mat = Matrix3(1) - mat;
440  mat = mat.singular_value_decomposition();
441  ori[j] += mat * shift + origin;
442  }
443  cc[j] /= j;
444  ccs[j] = ccs[j]/j - cc[j]*cc[j];
445  if ( ccs[j] > 0 ) ccs[j] = sqrt(ccs[j]);
446  else ccs[j] = 0;
447  cc[j] += ccs[j];
448  ori[j] /= j;
449  }
450  ccr[1] = 4*cc[1]/(cc[2]+cc[3]+cc[4]+cc[5]);
451  ccr[2] = 4*cc[2]/(cc[1]+cc[3]+cc[4]+cc[5]);
452  ccr[3] = 3*(cc[1]+cc[3])/(2*(cc[2]+cc[4]+cc[5]));
453  ccr[4] = 4*cc[4]/(cc[1]+cc[2]+cc[3]+cc[5]);
454  ccr[5] = 2*(cc[1]+cc[2]+cc[5])/(3*(cc[3]+cc[4]));
455  for ( j=1, jb=0, ccbest = 1.1; j<nmax; j++ ) {
456  if ( ccbest < ccr[j] ) {
457  ccbest = ccr[j];
458  jb = j;
459  }
460  cout << cc[j] << tab << ccr[j] << tab;
461  }
462  if ( !pref[jb] ) {
463  view[3] = 0;
464  } else {
465 // pone->image->origin(ori[jb]);
466  pone->origin(ori[jb]);
467 // polref = img_polar_transform(pref[jb], nannuli, nangles, ann_min, ann_max);
468 // pol = img_polar_transform(pone, nannuli, nangles, ann_min, ann_max);
469  polref = pref[jb]->cartesian_to_cylindrical(nannuli, nangles, 1);
470  pol = pone->cartesian_to_cylindrical(nannuli, nangles, 1);
471 // view[3] = comp->view[3] = img_correlate_annuli(polref, pol, 1, ann_min, ann_max, planf, planb, pcc);
472  view[3] = comp->view[3] = polref->correlate_annuli(pol, ann_min, ann_max,
473  0, TWOPI, planf, planb, pcc);
474  delete pol;
475  delete polref;
476  }
477  pref[jb]->rotate_and_add(pone, ori[jb], view);
478  delete pone;
479  comp->fom = cc[jb];
480  comp->type = ct[jb];
481  switch ( jb+1 ) {
482  case 2: comp->color = RGBA<float>(1,1,0,1); break;
483  case 3: comp->color = RGBA<float>(1,0.5,0,1); break;
484  case 4: comp->color = RGBA<float>(0.3,1,0.3,1); break;
485  case 5: comp->color = RGBA<float>(0,0,1,1); break;
486  case 6: comp->color = RGBA<float>(1,0,0,1); break;
487  default: comp->color = RGBA<float>(1,1,1,1);
488  }
489  num[jb]++;
490  if ( verbose )
491  cout << comp->id << tab << jb+1 << tab << comp->view.angle()*180.0/M_PI << tab << pcc << endl;
492  }
493 
496  delete p;
497 
498  if ( verbose ) {
499  cout << "Order\tCount" << endl;
500  for ( j=0; j<nmax; j++ )
501  cout << j+1 << tab << num[j] << endl;
502  }
503 
504  for ( j=0; j<nmax; j++ ) if ( num[j] ) pref[j]->multiply(1.0L/num[j]);
505 
506  delete[] num;
507  delete[] cc;
508  delete[] ccs;
509  delete[] ccr;
510  delete[] ori;
511 
512  Bimage* pfin = new Bimage();
513  pfin->catenate(nmax, pref);
514 
515  for ( j=0; j<nmax; j++ ) delete pref[j];
516  delete[] pref;
517 
518  pfin->pad(ft_size, FILL_BACKGROUND, pfin->background(long(0)));
519 
520  pfin->fft();
521 
522  pfin->complex_to_intensities();
523 
524  for ( i=0; i<pfin->images(); i++ )
525  pfin->image[i].origin(0,0,0);
526 
527  pfin->center_wrap();
528 
529  return pfin;
530 }
531 
532 int comp_set_fom_sym(Bcomponent* comp, Bimage* p, long minorder, long maxorder)
533 {
534  if ( minorder < 1 ) minorder = 1;
535 
536  long i, j, k, is(0), is2, xx, nyz(p->sizeY()*p->sizeZ()), nf, nb;
537  double v, sf, sb, mx(0), mx2(0);
538 
539  if ( verbose & VERB_DEBUG )
540  cout << "DEBUG comp_set_fom_sym: comp_id=" << comp->id << endl;
541 
542  Bimage* psym = new Bimage(Float, TSimple, maxorder+1, p->sizeY(), p->sizeZ(), 1);
543 
544  for ( j=0; j<nyz; j++ ) {
545  for ( k=minorder; k<=maxorder; k++ ) {
546  i = j*p->sizeX();
547  nf = nb = 0;
548  sf = sb = 0;
549  for ( xx=minorder, i+=xx; xx<p->sizeX()/2; xx++, i++ ) {
550  v = (*p)[i] * sqrt(1.0*xx);
551  if ( k%xx == 0 ) {
552  sf += v;
553  nf++;
554  } else {
555  sb += v;
556  nb++;
557  }
558  }
559  sf /= nf;
560  sb /= nb;
561  if ( sb < 0.001 ) sb = 0.001;
562  if ( sf < 0.001 ) sf = 0.001;
563 // psym->set(j*psym->sizeX()+k, 1 - sb/sf);
564 // psym->set(j*psym->sizeX()+k, sf - sb);
565  psym->set(j*psym->sizeX()+k, sf/sb - 1);
566 // cout << k << tab << nf << "," << sf << tab << nb << "," << sb << endl;
567  }
568  mx = mx2 = 0;
569  is = is2 = 0;
570  for ( k=minorder; k<=maxorder; k++ ) { // find the highest value
571  v = (*psym)[j*psym->sizeX()+k];
572  if ( mx < v ) {
573  mx = v;
574  is = k;
575  }
576  }
577  for ( k=minorder; k<=maxorder; k++ ) if ( k != is ) { // find the second highest value
578  v = (*psym)[j*psym->sizeX()+k];
579  if ( mx2 < v ) {
580  mx2 = v;
581  is2 = k;
582  }
583  }
584  if ( is2%is == 0 ) { // if the highest is a factor of the second, find another second highest
585  mx2 = 0;
586  for ( k=minorder; k<=maxorder; k++ ) if ( k != is && k != is2 ) {
587  v = (*psym)[j*psym->sizeX()+k];
588  if ( mx2 < v ) {
589  mx2 = v;
590  }
591  }
592  is = is2;
593  }
594  }
595 
596  delete psym;
597 
598  comp->fom = 1 - mx2/mx;
599  comp->sel = is;
600 
601  return 0;
602 }
603 
619  long ann_min, long ann_max, long ann_width,
620  long zmin, long zmax, long zinc, long minorder, long maxorder)
621 {
622  if ( ann_width < 1 ) ann_width = ann_max - ann_min;
623 
624  long i, nsym[maxorder+1];
625  double fomsym[maxorder+1], sep(0), sep_avg(0);
626  Vector3<long> size;
627  Vector3<double> origin;
628  Matrix3 mat(1);
629  Bstring id;
630  Bmodel* mp;
631  Bcomponent* comp;
632  Bimage* p = NULL;
633  Bimage* pex = NULL;
634  Bimage* pps = NULL;
635 
636  for ( i=0; i<=maxorder; i++ ) fomsym[i] = nsym[i] = 0;
637 
638  fft_plan plan = fft_setup_plan(nangles, 1, 1, FFTW_FORWARD, 1);
639 
640  p = read_img(model->fmap, 0, 0);
641 
642  if ( zmax <= 0 ) {
643  zmin = p->sizeZ() / 4;
644  zmax = p->sizeZ() - zmin - 1;
645  zinc = zmax - zmin + 1;
646  }
647 
648  delete p;
649 
650  if ( verbose ) {
651  cout << "Determining cyclic symmetry:" << endl;
652  cout << "Maximum order: " << nangles << endl;
653  cout << "Number of angles: " << maxorder << endl;
654  cout << "Annuli: " << ann_min << " - " << ann_max << " @ " << ann_width << " pixels" << endl;
655  cout << "Z limits: " << zmin << " - " << zmax << " @ " << zinc << " pixels" << endl;
656  }
657 
658  if ( verbose )
659  cout << "Model\tComponent\tOrder\tPower\tSeparation" << endl;
660  for ( i=0, mp = model; mp; mp = mp->next ) {
661  p = read_img(model->fmap, 1, mp->img_num);
662  for ( comp = mp->comp; comp; comp = comp->next, i++ ) {
663  size = Vector3<long>(4*comp->radius, 4*comp->radius, 4*comp->radius);
664  size = size.min(p->size());
665  origin = size/2;
666  pex = p->extract(0, p->image->origin() + comp->loc/p->sampling(0), size, origin, mat);
667 // pex->rotate(pex->size()/2, comp->view);
668  if ( ann_max > 0 ) {
669  if ( ann_width < 1 ) ann_width = ann_max - ann_min;
670  if ( ann_width < 1 ) ann_width = 1;
671  } else if ( ann_width > 0 ) {
672  ann_min = comp->radius/p->sampling(0)[0] - ann_width/2;
673  ann_max = ann_min + ann_width - 1;
674  } else {
675  ann_min = comp->radius/(2*p->sampling(0)[0]);
676  ann_max = 3*ann_min;
677  ann_width = ann_max - ann_min + 1;
678  }
679  pps = pex->polar_transform(nangles, ann_min, ann_max, ann_width, zmin, zmax, zinc);
680  delete pex;
681  pps->line_powerspectra(plan);
682  comp_set_fom_sym(comp, pps, minorder, maxorder);
683  delete pps;
684  sep = TWOPI*comp->radius/comp->sel;
685  sep_avg += sep;
686  if ( verbose )
687  cout << mp->id << tab << comp->id << tab << comp->sel << tab <<
688  setprecision(4) << comp->fom << tab << sep << endl;
689  nsym[comp->sel]++;
690  fomsym[comp->sel] += comp->fom;
691  }
692  delete p;
693  }
694 
695  if ( i ) sep_avg /= i;
696 
697  fft_destroy_plan(plan);
698 
699  for ( i=minorder; i<=maxorder; i++ ) if ( nsym[i]) {
700  fomsym[i] /= nsym[i];
701  }
702 
703  if ( verbose ) {
704  cout << "Order\tCount\tFOM" << endl;
705  for ( i=minorder; i<=maxorder; i++ )
706  cout << i << tab << nsym[i] << tab << fomsym[i] << endl;
707  cout << "Separation average: " << sep_avg << endl << endl;
708  }
709 
710  return 0;
711 }
model_catenate_maps
int model_catenate_maps(Bmodel *model, Bstring &filename)
Concatenates all model maps into one multi-image file.
Definition: model_map.cpp:158
Bimage::complex_to_intensities
void complex_to_intensities()
The intensities from a complex image is written to a simple image.
Definition: Bimage_complex.cpp:92
Bmodel::fom
float fom
Definition: rwmodel.h:128
Bcomponent::next
Bcomponent * next
Definition: rwmodel.h:52
Bimage::sizeZ
void sizeZ(long nz)
Definition: Bimage.h:392
Bcomponent
Definition: rwmodel.h:51
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:116
NPOLANG
#define NPOLANG
Definition: Bimage.h:30
Matrix3::singular_value_decomposition
Matrix3 singular_value_decomposition()
Definition: Matrix3.h:320
rwmodel.h
Header file for reading and writing atomic model files.
Bcomponent::loc
Vector3< float > loc
Definition: rwmodel.h:58
Bimage::set
void set(long j, double v)
Sets a single value at the given index.
Definition: Bimage.cpp:1118
Bstring
Definition: Bstring.h:29
model_extract_build.h
Functions to extract subvolumes and build new maps.
Bcomponent::id
Bstring id
Definition: rwmodel.h:53
base
string base(string &filename)
Definition: string_util.cpp:28
model_shell_fit
int model_shell_fit(Bmodel *model, double hires, double lores, int neg)
Fits a shell model as a rigid body to a map.
Definition: model_map.cpp:192
Bcomptype
Definition: rwmodel.h:25
Vector3< double >
Bimage::sizeX
void sizeX(long nx)
Definition: Bimage.h:390
Bmodel::next
Bmodel * next
Definition: rwmodel.h:120
Bimage::line_powerspectra
int line_powerspectra(fft_plan plan)
Calculates the 1D power spectrum of each line in an image.
Definition: Bimage_polar.cpp:814
error_show
int error_show(string message, string file, int line)
Displays the error with file and line reference.
Definition: utilities.cpp:719
Bimage::background
double background(long nn)
Definition: Bimage.h:549
Bimage::size
Vector3< long > size() const
Definition: Bimage.h:386
sb
int sb(0)
Bimage::transform
int transform(Vector3< double > scale, Vector3< double > origin, Vector3< double > translate, Matrix3 mat, int fill_type=0, double fill=0)
Transforms an image by translation, rotation, scaling and skewing, in place.
Definition: Bimage_transform.cpp:37
View
Definition: View.h:26
comp_type_list_kill
int comp_type_list_kill(Bcomptype *type)
Deallocates memory for a list of component types.
Definition: rwmodel.cpp:929
Bimage::find_shift
int find_shift(Bimage *pref, Bimage *pmask, double hires, double lores, double radius, double sigma, int refine_flag)
Calculates a cross-correlation map to find the shift for the pair of images.
Definition: Bimage_correlate.cpp:929
Bimage::image
Bsub_image * image
Definition: Bimage.h:202
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:111
Bmodel::fmap
Bstring fmap
Definition: rwmodel.h:125
Bimage::cartesian_to_cylindrical
Bimage * cartesian_to_cylindrical(long nannuli, long nphi, int flag=0)
Calculates an image with cylindrical coordinates.
Definition: Bimage_polar.cpp:592
planf
fft_plan planf
Definition: bico.cpp:24
Bimage::rotate_and_add
int rotate_and_add(Bimage *p, Vector3< double > origin, View view)
Rotates an image to a specified view and adds it to another image.
Definition: Bimage_transform.cpp:512
mg_orient.h
Library routines for single particle analysis.
Bimage::images
long images()
Definition: Bimage.h:504
Bmodel::comp
Bcomponent * comp
Definition: rwmodel.h:132
Matrix3
Definition: Matrix3.h:18
read_img
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
Definition: rwimg.cpp:77
Bsub_image::origin
void origin(double x, double y, double z)
Definition: Bimage.h:136
Bimage::multiply
void multiply(long j, Complex< double > cv)
Definition: Bimage.h:325
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
Bimage::project
Bimage * project(char axis, int flags=1)
Projects a 3D image to a 2D image down one of the three major axes.
Definition: Bimage_project.cpp:31
Bimage::add
void add(long j, double v)
Definition: Bimage.h:321
Bstring::str
string str()
Definition: Bstring.h:42
Vector3::normalize
double normalize()
Definition: Vector3.h:238
Bimage::sizeY
void sizeY(long ny)
Definition: Bimage.h:391
fft_destroy_plan
int fft_destroy_plan(fft_plan plan)
Deallocates a plan for fast Fourier transforms.
Definition: fft.cpp:87
Bimage::fft
int fft()
Definition: Bimage.h:830
Bmodel::id
Bstring id
Definition: rwmodel.h:121
model_extract_component_densities
Bimage * model_extract_component_densities(Bmodel *model, Vector3< long > size, Vector3< double > origin)
Extracts all densities associated with components in a model.
Definition: model_extract_build.cpp:836
Bimage
General image parameter class.
Definition: Bimage.h:177
model_from_images
Bmodel * model_from_images(Bimage *plist)
Creates one or more models from 3D images.
Definition: model_map.cpp:28
Unknown_Type
@ Unknown_Type
Definition: utilities.h:151
Bmodel::sel
int sel
Definition: rwmodel.h:129
Bstring::alnum
Bstring alnum()
Definition: Bstring.cpp:357
verbose
int verbose
Bmodel
Definition: rwmodel.h:119
Bimage::center_wrap
int center_wrap()
Centers an image with wrapping.
Definition: Bimage_transform.cpp:708
Bimage::file_name
void file_name(string s)
Definition: Bimage.h:245
M_PI
#define M_PI
Definition: utilities.h:63
utilities.h
Header file for general utilities.
tab
ostream & tab(ostream &out)
Definition: utilities.cpp:22
RGBA< float >
Bimage::interpolate
double interpolate(long cc, double xx, double yy=0, double zz=0, long nn=0, double fill=0) const
Interpolates using a given location.
Definition: Bimage.cpp:1414
fft_setup_plan
fft_plan fft_setup_plan(long x, long y, long z, fft_direction dir, int opt)
Sets up a plan for fast Fourier transforms.
Definition: fft.cpp:31
Bmodel::img_num
int img_num
Definition: rwmodel.h:127
Bstring::length
long length() const
Definition: Bstring.cpp:263
Bcomponent::fom
float fom
Definition: rwmodel.h:65
Bimage::origin
void origin(double ox, double oy, double oz)
Definition: Bimage.h:570
Bcomponent::type
Bcomptype * type
Definition: rwmodel.h:54
Bcomptype::id
Bstring id
Definition: rwmodel.h:27
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1765
model
Bmodel * model
Definition: bshow.cpp:34
Bimage::index
long index(long nx, long ny) const
Definition: Bimage.h:396
Vector3::volume
double volume()
Definition: Vector3.h:237
rwimg.h
Header file for 2D and 3D image I/O.
Bimage::polar_transform
Bimage * polar_transform(long nangles, long ann_min, long ann_max, long dann, long zmin, long zmax, long zinc)
Calculates an image with cylindrical coordinates by integration.
Definition: Bimage_polar.cpp:699
model_shell_power_spectrum
Bimage * model_shell_power_spectrum(Bmodel *model, Vector3< long > size, Vector3< double > origin, int ft_size, int ann_min, int ann_max, double hires, double lores)
Calculates a radial profile from a shell model.
Definition: model_map.cpp:344
Bimage::extract
Bimage * extract(long nn)
Extracts one sub-image into new image structure.
Definition: Bimage_extract.cpp:21
fft_plan
fftwf_plan fft_plan
Definition: fft.h:20
Bimage::catenate
void catenate(long m, Bimage **p)
Catenates an array of images of the same size into a multi-image structure.
Definition: Bimage_combine.cpp:52
model_add
Bmodel * model_add(Bmodel **model, Bstring &id)
Adds a model to a linked list.
Definition: rwmodel.cpp:181
Bimage::invert
void invert()
Inverts the data in the image.
Definition: Bimage.cpp:3111
model_transform.h
Library routines used for model transformation.
model_add_type_by_id
Bcomptype * model_add_type_by_id(Bmodel *model, Bstring &id)
Add a type to a model if the identifier does not exist already.
Definition: rwmodel.cpp:414
Bstring::base
Bstring base()
Definition: Bstring.cpp:516
FILL_BACKGROUND
#define FILL_BACKGROUND
Definition: utilities.h:178
Vector3::min
Type min()
Definition: Vector3.h:169
Bimage::pad
int pad(long sz, int fill_type=0, double fill=0)
Pads an image to a new size with a given fill value.
Definition: Bimage_resize.cpp:347
img_combine.h
Header file for combining two images in various ways.
planb
fft_plan planb
Definition: bico.cpp:24
Bimage::sampling
void sampling(long nn, Vector3< double > u)
Definition: Bimage.h:514
img_from_model
Bimage * img_from_model(Bmodel *model, Vector3< double > ori, Vector3< long > size, Vector3< double > sam, double sigma)
Calculates a map from model component coordinates.
Definition: model_map.cpp:59
Bmodel::type
Bcomptype * type
Definition: rwmodel.h:131
Bcomptype::next
Bcomptype * next
Definition: rwmodel.h:26
Bcomponent::radius
float radius
Definition: rwmodel.h:62
Vector3::length
double length()
Definition: Vector3.h:222
model_shell_radial_profile
int model_shell_radial_profile(Bmodel *model)
Calculates a radial profile from a shell model.
Definition: model_map.cpp:240
Bimage::edge
int edge(int type, Vector3< long > rect, Vector3< double > start, double width, int fill_type=0, double fill=0)
Smooths the image edge with a soft rectangular function.
Definition: Bimage_edit.cpp:321
model_shift
long model_shift(Bmodel *model, Vector3< double > shift)
Shifts a model.
Definition: model_transform.cpp:43
model_component_symmetry
int model_component_symmetry(Bmodel *model, long nangles, long ann_min, long ann_max, long ann_width, long zmin, long zmax, long zinc, long minorder, long maxorder)
Determines the cyclic symmetry of components.
Definition: model_map.cpp:618
Float
@ Float
Definition: utilities.h:161
VERB_LABEL
#define VERB_LABEL
Definition: utilities.h:110
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:713
findNextPowerOf
int findNextPowerOf(int startNumber, int powerOf)
Finds the next greatest number that is a power of a given number.
Definition: utilities.cpp:397
comp_set_fom_sym
int comp_set_fom_sym(Bcomponent *comp, Bimage *p, long minorder, long maxorder)
Definition: model_map.cpp:532
Bimage::correlate_annuli
double correlate_annuli(Bimage *polref, int ann_min, int ann_max, double ang_min, double ang_max, fft_plan planf, fft_plan planb, double &cc_max)
Correlate annuli of a polar image.
Definition: Bimage_align.cpp:592
img_catenate
Bimage * img_catenate(Bstring *file_list, Bstring &rawstring, DataType newdatatype, Vector3< long > nusize, int setZslices=0, int fill_type=0, double fill=0, double newavg=0, double newstd=0)
Catenates a list of images into a multi-image structure.
Definition: img_combine.cpp:163
TWOPI
#define TWOPI
Definition: utilities.h:72
Bcomponent::sel
int sel
Definition: rwmodel.h:66
Vector3::max
Type max()
Definition: Vector3.h:175