2007-12-28 16:20:00 +00:00
|
|
|
#include <Eigen/Core>
|
2010-03-08 20:34:24 +01:00
|
|
|
#include <iostream>
|
2007-12-24 11:14:25 +00:00
|
|
|
|
2008-03-10 17:23:11 +00:00
|
|
|
template <typename Derived>
|
2021-12-07 19:57:38 +00:00
|
|
|
Eigen::Block<Derived> topLeftCorner(Eigen::MatrixBase<Derived>& m, int rows, int cols) {
|
2008-03-14 10:38:37 +00:00
|
|
|
return Eigen::Block<Derived>(m.derived(), 0, 0, rows, cols);
|
2007-12-26 09:25:00 +00:00
|
|
|
}
|
|
|
|
|
|
2008-03-10 17:23:11 +00:00
|
|
|
template <typename Derived>
|
2021-12-07 19:57:38 +00:00
|
|
|
const Eigen::Block<const Derived> topLeftCorner(const Eigen::MatrixBase<Derived>& m, int rows, int cols) {
|
2011-02-06 12:43:01 -05:00
|
|
|
return Eigen::Block<const Derived>(m.derived(), 0, 0, rows, cols);
|
2007-12-24 11:14:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(int, char**) {
|
2021-12-07 19:57:38 +00:00
|
|
|
Eigen::Matrix4d m = Eigen::Matrix4d::Identity();
|
|
|
|
|
std::cout << topLeftCorner(4 * m, 2, 3) << std::endl; // calls the const version
|
2008-01-13 23:38:48 +00:00
|
|
|
topLeftCorner(m, 2, 3) *= 5; // calls the non-const version
|
2021-12-07 19:57:38 +00:00
|
|
|
std::cout << "Now the matrix m is:" << std::endl << m << std::endl;
|
2007-12-24 11:14:25 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|