IMP  2.1.1
The Integrative Modeling Platform
project.h
Go to the documentation of this file.
1 /**
2  * \file em2d/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/base/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 
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 };
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  */
60 class IMPEM2DEXPORT ProjectingOptions: public ProjectingParameters {
61 
62  /**
63  * Sets the default values for the options: Don't save matching images,
64  * normalize the projections, and clear the data matrix after projecting
65  */
66  void init_defaults() {
67  save_images = false;
68  normalize = true;
69  clear_matrix_before_projecting = true;
70  }
71 public:
72 #ifndef SWIG
73  base::Pointer<ImageReaderWriter> srw; // Writer used to save the images
74 #endif
75  bool save_images; // Save images after projeting
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
105  << " " << resolution << std::endl;};
106 };
108 
109 
110 //! Generates projections from particles
111 /**
112  \param[in] ps particles to project
113  \param[in] vs set of spherical vectors with the directions of projection
114  \param[in] rows size of the images
115  \param[in] cols
116  \param[in] options Options for control the projecting
117  \param[in] names names of the images
118 */
119 IMPEM2DEXPORT em2d::Images get_projections(const kernel::ParticlesTemp &ps,
120  const algebra::SphericalVector3Ds &vs,
121  int rows, int cols, const ProjectingOptions &options,
122  Strings names=Strings());
123 
124 
125 //! Generates projections from particles
126 /**
127  `registration_values` describes registration values with the parameters of
128  the projections to generate.
129 
130  \note See the function get_projections() for the rest of the parameters
131 */
132 IMPEM2DEXPORT em2d::Images get_projections(const kernel::ParticlesTemp &ps,
133  const RegistrationResults &registration_values,
134  int rows, int cols, const ProjectingOptions &options,
135  Strings names=Strings());
136 
137 
138 //! Generates a projection from particles
139 /**
140  \param[in] img
141  \param[in] ps particles to project
142  \param[in] reg Registration value with the parameters of the projection
143  \param[in] options
144  \param[in] masks Precomputed masks for projecting the particles. Very useful
145  for speeding the projection procedure if they are given.
146  If nullptr, they are computed
147  \param[in] name
148  \return img the projection will be stored here
149  \note See the function get_projections() for the rest of the parameters
150 */
151 IMPEM2DEXPORT void get_projection(em2d::Image *img,
152  const kernel::ParticlesTemp &ps,
153  const RegistrationResult &reg, const ProjectingOptions &options,
154  MasksManagerPtr masks=MasksManagerPtr(), String name="");
155 
156 
157 //! Projects a set of particles. This is the core function that others call
158 /**
159  \param[in] ps particles to project
160  \param[in] m2
161  \param[in] R rotation to apply to the particles (respect to the centroid)
162  \param[in] translation Translation to apply after rotation
163  \param[in] options
164  \param[in] masks
165  \note See the function get_projection() for the rest of the parameters
166 */
167 IMPEM2DEXPORT void do_project_particles(const kernel::ParticlesTemp &ps,
168  cv::Mat &m2,
169  const algebra::Rotation3D &R,
170  const algebra::Vector3D &translation,
171  const ProjectingOptions &options,
172  MasksManagerPtr masks);
173 
174 
175 /** This function is slightly different than the other ones.
176  Only generates evenly distributed projections and determines the size of
177  the images that encloses the particles. Should not be used unless this is
178  exactly what you want.
179 */
181  const kernel::ParticlesTemp &ps,
182  unsigned int n,
183  const ProjectingOptions &options);
184 
185 
186 
187 
188 //! Project the points contained in Vector3Ds to gen vectors in 2D
189 /**
190  \param[in] ps the points
191  \param[in] R Rotation to apply to the points to project them in the Z axis
192  \param[in] translation translation to apply to the points
193  \return A set of Vector2D with the projected points
194 */
196  const algebra::Vector3Ds &ps,
197  const algebra::Rotation3D &R,
198  const algebra::Vector3D &translation);
199 
200 
201 
202 
203 //! Project the points contained in Vector3Ds
204 /**
205  \param[in] ps the points
206  \param[in] R Rotation to apply to the points to project them in the Z axis
207  \param[in] translation translation to apply to the points
208  \param[in] center Center point used for the rotation around it
209  \return A set of Vector2D with the projected points
210 */
212  const algebra::Vector3Ds &ps,
213  const algebra::Rotation3D &R,
214  const algebra::Vector3D &translation,
215  const algebra::Vector3D &center);
216 
217 
218 //! Get an automatic size for an image that contains the particles
219 /**
220  slack is the number of pixels left as border
221 */
222 IMPEM2DEXPORT unsigned int get_enclosing_image_size(
223  const kernel::ParticlesTemp &ps, double pixel_size,
224  unsigned int slack);
225 
226 
227 
228 IMPEM2D_END_NAMESPACE
229 
230 
231 #endif /* IMPEM2D_PROJECT_H */
void do_project_particles(const kernel::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.
projection masks Copyright 2007-2013 IMP Inventors. All rights reserved.
A nullptr-initialized pointer to an IMP Object.
unsigned int get_enclosing_image_size(const kernel::ParticlesTemp &ps, double pixel_size, unsigned int slack)
Get an automatic size for an image that contains the particles.
void get_projection(em2d::Image *img, const kernel::ParticlesTemp &ps, const RegistrationResult &reg, const ProjectingOptions &options, MasksManagerPtr masks=MasksManagerPtr(), String name="")
Generates a projection from particles.
Virtual class for reader/writers of images.
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.
IMP::base::Vector< String > Strings
Standard way to pass a bunch of String values.
Definition: base/types.h:51
Virtual class for reader/writers of images Copyright 2007-2013 IMP Inventors. All rights reserved...
Parameters given as options to the get_projections() functions.
Definition: project.h:60
A smart pointer to a reference counted object.
Definition: base/Pointer.h:87
inteface with OpenCV Copyright 2007-2013 IMP Inventors. All rights reserved.
ProjectingOptions(double ps, double res)
Definition: project.h:90
IMP images for Electron Microscopy using openCV matrices Copyright 2007-2013 IMP Inventors. All rights reserved.
algebra::Vector2Ds do_project_vectors(const algebra::Vector3Ds &ps, const algebra::Rotation3D &R, const algebra::Vector3D &translation)
Project the points contained in Vector3Ds to gen vectors in 2D.
ProjectingParameters(double ps, double res)
Definition: project.h:42
Stores and converts spherical coordinates.
void save_images(Images images, const Strings &names, const ImageReaderWriter *rw)
Images create_evenly_distributed_projections(const kernel::ParticlesTemp &ps, unsigned int n, const ProjectingOptions &options)
Simple 3D rotation class.
Parameters needed for the core projection routine.
Definition: project.h:31
3D rotation class.
Definition: Rotation3D.h:45
em2d::Images get_projections(const kernel::ParticlesTemp &ps, const algebra::SphericalVector3Ds &vs, int rows, int cols, const ProjectingOptions &options, Strings names=Strings())
Generates projections from particles.
Simple 3D vector class.
Class to manage registration results.
void show(std::ostream &out=std::cout) const
Definition: project.h:49
void show(std::ostream &out=std::cout) const
Definition: project.h:103
Operations involving FFT Copyright 2007-2013 IMP Inventors. All rights reserved.
Registration results class Copyright 2007-2013 IMP Inventors. All rights reserved.
Decorator for a sphere-like particle.
std::string String
Basic string value.
Definition: base/types.h:44
2D Electron Microscopy images in IMP
Definition: Image.h:32