Re: [eigen] Casting matrices

[ Thread Index | Date Index | More Archives ]

On Monday 10 November 2008 00:45:12 Timothy Hunter wrote:
> Hello list,
> I want to convert a Eigen::MatrixXi to  a double *  (already allocated
> and of the right size).
> A way to do it is to iterate:
> for(int i=0;i<mat.rows();++i)
>   for(int j=0;j<mat.cols();++j)
>      double_ptr[i*mat.cols()+j] = static_cast<double>(mat(i,j));
> However I would like to use MatrixXd::Map in this occasion.

Then all you need to do is:

MatrixXf::Map(double_ptr, mat.rows(), mat.cols())
  = mat.cast<double>();

Note that the Matrix::Map static method has been added in SVN very recently, 
beta1 is not enough. (The old way of constructing a Map<MatrixXf> explicitly 
is less practical here, cf. the thread on this list with Cristovao).

> More generally, it is not currently possible to do casting operations
> like Vector3i = Vector3d and I want to add it on the wishlist if you
> know of an elegant way to do it.

It is already possible, you can do:

Vector3d vd;
Vector3i vi = vd.cast<int>();



Mail converted by MHonArc 2.6.19+