Re: [eigen] Casting matrices

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


I should read the documentation more carefully....
Maybe this feature should be added in the tutorial
(http://eigen.tuxfamily.org/api/TutorialCore.html) ?


On Sun, Nov 9, 2008 at 4:08 PM, Benoît Jacob <jacob@xxxxxxxxxxxxxxx> wrote:
> 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>();
>
> Cheers,
> Benoit
>
> ---
>
>


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/