IMP Reference Guide  develop.8b7eb21230,2024/06/24 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
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>
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 #include <cereal/access.hpp>
21
22 IMPEM2D_BEGIN_NAMESPACE
23
24 //! Class to manage registration results
25 /*!
26  \note Stores the rotation and in-plane translation needed to register a
27  model with an EM image. The values can come from a coarse registration, or
28  from a fine registration (optimized with simplex).
29  In the second case, the function get_is_optimized_result() will return true
30  Contains:
31  - Rotation in 3D of the model to register its projection with an image
32  - The rotation is understood as ZYZ
33  - shift shift to apply to the projection of the model (after rotation) to
34  align it with the given image
35 */
36 class IMPEM2DEXPORT RegistrationResult {
37  public:
39
40  RegistrationResult(double phi, double theta, double psi,
41  algebra::Vector2D shift, int projection_index = 0,
42  int image_index = 0, String name = "");
43
45  algebra::Vector2D shift = algebra::Vector2D(0., 0.),
46  int projection_index = 0, int image_index = 0,
47  String name = "");
48
49  inline double get_phi() const { return phi_; }
50  inline double get_theta() const { return theta_; }
51  inline double get_psi() const { return psi_; }
52
53  inline algebra::Vector2D get_shift() const { return shift_; }
54
55  inline algebra::Vector3D get_shift_3d() const {
56  return algebra::Vector3D(shift_[0], shift_[1], 0.0);
57  }
58
59  //! Projection that best matches the image after coarse registration
60  inline int get_projection_index() const { return projection_index_; }
61
62  inline void set_projection_index(int index) { projection_index_ = index; }
63
64  //! Image that has been registered
65  inline int get_image_index() const { return image_index_; }
66
67  //! Index of the image that is registered
68  inline void set_image_index(int index) { image_index_ = index; }
69
70  //! Name of the object
71  inline String get_name() const { return name_; }
72
73  //! Cross correlation coefficient between the image and the projection of
74  //! the model after registration
75  inline double get_ccc() const { return ccc_; }
76
77  inline void set_ccc(double ccc) {
78  ccc_ = ccc;
79  is_optimized_result_ = false;
80  }
81
82  //! Returns the score computed by the ScoreFunction comparing an image
83  //! and a projection
84  double get_score() const { return Score_; }
85
86  void set_score(double Score) {
87  Score_ = Score;
88  is_optimized_result_ = true;
89  }
90
91  //! Rotation to apply to the model
92  inline void set_rotation(double phi, double theta, double psi) {
93  phi_ = phi;
94  theta_ = theta;
95  psi_ = psi;
96  R_ = algebra::get_rotation_from_fixed_zyz(phi_, theta_, psi_);
97  }
98
99  //! Rotation to apply to the model
100  void set_rotation(algebra::Rotation3D R);
101
102  //! Shift to apply to the projection to register
103  inline void set_shift(algebra::Vector2D shift) { shift_ = shift; }
104
105  inline void set_name(String name) { name_ = name; }
106
107  //! adds an in-plane transformation to the result stored
108  //! The translation is understood as a shift (in pixels)
110
111  IMP_SHOWABLE(RegistrationResult);
112
113  //! Writes a parseable result
114  void write(std::ostream &out = std::cout) const;
115
116  //! Writes an info line to with the contents of a result line
117  void write_comment_line(std::ostream &out = std::cout) const;
118
121
122  //! Gets a random result
123  void set_random_registration(unsigned int index, double maximum_shift);
124
125  //! Returns the rotation for the 3 projection angles
126  inline algebra::Rotation3D get_rotation() const { return R_; }
127
128  //! Sets the registration results to the header of an image
130
131  //! Reads the registration parameters from an image
133
134  bool get_is_optimized_result() const { return is_optimized_result_; }
135
136  ~RegistrationResult();
137
138  protected:
139  //! Translation in pixels and the rows first (y rows, x columns)
141  //! Cross correlation coefficient
142  double ccc_;
143
144  //! Score
145  double Score_;
146  //! name and index of the projection compared
148  int projection_index_;
149  //! index of the image being registered
151  //! Euler angles (ZYZ)
152  double phi_, theta_, psi_;
154  bool is_optimized_result_;
155
156 private:
157  friend class cereal::access;
158
159  template<class Archive> void serialize(Archive &ar) {
160  ar(shift_, ccc_, Score_, name_, projection_index_, image_index_,
161  phi_, theta_, psi_, R_, is_optimized_result_);
162  }
163 };
165
166 //! Reads a set of registration results
167 IMPEM2DEXPORT RegistrationResults
169
170 //! Writes a set of registration results
171 IMPEM2DEXPORT void write_registration_results(
172  String filename, const RegistrationResults &results);
173
174 //! Provides a set of random registration results (or parameters)
175 /*!
176  \param[in] n the number of requested results
177  \param[in] maximum_shift shift from the center in pixels
178 */
179 IMPEM2DEXPORT RegistrationResults
180  get_random_registration_results(unsigned int n, double maximum_shift = 5.0);
181
182 //! Provides a set of registration results with directions of projection
183 //! evenly distributed in the hemisphere
184 /*!
185  \param[in] n_projections the number of requested projections
186 */
187 IMPEM2DEXPORT RegistrationResults
188  get_evenly_distributed_registration_results(unsigned int n_projections);
189
190 IMPEM2D_END_NAMESPACE
191
192 #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:404
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.
RegistrationResults get_evenly_distributed_registration_results(unsigned int n_projections)
Simple 2D vector class.
double ccc_
Cross correlation coefficient.
#define IMP_SHOWABLE(Name)
A more IMP-like version of the std::vector.
Definition: Vector.h:50
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:52
A nullptr-initialized pointer to an IMP Object.
algebra::Rotation3D get_rotation() const
Returns the rotation for the 3 projection angles.