[vtkusers] Actor -- isMovable?

Cory Quammen cquammen at cs.unc.edu
Mon Nov 9 07:56:02 EST 2009


Piotr,

I've replied to the list so that others may benefit from our discussion.

I understand your question as: 1). you have a data set, 2). you've
found a camera view you want to preserve, and 3). you want to apply
this view to a modified version of your molecule. This is quite easy.

If you are making the change to the molecule data in the same
application instance, as long as you make sure that the first VTK
filter in your pipeline can "see" the change (e.g., at some point one
of the filter's Modified() methods is called), calling
ren->GetRenderWindow()->Render() should invoke a series of updates
that will lead to your updated model being displayed. Basically, you
don't have to do anything but re-render. The camera view should not
change or reset.

If you want to save the camera view across program instances, you can
get the camera matrix similar to how you would do it in the vtkActor.
But I find it easier to do as follows:

vtkCamera* cam = renderer->GetActiveCamera();
double* position = cam->GetPosition();
double* focalPoint = cam->GetFocalPoint();
double* upVector = cam->GetViewUp();

// Save position, focalPoint, upVector, all of which are 3-element
double arrays, to a file or data structure

To set the camera up again, just use

cam->SetPosition(position);
cam->SetFocalPoint(focalPoint);
cam->SetViewUp(upVector);

Hope that helps,
Cory

On Mon, Nov 9, 2009 at 4:05 AM, Piotr Byzia <piotr.byzia at gmail.com> wrote:
> Hi Cory,
>
> These are incredibly helpful insights, thank you so much.
>
> I must re-thing this interactor style issue.
>
> ren->GetRenderWindow()->Render() turned out to be what I needed :)
>
> And one follow-up question to the transformation matrix: let's say I have
> rotated the camera on the scene with my molecule (so the initial view has
> changed using vtkInteractorStyleTrackballCamera), followed by a changes in
> some of the molecules data set (a few coordinates changes resulting in a new
> coordinates for some lines). What should be a course of action here if I
> want to preserve the view (same angle, distance etc. of the camera) and
> update the molecule actor? Similar to what you described below, except that
> after redrawing a whole structure I must apply a transformation matrix to
> the *camera* to update the view accordingly?
> In other words, what is equivalent for the vtkActor->GetMatrix() and how
> should I update the camera view after reloading the molecule.
> I guess this is going to be suboptimal (reloading the whole structure again
> and setting the camera again). Any suggestions on improvements are more than
> welcome ;-)
>
> I apologize if I'm not using the proper VTK's vocabulary here.
>
> Best wishes,
> Piotr Byzia
>
>
>
>
> On 05.11.2009, at 16:18, Cory Quammen wrote:
>
>> On Thu, Nov 5, 2009 at 8:46 AM, Piotr Byzia <piotr.byzia at gmail.com> wrote:
>>>
>>> Thank you Cory,
>>>
>>> This explains everything :-)
>>>
>>> And it'd be a perfect solution if there were some kind of offset when
>>> picking an object to act on.
>>>
>>> I couldn't find anything helpful on
>>>
>>> http://www.vtk.org/doc/release/4.0/html/classvtkInteractorStyleTrackballActor.html
>>> but maybe it's some different class I should be looking in?
>>>
>>> In my case, actors are molecules in lines representation (sample
>>> http://media.piotr.byzia.pl/molecule_lines.PNG) and it's hard to target a
>>> single line to rotate / zoom it, thus vtkInteractorStyleTrackballCamera
>>> was
>>> ideal: I could rotate a molecule wherever I pressed a mouse button.
>>>
>>> However, imagine 2 molecules in the same window, now, I want to be able
>>> to
>>> pick only one of them and rotate etc. so I can't use a TrackballCamera
>>> mode,
>>> and TrackballActor is a pain with those lines...
>>
>> Yes, I can see how that would be a pain. I'm not sure how you can do
>> this with mouse interaction without changing the representation of the
>> molecule to something thicker than lines. An alternative might be to
>> provide transformation controls in your GUI, but that is a bit more
>> cumbersome for the user. You can manually change the orientation of
>> the actor with vtkActor->RotateX(), ->RotateY(), ->RotateZ(), for
>> instance.
>>
>>> If you still have a patience, my additional questions are, how can I
>>> retrieve a coordinates (the same code as previously pasted in this
>>> message)
>>> of all points used to draw a lines, after rotating my molecule?
>>
>> If you are just moving the camera, then the point positions will not
>> change. If you are moving the actor, the points in your molecule data
>> will also not change: all that changes is that the actor tells the GPU
>> to apply a matrix describing the position/orientation/size of the
>> geometry before drawing it. To get the points as they appear to be
>> positioned in the screen, you can apply that same matrix that the
>> actor uses to your data set. Do this by getting the transformation
>> matrix with vtkActor->GetMatrix() and set that up in a
>> vtkTransformFilter like this (forgive me if this isn't absolutely
>> correct Python):
>>
>> transform = vtkMatrixToLinearTransform()
>> transform.SetMatrix(actor->GetMatrix())
>> transformFilter = vtkTransformFilter()
>> transformFilter.SetTransform(transform)
>> transformFilter.SetInput(moleculeGeometry)
>> transformFilter.Update()
>>
>> rotatedMolecule = transformFilter.GetOutput()
>> rotatedMolecule.Update() # might not be necessary
>>
>> for i in xrange(rotatedMolecule.GetNumberOfPoints()):
>>  pt = rotatedMolecule.GetPoint(i)
>>  # Do something with point
>>
>> This assumes you have the molecule line geometry stored in a
>> vtkPolyData. The transform filter applies the same transformation
>> matrix that was applied to the actor that you manipulated. I hope that
>> I didn't make this too confusing. I am doing this very thing in an
>> application, so I know that it works.
>>
>>> And the last one, as I mentioned earlier, I was able to set actor
>>> VisibilityOff() property from my GUI, but the change is made only after I
>>> move mouse over the rendering window. How can I update window right after
>>> the property has been set?
>>> I tried
>>> my_actor.GetMapper().GetInput().Update()
>>> ren.Render()
>>> ren.Render().Update()
>>>
>>> ren is QVTKWindowInteractor instance. I guess this is the source of my
>>> problem, while there are only a few methods overloaded.
>>
>> Try ren->GetRenderWindow()->Render()
>>
>> Cory
>>
>>>
>>> I'd appreciate any pointers, which method I should add there so that
>>> updating will work.
>>>
>>> Thank you,
>>> Piotr Byzia
>>>
>>>
>>>
>>> On 05.11.2009, at 13:52, Cory Quammen wrote:
>>>
>>>> Piotr,
>>>>
>>>> The interactor style you have let's you switch between two modes. In
>>>> one mode, you are moving the camera. Mouse motions in the window will
>>>> affect the camera, but it will not change the actors position or
>>>> orientation in world space. Sure, they appear to move on the screen,
>>>> but what you see really comes from the camera moving. In this mode,
>>>> calling PickableOff() won't have any effect because you aren't picking
>>>> any actors.
>>>>
>>>> The other mode, however, lets you pick individual actors and change
>>>> their position, orientation, and scale in world space. For this mode,
>>>> you *can* pick actors and change these properties. Calling
>>>> PickableOff() will have an effect here; it will prevent you from
>>>> picking and subsequently modifying the actor position, orientation,
>>>> and scale.
>>>>
>>>> In your code, the first mode is what you have.  To see what the second
>>>> mode is like, you might try
>>>>
>>>>
>>>>
>>>> widget_3d.GetRenderWindow().GetInteractor().GetInteractorStyle().SetCurrentStyleToTrackballActor()
>>>>
>>>> This mode will let you manipulate individual actors, unless of course
>>>> you set them to PickableOff(). This seems to me close to what are you
>>>> going for.
>>>>
>>>> I hope that helps,
>>>> Cory
>>>>
>>>> On Thu, Nov 5, 2009 at 5:48 AM, Piotr Byzia <piotr.byzia at gmail.com>
>>>> wrote:
>>>>>
>>>>> Hi Karthik,
>>>>> I disabled the interactor style, however I still can rotate my actor
>>>>> (by
>>>>> the
>>>>> mouse interaction).
>>>>> This's what I've done:
>>>>>
>>>>>
>>>>> widget_3d.GetRenderWindow().GetInteractor().GetInteractorStyle().EnabledOff()
>>>>> my_actor.PickableOff()
>>>>> widget_3d is an instance of
>>>>> QVTKRenderWindowInteractor.QVTKRenderWindowInteractor(self)
>>>>> Below is an output
>>>>> for widget_3d.GetRenderWindow().GetInteractor().GetInteractorStyle()
>>>>> Let me know if there is any other information which might help.
>>>>> vtkInteractorStyleSwitch (0E995418)
>>>>>  Debug: Off
>>>>>  Modified Time: 945
>>>>>  Reference Count: 2
>>>>>  Registered Events: (none)
>>>>>  Current Renderer: 00000000
>>>>>  Default Renderer: 00000000
>>>>>  Enabled: 0
>>>>>  Priority: 0
>>>>>  Interactor: 0E9418D0
>>>>>  Key Press Activation: Off
>>>>>  Key Press Activation Value: i
>>>>>  Auto Adjust Camera Clipping Range On
>>>>>  Pick Color: (1, 0, 0)
>>>>>  CurrentRenderer: 00000000
>>>>>  Picked Renderer: (none)
>>>>>  Current Actor: (none)
>>>>>  Interactor: 0E9418D0
>>>>>  Prop Picked: No
>>>>>  State: 0
>>>>>  UseTimers: 0
>>>>>  HandleObservers: 1
>>>>>  MouseWheelMotionFactor: 1
>>>>>  Timer Duration: 10
>>>>>  CurrentStyle 0E9A3818
>>>>>   vtkInteractorStyleTrackballCamera
>>>>>   Debug: Off
>>>>>   Modified Time: 1703
>>>>>   Reference Count: 1
>>>>>   Registered Events:
>>>>>     Registered Observers:
>>>>>       vtkObserver (0E9912B8)
>>>>>         Event: 41
>>>>>         EventName: EndInteractionEvent
>>>>>         Command: 0E9A58E0
>>>>>         Priority: 0
>>>>>         Tag: 2
>>>>>       vtkObserver (0E9906B0)
>>>>>         Event: 39
>>>>>         EventName: StartInteractionEvent
>>>>>         Command: 0E9A58E0
>>>>>         Priority: 0
>>>>>         Tag: 1
>>>>>   Current Renderer: 00000000
>>>>>   Default Renderer: 00000000
>>>>>   Enabled: 0
>>>>>   Priority: 0
>>>>>   Interactor: 0E9418D0
>>>>>   Key Press Activation: Off
>>>>>   Key Press Activation Value: i
>>>>>   Auto Adjust Camera Clipping Range On
>>>>>   Pick Color: (1, 0, 0)
>>>>>   CurrentRenderer: 00000000
>>>>>   Picked Renderer: (none)
>>>>>   Current Actor: (none)
>>>>>   Interactor: 0E9418D0
>>>>>   Prop Picked: No
>>>>>   State: 0
>>>>>   UseTimers: 0
>>>>>   HandleObservers: 1
>>>>>   MouseWheelMotionFactor: 1
>>>>>   Timer Duration: 10
>>>>>   MotionFactor: 10
>>>>>
>>>>>
>>>>> On 04.11.2009, at 18:25, Karthik Krishnan wrote:
>>>>>
>>>>> try to disable the interactor style set on teh interactor
>>>>>
>>>>> interactor->GetInteractorStyle()->EnabledOff()
>>>>>
>>>>> On Wed, Nov 4, 2009 at 10:35 AM, Piotr Byzia <piotr.byzia at gmail.com>
>>>>> wrote:
>>>>>>
>>>>>> Cory and Karthik,
>>>>>>
>>>>>> Thank you for your suggestions.
>>>>>>
>>>>>> By moving, I meant an interaction with a mouse.
>>>>>> Indeed, I have no interaction style defined explicitly, but it seems
>>>>>> that
>>>>>> Python interface has some default one set up, because I was able to
>>>>>> run
>>>>>> this:
>>>>>>
>>>>>> lines_actor.PickableOff()
>>>>>> print lines_actor.GetPickable()
>>>>>> lines_actor.PickableOn()
>>>>>> print lines_actor.GetPickable()
>>>>>> lines_actor.SetPickable(0)
>>>>>> print lines_actor.GetPickable()
>>>>>>
>>>>>> which produced:
>>>>>> 0
>>>>>> 1
>>>>>> 0
>>>>>>
>>>>>> (I apologize if this is something obvious for you, I just started
>>>>>> experimenting with VTK)
>>>>>> So, vtkActor() has an interaction style by default, thus I was able to
>>>>>> call PickableOff() on it.
>>>>>> However it does not work, while I was able to pick and move around
>>>>>> (rotate) lines_actor with the mouse.
>>>>>>
>>>>>> I had the same issue with lines_actor.DragableOff().
>>>>>>
>>>>>> What is surprising, lines_actor.VisibilityOff() works fine!
>>>>>> (lines_actor
>>>>>> was not visible on the scene)
>>>>>>
>>>>>> Do you possibly have ideas what can interfere with the PickableOff()
>>>>>> ??
>>>>>>
>>>>>> Thanks for any suggestions,
>>>>>> Piotr Byzia
>>>>>>
>>>>>>
>>>>>> On 04.11.2009, at 14:16, Cory Quammen wrote:
>>>>>>
>>>>>>> Hi Piotr,
>>>>>>>
>>>>>>> Perhaps you could clarify what you mean by moving an actor. It
>>>>>>> doesn't
>>>>>>> sound like you have an interactor style that is manipulating the
>>>>>>> actors by picking with the mouse. If you did, however, you could call
>>>>>>> PickableOff() on the actor, which will prevent you from picking it
>>>>>>> and
>>>>>>> thereby prevent movement of the actor.
>>>>>>>
>>>>>>> How exactly are you moving the actors now?
>>>>>>>
>>>>>>> Cory
>>>>>>>
>>>>>>> On Wed, Nov 4, 2009 at 7:21 AM, Piotr Byzia <piotr.byzia at gmail.com>
>>>>>>> wrote:
>>>>>>>>
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> I want to set an actor to be movable or non-movable, depending on
>>>>>>>> settings
>>>>>>>> which I control through PyQT GUI.
>>>>>>>> In other words, having a few actors on the scene I want to set
>>>>>>>> checkboxes in
>>>>>>>> my GUI that would freeze a given actor, and the rest of them to
>>>>>>>> react
>>>>>>>> as
>>>>>>>> usual to the mouse movements / clicks.
>>>>>>>>
>>>>>>>> Regarding visibility of the actor I'm using
>>>>>>>> GetProperty().SetOpacity(0.0) on
>>>>>>>> an instance of any given actor.
>>>>>>>> I can't see anything related to movement in the GetProperty()
>>>>>>>> properties, I
>>>>>>>> believe it's somewhere else?
>>>>>>>>
>>>>>>>> Here are most important parts of the code I'm using to generate a
>>>>>>>> single
>>>>>>>> actor:
>>>>>>>>
>>>>>>>> self.ren = vtk.vtkRenderer()
>>>>>>>> self.ren.SetBackground(0, 0, 0)
>>>>>>>> self.widget_3d.GetRenderWindow().AddRenderer(self.ren)
>>>>>>>>
>>>>>>>> apd=vtk.vtkAppendPolyData()
>>>>>>>>
>>>>>>>> for i in xrange(len(coordinates)):
>>>>>>>>  line=vtk.vtkLineSource()
>>>>>>>>
>>>>>>>>  line.SetPoint1(coordinates[i][0]) # 1st atom coordinates for a
>>>>>>>> given
>>>>>>>> bond
>>>>>>>>  line.SetPoint2(coordinates[i][1]) # 2nd atom coordinates for a
>>>>>>>> given
>>>>>>>> bond
>>>>>>>>  line.SetResolution(21)
>>>>>>>>  apd.AddInput(line.GetOutput())
>>>>>>>>
>>>>>>>> mapper = vtk.vtkPolyDataMapper()
>>>>>>>> mapper.SetInput(apd.GetOutput())
>>>>>>>> lines_actor = vtk.vtkActor()
>>>>>>>> lines_actor.SetMapper(mapper)
>>>>>>>> lines_actor.GetProperty().SetColor(0.7, 0.0, 0.0)
>>>>>>>> lines_actor.GetProperty().SetOpacity(1.0)
>>>>>>>>
>>>>>>>> self.ren.AddActor(lines_actor)
>>>>>>>>
>>>>>>>>
>>>>>>>> I found SetCurrentStyleToTrackballActor(), but I want to control
>>>>>>>> this
>>>>>>>> behavior from my GUI.
>>>>>>>> Besides, trackball mode is very inconvenient in my case, with
>>>>>>>> molecules
>>>>>>>> in
>>>>>>>> "lines" representation (it's hard to pick a single line).
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>> Piotr Byzia
>>>>>>>> _______________________________________________
>>>>>>>> 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
>>>>>>>>
>>>>>>>> Follow this link to subscribe/unsubscribe:
>>>>>>>> http://www.vtk.org/mailman/listinfo/vtkusers
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> Cory Quammen
>>>>>>> Center for Computer Integrated Systems for Microscopy and
>>>>>>> Manipulation
>>>>>>> (CISMM)
>>>>>>> Department of Computer Science
>>>>>>> University of North Carolina at Chapel Hill
>>>>>>> http://www.cs.unc.edu/~cquammen
>>>>>>
>>>>>> _______________________________________________
>>>>>> 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
>>>>>>
>>>>>> Follow this link to subscribe/unsubscribe:
>>>>>> http://www.vtk.org/mailman/listinfo/vtkusers
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Cory Quammen
>>>> Center for Computer Integrated Systems for Microscopy and Manipulation
>>>> (CISMM)
>>>> Department of Computer Science
>>>> University of North Carolina at Chapel Hill
>>>> http://www.cs.unc.edu/~cquammen
>>>
>>>
>>
>>
>>
>> --
>> Cory Quammen
>> Center for Computer Integrated Systems for Microscopy and Manipulation
>> (CISMM)
>> Department of Computer Science
>> University of North Carolina at Chapel Hill
>> http://www.cs.unc.edu/~cquammen
>
>



-- 
Cory Quammen
Center for Computer Integrated Systems for Microscopy and Manipulation (CISMM)
Department of Computer Science
University of North Carolina at Chapel Hill
http://www.cs.unc.edu/~cquammen



More information about the vtkusers mailing list