Xmipp  v3.23.11-Nereus
projection.h
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 #ifndef CORE_PROJECTION_H
27 #define CORE_PROJECTION_H
28 
29 #include "core/xmipp_filename.h"
30 #include "core/xmipp_threads.h"
31 #include "core/matrix1d.h"
32 #include "grids.h"
33 
34 class Projection;
35 template<typename T>
36 class Image;
37 template<typename T>
38 class Matrix2D;
39 template<typename T>
40 class MultidimArray;
41 class SimpleGrid;
42 class Basis;
43 class XmippProgram;
44 
48 
49 // These two structures are needed when projecting and backprojecting using
50 // threads. They make mutual exclusion and synchronization possible.
52 extern pthread_mutex_t project_mutex;
53 
54 /* Projection parameters for tomography --------------------------- */
59 {
60 public:
71  int starting;
74 
76  int proj_Xdim;
78  int proj_Ydim;
79 
82  // Show angles calculation in std::out
84 
86  double axisRot;
88  double axisTilt;
92  double tilt0;
94  double tiltF;
96  double tiltStep;
97 
99  double Npixel_avg;
101  double Npixel_dev;
102 
104  double Ncenter_avg;
106  double Ncenter_dev;
107 
109  double Nangle_avg;
111  double Nangle_dev;
112 
113 public:
114 
116 
119  void read(const FileName &fn_proj_param);
120  void defineParams(XmippProgram * program);
121  void readParams(XmippProgram * program);
122 
126  void calculateProjectionAngles(Projection &P, double angle, double inplaneRot,
127  const Matrix1D<double> &sinplane);
128 };
129 
137 typedef struct
138 {
142  const SimpleGrid * grid;
143  const Basis * basis;
146  int FORW;
147  int eq_mode;
148  const Image<int> *VNeq;
151  double ray_length;
152  double rot;
153  double tilt;
154  double psi;
155  bool destroy;
156 }
158 
160 
161 template <class T>
162 void project_SimpleGrid(Image<T> *vol, const SimpleGrid *grid,
163  const Basis *basis,
164  Projection *proj, Projection *norm_proj, int FORW, int eq_mode,
165  const Image<int> *VNeq, Matrix2D<double> *M,
166  const MultidimArray<int> *mask=nullptr,
167  double ray_length = -1.0,
168  int thread_id = -1, int num_threads = 1);
169 
170 /*---------------------------------------------------------------------------*/
171 /* PROJECTION GENERATION */
172 /*---------------------------------------------------------------------------*/
173 // Projecting functions ====================================================
174 constexpr int FORWARD = 1;
175 constexpr int BACKWARD = 0;
176 
177 constexpr int ARTK = 1;
178 constexpr int CAVK = 2;
179 constexpr int COUNT_EQ = 3;
180 constexpr int CAV = 4;
181 constexpr int CAVARTK = 5;
182 
196 void projectVolume(MultidimArray<double> &V, Projection &P, int Ydim, int Xdim,
197  double rot, double tilt, double psi,
198  const Matrix1D<double> *roffset=nullptr);
199 
216  int Ydim, int Xdim);
217 
229 
234  const Basis &basis, Projection &read_proj);
235 
245 void project_Crystal_Volume(GridVolume &vol, const Basis &basis,
246  Projection &proj, Projection &norm_proj,
247  int Ydim, int Xdim,
248  double rot, double tilt, double psi, const Matrix1D<double> &shift,
249  const Matrix1D<double> &aint, const Matrix1D<double> &bint,
250  const Matrix2D<double> &D, const Matrix2D<double> &Dinv,
251  const MultidimArray<int> &mask, int FORW, int eq_mode = ARTK);
252 
253 // Implementations =========================================================
254 // Some aliases
255 #define x0 STARTINGX(IMGMATRIX(*proj))
256 #define xF FINISHINGX(IMGMATRIX(*proj))
257 #define y0 STARTINGY(IMGMATRIX(*proj))
258 #define yF FINISHINGY(IMGMATRIX(*proj))
259 #define xDim XSIZE(IMGMATRIX(*proj))
260 #define yDim YSIZE(IMGMATRIX(*proj))
261 
262 // Projections from single particles #######################################
263 // Projections from basis volumes ==========================================
264 
265 /* Projection of a simple volume ------------------------------------------- */
266 // The projection is not precleaned (set to 0) before projecting and its
267 // angles are supposed to be already written (and all Euler matrices
268 // precalculated
269 // The projection plane is supposed to pass through the Universal coordinate
270 // origin
271 
272 /* Time measures ...........................................................
273  This function has been optimized in time, several approaches have been
274  tried and here are the improvements in time
275  Case: Base (unit time measure)
276  The points within the footprint are calculated inside the
277  inner loop instead of computing the foot coordinate for the
278  first corner and knowing the sampling rate in the oversampled
279  image go on the next points. The image access was done directly
280  (physical access).
281 
282  Notation simplification:
283  Case: VOLVOXEL(V,k,i,j) ----> V(k,i,j): + 38% (Inacceptable)
284  Case: DIRECT_IMGPIXEL ----> IMGPIXEL: + 5% (Acceptable)
285 
286  Algorithmic changes:
287  Case: project each basis position ----> +325% (Inacceptable)
288  get rid of all beginZ, beginY, prjX, ... and project each
289  basis position onto the projection plane
290  Case: footprint coordinates outside ----> - 33% (Great!!)
291  the footprint coordinates are computed outside the inner
292  loop, but you have to use the sampling rate instead to
293  move over the oversampled image.
294 */
295 
296 const int ART_PIXEL_SUBSAMPLING = 2;
297 
300 template <class T>
301 void *project_SimpleGridThread( void * params );
302 
306 template <class T>
307 void project_SimpleGrid(Image<T> *vol, const SimpleGrid *grid,
308  const Basis *basis,
309  Projection *proj, Projection *norm_proj, int FORW, int eq_mode,
310  const Image<int> *VNeq, Matrix2D<double> *M,
311  const MultidimArray<int> *mask,
312  double ray_length,
313  int thread_id, int numthreads);
314 
315 /* Project a Grid Volume --------------------------------------------------- */
342 template <class T>
343 void project_GridVolume(
344  GridVolumeT<T> &vol, // Volume
345  const Basis &basis, // Basis
346  Projection &proj, // Projection
347  Projection &norm_proj, // Projection of a unitary volume
348  int Ydim, // Dimensions of the projection
349  int Xdim,
350  double rot, double tilt, double psi, // Euler angles
351  int FORW, // 1 if we are projecting a volume
352  // norm_proj is calculated
353  // 0 if we are backprojecting
354  // norm_proj must be valid
355  int eq_mode, // ARTK, CAVARTK, CAVK or CAV
356  GridVolumeT<int> *GVNeq, // Number of equations per blob
357  Matrix2D<double> *M, // System matrix
358  const MultidimArray<int> *mask, // mask(i,j)=0 => do not update this pixel
359  double ray_length, // Ray length of the projection
360  int threads);
361 
362 #undef x0
363 #undef xF
364 #undef y0
365 #undef yF
366 #undef xDim
367 #undef yDim
368 
369 #endif
const MultidimArray< int > * mask
Definition: projection.h:150
bool only_create_angles
Only create angles, do not project.
Definition: projection.h:81
void defineParams(XmippProgram *program)
Definition: projection.cpp:74
double Npixel_dev
Standard deviation of the noise to be added to each pixel grey value.
Definition: projection.h:101
constexpr int FORWARD
Definition: projection.h:174
FileName fnOut
Output filename (used for a singleProjection)
Definition: projection.h:67
std::string fn_projection_extension
Extension for projection filenames. This is optional.
Definition: projection.h:73
constexpr int COUNT_EQ
Definition: projection.h:179
Projection * global_norm_proj
Definition: projection.h:145
const SimpleGrid * grid
Definition: projection.h:142
double tilt0
Minimum tilt around this axis.
Definition: projection.h:92
void * project_SimpleGridThread(void *params)
constexpr int ARTK
Definition: projection.h:177
void readParams(XmippProgram *program)
Definition: projection.cpp:97
void singleWBP(MultidimArray< double > &V, Projection &P)
Definition: projection.cpp:609
double tiltF
Maximum tilt around this axis.
Definition: projection.h:94
const Image< int > * VNeq
Definition: projection.h:148
Matrix1D< double > raxis
Offset of the tilt axis.
Definition: projection.h:90
Definition: mask.h:36
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
const int ART_PIXEL_SUBSAMPLING
Definition: projection.h:296
void project_SimpleGrid(Image< T > *vol, const SimpleGrid *grid, const Basis *basis, Projection *proj, Projection *norm_proj, int FORW, int eq_mode, const Image< int > *VNeq, Matrix2D< double > *M, const MultidimArray< int > *mask=nullptr, double ray_length=-1.0, int thread_id=-1, int num_threads=1)
double Ncenter_avg
Bias to apply to the image center.
Definition: projection.h:104
void projectVolume(MultidimArray< double > &V, Projection &P, int Ydim, int Xdim, double rot, double tilt, double psi, const Matrix1D< double > *roffset=nullptr)
Definition: projection.cpp:337
double Ncenter_dev
Standard deviation of the image center.
Definition: projection.h:106
void project_GridVolume(GridVolumeT< T > &vol, const Basis &basis, Projection &proj, Projection &norm_proj, int Ydim, int Xdim, double rot, double tilt, double psi, int FORW, int eq_mode, GridVolumeT< int > *GVNeq, Matrix2D< double > *M, const MultidimArray< int > *mask, double ray_length, int threads)
Definition: basis.h:45
pthread_mutex_t project_mutex
Definition: projection.cpp:47
double Nangle_dev
Standard deviation of the angles.
Definition: projection.h:111
int proj_Xdim
Projection Xdim.
Definition: projection.h:76
void project_Crystal_Volume(GridVolume &vol, const Basis &basis, Projection &proj, Projection &norm_proj, int Ydim, int Xdim, double rot, double tilt, double psi, const Matrix1D< double > &shift, const Matrix1D< double > &aint, const Matrix1D< double > &bint, const Matrix2D< double > &D, const Matrix2D< double > &Dinv, const MultidimArray< int > &mask, int FORW, int eq_mode=ARTK)
void calculateProjectionAngles(Projection &P, double angle, double inplaneRot, const Matrix1D< double > &sinplane)
Definition: projection.cpp:277
double axisRot
Rotational angle of the tilt axis.
Definition: projection.h:86
FileName fnRoot
Root filename (used for a stack)
Definition: projection.h:65
double axisTilt
Tilt angle of the tilt axis.
Definition: projection.h:88
constexpr int CAV
Definition: projection.h:180
barrier_t project_barrier
Definition: projection.cpp:46
constexpr int CAVARTK
Definition: projection.h:181
Image< double > * vol
Definition: projection.h:141
Matrix2D< double > * M
Definition: projection.h:149
bool singleProjection
Only project a single image.
Definition: projection.h:69
constexpr int CAVK
Definition: projection.h:178
double psi(const double x)
project_thread_params * project_threads
Definition: projection.cpp:48
constexpr int BACKWARD
Definition: projection.h:175
Projection * global_proj
Definition: projection.h:144
void read(const FileName &fn_proj_param)
Definition: projection.cpp:129
double tiltStep
Step in tilt.
Definition: projection.h:96
void projectVolumeOffCentered(MultidimArray< double > &V, Projection &P, int Ydim, int Xdim)
Definition: projection.cpp:594
void count_eqs_in_projection(GridVolumeT< int > &GVNeq, const Basis &basis, Projection &read_proj)
int starting
First projection number. By default, 1.
Definition: projection.h:71
double Nangle_avg
Bias to apply to the angles.
Definition: projection.h:109
const Basis * basis
Definition: projection.h:143