75 std::cout <<
"Reference volume: " <<
fn_ref << std::endl
80 <<
"Max. Shift: " <<
max_shift << std::endl
89 addUsageLine(
"+This program assigns Euler angles to experimental projections by ");
90 addUsageLine(
"+minimizing the difference between the given experimental image and ");
91 addUsageLine(
"+the central slice of a reference volume in Fourier space. All ");
92 addUsageLine(
"+interpolations are based on a B-spline model of the images and the ");
93 addUsageLine(
"+volume. The translations are also optimized. Since an iterative ");
94 addUsageLine(
"+optimization is performed, it must be initialized with some rough ");
95 addUsageLine(
"+estimate of the angles. The output of xmipp_angular_predict can be ");
96 addUsageLine(
"+used as initialization without any transformation.");
97 addUsageLine(
"+The method is fully described at http://www.ncbi.nlm.nih.gov/pubmed/15885434");
104 addParamsLine(
" [--gaussian_Fourier <s=0.5>] : Weighting sigma in Fourier space");
105 addParamsLine(
" :+Small values of this parameter concentrate ");
106 addParamsLine(
" :+the optimization on low frequencies. This ");
108 addParamsLine(
" [--gaussian_Real <s=0.5>] : Weighting sigma in Real space");
109 addParamsLine(
" :+Small values of this parameter concentrate ");
110 addParamsLine(
" :+the optimization in the image center. This ");
112 addParamsLine(
" [--zerofreq_weight <s=0. >] : Zero-frequency weight");
113 addParamsLine(
" [--max_iter <max=60>] : Maximum number of iterations");
114 addParamsLine(
" :+Convergence might be reached before this number of iterations");
115 addParamsLine(
" [--max_shift <s=-1>] : Maximum shift allowed");
116 addParamsLine(
" :+Use this option to limit the maximum shift that the ");
117 addParamsLine(
" :+optimization process can find. If the minimum is ");
118 addParamsLine(
" :+found beyond this limit (note it is an absolute limit ");
119 addParamsLine(
" :+on the shift and it is not relative to the initial shift), ");
120 addParamsLine(
" :+then the solution given by the initial guess is kept ");
121 addParamsLine(
" :+since the optimized one looks suspicious.");
122 addParamsLine(
" [--max_angular_change <a=-1>]: Maximum angular change allowed");
123 addParamsLine(
" :+Use this option to limit the maximum angular ");
124 addParamsLine(
" :+change with respect to the initial solution ");
125 addParamsLine(
" :+that the optimization algorithm can find. If ");
126 addParamsLine(
" :+the solution found is beyond this limit, then ");
127 addParamsLine(
" :+the initial solution is returned instead of the ");
128 addParamsLine(
" :+optimized one since this latter looks suspicious.");
130 addExampleLine(
"xmipp_angular_continuous_assign -i anglesFromDiscreteAssignment.doc --ref reference.vol -o assigned_angles.xmd");
139 V().setXmippOrigin();
198 img().setXmippOrigin();
200 double old_rot, old_tilt, old_psi, old_shiftX, old_shiftY;
211 pose(3) = -old_shiftX;
212 pose(4) = -old_shiftY;
223 double shift=
sqrt(pose(3)*pose(3)+pose(4)*pose(4));
224 double new_rot=old_rot;
225 double new_tilt=old_tilt;
226 double new_psi=old_psi;
227 double new_shiftX=old_shiftX;
228 double new_shiftY=old_shiftY;
239 new_shiftX = -pose(3);
240 new_shiftY = -pose(4);
326 long NumberIterPerformed, NumberSuccPerformed,
329 Data.
nx_Cost = max_no_iter + 1;
365 while (Failures(last_iteration_performed - 1) > 0.0)
366 last_iteration_performed--;
369 pose_parameters(0) =
RAD2DEG(output_pose(0, last_iteration_performed - 1));
370 pose_parameters(1) =
RAD2DEG(output_pose(1, last_iteration_performed - 1));
371 pose_parameters(2) =
RAD2DEG(output_pose(2, last_iteration_performed - 1));
372 pose_parameters(3) = output_pose(3, last_iteration_performed - 1);
373 pose_parameters(4) = output_pose(4, last_iteration_performed - 1);
376 retval = Cost(last_iteration_performed - 1);
381 std::cout <<
"There is a problem with one image, angles not assigned\n";
398 qk = k - (2L * period - 2L) * (
long)
floor((
double) k / (
double)(2L * period - 2L));
400 if ((qk < period) && (qk >= 0L))
403 sqk = 2L * period - 2L - qk;
415 qk = k - period * (long)
floor((
double) k / (double) period);
417 qk =
ABS(k + 1L) - period * (long)
floor((
double)
ABS(k + 1L) / (double) period);
419 if ((k >= 0L) || (period == 1L))
422 sqk = period - 1L - qk;
427 #define PERIODIZATION(y, period, k) \ 435 qk = K - period * (long) floor((double) K / (double) period); \ 438 long aux=ABS(K+1L); \ 439 qk = aux - period * (long) floor((double) aux / (double) period); \ 442 if ((K >= 0L) || (period == 1L)) \ 445 y = period - 1L - qk; \ 465 *cost += Weight * Difference * Difference;
467 for (m = 0L; m < 5L; m++)
472 Gradient[0] += Weight * dp0 * Difference;
473 for (l = 0L; l < 5L; l++)
477 Hessian[CC + l] += Weight * dp0 * dp0;
481 Hessian[CC + l] += Weight * dp0 * dp1;
485 Hessian[CC + l] += Weight * dp0 * dp2;
489 Hessian[CC + l] += Weight * dp0 * dp3;
493 Hessian[CC + l] += Weight * dp0 * dp4;
500 Gradient[1] += Weight * dp1 * Difference;
501 for (l = 1L; l < 5L; l++)
505 Hessian[CC + l] += Weight * dp1 * dp1;
509 Hessian[CC + l] += Weight * dp1 * dp2;
513 Hessian[CC + l] += Weight * dp1 * dp3;
517 Hessian[CC + l] += Weight * dp1 * dp4;
524 Gradient[2] += Weight * dp2 * Difference;
525 for (l = 2L; l < 5L; l++)
529 Hessian[CC + l] += Weight * dp2 * dp2;
533 Hessian[CC + l] += Weight * dp2 * dp3;
537 Hessian[CC + l] += Weight * dp2 * dp4;
544 Gradient[3] += Weight * dp3 * Difference;
545 for (l = 3L; l < 5L; l++)
549 Hessian[CC + l] += Weight * dp3 * dp3;
553 Hessian[CC + l] += Weight * dp3 * dp4;
560 Gradient[4] += Weight * dp4 * Difference;
561 Hessian[CC + 4L] += Weight * dp4 * dp4;
601 long indx, indy, l, l1, l2,
m, m1, m2,
n, n1, n2;
603 double phi,
theta,
psi,
x0,
y0, Sinphi, Cosphi, Sinpsi, Cospsi, Sintheta, Costheta;
604 double *hlp, *Rz1, *Ry, *Rz2, *DRz1, *DRy, *DRz2;
605 double *DR0, *DR1, *DR2, *mn, *Arg;
606 double *Grad_re, *Grad_im, *Hessian_re, *Hessian_im, *Gradient_re, *Gradient_im;
607 double scx, scy,
x,
y,
z;
608 double xminusl, yminusm, zminusn, re_Coeff, im_Coeff;
609 double re_columns, re_rows, im_columns, im_rows;
610 double re_slices, re_slices_d1, re_slices_d2, re_slices_d3, re_columns_d1, re_columns_d2, re_rows_d1;
611 double im_slices, im_slices_d1, im_slices_d2, im_slices_d3, im_columns_d1, im_columns_d2, im_rows_d1;
612 double a,
b,
c, SinC, CosC, redftproj, imdftproj;
613 double da, db, dc, da0[1], da1[1], da2[1], da3[1], da4[1];
614 double db0[1], db1[1], db2[1], db3[1], db4[1], dc0[1], dc1[1], dc2[1], dc3[1], dc4[1];
615 double prv_re, prv_im, Difference_re, Difference_im, Weight;
616 double dp0_re, dp0_im, dp1_re, dp1_im, dp2_re, dp2_im, dp3_re, dp3_im, dp4_re, dp4_im;
617 double cost_re, cost_im, *R, *Q, *Q2, *dQ0, *dQ1, *dQ2, *dQ2_0, *dQ2_1, *dQ2_2;
618 double sum_xx_re, sum_xx_im, sc_re, sc_im;
619 double *DP_0, *DP_1, *DP_2, *DP_3, *DP_4, *pntr_ReOut, *pntr_ImOut;
620 double *pntr_DP_re, *pntr_DP_im, *pntr_DP_0_re, *pntr_DP_0_im, *pntr_DP_1_re, *pntr_DP_1_im;
621 double *pntr_DP_2_re, *pntr_DP_2_im, *pntr_DP_3_re, *pntr_DP_3_im;
622 double *pntr_DP_4_re, *pntr_DP_4_im;
624 size_t poolSize = (18 * 16) + (4 * 4) + (2 * 5) + (2 * 25);
625 auto pool = std::unique_ptr<double[]>(
new double[poolSize]);
626 double *poolNext = pool.get();
627 auto getNextFromPool = [&](
size_t count) {
633 if (( ! pool) || (
nullptr == poolNext)) {
639 theta = Parameters[1];
648 Sintheta = sin(theta);
649 Costheta = cos(theta);
651 Rz1 = getNextFromPool(16);
652 Ry = getNextFromPool(16);
653 Rz2 = getNextFromPool(16);
663 hlp += (std::ptrdiff_t)3L;
676 hlp += (std::ptrdiff_t)3L;
688 hlp += (std::ptrdiff_t)2L;
690 hlp += (std::ptrdiff_t)6L;
692 hlp += (std::ptrdiff_t)2L;
695 R = getNextFromPool(16);
702 DRz1 = getNextFromPool(16);
703 DRy = getNextFromPool(16);
704 DRz2 = getNextFromPool(16);
705 for (i = 0L; i < 16L; i++)
715 hlp += (std::ptrdiff_t)3L;
722 hlp += (std::ptrdiff_t)3L;
728 hlp += (std::ptrdiff_t)2L;
730 hlp += (std::ptrdiff_t)6L;
732 hlp += (std::ptrdiff_t)2L;
735 DR0 = getNextFromPool(16);
736 DR1 = getNextFromPool(16);
737 DR2 = getNextFromPool(16);
754 mn = getNextFromPool(4);
755 Arg = getNextFromPool(4);
756 Grad_re = getNextFromPool(4);
757 Grad_im = getNextFromPool(4);
758 Gradient_re = getNextFromPool(5);
759 Gradient_im = getNextFromPool(5);
760 Hessian_re = getNextFromPool(25);
761 Hessian_im = getNextFromPool(25);
803 pntr_ReOut = dftCompProj;
804 pntr_ImOut = pntr_ReOut + (std::ptrdiff_t) SizeIm;
807 pntr_DP_0_im = pntr_DP_0_re + (std::ptrdiff_t) SizeIm;
810 pntr_DP_1_im = pntr_DP_1_re + (std::ptrdiff_t) SizeIm;
813 pntr_DP_2_im = pntr_DP_2_re + (std::ptrdiff_t) SizeIm;
816 pntr_DP_3_im = pntr_DP_3_re + (std::ptrdiff_t) SizeIm;
819 pntr_DP_4_im = pntr_DP_4_re + (std::ptrdiff_t) SizeIm;
821 Q = getNextFromPool(16);
822 Q2 = getNextFromPool(16);
823 auto freeAllVolumes = [&] {
852 dQ0 = getNextFromPool(16);
853 dQ1 = getNextFromPool(16);
854 dQ2 = getNextFromPool(16);
855 dQ2_0 = getNextFromPool(16);
856 dQ2_1 = getNextFromPool(16);
857 dQ2_2 = getNextFromPool(16);
925 for (indy = 0L; indy < My; indy++)
927 for (indx = 0L; indx < Mx; indx++)
930 mn[0] = (double)(indx - Mx / 2L);
931 mn[1] = (double)(indy - My / 2L);
946 l1 = (long) ceil(x - 2.0);
948 m1 = (long) ceil(y - 2.0);
950 n1 = (long) ceil(z - 2.0);
961 for (n = n1; n <= n2; n++)
965 CC1 = Nx * Ny * Laux;
972 for (m = m1; m <= m2; m++)
975 CC = CC1 + Nx * Laux;
980 for (l = l1; l <= l2; l++)
982 xminusl = x - (double) l;
984 long Laux2=CC + Laux;
985 re_Coeff = CoefRe[Laux2];
986 im_Coeff = CoefIm[Laux2];
989 re_rows += re_Coeff * aux;
990 re_rows_d1 += re_Coeff * aux2;
991 im_rows += im_Coeff * aux;
992 im_rows_d1 += im_Coeff * aux2;
994 yminusm = y - (double) m;
997 re_columns += re_rows * aux;
998 re_columns_d1 += re_rows_d1 * aux;
999 re_columns_d2 += re_rows * aux2;
1000 im_columns += im_rows * aux;
1001 im_columns_d1 += im_rows_d1 * aux;
1002 im_columns_d2 += im_rows * aux2;
1004 zminusn = z - (double) n;
1007 re_slices += re_columns * aux;
1008 re_slices_d1 += re_columns_d1 * aux;
1009 re_slices_d2 += re_columns_d2 * aux;
1010 re_slices_d3 += re_columns * aux2;
1011 im_slices += im_columns * aux;
1012 im_slices_d1 += im_columns_d1 * aux;
1013 im_slices_d2 += im_columns_d2 * aux;
1014 im_slices_d3 += im_columns * aux2;
1018 Grad_re[0] = re_slices_d1;
1019 Grad_re[1] = re_slices_d2;
1020 Grad_re[2] = re_slices_d3;
1024 Grad_im[0] = im_slices_d1;
1025 Grad_im[1] = im_slices_d2;
1026 Grad_im[2] = im_slices_d3;
1029 c = scx * mn[0] + scy * mn[1];
1034 redftproj = (a * CosC + b * SinC) * S;
1035 imdftproj = (b * CosC - a * SinC) * S;
1037 index = indy * Mx + indx;
1039 pntr_ReOut[
index] = redftproj;
1040 pntr_ImOut[
index] = imdftproj;
1043 if (!((indx == (Mx / 2L)) && (indy == (My / 2L))))
1045 sum_xx_re += redftproj * redftproj;
1046 sum_xx_im += imdftproj * imdftproj;
1115 dc3[0] = scx1 * mn[0];
1116 dc4[0] = scy1 * mn[1];
1121 pntr_DP_re = pntr_DP_0_re;
1122 pntr_DP_im = pntr_DP_0_im;
1124 (da * CosC - a * SinC * dc + db * SinC + b * CosC * dc) * S;
1126 (db * CosC - b * SinC * dc - da * SinC - a * CosC * dc) * S;
1132 pntr_DP_re = pntr_DP_1_re;
1133 pntr_DP_im = pntr_DP_1_im;
1135 (da * CosC - a * SinC * dc + db * SinC + b * CosC * dc) * S;
1137 ((db * CosC - b * SinC * dc - da * SinC - a * CosC * dc) * S);
1142 pntr_DP_re = pntr_DP_2_re;
1143 pntr_DP_im = pntr_DP_2_im;
1145 ((da * CosC - a * SinC * dc + db * SinC + b * CosC * dc) * S);
1147 ((db * CosC - b * SinC * dc - da * SinC - a * CosC * dc) * S);
1153 pntr_DP_re = pntr_DP_3_re;
1154 pntr_DP_im = pntr_DP_3_im;
1156 ((da * CosC - a * SinC * dc + db * SinC + b * CosC * dc) * S);
1158 ((db * CosC - b * SinC * dc - da * SinC - a * CosC * dc) * S);
1163 pntr_DP_re = pntr_DP_4_re;
1164 pntr_DP_im = pntr_DP_4_im;
1166 ((da * CosC - a * SinC * dc + db * SinC + b * CosC * dc) * S);
1168 ((db * CosC - b * SinC * dc - da * SinC - a * CosC * dc) * S);
1178 for (i = 0L; i < 5L; i++)
1180 Gradient_re[
i] = 0.0;
1181 Gradient_im[
i] = 0.0;
1182 for (j = 0L; j < 5L; j++)
1184 Hessian_re[i * 5L +
j] = 0.0;
1185 Hessian_im[i * 5L +
j] = 0.0;
1189 sc_re = 1.0 /
sqrt(sum_xx_re + sum_xx_im);
1193 for (indy = 0L; indy < My; indy++)
1195 for (indx = 0L; indx < Mx; indx++)
1198 index = indy * Mx + indx;
1200 Weight = (double) pntr_Weight[index];
1202 prv_re = (sc_re * (double) pntr_ReOut[index]);
1203 Difference_re = (double)(prv_re - pntr_ReInp[index]);
1205 prv_im = (sc_im * (double) pntr_ImOut[index]);
1206 Difference_im = (double)(prv_im - pntr_ImInp[index]);
1208 dp0_re = sc_re * (double) pntr_DP_0_re[index];
1209 dp1_re = sc_re * (double) pntr_DP_1_re[index];
1210 dp2_re = sc_re * (double) pntr_DP_2_re[index];
1211 dp3_re = sc_re * (double) pntr_DP_3_re[index];
1212 dp4_re = sc_re * (double) pntr_DP_4_re[index];
1214 dp0_im = sc_im * (double) pntr_DP_0_im[index];
1215 dp1_im = sc_im * (double) pntr_DP_1_im[index];
1216 dp2_im = sc_im * (double) pntr_DP_2_im[index];
1217 dp3_im = sc_im * (double) pntr_DP_3_im[index];
1218 dp4_im = sc_im * (double) pntr_DP_4_im[index];
1220 if (
gradhesscost_atpixel(Gradient_re, Hessian_re, &cost_re, Difference_re, dp0_re, dp1_re, dp2_re, dp3_re, dp4_re, Weight) ==
ERROR)
1226 if (
gradhesscost_atpixel(Gradient_im, Hessian_im, &cost_im, Difference_im, dp0_im, dp1_im, dp2_im, dp3_im, dp4_im, Weight))
1237 *cost = (cost_re + cost_im) / 2.0;
1239 for (i = 0L; i < 5L; i++)
1241 Gradient[
i] = Gradient_re[
i] + Gradient_im[
i];
1242 for (j = 0L; j < 5L; j++)
1243 Hessian[i * 5L + j] = Hessian_re[i * 5L + j] + Hessian_im[i * 5L + j];
1247 for (i = 0L; i < 4L; i++)
1248 for (j = i + 1L; j < 5L; j++)
1249 Hessian[j * 5L + i] = Hessian[i * 5L + j];
1269 double *pntr_Weight,
1287 double *dftCompProj,
1297 #define DBL_EPSILON 2e-16 1302 double wmax, thresh;
1305 double costchanged[1];
1307 da = (
double *)malloc((
size_t)ma *
sizeof(double));
1308 if (da == (
double *)NULL)
1313 u = (
double *)malloc((
size_t)(ma * ma) *
sizeof(
double));
1314 if (u == (
double *)NULL)
1320 v = (
double *)malloc((
size_t)(ma * ma) *
sizeof(
double));
1321 if (v == (
double *)NULL)
1328 w = (
double *)malloc((
size_t)ma *
sizeof(double));
1329 if (w == (
double *)NULL)
1340 for (i = 0L; (i < ma); t += (std::ptrdiff_t)(ma + 1L), i++)
1342 for (j = 0L; (j < ma); alpha++, j++)
1346 u -= (std::ptrdiff_t)(ma * ma);
1347 alpha -= (std::ptrdiff_t)(ma * ma);
1360 t = w + (std::ptrdiff_t)ma;
1364 thresh = epsilon * wmax;
1365 w += (std::ptrdiff_t)ma;
1372 for (i = 0; (i < ma); i++)
1374 u[i * ma +
j] = 0.0;
1375 v[i * ma +
j] = 0.0;
1390 v = (
double *)memcpy(v, a, (
size_t)ma *
sizeof(double));
1391 t = v + (std::ptrdiff_t)ma;
1392 a += (std::ptrdiff_t)ma;
1393 da += (std::ptrdiff_t)ma;
1403 CoefRe, CoefIm, pntr_ReInp, pntr_ImInp, pntr_Weight,
1404 Nx, Ny, Nz, indx0, indy0, indz0, Mx, My,
1405 Left, Right, Q1, Q3, scx1, scy1, S, SizeIm,
1406 DoDesProj, dftCompProj) ==
ERROR)
1418 if (costchanged[0] < OldCost)
1420 if ((fabs(a[0] - v[0]) < tol_angle) && (fabs(a[1] - v[1]) < tol_angle) && (fabs(a[2] - v[2]) < tol_angle))
1422 if ((fabs(a[3] - v[3]) < tol_shift) && (fabs(a[4] - v[4]) < tol_shift))
1431 if (costchanged[0] < OldCost)
1433 for (i = 0L; (i < ma); i++)
1435 for (j = 0L; (j < ma); j++)
1436 alpha[i * ma + j] = u[i * ma + j];
1440 *cost = costchanged[0];
1453 for (i = 0L; (i < ma); i++)
1455 for (j = 0L; (j < ma); j++)
1456 alpha[i * ma + j] = u[i * ma + j];
1460 *cost = costchanged[0];
1464 #define DBL_MIN 1e-26 1467 #define DBL_MAX 1e+26 1471 if (costchanged[0] < OldCost)
1475 *lambda /= LambdaScale;
1486 *lambda *= LambdaScale;
1544 " Error - ReDftVolume and ImDftVolume should have same dimensions.");
1552 " Error - ReDftImage and ImDftImage should have same dimensions.");
1566 " Error - Weight should have same dimensions as ReDftImage and ImDftImage.");
1573 " Error - VoxelSize is a 3-element vector.");
1576 if (((
double) *Data->
VoxelSize <= 0.0) || ((
double) *(Data->
VoxelSize + (std::ptrdiff_t) 1L)
1577 <= 0.0) || ((
double) *(Data->
VoxelSize + (std::ptrdiff_t) 2L) <= 0.0))
1580 " Error - VoxelSize must have all positive elements.");
1587 " Error - PixelSize is a 2-element vector.");
1590 if (((
double) *Data->
PixelSize <= 0.0) ||
1591 ((
double) *(Data->
PixelSize + (std::ptrdiff_t) 1L) <= 0.0))
1594 " Error - PixelSize must have positive elements.");
1601 " Error - Rotation is a 5-element vector.");
1607 " Error - ScaleLambda must be greater than 0.0.");
1613 " Error - LambdaInitial must be greater than or equal to 0.0.");
1619 " Error - MaxNoIter must be greater or equal to 0.");
1625 " Error - MaxNoFailure must be greater or equal to 0.");
1631 " Error - SatisfNoSuccess must be greater or equal to 0.");
1637 " Error - SatisfNoSuccess + MaxNoFailure must be smaller or equal to MaxNoIter.");
1643 " Error - MakeDesiredProj should be 0 or 1.");
1692 const long OrderOfSpline = 3L;
1695 int Status = !
ERROR, DoDesProj, IteratingStop, FlagMaxIter;
1697 long MaxIter, MaxIter1, MaxIter2,
iter;
1698 long Mx, My, Nx, Ny, Nz, indx0, indy0, indz0, indx, indy,
index;
1699 long SizeIm, MaxNumberOfFailures, SatisfNumberOfSuccesses, nSuccess, nFailure;
1700 double *reDftVolume, *imDftVolume, *pntr_ReInp, *pntr_ImInp, *CoefRe, *CoefIm, *par;
1701 double *pntr_par0, *pntr_par1, *pntr_par2, *pntr_par3, *pntr_par4, *pntr_cost;
1702 double *pntr_time, *pntr_FailureIter, *pntr_RedftCompProj, *pntr_ImdftCompProj;
1703 double LambdaScale,
lambda, cost, OldCost, tol_angle, tol_shift;
1704 double OneIterInSeconds, *Parameters, *Gradient, *Hessian;
1705 double *Q1, *Q3, *As, *Ap, *hlp;
1706 double vox_x, vox_y, vox_z, pix_x, pix_y, scx1, scy1, S;
1707 double sum_xx_re, sum_xx_im, dftproj_inp_re, dftproj_inp_im, sc_re, sc_im;
1708 time_t time1, time2, *tp1 =
nullptr, *tp2 =
nullptr;
1716 size_t poolSize = (4 * 16) + (2 * 5) + (1 * 25);
1717 auto pool = std::unique_ptr<double[]>(
new double[poolSize]);
1718 double *poolNext = pool.get();
1719 auto getNextFromPool = [&](
size_t count) {
1720 auto tmp = poolNext;
1725 if (( ! pool) || (
nullptr == poolNext)) {
1752 vox_x = (
double) *par++;
1753 vox_y = (double) *par++;
1754 vox_z = (double) *par;
1757 pix_x = (double) *par++;
1758 pix_y = (double) *par;
1760 scx1 = 2.0 *
PI / ((double) Mx * pix_x);
1761 scy1 = 2.0 *
PI / ((double) My * pix_y);
1763 S = (double)(Nx * Ny * Nz) / (double)(Mx * My);
1770 MaxIter1 = MaxIter - 1L;
1771 MaxIter2 = MaxIter + 1L;
1778 Parameters = getNextFromPool(5);
1781 Parameters[0] = (double)(*par++) *
PI / 180.0;
1782 Parameters[1] = (double)(*par++) *
PI / 180.0;
1783 Parameters[2] = (double)(*par++) *
PI / 180.0;
1784 Parameters[3] = (double)(*par++);
1785 Parameters[4] = (double)(*par);
1788 if (Status ==
ERROR)
1795 if (Status ==
ERROR)
1804 if (Status ==
ERROR)
1814 if (Status ==
ERROR)
1822 Gradient = getNextFromPool(5);
1823 Hessian = getNextFromPool(25);
1824 Q1 = getNextFromPool(16);
1836 hlp += (std::ptrdiff_t)5L;
1838 hlp += (std::ptrdiff_t)5L;
1841 Q3 = getNextFromPool(16);
1851 *hlp = 1.0 / (double) Mx;
1852 hlp += (std::ptrdiff_t)5L;
1853 *hlp = 1.0 / (double) My;
1856 As = getNextFromPool(16);
1857 Ap = getNextFromPool(16);
1868 hlp += (std::ptrdiff_t)5L;
1870 hlp += (std::ptrdiff_t)5L;
1884 hlp += (std::ptrdiff_t)5L;
1890 for (indy = 0L; indy < My; indy++)
1892 for (indx = 0L; indx < Mx; indx++)
1894 index = indy * Mx + indx;
1895 dftproj_inp_re = (double) pntr_ReInp[index];
1896 dftproj_inp_im = (double) pntr_ImInp[index];
1897 sum_xx_re += dftproj_inp_re * dftproj_inp_re;
1898 sum_xx_im += dftproj_inp_im * dftproj_inp_im;
1902 index = (My / 2L) * Mx + (Mx / 2L);
1903 dftproj_inp_re = (double) pntr_ReInp[index];
1904 dftproj_inp_im = (double) pntr_ImInp[index];
1906 sc_re = 1.0 /
sqrt(sum_xx_re + sum_xx_im - dftproj_inp_re * dftproj_inp_re - dftproj_inp_im * dftproj_inp_im);
1909 for (indy = 0L; indy < My; indy++)
1911 for (indx = 0L; indx < Mx; indx++)
1913 index = indy * Mx + indx;
1914 dftproj_inp_re = (double) pntr_ReInp[index];
1915 dftproj_inp_im = (double) pntr_ImInp[index];
1916 pntr_ReInp[
index] = (sc_re * dftproj_inp_re);
1917 pntr_ImInp[
index] = (sc_im * dftproj_inp_im);
1921 pntr_RedftCompProj = Data->
dftProj;
1922 pntr_ImdftCompProj = pntr_RedftCompProj + (std::ptrdiff_t) SizeIm;
1923 for (indy = 0L; indy < My; indy++)
1925 for (indx = 0L; indx < Mx; indx++)
1927 index = indy * Mx + indx;
1928 pntr_RedftCompProj[
index] = 0.0;
1929 pntr_ImdftCompProj[
index] = 0.0;
1934 pntr_par1 = pntr_par0 + (std::ptrdiff_t) MaxIter2;
1935 pntr_par2 = pntr_par1 + (std::ptrdiff_t) MaxIter2;
1936 pntr_par3 = pntr_par2 + (std::ptrdiff_t) MaxIter2;
1937 pntr_par4 = pntr_par3 + (std::ptrdiff_t) MaxIter2;
1938 pntr_cost = Data->
Cost;
1941 for (indx = 0L; indx < MaxIter2; indx++)
1950 *pntr_FailureIter++ = 0.0;
1956 CoefRe, CoefIm, pntr_ReInp, pntr_ImInp, Data->
Weight,
1957 Nx, Ny, Nz, indx0, indy0, indz0, Mx, My,
1958 Ap, As, Q1, Q3, scx1, scy1, S, SizeIm,
1968 OneIterInSeconds = difftime(time2, time1);
1979 pntr_par1 = pntr_par0 + (std::ptrdiff_t) MaxIter2;
1980 pntr_par2 = pntr_par1 + (std::ptrdiff_t) MaxIter2;
1981 pntr_par3 = pntr_par2 + (std::ptrdiff_t) MaxIter2;
1982 pntr_par4 = pntr_par3 + (std::ptrdiff_t) MaxIter2;
1984 pntr_cost = Data->
Cost;
1989 *pntr_par0++ = Parameters[0];
1990 *pntr_par1++ = Parameters[1];
1991 *pntr_par2++ = Parameters[2];
1992 *pntr_par3++ = Parameters[3];
1993 *pntr_par4++ = Parameters[4];
1994 *pntr_cost++ = cost;
1995 *pntr_time++ = OneIterInSeconds;
1998 if ((MaxIter == 0L) && (!DoDesProj))
2010 FlagMaxIter = (MaxIter != 1L);
2019 CoefRe, CoefIm, pntr_ReInp, pntr_ImInp, Data->
Weight,
2020 Nx, Ny, Nz, indx0, indy0, indz0, Mx, My,
2021 Ap, As, Q1, Q3, scx1, scy1, S, SizeIm,
2022 DoDesProj, Data->
dftProj, OldCost, &lambda, LambdaScale,
2023 &iter, tol_angle, tol_shift, &IteratingStop) ==
ERROR)
2032 OneIterInSeconds = difftime(time2, time1);
2034 *pntr_par0++ = Parameters[0];
2035 *pntr_par1++ = Parameters[1];
2036 *pntr_par2++ = Parameters[2];
2037 *pntr_par3++ = Parameters[3];
2038 *pntr_par4++ = Parameters[4];
2039 *pntr_cost++ = cost;
2040 *pntr_time++ = OneIterInSeconds;
2047 if (nSuccess >= SatisfNumberOfSuccesses)
2059 *pntr_FailureIter++ = (iter + 1L);
2063 while ((nFailure <= MaxNumberOfFailures) && (iter < MaxIter1) && FlagMaxIter);
int return_gradhesscost(double *Gradient, double *Hessian, double *cost, double *Parameters, double *CoefRe, double *CoefIm, double *pntr_ReInp, double *pntr_ImInp, double *pntr_Weight, long Nx, long Ny, long Nz, long indx0, long indy0, long indz0, long Mx, long My, double *Left, double *Right, double *Q1, double *Q3, double scx1, double scy1, double S, long SizeIm, int DoDesProj, double *dftCompProj)
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
double getDoubleParam(const char *param, int arg=0)
void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
__host__ __device__ float2 floor(const float2 v)
long * NumberSuccPerformed
int cstregistrationCheck(struct cstregistrationStruct *Data)
int cstregistrationSize(struct cstregistrationStruct *Data)
void Euler_angles2matrix(T alpha, T beta, T gamma, Matrix2D< T > &A, bool homogeneous)
long periodization(long period, long k)
double beta(const double a, const double b)
void sqrt(Image< double > &op)
int VectorScalarProduct(double A[], double B[], double *X, long Lines)
int MatrixTimesVector(double *A, double *B, double *X, long Lines, long Columns)
#define MULTIDIM_ARRAY(v)
int gradhesscost_atpixel(double *Gradient, double *Hessian, double *cost, double Difference, double dp0, double dp1, double dp2, double dp3, double dp4, double Weight)
void defineParams()
Define parameters.
double max_angular_change
#define WRITE_ERROR(FunctionName, String)
double CSTSplineAssignment(MultidimArray< double > &ReDFTVolume, MultidimArray< double > &ImDFTVolume, MultidimArray< double > &image, MultidimArray< double > &weight, Matrix1D< double > &pose_parameters, int max_no_iter)
#define BSPLINE03DIFF1(y, x)
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
MultidimArray< double > imDFTVolume
void CenterFFT(MultidimArray< T > &v, bool forward)
void apply_mask(const MultidimArray< T > &I, MultidimArray< T > &result, T subs_val=0, bool apply_geo=false)
T & getValue(MDLabel label)
const char * getParam(const char *param, int arg=0)
void readParams()
Read argument from command line.
double Euler_distanceBetweenMatrices(const Matrix2D< double > &E1, const Matrix2D< double > &E2)
#define PERIODIZATION(y, period, k)
int AllocateVolumeDouble(double **Volume, long Nx, long Ny, long Nz, int *Status)
int FreeVolumeDouble(double **Volume)
void addExampleLine(const char *example, bool verbatim=true)
MultidimArray< double > reDFTVolume
int verbose
Verbosity level.
int SingularValueBackSubstitution(double *U, double W[], double *V, long Lines, long Columns, double B[], double X[], int *Status)
const MultidimArray< double > & get_cont_mask() const
long * NumberIterPerformed
int MatrixTranspose(double *A, double *At, long Lines, long Columns)
double gaussian_DFT_sigma
int levenberg_cst(double beta[], double *alpha, double *cost, double a[], double *CoefRe, double *CoefIm, double *pntr_ReInp, double *pntr_ImInp, double *pntr_Weight, long Nx, long Ny, long Nz, long indx0, long indy0, long indz0, long Mx, long My, double *Left, double *Right, double *Q1, double *Q3, double scx1, double scy1, double S, long SizeIm, int DoDesProj, double *dftCompProj, double OldCost, double *lambda, double LambdaScale, long *iter, double tol_angle, double tol_shift, int *IteratingStop)
void setValue(MDLabel label, const T &d, bool addLabel=true)
double * OutputParameters
void generate_mask(bool apply_geo=false)
#define MATRIX1D_ARRAY(v)
double psi(const double x)
int SingularValueDecomposition(double *U, long Lines, long Columns, double W[], double *V, long MaxIterations, int *Status)
ProgAngularContinuousAssign()
Empty constructor.
int GetIdentitySquareMatrix(double *A, long Size)
double gaussian_Real_sigma
long mirroring(long period, long k)
int multiply_3Matrices(double *A, double *B, double *C, double *X, long Lines, long CommonSizeH, long CommonSizeW, long Columns)
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
void addUsageLine(const char *line, bool verbatim=false)
int cstregistration(struct cstregistrationStruct *Data)
int getIntParam(const char *param, int arg=0)
#define MATRIX2D_ARRAY(m)
void addParamsLine(const String &line)
std::map< String, CommentList > defaultComments
long * NumberFailPerformed