Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
QmlMitkRenderWindowItem.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3  The Medical Imaging Interaction Toolkit (MITK)
4 
5  Copyright (c) German Cancer Research Center,
6  Division of Medical and Biological Informatics.
7  All rights reserved.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without
10  even the implied warranty of MERCHANTABILITY or FITNESS FOR
11  A PARTICULAR PURPOSE.
12 
13  See LICENSE.txt or http://www.mitk.org for details.
14 
15  ===================================================================*/
16 
18 
19 #include <QVTKInteractor.h>
20 
21 #include <vtkEventQtSlotConnect.h>
22 #include <vtkGenericOpenGLRenderWindow.h>
23 #include <vtkTextProperty.h>
24 
25 #include "mitkMouseWheelEvent.h"
26 #include "mitkMousePressEvent.h"
27 #include "mitkMouseMoveEvent.h"
29 #include "mitkMouseReleaseEvent.h"
31 #include "mitkInternalEvent.h"
33 #include "mitkCameraController.h"
34 
35 #include "QmlMitkStdMultiItem.h"
36 #include <QQuickWindow>
37 
39 
41 {
42  if (GetInstances().contains(rw))
43  {
44  return GetInstances()[rw];
45  }
46  return 0;
47 }
48 
49 QMap<vtkRenderWindow*, QmlMitkRenderWindowItem*>& QmlMitkRenderWindowItem::GetInstances()
50 {
51  static QMap<vtkRenderWindow*, QmlMitkRenderWindowItem*> s_Instances;
52  return s_Instances;
53 }
54 
55 QmlMitkRenderWindowItem::QmlMitkRenderWindowItem(QQuickItem* parent, const QString& name, mitk::VtkPropRenderer* , mitk::RenderingManager* renderingManager) : QVTKQuickItem(parent)
56 {
57  instance = this;
58 
59  mitk::RenderWindowBase::Initialize(renderingManager, name.toStdString().c_str());
61 
62  this->m_annotation = vtkSmartPointer<vtkCornerAnnotation>::New();
63  this->m_rectangle = vtkSmartPointer<vtkMitkRectangleProp>::New();
64 }
65 
67 {
69  if (m_DataStorage.IsNotNull())
70  {
71  mitk::RenderingManager::GetInstance()->InitializeViews( m_DataStorage->ComputeBoundingGeometry3D(m_DataStorage->GetAll()) );
72  }
73 
74  if (this->GetRenderer()->GetSliceNavigationController()->GetDefaultViewDirection() == mitk::SliceNavigationController::Original)
75  return;
76 
77  mitk::DataNode::Pointer planeNode;
80 
81  layer = mitk::IntProperty::New(1000);
82 
83  planeNode = this->GetRenderer()->GetCurrentWorldPlaneGeometryNode();
84 
85  planeNode->SetProperty("visible", mitk::BoolProperty::New(true));
86  planeNode->SetProperty("name", mitk::StringProperty::New("plane"));
87  planeNode->SetProperty("isPlane", mitk::BoolProperty::New(true));
88  planeNode->SetProperty("includeInBoundingBox", mitk::BoolProperty::New(false));
89  planeNode->SetProperty("helper object", mitk::BoolProperty::New(true));
90  planeNode->SetProperty("layer", layer);
91  planeNode->SetMapper(mitk::BaseRenderer::Standard2D, mapper);
92 
93  switch (this->GetRenderer()->GetSliceNavigationController()->GetDefaultViewDirection())
94  {
96  planeNode->SetColor(0.88, 0.35, 0.27);
97  break;
99  planeNode->SetColor(0.25, 0.7, 0.35);
100  break;
102  planeNode->SetColor(0.01, 0.31, 0.67);
103  break;
104  default:
105  planeNode->SetColor(1.0, 1.0, 0.0);
106  }
107 
108 }
109 
111 {
112  this->m_viewType = viewType;
113 
114  emit this->viewTypeChanged();
115 }
116 
118 {
119  this->m_annotation->SetText(0, text.c_str());
120  this->m_annotation->SetMaximumFontSize(12);
121  this->m_annotation->GetTextProperty()->SetColor( color[0],color[1],color[2] );
122 
123 
124  if(!this->GetRenderer()->GetVtkRenderer()->HasViewProp(this->m_annotation))
125  {
126  this->GetRenderer()->GetVtkRenderer()->AddViewProp(this->m_annotation);
127  }
128 
129  this->m_rectangle->SetColor(color[0],color[1],color[2]);
130 
131  if(!this->GetRenderer()->GetVtkRenderer()->HasViewProp(this->m_rectangle))
132  {
133  this->GetRenderer()->GetVtkRenderer()->AddViewProp(this->m_rectangle);
134  }
135 }
136 
138 {
139  switch (this->m_viewType)
140  {
141  case 0:
144  break;
145  case 1:
148  break;
149  case 2:
152  break;
153  case 3:
156  break;
157  default:
158  break;
159  }
160 }
161 
163 {
164  if(this->m_multiItem == multiItem)
165  return;
166 
167  this->m_multiItem = multiItem;
168  this->m_multiItem->registerViewerItem(this);
169 }
170 
172 {
173  return this->m_multiItem;
174 }
175 
177 {
178  this->GetRenderer()->SetDataStorage(storage);
179 }
180 
182 {
183  qreal ratio = this->window()->effectiveDevicePixelRatio();
184  mitk::Point2D point;
185  point[0] = me->x()*ratio;
186  point[1] = me->y()*ratio;
187  return point;
188 }
189 
191 {
192  qreal ratio = this->window()->effectiveDevicePixelRatio();
193  mitk::Point2D point;
194  point[0] = we->x()*ratio;
195  point[1] = we->y()*ratio;
196  return point;
197 }
198 
200 {
202  switch (me->button())
203  {
204  case Qt::LeftButton:
206  break;
207  case Qt::RightButton:
209  break;
210  case Qt::MidButton:
212  break;
213  default:
214  eventButton = mitk::InteractionEvent::NoButton;
215  break;
216  }
217  return eventButton;
218 }
219 
221 {
223 
224  if (me->buttons() & Qt::LeftButton)
225  {
226  buttonState = buttonState | mitk::InteractionEvent::LeftMouseButton;
227  }
228  if (me->buttons() & Qt::RightButton)
229  {
230  buttonState = buttonState | mitk::InteractionEvent::RightMouseButton;
231  }
232  if (me->buttons() & Qt::MidButton)
233  {
234  buttonState = buttonState | mitk::InteractionEvent::MiddleMouseButton;
235  }
236  return buttonState;
237 }
238 
240 {
242 
243  if (me->modifiers() & Qt::ALT)
244  {
245  modifiers = modifiers | mitk::InteractionEvent::AltKey;
246  }
247  if (me->modifiers() & Qt::CTRL)
248  {
249  modifiers = modifiers | mitk::InteractionEvent::ControlKey;
250  }
251  if (me->modifiers() & Qt::SHIFT)
252  {
253  modifiers = modifiers | mitk::InteractionEvent::ShiftKey;
254  }
255  return modifiers;
256 }
257 
259 {
261 
262  if (we->buttons() & Qt::LeftButton)
263  {
264  buttonState = buttonState | mitk::InteractionEvent::LeftMouseButton;
265  }
266  if (we->buttons() & Qt::RightButton)
267  {
268  buttonState = buttonState | mitk::InteractionEvent::RightMouseButton;
269  }
270  if (we->buttons() & Qt::MidButton)
271  {
272  buttonState = buttonState | mitk::InteractionEvent::MiddleMouseButton;
273  }
274  return buttonState;
275 }
276 
277 
279 {
280  return this->m_viewType;
281 }
282 
284 {
285  mitk::Point2D mousePosition = GetMousePosition(me);
286  //mousePosition[1] = this->GetRenderer()->GetSizeY() - mousePosition[1];
287 
288  mitk::MousePressEvent::Pointer mPressEvent =
290 
291  mitk::RenderWindowBase::HandleEvent(mPressEvent.GetPointer());
293 }
294 
296 {
297  mitk::Point2D mousePosition = GetMousePosition(me);
298  //mousePosition[1] = this->GetRenderer()->GetSizeY() - mousePosition[1];
299 
300  mitk::MouseReleaseEvent::Pointer mReleaseEvent =
302 
303  mitk::RenderWindowBase::HandleEvent(mReleaseEvent.GetPointer());
305 }
306 
308 {
309  mitk::Point2D mousePosition = GetMousePosition(me);
310  //mousePosition[1] = this->GetRenderer()->GetSizeY() - mousePosition[1];
311 
312  mitk::MouseMoveEvent::Pointer mMoveEvent =
314 
315  mitk::RenderWindowBase::HandleEvent(mMoveEvent.GetPointer());
317 }
318 
320 {
321  mitk::Point2D mousePosition = GetMousePosition(we);
322 
323  mitk::MouseWheelEvent::Pointer mWheelEvent =
325 
326  mitk::RenderWindowBase::HandleEvent(mWheelEvent.GetPointer());
328 }
329 
331 {
332 
334  if (vPR)
335  {
336  vPR->PrepareRender();
337  }
338 
340 
341  return true;
342 }
343 
345 {
346 }
347 
348 void QmlMitkRenderWindowItem::geometryChanged(const QRectF & newGeometry, const QRectF & oldGeometry)
349 {
350  QVTKQuickItem::geometryChanged(newGeometry, oldGeometry);
352 }
353 
355 {
356  this->Destroy();
357 }
358 
360 {
362 }
363 
365 {
367 }
virtual bool InitializeViews(const BaseGeometry *geometry, RequestType type=REQUEST_UPDATE_ALL, bool preserveRoughOrientationInWorldSpace=false)
virtual bool HandleEvent(InteractionEvent *interactionEvent)
virtual DataNode * GetCurrentWorldPlaneGeometryNode()
Get a DataNode pointing to a data object containing the current 2D-worldgeometry. ...
void setMultiItem(QmlMitkStdMultiItem *multiItem)
mitk::InteractionEvent::MouseButtons GetButtonState(QMouseEvent *me) const
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
static Pointer New(BaseRenderer *_arga, const Point2D &_argb, MouseButtons _argc, ModifierKeys _argd, MouseButtons _arge)
mitk::Point2D GetMousePosition(QMouseEvent *me) const
static BaseRenderer * GetInstance(vtkRenderWindow *renWin)
mitk::InteractionEvent::MouseButtons GetEventButton(QMouseEvent *me) const
mitk::InteractionEvent::ModifierKeys GetModifiers(QInputEvent *me) const
virtual void SetDataStorage(mitk::DataStorage *storage) override
set the datastorage that will be used for rendering
virtual void mouseMoveEvent(QMouseEvent *e)
virtual void mouseMoveEvent(QMouseEvent *e)
virtual vtkRenderWindowInteractor * GetVtkRenderWindowInteractor()
QVTKInteractor * GetInteractor() const
void SetDataStorage(mitk::DataStorage::Pointer storage)
virtual DataStorage::Pointer GetDataStorage() const
static Pointer New()
virtual void wheelEvent(QWheelEvent *e)
static Pointer New(BaseRenderer *_arga, const Point2D &_argb, MouseButtons _argc, ModifierKeys _argd, int _arge)
virtual void mouseReleaseEvent(QMouseEvent *e)
mitk::DataStorage::Pointer m_DataStorage
Manager for coordinating the rendering process.
static RenderingManager * GetInstance()
static QmlMitkRenderWindowItem * instance
static QmlMitkRenderWindowItem * GetInstanceForVTKRenderWindow(vtkRenderWindow *rw)
virtual CameraController * GetCameraController()
virtual void mousePressEvent(QMouseEvent *e)
virtual void mousePressEvent(QMouseEvent *e)
static Pointer New(BaseRenderer *_arga, const Point2D &_argb, MouseButtons _argc, ModifierKeys _argd)
virtual mitk::VtkPropRenderer * GetRenderer()
virtual void wheelEvent(QWheelEvent *e)
void setDecorationProperties(std::string text, mitk::Color color)
itk::RGBPixel< float > Color
Color Standard RGB color typedef (float)
virtual void PrepareRender()
This methods contains all method neceassary before a VTK Render() call.
static Pointer New()
static Pointer New(BaseRenderer *_arga, const Point2D &_argb, MouseButtons _argc, ModifierKeys _argd, MouseButtons _arge)
static QMap< vtkRenderWindow *, QmlMitkRenderWindowItem * > & GetInstances()
virtual vtkRenderWindow * GetVtkRenderWindow()
void Initialize(mitk::RenderingManager *renderingManager=NULL, const char *name="unnamed renderer", mitk::BaseRenderer::RenderingMode::Type renderingMode=mitk::BaseRenderer::RenderingMode::Standard)
void registerViewerItem(QmlMitkRenderWindowItem *viewerItem)
virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
virtual void SetMapperID(const MapperSlotId mapperId) override
Set the MapperSlotId to use.
virtual SliceNavigationController * GetSliceNavigationController()
virtual mitk::SliceNavigationController * GetSliceNavigationController()
virtual void mouseReleaseEvent(QMouseEvent *e)
QmlMitkStdMultiItem * getMultiItem()
vtkRenderer * GetVtkRenderer() const
void Fit()
Fit Adjust the camera, so that the world bounding box is fully visible.
QmlMitkRenderWindowItem(QQuickItem *parent=0, const QString &name="QML render window", mitk::VtkPropRenderer *renderer=NULL, mitk::RenderingManager *renderingManager=NULL)
static Pointer New()
vtkOpenGLRenderWindow * GetRenderWindow() const
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.