Chemical Data Processing Library C++ API - Version 1.4.0
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 
50  template <typename VA, typename V = typename VA::ElementType, typename T = typename V::ValueType>
52  {
53 
54  public:
56  typedef VA VectorArrayType;
58  typedef V VectorType;
60  typedef T ValueType;
63 
74  template <typename VE>
75  bool calculate(const VectorArrayType& points, const VectorArrayType& ref_points, const VectorExpression<VE>& weights,
76  bool do_center = true, std::size_t max_svd_iter = 0)
77  {
78 
79  return kabschAlgo.align(MatrixVectorArrayAdapter(points), MatrixVectorArrayAdapter(ref_points),
80  weights, do_center, max_svd_iter);
81  }
82 
91  bool calculate(const VectorArrayType& points, const VectorArrayType& ref_points,
92  bool do_center = true, std::size_t max_svd_iter = 0)
93  {
94 
95  return kabschAlgo.align(MatrixVectorArrayAdapter(points), MatrixVectorArrayAdapter(ref_points),
96  do_center, max_svd_iter);
97  }
98 
103  const MatrixType& getTransform() const
104  {
105  return kabschAlgo.getTransform();
106  }
107 
108  private:
109  class MatrixVectorArrayAdapter : public MatrixExpression<MatrixVectorArrayAdapter>
110  {
111 
112  typedef MatrixVectorArrayAdapter SelfType;
113 
114  public:
116  typedef const ValueType Reference;
117  typedef const ValueType ConstReference;
118  typedef typename VectorArrayType::SizeType SizeType;
119  typedef std::ptrdiff_t DifferenceType;
120  typedef SelfType ClosureType;
121  typedef const SelfType ConstClosureType;
122 
123  explicit MatrixVectorArrayAdapter(const VectorArrayType& va):
124  data(va) {}
125 
126  Reference operator()(SizeType i, SizeType j)
127  {
128  return data.getData()[j].getData()[i];
129  }
130 
131  ConstReference operator()(SizeType i, SizeType j) const
132  {
133  return data[j][i];
134  }
135 
136  SizeType getSize1() const
137  {
138  return VectorType::Size;
139  }
140 
141  SizeType getSize2() const
142  {
143  return data.getSize();
144  }
145 
146  SizeType getMaxSize() const
147  {
148  return data.getMaxSize();
149  }
150 
151  SizeType getMaxSize1() const
152  {
153  return VectorType::Size;
154  }
155 
156  SizeType getMaxSize2() const
157  {
158  return data.getMaxSize();
159  }
160 
161  bool isEmpty() const
162  {
163  return data.isEmpty();
164  }
165 
166  const VectorArrayType& getData() const
167  {
168  return data;
169  }
170 
171  VectorArrayType& getData()
172  {
173  return data;
174  }
175 
176  MatrixVectorArrayAdapter& operator=(const MatrixVectorArrayAdapter& a)
177  {
178  data.operator=(a.data);
179  return *this;
180  }
181 
182  void swap(MatrixVectorArrayAdapter& a)
183  {
184  data.swap(a.data);
185  }
186 
187  friend void swap(MatrixVectorArrayAdapter& a1, MatrixVectorArrayAdapter& a2)
188  {
189  a1.swap(a2);
190  }
191 
192  private:
193  const VectorArrayType& data;
194  };
195 
196  KabschAlgorithm<ValueType> kabschAlgo;
197  };
198  } // namespace Math
199 } // namespace CDPL
200 
201 #endif // CDPL_MATH_VECTORARRAYALIGNMENTCALCULATOR_HPP
Implementation of the Kabsch algorithm.
Definition of various matrix expression types and operations.
Definition of various vector expression types and operations.
Implementation of the Kabsch algorithm [KABA].
Definition: KabschAlgorithm.hpp:62
const MatrixType & getTransform() const
Returns the rigid-body transformation produced by the most recent successful align() call.
Definition: KabschAlgorithm.hpp:206
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:89
CRTP base class for all matrix expression types.
Definition: Expression.hpp:104
Convenience wrapper around Math::KabschAlgorithm that operates directly on Math::VectorArray inputs.
Definition: VectorArrayAlignmentCalculator.hpp:52
const MatrixType & getTransform() const
Returns the rigid-body transformation produced by the most recent successful calculate() call.
Definition: VectorArrayAlignmentCalculator.hpp:103
bool calculate(const VectorArrayType &points, const VectorArrayType &ref_points, const VectorExpression< VE > &weights, bool do_center=true, std::size_t max_svd_iter=0)
Aligns points onto ref_points (with per-point weights) using the Kabsch algorithm.
Definition: VectorArrayAlignmentCalculator.hpp:75
T ValueType
The scalar value type.
Definition: VectorArrayAlignmentCalculator.hpp:60
bool calculate(const VectorArrayType &points, const VectorArrayType &ref_points, bool do_center=true, std::size_t max_svd_iter=0)
Aligns points onto ref_points (with uniform weights) using the Kabsch algorithm.
Definition: VectorArrayAlignmentCalculator.hpp:91
V VectorType
The vector element type of VectorArrayType.
Definition: VectorArrayAlignmentCalculator.hpp:58
VA VectorArrayType
The vector-array type.
Definition: VectorArrayAlignmentCalculator.hpp:56
KabschAlgorithm< ValueType >::MatrixType MatrixType
The matrix type used for the computed transformation.
Definition: VectorArrayAlignmentCalculator.hpp:62
CRTP base class for all vector expression types.
Definition: Expression.hpp:66
constexpr unsigned int V
Specifies Vanadium.
Definition: AtomType.hpp:177
constexpr unsigned int T
Specifies Hydrogen (Tritium).
Definition: AtomType.hpp:67
The namespace of the Chemical Data Processing Library.