<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<br>
<br>
<div class="moz-cite-prefix">On 8/6/2015 1:52 PM, Cory Quammen
wrote:<br>
</div>
<blockquote
cite="mid:CAB5Fpx532gPSmU+DambM-uqvk8D2fosFrvVF8QgumMcQA9f2uA@mail.gmail.com"
type="cite">
<div dir="ltr">
<div><br>
</div>
<div class="gmail_extra">
<div class="gmail_quote">I guess I don't see the problem here.
You have a reference to the actor here, and the actor has
the orientation. Did you try this approach out and it didn't
work? vtkActor::SetOrientation(0, 0, 0) will reset the
rotation for you.</div>
</div>
</div>
</blockquote>
Tried SetOrientation(0,0,0) and as you say that works too. However,
with my molecular model I can't do such a thing.<br>
<blockquote
cite="mid:CAB5Fpx532gPSmU+DambM-uqvk8D2fosFrvVF8QgumMcQA9f2uA@mail.gmail.com"
type="cite">
<div dir="ltr">
<div class="gmail_extra">
<div class="gmail_quote">
<div> </div>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000"><span> <br>
What I'm looking for is instead to perform incremental
rotations, avoiding the "transforming back", i.e.
(reset) part.</span></div>
</blockquote>
<div><br>
</div>
<div>I don't know of a quick and easy way to get the
incremental rotation you are looking for, hence my
suggestion.<br>
</div>
</div>
</div>
</div>
</blockquote>
<br>
Appreciate it! Your approach works fine. Now looking in to making it
more efficient. Should be possible I think..<br>
<br>
Thanks!<br>
tk<br>
<br>
Here is the full code in case. It is just the boxwidget example code
modified.<br>
<br>
#include <vtkSmartPointer.h><br>
#include <vtkActor.h><br>
#include <vtkBoxWidget.h><br>
#include <vtkCamera.h><br>
#include <vtkCommand.h><br>
#include <vtkConeSource.h><br>
#include <vtkInteractorStyleTrackballCamera.h><br>
#include <vtkPolyDataMapper.h><br>
#include <vtkRenderWindow.h><br>
#include <vtkRenderWindowInteractor.h><br>
#include <vtkRenderer.h><br>
#include <vtkTransform.h><br>
<br>
class vtkMyCallback : public vtkCommand<br>
{<br>
public:<br>
static vtkMyCallback *New()<br>
{<br>
return new vtkMyCallback;<br>
}<br>
<br>
virtual void Execute(vtkObject *caller, unsigned long,
void*)<br>
{<br>
static int callCount = 0;<br>
static double lastAngle = 0;<br>
<br>
vtkSmartPointer<vtkTransform> t =
vtkSmartPointer<vtkTransform>::New();<br>
static vtkSmartPointer<vtkTransform> lastTransform
= vtkSmartPointer<vtkTransform>::New();<br>
vtkBoxWidget *widget =
reinterpret_cast<vtkBoxWidget*>(caller);<br>
widget->GetTransform(t);<br>
<br>
double *pos = t->GetPosition();<br>
double *lastPos = lastTransform->GetPosition();<br>
double *wxyz = t->GetOrientationWXYZ();<br>
double *lastWXYZ =
lastTransform->GetOrientationWXYZ();<br>
<br>
if(anActor)<br>
{<br>
cout<<"CallCount:
"<<callCount<<"Current Angle "<<wxyz[0]<<"
Effective angle:"<< wxyz[0] - lastAngle<br>
<<" Position: "<<pos[0]<<",
"<<pos[1]<<", "<<pos[2]<<endl;<br>
<br>
//Transform 'back'<br>
anActor->RotateWXYZ(-lastAngle, lastWXYZ[1],
lastWXYZ[2], lastWXYZ[3]);<br>
anActor->RotateWXYZ(wxyz[0], wxyz[1], wxyz[2],
wxyz[3]);<br>
}<br>
<br>
//Save transform data<br>
lastAngle = wxyz[0] ;<br>
lastTransform = t;<br>
callCount++;<br>
}<br>
<br>
vtkActor* anActor;<br>
};<br>
<br>
<br>
int main(int, char*[])<br>
{<br>
vtkSmartPointer<vtkConeSource> cone =
vtkSmartPointer<vtkConeSource>::New();<br>
cone->SetHeight( 3.0 );<br>
cone->SetRadius( 2.0 );<br>
cone->SetResolution( 50 );<br>
cone->Update();<br>
<br>
vtkSmartPointer<vtkPolyDataMapper> coneMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();<br>
coneMapper->SetInputConnection( cone->GetOutputPort() );<br>
<br>
vtkSmartPointer<vtkActor> coneActor =
vtkSmartPointer<vtkActor>::New();<br>
coneActor->SetMapper( coneMapper );<br>
<br>
vtkSmartPointer<vtkRenderer> ren1=
vtkSmartPointer<vtkRenderer>::New();<br>
ren1->AddActor( coneActor );<br>
ren1->SetBackground( 0.1, 0.2, 0.4 );<br>
<br>
coneActor->SetPosition(1,1,1);<br>
vtkSmartPointer<vtkRenderWindow> renWin =
vtkSmartPointer<vtkRenderWindow>::New();<br>
renWin->AddRenderer( ren1 );<br>
renWin->SetSize( 300, 300 );<br>
<br>
vtkSmartPointer<vtkRenderWindowInteractor> iren =
vtkSmartPointer<vtkRenderWindowInteractor>::New();<br>
iren->SetRenderWindow(renWin);<br>
<br>
vtkSmartPointer<vtkInteractorStyleTrackballCamera> style =
vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();<br>
iren->SetInteractorStyle(style);<br>
<br>
// The place factor<br>
// controls the initial size of the widget with respect to the
bounding box<br>
// of the input to the widget.<br>
vtkSmartPointer<vtkBoxWidget> boxWidget =
vtkSmartPointer<vtkBoxWidget>::New();<br>
boxWidget->SetInteractor(iren);<br>
boxWidget->SetPlaceFactor(2.25);<br>
<br>
boxWidget->HandlesOff();<br>
boxWidget->SetTranslationEnabled(0);<br>
boxWidget->SetScalingEnabled(0);<br>
<br>
<br>
//For placement<br>
boxWidget->SetProp3D(coneActor);<br>
boxWidget->PlaceWidget();<br>
<br>
vtkSmartPointer<vtkMyCallback> callback =
vtkSmartPointer<vtkMyCallback>::New();<br>
boxWidget->AddObserver(vtkCommand::InteractionEvent,
callback);<br>
<br>
boxWidget->On();<br>
callback->anActor = coneActor;<br>
<br>
iren->Initialize();<br>
iren->Start();<br>
<br>
return EXIT_SUCCESS;<br>
}<br>
<br>
<br>
<blockquote
cite="mid:CAB5Fpx532gPSmU+DambM-uqvk8D2fosFrvVF8QgumMcQA9f2uA@mail.gmail.com"
type="cite">
<div dir="ltr">
<div class="gmail_extra">
<div class="gmail_quote">
<div><br>
</div>
<div>Cory</div>
<div> <br>
</div>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000"><span><span
class="HOEnZb"><font color="#888888"><br>
<br>
tk<br>
</font></span></span>
<div>
<div class="h5"><br>
<blockquote type="cite">
<div class="gmail_extra">
<div class="gmail_quote">On Thu, Aug 6, 2015 at
4:26 PM, Totte Karlsson <span dir="ltr"><<a
moz-do-not-send="true"
href="mailto:totte@dunescientific.com"
target="_blank"><a class="moz-txt-link-abbreviated" href="mailto:totte@dunescientific.com">totte@dunescientific.com</a></a>></span>
wrote:<br>
<blockquote class="gmail_quote"
style="margin:0 0 0 .8ex;border-left:1px
#ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000"> Hello
Cory,<br>
I was able to use your suggestion and got
some code to work, as follows:<span><br>
<br>
virtual void Execute(vtkObject
*caller, unsigned long, void*)<br>
{<br>
</span><span> static int callCount
= 0;<br>
</span> static double lastAngle =
0;<br>
static double lastVec[3] =
{0,0,0};<span><br>
vtkSmartPointer<vtkTransform> t
=
vtkSmartPointer<vtkTransform>::New();<br>
</span> static
vtkSmartPointer<vtkTransform>
lastTransform =
vtkSmartPointer<vtkTransform>::New();<span><br>
vtkBoxWidget *widget =
reinterpret_cast<vtkBoxWidget*>(caller);<br>
widget->GetTransform(t);<br>
<br>
</span> double* wxyz =
t->GetOrientationWXYZ();<br>
double* lastWXYZ =
lastTransform->GetOrientationWXYZ();<br>
<br>
if(anActor)<br>
{<br>
cout<<"CallCount:
"<<callCount<<"Current Angle
"<<wxyz[0]<<" Effective
angle:"<< wxyz[0] -
lastAngle<<endl;<br>
<br>
//Transform 'back'<br>
anActor->RotateWXYZ(-lastAngle,
lastWXYZ[1], lastWXYZ[2], lastWXYZ[3]);<span><br>
anActor->RotateWXYZ(wxyz[0], wxyz[1],
wxyz[2], wxyz[3]);<br>
}<br>
<br>
</span> //Save transform data<br>
lastAngle = wxyz[0] ;<br>
lastVec[0] =wxyz[1];<br>
lastVec[1] =wxyz[2];<br>
lastVec[2] =wxyz[3];<br>
<br>
lastTransform = t;<br>
callCount++;<br>
}<br>
<br>
In the above code, two transformations of
the actor are done, in order to follow the
orientation of the widget. 1) to rotate
the actor to its initial position, and 2),
applying current transformation.<br>
<br>
Although the above code works, is there a
way to get the 'incremental' transform
somehow? I'm a novice about these things
so sorry if asking something obvious...<span><font
color="#888888"><br>
<br>
tk</font></span><span><br>
<br>
<br>
<div>On 8/6/2015 7:40 AM, Cory Quammen
wrote:<br>
</div>
</span>
<div>
<div>
<blockquote type="cite">
<div dir="ltr">TK,
<div><br>
</div>
<div>You can get the orientation
in angle-axis representation
with</div>
<div><br>
</div>
<div>double wxyz[4];</div>
<div>t->GetOrientationWXYZ(wxyz);</div>
<div><br>
</div>
<div>From the docs [1]:</div>
<div><br>
</div>
<div><span
style="color:rgb(0,0,0);font-family:Roboto,sans-serif;font-size:14px;line-height:22px">The
angle (w) is in degrees and
the axis (xyz) is a unit
vector.</span><br>
</div>
<div><br>
</div>
<div>You should be able to apply
this rotation to your molecule
model's RotateAboutVector
function.</div>
<div><br>
</div>
<div>HTH,</div>
<div>Cory</div>
<div><span
style="color:rgb(0,0,0);font-family:Roboto,sans-serif;font-size:14px;line-height:22px"><br>
</span></div>
<div><span
style="color:rgb(0,0,0);font-family:Roboto,sans-serif;font-size:14px;line-height:22px">[1] </span><font
color="#000000" face="Roboto,
sans-serif"><span
style="font-size:14px;line-height:22px"><a
moz-do-not-send="true"
href="http://www.vtk.org/doc/nightly/html/classvtkTransform.html#aa8244cbab95a2dbb20e94af6e7f16b7f"
target="_blank"><a class="moz-txt-link-freetext" href="http://www.vtk.org/doc/nightly/html/classvtkTransform.html#aa8244cbab95a2dbb20e94af6e7f16b7f">http://www.vtk.org/doc/nightly/html/classvtkTransform.html#aa8244cbab95a2dbb20e94af6e7f16b7f</a></a></span></font></div>
<div><br>
</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Wed,
Aug 5, 2015 at 8:54 PM, Totte
Karlsson <span dir="ltr"><<a
moz-do-not-send="true"
href="mailto:totte@dunescientific.com"
target="_blank"><a class="moz-txt-link-abbreviated" href="mailto:totte@dunescientific.com">totte@dunescientific.com</a></a>></span>
wrote:<br>
<blockquote class="gmail_quote"
style="margin:0 0 0
.8ex;border-left:1px #ccc
solid;padding-left:1ex">Hello,<br>
I'm using vtk to visualize 3D
models of molecules.<br>
The actual molecular model is
decoupled from vtk code, and
visualization is implemented
using a model-view kind of
design.<br>
<br>
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.<br>
<br>
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.<br>
<br>
Instead I believe allowing
interaction with something
like a box widget that
encapsulates the molecule
view, (with disabled handles),
would be better.<br>
<br>
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.<br>
<br>
For example, a boxwidget
callback (from boxwidget
example at <a
moz-do-not-send="true"
href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/Widgets/BoxWidget"
target="_blank"><a class="moz-txt-link-freetext" href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/Widgets/BoxWidget">http://www.vtk.org/Wiki/VTK/Examples/Cxx/Widgets/BoxWidget</a></a>):<br>
<br>
class vtkMyCallback : public
vtkCommand<br>
{<br>
public:<br>
static vtkMyCallback
*New() {
return new vtkMyCallback; }<br>
<br>
virtual void
Execute(vtkObject *caller,
unsigned long, void*)<br>
{<br>
vtkSmartPointer<vtkTransform>
t =
vtkSmartPointer<vtkTransform>::New();<br>
vtkBoxWidget *widget =
reinterpret_cast<vtkBoxWidget*>(caller);<br>
widget->GetTransform(t);<br>
<br>
double* angles?? =
t->GetOrientation();<br>
if(aMoleculeModel)<br>
{<br>
//Use some
secret(!) code to manipulate
orientation of a molecule to
'rotate' it together with the
boxWidget<br>
aMoleculeModel->RotateZ(??);<br>
aMoleculeModel->RotateY(??);<br>
aMoleculeModel->RotateZ(??);<br>
}<br>
}<br>
Molecule* aMoleculeModel;<br>
<br>
Anyone seeing how to do this
or have some pointers?<br>
<br>
Cheers,<br>
tk<br>
<br>
_______________________________________________<br>
Powered by <a
moz-do-not-send="true"
href="http://www.kitware.com"
rel="noreferrer"
target="_blank"><a class="moz-txt-link-abbreviated" href="http://www.kitware.com">www.kitware.com</a></a><br>
<br>
Visit other Kitware
open-source projects at <a
moz-do-not-send="true"
href="http://www.kitware.com/opensource/opensource.html"
target="_blank"><a class="moz-txt-link-freetext" href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a></a><br>
<br>
Please keep messages on-topic
and check the VTK FAQ at: <a
moz-do-not-send="true"
href="http://www.vtk.org/Wiki/VTK_FAQ"
target="_blank"><a class="moz-txt-link-freetext" href="http://www.vtk.org/Wiki/VTK_FAQ">http://www.vtk.org/Wiki/VTK_FAQ</a></a><br>
<br>
Search the list archives at: <a
moz-do-not-send="true"
href="http://markmail.org/search/?q=vtkusers"
target="_blank"><a class="moz-txt-link-freetext" href="http://markmail.org/search/?q=vtkusers">http://markmail.org/search/?q=vtkusers</a></a><br>
<br>
Follow this link to
subscribe/unsubscribe:<br>
<a moz-do-not-send="true"
href="http://public.kitware.com/mailman/listinfo/vtkusers"
rel="noreferrer"
target="_blank">http://public.kitware.com/mailman/listinfo/vtkusers</a><br>
</blockquote>
</div>
<br>
<br clear="all">
<div><br>
</div>
-- <br>
<div>Cory Quammen<br>
R&D Engineer<br>
Kitware, Inc.</div>
</div>
</blockquote>
<br>
</div>
</div>
<span>
<div>-- <br>
<hr size="1">
<table border="0" cellpadding="0"
cellspacing="0">
<tbody>
<tr>
<td><a moz-do-not-send="true"
href="http://www.dunescientific.com/"
target="_blank"><img
moz-do-not-send="true"
src="http://www.dunescientific.com/images/email/ds_logo_233x60.png"
alt="" border="0"
height="40"></a></td>
<td><img moz-do-not-send="true"
src="http://www.dunescientific.com/images/email/spacer.gif" alt=""
border="0" height="1"
width="15"></td>
<td bgcolor="#cccccc"><img
moz-do-not-send="true"
src="http://www.dunescientific.com/images/email/spacer.gif"
alt="" border="0" height="1"
width="1"></td>
<td><img moz-do-not-send="true"
src="http://www.dunescientific.com/images/email/spacer.gif" alt=""
border="0" height="1"
width="10"></td>
<td>
<div
style="font-size:10px;color:#666666">
Totte Karlsson: <a
moz-do-not-send="true"
href="mailto:totte@dunescientific.com"
target="_blank"><a class="moz-txt-link-abbreviated" href="mailto:totte@dunescientific.com">totte@dunescientific.com</a></a>
or <a
moz-do-not-send="true"
href="tel:%20425%20%20780-9648"
value="+14257809648"
target="_blank">(425)
780-9648</a><br>
<a moz-do-not-send="true"
href="http://www.dunescientific.com/"
target="_blank">http://www.dunescientific.com/</a>
<br>
© 2015 Dune Scientific, LLC.
All rights reserved. </div>
</td>
</tr>
</tbody>
</table>
</div>
<br>
<br>
</span></div>
</blockquote>
</div>
<br>
<br clear="all">
<div><br>
</div>
-- <br>
<div>Cory Quammen<br>
R&D Engineer<br>
Kitware, Inc.</div>
</div>
</blockquote>
<br>
<div>-- <br>
<hr size="1">
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td><a moz-do-not-send="true"
href="http://www.dunescientific.com/"
target="_blank"><img
moz-do-not-send="true"
src="http://www.dunescientific.com/images/email/ds_logo_233x60.png"
alt="" border="0" height="40"></a></td>
<td><img moz-do-not-send="true"
src="http://www.dunescientific.com/images/email/spacer.gif"
alt="" border="0" height="1" width="15"></td>
<td bgcolor="#cccccc"><img
moz-do-not-send="true"
src="http://www.dunescientific.com/images/email/spacer.gif"
alt="" border="0" height="1" width="1"></td>
<td><img moz-do-not-send="true"
src="http://www.dunescientific.com/images/email/spacer.gif"
alt="" border="0" height="1" width="10"></td>
<td>
<div style="font-size:10px;color:#666666">
Totte Karlsson: <a
moz-do-not-send="true"
href="mailto:totte@dunescientific.com"
target="_blank"><a class="moz-txt-link-abbreviated" href="mailto:totte@dunescientific.com">totte@dunescientific.com</a></a>
or <a moz-do-not-send="true"
href="tel:%20425%20%20780-9648"
value="+14257809648" target="_blank">(425)
780-9648</a><br>
<a moz-do-not-send="true"
href="http://www.dunescientific.com/"
target="_blank">http://www.dunescientific.com/</a>
<br>
© 2015 Dune Scientific, LLC. All rights
reserved. </div>
</td>
</tr>
</tbody>
</table>
</div>
<br>
<br>
</div>
</div>
</div>
<br>
_______________________________________________<br>
Powered by <a moz-do-not-send="true"
href="http://www.kitware.com" rel="noreferrer"
target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a
moz-do-not-send="true"
href="http://www.kitware.com/opensource/opensource.html"
rel="noreferrer" target="_blank"><a class="moz-txt-link-freetext" href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a></a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a
moz-do-not-send="true"
href="http://www.vtk.org/Wiki/VTK_FAQ" rel="noreferrer"
target="_blank"><a class="moz-txt-link-freetext" href="http://www.vtk.org/Wiki/VTK_FAQ">http://www.vtk.org/Wiki/VTK_FAQ</a></a><br>
<br>
Search the list archives at: <a moz-do-not-send="true"
href="http://markmail.org/search/?q=vtkusers"
rel="noreferrer" target="_blank">http://markmail.org/search/?q=vtkusers</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a moz-do-not-send="true"
href="http://public.kitware.com/mailman/listinfo/vtkusers"
rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/vtkusers</a><br>
<br>
</blockquote>
</div>
<br>
<br clear="all">
<div><br>
</div>
-- <br>
<div class="gmail_signature">Cory Quammen<br>
R&D Engineer<br>
Kitware, Inc.</div>
</div>
</div>
</blockquote>
<br>
<div class="moz-signature">-- <br>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<hr size="1">
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td><a moz-do-not-send="true"
href="http://www.dunescientific.com/" target="_blank"><img
moz-do-not-send="true"
src="http://www.dunescientific.com/images/email/ds_logo_233x60.png"
alt="" border="0" height="40"></a></td>
<td><img moz-do-not-send="true"
src="http://www.dunescientific.com/images/email/spacer.gif"
alt="" border="0" height="1" width="15"></td>
<td bgcolor="#cccccc"><img moz-do-not-send="true"
src="http://www.dunescientific.com/images/email/spacer.gif"
alt="" border="0" height="1" width="1"></td>
<td><img moz-do-not-send="true"
src="http://www.dunescientific.com/images/email/spacer.gif"
alt="" border="0" height="1" width="10"></td>
<td>
<div style="font-size:10px;color:#666666"> Totte Karlsson:
<a moz-do-not-send="true"
href="mailto:totte@dunescientific.com" target="_blank">totte@dunescientific.com</a>
or <a moz-do-not-send="true"
href="tel:%20425%20%20780-9648" value="+14257809648"
target="_blank">(425) 780-9648</a><br>
<a moz-do-not-send="true"
href="http://www.dunescientific.com/" target="_blank">http://www.dunescientific.com/</a>
<br>
© 2015 Dune Scientific, LLC. All rights reserved. </div>
</td>
</tr>
</tbody>
</table>
</div>
<br>
<br>
</body>
</html>