Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkVtkSurfaceReader.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 "mitkVtkSurfaceReader.h"
17 #include <itksys/SystemTools.hxx>
18 #include <mitkSurface.h>
19 #include <vtkDataReader.h>
20 #include <vtkPolyDataReader.h>
21 #include <vtkXMLPolyDataReader.h>
22 
24 {
25 }
26 
28 {
29 }
30 
32 {
33  if (m_FileName != "")
34  {
35  bool success = false;
36  MITK_INFO << "Loading " << m_FileName << " as vtk" << std::endl;
37 
38  std::string ext = itksys::SystemTools::GetFilenameLastExtension(m_FileName);
39  ext = itksys::SystemTools::LowerCase(ext);
40  if (ext == ".vtk")
41  {
43  vtkDataReader *chooser = vtkDataReader::New();
44  chooser->SetFileName(m_FileName.c_str());
45  if (chooser->IsFilePolyData())
46  {
48  itkDebugMacro(<< "PolyData");
49  vtkPolyDataReader *reader = vtkPolyDataReader::New();
50  reader->SetFileName(m_FileName.c_str());
51  reader->Update();
52 
53  if (reader->GetOutput() != nullptr)
54  {
55  mitk::Surface::Pointer output = this->GetOutput();
56  output->SetVtkPolyData(reader->GetOutput());
57  success = true;
58  }
59  reader->Delete();
60  }
61  chooser->Delete();
62  }
63  else if (ext == ".vtp")
64  {
65  vtkXMLPolyDataReader *reader = vtkXMLPolyDataReader::New();
66  if (reader->CanReadFile(m_FileName.c_str()))
67  {
69  itkDebugMacro(<< "XMLPolyData");
70  reader->SetFileName(m_FileName.c_str());
71  reader->Update();
72 
73  if (reader->GetOutput() != nullptr)
74  {
75  mitk::Surface::Pointer output = this->GetOutput();
76  output->SetVtkPolyData(reader->GetOutput());
77  success = true;
78  }
79  reader->Delete();
80  }
81  }
82  if (!success)
83  {
84  itkWarningMacro(<< " ... sorry, this .vtk format is not supported yet.");
85  }
86  }
87 }
88 
90  const std::string /*filePrefix*/,
91  const std::string /*filePattern*/)
92 {
93  // First check the extension
94  if (filename == "")
95  return false;
96 
97  std::string ext = itksys::SystemTools::GetFilenameLastExtension(filename);
98  ext = itksys::SystemTools::LowerCase(ext);
99  if (ext == ".vtk")
100  {
101  vtkDataReader *chooser = vtkDataReader::New();
102  chooser->SetFileName(filename.c_str());
103  if (!chooser->IsFilePolyData())
104  {
105  chooser->Delete();
106  return false;
107  }
108  chooser->Delete();
109  }
110  else if (ext == ".vtp")
111  {
112  vtkXMLPolyDataReader *chooser = vtkXMLPolyDataReader::New();
113  if (!chooser->CanReadFile(filename.c_str()))
114  {
115  chooser->Delete();
116  return false;
117  }
118  chooser->Delete();
119  }
120  else
121  return false;
122 
123  return true;
124 }
#define MITK_INFO
Definition: mitkLogMacros.h:22
static bool CanReadFile(const std::string filename, const std::string filePrefix, const std::string filePattern)
static const std::string filename
virtual void GenerateData() override
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.