Medical Imaging Interaction Toolkit  2024.06.00
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 
88  void SetViewDirection(mitk::AnatomicalPlane viewDirection);
89 
92  void ReorientSlices(mitk::Point3D origin, mitk::Vector3D rotation);
93 
96  void Render();
97 
100  mitk::DataStorage::Pointer GetDataStorage();
101 
106  void SetMapperID(mitk::BaseRenderer::StandardMapperSlot id);
107 
112  void AddNodeToStorage(mitk::DataNode::Pointer node);
113 
118  void SetMapperIDToRender3D();
119 
123  void SetMapperIDToRender2D();
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:
190  void Initialize(
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
mitkRenderWindow.h
mitk::BaseProperty
Abstract base class for properties.
Definition: mitkBaseProperty.h:36
mitk::RenderingTestHelper::ArgcHelperClass::GetArgv
char ** GetArgv()
Definition: mitkRenderingTestHelper.h:179
mitkDataStorage.h
mitk::AntiAliasing
AntiAliasing
Definition: mitkAntiAliasing.h:18
mitk::RenderingTestHelper::m_DataStorage
mitk::DataStorage::Pointer m_DataStorage
Definition: mitkRenderingTestHelper.h:209
itk::SmartPointer< Self >
mitk::RenderingTestHelper::ArgcHelperClass::ArgcHelperClass
ArgcHelperClass(const std::vector< std::string > &argstrings)
Definition: mitkRenderingTestHelper.h:166
mitk::RenderingTestHelper::ArgcHelperClass::GetArgc
int GetArgc()
Definition: mitkRenderingTestHelper.h:180
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
mitk::BaseRenderer::StandardMapperSlot
StandardMapperSlot
Defines which kind of mapper (e.g. 2D or 3D) should be used.
Definition: mitkBaseRenderer.h:66
mitk::AntiAliasing::None
@ None
mitk::RenderingTestHelper
Definition: mitkRenderingTestHelper.h:28
mitk::RenderingTestHelper::ArgcHelperClass
The ArgcHelperClass class is a convenience class to convert a vector of strings to the standard c++ a...
Definition: mitkRenderingTestHelper.h:156
mitk::AnatomicalPlane
AnatomicalPlane
Definition: mitkAnatomicalPlanes.h:18
mitk::Vector< ScalarType, 3 >
mitk::IOUtil::GetProgramPath
static std::string GetProgramPath()
mitk::Point< ScalarType, 3 >
mitk::RenderingTestHelper::m_RenderWindow
mitk::RenderWindow::Pointer m_RenderWindow
Definition: mitkRenderingTestHelper.h:208
mitkIOUtil.h
mitk::RenderingTestHelper::m_AutomaticallyCloseRenderWindow
bool m_AutomaticallyCloseRenderWindow
Definition: mitkRenderingTestHelper.h:211