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