IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
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-2022 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"
18#include "IMP/Pointer.h"
19#include <string>
20#include <cereal/access.hpp>
21
22IMPEM2D_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*/
36class IMPEM2DEXPORT RegistrationResult {
37 public:
38 RegistrationResult();
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
44 RegistrationResult(algebra::Rotation3D R,
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;
97 }
98
99 //! Rotation to apply to the model
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
119 //! read
120 void read(const String &s);
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
129 void set_in_image(em::ImageHeader &header) const;
130
131 //! Reads the registration parameters from an image
132 void read_from_image(const em::ImageHeader &header);
133
134 bool get_is_optimized_result() const { return is_optimized_result_; }
135
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
156private:
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
167IMPEM2DEXPORT RegistrationResults
169
170//! Writes a set of registration results
171IMPEM2DEXPORT 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*/
179IMPEM2DEXPORT 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*/
187IMPEM2DEXPORT RegistrationResults
189
190IMPEM2D_END_NAMESPACE
191
192#endif /* IMPEM2D_REGISTRATION_RESULT_H */
Header for EM images. Compatible with Spider and Xmipp formats Copyright 2007-2022 IMP Inventors....
A nullptr-initialized pointer to an IMP Object.
Represent a rotation in 2D space.
Simple 3D rotation class.
2D transformations. Copyright 2007-2026 IMP Inventors. All rights reserved.
Simple 2D vector class.
Simple 3D vector class.
3D rotation class.
Definition Rotation3D.h:52
Simple 2D transformation class.
Class to manage registration results.
int get_projection_index() const
Projection that best matches the image after coarse registration.
double phi_
Euler angles (ZYZ).
String get_name() const
Name of the object.
void set_in_image(em::ImageHeader &header) const
Sets the registration results to the header of an image.
int get_image_index() const
Image that has been registered.
String name_
name and index of the projection compared
void set_rotation(double phi, double theta, double psi)
Rotation to apply to the model.
void set_shift(algebra::Vector2D shift)
Shift to apply to the projection to register.
void write_comment_line(std::ostream &out=std::cout) const
Writes an info line to with the contents of a result line.
algebra::Vector2D shift_
Translation in pixels and the rows first (y rows, x columns).
void read(const String &s)
read
void set_rotation(algebra::Rotation3D R)
Rotation to apply to the model.
void set_image_index(int index)
Index of the image that is registered.
void set_random_registration(unsigned int index, double maximum_shift)
Gets a random result.
int image_index_
index of the image being registered
void write(std::ostream &out=std::cout) const
Writes a parseable result.
double ccc_
Cross correlation coefficient.
algebra::Rotation3D get_rotation() const
Returns the rotation for the 3 projection angles.
void add_in_plane_transformation(algebra::Transformation2D t)
void read_from_image(const em::ImageHeader &header)
Reads the registration parameters from an image.
Class to deal with the header of Electron Microscopy images in IMP.
Definition ImageHeader.h:28
Rotation3D get_rotation_from_fixed_zyz(double Rot, double Tilt, double Psi)
Generate a rotation object from Euler Angles.
IMP::Vector< RegistrationResult > RegistrationResults
RegistrationResults read_registration_results(const String &filename)
Reads a set of registration results.
RegistrationResults get_evenly_distributed_registration_results(unsigned int n_projections)
void write_registration_results(String filename, const RegistrationResults &results)
Writes a set of registration results.
RegistrationResults get_random_registration_results(unsigned int n, double maximum_shift=5.0)
Provides a set of random registration results (or parameters).
std::string String
Basic string value.
Definition types.h:43
VectorD< 3 > Vector3D
Definition VectorD.h:407
VectorD< 2 > Vector2D
Definition VectorD.h:403
#define IMP_SHOWABLE(Name)
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.