Image.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
5 //
6 // Eigen 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 3 of the License, or (at your option) any later version.
10 //
11 // Alternatively, you can redistribute it and/or
12 // modify it under the terms of the GNU General Public License as
13 // published by the Free Software Foundation; either version 2 of
14 // the License, or (at your option) any later version.
15 //
16 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
17 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public
22 // License and a copy of the GNU General Public License along with
23 // Eigen. If not, see <http://www.gnu.org/licenses/>.
24 
25 #ifndef EIGEN_MISC_IMAGE_H
26 #define EIGEN_MISC_IMAGE_H
27 
28 namespace Eigen {
29 
30 namespace internal {
31 
35 template<typename DecompositionType>
36 struct traits<image_retval_base<DecompositionType> >
37 {
38  typedef typename DecompositionType::MatrixType MatrixType;
39  typedef Matrix<
40  typename MatrixType::Scalar,
41  MatrixType::RowsAtCompileTime, // the image is a subspace of the destination space, whose
42  // dimension is the number of rows of the original matrix
43  Dynamic, // we don't know at compile time the dimension of the image (the rank)
44  MatrixType::Options,
45  MatrixType::MaxRowsAtCompileTime, // the image matrix will consist of columns from the original matrix,
46  MatrixType::MaxColsAtCompileTime // so it has the same number of rows and at most as many columns.
47  > ReturnType;
48 };
49 
50 template<typename _DecompositionType> struct image_retval_base
51  : public ReturnByValue<image_retval_base<_DecompositionType> >
52 {
53  typedef _DecompositionType DecompositionType;
54  typedef typename DecompositionType::MatrixType MatrixType;
55  typedef ReturnByValue<image_retval_base> Base;
56  typedef typename Base::Index Index;
57 
58  image_retval_base(const DecompositionType& dec, const MatrixType& originalMatrix)
59  : m_dec(dec), m_rank(dec.rank()),
60  m_cols(m_rank == 0 ? 1 : m_rank),
61  m_originalMatrix(originalMatrix)
62  {}
63 
64  inline Index rows() const { return m_dec.rows(); }
65  inline Index cols() const { return m_cols; }
66  inline Index rank() const { return m_rank; }
67  inline const DecompositionType& dec() const { return m_dec; }
68  inline const MatrixType& originalMatrix() const { return m_originalMatrix; }
69 
70  template<typename Dest> inline void evalTo(Dest& dst) const
71  {
72  static_cast<const image_retval<DecompositionType>*>(this)->evalTo(dst);
73  }
74 
75  protected:
76  const DecompositionType& m_dec;
77  Index m_rank, m_cols;
78  const MatrixType& m_originalMatrix;
79 };
80 
81 } // end namespace internal
82 
83 #define EIGEN_MAKE_IMAGE_HELPERS(DecompositionType) \
84  typedef typename DecompositionType::MatrixType MatrixType; \
85  typedef typename MatrixType::Scalar Scalar; \
86  typedef typename MatrixType::RealScalar RealScalar; \
87  typedef typename MatrixType::Index Index; \
88  typedef Eigen::internal::image_retval_base<DecompositionType> Base; \
89  using Base::dec; \
90  using Base::originalMatrix; \
91  using Base::rank; \
92  using Base::rows; \
93  using Base::cols; \
94  image_retval(const DecompositionType& dec, const MatrixType& originalMatrix) \
95  : Base(dec, originalMatrix) {}
96 
97 } // end namespace Eigen
98 
99 #endif // EIGEN_MISC_IMAGE_H