2007-12-28 16:20:00 +00:00
|
|
|
#include <Eigen/Core>
|
2010-03-08 20:34:24 +01:00
|
|
|
#include <iostream>
|
2010-04-22 18:27:13 -04:00
|
|
|
using namespace Eigen;
|
2007-12-24 11:14:25 +00:00
|
|
|
using namespace std;
|
|
|
|
|
|
2008-03-10 17:23:11 +00:00
|
|
|
template<typename Derived>
|
2008-01-13 23:38:48 +00:00
|
|
|
Eigen::Block<Derived>
|
2008-03-10 17:23:11 +00:00
|
|
|
topLeftCorner(MatrixBase<Derived>& m, int rows, int cols)
|
2007-12-24 11:14:25 +00:00
|
|
|
{
|
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>
|
2008-01-13 23:38:48 +00:00
|
|
|
const Eigen::Block<Derived>
|
2008-03-10 17:23:11 +00:00
|
|
|
topLeftCorner(const MatrixBase<Derived>& m, int rows, int cols)
|
2007-12-26 09:25:00 +00:00
|
|
|
{
|
2008-03-14 10:38:37 +00:00
|
|
|
return Eigen::Block<Derived>(m.derived(), 0, 0, rows, cols);
|
2007-12-24 11:14:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(int, char**)
|
|
|
|
|
{
|
2008-07-21 00:34:46 +00:00
|
|
|
Matrix4d m = Matrix4d::Identity();
|
2008-01-13 23:38:48 +00: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 11:14:25 +00:00
|
|
|
cout << "Now the matrix m is:" << endl << m << endl;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|