Chemical Data Processing Library C++ API - Version 1.1.1
VectorArrayAlignmentCalculator.hpp
Go to the documentation of this file.
1 /*
2  * VectorArrayAlignmentCalculator.hpp
3  *
4  * Copyright (C) 2003 Thomas Seidel <thomas.seidel@univie.ac.at>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library; see the file COPYING. If not, write to
18  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
27 #ifndef CDPL_MATH_VECTORARRAYALIGNMENTCALCULATOR_HPP
28 #define CDPL_MATH_VECTORARRAYALIGNMENTCALCULATOR_HPP
29 
30 #include <cstddef>
31 
35 
36 
37 namespace CDPL
38 {
39 
40  namespace Math
41  {
42 
43  template <typename VA, typename V = typename VA::ElementType, typename T = typename V::ValueType>
45  {
46 
47  public:
48  typedef VA VectorArrayType;
49  typedef V VectorType;
50  typedef T ValueType;
52 
53  template <typename VE>
54  bool calculate(const VectorArrayType& points, const VectorArrayType& ref_points, const VectorExpression<VE>& weights,
55  bool do_center = true, std::size_t max_svd_iter = 0)
56  {
57 
58  return kabschAlgo.align(MatrixVectorArrayAdapter(points), MatrixVectorArrayAdapter(ref_points),
59  weights, do_center, max_svd_iter);
60  }
61 
62  bool calculate(const VectorArrayType& points, const VectorArrayType& ref_points,
63  bool do_center = true, std::size_t max_svd_iter = 0)
64  {
65 
66  return kabschAlgo.align(MatrixVectorArrayAdapter(points), MatrixVectorArrayAdapter(ref_points),
67  do_center, max_svd_iter);
68  }
69 
70  const MatrixType& getTransform() const
71  {
72  return kabschAlgo.getTransform();
73  }
74 
75  private:
76  class MatrixVectorArrayAdapter : public MatrixExpression<MatrixVectorArrayAdapter>
77  {
78 
79  typedef MatrixVectorArrayAdapter SelfType;
80 
81  public:
83  typedef const ValueType Reference;
84  typedef const ValueType ConstReference;
85  typedef typename VectorArrayType::SizeType SizeType;
86  typedef std::ptrdiff_t DifferenceType;
87  typedef SelfType ClosureType;
88  typedef const SelfType ConstClosureType;
89 
90  explicit MatrixVectorArrayAdapter(const VectorArrayType& va):
91  data(va) {}
92 
93  Reference operator()(SizeType i, SizeType j)
94  {
95  return data.getData()[j].getData()[i];
96  }
97 
98  ConstReference operator()(SizeType i, SizeType j) const
99  {
100  return data[j][i];
101  }
102 
103  SizeType getSize1() const
104  {
105  return VectorType::Size;
106  }
107 
108  SizeType getSize2() const
109  {
110  return data.getSize();
111  }
112 
113  SizeType getMaxSize() const
114  {
115  return data.getMaxSize();
116  }
117 
118  SizeType getMaxSize1() const
119  {
120  return VectorType::Size;
121  }
122 
123  SizeType getMaxSize2() const
124  {
125  return data.getMaxSize();
126  }
127 
128  bool isEmpty() const
129  {
130  return data.isEmpty();
131  }
132 
133  const VectorArrayType& getData() const
134  {
135  return data;
136  }
137 
138  VectorArrayType& getData()
139  {
140  return data;
141  }
142 
143  MatrixVectorArrayAdapter& operator=(const MatrixVectorArrayAdapter& a)
144  {
145  data.operator=(a.data);
146  return *this;
147  }
148 
149  void swap(MatrixVectorArrayAdapter& a)
150  {
151  data.swap(a.data);
152  }
153 
154  friend void swap(MatrixVectorArrayAdapter& a1, MatrixVectorArrayAdapter& a2)
155  {
156  a1.swap(a2);
157  }
158 
159  private:
160  const VectorArrayType& data;
161  };
162 
163  KabschAlgorithm<ValueType> kabschAlgo;
164  };
165  } // namespace Math
166 } // namespace CDPL
167 
168 #endif // CDPL_MATH_VECTORARRAYALIGNMENTCALCULATOR_HPP
CDPL::Math::VectorArrayAlignmentCalculator::MatrixType
KabschAlgorithm< ValueType >::MatrixType MatrixType
Definition: VectorArrayAlignmentCalculator.hpp:51
CDPL::Math::VectorExpression
Definition: Expression.hpp:54
CDPL::Math::VectorArrayAlignmentCalculator::calculate
bool calculate(const VectorArrayType &points, const VectorArrayType &ref_points, const VectorExpression< VE > &weights, bool do_center=true, std::size_t max_svd_iter=0)
Definition: VectorArrayAlignmentCalculator.hpp:54
VectorExpression.hpp
Definition of various vector expression types and operations.
CDPL::Math::VectorArrayAlignmentCalculator::VectorType
V VectorType
Definition: VectorArrayAlignmentCalculator.hpp:49
CDPL::Math::VectorArrayAlignmentCalculator
Definition: VectorArrayAlignmentCalculator.hpp:45
CDPL::Math::MatrixExpression
Definition: Expression.hpp:76
CDPL::Math::VectorArrayAlignmentCalculator::getTransform
const MatrixType & getTransform() const
Definition: VectorArrayAlignmentCalculator.hpp:70
VectorArray< Vector3D >
CDPL::Math::VectorArrayAlignmentCalculator::ValueType
T ValueType
Definition: VectorArrayAlignmentCalculator.hpp:50
V
MatrixExpression.hpp
Definition of various matrix expression types and operations.
CDPL::Chem::AtomType::T
const unsigned int T
Specifies Hydrogen (Tritium).
Definition: AtomType.hpp:67
CDPL::Math::KabschAlgorithm::align
bool align(const MatrixExpression< M1 > &points, const MatrixExpression< M2 > &ref_points, const VectorExpression< V > &weights, bool do_center=true, std::size_t max_svd_iter=0)
Computes the rigid body transformation that aligns a set of -dimensional points points with a corres...
Definition: KabschAlgorithm.hpp:86
CDPL::Math::KabschAlgorithm
Implementation of the Kabsch algorithm [KABA].
Definition: KabschAlgorithm.hpp:62
KabschAlgorithm.hpp
Implementation of the Kabsch algorithm.
CDPL
The namespace of the Chemical Data Processing Library.
CDPL::Math::VectorArrayAlignmentCalculator::calculate
bool calculate(const VectorArrayType &points, const VectorArrayType &ref_points, bool do_center=true, std::size_t max_svd_iter=0)
Definition: VectorArrayAlignmentCalculator.hpp:62
CDPL::Math::VectorArrayAlignmentCalculator::VectorArrayType
VA VectorArrayType
Definition: VectorArrayAlignmentCalculator.hpp:48
CDPL::Math::KabschAlgorithm::getTransform
const MatrixType & getTransform() const
Definition: KabschAlgorithm.hpp:199