Reply to topic

How to access Row and Col Size

Gabyx
Registered Member
Posts
10
Karma
0

How to access Row and Col Size

Wed Nov 07, 2012 8:53 am
Hello,

I would like to wrap the Eigen::Block into my own struct with the typedef (so to have some abstraction, that I dont want to use directly Eigen stuff in my code). But I dont know how to write this with templates, because I dont know how to access the template parameter (-1 or any integer) for Row and COL? So there must be a way of getting to the underlying type of this integer. The class DynamicBlock works, but how do I write StaticBlock?

Code: Select all
template<typename MatrixType>
struct StaticBlock{
   typedef Block< MatrixType , MatrixType::Row ,  MatrixType::Col > type;
   typedef Block<MatrixType , MatrixType::Row ,  MatrixType::Col > const_type;
};

struct DynamicBlock{
   typedef Block< MatrixType , Eigen::Dynamic ,  Eigen::Dynamic > type;
   typedef Block<MatrixType , Eigen::Dynamic ,  Eigen::Dynamic > const_type;
};


I would like to write
Code: Select all
StaticBlock<Eigen::Matrix<double,4,1>::type
which then is a correct static Block :-)?
How do I do this?

THanks alot!!
Dee33
Registered Member
Posts
54
Karma
0
OS

Re: How to access Row and Col Size

Wed Nov 07, 2012 9:02 am
Are you looking for MatrixType::RowsAtCompileTime and MatrixType::ColsAtCompileTime ?
Gabyx
Registered Member
Posts
10
Karma
0

Re: How to access Row and Col Size

Wed Nov 07, 2012 9:05 am
Yes, I think this is it ?

Is this the correct template parameter? Or how do we call these?
Dee33
Registered Member
Posts
54
Karma
0
OS

Re: How to access Row and Col Size

Wed Nov 07, 2012 9:52 am
Yes you can use it as template parameter
Gabyx
Registered Member
Posts
10
Karma
0

Re: How to access Row and Col Size

Wed Nov 07, 2012 1:33 pm
I have found the solution to wrap the eigen type:

like


Code: Select all
struct MyMatrix {
   typedef Eigen::Matrix<double,7,1> VectorQObj;
   typedef Eigen::Matrix<double,6,1> VectorUObj;
   typedef Eigen::Matrix<double,4,1> Quaternion;

};


template<typename MatrixType,int M=Eigen::Dynamic, int N=Eigen::Dynamic>
struct MatrixBlock{
   typedef Block< MatrixType ,M, N > type;
   typedef Block< const MatrixType , M, N> const_type;
};


lets me write stuff like this:

Code: Select all
MatrixBlock<MyMatrix::VectorQObj,4,1>::const_type  getQuaternion() const {
      cout << "Const called" <<endl;
      return MatrixBlock<MyMatrix::VectorQObj,4,1>::const_type(q,0,0);
   }

    MatrixBlock<MyMatrix::VectorQObj,4,1>::type  getQuaternion(){
      cout << "Normal called" <<endl;
      return MatrixBlock<MyMatrix::VectorQObj,4,1>::type(q,3,0);
   }



Can somebody tell me if this make sense to use like this or if there are some disadantages?

Thanks!!
User avatar ggael
Moderator
Posts
2194
Karma
15
OS
That sounds overkill, why not directly using VectorBlock<MyMatrix::VectorQObj,4> and VectorBlock<const MyMatrix::VectorQObj,4> ??

 
Reply to topic

Bookmarks



Who is online

Registered users: alake, Alexa [Bot], Baidu [Spider], Bing [Bot], blue_bullet, chicken2jail, claydoh, colomar, Exabot [Bot], garthecho, ghevan, Google [Bot], google01103, Hans, inhiway, kainz.a, koriun, La Ninje, lazyit, Majestic-12 [Bot], mmistretta, nezumi, pedrorodriguez, private_lock, robinh, scummos, Tuukka, urgo, Uri_Herrera, wolfi323, Yahoo [Bot]