IMP  2.0.1
The Integrative Modeling Platform
project.h
Go to the documentation of this file.
1 /**
2  * \file project.h
3  * \brief Generation of projections from models or density maps
4  * Copyright 2007-2013 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 
28 IMPEM2D_BEGIN_NAMESPACE
29 
30 // Parameters needed for the core projection routine
31 class IMPEM2DEXPORT ProjectingParameters {
32 public:
33  double pixel_size, resolution;
34 
35  ProjectingParameters() {};
36 
37  /**
38  *
39  * @param ps Pixel size of the image to generate when projection
40  * @param res Resolution used to downsample an atomic model before projecting
41  */
42  ProjectingParameters(double ps, double res):
43  pixel_size(ps), resolution(res) {};
44 
45  /**
46  * Shows information about the class
47  * @param out Stream used to show the information
48  */
49  void show(std::ostream &out = std::cout) const {
50  out << "ProjectingParameters " << pixel_size
51  << " " << resolution << std::endl;};
52 };
53 IMP_VALUES(ProjectingParameters,ProjectingParametersList);
54 
55 
56 // Parameters given as options to the get_projections() functions.
57 // This class augments ProjectingParameters adding values that are options
58 // for the projecting functions, not core parameters.
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 public:
71 #ifndef SWIG
72  IMP::Pointer<ImageReaderWriter> srw; // Writer used to save the images
73 #endif
74  bool save_images; // Save images after projeting
75  bool normalize; // Normalize the projection after generating it
76  bool clear_matrix_before_projecting; // Set the matrix to zeros
77 
78  /**
79  * Constructor. Calls init_defaults()
80  */
81  ProjectingOptions() {init_defaults();}
82 
83  /**
84  * The arguments passed to the constructor are the same as the arguments to
85  * to the constructor of ProjectingParameters class.
86  * @param ps
87  * @param res
88  */
89  ProjectingOptions(double ps, double res): ProjectingParameters(ps, res) {
90  init_defaults();
91  }
92 
93  ProjectingOptions(double ps, double res, ImageReaderWriter *irw):
94  ProjectingParameters(ps, res), srw(irw) {
95  init_defaults();
96  }
97 
98  /**
99  * Shows information about the class
100  * @param out Stream used to show the information
101  */
102  void show(std::ostream &out = std::cout) const {
103  out << "ProjectingOptions " << pixel_size
104  << " " << resolution << std::endl;};
105 };
107 
108 
109 //! Generates projectios 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(const ParticlesTemp &ps,
119  const algebra::SphericalVector3Ds &vs,
120  int rows, int cols, const ProjectingOptions &options,
121  Strings names=Strings());
122 
123 
124 //! Generates projectios from particles
125 /*!
126  \param[in] registration_values Registration values with the parameters of
127  the projections to generate
128  \note See the function get_projections() for the rest of the parameters
129 */
130 IMPEM2DEXPORT em2d::Images get_projections(const ParticlesTemp &ps,
131  const RegistrationResults &registration_values,
132  int rows, int cols, const ProjectingOptions &options,
133  Strings names=Strings());
134 
135 
136 //! Generates a projection from particles
137 /*!
138  \param[in] ps particles to project
139  \param[in] reg Registration value with the parameters of the projection
140  \param[in] masks Precomputed masks for projecting the particles. Very useful
141  for speeding the projection procedure if they are given.
142  If nullptr, they are computed
143  \param[out] img the projection will be stored here
144  \note See the function get_projections() for the rest of the parameters
145 */
146 IMPEM2DEXPORT void get_projection(em2d::Image *img,const ParticlesTemp &ps,
147  const RegistrationResult &reg, const ProjectingOptions &options,
148  MasksManagerPtr masks=MasksManagerPtr(), String name="");
149 
150 
151 //! Projects a set of particles. This is the core function that others call
152 /*!
153  \param[in] ps particles to project
154  \param[in] R rotation to apply to the particles (respect to the centroid)
155  \param[in] translation Translation to apply after rotation
156  \param[in] clear_matrix_before If true the matrix is set to zero before
157  projecting the particles. You want this 99% of the time, as
158  setting to false will add one projection on top of the other
159  \note See the function get_projection() for the rest of the parameters
160 */
161 IMPEM2DEXPORT void do_project_particles(const ParticlesTemp &ps,
162  cv::Mat &m2,
163  const algebra::Rotation3D &R,
164  const algebra::Vector3D &translation,
165  const ProjectingOptions &options,
166  MasksManagerPtr masks);
167 
168 
169 /*! This function is slightly different than the other ones.
170  Only generates evenly distributed projections and determines the size of
171  the images that encloses the particles. Should not be used unless this is
172  exactly what you want.
173 */
175  const ParticlesTemp &ps,
176  unsigned int n,
177  const ProjectingOptions &options);
178 
179 
180 
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,
191  const algebra::Rotation3D &R,
192  const algebra::Vector3D &translation);
193 
194 
195 
196 
197 //! Project the points contained in Vector3Ds
198 /*!
199  \param[in] ps the points
200  \param[in] R Rotation to apply to the points to project them in the Z axis
201  \param[in] translation translation to apply to the points
202  \param[in] center Center point used for the rotation around it
203  \return A set of Vector2D with the projected points
204 */
206  const algebra::Vector3Ds &ps,
207  const algebra::Rotation3D &R,
208  const algebra::Vector3D &translation,
209  const algebra::Vector3D &center);
210 
211 
212 /*! Get an automatic size for an image that contains the particles
213  \param[in] slack is the number of pixels left as border
214 */
215 IMPEM2DEXPORT unsigned int get_enclosing_image_size(const ParticlesTemp &ps,
216  double pixel_size,
217  unsigned int slack);
218 
219 
220 
221 IMPEM2D_END_NAMESPACE
222 
223 
224 #endif /* IMPEM2D_PROJECT_H */