Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkSTLFileReaderTest.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 #include "mitkIOUtil.h"
14 #include "mitkImage.h"
15 #include "mitkSlicedGeometry3D.h"
16 #include "mitkSurface.h"
17 #include "mitkTestFixture.h"
18 #include "mitkTestingMacros.h"
19 #include <vtkPolyData.h>
20 #include <vtkSTLReader.h>
21 #include <vtkSmartPointer.h>
22 
23 #include <fstream>
24 
25 class mitkSTLFileReaderTestSuite : public mitk::TestFixture
26 {
27  CPPUNIT_TEST_SUITE(mitkSTLFileReaderTestSuite);
28  MITK_TEST(testReadFile);
29  CPPUNIT_TEST_SUITE_END();
30 
31 private:
33  std::string m_SurfacePath;
34 
35 public:
40  void setUp() override { m_SurfacePath = GetTestDataFilePath("ball.stl"); }
41  void tearDown() override {}
42  void testReadFile()
43  {
44  // Read STL-Image from file
45  mitk::Surface::Pointer surface = mitk::IOUtil::Load<mitk::Surface>(m_SurfacePath);
46 
47  // check some basic stuff
48  CPPUNIT_ASSERT_MESSAGE("Reader output not nullptr", surface.IsNotNull());
49  CPPUNIT_ASSERT_MESSAGE("IsInitialized()", surface->IsInitialized());
50  CPPUNIT_ASSERT_MESSAGE("mitk::Surface::SetVtkPolyData()", (surface->GetVtkPolyData() != nullptr));
51  CPPUNIT_ASSERT_MESSAGE("Availability of geometry", (surface->GetGeometry() != nullptr));
52 
53  // use vtk stl reader for reference
54  vtkSmartPointer<vtkSTLReader> myVtkSTLReader = vtkSmartPointer<vtkSTLReader>::New();
55  myVtkSTLReader->SetFileName(m_SurfacePath.c_str());
56  myVtkSTLReader->Update();
57  vtkSmartPointer<vtkPolyData> myVtkPolyData = myVtkSTLReader->GetOutput();
58  // vtkPolyData from vtkSTLReader directly
59  int n = myVtkPolyData->GetNumberOfPoints();
60  // vtkPolyData from mitkSTLFileReader
61  int m = surface->GetVtkPolyData()->GetNumberOfPoints();
62  CPPUNIT_ASSERT_MESSAGE("Number of Points in VtkPolyData", (n == m));
63  }
64 };
65 MITK_TEST_SUITE_REGISTRATION(mitkSTLFileReader)
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
#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.
Test fixture for parameterized tests.