Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkSurfaceVtkMapper2DTest.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 // MITK
18 #include <mitkIOUtil.h>
21 #include <mitkTestFixture.h>
22 #include <mitkTestingMacros.h>
23 
24 class mitkSurfaceVtkMapper2DTestSuite : public mitk::TestFixture
25 {
26  CPPUNIT_TEST_SUITE(mitkSurfaceVtkMapper2DTestSuite);
27  MITK_TEST(RenderBall);
28  MITK_TEST(RenderOpaqueBall);
29  MITK_TEST(RenderRedBall);
30  MITK_TEST(RenderBallWithGeometry);
31  MITK_TEST(RenderRedBinary);
32  CPPUNIT_TEST_SUITE_END();
33 
34 private:
36  mitk::RenderingTestHelper m_RenderingTestHelper;
37  std::vector<std::string> m_CommandlineArgs;
38  std::string m_PathToBall;
39  std::string m_PathToBinary;
40 
41 public:
47  mitkSurfaceVtkMapper2DTestSuite() : m_RenderingTestHelper(640, 480) {}
52  void setUp()
53  {
54  m_RenderingTestHelper = mitk::RenderingTestHelper(640, 480);
55 
56  m_PathToBall = GetTestDataFilePath("ball.stl");
57  m_PathToBinary = GetTestDataFilePath("binary.stl");
58 
59  // Build a command line for the vtkTesting::Test method.
60  // See VTK documentation and RenderingTestHelper for more information.
61  // Use the following command line option to save the difference image
62  // and the test image in some tmp folder
63  // m_CommandlineArgs.push_back("-T");
64  // m_CommandlineArgs.push_back("/path/to/save/tmp/difference/images/");
65  m_CommandlineArgs.push_back("-V");
66  }
67 
68  void tearDown() {}
69  void RenderBall()
70  {
72  node->SetData(mitk::IOUtil::Load(m_PathToBall)[0]);
73  m_RenderingTestHelper.AddNodeToStorage(node);
74 
75  // reference screenshot for this test
76  m_CommandlineArgs.push_back(GetTestDataFilePath("RenderingTestData/ReferenceScreenshots/ball640x480REF.png"));
77  // Convert vector of strings to argc/argv
78  mitk::RenderingTestHelper::ArgcHelperClass arg(m_CommandlineArgs);
79  CPPUNIT_ASSERT(m_RenderingTestHelper.CompareRenderWindowAgainstReference(arg.GetArgc(), arg.GetArgv()) == true);
80  }
81 
82  void RenderBallWithGeometry()
83  {
85  node->SetData(mitk::IOUtil::Load(m_PathToBall)[0]);
86  // Modify the geometry a little
87  mitk::Vector3D spacing;
88  spacing[0] = 0.5;
89  spacing[1] = 1.5;
90  spacing[2] = 0.75;
91  node->GetData()->GetGeometry()->SetSpacing(spacing);
92  m_RenderingTestHelper.AddNodeToStorage(node);
93 
94  // reference screenshot for this test
95  m_CommandlineArgs.push_back(
96  GetTestDataFilePath("RenderingTestData/ReferenceScreenshots/ballWithGeometry640x480REF.png"));
97  // Convert vector of strings to argc/argv
98  mitk::RenderingTestHelper::ArgcHelperClass arg(m_CommandlineArgs);
99  CPPUNIT_ASSERT(m_RenderingTestHelper.CompareRenderWindowAgainstReference(arg.GetArgc(), arg.GetArgv()) == true);
100  }
101 
102  void RenderOpaqueBall()
103  {
105  node->SetData(mitk::IOUtil::Load(m_PathToBall)[0]);
106  node->SetOpacity(0.5);
107  m_RenderingTestHelper.AddNodeToStorage(node);
108 
109  // reference screenshot for this test
110  m_CommandlineArgs.push_back(
111  GetTestDataFilePath("RenderingTestData/ReferenceScreenshots/ballOpacity640x480REF.png"));
112  // Convert vector of strings to argc/argv
113  mitk::RenderingTestHelper::ArgcHelperClass arg(m_CommandlineArgs);
114  CPPUNIT_ASSERT(m_RenderingTestHelper.CompareRenderWindowAgainstReference(arg.GetArgc(), arg.GetArgv()) == true);
115  }
116 
117  void RenderRedBall()
118  {
120  node->SetData(mitk::IOUtil::Load(m_PathToBall)[0]);
121  node->SetProperty("color", mitk::ColorProperty::New(1.0f, 0.0f, 0.0f));
122  m_RenderingTestHelper.AddNodeToStorage(node);
123 
124  // reference screenshot for this test
125  m_CommandlineArgs.push_back(
126  GetTestDataFilePath("RenderingTestData/ReferenceScreenshots/ballColorRed640x480REF.png"));
127  // Convert vector of strings to argc/argv
128  mitk::RenderingTestHelper::ArgcHelperClass arg(m_CommandlineArgs);
129  CPPUNIT_ASSERT(m_RenderingTestHelper.CompareRenderWindowAgainstReference(arg.GetArgc(), arg.GetArgv()) == true);
130  }
131 
132  void RenderRedBinary()
133  {
135  node->SetData(mitk::IOUtil::Load(m_PathToBinary)[0]);
136  node->SetProperty("color", mitk::ColorProperty::New(1.0f, 0.0f, 0.0f));
137  m_RenderingTestHelper.AddNodeToStorage(node);
138 
139  // reference screenshot for this test
140  m_CommandlineArgs.push_back(
141  GetTestDataFilePath("RenderingTestData/ReferenceScreenshots/binaryColorRed640x480REF.png"));
142  // Convert vector of strings to argc/argv
143  mitk::RenderingTestHelper::ArgcHelperClass arg(m_CommandlineArgs);
144  CPPUNIT_ASSERT(m_RenderingTestHelper.CompareRenderWindowAgainstReference(arg.GetArgc(), arg.GetArgv()) == true);
145  }
146 };
147 MITK_TEST_SUITE_REGISTRATION(mitkSurfaceVtkMapper2D)
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
static Pointer New()
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
static std::string GetTestDataFilePath(const std::string &testData)
Get the absolute path for test data.
bool CompareRenderWindowAgainstReference(int argc, char *argv[], double threshold=10.0)
CompareRenderWindowAgainstReference Convenience method to compare the image rendered in the internal ...
static Pointer New()
Test fixture for parameterized tests.
The ArgcHelperClass class is a convinience class to convert a vector of strings to the standard c++ a...
static DataStorage::SetOfObjects::Pointer Load(const std::string &path, DataStorage &storage)
Load a file into the given DataStorage.
Definition: mitkIOUtil.cpp:483
void AddNodeToStorage(mitk::DataNode::Pointer node)
AddNodeToStorage Add a node to the datastorage and perform a reinit which is necessary for rendering...