Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "mitkIOUtil.h"
18 #include "mitkImage.h"
19 #include "mitkSlicedGeometry3D.h"
20 #include "mitkSurface.h"
21 #include "mitkTestFixture.h"
22 #include "mitkTestingMacros.h"
23 #include <vtkPolyData.h>
24 #include <vtkSTLReader.h>
25 #include <vtkSmartPointer.h>
26 
27 #include <fstream>
28 
29 class mitkSTLFileReaderTestSuite : public mitk::TestFixture
30 {
31  CPPUNIT_TEST_SUITE(mitkSTLFileReaderTestSuite);
32  MITK_TEST(testReadFile);
33  CPPUNIT_TEST_SUITE_END();
34 
35 private:
37  std::string m_SurfacePath;
38 
39 public:
44  void setUp() override { m_SurfacePath = GetTestDataFilePath("ball.stl"); }
45  void tearDown() override {}
46  void testReadFile()
47  {
48  // Read STL-Image from file
49  mitk::Surface::Pointer surface = mitk::IOUtil::LoadSurface(m_SurfacePath);
50 
51  // check some basic stuff
52  CPPUNIT_ASSERT_MESSAGE("Reader output not NULL", surface.IsNotNull());
53  CPPUNIT_ASSERT_MESSAGE("IsInitialized()", surface->IsInitialized());
54  CPPUNIT_ASSERT_MESSAGE("mitk::Surface::SetVtkPolyData()", (surface->GetVtkPolyData() != NULL));
55  CPPUNIT_ASSERT_MESSAGE("Availability of geometry", (surface->GetGeometry() != NULL));
56 
57  // use vtk stl reader for reference
58  vtkSmartPointer<vtkSTLReader> myVtkSTLReader = vtkSmartPointer<vtkSTLReader>::New();
59  myVtkSTLReader->SetFileName(m_SurfacePath.c_str());
60  myVtkSTLReader->Update();
61  vtkSmartPointer<vtkPolyData> myVtkPolyData = myVtkSTLReader->GetOutput();
62  // vtkPolyData from vtkSTLReader directly
63  int n = myVtkPolyData->GetNumberOfPoints();
64  // vtkPolyData from mitkSTLFileReader
65  int m = surface->GetVtkPolyData()->GetNumberOfPoints();
66  CPPUNIT_ASSERT_MESSAGE("Number of Points in VtkPolyData", (n == m));
67  }
68 };
69 MITK_TEST_SUITE_REGISTRATION(mitkSTLFileReader)
static mitk::Surface::Pointer LoadSurface(const std::string &path)
LoadSurface Convenience method to load an arbitrary mitkSurface.
Definition: mitkIOUtil.cpp:608
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.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.