// 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 mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray*prhs[]) { double angs[3]; const double *p_angs=mxGetPr(prhs[1]); angs[0]=(double)p_angs[0]; angs[1]=(double)p_angs[1]; angs[2]=(double)p_angs[2]; Matrix1D<double> axis; getMatrix1D(prhs[2],axis); Matrix2D<double> A3D, A2D; bool wrap = (bool)mxGetScalar(prhs[5]); mwSize ndims = mxGetNumberOfDimensions(prhs[0]); /*mode: 1 euler, 2 align_with_Z, 3 axis, 4 tform*/ switch ((int)mxGetScalar(prhs[3])) { case 1: Euler_angles2matrix(angs[0], angs[1], angs[2], A3D, true); break; case 2: alignWithZ(axis,A3D); break; case 3: rotation3DMatrix(angs[0], axis, A3D); A2D.resize(3,3); A2D(0,0)=A3D(0,0); A2D(0,1)=A3D(0,1); A2D(0,2)=A3D(0,2); A2D(1,0)=A3D(1,0); A2D(1,1)=A3D(1,1); A2D(1,2)=A3D(1,2); A2D(2,0)=A3D(2,0); A2D(2,1)=A3D(2,1); A2D(2,2)=A3D(2,2); break; case 4: getMatrix2D(prhs[6],A2D); A3D = A2D; break; } if (ndims == 2) { Image<double> img, img_out; getMatrix2D(prhs[0],img()); if (MAT_XSIZE(A2D) != 0) { applyGeometry(BSPLINE3,img_out(), img(), A2D, IS_NOT_INV, wrap); setMatrix2D(img_out(),plhs[0]); } else { setMatrix2D(img(),plhs[0]); } } else { Image<double> vol, vol_out; getMatrix3D(prhs[0],vol()); applyGeometry(BSPLINE3, vol_out(), vol(), A3D, IS_NOT_INV, wrap); setMatrix3D(vol_out(),plhs[0]); } }