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