double spatial_Bspline03_integralf(double alpha) { XX(global_aux) = XX(global_r) + alpha * XX(global_u); YY(global_aux) = YY(global_r) + alpha * YY(global_u); ZZ(global_aux) = ZZ(global_r) + alpha * ZZ(global_u); return spatial_Bspline03LUT(global_aux); }
void actualPhaseFlip(MultidimArray<double> &I, CTFDescription ctf) { // Perform the Fourier transform FourierTransformer transformer; MultidimArray< std::complex<double> > M_inFourier; transformer.FourierTransform(I,M_inFourier,false); Matrix1D<double> freq(2); // Frequencies for Fourier plane int yDim=YSIZE(I); int xDim=XSIZE(I); double iTm=1.0/ctf.Tm; for (size_t i=0; i<YSIZE(M_inFourier); ++i) { FFT_IDX2DIGFREQ(i, yDim, YY(freq)); YY(freq) *= iTm; for (size_t j=0; j<XSIZE(M_inFourier); ++j) { FFT_IDX2DIGFREQ(j, xDim, XX(freq)); XX(freq) *= iTm; ctf.precomputeValues(XX(freq),YY(freq)); if (ctf.getValuePureWithoutDampingAt()<0) DIRECT_A2D_ELEM(M_inFourier,i,j)*=-1; } } // Perform inverse Fourier transform and finish transformer.inverseFourierTransform(); }
// Computes sum of the values of a unitary blob on grid points. The blob is // supposed to be at the origin of the absolute coordinate system double sum_blob_SimpleGrid(const struct blobtype &blob, const SimpleGrid &grid, const Matrix2D<double> *D) { SPEED_UP_temps012; Matrix1D<double> gr(3), ur(3), corner1(3), corner2(3); double actual_radius; int i, j, k; double sum = 0.0; // Compute the limits of the blob in the grid coordinate system grid.universe2grid(vectorR3(-blob.radius, -blob.radius, -blob.radius), corner1); grid.universe2grid(vectorR3(blob.radius, blob.radius, blob.radius), corner2); if (D != NULL) box_enclosing(corner1, corner2, *D, corner1, corner2); // Compute the sum in the points inside the grid // The integer part of the vectors is taken for not picking points // just in the border of the blob, which we know they are 0. for (i = (int)XX(corner1); i <= (int)XX(corner2); i++) for (j = (int)YY(corner1); j <= (int)YY(corner2); j++) for (k = (int)ZZ(corner1); k <= (int)ZZ(corner2); k++) { VECTOR_R3(gr, i, j, k); grid.grid2universe(gr, ur); if (D != NULL) M3x3_BY_V3x1(ur, *D, ur); actual_radius = ur.module(); if (actual_radius < blob.radius) sum += kaiser_value(actual_radius, blob.radius, blob.alpha, blob.order); } return sum; }
// Apply transformation --------------------------------------------------- void applyTransformation(const MultidimArray<double> &V2, MultidimArray<double> &Vaux, double *p) { Matrix1D<double> r(3); Matrix2D<double> A, Aaux; double greyScale = p[0]; double greyShift = p[1]; double rot = p[2]; double tilt = p[3]; double psi = p[4]; double scale = p[5]; ZZ(r) = p[6]; YY(r) = p[7]; XX(r) = p[8]; Euler_angles2matrix(rot, tilt, psi, A, true); translation3DMatrix(r,Aaux); A = A * Aaux; scale3DMatrix(vectorR3(scale, scale, scale),Aaux); A = A * Aaux; applyGeometry(LINEAR, Vaux, V2, A, IS_NOT_INV, WRAP); if (greyScale!=1 || greyShift!=0) FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(Vaux) DIRECT_MULTIDIM_ELEM(Vaux,n)=DIRECT_MULTIDIM_ELEM(Vaux,n)*greyScale+greyShift; }
static int bloch_jacobian(long int N, realtype t, N_Vector M, N_Vector fM, DlsMat J, void *user_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3) { struct bloch_sim *bs = (struct bloch_sim*)user_data; int i; for (i=0; i < bs->num_cells; ++i) { realtype dw = bs->cell_frequencies[i] - bs->w_avg; realtype w_1 = bs->rf_on ? bs->w_1 : 0.0; XX(J,i) = -1 / bs->T_2; XY(J,i) = dw; XZ(J,i) = 0.0; YX(J,i) = -dw; YY(J,i) = -1 / bs->T_2; YZ(J,i) = w_1; ZX(J,i) = 0.0; ZY(J,i) = -w_1; ZZ(J,i) = -1 / bs->T_1; } return 0; }
std::string Ioss::Sym_Tensor_21::label(int which, const char) const { assert(which > 0 && which <= component_count()); switch(which) { case 1: return XX(); case 2: return YY(); case 3: return XY(); default: return ""; } }
NOX::Abstract::Group::ReturnType LOCA::BorderedSolver::Nested::applyInverseTranspose( Teuchos::ParameterList& params, const NOX::Abstract::MultiVector* F, const NOX::Abstract::MultiVector::DenseMatrix* G, NOX::Abstract::MultiVector& X, NOX::Abstract::MultiVector::DenseMatrix& Y) const { bool isZeroF = (F == NULL); bool isZeroG = (G == NULL); if (isZeroF && isZeroG) { X.init(0.0); Y.putScalar(0.0); } int num_cols = X.numVectors(); Teuchos::RCP<NOX::Abstract::MultiVector> FF; if (!isZeroF) FF = unbordered_grp->getX().createMultiVector(num_cols); NOX::Abstract::MultiVector::DenseMatrix GG(myWidth, num_cols); GG.putScalar(0.0); if (!isZeroF) { NOX::Abstract::MultiVector::DenseMatrix GG1(Teuchos::View, GG, underlyingWidth, num_cols, 0, 0); grp->extractSolutionComponent(*F, *FF); grp->extractParameterComponent(false, *F, GG1); } if (!isZeroG) { NOX::Abstract::MultiVector::DenseMatrix GG2(Teuchos::View, GG, numConstraints, num_cols, underlyingWidth, 0); GG2.assign(*G); } Teuchos::RCP<NOX::Abstract::MultiVector> XX = unbordered_grp->getX().createMultiVector(num_cols); NOX::Abstract::MultiVector::DenseMatrix YY(myWidth, num_cols); NOX::Abstract::MultiVector::DenseMatrix YY1(Teuchos::View, YY, underlyingWidth, num_cols, 0, 0); NOX::Abstract::MultiVector::DenseMatrix YY2(Teuchos::View, YY, numConstraints, num_cols, underlyingWidth, 0); NOX::Abstract::Group::ReturnType status = solver->applyInverseTranspose(params, FF.get(), &GG, *XX, YY); Y.assign(YY2); grp->loadNestedComponents(*XX, YY1, X); return status; }
/* Sum spline on a grid ---------------------------------------------------- */ double sum_spatial_Bspline03_SimpleGrid(const SimpleGrid &grid) { Matrix1D<double> gr(3), ur(3), corner1(3), corner2(3); int i, j, k; double sum = 0.0; // Compute the limits of the spline in the grid coordinate system grid.universe2grid(vectorR3(-2.0, -2.0, -2.0), corner1); grid.universe2grid(vectorR3(2.0, 2.0, 2.0), corner2); // Compute the sum in the points inside the grid // The integer part of the vectors is taken for not picking points // just in the border of the spline, which we know they are 0. for (i = (int)XX(corner1); i <= (int)XX(corner2); i++) for (j = (int)YY(corner1); j <= (int)YY(corner2); j++) for (k = (int)ZZ(corner1); k <= (int)ZZ(corner2); k++) { VECTOR_R3(gr, i, j, k); grid.grid2universe(gr, ur); sum += spatial_Bspline03(ur); } return sum; }
void do_the_thing(t_env *e, float angle, int length, int change) { (void)change; while (e->inc < 13) { // length = LY - e->yn; length = e->b; draw_polar(e->xn, e->yn, 270, length, e, VIOLET); length = e->mp - e->xn; e->mp = e->xn; draw_polar(XO, YO, 180, length, e, BLUE); length = get_both(XX(1), YY(1), LX, LY, e); draw_polar(XO, YO, angle, length, e, ORANGE); } }
std::string Ioss::Matrix_33::label(int which, const char) const { assert(which > 0 && which <= component_count()); switch(which) { case 1: return XX(); case 2: return XY(); case 3: return XZ(); case 4: return YX(); case 5: return YY(); case 6: return YZ(); case 7: return ZX(); case 8: return ZY(); case 9: return ZZ(); default: return ""; } }
/* Passing to tilted ------------------------------------------------------- */ void TiltPairAligner::passToUntilted(int _mtX, int _mtY, int &_muX, int &_muY) { if (Nu > 3) { SPEED_UP_temps012; VECTOR_R3(m, _mtX, _mtY, 1); M3x3_BY_V3x1(m, Ptu, m); _muX = (int) XX(m); _muY = (int) YY(m); } else { _muX = _mtX; _muY = _mtY; } }
/* Transform all coordinates ---------------------------------------------- */ void Micrograph::transform_coordinates(const Matrix2D<double> &M) { Matrix1D<double> m(3); SPEED_UP_temps012; int imax = coords.size(); for (int i = 0; i < imax; i++) { if (coords[i].valid) { VECTOR_R3(m, coords[i].X, coords[i].Y, 1); M3x3_BY_V3x1(m, M, m); coords[i].X = (int) XX(m); coords[i].Y = (int) YY(m); } } }
NOX::Abstract::Group::ReturnType LOCA::BorderedSolver::Nested::applyTranspose( const NOX::Abstract::MultiVector& X, const NOX::Abstract::MultiVector::DenseMatrix& Y, NOX::Abstract::MultiVector& U, NOX::Abstract::MultiVector::DenseMatrix& V) const { int num_cols = X.numVectors(); Teuchos::RCP<NOX::Abstract::MultiVector> XX = unbordered_grp->getX().createMultiVector(num_cols); Teuchos::RCP<NOX::Abstract::MultiVector> UU = unbordered_grp->getX().createMultiVector(num_cols); NOX::Abstract::MultiVector::DenseMatrix YY(myWidth, num_cols); NOX::Abstract::MultiVector::DenseMatrix VV(myWidth, num_cols); NOX::Abstract::MultiVector::DenseMatrix YY1(Teuchos::View, YY, underlyingWidth, num_cols, 0, 0); NOX::Abstract::MultiVector::DenseMatrix YY2(Teuchos::View, YY, numConstraints, num_cols, underlyingWidth, 0); NOX::Abstract::MultiVector::DenseMatrix VV1(Teuchos::View, VV, underlyingWidth, num_cols, 0, 0); NOX::Abstract::MultiVector::DenseMatrix VV2(Teuchos::View, VV, numConstraints, num_cols, underlyingWidth, 0); grp->extractSolutionComponent(X, *XX); grp->extractParameterComponent(false, X, YY1); YY2.assign(Y); NOX::Abstract::Group::ReturnType status = solver->applyTranspose(*XX, YY, *UU, VV); V.assign(VV2); grp->loadNestedComponents(*UU, VV1, U); return status; }
// Write PDB format void Assembly::writePDB(std::string filename) { FILE *file; file = fopen(filename.c_str(), "w"); if (file==NULL) REPORT_ERROR("Error writing file: " + filename); fprintf(file, "%s\n", "REMARK Created by DsigNA"); long int atomnum = 0; for (int imol = 0; imol < molecules.size(); imol++) { for (int ires = 0; ires < molecules[imol].residues.size(); ires++) { for (int iatom = 0; iatom < molecules[imol].residues[ires].atoms.size(); iatom++, atomnum++) { // If more than 100,000 atoms: just start counting at one again. if (atomnum > 99999) atomnum -= 99999; char chainID = molecules[imol].name[0]; fprintf(file, "ATOM %5d %-4s %3s %1c%4d %8.3f%8.3f%8.3f%6.2f%6.2f %4s\n", atomnum, molecules[imol].residues[ires].atoms[iatom].name.c_str(), molecules[imol].residues[ires].name.c_str(), chainID, molecules[imol].residues[ires].number, XX(molecules[imol].residues[ires].atoms[iatom].coords), YY(molecules[imol].residues[ires].atoms[iatom].coords), ZZ(molecules[imol].residues[ires].atoms[iatom].coords), molecules[imol].residues[ires].atoms[iatom].occupancy, molecules[imol].residues[ires].atoms[iatom].bfactor, molecules[imol].name.c_str()); } } if (imol + 1 < molecules.size()) fprintf(file, "%s\n", "TER"); } fprintf(file, "%s\n", "END"); fclose(file); }
void Coordinates::update(void) { Matrix M1, M2; selfTest(); M1.loadIdentity(); M1.translate(On); M2.newUVN(Xn,Yn,Zn); mO2N = M1 * M2;//Old->New Vector XX(1,0,0),YY(0,1,0),ZZ(0,0,1); fPoint o(0,0,0); o = o * mO2N; M1.loadIdentity(); M1.translate(o); XX = XX * mO2N; YY = YY * mO2N; ZZ = ZZ * mO2N; /* printf("\n------On------\n");o.outputs(); printf("\n------XXn------\n");XX.outputs(); printf("\n------YYn------\n");YY.outputs(); printf("\n------ZZn------\n");ZZ.outputs(); */ M2.newUVN(XX,YY,ZZ); mN2O = M1 * M2;//New -> Old }
std::cout << " correction= " << vol_correction << std::endl << " Number of eqs= " << N_eq << std::endl << " Blob after correction= " << A3D_ELEM(*vol_blobs, k, i, j) << std::endl; #endif } } // Prepare for next iteration XX(act_coord) = XX(act_coord) + grid->relative_size * (grid->basis)( 0, 0); YY(act_coord) = YY(act_coord) + grid->relative_size * (grid->basis)( 1, 0); ZZ(act_coord) = ZZ(act_coord) + grid->relative_size * (grid->basis)( 2, 0); } XX(beginY) = XX(beginY) + grid->relative_size * (grid->basis)( 0, 1); YY(beginY) = YY(beginY) + grid->relative_size * (grid->basis)( 1, 1); ZZ(beginY) = ZZ(beginY) + grid->relative_size * (grid->basis)( 2, 1); } pthread_mutex_lock(&blobs_conv_mutex); for( int in = (assigned_slice-min_separation+1) ; in <= (assigned_slice+min_separation-1); in ++ ) { if( in != assigned_slice ) { if( ( in >= 0 ) && ( in < z_planes)) { if( slices_status[in] != -1 ) slices_status[in]--; } }
void draw_blue(t_env *e, int i) { int length = e->xsym - e->xo[INC]; draw_polar(XX(1 + i), YY(1 + i), 180, length, e, BLUE); }
void C3DPlotCanvas::OnMouse( wxMouseEvent& event ) { wxPoint pt(event.GetPosition()); wxClientDC dc(this); PrepareDC(dc); wxPoint point(event.GetLogicalPosition(dc)); if (event.RightDown()) { m_bRButton = true; int where[2]; where[0] = point.x; where[1] = point.y; last[0] = point.x; last[1] = point.y; ball->mouse_down(where,3); } if (event.RightUp()) { m_bRButton = false; int where[2]; where[0] = point.x; where[1] = point.y; ball->mouse_up(where,3); } if (event.LeftDown()) { if ((event.CmdDown()) && this->m_d && this->b_select) { m_brush = true; last[0] = point.x; last[1] = point.y; } else { m_bLButton = true; int where[2]; where[0] = point.x; where[1] = point.y; last[0] = point.x; last[1] = point.y; ball->mouse_down(where,1); } } if (event.LeftUp()) { if (bSelect && this->m_d ) { bSelect = false; SelectByRect(); } else if (m_brush) { m_brush = false; } else { m_bLButton = false; int where[2]; where[0] = point.x; where[1] = point.y; ball->mouse_up(where,1); } } if (event.Dragging()) { int where[2]; where[0] = point.x; where[1] = point.y; if (m_brush) { float vp[4]; glGetFloatv(GL_VIEWPORT, vp); float W=vp[2], H=vp[3]; float diam = 2*(ball->radius); ball->apply_transform(); int pix1[2], pix2[2], pix3[2]; pix1[0] = (int)(W/2); pix1[1] = (int)(H/2); pix2[0] = (int)(W/2-1); pix2[1] = (int)(H/2); pix3[0] = (int)(W/2); pix3[1] = (int)(H/2-1); double world1[3], world2[3],world3[3]; unproject_pixel(pix1, world1, 0.0); unproject_pixel(pix2, world2, 0.0); unproject_pixel(pix3, world3, 0.0); ball->unapply_transform(); Vec3f w1(world1); Vec3f w2(world2); Vec3f w3(world3); Vec3f screen_x = w1-w2; unitize(screen_x); Vec3f screen_y = w3-w1; unitize(screen_y); Vec3f XX(1,0,0); Vec3f YY(0,1,0); Vec3f ZZ(0,0,1); xp += diam * (where[0] - last[0]) / W *(XX*screen_x); yp += diam * (where[0] - last[0]) / W *(YY*screen_x); zp += diam * (where[0] - last[0]) / W *(ZZ*screen_x); xp += diam * (last[1] - where[1]) / H *(XX*screen_y); yp += diam * (last[1] - where[1]) / H *(YY*screen_y); zp += diam * (last[1] - where[1]) / H *(ZZ*screen_y); if (xp < -1.0) xp = -1.0; if (xp > 1.0) xp = 1.0; if (yp < -1.0) yp = -1.0; if (yp > 1.0) yp = 1.0; if (zp < -1.0) zp = -1.0; if (zp > 1.0) zp = 1.0; last[0] = where[0]; last[1] = where[1]; c3d_plot_frame->control->m_xp->SetValue((int)((xp+1)*10000)); c3d_plot_frame->control->m_yp->SetValue((int)((yp+1)*10000)); c3d_plot_frame->control->m_zp->SetValue((int)((zp+1)*10000)); this->UpdateSelect(); } else { bSelect = false; if (m_bLButton & m_bRButton) { ball->mouse_drag(where,last,2); last[0] = where[0]; last[1] = where[1]; } else if (m_bLButton) { ball->mouse_drag(where,last,1); last[0] = where[0]; last[1] = where[1]; } else if (m_bRButton) { ball->mouse_drag(where,last,3); last[0] = where[0]; last[1] = where[1]; } } } Refresh(); }
// Read Symmetry file ====================================================== // crystal symmetry matices from http://cci.lbl.gov/asu_gallery/ int SymList::read_sym_file(FileName fn_sym) { int i, j; FILE *fpoii; char line[80]; char *auxstr; DOUBLE ang_incr, rot_ang; int fold; Matrix2D<DOUBLE> L(4, 4), R(4, 4); Matrix1D<DOUBLE> axis(3); int pgGroup = 0, pgOrder = 0; std::vector<std::string> fileContent; //check if reserved word // Open file --------------------------------------------------------- if ((fpoii = fopen(fn_sym.c_str(), "r")) == NULL) { //check if reserved word and return group and order if (isSymmetryGroup(fn_sym, pgGroup, pgOrder)) { fill_symmetry_class(fn_sym, pgGroup, pgOrder, fileContent); } else REPORT_ERROR((std::string)"SymList::read_sym_file:Can't open file: " + " or do not recognize symmetry group" + fn_sym); } else { while (fgets(line, 79, fpoii) != NULL) { if (line[0] == ';' || line[0] == '#' || line[0] == '\0') continue; fileContent.push_back(line); } fclose(fpoii); } // Count the number of symmetries ------------------------------------ true_symNo = 0; // count number of axis and mirror planes. It will help to identify // the crystallographic symmetry int no_axis, no_mirror_planes, no_inversion_points; no_axis = no_mirror_planes = no_inversion_points = 0; for (int n=0; n<fileContent.size(); n++) { strcpy(line,fileContent[n].c_str()); auxstr = firstToken(line); if (auxstr == NULL) { std::cout << line; std::cout << "Wrong line in symmetry file, the line is skipped\n"; continue; } if (strcmp(auxstr, "rot_axis") == 0) { auxstr = nextToken(); fold = textToInteger(auxstr); true_symNo += (fold - 1); no_axis++; } else if (strcmp(auxstr, "mirror_plane") == 0) { true_symNo++; no_mirror_planes++; } else if (strcmp(auxstr, "inversion") == 0) { true_symNo += 1; no_inversion_points = 1; } } // Ask for memory __L.resize(4*true_symNo, 4); __R.resize(4*true_symNo, 4); __chain_length.resize(true_symNo); __chain_length.initConstant(1); // Read symmetry parameters i = 0; for (int n=0; n<fileContent.size(); n++) { strcpy(line,fileContent[n].c_str()); auxstr = firstToken(line); // Rotational axis --------------------------------------------------- if (strcmp(auxstr, "rot_axis") == 0) { auxstr = nextToken(); fold = textToInteger(auxstr); auxstr = nextToken(); XX(axis) = textToDOUBLE(auxstr); auxstr = nextToken(); YY(axis) = textToDOUBLE(auxstr); auxstr = nextToken(); ZZ(axis) = textToDOUBLE(auxstr); ang_incr = 360. / fold; L.initIdentity(); for (j = 1, rot_ang = ang_incr; j < fold; j++, rot_ang += ang_incr) { rotation3DMatrix(rot_ang, axis, R); R.setSmallValuesToZero(); set_matrices(i++, L, R.transpose()); } __sym_elements++; // inversion ------------------------------------------------------ } else if (strcmp(auxstr, "inversion") == 0) { L.initIdentity(); L(2, 2) = -1; R.initIdentity(); R(0, 0) = -1.; R(1, 1) = -1.; R(2, 2) = -1.; set_matrices(i++, L, R); __sym_elements++; // mirror plane ------------------------------------------------------------- } else if (strcmp(auxstr, "mirror_plane") == 0) { auxstr = nextToken(); XX(axis) = textToFloat(auxstr); auxstr = nextToken(); YY(axis) = textToFloat(auxstr); auxstr = nextToken(); ZZ(axis) = textToFloat(auxstr); L.initIdentity(); L(2, 2) = -1; Matrix2D<DOUBLE> A; alignWithZ(axis,A); A = A.transpose(); R = A * L * A.inv(); L.initIdentity(); set_matrices(i++, L, R); __sym_elements++; } } compute_subgroup(); return pgGroup; }
void ProgResolutionIBW::edgeWidth(const MultidimArray<double> &volCoeffs, const MultidimArray<double> &edges, MultidimArray <double>& widths, const Matrix1D<double> &dir, double step) const { double forward_count, backward_count, slope; Matrix1D<double> pos_aux_fw(3), pos_aux_bw(3), pos(3), pos_aux(3), next_pos(3), Kdir; Kdir=step*dir; //Visit all elements in volume FOR_ALL_ELEMENTS_IN_ARRAY3D(edges) { //Check for border pixels if (A3D_ELEM(edges,k,i,j)!=0) { //reset all counters forward_count=0; backward_count=0; VECTOR_R3(pos_aux_fw,j,i,k); pos_aux_bw=pos=pos_aux_fw; //find out if pixel magnitude grows or decreases pos_aux=pos; pos_aux+=dir; double value_plus_dir=volCoeffs.interpolatedElementBSpline3D(XX(pos_aux),YY(pos_aux),ZZ(pos_aux)); pos_aux=pos; pos_aux-=dir; double value_minus_dir=volCoeffs.interpolatedElementBSpline3D(XX(pos_aux),YY(pos_aux),ZZ(pos_aux)); slope=value_plus_dir-value_minus_dir; double sign; if (slope>0) sign=1; else sign=-1; //current_pixel is multiplied by the sign, so only one condition is enough to detect an //extremum no matter if the pixel values increase or decrease double current_pixel=sign*volCoeffs.interpolatedElementBSpline3D (XX(pos_aux_fw),YY(pos_aux_fw),ZZ(pos_aux_fw)); double next_pixel; bool not_found; //Search for local extremum ahead of the edge in the given direction do { not_found=true; next_pos=pos_aux_fw+Kdir; next_pixel=sign*volCoeffs.interpolatedElementBSpline3D (XX(next_pos),YY(next_pos),ZZ(next_pos)); if(next_pixel>current_pixel) { current_pixel=next_pixel; pos_aux_fw=next_pos; forward_count++; } else { not_found=false; } } while(not_found); current_pixel=sign*volCoeffs.interpolatedElementBSpline3D (XX(pos_aux_bw),YY(pos_aux_bw),ZZ(pos_aux_bw)); //Search for local extremum behind of the edge in the given direction do { not_found=true; next_pos=pos_aux_bw-Kdir; next_pixel=sign*volCoeffs.interpolatedElementBSpline3D (XX(next_pos),YY(next_pos),ZZ(next_pos)); if(next_pixel<current_pixel) { current_pixel=next_pixel; pos_aux_bw=next_pos; backward_count++; } else { not_found=false; } } while(not_found); //If the width found for this position is smaller than the one stores in edges volume //before it is overwritten if ((forward_count+backward_count)<A3D_ELEM(widths,k,i,j)) { A3D_ELEM(widths,k,i,j)=forward_count+backward_count; } } } }
// Reading from a file void MlModel::read(FileName fn_in) { // Clear current model clear(); // Open input file std::ifstream in(fn_in.data(), std::ios_base::in); if (in.fail()) { REPORT_ERROR((std::string) "MlModel::readStar: File " + fn_in + " cannot be read."); } MetaDataTable MDclass, MDgroup, MDlog, MDsigma; // Read general stuff MDlog.readStar(in, "model_general"); if (!MDlog.getValue(EMDL_MLMODEL_DIMENSIONALITY, ref_dim) || !MDlog.getValue(EMDL_MLMODEL_ORIGINAL_SIZE, ori_size) || !MDlog.getValue(EMDL_MLMODEL_CURRENT_RESOLUTION, current_resolution) || !MDlog.getValue(EMDL_MLMODEL_CURRENT_SIZE, current_size) || !MDlog.getValue(EMDL_MLMODEL_PADDING_FACTOR, padding_factor) || !MDlog.getValue(EMDL_MLMODEL_INTERPOLATOR, interpolator) || !MDlog.getValue(EMDL_MLMODEL_MINIMUM_RADIUS_NN_INTERPOLATION, r_min_nn) || !MDlog.getValue(EMDL_MLMODEL_PIXEL_SIZE, pixel_size) || !MDlog.getValue(EMDL_MLMODEL_NR_CLASSES, nr_classes) || !MDlog.getValue(EMDL_MLMODEL_NR_GROUPS, nr_groups) || !MDlog.getValue(EMDL_MLMODEL_TAU2_FUDGE_FACTOR, tau2_fudge_factor) || !MDlog.getValue(EMDL_MLMODEL_NORM_CORRECTION_AVG, avg_norm_correction) || !MDlog.getValue(EMDL_MLMODEL_SIGMA_OFFSET, sigma2_offset) || !MDlog.getValue(EMDL_MLMODEL_PRIOR_MODE, orientational_prior_mode) || !MDlog.getValue(EMDL_MLMODEL_SIGMA_ROT, sigma2_rot) || !MDlog.getValue(EMDL_MLMODEL_SIGMA_TILT, sigma2_tilt) || !MDlog.getValue(EMDL_MLMODEL_SIGMA_PSI, sigma2_psi) || !MDlog.getValue(EMDL_MLMODEL_LL, LL) || !MDlog.getValue(EMDL_MLMODEL_AVE_PMAX, ave_Pmax)) { REPORT_ERROR("MlModel::readStar: incorrect model_general table"); } // Take inverse again of current resolution: current_resolution = 1. / current_resolution; sigma2_offset *= sigma2_offset; sigma2_rot *= sigma2_rot; sigma2_tilt *= sigma2_tilt; sigma2_psi *= sigma2_psi; // Resize vectors initialise(); // Read classes FileName fn_tmp; Image<double> img; MDclass.readStar(in, "model_classes"); int iclass = 0; FOR_ALL_OBJECTS_IN_METADATA_TABLE(MDclass) { if (!MDclass.getValue(EMDL_MLMODEL_REF_IMAGE, fn_tmp) || !MDclass.getValue(EMDL_MLMODEL_PDF_CLASS, pdf_class[iclass]) || !MDclass.getValue(EMDL_MLMODEL_ACCURACY_ROT, acc_rot[iclass]) || !MDclass.getValue(EMDL_MLMODEL_ACCURACY_TRANS, acc_trans[iclass])) { REPORT_ERROR("MlModel::readStar: incorrect model_classes table"); } if (ref_dim == 2) { if (!MDclass.getValue(EMDL_MLMODEL_PRIOR_OFFX_CLASS, XX(prior_offset_class[iclass])) || !MDclass.getValue(EMDL_MLMODEL_PRIOR_OFFY_CLASS, YY(prior_offset_class[iclass]))) { REPORT_ERROR("MlModel::readStar: incorrect model_classes table: no offset priors for 2D classes"); } } // Read in actual reference image img.read(fn_tmp); Iref[iclass] = img(); iclass++; } // Read group stuff MDgroup.readStar(in, "model_groups"); long int igroup; FOR_ALL_OBJECTS_IN_METADATA_TABLE(MDgroup) { if (!MDgroup.getValue(EMDL_MLMODEL_GROUP_NO, igroup)) { REPORT_ERROR("MlModel::readStar: incorrect model_groups table"); } //Start counting of groups at 1, not at 0.... if (!MDgroup.getValue(EMDL_MLMODEL_GROUP_SCALE_CORRECTION, scale_correction[igroup - 1]) || !MDgroup.getValue(EMDL_MLMODEL_GROUP_NR_PARTICLES, nr_particles_group[igroup - 1]) || !MDgroup.getValue(EMDL_MLMODEL_GROUP_NAME, group_names[igroup - 1])) { REPORT_ERROR("MlModel::readStar: incorrect model_groups table"); } } // Read SSNR, noise reduction, tau2_class spectra for each class for (int iclass = 0; iclass < nr_classes; iclass++) { MDsigma.readStar(in, "model_class_" + integerToString(iclass + 1)); int idx; FOR_ALL_OBJECTS_IN_METADATA_TABLE(MDsigma) { if (!MDsigma.getValue(EMDL_SPECTRAL_IDX, idx)) { REPORT_ERROR("MlModel::readStar: incorrect table model_class_" + integerToString(iclass)); } if (!MDsigma.getValue(EMDL_MLMODEL_DATA_VS_PRIOR_REF, data_vs_prior_class[iclass](idx)) || !MDsigma.getValue(EMDL_MLMODEL_TAU2_REF, tau2_class[iclass](idx)) || !MDsigma.getValue(EMDL_MLMODEL_FSC_HALVES_REF, fsc_halves_class[iclass](idx)) || !MDsigma.getValue(EMDL_MLMODEL_SIGMA2_REF, sigma2_class[iclass](idx))) { REPORT_ERROR("MlModel::readStar: incorrect table model_class_" + integerToString(iclass)); } } } // Read sigma models for each group for (int igroup = 0; igroup < nr_groups; igroup++) { if (nr_particles_group[igroup] > 0) { MDsigma.readStar(in, "model_group_" + integerToString(igroup + 1)); int idx; FOR_ALL_OBJECTS_IN_METADATA_TABLE(MDsigma) { if (!MDsigma.getValue(EMDL_SPECTRAL_IDX, idx)) { REPORT_ERROR("MlModel::readStar: incorrect table model_group_" + integerToString(igroup)); } if (!MDsigma.getValue(EMDL_MLMODEL_SIGMA2_NOISE, sigma2_noise[igroup](idx))) { REPORT_ERROR("MlModel::readStar: incorrect table model_group_" + integerToString(igroup)); } } } else {
/* Splines -> Voxels for a SimpleGrid -------------------------------------- */ void spatial_Bspline032voxels_SimpleGrid(const MultidimArray<double> &vol_splines, const SimpleGrid &grid, MultidimArray<double> *vol_voxels, const MultidimArray<double> *vol_mask = NULL) { Matrix1D<double> act_coord(3); // Coord: Actual position inside // the voxel volume without deforming Matrix1D<double> beginZ(3); // Coord: Voxel coordinates of the // blob at the 3D point // (z0,YY(lowest),XX(lowest)) Matrix1D<double> beginY(3); // Coord: Voxel coordinates of the // blob at the 3D point // (z0,y0,XX(lowest)) Matrix1D<double> corner2(3), corner1(3); // Coord: Corners of the // blob in the voxel volume Matrix1D<double> gcurrent(3); // Position in g of current point double intx, inty, intz; // Nearest integer voxel int i, j, k; // Index within the blob volume bool process; // True if this blob has to be // processed double spline_radius = 2 * sqrt(3.0); // Some aliases #define x0 STARTINGX(*vol_voxels) #define xF FINISHINGX(*vol_voxels) #define y0 STARTINGY(*vol_voxels) #define yF FINISHINGY(*vol_voxels) #define z0 STARTINGZ(*vol_voxels) #define zF FINISHINGZ(*vol_voxels) #ifdef DEBUG bool condition = true; (*vol_voxels)().printShape(); std::cout << std::endl; std::cout << "x0= " << x0 << " xF= " << xF << std::endl; std::cout << "y0= " << y0 << " yF= " << yF << std::endl; std::cout << "z0= " << z0 << " zF= " << zF << std::endl; std::cout << grid; #endif // Convert the whole grid ............................................... // Corner of the plane defined by Z. These coordinates are in the // universal coord. system grid.grid2universe(grid.lowest, beginZ); Matrix1D<double> grid_index(3); for (k = (int) ZZ(grid.lowest); k <= (int) ZZ(grid.highest); k++) { // Corner of the row defined by Y beginY = beginZ; for (i = (int) YY(grid.lowest); i <= (int) YY(grid.highest); i++) { // First point in the row act_coord = beginY; for (j = (int) XX(grid.lowest); j <= (int) XX(grid.highest); j++) { VECTOR_R3(grid_index, j, i, k); #ifdef DEBUG if (condition) { printf("Dealing spline at (%d,%d,%d) = %f\n", j, i, k, A3D_ELEM(vol_splines, k, i, j)); std::cout << "Center of the blob " << act_coord.transpose() << std::endl; } #endif // These two corners are also real valued process = true; if (XX(act_coord) >= xF) process = false; if (YY(act_coord) >= yF) process = false; if (ZZ(act_coord) >= zF) process = false; if (XX(act_coord) <= x0) process = false; if (YY(act_coord) <= y0) process = false; if (ZZ(act_coord) <= z0) process = false; #ifdef DEBUG if (!process && condition) std::cout << " It is outside output volume\n"; #endif if (!grid.is_interesting(act_coord)) { #ifdef DEBUG if (process && condition) std::cout << " It is not interesting\n"; #endif process = false; } if (process) { V3_PLUS_CT(corner1, act_coord, -spline_radius); V3_PLUS_CT(corner2, act_coord, spline_radius); #ifdef DEBUG if (condition) { std::cout << "Corner 1 for this point " << corner1.transpose() << std::endl; std::cout << "Corner 2 for this point " << corner2.transpose() << std::endl; } #endif // Clip the corners to the volume borders XX(corner1) = ROUND(CLIP(XX(corner1), x0, xF)); YY(corner1) = ROUND(CLIP(YY(corner1), y0, yF)); ZZ(corner1) = ROUND(CLIP(ZZ(corner1), z0, zF)); XX(corner2) = ROUND(CLIP(XX(corner2), x0, xF)); YY(corner2) = ROUND(CLIP(YY(corner2), y0, yF)); ZZ(corner2) = ROUND(CLIP(ZZ(corner2), z0, zF)); #ifdef DEBUG if (condition) { std::cout << "Clipped and rounded Corner 1 " << corner1.transpose() << std::endl; std::cout << "Clipped and rounded Corner 2 " << corner2.transpose() << std::endl; } #endif // Effectively convert for (intz = ZZ(corner1); intz <= ZZ(corner2); intz++) for (inty = YY(corner1); inty <= YY(corner2); inty++) for (intx = XX(corner1); intx <= XX(corner2); intx++) { int iz = (int)intz, iy = (int)inty, ix = (int)intx; if (vol_mask != NULL) if (!A3D_ELEM(*vol_mask, iz, iy, ix)) continue; // Compute the spline value at this point VECTOR_R3(gcurrent, intx, inty, intz); V3_MINUS_V3(gcurrent, act_coord, gcurrent); double spline_value = spatial_Bspline03(gcurrent); #ifdef DEBUG_MORE if (condition) { std::cout << "At (" << intx << "," << inty << "," << intz << ") value=" << spline_value; std::cout.flush(); } #endif // Add at that position the corresponding spline value A3D_ELEM(*vol_voxels, iz, iy, ix) += A3D_ELEM(vol_splines, k, i, j) * spline_value; #ifdef DEBUG_MORE if (condition) { std::cout << " adding " << A3D_ELEM(vol_splines, k, i, j) << " * " << value_spline << " = " << A3D_ELEM(vol_splines, k, i, j)* value_spline << std::endl; std::cout.flush(); } #endif } } // Prepare for next iteration XX(act_coord) = XX(act_coord) + grid.relative_size * grid.basis(0, 0); YY(act_coord) = YY(act_coord) + grid.relative_size * grid.basis(1, 0); ZZ(act_coord) = ZZ(act_coord) + grid.relative_size * grid.basis(2, 0); } XX(beginY) = XX(beginY) + grid.relative_size * grid.basis(0, 1); YY(beginY) = YY(beginY) + grid.relative_size * grid.basis(1, 1); ZZ(beginY) = ZZ(beginY) + grid.relative_size * grid.basis(2, 1); } XX(beginZ) = XX(beginZ) + grid.relative_size * grid.basis(0, 2); YY(beginZ) = YY(beginZ) + grid.relative_size * grid.basis(1, 2); ZZ(beginZ) = ZZ(beginZ) + grid.relative_size * grid.basis(2, 2); } }
//#define DEBUG void spatial_Bspline032voxels(const GridVolume &vol_splines, MultidimArray<double> *vol_voxels, int Zdim, int Ydim, int Xdim) { // Resize and set starting corner ....................................... if (Zdim == 0 || Ydim == 0 || Xdim == 0) { Matrix1D<double> size = vol_splines.grid(0).highest - vol_splines.grid(0).lowest; Matrix1D<double> corner = vol_splines.grid(0).lowest; (*vol_voxels).initZeros(CEIL(ZZ(size)), CEIL(YY(size)), CEIL(XX(size))); STARTINGX(*vol_voxels) = FLOOR(XX(corner)); STARTINGY(*vol_voxels) = FLOOR(YY(corner)); STARTINGZ(*vol_voxels) = FLOOR(ZZ(corner)); } else { (*vol_voxels).initZeros(Zdim, Ydim, Xdim); (*vol_voxels).setXmippOrigin(); } // Convert each subvolume ............................................... for (size_t i = 0; i < vol_splines.VolumesNo(); i++) { spatial_Bspline032voxels_SimpleGrid(vol_splines(i)(), vol_splines.grid(i), vol_voxels); #ifdef DEBUG std::cout << "Spline grid no " << i << " stats: "; vol_splines(i)().printStats(); std::cout << std::endl; std::cout << "So far vol stats: "; (*vol_voxels).printStats(); std::cout << std::endl; VolumeXmipp save; save() = *vol_voxels; save.write((std::string)"PPPvoxels" + integerToString(i)); #endif } // Now normalise the resulting volume .................................. double inorm = 1.0 / sum_spatial_Bspline03_Grid(vol_splines.grid()); FOR_ALL_ELEMENTS_IN_ARRAY3D(*vol_voxels) A3D_ELEM(*vol_voxels, k, i, j) *= inorm; // Set voxels outside interest region to minimum value ................. double R = vol_splines.grid(0).get_interest_radius(); if (R != -1) { double R2 = (R - 6) * (R - 6); // Compute minimum value within sphere double min_val = A3D_ELEM(*vol_voxels, 0, 0, 0); FOR_ALL_ELEMENTS_IN_ARRAY3D(*vol_voxels) if (j*j + i*i + k*k <= R2 - 4) min_val = XMIPP_MIN(min_val, A3D_ELEM(*vol_voxels, k, i, j)); // Substitute minimum value R2 = (R - 2) * (R - 2); FOR_ALL_ELEMENTS_IN_ARRAY3D(*vol_voxels) if (j*j + i*i + k*k >= R2) A3D_ELEM(*vol_voxels, k, i, j) = min_val; }
//#define DEBUG double spatial_Bspline03_proj( const Matrix1D<double> &r, const Matrix1D<double> &u) { // Avoids divisions by zero and allows orthogonal rays computation static Matrix1D<double> ur(3); if (XX(u) == 0) XX(ur) = XMIPP_EQUAL_ACCURACY; else XX(ur) = XX(u); if (YY(u) == 0) YY(ur) = XMIPP_EQUAL_ACCURACY; else YY(ur) = YY(u); if (ZZ(u) == 0) ZZ(ur) = XMIPP_EQUAL_ACCURACY; else ZZ(ur) = ZZ(u); // Some precalculated variables double x_sign = SGN(XX(ur)); double y_sign = SGN(YY(ur)); double z_sign = SGN(ZZ(ur)); // Compute the minimum and maximum alpha for the ray double alpha_xmin = (-2 - XX(r)) / XX(ur); double alpha_xmax = (2 - XX(r)) / XX(ur); double alpha_ymin = (-2 - YY(r)) / YY(ur); double alpha_ymax = (2 - YY(r)) / YY(ur); double alpha_zmin = (-2 - ZZ(r)) / ZZ(ur); double alpha_zmax = (2 - ZZ(r)) / ZZ(ur); double alpha_min = XMIPP_MAX(XMIPP_MIN(alpha_xmin, alpha_xmax), XMIPP_MIN(alpha_ymin, alpha_ymax)); alpha_min = XMIPP_MAX(alpha_min, XMIPP_MIN(alpha_zmin, alpha_zmax)); double alpha_max = XMIPP_MIN(XMIPP_MAX(alpha_xmin, alpha_xmax), XMIPP_MAX(alpha_ymin, alpha_ymax)); alpha_max = XMIPP_MIN(alpha_max, XMIPP_MAX(alpha_zmin, alpha_zmax)); if (alpha_max - alpha_min < XMIPP_EQUAL_ACCURACY) return 0.0; #ifdef DEBUG std::cout << "Pixel: " << r.transpose() << std::endl << "Dir: " << ur.transpose() << std::endl << "Alpha x:" << alpha_xmin << " " << alpha_xmax << std::endl << " " << (r + alpha_xmin*ur).transpose() << std::endl << " " << (r + alpha_xmax*ur).transpose() << std::endl << "Alpha y:" << alpha_ymin << " " << alpha_ymax << std::endl << " " << (r + alpha_ymin*ur).transpose() << std::endl << " " << (r + alpha_ymax*ur).transpose() << std::endl << "Alpha z:" << alpha_zmin << " " << alpha_zmax << std::endl << " " << (r + alpha_zmin*ur).transpose() << std::endl << " " << (r + alpha_zmax*ur).transpose() << std::endl << "alpha :" << alpha_min << " " << alpha_max << std::endl << std::endl; #endif // Compute the first point in the volume intersecting the ray static Matrix1D<double> v(3); V3_BY_CT(v, ur, alpha_min); V3_PLUS_V3(v, r, v); #ifdef DEBUG std::cout << "First entry point: " << v.transpose() << std::endl; std::cout << " Alpha_min: " << alpha_min << std::endl; #endif // Follow the ray double alpha = alpha_min; double ray_sum = 0; do { double alpha_x = (XX(v) + x_sign - XX(r)) / XX(ur); double alpha_y = (YY(v) + y_sign - YY(r)) / YY(ur); double alpha_z = (ZZ(v) + z_sign - ZZ(r)) / ZZ(ur); // Which dimension will ray move next step into?, it isn't neccesary to be only // one. double diffx = ABS(alpha - alpha_x); double diffy = ABS(alpha - alpha_y); double diffz = ABS(alpha - alpha_z); double diff_alpha = XMIPP_MIN(XMIPP_MIN(diffx, diffy), diffz); ray_sum += spatial_Bspline03_integral(r, ur, alpha, alpha + diff_alpha); // Update alpha and the next entry point if (ABS(diff_alpha - diffx) <= XMIPP_EQUAL_ACCURACY) alpha = alpha_x; if (ABS(diff_alpha - diffy) <= XMIPP_EQUAL_ACCURACY) alpha = alpha_y; if (ABS(diff_alpha - diffz) <= XMIPP_EQUAL_ACCURACY) alpha = alpha_z; XX(v) += diff_alpha * XX(ur); YY(v) += diff_alpha * YY(ur); ZZ(v) += diff_alpha * ZZ(ur); #ifdef DEBUG std::cout << "Alpha x,y,z: " << alpha_x << " " << alpha_y << " " << alpha_z << " ---> " << alpha << std::endl; std::cout << " Next entry point: " << v.transpose() << std::endl << " diff_alpha: " << diff_alpha << std::endl << " ray_sum: " << ray_sum << std::endl << " Alfa tot: " << alpha << "alpha_max: " << alpha_max << std::endl; #endif } while ((alpha_max - alpha) > XMIPP_EQUAL_ACCURACY); return ray_sum; }
void run () { mask.allowed_data_types = INT_MASK; // Main program ========================================================= params.V1.read(fn1); params.V1().setXmippOrigin(); params.V2.read(fn2); params.V2().setXmippOrigin(); // Initialize best_fit double best_fit = 1e38; Matrix1D<double> best_align(8); bool first = true; // Generate mask if (mask_enabled) { mask.generate_mask(params.V1()); params.mask_ptr = &(mask.get_binary_mask()); } else params.mask_ptr = NULL; // Exhaustive search if (!usePowell && !useFRM) { // Count number of iterations int times = 1; if (!tell) { if (grey_scale0 != grey_scaleF) times *= FLOOR(1 + (grey_scaleF - grey_scale0) / step_grey); if (grey_shift0 != grey_shiftF) times *= FLOOR(1 + (grey_shiftF - grey_shift0) / step_grey_shift); if (rot0 != rotF) times *= FLOOR(1 + (rotF - rot0) / step_rot); if (tilt0 != tiltF) times *= FLOOR(1 + (tiltF - tilt0) / step_tilt); if (psi0 != psiF) times *= FLOOR(1 + (psiF - psi0) / step_psi); if (scale0 != scaleF) times *= FLOOR(1 + (scaleF - scale0) / step_scale); if (z0 != zF) times *= FLOOR(1 + (zF - z0) / step_z); if (y0 != yF) times *= FLOOR(1 + (yF - y0) / step_y); if (x0 != xF) times *= FLOOR(1 + (xF - x0) / step_x); init_progress_bar(times); } else std::cout << "#grey_factor rot tilt psi scale z y x fitness\n"; // Iterate int itime = 0; int step_time = CEIL((double)times / 60.0); Matrix1D<double> r(3); Matrix1D<double> trial(9); for (double grey_scale = grey_scale0; grey_scale <= grey_scaleF ; grey_scale += step_grey) for (double grey_shift = grey_shift0; grey_shift <= grey_shiftF ; grey_shift += step_grey_shift) for (double rot = rot0; rot <= rotF ; rot += step_rot) for (double tilt = tilt0; tilt <= tiltF ; tilt += step_tilt) for (double psi = psi0; psi <= psiF ; psi += step_psi) for (double scale = scale0; scale <= scaleF ; scale += step_scale) for (ZZ(r) = z0; ZZ(r) <= zF ; ZZ(r) += step_z) for (YY(r) = y0; YY(r) <= yF ; YY(r) += step_y) for (XX(r) = x0; XX(r) <= xF ; XX(r) += step_x) { // Form trial vector trial(0) = grey_scale; trial(1) = grey_shift; trial(2) = rot; trial(3) = tilt; trial(4) = psi; trial(5) = scale; trial(6) = ZZ(r); trial(7) = YY(r); trial(8) = XX(r); // Evaluate double fit = fitness(MATRIX1D_ARRAY(trial)); // The best? if (fit < best_fit || first) { best_fit = fit; best_align = trial; first = false; if (tell) std::cout << "Best so far\n"; } // Show fit if (tell) std::cout << trial << " " << fit << std::endl; else if (++itime % step_time == 0) progress_bar(itime); } if (!tell) progress_bar(times); } else if (usePowell) { // Use Powell optimization Matrix1D<double> x(9), steps(9); double fitness; int iter; steps.initConstant(1); if (onlyShift) steps(0)=steps(1)=steps(2)=steps(3)=steps(4)=steps(5)=0; if (params.alignment_method == COVARIANCE) steps(0)=steps(1)=0; x(0)=grey_scale0; x(1)=grey_shift0; x(2)=rot0; x(3)=tilt0; x(4)=psi0; x(5)=scale0; x(6)=z0; x(7)=y0; x(8)=x0; powellOptimizer(x,1,9,&wrapperFitness,NULL,0.01,fitness,iter,steps,true); best_align=x; best_fit=fitness; first=false; } else if (useFRM) { String scipionPython; initializeScipionPython(scipionPython); PyObject * pFunc = getPointerToPythonFRMFunction(); double rot,tilt,psi,x,y,z,score; Matrix2D<double> A; alignVolumesFRM(pFunc, params.V1(), params.V2(), Py_None, rot,tilt,psi,x,y,z,score,A,maxShift,maxFreq,params.mask_ptr); best_align.initZeros(9); best_align(0)=1; // Gray scale best_align(1)=0; // Gray shift best_align(2)=rot; best_align(3)=tilt; best_align(4)=psi; best_align(5)=1; // Scale best_align(6)=z; best_align(7)=y; best_align(8)=x; best_fit=-score; } if (!first) std::cout << "The best correlation is for\n" << "Scale : " << best_align(5) << std::endl << "Translation (X,Y,Z) : " << best_align(8) << " " << best_align(7) << " " << best_align(6) << std::endl << "Rotation (rot,tilt,psi): " << best_align(2) << " " << best_align(3) << " " << best_align(4) << std::endl << "Best grey scale : " << best_align(0) << std::endl << "Best grey shift : " << best_align(1) << std::endl << "Fitness value : " << best_fit << std::endl; Matrix1D<double> r(3); XX(r) = best_align(8); YY(r) = best_align(7); ZZ(r) = best_align(6); Matrix2D<double> A,Aaux; Euler_angles2matrix(best_align(2), best_align(3), best_align(4), A, true); translation3DMatrix(r,Aaux); A = A * Aaux; scale3DMatrix(vectorR3(best_align(5), best_align(5), best_align(5)),Aaux); A = A * Aaux; if (verbose!=0) std::cout << "xmipp_transform_geometry will require the following values" << "\n Angles: " << best_align(2) << " " << best_align(3) << " " << best_align(4) << "\n Shifts: " << A(0,3) << " " << A(1,3) << " " << A(2,3) << std::endl; if (apply) { applyTransformation(params.V2(),params.Vaux(),MATRIX1D_ARRAY(best_align)); params.V2()=params.Vaux(); params.V2.write(fnOut); } }
// Shift an image through phase-shifts in its Fourier Transform (without pretabulated sine and cosine) void shiftImageInFourierTransform(MultidimArray<Complex >& in, MultidimArray<Complex >& out, double oridim, Matrix1D<double> shift) { out.resize(in); shift /= -oridim; double dotp, a, b, c, d, ac, bd, ab_cd, x, y, z, xshift, yshift, zshift; switch (in.getDim()) { case 1: xshift = XX(shift); if (ABS(xshift) < XMIPP_EQUAL_ACCURACY) { out = in; return; } for (long int j = 0; j < XSIZE(in); j++) { x = j; dotp = 2 * PI * (x * xshift); a = cos(dotp); b = sin(dotp); c = DIRECT_A1D_ELEM(in, j).real; d = DIRECT_A1D_ELEM(in, j).imag; ac = a * c; bd = b * d; ab_cd = (a + b) * (c + d); // (ab_cd-ac-bd = ad+bc : but needs 4 multiplications) DIRECT_A1D_ELEM(out, j) = Complex(ac - bd, ab_cd - ac - bd); } break; case 2: xshift = XX(shift); yshift = YY(shift); if (ABS(xshift) < XMIPP_EQUAL_ACCURACY && ABS(yshift) < XMIPP_EQUAL_ACCURACY) { out = in; return; } for (long int i = 0; i < XSIZE(in); i++) for (long int j = 0; j < XSIZE(in); j++) { x = j; y = i; dotp = 2 * PI * (x * xshift + y * yshift); a = cos(dotp); b = sin(dotp); c = DIRECT_A2D_ELEM(in, i, j).real; d = DIRECT_A2D_ELEM(in, i, j).imag; ac = a * c; bd = b * d; ab_cd = (a + b) * (c + d); DIRECT_A2D_ELEM(out, i, j) = Complex(ac - bd, ab_cd - ac - bd); } for (long int i = YSIZE(in) - 1; i >= XSIZE(in); i--) { y = i - YSIZE(in); for (long int j = 0; j < XSIZE(in); j++) { x = j; dotp = 2 * PI * (x * xshift + y * yshift); a = cos(dotp); b = sin(dotp); c = DIRECT_A2D_ELEM(in, i, j).real; d = DIRECT_A2D_ELEM(in, i, j).imag; ac = a * c; bd = b * d; ab_cd = (a + b) * (c + d); DIRECT_A2D_ELEM(out, i, j) = Complex(ac - bd, ab_cd - ac - bd); } } break; case 3: xshift = XX(shift); yshift = YY(shift); zshift = ZZ(shift); if (ABS(xshift) < XMIPP_EQUAL_ACCURACY && ABS(yshift) < XMIPP_EQUAL_ACCURACY && ABS(zshift) < XMIPP_EQUAL_ACCURACY) { out = in; return; } for (long int k = 0; k < ZSIZE(in); k++) { z = (k < XSIZE(in)) ? k : k - ZSIZE(in); for (long int i = 0; i < YSIZE(in); i++) { y = (i < XSIZE(in)) ? i : i - YSIZE(in); for (long int j = 0; j < XSIZE(in); j++) { x = j; dotp = 2 * PI * (x * xshift + y * yshift + z * zshift); a = cos(dotp); b = sin(dotp); c = DIRECT_A3D_ELEM(in, k, i, j).real; d = DIRECT_A3D_ELEM(in, k, i, j).imag; ac = a * c; bd = b * d; ab_cd = (a + b) * (c + d); DIRECT_A3D_ELEM(out, k, i, j) = Complex(ac - bd, ab_cd - ac - bd); } } } break; default: REPORT_ERROR("shiftImageInFourierTransform ERROR: dimension should be 1, 2 or 3!"); } }
void * blobs2voxels_SimpleGrid( void * data ) { ThreadBlobsToVoxels * thread_data = (ThreadBlobsToVoxels *) data; const MultidimArray<double> *vol_blobs = thread_data->vol_blobs; const SimpleGrid *grid = thread_data->grid; const struct blobtype *blob = thread_data->blob; MultidimArray<double> *vol_voxels = thread_data->vol_voxels; const Matrix2D<double> *D = thread_data->D; int istep = thread_data->istep; MultidimArray<double> *vol_corr = thread_data->vol_corr; const MultidimArray<double> *vol_mask = thread_data->vol_mask; ; bool FORW = thread_data->FORW; int eq_mode = thread_data->eq_mode; int min_separation = thread_data->min_separation; int z_planes = (int)(ZZ(grid->highest) - ZZ(grid->lowest) + 1); Matrix2D<double> Dinv; // Inverse of D Matrix1D<double> act_coord(3); // Coord: Actual position inside // the voxel volume without deforming Matrix1D<double> real_position(3); // Coord: actual position after // applying the V transformation Matrix1D<double> beginZ(3); // Coord: Voxel coordinates of the // blob at the 3D point // (z0,YY(lowest),XX(lowest)) Matrix1D<double> beginY(3); // Coord: Voxel coordinates of the // blob at the 3D point // (z0,y0,XX(lowest)) Matrix1D<double> corner2(3), corner1(3); // Coord: Corners of the // blob in the voxel volume Matrix1D<double> gcurrent(3); // Position in g of current point MultidimArray<double> blob_table; // Something like a blobprint // but with the values of the // blob in space double d; // Distance between the center // of the blob and a voxel position int id; // index inside the blob value // table for tha blob value at // a distance d double intx, inty, intz; // Nearest integer voxel int i, j, k; // Index within the blob volume int process; // True if this blob has to be // processed double vol_correction=0; // Correction to apply to the // volume when "projecting" back SPEED_UP_temps012; // Some aliases #define x0 STARTINGX(*vol_voxels) #define xF FINISHINGX(*vol_voxels) #define y0 STARTINGY(*vol_voxels) #define yF FINISHINGY(*vol_voxels) #define z0 STARTINGZ(*vol_voxels) #define zF FINISHINGZ(*vol_voxels) #ifdef DEBUG bool condition = !FORW; if (condition) { (*vol_voxels)().printShape(); std::cout << std::endl; std::cout << "x0= " << x0 << " xF= " << xF << std::endl; std::cout << "y0= " << y0 << " yF= " << yF << std::endl; std::cout << "z0= " << z0 << " zF= " << zF << std::endl; std::cout << grid; } #endif // Invert deformation matrix ............................................ if (D != NULL) Dinv = D->inv(); // Compute a blob value table ........................................... blob_table.resize((int)(blob->radius*istep + 1)); for (size_t i = 0; i < blob_table.xdim; i++) { A1D_ELEM(blob_table, i) = kaiser_value((double)i/istep, blob->radius, blob->alpha, blob->order); #ifdef DEBUG_MORE if (condition) std::cout << "Blob (" << i << ") r=" << (double)i / istep << " val= " << A1D_ELEM(blob_table, i) << std::endl; #endif } int assigned_slice; do { assigned_slice = -1; do { pthread_mutex_lock(&blobs_conv_mutex); if( slices_processed == z_planes ) { pthread_mutex_unlock(&blobs_conv_mutex); return (void*)NULL; } for(int w = 0 ; w < z_planes ; w++ ) { if( slices_status[w]==0 ) { slices_status[w] = -1; assigned_slice = w; slices_processed++; for( int in = (w-min_separation+1) ; in <= (w+min_separation-1 ) ; in ++ ) { if( in != w ) { if( ( in >= 0 ) && ( in < z_planes )) { if( slices_status[in] != -1 ) slices_status[in]++; } } } break; } } pthread_mutex_unlock(&blobs_conv_mutex); } while( assigned_slice == -1); // Convert the whole grid ............................................... // Corner of the plane defined by Z. These coordinates are in the // universal coord. system Matrix1D<double> aux( grid->lowest ); k = (int)(assigned_slice + ZZ( grid->lowest )); ZZ(aux) = k; grid->grid2universe(aux, beginZ); Matrix1D<double> grid_index(3); // Corner of the row defined by Y beginY = beginZ; for (i = (int) YY(grid->lowest); i <= (int) YY(grid->highest); i++) { // First point in the row act_coord = beginY; for (j = (int) XX(grid->lowest); j <= (int) XX(grid->highest); j++) { VECTOR_R3(grid_index, j, i, k); #ifdef DEBUG if (condition) { printf("Dealing blob at (%d,%d,%d) = %f\n", j, i, k, A3D_ELEM(*vol_blobs, k, i, j)); std::cout << "Center of the blob " << act_coord.transpose() << std::endl; } #endif // Place act_coord in its right place if (D != NULL) { M3x3_BY_V3x1(real_position, *D, act_coord); #ifdef DEBUG if (condition) std::cout << "Center of the blob moved to " //ROB, the "moved" coordinates are in // real_position not in act_coord << act_coord.transpose() << std::endl; << real_position.transpose() << std::endl; #endif // ROB This is OK if blob.radius is in Cartesian space as I // think is the case } else real_position = act_coord; // These two corners are also real valued process = true; //ROB //This is OK if blob.radius is in Cartesian space as I think is the case V3_PLUS_CT(corner1, real_position, -blob->radius); V3_PLUS_CT(corner2, real_position, blob->radius); #ifdef DEFORM_BLOB_WHEN_IN_CRYSTAL //ROB //we do not need this, it is already in Cartesian space //if (D!=NULL) // box_enclosing(corner1,corner2, *D, corner1, corner2); #endif if (XX(corner1) >= xF) process = false; if (YY(corner1) >= yF) process = false; if (ZZ(corner1) >= zF) process = false; if (XX(corner2) <= x0) process = false; if (YY(corner2) <= y0) process = false; if (ZZ(corner2) <= z0) process = false; #ifdef DEBUG if (!process && condition) std::cout << " It is outside output volume\n"; #endif if (!grid->is_interesting(real_position)) { #ifdef DEBUG if (process && condition) std::cout << " It is not interesting\n"; #endif process = false; } #ifdef DEBUG if (condition) { std::cout << "Corner 1 for this point " << corner1.transpose() << std::endl; std::cout << "Corner 2 for this point " << corner2.transpose() << std::endl; } #endif if (process) { // Clip the corners to the volume borders XX(corner1) = ROUND(CLIP(XX(corner1), x0, xF)); YY(corner1) = ROUND(CLIP(YY(corner1), y0, yF)); ZZ(corner1) = ROUND(CLIP(ZZ(corner1), z0, zF)); XX(corner2) = ROUND(CLIP(XX(corner2), x0, xF)); YY(corner2) = ROUND(CLIP(YY(corner2), y0, yF)); ZZ(corner2) = ROUND(CLIP(ZZ(corner2), z0, zF)); #ifdef DEBUG if (condition) { std::cout << "Clipped and rounded Corner 1 " << corner1.transpose() << std::endl; std::cout << "Clipped and rounded Corner 2 " << corner2.transpose() << std::endl; } #endif if (!FORW) switch (eq_mode) { case VARTK: vol_correction = 0; break; case VMAXARTK: vol_correction = -1e38; break; } // Effectively convert long N_eq; N_eq = 0; for (intz = ZZ(corner1); intz <= ZZ(corner2); intz++) for (inty = YY(corner1); inty <= YY(corner2); inty++) for (intx = XX(corner1); intx <= XX(corner2); intx++) { int iz = (int)intz, iy = (int)inty, ix = (int)intx; if (vol_mask != NULL) if (!A3D_ELEM(*vol_mask, iz, iy, ix)) continue; // Compute distance to the center of the blob VECTOR_R3(gcurrent, intx, inty, intz); #ifdef DEFORM_BLOB_WHEN_IN_CRYSTAL // ROB //if (D!=NULL) // M3x3_BY_V3x1(gcurrent,Dinv,gcurrent); #endif V3_MINUS_V3(gcurrent, real_position, gcurrent); d = sqrt(XX(gcurrent) * XX(gcurrent) + YY(gcurrent) * YY(gcurrent) + ZZ(gcurrent) * ZZ(gcurrent)); if (d > blob->radius) continue; id = (int)(d * istep); #ifdef DEBUG_MORE if (condition) { std::cout << "At (" << intx << "," << inty << "," << intz << ") distance=" << d; std::cout.flush(); } #endif // Add at that position the corresponding blob value if (FORW) { A3D_ELEM(*vol_voxels, iz, iy, ix) += A3D_ELEM(*vol_blobs, k, i, j) * A1D_ELEM(blob_table, id); #ifdef DEBUG_MORE if (condition) { std::cout << " adding " << A3D_ELEM(*vol_blobs, k, i, j) << " * " << A1D_ELEM(blob_table, id) << " = " << A3D_ELEM(*vol_blobs, k, i, j)* A1D_ELEM(blob_table, id) << std::endl; std::cout.flush(); } #endif if (vol_corr != NULL) A3D_ELEM(*vol_corr, iz, iy, ix) += A1D_ELEM(blob_table, id) * A1D_ELEM(blob_table, id); } else { double contrib = A3D_ELEM(*vol_corr, iz, iy, ix) * A1D_ELEM(blob_table, id); switch (eq_mode) { case VARTK: vol_correction += contrib; N_eq++; break; case VMAXARTK: if (contrib > vol_correction) vol_correction = contrib; break; } #ifdef DEBUG_MORE if (condition) { std::cout << " adding " << A3D_ELEM(*vol_corr, iz, iy, ix) << " * " << A1D_ELEM(blob_table, id) << " = " << contrib << std::endl; std::cout.flush(); } #endif } } if (N_eq == 0) N_eq = 1; if (!FORW) { A3D_ELEM(*vol_blobs, k, i, j) += vol_correction / N_eq; #ifdef DEBUG_MORE std::cout << " correction= " << vol_correction << std::endl << " Number of eqs= " << N_eq << std::endl << " Blob after correction= " << A3D_ELEM(*vol_blobs, k, i, j) << std::endl; #endif } } // Prepare for next iteration XX(act_coord) = XX(act_coord) + grid->relative_size * (grid->basis)( 0, 0); YY(act_coord) = YY(act_coord) + grid->relative_size * (grid->basis)( 1, 0); ZZ(act_coord) = ZZ(act_coord) + grid->relative_size * (grid->basis)( 2, 0); }
// Evaluate plane ---------------------------------------------------------- double evaluatePlane(double rot, double tilt, const MultidimArray<double> *V, const MultidimArray<double> *Vmag, double maxFreq, double planeWidth, int direction, MultidimArray<double> *Vdraw=NULL, bool setPos=false, double rotPos=0, double tiltPos=0) { if (rot<0 || rot>360 || tilt<-90 || tilt>90) return 0; Matrix2D<double> E, Einv; Euler_angles2matrix(rot,tilt,0,E); Einv=E.transpose(); if (setPos) { Matrix2D<double> Epos; Euler_angles2matrix(rotPos,tiltPos,0,Epos); double angle=acos(E(2,0)*Epos(2,0)+E(2,1)*Epos(2,1)+E(2,2)*Epos(2,2)); angle=RAD2DEG(angle); if (fabs(angle)<20 || fabs(180-angle)<20) return 0; } size_t N=XMIPP_MAX(XSIZE(*Vmag),YSIZE(*Vmag)/2); N=XMIPP_MAX(N,ZSIZE(*Vmag)/2); double df=0.5/N; Matrix1D<double> freq(3), freqp(3); Matrix1D<int> idx(3); double sumNeg=0, sumPos=0; int Nneg=0, Npos=0; double maxFreq2=maxFreq*maxFreq; int iPlaneWidth=(int)ceil(planeWidth); for (double ix=0; ix<=N; ix++) { XX(freq)=ix*df; double fx2=XX(freq)*XX(freq); if (fx2>maxFreq2) continue; for (double iy=-(int)N; iy<=N; iy++) { YY(freq)=iy*df; double fx2fy2=fx2+YY(freq)*YY(freq); if (fx2fy2>maxFreq2) continue; for (int iz=-iPlaneWidth; iz<=iPlaneWidth; iz++) { if (iz==0 || ix==0 || iy==0) continue; // Frequency in the coordinate system of the plane ZZ(freq)=iz*df; // Frequency in the coordinate system of the volume SPEED_UP_temps012; M3x3_BY_V3x1(freqp,Einv,freq); bool inverted=false; if (XX(freqp)<0) { XX(freqp)=-XX(freqp); YY(freqp)=-YY(freqp); ZZ(freqp)=-ZZ(freqp); inverted=true; } // Get the corresponding index DIGFREQ2FFT_IDX(ZZ(freqp), ZSIZE(*V), ZZ(idx)); DIGFREQ2FFT_IDX(YY(freqp), YSIZE(*V), YY(idx)); DIGFREQ2FFT_IDX(XX(freqp), XSIZE(*V), XX(idx)); if (XX(idx) < STARTINGX(*Vmag) || XX(idx) > FINISHINGX(*Vmag) || YY(idx) < STARTINGY(*Vmag) || YY(idx) > FINISHINGY(*Vmag) || ZZ(idx) < STARTINGZ(*Vmag) || ZZ(idx) > FINISHINGZ(*Vmag)) continue; // Make the corresponding sums bool negativeSum; if (direction==1) negativeSum=iz<0; else negativeSum=iz>0; double val=A3D_ELEM(*Vmag,ZZ(idx),YY(idx),XX(idx)); if ((negativeSum && !inverted) || (!negativeSum && inverted)) // XOR { sumNeg+=val; Nneg++; if (Vdraw!=NULL) (*Vdraw)(idx)=2*direction*val; } else { sumPos+=val; Npos++; if (Vdraw!=NULL) (*Vdraw)(idx)=1.0/2.0*direction*val; } } } } if (fabs(Nneg-Npos)/(0.5*(Nneg+Npos))>0.5) // If there is a difference of more than 50% return 1e38; if (Nneg!=0) sumNeg/=Nneg; else return 1e38; if (Npos!=0) sumPos/=Npos; else return 1e38; return -(sumPos-sumNeg); }
void ProgAngularProjectLibrary::project_angle_vector (int my_init, int my_end, bool verbose) { Projection P; FileName fn_proj; double rot,tilt,psi; int mySize; int numberStepsPsi = 1; mySize=my_end-my_init+1; if (psi_sampling < 360) { numberStepsPsi = (int) (359.99999/psi_sampling); mySize *= numberStepsPsi; } if (verbose) init_progress_bar(mySize); int myCounter=0; for (double mypsi=0;mypsi<360;mypsi += psi_sampling) for (int i=0;i<my_init;i++) myCounter++; // if (shears && XSIZE(inputVol())!=0 && VShears==NULL) // VShears=new RealShearsInfo(inputVol()); if (projType == SHEARS && XSIZE(inputVol())!=0 && Vshears==NULL) Vshears=new RealShearsInfo(inputVol()); if (projType == FOURIER && XSIZE(inputVol())!=0 && Vfourier==NULL) Vfourier=new FourierProjector(inputVol(), paddFactor, maxFrequency, BSplineDeg); for (double mypsi=0;mypsi<360;mypsi += psi_sampling) { for (int i=my_init;i<=my_end;i++) { if (verbose) progress_bar(i-my_init); psi= mypsi+ZZ(mysampling.no_redundant_sampling_points_angles[i]); tilt= YY(mysampling.no_redundant_sampling_points_angles[i]); rot= XX(mysampling.no_redundant_sampling_points_angles[i]); // if (shears) // projectVolume(*VShears, P, Ydim, Xdim, rot,tilt,psi); // else // projectVolume(inputVol(), P, Ydim, Xdim, rot,tilt,psi); if (projType == SHEARS) projectVolume(*Vshears, P, Ydim, Xdim, rot, tilt, psi); else if (projType == FOURIER) projectVolume(*Vfourier, P, Ydim, Xdim, rot, tilt, psi); else if (projType == REALSPACE) projectVolume(inputVol(), P, Ydim, Xdim, rot, tilt, psi); P.setEulerAngles(rot,tilt,psi); P.setDataMode(_DATA_ALL); P.write(output_file,(size_t) (numberStepsPsi * i + mypsi +1),true,WRITE_REPLACE); } } if (verbose) progress_bar(mySize); }
void ProgValidationTiltPairs::run() { MetaData MD_tilted, MD_untilted, DF1sorted, DF2sorted, DFweights; MD_tilted.read(fntiltimage_In); MD_untilted.read(fnuntiltimage_In); DF1sorted.sort(MD_tilted,MDL_ITEM_ID,true); DF2sorted.sort(MD_untilted,MDL_ITEM_ID,true); MDIterator iter1(DF1sorted), iter2(DF2sorted); std::vector< Matrix1D<double> > ang1, ang2; Matrix1D<double> rotTiltPsi(3), z(3); size_t currentId; bool anotherImageIn2=iter2.hasNext(); size_t id1, id2; bool mirror; Matrix2D<double> Eu, Et, R; double alpha, beta; while (anotherImageIn2) { ang1.clear(); ang2.clear(); // Take current id DF2sorted.getValue(MDL_ITEM_ID,currentId,iter2.objId); // Grab all the angles in DF2 associated to this id bool anotherIteration=false; do { DF2sorted.getValue(MDL_ITEM_ID,id2,iter2.objId); anotherIteration=false; if (id2==currentId) { DF2sorted.getValue(MDL_ANGLE_ROT,XX(rotTiltPsi),iter2.objId); DF2sorted.getValue(MDL_ANGLE_TILT,YY(rotTiltPsi),iter2.objId); DF2sorted.getValue(MDL_ANGLE_PSI,ZZ(rotTiltPsi),iter2.objId); DF2sorted.getValue(MDL_FLIP,mirror,iter2.objId); std::cout << "From DF2:" << XX(rotTiltPsi) << " " << YY(rotTiltPsi) << " " << ZZ(rotTiltPsi) << " " << mirror << std::endl; //LINEA ANTERIOR ORIGINAL if (mirror) { double rotp, tiltp, psip; Euler_mirrorX(XX(rotTiltPsi),YY(rotTiltPsi),ZZ(rotTiltPsi), rotp, tiltp, psip); XX(rotTiltPsi)=rotp; YY(rotTiltPsi)=tiltp; ZZ(rotTiltPsi)=psip; } ang2.push_back(rotTiltPsi); iter2.moveNext(); if (iter2.hasNext()) anotherIteration=true; } } while (anotherIteration); // Advance Iter 1 to catch Iter 2 double N=0, cumulatedDistance=0; size_t newObjId=0; if (iter1.objId>0) { DF1sorted.getValue(MDL_ITEM_ID,id1,iter1.objId); while (id1<currentId && iter1.hasNext()) { iter1.moveNext(); DF1sorted.getValue(MDL_ITEM_ID,id1,iter1.objId); } // If we are at the end of DF1, then we did not find id1 such that id1==currentId if (!iter1.hasNext()) break; // Grab all the angles in DF1 associated to this id anotherIteration=false; do { DF1sorted.getValue(MDL_ITEM_ID,id1,iter1.objId); anotherIteration=false; if (id1==currentId) { DF1sorted.getValue(MDL_ANGLE_ROT,XX(rotTiltPsi),iter1.objId); DF1sorted.getValue(MDL_ANGLE_TILT,YY(rotTiltPsi),iter1.objId); DF1sorted.getValue(MDL_ANGLE_PSI,ZZ(rotTiltPsi),iter1.objId); DF1sorted.getValue(MDL_FLIP,mirror,iter1.objId); std::cout << "From DF1:" << XX(rotTiltPsi) << " " << YY(rotTiltPsi) << " " << ZZ(rotTiltPsi) << " " << mirror << std::endl; //LINEA ANTERIOR ORIGINAL if (mirror) { double rotp, tiltp, psip; Euler_mirrorX(XX(rotTiltPsi),YY(rotTiltPsi),ZZ(rotTiltPsi), rotp, tiltp, psip); XX(rotTiltPsi)=rotp; YY(rotTiltPsi)=tiltp; ZZ(rotTiltPsi)=psip; } ang1.push_back(rotTiltPsi); iter1.moveNext(); if (iter1.hasNext()) anotherIteration=true; } } while (anotherIteration); // Process both sets of angles for (size_t i=0; i<ang2.size(); ++i) { const Matrix1D<double> &anglesi=ang2[i]; double rotu=XX(anglesi); double tiltu=YY(anglesi); double psiu=ZZ(anglesi); Euler_angles2matrix(rotu,tiltu,psiu,Eu,false); /*std::cout << "------UNTILTED MATRIX------" << std::endl; std::cout << Eu << std::endl; std::cout << "vector" << std::endl; std::cout << Eu(2,0) << " " << Eu(2,1) << " " << Eu(2,2) << std::endl;*/ for (size_t j=0; j<ang1.size(); ++j) { const Matrix1D<double> &anglesj=ang1[j]; double rott=XX(anglesj); double tiltt=YY(anglesj); double psit=ZZ(anglesj); double alpha_x, alpha_y; Euler_angles2matrix(rott,tiltt,psit,Et,false); ////////////////////////////////////////////////////////////////// double untilt_angles[3]={rotu, tiltu, psiu}, tilt_angles[3]={rott, tiltt, psit}; angles2tranformation(untilt_angles, tilt_angles, alpha_x, alpha_y); //std::cout << "alpha = " << (alpha_x*alpha_x+alpha_y*alpha_y) << std::endl; ////////////////////////////////////////////////////////////////// /*std::cout << "------TILTED MATRIX------" << std::endl; std::cout << Et << std::endl; std::cout << "vector" << std::endl; std::cout << Et(2,0) << " " << Et(2,1) << " " << Et(2,2) << std::endl; std::cout << "---------------------------" << std::endl; std::cout << "---------------------------" << std::endl;*/ R=Eu*Et.transpose(); double rotTransf, tiltTransf, psiTransf; Euler_matrix2angles(R, rotTransf, tiltTransf, psiTransf); std::cout << "Rot_and_Tilt " << rotTransf << " " << tiltTransf << std::endl; //LINEA ANTERIOR ORIGINAL XX(z) = Eu(2,0) - Et(2,0); YY(z) = Eu(2,1) - Et(2,1); ZZ(z) = Eu(2,2) - Et(2,2); alpha = atan2(YY(z), XX(z)); //Expressed in rad beta = atan2(XX(z)/cos(alpha), ZZ(z)); //Expressed in rad std::cout << "alpha = " << alpha*180/PI << std::endl; std::cout << "beta = " << beta*180/PI << std::endl; } } } else N=0; if (N>0) { double meanDistance=cumulatedDistance/ang2.size(); DFweights.setValue(MDL_ANGLE_DIFF,meanDistance,newObjId); } else if (newObjId>0) DFweights.setValue(MDL_ANGLE_DIFF,-1.0,newObjId); anotherImageIn2=iter2.hasNext(); } std::complex<double> qu[4], qt[4], M[4], Inv_qu[4], test[4], P1[4], P2[4], Inv_quu[4]; double rotu=34*PI/180, tiltu=10*PI/180, psiu=5*PI/180; double rott=25*PI/180, tiltt=15*PI/180, psit=40*PI/180; quaternion2Paulibasis(rotu, tiltu, psiu, qu); /*std::cout << "quaternion2Pauli" << std::endl; std::cout << "Untilted " << qu[0] << " " << qu[1] << " " << qu[2] << " " << qu[3] << std::endl; std::cout << " " << std::endl;*/ Paulibasis2matrix(qu,M); /*std::cout << "Pauli2matrix" << std::endl; std::cout << "Matriz " << M[0] << " " << M[1] << " " << M[2] << " " << M[3] << std::endl; std::cout << " " << std::endl;*/ inverse_matrixSU2(M, Inv_qu); /*std::cout << "inverse_matrixSU(2)" << std::endl; std::cout << "Inversa " << Inv_qu[0] << " " << Inv_qu[1] << " " << Inv_qu[2] << " " << Inv_qu[3] << std::endl; std::cout << " " << std::endl;*/ quaternion2Paulibasis(rott, tiltt, psit, qt); /*std::cout << "quaternion2Pauli" << std::endl; std::cout << "Tilted " << qt[0] << " " << qt[1] << " " << qt[2] << " " << qt[3] << std::endl; std::cout << " " << std::endl;*/ InversefromPaulibasis(qu,Inv_quu); Pauliproduct(qt, Inv_qu, P1); /*std::cout << "Pauliproduct" << std::endl; std::cout << "quaternion qt " << P1[0] << " " << P1[1] << " " << P1[2] << " " << P1[3] << std::endl; std::cout << " " << std::endl; std::cout << "-----------------------------------" << std::endl;*/ //double alpha_x, alpha_y; //extrarotationangles(P1, alpha_x, alpha_y); //std::cout << "alpha_x = " << alpha_x << " " << "alpha_y = " << alpha_y << std::endl; }