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 "mitkVtkSurfaceReader.h"
00018 #include <mitkSurface.h>
00019 #include <vtkDataReader.h>
00020 #include <vtkPolyDataReader.h>
00021 #if ((VTK_MAJOR_VERSION > 4) || ((VTK_MAJOR_VERSION==4) && (VTK_MINOR_VERSION>=4) ))
00022 #include <vtkXMLPolyDataReader.h>
00023 #endif
00024 #include <itksys/SystemTools.hxx>
00025
00026
00027 mitk::VtkSurfaceReader::VtkSurfaceReader()
00028 : m_FileName("")
00029 {
00030 }
00031
00032 mitk::VtkSurfaceReader::~VtkSurfaceReader()
00033 {
00034 }
00035
00036 void mitk::VtkSurfaceReader::GenerateData()
00037 {
00038 if( m_FileName != "")
00039 {
00040 bool success = false;
00041 MITK_INFO << "Loading " << m_FileName << " as vtk" << 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->IsFilePolyData())
00051 {
00053 itkDebugMacro( << "PolyData" );
00054 vtkPolyDataReader *reader = vtkPolyDataReader::New();
00055 reader->SetFileName( m_FileName.c_str() );
00056 reader->Update();
00057
00058 if ( reader->GetOutput() != NULL )
00059 {
00060 mitk::Surface::Pointer output = this->GetOutput();
00061 output->SetVtkPolyData( reader->GetOutput() );
00062 success = true;
00063 }
00064 reader->Delete();
00065 }
00066 chooser->Delete();
00067 }
00068 #if ((VTK_MAJOR_VERSION > 4) || ((VTK_MAJOR_VERSION==4) && (VTK_MINOR_VERSION>=4) ))
00069 else
00070 if (ext == ".vtp")
00071 {
00072 vtkXMLPolyDataReader *reader=vtkXMLPolyDataReader::New();
00073 if( reader->CanReadFile(m_FileName.c_str()) )
00074 {
00076 itkDebugMacro( << "XMLPolyData" );
00077 reader->SetFileName( m_FileName.c_str() );
00078 reader->Update();
00079
00080 if ( reader->GetOutput() != NULL )
00081 {
00082 mitk::Surface::Pointer output = this->GetOutput();
00083 output->SetVtkPolyData( reader->GetOutput() );
00084 success = true;
00085 }
00086 reader->Delete();
00087 }
00088 }
00089 #endif
00090 if(!success)
00091 {
00092 itkWarningMacro( << " ... sorry, this .vtk format is not supported yet." );
00093 }
00094 }
00095 }
00096
00097 bool mitk::VtkSurfaceReader::CanReadFile(const std::string filename, const std::string , const std::string )
00098 {
00099
00100 if( filename == "" )
00101 return false;
00102
00103 std::string ext = itksys::SystemTools::GetFilenameLastExtension(filename);
00104 ext = itksys::SystemTools::LowerCase(ext);
00105 if (ext == ".vtk")
00106 {
00107 vtkDataReader *chooser=vtkDataReader::New();
00108 chooser->SetFileName(filename.c_str() );
00109 if(!chooser->IsFilePolyData())
00110 {
00111 chooser->Delete();
00112 return false;
00113 }
00114 chooser->Delete();
00115 }
00116 #if ((VTK_MAJOR_VERSION > 4) || ((VTK_MAJOR_VERSION==4) && (VTK_MINOR_VERSION>=4) ))
00117 else
00118 if (ext == ".vtp")
00119 {
00120 vtkXMLPolyDataReader *chooser=vtkXMLPolyDataReader::New();
00121 if(!chooser->CanReadFile(filename.c_str()))
00122 {
00123 chooser->Delete();
00124 return false;
00125 }
00126 chooser->Delete();
00127 }
00128 #endif
00129 else
00130 return false;
00131
00132 return true;
00133 }