17 #ifndef __mitkNrrdTbssImageReader_cpp
18 #define __mitkNrrdTbssImageReader_cpp
22 #include "itkImageFileReader.h"
23 #include "itkMetaDataObject.h"
24 #include "itkNrrdImageIO.h"
25 #include "itkNiftiImageIO.h"
27 #include <itkImageFileWriter.h>
32 #include "itksys/SystemTools.hxx"
47 if ( ( ! m_OutputCache ) || ( this->GetMTime( ) > m_CacheTime.GetMTime( ) ) )
49 this->GenerateOutputInformation();
50 itkWarningMacro(
"Cache regenerated!");
55 itkWarningMacro(
"Tree cache is empty!")
59 static_cast<OutputType*
>(this->GetPrimaryOutput())
60 ->SetImage(m_OutputCache->GetImage());
61 static_cast<OutputType*
>(this->GetPrimaryOutput())
62 ->SetGroupInfo(m_OutputCache->GetGroupInfo());
64 static_cast<OutputType*
>(this->GetPrimaryOutput())
65 ->InitializeFromVectorImage();
74 if ( m_FileName ==
"")
76 throw itk::ImageFileReaderException(__FILE__, __LINE__,
"Sorry, the filename to be read is empty!");
82 const std::string& locale =
"C";
83 const std::string& currLocale = setlocale( LC_ALL,
nullptr );
85 if ( locale.compare(currLocale)!=0 )
89 MITK_INFO <<
" ** Changing locale from " << setlocale(LC_ALL,
nullptr) <<
" to '" << locale <<
"'";
90 setlocale(LC_ALL, locale.c_str());
94 MITK_INFO <<
"Could not set locale " << locale;
99 MITK_INFO <<
"NrrdTbssImageReader READING IMAGE INFORMATION";
102 std::string ext = itksys::SystemTools::GetFilenameLastExtension(m_FileName);
103 ext = itksys::SystemTools::LowerCase(ext);
106 typedef itk::ImageFileReader<ImageType> FileReaderType;
108 reader->SetFileName(this->m_FileName);
110 reader->SetImageIO(io);
113 img = reader->GetOutput();
116 MITK_INFO <<
"NrrdTbssImageReader READING HEADER INFORMATION";
119 itk::MetaDataDictionary imgMetaDictionary = img->GetMetaDataDictionary();
120 std::vector<std::string> imgMetaKeys = imgMetaDictionary.GetKeys();
121 std::vector<std::string>::const_iterator itKey = imgMetaKeys.begin();
122 std::string metaString;
126 std::string measurementInfo;
129 std::vector< std::pair<std::string, int> > groups;
131 for (; itKey != imgMetaKeys.end(); itKey ++)
133 itk::ExposeMetaData<std::string> (imgMetaDictionary, *itKey, metaString);
135 MITK_INFO << *itKey <<
" ---> " << metaString;
137 if (itKey->find(
"Group_index") != std::string::npos)
140 std::vector<std::string> tokens;
141 this->Tokenize(metaString, tokens,
" ");
144 std::pair< std::string, int > p;
147 for (
unsigned int i=0; i<tokens.size()-1;i++)
150 p.first.append(tokens.at(i));
153 std::cout << p.first << std::endl;
155 p.second = atoi(tokens.at(tokens.size()-1 ).c_str());
162 else if(itKey->find(
"Measurement info") != std::string::npos)
164 measurementInfo = metaString;
173 outputForCache->SetGroupInfo(groups);
174 outputForCache->SetMeasurementInfo(measurementInfo);
182 outputForCache->SetImage(img);
187 m_OutputCache = outputForCache;
188 m_CacheTime.Modified();
192 MITK_INFO <<
" ** Changing locale back from " << setlocale(LC_ALL,
nullptr) <<
" to '" << currLocale <<
"'";
193 setlocale(LC_ALL, currLocale.c_str());
197 MITK_INFO <<
"Could not reset locale " << currLocale;
200 catch(std::exception& e)
202 MITK_INFO <<
"Std::Exception while reading file!!";
204 throw itk::ImageFileReaderException(__FILE__, __LINE__, e.what());
208 MITK_INFO <<
"Exception while reading file!!";
209 throw itk::ImageFileReaderException(__FILE__, __LINE__,
"Sorry, an error occurred while reading the requested vessel tree file!");
219 return m_FileName.c_str();
225 m_FileName = aFileName;
231 return m_FilePrefix.c_str();
237 m_FilePrefix = aFilePrefix;
243 return m_FilePattern.c_str();
249 m_FilePattern = aFilePattern;
261 if( filePattern !=
"" && filePrefix !=
"" )
265 std::string ext = itksys::SystemTools::GetFilenameLastExtension(filename);
266 ext = itksys::SystemTools::LowerCase(ext);
272 typedef itk::ImageFileReader<ImageType> FileReaderType;
274 reader->SetImageIO(io);
275 reader->SetFileName(filename);
281 catch(itk::ExceptionObject e)
itk::SmartPointer< Self > Pointer
Base of all data objects.
void SetFilePrefix(const char *aFilePrefix) override
Specify file prefix for the file(s) to load.
DataCollection - Class to facilitate loading/accessing structured data.
virtual void GenerateOutputInformation() override
const char * GetFileName() const override
const char * GetFilePrefix() const override
Get the specified file prefix for the file(s) to load.
static bool CanReadFile(const std::string filename, const std::string filePrefix, const std::string filePattern)
void SetFilePattern(const char *aFilePattern) override
Specified file pattern for the file(s) to load. The sprintf format used to build filename from FilePr...
const char * GetFilePattern() const override
Get the specified file pattern for the file(s) to load. The sprintf format used to build filename fro...
static const std::string filename
void SetFileName(const char *aFileName) override
Specify the file to load.
virtual void GenerateData() override
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.