55 (
String)
"Prog_Project_Parameters::read: There is a problem " 56 "opening the file " + fn_crystal);
58 std::vector <double> ParamVec;
67 XX(
a) = scale * ParamVec[0];
68 YY(
a) = scale * ParamVec[1];
72 XX(
b) = scale * ParamVec[0];
73 YY(
b) = scale * ParamVec[1];
77 if (ParamVec.size() < 2)
88 std::cerr <<
"crystal_Xdim" << crystal_Xdim<<std::endl;
89 std::cerr <<
"crystal_Ydim" << crystal_Ydim<<std::endl;
90 std::cerr <<
"a vector" <<
a <<std::endl;
91 std::cerr <<
"b vector" <<
b <<std::endl;
92 std::cerr <<
"Nshift_devr" <<
Nshift_dev <<std::endl;
93 std::cerr <<
"Nshift_avg" <<
Nshift_avg <<std::endl;
104 std::vector<double> FCVect(2);
106 std::vector<double> TVector;
130 if ((fh_param = fopen(fn_crystal.c_str(),
"w")) ==
nullptr)
132 (std::string)
"Prog_Project_Parameters::write: There is a problem " 133 "opening the file " + fn_crystal +
" for output");
135 fprintf(fh_param,
"# Crystal dimensions (X, Y)\n");
137 fprintf(fh_param,
"# Crystal a lattice vector (X, Y)\n");
139 fprintf(fh_param,
"# Crystal b lattice vector (X, Y)\n");
142 fprintf(fh_param,
"# Noise (and bias) applied to the magnitude shift\n");
149 fprintf(fh_param,
"# Disappearing threshold\n");
152 fprintf(fh_param,
"# Orthogonal Projections\n");
160 fprintf(fh_param,
"# File with shifts for each unit cell\n");
173 float rot,
float tilt,
float psi)
184 P().setXmippOrigin();
206 double nor = 1 / (
XX(proja) *
YY(projb) -
XX(projb) *
YY(proja));
214 AuxMat(0, 0) =
XX(prm_crystal.
a);
215 AuxMat(0, 1) =
YY(prm_crystal.
a);
217 AuxMat(1, 0) =
XX(prm_crystal.
b);
218 AuxMat(1, 1) =
YY(prm_crystal.
b);
225 D(0, 0) =
XSIZE(P());
229 D(1, 1) =
YSIZE(P());
248 std::cout <<
"P shape ";
250 std::cout << std::endl;
251 std::cout <<
"P.euler " << P.
euler;
252 std::cout << std::endl;
253 std::cout <<
"rot= " << rot <<
" tilt= " << tilt <<
" psi= " << psi << std::endl;
254 std::cout <<
"a " << prm_crystal.
a.
transpose() << std::endl;
255 std::cout <<
"b " << prm_crystal.
b.
transpose() << std::endl;
256 std::cout <<
"proja " << proja.
transpose() << std::endl;
257 std::cout <<
"projb " << projb.
transpose() << std::endl;
260 std::cout <<
"A\n" << A << std::endl;
261 std::cout <<
"Ainv\n" << Ainv << std::endl;
262 std::cout <<
"D\n" << D << std::endl;
263 std::cout <<
"Dinv\n" << Dinv << std::endl;
271 std::cout <<
"aprojd " << aprojd.
transpose() << std::endl;
272 std::cout <<
"bprojd " << bprojd.
transpose() << std::endl;
293 std::cout <<
"corner1 before deformation " << corner1.transpose() << std::endl;
294 std::cout <<
"corner2 before deformation " << corner2.
transpose() << std::endl;
300 std::cout <<
"corner1 after deformation " << corner1.transpose() << std::endl;
301 std::cout <<
"corner2 after deformation " << corner2.
transpose() << std::endl;
314 prm_crystal, cell_shiftX, cell_shiftY, cell_shiftZ, cell_inside,
315 exp_shifts_matrix_X, exp_shifts_matrix_Y, exp_shifts_matrix_Z);
321 exp_normal_shifts_matrix_X,
322 exp_normal_shifts_matrix_Y,
323 exp_normal_shifts_matrix_Z,
329 std::cout <<
"prm_crystal ";
330 std::cout << std::endl;
331 std::cout <<
"prm_crystal" << prm_crystal.
DF_shift << std::endl;
332 std::cout <<
"prm_crystal" << prm_crystal.
DF_shift_bool << std::endl;
348 temp_vect = AE *
vectorR3(exp_shifts_matrix_X(
i,
j),
349 exp_shifts_matrix_Y(
i,
j),
350 exp_shifts_matrix_Z(
i,
j));
355 exp_shifts_matrix_Z(
i,
j) = 65;
357 exp_shifts_matrix_Z(
i,
j) = 0;
358 temp_vect = AE *
vectorR3(exp_shifts_matrix_X(
i,
j),
359 exp_shifts_matrix_Y(
i,
j),
360 exp_shifts_matrix_Z(
i,
j));
365 cell_shiftX(
i,
j) +=
XX(temp_vect);
366 cell_shiftY(
i,
j) +=
YY(temp_vect);
369 cell_shiftZ(
i,
j) +=
ZZ(temp_vect);
373 std::cout <<
"Cell inside shape ";
375 std::cout << std::endl;
376 std::cout <<
"Cell inside\n" << cell_inside << std::endl;
377 std::cout <<
"Cell shiftX\n" << cell_shiftX << std::endl;
378 std::cout <<
"Cell shiftY\n" << cell_shiftY << std::endl;
379 std::cout <<
"Cell shiftZ\n" << cell_shiftZ << std::endl;
383 double density_factor = 1.0;
388 (P.
euler).getCol(2, projection_direction);
390 density_factor = (projection_direction * Dinv).module();
393 std::cout <<
"projection_direction" << projection_direction << std::endl;
394 std::cout <<
"projection_direction*A" << projection_direction*A << std::endl;
399 std::cout <<
"X proyectado=" << (AE*
vectorR3(1.0, 0.0, 0.0)).
transpose() << std::endl;
400 std::cout <<
"Y proyectado=" << (AE*
vectorR3(0.0, 1.0, 0.0)).
transpose() << std::endl;
401 std::cout <<
"P.euler_shape=" << std::endl;
402 std::cout << P.
euler << std::endl;
403 std::cout <<
"P.euler=" << P.
euler << std::endl;
404 std::cout <<
"AE=" << AE << std::endl;
405 std::cout <<
"AEinv=" << AEinv << std::endl;
406 std::cout <<
"Ainv=" << Ainv << std::endl;
407 std::cout <<
"density_factor=" << density_factor << std::endl;
413 if (cell_inside(
i,
j))
420 VECTOR_R3(cell_shift, cell_shiftX(
i,
j), cell_shiftY(
i,
j), cell_shiftZ(
i,
j));
425 std::cout <<
"cell_shift on deformed projection plane " 432 std::cout <<
"cell_shift on real space " 455 normal_vector(0) = exp_normal_shifts_matrix_X(
i,
j);
456 normal_vector(1) = exp_normal_shifts_matrix_Y(
i,
j);
457 normal_vector(2) = exp_normal_shifts_matrix_Z(
i,
j);
462 inverse_angles_matrix = angles_matrix.
inv();
464 for (
size_t ii = 0; ii < aux.
VF.size(); ii++)
465 aux.
VF[ii]->rotate(angles_matrix);
471 std::cout <<
"cell_shift after moving to ground " 475 aux.
shift(
XX(cell_shift),
YY(cell_shift),
ZZ(cell_shift));
481 P() = P() * density_factor;
484 std::cout <<
"After Projecting ...\n" << aux << std::endl;
486 std::cout <<
"Hit any key\n";
503 int &iamin,
int &iamax,
int &ibmin,
int &ibmax)
510 double x0 =
XX(proj_corner1) +
XX(cell_corner1);
511 double y0 =
YY(proj_corner1) +
YY(cell_corner1);
512 double xF =
XX(proj_corner2) +
XX(cell_corner2);
513 double yF =
YY(proj_corner2) +
YY(cell_corner2);
524 std::cerr <<
"A" << A <<std::endl;
525 std::cerr <<
"Ainv" << Ainv <<std::endl;
535 std::cerr <<
"r" << r <<std::endl;
547 std::cerr <<
"r" << r <<std::endl;
548 std::cerr <<
"Ainv" << Ainv <<std::endl;
549 std::cerr <<
"iamin" << iamin <<std::endl;
550 std::cerr <<
"iamax" << iamax <<std::endl;
551 std::cerr <<
"ibmin" << ibmin <<std::endl;
552 std::cerr <<
"ibmax" << ibmax <<std::endl;
556 #define CHANGE_COORDS_AND_CHOOSE_CORNERS2D \ 557 M2x2_BY_V2x1(r,Ainv,r); \ 558 iamin=XMIPP_MIN(FLOOR(XX(r)),iamin); iamax=XMIPP_MAX(CEIL(XX(r)),iamax); \ 559 ibmin=XMIPP_MIN(FLOOR(YY(r)),ibmin); ibmax=XMIPP_MAX(CEIL(YY(r)),ibmax); 591 int r1 = 0,
r2 = 0,
r3 = 0, c1 = 0, c2 = 0, c3 = 0;
593 #define x0 STARTINGX(visited) 594 #define y0 STARTINGY(visited) 595 #define xF FINISHINGX(visited) 596 #define yF FINISHINGY(visited) 602 r1 += visited(
i - 1,
j - 1);
603 c1 += visited(
i - 1,
j - 1);
607 r1 += visited(
i - 1,
j);
608 c2 += visited(
i - 1,
j);
612 r1 += visited(
i - 1,
j + 1);
613 c3 += visited(
i - 1,
j + 1);
617 r2 += visited(
i ,
j - 1);
618 c1 += visited(
i ,
j - 1);
620 r2 += visited(
i ,
j);
621 c2 += visited(
i ,
j);
624 r2 += visited(
i ,
j + 1);
625 c3 += visited(
i ,
j + 1);
627 if (i < yF && j >
x0)
629 r3 += visited(
i + 1,
j - 1);
630 c1 += visited(
i + 1,
j - 1);
634 r3 += visited(
i + 1,
j);
635 c2 += visited(
i + 1,
j);
639 r3 += visited(
i + 1,
j + 1);
640 c3 += visited(
i + 1,
j + 1);
644 std::cout << r1 <<
" " <<
r2 <<
" " <<
r3 <<
" " 645 << c1 <<
" " << c2 <<
" " << c3 << std::endl;
649 if (r1 == 0 &&
r2 == 1 &&
r3 == 0 && c1 == 0 && c2 == 1 && c3 == 0)
653 else if (r1 == 0 &&
r2 == 1 &&
r3 == 1 && c1 == 0 && c2 == 2 && c3 == 0)
657 else if (r1 == 0 &&
r2 == 2 &&
r3 == 1 && c1 == 0 && c2 == 1 && c3 == 2)
661 else if (r1 == 2 &&
r2 == 2 &&
r3 == 0 && c1 == 0 && c2 == 2 && c3 == 2)
665 else if (r1 == 2 &&
r2 == 1 &&
r3 == 0 && c1 == 0 && c2 == 2 && c3 == 1)
669 else if (r1 == 2 &&
r2 == 2 &&
r3 == 0 && c1 == 2 && c2 == 2 && c3 == 0)
673 else if (r1 == 1 &&
r2 == 2 &&
r3 == 0 && c1 == 2 && c2 == 1 && c3 == 0)
677 else if (r1 == 0 &&
r2 == 2 &&
r3 == 2 && c1 == 2 && c2 == 2 && c3 == 0)
681 else if (r1 == 0 &&
r2 == 1 &&
r3 == 2 && c1 == 1 && c2 == 2 && c3 == 0)
685 else if (r1 == 1 &&
r2 == 2 &&
r3 == 2 && c1 == 3 && c2 == 2 && c3 == 0)
689 else if (r1 == 0 &&
r2 == 2 &&
r3 == 3 && c1 == 1 && c2 == 2 && c3 == 2)
693 else if (r1 == 0 &&
r2 == 2 &&
r3 == 2 && c1 == 0 && c2 == 2 && c3 == 2)
697 else if (r1 == 2 &&
r2 == 2 &&
r3 == 1 && c1 == 0 && c2 == 2 && c3 == 3)
701 else if (r1 == 3 &&
r2 == 2 &&
r3 == 0 && c1 == 2 && c2 == 2 && c3 == 1)
730 int iamin, iamax, ibmin, ibmax;
733 corner1, corner2, aprojd, bprojd, iamin, iamax, ibmin, ibmax);
738 std::cout << std::endl;
739 std::cout <<
"aprojd=" << aproj.
transpose() << std::endl;
740 std::cout <<
"bprojd=" << bproj.
transpose() << std::endl;
741 std::cout << iamin <<
" " << iamax <<
" " << ibmin <<
" " << ibmax << std::endl;
749 weight(-1, 0) = weight(1, 0) = 1 / aproj.
module();
750 weight(0, -1) = weight(0, 1) = 1 / bproj.
module();
751 weight(-1, 1) = weight(1, -1) = 1 / (aproj - bproj).module();
752 weight(-1, -1) = weight(1, 1) = 1 / (aproj + bproj).module();
755 cell_shiftX.
initZeros(ibmax - ibmin + 1, iamax - iamin + 1);
761 cell_inside.
initZeros(ibmax - ibmin + 1, iamax - iamin + 1);
767 int visited_size =
XMIPP_MAX(iamax - iamin + 1, ibmax - ibmin + 1) + 2;
768 visited.
initZeros(visited_size, visited_size);
769 STARTINGX(visited) = iamin - (visited_size - (iamax - iamin + 1) + 1) / 2;
770 STARTINGY(visited) = ibmin - (visited_size - (ibmax - ibmin + 1) + 1) / 2;
773 std::cout <<
"weight=" << weight;
774 std::cout <<
"cell_shiftX shape ";
776 std::cout << std::endl;
777 std::cout <<
"cell_inside shape ";
779 std::cout << std::endl;
780 std::cout <<
"visited shape ";
782 std::cout << std::endl;
790 #define INDEX(r) (int)YY(r),(int)XX(r) 794 visited(
INDEX(r)) =
true;
797 std::cout <<
" Visiting " << r.transpose() << std::endl;
801 double total_weight = 0;
802 double total_shiftX = 0;
803 double total_shiftY = 0;
804 for (
YY(sh) = -1;
YY(sh) <= 1;
YY(sh)++)
805 for (
XX(sh) = -1;
XX(sh) <= 1;
XX(sh)++)
810 total_weight += weight(
INDEX(sh));
811 total_shiftX += weight(
INDEX(sh)) * cell_shiftX(
INDEX(ri));
812 total_shiftY += weight(
INDEX(sh)) * cell_shiftY(
INDEX(ri));
815 if (total_weight == 0)
820 prm_crystal.
Nshift_dev) + total_shiftX / total_weight;
822 prm_crystal.
Nshift_dev) + total_shiftY / total_weight;
830 std::cout <<
"Cell shift X without absolute displacements" << cell_shiftX;
831 std::cout <<
"Cell shift Y without absolute displacements" << cell_shiftY;
839 if (!cell_shiftX.outside(
i,
j))
842 cell_shiftX(
i,
j) +=
j *
XX(aprojd) +
i *
XX(bprojd);
843 cell_shiftY(
i,
j) +=
j *
YY(aprojd) +
i *
YY(bprojd);
847 XX(auxcorner1) =
XX(corner1) + cell_shiftX(
i,
j);
848 YY(auxcorner1) =
YY(corner1) + cell_shiftY(
i,
j);
849 XX(auxcorner2) =
XX(corner2) + cell_shiftX(
i,
j);
850 YY(auxcorner2) =
YY(corner2) + cell_shiftY(
i,
j);
858 cell_inside(
i,
j) = 1;
862 std::cout <<
"(i,j)=(" <<
i <<
"," <<
j <<
")\n";
863 std::cout <<
" Projection shape ";
865 std::cout << std::endl;
866 std::cout <<
" AuxCorner1 " << auxcorner1.transpose() << std::endl
867 <<
" Origin " << cell_shiftX(
i, j) <<
" " 868 << cell_shiftY(
i, j) << std::endl
869 <<
" AuxCorner2 " << auxcorner2.
transpose() << std::endl;
870 std::cout <<
" Inside= " << cell_inside(
i, j) << std::endl;
887 double phantom_scale)
890 aux_DF_shift = prm_crystal.
DF_shift;
891 exp_shifts_matrix_X.
resize(cell_inside);
893 exp_shifts_matrix_Y.
resize(cell_inside);
895 exp_shifts_matrix_Z.
resize(cell_inside);
898 exp_normal_shifts_matrix_X.
resize(cell_inside);
900 exp_normal_shifts_matrix_Y.
resize(cell_inside);
902 exp_normal_shifts_matrix_Z.
resize(cell_inside);
908 std::cout << aux_DF_shift;
909 std::cout <<
"exp_shifts_matrix_X shape" << std::endl;
911 std::cout << std::endl;
916 for (
size_t objId : aux_DF_shift.ids())
922 if (!exp_shifts_matrix_X.
outside(xcell,ycell))
924 aux_DF_shift.getValue(
MDL_SHIFT_X,exp_shifts_matrix_X(ycell, xcell),objId);
925 aux_DF_shift.getValue(
MDL_SHIFT_Y,exp_shifts_matrix_Y(ycell, xcell),objId);
926 aux_DF_shift.getValue(
MDL_SHIFT_Z,exp_shifts_matrix_Z(ycell, xcell),objId);
928 aux_DF_shift.getValue(
MDL_CRYSTAL_SHIFTX,exp_normal_shifts_matrix_X(ycell, xcell),objId);
929 aux_DF_shift.getValue(
MDL_CRYSTAL_SHIFTY,exp_normal_shifts_matrix_Y(ycell, xcell),objId);
930 aux_DF_shift.getValue(
MDL_CRYSTAL_SHIFTZ,exp_normal_shifts_matrix_Z(ycell, xcell),objId);
935 std::cout <<
"exp_shifts_matrix_X" << exp_shifts_matrix_X;
936 std::cout <<
"exp_shifts_matrix_Y" << exp_shifts_matrix_Y;
937 std::cout <<
"exp_shifts_matrix_Z" << exp_shifts_matrix_Z;
#define VECTOR_R2(v, x, y)
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
void read(const FileName &fn_crystal, double scale=1.0)
#define SPEED_UP_tempsDouble
double phantom_scale
Param file scale.
int proj_Ydim
Projection Ydim.
void printShape(std::ostream &out=std::cout) const
#define REPORT_ERROR(nerr, ErrormMsg)
Problem with matrix size.
void Euler_angles2matrix(T alpha, T beta, T gamma, Matrix2D< T > &A, bool homogeneous)
void write(const FileName &fn_crystal)
void Euler_direction2angles(Matrix1D< double > &v0, double &alpha, double &beta, double &gamma)
Matrix1D< double > b
Crustal vector b.
double beta(const double a, const double b)
Matrix1D< double > vectorR3(double x, double y, double z)
bool isCorner(const Matrix1D< double > &v) const
void write(const FileName &name="", size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE, CastWriteMode castMode=CW_CAST, int _swapWrite=0)
void inv(Matrix2D< T > &result) const
int proj_Xdim
Projection Xdim.
bool orthogonal
Orthogonalize projections.
void shift(double shiftX, double shiftY, double shiftZ)
Matrix1D< double > a
Crystal vector a.
#define V2_PLUS_V2(a, b, c)
#define FOR_ALL_ELEMENTS_IN_ARRAY2D(m)
Matrix1D< T > transpose() const
bool DF_shift_bool
is doc file with shifts available
MetaDataVec DF_shift
Document File for shifts. Order: H K x_SHIFT y_SHIFT z_SHIFT.
void fill_cell_positions(Projection &P, Matrix1D< double > &aproj, Matrix1D< double > &bproj, Matrix1D< double > &aprojd, Matrix1D< double > &bprojd, Matrix1D< double > &corner1, Matrix1D< double > &corner2, const Crystal_Projection_Parameters &prm_crystal, MultidimArray< double > &cell_shiftX, MultidimArray< double > &cell_shiftY, MultidimArray< double > &cell_shiftZ, MultidimArray< int > &cell_inside, MultidimArray< double > &exp_shifts_matrix_X, MultidimArray< double > &exp_shifts_matrix_Y, MultidimArray< double > &exp_shifts_matrix_Z)
void find_crystal_limits(const Matrix1D< double > &proj_corner1, const Matrix1D< double > &proj_corner2, const Matrix1D< double > &cell_corner1, const Matrix1D< double > &cell_corner2, const Matrix1D< double > &a, const Matrix1D< double > &b, int &iamin, int &iamax, int &ibmin, int &ibmax)
double disappearing_th
Disappearing threshold.
void rectangle_enclosing(const Matrix1D< double > &v0, const Matrix1D< double > &vF, const Matrix2D< double > &V, Matrix1D< double > &corner1, Matrix1D< double > &corner2)
#define M2x2_BY_V2x1(a, M, b)
void transpose(double *array, int size)
Crystal_Projection_Parameters()
#define M3x3_BY_M3x3(A, B, C)
void resize(size_t Xdim, bool copy=true)
constexpr double MIN_MODULE
double Nshift_dev
Standard deviation of the magnitude shift.
Matrix1D< double > vectorR2(double x, double y)
int crystal_Xdim
Crystal X dimension.
Matrix1D< double > direction
#define M2x2_BY_CT(M2, M1, k)
#define M3x3_BY_V3x1(a, M, b)
#define CHANGE_COORDS_AND_CHOOSE_CORNERS2D
int crystal_Ydim
Crystal Y dimension.
bool isMetaData(bool failIfNotExists=true) const
void move_following_spiral(Matrix1D< double > &r, const MultidimArray< int > &visited)
FileName removeBlockName() const
bool outside(int k, int i, int j) const
#define FIRST_XMIPP_INDEX(size)
double psi(const double x)
#define VECTOR_R3(v, x, y, z)
FileName fn_shift
file with shifts
String formatString(const char *format,...)
void project_crystal(Phantom &phantom, Projection &P, const ParametersProjection &prm, PROJECT_Side_Info &side, const Crystal_Projection_Parameters &prm_crystal, float rot, float tilt, float psi)
fprintf(glob_prnt.io, "\)
void setAngles(double _rot, double _tilt, double _psi)
void initZeros(const MultidimArray< T1 > &op)
#define M2x2_INV(Ainv, A)
#define LAST_XMIPP_INDEX(size)
void project_to(Projection &P, int Ydim, int Xdim, double rot, double tilt, double psi, const Matrix2D< double > *A=nullptr) const
void resize(size_t Ydim, size_t Xdim, bool noCopy=false)
void init_shift_matrix(const Crystal_Projection_Parameters &prm_crystal, MultidimArray< int > &cell_inside, MultidimArray< double > &exp_shifts_matrix_X, MultidimArray< double > &exp_shifts_matrix_Y, MultidimArray< double > &exp_shifts_matrix_Z, MultidimArray< double > &exp_normal_shifts_matrix_X, MultidimArray< double > &exp_normal_shifts_matrix_Y, MultidimArray< double > &exp_normal_shifts_matrix_Z, double phantom_scale)
std::vector< Feature * > VF
List with the features.
double Nshift_avg
Bias to apply to the magnitude shift.