// Check whether projection directions are unique ================================= bool directions_are_unique(double rot, double tilt, double rot2, double tilt2, double rot_limit, double tilt_limit, SymList &SL, bool include_mirrors, Matrix2D<double> &Laux, Matrix2D<double> &Raux) { bool are_unique = true; double rot2p, tilt2p, psi2p, psi2 = 0.; double diff_rot, diff_tilt; int isymmax=SL.symsNo(); for (int isym = 0; isym <= isymmax; isym++) { if (isym == 0) { rot2p = rot2; tilt2p = tilt2; psi2p = psi2; } else { SL.getMatrices(isym - 1, Laux, Raux,false); Euler_apply_transf(Laux, Raux, rot2, tilt2, psi2, rot2p, tilt2p, psi2p); } double aux=rot - rot2p; diff_rot = fabs(realWRAP(aux, -180, 180)); aux=tilt - tilt2p; diff_tilt = fabs(realWRAP(aux, -180, 180)); if ((rot_limit - diff_rot) > 1e-3 && (tilt_limit - diff_tilt) > 1e-3) are_unique = false; Euler_another_set(rot2p, tilt2p, psi2p, rot2p, tilt2p, psi2p); aux=rot - rot2p; diff_rot = fabs(realWRAP(aux, -180, 180)); aux=tilt - tilt2p; diff_tilt = fabs(realWRAP(aux, -180, 180)); if ((rot_limit - diff_rot) > 1e-3 && (tilt_limit - diff_tilt) > 1e-3) are_unique = false; if (!include_mirrors) { Euler_up_down(rot2p, tilt2p, psi2p, rot2p, tilt2p, psi2p); aux=rot - rot2p; diff_rot = fabs(realWRAP(aux, -180, 180)); aux=tilt - tilt2p; diff_tilt = fabs(realWRAP(aux, -180, 180)); if ((rot_limit - diff_rot) > 1e-3 && (tilt_limit - diff_tilt) > 1e-3) are_unique = false; Euler_another_set(rot2p, tilt2p, psi2p, rot2p, tilt2p, psi2p); aux=rot - rot2p; diff_rot = fabs(realWRAP(aux, -180, 180)); aux=tilt - tilt2p; diff_tilt = fabs(realWRAP(aux, -180, 180)); if ((rot_limit - diff_rot) > 1e-3 && (tilt_limit - diff_tilt) > 1e-3) are_unique = false; } } return are_unique; }
int find_nearest_direction(double rot1, double tilt1, std::vector<double> &rotList, std::vector<double> &tiltList, SymList &SL, Matrix2D<double> &Laux, Matrix2D<double> &Raux) { int optdir; double dist, mindist; double newrot, newtilt, newpsi; optdir = -1; mindist = 9999.; int imax=SL.symsNo(); size_t nmax=rotList.size(); double *ptrRot=NULL; double *ptrTilt=NULL; if (nmax>0) { ptrRot=&rotList[0]; ptrTilt=&tiltList[0]; } for (size_t n=0; n<nmax; ++n, ++ptrRot, ++ptrTilt) { dist = distance_directions(rot1, tilt1, *ptrRot, *ptrTilt, false); if (dist < mindist) { mindist = dist; optdir = n; } for (int i = 0; i < imax; i++) { SL.getMatrices(i, Laux, Raux, false); Euler_apply_transf(Laux, Raux, rot1, tilt1, 0., newrot, newtilt, newpsi); dist = distance_directions(newrot, newtilt, *ptrRot, *ptrTilt, false); if (dist < mindist) { mindist = dist; optdir = n; } } } return optdir; }