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*: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>*Date*: Thu, 22 Oct 2009 11:57:24 -0400*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 :content-transfer-encoding; bh=gNQ4qkLaw7mu6R+/TupozlN3lZ8JoTsBkxqUp5gk0Vw=; b=DzQgd6Wde3zvPxB+88rJ0i+CKSbXFNsY3K6hpg1pqz87XBbk8nsu0jdJh+Kx/rmDQq qd8ghAdE0pHR5qpKy+VhVWeiGqVd2C2Osex1GrDVgF/FEki956tbJ2mThtpBfzbbH5bh HdJMNou0GKQ8saK6Aw06t8bjkO8N+wYCH7CHA=*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:content-transfer-encoding; b=lk7hClObiZyyjqJqSYj/u9RdU3i8bQdhztPQ5o+CtmdJbns528Ft4hXo6FTo9bK4zY +HdvVXr8gFOoQ0pyDkfUV7a5uumwJMBwqj2JWqkohADfbxvkty8lH8Uj2I0S21j5naqE dTDaXnzDr6aWMyziUsHS/Zoi3QHT0aZn+ffCk=

2009/10/22 Gael Guennebaud <gael.guennebaud@xxxxxxxxx>: > > > On Wed, Oct 21, 2009 at 4:41 PM, Benoit Jacob <jacob.benoit.1@xxxxxxxxx> > wrote: >> >> 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, >> > >> > 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. >> >> OK. So indeed with the current quaternion class you were out of luck >> because its array is 16-byte aligned. >> >> > >> > 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. >> >> Indeed. >> >> > >> > 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>. >> >> Good. >> 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 >> ) >> >> > 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. >> >> That's good and there's no alignment issue, because the StorageType >> 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. >> >> > >> > 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. >> >> Looks good. >> >> 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. This is what Mathieu's patch does. > 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. The reason why I introduced DiagonalBase was that DiagonalMatrix and DiagonalWrapper can't be completely unified, they need e.g. different constructors and have different ei_traits. Now looking at the case of quaternions, there too we need different constructors: the QuaternionWrapper needs a ctor taking a pointer and doesn't want the ctor taking 4 numbers, for example. So, you're right. Benoit

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

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

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

**Re: [eigen] Mapping array of scalars into quaternions***From:*Gael Guennebaud

**Messages sorted by:**[ date | thread ]- Prev by Date:
**Re: [eigen] Map: introduce "AlignedPointer" flag?** - Next by Date:
**Re: [eigen] Mapping array of scalars into quaternions** - 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/ |