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
QmlMitkRenderingManager.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 
19 #include "mitkGeometry3D.h"
20 #include "mitkBaseRenderer.h"
22 #include <QCoreApplication>
23 #include <QTimer>
24 
27 :pendingTimerCallbacks(0)
28 {
29 }
30 
33 {
34 }
35 
36 void
39 {
40  QCoreApplication::postEvent( this, new QmlMitkRenderingRequestEvent );
41 }
42 
43 
44 void
47 {
48  QTimer::singleShot(200, this, SLOT(TimerCallback()));
49  pendingTimerCallbacks++;
50 }
51 
52 void
55 {
56  if(!--pendingTimerCallbacks)
57  {
58  this->ExecutePendingHighResRenderingRequest();
59  }
60 }
61 
62 #include <iostream>
63 
64 bool
66 ::event( QEvent *event )
67 {
68  if ( event->type() == (QEvent::Type) QmlMitkRenderingRequestEvent::RenderingRequest )
69  {
70  // Directly process all pending rendering requests
71  //this->ExecutePendingRequests();
72  this->MyUpdateExecutePendingRequests();
73 
74  return true;
75  }
76 
77  return false;
78 }
79 
80 #include "QVTKQuickItem.h"
81 
82 void QmlMitkRenderingManager::MyUpdateExecutePendingRequests()
83 {
84  m_UpdatePending = false;
85 
86  // Satisfy all pending update requests
87  RenderWindowList::iterator it;
88  int i = 0;
89  for ( it = m_RenderWindowList.begin(); it != m_RenderWindowList.end(); ++it, ++i )
90  {
91  if ( it->second == RENDERING_REQUESTED )
92  {
93  vtkRenderWindow* renderWindow = it->first;
94 
95  // If the renderWindow is not valid, we do not want to inadvertantly create
96  // an entry in the m_RenderWindowList map. It is possible if the user is
97  // regularly calling AddRenderer and RemoveRenderer for a rendering update
98  // to come into this method with a renderWindow pointer that is valid in the
99  // sense that the window does exist within the application, but that
100  // renderWindow has been temporarily removed from this RenderingManager for
101  // performance reasons.
102  if (m_RenderWindowList.find( renderWindow ) == m_RenderWindowList.end())
103  {
104  continue;
105  }
106 
107  // Erase potentially pending requests for this window
108  m_RenderWindowList[renderWindow] = RENDERING_INACTIVE;
109 
110  m_UpdatePending = false;
111 
112  // Immediately repaint this window (implementation platform specific)
113  // If the size is 0 it crahses
114  int *size = renderWindow->GetSize();
115  if ( 0 != size[0] && 0 != size[1] )
116  {
118  if (qqi)
119  {
120  qqi->update();
121  }
122  }
123  }
124  }
125 }
RenderWindowList m_RenderWindowList
virtual void GenerateRenderingRequestEvent()
virtual bool event(QEvent *event)
static QmlMitkRenderWindowItem * GetInstanceForVTKRenderWindow(vtkRenderWindow *rw)