[Insight-users] QuaternionTransform: Direction of Rotation
Lydia Ng
lng at insightful . com
Fri, 15 Aug 2003 14:38:38 -0700
Hi Michael,
We have made some fixes so that QuaternionTransform and AffineTransform
now have the same direction for positive rotation.
BTW - We didn't touch any of the vnl code, instead we get the
rotation_matrix from the conjugate quaternion.
- Lydia
> -----Original Message-----
> From: Luis Ibanez [mailto:luis . ibanez at kitware . com]
> Sent: Tuesday, August 12, 2003 4:40 PM
> To: Michael Kuhn
> Cc: insight-users; Lydia Ng
> Subject: Re: [Insight-users] QuaternionTransform: Direction of
Rotation
>=20
>=20
> Hi Michael,
>=20
> Thanks for posting such a detailed test.
>=20
> I was able to reproduce the error you reported, and it seems
> to be due to a difference in the way VXL/vnl and ITK represent
> matrices.
>=20
> It seems that the rotation_matrix produced by the vnl_quaternion
> should be transposed before being transferred to ITK in
> itkQuaternionTransform.txx.
>=20
> It is likely that the Jacobian of the transform may have also
> some transposition.
>=20
> We are looking into this, and will be commiting some fix soon.
>=20
> In the meantime, the correct matrix is the one you are obtaining
> with the AffineTransform.
>=20
>=20
>=20
> Regards,
>=20
>=20
>=20
> Luis
>=20
>=20
> -----------------------
> Michael Kuhn wrote:
> > Hi,
> >
> > I'm still having problems to understand the correct setup of the
> > quaternion transform parameters. I quickly set up a program to
> > demonstrate my problem:
> >
> > I'm trying to rotate the point (1, 0, 0) around the z-Axis by angle
+phi
> > using an affine and a quaternion transform.
> >
> > The results of these two transforms turn out to be different with
> > respect to the direction of rotation. Is there something wrong with
the
> > way I set up the parameters?
> >
> > Thanks,
> >
> > Michael
> >
> >
> > Below the output of my program and the program code:
> >
> > Output:
> > --------
> >
> > result for affine transform:
> > 0.980067
> > 0.198669
> > 0
> > result for quaternion transform:
> > 0.980067
> > -0.198669
> > 0
> >
> >
> >
> >
> > Program Code
> > ---------------
> >
> > #include "itkQuaternionRigidTransform.h"
> > #include "itkAffineTransform.h"
> >
> >
> > #include <iostream>
> >
> > int main(int argc, char** argv) {
> >
> > typedef itk::QuaternionRigidTransform<double>
> QuaternionTransformType;
> > typedef itk::AffineTransform<double, 3> AffineTransformType;
> >
> > QuaternionTransformType::Pointer quaternionTransform =3D
> > QuaternionTransformType::New();
> >
> > AffineTransformType::Pointer affineTransform =3D
> > AffineTransformType::New();
> >
> > double phi =3D 0.2;
> > // rotation around the z-Axis for Affine Transform:
> >
> > AffineTransformType::ParametersType
> > affineParameters(affineTransform->GetNumberOfParameters());
> >
> > affineParameters[0] =3D cos(phi);
> > affineParameters[1] =3D -sin(phi);
> > affineParameters[2] =3D 0;
> > affineParameters[3] =3D sin(phi);
> > affineParameters[4] =3D cos(phi);
> > affineParameters[5] =3D 0;
> > affineParameters[6] =3D 0;
> > affineParameters[7] =3D 0;
> > affineParameters[8] =3D 1;
> > affineParameters[9] =3D 0;
> > affineParameters[10] =3D 0;
> > affineParameters[11] =3D 0;
> >
> > affineTransform->SetParameters(affineParameters);
> >
> >
> >
> > // rotation around the z-Axis for Quaternion Transform:
> >
> > QuaternionTransformType::ParametersType
> > quaternionParameters(quaternionTransform-
> >GetNumberOfParameters());
> >
> > quaternionParameters[0] =3D 0;
> > quaternionParameters[1] =3D 0;
> > quaternionParameters[2] =3D 1 * sin(phi / 2);
> > quaternionParameters[3] =3D cos(phi / 2);
> > quaternionParameters[4] =3D 0;
> > quaternionParameters[5] =3D 0;
> > quaternionParameters[6] =3D 0;
> >
> > quaternionTransform->SetParameters(quaternionParameters);
> >
> >
> > // Define point (1, 0, 0) and rotate with Affine Transform:
> > AffineTransformType::InputPointType inPointAffine;
> >
> > inPointAffine[0] =3D 1;
> > inPointAffine[1] =3D 0;
> > inPointAffine[2] =3D 0;
> >
> > AffineTransformType::OutputPointType outPointAffine =3D
> > affineTransform->TransformPoint(inPointAffine);
> >
> > // Define point (1, 0, 0) and rotate with Quaternion Transform:
> > QuaternionTransformType::InputPointType inPointQuaternion;
> >
> > inPointQuaternion[0] =3D 1;
> > inPointQuaternion[1] =3D 0;
> > inPointQuaternion[2] =3D 0;
> >
> > QuaternionTransformType::OutputPointType outPointQuaternion;
> > outPointQuaternion =3D
> > quaternionTransform->TransformPoint(inPointQuaternion);
> >
> > // compare the two results
> > std::cout << "result for affine transform: " << std::endl;
> > for (int i =3D 0; i < 3; i++) {
> > std::cout << outPointAffine[i] << std::endl;
> > }
> >
> > std::cout << "result for quaternion transform: " << std::endl;
> > for (int i =3D 0; i < 3; i++) {
> > std::cout << outPointQuaternion[i] << std::endl;
> > }
> >
> > return 0;
> > }
> >
> >
> > _______________________________________________
> > Insight-users mailing list
> > Insight-users at itk . org
> > http://www . itk . org/mailman/listinfo/insight-users
> >
>=20
>=20