Medical Imaging Interaction Toolkit  2018.4.99-87d68d9f
Medical Imaging Interaction Toolkit
mitkLayoutAnnotationRendererTest.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 
22 void createTextAnnotationWithLayouter(std::vector<mitk::TextAnnotation2D::Pointer> &Annotation,
24  mitk::BaseRenderer *renderer,
25  int fontsize,
26  float red,
27  float green,
28  float blue,
29  int prio,
30  std::string text)
31 {
32  // Create a textAnnotation2D
34 
35  textAnnotation->SetText(text);
36  textAnnotation->SetFontSize(fontsize);
37  textAnnotation->SetColor(red, green, blue);
38  textAnnotation->SetOpacity(1);
39 
40  mitk::LayoutAnnotationRenderer::AddAnnotation(textAnnotation, renderer, align, 5, 5, prio);
41  Annotation.push_back(textAnnotation);
42 }
43 
44 class mitkLayoutAnnotationRendererTestSuite : public mitk::TestFixture
45 {
46  CPPUNIT_TEST_SUITE(mitkLayoutAnnotationRendererTestSuite);
47  MITK_TEST(Render2DAnnotation);
48 
49  CPPUNIT_TEST_SUITE_END();
50 
51 private:
53  mitk::RenderingTestHelper m_RenderingTestHelper;
54  std::vector<std::string> m_CommandlineArgs;
55  std::string m_PathToBall;
56  std::string m_PathToImage;
57  std::string m_ReferenceImagePath;
58 
59 public:
65  mitkLayoutAnnotationRendererTestSuite() : m_RenderingTestHelper(500, 500) {}
70  void setUp()
71  {
72  m_RenderingTestHelper = mitk::RenderingTestHelper(500, 500);
73 
74  m_PathToBall = GetTestDataFilePath("ball.stl");
75  m_PathToImage = GetTestDataFilePath("Pic3D.nrrd");
76  m_ReferenceImagePath = "RenderingTestData/ReferenceScreenshots/Annotation/";
77 
78  // Build a command line for the vtkTesting::Test method.
79  // See VTK documentation and RenderingTestHelper for more information.
80  // Use the following command line option to save the difference image
81  // and the test image in some tmp folder
82  // m_CommandlineArgs.push_back("-T");
83  // m_CommandlineArgs.push_back("/path/to/save/tmp/difference/images/");
84  m_CommandlineArgs.push_back("-V");
85  }
86 
87  void tearDown() {}
88  void Render2DAnnotation()
89  {
91  ballnode->SetData(mitk::IOUtil::Load(m_PathToBall)[0]);
92  m_RenderingTestHelper.AddNodeToStorage(ballnode);
93 
95  imagenode->SetData(mitk::IOUtil::Load(m_PathToImage)[0]);
96  m_RenderingTestHelper.AddNodeToStorage(imagenode);
97 
98  std::string refImagePath = GetTestDataFilePath(m_ReferenceImagePath + "LayoutAnnotationRenderer.png");
99  // reference screenshot for this test
100  m_CommandlineArgs.push_back(refImagePath);
101  // Convert vector of strings to argc/argv
102  mitk::RenderingTestHelper::ArgcHelperClass arg(m_CommandlineArgs);
104 
105  std::vector<mitk::TextAnnotation2D::Pointer> Annotation;
106  mitk::BaseRenderer *renderer = mitk::BaseRenderer::GetInstance(m_RenderingTestHelper.GetVtkRenderWindow());
107 
109  Annotation, mitk::LayoutAnnotationRenderer::TopLeft, renderer, 20, 1.0, 1.0, 1.0, 1, "TopLeft1");
111  Annotation, mitk::LayoutAnnotationRenderer::TopLeft, renderer, 15, 1.0, 1.0, 1.0, 3, "TopLeft3");
113  Annotation, mitk::LayoutAnnotationRenderer::TopLeft, renderer, 25, 1.0, 0.0, 1.0, 2, "TopLeft2");
114 
115  createTextAnnotationWithLayouter(Annotation, mitk::LayoutAnnotationRenderer::Top, renderer, 15, 1.0, 1.0, 1.0, 3, "Top3");
116  createTextAnnotationWithLayouter(Annotation, mitk::LayoutAnnotationRenderer::Top, renderer, 20, 1.0, 1.0, 1.0, 1, "Top1");
117  createTextAnnotationWithLayouter(Annotation, mitk::LayoutAnnotationRenderer::Top, renderer, 25, 1.0, 0.0, 1.0, 2, "Top2");
118 
120  Annotation, mitk::LayoutAnnotationRenderer::TopRight, renderer, 20, 1.0, 1.0, 1.0, 1, "TopRight1");
122  Annotation, mitk::LayoutAnnotationRenderer::TopRight, renderer, 15, 1.0, 1.0, 1.0, 3, "TopRight3");
124  Annotation, mitk::LayoutAnnotationRenderer::TopRight, renderer, 25, 1.0, 0.0, 1.0, 2, "TopRight2");
125 
126  createTextAnnotationWithLayouter(Annotation, mitk::LayoutAnnotationRenderer::Left, renderer, 20, 1.0, 1.0, 1.0, 1, "Left1");
127  createTextAnnotationWithLayouter(Annotation, mitk::LayoutAnnotationRenderer::Left, renderer, 15, 1.0, 1.0, 1.0, 3, "Left3");
128  createTextAnnotationWithLayouter(Annotation, mitk::LayoutAnnotationRenderer::Left, renderer, 25, 1.0, 0.0, 1.0, 2, "Left2");
129 
130  createTextAnnotationWithLayouter(Annotation, mitk::LayoutAnnotationRenderer::Right, renderer, 25, 1.0, 0.0, 1.0, 2, "Right2");
131  createTextAnnotationWithLayouter(Annotation, mitk::LayoutAnnotationRenderer::Right, renderer, 20, 1.0, 1.0, 1.0, 1, "Right1");
132  createTextAnnotationWithLayouter(Annotation, mitk::LayoutAnnotationRenderer::Right, renderer, 15, 1.0, 1.0, 1.0, 3, "Right3");
133 
135  Annotation, mitk::LayoutAnnotationRenderer::BottomLeft, renderer, 25, 1.0, 0.0, 1.0, 2, "BottomLeft2");
137  Annotation, mitk::LayoutAnnotationRenderer::BottomLeft, renderer, 20, 1.0, 1.0, 1.0, 1, "BottomLeft1");
139  Annotation, mitk::LayoutAnnotationRenderer::BottomLeft, renderer, 15, 1.0, 1.0, 1.0, 3, "BottomLeft3");
140 
141  createTextAnnotationWithLayouter(Annotation, mitk::LayoutAnnotationRenderer::Bottom, renderer, 15, 1.0, 1.0, 1.0, 3, "Bottom3");
142  createTextAnnotationWithLayouter(Annotation, mitk::LayoutAnnotationRenderer::Bottom, renderer, 20, 1.0, 1.0, 1.0, 1, "Bottom1");
143  createTextAnnotationWithLayouter(Annotation, mitk::LayoutAnnotationRenderer::Bottom, renderer, 25, 1.0, 0.0, 1.0, 2, "Bottom2");
144 
146  Annotation, mitk::LayoutAnnotationRenderer::BottomRight, renderer, 25, 1.0, 0.0, 1.0, 2, "BottomRight2");
148  Annotation, mitk::LayoutAnnotationRenderer::BottomRight, renderer, 20, 1.0, 1.0, 1.0, 1, "BottomRight1");
150  Annotation, mitk::LayoutAnnotationRenderer::BottomRight, renderer, 15, 1.0, 1.0, 1.0, 3, "BottomRight3");
151 
152  m_RenderingTestHelper.Render();
153 // m_RenderingTestHelper.SaveReferenceScreenShot(refImagePath);
154  m_RenderingTestHelper.SetAutomaticallyCloseRenderWindow(true);
155  CPPUNIT_ASSERT(m_RenderingTestHelper.CompareRenderWindowAgainstReference(arg.GetArgc(), arg.GetArgv()) == true);
156  }
157 };
158 MITK_TEST_SUITE_REGISTRATION(mitkLayoutAnnotationRenderer)
void SetViewDirection(mitk::SliceNavigationController::ViewDirection viewDirection)
Set the view direction of the renderwindow (e.g. sagittal, coronal, axial)
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
void createTextAnnotationWithLayouter(std::vector< mitk::TextAnnotation2D::Pointer > &Annotation, mitk::LayoutAnnotationRenderer::Alignment align, mitk::BaseRenderer *renderer, int fontsize, float red, float green, float blue, int prio, std::string text)
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 void AddAnnotation(Annotation *annotation, const std::string &rendererID, Alignment alignment=TopLeft, double marginX=5, double marginY=5, int priority=-1)
static std::string GetTestDataFilePath(const std::string &testData)
Get the absolute path for test data.
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.
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