Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "mitkVtkUnstructuredGridReader.h"
00018 #include <mitkUnstructuredGrid.h>
00019 #include <vtkDataReader.h>
00020 #include <vtkUnstructuredGridReader.h>
00021 #if ((VTK_MAJOR_VERSION > 4) || ((VTK_MAJOR_VERSION==4) && (VTK_MINOR_VERSION>=4) ))
00022 #include <vtkXMLUnstructuredGridReader.h>
00023 #endif
00024 #include <itksys/SystemTools.hxx>
00025
00026
00027 mitk::VtkUnstructuredGridReader::VtkUnstructuredGridReader()
00028 : m_FileName("")
00029 {
00030 }
00031
00032 mitk::VtkUnstructuredGridReader::~VtkUnstructuredGridReader()
00033 {
00034 }
00035
00036 void mitk::VtkUnstructuredGridReader::GenerateData()
00037 {
00038 if( m_FileName != "")
00039 {
00040 bool success = false;
00041 MITK_INFO << "Loading " << m_FileName << " as vtk unstructured grid" << std::endl;
00042
00043 std::string ext = itksys::SystemTools::GetFilenameLastExtension(m_FileName);
00044 ext = itksys::SystemTools::LowerCase(ext);
00045 if (ext == ".vtk")
00046 {
00048 vtkDataReader *chooser=vtkDataReader::New();
00049 chooser->SetFileName(m_FileName.c_str() );
00050 if( chooser->IsFileUnstructuredGrid())
00051 {
00053 itkDebugMacro( << "UnstructuredGrid" );
00054 vtkUnstructuredGridReader *reader = vtkUnstructuredGridReader::New();
00055 reader->SetFileName( m_FileName.c_str() );
00056 reader->Update();
00057
00058 if ( reader->GetOutput() != NULL )
00059 {
00060 mitk::UnstructuredGrid::Pointer output = this->GetOutput();
00061 output->SetVtkUnstructuredGrid( reader->GetOutput() );
00062 success = true;
00063 }
00064 reader->Delete();
00065 }
00066 }
00067 #if ((VTK_MAJOR_VERSION > 4) || ((VTK_MAJOR_VERSION==4) && (VTK_MINOR_VERSION>=4) ))
00068 else
00069 if (ext == ".vtu")
00070 {
00071 vtkXMLUnstructuredGridReader *reader=vtkXMLUnstructuredGridReader::New();
00072 if( reader->CanReadFile(m_FileName.c_str()) )
00073 {
00075 itkDebugMacro( << "XMLUnstructuredGrid" );
00076 reader->SetFileName( m_FileName.c_str() );
00077 reader->Update();
00078
00079 if ( reader->GetOutput() != NULL )
00080 {
00081 mitk::UnstructuredGrid::Pointer output = this->GetOutput();
00082 output->SetVtkUnstructuredGrid( reader->GetOutput() );
00083 success = true;
00084 }
00085 reader->Delete();
00086 }
00087 }
00088 #endif
00089 if(!success)
00090 {
00091 itkExceptionMacro( << " ... sorry, this .vtk format is not supported yet." );
00092 }
00093 }
00094 }
00095
00096 bool mitk::VtkUnstructuredGridReader::CanReadFile(const std::string filename, const std::string , const std::string )
00097 {
00098
00099 if( filename == "" )
00100 return false;
00101
00102 std::string ext = itksys::SystemTools::GetFilenameLastExtension(filename);
00103 ext = itksys::SystemTools::LowerCase(ext);
00104 if (ext == ".vtk")
00105 {
00106 vtkDataReader *chooser=vtkDataReader::New();
00107 chooser->SetFileName(filename.c_str() );
00108 if(!chooser->IsFileUnstructuredGrid())
00109 {
00110 chooser->Delete();
00111 return false;
00112 }
00113 }
00114 #if ((VTK_MAJOR_VERSION > 4) || ((VTK_MAJOR_VERSION==4) && (VTK_MINOR_VERSION>=4) ))
00115 else
00116 if (ext == ".vtu")
00117 {
00118 vtkXMLUnstructuredGridReader *chooser=vtkXMLUnstructuredGridReader::New();
00119 if(!chooser->CanReadFile(filename.c_str()))
00120 {
00121 chooser->Delete();
00122 return false;
00123 }
00124 }
00125 #endif
00126 else
00127 return false;
00128
00129 return true;
00130 }