Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkSplineVtkMapper3DTest.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 <mitkSplineVtkMapper3D.h>
22 #include <mitkTestFixture.h>
23 #include <mitkTestingMacros.h>
24 
25 #include <vtkDebugLeaks.h>
26 
27 class mitkSplineVtkMapper3DTestSuite : public mitk::TestFixture
28 {
29  CPPUNIT_TEST_SUITE(mitkSplineVtkMapper3DTestSuite);
30 
32  vtkDebugLeaks::SetExitError(0);
33 
34  MITK_TEST(RenderSpline);
35  MITK_TEST(RenderBlueSpline);
36  MITK_TEST(RenderThickSpline);
37  // MITK_TEST(RenderThickTranslucentSpline);
38  MITK_TEST(RenderLowResolutionSpline);
39  CPPUNIT_TEST_SUITE_END();
40 
41 private:
43  mitk::RenderingTestHelper m_RenderingTestHelper;
44  std::vector<std::string> m_CommandlineArgs;
45  std::string m_PathToPointSet;
46 
47 public:
53  mitkSplineVtkMapper3DTestSuite() : m_RenderingTestHelper(640, 480) {}
58  void setUp()
59  {
60  m_RenderingTestHelper = mitk::RenderingTestHelper(640, 480);
61 
62  // disables anti-aliasing which is enabled on several graphics cards and
63  // causes problems when doing a pixel-wise comparison to a reference image
64  m_RenderingTestHelper.GetVtkRenderWindow()->SetMultiSamples(0);
65 
66  m_PathToPointSet =
67  GetTestDataFilePath("InteractionTestData/ReferenceData/PointSetDataInteractor_PointsAdd2d3d.mps");
68 
69  // Build a command line for the vtkTesting::Test method.
70  // See VTK documentation and RenderingTestHelper for more information.
71  // Use the following command line option to save the difference image
72  // and the test image in some tmp folder
73  // m_CommandlineArgs.push_back("-T");
74  // m_CommandlineArgs.push_back("/path/to/save/tmp/difference/images/");
75  m_CommandlineArgs.push_back("-V");
76  }
77 
78  void tearDown() {}
79  void RenderSpline()
80  {
82  node->SetData(mitk::IOUtil::Load(m_PathToPointSet)[0]);
83 
85  node->SetMapper(mitk::BaseRenderer::StandardMapperSlot::Standard3D, mapper);
86 
87  m_RenderingTestHelper.AddNodeToStorage(node);
88  m_RenderingTestHelper.SetMapperIDToRender3D();
89 
90  // reference screenshot for this test
91  m_CommandlineArgs.push_back(GetTestDataFilePath("RenderingTestData/ReferenceScreenshots/spline_linewidth_1.png"));
92  // Convert vector of strings to argc/argv
93  mitk::RenderingTestHelper::ArgcHelperClass arg(m_CommandlineArgs);
94  CPPUNIT_ASSERT(m_RenderingTestHelper.CompareRenderWindowAgainstReference(arg.GetArgc(), arg.GetArgv()) == true);
95  }
96 
97  void RenderBlueSpline()
98  {
100  node->SetData(mitk::IOUtil::Load(m_PathToPointSet)[0]);
101  node->SetProperty("color", mitk::ColorProperty::New(0.0f, 0.0f, 1.0f));
102 
104  node->SetMapper(mitk::BaseRenderer::StandardMapperSlot::Standard3D, mapper);
105 
106  m_RenderingTestHelper.AddNodeToStorage(node);
107  m_RenderingTestHelper.SetMapperIDToRender3D();
108  // reference screenshot for this test
109  m_CommandlineArgs.push_back(
110  GetTestDataFilePath("RenderingTestData/ReferenceScreenshots/spline_blue_linewidth_1.png"));
111  // Convert vector of strings to argc/argv
112  mitk::RenderingTestHelper::ArgcHelperClass arg(m_CommandlineArgs);
113  CPPUNIT_ASSERT(m_RenderingTestHelper.CompareRenderWindowAgainstReference(arg.GetArgc(), arg.GetArgv()) == true);
114  }
115 
116  void RenderThickSpline()
117  {
119  node->SetData(mitk::IOUtil::Load(m_PathToPointSet)[0]);
120 
121  node->SetProperty("line width", mitk::IntProperty::New(8));
122 
124  node->SetMapper(mitk::BaseRenderer::StandardMapperSlot::Standard3D, mapper);
125 
126  m_RenderingTestHelper.AddNodeToStorage(node);
127  m_RenderingTestHelper.SetMapperIDToRender3D();
128  // reference screenshot for this test
129  m_CommandlineArgs.push_back(GetTestDataFilePath("RenderingTestData/ReferenceScreenshots/spline_linewidth_8.png"));
130  // Convert vector of strings to argc/argv
131  mitk::RenderingTestHelper::ArgcHelperClass arg(m_CommandlineArgs);
132  CPPUNIT_ASSERT(m_RenderingTestHelper.CompareRenderWindowAgainstReference(arg.GetArgc(), arg.GetArgv()) == true);
133  }
134 
135  // Currently, rending of objects with opacity < 1.0 fails on the dashboard
136  // see bug 19575
137  // void RenderThickTranslucentSpline()
138  //{
139  // mitk::DataNode::Pointer node = mitk::DataNode::New();
140  // node->SetData(mitk::IOUtil::Load(m_PathToPointSet)[0]);
141  // node->SetOpacity(0.5f);
142 
143  // node->SetProperty("line width", mitk::IntProperty::New(8));
144 
145  // mitk::SplineVtkMapper3D::Pointer mapper = mitk::SplineVtkMapper3D::New();
146  // node->SetMapper(mitk::BaseRenderer::StandardMapperSlot::Standard3D, mapper);
147 
148  // m_RenderingTestHelper.AddNodeToStorage(node);
149  // m_RenderingTestHelper.SetMapperIDToRender3D();
150  // //reference screenshot for this test
151  // m_CommandlineArgs.push_back(GetTestDataFilePath("RenderingTestData/ReferenceScreenshots/spline_translucent_linewidth_8.png"));
152  // //Convert vector of strings to argc/argv
153  // mitk::RenderingTestHelper::ArgcHelperClass arg(m_CommandlineArgs);
154  // CPPUNIT_ASSERT(m_RenderingTestHelper.CompareRenderWindowAgainstReference(arg.GetArgc(), arg.GetArgv()) == true);
155  //}
156 
157  void RenderLowResolutionSpline()
158  {
160  node->SetData(mitk::IOUtil::Load(m_PathToPointSet)[0]);
161 
163  node->SetMapper(mitk::BaseRenderer::StandardMapperSlot::Standard3D, mapper);
164 
165  mapper->SetSplineResolution(50);
166 
167  m_RenderingTestHelper.AddNodeToStorage(node);
168  m_RenderingTestHelper.SetMapperIDToRender3D();
169  // reference screenshot for this test
170  m_CommandlineArgs.push_back(
171  GetTestDataFilePath("RenderingTestData/ReferenceScreenshots/spline_lowRes_linewidth_1.png"));
172  // Convert vector of strings to argc/argv
173  mitk::RenderingTestHelper::ArgcHelperClass arg(m_CommandlineArgs);
174  CPPUNIT_ASSERT(m_RenderingTestHelper.CompareRenderWindowAgainstReference(arg.GetArgc(), arg.GetArgv()) == true);
175  }
176 };
177 MITK_TEST_SUITE_REGISTRATION(mitkSplineVtkMapper3D)
static Pointer New()
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
vtkRenderWindow * GetVtkRenderWindow()
Getter for the vtkRenderWindow which should be used to call vtkRegressionTestImage.
static Pointer New()
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
void SetMapperIDToRender3D()
SetMapperIDToRender3D Convenience method to render in a 3D renderwindow.
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 Pointer New()
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...