Eigen.h
Go to the documentation of this file.
1 /*
2  * Medical Image Registration ToolKit (MIRTK)
3  *
4  * Copyright 2008-2017 Imperial College London
5  * Copyright 2008-2015 Daniel Rueckert, Julia Schnabel
6  * Copyright 2013-2017 Andreas Schuh
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 /**
22  * \file mirtk/Eigen.h
23  * \brief Interface to Eigen3 library.
24  *
25  * \attention Include this header in internal files such as .cc translation units only!
26  */
27 
28 #ifndef MIRTK_Eigen_H
29 #define MIRTK_Eigen_H
30 
31 #include "mirtk/Matrix.h"
32 #include "mirtk/Vector.h"
33 
34 #if defined __clang__
35  #pragma clang diagnostic push
36  // Disable "'register' storage class specifier is deprecated" warning
37  #pragma clang diagnostic ignored "-Wdeprecated-register"
38 #endif
39 #include "Eigen/Core"
40 #if defined __clang__
41  // Enable warnings again
42  #pragma clang diagnostic pop
43 #endif
44 
45 
46 namespace mirtk {
47 
48 
49 const double EIGEN_TOL = 1.0e-5;
50 
51 
52 // -----------------------------------------------------------------------------
53 inline Eigen::VectorXd VectorToEigen(const Vector &a)
54 {
55  Eigen::VectorXd b(a.Rows());
56  for (int i = 0; i < a.Rows(); ++i) b(i) = a(i);
57  return b;
58 }
59 
60 // -----------------------------------------------------------------------------
61 inline Vector EigenToVector(const Eigen::VectorXd &a)
62 {
63  Vector b(static_cast<int>(a.size()));
64  for (int i = 0; i < b.Rows(); ++i) b(i) = a(i);
65  return b;
66 }
67 
68 // -----------------------------------------------------------------------------
69 inline Eigen::MatrixXd MatrixToEigen(const Matrix &a)
70 {
71  Eigen::MatrixXd b(a.Rows(), a.Cols());
72  for (int i = 0; i < a.Rows(); ++i)
73  for (int j = 0; j < a.Cols(); ++j) {
74  b(i, j) = a(i, j);
75  }
76  return b;
77 }
78 
79 // -----------------------------------------------------------------------------
80 inline Matrix EigenToMatrix(const Eigen::MatrixXd &a)
81 {
82  Matrix b(static_cast<int>(a.rows()), static_cast<int>(a.cols()));
83  for (int i = 0; i < b.Rows(); ++i)
84  for (int j = 0; j < b.Cols(); ++j) {
85  b(i, j) = a(i, j);
86  }
87  return b;
88 }
89 
90 
91 } // namespace mirtk
92 
93 #endif // MIRTK_Eigen_H
Definition: IOConfig.h:41