Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkVtiFileReader.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 "mitkVtiFileReader.h"
14 
15 #include <vtkImageData.h>
16 #include <vtkXMLImageDataReader.h>
17 
18 mitk::VtiFileReader::VtiFileReader() : m_FileName(""), m_FilePrefix(""), m_FilePattern("")
19 {
20 }
21 
23 {
24 }
25 
27 {
28  if (m_FileName != "")
29  {
30  vtkXMLImageDataReader *vtkReader = vtkXMLImageDataReader::New();
31  vtkReader->SetFileName(m_FileName.c_str());
32  vtkReader->Update();
33 
34  if (vtkReader->GetOutput() != nullptr)
35  {
36  mitk::Image::Pointer output = this->GetOutput();
37  output->Initialize(vtkReader->GetOutput());
38  output->SetVolume(vtkReader->GetOutput()->GetScalarPointer());
39  }
40  vtkReader->Delete();
41  }
42 }
43 
44 bool mitk::VtiFileReader::CanReadFile(const std::string filename,
45  const std::string /*filePrefix*/,
46  const std::string /*filePattern*/)
47 {
48  // First check the extension
49  if (filename == "")
50  return false;
51 
52  bool extensionFound = false;
53  std::string::size_type VTIPos = filename.rfind(".vti");
54  if ((VTIPos != std::string::npos) && (VTIPos == filename.length() - 4))
55  extensionFound = true;
56 
57  VTIPos = filename.rfind(".VTI");
58  if ((VTIPos != std::string::npos) && (VTIPos == filename.length() - 4))
59  extensionFound = true;
60 
61  if (!extensionFound)
62  return false;
63 
64  return true;
65 }
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