Re: [eigen] Mapping array of scalars into quaternions |

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

*To*: eigen@xxxxxxxxxxxxxxxxxxx*Subject*: Re: [eigen] Mapping array of scalars into quaternions*From*: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>*Date*: Thu, 22 Oct 2009 12:14:02 +0200*Dkim-signature*: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type; bh=Yu0hUWx1x2RMjMXswyQakawbHvluHb2Silqg2jnY93k=; b=SgtiqodLF5o3udT53aeFhejWnVrX90u1UXN7oE730QoDl0u1/eQdutuXki/N5AE7Sd f9CZ44B0i8Y5vkpbhrv4UScWfM/et9/G7/2TcRA2mGklxbD/1VlHu7zVpqwCOci1Bwiz x5UJDMGB2Zz1Z2+PeDKdTCNym7BKp/NCezJ3I=*Domainkey-signature*: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=yBc0XQ0uvqsAsbJ3usNJxP7kiWqwbjCGFzjdOoCOxKqjMZQ1TuGtef9FcZMAj8qr5W h9dkWaDHx9m06czheXkMXbu8xF33uKMecQz6E/BgfRw5y4Pk/Cg9F65JhnXuhwBucD2k 3bgIHMHpUTlVHuA2wLYt1jZCUVinJ6PofM4No=

On Wed, Oct 21, 2009 at 4:41 PM, Benoit Jacob <jacob.benoit.1@xxxxxxxxx> wrote:

well, I guess we still want the user to be able to just write:

typedef Quaternion<MyScalar> MyQuat;

and not:

typedef Quaternion<Matrix<MyScalar,4,1> > MyQuat;

right ?

then the first template argument of Quaternion must be the scalar type. But if we prefer we can also introduce a QuaternionBase and a QuaternionWrapper classes like we did for DiagonalMatrix. Of course this is more work, but perhaps that's a good idea to harmonize that over Eigen.

gael.

Hi,

this is really good stuff, i can confirm that you've correctly

understood the various issues about which you were unsure.

Incidentally we had been talking about something like this with Rohit

recently.

There are so many things to do at the moment, could you please address

these points before we apply your patch, that would help a lot:

1) need to extend the quaternion unit tests to cover that. The file is

test/geo_quaternion.cpp. No need to adapt all of it, just append a few

sanity checks for Quaternion<Map...> at the end, e.g. build a

quaternion that maps the array of a plain quaternion, do some

arithmetic on both and check (VERIFY_IS_APPROX) that the results are

the same.

2) i've made a few comments inline below.

2009/10/21 Mathieu Gautier <mathieu.gautier@xxxxxx>:

> Hi,OK. So indeed with the current quaternion class you were out of luck

>

> I want to implement a class which hold both a quaternion and a vector3 to

> discribe a position of a frame in respect to an other frame (Something

> similar to Frame in KDL). For some historic reason, the memory layout must

> be a continuous array of scalar (Scalar[7]), the 3 first scalars are the

> vector3 and the other are the quaternion. Besides I have to interface this

> structure with other libraries which return an array of 7 scalars. I also

> have to map array of 4 scalars into the Quaternion class.

because its array is 16-byte aligned.

Indeed.

>

> I though of something like that :

>

> template<typename _Scalars>

> struct Frame {

> _Scalars[7] data;

> Map<Matrix<3,1,_Scalars>> v;

> Map<Quaternion<_Scalars>> q;

> };

>

> and setting the Map accordingly. However, there's no such concept of Map for

> the Quaternion class or RotationBase.

Good.

>

> So, I modified the Quaternion class to use either a Matrix<Scalar,4,1> to

> store the quaternion coefficients or a Map<Matrix<Scalar,4,1>> to map an

> array of scalars. I added a argument to the template prototype of the

> quaternion class which I call StorageType which is either the Matrix or

> Map<Matrix>.

In the Quaternion constructor, you could add some sanity checks for that type:

EIGEN_STATIC_ASSERT_VECTOR_ONLY(StorageType)

EIGEN_STATIC_ASSERT(

int(StorageType::Flags)&DirectAccessBit,

THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_WITH_DIRECT_MEMORY_ACCESS_SUCH_AS_MAP_OR_PLAIN_MATRICES

)That's good and there's no alignment issue, because the StorageType

> Since I have almost no experience with Eigen, I don't know if it's the

> better choice and if it could cause alignement issues. I have attached my

> modifications as a patch. This implementation may be incomplete.

would only claim to be aligned if you explicitly tell it that the

pointer is aligned.

Currently we have a little performance trouble: there's no way to tell

Map that the pointer is aligned, but see other new thread, this is

taken care of.

Looks good.

>

> So, to summarize, the Frame class would be:

>

> template<typename _Scalars>

> struct Frame {

> _Scalars[7] data;

> Map<Matrix<3,1,_Scalars>> v;

> QuaternionMap<_Scalars> q;

> };

>

> where v is a mapping of data and q a mapping of data+3.

Some more comments inline in the patch:

>

> --> -template<typename _Scalar> struct ei_traits<Quaternion<_Scalar> >

> +template<typename _Scalar, class StorageType> struct

> ei_traits<Quaternion<_Scalar, StorageType> >

> {

> typedef _Scalar Scalar;

> };

>

> -template<typename _Scalar>

> -class Quaternion : public RotationBase<Quaternion<_Scalar>,3>

> +template<typename _Scalar, class StorageType = Matrix<_Scalar, 4, 1>>

> +class Quaternion : public RotationBase<Quaternion<_Scalar, StorageType>,3>

Why make it templated in both the Scalar and StorageType? The Scalar

could be deduced from the storage type:

typedef typename StorageType::Scalar Scalar;

fewer template argument passing, is better.

well, I guess we still want the user to be able to just write:

typedef Quaternion<MyScalar> MyQuat;

and not:

typedef Quaternion<Matrix<MyScalar,4,1> > MyQuat;

right ?

then the first template argument of Quaternion must be the scalar type. But if we prefer we can also introduce a QuaternionBase and a QuaternionWrapper classes like we did for DiagonalMatrix. Of course this is more work, but perhaps that's a good idea to harmonize that over Eigen.

gael.

**Follow-Ups**:**Re: [eigen] Mapping array of scalars into quaternions***From:*Mathieu Gautier

**Re: [eigen] Mapping array of scalars into quaternions***From:*Benoit Jacob

**References**:**[eigen] Mapping array of scalars into quaternions***From:*Mathieu Gautier

**Re: [eigen] Mapping array of scalars into quaternions***From:*Benoit Jacob

**Messages sorted by:**[ date | thread ]- Prev by Date:
**Re: [eigen] Mapping array of scalars into quaternions** - Next by Date:
**Re: [eigen] Eigen::FFT and Eigen::Complex in repo** - Previous by thread:
**Re: [eigen] Mapping array of scalars into quaternions** - Next by thread:
**Re: [eigen] Mapping array of scalars into quaternions**

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