Medical Imaging Interaction Toolkit  2018.4.99-4c24e3cb
Medical Imaging Interaction Toolkit
mitkColorBarAnnotationTest.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 <mitkColorBarAnnotation.h>
19 #include <mitkTestFixture.h>
20 #include <mitkTestingMacros.h>
21 
22 class mitkColorBarAnnotationTestSuite : public mitk::TestFixture
23 {
24  CPPUNIT_TEST_SUITE(mitkColorBarAnnotationTestSuite);
25  MITK_TEST(RenderColorBarAnnotation);
26 
27  CPPUNIT_TEST_SUITE_END();
28 
29 private:
31  mitk::RenderingTestHelper m_RenderingTestHelper;
32  std::vector<std::string> m_CommandlineArgs;
33  std::string m_PathToBall;
34  std::string m_PathToImage;
35  std::string m_ReferenceImagePath;
36 
37 public:
43  mitkColorBarAnnotationTestSuite() : m_RenderingTestHelper(300, 300) {}
48  void setUp()
49  {
50  m_RenderingTestHelper = mitk::RenderingTestHelper(300, 300);
51 
52  m_PathToBall = GetTestDataFilePath("ball.stl");
53  m_PathToImage = GetTestDataFilePath("Pic3D.nrrd");
54  m_ReferenceImagePath = "RenderingTestData/ReferenceScreenshots/Annotation/";
55 
56  // Build a command line for the vtkTesting::Test method.
57  // See VTK documentation and RenderingTestHelper for more information.
58  // Use the following command line option to save the difference image
59  // and the test image in some tmp folder
60  // m_CommandlineArgs.push_back("-T");
61  // m_CommandlineArgs.push_back("/path/to/save/tmp/difference/images/");
62  m_CommandlineArgs.push_back("-V");
63  }
64 
65  void tearDown() {}
66  void RenderColorBarAnnotation()
67  {
69  ballnode->SetData(mitk::IOUtil::Load(m_PathToBall)[0]);
70  m_RenderingTestHelper.AddNodeToStorage(ballnode);
71 
73  imagenode->SetData(mitk::IOUtil::Load(m_PathToImage)[0]);
74  m_RenderingTestHelper.AddNodeToStorage(imagenode);
75 
76  std::string refImagePath = GetTestDataFilePath(m_ReferenceImagePath + "mitkColorBarAnnotation.png");
77 
78  // reference screenshot for this test
79  m_CommandlineArgs.push_back(refImagePath);
80  // Convert vector of strings to argc/argv
81  mitk::RenderingTestHelper::ArgcHelperClass arg(m_CommandlineArgs);
83 
85 
86  mitk::BaseRenderer *renderer = mitk::BaseRenderer::GetInstance(m_RenderingTestHelper.GetVtkRenderWindow());
87  mitk::ManualPlacementAnnotationRenderer::AddAnnotation(colorbar.GetPointer(), renderer);
88 
89  m_RenderingTestHelper.Render();
90 // m_RenderingTestHelper.SaveReferenceScreenShot(refImagePath);
91  m_RenderingTestHelper.SetAutomaticallyCloseRenderWindow(true);
92  CPPUNIT_ASSERT(m_RenderingTestHelper.CompareRenderWindowAgainstReference(arg.GetArgc(), arg.GetArgv()) == true);
93  }
94 };
95 MITK_TEST_SUITE_REGISTRATION(mitkColorBarAnnotation)
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 ...
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 Pointer New()
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