[vtkusers] Relative Rotation with VTK Transform

Lonni Besançon lonni.besancon at gmail.com
Tue Feb 16 19:29:47 EST 2016


David,

I decided to get back to a basic version of the code to make sure that I did
not do anything wrong.

/void method(double* rotation, double* translation){
//rotation is in the form of a quaternion with angle in radians
vtkSmartPointer<vtkTransform>t = vtkTransform::New();
double axis[3] ;
t->SetMatrix(actor->GetMatrix());  
vtkQuaternion<double> q =
vtkQuaternion<double>(rotation[3],rotation[0],rotation[2],rotation[1]);
q.Normalize();
angle = q.GetRotationAngleAndAxis(axis);
t->PreMultiply();
t->RotateWXYZ(angle*180.0/3.14,axis[0],axis[1],axis[2]);
actor->SetUserMatrix(t->GetMatrix());

}/

So this is a basic version that does not work.

Yet I thought this was only linked to the Pre or Post Multiply setup, so I
tried changing it and it did not actually change anything.

So then I thought that what I was missing was to take into account the
current orientation of my actor and so I did:

/void method(double* rotation, double* translation){
double quatActor[4] ;
double axis[3] ;
//rotation is in the form of a quaternion with angle in radians
vtkSmartPointer<vtkTransform>t = vtkTransform::New();
t->SetMatrix(actor->GetMatrix());  
vtkQuaternion<double> q =
vtkQuaternion<double>(rotation[3],rotation[0],rotation[2],rotation[1]);
t->GetOrientationWXYZ (quatActor) ;
vtkQuaternion<double> qA =
vtkQuaternion<double>(quatActor[3],quatActor[0],quatActor[1],quatActor[2]);
q = qA.Inverse() * q ;
q.Normalize();
angle = qA.GetRotationAngleAndAxis(axis);
t->RotateWXYZ(angle*180.0/3.14,axis[0],axis[1],axis[2]);
}/

But I don't get a better result.
Is there a crucial point that I'm missing here? Or maybe I misunderstood how
the Transform works. In any case, I have a feeling there is something
obvious that I don't get right with vtkTransforms right now.

My aim is to mimic what you would get with a mouse or a touch input. Imagine
we use the bunny.vtp dataset, tilting the tablet along the x axis causes the
bunny to show its feet. If we rotate with 90 degrees, its ears are not shown
and we only see the paws.
Then if the rotation was along the y axis, say 90 degrees, we would get to
see its tail in front of us. If we were then to perform a rotation along the
x-axis, we should see as a result the tail going up. However, in my case,
what I see is the bunny rotating as if it was still in its original position
( the paws are going up, and not the tail ).





--
View this message in context: http://vtk.1045678.n5.nabble.com/Relative-Rotation-with-VTK-Transform-tp5736566p5736602.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list