Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RT.hh
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file core/kinematics/RT.hh
11 /// @brief Rotation + translation class
12 /// @author Phil Bradley
13 
14 
15 #ifndef INCLUDED_core_kinematics_RT_hh
16 #define INCLUDED_core_kinematics_RT_hh
17 
18 
19 // Unit headers
21 
22 // Package headers
23 #include <core/kinematics/Stub.hh>
24 
25 // Numeric Headers
26 #include <numeric/xyzVector.hh>
27 #include <numeric/xyzMatrix.hh>
28 
29 // Utility headers
30 
31 #include <utility/vector1.fwd.hh>
32 
33 #include <utility/vector1.hh>
34 
35 //#include <utility/pointer/ReferenceCount.hh>
36 
37 
38 namespace core {
39 namespace kinematics {
40 
41 
42 /// @brief Rotation + translation class
43 /// @note Used in jumps
44 //class RT : public utility::pointer::ReferenceCount {
45 class RT {
46 
47 public: // Types
48 
49  typedef numeric::xyzVector< Real > Vector; // DOUBLE!
50  typedef numeric::xyzMatrix< Real > Matrix; // DOUBLE!
51 
52  // Types to prevent compile failure when std::distance is in scope
53  typedef void iterator_category;
54  typedef void difference_type;
55 
56 public:
57 
58  /// @brief Default constructor
59  inline
60  RT():
61  rotation( Matrix::identity() ),
62  translation( 0.0 )
63  {}
64 
65  /// @brief matrix/vector constructor
66  inline
67  RT( Matrix const & rot, Vector const & vec ):
68  rotation( rot ),
69  translation( vec )
70  {}
71 
72  /// @brief construct from two stubs
73  RT( Stub const & stub1, Stub const & stub2 )
74  {
75  this->from_stubs( stub1, stub2 );
76  }
77 
78  /// @brief copy constructor
79  RT ( RT const & src ):
80  //ReferenceCount(),
81  rotation( src.rotation ),
83  {}
84 
85  /// @brief update from stubs
86  void
88  Stub const & stub1,
89  Stub const & stub2
90  )
91  {
92  translation = stub1.M.transposed() * ( stub2.v - stub1.v );
93  rotation = stub1.M.transposed() * stub2.M;
94  }
95 
96  /// @brief reverse the "view"
97  void
99  {
100  // new rotation is the inversed(transposed) old rotation
101  rotation.transpose();
102 
103  // new translation is the negated old tranlation in m1 frame rewritten
104  // in m2 frame (left multiplied by old_rotation^T = new_rotation)
105  translation = rotation * translation.negate();
106  }
107 
108  /// @brief reverse the "view"
109  void
111  {
112  reverse();
113  }
114 
115  /// @brief return to default-constructed state
116  void
118  {
119  translation.zero();
120  rotation.to_identity();
121  }
122 
123  /// @brief return to default-constructed state (another name)
124  void
126  {
127  translation.zero();
128  rotation.to_identity();
129  }
130 
131  /// @brief set the tranlsation
132  void
134  {
135  translation = t;
136  }
137 
138  /// @brief set the rotation
139  void
140  set_rotation( Matrix const & r )
141  {
142  rotation = r;
143  }
144 
145 
146  /// @brief get the rotation
147  Matrix const &
148  get_rotation() const
149  {
150  return rotation;
151  }
152 
153  /// @brief get the translation
154  Vector const &
156  {
157  return translation;
158  }
159 
160  ///
161  Real
162  distance_squared( RT const & b ) const
163  {
164  return ( translation .distance_squared( b.translation ) +
165  rotation.col(1).distance_squared( b.rotation.col(1) ) +
166  rotation.col(2).distance_squared( b.rotation.col(2) ) +
167  rotation.col(3).distance_squared( b.rotation.col(3) ) );
168  }
169 
170 
171  /// @brief update the transform to include small additional rigid-body rotations and translations
172  /// @note PHIL: IT WOULD BE GOOD TO ELIMINATE ARGUMENT ARRAYS IN MINI BY USE OF
173  /// APPROPRIATE LAYERED DATA STRUCTURES
174  void
176  utility::vector1<Real> const & rb,
177  Vector const & rb_center
178  );
179 
180 
181  /// @brief should be inverse of RT::from_stubs
182  void
184  Stub const & stub1,
185  Stub & stub2
186  ) const
187  {
188  stub2.M = stub1.M * rotation;
189  stub2.v = stub1.v + stub1.M * translation;
190  }
191 
192  /// @brief output operator
193  friend std::ostream & operator <<( std::ostream & os, RT const & rt );
194  /// @brief input operator
195  friend std::istream & operator >>( std::istream & is, RT & rt );
196 
197  /// @brief copy operator
198  RT & operator =( RT const & src ) {
199  rotation = src.rotation;
200  translation = src.translation;
201  return *this;
202  }
203 
204  /// @brief check for orthogonality
205  bool ortho_check() const;
206 
207  friend
208  inline
209  Real
210  distance( RT const & a, RT const & b );
211 
212 
213 private: // Fields
214  /// rotation matrix, written in stub1 frame
215  Matrix rotation; // 3x3
216  /// tranlsation vector, written in stub1 frame
218 
219 }; // RT
220 
221 
222 ///////////////////////////////////////////////////////////////////////////////
223 /// @brief root squared devitation of two RTs
224 inline
225 Real
226 distance( RT const & a, RT const & b )
227 {
228  using namespace numeric;
229  return
230  std::sqrt( a.rotation.col(1).distance_squared( b.rotation.col(1) ) +
231  a.rotation.col(2).distance_squared( b.rotation.col(2) ) +
232  a.rotation.col(3).distance_squared( b.rotation.col(3) ) +
233  a.translation .distance_squared( b.translation ) );
234 }
235 
236 } // kinematics
237 } // core
238 
239 
240 #endif // INCLUDED_core_kinematics_RT_HH