Fraxinus  2023.01.05-dev+develop.0da12
An IGT application
cxMultiViewCache.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #include "cxMultiViewCache.h"
13 #include "vtkRenderWindow.h"
14 #include "cxViewService.h"
15 #include "cxRenderWindowFactory.h"
16 
17 namespace cx
18 {
19 
21  mRenderWindowFactory(factory)
22 {
23  // add a hidden window in order to handle the shared context (ref hack in vtkRenderWindow descendants
24  // that add support for shared gl contexts)
25  if (!mStaticRenderWindow.GetPointer())
26  {
27  mStaticRenderWindow = mRenderWindowFactory->getSharedRenderWindow();
28  if(mStaticRenderWindow)
29  mStaticRenderWindow->Render();
30  }
31 }
32 
33 ViewWidget* MultiViewCache::retrieveView(QWidget* widget, View::Type type, bool offScreenRendering)
34 {
35  // create one cache per type. This alleviates cross-settings between 2D and 3D,
36  // and also separates on/offscreen rendering, which doesn't mix well.
37  QString cache_uid = QString("View_%1_%2").arg(type).arg(offScreenRendering);
38  if (!mViewCache.count(cache_uid))
39  mViewCache[cache_uid].reset(new ViewCache<ViewWidget>(mRenderWindowFactory, widget, cache_uid));
40  ViewCachePtr cache = mViewCache[cache_uid];
41 
42  ViewWidget* vw = cache->retrieveView();
43  vw->getRenderWindow()->SetOffScreenRendering(offScreenRendering);
44  return vw;
45 }
46 
48 {
49  for (std::map<QString, ViewCachePtr>::iterator iter=mViewCache.begin(); iter!=mViewCache.end(); ++iter)
50  {
51  iter->second->clearUsedViews();
52  }
53 }
54 
56 {
57  for (std::map<QString, ViewCachePtr>::iterator iter=mViewCache.begin(); iter!=mViewCache.end(); ++iter)
58  {
59  iter->second->clearCache();
60  }
61 
62 }
63 
64 
65 } // namespace cx
virtual vtkRenderWindowPtr getRenderWindow()
Get the vtkRenderWindow used by this View.
Definition: cxViewWidget.h:40
MultiViewCache(RenderWindowFactoryPtr factory)
ViewWidget * retrieveView(QWidget *widget, View::Type type, bool offScreenRendering)
boost::shared_ptr< class RenderWindowFactory > RenderWindowFactoryPtr
Namespace for all CustusX production code.