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
mitkSTLFileReader.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 #include "mitkSTLFileReader.h"
17 #include <mitkSurface.h>
18 #include <vtkCleanPolyData.h>
19 #include <vtkPolyData.h>
20 #include <vtkPolyDataNormals.h>
21 #include <vtkSTLReader.h>
22 #include <vtkSmartPointer.h>
23 
25 {
26 }
27 
29 {
30 }
31 
33 {
34  mitk::Surface::Pointer output = this->GetOutput();
35 
36  if (m_FileName != "")
37  {
38  MITK_INFO("mitkSTLFileReader") << "Loading " << m_FileName << " as stl..." << std::endl;
39  vtkSmartPointer<vtkSTLReader> stlReader = vtkSmartPointer<vtkSTLReader>::New();
40  stlReader->SetFileName(m_FileName.c_str());
41 
42  vtkSmartPointer<vtkPolyDataNormals> normalsGenerator = vtkSmartPointer<vtkPolyDataNormals>::New();
43  normalsGenerator->SetInputConnection(stlReader->GetOutputPort());
44 
45  vtkSmartPointer<vtkCleanPolyData> cleanPolyDataFilter = vtkSmartPointer<vtkCleanPolyData>::New();
46  cleanPolyDataFilter->SetInputConnection(normalsGenerator->GetOutputPort());
47  cleanPolyDataFilter->PieceInvariantOff();
48  cleanPolyDataFilter->ConvertLinesToPointsOff();
49  cleanPolyDataFilter->ConvertPolysToLinesOff();
50  cleanPolyDataFilter->ConvertStripsToPolysOff();
51  cleanPolyDataFilter->PointMergingOn();
52  cleanPolyDataFilter->Update();
53 
54  if ((stlReader->GetOutput() != nullptr) && (cleanPolyDataFilter->GetOutput() != nullptr))
55  {
56  vtkSmartPointer<vtkPolyData> surfaceWithNormals = cleanPolyDataFilter->GetOutput();
57  output->SetVtkPolyData(surfaceWithNormals);
58  }
59  }
60 }
61 
63  const std::string /*filePrefix*/,
64  const std::string /*filePattern*/)
65 {
66  // First check the extension
67  if (filename == "")
68  {
69  // MITK_INFO<<"No filename specified."<<std::endl;
70  return false;
71  }
72 
73  bool extensionFound = false;
74  std::string::size_type STLPos = filename.rfind(".stl");
75  if ((STLPos != std::string::npos) && (STLPos == filename.length() - 4))
76  {
77  extensionFound = true;
78  }
79 
80  STLPos = filename.rfind(".STL");
81  if ((STLPos != std::string::npos) && (STLPos == filename.length() - 4))
82  {
83  extensionFound = true;
84  }
85 
86  if (!extensionFound)
87  {
88  // MITK_INFO<<"The filename extension is not recognized."<<std::endl;
89  return false;
90  }
91 
92  return true;
93 }
Superclass of all classes generating surfaces (instances of class Surface) as output.
#define MITK_INFO
Definition: mitkLogMacros.h:22
DataCollection - Class to facilitate loading/accessing structured data.
static const std::string filename
virtual void GenerateData() override
static bool CanReadFile(const std::string filename, const std::string filePrefix, const std::string filePattern)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.