Xmipp  v3.23.11-Nereus
forward_zernike_subtomos.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Carlos Oscar Sanchez Sorzano (coss@cnb.csic.es)
4  * David Herreros Calero (dherreros@cnb.csic.es)
5  *
6  * Unidad de Bioinformatica of 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/transformations.h"
31 #include "data/projection.h"
32 #include "data/mask.h"
33 
34 // Empty constructor =======================================================
36 {
37  resume = false;
38  produces_a_metadata = true;
40  showOptimization = false;
41 }
42 
44 
45 // Read arguments ==========================================================
47 {
49  fnVolR = getParam("--ref");
50  fnMaskR = getParam("--mask");
51  fnOutDir = getParam("--odir");
52  maxShift = getDoubleParam("--max_shift");
53  maxAngularChange = getDoubleParam("--max_angular_change");
54  maxResol = getDoubleParam("--max_resolution");
55  Ts = getDoubleParam("--sampling");
56  Rmax = getIntParam("--Rmax");
57  RmaxDef = getIntParam("--RDef");
58  optimizeAlignment = checkParam("--optimizeAlignment");
59  optimizeDeformation = checkParam("--optimizeDeformation");
60  optimizeDefocus = checkParam("--optimizeDefocus");
61  phaseFlipped = checkParam("--phaseFlipped");
62  useCTF = checkParam("--useCTF");
63  L1 = getIntParam("--l1");
64  L2 = getIntParam("--l2");
65  loop_step = getIntParam("--step");
66  lambda = getDoubleParam("--regularization");
67  resume = checkParam("--resume");
68  Rerunable::setFileName(fnOutDir + "/sphDone.xmd");
69  blob_r = getDoubleParam("--blobr");
70  t1 = getDoubleParam("--t1");
71  t2 = getDoubleParam("--t2");
72  keep_input_columns = true;
73 }
74 
75 // Show ====================================================================
77 {
78  if (!verbose)
79  return;
81  std::cout
82  << "Output directory: " << fnOutDir << std::endl
83  << "Reference volume: " << fnVolR << std::endl
84  << "Reference mask: " << fnMaskR << std::endl
85  << "Max. Shift: " << maxShift << std::endl
86  << "Max. Angular Change: " << maxAngularChange << std::endl
87  << "Max. Resolution: " << maxResol << std::endl
88  << "Sampling: " << Ts << std::endl
89  << "Max. Radius: " << Rmax << std::endl
90  << "Max. Radius Deform. " << RmaxDef << std::endl
91  << "Zernike Degree: " << L1 << std::endl
92  << "SH Degree: " << L2 << std::endl
93  << "Step: " << loop_step << std::endl
94  << "Correct CTF: " << useCTF << std::endl
95  << "Optimize alignment: " << optimizeAlignment << std::endl
96  << "Optimize deformation:" << optimizeDeformation<< std::endl
97  << "Optimize defocus: " << optimizeDefocus << std::endl
98  << "Phase flipped: " << phaseFlipped << std::endl
99  << "Regularization: " << lambda << std::endl
100  << "Blob radius: " << blob_r << std::endl
101  ;
102 }
103 
104 // usage ===================================================================
106 {
107  addUsageLine("Make a continuous angular assignment with deformations");
108  defaultComments["-i"].clear();
109  defaultComments["-i"].addComment("Metadata with initial alignment");
110  defaultComments["-o"].clear();
111  defaultComments["-o"].addComment("Metadata with the angular alignment and deformation parameters");
113  addParamsLine(" --ref <volume> : Reference volume");
114  addParamsLine(" [--mask <m=\"\">] : Reference volume");
115  addParamsLine(" [--odir <outputDir=\".\">] : Output directory");
116  addParamsLine(" [--max_shift <s=-1>] : Maximum shift allowed in pixels");
117  addParamsLine(" [--max_angular_change <a=5>] : Maximum angular change allowed (in degrees)");
118  addParamsLine(" [--max_resolution <f=4>] : Maximum resolution (A)");
119  addParamsLine(" [--sampling <Ts=1>] : Sampling rate (A/pixel)");
120  addParamsLine(" [--Rmax <R=-1>] : Maximum radius (px). -1=Half of volume size");
121  addParamsLine(" [--RDef <r=-1>] : Maximum radius of the deformation (px). -1=Half of volume size");
122  addParamsLine(" [--l1 <l1=3>] : Degree Zernike Polynomials=1,2,3,...");
123  addParamsLine(" [--l2 <l2=2>] : Harmonical depth of the deformation=1,2,3,...");
124  addParamsLine(" [--step <step=1>] : Voxel index step");
125  addParamsLine(" [--useCTF] : Correct CTF");
126  addParamsLine(" [--optimizeAlignment] : Optimize alignment");
127  addParamsLine(" [--optimizeDeformation] : Optimize deformation");
128  addParamsLine(" [--optimizeDefocus] : Optimize defocus");
129  addParamsLine(" [--phaseFlipped] : Input images have been phase flipped");
130  addParamsLine(" [--regularization <l=0.01>] : Regularization weight");
131  addParamsLine(" [--blobr <b=4>] : Blob radius for forward mapping splatting");
132  addParamsLine(" [--t1 <t1=-60>] : First tilt angle range");
133  addParamsLine(" [--t2 <t2=60>] : Second tilt angle range");
134  addParamsLine(" [--resume] : Resume processing");
135  addExampleLine("A typical use is:",false);
136  addExampleLine("xmipp_forward_zernike_subtomos -i anglesFromContinuousAssignment.xmd --ref reference.vol -o assigned_anglesAndDeformations.xmd --optimizeAlignment --optimizeDeformation --depth 1");
137 }
138 
140 {
141  V.read(fnVolR);
142  V().setXmippOrigin();
143  Xdim=XSIZE(V());
144  Vdeformed().initZeros(V());
145  Vdeformed().setXmippOrigin();
146  // sumV=V().sum();
147 
148  Ifilteredp().initZeros(Xdim,Xdim,Xdim);
149  Ifilteredp().setXmippOrigin();
150  P().initZeros(Xdim,Xdim,Xdim);
151 
152  if (RmaxDef<0)
153  RmaxDef = Xdim/2;
154 
155  // Read Reference mask if avalaible (otherwise sphere of radius RmaxDef is used)
156  Mask mask;
157  mask.type = BINARY_CIRCULAR_MASK;
158  mask.mode = INNER_MASK;
159  if (fnMaskR != "") {
160  Image<double> aux;
161  aux.read(fnMaskR);
162  typeCast(aux(), V_mask);
164  double Rmax2 = RmaxDef*RmaxDef;
165  for (int k=STARTINGZ(V_mask); k<=FINISHINGZ(V_mask); k++) {
166  for (int i=STARTINGY(V_mask); i<=FINISHINGY(V_mask); i++) {
167  for (int j=STARTINGX(V_mask); j<=FINISHINGX(V_mask); j++) {
168  double r2 = k*k + i*i + j*j;
169  if (r2>=Rmax2)
170  A3D_ELEM(V_mask,k,i,j) = 0;
171  }
172  }
173  }
174  }
175  else {
176  mask.R1 = RmaxDef;
177  mask.generate_mask(V());
178  V_mask = mask.get_binary_mask();
180  }
181 
182  // Total Volume Mass (Inside Mask)
183  sumV = 0;
184  for (int k = STARTINGZ(V()); k <= FINISHINGZ(V()); k += loop_step)
185  {
186  for (int i = STARTINGY(V()); i <= FINISHINGY(V()); i += loop_step)
187  {
188  for (int j = STARTINGX(V()); j <= FINISHINGX(V()); j += loop_step)
189  {
190  if (A3D_ELEM(V_mask, k, i, j) == 1)
191  {
192  sumV++;
193  }
194  }
195  }
196  }
197 
198  // Construct mask
199  if (Rmax<0)
200  Rmax=Xdim/2;
201  mask.R1 = Rmax;
202  mask.generate_mask(Xdim,Xdim,Xdim);
203  mask3D=mask.get_binary_mask();
204 
205  // Low pass filter
207  filter.do_generate_3dmask = true;
209  filter.raised_w=0.02;
210 
211  // MW filter
212  // filterMW.FilterBand=WEDGE;
213  // filterMW.FilterShape=WEDGE;
214  // filterMW.do_generate_3dmask = true;
215  // filterMW.t1 = t1;
216  // filterMW.t2 = t2;
217  // filterMW.rot=filterMW.tilt=filterMW.psi=0.0;
221  filterMW.t1 = t1;
222  filterMW.t2 = t2;
225  filterMW.raised_w=0.02;
226 
227  // Transformation matrix
228  A.initIdentity(4);
229 
230  // CTF Filter
233  FilterCTF.ctf.enable_CTFnoise = false;
235 
236  vecSize = 0;
239 
240  createWorkFiles();
241 
242  // Blob
243  blob.radius = blob_r; // Blob radius in voxels
244  blob.order = 2; // Order of the Bessel function
245  blob.alpha = 7.05; // Smoothness parameter
246 
247 }
248 
251  rename(Rerunable::getFileName().c_str(), (fnOutDir + fn_out).c_str());
252 }
253 
254 // #define DEBUG
256 {
257  const MultidimArray<double> &mV=V();
258  idx_z_clnm.clear();
259  z_clnm_diff.clear();
261  {
262  VEC_ELEM(clnm,i)=pclnm[i+1];
263  if (VEC_ELEM(clnm,i) != VEC_ELEM(prev_clnm,i))
264  {
265  idx_z_clnm.push_back(i);
266  z_clnm_diff.push_back(VEC_ELEM(clnm, i) - VEC_ELEM(prev_clnm, i));
267  // std::cout << i << std::endl;
268  }
269  }
270  double deformation=0.0;
271  totalDeformation=0.0;
272 
273  P().initZeros(Xdim,Xdim,Xdim);
274  P().setXmippOrigin();
275  double currentRot=old_rot + deltaRot;
276  double currentTilt=old_tilt + deltaTilt;
277  double currentPsi=old_psi + deltaPsi;
278  deformVol(P(), mV, deformation, currentRot, currentTilt, currentPsi);
279 
280  double cost=0.0;
281  const MultidimArray<int> &mMask3D=mask3D;
282 
283  if (old_flip)
284  {
285  MAT_ELEM(A, 0, 0) *= -1;
286  MAT_ELEM(A, 0, 1) *= -1;
287  MAT_ELEM(A, 0, 2) *= -1;
288  }
289 
290  // Image<double> save;
291  // save()=Ifiltered();
292  // save.write("PPPbefore.mrc");
293 
295  xmipp_transformation::IS_NOT_INV,xmipp_transformation::DONT_WRAP,0.);
296 
297  // Image<double> save;
298  // save()=P();
299  // save.write("PPPtheo.mrc");
300 
301  // save()=Ifilteredp();
302  // save.write("PPPexp.mrc");
303 
304  // std::cout << "Press any key" << std::endl;
305  // char c; std::cin >> c;
306 
309 
310  if (hasCTF)
311  {
312  double defocusU=old_defocusU+deltaDefocusU;
313  double defocusV=old_defocusV+deltaDefocusV;
314  double angle=old_defocusAngle+deltaDefocusAngle;
315  if (defocusU!=currentDefocusU || defocusV!=currentDefocusV || angle!=currentAngle) {
316  updateCTFImage(defocusU,defocusV,angle);
317  }
318  // FilterCTF1.ctf = ctf;
320  if (phaseFlipped)
323  }
324  // filter.applyMaskSpace(P());
325 
326 
327  const MultidimArray<double> &mP=P();
328  MultidimArray<double> &mIfilteredp=Ifilteredp();
329  double corr1=correlationIndex(mIfilteredp,mP,&mMask3D);
330 
331  cost=-corr1;
332 
333 #ifdef DEBUG
334  std::cout << "A=" << A << std::endl;
335  Image<double> save;
336  save()=P();
337  save.write("PPPtheo.xmp");
338  save()=Ifilteredp();
339  save.write("PPPfilteredp.xmp");
340  save()=Ifiltered();
341  save.write("PPPfiltered.xmp");
342  // Vdeformed.write("PPPVdeformed.vol");
343  std::cout << "Cost=" << cost << " deformation=" << deformation << std::endl;
344  std::cout << "Press any key" << std::endl;
345  char c; std::cin >> c;
346 #endif
347 
348  if (showOptimization)
349  {
350  std::cout << "A=" << A << std::endl;
351  Image<double> save;
352  save()=P();
353  save.write("PPPtheo.mrc");
354  save()=Ifilteredp();
355  save.write("PPPfilteredp.mrc");
356  save()=Ifiltered();
357  save.write("PPPfiltered.mrc");
358  Vdeformed.write("PPPVdeformed.vol");
359  std::cout << "Deformation=" << totalDeformation << std::endl;
360  std::cout << "Press any key" << std::endl;
361  char c; std::cin >> c;
362  }
363 
364  // double massDiff=std::abs(sumV-sumVd)/sumV;
365  prev_clnm = clnm;
366  double retval=cost+lambda*abs(deformation - prior_deformation);
367  if (showOptimization)
368  std::cout << cost << " " << deformation << " " << lambda*deformation << " " << sumV << " " << retval << std::endl;
369  return retval;
370 }
371 
372 double continuousZernikeSubtomoCost(double *x, void *_prm)
373 {
375  int idx = 3*(prm->vecSize);
376  // TODO: Optimize parameters for each image (not sharing)
377  // prm->deltaDefocusU[0]=x[idx+6]; prm->deltaDefocusU[1]=x[idx+6];
378  // prm->deltaDefocusV[0]=x[idx+7]; prm->deltaDefocusV[1]=x[idx+7];
379  // prm->deltaDefocusAngle[0]=x[idx+8]; prm->deltaDefocusAngle[1]=x[idx+8];
380 
381  prm->deltaX = x[idx + 1];
382  prm->deltaY = x[idx + 2];
383  prm->deltaZ = x[idx + 3];
384  prm->deltaRot = x[idx + 4];
385  prm->deltaTilt = x[idx + 5];
386  prm->deltaPsi = x[idx + 6];
387  prm->deltaDefocusU=x[idx + 7];
388  prm->deltaDefocusV=x[idx + 8];
389  prm->deltaDefocusAngle=x[idx + 9];
390 
391  MAT_ELEM(prm->A, 0, 3) = prm->old_shiftX + prm->deltaX;
392  MAT_ELEM(prm->A, 1, 3) = prm->old_shiftY + prm->deltaY;
393  MAT_ELEM(prm->A, 2, 3) = prm->old_shiftZ + prm->deltaZ;
394  MAT_ELEM(prm->A, 0, 0) = 1;
395  MAT_ELEM(prm->A, 0, 1) = 0;
396  MAT_ELEM(prm->A, 0, 2) = 0;
397  MAT_ELEM(prm->A, 1, 0) = 0;
398  MAT_ELEM(prm->A, 1, 1) = 1;
399  MAT_ELEM(prm->A, 1, 2) = 0;
400  MAT_ELEM(prm->A, 2, 0) = 0;
401  MAT_ELEM(prm->A, 2, 1) = 0;
402  MAT_ELEM(prm->A, 2, 2) = 1;
403  // MAT_ELEM(prm->A, 3, 0) = 0;
404  // MAT_ELEM(prm->A, 3, 1) = 0;
405  // MAT_ELEM(prm->A, 3, 2) = 0;
406  // MAT_ELEM(prm->A, 3, 3) = 1;
407 
408  return prm->transformImageSph(x);
409 
410  // return prm->transformImageSph(x,prm->old_rot+deltaRot, prm->old_tilt+deltaTilt, prm->old_psi+deltaPsi,
411  // prm->A, deltaDefocusU, deltaDefocusV, deltaDefocusAngle);
412 }
413 
414 // Predict =================================================================
415 //#define DEBUG
416 void ProgForwardZernikeSubtomos::processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
417 {
419  // totalSize = 3*num_Z_coeff + 3 shifts + 3 angles + 3 CTF
420  int totalSize = 3*vecSize + 9;
421  p.initZeros(totalSize);
422  clnm.initZeros(totalSize);
423  prev_clnm.initZeros(totalSize);
424 
425  // Init positions and deformation field
426  vpos.initZeros(sumV, 8);
427  df.initZeros(sumV, 3);
428 
429  flagEnabled=1;
430 
431  rowIn.getValueOrDefault(MDL_IMAGE, fnImage, "");
438  I.read(fnImage);
439  I().setXmippOrigin();
440  Ifiltered() = I();
443 
444  if (verbose >= 2)
445  std::cout << "Processing Image (" << fnImage << ")" << std::endl;
446 
447  if (rowIn.containsLabel(MDL_FLIP))
448  rowIn.getValue(MDL_FLIP,old_flip);
449  else
450  old_flip = false;
451 
452  prior_deformation = 0.0;
454  {
455  std::vector<double> vectortemp;
456  rowIn.getValue(MDL_SPH_COEFFICIENTS, vectortemp);
458  for (int i=0; i<3*vecSize; i++)
459  {
460  clnm[i] = vectortemp[i];
461  }
462  // if (optimizeDeformation)
463  // rotateCoefficients<Direction::ROTATE>();
464  p = clnm;
465  prev_clnm = clnm;
466  preComputeDF();
467  }
468 
469  // FIXME: Add defocus per image and make CTF correction available
471  {
472  hasCTF=true;
473  FilterCTF.ctf.readFromMdRow(rowIn);
474  FilterCTF.ctf.Tm = Ts;
479  }
480  else
481  hasCTF=false;
482 
483  // If deformation is not optimized, do a single iteration
484  //? Si usamos priors es mejor ir poco a poco, ir poco a poco pero usar todos los coeffs cada vez (mas lento)
485  //? O dar solo una iteracion con todos los coeffs?
486  int h = 1;
487  // if (!optimizeDeformation)
488  // if (rowIn.containsLabel(MDL_SPH_COEFFICIENTS))
489  // h = L2;
490 
491  for (;h<=L2;h++)
492  {
493  if (verbose>=2)
494  {
495  std::cout<<std::endl;
496  std::cout<<"------------------------------ Basis Degrees: ("<<L1<<","<<h<<") ----------------------------"<<std::endl;
497  }
498  steps.clear();
499  steps.initZeros(totalSize);
500 
501  // Optimize
502  double cost=-1;
503  correlation = 0.0;
504  try
505  {
506  cost=1e38;
507  int iter;
508  if (optimizeAlignment)
509  {
510  int init = steps.size() - 9;
511  int end = steps.size() - 3;
512  for (int i = init; i < end; i++)
513  steps(i)=1.;
514  }
515  if (optimizeDefocus)
516  {
517  int init = steps.size() - 3;
518  int end = steps.size();
519  for (int i = init; i < end; i++)
520  steps(i)=1.;
521  }
523  {
524  minimizepos(L1,h,steps);
525  }
526  steps_cp = steps;
527  powellOptimizer(p, 1, totalSize, &continuousZernikeSubtomoCost, this, 0.1, cost, iter, steps, verbose>=2);
528 
529  if (verbose>=3)
530  {
531  showOptimization = true;
533  showOptimization = false;
534  }
535 
536  if (cost>0)
537  {
538  flagEnabled=-1;
539  p.initZeros();
540  }
541  cost=-cost;
542  correlation=cost;
543  if (verbose>=2)
544  {
545  std::cout<<std::endl;
546  for (int j=1;j<4;j++)
547  {
548  switch (j)
549  {
550  case 1:
551  std::cout << "X Coefficients=(";
552  break;
553  case 2:
554  std::cout << "Y Coefficients=(";
555  break;
556  case 3:
557  std::cout << "Z Coefficients=(";
558  break;
559  }
560  for (int i=(j-1)*vecSize;i<j*vecSize;i++)
561  {
562  std::cout << p(i);
563  if (i<j*vecSize-1)
564  std::cout << ",";
565  }
566  std::cout << ")" << std::endl;
567  }
568  std::cout << "Radius=" << RmaxDef << std::endl;
569  std::cout << " Dshift=(" << p(totalSize-5) << "," << p(totalSize-4) << ") "
570  << "Drot=" << p(totalSize-3) << " Dtilt=" << p(totalSize-2)
571  << " Dpsi=" << p(totalSize-1) << std::endl;
572  std::cout << " Total deformation=" << totalDeformation << std::endl;
573  std::cout<<std::endl;
574  }
575  }
576  catch (XmippError &XE)
577  {
578  std::cerr << XE.what() << std::endl;
579  std::cerr << "Warning: Cannot refine " << fnImg << std::endl;
580  flagEnabled=-1;
581  }
582  }
583 
584  // if (optimizeDeformation)
585  // {
586  // rotateCoefficients<Direction::UNROTATE>();
587  // }
588 
589  //AJ NEW
590  writeImageParameters(rowOut);
591  //END AJ
592 
593 }
594 #undef DEBUG
595 
597  int pos = 3*vecSize;
598  if (flagEnabled==1) {
599  row.setValue(MDL_ENABLED, 1);
600  }
601  else {
602  row.setValue(MDL_ENABLED, -1);
603  }
604 
605  row.setValue(MDL_ANGLE_ROT, old_rot+p(pos+3));
606  row.setValue(MDL_ANGLE_TILT, old_tilt+p(pos+4));
607  row.setValue(MDL_ANGLE_PSI, old_psi+p(pos+5));
608  row.setValue(MDL_SHIFT_X, old_shiftX+p(pos));
609  row.setValue(MDL_SHIFT_Y, old_shiftY+p(pos+1));
610  row.setValue(MDL_SHIFT_Z, old_shiftZ+p(pos+2));
611 
613  std::vector<double> vectortemp;
614  size_t end_clnm = VEC_XSIZE(clnm)-9;
615  for (int j = 0; j < end_clnm; j++) {
616  vectortemp.push_back(clnm(j));
617  }
618  row.setValue(MDL_SPH_COEFFICIENTS, vectortemp);
619  // row.setValue(MDL_COST, correlation);
620 }
621 
623  MDRowVec rowAppend;
625  getOutputMd().getRow(rowAppend, getOutputMd().lastRowId());
626  checkPoint.addRow(rowAppend);
627  checkPoint.append(Rerunable::getFileName());
628 }
629 
631 {
632  for (int h=0; h<=l2; h++)
633  {
634  int numSPH = 2*h+1;
635  int count=l1-h+1;
636  int numEven=(count>>1)+(count&1 && !(h&1));
637  if (h%2 == 0) {
638  vecSize += numSPH*numEven;
639  }
640  else {
641  vecSize += numSPH*(l1-h+1-numEven);
642  }
643  }
644 }
645 
647 {
648  int size = 0;
649  int prevSize = 0;
650  numCoefficients(L1,l2,size);
651  numCoefficients(L1,l2-1,prevSize);
652  int totalSize = (steps.size()-9)/3;
653  if (l2 > 1)
654  {
655  for (int idx = prevSize; idx < size; idx++)
656  {
657  VEC_ELEM(steps, idx) = 1.;
658  VEC_ELEM(steps, idx + totalSize) = 1.;
659  VEC_ELEM(steps, idx + 2 * totalSize) = 1.;
660  }
661  }
662  else
663  {
664  for (int idx = 0; idx < size; idx++)
665  {
666  VEC_ELEM(steps, idx) = 1.;
667  VEC_ELEM(steps, idx + totalSize) = 1.;
668  VEC_ELEM(steps, idx + 2 * totalSize) = 1.;
669  }
670  }
671 }
672 
675 {
676  int idx = 0;
677  vL1.initZeros(vecSize);
678  vN.initZeros(vecSize);
679  vL2.initZeros(vecSize);
680  vM.initZeros(vecSize);
681  for (int h=0; h<=l2; h++) {
682  int totalSPH = 2*h+1;
683  int aux = std::floor(totalSPH/2);
684  for (int l=h; l<=l1; l+=2) {
685  for (int m=0; m<totalSPH; m++) {
686  VEC_ELEM(vL1,idx) = l;
687  VEC_ELEM(vN,idx) = h;
688  VEC_ELEM(vL2,idx) = h;
689  VEC_ELEM(vM,idx) = m-aux;
690  idx++;
691  }
692  }
693  }
694 }
695 
696 void ProgForwardZernikeSubtomos::updateCTFImage(double defocusU, double defocusV, double angle)
697 {
698  FilterCTF.ctf.K=1; // get pure CTF with no envelope
703 }
704 
705 template<ProgForwardZernikeSubtomos::Direction DIRECTION>
707  int pos = 3*vecSize;
708  size_t idxY0=(VEC_XSIZE(clnm)-9)/3;
709  size_t idxZ0=2*idxY0;
710 
711  double rot = old_rot+p(pos+2);
712  double tilt = old_tilt+p(pos+3);
713  double psi = old_psi+p(pos+4);
714 
716  R.initIdentity(3);
717  Euler_angles2matrix(rot, tilt, psi, R, false);
718  if (DIRECTION == Direction::UNROTATE)
719  R = R.inv();
721  c.initZeros(3);
722  for (size_t idx=0; idx<idxY0; idx++) {
723  XX(c) = VEC_ELEM(clnm,idx); YY(c) = VEC_ELEM(clnm,idx+idxY0); ZZ(c) = VEC_ELEM(clnm,idx+idxZ0);
724  c = R * c;
725  VEC_ELEM(clnm,idx) = XX(c); VEC_ELEM(clnm,idx+idxY0) = YY(c); VEC_ELEM(clnm,idx+idxZ0) = ZZ(c);
726  }
727 }
728 
730  double rot, double tilt, double psi)
731 {
732  size_t idxY0=(VEC_XSIZE(clnm)-9)/3;
733  double Ncount=0.0;
734  double modg=0.0;
735  double diff2=0.0;
736 
737  def=0.0;
738  size_t idxZ0=2*idxY0;
739  // sumVd=0.0;
740  double RmaxF=RmaxDef;
741  double RmaxF2=RmaxF*RmaxF;
742  double iRmaxF=1.0/RmaxF;
743  // Rotation Matrix
744  // Matrix2D<double> R, R_inv;
745  // Matrix2D<double> R;
746  // R.initIdentity(3);
747  // Euler_angles2matrix(rot, tilt, psi, R, false);
748  // Matrix2D<double> R_inv = R.inv();
749  // R_inv = R.inv();
750 
751  // auto stepsMask = std::vector<size_t>();
752  // if (optimizeDeformation)
753  // {
754  // for (size_t idx = 0; idx < idxY0; idx++)
755  // {
756  // if (1 == VEC_ELEM(steps_cp, idx))
757  // {
758  // stepsMask.emplace_back(idx);
759  // }
760  // }
761  // }
762  // else {
763  // for (size_t idx = 0; idx < idxY0; idx++)
764  // {
765  // stepsMask.emplace_back(idx);
766  // }
767  // }
768 
769  auto sz = idx_z_clnm.size();
770  Matrix1D<int> l1, l2, n, m, idx_v;
771 
772  if (!idx_z_clnm.empty())
773  {
774  l1.initZeros(sz);
775  l2.initZeros(sz);
776  n.initZeros(sz);
777  m.initZeros(sz);
778  idx_v.initZeros(sz);
779  for (auto j=0; j<sz; j++)
780  {
781  auto idx = idx_z_clnm[j];
782  if (idx >= idxY0 && idx < idxZ0)
783  idx -= idxY0;
784  else if (idx >= idxZ0)
785  idx -= idxZ0;
786 
787  VEC_ELEM(idx_v,j) = idx;
788  VEC_ELEM(l1,j) = VEC_ELEM(vL1, idx);
789  VEC_ELEM(n,j) = VEC_ELEM(vN, idx);
790  VEC_ELEM(l2,j) = VEC_ELEM(vL2, idx);
791  VEC_ELEM(m,j) = VEC_ELEM(vM, idx);
792  }
793  }
794 
795  // // TODO: Poner primero i y j en el loop, acumular suma y guardar al final
796  // const auto lastZ = FINISHINGZ(mV);
797  // const auto lastY = FINISHINGY(mV);
798  // const auto lastX = FINISHINGX(mV);
799  // for (int k=STARTINGZ(mV); k<=lastZ; k+=loop_step)
800  // {
801  // for (int i=STARTINGY(mV); i<=lastY; i+=loop_step)
802  // {
803  // for (int j=STARTINGX(mV); j<=lastX; j+=loop_step)
804  // {
805  // if (A3D_ELEM(V_mask,k,i,j) == 1) {
806  // // ZZ(p) = k; YY(p) = i; XX(p) = j;
807  // // pos = R_inv * pos;
808  // // pos = R * pos;
809  // double gx=0.0, gy=0.0, gz=0.0;
810  // double k2=k*k;
811  // double kr=k*iRmaxF;
812  // double k2i2=k2+i*i;
813  // double ir=i*iRmaxF;
814  // double r2=k2i2+j*j;
815  // double jr=j*iRmaxF;
816  // double rr=sqrt(r2)*iRmaxF;
817  // for (auto idx : stepsMask) {
818  // auto l1 = VEC_ELEM(vL1,idx);
819  // auto n = VEC_ELEM(vN,idx);
820  // auto l2 = VEC_ELEM(vL2,idx);
821  // auto m = VEC_ELEM(vM,idx);
822  // auto zsph=ZernikeSphericalHarmonics(l1,n,l2,m,jr,ir,kr,rr);
823  // auto c = std::array<double, 3>{};
824  // // XX(c_rot) = VEC_ELEM(clnm,idx); YY(c_rot) = VEC_ELEM(clnm,idx+idxY0); ZZ(c_rot) = VEC_ELEM(clnm,idx+idxZ0);
825  // // if (num_images == 1 && optimizeDeformation)
826  // // {
827  // // //? Hacer algun check para ahorrarnos cuentas si no usamos priors (en ese
828  // // //? caso podemos usar las lineas comentadas)
829  // // double c_x = VEC_ELEM(clnm,idx);
830  // // double c_y = VEC_ELEM(clnm,idx+idxY0);
831  // // // c[0] = R_inv.mdata[0] * c_x + R_inv.mdata[1] * c_y;
832  // // // c[1] = R_inv.mdata[3] * c_x + R_inv.mdata[4] * c_y;
833  // // // c[2] = R_inv.mdata[6] * c_x + R_inv.mdata[7] * c_y;
834  // // double c_z = VEC_ELEM(clnm, idx + idxZ0);
835  // // c[0] = R_inv.mdata[0] * c_x + R_inv.mdata[1] * c_y + R_inv.mdata[2] * c_z;
836  // // c[1] = R_inv.mdata[3] * c_x + R_inv.mdata[4] * c_y + R_inv.mdata[5] * c_z;
837  // // c[2] = R_inv.mdata[6] * c_x + R_inv.mdata[7] * c_y + R_inv.mdata[8] * c_z;
838  // // }
839  // // else {
840  // c[0] = VEC_ELEM(clnm,idx);
841  // c[1] = VEC_ELEM(clnm,idx+idxY0);
842  // c[2] = VEC_ELEM(clnm,idx+idxZ0);
843  // // }
844  // if (rr>0 || l2==0) {
845  // gx += c[0] *(zsph);
846  // gy += c[1] *(zsph);
847  // gz += c[2] *(zsph);
848  // }
849  // }
850 
851  // auto pos = std::array<double, 3>{};
852  // double r_x = j + gx;
853  // double r_y = i + gy;
854  // double r_z = k + gz;
855  // pos[0] = R.mdata[0] * r_x + R.mdata[1] * r_y + R.mdata[2] * r_z;
856  // pos[1] = R.mdata[3] * r_x + R.mdata[4] * r_y + R.mdata[5] * r_z;
857  // pos[2] = R.mdata[6] * r_x + R.mdata[7] * r_y + R.mdata[8] * r_z;
858 
859  // double voxel_mV = A3D_ELEM(mV,k,i,j);
860  // splattingAtPos(pos, voxel_mV, mP, mV);
861  // if (!mV.outside(pos[2], pos[1], pos[0]))
862  // sumVd += voxel_mV;
863  // modg += gx*gx+gy*gy+gz*gz;
864  // Ncount++;
865  // }
866  // }
867  // }
868  // }
869 
870  const auto &mVpos = vpos;
871  const auto lastY = FINISHINGY(mVpos);
872  for (int i=STARTINGY(mVpos); i<=lastY; i++)
873  {
874  double &gx = A2D_ELEM(df, i, 0);
875  double &gy = A2D_ELEM(df, i, 1);
876  double &gz = A2D_ELEM(df, i, 2);
877  double r_x = A2D_ELEM(mVpos, i, 0);
878  double r_y = A2D_ELEM(mVpos, i, 1);
879  double r_z = A2D_ELEM(mVpos, i, 2);
880  double xr = A2D_ELEM(mVpos, i, 3);
881  double yr = A2D_ELEM(mVpos, i, 4);
882  double zr = A2D_ELEM(mVpos, i, 5);
883  double rr = A2D_ELEM(mVpos, i, 6);
884 
885  if (!idx_z_clnm.empty())
886  {
887  for (auto j = 0; j < sz; j++)
888  {
889  auto idx = VEC_ELEM(idx_v, j);
890  auto aux_l2 = VEC_ELEM(l2, j);
891  auto zsph = ZernikeSphericalHarmonics(VEC_ELEM(l1, j), VEC_ELEM(n, j),
892  aux_l2, VEC_ELEM(m, j), xr, yr, zr, rr);
893 
894  auto diff_c_x = VEC_ELEM(clnm, idx) - VEC_ELEM(prev_clnm, idx);
895  auto diff_c_y = VEC_ELEM(clnm, idx + idxY0) - VEC_ELEM(prev_clnm, idx + idxY0);
896  auto diff_c_z = VEC_ELEM(clnm, idx + idxZ0) - VEC_ELEM(prev_clnm, idx + idxZ0);
897  // auto i_diff_c_x = R_inv.mdata[0] * diff_c_x + R_inv.mdata[1] * diff_c_y;
898  // auto i_diff_c_y = R_inv.mdata[3] * diff_c_x + R_inv.mdata[4] * diff_c_y;
899  // auto i_diff_c_z = R_inv.mdata[6] * diff_c_x + R_inv.mdata[7] * diff_c_y;
900  if (rr > 0 || aux_l2 == 0)
901  {
902  gx += diff_c_x * (zsph);
903  gy += diff_c_y * (zsph);
904  gz += diff_c_z * (zsph);
905  }
906  }
907  }
908 
909  auto r_gx = R.mdata[0] * gx + R.mdata[1] * gy + R.mdata[2] * gz;
910  auto r_gy = R.mdata[3] * gx + R.mdata[4] * gy + R.mdata[5] * gz;
911  auto r_gz = R.mdata[6] * gx + R.mdata[7] * gy + R.mdata[8] * gz;
912 
913  auto pos = std::array<double, 3>{};
914  pos[0] = r_x + r_gx;
915  pos[1] = r_y + r_gy;
916  pos[2] = r_z + r_gz;
917 
918  double voxel_mV = A2D_ELEM(mVpos, i, 7);
919  splattingAtPos(pos, voxel_mV, mP, mV);
920 
921  modg += gx * gx + gy * gy + gz * gz;
922  Ncount++;
923  }
924 
925  // def=sqrt(modg/Ncount);
926  def = sqrt(modg/Ncount);
927  totalDeformation = def;
928 }
929 
932  w.initZeros(8);
933 
934  int x0 = FLOOR(x);
935  double fx0 = x - x0;
936  int x1 = x0 + 1;
937  double fx1 = x1 - x;
938 
939  int y0 = FLOOR(y);
940  double fy0 = y - y0;
941  int y1 = y0 + 1;
942  double fy1 = y1 - y;
943 
944  int z0 = FLOOR(z);
945  double fz0 = z - z0;
946  int z1 = z0 + 1;
947  double fz1 = z1 - z;
948 
949  VEC_ELEM(w,0) = fx1 * fy1 * fz1; // w000 (x0,y0,z0)
950  VEC_ELEM(w,1) = fx1 * fy1 * fz0; // w001 (x0,y0,z1)
951  VEC_ELEM(w,2) = fx1 * fy0 * fz1; // w010 (x0,y1,z0)
952  VEC_ELEM(w,3) = fx1 * fy0 * fz0; // w011 (x0,y1,z1)
953  VEC_ELEM(w,4) = fx0 * fy1 * fz1; // w100 (x1,y0,z0)
954  VEC_ELEM(w,5) = fx0 * fy1 * fz0; // w101 (x1,y0,z1)
955  VEC_ELEM(w,6) = fx0 * fy0 * fz1; // w110 (x1,y1,z0)
956  VEC_ELEM(w,7) = fx0 * fy0 * fz0; // w111 (x1,y1,z1)
957 
958  return w;
959 }
960 
961 void ProgForwardZernikeSubtomos::splattingAtPos(std::array<double, 3> r, double weight, MultidimArray<double> &mP, const MultidimArray<double> &mV) {
962  // Find the part of the volume that must be updated
963  // double x_pos = r[0];
964  // double y_pos = r[1];
965  // double z_pos = r[2];
966  // // int k0 = XMIPP_MAX(FLOOR(z_pos - blob_r), STARTINGZ(mV));
967  // // int kF = XMIPP_MIN(CEIL(z_pos + blob_r), FINISHINGZ(mV));
968  // // int i0 = XMIPP_MAX(FLOOR(y_pos - blob_r), STARTINGY(mV));
969  // // int iF = XMIPP_MIN(CEIL(y_pos + blob_r), FINISHINGY(mV));
970  // // int j0 = XMIPP_MAX(FLOOR(x_pos - blob_r), STARTINGX(mV));
971  // // int jF = XMIPP_MIN(CEIL(x_pos + blob_r), FINISHINGX(mV));
972  // int k0 = XMIPP_MAX(FLOOR(z_pos - sigma4), STARTINGZ(mV));
973  // int kF = XMIPP_MIN(CEIL(z_pos + sigma4), FINISHINGZ(mV));
974  // int i0 = XMIPP_MAX(FLOOR(y_pos - sigma4), STARTINGY(mV));
975  // int iF = XMIPP_MIN(CEIL(y_pos + sigma4), FINISHINGY(mV));
976  // int j0 = XMIPP_MAX(FLOOR(x_pos - sigma4), STARTINGX(mV));
977  // int jF = XMIPP_MIN(CEIL(x_pos + sigma4), FINISHINGX(mV));
978  // int size = gaussianProjectionTable.size();
979  // for (int k = k0; k <= kF; k++)
980  // {
981  // double k2 = (z_pos - k) * (z_pos - k);
982  // for (int i = i0; i <= iF; i++)
983  // {
984  // double y2 = (y_pos - i) * (y_pos - i);
985  // for (int j = j0; j <= jF; j++)
986  // {
987  // // double mod = sqrt((x_pos - j) * (x_pos - j) + y2 + k2);
988  // // // A3D_ELEM(Vdeformed(),k, i, j) += weight * blob_val(rdiff.module(), blob);
989  // // A3D_ELEM(mP, k, i, j) += weight * kaiser_value(mod, blob.radius, blob.alpha, blob.order);
990  // double mod = sqrt((x_pos - j) * (x_pos - j) + y2 + k2);
991  // double didx = mod * 1000;
992  // int idx = ROUND(didx);
993  // if (idx < size)
994  // {
995  // double gw = gaussianProjectionTable.vdata[idx];
996  // A3D_ELEM(mP, k, i, j) += weight * gw;
997  // }
998  // }
999  // }
1000  // }
1001 
1002  double x_pos = r[0];
1003  double y_pos = r[1];
1004  double z_pos = r[2];
1005  int i0 = XMIPP_MAX(CEIL(y_pos - loop_step), STARTINGY(mV));
1006  int iF = XMIPP_MIN(FLOOR(y_pos + loop_step), FINISHINGY(mV));
1007  int j0 = XMIPP_MAX(CEIL(x_pos - loop_step), STARTINGX(mV));
1008  int jF = XMIPP_MIN(FLOOR(x_pos + loop_step), FINISHINGX(mV));
1009  int k0 = XMIPP_MAX(CEIL(z_pos - loop_step), STARTINGZ(mV));
1010  int kF = XMIPP_MIN(FLOOR(z_pos + loop_step), FINISHINGZ(mV));
1011 
1012  double m = 1. / loop_step;
1013  for (int k = k0; k <= kF; k++)
1014  {
1015  double z_val = 1. - m * ABS(k - z_pos);
1016  for (int i = i0; i <= iF; i++)
1017  {
1018  double y_val = 1. - m * ABS(i - y_pos);
1019  for (int j = j0; j <= jF; j++)
1020  {
1021  double x_val = 1. - m * ABS(j - x_pos);
1022  A3D_ELEM(mP, k, i, j) += weight * x_val * y_val * z_val;
1023  }
1024  }
1025  }
1026 }
1027 
1028 void ProgForwardZernikeSubtomos::rotatePositions(double rot, double tilt, double psi)
1029 {
1030  // Matrix2D<double> R;
1031  R.initIdentity(3);
1032  Euler_angles2matrix(rot, tilt, psi, R, false);
1033 
1034  const MultidimArray<double> &mV=V();
1035 
1036  const auto lastZ = FINISHINGZ(mV);
1037  const auto lastY = FINISHINGY(mV);
1038  const auto lastX = FINISHINGX(mV);
1039  size_t count = 0;
1040  double iRmaxF=1.0/RmaxDef;
1041  for (int k=STARTINGZ(mV); k<=lastZ; k+=loop_step)
1042  {
1043  for (int i=STARTINGY(mV); i<=lastY; i+=loop_step)
1044  {
1045  for (int j=STARTINGX(mV); j<=lastX; j+=loop_step)
1046  {
1047  if (A3D_ELEM(V_mask,k,i,j) == 1) {
1048  double x = j;
1049  double y = i;
1050  double z = k;
1051  double r_x = R.mdata[0] * x + R.mdata[1] * y + R.mdata[2] * z;
1052  double r_y = R.mdata[3] * x + R.mdata[4] * y + R.mdata[5] * z;
1053  double r_z = R.mdata[6] * x + R.mdata[7] * y + R.mdata[8] * z;
1054 
1055  A2D_ELEM(vpos, count, 0) = r_x;
1056  A2D_ELEM(vpos, count, 1) = r_y;
1057  A2D_ELEM(vpos, count, 2) = r_z;
1058  A2D_ELEM(vpos, count, 3) = j * iRmaxF;
1059  A2D_ELEM(vpos, count, 4) = i * iRmaxF;
1060  A2D_ELEM(vpos, count, 5) = z * iRmaxF;
1061  A2D_ELEM(vpos, count, 6) = sqrt(x*x + y*y + z*z) * iRmaxF;
1062  A2D_ELEM(vpos, count, 7) = A3D_ELEM(mV, k, i, j);
1063 
1064  count++;
1065  }
1066  }
1067  }
1068  }
1069 }
1070 
1071 
1073 {
1074  size_t idxY0=(VEC_XSIZE(clnm)-9)/3;
1075  size_t idxZ0=2*idxY0;
1076  // Matrix2D<double> R_inv = R.inv();
1077  const auto &mVpos = vpos;
1078  const auto lastY = FINISHINGY(mVpos);
1079  for (int i=STARTINGY(mVpos); i<=lastY; i++)
1080  {
1081  double &gx = A2D_ELEM(df, i, 0);
1082  double &gy = A2D_ELEM(df, i, 1);
1083  double &gz = A2D_ELEM(df, i, 2);
1084  double r_x = A2D_ELEM(mVpos, i, 0);
1085  double r_y = A2D_ELEM(mVpos, i, 1);
1086  double r_z = A2D_ELEM(mVpos, i, 2);
1087  double xr = A2D_ELEM(mVpos, i, 3);
1088  double yr = A2D_ELEM(mVpos, i, 4);
1089  double zr = A2D_ELEM(mVpos, i, 5);
1090  double rr = A2D_ELEM(mVpos, i, 6);
1091 
1092  if (!idx_z_clnm.empty())
1093  {
1094  for (int idx = 0; idx < idxY0; idx++)
1095  {
1096  auto aux_l2 = VEC_ELEM(vL2, idx);
1097  auto zsph = ZernikeSphericalHarmonics(VEC_ELEM(vL1, idx), VEC_ELEM(vN, idx),
1098  aux_l2, VEC_ELEM(vM, idx), xr, yr, zr, rr);
1099  auto c_x = VEC_ELEM(clnm, idx);
1100  auto c_y = VEC_ELEM(clnm, idx + idxY0);
1101  auto c_z = VEC_ELEM(clnm, idx + idxZ0);
1102  // auto i_c_x = R_inv.mdata[0] * c_x + R_inv.mdata[1] * c_y + R_inv.mdata[2] * c_z;
1103  // auto i_c_y = R_inv.mdata[3] * c_x + R_inv.mdata[4] * c_y + R_inv.mdata[5] * c_z;
1104  // auto i_c_z = R_inv.mdata[6] * c_x + R_inv.mdata[7] * c_y + R_inv.mdata[8] * c_z;
1105  if (rr > 0 || aux_l2 == 0)
1106  {
1107  gx += c_x * (zsph);
1108  gy += c_y * (zsph);
1109  gz += c_z * (zsph);
1110  }
1111  }
1112  }
1113  }
1114 }
ProgForwardZernikeSubtomos()
Empty constructor.
Rotation angle of an image (double,degrees)
#define A2D_ELEM(v, i, j)
#define VEC_ELEM(v, i)
Definition: matrix1d.h:245
double alpha
Smoothness parameter.
Definition: blobs.h:121
Defocus U (Angstroms)
#define XMIPP_MAX(x, y)
Definition: xmipp_macros.h:193
double getDoubleParam(const char *param, int arg=0)
__host__ __device__ float2 floor(const float2 v)
double continuousZernikeSubtomoCost(double *x, void *_prm)
CTFDescription ctf
~ProgForwardZernikeSubtomos()
Destructor.
void clear()
Definition: matrix1d.cpp:67
#define FINISHINGX(v)
size_t size() const
Definition: matrix1d.h:508
void defineParams()
Define parameters.
#define VEC_XSIZE(m)
Definition: matrix1d.h:77
void Euler_angles2matrix(T alpha, T beta, T gamma, Matrix2D< T > &A, bool homogeneous)
Definition: geometry.cpp:624
doublereal * c
Definition: mask.h:360
void rotatePositions(double rot, double tilt, double psi)
void sqrt(Image< double > &op)
void updateCTFImage(double defocusU, double defocusV, double angle)
Tilting angle of an image (double,degrees)
static double * y
double DeltafV
Defocus in V (in Angstroms). Negative values are underfocused.
Definition: ctf.h:830
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)
void write(const FileName &name="", size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE, CastWriteMode castMode=CW_CAST, int _swapWrite=0)
double correlationIndex(const MultidimArray< T > &x, const MultidimArray< T > &y, const MultidimArray< int > *mask=NULL, MultidimArray< double > *Contributions=NULL)
int l
Definition: svm.h:62
void inv(Matrix2D< T > &result) const
Definition: matrix2d.cpp:663
Special label to be used when gathering MDs in MpiMetadataPrograms.
doublereal * w
void abs(Image< double > &op)
T * mdata
Definition: matrix2d.h:395
Name for the CTF Model (std::string)
void powellOptimizer(Matrix1D< double > &p, int i0, int n, double(*f)(double *x, void *), void *prm, double ftol, double &fret, int &iter, const Matrix1D< double > &steps, bool show)
void setFileName(const FileName &fn)
#define z0
#define FINISHINGZ(v)
glob_prnt iter
void numCoefficients(int l1, int l2, int &vecSize)
Length of coefficients vector.
std::unique_ptr< MDRow > getRow(size_t id) override
#define STARTINGX(v)
doublereal * x
#define i
Is this image enabled? (int [-1 or 1])
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
size_t addRow(const MDRow &row) override
double DeltafU
Global gain. By default, 1.
Definition: ctf.h:828
#define STARTINGY(v)
#define MAT_ELEM(m, i, j)
Definition: matrix2d.h:116
#define A3D_ELEM(V, k, i, j)
double azimuthal_angle
Azimuthal angle (between X and U) in degrees.
Definition: ctf.h:832
#define FOR_ALL_ELEMENTS_IN_MATRIX1D(v)
Definition: matrix1d.h:72
const FileName & getFileName() const
T & getValue(MDLabel label)
#define FLOOR(x)
Definition: xmipp_macros.h:240
#define y0
const char * getParam(const char *param, int arg=0)
#define x0
#define XX(v)
Definition: matrix1d.h:85
#define CEIL(x)
Definition: xmipp_macros.h:225
Deformation in voxels.
#define CTF
double R1
Definition: mask.h:413
Flip the image? (bool)
void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
#define XSIZE(v)
double Tm
Sampling rate (A/pixel)
Definition: ctf.h:240
int type
Definition: mask.h:402
#define ABS(x)
Definition: xmipp_macros.h:142
double z
void addExampleLine(const char *example, bool verbatim=true)
void readFromMdRow(const MDRow &row, bool disable_if_not_K=true)
Definition: ctf.cpp:1172
void deformVol(MultidimArray< double > &mVD, const MultidimArray< double > &mV, double &def, double rot, double tilt, double psi)
Deform a volumen using Zernike-Spherical harmonic basis.
int verbose
Verbosity level.
virtual void checkPoint()
For very long programs, it may be needed to write checkpoints.
void initZeros()
Definition: matrix1d.h:592
#define XMIPP_MIN(x, y)
Definition: xmipp_macros.h:181
FileName fnOutDir
Output directory.
#define j
double steps
#define YY(v)
Definition: matrix1d.h:93
int m
const T & getValueOrDefault(MDLabel label, const T &def) const
double K
Global gain. By default, 1.
Definition: ctf.h:238
virtual void writeImageParameters(MDRow &row)
void setValue(MDLabel label, const T &d, bool addLabel=true)
#define WEDGE_RC
#define FINISHINGY(v)
void show() const override
void generate_mask(bool apply_geo=false)
Definition: mask.cpp:1577
void minimizepos(int L1, int l2, Matrix1D< double > &steps)
Determine the positions to be minimize of a vector containing spherical harmonic coefficients.
virtual bool containsLabel(MDLabel label) const =0
void typeCast(const Matrix1D< T1 > &v1, Matrix1D< T2 > &v2)
Definition: matrix1d.h:1227
void append(const FileName &outFile) const
#define BINARY_CIRCULAR_MASK
Definition: mask.h:365
double ZernikeSphericalHarmonics(int n, int m, double xr, double yr, double zr, double r)
void produceSideInfo()
Produce Side information.
Definition: ctf.cpp:1392
double psi(const double x)
Deformation coefficients.
int order
Derivation order and Bessel function order.
Definition: blobs.h:118
Shift for the image in the Z axis (double)
void splattingAtPos(std::array< double, 3 > r, double weight, MultidimArray< double > &mP, const MultidimArray< double > &mV)
bool keep_input_columns
Keep input metadata columns.
bool checkParam(const char *param)
void fillVectorTerms(int l1, int l2, Matrix1D< int > &vL1, Matrix1D< int > &vN, Matrix1D< int > &vL2, Matrix1D< int > &vM)
Zernike and SPH coefficients allocation.
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
void readParams()
Read argument from command line.
float r2
ProgClassifyCL2D * prm
bool each_image_produces_an_output
Indicate that an output is produced for each image in the input.
Shift for the image in the Y axis (double)
void addUsageLine(const char *line, bool verbatim=false)
void initZeros(const MultidimArray< T1 > &op)
bool enable_CTFnoise
Enable CTFnoise part.
Definition: ctf.h:273
const MultidimArray< int > & get_binary_mask() const
Definition: mask.h:707
T * adaptForNumericalRecipes() const
Definition: matrix1d.h:844
int getIntParam(const char *param, int arg=0)
void generateMask(MultidimArray< double > &v)
#define STARTINGZ(v)
double radius
Spatial radius in Universal System units.
Definition: blobs.h:115
int * n
Name of an image (std::string)
#define ZZ(v)
Definition: matrix1d.h:101
bool produces_a_metadata
Indicate that the unique final output file is a Metadata.
Matrix1D< double > weightsInterpolation3D(double x, double y, double z)
#define LOWPASS
void addParamsLine(const String &line)
void initIdentity()
Definition: matrix2d.h:673
int mode
Definition: mask.h:407
void applyMaskSpace(MultidimArray< double > &v)
std::map< String, CommentList > defaultComments
Definition: xmipp_program.h:83
constexpr int INNER_MASK
Definition: mask.h:47