IMP logo
IMP Reference Guide  develop.eb1b99edaa,2026/06/25
The Integrative Modeling Platform
project.h
Go to the documentation of this file.
1 /**
2  * \file IMP/em2d/project.h
3  * \brief Generation of projections from models or density maps
4  * Copyright 2007-2022 IMP Inventors. All rights reserved.
5 */
6 
7 #ifndef IMPEM2D_PROJECT_H
8 #define IMPEM2D_PROJECT_H
9 
10 #include <IMP/em2d/em2d_config.h>
13 #include "IMP/em2d/Image.h"
15 #include "IMP/em2d/FFToperations.h"
17 #include "IMP/algebra/Vector3D.h"
18 #include "IMP/algebra/Rotation3D.h"
20 #include "IMP/core/XYZR.h"
21 #include "IMP/Pointer.h"
22 #include "IMP.h"
23 #include <complex>
24 #include <algorithm>
25 #include <fstream>
26 #include <cereal/access.hpp>
27 
28 IMPEM2D_BEGIN_NAMESPACE
29 
30 //! Parameters needed for the core projection routine
31 class IMPEM2DEXPORT ProjectingParameters {
32 private:
33  friend class cereal::access;
34 
35  template<class Archive> void serialize(Archive &ar) {
36  ar(pixel_size, resolution);
37  }
38 
39  public:
40  double pixel_size, resolution;
41 
43 
44  /**
45  *
46  * @param ps Pixel size of the image to generate when projection
47  * @param res Resolution used to downsample an atomic model before projecting
48  */
49  ProjectingParameters(double ps, double res)
50  : pixel_size(ps), resolution(res) {};
51 
52  /**
53  * Shows information about the class
54  * @param out Stream used to show the information
55  */
56  void show(std::ostream &out = std::cout) const {
57  out << "ProjectingParameters " << pixel_size << " " << resolution
58  << std::endl;
59  };
60 };
62 
63 //! Parameters given as options to the get_projections() functions.
64 /** This class augments ProjectingParameters adding values that are options
65  for the projecting functions, not core parameters.
66  */
67 class IMPEM2DEXPORT ProjectingOptions : public ProjectingParameters {
68 
69  /**
70  * Sets the default values for the options: Don't save matching images,
71  * normalize the projections, and clear the data matrix after projecting
72  */
73  void init_defaults() {
74  save_images = false;
75  normalize = true;
76  clear_matrix_before_projecting = true;
77  }
78 
79  public:
80 #ifndef SWIG
81  Pointer<ImageReaderWriter> srw; // Writer used to save the images
82 #endif
83  bool save_images; // Save images after projecting
84  bool normalize; // Normalize the projection after generating it
85  bool clear_matrix_before_projecting; // Set the matrix to zeros
86 
87  /**
88  * Constructor. Calls init_defaults()
89  */
90  ProjectingOptions() { init_defaults(); }
91 
92  /**
93  * The arguments passed to the constructor are the same as the arguments to
94  * to the constructor of ProjectingParameters class.
95  * @param ps
96  * @param res
97  */
98  ProjectingOptions(double ps, double res) : ProjectingParameters(ps, res) {
99  init_defaults();
100  }
101 
102  ProjectingOptions(double ps, double res, ImageReaderWriter *irw)
103  : ProjectingParameters(ps, res), srw(irw) {
104  init_defaults();
105  }
106 
107  /**
108  * Shows information about the class
109  * @param out Stream used to show the information
110  */
111  void show(std::ostream &out = std::cout) const {
112  out << "ProjectingOptions " << pixel_size << " " << resolution << std::endl;
113  };
114 };
116 
117 //! Generates projections from particles
118 /**
119  \param[in] ps particles to project
120  \param[in] vs set of spherical vectors with the directions of projection
121  \param[in] rows size of the images
122  \param[in] cols
123  \param[in] options Options for control the projecting
124  \param[in] names names of the images
125 */
126 IMPEM2DEXPORT em2d::Images get_projections(
127  const ParticlesTemp &ps, const algebra::SphericalVector3Ds &vs,
128  int rows, int cols, const ProjectingOptions &options,
129  Strings names = Strings());
130 
131 //! Generates projections from particles
132 /**
133  `registration_values` describes registration values with the parameters of
134  the projections to generate.
135 
136  \note See the function get_projections() for the rest of the parameters
137 */
138 IMPEM2DEXPORT em2d::Images get_projections(
139  const ParticlesTemp &ps,
140  const RegistrationResults &registration_values, int rows, int cols,
141  const ProjectingOptions &options, Strings names = Strings());
142 
143 //! Generates a projection from particles
144 /**
145  \param[out] img the projection will be stored here
146  \param[in] ps particles to project
147  \param[in] reg Registration value with the parameters of the projection
148  \param[in] options
149  \param[in] masks Precomputed masks for projecting the particles. Very useful
150  for speeding the projection procedure if they are given.
151  If nullptr, they are computed
152  \param[in] name
153  \note See the function get_projections() for the rest of the parameters
154 */
155 IMPEM2DEXPORT void get_projection(em2d::Image *img,
156  const ParticlesTemp &ps,
157  const RegistrationResult &reg,
158  const ProjectingOptions &options,
159  MasksManagerPtr masks = MasksManagerPtr(),
160  String name = "");
161 
162 //! Projects a set of particles. This is the core function that others call
163 /**
164  \param[in] ps particles to project
165  \param[in] m2
166  \param[in] R rotation to apply to the particles (respect to the centroid)
167  \param[in] translation Translation to apply after rotation
168  \param[in] options
169  \param[in] masks
170  \note See the function get_projection() for the rest of the parameters
171 */
172 IMPEM2DEXPORT void do_project_particles(const ParticlesTemp &ps,
173  cv::Mat &m2,
174  const algebra::Rotation3D &R,
175  const algebra::Vector3D &translation,
176  const ProjectingOptions &options,
177  MasksManagerPtr masks);
178 
179 /** This function is slightly different than the other ones.
180  Only generates evenly distributed projections and determines the size of
181  the images that encloses the particles. Should not be used unless this is
182  exactly what you want.
183 */
184 IMPEM2DEXPORT Images
186  unsigned int n,
187  const ProjectingOptions &options);
188 
189 //! Project the points contained in Vector3Ds to gen vectors in 2D
190 /**
191  \param[in] ps the points
192  \param[in] R Rotation to apply to the points to project them in the Z axis
193  \param[in] translation translation to apply to the points
194  \return A set of Vector2D with the projected points
195 */
197  const algebra::Vector3Ds &ps, const algebra::Rotation3D &R,
198  const algebra::Vector3D &translation);
199 
200 //! Project the points contained in Vector3Ds
201 /**
202  \param[in] ps the points
203  \param[in] R Rotation to apply to the points to project them in the Z axis
204  \param[in] translation translation to apply to the points
205  \param[in] center Center point used for the rotation around it
206  \return A set of Vector2D with the projected points
207 */
209  const algebra::Vector3Ds &ps, const algebra::Rotation3D &R,
210  const algebra::Vector3D &translation, const algebra::Vector3D &center);
211 
212 //! Get an automatic size for an image that contains the particles
213 /**
214  slack is the number of pixels left as border
215 */
216 IMPEM2DEXPORT unsigned int get_enclosing_image_size(
217  const ParticlesTemp &ps, double pixel_size, unsigned int slack);
218 
219 IMPEM2D_END_NAMESPACE
220 
221 #endif /* IMPEM2D_PROJECT_H */
Images create_evenly_distributed_projections(const ParticlesTemp &ps, unsigned int n, const ProjectingOptions &options)
projection masks Copyright 2007-2023 IMP Inventors. All rights reserved.
IMP::Vector< String > Strings
Standard way to pass a bunch of String values.
Definition: types.h:50
Include all non-deprecated headers in IMP.
Virtual class for reader/writers of images.
void do_project_particles(const ParticlesTemp &ps, cv::Mat &m2, const algebra::Rotation3D &R, const algebra::Vector3D &translation, const ProjectingOptions &options, MasksManagerPtr masks)
Projects a set of particles. This is the core function that others call.
Virtual class for reader/writers of images Copyright 2007-2022 IMP Inventors. All rights reserved...
Parameters given as options to the get_projections() functions.
Definition: project.h:67
Interface with OpenCV Copyright 2007-2026 IMP Inventors. All rights reserved.
ProjectingOptions(double ps, double res)
Definition: project.h:98
A more IMP-like version of the std::vector.
Definition: Vector.h:50
IMP images for Electron Microscopy using openCV matrices Copyright 2007-2022 IMP Inventors. All rights reserved.
A smart pointer to a reference counted object.
Definition: Pointer.h:87
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.
Definition: value_macros.h:23
ProjectingParameters(double ps, double res)
Definition: project.h:49
VectorD< 3 > Vector3D
Definition: VectorD.h:407
Stores and converts spherical coordinates.
Simple 3D vector class.
Vector< VectorD< 2 > > Vector2Ds
Definition: VectorD.h:405
algebra::Vector2Ds do_project_vectors(const algebra::Vector3Ds &ps, const algebra::Rotation3D &R, const algebra::Vector3D &translation, const algebra::Vector3D &center)
Project the points contained in Vector3Ds.
void save_images(Images images, const Strings &names, const ImageReaderWriter *rw)
Simple 3D rotation class.
Parameters needed for the core projection routine.
Definition: project.h:31
Vector< VectorD< 3 > > Vector3Ds
Definition: VectorD.h:409
3D rotation class.
Definition: Rotation3D.h:52
unsigned int get_enclosing_image_size(const ParticlesTemp &ps, double pixel_size, unsigned int slack)
Get an automatic size for an image that contains the particles.
A nullptr-initialized pointer to an IMP Object.
Class to manage registration results.
void show(std::ostream &out=std::cout) const
Definition: project.h:56
void show(std::ostream &out=std::cout) const
Definition: project.h:111
em2d::Images get_projections(const ParticlesTemp &ps, const RegistrationResults &registration_values, int rows, int cols, const ProjectingOptions &options, Strings names=Strings())
Generates projections from particles.
Operations involving FFT Copyright 2007-2022 IMP Inventors. All rights reserved.
Registration results class Copyright 2007-2022 IMP Inventors. All rights reserved.
Decorator for a sphere-like particle.
std::string String
Basic string value.
Definition: types.h:43
2D Electron Microscopy images in IMP
Definition: Image.h:27
void get_projection(em2d::Image *img, const ParticlesTemp &ps, const RegistrationResult &reg, const ProjectingOptions &options, MasksManagerPtr masks=MasksManagerPtr(), String name="")
Generates a projection from particles.