Xmipp  v3.23.11-Nereus
angular_projection_matching.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Sjors Scheres scheres@cnb.csic.es (2004)
4  * Authors: Roberto Marabini roberto@cnb.csic.es (2012)
5  *
6  * Unidad de Bioinformatica del Centro Nacional de Biotecnologia , CSIC
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21  * 02111-1307 USA
22  *
23  * All comments concerning this program package may be sent to the
24  * e-mail address 'xmipp@cnb.csic.es'
25  ***************************************************************************/
26 
28 #include "core/xmipp_image.h"
29 #include "core/metadata_vec.h"
31 #include "data/ctf.h"
32 #include "data/filters.h"
33 
34 
35 //#define DEBUG
36 //#define TIMING
37 
38 // For blocking of threads
39 pthread_mutex_t update_refs_in_memory_mutex = PTHREAD_MUTEX_INITIALIZER;
40 pthread_mutex_t debug_mutex = PTHREAD_MUTEX_INITIALIZER;
41 
42 
43 // Read arguments ==========================================================
45 
46 {
47  fn_exp = getParam("-i");
48  fn_out = getParam("-o");
49  fn_ref = getParam("--ref");
50 
51  // Additional commands
52  pad=XMIPP_MAX(1.,getDoubleParam("--pad"));
53  Ri=getIntParam("--Ri");
54  Ro=getIntParam("--Ro");
55  search5d_shift = getIntParam("--search5d_shift");
56  search5d_step = getIntParam("--search5d_step");
57  max_shift = getDoubleParam("--max_shift");
58  numOrientations = getIntParam("--number_orientations");
59 
60  avail_memory = getDoubleParam("--mem");
61  if (checkParam("--ctf"))
62  fn_ctf = getParam("--ctf");
63  phase_flipped = checkParam("--phase_flipped");
64  threads = getIntParam("--thr");
65 
66  do_scale = checkParam("--scale");
67  if (checkParam("--append"))
69  else
71 
72  if(do_scale)
73  {
74  scale_step = getDoubleParam("--scale",0);
75  //Scale Step can't be 0
76  if (scale_step == 0)
77  scale_step = 1;
78  scale_nsteps = getDoubleParam("--scale",1);
79  }
80 
81 }
82 
84 {
85  addUsageLine("Perform a discrete angular assignment using projection matching in real space.");
86  addUsageLine("This program is relatively fast, using polar coordinates for the in-plane ");
87  addUsageLine("angular searches and the 5-dimensional search of rotation angles and origin ");
88  addUsageLine("offsets is broken in two: first the angles are search in a 3D-search; then, ");
89  addUsageLine("for the optimal orientation the origin offsets are searched (2D).");
90  addUsageLine(" ");
91  addUsageLine("The output of the program consists of a document file with all assigned angles");
92  addUsageLine("and rotations. This file also contains a column for the maximum cross-correlation ");
93  addUsageLine("coefficient. Note that the program does not alter the image headers. ");
94  addUsageLine("The recommended use of this program is within the python script of the ");
95  addUsageLine("xmipp_protocol_projmatch.py");
96  addSeeAlsoLine("angular_discrete_assign, angular_continuous_assign, angular_project_library");
97  addExampleLine("Example of use: Sample at 2 pixel step size for 5D shift search",false);
98  addExampleLine("xmipp_angular_projection_matching -i experimental.doc -o assigned_angles.doc --ref reference.stk --search5d_step 2");
99  addParamsLine(" -i <doc_file> : Docfile with input images");
100  addParamsLine(" -o <output_filename> : Output filename");
101  addParamsLine(" -r <stackFile> : Reference projections");
102  addParamsLine(" alias --ref;");
103  addParamsLine(" [--search5d_shift <s5dshift=0>]: Search range (in +/- pix) for 5D shift search");
104  addParamsLine(" [--search5d_step <s5dstep=2>] : Step size for 5D shift search (in pix)");
105  addParamsLine(" [--Ri <ri=1>] : Inner radius to limit rotational search");
106  addParamsLine(" [--Ro <ro=-1>] : Outer radius to limit rotational search");
107  addParamsLine(" : ro = -1 -> dim/2-1");
108  addParamsLine(" [-s <step=1> <n_steps=3>] : scale step factor (1 means 0.01 in/de-crements) and number of steps around 1.");
109  addParamsLine(" : with default values: 1 0.01 | 0.02 | 0.03");
110  addParamsLine(" alias --scale;");
111  addParamsLine("==+Extra parameters==");
112  addParamsLine(" [--mem <mem=1>] : Available memory for reference library (Gb)");
113  addParamsLine(" [--max_shift <max_shift=-1>] : Max. change in origin offset (+/- pixels; neg= no limit)");
114  addParamsLine(" [--ctf <filename>] : CTF to apply to the reference projections, either a");
115  addParamsLine(" : CTF parameter file or a 2D image with the CTF amplitudes");
116  addParamsLine(" [--pad <pad=1>] : Padding factor (for CTF correction only)");
117  addParamsLine(" [--phase_flipped] : Use this if the experimental images have been phase flipped");
118  addParamsLine(" [--thr <threads=1>] : Number of concurrent threads");
119  addParamsLine(" [--number_orientations <numOrientations=1>] : Number of possible orientations for each experimental image");
120  addParamsLine(" [--append] : Append (versus overwrite) data to the output file");
121 }
122 
123 /* Show -------------------------------------------------------------------- */
125 {
126  if (!verbose)
127  return;
128 
129  std::cout
130  << " Input images : "<< fn_exp << std::endl
131  << " Output file : "<< fn_out << std::endl
132  ;
133  if (Ri>0)
134  std::cout << " Inner radius rot-search : " << Ri<< std::endl;
135  if (Ro>0)
136  std::cout << " Outer radius rot-search : " << Ro << std::endl;
138  {
139  std::cout << " Number of references : " << total_nr_refs << std::endl
140  << " Nr. refs in memory : " << max_nr_refs_in_memory << " (using " << avail_memory <<" Gb)" << std::endl
141  ;
142  }
143  else
144  {
145  std::cout << " Number of references : " << total_nr_refs << " (all stored in memory)" << std::endl;
146  }
147  std::cout << " Max. allowed shift : +/- " <<max_shift<<" pixels"<<std::endl;
148  if (search5d_shift > 0)
149  {
150  std::cout << " 5D-search shift range : "<<search5d_shift<<" pixels (sampled "<<nr_trans<<" times)"<<std::endl;
151  }
152  if (fn_ctf!="")
153  {
154  if (!fn_ctf.isMetaData())
155  {
156  std::cout << " CTF image : " <<fn_ctf<<std::endl;
157  if (pad > 1.)
158  std::cout << " Padding factor : "<< pad << std::endl;
159  }
160  else
161  {
162  std::cout << " CTF parameter file : " <<fn_ctf<<std::endl;
163  if (phase_flipped)
164  std::cout << " + Assuming images have been phase flipped " << std::endl;
165  else
166  std::cout << " + Assuming images have not been phase flipped " << std::endl;
167  }
168  }
169  if (threads>1)
170  {
171  std::cout << " -> Using "<<threads<<" parallel threads"<<std::endl;
172  }
173 
174  if (numOrientations != 1)
175  std::cout << " -> Using "<<numOrientations<<" possible orientations for each particle"<<std::endl;
176 
177 
178  std::cout << " ================================================================="<<std::endl;
179 }
180 
181 /* Run --------------------------------------------------------------------- */
183 {
184  produceSideInfo();
185 
186  show();
187 
189 
191 
192  destroyAndClean();
193  if (verbose)
194  std::cout << "done!"<<std::endl;
195 }
196 
198 {
199  delete [] fP_ref;
200  delete [] proj_ref;
201  delete [] fP_img;
202  delete [] fPm_img;
203  delete [] stddev_ref;
204  delete [] stddev_img;
205 
206 }
207 
208 // Side info stuff ===================================================================
210 {
211 
212  Image<double> img,empty;
213  Projection proj;
214  MetaDataVec DF;
215  MetaDataVec SFr,emptySF;
216  SymList SL;
217  FileName fn_img;
219  MultidimArray<double> dataline(3);
220  Polar<double> P;
222 
223  // Read Selfile and get dimensions
224  MetaDataDb MetaDataLeft;
225  MetaDataDb MetaDataRight;
226  String blockName = "all_exp_images";
227 
228  FileName inputFn = fn_exp.removeBlockName();
229  if (existsBlockInMetaDataFile(inputFn, blockName))
230  {
231  FileName rightFn;
232  rightFn.compose(blockName, inputFn);
233  MetaDataRight.read(rightFn);
234  MetaDataLeft.read(fn_exp);
235  //Join with angles and shifhts
236  DFexp.join1(MetaDataLeft, MetaDataRight, MDL_IMAGE,LEFT);
237  }
238  else
239  DFexp.read(fn_exp);
240  //DFexp.removeDisabled();
241 
242 
244  // Thread barrier
246 
247  // Read one image to get dim
249  img.read(fn_img);
250  dim = XSIZE(img());
251 
252  // Check that the reference and the experimental images are of the same
253  // size
254  FileName fnt;
255  fnt.compose(FIRST_IMAGE, fn_ref);
256  Image<double> imgRef;
257  imgRef.read(fnt,HEADER);
258 
259  if (!imgRef().sameShape(img()))
261  "Check that the reference volume and the experimental images are of the same size");
262 
263  // Set padding dimension
264  paddim=ROUND(pad*dim);
265 
266  // Set max_shift
267  if (max_shift<0)
268  max_shift = dim/2;
269 
270  // Set ring defaults
271  if (Ri<1)
272  Ri=1;
273  if (Ro<0)
274  Ro=(dim/2)-1;
275 
276  // Calculate necessary memory per image
281  double memory_per_ref = 0.;
282  for (int i = 0; i < fP.getRingNo(); i++)
283  {
284  memory_per_ref += (double) fP.getSampleNo(i) * 2 * sizeof(double);
285  }
286  memory_per_ref += dim * dim * sizeof(double);
287  max_nr_imgs_in_memory = ROUND( 1024 * 1024 * 1024 * avail_memory / memory_per_ref);
288 
289  // Set up angular sampling
292 
293  //#define DEBUG
294 #ifdef DEBUG
295 
296  std::cerr << "XXXXmysampling.no_redundant_sampling_points_indexXXXXXX" <<std::endl;
297  for (std::vector<size_t>::iterator i =
300  ++i)
301  std::cerr << *i << " ";
302  std::cerr << std::endl;
303  std::cerr << "exit" <<std::endl;
304 #endif
305 #undef DEBUG
306 
308  for (size_t i = 0; i < mysampling.no_redundant_sampling_points_index.size(); i++)
310 
311  // Don't reserve more memory than necessary
312  max_nr_refs_in_memory = XMIPP_MIN(max_nr_imgs_in_memory, total_nr_refs);
313 
314  // Initialize pointers for reference retrieval
318  loop_forward_refs=true;
319 
320  // Initialize 5D search vectors
321  search5d_xoff.clear();
322  search5d_yoff.clear();
323  // Make sure origin is included
324  if(search5d_step == 0)
325  {
326  printf("***********************************************************\n");
327  printf("* ERROR: search step should be different from 0\n");
328  printf("* search step set to 1 \n");
329  printf("***********************************************************\n");
330 
331  search5d_step = 1;
332  }
334  nr_trans = 0;//number translations in 5D
335  for (int xoff = -myfinal; xoff <= myfinal; xoff+= search5d_step)
336  {
337  for (int yoff = -myfinal; yoff <= myfinal; yoff+= search5d_step)
338  {
339  // Only take a circle (not a square)
340  if ( xoff*xoff + yoff*yoff <= search5d_shift*search5d_shift)
341  {
342  search5d_xoff.push_back(xoff);
343  search5d_yoff.push_back(yoff);
344  nr_trans++;
345  }
346  }
347  }
348 
349  // Initialize all arrays
350  try
351  {
356 
357  stddev_ref = new double[max_nr_refs_in_memory];
358  stddev_img = new double[nr_trans];
359  }
360  catch (std::bad_alloc&)
361  {
362  REPORT_ERROR(ERR_MEM_BADREQUEST,"Error allocating memory in produceSideInfo");
363  }
364 
365  // CTF stuff
366  if (fn_ctf != "")
367  {
368  if (!fn_ctf.isMetaData())
369  {
370  Image<double> img;
371  img.read(fn_ctf);
372  Mctf=img();
373  if (XSIZE(Mctf) != paddim)
374  {
375  std::cerr<<"image size= "<<dim<<" padding factor= "<<pad<<" padded image size= "<<paddim<<" Wiener filter size= "<<XSIZE(Mctf)<<std::endl;
377  "Incompatible padding factor for this CTF filter");
378  }
379  }
380  else
381  {
382  CTFDescription ctf;
384  ctf.read(fn_ctf);
385  if (ABS(ctf.DeltafV - ctf.DeltafU) >1.)
386  {
388  "ERROR!! Only non-astigmatic CTFs are allowed!");
389  }
390  ctf.enable_CTF = true;
391  ctf.produceSideInfo();
392  ctf.generateCTF(paddim, paddim, ctfmask);
395  {
396  if (phase_flipped)
397  dAij(Mctf, i, j) = fabs(dAij(ctfmask, i, j).real());
398  else
399  dAij(Mctf, i, j) = dAij(ctfmask, i, j).real();
400  }
401  }
402  }
403 
404  //Store the id's of each experimental image from metadata
406 }
407 
409  Polar_fftw_plans &local_plans)
410 {
411  FileName fnt;
412  Image<double> img;
413  double mean,stddev;
415  Polar<double> P;
417  FourierTransformer local_transformer;
418 
419  // Image was not stored yet: read it from disc and store
420  // std::vector<size_t>::const_iterator found =
421  // std::find((mysampling.no_redundant_sampling_points_index).begin(),
422  // (mysampling.no_redundant_sampling_points_index).end(),
423  // (size_t)refno
424  // );
425  // //found = found - (mysampling.no_redundant_sampling_points_index).begin();
426  // _pointer = found - (mysampling.no_redundant_sampling_points_index).begin();
427  // if (found == (mysampling.no_redundant_sampling_points_index).end())
428  // REPORT_ERROR(ERR_VALUE_INCORRECT, "Wrong reference number");
429  // fnt.compose(_pointer + FIRST_IMAGE, fn_ref);
432  img.read(fnt, _DATA_ALL);
433  img().setXmippOrigin();
434 
435  //#define DEBUG
436 #ifdef DEBUG
437 
438  double rot_tmp,tilt_tmp,psi_tmp;
439  img.getEulerAngles(rot_tmp,tilt_tmp,psi_tmp);
440 
441  {
442  std::cerr << "index_found: " << convert_refno_to_stack_position[refno] << std::endl;
443  std::cerr << "refno: " << refno<<std::endl;
444  std::cerr << "reading image " << fnt << std::endl;
445  std::cerr << "rot_tmp,tilt_tmp,psi_tmp: " << rot_tmp<< " "<< tilt_tmp<< " "<<psi_tmp<< std::endl;
446  // std::cerr << "XXXXno_redundant_sampling_points_indexXXXXXX" <<std::endl;
447  // for (std::vector<size_t>::iterator i =
448  // mysampling.my_neighbors.begin();
449  // i != mysampling.my_neighbors.end();
450  // ++i)
451  // std::cerr << *i << " ";
452  std::cerr << std::endl;
453  }
454 #endif
455 #undef DEBUG
456  // Apply CTF
457  if (fn_ctf!="")
458  {
460  if (paddim > dim)
461  {
462  // pad real-space image
463  int x0 = FIRST_XMIPP_INDEX(paddim);
464  int xF = LAST_XMIPP_INDEX(paddim);
465  img().selfWindow(x0, x0, xF,xF);
466  }
467  local_transformer.FourierTransform(img(),Faux);
469  {
470  dAij(Faux,i,j) *= dAij(Mctf,i,j);
471  }
472  local_transformer.inverseFourierTransform(Faux,img());
473 
474  if (paddim > dim)
475  {
476  // de-pad real-space image
477  int x0 = FIRST_XMIPP_INDEX(dim);
478  int xF = LAST_XMIPP_INDEX(dim);
479  img().selfWindow(x0, x0, xF,xF);
480  }
481  }
482 
483  // Calculate FTs of polar rings and its stddev
486  P.computeAverageAndStddev(mean,stddev);
487  P -= mean;
488  fourierTransformRings(P,fP,local_plans,true);
489 
490  pthread_mutex_lock( &update_refs_in_memory_mutex );
491 
493  pointer_allrefs2refsinmem[refno] = counter;
494  if (pointer_refsinmem2allrefs[counter] != -1)
495  {
496  // This position was in use already
497  // Images will be overwritten, so reset the
498  // pointer_allrefs2refsinmem of the old images to -1
500  }
501  pointer_refsinmem2allrefs[counter] = refno;
502  fP_ref[counter] = fP;
503  stddev_ref[counter] = stddev;
504  proj_ref[counter] = img();
505  //#define DEBUG
506 #ifdef DEBUG
507 
508  std::cerr<<"counter= "<<counter<<"refno= "<<refno<<" stddev = "<<stddev;
509  std::cerr<<" refsinmem2allrefs= "<<pointer_refsinmem2allrefs[counter];
510  std::cerr<<" allrefs2refsinmem= "<<pointer_allrefs2refsinmem[pointer_refsinmem2allrefs[counter]] <<std::endl;
511  std::cerr << "pointer_allrefs2refsinmem" <<std::endl;
512  for (std::vector<int>::iterator i = pointer_allrefs2refsinmem.begin();
513  i != pointer_allrefs2refsinmem.end();
514  ++i)
515  std::cerr << *i << " ";
516  std::cerr <<std::endl;
517  std::cerr << "pointer_refsinmem2allrefs" <<std::endl;
518  for (std::vector<int>::iterator i = pointer_refsinmem2allrefs.begin();
519  i != pointer_refsinmem2allrefs.end();
520  ++i)
521  std::cerr << *i << " ";
522  std::cerr <<std::endl;
523 #endif
524 
526  pthread_mutex_unlock( &update_refs_in_memory_mutex );
527  // local_transformer.cleanup();
528 }
529 
530 void * threadRotationallyAlignOneImage( void * data )
531 {
532  auto * thread_data = (structThreadRotationallyAlignOneImage *) data;
533 
534  // Variables from above
535  size_t thread_id = thread_data->thread_id;
536  ProgAngularProjectionMatching *prm = thread_data->prm;
537  size_t thread_num = prm->threads;
538  MultidimArray<double> *img = thread_data->img;
539  size_t &this_image = thread_data->this_image;
540 
541 
542  int *opt_refno = thread_data->opt_refno;
543  double *opt_psi = thread_data->opt_psi;
544  bool *opt_flip = thread_data->opt_flip;
545  double *maxcorr = thread_data->maxcorr;
546 
547  // Local variables
549  MultidimArray<double> ang, corr;
550  MultidimArray<int> indxCorr;
551  size_t myinit, myfinal, myincr;
552  int refno;
553  bool done_once=false;
554  double mean, stddev;
555  Polar<double> P;
558  Polar_fftw_plans local_plans;
559  size_t imgno = this_image - FIRST_IMAGE;
560 
561 #ifdef TIMING
562 
563  TimeStamp t0,t1,t2;
564  time_config();
565  annotate_time(&t0);
566  annotate_time(&t2);
567 #endif
568 
570  // Precalculate polar transform of each translation
571  // This loop is also threaded
572  myinit = thread_id;
573  myincr = thread_num;
574  for (size_t itrans = myinit; itrans < prm->nr_trans; itrans+=myincr)
575  {
576  P.getPolarFromCartesianBSpline(Maux,prm->Ri,prm->Ro,3,
577  (double)prm->search5d_xoff[itrans],
578  (double)prm->search5d_yoff[itrans]);
579  P.computeAverageAndStddev(mean,stddev);
580  P -= mean; // for normalized cross-correlation coefficient
581  if (itrans == myinit)
582  P.calculateFftwPlans(local_plans);
583  fourierTransformRings(P,prm->fP_img[itrans],local_plans,false);
584  fourierTransformRings(P,prm->fPm_img[itrans],local_plans,true);
585  prm->stddev_img[itrans] = stddev;
586  done_once=true;
587  }
588  // If thread did not have to do any itrans, initialize fftw plans
589  if (!done_once)
590  {
591  P.getPolarFromCartesianBSpline(Maux,prm->Ri,prm->Ro);
592  P.calculateFftwPlans(local_plans);
593  }
594  // Prepare FFTW plan for rotational correlation
595  corr.resize(P.getSampleNoOuterRing());
596  rotAux.local_transformer.setReal(corr);
598 
599  // All threads have to wait until the itrans loop is done
600  barrier_wait(&(prm->thread_barrier));
601 
602 #ifdef TIMING
603 
604  float prepare_img = elapsed_time(t0);
605  float get_refs = 0.;
606  annotate_time(&t0);
607 #endif
608 
609  //pthread_mutex_lock( &debug_mutex );
610  // Switch the order of looping through the references every time.
611  // That way, in case max_nr_refs_in_memory<total_nr_refs
612  // the references read in memory for the previous image
613  // will still be there when processing the next image
614  // Every thread processes a part of the references
615  if (prm->loop_forward_refs)
616  {
617  myinit = 0;
618  myfinal = prm->mysampling.my_neighbors[imgno].size();
619  myincr = +1;
620  }
621  else
622  {
623  myinit = prm->mysampling.my_neighbors[imgno].size() - 1;
624  myfinal = -1;
625  myincr = -1;
626  }
627  // Loop over all relevant "neighbours" (i.e. directions within the search range)
628  //for (int i = myinit; i != myfinal; i+=myincr)
629  for (size_t i = myinit; i != myfinal; i += myincr)
630  {
631  if (i%thread_num == thread_id)
632  {
633 
634 #ifdef DEBUG_THREADS
635  pthread_mutex_lock( &debug_mutex );
636  std::cerr<<" thread_id= "<<thread_id<<" i= "<<i<<" "<<myinit<<" "<<myfinal<<" "<<myincr<<std::endl;
637  pthread_mutex_unlock( &debug_mutex );
638 #endif
639 
640 #ifdef TIMING
641 
642  annotate_time(&t1);
643 #endif
644  // Get pointer to the current reference image
645 #ifdef DEBUG
646 
647  if(prm->mysampling.my_neighbors[imgno][i]==58)
648  {
649  std::cerr << "XXXXpointer_allrefs2refsinmemXXXXXX" <<std::endl;
650  for (std::vector<int>::iterator i = prm->
652  i != prm->pointer_allrefs2refsinmem.end();
653  ++i)
654  std::cerr << *i << std::endl;
655  std::cerr << "XXXXpointer_refsinmem2allrefsXXXXXX" <<std::endl;
656  for (std::vector<int>
657  ::iterator i = prm->pointer_refsinmem2allrefs.begin();
658  i != prm->pointer_refsinmem2allrefs.end();
659  ++i)
660  std::cerr << *i << std::endl;
661  std::cerr <<std::endl;
662 
663  }
664 #endif
665 
666  refno = prm->pointer_allrefs2refsinmem[prm->mysampling.my_neighbors[imgno][i]];
667  if (refno == -1)
668  {
669  // Reference is not stored in memory (anymore): (re-)read from disc
670  prm->getCurrentReference(prm->mysampling.my_neighbors[imgno][i],local_plans);
671  refno = prm->pointer_allrefs2refsinmem[prm->mysampling.my_neighbors[imgno][i]];
672  }
673 
674 
675 #ifdef TIMING
676  get_refs += elapsed_time(t1);
677 #endif
678  //#define DEBUG
679 #ifdef DEBUG
680 
681  std::cerr << "imgno " << imgno <<std::endl;
682  std::cerr<<"Got refno= "<<refno
683  <<" pointer= "<<prm->mysampling.my_neighbors[imgno][i]<<std::endl;
684 #endif
685 
686  // Loop over all 5D-search translations
687  for (size_t itrans = 0; itrans < prm->nr_trans; itrans++)
688  {
689 #ifdef DEBUG
690 
691  std::cerr<< "prm->stddev_ref[refno], prm->stddev_img[itrans]: " <<
692  prm->stddev_ref[refno] << " " <<
693  prm->stddev_img[itrans];
694 #endif
695 
696  MultidimArray<double> allCorr, allAng;
697  allCorr.resizeNoCopy(XSIZE(corr)*2);
698  allAng.resizeNoCopy(XSIZE(corr)*2);
699 
700  // A. Check straight image
701  rotationalCorrelation(prm->fP_img[itrans],
702  prm->fP_ref[refno],
703  ang,rotAux);
704  corr /= prm->stddev_ref[refno] * prm->stddev_img[itrans]; // for normalized ccf
705 
706 
707  memcpy(&dAi(allCorr,0),&dAi(corr,0),XSIZE(corr)*sizeof(double));
708  memcpy(&dAi(allAng,0),&dAi(ang,0),XSIZE(ang)*sizeof(double));
709 
710  rotationalCorrelation(prm->fPm_img[itrans],prm->fP_ref[refno],ang,rotAux);
711  corr /= prm->stddev_ref[refno] * prm->stddev_img[itrans]; // for normalized ccf
712  memcpy(&dAi(allCorr,XSIZE(corr)),&dAi(corr,0),XSIZE(corr)*sizeof(double));
713  memcpy(&dAi(allAng,XSIZE(corr)),&dAi(ang,0),XSIZE(corr)*sizeof(double));
714 
715  size_t nIter = XMIPP_MIN(thread_data->numOrientations,corr.getSize());
716  double bestLastCorr = 99e99;
717  for (size_t n = 0; n < nIter; n++)
718  {
719  for (size_t k = 0; k < XSIZE(allCorr); k++)
720  {
721  if ( (DIRECT_A1D_ELEM(allCorr,k)> maxcorr[n]) && (DIRECT_A1D_ELEM(allCorr,k)<bestLastCorr))
722  {
723  maxcorr[n] = DIRECT_A1D_ELEM(allCorr,k);
724  opt_psi[n] = DIRECT_A1D_ELEM(allAng,k);
725  //FIXME not sure about FIRST_IMAGE
726  opt_refno[n] = prm->mysampling.my_neighbors[imgno][i];/*+FIRST_IMAGE;*/
727  if ( k >= XSIZE(corr))
728  opt_flip[n] = true;
729  else
730  opt_flip[n] = false;
731  }
732  }
733 
734  bestLastCorr = maxcorr[n];
735  }
736 
737 
738 #ifdef DEBUG
739  std::cerr<<"mirror: corr "<<maxcorr;
740  if (opt_flip)
741  std::cerr<<"**";
742  std::cerr<<std::endl;
743 #endif
744 #undef DEBUG
745 
746  }
747  //#define DEBUG
748 #ifdef DEBUG
749  std::cerr << "DEBUG_ROB, imgno:" << imgno << std::endl;
750  std::cerr << "DEBUG_ROB, i:" << i << std::endl;
751  std::cerr << "DEBUG_ROB, prm->mysampling.my_neighbors[imgno][i]:" << prm->mysampling.my_neighbors[imgno][i] << std::endl;
752  std::cerr<<"straight: corr "<<maxcorr<<std::endl;
753 #endif
754 #undef DEBUG
755 
756  }
757  }
758 
759 
760 #ifdef TIMING
761  float all_rot_align = elapsed_time(t0);
762  float total_rot = elapsed_time(t2);
763  std::cerr<<" rotal%% "<<total_rot
764  <<" => prep: "<<prepare_img
765  <<" all_refs: "<<all_rot_align
766  <<" (of which "<<get_refs
767  <<" to get "<< prm->mysampling.my_neighbors[imgno].size()
768  <<" refs for imgno "<<imgno<<" )"
769  <<std::endl;
770 #endif
771  //pthread_mutex_unlock( &debug_mutex );
772  //std::cerr << "DEBUG_JM: threadRotationallyAlignOneImage END" <<std::endl;
773  return nullptr;
774 }
775 
777  const int &opt_refno,
778  const double &opt_psi,
779  const bool &opt_flip,
780  double &opt_xoff,
781  double &opt_yoff,
782  double &maxcorr)
783 {
784 
785  MultidimArray<double> Mtrans,Mimg,Mref;
786  int refno;
787  Mtrans.setXmippOrigin();
788  Mimg.setXmippOrigin();
789  Mref.setXmippOrigin();
790 #ifdef TIMING
791 
792  TimeStamp t0,t1,t2;
793  time_config();
794  annotate_time(&t0);
795 #endif
796 
797 #ifdef DEBUG
798 
799  std::cerr<<"start trans: opt_refno= "<<opt_refno<<" pointer= "<<pointer_allrefs2refsinmem[opt_refno]<<" opt_psi= "<<opt_psi<<"opt_flip= "<<opt_flip<<std::endl;
800 #endif
801 
802  // Get pointer to the correct reference image in memory
803  refno = pointer_allrefs2refsinmem[opt_refno];
804  if (refno == -1)
805  {
806  // Reference is not stored in memory (anymore): (re-)read from disc
808  refno = pointer_allrefs2refsinmem[opt_refno];
809  }
810 
811  // Rotate stored reference projection by phi degrees
812  rotate(xmipp_transformation::BSPLINE3,Mref,proj_ref[refno],opt_psi,xmipp_transformation::DONT_WRAP);
813  //rotate(BSPLINE3,Mref,proj_ref[refno],-opt_psi,DONT_WRAP);
814 
815 #ifdef DEBUG
816 
817  std::cerr<<"rotated ref "<<std::endl;
818 #endif
819 
820  if (opt_flip)
821  {
822  // Flip experimental image
823  Matrix2D<double> A(3,3);
824  A.initIdentity();
825  MAT_ELEM(A,0, 0) = -1.;
826  //MAT_ELEM(A,0, 1) *= -1.;
827  applyGeometry(xmipp_transformation::LINEAR, Mimg, img, A, xmipp_transformation::IS_INV, xmipp_transformation::DONT_WRAP);
828  }
829  else
830  Mimg = img;
831 
832 
833  // Perform the actual search for the optimal shift
834  if (max_shift>0)
835  {
836  CorrelationAux aux;
837  bestShift(Mref,Mimg,opt_xoff,opt_yoff,aux);
838  }
839  else
840  opt_xoff = opt_yoff = 0.;
841  if (opt_xoff * opt_xoff + opt_yoff * opt_yoff > max_shift * max_shift)
842  opt_xoff = opt_yoff = 0.;
843  //#define DEBUG
844 #ifdef DEBUG
845 
846  std::cerr<<"optimal shift "<<opt_xoff<<" "<<opt_yoff<<std::endl;
847 #endif
848 
849  // Calculate standard cross-correlation coefficient
850  translate(xmipp_transformation::LINEAR,Mtrans,Mimg,vectorR2(opt_xoff,opt_yoff),true);
851  maxcorr = correlationIndex(Mref,Mtrans);
852 
853 #ifdef DEBUG
854 
855  std::cerr<<"optimal shift corr "<<maxcorr<<std::endl;
856 #endif
857 #undef DEBUG
858  // Correct X-shift for mirrored images
859  if (opt_flip)
860  opt_xoff *= -1.;
861 
862 #ifdef TIMING
863 
864  float total_trans = elapsed_time(t0);
865  std::cerr<<" trans%% "<<total_trans <<std::endl;
866 #endif
867 
868 }
869 
870 
872  const int &opt_refno,
873  const double &opt_psi,
874  const bool &opt_flip,
875  const double &opt_xoff,
876  const double &opt_yoff,
877  const double &old_scale,
878  double &opt_scale,
879  double &maxcorr)
880 {
881  MultidimArray<double> Mscale,Mtrans,Mref,Mimg;
882  int refno;
883 
884  Mscale.setXmippOrigin();
885  Mtrans.setXmippOrigin();
886  Mref.setXmippOrigin();
887  Mimg.setXmippOrigin();
888 
889 #ifdef TIMING
890 
891  TimeStamp t0,t1,t2;
892  time_config();
893  annotate_time(&t0);
894 #endif
895 
896  // ROTATE + SHIFT
897  // Transformation matrix
898  Matrix2D<double> A(3,3);
899  A.initIdentity();
900  double ang, cosine, sine;
901  ang = DEG2RAD(opt_psi);
902  cosine = cos(ang);
903  sine = sin(ang);
904 
905  // Rotation
906  MAT_ELEM(A,0, 0) = cosine;
907  MAT_ELEM(A,0, 1) = sine;
908  MAT_ELEM(A,1, 0) = -sine;
909  MAT_ELEM(A,1, 1) = cosine;
910 
911  // Shift
912  MAT_ELEM(A,0, 2) = -opt_xoff;
913  MAT_ELEM(A,1, 2) = -opt_yoff;
914 
916  // Multiply shifts by old_scale
917 
918  if (opt_flip)
919  {
920  MAT_ELEM(A,0, 2) = opt_xoff;
921  MAT_ELEM(A,0, 0) *= -1.;
922  MAT_ELEM(A,0, 1) *= -1.;
923  }
924 
925  // Get pointer to the correct reference image in memory
926  refno = pointer_allrefs2refsinmem[opt_refno];
927  if (refno == -1)
928  {
929  // Reference is not stored in memory (anymore): (re-)read from disc
931  refno = pointer_allrefs2refsinmem[opt_refno];
932  }
933  applyGeometry(xmipp_transformation::LINEAR, Mref, proj_ref[refno], A, xmipp_transformation::IS_NOT_INV, xmipp_transformation::DONT_WRAP);
934 
935 
936  Mtrans = img;
937 
938  // Scale search
939  double corr;
940  opt_scale = 1;
941  //maxcorr = -999;
942 
943  // 1 (0.01 * scale_step * scale_nsteps)
944  double scale = 1 - 0.01 * scale_step * scale_nsteps;
945  while(scale <= 1 + 0.01 * scale_step * scale_nsteps)
946  {
947  if(scale == 1.)
948  continue;
949 
950  // apply current scale
951  A.initIdentity();
952  A /= scale;
953  applyGeometry(xmipp_transformation::LINEAR, Mscale, Mtrans, A, xmipp_transformation::IS_INV, xmipp_transformation::DONT_WRAP);
954 
955  //Image spread correction (if scale != 1) for scale search
956  Mscale = Mscale / (scale * scale * old_scale * old_scale);
957 
958  corr = correlationIndex(Mref,Mscale);
959 
960  // best scale update
961  if(corr > maxcorr)
962  {
963  opt_scale = scale;
964  maxcorr = corr;
965  }
966  scale += 0.01 * scale_step;
967  }
968 
969 #ifdef TIMING
970 
971  float total_trans = elapsed_time(t0);
972  std::cerr<<" trans%% "<<total_trans <<std::endl;
973 #endif
974 
975 }
976 
978 {
979  //Init progress bar
980  size_t total_number_of_images = DFexp.size();
981  if (verbose)
982  {
983  progress_bar_step = XMIPP_MAX(1, total_number_of_images / 80);
984  init_progress_bar(total_number_of_images);
985  }
987  if (verbose)
988  progress_bar(total_number_of_images);
989 }
990 
991 void ProgAngularProjectionMatching::processSomeImages(const std::vector<size_t> &imagesToProcess)
992 {
993  Image<double> img;
994  //double
995  //opt_rot=0.,
996  //opt_tilt=0.;
997  //opt_psi=0.,
998  //opt_xoff=0.,
999  //opt_yoff=0.,
1000  //opt_scale=0.;
1001  //maxcorr=-99.e99;
1002 
1003  auto opt_flip = std::vector<bool> (numOrientations, false);
1004  auto opt_refno = std::vector<int> (numOrientations, 0);
1005  auto opt_psi = std::vector<double> (numOrientations, 0);
1006  auto maxcorr = std::vector<double> (numOrientations, 0);
1007  auto opt_xoff = std::vector<double> (numOrientations, 0);
1008  auto opt_yoff = std::vector<double> (numOrientations, 0);
1009  auto opt_scale = std::vector<double> (numOrientations, 0);
1010  auto opt_rot = std::vector<double> (numOrientations, 0);
1011  auto opt_tilt = std::vector<double> (numOrientations, 0);
1012 
1013  size_t itemId=0;
1014  size_t nr_images = imagesToProcess.size();
1015  size_t idNew, imgid;
1016  FileName fn;
1017 
1018  // Call threads to calculate the rotational alignment of each image in the selfile
1019  auto * th_ids = (pthread_t *)malloc( threads * sizeof( pthread_t));
1020 
1021  // Allocate threads.
1022  auto * threads_d = (structThreadRotationallyAlignOneImage *)
1023  malloc ( threads * sizeof( structThreadRotationallyAlignOneImage ) );
1024 
1025  // Allocate threads vectors.
1026  for( int c = 0 ; c < threads ; c++ )
1027  {
1028  threads_d[c].opt_refno = (int *)malloc (sizeof(int)*numOrientations);
1029  threads_d[c].opt_psi = (double *)malloc (sizeof(double)*numOrientations);
1030  threads_d[c].opt_flip = (bool *) malloc (sizeof(bool)*numOrientations);
1031  threads_d[c].maxcorr = (double *)malloc (sizeof(double)*numOrientations);
1032  threads_d[c].numOrientations = numOrientations;
1033  }
1034 
1035  for (size_t imgno = 0; imgno < nr_images; imgno++)
1036  {
1037  imgid = imagesToProcess[imgno];
1038 
1039  FileName pp;
1040  DFexp.getValue(MDL_IMAGE,pp, imgid);
1041 
1042  getCurrentImage(imgid, img);
1043  for( int c = 0 ; c < threads ; c++ )
1044  {
1045  threads_d[c].thread_id = c;
1046  threads_d[c].prm = this;
1047  threads_d[c].img = &img();
1048  threads_d[c].this_image = imgid;
1049  for (size_t i=0; i<numOrientations ;i++)
1050  {
1051  threads_d[c].maxcorr[i] = -99.e99;
1052  threads_d[c].opt_refno[i] = -1;
1053  opt_scale[i] = 1;
1054  opt_refno[i] = -1;
1055  }
1056  pthread_create( (th_ids+c), nullptr, threadRotationallyAlignOneImage, (void *)(threads_d+c) );
1057  }
1058  // Wait for threads to finish
1059  for( int c = 0 ; c < threads ; c++ )
1060  pthread_join(*(th_ids+c),nullptr);
1061 
1062  //Get optimal refno, psi, flip and maxcorr
1063  auto * indexThreads = new int[threads](); // init to zero
1064  size_t bestThreadCorr = 0;
1065  double tempCorr;
1066  size_t counterValidCorrs = 0;
1067  bool validCorr = false;
1068  for( int n = 0 ; n < numOrientations ; n++ )
1069  {
1070  tempCorr = -99.e99;
1071  validCorr = false;
1072  for( int c = 0 ; c < threads ; c++ )
1073  {
1074  if (threads_d[c].maxcorr[indexThreads[c]] > tempCorr)
1075  {
1076  if (not validCorr)
1077  {
1078  counterValidCorrs++;
1079  validCorr = true;
1080  }
1081 
1082  bestThreadCorr = c;
1083  tempCorr = threads_d[c].maxcorr[indexThreads[c]];
1084  }
1085 
1086  }
1087 
1088  if (not validCorr)
1089  break;
1090 
1091  opt_refno[n] = threads_d[bestThreadCorr].opt_refno[indexThreads[bestThreadCorr]];
1092  opt_psi[n] = threads_d[bestThreadCorr].opt_psi[indexThreads[bestThreadCorr]];
1093  opt_flip[n] = threads_d[bestThreadCorr].opt_flip[indexThreads[bestThreadCorr]];
1094  maxcorr[n] = threads_d[bestThreadCorr].maxcorr[indexThreads[bestThreadCorr]];
1095  indexThreads[bestThreadCorr]++;
1096 
1097 
1098  if (opt_refno[n]>=0)
1099  {
1102  }
1103  else
1104  {
1105  opt_rot[n]=0;
1106  opt_tilt[n]=0;
1107  }
1108  }
1109 
1110  delete[] indexThreads;
1111  // Flip order to loop through references
1113 
1114  //#define DEBUG
1115 #ifdef DEBUG
1116  std::cerr << "DEBUG_ROB, img.name():" << img.name() << std::endl;
1117 #endif
1118 #undef DEBUG
1119 
1120  for(int n=0; n < counterValidCorrs; n++)
1121  {
1122  //std::cout << " " << std::endl;
1123  //std::cout << maxcorr[n] << std::endl;
1125  opt_refno[n],
1126  opt_psi[n],
1127  opt_flip[n],
1128  opt_xoff[n],
1129  opt_yoff[n],
1130  maxcorr[n]);
1131 
1132  //std::cout << maxcorr[n] << std::endl;
1133  if(do_scale && scale_nsteps > 0)
1134  {
1135  // Compute a better scale (scale_min -> scale_max)
1136  scaleAlignOneImage(img(), opt_refno[n], opt_psi[n], opt_flip[n], opt_xoff[n], opt_yoff[n], img.scale(), opt_scale[n], maxcorr[n]);
1137  }
1138 
1139  //Add the previously applied scale to the newly found one
1140  opt_scale[n] *= img.scale();
1142  // Divide opt_shifts by old_scale
1143 
1144  // Add previously applied translation to the newly found one
1145  opt_xoff[n] += img.Xoff();
1146  opt_yoff[n] += img.Yoff();
1147 
1148  // Output
1149  DFexp.getValue(MDL_IMAGE, fn, imgid);
1150  DFexp.getValue(MDL_ITEM_ID, itemId, imgid);
1151 
1152  idNew = DFo.addObject();
1153  DFo.setValue(MDL_ITEM_ID,itemId,idNew);
1154  DFo.setValue(MDL_IMAGE, fn,idNew);
1155  DFo.setValue(MDL_ANGLE_ROT, opt_rot[n],idNew);
1156  DFo.setValue(MDL_ANGLE_TILT,opt_tilt[n],idNew);
1157  DFo.setValue(MDL_ANGLE_PSI, opt_psi[n],idNew);
1158 
1159  //opt_xoff=0;
1160  DFo.setValue(MDL_SHIFT_X, opt_xoff[n],idNew);
1161  DFo.setValue(MDL_SHIFT_Y, opt_yoff[n],idNew);
1162  DFo.setValue(MDL_REF, opt_refno[n] /*+ FIRST_IMAGE*/,idNew);
1163  DFo.setValue(MDL_FLIP, opt_flip[n],idNew);
1164  DFo.setValue(MDL_SCALE, opt_scale[n],idNew);
1165  DFo.setValue(MDL_MAXCC, maxcorr[n],idNew);
1166 
1167  }
1168 
1169  /* FIXME ROB */
1170  //opt_psi += img.psi();
1171  /* */
1172 
1173  //opt_scale=1.0;
1174 
1175  if (verbose && imgno % progress_bar_step == 0)
1176  progress_bar(imgno);
1177  //#endif
1178  //DFo.write("/dev/stderr");
1179  }//loop over images
1180  free(th_ids);
1181 
1182  for( int c = 0 ; c < threads ; c++ )
1183  {
1184  free(threads_d[c].opt_refno);
1185  free(threads_d[c].opt_psi);
1186  free(threads_d[c].opt_flip);
1187  free(threads_d[c].maxcorr);
1188  }
1189 
1190  free(threads_d);
1191 
1192 }//function processSomeImages
1193 
1195 {
1196  FileName fn_img;
1197  Matrix2D<double> A;
1198  //init A just in case
1199  A.initIdentity(3);
1200 
1201  // jump to line imgno+1 in DFexp, get data and filename
1202  DFexp.getValue(MDL_IMAGE,fn_img, imgid);
1203 
1204  // Read actual image
1205  img.read(fn_img);
1206  img().setXmippOrigin();
1207 
1208  // Store translation in header and apply it to the actual image
1209  //No need to get initial angles since those came with the reference projection
1210  double shiftX=0., shiftY=0.;
1211  DFexp.getValue(MDL_SHIFT_X,shiftX, imgid);
1212  DFexp.getValue(MDL_SHIFT_Y,shiftY, imgid);
1213 
1214  img.setShifts(shiftX,shiftY);
1215 
1216  //FIXME ROB
1217  //img.setEulerAngles(0.,0.,psi);
1218  img.setEulerAngles(0.,0.,0);
1219  //
1220  img.setFlip(0.);
1221 
1222  double scale;
1223  scale = 1.;
1225  DFexp.getValue(MDL_SCALE, scale, imgid);
1226  img.setScale(scale);
1227 
1228  img.getTransformationMatrix(A,true);
1229  A=A.inv();
1230  //std::cerr << "DEBUG_ROB, A:" << A << std::endl;
1231  //img.write("before.spi");
1232  if (!A.isIdentity())
1233  selfApplyGeometry(xmipp_transformation::BSPLINE3, img(), A, xmipp_transformation::IS_INV, xmipp_transformation::WRAP);
1234  //img.write("after.spi");
1235  //exit(0);
1236 }
1237 
1239 {
1241 }
void selfApplyGeometry(int Splinedegree, MultidimArray< std::complex< double > > &V1, const Matrix2D< double > &A, bool inv, bool wrap, std::complex< double > outside)
int barrier_init(barrier_t *barrier, int needed)
#define dAi(v, i)
void init_progress_bar(long total)
bool isIdentity() const
Definition: matrix2d.cpp:1323
Rotation angle of an image (double,degrees)
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
#define XMIPP_MAX(x, y)
Definition: xmipp_macros.h:193
void scaleAlignOneImage(MultidimArray< double > &img, const int &samplenr, const double &psi, const bool &opt_flip, const double &opt_xoff, const double &opt_yoff, const double &old_scale, double &opt_scale, double &maxcorr)
void setScale(double scale, const size_t n=0)
void getCurrentReference(int refno, Polar_fftw_plans &local_plans)
double getDoubleParam(const char *param, int arg=0)
void inverseFourierTransform()
Definition: xmipp_fftw.cpp:329
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
pthread_mutex_t update_refs_in_memory_mutex
#define FOR_ALL_DIRECT_ELEMENTS_IN_ARRAY2D(m)
doublereal * c
#define DEG2RAD(d)
Definition: xmipp_macros.h:312
void resizeNoCopy(const MultidimArray< T1 > &v)
#define dAij(M, i, j)
void findObjects(std::vector< size_t > &objectsOut, const MDQuery &query) const override
#define pp(s, x)
Definition: ml2d.cpp:473
bool getValue(MDObject &mdValueOut, size_t id) const override
int getSampleNoOuterRing() const
Definition: polar.h:386
Tilting angle of an image (double,degrees)
double DeltafV
Defocus in V (in Angstroms). Negative values are underfocused.
Definition: ctf.h:830
void rotationalCorrelation(const Polar< std::complex< double > > &M1, const Polar< std::complex< double > > &M2, MultidimArray< double > &angles, RotationalCorrelationAux &aux)
Definition: polar.cpp:99
Shift for the image in the X axis (double)
void applyGeometry(int SplineDegree, MultidimArray< std::complex< double > > &V2, const MultidimArray< std::complex< double > > &V1, const Matrix2D< double > &A, bool inv, bool wrap, std::complex< double > outside, MultidimArray< double > *BcoeffsPtr)
virtual void readParams()
Read arguments from command line.
bool existsBlockInMetaDataFile(const FileName &inFileWithBlock)
void processSomeImages(const std::vector< size_t > &imagesToProcess)
double correlationIndex(const MultidimArray< T > &x, const MultidimArray< T > &y, const MultidimArray< int > *mask=NULL, MultidimArray< double > *Contributions=NULL)
void computeAverageAndStddev(double &avg, double &stddev, int mode=FULL_CIRCLES) const
Definition: polar.h:488
virtual void defineParams()
Define arguments accepted.
void compose(const String &str, const size_t no, const String &ext="")
int getSampleNo(int iring) const
Definition: polar.h:373
void inv(Matrix2D< T > &result) const
Definition: matrix2d.cpp:663
Special label to be used when gathering MDs in MpiMetadataPrograms.
const FileName & name() const
double elapsed_time(ProcessorTimeStamp &time, bool _IN_SECS)
Polar< std::complex< double > > * fP_ref
FileName removeAllExtensions() const
Incorrect MultidimArray size.
Definition: xmipp_error.h:174
Bad amount of memory requested.
Definition: xmipp_error.h:165
#define i
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
#define rotate(a, i, j, k, l)
Unique identifier for items inside a list or set (std::size_t)
void addSeeAlsoLine(const char *seeAlso)
void read(const FileName &fn, bool disable_if_not_K=true)
Definition: ctf.cpp:1220
void * threadRotationallyAlignOneImage(void *data)
void time_config()
double DeltafU
Global gain. By default, 1.
Definition: ctf.h:828
bool enable_CTF
Enable CTF part.
Definition: ctf.h:275
#define MAT_ELEM(m, i, j)
Definition: matrix2d.h:116
void setShifts(double xoff, double yoff, double zoff=0., const size_t n=0)
#define DIRECT_A1D_ELEM(v, i)
std::vector< size_t > no_redundant_sampling_points_index
Definition: sampling.h:123
pthread_mutex_t debug_mutex
const char * getParam(const char *param, int arg=0)
#define x0
#define XX(v)
Definition: matrix1d.h:85
size_t numberSamplesAsymmetricUnit
Definition: sampling.h:78
void setReal(MultidimArray< double > &img)
Definition: xmipp_fftw.cpp:129
void getPolarFromCartesianBSpline(const MultidimArray< T > &M1, int first_ring, int last_ring, int BsplineOrder=3, double xoff=0., double yoff=0., double oversample1=1., int mode1=FULL_CIRCLES)
Definition: polar.h:625
size_t addObject() override
void setFlip(bool flip, const size_t n=0)
Flip the image? (bool)
void produceSplineCoefficients(int SplineDegree, MultidimArray< double > &coeffs, const MultidimArray< T > &V1)
#define XSIZE(v)
double Yoff(const size_t n=0) const
void progress_bar(long rlen)
void getEulerAngles(double &rot, double &tilt, double &psi, const size_t n=0) const
double scale(const size_t n=0) const
#define ABS(x)
Definition: xmipp_macros.h:142
free((char *) ob)
void addExampleLine(const char *example, bool verbatim=true)
#define ROUND(x)
Definition: xmipp_macros.h:210
Maximum cross-correlation for the image (double)
scaling factor for an image or volume (double)
Matrix1D< double > vectorR2(double x, double y)
Definition: matrix1d.cpp:884
int verbose
Verbosity level.
void write(const FileName &outFile, WriteModeMetaData mode=MD_OVERWRITE) const override
void translationallyAlignOneImage(MultidimArray< double > &img, const int &samplenr, const double &psi, const bool &opt_flip, double &opt_xoff, double &opt_yoff, double &maxcorr)
#define xF
size_t size() const override
void FourierTransform(T &v, T1 &V, bool getCopy=true)
Definition: xmipp_fftw.h:166
Polar< std::complex< double > > * fPm_img
#define XMIPP_MIN(x, y)
Definition: xmipp_macros.h:181
std::vector< std::vector< size_t > > my_neighbors
Definition: sampling.h:87
#define j
#define YY(v)
Definition: matrix1d.h:93
void fourierTransformRings(Polar< double > &in, Polar< std::complex< double > > &out, Polar_fftw_plans &plans, bool conjugated)
Definition: polar.cpp:34
size_t firstRowId() const override
void generateCTF(const MultidimArray< T1 > &sample_image, MultidimArray< T2 > &CTF, double Ts=-1)
Definition: ctf.h:1194
void getCurrentImage(size_t imgid, Image< double > &img)
void setEulerAngles(double rot, double tilt, double psi, const size_t n=0)
Class to which the image belongs (int)
void readSamplingFile(const FileName &infilename, bool read_vectors=true, bool read_sampling_sphere=false)
Definition: sampling.cpp:1592
std::vector< Matrix1D< double > > no_redundant_sampling_points_angles
Definition: sampling.h:121
bool isMetaData(bool failIfNotExists=true) const
bool setValue(const MDObject &mdValueIn, size_t id) override
Definition: metadata_db.cpp:90
FileName removeBlockName() const
void translate(PDB *pdb_original, PDB *pdb_move, unsigned num_atoms, double x0, double y0, double z0)
Definition: lib_pwk.cpp:125
Polar< std::complex< double > > * fP_img
FourierTransformer local_transformer
Definition: polar.h:794
#define FIRST_XMIPP_INDEX(size)
Definition: xmipp_macros.h:439
std::vector< size_t > convert_refno_to_stack_position
std::string String
Definition: xmipp_strings.h:34
void produceSideInfo()
Produce Side information.
Definition: ctf.cpp:1392
int getRingNo() const
Definition: polar.h:326
double Xoff(const size_t n=0) const
void read(const FileName &inFile, const std::vector< MDLabel > *desiredLabels=NULL, bool decomposeStack=true) override
template float bestShift(MultidimArray< float > &, float &, float &, const MultidimArray< int > *, int)
void join1(const MetaDataDb &mdInLeft, const MetaDataDb &mdInRight, const MDLabel label, JoinType type=LEFT)
bool checkParam(const char *param)
void getTransformationMatrix(Matrix2D< double > &A, bool only_apply_shifts=false, const size_t n=0)
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
#define FIRST_IMAGE
ProgClassifyCL2D * prm
Shift for the image in the Y axis (double)
void addUsageLine(const char *line, bool verbatim=false)
void annotate_time(TimeStamp *time)
#define LAST_XMIPP_INDEX(size)
Definition: xmipp_macros.h:448
int barrier_wait(barrier_t *barrier)
int getIntParam(const char *param, int arg=0)
void calculateFftwPlans(Polar_fftw_plans &out)
Definition: polar.h:708
Incorrect value received.
Definition: xmipp_error.h:195
int * n
Name of an image (std::string)
size_t TimeStamp
Definition: xmipp_funcs.h:823
void addParamsLine(const String &line)
void initIdentity()
Definition: matrix2d.h:673
bool containsLabel(const MDLabel label) const override
Definition: metadata_db.h:305