Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "mitkPicVolumeTimeSeriesReader.h"
00020 #include "mitkPicFileReader.h"
00021 #include <itkImageFileReader.h>
00022 #include <string>
00023
00024 extern "C"
00025 {
00026 mitkIpPicDescriptor * MITKipPicGet( char *infile_name, mitkIpPicDescriptor *pic );
00027 mitkIpPicDescriptor * MITKipPicGetTags( char *infile_name, mitkIpPicDescriptor *pic );
00028 }
00029
00030
00031 void mitk::PicVolumeTimeSeriesReader::GenerateOutputInformation()
00032 {
00033 mitk::Image::Pointer output = this->GetOutput();
00034
00035 if ( ( output->IsInitialized() ) && ( this->GetMTime() <= m_ReadHeaderTime.GetMTime() ) )
00036 return ;
00037
00038 itkDebugMacro( << "Reading file for GenerateOutputInformation()" << m_FileName );
00039
00040 if ( ! this->GenerateFileList() )
00041 {
00042 itkWarningMacro( "Sorry, file list could not be generated!" );
00043 return ;
00044 }
00045
00046
00047
00048
00049
00050 char* filename = const_cast<char *> ( m_MatchedFileNames[ 0 ].c_str() );
00051 mitkIpPicDescriptor * header = mitkIpPicGetHeader( filename, NULL );
00052 header = MITKipPicGetTags( filename, header );
00053
00054 if ( header == NULL )
00055 {
00056 itk::ImageFileReaderException e( __FILE__, __LINE__ );
00057 itk::OStringStream msg;
00058 msg << " Could not read file " << m_FileName.c_str();
00059 e.SetDescription( msg.str().c_str() );
00060 throw e;
00061 return ;
00062 }
00063 if ( header->dim != 3 )
00064 {
00065 itk::ImageFileReaderException e( __FILE__, __LINE__ , "Only 3D-pic volumes are supported! " );
00066 throw e;
00067 return ;
00068 }
00069
00070
00071
00072
00073 header->dim = 4;
00074 header->n[ 3 ] = m_MatchedFileNames.size();
00075
00076 output->Initialize( header );
00077
00078 mitkIpPicFree( header );
00079
00080 m_ReadHeaderTime.Modified();
00081 }
00082
00083
00084 void mitk::PicVolumeTimeSeriesReader::GenerateData()
00085 {
00086 mitk::Image::Pointer output = this->GetOutput();
00087
00088
00089
00090
00091 if ( m_FilePrefix == "" || m_FilePattern == "" )
00092 {
00093 throw itk::ImageFileReaderException( __FILE__, __LINE__, "Both FilePattern and FilePrefix must be non-empty" );
00094 }
00095
00096 if ( m_MatchedFileNames.size() == 0 )
00097 {
00098 throw itk::ImageFileReaderException( __FILE__, __LINE__, "Sorry, there are no files to read!" );
00099 }
00100
00101
00102
00103
00104
00105 mitkIpPicDescriptor* volume3d = NULL;
00106 for ( unsigned int t = 0 ; t < m_MatchedFileNames.size() ; ++t )
00107 {
00108 char* filename = const_cast< char* >( m_MatchedFileNames[ t ].c_str() );
00109 MITK_INFO << "Reading file " << filename << "..." << std::endl;
00110 volume3d = MITKipPicGet( filename, NULL );
00111
00112 if ( volume3d == NULL )
00113 {
00114 ::itk::OStringStream message;
00115 message << "mitk::ERROR: " << this->GetNameOfClass() << "(" << this << "): "
00116 << "File (" << filename << ") of time frame " << t << " could not be read!";
00117 throw itk::ImageFileReaderException( __FILE__, __LINE__, message.str().c_str() );
00118 }
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129 PicFileReader::ConvertHandedness(volume3d);
00130 bool result;
00131 result = output->SetPicVolume( volume3d, t );
00132 if(result==false)
00133 {
00134 ::itk::OStringStream message;
00135 message << "mitk::ERROR: " << this->GetNameOfClass() << "(" << this << "): "
00136 << "Volume of time frame " << t << " did not match size of other time frames.";
00137 throw itk::ImageFileReaderException( __FILE__, __LINE__, message.str().c_str() );
00138 }
00139 mitkIpPicFree ( volume3d );
00140 }
00141 }
00142
00143 bool mitk::PicVolumeTimeSeriesReader::CanReadFile(const std::string , const std::string filePrefix, const std::string filePattern)
00144 {
00145 if( filePattern == "" && filePrefix == "" )
00146 return false;
00147
00148 bool extensionFound = false;
00149 std::string::size_type PICPos = filePattern.rfind(".pic");
00150 if ((PICPos != std::string::npos)
00151 && (PICPos == filePattern.length() - 4))
00152 {
00153 extensionFound = true;
00154 }
00155
00156 PICPos = filePattern.rfind(".pic.gz");
00157 if ((PICPos != std::string::npos)
00158 && (PICPos == filePattern.length() - 7))
00159 {
00160 extensionFound = true;
00161 }
00162
00163 if( !extensionFound )
00164 return false;
00165
00166 return true;
00167 }
00168
00169 mitk::PicVolumeTimeSeriesReader::PicVolumeTimeSeriesReader()
00170 {
00171
00172 }
00173
00174 mitk::PicVolumeTimeSeriesReader::~PicVolumeTimeSeriesReader()
00175 {}
00176