1 | // This file is part of Eigen, a lightweight C++ template library |
---|
2 | // for linear algebra. |
---|
3 | // |
---|
4 | // Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr> |
---|
5 | // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> |
---|
6 | // |
---|
7 | // This Source Code Form is subject to the terms of the Mozilla |
---|
8 | // Public License v. 2.0. If a copy of the MPL was not distributed |
---|
9 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. |
---|
10 | |
---|
11 | #ifndef EIGEN_BLOCK2_H |
---|
12 | #define EIGEN_BLOCK2_H |
---|
13 | |
---|
14 | namespace Eigen { |
---|
15 | |
---|
16 | /** \returns a dynamic-size expression of a corner of *this. |
---|
17 | * |
---|
18 | * \param type the type of corner. Can be \a Eigen::TopLeft, \a Eigen::TopRight, |
---|
19 | * \a Eigen::BottomLeft, \a Eigen::BottomRight. |
---|
20 | * \param cRows the number of rows in the corner |
---|
21 | * \param cCols the number of columns in the corner |
---|
22 | * |
---|
23 | * Example: \include MatrixBase_corner_enum_int_int.cpp |
---|
24 | * Output: \verbinclude MatrixBase_corner_enum_int_int.out |
---|
25 | * |
---|
26 | * \note Even though the returned expression has dynamic size, in the case |
---|
27 | * when it is applied to a fixed-size matrix, it inherits a fixed maximal size, |
---|
28 | * which means that evaluating it does not cause a dynamic memory allocation. |
---|
29 | * |
---|
30 | * \sa class Block, block(Index,Index,Index,Index) |
---|
31 | */ |
---|
32 | template<typename Derived> |
---|
33 | inline Block<Derived> DenseBase<Derived> |
---|
34 | ::corner(CornerType type, Index cRows, Index cCols) |
---|
35 | { |
---|
36 | switch(type) |
---|
37 | { |
---|
38 | default: |
---|
39 | eigen_assert(false && "Bad corner type."); |
---|
40 | case TopLeft: |
---|
41 | return Block<Derived>(derived(), 0, 0, cRows, cCols); |
---|
42 | case TopRight: |
---|
43 | return Block<Derived>(derived(), 0, cols() - cCols, cRows, cCols); |
---|
44 | case BottomLeft: |
---|
45 | return Block<Derived>(derived(), rows() - cRows, 0, cRows, cCols); |
---|
46 | case BottomRight: |
---|
47 | return Block<Derived>(derived(), rows() - cRows, cols() - cCols, cRows, cCols); |
---|
48 | } |
---|
49 | } |
---|
50 | |
---|
51 | /** This is the const version of corner(CornerType, Index, Index).*/ |
---|
52 | template<typename Derived> |
---|
53 | inline const Block<Derived> |
---|
54 | DenseBase<Derived>::corner(CornerType type, Index cRows, Index cCols) const |
---|
55 | { |
---|
56 | switch(type) |
---|
57 | { |
---|
58 | default: |
---|
59 | eigen_assert(false && "Bad corner type."); |
---|
60 | case TopLeft: |
---|
61 | return Block<Derived>(derived(), 0, 0, cRows, cCols); |
---|
62 | case TopRight: |
---|
63 | return Block<Derived>(derived(), 0, cols() - cCols, cRows, cCols); |
---|
64 | case BottomLeft: |
---|
65 | return Block<Derived>(derived(), rows() - cRows, 0, cRows, cCols); |
---|
66 | case BottomRight: |
---|
67 | return Block<Derived>(derived(), rows() - cRows, cols() - cCols, cRows, cCols); |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | /** \returns a fixed-size expression of a corner of *this. |
---|
72 | * |
---|
73 | * \param type the type of corner. Can be \a Eigen::TopLeft, \a Eigen::TopRight, |
---|
74 | * \a Eigen::BottomLeft, \a Eigen::BottomRight. |
---|
75 | * |
---|
76 | * The template parameters CRows and CCols arethe number of rows and columns in the corner. |
---|
77 | * |
---|
78 | * Example: \include MatrixBase_template_int_int_corner_enum.cpp |
---|
79 | * Output: \verbinclude MatrixBase_template_int_int_corner_enum.out |
---|
80 | * |
---|
81 | * \sa class Block, block(Index,Index,Index,Index) |
---|
82 | */ |
---|
83 | template<typename Derived> |
---|
84 | template<int CRows, int CCols> |
---|
85 | inline Block<Derived, CRows, CCols> |
---|
86 | DenseBase<Derived>::corner(CornerType type) |
---|
87 | { |
---|
88 | switch(type) |
---|
89 | { |
---|
90 | default: |
---|
91 | eigen_assert(false && "Bad corner type."); |
---|
92 | case TopLeft: |
---|
93 | return Block<Derived, CRows, CCols>(derived(), 0, 0); |
---|
94 | case TopRight: |
---|
95 | return Block<Derived, CRows, CCols>(derived(), 0, cols() - CCols); |
---|
96 | case BottomLeft: |
---|
97 | return Block<Derived, CRows, CCols>(derived(), rows() - CRows, 0); |
---|
98 | case BottomRight: |
---|
99 | return Block<Derived, CRows, CCols>(derived(), rows() - CRows, cols() - CCols); |
---|
100 | } |
---|
101 | } |
---|
102 | |
---|
103 | /** This is the const version of corner<int, int>(CornerType).*/ |
---|
104 | template<typename Derived> |
---|
105 | template<int CRows, int CCols> |
---|
106 | inline const Block<Derived, CRows, CCols> |
---|
107 | DenseBase<Derived>::corner(CornerType type) const |
---|
108 | { |
---|
109 | switch(type) |
---|
110 | { |
---|
111 | default: |
---|
112 | eigen_assert(false && "Bad corner type."); |
---|
113 | case TopLeft: |
---|
114 | return Block<Derived, CRows, CCols>(derived(), 0, 0); |
---|
115 | case TopRight: |
---|
116 | return Block<Derived, CRows, CCols>(derived(), 0, cols() - CCols); |
---|
117 | case BottomLeft: |
---|
118 | return Block<Derived, CRows, CCols>(derived(), rows() - CRows, 0); |
---|
119 | case BottomRight: |
---|
120 | return Block<Derived, CRows, CCols>(derived(), rows() - CRows, cols() - CCols); |
---|
121 | } |
---|
122 | } |
---|
123 | |
---|
124 | } // end namespace Eigen |
---|
125 | |
---|
126 | #endif // EIGEN_BLOCK2_H |
---|