Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
Medical Imaging Interaction Toolkit
mitkManualPlacementAnnotationRendererTest.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 
18 #include <mitkTestFixture.h>
19 #include <mitkTestingMacros.h>
20 #include <mitkTextAnnotation2D.h>
21 #include <mitkTextAnnotation3D.h>
22 
23 class mitkManualPlacementAnnotationRendererTestSuite : public mitk::TestFixture
24 {
25  CPPUNIT_TEST_SUITE(mitkManualPlacementAnnotationRendererTestSuite);
26  MITK_TEST(Render2DAnnotation);
27  MITK_TEST(Render3DAnnotation);
28 
29  CPPUNIT_TEST_SUITE_END();
30 
31 private:
33  mitk::RenderingTestHelper m_RenderingTestHelper;
34  std::vector<std::string> m_CommandlineArgs;
35  std::string m_PathToBall;
36  std::string m_PathToImage;
37  std::string m_ReferenceImagePath;
38 
39 public:
45  mitkManualPlacementAnnotationRendererTestSuite() : m_RenderingTestHelper(300, 300) {}
50  void setUp()
51  {
52  m_RenderingTestHelper = mitk::RenderingTestHelper(300, 300);
53 
54  m_PathToBall = GetTestDataFilePath("ball.stl");
55  m_PathToImage = GetTestDataFilePath("Pic3D.nrrd");
56  m_ReferenceImagePath = "RenderingTestData/ReferenceScreenshots/Annotation/";
57 
58  // Build a command line for the vtkTesting::Test method.
59  // See VTK documentation and RenderingTestHelper for more information.
60  // Use the following command line option to save the difference image
61  // and the test image in some tmp folder
62  // m_CommandlineArgs.push_back("-T");
63  // m_CommandlineArgs.push_back("/path/to/save/tmp/difference/images/");
64  m_CommandlineArgs.push_back("-V");
65  }
66 
67  void tearDown() {}
68  void Render2DAnnotation()
69  {
71  ballnode->SetData(mitk::IOUtil::Load(m_PathToBall)[0]);
72  m_RenderingTestHelper.AddNodeToStorage(ballnode);
73 
75  imagenode->SetData(mitk::IOUtil::Load(m_PathToImage)[0]);
76  m_RenderingTestHelper.AddNodeToStorage(imagenode);
77 
78  std::string refImagePath = GetTestDataFilePath(m_ReferenceImagePath + "ManualPlacementAnnotationRenderer2DAnnotation.png");
79 
80  // reference screenshot for this test
81  m_CommandlineArgs.push_back(refImagePath);
82  // Convert vector of strings to argc/argv
83  mitk::RenderingTestHelper::ArgcHelperClass arg(m_CommandlineArgs);
85 
87 
88  textAnnotation2D->SetText("TEST ManualPlacementAnnotationRenderer2DAnnotation");
89  mitk::Point2D pos;
90  pos[0] = 0;
91  pos[1] = 0;
92  textAnnotation2D->SetPosition2D(pos);
93 
94  mitk::BaseRenderer *renderer = mitk::BaseRenderer::GetInstance(m_RenderingTestHelper.GetVtkRenderWindow());
95  mitk::ManualPlacementAnnotationRenderer::AddAnnotation(textAnnotation2D.GetPointer(), renderer);
96 
97  m_RenderingTestHelper.Render();
98 // m_RenderingTestHelper.SaveReferenceScreenShot(refImagePath);
99  m_RenderingTestHelper.SetAutomaticallyCloseRenderWindow(true);
100  CPPUNIT_ASSERT(m_RenderingTestHelper.CompareRenderWindowAgainstReference(arg.GetArgc(), arg.GetArgv()) == true);
101  }
102 
103  void Render3DAnnotation()
104  {
106  ballnode->SetData(mitk::IOUtil::Load(m_PathToBall)[0]);
107  m_RenderingTestHelper.AddNodeToStorage(ballnode);
108 
110  imagenode->SetData(mitk::IOUtil::Load(m_PathToImage)[0]);
111  m_RenderingTestHelper.AddNodeToStorage(imagenode);
112 
113  std::string refImagePath = GetTestDataFilePath(m_ReferenceImagePath + "ManualPlacementAnnotationRenderer3DAnnotation.png");
114  // reference screenshot for this test
115  m_CommandlineArgs.push_back(refImagePath);
116  // Convert vector of strings to argc/argv
117  mitk::RenderingTestHelper::ArgcHelperClass arg(m_CommandlineArgs);
118  m_RenderingTestHelper.SetMapperIDToRender3D();
119 
121 
122  textAnnotation3D->SetText("TEST ManualPlacementAnnotationRenderer3DAnnotation");
123  mitk::Point3D pos;
124  pos[0] = 10;
125  pos[1] = 10;
126  pos[2] = 10;
127  textAnnotation3D->SetPosition3D(pos);
128 
129  mitk::BaseRenderer *renderer = mitk::BaseRenderer::GetInstance(m_RenderingTestHelper.GetVtkRenderWindow());
130  mitk::ManualPlacementAnnotationRenderer::AddAnnotation(textAnnotation3D.GetPointer(), renderer);
131 
132  m_RenderingTestHelper.Render();
133 // m_RenderingTestHelper.SaveReferenceScreenShot(refImagePath);
134  m_RenderingTestHelper.SetAutomaticallyCloseRenderWindow(true);
135  CPPUNIT_ASSERT(m_RenderingTestHelper.CompareRenderWindowAgainstReference(arg.GetArgc(), arg.GetArgv()) == true);
136  }
137 };
138 MITK_TEST_SUITE_REGISTRATION(mitkManualPlacementAnnotationRenderer)
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.
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.
static Pointer New()
static Pointer New()
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 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