Benoit Jacob | 8622078 | 2007-12-28 16:20:00 +0000 | [diff] [blame] | 1 | #include <Eigen/Core> |
Benoit Jacob | 3cd2a12 | 2007-12-24 11:14:25 +0000 | [diff] [blame] | 2 | USING_PART_OF_NAMESPACE_EIGEN |
| 3 | using namespace std; |
| 4 | |
| 5 | template<typename Scalar, typename Derived> |
Benoit Jacob | 183bf54 | 2008-01-13 23:38:48 +0000 | [diff] [blame] | 6 | Eigen::Block<Derived> |
| 7 | topLeftCorner(MatrixBase<Scalar, Derived>& m, int rows, int cols) |
Benoit Jacob | 3cd2a12 | 2007-12-24 11:14:25 +0000 | [diff] [blame] | 8 | { |
Benoit Jacob | 861c6f4 | 2008-03-04 17:08:23 +0000 | [diff] [blame] | 9 | return Eigen::Block<Derived>(m.asArg(), 0, 0, rows, cols); |
Benoit Jacob | 6b9370e | 2007-12-26 09:25:00 +0000 | [diff] [blame] | 10 | } |
| 11 | |
| 12 | template<typename Scalar, typename Derived> |
Benoit Jacob | 183bf54 | 2008-01-13 23:38:48 +0000 | [diff] [blame] | 13 | const Eigen::Block<Derived> |
| 14 | topLeftCorner(const MatrixBase<Scalar, Derived>& m, int rows, int cols) |
Benoit Jacob | 6b9370e | 2007-12-26 09:25:00 +0000 | [diff] [blame] | 15 | { |
Benoit Jacob | 861c6f4 | 2008-03-04 17:08:23 +0000 | [diff] [blame] | 16 | return Eigen::Block<Derived>(m.asArg(), 0, 0, rows, cols); |
Benoit Jacob | 3cd2a12 | 2007-12-24 11:14:25 +0000 | [diff] [blame] | 17 | } |
| 18 | |
| 19 | int main(int, char**) |
| 20 | { |
Benoit Jacob | 183bf54 | 2008-01-13 23:38:48 +0000 | [diff] [blame] | 21 | Matrix4d m = Matrix4d::identity(); |
| 22 | cout << topLeftCorner(4*m, 2, 3) << endl; // calls the const version |
| 23 | topLeftCorner(m, 2, 3) *= 5; // calls the non-const version |
Benoit Jacob | 3cd2a12 | 2007-12-24 11:14:25 +0000 | [diff] [blame] | 24 | cout << "Now the matrix m is:" << endl << m << endl; |
| 25 | return 0; |
| 26 | } |