Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkVtkImageReader.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 "mitkVtkImageReader.h"
14 
15 #include <vtkDataReader.h>
16 #include <vtkStructuredPoints.h>
17 #include <vtkStructuredPointsReader.h>
18 
19 mitk::VtkImageReader::VtkImageReader() : m_FileName(""), m_FilePrefix(""), m_FilePattern("")
20 {
21 }
22 
24 {
25 }
26 
28 {
29  if (m_FileName != "")
30  {
31  MITK_INFO << "Loading " << m_FileName << " as vtk" << std::endl;
32 
34  vtkDataReader *chooser = vtkDataReader::New();
35  chooser->SetFileName(m_FileName.c_str());
36 
37  if (chooser->IsFileStructuredPoints())
38  {
40  MITK_INFO << "StructuredPoints" << std::endl;
41  vtkStructuredPointsReader *reader = vtkStructuredPointsReader::New();
42  reader->SetFileName(m_FileName.c_str());
43  reader->Update();
44 
45  if (reader->GetOutput() != nullptr)
46  {
47  mitk::Image::Pointer output = this->GetOutput();
48  output->Initialize(reader->GetOutput());
49  output->SetVolume(reader->GetOutput()->GetScalarPointer());
50  }
51  reader->Delete();
52  }
53  else
54  {
55  MITK_ERROR << " ... sorry, this .vtk format is not supported yet." << std::endl;
56  }
57  chooser->Delete();
58  }
59 }
60 
61 bool mitk::VtkImageReader::CanReadFile(const std::string filename,
62  const std::string /*filePrefix*/,
63  const std::string /*filePattern*/)
64 {
65  // First check the extension
66  if (filename == "")
67  return false;
68 
69  bool extensionFound = false;
70  std::string::size_type PVTKPos = filename.rfind(".pvtk");
71  if ((PVTKPos != std::string::npos) && (PVTKPos == filename.length() - 5))
72  {
73  extensionFound = true;
74  }
75 
76  PVTKPos = filename.rfind(".PVTK");
77  if ((PVTKPos != std::string::npos) && (PVTKPos == filename.length() - 5))
78  {
79  extensionFound = true;
80  }
81 
82  if (extensionFound)
83  {
84  vtkDataReader *chooser = vtkDataReader::New();
85  chooser->SetFileName(filename.c_str());
86  if (!chooser->IsFileStructuredPoints())
87  return false;
88  }
89  else
90  return false;
91 
92  return true;
93 }
#define MITK_INFO
Definition: mitkLogMacros.h:18
#define MITK_ERROR
Definition: mitkLogMacros.h:20
static bool CanReadFile(const std::string filename, const std::string filePrefix, const std::string filePattern)
OutputType * GetOutput()
Get the output data of this image source object.
void GenerateData() override