Medical Imaging Interaction Toolkit  2018.4.99-3e3f1a6e
Medical Imaging Interaction Toolkit
mitkLogoAnnotationTest.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 (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 // MITK
14 #include <mitkIOUtil.h>
15 
17 #include <mitkLogoAnnotation.h>
19 #include <mitkTestFixture.h>
20 #include <mitkTestingMacros.h>
21 
22 class mitkLogoAnnotationTestSuite : public mitk::TestFixture
23 {
24  CPPUNIT_TEST_SUITE(mitkLogoAnnotationTestSuite);
25  MITK_TEST(RenderMbiLogo);
26  MITK_TEST(RenderLogo);
27 
28  CPPUNIT_TEST_SUITE_END();
29 
30 private:
32  mitk::RenderingTestHelper m_RenderingTestHelper;
33  std::vector<std::string> m_CommandlineArgs;
34  std::string m_PathToBall;
35  std::string m_PathToImage;
36  std::string m_PathToLogo;
37  std::string m_PathToMitkLogo;
38  std::string m_ReferenceImagePath;
39 
40 public:
46  mitkLogoAnnotationTestSuite() : m_RenderingTestHelper(300, 300) {}
51  void setUp()
52  {
53  m_RenderingTestHelper = mitk::RenderingTestHelper(300, 300);
54 
55  m_PathToBall = GetTestDataFilePath("ball.stl");
56  m_PathToImage = GetTestDataFilePath("Pic3D.nrrd");
57  m_PathToLogo = GetTestDataFilePath("RenderingTestData/texture.jpg");
58  m_PathToMitkLogo = GetTestDataFilePath("RenderingTestData/defaultWatermark.png");
59  m_ReferenceImagePath = "RenderingTestData/ReferenceScreenshots/Annotation/";
60 
61  // Build a command line for the vtkTesting::Test method.
62  // See VTK documentation and RenderingTestHelper for more information.
63  // Use the following command line option to save the difference image
64  // and the test image in some tmp folder
65  // m_CommandlineArgs.push_back("-T");
66  // m_CommandlineArgs.push_back("/path/to/save/tmp/difference/images/");
67  m_CommandlineArgs.push_back("-V");
68  }
69 
70  void tearDown() {}
71  void RenderMbiLogo()
72  {
74  ballnode->SetData(mitk::IOUtil::Load(m_PathToBall)[0]);
75  m_RenderingTestHelper.AddNodeToStorage(ballnode);
76 
78  imagenode->SetData(mitk::IOUtil::Load(m_PathToImage)[0]);
79  m_RenderingTestHelper.AddNodeToStorage(imagenode);
80 
81  std::string refImagePath = GetTestDataFilePath(m_ReferenceImagePath + "LogoAnnotation_mitkLogo.png");
82 
83  // reference screenshot for this test
84  m_CommandlineArgs.push_back(refImagePath);
85  // Convert vector of strings to argc/argv
86  mitk::RenderingTestHelper::ArgcHelperClass arg(m_CommandlineArgs);
88 
90 
91  logoAnnotation->SetLogoImagePath(m_PathToMitkLogo);
92  logoAnnotation->LoadLogoImageFromPath();
93  logoAnnotation->SetOpacity(0.5);
95  offset.Fill(0.03);
96  logoAnnotation->SetOffsetVector(offset);
97  logoAnnotation->SetRelativeSize(0.5);
98  logoAnnotation->SetCornerPosition(1);
99 
100  mitk::BaseRenderer *renderer = mitk::BaseRenderer::GetInstance(m_RenderingTestHelper.GetVtkRenderWindow());
101  mitk::ManualPlacementAnnotationRenderer::AddAnnotation(logoAnnotation.GetPointer(), renderer);
102 
103  m_RenderingTestHelper.Render();
104 // m_RenderingTestHelper.SaveReferenceScreenShot(refImagePath);
105  m_RenderingTestHelper.SetAutomaticallyCloseRenderWindow(true);
106  CPPUNIT_ASSERT(m_RenderingTestHelper.CompareRenderWindowAgainstReference(arg.GetArgc(), arg.GetArgv()) == true);
107  }
108 
109  void RenderLogo()
110  {
112  ballnode->SetData(mitk::IOUtil::Load(m_PathToBall)[0]);
113  m_RenderingTestHelper.AddNodeToStorage(ballnode);
114 
116  imagenode->SetData(mitk::IOUtil::Load(m_PathToImage)[0]);
117  m_RenderingTestHelper.AddNodeToStorage(imagenode);
118 
119  std::string refImagePath = GetTestDataFilePath(m_ReferenceImagePath + "LogoAnnotation.png");
120 
121  // reference screenshot for this test
122  m_CommandlineArgs.push_back(refImagePath);
123  // Convert vector of strings to argc/argv
124  mitk::RenderingTestHelper::ArgcHelperClass arg(m_CommandlineArgs);
126 
128 
129  logoAnnotation->SetLogoImagePath(m_PathToLogo);
130  logoAnnotation->LoadLogoImageFromPath();
131 
132  mitk::BaseRenderer *renderer = mitk::BaseRenderer::GetInstance(m_RenderingTestHelper.GetVtkRenderWindow());
133  mitk::ManualPlacementAnnotationRenderer::AddAnnotation(logoAnnotation.GetPointer(), renderer);
134 
135  m_RenderingTestHelper.Render();
136 // m_RenderingTestHelper.SaveReferenceScreenShot(refImagePath);
137  m_RenderingTestHelper.SetAutomaticallyCloseRenderWindow(true);
138  CPPUNIT_ASSERT(m_RenderingTestHelper.CompareRenderWindowAgainstReference(arg.GetArgc(), arg.GetArgv()) == true);
139  }
140 };
141 
142 MITK_TEST_SUITE_REGISTRATION(mitkLogoAnnotation)
void SetViewDirection(mitk::SliceNavigationController::ViewDirection viewDirection)
Set the view direction of the renderwindow (e.g. sagittal, coronal, axial)
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
static BaseRenderer * GetInstance(vtkRenderWindow *renWin)
vtkRenderWindow * GetVtkRenderWindow()
Getter for the vtkRenderWindow which should be used to call vtkRegressionTestImage.
Organizes the rendering process.
#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 Vector3D offset
static Pointer New()
void Render()
Render everything into an mitkRenderWindow. Call SetViewDirection() and SetProperty() before this met...
static Pointer New()
Test fixture for parameterized tests.
static void AddAnnotation(Annotation *Annotation, const std::string &rendererID)
The ArgcHelperClass class is a convinience class to convert a vector of strings to the standard c++ a...
void SetAutomaticallyCloseRenderWindow(bool automaticallyCloseRenderWindow)
SetStopRenderWindow Convenience method to make the renderwindow hold after rendering. Usefull for debugging.
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.
Definition: mitkIOUtil.cpp:489