CustusX  2023.01.05-dev+develop.0da12
An IGT application
cxSharedContextCreatedCallback.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 
13 
14 #include <vtkOpenGLRenderWindow.h>
15 
16 #include "vtkRenderWindow.h"
17 #include "cxLogger.h"
18 #include "cxSharedOpenGLContext.h"
19 #include "cxRenderWindowFactory.h"
20 
21 namespace cx
22 {
23 
25 {
26  return new SharedContextCreatedCallback();
27 }
28 
30  mRenderWindowFactory(NULL)
31 {
32 }
33 
35 {
36  mRenderWindowFactory = factory;
37 }
38 
39 void SharedContextCreatedCallback::Execute(vtkObject *renderWindow, unsigned long eventId, void *cbo)
40 {
41  if(!mRenderWindowFactory)
42  {
43  CX_LOG_ERROR() << "SharedContextCreatedCallback::Execute: RenderWindowFactoryPtr missing";
44  return;
45  }
46 
47  if(eventId == vtkCommand::CXSharedContextCreatedEvent)
48  {
49  vtkOpenGLRenderWindowPtr opengl_renderwindow = vtkOpenGLRenderWindow::SafeDownCast(renderWindow);
50 
51  if(SharedOpenGLContext::isValid(opengl_renderwindow))
52  {
53  mRenderWindowFactory->setSharedRenderWindow(opengl_renderwindow);
54  }
55  else
56  {
57  CX_LOG_WARNING() << "VTK render window is not an opengl renderwindow. This means we don't have an OpenGL shared context";
58  }
59  }
60 }
61 
62 }//cx
Use to create all vtkRenderWindows, and store a single shared render window.
vtkSmartPointer< class vtkOpenGLRenderWindow > vtkOpenGLRenderWindowPtr
static SharedContextCreatedCallback * New()
virtual void Execute(vtkObject *view, unsigned long eventId, void *cbo)
#define CX_LOG_ERROR
Definition: cxLogger.h:99
#define CX_LOG_WARNING
Definition: cxLogger.h:98
void setRenderWindowFactory(RenderWindowFactory *factory)
static bool isValid(vtkOpenGLRenderWindowPtr opengl_renderwindow, bool print=false)
Namespace for all CustusX production code.