[vtkusers] Relative Rotation with VTK Transform

David Gobbi david.gobbi at gmail.com
Tue Feb 16 22:14:48 EST 2016


On Tue, Feb 16, 2016 at 5:29 PM, Lonni Besançon <lonni.besancon at gmail.com>
wrote:

> 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
>

The above comment confuses me.  None of the elements of a quaternion are
angles, so why say "in radians"?


vtkSmartPointer<vtkTransform>t = vtkTransform::New();
>

This is a minor point, but using a VTK smart pointer like the above creates
a memory leak.  Proper use of vtkSmartPointer is this:

vtkSmartPointer<vtkTransform> t = vtkSmartPointer<vtkTransform>::New();



> double axis[3] ;
> t->SetMatrix(actor->GetMatrix());
> vtkQuaternion<double> q =
> vtkQuaternion<double>(rotation[3],rotation[0],rotation[2],rotation[1]);
>

This line of code also confuses me.  What are the elements of "rotation"?
Why is this strange ordering used?



> q.Normalize();
> angle = q.GetRotationAngleAndAxis(axis);
> t->PreMultiply();
> t->RotateWXYZ(angle*180.0/3.14,axis[0],axis[1],axis[2]);
>

Using "3.14" for pi is not very precise.


Please fix my confusion regarding the elements of "rotation" before I go
any further with this...

 - David



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.
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160216/1ed9dfe0/attachment.html>


More information about the vtkusers mailing list