[vtkusers] Using a boxwidgets transform to rotate a non-vtk 3D model?
Totte Karlsson
totte at dunescientific.com
Thu Aug 6 15:55:43 EDT 2015
On 8/6/2015 7:40 AM, Cory Quammen wrote:
> TK,
>
> You can get the orientation in angle-axis representation with
>
> double wxyz[4];
> t->GetOrientationWXYZ(wxyz);
>
> From the docs [1]:
>
> The angle (w) is in degrees and the axis (xyz) is a unit vector.
>
> You should be able to apply this rotation to your molecule model's
> RotateAboutVector function.
>
>
Thanks for the response.
I modified the boxwidget example in order to test your approach using a
vtk actor, instead of my model, and what I believe I'm seeing is that
the data from getOrientationWXYZ () is from the 'initial' orientation,
instead of a progressive transformation. E.g using the following code in
the callback function:
virtual void Execute(vtkObject *caller, unsigned long, void*)
{
static int callCount = 0;
vtkSmartPointer<vtkTransform> t =
vtkSmartPointer<vtkTransform>::New();
vtkBoxWidget *widget = reinterpret_cast<vtkBoxWidget*>(caller);
widget->GetTransform(t);
//widget->GetProp3D()->SetUserTransform(t);
double* wxyz = t->GetOrientationWXYZ();
if(anActor)
{
cout<<"CallCount: "<<callCount<<" Angle "<<wxyz[0]<<endl;
anActor->RotateWXYZ(wxyz[0], wxyz[1], wxyz[2],wxyz[3]);
}
callCount++;
}
Gives an angle output like this:
CallCount: 0 Angle 0
CallCount: 1 Angle 0.848528
CallCount: 2 Angle 1.69706
CallCount: 3 Angle 2.54558
CallCount: 4 Angle 3.39411
CallCount: 5 Angle 5.9397
CallCount: 6 Angle 6.78823
CallCount: 7 Angle 7.63675
CallCount: 8 Angle 8.48528
CallCount: 9 Angle 8.48528
CallCount: 10 Angle 8.48528
when moving the widget slightly with the mouse. Each 'callcount'
represent a movement using the mouse.
Question is, how would one go about getting the 'latest' transformation,
instead of the 'accumulated' one from the box widgets GetTransform()?
I guess I could save the transformation each time and do a 'back
transformation' before applying the new transformation. But that would
be more work (I assume), than applying an incremental rotation.
-tk
>
> [1]
> http://www.vtk.org/doc/nightly/html/classvtkTransform.html#aa8244cbab95a2dbb20e94af6e7f16b7f
>
>
> On Wed, Aug 5, 2015 at 8:54 PM, Totte Karlsson
> <totte at dunescientific.com <mailto:totte at dunescientific.com>> wrote:
>
> Hello,
> I'm using vtk to visualize 3D models of molecules.
> The actual molecular model is decoupled from vtk code, and
> visualization is implemented using a model-view kind of design.
>
> Currently I have the following challenge. If a user wants to
> manipulate the absolute orientation of the molecule, it is done by
> manipulating the underlying model using rotation functions, like
> RotateX, RotateY, RotateAboutVector, and translation functions
> TranslateX, Y etc.
>
> For now 3D rotations are simply done using two scrollbars, one
> horizontal and one vertical, causing the underlying model being
> rotated about the vtk viewUP vector and the vtk cameraPlane normal
> respectively. This works fine, but is not so intuitive for the user.
>
> Instead I believe allowing interaction with something like a box
> widget that encapsulates the molecule view, (with disabled
> handles), would be better.
>
> The challenge is how to figure out how to capture the boxwidgets
> orientation in a callback, and using this information in order to
> manipulate the underlying molecular model.
>
> For example, a boxwidget callback (from boxwidget example at
> http://www.vtk.org/Wiki/VTK/Examples/Cxx/Widgets/BoxWidget):
>
> class vtkMyCallback : public vtkCommand
> {
> public:
> static vtkMyCallback *New() { return new
> vtkMyCallback; }
>
> virtual void Execute(vtkObject *caller, unsigned long, void*)
> {
> vtkSmartPointer<vtkTransform> t =
> vtkSmartPointer<vtkTransform>::New();
> vtkBoxWidget *widget =
> reinterpret_cast<vtkBoxWidget*>(caller);
> widget->GetTransform(t);
>
> double* angles?? = t->GetOrientation();
> if(aMoleculeModel)
> {
> //Use some secret(!) code to manipulate orientation of
> a molecule to 'rotate' it together with the boxWidget
> aMoleculeModel->RotateZ(??);
> aMoleculeModel->RotateY(??);
> aMoleculeModel->RotateZ(??);
> }
> }
> Molecule* aMoleculeModel;
>
> Anyone seeing how to do this or have some pointers?
>
> Cheers,
> tk
>
> _______________________________________________
> Powered by www.kitware.com <http://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
>
>
>
>
> --
> Cory Quammen
> R&D Engineer
> Kitware, Inc.
--
------------------------------------------------------------------------
<http://www.dunescientific.com/>
Totte Karlsson: totte at dunescientific.com
<mailto:totte at dunescientific.com> or (425) 780-9648
<tel:%20425%20%20780-9648>
http://www.dunescientific.com/
© 2015 Dune Scientific, LLC. All rights reserved.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150806/7110bfdf/attachment.html>
More information about the vtkusers
mailing list