Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
SimilarityTransform.cpp
1 /** This file is part of the BIAS library (Basic ImageAlgorithmS).
2 
3 Copyright (C) 2003-2009 (see file CONTACT for details)
4  Multimediale Systeme der Informationsverarbeitung
5  Institut fuer Informatik
6  Christian-Albrechts-Universitaet Kiel
7 
8 
9 BIAS is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version.
13 
14 BIAS is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU Lesser General Public License for more details.
18 
19 You should have received a copy of the GNU Lesser General Public License
20 along with BIAS; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23 
24 
25 #include <Geometry/SimilarityTransform.hh>
26 #include <MathAlgo/SVD.hh>
27 #include <Base/Geometry/RMatrixBase.hh>
28 #include <fstream>
29 #include <iostream>
30 #include <Base/Math/Matrix3x4.hh>
31 
32 using namespace BIAS;
33 using namespace std;
34 
35 
37 Load(const std::string& inputFile)
38 {
39  ifstream ifs(inputFile.c_str());
40  if(!ifs)
41  return false;
42  ifs>>*this;
43  if(!ifs) {
44  ifs.close();
45  return false;
46  }
47  ifs.close();
48  return true;
49 }
50 
52 Save(const std::string& outputFile)
53 {
54  ofstream ofs(outputFile.c_str());
55  if(!ofs)
56  return false;
57  ofs<<*this;
58  if(!ofs) {
59  ofs.close();
60  return false;
61  }
62  ofs.close();
63  return true;
64 }
65 
66 
68 {
69  cout<<"Translation:"<<C_<<endl;
70 
71  RMatrixBase R;
72  R.SetFromQuaternion(Q_);
73  cout<<"Rotation Matrix: "<<R<<endl;
74 
75  Vector3<double> axis;
76  double angle;
77 
78  R.GetRotationAxisAngle(axis, angle);
79  cout<<" axis = "<<axis<<endl;
80  cout<<"angle = "<<angle<<endl<<endl;
81  cout<<"Matrix representation:"<<GetTransformMatrix()<<endl;
82 }
83 
85 {
86  Matrix4x4<double> result;
87  RMatrixBase R;
88  result[3][3] = 1.0;
89  R.SetFromQuaternion(Q_);
90  R *= scale_;
91  for (unsigned int r = 0; r < 3; r++)
92  for (unsigned int c = 0; c < 3; c++)
93  result[r][c]= R[r][c];
94  result[0][3] = C_[0];
95  result[1][3] = C_[1];
96  result[2][3] = C_[2];
97  return result;
98 }
bool Save(const std::string &outputFile)
Save similarity transform to text file outputFile.
Matrix4x4< double > GetTransformMatrix() const
Returns 4x4 transformation matrix corresponding to this.
int SetFromQuaternion(const Quaternion< ROTATION_MATRIX_TYPE > &q)
Set rotation matrix from a quaternion.
void Dump()
Print transformation together with more intuitive rotation representations for debugging purposed...
Implements a 3D rotation matrix.
Definition: RMatrixBase.hh:44
int GetRotationAxisAngle(Vector3< ROTATION_MATRIX_TYPE > &axis, ROTATION_MATRIX_TYPE &angle) const
Calculates angle and rotation axis representation for this rotation matrix.
bool Load(const std::string &inputFile)
Load similarity transform from text file inputFile.