[vtkusers] How to add vtkRenderWindowInteractor to a native Cocoa window
Elvis Dowson
elvis.dowson at mac.com
Thu Oct 23 14:06:50 EDT 2008
Hi Clint,
I just took a quick look at the QVTKInteractor
class (currently defined inside the QVTKWidget source files).
Here are some initial thoughts.
QVTKInteractor Specifications
The new QVTKInteractor class should work with a QGraphicsView. One
should be able to perform off-screen rendering using VTK in off-screen
mode and render VTK images in a QGraphicsScene contained in a
QGraphicsView. The QGraphicsScene will take care of rendering
QTWidgets on top of the VTK generated OpenGL images. The
QVTKInteractor class shall be derived from vtkRenderWindowInteractor,
and be able to process mouse movements from the QGraphicsView.
QVTKInteractor Design
QVTKInteractor::SetGraphicsView(QGraphicsView* ) method
In terms of design, the QVTKInteractor should be able to attach itself
to a QGraphicsView via a SetGraphicsView(QGraphicsView* ) method.
I am not going to implement the vtkSetRenderWindow(vtkRenderWindow* )
method since we don't have a vtkRenderWindow here when using a
framebuffer object, plus it is the wrong place to attach an
interactor, since all the interaction is going to take place in the
view and not the vtkRenderWindow.
Signals & Slots
Implement signals within the view (a QGrahicsView subclass), so that a
signal will be emitted whenever a mouse event occurs. See: Qt 4.4.3:
Signals and Slots
Q_SIGNALS:
// Description:
// This signal will be emitted whenever a mouse event occurs
// within the QVTK window
void mouseEvent(QMouseEvent* event);
Implement a slot in QVTKInteractor to handle mouse events. This will
need to internally interface with VTK.
public Q_SLOTS:
// Description:
// This slot will be automatically invoked whenever a mouse event
occurs
void mouseEvent();
Question 01: I was wondering if I should internally pass these
commands to the off screen vtkRenderWindow instance? Suppose at some
point, I do get rid of the un-necessary vtkRenderWindow, when
performing off-screen rendering, can I still pass interactor events to
VTK to interact with the VTK scene, in off-screen mode?
Summary
In terms of usage, one would need to subclass from QGraphicsView and
emit a signal on mouse move.
The QVTKInteractor associated with the QGraphicsView will process the
mouse movements using its slot, and send these commands to the off-
screen vtk OpenGL rendering context.
It seems a pretty straightforward design. It has the advantage of
being loosely coupled and strongly typed at the same time, using the
Qt signals and slots mechanism.
I was wondering if this approach seems okay to you, and if I can
proceed ahead with realizing a preliminary prototype?
Do also let me know if I have missed somethings here.
Admittedly, I am trying to keep the initial functionality to a minimum
and not considering QVTKWidget compatibility in the first go. Once I
have completed the integration with a QGraphicsView, then same parts
can be adapted for QVTKWidget, and expose this class in a separate
QVTKInteractor.h and QVTKInteractor.cpp file.
Best regards,
Elvis Dowson
On Oct 22, 2008, at 8:19 PM, clinton at elemtech.com wrote:
>
> I'm guessing you should be able to set up an interactor like you
> normally
> would. The only missing piece is taking mouse events from the
> QGraphicsView
> and passing them off to the interactor. You can look at
> QVTKWidget.cxx for
> how to pass them off to the interactor. Getting mouse events from the
> QGraphicsView is another part of the issue.
>
> If you'd like to experiment, you can try modifying the
> QVTKInteractor to do
> event filtering on the QVTKWidget and pass events to the
> interactor. That
> would mean moving all the handing of mouse and key events from
> QVTKWidget
> into QVTKInteractor. Then you might be able to use that new
> QVTKInteractor
> with the QGraphicsView. If it works well, then this is something
> that can go
> into VTK.
>
> Clint
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20081023/ece4e145/attachment.htm>
More information about the vtkusers
mailing list