14 #include <vtkCamera.h> 15 #include <vtkOpenGLRenderWindow.h> 16 #include <vtkPNGWriter.h> 17 #include <vtkRenderLargeImage.h> 18 #include <vtkRenderWindow.h> 19 #include <vtkRenderWindowInteractor.h> 33 #define RESIZE_WORKAROUND 37 #ifdef RESIZE_WORKAROUND 38 #include "vtkWin32OpenGLRenderWindow.h" 42 #include "vtkTesting.h" 47 : m_AutomaticallyCloseRenderWindow(true)
53 int width,
int height,
int argc,
char *argv[],
AntiAliasing antiAliasing)
69 if (0 == renderWindow->SupportsOpenGL())
71 auto openGLRenderWindow =
dynamic_cast<vtkOpenGLRenderWindow*
>(renderWindow);
73 auto message =
nullptr != openGLRenderWindow
74 ? openGLRenderWindow->GetOpenGLSupportMessage()
75 : std::string(
"No details available.");
86 #ifdef RESIZE_WORKAROUND 88 HWND hWnd =
static_cast<vtkWin32OpenGLRenderWindow *
>(this->
GetVtkRenderWindow())->GetWindowId();
93 r.right = r.left + width;
94 r.bottom = r.top + height;
96 LONG style = GetWindowLong(hWnd, GWL_STYLE);
97 AdjustWindowRect(&r, style, FALSE);
104 if (GetWindowRect(hWnd, &rect))
106 int width = rect.right - rect.left;
107 int height = rect.bottom - rect.top;
114 SetWindowPos(hWnd, HWND_TOP, 0, 0, r.right - r.left, r.bottom - r.top, SWP_NOZORDER);
116 GetWindowRect(hWnd, &rect);
118 int width2 = rect.right - rect.left;
119 int height2 = rect.bottom - rect.top;
125 SetWindowPos(hWnd, HWND_TOP, 0, 0, 2 * (r.right - r.left) - width2, 2 * (r.bottom - r.top) - height2, SWP_NOZORDER);
171 MITK_ERROR <<
"No images loaded in data storage!";
184 for (
int i = 1; i < argc; ++i)
187 std::string tmp = argv[i];
188 if ((tmp.compare(
"-T")) && (tmp.compare(
"-V")))
202 ->GetSliceNavigationController()
203 ->SetDefaultViewDirection(viewDirection);
212 sliceNavigationController->ReorientSlices(origin, rotation);
248 bool doubleBuffering(renderer->GetRenderWindow()->GetDoubleBuffer());
249 renderer->GetRenderWindow()->DoubleBufferOff();
251 vtkSmartPointer<vtkRenderLargeImage> magnifier = vtkSmartPointer<vtkRenderLargeImage>::New();
252 magnifier->SetInput(renderer);
253 magnifier->SetMagnification(1);
255 vtkSmartPointer<vtkImageWriter> fileWriter = vtkSmartPointer<vtkPNGWriter>::New();
256 fileWriter->SetInputConnection(magnifier->GetOutputPort());
257 fileWriter->SetFileName(fileName.c_str());
260 renderer->GetRenderWindow()->SetDoubleBuffer(doubleBuffering);
281 catch (
const itk::ExceptionObject &e )
283 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 Initialize(int width, int height, AntiAliasing antiAliasing=AntiAliasing::None)
Initialize Internal method to initialize the renderwindow and set the datastorage.
void SetViewDirection(mitk::SliceNavigationController::ViewDirection viewDirection)
Set the view direction of the renderwindow (e.g. sagittal, coronal, axial)
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.
void SetAntiAliasing(AntiAliasing antiAliasing)
mitk::DataStorage::Pointer m_DataStorage
bool m_AutomaticallyCloseRenderWindow
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.
void Render()
Render everything into an mitkRenderWindow. Call SetViewDirection() and SetProperty() before this met...
static RenderingManager * GetInstance()
ViewDirection
Possible view directions, Original will uses the PlaneGeometry instances in a SlicedGeometry3D provid...
Specialized mitk::Exception for skipped tests.
mitk::RenderWindow::Pointer m_RenderWindow
void AddToStorage(const std::string &filename)
This method tries to load the given file into a member datastorage, in order to render it...
RenderingTestHelper(int width, int height, int argc, char *argv[], AntiAliasing antiAliasing=AntiAliasing::None)
Generate a rendering test helper object including a render window of the size width * height (in pixe...
mitk::DataStorage::Pointer GetDataStorage()
Returns the datastorage, in order to modify the data inside a rendering test.
static Pointer New(const char *_arg)
#define mitkThrowException(classname)
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 AddNodeToStorage(mitk::DataNode::Pointer node)
AddNodeToStorage Add a node to the datastorage and perform a reinit which is necessary for rendering...
static DataStorage::SetOfObjects::Pointer Load(const std::string &path, DataStorage &storage, const ReaderOptionsFunctorBase *optionsCallback=nullptr)
Load a file into the given DataStorage.