Xmipp  v3.23.11-Nereus
project_tomography.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Carlos Oscar S. Sorzano (coss@cnb.csic.es)
4  *
5  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20  * 02111-1307 USA
21  *
22  * All comments concerning this program package may be sent to the
23  * e-mail address 'xmipp@cnb.csic.es'
24  ***************************************************************************/
25 
26 #include "project_tomography.h"
27 #include "directions.h"
29 
31 {
32  addUsageLine("Generate projections as if it were a single axis tomographic series.");
33  addSeeAlsoLine("phantom_create, phantom_project");
34  //Params
35  projParam.defineParams(this);
36  //Examples
37  addExampleLine("Generating a set of projections using a projection parameter:", false);
38  addExampleLine("Generating a single projection at 45 degrees around X axis:", false);
39  addExampleLine("Generating a single projection at 45 degrees around Y axis:", false);
40  //Example projection file
41  addExampleLine("In the following link you can find an example of projection parameter file:",false);
42  addExampleLine(" ",false);
43  addExampleLine("https://sourceforge.net/p/testxmipp/code/ci/master/tree/input/tomoProjection.param?format=raw",false);
44 }
45 
47 {
48  projParam.readParams(this);
49 }
50 
52 {
53 
54  Projection proj;
55  MetaDataVec projMD;
56 
58 
61 
62  // Project
63  int expectedNumProjs = FLOOR((projParam.tiltF-projParam.tilt0)/projParam.tiltStep);
64  int numProjs=0;
65 
66  std::cerr << "Projecting ...\n";
67  if (!(projParam.show_angles))
68  init_progress_bar(expectedNumProjs);
69 
70  projMD.setComment("True rot, tilt and psi; rot, tilt, psi, X and Y shifts applied");
71  double tRot,tTilt,tPsi,rot,tilt,psi;
72  FileName fn_proj; // Projection name
73  int idx = 1;
74  size_t objId;
75 
76  int iterAngle=static_cast<int>((projParam.tiltF - projParam.tilt0) / projParam.tiltStep);
77  for (int iangle=0; iangle<=iterAngle; iangle++)
78  {
79  double angle=projParam.tilt0+iangle*projParam.tiltStep;
81  fn_proj = projParam.fnOut;
82  else
83  fn_proj.compose(idx, projParam.fnRoot + ".stk");
84 
85  // Choose Center displacement ........................................
88  Matrix1D<double> inPlaneShift(3);
89  VECTOR_R3(inPlaneShift,shiftX,shiftY,0);
90 
91  projParam.calculateProjectionAngles(proj,angle, 0,inPlaneShift);
92 
93  // Really project ....................................................
97 
98  // Add noise in angles and voxels ....................................
99  proj.getEulerAngles(tRot, tTilt,tPsi);
100 
104 
105  proj.setEulerAngles(rot,tilt,psi);
106 
107  objId = projMD.addObject();
109  {
111  projMD.setValue(MDL_IMAGE,fn_proj,objId);
112  }
113 
114  projMD.setValue(MDL_ANGLE_ROT,rot,objId);
115  projMD.setValue(MDL_ANGLE_TILT,tilt,objId);
116  projMD.setValue(MDL_ANGLE_PSI,psi,objId);
117  projMD.setValue(MDL_ANGLE_ROT2,tRot,objId);
118  projMD.setValue(MDL_ANGLE_TILT2,tTilt,objId);
119  projMD.setValue(MDL_ANGLE_PSI2,tPsi,objId);
120  projMD.setValue(MDL_SHIFT_X,shiftX,objId);
121  projMD.setValue(MDL_SHIFT_Y,shiftY,objId);
122 
123  IMGMATRIX(proj).addNoise(projParam.Npixel_avg, projParam.Npixel_dev, "gaussian");
124 
125  // Save ..............................................................
127  std::cout << idx << "\t" << tRot << "\t"
128  << tTilt << "\t" << tPsi << std::endl;
129  else if ((expectedNumProjs % XMIPP_MAX(1, numProjs / 60))
130  == 0)
131  progress_bar(numProjs);
132 
133  numProjs++;
134  idx++;
135  }
136  if (!projParam.show_angles)
137  progress_bar(expectedNumProjs);
138 
140  {
141  projMD.setComment("Angles rot,tilt and psi contain noisy projection angles and rot2,tilt2 and psi2 contain actual projection angles");
142  projMD.write(projParam.fnRoot + ".sel");
143  }
144 
145  return;
146 }
147 
148 /* Produce Side Information ================================================ */
151 {
152  phantomVol.read(prm.fnPhantom);
153  phantomVol().setXmippOrigin();
154 }
bool only_create_angles
Only create angles, do not project.
Definition: projection.h:81
void init_progress_bar(long total)
void defineParams(XmippProgram *program)
Definition: projection.cpp:74
Rotation angle of an image (double,degrees)
double Npixel_dev
Standard deviation of the noise to be added to each pixel grey value.
Definition: projection.h:101
#define XMIPP_MAX(x, y)
Definition: xmipp_macros.h:193
Tilting angle of an image (double,degrees)
FileName fnOut
Output filename (used for a singleProjection)
Definition: projection.h:67
double tilt0
Minimum tilt around this axis.
Definition: projection.h:92
Tilting angle of an image (double,degrees)
Shift for the image in the X axis (double)
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 compose(const String &str, const size_t no, const String &ext="")
Special label to be used when gathering MDs in MpiMetadataPrograms.
void readParams(XmippProgram *program)
Definition: projection.cpp:97
void write(const FileName &outFile, WriteModeMetaData mode=MD_OVERWRITE) const
#define IMGMATRIX(I)
double tiltF
Maximum tilt around this axis.
Definition: projection.h:94
virtual void setComment(const String &newComment="No comment")
void addSeeAlsoLine(const char *seeAlso)
Rotation angle of an image (double,degrees)
double Npixel_avg
Bias to be applied to each pixel grey value */.
Definition: projection.h:99
int proj_Ydim
Projection Ydim.
Definition: projection.h:78
#define FLOOR(x)
Definition: xmipp_macros.h:240
void produceSideInfo(const ParametersProjectionTomography &prm)
double Ncenter_avg
Bias to apply to the image center.
Definition: projection.h:104
bool setValue(const MDObject &mdValueIn, size_t id)
size_t addObject() override
double Ncenter_dev
Standard deviation of the image center.
Definition: projection.h:106
void progress_bar(long rlen)
void getEulerAngles(double &rot, double &tilt, double &psi, const size_t n=0) const
void addExampleLine(const char *example, bool verbatim=true)
double Nangle_dev
Standard deviation of the angles.
Definition: projection.h:111
int proj_Xdim
Projection Xdim.
Definition: projection.h:76
void calculateProjectionAngles(Projection &P, double angle, double inplaneRot, const Matrix1D< double > &sinplane)
Definition: projection.cpp:277
Psi angle of an image (double,degrees)
FileName fnRoot
Root filename (used for a stack)
Definition: projection.h:65
void setEulerAngles(double rot, double tilt, double psi, const size_t n=0)
bool singleProjection
Only project a single image.
Definition: projection.h:69
double psi(const double x)
double rnd_gaus()
#define VECTOR_R3(v, x, y, z)
Definition: matrix1d.h:124
#define ALL_IMAGES
ParametersProjectionTomography projParam
Projection parameters.
ProgClassifyCL2D * prm
double tiltStep
Step in tilt.
Definition: projection.h:96
Shift for the image in the Y axis (double)
void projectVolumeOffCentered(MultidimArray< double > &V, Projection &P, int Ydim, int Xdim)
Definition: projection.cpp:594
void addUsageLine(const char *line, bool verbatim=false)
unsigned int randomize_random_generator()
Name of an image (std::string)
Image< double > phantomVol
Phantom Xmipp volume.
double Nangle_avg
Bias to apply to the angles.
Definition: projection.h:109