2008-01-13 23:38:48 +00:00
|
|
|
#include <Eigen/Core>
|
2010-03-08 20:34:24 +01:00
|
|
|
#include <iostream>
|
2008-01-13 23:38:48 +00:00
|
|
|
|
2008-03-10 17:23:11 +00:00
|
|
|
template <typename Derived>
|
2021-12-07 19:57:38 +00:00
|
|
|
Eigen::Block<Derived, 2, 2> topLeft2x2Corner(Eigen::MatrixBase<Derived>& m) {
|
2008-03-14 10:38:37 +00:00
|
|
|
return Eigen::Block<Derived, 2, 2>(m.derived(), 0, 0);
|
2008-01-13 23:38:48 +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, 2, 2> topLeft2x2Corner(const Eigen::MatrixBase<Derived>& m) {
|
2011-02-06 12:43:01 -05:00
|
|
|
return Eigen::Block<const Derived, 2, 2>(m.derived(), 0, 0);
|
2008-01-13 23:38:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(int, char**) {
|
2021-12-07 19:57:38 +00:00
|
|
|
Eigen::Matrix3d m = Eigen::Matrix3d::Identity();
|
|
|
|
|
std::cout << topLeft2x2Corner(4 * m) << std::endl; // calls the const version
|
2008-01-13 23:38:48 +00:00
|
|
|
topLeft2x2Corner(m) *= 2; // 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;
|
2008-01-13 23:38:48 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|