Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RT.cc
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.cc
11 /// @brief Rotation + translation class
12 /// @author Phil Bradley
13 
14 
15 // Unit headers
16 #include <core/kinematics/RT.hh>
17 
18 // Package headers
19 #include <core/kinematics/Stub.hh>
20 
21 // Numeric headers
22 #include <numeric/xyz.functions.hh>
23 
24 // C++ Headers
25 #include <iostream>
26 #include <string>
27 
28 #include <utility/vector1.hh>
29 
30 
31 
32 namespace core {
33 namespace kinematics {
34 
35 ///////////////////////////////////////////////////////////////////////////////
36 /// @details rb are the small changes in translation and rotation, written in up-stream (jump_start)
37 /// rb_center is the center of rotation, written in the down-stream (jump_end)
38 
39 // coordinate system NOTE: downstream!!!!!
40 //
41 void
43  utility::vector1<Real> const & rb,
44  Vector const & rb_center
45 )
46 {
47  using namespace numeric;
48 
49  assert( Size(rb.size()) == 6 );
50  // simple: rotation gets multiplied by Rzyx,
51  // translation (t) goes to center + Rzyx(t-center) + rb_trans
52 
53  // find position of rb-center in jump_start coord sys
54  // m2 -> m1: R * V
55  Vector new_center(translation + rotation * rb_center);
56 
57 
58  // create a transformation matrix from the 3 rb angles
59  Matrix const Rzyx(
60  z_rotation_matrix_degrees( rb[6] ) * (
61  y_rotation_matrix_degrees( rb[5] ) *
62  x_rotation_matrix_degrees( rb[4] ) )
63  );
64 
65  rotation.left_multiply_by( Rzyx );
66 
67 
68  Vector rb_trans( rb[1], rb[2], rb[3] ); // load the first 3
69  translation = new_center + Rzyx * ( translation - new_center ) + rb_trans;
70 } // fold_in_rb_deltas
71 
72 
73 
74 ///////////////////////////////////////////////////////////////////////////////
75 bool
77  const
78 {
79  Real const tolerance( 1e-3 );
80  Matrix delta( rotation * rotation.transposed() - Matrix::identity() );
81  return ( ( delta.col_x().length() +
82  delta.col_y().length() +
83  delta.col_z().length() ) < tolerance );
84 }
85 // // debug orthogonality
86 // Real dev(0.0);
87 // for ( int i=1; i<=3; ++i ) {
88 // for ( int j=1; j<=3; ++j ) {
89 // Real f =
90 // rotation(1,i) * rotation(1,j) +
91 // rotation(2,i) * rotation(2,j) +
92 // rotation(3,i) * rotation(3,j);
93 // if ( i==j ) dev += std::abs(1.0-f);
94 // else dev += std::abs(f);
95 // }
96 // }
97 // return ( dev < 0.01 );
98 // }
99 
100 
101 /////////////////////////////////////////////////////////////////////////////
102 // @details these two extractors must be inverses: ie if we write an RT
103 // out with one and then read it back in using the other the
104 // new RT should be the same
105 // this is critical for pose silent input/output to work correctly.
106 
107 std::ostream &
109  std::ostream & os,
110  const RT & rt
111 )
112 {
113  assert( rt.ortho_check() );
114  os << "RT "; // olange: removed whitespace before RT --> gives problem in silent files.
115  for ( int i = 1; i <= 3; ++i ) {
116  for ( int j = 1; j <= 3; ++j ) {
117  //os << F(9,3,rt.rotation(i,j)); // output by row
118  os << rt.rotation(i,j) << ' '; // chu -- more digits for precision
119  }
120  }
121  for ( int i = 1; i <= 3; ++i ) {
122  //os << F(9,3,rt.translation(i) );
123  os << rt.translation(i) << ' '; // chu -- more digits for precision
124  }
125  os << ' ';
126  return os;
127 }
128 
129 ///////////////////////////////////////////////////////////////////////////////
130 std::istream &
132  std::istream & is,
133  RT & rt
134 )
135 {
136  std::string tag;
137  is >> tag;
138  if ( !is.fail() && tag == "RT" ) {
139  for ( int i = 1; i <= 3; ++i ) {
140  for ( int j = 1; j <= 3; ++j ) {
141  is >> rt.rotation(i,j); // input by row
142  }
143  }
144  for ( int i = 1; i <= 3; ++i ) {
145  is >> rt.translation(i);
146  }
147  if ( !is.fail() ) {
148  if ( !rt.ortho_check() ) {
149  std::cout << "RT failed orthogonality check!" << std::endl;
150  is.setstate( std::ios_base::failbit );
151  }
152  }
153  }
154  return is;
155 }
156 
157 
158 } // namespace kinematics
159 } // namespace core