IMP  2.0.1
The Integrative Modeling Platform
RegistrationResult.h
Go to the documentation of this file.
1 /*!
2  * \file RegistrationResult.h
3  * \brief Registration results class
4  * Copyright 2007-2013 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  I 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:
37 
39 
40  RegistrationResult(double phi,double theta,double psi,
41  algebra::Vector2D shift,
42  int projection_index=0,
43  int image_index=0,
44  String name="");
45 
48  int projection_index=0,
49  int image_index=0,
50  String name = "");
51 
52 
53  inline double get_phi() const { return phi_;}
54  inline double get_theta() const { return theta_;}
55  inline double get_psi() const { return psi_;}
56 
57  inline algebra::Vector2D get_shift() const { return shift_;}
58 
59  inline algebra::Vector3D get_shift_3d() const {
60  return algebra::Vector3D(shift_[0],shift_[1],0.0);
61  }
62 
63  //! Projection that best matches the image after coarse registration
64  inline int get_projection_index() const { return projection_index_;}
65 
66  inline void set_projection_index(int index) {projection_index_=index;}
67 
68  //! Image that has been registered
69  inline int get_image_index() const { return image_index_;}
70 
71  //! Index of the image that is registered
72  inline void set_image_index(int index) {image_index_=index;}
73 
74  //! Name of the object
75  inline String get_name() const { return name_;}
76 
77  //! Cross correlation coefficient between the image and the projection of
78  //! the model after registration
79  inline double get_ccc() const { return ccc_;}
80 
81  inline void set_ccc(double ccc) {
82  ccc_ = ccc;
83  is_optimized_result_ = false;
84  }
85 
86  //! Returns the score computed by the ScoreFunction comparing an image
87  //! and a projection
88  double get_score() const { return Score_;}
89 
90  void set_score(double Score) {
91  Score_= Score;
92  is_optimized_result_ = true;
93  }
94 
95 
96  //! Rotation to apply to the model
97  inline void set_rotation(double phi,double theta,double psi) {
98  phi_=phi; theta_=theta; psi_=psi;
99  R_=algebra::get_rotation_from_fixed_zyz(phi_,theta_,psi_);
100  }
101 
102  //! Rotation to apply to the model
103  void set_rotation(algebra::Rotation3D R);
104 
105 
106  //! Shift to apply to the projection to register
107  inline void set_shift(algebra::Vector2D shift) { shift_=shift;}
108 
109  inline void set_name(String name) {name_=name;}
110 
111  //! adds an in-plane transformation to the result stored
112  //! The translation is understood as a shift (in pixels)
113  void add_in_plane_transformation(algebra::Transformation2D t);
114 
115  IMP_SHOWABLE(RegistrationResult);
116 
117  //! Writes a parseable result
118  void write(std::ostream& out = std::cout) const;
119 
120  //! Writes an info line to with the contents of a result line
121  void write_comment_line(std::ostream& out = std::cout) const;
122 
123  //! read
124  void read(const String &s);
125 
126  //! Gets a random result
127  void set_random_registration(unsigned int index,double maximum_shift);
128 
129  //! Returns the rotation for the 3 projection angles
131  return R_;
132  }
133 
134  //! Sets the registration results to the header of an image
135  void set_in_image(em::ImageHeader &header) const;
136 
137  //! Reads the registration parameters from an image
138  void read_from_image(const em::ImageHeader &header);
139 
140  bool get_is_optimized_result() const { return is_optimized_result_; }
141 
142  ~RegistrationResult();
143 
144 protected:
145  //! Translation in pixels and the rows first (y rows, x columns)
147  //! Cross correlation coefficient
148  double ccc_;
149 
150  //! Score
151  double Score_;
152  //! name and index of the projection compared
154  int projection_index_;
155  //! index of the image being registered
157  //! Euler angles (ZYZ)
158  double phi_,theta_,psi_;
160  // false when the RegistrationResult is built from a rotation directly
161  bool angles_defined_,is_optimized_result_;
162 };
164 
165 //! Reads a set of registration results
167  const String &filename);
168 
169 //! Writes a set of registration results
170 IMPEM2DEXPORT void write_registration_results(
171  String filename,const RegistrationResults &results);
172 
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 */
180  (unsigned int n,double maximum_shift=5.0);
181 
182 
183 //! Provides a set of registration results with directions of projection
184 //! evenly distributed in the semisphere
185 /*!
186  \param[in] n_projections the number of requested projections
187 */
188 IMPEM2DEXPORT RegistrationResults
189  get_evenly_distributed_registration_results(unsigned int n_projections);
190 
191 
192 inline double get_random_between_zero_and_one() {
193  return (static_cast<double>(rand()) /(static_cast<double>(RAND_MAX)+1));
194 }
195 
196 IMPEM2D_END_NAMESPACE
197 
198 #endif /* IMPEM2D_REGISTRATION_RESULT_H */