Medical Imaging Interaction Toolkit  2025.12.02
Medical Imaging Interaction Toolkit
mitkRenderingTestHelper.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef mitkRenderingTestHelper_h
14 #define mitkRenderingTestHelper_h
15 
16 #include <mitkDataStorage.h>
17 #include <mitkRenderWindow.h>
18 #include <vtkSmartPointer.h>
19 
20 #include <MitkTestingHelperExports.h>
21 #include <mitkIOUtil.h>
22 
23 class vtkRenderWindow;
24 class vtkRenderer;
25 
26 namespace mitk
27 {
28  class MITKTESTINGHELPER_EXPORT RenderingTestHelper
29  {
30  public:
41  int width,
42  int height,
43  int argc,
44  char *argv[],
45  AntiAliasing antiAliasing = AntiAliasing::None);
46 
50  int width,
51  int height,
52  AntiAliasing antiAliasing = AntiAliasing::None);
53 
56 
59  vtkRenderer *GetVtkRenderer();
60 
63  vtkRenderWindow *GetVtkRenderWindow();
64 
68  void SaveAsPNG(std::string fileName);
69 
76  void SetAutomaticallyCloseRenderWindow(bool automaticallyCloseRenderWindow);
77 
84  void SetImageProperty(const char *propertyKey, mitk::BaseProperty *property);
85 
89 
93 
96  void Render();
97 
100  mitk::DataStorage::Pointer GetDataStorage();
101 
107 
112  void AddNodeToStorage(mitk::DataNode::Pointer node);
113 
119 
124 
129  void SaveReferenceScreenShot(std::string fileName);
130 
148  bool CompareRenderWindowAgainstReference(int argc, char *argv[], double threshold = 10.0);
149 
157  {
158  private:
162  std::vector<char *> argv;
163  std::vector<std::vector<char>> argvec;
164 
165  public:
166  ArgcHelperClass(const std::vector<std::string> &argstrings)
167  : argv(argstrings.size() + 1), argvec(argstrings.size() + 1)
168  {
169  std::vector<std::string> cmdArgs;
170  cmdArgs.push_back(mitk::IOUtil::GetProgramPath());
171  cmdArgs.insert(cmdArgs.end(), argstrings.begin(), argstrings.end());
172  for (std::size_t i = 0; i < cmdArgs.size(); ++i)
173  {
174  argvec[i].assign(cmdArgs[i].begin(), cmdArgs[i].end());
175  argvec[i].push_back('\0');
176  argv[i] = &argvec[i][0];
177  }
178  }
179  char **GetArgv() { return &argv[0]; }
180  int GetArgc() { return argv.size(); }
181  };
182 
183  protected:
191  int width,
192  int height,
193  AntiAliasing antiAliasing = AntiAliasing::None);
194 
198  void AddToStorage(const std::string &filename);
199 
206  void SetInputFileNames(int argc, char *argv[]);
207 
208  mitk::RenderWindow::Pointer m_RenderWindow; //<< Contains the mitkRenderWindow into which the test renders the data
209  mitk::DataStorage::Pointer m_DataStorage; //<< Contains the mitkDataStorage which contains the data to be rendered
210  bool
211  m_AutomaticallyCloseRenderWindow; //<< Flag indicating whether the renderwindow should automatically close (true,
212  // default) or stay open (false). Useful for debugging.
213  };
214 } // namespace mitk
215 #endif
Abstract base class for properties.
StandardMapperSlot
Defines which kind of mapper (e.g. 2D or 3D) should be used.
static std::string GetProgramPath()
The ArgcHelperClass class is a convenience class to convert a vector of strings to the standard c++ a...
ArgcHelperClass(const std::vector< std::string > &argstrings)
mitk::DataStorage::Pointer GetDataStorage()
Returns the datastorage, in order to modify the data inside a rendering test.
void SetAutomaticallyCloseRenderWindow(bool automaticallyCloseRenderWindow)
SetStopRenderWindow Convenience method to make the renderwindow hold after rendering....
void SetViewDirection(mitk::AnatomicalPlane viewDirection)
Set the view direction of the renderwindow (e.g. sagittal, coronal, axial)
void SetImageProperty(const char *propertyKey, mitk::BaseProperty *property)
This method set the property of the member datastorage.
mitk::DataStorage::Pointer m_DataStorage
bool CompareRenderWindowAgainstReference(int argc, char *argv[], double threshold=10.0)
CompareRenderWindowAgainstReference Convenience method to compare the image rendered in the internal ...
mitk::RenderWindow::Pointer m_RenderWindow
vtkRenderWindow * GetVtkRenderWindow()
Getter for the vtkRenderWindow which should be used to call vtkRegressionTestImage.
void SaveAsPNG(std::string fileName)
Method can be used to save a screenshot (e.g. reference screenshot as a .png file.
void Render()
Render everything into an mitkRenderWindow. Call SetViewDirection() and SetProperty() before this met...
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...
void SaveReferenceScreenShot(std::string fileName)
SaveReferenceScreenShot Convenience method to save a reference screen shot.
RenderingTestHelper(int width, int height, AntiAliasing antiAliasing=AntiAliasing::None)
Generate a rendering test helper object including a render window of the size width * height (in pixe...
void SetMapperIDToRender2D()
SetMapperIDToRender2D Convenience method to render in a 2D renderwindow.
void AddToStorage(const std::string &filename)
This method tries to load the given file into a member datastorage, in order to render it.
void ReorientSlices(mitk::Point3D origin, mitk::Vector3D rotation)
Reorient the slice (e.g. rotation and translation like the swivel mode).
vtkRenderer * GetVtkRenderer()
Getter for the vtkRenderer.
void SetMapperID(mitk::BaseRenderer::StandardMapperSlot id)
SetMapperID Change between Standard2D and 3D mappers.
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...
void AddNodeToStorage(mitk::DataNode::Pointer node)
AddNodeToStorage Add a node to the datastorage and perform a reinit which is necessary for rendering.
void SetMapperIDToRender3D()
SetMapperIDToRender3D Convenience method to render in a 3D renderwindow.
void Initialize(int width, int height, AntiAliasing antiAliasing=AntiAliasing::None)
Initialize Internal method to initialize the renderwindow and set the datastorage.
Find image slices visible on a given plane.