Medical Imaging Interaction Toolkit  2018.4.99-3e3f1a6e
Medical Imaging Interaction Toolkit
mitkLabelAnnotation3DTest.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 <mitkLabelAnnotation3D.h>
19 #include <mitkTestFixture.h>
20 #include <mitkTestingMacros.h>
21 
22 class mitkLabelAnnotation3DTestSuite : public mitk::TestFixture
23 {
24  CPPUNIT_TEST_SUITE(mitkLabelAnnotation3DTestSuite);
25  MITK_TEST(Render2DAnnotation);
26  MITK_TEST(Render3DAnnotation);
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_ReferenceImagePath;
37 
38 public:
44  mitkLabelAnnotation3DTestSuite() : m_RenderingTestHelper(300, 300) {}
49  void setUp()
50  {
51  m_RenderingTestHelper = mitk::RenderingTestHelper(300, 300);
52 
53  m_PathToBall = GetTestDataFilePath("ball.stl");
54  m_PathToImage = GetTestDataFilePath("Pic3D.nrrd");
55  m_ReferenceImagePath = "RenderingTestData/ReferenceScreenshots/Annotation/";
56 
57  // Build a command line for the vtkTesting::Test method.
58  // See VTK documentation and RenderingTestHelper for more information.
59  // Use the following command line option to save the difference image
60  // and the test image in some tmp folder
61  // m_CommandlineArgs.push_back("-T");
62  // m_CommandlineArgs.push_back("/path/to/save/tmp/difference/images/");
63  m_CommandlineArgs.push_back("-V");
64  }
65 
66  void tearDown() {}
67  void Render2DAnnotation()
68  {
69  std::string refImagePath = GetTestDataFilePath(m_ReferenceImagePath + "mitkLabelAnnotation2D.png");
70  // reference screenshot for this test
71  m_CommandlineArgs.push_back(refImagePath);
72  // Convert vector of strings to argc/argv
73  mitk::RenderingTestHelper::ArgcHelperClass arg(m_CommandlineArgs);
75 
79  offset[0] = .5;
80  offset[1] = .5;
81  offset[2] = .5;
82 
83  std::vector<std::string> labels;
84  unsigned long idx = 0;
85  for (int i = -10; i < 10; i += 4)
86  {
87  for (int j = -10; j < 10; j += 4)
88  {
89  mitk::Point3D point;
90  point[0] = i;
91  point[1] = j;
92  point[2] = (i * j) / 10;
93  pointset->InsertPoint(idx++, point);
94  labels.push_back("test");
95  }
96  }
97 
98  label3d->SetLabelCoordinates(pointset);
99  label3d->SetLabelVector(labels);
100  label3d->SetOffsetVector(offset);
101 
103  datanode->SetData(pointset);
104  datanode->SetName("pointSet");
105  m_RenderingTestHelper.AddNodeToStorage(datanode);
106 
107  mitk::BaseRenderer *renderer = mitk::BaseRenderer::GetInstance(m_RenderingTestHelper.GetVtkRenderWindow());
108  mitk::ManualPlacementAnnotationRenderer::AddAnnotation(label3d.GetPointer(), renderer);
109 
110  m_RenderingTestHelper.Render();
111 // m_RenderingTestHelper.SaveReferenceScreenShot(refImagePath);
112  m_RenderingTestHelper.SetAutomaticallyCloseRenderWindow(true);
113  CPPUNIT_ASSERT(m_RenderingTestHelper.CompareRenderWindowAgainstReference(arg.GetArgc(), arg.GetArgv()) == true);
114  }
115 
116  void Render3DAnnotation()
117  {
118  std::string refImagePath = GetTestDataFilePath(m_ReferenceImagePath + "mitkLabelAnnotation3D.png");
119  // reference screenshot for this test
120  m_CommandlineArgs.push_back(refImagePath);
121  // Convert vector of strings to argc/argv
122  mitk::RenderingTestHelper::ArgcHelperClass arg(m_CommandlineArgs);
123  m_RenderingTestHelper.SetMapperIDToRender3D();
124 
128  offset[0] = .5;
129  offset[1] = .5;
130  offset[2] = .5;
131 
132  std::vector<std::string> labels;
133  unsigned long idx = 0;
134  for (int i = -10; i < 10; i += 4)
135  {
136  for (int j = -10; j < 10; j += 4)
137  {
138  mitk::Point3D point;
139  point[0] = i;
140  point[1] = j;
141  point[2] = (i * j) / 10;
142  pointset->InsertPoint(idx++, point);
143  labels.push_back("test");
144  }
145  }
146 
147  label3d->SetLabelCoordinates(pointset);
148  label3d->SetLabelVector(labels);
149  label3d->SetOffsetVector(offset);
150 
152  datanode->SetData(pointset);
153  datanode->SetName("pointSet");
154  m_RenderingTestHelper.AddNodeToStorage(datanode);
155 
156  mitk::BaseRenderer *renderer = mitk::BaseRenderer::GetInstance(m_RenderingTestHelper.GetVtkRenderWindow());
157  mitk::ManualPlacementAnnotationRenderer::AddAnnotation(label3d.GetPointer(), renderer);
158 
159  m_RenderingTestHelper.Render();
160 // m_RenderingTestHelper.SaveReferenceScreenShot(refImagePath);
161  m_RenderingTestHelper.SetAutomaticallyCloseRenderWindow(true);
162  CPPUNIT_ASSERT(m_RenderingTestHelper.CompareRenderWindowAgainstReference(arg.GetArgc(), arg.GetArgv()) == true);
163  }
164 };
165 MITK_TEST_SUITE_REGISTRATION(mitkLabelAnnotation3D)
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.
static Pointer New()
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.
bool CompareRenderWindowAgainstReference(int argc, char *argv[], double threshold=10.0)
CompareRenderWindowAgainstReference Convenience method to compare the image rendered in the internal ...
static Vector3D offset
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()