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