IMP logo
IMP Reference Guide  2.16.0
The Integrative Modeling Platform
RegistrationResult.h
Go to the documentation of this file.
1 /*!
2  * \file IMP/em2d/RegistrationResult.h
3  * \brief Registration results class
4  * Copyright 2007-2021 IMP Inventors. All rights reserved.
5 */
6 
7 #ifndef IMPEM2D_REGISTRATION_RESULT_H
8 #define IMPEM2D_REGISTRATION_RESULT_H
9 
10 #include "IMP/em2d/internal/rotation_helper.h"
11 #include <IMP/em2d/em2d_config.h>
12 #include "IMP/em/ImageHeader.h"
13 #include "IMP/algebra/Vector3D.h"
14 #include "IMP/algebra/Vector2D.h"
15 #include "IMP/algebra/Rotation3D.h"
16 #include "IMP/algebra/Rotation2D.h"
18 #include "IMP/Pointer.h"
19 #include <string>
20 
21 IMPEM2D_BEGIN_NAMESPACE
22 
23 //! Class to manage registration results
24 /*!
25  \note Stores the rotation and in-plane translation needed to register a
26  model with an EM image. The values can come from a coarse registration, or
27  from a fine registration (optimized with simplex).
28  In the second case, the function get_is_optimized_result() will return true
29  Contains:
30  - Rotation in 3D of the model to register its projection with an image
31  - The rotation is understood as ZYZ
32  - shift shift to apply to the projection of the model (after rotation) to
33  align it with the given image
34 */
35 class IMPEM2DEXPORT RegistrationResult {
36  public:
38 
39  RegistrationResult(double phi, double theta, double psi,
40  algebra::Vector2D shift, int projection_index = 0,
41  int image_index = 0, String name = "");
42 
44  algebra::Vector2D shift = algebra::Vector2D(0., 0.),
45  int projection_index = 0, int image_index = 0,
46  String name = "");
47 
48  inline double get_phi() const { return phi_; }
49  inline double get_theta() const { return theta_; }
50  inline double get_psi() const { return psi_; }
51 
52  inline algebra::Vector2D get_shift() const { return shift_; }
53 
54  inline algebra::Vector3D get_shift_3d() const {
55  return algebra::Vector3D(shift_[0], shift_[1], 0.0);
56  }
57 
58  //! Projection that best matches the image after coarse registration
59  inline int get_projection_index() const { return projection_index_; }
60 
61  inline void set_projection_index(int index) { projection_index_ = index; }
62 
63  //! Image that has been registered
64  inline int get_image_index() const { return image_index_; }
65 
66  //! Index of the image that is registered
67  inline void set_image_index(int index) { image_index_ = index; }
68 
69  //! Name of the object
70  inline String get_name() const { return name_; }
71 
72  //! Cross correlation coefficient between the image and the projection of
73  //! the model after registration
74  inline double get_ccc() const { return ccc_; }
75 
76  inline void set_ccc(double ccc) {
77  ccc_ = ccc;
78  is_optimized_result_ = false;
79  }
80 
81  //! Returns the score computed by the ScoreFunction comparing an image
82  //! and a projection
83  double get_score() const { return Score_; }
84 
85  void set_score(double Score) {
86  Score_ = Score;
87  is_optimized_result_ = true;
88  }
89 
90  //! Rotation to apply to the model
91  inline void set_rotation(double phi, double theta, double psi) {
92  phi_ = phi;
93  theta_ = theta;
94  psi_ = psi;
95  R_ = algebra::get_rotation_from_fixed_zyz(phi_, theta_, psi_);
96  }
97 
98  //! Rotation to apply to the model
99  void set_rotation(algebra::Rotation3D R);
100 
101  //! Shift to apply to the projection to register
102  inline void set_shift(algebra::Vector2D shift) { shift_ = shift; }
103 
104  inline void set_name(String name) { name_ = name; }
105 
106  //! adds an in-plane transformation to the result stored
107  //! The translation is understood as a shift (in pixels)
108  void add_in_plane_transformation(algebra::Transformation2D t);
109 
110  IMP_SHOWABLE(RegistrationResult);
111 
112  //! Writes a parseable result
113  void write(std::ostream &out = std::cout) const;
114 
115  //! Writes an info line to with the contents of a result line
116  void write_comment_line(std::ostream &out = std::cout) const;
117 
118  //! read
119  void read(const String &s);
120 
121  //! Gets a random result
122  void set_random_registration(unsigned int index, double maximum_shift);
123 
124  //! Returns the rotation for the 3 projection angles
125  inline algebra::Rotation3D get_rotation() const { return R_; }
126 
127  //! Sets the registration results to the header of an image
128  void set_in_image(em::ImageHeader &header) const;
129 
130  //! Reads the registration parameters from an image
131  void read_from_image(const em::ImageHeader &header);
132 
133  bool get_is_optimized_result() const { return is_optimized_result_; }
134 
135  ~RegistrationResult();
136 
137  protected:
138  //! Translation in pixels and the rows first (y rows, x columns)
140  //! Cross correlation coefficient
141  double ccc_;
142 
143  //! Score
144  double Score_;
145  //! name and index of the projection compared
147  int projection_index_;
148  //! index of the image being registered
150  //! Euler angles (ZYZ)
151  double phi_, theta_, psi_;
153  bool is_optimized_result_;
154 };
156 
157 //! Reads a set of registration results
158 IMPEM2DEXPORT RegistrationResults
159  read_registration_results(const String &filename);
160 
161 //! Writes a set of registration results
162 IMPEM2DEXPORT void write_registration_results(
163  String filename, const RegistrationResults &results);
164 
165 //! Provides a set of random registration results (or parameters)
166 /*!
167  \param[in] n the number of requested results
168  \param[in] maximum_shift shift from the center in pixels
169 */
170 IMPEM2DEXPORT RegistrationResults
171  get_random_registration_results(unsigned int n, double maximum_shift = 5.0);
172 
173 //! Provides a set of registration results with directions of projection
174 //! evenly distributed in the hemisphere
175 /*!
176  \param[in] n_projections the number of requested projections
177 */
178 IMPEM2DEXPORT RegistrationResults
179  get_evenly_distributed_registration_results(unsigned int n_projections);
180 
181 IMPEM2D_END_NAMESPACE
182 
183 #endif /* IMPEM2D_REGISTRATION_RESULT_H */
void set_rotation(double phi, double theta, double psi)
Rotation to apply to the model.
String get_name() const
Name of the object.
Represent a rotation in 2D space.
VectorD< 2 > Vector2D
Definition: VectorD.h:417
String name_
name and index of the projection compared
int get_image_index() const
Image that has been registered.
Class to deal with the header of Electron Microscopy images in IMP.
Definition: ImageHeader.h:28
RegistrationResults get_evenly_distributed_registration_results(unsigned int n_projections)
Simple 2D vector class.
double ccc_
Cross correlation coefficient.
2D transformations. Copyright 2007-2021 IMP Inventors. All rights reserved.
#define IMP_SHOWABLE(Name)
A more IMP-like version of the std::vector.
Definition: Vector.h:40
void set_shift(algebra::Vector2D shift)
Shift to apply to the projection to register.
RegistrationResults get_random_registration_results(unsigned int n, double maximum_shift=5.0)
Provides a set of random registration results (or parameters)
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.
Definition: value_macros.h:23
void set_image_index(int index)
Index of the image that is registered.
algebra::Vector2D shift_
Translation in pixels and the rows first (y rows, x columns)
Rotation3D get_rotation_from_fixed_zyz(double Rot, double Tilt, double Psi)
Generate a rotation object from Euler Angles.
void write_registration_results(String filename, const RegistrationResults &results)
Writes a set of registration results.
Simple 2D transformation class.
int image_index_
index of the image being registered
double phi_
Euler angles (ZYZ)
Simple 3D rotation class.
3D rotation class.
Definition: Rotation3D.h:51
A nullptr-initialized pointer to an IMP Object.
algebra::Rotation3D get_rotation() const
Returns the rotation for the 3 projection angles.
RegistrationResults read_registration_results(const String &filename)
Reads a set of registration results.
VectorD< 3 > Vector3D
Definition: VectorD.h:421
Simple 3D vector class.
int get_projection_index() const
Projection that best matches the image after coarse registration.
Class to manage registration results.
Header for EM images. Compatible with Spider and Xmipp formats Copyright 2007-2021 IMP Inventors...
std::string String
Basic string value.
Definition: types.h:44