27 #ifndef CORE_TRANSFORMATIONS_H 28 #define CORE_TRANSFORMATIONS_H 47 bool only_apply_shifts =
false);
49 bool getLoopRange(
double value,
double min,
double max,
double delta,
int loopLimit,
int &minIter,
int &maxIter);
64 T &scale, T &shiftX, T &shiftY,
69 double &scale,
double &shiftX,
double &shiftY,
70 double &shiftZ,
double &rot,
double &tilt,
double &
psi);
136 bool homogeneous=
true);
150 bool homogeneous=
true);
190 bool homogeneous=
true);
199 template<
typename T1,
typename T,
bool wrap>
206 const double Aref00=
MAT_ELEM(Aref,0,0);
207 const double Aref10=
MAT_ELEM(Aref,1,0);
210 const double cen_y = (int)(
YSIZE(V2) / 2);
211 const double cen_x = (int)(
XSIZE(V2) / 2);
212 const double cen_yp = (int)(
YSIZE(V1) / 2);
213 const double cen_xp = (int)(
XSIZE(V1) / 2);
214 const double minxp = -cen_xp;
215 const double minyp = -cen_yp;
218 const double maxxp =
XSIZE(V1) - cen_xp - 1;
219 const double maxyp =
YSIZE(V1) - cen_yp - 1;
222 const int Xdim =
XSIZE(V1);
223 const int Ydim =
YSIZE(V1);
230 #ifdef DEBUG_APPLYGEO 231 std::cout <<
"A\n" << Aref << std::endl
232 <<
"(cen_x ,cen_y )=(" << cen_x <<
"," << cen_y <<
")\n" 233 <<
"(cen_xp,cen_yp)=(" << cen_xp <<
"," << cen_yp <<
")\n" 234 <<
"(min_xp,min_yp)=(" << minxp <<
"," << minyp <<
")\n" 235 <<
"(max_xp,max_yp)=(" << maxxp <<
"," << maxyp <<
")\n";
238 const double x = -cen_x;
240 for (
size_t i = 0;
i <
YSIZE(V2);
i++)
258 #ifdef DEBUG_APPLYGEO 260 std::cout <<
"Computing (" <<
i <<
"," <<
j <<
")\n";
261 std::cout <<
" (y, x) =(" << y <<
"," << x <<
")\n" 262 <<
" before wrapping (y',x')=(" << yp <<
"," << xp <<
") " 270 xp =
realWRAP(xp, minxp - 0.5, maxxp + 0.5);
275 yp =
realWRAP(yp, minyp - 0.5, maxyp + 0.5);
278 #ifdef DEBUG_APPLYGEO 280 std::cout <<
" after wrapping (y',x')=(" << yp <<
"," << xp <<
") " 282 std::cout <<
" Interp = " << interp << std::endl;
293 double wx = xp + cen_xp;
294 double wy = yp + cen_yp;
301 double wx_1 = 1 - wx;
302 double wy_1 = 1 - wy;
310 #ifdef DEBUG_APPLYGEO 311 std::cout <<
" From (" << n1 <<
"," << m1 <<
") and (" 312 << n2 <<
"," << m2 <<
")\n";
313 std::cout <<
" wx= " << wx <<
" wy= " << wy
323 dAij(V2,
i, j) = (T) (v1 + v2 + v3 + v4);
325 std::cout <<
" val= " <<
dAij(V2,
i, j) << std::endl;
337 int globalMin=0, globalMax=
XSIZE(V2);
340 int minX, maxX, minY, maxY;
368 if ((globalMax >= 0) && ((
size_t)globalMax >
XSIZE(V2)))
370 globalMax =
XSIZE(V2);
373 xp += globalMin*Aref00;
374 yp += globalMin*Aref10;
378 #pragma simd reduction (+:xp,yp) 379 for (
int j=globalMin;
j<globalMax ;
j++)
381 #ifdef DEBUG_APPLYGEO 383 std::cout <<
"Computing (" <<
i <<
"," <<
j <<
")\n";
384 std::cout <<
" (y, x) =(" << y <<
"," << x <<
")\n" 385 <<
" before wrapping (y',x')=(" << yp <<
"," << xp <<
") " 388 std::cout <<
" after wrapping (y',x')=(" << yp <<
"," << xp <<
") " 390 std::cout <<
" Interp = " << interp << std::endl;
401 double wx = xp + cen_xp;
405 double wy = yp + cen_yp;
410 #ifdef DEBUG_APPLYGEO 411 std::cout <<
" From (" << n1 <<
"," << m1 <<
") and (" 412 << n2 <<
"," << m2 <<
")\n";
413 std::cout <<
" wx= " << wx <<
" wy= " << wy << std::endl;
420 double wx_1 = (1-wx);
421 double wy_1 = (1-wy);
422 double aux2=wy_1* wx_1 ;
425 if ((wx != 0) && ((m2 < 0) || ((
size_t)m2 < V1.
xdim)))
428 if ((wy != 0) && ((n2 < 0) || ((
size_t)n2 < V1.
ydim)))
433 if ((wx != 0) && ((m2 < 0) || ((
size_t)m2 < V1.
xdim)))
437 dAij(V2,
i, j) = (T) tmp;
440 std::cout <<
" val= " <<
dAij(V2,
i, j) << std::endl;
530 template<
typename T1,
typename T,
typename T2>
590 if (1 == SplineDegree) {
592 applyGeometryImpl::applyGeometry2DDegree1<T1, T, true>(V2, V1, Aref);
594 applyGeometryImpl::applyGeometry2DDegree1<T1, T, false>(V2, V1, Aref);
604 double cen_y = (int)(
YSIZE(V2) / 2);
605 double cen_x = (int)(
XSIZE(V2) / 2);
606 double cen_yp = (int)(
YSIZE(V1) / 2);
607 double cen_xp = (int)(
XSIZE(V1) / 2);
608 double minxp = -cen_xp;
609 double minyp = -cen_yp;
612 double maxxp =
XSIZE(V1) - cen_xp - 1;
613 double maxyp =
YSIZE(V1) - cen_yp - 1;
616 size_t Xdim =
XSIZE(V1);
617 size_t Ydim =
YSIZE(V1);
619 if (SplineDegree > 1)
622 if (BcoeffsPtr!=NULL)
623 BcoeffsToUse=BcoeffsPtr;
627 BcoeffsToUse = &Bcoeffs;
638 #ifdef DEBUG_APPLYGEO 639 std::cout <<
"A\n" << Aref << std::endl
640 <<
"(cen_x ,cen_y )=(" << cen_x <<
"," << cen_y <<
")\n" 641 <<
"(cen_xp,cen_yp)=(" << cen_xp <<
"," << cen_yp <<
")\n" 642 <<
"(min_xp,min_yp)=(" << minxp <<
"," << minyp <<
")\n" 643 <<
"(max_xp,max_yp)=(" << maxxp <<
"," << maxyp <<
")\n";
648 for (
size_t i = 0;
i <
YSIZE(V2);
i++)
658 int globalMin=0, globalMax=
XSIZE(V2);
663 int minX, maxX, minY, maxY;
691 if ((globalMax >= 0) && ((
size_t)globalMax >
XSIZE(V2)))
693 globalMax =
XSIZE(V2);
696 xp += globalMin*Aref00;
697 yp += globalMin*Aref10;
708 for (
int j=globalMin;
j<globalMax ;
j++)
710 #ifdef DEBUG_APPLYGEO 712 std::cout <<
"Computing (" <<
i <<
"," <<
j <<
")\n";
713 std::cout <<
" (y, x) =(" << y <<
"," << x <<
")\n" 714 <<
" before wrapping (y',x')=(" << yp <<
"," << xp <<
") " 722 xp =
realWRAP(xp, minxp - 0.5, maxxp + 0.5);
727 yp =
realWRAP(yp, minyp - 0.5, maxyp + 0.5);
730 #ifdef DEBUG_APPLYGEO 732 std::cout <<
" after wrapping (y',x')=(" << yp <<
"," << xp <<
") " 734 std::cout <<
" Interp = " << interp << std::endl;
748 double wx = xp + cen_xp;
752 double wy = yp + cen_yp;
758 if ((m2 >= 0) && ((size_t)m2 >= Xdim))
760 if ((n2 >=0) && ((size_t)n2 >= Ydim))
763 #ifdef DEBUG_APPLYGEO 764 std::cout <<
" From (" << n1 <<
"," << m1 <<
") and (" 765 << n2 <<
"," << m2 <<
")\n";
766 std::cout <<
" wx= " << wx <<
" wy= " << wy
775 double wx_1 = (1-wx);
776 double wy_1 = (1-wy);
777 double aux2=wy_1* wx_1 ;
780 if ((wx != 0) && ((m2 < 0) || ((
size_t)m2 < V1.
xdim)))
783 if ((wy != 0) && ((n2 < 0) || ((
size_t)n2 < V1.
ydim)))
788 if ((wx != 0) && ((m2 < 0) || ((
size_t)m2 < V1.
xdim)))
792 dAij(V2,
i, j) = (T) tmp;
794 else if (SplineDegree==0)
798 else if (SplineDegree==3)
809 std::cout <<
" val= " <<
dAij(V2,
i, j) << std::endl;
821 #pragma simd reduction (+:xp,yp) 822 for (
int j=globalMin;
j<globalMax ;
j++)
824 #ifdef DEBUG_APPLYGEO 826 std::cout <<
"Computing (" <<
i <<
"," <<
j <<
")\n";
827 std::cout <<
" (y, x) =(" << y <<
"," << x <<
")\n" 828 <<
" before wrapping (y',x')=(" << yp <<
"," << xp <<
") " 831 std::cout <<
" after wrapping (y',x')=(" << yp <<
"," << xp <<
") " 833 std::cout <<
" Interp = " << interp << std::endl;
844 double wx = xp + cen_xp;
848 double wy = yp + cen_yp;
853 #ifdef DEBUG_APPLYGEO 854 std::cout <<
" From (" << n1 <<
"," << m1 <<
") and (" 855 << n2 <<
"," << m2 <<
")\n";
856 std::cout <<
" wx= " << wx <<
" wy= " << wy << std::endl;
863 double wx_1 = (1-wx);
864 double wy_1 = (1-wy);
865 double aux2=wy_1* wx_1 ;
868 if ((wx != 0) && ((m2 < 0) || ((
size_t)m2 < V1.
xdim)))
871 if ((wy != 0) && ((n2 < 0) || ((
size_t)n2 < V1.
ydim)))
876 if ((wx != 0) && ((m2 < 0) || ((
size_t)m2 < V1.
xdim)))
880 dAij(V2,
i, j) = (T) tmp;
883 std::cout <<
" val= " <<
dAij(V2,
i, j) << std::endl;
891 else if (SplineDegree==0)
893 #pragma simd reduction (+:xp,yp) 894 for (
int j=globalMin;
j<globalMax ;
j++)
896 #ifdef DEBUG_APPLYGEO 898 std::cout <<
"Computing (" <<
i <<
"," <<
j <<
")\n";
899 std::cout <<
" (y, x) =(" << y <<
"," << x <<
")\n" 900 <<
" before wrapping (y',x')=(" << yp <<
"," << xp <<
") " 903 std::cout <<
" after wrapping (y',x')=(" << yp <<
"," << xp <<
") " 905 std::cout <<
" Interp = " << interp << std::endl;
912 std::cout <<
" val= " <<
dAij(V2,
i, j) << std::endl;
920 else if (SplineDegree==3)
922 for (
int j=globalMin;
j<globalMax ;
j++)
924 #ifdef DEBUG_APPLYGEO 926 std::cout <<
"Computing (" <<
i <<
"," <<
j <<
")\n";
927 std::cout <<
" (y, x) =(" << y <<
"," << x <<
")\n" 928 <<
" before wrapping (y',x')=(" << yp <<
"," << xp <<
") " 931 std::cout <<
" after wrapping (y',x')=(" << yp <<
"," << xp <<
") " 933 std::cout <<
" Interp = " << interp << std::endl;
942 std::cout <<
" val= " <<
dAij(V2,
i, j) << std::endl;
952 for (
int j=globalMin;
j<globalMax ;
j++)
954 #ifdef DEBUG_APPLYGEO 956 std::cout <<
"Computing (" <<
i <<
"," <<
j <<
")\n";
957 std::cout <<
" (y, x) =(" << y <<
"," << x <<
")\n" 958 <<
" before wrapping (y',x')=(" << yp <<
"," << xp <<
") " 961 std::cout <<
" after wrapping (y',x')=(" << yp <<
"," << xp <<
") " 963 std::cout <<
" Interp = " << interp << std::endl;
971 std::cout <<
" val= " <<
dAij(V2,
i, j) << std::endl;
987 size_t m1, n1, o1, m2, n2, o2;
988 double x,
y,
z, xp, yp, zp;
989 double minxp, minyp, maxxp, maxyp, minzp, maxzp;
990 double cen_x, cen_y, cen_z, cen_xp, cen_yp, cen_zp;
997 cen_z = (int)(V2.
zdim / 2);
998 cen_y = (int)(V2.
ydim / 2);
999 cen_x = (int)(V2.
xdim / 2);
1000 cen_zp = (int)(V1.
zdim / 2);
1001 cen_yp = (int)(V1.
ydim / 2);
1002 cen_xp = (int)(V1.
xdim / 2);
1006 maxxp = V1.
xdim - cen_xp - 1;
1007 maxyp = V1.
ydim - cen_yp - 1;
1008 maxzp = V1.
zdim - cen_zp - 1;
1012 std::cout <<
"Geometry 2 center=(" 1013 << cen_z <<
"," << cen_y <<
"," << cen_x <<
")\n" 1014 <<
"Geometry 1 center=(" 1015 << cen_zp <<
"," << cen_yp <<
"," << cen_xp <<
")\n" 1017 << minzp <<
"," << minyp <<
"," << minxp <<
")\n" 1019 << maxzp <<
"," << maxyp <<
"," << maxxp <<
")\n" 1023 if (SplineDegree > 1)
1026 if (BcoeffsPtr!=NULL)
1027 BcoeffsToUse=BcoeffsPtr;
1031 BcoeffsToUse = &Bcoeffs;
1044 for (
size_t k = 0;
k < V2.
zdim;
k++)
1045 for (
size_t i = 0;
i < V2.
ydim;
i++)
1060 for (
size_t j = 0;
j < V2.
xdim;
j++)
1067 bool show_debug =
false;
1068 if ((
i == 0 &&
j == 0 &&
k == 0) ||
1073 std::cout <<
"(x,y,z)-->(xp,yp,zp)= " 1074 <<
"(" << x <<
"," << y <<
"," << z <<
") " 1075 <<
"(" << xp <<
"," << yp <<
"," << zp <<
")\n";
1089 xp =
realWRAP(xp, minxp - 0.5, maxxp + 0.5);
1092 yp =
realWRAP(yp, minyp - 0.5, maxyp + 0.5);
1095 zp =
realWRAP(zp, minzp - 0.5, maxzp + 0.5);
1097 else if (x_isOut || y_isOut || z_isOut)
1102 if (SplineDegree == 1)
1128 std::cout <<
"After wrapping(xp,yp,zp)= " 1129 <<
"(" << xp <<
"," << yp <<
"," << zp <<
")\n";
1130 std::cout <<
"(m1,n1,o1)-->(m2,n2,o2)=" 1131 <<
"(" << m1 <<
"," << n1 <<
"," << o1 <<
") " 1132 <<
"(" << m2 <<
"," << n2 <<
"," << o2 <<
")\n";
1133 std::cout <<
"(wx,wy,wz)=" 1134 <<
"(" << wx <<
"," << wy <<
"," << wz <<
")\n";
1147 double aux1=wz_1 * wy_1;
1148 double aux2=aux1*wx_1;
1151 if (wx != 0 && m2 < V1.
xdim)
1154 if (wy != 0 && n2 < V1.
ydim)
1159 if (wx != 0 && m2 < V1.
xdim)
1163 if (wz != 0 && o2 < V1.
zdim)
1168 if (wx != 0 && m2 < V1.
xdim)
1170 if (wy != 0 && n2 < V1.
ydim)
1175 if (wx != 0 && m2 < V1.
xdim)
1204 "tmp= " << tmp << std::endl;
1209 else if (SplineDegree==0)
1233 template<
typename T>
1238 bool wrap, T outside = 0)
1240 #define APPLYGEO(type) applyGeometry(SplineDegree,V2, (*(MultidimArray<type>*)(V1.im)), A, inv, wrap, outside); 1252 template<
typename T>
1256 bool wrap, T outside = 0)
1260 applyGeometry(SplineDegree, V1, aux, A, inv, wrap, outside);
1276 bool wrap, std::complex<double> outside);
1283 bool wrap,
double outside);
1292 template<
typename T>
1306 template <
typename T>
1322 template<
typename T>
1326 double ang,
char axis =
'Z',
1327 bool wrap = xmipp_transformation::DONT_WRAP, T outside = 0)
1341 applyGeometry(SplineDegree, V2, V1, tmp, xmipp_transformation::IS_NOT_INV, wrap, outside);
1349 template<
typename T>
1352 double ang,
char axis =
'Z',
1353 bool wrap = xmipp_transformation::DONT_WRAP, T outside = 0)
1357 rotate(SplineDegree, V1, aux, ang,
axis, wrap, outside);
1371 template<
typename T>
1376 bool wrap = xmipp_transformation::WRAP, T outside = 0)
1385 applyGeometry(SplineDegree, V2, V1, tmp, xmipp_transformation::IS_INV, wrap, outside);
1393 template<
typename T>
1397 bool wrap = xmipp_transformation::WRAP, T outside = 0)
1401 translate(SplineDegree, V1, aux, v, wrap, outside);
1410 template<
typename T>
1414 bool wrap = xmipp_transformation::WRAP)
1421 translate(SplineDegree, V2, V1, center, wrap, 0);
1429 template<
typename T>
1432 bool wrap = xmipp_transformation::WRAP)
1450 template<
typename T1,
typename T>
1454 size_t Xdim,
size_t Ydim,
size_t Zdim = 1)
1456 if (Xdim ==
XSIZE(V1) && Ydim ==
YSIZE(V1) && \
1467 tmp(0, 0) = (double) Xdim / (
double)
XSIZE(V1);
1468 tmp(1, 1) = (double) Ydim / (
double)
YSIZE(V1);
1474 tmp(0, 0) = (double) Xdim / (
double)
XSIZE(V1);
1475 tmp(1, 1) = (double) Ydim / (
double)
YSIZE(V1);
1476 tmp(2, 2) = (double) Zdim / (
double)
ZSIZE(V1);
1483 applyGeometry(SplineDegree, V2, V1, tmp, xmipp_transformation::IS_NOT_INV, xmipp_transformation::WRAP, (T)0);
1496 template<
typename T>
1501 #define SCALETOSIZE(type) scaleToSize(SplineDegree,V2,*((MultidimArray<type>*)(V1.im)),Xdim,Ydim,Zdim); 1516 template<
typename T>
1521 #define SCALETOSIZE(type) scaleToSize(SplineDegree,MULTIDIM_ARRAY_TYPE(V2,type),V1,Xdim,Ydim,Zdim); 1545 template<
typename T>
1548 int Xdim,
int Ydim,
int Zdim = 1)
1551 scaleToSize(SplineDegree, V1, aux, Xdim, Ydim, Zdim);
1556 int Xdim,
int Ydim,
int Zdim = 1);
1563 int Xdim,
int Ydim,
int Zdim = 1);
1568 int Xdim,
int Ydim,
int Zdim = 1);
1577 template<
typename T>
1588 template<
typename T>
1596 template<
typename T>
1606 for (
int i = 0;
i < levels;
i++)
1620 template<
typename T>
1639 template<
typename T>
1649 for (
int i = 0;
i < levels;
i++)
1674 template<
typename T>
1710 template<
typename T>
1715 const bool& rounding =
false)
1720 if (center_of_rot.
size() < 3)
1731 distances(0) = (int)
floor(
sqrt(x * x + y * y + z * z));
1734 distances(1) = (int)
floor(
sqrt(x * x + y * y + z * z));
1737 distances(2) = (int)
floor(
sqrt(x * x + y * y + z * z));
1740 distances(3) = (int)
floor(
sqrt(x * x + y * y + z * z));
1743 distances(4) = (int)
floor(
sqrt(x * x + y * y + z * z));
1746 distances(5) = (int)
floor(
sqrt(x * x + y * y + z * z));
1749 distances(6) = (int)
floor(
sqrt(x * x + y * y + z * z));
1752 distances(7) = (int)
floor(
sqrt(x * x + y * y + z * z));
1766 ZZ(idx) =
k -
ZZ(center_of_rot);
1767 YY(idx) =
i -
YY(center_of_rot);
1768 XX(idx) =
j -
XX(center_of_rot);
1788 template<
typename T>
1793 const bool& rounding =
false)
1798 if (center_of_rot.
size() < 3)
1809 distances(0) = (int)
floor(
sqrt(x * x + y * y + z * z));
1812 distances(1) = (int)
floor(
sqrt(x * x + y * y + z * z));
1815 distances(2) = (int)
floor(
sqrt(x * x + y * y + z * z));
1818 distances(3) = (int)
floor(
sqrt(x * x + y * y + z * z));
1821 distances(4) = (int)
floor(
sqrt(x * x + y * y + z * z));
1824 distances(5) = (int)
floor(
sqrt(x * x + y * y + z * z));
1827 distances(6) = (int)
floor(
sqrt(x * x + y * y + z * z));
1830 distances(7) = (int)
floor(
sqrt(x * x + y * y + z * z));
1841 ZZ(idx) =
k -
ZZ(center_of_rot);
1842 YY(idx) =
i -
YY(center_of_rot);
1843 XX(idx) =
j -
XX(center_of_rot);
1853 template<
typename T>
1879 template<
typename T>
1883 inCentered.
alias(in);
1894 for (
double ang=0; ang<
TWOPI; ang+=TWOPI/72)
1896 double x=
j*cos(ang);
1897 double y=
j*sin(ang);
1911 template<
typename T>
1916 bool rounding =
false);
1929 int SplineDegree = 3);
1940 int SplineDegree = 3);
1950 int SplineDegree = 3);
void min(Image< double > &op1, const Image< double > &op2)
#define A2D_ELEM(v, i, j)
__host__ __device__ float2 floor(const float2 v)
#define REPORT_ERROR(nerr, ErrormMsg)
T interpolatedElementBSpline2D_Degree3(double x, double y) const
Problem with matrix size.
void resizeNoCopy(const MultidimArray< T1 > &v)
void sqrt(Image< double > &op)
T interpolatedElementBSpline3D(double x, double y, double z, int SplineDegree=3) const
#define DIRECT_A2D_ELEM(v, i, j)
void inv(Matrix2D< T > &result) const
#define SAME_SHAPE3D(v1, v2)
#define FOR_ALL_DIRECT_ELEMENTS_IN_ARRAY1D(v)
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
void centerOfMass(Matrix1D< double > ¢er, void *mask=NULL, size_t n=0)
#define MAT_ELEM(m, i, j)
#define A3D_ELEM(V, k, i, j)
#define FOR_ALL_ELEMENTS_IN_ARRAY3D(V)
void applyGeometry2DDegree1(MultidimArray< T > &__restrict__ V2, const MultidimArray< T1 > &__restrict__ V1, const Matrix2D< double > &Aref)
Incorrect argument received.
#define XMIPP_EQUAL_ACCURACY
void resize(size_t Xdim, bool copy=true)
void max(Image< double > &op1, const Image< double > &op2)
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
#define dAkij(V, k, i, j)
#define DIRECT_MULTIDIM_ELEM(v, n)
T interpolatedElement3D(double x, double y, double z, T outside_value=(T) 0) const
void alias(const MultidimArray< T > &m)
#define DIRECT_A3D_ELEM(v, k, i, j)
#define XMIPP_RANGE_OUTSIDE(x, min, max)
T interpolatedElementBSpline2D(double x, double y, int SplineDegree=3) const
TYPE distance(struct Point_T *p, struct Point_T *q)
void typeCast(const Matrix1D< T1 > &v1, Matrix1D< T2 > &v2)
double psi(const double x)
#define realWRAP(x, x0, xF)
#define XMIPP_RANGE_OUTSIDE_FAST(x, min, max)
Incorrect MultidimArray dimensions.
void initZeros(const MultidimArray< T1 > &op)
Incorrect value received.
#define SWITCHDATATYPE(datatype, OP)