Medical Imaging Interaction Toolkit  2018.4.99-a3d2e8fb
Medical Imaging Interaction Toolkit
mitkTextAnnotation3DTest.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 <mitkTextAnnotation3D.h>
21 
22 class mitkTextAnnotation3DTestSuite : public mitk::TestFixture
23 {
24  CPPUNIT_TEST_SUITE(mitkTextAnnotation3DTestSuite);
25  MITK_TEST(Render3DAnnotation);
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  mitkTextAnnotation3DTestSuite() : 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 Render3DAnnotation()
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 + "TextAnnotation3D.png");
77  // reference screenshot for this test
78  m_CommandlineArgs.push_back(refImagePath);
79  // Convert vector of strings to argc/argv
80  mitk::RenderingTestHelper::ArgcHelperClass arg(m_CommandlineArgs);
81  m_RenderingTestHelper.SetMapperIDToRender3D();
82 
84 
85  textAnnotation3D->SetText("TESTManualPlacementAnnotationRenderer3DAnnotation");
86  mitk::Point3D pos;
87  pos[0] = 10;
88  pos[1] = 10;
89  pos[2] = 10;
90  textAnnotation3D->SetPosition3D(pos);
91 
92  mitk::BaseRenderer *renderer = mitk::BaseRenderer::GetInstance(m_RenderingTestHelper.GetVtkRenderWindow());
93  mitk::ManualPlacementAnnotationRenderer::AddAnnotation(textAnnotation3D.GetPointer(), renderer);
94 
95  m_RenderingTestHelper.Render();
96 // m_RenderingTestHelper.SaveReferenceScreenShot(refImagePath);
97  m_RenderingTestHelper.SetAutomaticallyCloseRenderWindow(true);
98  CPPUNIT_ASSERT(m_RenderingTestHelper.CompareRenderWindowAgainstReference(arg.GetArgc(), arg.GetArgv()) == true);
99  }
100 };
101 MITK_TEST_SUITE_REGISTRATION(mitkTextAnnotation3D)
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()
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