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