18 #include <vtkCamera.h>
19 #include <vtkPNGWriter.h>
20 #include <vtkRenderLargeImage.h>
21 #include <vtkRenderWindow.h>
22 #include <vtkRenderWindowInteractor.h>
32 #include <vtkOpenGL.h>
33 #include <vtkOpenGLExtensionManager.h>
34 #include <vtksys/SystemTools.hxx>
38 #define RESIZE_WORKAROUND
42 #ifdef RESIZE_WORKAROUND
43 #include "vtkWin32OpenGLRenderWindow.h"
47 #include "vtkTesting.h"
52 : m_AutomaticallyCloseRenderWindow(true)
54 this->
Initialize(width, height, renderingMode);
59 : m_AutomaticallyCloseRenderWindow(true)
61 this->
Initialize(width, height, renderingMode);
72 this->SetMapperIDToRender2D();
73 this->GetVtkRenderWindow()->SetSize(width, height);
75 #ifdef RESIZE_WORKAROUND
77 HWND hWnd =
static_cast<vtkWin32OpenGLRenderWindow *
>(this->GetVtkRenderWindow())->GetWindowId();
82 r.right = r.left + width;
83 r.bottom = r.top + height;
85 LONG style = GetWindowLong(hWnd, GWL_STYLE);
86 AdjustWindowRect(&r, style, FALSE);
93 if (GetWindowRect(hWnd, &rect))
95 int width = rect.right - rect.left;
96 int height = rect.bottom - rect.top;
103 SetWindowPos(hWnd, HWND_TOP, 0, 0, r.right - r.left, r.bottom - r.top, SWP_NOZORDER);
105 GetWindowRect(hWnd, &rect);
107 int width2 = rect.right - rect.left;
108 int height2 = rect.bottom - rect.top;
114 SetWindowPos(hWnd, HWND_TOP, 0, 0, 2 * (r.right - r.left) - width2, 2 * (r.bottom - r.top) - height2, SWP_NOZORDER);
118 m_RenderWindow->GetRenderer()->Resize(width, height);
130 const GLubyte *version = glGetString(GL_VERSION);
133 return *version >=
'2';
138 GLint maxTextureSize;
140 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
143 MITK_INFO <<
"OpenGL Render Context Information: \n"
144 <<
"- GL_VENDOR: " << glGetString(GL_VENDOR) <<
"\n"
145 <<
"- GL_RENDERER: " << glGetString(GL_RENDERER) <<
"\n"
146 <<
"- GL_VERSION: " << glGetString(GL_VERSION) <<
"\n"
147 <<
"- GL_MAX_TEXTURE_SIZE: " << maxTextureSize <<
"\n"
148 <<
"- GL_EXTENSIONS: " << glGetString(GL_EXTENSIONS);
153 m_RenderWindow->GetRenderer()->SetMapperID(
id);
174 m_RenderWindow->GetRenderer()->PrepareRender();
176 this->GetVtkRenderWindow()->Render();
177 this->GetVtkRenderWindow()->WaitForCompletion();
178 if (m_AutomaticallyCloseRenderWindow ==
false)
181 this->GetVtkRenderWindow()->GetInteractor()->Start();
186 MITK_ERROR <<
"No images loaded in data storage!";
199 for (
int i = 1; i < argc; ++i)
202 std::string tmp = argv[i];
203 if ((tmp.compare(
"-T")) && (tmp.compare(
"-V")))
205 this->AddToStorage(tmp);
217 ->GetSliceNavigationController()
218 ->SetDefaultViewDirection(viewDirection);
227 sliceNavigationController->ReorientSlices(origin, rotation);
232 return m_RenderWindow->GetRenderer()->GetVtkRenderer();
242 return m_RenderWindow->GetVtkRenderWindow();
253 if (vtkTesting::Test(argc, argv, this->GetVtkRenderWindow(), threshold) == 1)
262 vtkSmartPointer<vtkRenderer> renderer = this->GetVtkRenderer();
263 bool doubleBuffering(renderer->GetRenderWindow()->GetDoubleBuffer());
264 renderer->GetRenderWindow()->DoubleBufferOff();
267 magnifier->SetInput(renderer);
268 magnifier->SetMagnification(1);
271 fileWriter->SetInputConnection(magnifier->GetOutputPort());
272 fileWriter->SetFileName(fileName.c_str());
275 renderer->GetRenderWindow()->SetDoubleBuffer(doubleBuffering);
280 m_AutomaticallyCloseRenderWindow = automaticallyCloseRenderWindow;
285 this->SaveAsPNG(fileName);
296 catch (itk::ExceptionObject &e)
298 MITK_ERROR <<
"Failed loading test data '" << filename <<
"': " << e.what();
void SaveAsPNG(std::string fileName)
Method can be used to save a screenshot (e.g. reference screenshot as a .png file.
virtual bool InitializeViews(const BaseGeometry *geometry, RequestType type=REQUEST_UPDATE_ALL, bool preserveRoughOrientationInWorldSpace=false)
void SetViewDirection(mitk::SliceNavigationController::ViewDirection viewDirection)
Set the view direction of the renderwindow (e.g. sagittal, coronal, axial)
RenderingTestHelper(int width, int height, int argc, char *argv[], mitk::BaseRenderer::RenderingMode::Type renderingMode=mitk::BaseRenderer::RenderingMode::Standard)
Generate a rendering test helper object including a render window of the size width * height (in pixe...
static BaseRenderer * GetInstance(vtkRenderWindow *renWin)
vtkRenderWindow * GetVtkRenderWindow()
Getter for the vtkRenderWindow which should be used to call vtkRegressionTestImage.
void SetMapperID(mitk::BaseRenderer::StandardMapperSlot id)
SetMapperID Change between Standard2D and 3D mappers.
bool IsAdvancedOpenGL()
Returns true if the opengl context is compatible for advanced vtk effects.
static mitk::DataStorage::Pointer GetDataStorage()
void SetMapperIDToRender3D()
SetMapperIDToRender3D Convenience method to render in a 3D renderwindow.
void SaveReferenceScreenShot(std::string fileName)
SaveReferenceScreenShot Convenience method to save a reference screen shot.
void SetInputFileNames(int argc, char *argv[])
This method tries to parse the given argv for files (e.g. images) and load them into a member datasto...
bool CompareRenderWindowAgainstReference(int argc, char *argv[], double threshold=10.0)
CompareRenderWindowAgainstReference Convenience method to compare the image rendered in the internal ...
void SetImageProperty(const char *propertyKey, mitk::BaseProperty *property)
This method set the property of the member datastorage.
void ReorientSlices(mitk::Point3D origin, mitk::Vector3D rotation)
Reorient the slice (e.g. rotation and translation like the swivel mode).
Abstract base class for properties.
mitk::DataStorage::Pointer m_DataStorage
void Render()
Render everything into an mitkRenderWindow. Call SetViewDirection() and SetProperty() before this met...
static RenderingManager * GetInstance()
static const std::string filename
void AddToStorage(const std::string &filename)
This method tries to load the given file into a member datastorage, in order to render it...
mitk::DataStorage::Pointer GetDataStorage()
Returns the datastorage, in order to modify the data inside a rendering test.
static Pointer New(const char *_arg)
void Initialize(int width, int height, mitk::BaseRenderer::RenderingMode::Type renderingMode=mitk::BaseRenderer::RenderingMode::Standard)
Initialize Internal method to initialize the renderwindow and set the datastorage.
vtkRenderer * GetVtkRenderer()
Getter for the vtkRenderer.
void SetAutomaticallyCloseRenderWindow(bool automaticallyCloseRenderWindow)
SetStopRenderWindow Convenience method to make the renderwindow hold after rendering. Usefull for debugging.
void SetMapperIDToRender2D()
SetMapperIDToRender2D Convenience method to render in a 2D renderwindow.
void PrintGLInfo()
Prints the opengl information, e.g. version, vendor and extensions, This function can only be called ...
static DataStorage::SetOfObjects::Pointer Load(const std::string &path, DataStorage &storage)
Load a file into the given DataStorage.
void AddNodeToStorage(mitk::DataNode::Pointer node)
AddNodeToStorage Add a node to the datastorage and perform a reinit which is necessary for rendering...
ViewDirection
Possible view directions, Original will uses the PlaneGeometry instances in a SlicedGeometry3D provid...
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.