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:
58  typedef VA VectorArrayType;
59 
63  typedef V VectorType;
64 
68  typedef T ValueType;
69 
74 
85  template <typename VE>
86  bool calculate(const VectorArrayType& points, const VectorArrayType& ref_points, const VectorExpression<VE>& weights,
87  bool do_center = true, std::size_t max_svd_iter = 0)
88  {
89 
90  return kabschAlgo.align(MatrixVectorArrayAdapter(points), MatrixVectorArrayAdapter(ref_points),
91  weights, do_center, max_svd_iter);
92  }
93 
102  bool calculate(const VectorArrayType& points, const VectorArrayType& ref_points,
103  bool do_center = true, std::size_t max_svd_iter = 0)
104  {
105 
106  return kabschAlgo.align(MatrixVectorArrayAdapter(points), MatrixVectorArrayAdapter(ref_points),
107  do_center, max_svd_iter);
108  }
109 
114  const MatrixType& getTransform() const
115  {
116  return kabschAlgo.getTransform();
117  }
118 
119  private:
120  class MatrixVectorArrayAdapter : public MatrixExpression<MatrixVectorArrayAdapter>
121  {
122 
123  typedef MatrixVectorArrayAdapter SelfType;
124 
125  public:
127  typedef const ValueType Reference;
128  typedef const ValueType ConstReference;
129  typedef typename VectorArrayType::SizeType SizeType;
130  typedef std::ptrdiff_t DifferenceType;
131  typedef SelfType ClosureType;
132  typedef const SelfType ConstClosureType;
133 
134  explicit MatrixVectorArrayAdapter(const VectorArrayType& va):
135  data(va) {}
136 
137  Reference operator()(SizeType i, SizeType j)
138  {
139  return data.getData()[j].getData()[i];
140  }
141 
142  ConstReference operator()(SizeType i, SizeType j) const
143  {
144  return data[j][i];
145  }
146 
147  SizeType getSize1() const
148  {
149  return VectorType::Size;
150  }
151 
152  SizeType getSize2() const
153  {
154  return data.getSize();
155  }
156 
157  SizeType getMaxSize() const
158  {
159  return data.getMaxSize();
160  }
161 
162  SizeType getMaxSize1() const
163  {
164  return VectorType::Size;
165  }
166 
167  SizeType getMaxSize2() const
168  {
169  return data.getMaxSize();
170  }
171 
172  bool isEmpty() const
173  {
174  return data.isEmpty();
175  }
176 
177  const VectorArrayType& getData() const
178  {
179  return data;
180  }
181 
182  VectorArrayType& getData()
183  {
184  return data;
185  }
186 
187  MatrixVectorArrayAdapter& operator=(const MatrixVectorArrayAdapter& a)
188  {
189  data.operator=(a.data);
190  return *this;
191  }
192 
193  void swap(MatrixVectorArrayAdapter& a)
194  {
195  data.swap(a.data);
196  }
197 
198  friend void swap(MatrixVectorArrayAdapter& a1, MatrixVectorArrayAdapter& a2)
199  {
200  a1.swap(a2);
201  }
202 
203  private:
204  const VectorArrayType& data;
205  };
206 
207  KabschAlgorithm<ValueType> kabschAlgo;
208  };
209  } // namespace Math
210 } // namespace CDPL
211 
212 #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:214
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:97
CRTP base class of all matrix expression types.
Definition: Expression.hpp:108
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:114
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:86
T ValueType
The scalar value type.
Definition: VectorArrayAlignmentCalculator.hpp:68
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:102
V VectorType
The vector element type of VectorArrayType.
Definition: VectorArrayAlignmentCalculator.hpp:63
VA VectorArrayType
The vector-array type.
Definition: VectorArrayAlignmentCalculator.hpp:58
KabschAlgorithm< ValueType >::MatrixType MatrixType
The matrix type used for the computed transformation.
Definition: VectorArrayAlignmentCalculator.hpp:73
CRTP base class of all vector expression types.
Definition: Expression.hpp:68
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.