[Insight-users] QuaternionTransform: Direction of Rotation

Luis Ibanez luis . ibanez at kitware . com
Tue, 12 Aug 2003 19:39:44 -0400


Hi Michael,

Thanks for posting such a detailed test.

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.

It seems that the rotation_matrix  produced by the vnl_quaternion
should be transposed before being transferred to ITK in
itkQuaternionTransform.txx.

It is likely that the Jacobian of the transform may have also
some transposition.

We are looking into this, and will be commiting some fix soon.

In the meantime, the correct matrix is the one you are obtaining
with the AffineTransform.



Regards,



   Luis


-----------------------
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 =
>        QuaternionTransformType::New();
> 
>    AffineTransformType::Pointer affineTransform = 
> AffineTransformType::New();
> 
>    double phi = 0.2;
>       // rotation around the z-Axis for Affine Transform:
> 
>    AffineTransformType::ParametersType
>        affineParameters(affineTransform->GetNumberOfParameters());
> 
>    affineParameters[0] = cos(phi);
>    affineParameters[1] = -sin(phi);
>    affineParameters[2] = 0;
>    affineParameters[3] = sin(phi);
>    affineParameters[4] = cos(phi);
>    affineParameters[5] = 0;
>    affineParameters[6] = 0;
>    affineParameters[7] = 0;
>    affineParameters[8] = 1;
>    affineParameters[9] = 0;
>    affineParameters[10] = 0;
>    affineParameters[11] = 0;
> 
>    affineTransform->SetParameters(affineParameters);
> 
> 
> 
>    // rotation around the z-Axis for Quaternion Transform:
> 
>    QuaternionTransformType::ParametersType
>        quaternionParameters(quaternionTransform->GetNumberOfParameters());
> 
>    quaternionParameters[0] = 0;
>    quaternionParameters[1] = 0;
>    quaternionParameters[2] = 1 * sin(phi / 2);
>    quaternionParameters[3] = cos(phi / 2);
>    quaternionParameters[4] = 0;
>    quaternionParameters[5] = 0;
>    quaternionParameters[6] = 0;
> 
>    quaternionTransform->SetParameters(quaternionParameters);
> 
> 
>    // Define point (1, 0, 0) and rotate with Affine Transform:
>    AffineTransformType::InputPointType inPointAffine;
> 
>    inPointAffine[0] = 1;
>    inPointAffine[1] = 0;
>    inPointAffine[2] = 0;
> 
>    AffineTransformType::OutputPointType outPointAffine =
>        affineTransform->TransformPoint(inPointAffine);
> 
>    // Define point (1, 0, 0) and rotate with Quaternion Transform:
>    QuaternionTransformType::InputPointType inPointQuaternion;
> 
>    inPointQuaternion[0] = 1;
>    inPointQuaternion[1] = 0;
>    inPointQuaternion[2] = 0;
> 
>    QuaternionTransformType::OutputPointType outPointQuaternion;
>    outPointQuaternion =
>        quaternionTransform->TransformPoint(inPointQuaternion);
> 
>    // compare the two results
>    std::cout << "result for affine transform: " << std::endl;
>    for (int i = 0; i < 3; i++) {
>        std::cout << outPointAffine[i] << std::endl;
>    }
> 
>    std::cout << "result for quaternion transform: " << std::endl;
>    for (int i = 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
>