diff --git a/Modules/OpenViewCore/files.cmake b/Modules/OpenViewCore/files.cmake index 7b623f32e3..41db844fff 100644 --- a/Modules/OpenViewCore/files.cmake +++ b/Modules/OpenViewCore/files.cmake @@ -1,22 +1,21 @@ file(GLOB_RECURSE H_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/include/*") set(CPP_FILES - vtkEventQtSlotConnect.cxx vtkQtConnection.cxx - QVTKInteractorAdapter.cxx + QVTKMitkInteractorAdapter.cxx QVTKQuickItem.cxx QVTKFramebufferObjectRenderer.cxx QVTKInternalOpenglRenderWindow.cxx ) set(MOC_H_FILES - include/QVTKInteractorAdapter.h + include/QVTKMitkInteractorAdapter.h include/QVTKQuickItem.h include/vtkQtConnection.h ) set(UI_FILES ) set(QRC_FILES ) diff --git a/Modules/OpenViewCore/include/QVTKInteractorAdapter.h b/Modules/OpenViewCore/include/QVTKMitkInteractorAdapter.h similarity index 84% rename from Modules/OpenViewCore/include/QVTKInteractorAdapter.h rename to Modules/OpenViewCore/include/QVTKMitkInteractorAdapter.h index 20df083439..2719bb5c91 100644 --- a/Modules/OpenViewCore/include/QVTKInteractorAdapter.h +++ b/Modules/OpenViewCore/include/QVTKMitkInteractorAdapter.h @@ -1,86 +1,86 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ // original copyright below /*========================================================================= Program: Visualization Toolkit - Module: QVTKInteractorAdapter.h + Module: QVTKMitkInteractorAdapter.h Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen All rights reserved. See Copyright.txt or http://www.kitware.com/Copyright.htm for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notice for more information. =========================================================================*/ /*========================================================================= Copyright 2004 Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive license for use of this work by or on behalf of the U.S. Government. Redistribution and use in source and binary forms, with or without modification, are permitted provided that this Notice and any statement of authorship are reproduced on all copies. =========================================================================*/ /*======================================================================== For general information about using VTK and Qt, see: http://www.trolltech.com/products/3rdparty/vtksupport.html =========================================================================*/ -// .NAME QVTKInteractorAdapter - Handle Qt events. +// .NAME QVTKMitkInteractorAdapter - Handle Qt events. // .SECTION Description // QVTKInteractor handles relaying Qt events to VTK. -#ifndef Q_VTK_INTERACTOR_ADAPTER_H -#define Q_VTK_INTERACTOR_ADAPTER_H +#ifndef Q_VTK_MITK_INTERACTOR_ADAPTER_H +#define Q_VTK_MITK_INTERACTOR_ADAPTER_H #include #include class vtkRenderWindowInteractor; class QEvent; -// .NAME QVTKInteractorAdapter - A QEvent translator. +// .NAME QVTKMitkInteractorAdapter - A QEvent translator. // .SECTION Description -// QVTKInteractorAdapter translates QEvents and send them to a +// QVTKMitkInteractorAdapter translates QEvents and send them to a // vtkRenderWindowInteractor. -class MITKOPENVIEWCORE_EXPORT QVTKInteractorAdapter : public QObject +class MITKOPENVIEWCORE_EXPORT QVTKMitkInteractorAdapter : public QObject { Q_OBJECT public: // Description: // Constructor: takes QObject parent - QVTKInteractorAdapter(QObject* parent); + QVTKMitkInteractorAdapter(QObject* parent); // Description: // Destructor - ~QVTKInteractorAdapter(); + ~QVTKMitkInteractorAdapter(); // Description: // Process a QEvent and send it to the interactor // returns whether the event was recognized and processed bool ProcessEvent(QEvent* e, vtkRenderWindowInteractor* iren); }; #endif diff --git a/Modules/OpenViewCore/include/QVTKQuickItem.h b/Modules/OpenViewCore/include/QVTKQuickItem.h index 7f5bb8004a..8d987b0099 100644 --- a/Modules/OpenViewCore/include/QVTKQuickItem.h +++ b/Modules/OpenViewCore/include/QVTKQuickItem.h @@ -1,116 +1,116 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ // original copyright below /*======================================================================== OpenView -- http://openview.kitware.com Copyright 2012 Kitware, Inc. Licensed under the BSD license. See LICENSE file for details. ========================================================================*/ #ifndef __QVTKQuickItem_h #define __QVTKQuickItem_h #include #include #include "vtkSmartPointer.h" #include "vtkNew.h" #include #include class QOpenGLContext; class QOpenGLFramebufferObject; -class QVTKInteractorAdapter; +class QVTKMitkInteractorAdapter; class QVTKInteractor; class QVTKFramebufferObjectRenderer; class vtkEventQtSlotConnect; class vtkOpenGLRenderWindow; class vtkObject; class vtkContextView; class MITKOPENVIEWCORE_EXPORT QVTKQuickItem : public QQuickFramebufferObject { Q_OBJECT public: QVTKQuickItem(QQuickItem* parent = 0); // Description: // destructor ~QVTKQuickItem(); Renderer *createRenderer() const; // Description: // get the render window used with this item vtkOpenGLRenderWindow* GetRenderWindow() const; // Description: // get the render window interactor used with this item // this item enforces its own interactor QVTKInteractor* GetInteractor() const; QMutex m_viewLock; protected slots: // slot called when vtk wants to know if the context is current virtual void IsCurrent(vtkObject* caller, unsigned long vtk_event, void* client_data, void* call_data); // slot called when vtk wants to know if a window is direct virtual void IsDirect(vtkObject* caller, unsigned long vtk_event, void* client_data, void* call_data); // slot called when vtk wants to know if a window supports OpenGL virtual void SupportsOpenGL(vtkObject* caller, unsigned long vtk_event, void* client_data, void* call_data); void onTextureFollowsItemSizeChanged(bool follows); protected: // Called ONCE from the render thread before the FBO is first created and while the GUI thread is blocked virtual void init(); // Called from the render thread BEFORE each update while the GUI thread blocked virtual bool prepareForRender(); // Called from the render thread AFTER each update while the GUI thread is NOT blocked virtual void cleanupAfterRender(); // handle item key events virtual void keyPressEvent(QKeyEvent* e); virtual void keyReleaseEvent(QKeyEvent* e); // handle item mouse events virtual void mousePressEvent(QMouseEvent* e); virtual void mouseReleaseEvent(QMouseEvent* e); virtual void mouseDoubleClickEvent(QMouseEvent* e); virtual void mouseMoveEvent(QMouseEvent* e); virtual void geometryChanged(const QRectF & newGeometry, const QRectF & oldGeometry); virtual void wheelEvent(QWheelEvent* e); virtual void hoverEnterEvent(QHoverEvent* e); virtual void hoverLeaveEvent(QHoverEvent* e); virtual void hoverMoveEvent(QHoverEvent* e); QSGNode* updatePaintNode(QSGNode *node, QQuickItem::UpdatePaintNodeData *nodeData); private: vtkOpenGLRenderWindow *m_win; vtkSmartPointer m_interactor; - QVTKInteractorAdapter* m_interactorAdapter; + QVTKMitkInteractorAdapter* m_interactorAdapter; vtkSmartPointer m_connect; friend class QVTKFramebufferObjectRenderer; }; #endif diff --git a/Modules/OpenViewCore/include/vtkEventQtSlotConnect.h b/Modules/OpenViewCore/include/vtkEventQtSlotConnect.h deleted file mode 100644 index 9224ea364e..0000000000 --- a/Modules/OpenViewCore/include/vtkEventQtSlotConnect.h +++ /dev/null @@ -1,119 +0,0 @@ -/*=================================================================== - -The Medical Imaging Interaction Toolkit (MITK) - -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. -All rights reserved. - -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. - -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ - -// original copyright below - -/*========================================================================= - - Copyright 2004 Sandia Corporation. - Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive - license for use of this work by or on behalf of the - U.S. Government. Redistribution and use in source and binary forms, with - or without modification, are permitted provided that this Notice and any - statement of authorship are reproduced on all copies. - -=========================================================================*/ - -/*======================================================================== - For general information about using VTK and Qt, see: - http://www.trolltech.com/products/3rdparty/vtksupport.html -=========================================================================*/ - -/*======================================================================== - !!! WARNING for those who want to contribute code to this file. - !!! If you use a commercial edition of Qt, you can modify this code. - !!! If you use an open source version of Qt, you are free to modify - !!! and use this code within the guidelines of the GPL license. - !!! Unfortunately, you cannot contribute the changes back into this - !!! file. Doing so creates a conflict between the GPL and BSD-like VTK - !!! license. -=========================================================================*/ - -// .NAME vtkEventQtSlotConnect - Manage connections between VTK events and Qt slots. -// .SECTION Description -// vtkEventQtSlotConnect provides a way to manage connections between VTK events -// and Qt slots. -// Qt slots to connect with must have one of the following signatures: -// - MySlot() -// - MySlot(vtkObject* caller) -// - MySlot(vtkObject* caller, unsigned long vtk_event) -// - MySlot(vtkObject* caller, unsigned long vtk_event, void* client_data) -// - MySlot(vtkObject* caller, unsigned long vtk_event, void* client_data, void* call_data) -// - MySlot(vtkObject* caller, unsigned long vtk_event, void* client_data, void* call_data, vtkCommand*) - - -#ifndef VTK_EVENT_QT_SLOT_CONNECT -#define VTK_EVENT_QT_SLOT_CONNECT - -#include "vtkObject.h" -#include "vtkCommand.h" // for event defines -#include // for version info - -#include - -class QObject; -class vtkQtConnections; -class vtkQtConnection; - -// manage connections between VTK object events and Qt slots -class MITKOPENVIEWCORE_EXPORT vtkEventQtSlotConnect : public vtkObject -{ - public: - static vtkEventQtSlotConnect* New(); - vtkTypeMacro(vtkEventQtSlotConnect, vtkObject) - - // Description: - // Print the current connections between VTK and Qt - void PrintSelf(ostream& os, vtkIndent indent); - - // Description: - // Connect a vtk object's event with a Qt object's slot. Multiple - // connections which are identical are treated as separate connections. - virtual void Connect(vtkObject* vtk_obj, unsigned long event, - const QObject* qt_obj, const char* slot, - void* client_data=NULL, float priority=0.0 - ,Qt::ConnectionType type = Qt::AutoConnection); - - // Description: - // Disconnect a vtk object from a qt object. - // Passing no arguments will disconnect all slots maintained by this object. - // Passing in only a vtk object will disconnect all slots from it. - // Passing only a vtk object and event, will disconnect all slots matching - // the vtk object and event. - // Passing all information in will match all information. - virtual void Disconnect( - vtkObject* vtk_obj=NULL, unsigned long event=vtkCommand::NoEvent, - const QObject* qt_obj=NULL, const char* slot = 0, void* client_data=NULL); - - // Description: - // Allow to query vtkEventQtSlotConnect to know if some Connect() have been - // setup and how many. - virtual int GetNumberOfConnections() const; - - protected: - vtkQtConnections* Connections; - friend class vtkQtConnection; - void RemoveConnection(vtkQtConnection*); - - vtkEventQtSlotConnect(); - ~vtkEventQtSlotConnect(); - - private: - // unimplemented - vtkEventQtSlotConnect(const vtkEventQtSlotConnect&); - void operator=(const vtkEventQtSlotConnect&); -}; -#endif diff --git a/Modules/OpenViewCore/src/QVTKInteractorAdapter.cxx b/Modules/OpenViewCore/src/QVTKMitkInteractorAdapter.cxx similarity index 97% rename from Modules/OpenViewCore/src/QVTKInteractorAdapter.cxx rename to Modules/OpenViewCore/src/QVTKMitkInteractorAdapter.cxx index afd8fe677c..fbe63ade53 100644 --- a/Modules/OpenViewCore/src/QVTKInteractorAdapter.cxx +++ b/Modules/OpenViewCore/src/QVTKMitkInteractorAdapter.cxx @@ -1,473 +1,473 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ // original copyright below /*========================================================================= Program: Visualization Toolkit - Module: QVTKInteractorAdapter.cxx + Module: QVTKMitkInteractorAdapter.cxx Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen All rights reserved. See Copyright.txt or http://www.kitware.com/Copyright.htm for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notice for more information. =========================================================================*/ /* * Copyright 2004 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the * U.S. Government. Redistribution and use in source and binary forms, with * or without modification, are permitted provided that this Notice and any * statement of authorship are reproduced on all copies. */ /*======================================================================== For general information about using VTK and Qt, see: http://www.trolltech.com/products/3rdparty/vtksupport.html =========================================================================*/ #ifdef _MSC_VER // Disable warnings that Qt headers give. #pragma warning(disable:4127) #pragma warning(disable:4512) #endif -#include "QVTKInteractorAdapter.h" +#include "QVTKMitkInteractorAdapter.h" #include "QVTKInteractor.h" #include #include #include #include #include "vtkCommand.h" // function to get VTK keysyms from ascii characters static const char* ascii_to_key_sym(int); // function to get VTK keysyms from Qt keys static const char* qt_key_to_key_sym(Qt::Key, Qt::KeyboardModifiers modifiers); -QVTKInteractorAdapter::QVTKInteractorAdapter(QObject* parentObject) +QVTKMitkInteractorAdapter::QVTKMitkInteractorAdapter(QObject* parentObject) : QObject(parentObject) { } -QVTKInteractorAdapter::~QVTKInteractorAdapter() +QVTKMitkInteractorAdapter::~QVTKMitkInteractorAdapter() { } -bool QVTKInteractorAdapter::ProcessEvent(QEvent* e, vtkRenderWindowInteractor* iren) +bool QVTKMitkInteractorAdapter::ProcessEvent(QEvent* e, vtkRenderWindowInteractor* iren) { if(iren == NULL || e == NULL) return false; const QEvent::Type t = e->type(); if(t == QEvent::Resize) { QResizeEvent* e2 = static_cast(e); QSize size = e2->size(); iren->SetSize(size.width(), size.height()); return true; } if(t == QEvent::FocusIn) { // For 3DConnexion devices: QVTKInteractor* qiren = QVTKInteractor::SafeDownCast(iren); if(qiren) { qiren->StartListening(); } return true; } if(t == QEvent::FocusOut) { // For 3DConnexion devices: QVTKInteractor* qiren = QVTKInteractor::SafeDownCast(iren); if(qiren) { qiren->StopListening(); } return true; } // the following events only happen if the interactor is enabled if(!iren->GetEnabled()) return false; if(t == QEvent::MouseButtonPress || t == QEvent::MouseButtonRelease || t == QEvent::MouseButtonDblClick || t == QEvent::MouseMove) { QMouseEvent* e2 = static_cast(e); // give interactor the event information iren->SetEventInformationFlipY(e2->x(), e2->y(), (e2->modifiers() & Qt::ControlModifier) > 0 ? 1 : 0, (e2->modifiers() & Qt::ShiftModifier ) > 0 ? 1 : 0, 0, e2->type() == QEvent::MouseButtonDblClick ? 1 : 0); if(t == QEvent::MouseMove) { iren->InvokeEvent(vtkCommand::MouseMoveEvent, e2); } else if(t == QEvent::MouseButtonPress || t == QEvent::MouseButtonDblClick) { switch(e2->button()) { case Qt::LeftButton: iren->InvokeEvent(vtkCommand::LeftButtonPressEvent, e2); break; case Qt::MidButton: iren->InvokeEvent(vtkCommand::MiddleButtonPressEvent, e2); break; case Qt::RightButton: iren->InvokeEvent(vtkCommand::RightButtonPressEvent, e2); break; default: break; } } else if(t == QEvent::MouseButtonRelease) { switch(e2->button()) { case Qt::LeftButton: iren->InvokeEvent(vtkCommand::LeftButtonReleaseEvent, e2); break; case Qt::MidButton: iren->InvokeEvent(vtkCommand::MiddleButtonReleaseEvent, e2); break; case Qt::RightButton: iren->InvokeEvent(vtkCommand::RightButtonReleaseEvent, e2); break; default: break; } } return true; } if(t == QEvent::Enter) { iren->InvokeEvent(vtkCommand::EnterEvent, e); return true; } if(t == QEvent::Leave) { iren->InvokeEvent(vtkCommand::LeaveEvent, e); return true; } if(t == QEvent::KeyPress || t == QEvent::KeyRelease) { QKeyEvent* e2 = static_cast(e); // get key and keysym information int ascii_key = e2->text().length() ? e2->text().unicode()->toLatin1() : 0; const char* keysym = ascii_to_key_sym(ascii_key); if(!keysym || e2->modifiers() == Qt::KeypadModifier) { // get virtual keys keysym = qt_key_to_key_sym(static_cast(e2->key()), e2->modifiers()); } if(!keysym) { keysym = "None"; } // give interactor event information iren->SetKeyEventInformation( (e2->modifiers() & Qt::ControlModifier), (e2->modifiers() & Qt::ShiftModifier), ascii_key, e2->count(), keysym); if(t == QEvent::KeyPress) { // invoke vtk event iren->InvokeEvent(vtkCommand::KeyPressEvent, e2); // invoke char event only for ascii characters if(ascii_key) { iren->InvokeEvent(vtkCommand::CharEvent, e2); } } else { iren->InvokeEvent(vtkCommand::KeyReleaseEvent, e2); } return true; } if(t == QEvent::Wheel) { QWheelEvent* e2 = static_cast(e); iren->SetEventInformationFlipY(e2->x(), e2->y(), (e2->modifiers() & Qt::ControlModifier) > 0 ? 1 : 0, (e2->modifiers() & Qt::ShiftModifier ) > 0 ? 1 : 0); // invoke vtk event // if delta is positive, it is a forward wheel event if(e2->delta() > 0) { iren->InvokeEvent(vtkCommand::MouseWheelForwardEvent, e2); } else { iren->InvokeEvent(vtkCommand::MouseWheelBackwardEvent, e2); } return true; } if(t == QEvent::ContextMenu) { QContextMenuEvent* e2 = static_cast(e); // give interactor the event information iren->SetEventInformationFlipY(e2->x(), e2->y(), (e2->modifiers() & Qt::ControlModifier) > 0 ? 1 : 0, (e2->modifiers() & Qt::ShiftModifier ) > 0 ? 1 : 0); // invoke event and pass qt event for additional data as well iren->InvokeEvent(QVTKInteractor::ContextMenuEvent, e2); return true; } if(t == QEvent::DragEnter) { QDragEnterEvent* e2 = static_cast(e); // invoke event and pass qt event for additional data as well iren->InvokeEvent(QVTKInteractor::DragEnterEvent, e2); return true; } if(t == QEvent::DragLeave) { QDragLeaveEvent* e2 = static_cast(e); // invoke event and pass qt event for additional data as well iren->InvokeEvent(QVTKInteractor::DragLeaveEvent, e2); return true; } if(t == QEvent::DragMove) { QDragMoveEvent* e2 = static_cast(e); // give interactor the event information iren->SetEventInformationFlipY(e2->pos().x(), e2->pos().y()); // invoke event and pass qt event for additional data as well iren->InvokeEvent(QVTKInteractor::DragMoveEvent, e2); return true; } if(t == QEvent::Drop) { QDropEvent* e2 = static_cast(e); // give interactor the event information iren->SetEventInformationFlipY(e2->pos().x(), e2->pos().y()); // invoke event and pass qt event for additional data as well iren->InvokeEvent(QVTKInteractor::DropEvent, e2); return true; } return false; } // ***** keysym stuff below ***** static const char *AsciiToKeySymTable[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, "Tab", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "space", "exclam", "quotedbl", "numbersign", "dollar", "percent", "ampersand", "quoteright", "parenleft", "parenright", "asterisk", "plus", "comma", "minus", "period", "slash", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "colon", "semicolon", "less", "equal", "greater", "question", "at", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "bracketleft", "backslash", "bracketright", "asciicircum", "underscore", "quoteleft", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "braceleft", "bar", "braceright", "asciitilde", "Delete", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; const char* ascii_to_key_sym(int i) { if(i >= 0) { return AsciiToKeySymTable[i]; } return 0; } #define QVTK_HANDLE(x,y) \ case x : \ ret = y; \ break; #define QVTK_HANDLE_KEYPAD(x, y, z) \ case x : \ ret = (modifiers & Qt::KeypadModifier) ? (y) : (z); \ break; const char* qt_key_to_key_sym(Qt::Key i, Qt::KeyboardModifiers modifiers) { const char* ret = 0; switch(i) { // Cancel QVTK_HANDLE(Qt::Key_Backspace, "BackSpace") QVTK_HANDLE(Qt::Key_Tab, "Tab") QVTK_HANDLE(Qt::Key_Backtab, "Tab") QVTK_HANDLE(Qt::Key_Clear, "Clear") QVTK_HANDLE(Qt::Key_Return, "Return") QVTK_HANDLE(Qt::Key_Enter, "Return") QVTK_HANDLE(Qt::Key_Shift, "Shift_L") QVTK_HANDLE(Qt::Key_Control, "Control_L") QVTK_HANDLE(Qt::Key_Alt, "Alt_L") QVTK_HANDLE(Qt::Key_Pause, "Pause") QVTK_HANDLE(Qt::Key_CapsLock, "Caps_Lock") QVTK_HANDLE(Qt::Key_Escape, "Escape") QVTK_HANDLE(Qt::Key_Space, "space") QVTK_HANDLE(Qt::Key_PageUp, "Prior") QVTK_HANDLE(Qt::Key_PageDown, "Next") QVTK_HANDLE(Qt::Key_End, "End") QVTK_HANDLE(Qt::Key_Home, "Home") QVTK_HANDLE(Qt::Key_Left, "Left") QVTK_HANDLE(Qt::Key_Up, "Up") QVTK_HANDLE(Qt::Key_Right, "Right") QVTK_HANDLE(Qt::Key_Down, "Down") QVTK_HANDLE(Qt::Key_Select, "Select") QVTK_HANDLE(Qt::Key_Execute, "Execute") QVTK_HANDLE(Qt::Key_SysReq, "Snapshot") QVTK_HANDLE(Qt::Key_Insert, "Insert") QVTK_HANDLE(Qt::Key_Delete, "Delete") QVTK_HANDLE(Qt::Key_Help, "Help") QVTK_HANDLE_KEYPAD(Qt::Key_0, "KP_0", "0") QVTK_HANDLE_KEYPAD(Qt::Key_1, "KP_1", "1") QVTK_HANDLE_KEYPAD(Qt::Key_2, "KP_2", "2") QVTK_HANDLE_KEYPAD(Qt::Key_3, "KP_3", "3") QVTK_HANDLE_KEYPAD(Qt::Key_4, "KP_4", "4") QVTK_HANDLE_KEYPAD(Qt::Key_5, "KP_5", "5") QVTK_HANDLE_KEYPAD(Qt::Key_6, "KP_6", "6") QVTK_HANDLE_KEYPAD(Qt::Key_7, "KP_7", "7") QVTK_HANDLE_KEYPAD(Qt::Key_8, "KP_8", "8") QVTK_HANDLE_KEYPAD(Qt::Key_9, "KP_9", "9") QVTK_HANDLE(Qt::Key_A, "a") QVTK_HANDLE(Qt::Key_B, "b") QVTK_HANDLE(Qt::Key_C, "c") QVTK_HANDLE(Qt::Key_D, "d") QVTK_HANDLE(Qt::Key_E, "e") QVTK_HANDLE(Qt::Key_F, "f") QVTK_HANDLE(Qt::Key_G, "g") QVTK_HANDLE(Qt::Key_H, "h") QVTK_HANDLE(Qt::Key_I, "i") QVTK_HANDLE(Qt::Key_J, "h") QVTK_HANDLE(Qt::Key_K, "k") QVTK_HANDLE(Qt::Key_L, "l") QVTK_HANDLE(Qt::Key_M, "m") QVTK_HANDLE(Qt::Key_N, "n") QVTK_HANDLE(Qt::Key_O, "o") QVTK_HANDLE(Qt::Key_P, "p") QVTK_HANDLE(Qt::Key_Q, "q") QVTK_HANDLE(Qt::Key_R, "r") QVTK_HANDLE(Qt::Key_S, "s") QVTK_HANDLE(Qt::Key_T, "t") QVTK_HANDLE(Qt::Key_U, "u") QVTK_HANDLE(Qt::Key_V, "v") QVTK_HANDLE(Qt::Key_W, "w") QVTK_HANDLE(Qt::Key_X, "x") QVTK_HANDLE(Qt::Key_Y, "y") QVTK_HANDLE(Qt::Key_Z, "z") QVTK_HANDLE(Qt::Key_Asterisk, "asterisk") QVTK_HANDLE(Qt::Key_Plus, "plus") QVTK_HANDLE(Qt::Key_Bar, "bar") QVTK_HANDLE(Qt::Key_Minus, "minus") QVTK_HANDLE(Qt::Key_Period, "period") QVTK_HANDLE(Qt::Key_Slash, "slash") QVTK_HANDLE(Qt::Key_F1, "F1") QVTK_HANDLE(Qt::Key_F2, "F2") QVTK_HANDLE(Qt::Key_F3, "F3") QVTK_HANDLE(Qt::Key_F4, "F4") QVTK_HANDLE(Qt::Key_F5, "F5") QVTK_HANDLE(Qt::Key_F6, "F6") QVTK_HANDLE(Qt::Key_F7, "F7") QVTK_HANDLE(Qt::Key_F8, "F8") QVTK_HANDLE(Qt::Key_F9, "F9") QVTK_HANDLE(Qt::Key_F10, "F10") QVTK_HANDLE(Qt::Key_F11, "F11") QVTK_HANDLE(Qt::Key_F12, "F12") QVTK_HANDLE(Qt::Key_F13, "F13") QVTK_HANDLE(Qt::Key_F14, "F14") QVTK_HANDLE(Qt::Key_F15, "F15") QVTK_HANDLE(Qt::Key_F16, "F16") QVTK_HANDLE(Qt::Key_F17, "F17") QVTK_HANDLE(Qt::Key_F18, "F18") QVTK_HANDLE(Qt::Key_F19, "F19") QVTK_HANDLE(Qt::Key_F20, "F20") QVTK_HANDLE(Qt::Key_F21, "F21") QVTK_HANDLE(Qt::Key_F22, "F22") QVTK_HANDLE(Qt::Key_F23, "F23") QVTK_HANDLE(Qt::Key_F24, "F24") QVTK_HANDLE(Qt::Key_NumLock, "Num_Lock") QVTK_HANDLE(Qt::Key_ScrollLock, "Scroll_Lock") default: break; } return ret; } diff --git a/Modules/OpenViewCore/src/QVTKQuickItem.cxx b/Modules/OpenViewCore/src/QVTKQuickItem.cxx index 89bcc0f5bf..63d59948ec 100644 --- a/Modules/OpenViewCore/src/QVTKQuickItem.cxx +++ b/Modules/OpenViewCore/src/QVTKQuickItem.cxx @@ -1,258 +1,258 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ // original copyright below /*======================================================================== OpenView -- http://openview.kitware.com Copyright 2012 Kitware, Inc. Licensed under the BSD license. See LICENSE file for details. ========================================================================*/ #include "QVTKQuickItem.h" #include #include #include #include #include #include "QVTKInteractor.h" -#include "QVTKInteractorAdapter.h" +#include "QVTKMitkInteractorAdapter.h" #include "vtkGenericOpenGLRenderWindow.h" #include "vtkEventQtSlotConnect.h" #include "vtkgl.h" #include "vtkOpenGLExtensionManager.h" #include "vtkRenderer.h" #include "vtkCubeSource.h" #include "vtkPolyDataMapper.h" #include "vtkProperty.h" #include #include "QVTKInternalOpenglRenderWindow.h" #include "QVTKFramebufferObjectRenderer.h" QVTKQuickItem::QVTKQuickItem(QQuickItem* parent) : QQuickFramebufferObject(parent) { setAcceptHoverEvents(true); setAcceptedMouseButtons(Qt::LeftButton | Qt::MiddleButton | Qt::RightButton); m_interactor = vtkSmartPointer::New(); - m_interactorAdapter = new QVTKInteractorAdapter(this); + m_interactorAdapter = new QVTKMitkInteractorAdapter(this); m_connect = vtkSmartPointer::New(); m_win = vtkInternalOpenGLRenderWindow::New(); m_interactor->SetRenderWindow(m_win); m_connect->Connect(m_win, vtkCommand::WindowIsCurrentEvent, this, SLOT(IsCurrent(vtkObject*, unsigned long, void*, void*)), NULL, 0.0, Qt::DirectConnection); m_connect->Connect(m_win, vtkCommand::WindowIsDirectEvent, this, SLOT(IsDirect(vtkObject*, unsigned long, void*, void*)), NULL, 0.0, Qt::DirectConnection); m_connect->Connect(m_win, vtkCommand::WindowSupportsOpenGLEvent, this, SLOT(SupportsOpenGL(vtkObject*, unsigned long, void*, void*)), NULL, 0.0, Qt::DirectConnection); connect(this, SIGNAL(textureFollowsItemSizeChanged(bool)), this, SLOT(onTextureFollowsItemSizeChanged(bool))); } QVTKQuickItem::~QVTKQuickItem() { if(m_win) { m_connect->Disconnect(m_win, vtkCommand::WindowIsCurrentEvent, this, SLOT(IsCurrent(vtkObject*, unsigned long, void*, void*))); m_connect->Disconnect(m_win, vtkCommand::WindowIsDirectEvent, this, SLOT(IsDirect(vtkObject*, unsigned long, void*, void*))); m_connect->Disconnect(m_win, vtkCommand::WindowSupportsOpenGLEvent, this, SLOT(SupportsOpenGL(vtkObject*, unsigned long, void*, void*))); m_win->Delete(); } } QSGNode* QVTKQuickItem::updatePaintNode(QSGNode *node, QQuickItem::UpdatePaintNodeData *nodeData) { if (!node) { node = QQuickFramebufferObject::updatePaintNode(node, nodeData); QSGSimpleTextureNode *n = static_cast(node); if (n) n->setTextureCoordinatesTransform(QSGSimpleTextureNode::MirrorVertically); return node; } return QQuickFramebufferObject::updatePaintNode(node, nodeData); } QQuickFramebufferObject::Renderer *QVTKQuickItem::createRenderer() const { return new QVTKFramebufferObjectRenderer(static_cast(m_win)); } vtkOpenGLRenderWindow* QVTKQuickItem::GetRenderWindow() const { return m_win; } QVTKInteractor* QVTKQuickItem::GetInteractor() const { return m_interactor; } void QVTKQuickItem::IsCurrent(vtkObject*, unsigned long, void*, void* call_data) { bool* ptr = reinterpret_cast(call_data); *ptr = QOpenGLContext::currentContext() == this->window()->openglContext(); } void QVTKQuickItem::IsDirect(vtkObject*, unsigned long, void*, void* call_data) { int* ptr = reinterpret_cast(call_data); *ptr = 1; } void QVTKQuickItem::SupportsOpenGL(vtkObject*, unsigned long, void*, void* call_data) { int* ptr = reinterpret_cast(call_data); *ptr = 1; } void QVTKQuickItem::onTextureFollowsItemSizeChanged(bool follows) { if (!follows) { qWarning("QVTKQuickItem: Mouse interaction is not (yet) supported when textureFollowsItemSize==false"); } } void QVTKQuickItem::geometryChanged(const QRectF & newGeometry, const QRectF & oldGeometry) { QQuickFramebufferObject::geometryChanged(newGeometry, oldGeometry); QSize oldSize(oldGeometry.width(), oldGeometry.height()); QSize newSize(newGeometry.width(), newGeometry.height()); QResizeEvent e(newSize, oldSize); if (m_interactorAdapter) { this->m_viewLock.lock(); m_interactorAdapter->ProcessEvent(&e, m_interactor); this->m_viewLock.unlock(); } } void QVTKQuickItem::keyPressEvent(QKeyEvent* e) { e->accept(); this->m_viewLock.lock(); m_interactorAdapter->ProcessEvent(e, m_interactor); this->m_viewLock.unlock(); update(); } void QVTKQuickItem::keyReleaseEvent(QKeyEvent* e) { e->accept(); this->m_viewLock.lock(); m_interactorAdapter->ProcessEvent(e, m_interactor); this->m_viewLock.unlock(); update(); } void QVTKQuickItem::mousePressEvent(QMouseEvent* e) { e->accept(); this->m_viewLock.lock(); m_interactorAdapter->ProcessEvent(e, m_interactor); this->m_viewLock.unlock(); update(); } void QVTKQuickItem::mouseReleaseEvent(QMouseEvent* e) { e->accept(); this->m_viewLock.lock(); m_interactorAdapter->ProcessEvent(e, m_interactor); this->m_viewLock.unlock(); update(); } void QVTKQuickItem::mouseDoubleClickEvent(QMouseEvent* e) { e->accept(); this->m_viewLock.lock(); m_interactorAdapter->ProcessEvent(e, m_interactor); this->m_viewLock.unlock(); update(); } void QVTKQuickItem::mouseMoveEvent(QMouseEvent* e) { e->accept(); this->m_viewLock.lock(); m_interactorAdapter->ProcessEvent(e, m_interactor); this->m_viewLock.unlock(); update(); } void QVTKQuickItem::wheelEvent(QWheelEvent* e) { e->accept(); this->m_viewLock.lock(); m_interactorAdapter->ProcessEvent(e, m_interactor); this->m_viewLock.unlock(); update(); } void QVTKQuickItem::hoverEnterEvent(QHoverEvent* e) { e->accept(); QEvent e2(QEvent::Enter); this->m_viewLock.lock(); m_interactorAdapter->ProcessEvent(&e2, m_interactor); this->m_viewLock.unlock(); update(); } void QVTKQuickItem::hoverLeaveEvent(QHoverEvent* e) { e->accept(); QEvent e2(QEvent::Leave); this->m_viewLock.lock(); m_interactorAdapter->ProcessEvent(&e2, m_interactor); this->m_viewLock.unlock(); update(); } void QVTKQuickItem::hoverMoveEvent(QHoverEvent* e) { e->accept(); QMouseEvent e2(QEvent::MouseMove, e->pos(), Qt::NoButton, Qt::NoButton, e->modifiers()); this->m_viewLock.lock(); m_interactorAdapter->ProcessEvent(&e2, m_interactor); this->m_viewLock.unlock(); update(); } void QVTKQuickItem::init() { m_win->OpenGLInitContext(); m_win->GetExtensionManager()->LoadExtension("GL_VERSION_1_4"); m_win->GetExtensionManager()->LoadExtension("GL_VERSION_2_0"); } bool QVTKQuickItem::prepareForRender() { return true; } void QVTKQuickItem::cleanupAfterRender() { } diff --git a/Modules/OpenViewCore/src/vtkEventQtSlotConnect.cxx b/Modules/OpenViewCore/src/vtkEventQtSlotConnect.cxx deleted file mode 100644 index 3234bec55f..0000000000 --- a/Modules/OpenViewCore/src/vtkEventQtSlotConnect.cxx +++ /dev/null @@ -1,166 +0,0 @@ -/*=================================================================== - -The Medical Imaging Interaction Toolkit (MITK) - -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. -All rights reserved. - -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. - -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ - -// original copyright below - -/*========================================================================= - - Copyright 2004 Sandia Corporation. - Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive - license for use of this work by or on behalf of the - U.S. Government. Redistribution and use in source and binary forms, with - or without modification, are permitted provided that this Notice and any - statement of authorship are reproduced on all copies. - -=========================================================================*/ - -/*======================================================================== - For general information about using VTK and Qt, see: - http://www.trolltech.com/products/3rdparty/vtksupport.html -=========================================================================*/ - -/*======================================================================== - !!! WARNING for those who want to contribute code to this file. - !!! If you use a commercial edition of Qt, you can modify this code. - !!! If you use an open source version of Qt, you are free to modify - !!! and use this code within the guidelines of the GPL license. - !!! Unfortunately, you cannot contribute the changes back into this - !!! file. Doing so creates a conflict between the GPL and BSD-like VTK - !!! license. -=========================================================================*/ - -#include "vtkEventQtSlotConnect.h" -#include "vtkObjectFactory.h" -#include "vtkCallbackCommand.h" -#include "vtkQtConnection.h" - -#include - -#include - -// hold all the connections -class vtkQtConnections : public std::vector< vtkQtConnection* > {}; - -vtkStandardNewMacro(vtkEventQtSlotConnect) - -// constructor -vtkEventQtSlotConnect::vtkEventQtSlotConnect() -{ - Connections = new vtkQtConnections; -} - - -vtkEventQtSlotConnect::~vtkEventQtSlotConnect() -{ - // clean out connections - vtkQtConnections::iterator iter; - for(iter=Connections->begin(); iter!=Connections->end(); ++iter) - { - delete (*iter); - } - - delete Connections; -} - -void vtkEventQtSlotConnect::Connect( - vtkObject* vtk_obj, unsigned long event, - const QObject* qt_obj, const char* slot, - void* client_data, float priority - , Qt::ConnectionType type) -{ - if (!vtk_obj || !qt_obj) - { - vtkErrorMacro("Cannot connect NULL objects."); - return; - } - vtkQtConnection* connection = new vtkQtConnection(this); - connection->SetConnection( - vtk_obj, event, qt_obj, slot, client_data, priority - , type); - Connections->push_back(connection); -} - - -void vtkEventQtSlotConnect::Disconnect(vtkObject* vtk_obj, unsigned long event, - const QObject* qt_obj, const char* slot, void* client_data) -{ - if (!vtk_obj) - { - vtkQtConnections::iterator iter; - for(iter=this->Connections->begin(); iter!=this->Connections->end(); ++iter) - { - delete (*iter); - } - this->Connections->clear(); - return; - } - bool all_info = true; - if(slot == NULL || qt_obj == NULL || event == vtkCommand::NoEvent) - all_info = false; - - vtkQtConnections::iterator iter; - for(iter=Connections->begin(); iter!=Connections->end();) - { - // if information matches, remove the connection - if((*iter)->IsConnection(vtk_obj, event, qt_obj, slot, client_data)) - { - delete (*iter); - iter = Connections->erase(iter); - // if user passed in all information, only remove one connection and quit - if(all_info) - iter = Connections->end(); - } - else - ++iter; - } -} - -void vtkEventQtSlotConnect::PrintSelf(ostream& os, vtkIndent indent) -{ - this->Superclass::PrintSelf(os,indent); - if(Connections->empty()) - { - os << indent << "No Connections\n"; - } - else - { - os << indent << "Connections:\n"; - vtkQtConnections::iterator iter; - for(iter=Connections->begin(); iter!=Connections->end(); ++iter) - { - (*iter)->PrintSelf(os, indent.GetNextIndent()); - } - } -} - -void vtkEventQtSlotConnect::RemoveConnection(vtkQtConnection* conn) -{ - vtkQtConnections::iterator iter; - for(iter=this->Connections->begin(); iter!=this->Connections->end(); ++iter) - { - if(conn == *iter) - { - delete (*iter); - Connections->erase(iter); - return; - } - } -} - -int vtkEventQtSlotConnect::GetNumberOfConnections() const -{ - return static_cast(this->Connections->size()); -} diff --git a/Modules/QmlItems/src/QmlMitkRenderWindowItem.cpp b/Modules/QmlItems/src/QmlMitkRenderWindowItem.cpp index 4cd6c93758..c8ddc7ee19 100644 --- a/Modules/QmlItems/src/QmlMitkRenderWindowItem.cpp +++ b/Modules/QmlItems/src/QmlMitkRenderWindowItem.cpp @@ -1,368 +1,367 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "QmlMitkRenderWindowItem.h" #include -#include #include #include #include #include "mitkMouseWheelEvent.h" #include "mitkMousePressEvent.h" #include "mitkMouseMoveEvent.h" #include "mitkMouseDoubleClickEvent.h" #include "mitkMouseReleaseEvent.h" #include "mitkInteractionKeyEvent.h" #include "mitkInternalEvent.h" #include "mitkPlaneGeometryDataMapper2D.h" #include "mitkCameraController.h" #include "QmlMitkStdMultiItem.h" #include QmlMitkRenderWindowItem* QmlMitkRenderWindowItem::instance = nullptr; QmlMitkRenderWindowItem* QmlMitkRenderWindowItem::GetInstanceForVTKRenderWindow(vtkRenderWindow* rw) { if (GetInstances().contains(rw)) { return GetInstances()[rw]; } return 0; } QMap& QmlMitkRenderWindowItem::GetInstances() { static QMap s_Instances; return s_Instances; } QmlMitkRenderWindowItem::QmlMitkRenderWindowItem(QQuickItem* parent, const QString& name, mitk::VtkPropRenderer* , mitk::RenderingManager* renderingManager) : QVTKQuickItem(parent) { instance = this; mitk::RenderWindowBase::Initialize(renderingManager, name.toStdString().c_str()); GetInstances()[QVTKQuickItem::GetRenderWindow()] = this; this->m_annotation = vtkSmartPointer::New(); this->m_rectangle = vtkSmartPointer::New(); } void QmlMitkRenderWindowItem::createPlaneNode() { mitk::DataStorage::Pointer m_DataStorage = mitk::RenderWindowBase::GetRenderer()->GetDataStorage(); if (m_DataStorage.IsNotNull()) { mitk::RenderingManager::GetInstance()->InitializeViews( m_DataStorage->ComputeBoundingGeometry3D(m_DataStorage->GetAll()) ); } if (this->GetRenderer()->GetSliceNavigationController()->GetDefaultViewDirection() == mitk::SliceNavigationController::Original) return; mitk::DataNode::Pointer planeNode; mitk::IntProperty::Pointer layer; mitk::PlaneGeometryDataMapper2D::Pointer mapper = mitk::PlaneGeometryDataMapper2D::New(); layer = mitk::IntProperty::New(1000); planeNode = this->GetRenderer()->GetCurrentWorldPlaneGeometryNode(); planeNode->SetProperty("visible", mitk::BoolProperty::New(true)); planeNode->SetProperty("name", mitk::StringProperty::New("plane")); planeNode->SetProperty("isPlane", mitk::BoolProperty::New(true)); planeNode->SetProperty("includeInBoundingBox", mitk::BoolProperty::New(false)); planeNode->SetProperty("helper object", mitk::BoolProperty::New(true)); planeNode->SetProperty("layer", layer); planeNode->SetMapper(mitk::BaseRenderer::Standard2D, mapper); switch (this->GetRenderer()->GetSliceNavigationController()->GetDefaultViewDirection()) { case mitk::SliceNavigationController::Axial: planeNode->SetColor(0.88, 0.35, 0.27); break; case mitk::SliceNavigationController::Sagittal: planeNode->SetColor(0.25, 0.7, 0.35); break; case mitk::SliceNavigationController::Frontal: planeNode->SetColor(0.01, 0.31, 0.67); break; default: planeNode->SetColor(1.0, 1.0, 0.0); } } void QmlMitkRenderWindowItem::setViewType(int viewType) { this->m_viewType = viewType; emit this->viewTypeChanged(); } void QmlMitkRenderWindowItem::setDecorationProperties(std::string text, mitk::Color color) { this->m_annotation->SetText(0, text.c_str()); this->m_annotation->SetMaximumFontSize(12); this->m_annotation->GetTextProperty()->SetColor( color[0],color[1],color[2] ); if(!this->GetRenderer()->GetVtkRenderer()->HasViewProp(this->m_annotation)) { this->GetRenderer()->GetVtkRenderer()->AddViewProp(this->m_annotation); } this->m_rectangle->SetColor(color[0],color[1],color[2]); if(!this->GetRenderer()->GetVtkRenderer()->HasViewProp(this->m_rectangle)) { this->GetRenderer()->GetVtkRenderer()->AddViewProp(this->m_rectangle); } } void QmlMitkRenderWindowItem::setupView() { switch (this->m_viewType) { case 0: this->GetRenderer()->SetMapperID(mitk::BaseRenderer::Standard2D); this->GetRenderer()->GetSliceNavigationController()->SetDefaultViewDirection(mitk::SliceNavigationController::Axial); break; case 1: this->GetRenderer()->SetMapperID(mitk::BaseRenderer::Standard2D); this->GetRenderer()->GetSliceNavigationController()->SetDefaultViewDirection(mitk::SliceNavigationController::Frontal); break; case 2: this->GetRenderer()->SetMapperID(mitk::BaseRenderer::Standard2D); this->GetRenderer()->GetSliceNavigationController()->SetDefaultViewDirection(mitk::SliceNavigationController::Sagittal); break; case 3: this->GetRenderer()->SetMapperID(mitk::BaseRenderer::Standard3D); this->GetRenderer()->GetSliceNavigationController()->SetDefaultViewDirection(mitk::SliceNavigationController::Original); break; default: break; } } void QmlMitkRenderWindowItem::setMultiItem(QmlMitkStdMultiItem* multiItem) { if(this->m_multiItem == multiItem) return; this->m_multiItem = multiItem; this->m_multiItem->registerViewerItem(this); } QmlMitkStdMultiItem* QmlMitkRenderWindowItem::getMultiItem() { return this->m_multiItem; } void QmlMitkRenderWindowItem::SetDataStorage(mitk::DataStorage::Pointer storage) { this->GetRenderer()->SetDataStorage(storage); } mitk::Point2D QmlMitkRenderWindowItem::GetMousePosition(QMouseEvent* me) const { qreal ratio = this->window()->effectiveDevicePixelRatio(); mitk::Point2D point; point[0] = me->x()*ratio; point[1] = me->y()*ratio; return point; } mitk::Point2D QmlMitkRenderWindowItem::GetMousePosition(QWheelEvent* we) const { qreal ratio = this->window()->effectiveDevicePixelRatio(); mitk::Point2D point; point[0] = we->x()*ratio; point[1] = we->y()*ratio; return point; } mitk::InteractionEvent::MouseButtons QmlMitkRenderWindowItem::GetEventButton(QMouseEvent* me) const { mitk::InteractionEvent::MouseButtons eventButton; switch (me->button()) { case Qt::LeftButton: eventButton = mitk::InteractionEvent::LeftMouseButton; break; case Qt::RightButton: eventButton = mitk::InteractionEvent::RightMouseButton; break; case Qt::MidButton: eventButton = mitk::InteractionEvent::MiddleMouseButton; break; default: eventButton = mitk::InteractionEvent::NoButton; break; } return eventButton; } mitk::InteractionEvent::MouseButtons QmlMitkRenderWindowItem::GetButtonState(QMouseEvent* me) const { mitk::InteractionEvent::MouseButtons buttonState = mitk::InteractionEvent::NoButton; if (me->buttons() & Qt::LeftButton) { buttonState = buttonState | mitk::InteractionEvent::LeftMouseButton; } if (me->buttons() & Qt::RightButton) { buttonState = buttonState | mitk::InteractionEvent::RightMouseButton; } if (me->buttons() & Qt::MidButton) { buttonState = buttonState | mitk::InteractionEvent::MiddleMouseButton; } return buttonState; } mitk::InteractionEvent::ModifierKeys QmlMitkRenderWindowItem::GetModifiers(QInputEvent* me) const { mitk::InteractionEvent::ModifierKeys modifiers = mitk::InteractionEvent::NoKey; if (me->modifiers() & Qt::ALT) { modifiers = modifiers | mitk::InteractionEvent::AltKey; } if (me->modifiers() & Qt::CTRL) { modifiers = modifiers | mitk::InteractionEvent::ControlKey; } if (me->modifiers() & Qt::SHIFT) { modifiers = modifiers | mitk::InteractionEvent::ShiftKey; } return modifiers; } mitk::InteractionEvent::MouseButtons QmlMitkRenderWindowItem::GetButtonState(QWheelEvent* we) const { mitk::InteractionEvent::MouseButtons buttonState = mitk::InteractionEvent::NoButton; if (we->buttons() & Qt::LeftButton) { buttonState = buttonState | mitk::InteractionEvent::LeftMouseButton; } if (we->buttons() & Qt::RightButton) { buttonState = buttonState | mitk::InteractionEvent::RightMouseButton; } if (we->buttons() & Qt::MidButton) { buttonState = buttonState | mitk::InteractionEvent::MiddleMouseButton; } return buttonState; } int QmlMitkRenderWindowItem::getViewType() { return this->m_viewType; } void QmlMitkRenderWindowItem::mousePressEvent(QMouseEvent* me) { mitk::Point2D mousePosition = GetMousePosition(me); //mousePosition[1] = this->GetRenderer()->GetSizeY() - mousePosition[1]; mitk::MousePressEvent::Pointer mPressEvent = mitk::MousePressEvent::New(mitk::RenderWindowBase::GetRenderer(), mousePosition, GetButtonState(me), GetModifiers(me), GetEventButton(me)); mitk::RenderWindowBase::HandleEvent(mPressEvent.GetPointer()); QVTKQuickItem::mousePressEvent(me); } void QmlMitkRenderWindowItem::mouseReleaseEvent(QMouseEvent* me) { mitk::Point2D mousePosition = GetMousePosition(me); //mousePosition[1] = this->GetRenderer()->GetSizeY() - mousePosition[1]; mitk::MouseReleaseEvent::Pointer mReleaseEvent = mitk::MouseReleaseEvent::New(mitk::RenderWindowBase::GetRenderer(), mousePosition, GetButtonState(me), GetModifiers(me), GetEventButton(me)); mitk::RenderWindowBase::HandleEvent(mReleaseEvent.GetPointer()); QVTKQuickItem::mouseReleaseEvent(me); } void QmlMitkRenderWindowItem::mouseMoveEvent(QMouseEvent* me) { mitk::Point2D mousePosition = GetMousePosition(me); //mousePosition[1] = this->GetRenderer()->GetSizeY() - mousePosition[1]; mitk::MouseMoveEvent::Pointer mMoveEvent = mitk::MouseMoveEvent::New(mitk::RenderWindowBase::GetRenderer(), mousePosition, GetButtonState(me), GetModifiers(me)); mitk::RenderWindowBase::HandleEvent(mMoveEvent.GetPointer()); QVTKQuickItem::mouseMoveEvent(me); } void QmlMitkRenderWindowItem::wheelEvent(QWheelEvent *we) { mitk::Point2D mousePosition = GetMousePosition(we); mitk::MouseWheelEvent::Pointer mWheelEvent = mitk::MouseWheelEvent::New(mitk::RenderWindowBase::GetRenderer(), mousePosition, GetButtonState(we), GetModifiers(we), we->delta()); mitk::RenderWindowBase::HandleEvent(mWheelEvent.GetPointer()); QVTKQuickItem::wheelEvent(we); } bool QmlMitkRenderWindowItem::prepareForRender() { mitk::VtkPropRenderer *vPR = dynamic_cast(mitk::BaseRenderer::GetInstance(this->GetRenderWindow())); if (vPR) { vPR->PrepareRender(); } mitk::RenderWindowBase::GetRenderer()->ForceImmediateUpdate(); return true; } void QmlMitkRenderWindowItem::cleanupAfterRender() { } void QmlMitkRenderWindowItem::geometryChanged(const QRectF & newGeometry, const QRectF & oldGeometry) { QVTKQuickItem::geometryChanged(newGeometry, oldGeometry); mitk::BaseRenderer::GetInstance(this->GetRenderWindow())->GetCameraController()->Fit(); } QmlMitkRenderWindowItem::~QmlMitkRenderWindowItem() { this->Destroy(); } vtkRenderWindow* QmlMitkRenderWindowItem::GetVtkRenderWindow() { return QVTKQuickItem::GetRenderWindow(); } vtkRenderWindowInteractor* QmlMitkRenderWindowItem::GetVtkRenderWindowInteractor() { return QVTKQuickItem::GetInteractor(); }