diff --git a/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkNrrdTbssImageReader.cpp b/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkNrrdTbssImageReader.cpp index 07d5b336c1..be672973e5 100644 --- a/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkNrrdTbssImageReader.cpp +++ b/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkNrrdTbssImageReader.cpp @@ -1,316 +1,346 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-07-14 19:11:20 +0200 (Tue, 14 Jul 2009) $ Version: $Revision: 18127 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef __mitkNrrdTbssImageReader_cpp #define __mitkNrrdTbssImageReader_cpp #include "mitkNrrdTbssImageReader.h" #include "itkImageFileReader.h" #include "itkMetaDataObject.h" #include "itkNrrdImageIO.h" #include "itkNiftiImageIO.h" #include #include #include #include "itksys/SystemTools.hxx" namespace mitk { void NrrdTbssImageReader ::GenerateData() { // Since everything is completely read in GenerateOutputInformation() it is stored // in a cache variable. A timestamp is associated. // If the timestamp of the cache variable is newer than the MTime, we only need to // assign the cache variable to the DataObject. // Otherwise, the tree must be read again from the file and OuputInformation must // be updated! if ( ( ! m_OutputCache ) || ( this->GetMTime( ) > m_CacheTime.GetMTime( ) ) ) { this->GenerateOutputInformation(); itkWarningMacro("Cache regenerated!"); } if (!m_OutputCache) { itkWarningMacro("Tree cache is empty!") } int vecsize = m_OutputCache->GetImage()->GetVectorLength(); static_cast(this->GetOutput()) ->SetImage(m_OutputCache->GetImage()); static_cast(this->GetOutput()) ->SetGroupInfo(m_OutputCache->GetGroupInfo()); + static_cast(this->GetOutput()) + ->SetMetaInfo(m_OutputCache->GetMetaInfo()); + static_cast(this->GetOutput()) + ->SetIsMeta(m_OutputCache->GetIsMeta()); static_cast(this->GetOutput()) ->InitializeFromVectorImage(); } void NrrdTbssImageReader ::GenerateOutputInformation() { OutputType::Pointer outputForCache = OutputType::New(); + if ( m_FileName == "") { throw itk::ImageFileReaderException(__FILE__, __LINE__, "Sorry, the filename to be read is empty!"); } else { try { const std::string& locale = "C"; const std::string& currLocale = setlocale( LC_ALL, NULL ); if ( locale.compare(currLocale)!=0 ) { try { MITK_INFO << " ** Changing locale from " << setlocale(LC_ALL, NULL) << " to '" << locale << "'"; setlocale(LC_ALL, locale.c_str()); } catch(...) { MITK_INFO << "Could not set locale " << locale; } } MITK_INFO << "NrrdTbssImageReader READING IMAGE INFORMATION"; ImageType::Pointer img; std::string ext = itksys::SystemTools::GetFilenameLastExtension(m_FileName); ext = itksys::SystemTools::LowerCase(ext); if (ext == ".tbss") { typedef itk::ImageFileReader FileReaderType; FileReaderType::Pointer reader = FileReaderType::New(); reader->SetFileName(this->m_FileName); itk::NrrdImageIO::Pointer io = itk::NrrdImageIO::New(); reader->SetImageIO(io); reader->Update(); img = reader->GetOutput(); - } - MITK_INFO << "NrrdTbssImageReader READING HEADER INFORMATION"; - if (ext == ".tbss") - { + MITK_INFO << "NrrdTbssImageReader READING HEADER INFORMATION"; + itk::MetaDataDictionary imgMetaDictionary = img->GetMetaDataDictionary(); std::vector imgMetaKeys = imgMetaDictionary.GetKeys(); std::vector::const_iterator itKey = imgMetaKeys.begin(); std::string metaString; //int numberOfGradientImages = 0; std::string measurementInfo; + bool isMeta = false; + std::vector > metaInfo; std::vector< std::pair > groups; for (; itKey != imgMetaKeys.end(); itKey ++) { - - itk::ExposeMetaData (imgMetaDictionary, *itKey, metaString); MITK_INFO << *itKey << " ---> " << metaString; if (itKey->find("Group_index") != std::string::npos) { std::vector tokens; this->Tokenize(metaString, tokens, " "); if(tokens.size()==2) { std::cout << tokens.at(0) << " " << tokens.at(1) << std::endl; std::pair< std::string, int > p; p.first = tokens.at(0); std::string s = tokens.at(1); p.second = atoi(tokens.at(1).c_str()); groups.push_back(p); } } - else if(itKey->find("Measurement info")) + else if(itKey->find("Measurement info") != std::string::npos) { measurementInfo = metaString; } + else if(itKey->find("meta") != std::string::npos) + { + if(metaString == "true") + { + isMeta = true; + } + } + + else if(itKey->find("mean fa skeleton mask") != std::string::npos) + { + std::pair p; + p.first = mitk::TbssImage::MEAN_FA_SKELETON_MASK; + p.second = atoi(metaString.c_str()); + metaInfo.push_back(p); + } + + else if(itKey->find("mean fa skeleton") != std::string::npos) + { + std::pair p; + p.first = mitk::TbssImage::MEAN_FA_SKELETON; + p.second = atoi(metaString.c_str()); + metaInfo.push_back(p); + } + + } + outputForCache->SetIsMeta(isMeta); outputForCache->SetGroupInfo(groups); outputForCache->SetMeasurementInfo(measurementInfo); + outputForCache->SetMetaInfo(metaInfo); } // This call updates the output information of the associated VesselTreeData outputForCache->SetImage(img); // outputForCache->SetB_Value(m_B_Value); //outputForCache->SetDirections(m_DiffusionVectors); // outputForCache->SetOriginalDirections(m_OriginalDiffusionVectors); // outputForCache->SetMeasurementFrame(m_MeasurementFrame); // Since we have already read the tree, we can store it in a cache variable // so that it can be assigned to the DataObject in GenerateData(); m_OutputCache = outputForCache; m_CacheTime.Modified(); try { MITK_INFO << " ** Changing locale back from " << setlocale(LC_ALL, NULL) << " to '" << currLocale << "'"; setlocale(LC_ALL, currLocale.c_str()); } catch(...) { MITK_INFO << "Could not reset locale " << currLocale; } } catch(std::exception& e) { MITK_INFO << "Std::Exception while reading file!!"; MITK_INFO << e.what(); throw itk::ImageFileReaderException(__FILE__, __LINE__, e.what()); } catch(...) { MITK_INFO << "Exception while reading file!!"; throw itk::ImageFileReaderException(__FILE__, __LINE__, "Sorry, an error occurred while reading the requested vessel tree file!"); } } } const char* NrrdTbssImageReader ::GetFileName() const { return m_FileName.c_str(); } void NrrdTbssImageReader ::SetFileName(const char* aFileName) { m_FileName = aFileName; } const char* NrrdTbssImageReader ::GetFilePrefix() const { return m_FilePrefix.c_str(); } void NrrdTbssImageReader ::SetFilePrefix(const char* aFilePrefix) { m_FilePrefix = aFilePrefix; } const char* NrrdTbssImageReader ::GetFilePattern() const { return m_FilePattern.c_str(); } void NrrdTbssImageReader ::SetFilePattern(const char* aFilePattern) { m_FilePattern = aFilePattern; } bool NrrdTbssImageReader ::CanReadFile(const std::string filename, const std::string filePrefix, const std::string filePattern) { // First check the extension if( filename == "" ) return false; // check if image is serie if( filePattern != "" && filePrefix != "" ) return false; std::string ext = itksys::SystemTools::GetFilenameLastExtension(filename); ext = itksys::SystemTools::LowerCase(ext); if (ext == ".tbss") { itk::NrrdImageIO::Pointer io = itk::NrrdImageIO::New(); typedef itk::ImageFileReader FileReaderType; FileReaderType::Pointer reader = FileReaderType::New(); reader->SetImageIO(io); reader->SetFileName(filename); try { reader->Update(); } catch(itk::ExceptionObject e) { MITK_INFO << e.GetDescription(); return false; } /* typename ImageType::Pointer img = reader->GetOutput(); itk::MetaDataDictionary imgMetaDictionary = img->GetMetaDataDictionary(); std::vector imgMetaKeys = imgMetaDictionary.GetKeys(); std::vector::const_iterator itKey = imgMetaKeys.begin(); std::string metaString; for (; itKey != imgMetaKeys.end(); itKey ++) { itk::ExposeMetaData (imgMetaDictionary, *itKey, metaString); if (itKey->find("tbss") != std::string::npos) { if (metaString.find("ROI") != std::string::npos) { return true; } } } } */ // return false; return true; } return false; } } //namespace MITK #endif diff --git a/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkNrrdTbssImageWriter.cpp b/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkNrrdTbssImageWriter.cpp index 12edb618b2..1d96fab600 100644 --- a/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkNrrdTbssImageWriter.cpp +++ b/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkNrrdTbssImageWriter.cpp @@ -1,148 +1,192 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2008-12-10 18:05:13 +0100 (Mi, 10 Dez 2008) $ Version: $Revision: 15922 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef __mitkNrrdTbssImageWriter__cpp #define __mitkNrrdTbssImageWriter__cpp #include "mitkNrrdTbssImageWriter.h" #include "itkMetaDataDictionary.h" #include "itkMetaDataObject.h" #include "itkNrrdImageIO.h" //#include "itkNiftiImageIO.h" #include "itkImageFileWriter.h" #include "itksys/SystemTools.hxx" #include "boost/lexical_cast.hpp" #include #include mitk::NrrdTbssImageWriter::NrrdTbssImageWriter() : m_FileName(""), m_FilePrefix(""), m_FilePattern(""), m_Success(false) { this->SetNumberOfRequiredInputs( 1 ); } mitk::NrrdTbssImageWriter::~NrrdTbssImageWriter() {} void mitk::NrrdTbssImageWriter::GenerateData() { m_Success = false; InputType* input = this->GetInput(); if (input == NULL) { itkWarningMacro(<<"Sorry, input to NrrdTbssImageWriter is NULL!"); return; } if ( m_FileName == "" ) { itkWarningMacro( << "Sorry, filename has not been set!" ); return ; } itk::VectorImage::Pointer img = input->GetImage(); std::string key; std::string val; - std::vector< std::pair > groups = input->GetGroupInfo(); - std::vector< std::pair >::iterator it = groups.begin(); + /* For the case of a tbss image containing data of the patients: + Save info about the groups and the type of measurement */ - int i=0; - while(it != groups.end()) + if(!input->GetIsMeta()) { - std::pair p = *it; + key = "meta"; + val = "false"; + itk::EncapsulateMetaData< std::string >(input->GetImage()->GetMetaDataDictionary(),key,val); + + + std::vector< std::pair > groups = input->GetGroupInfo(); + std::vector< std::pair >::iterator it = groups.begin(); - key = "Group_index_" + boost::lexical_cast(i); - val = " " + p.first + " " + boost::lexical_cast(p.second); - //sprintf( keybuffer, "Group_index_%04d", std::string(i) ); - // sprintf( valbuffer, "%1d %1d", p.first, p.second); + int i=0; + while(it != groups.end()) + { + std::pair p = *it; - //std::cout << valbuffer << std::endl; + key = "Group_index_" + boost::lexical_cast(i); + val = " " + p.first + " " + boost::lexical_cast(p.second); + //sprintf( keybuffer, "Group_index_%04d", std::string(i) ); + // sprintf( valbuffer, "%1d %1d", p.first, p.second); - //itk::EncapsulateMetaData< std::string >(input->GetImage()->GetMetaDataDictionary(),std::string(keybuffer),std::string(valbuffer)); + //std::cout << valbuffer << std::endl; + + //itk::EncapsulateMetaData< std::string >(input->GetImage()->GetMetaDataDictionary(),std::string(keybuffer),std::string(valbuffer)); + itk::EncapsulateMetaData< std::string >(input->GetImage()->GetMetaDataDictionary(),key,val); + it++; + ++i; + } + + key = "Measurement info"; + val = input->GetMeasurementInfo(); itk::EncapsulateMetaData< std::string >(input->GetImage()->GetMetaDataDictionary(),key,val); - it++; - ++i; } + /* If we are dealing with metadata we need to know what index of the vector corresponds to what image. + Metadata are the images involved in the algorithms of tbss, like the mean FA Skeleton. */ + else + { + key = "meta"; + val = "true"; + itk::EncapsulateMetaData< std::string >(input->GetImage()->GetMetaDataDictionary(),key,val); - key = "Measurement info"; - val = input->GetMeasurementInfo(); - itk::EncapsulateMetaData< std::string >(input->GetImage()->GetMetaDataDictionary(),key,val); - + std::vector< std::pair > metaInfo = input->GetMetaInfo(); + std::vector< std::pair >::iterator it = metaInfo.begin(); + while(it != metaInfo.end()) + { + std::pair p = *it; + key = RetrieveString(p.first); + val = " " + boost::lexical_cast(p.second); + itk::EncapsulateMetaData< std::string >(input->GetImage()->GetMetaDataDictionary(),key,val); + it++; + } + } typedef itk::VectorImage ImageType; - itk::NrrdImageIO::Pointer io = itk::NrrdImageIO::New(); io->SetFileType( itk::ImageIOBase::Binary ); io->UseCompressionOn(); typedef itk::ImageFileWriter WriterType; WriterType::Pointer nrrdWriter = WriterType::New(); nrrdWriter->UseInputMetaDataDictionaryOn(); nrrdWriter->SetInput( img ); nrrdWriter->SetImageIO(io); nrrdWriter->SetFileName(m_FileName); nrrdWriter->UseCompressionOn(); nrrdWriter->SetImageIO(io); try { nrrdWriter->Update(); } catch (itk::ExceptionObject e) { std::cout << e << std::endl; } m_Success = true; } + +std::string mitk::NrrdTbssImageWriter::RetrieveString(mitk::TbssImage::MetaDataFunction meta) +{ + if(meta == mitk::TbssImage::MEAN_FA_SKELETON) + { + return "mean fa skeleton"; + } + else if(meta == mitk::TbssImage::MEAN_FA_SKELETON_MASK) + { + return "mean fa skeleton mask"; + } + return ""; +} + + + void mitk::NrrdTbssImageWriter::SetInput( InputType* tbssVol ) { this->ProcessObject::SetNthInput( 0, tbssVol ); } mitk::TbssImage* mitk::NrrdTbssImageWriter::GetInput() { if ( this->GetNumberOfInputs() < 1 ) { return NULL; } else { return dynamic_cast ( this->ProcessObject::GetInput( 0 ) ); } } std::vector mitk::NrrdTbssImageWriter::GetPossibleFileExtensions() { std::vector possibleFileExtensions; possibleFileExtensions.push_back(".tbss"); return possibleFileExtensions; } #endif //__mitkNrrdTbssImageWriter__cpp diff --git a/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkNrrdTbssImageWriter.h b/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkNrrdTbssImageWriter.h index e3cd29f418..92e76c00ff 100644 --- a/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkNrrdTbssImageWriter.h +++ b/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkNrrdTbssImageWriter.h @@ -1,138 +1,141 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2008-08-27 17:18:46 +0200 (Mi, 27 Aug 2008) $ Version: $Revision: 15096 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef _MITK_NRRDTBSSVOL_WRITER__H_ #define _MITK_NRRDTBSSVOL_WRITER__H_ #include #include #include #include #include "MitkDiffusionImagingExports.h" namespace mitk { /** * Writes diffusion volumes to a file * @ingroup Process */ class MitkDiffusionImaging_EXPORT NrrdTbssImageWriter : public mitk::FileWriterWithInformation { public: mitkClassMacro( NrrdTbssImageWriter, mitk::FileWriterWithInformation ) mitkWriterMacro itkNewMacro( Self ) typedef mitk::TbssImage InputType; /** * Sets the filename of the file to write. * @param FileName the nameInputType of the file to write. */ itkSetStringMacro( FileName ) /** * @returns the name of the file to be written to disk. */ itkGetStringMacro( FileName ) /** * @warning multiple write not (yet) supported */ itkSetStringMacro( FilePrefix ) /** * @warning multiple write not (yet) supported */ itkGetStringMacro( FilePrefix ) /** * @warning multiple write not (yet) supported */ itkSetStringMacro( FilePattern ) /** * @warning multiple write not (yet) supported */ itkGetStringMacro( FilePattern ) /**image * Sets the input object for the filter. * @param input the diffusion volumes to write to file. */ void SetInput( InputType* input ); /**itk::VectorImage * @returns the 0'th input object of the filter. */ InputType* GetInput(); /** * Returns false if an error happened during writing */ itkGetMacro( Success, bool ) /** * @return possible file extensions for the data type associated with the writer */ virtual std::vector GetPossibleFileExtensions(); // FileWriterWithInformation methods virtual const char * GetDefaultFilename() { return "TbssImage.tbss"; } virtual const char * GetFileDialogPattern() { return "Tbss Images (*.tbss)"; } virtual const char * GetDefaultExtension() { return ".tbss"; } virtual bool CanWriteBaseDataType(BaseData::Pointer data) { return (dynamic_cast(data.GetPointer()) != NULL); } virtual void DoWrite(BaseData::Pointer data) { if (CanWriteBaseDataType(data)) { this->SetInput(dynamic_cast(data.GetPointer())); this->Update(); } } protected: NrrdTbssImageWriter(); virtual ~NrrdTbssImageWriter(); virtual void GenerateData(); std::string m_FileName; std::string m_FilePrefix; std::string m_FilePattern; bool m_Success; + + + std::string RetrieveString(mitk::TbssImage::MetaDataFunction meta); }; } // end of namespace mitk #endif diff --git a/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkTbssImage.cpp b/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkTbssImage.cpp index a2a5289b67..3c8a68e4e8 100644 --- a/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkTbssImage.cpp +++ b/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkTbssImage.cpp @@ -1,116 +1,117 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2008-02-08 11:19:03 +0100 (Fr, 08 Feb 2008) $ Version: $Revision: 11989 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef __mitkTbssImage__cpp #define __mitkTbssImage__cpp #include "mitkTbssImage.h" #include "itkImageRegionIterator.h" #include "itkImageRegionConstIterator.h" #include "mitkImageCast.h" mitk::TbssImage::TbssImage() + : m_IsMeta(false) { } void mitk::TbssImage::InitializeFromVectorImage() { if(!m_Image) { MITK_INFO << "TBSS Image could not be initialized. Set all members first!" << std::endl; return; } typedef itk::Image ImgType; ImgType::Pointer img = ImgType::New(); img->SetSpacing( m_Image->GetSpacing() ); // Set the image spacing img->SetOrigin( m_Image->GetOrigin() ); // Set the image origin img->SetDirection( m_Image->GetDirection() ); // Set the image direction img->SetLargestPossibleRegion( m_Image->GetLargestPossibleRegion()); img->SetBufferedRegion( m_Image->GetLargestPossibleRegion() ); img->Allocate(); int vecLength = m_Image->GetVectorLength(); InitializeByItk( img.GetPointer(), 1, vecLength ); //for(int i=0; i itw (img, img->GetLargestPossibleRegion() ); itw = itw.Begin(); itk::ImageRegionConstIterator itr (m_Image, m_Image->GetLargestPossibleRegion() ); itr = itr.Begin(); while(!itr.IsAtEnd()) { itw.Set(itr.Get().GetElement(0)); ++itr; ++itw; } // init SetImportVolume(img->GetBufferPointer());//, 0, 0, CopyMemory); //SetVolume( img->GetBufferPointer(), i ); - //} + //}:: m_DisplayIndex = 0; MITK_INFO << "Tbss-Image successfully initialized."; } void mitk::TbssImage::SetDisplayIndexForRendering(int displayIndex) { MITK_INFO << "displayindex: " << displayIndex; int index = displayIndex; int vecLength = m_Image->GetVectorLength(); index = index > vecLength-1 ? vecLength-1 : index; if( m_DisplayIndex != index ) { typedef itk::Image ImgType; ImgType::Pointer img = ImgType::New(); CastToItkImage(this, img); itk::ImageRegionIterator itw (img, img->GetLargestPossibleRegion() ); itw = itw.Begin(); itk::ImageRegionConstIterator itr (m_Image, m_Image->GetLargestPossibleRegion() ); itr = itr.Begin(); while(!itr.IsAtEnd()) { itw.Set(itr.Get().GetElement(index)); ++itr; ++itw; } } m_DisplayIndex = index; } #endif /* __mitkTbssImage__cpp */ diff --git a/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkTbssImage.h b/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkTbssImage.h index c8cad4a39e..3b5e5605bb 100644 --- a/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkTbssImage.h +++ b/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkTbssImage.h @@ -1,137 +1,167 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2008-02-07 17:17:57 +0100 (Do, 07 Feb 2008) $ Version: $Revision: 11989 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef __mitkTbssImage__h #define __mitkTbssImage__h #include "mitkImage.h" #include "itkVectorImage.h" #include "mitkImageCast.h" #include "MitkDiffusionImagingExports.h" namespace mitk { /** * \brief this class encapsulates diffusion volumes (vectorimages not * yet supported by mitkImage) */ class MitkDiffusionImaging_EXPORT TbssImage : public Image { public: typedef itk::VectorImage ImageType; typedef itk::Index<3> IndexType; //typedef typename std::vector > RoiType; mitkClassMacro( TbssImage, Image ) itkNewMacro(Self) + enum MetaDataFunction + { + MEAN_FA_SKELETON, + MEAN_FA_SKELETON_MASK, + MISC + }; + + //void SetRequestedRegionToLargestPossibleReg tbssRoi->SetTbssType(mitk::TbssImage::ROI);ion(); //bool RequestedRegionIsOutsideOfTheBufferedRegion(); //virtual bool VerifyRequestedRegion(); //void SetRequestedRegion(itk::DataObject *data); ImageType::Pointer GetImage() { return m_Image; } void SetImage(ImageType::Pointer image ) { this->m_Image = image; } void InitializeFromImage() { MITK_INFO << "make an mitk image that can be shown by mitk"; this->InitializeByItk(m_Image.GetPointer(),1,1); } void SetGroupInfo( std::vector< std::pair > info) { m_GroupInfo = info; } std::vector< std::pair > GetGroupInfo() { return m_GroupInfo; } + void SetMetaInfo( std::vector< std::pair > info) + { + m_MetaInfo = info; + } + + std::vector< std::pair > GetMetaInfo() + { + return m_MetaInfo; + } + void SetMeasurementInfo(std::string s) { m_MeasurementInfo = s; } std::string GetMeasurementInfo() { return m_MeasurementInfo; } void InitializeFromVectorImage(); void SetDisplayIndexForRendering(int displayIndex); + void SetIsMeta(bool b) + { + m_IsMeta = b; + } + + bool GetIsMeta() + { + return m_IsMeta; + } + protected: TbssImage(); virtual ~TbssImage(){} ImageType::Pointer m_Image; std::vector< std::pair > m_GroupInfo; + std::vector< std::pair > m_MetaInfo; + int m_DisplayIndex; std::string m_MeasurementInfo; - + bool m_IsMeta; }; /* // Does the same es the normal CastToMitkImage, but needed to reimplemented due to the templatet pixeltype template void CastToTbssImage(const ItkOutputImageType* itkimage, itk::SmartPointer< mitk::TbssImage >& tbssoutputimage) { if(tbssoutputimage.IsNull()) { tbssoutputimage = mitk::TbssImage::New(); } tbssoutputimage->InitializeByItk(itkimage); tbssoutputimage->SetChannel(itkimage->GetBufferPointer()); } */ } // namespace mitk //#include "mitkTbssImage.cpp" #endif /* __mitkTbssImage__h */ diff --git a/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkTbssImporter.cpp b/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkTbssImporter.cpp index 0c0d255150..2aff58ce42 100644 --- a/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkTbssImporter.cpp +++ b/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkTbssImporter.cpp @@ -1,158 +1,248 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-07-14 19:11:20 +0200 (Tue, 14 Jul 2009) $ Version: $Revision: 18127 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef __mitkTbssImporter_cpp #define __mitkTbssImporter_cpp #include "mitkTbssImporter.h" #include #include namespace mitk { mitk::TbssImporter::TbssImporter() { } mitk::TbssImporter::TbssImporter(std::string path) : m_File(path) { } mitk::TbssImage::Pointer mitk::TbssImporter::Import() { // read all images with all_*.nii.gz mitk::TbssImage::Pointer tbssImg = mitk::TbssImage::New(); FileReaderType4D::Pointer reader = FileReaderType4D::New(); reader->SetFileName(m_File); reader->Update(); FloatImage4DType::Pointer img = FloatImage4DType::New(); img = reader->GetOutput(); m_Data = DataImageType::New(); FloatImage4DType::SizeType size = img->GetLargestPossibleRegion().GetSize(); FloatImage4DType::SpacingType spacing = img->GetSpacing(); DataImageType::SizeType dataSize; dataSize[0] = size[0]; dataSize[1] = size[1]; dataSize[2] = size[2]; m_Data->SetRegions(dataSize); DataImageType::SpacingType dataSpacing; dataSpacing[0] = spacing[0]; dataSpacing[1] = spacing[1]; dataSpacing[2] = spacing[2]; m_Data->SetSpacing(dataSpacing); FloatImage4DType::PointType origin = img->GetOrigin(); DataImageType::PointType dataOrigin; dataOrigin[0] = origin[0]; dataOrigin[1] = origin[1]; dataOrigin[2] = origin[2]; m_Data->SetOrigin(dataOrigin); FloatImage4DType::DirectionType dir = img->GetDirection(); DataImageType::DirectionType dataDir; for(int i=0; i<=2; i++) { for(int j=0; j<=2; j++) { dataDir[i][j] = dir[i][j]; } } m_Data->SetDirection(dataDir); // Set the length to one because otherwise allocate fails. Should be changed when groups/measurements are added m_Data->SetVectorLength(size[3]); m_Data->Allocate(); for(int i=0; i ix; ix[0] = i; ix[1] = j; ix[2] = k; itk::VariableLengthVector pixel = m_Data->GetPixel(ix); int vecSize = pixel.Size(); for(int z=0; z ix4; ix4[0] = i; ix4[1] = j; ix4[2] = k; ix4[3] = z; float value = img->GetPixel(ix4); pixel.SetElement(z, value); } m_Data->SetPixel(ix, pixel); } } } // mitk::CastToTbssImage(m_Data.GetPointer(), tbssImg); tbssImg->SetGroupInfo(m_Groups); tbssImg->SetMeasurementInfo(m_MeasurementInfo); tbssImg->SetImage(m_Data); - int vecsize = m_Data->GetVectorLength(); tbssImg->InitializeFromVectorImage(); return tbssImg; } + + mitk::TbssImage::Pointer mitk::TbssImporter::ImportMeta() + { + mitk::TbssImage::Pointer tbssImg = mitk::TbssImage::New(); + + + m_Data = DataImageType::New(); + + std::vector< std::pair > metaInfo; + + for(int i=0; i p = m_MetaFiles.at(i); + std::string function = p.first; + std::string file = p.second; + + // Add to metainfo to give the tbss image a function-index pair + std::pair pair; + + + pair.first = RetrieveTbssFunction(function); + pair.second = i; + + + metaInfo.push_back(pair); + + FileReaderType3D::Pointer fileReader = FileReaderType3D::New(); + fileReader->SetFileName(file); + fileReader->Update(); + + FloatImage3DType::Pointer img = fileReader->GetOutput(); + + FloatImage3DType::SizeType size = img->GetLargestPossibleRegion().GetSize(); + + if(i==0) + { + // First image in serie. Properties should be used to initialize m_Data + m_Data->SetRegions(img->GetLargestPossibleRegion().GetSize()); + m_Data->SetSpacing(img->GetSpacing()); + m_Data->SetOrigin(img->GetOrigin()); + m_Data->SetDirection(img->GetDirection()); + m_Data->SetVectorLength(m_MetaFiles.size()); + m_Data->Allocate(); + } + + for(int x=0; x ix; + ix[0] = x; + ix[1] = y; + ix[2] = z; + + float f = img->GetPixel(ix); + itk::VariableLengthVector pixel = m_Data->GetPixel(ix); + pixel.SetElement(i, f); + m_Data->SetPixel(ix, pixel); + + } + } + } + + + } + + tbssImg->SetIsMeta(true); + tbssImg->SetImage(m_Data); + tbssImg->SetMetaInfo(metaInfo); + tbssImg->InitializeFromVectorImage(); + + return tbssImg; + } + + + mitk::TbssImage::MetaDataFunction mitk::TbssImporter::RetrieveTbssFunction(std::string s) + { + if(s == "skeleton mask") + { + return mitk::TbssImage::MEAN_FA_SKELETON_MASK; + } + else if(s == "mean fa skeleton") + { + return mitk::TbssImage::MEAN_FA_SKELETON; + } + + return mitk::TbssImage::MISC; + } + } #endif // __mitkTbssImporter_cpp diff --git a/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkTbssImporter.h b/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkTbssImporter.h index 1f52c9ffff..7a84f42829 100644 --- a/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkTbssImporter.h +++ b/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkTbssImporter.h @@ -1,98 +1,113 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-07-14 19:11:20 +0200 (Tue, 14 Jul 2009) $ Version: $Revision: 18127 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef __mitkTbssImporter_h #define __mitkTbssImporter_h #include "mitkCommon.h" #include "mitkFileReader.h" #include "itkImage.h" #include "itkVectorImage.h" #include "itkImageFileReader.h" #include "mitkTbssImage.h" namespace mitk { //template class TbssImporter : public itk::Object { public: // typedef TPixelType PixelType; typedef itk::VectorImage DataImageType; // type of the 3d vector image containing the skeletonized images typedef itk::Image FloatImage4DType; typedef itk::ImageFileReader FileReaderType4D; + typedef itk::Image FloatImage3DType; + typedef itk::ImageFileReader FileReaderType3D; + TbssImporter(); mitkClassMacro( TbssImporter, Object ) itkNewMacro(Self) TbssImporter(std::string path); void SetInputFile(std::string f) { m_File = f; } mitk::TbssImage::Pointer Import(); + mitk::TbssImage::Pointer ImportMeta(); + void SetGroupInfo(std::vector< std::pair > groups) { m_Groups = groups; } std::vector< std::pair > GetGroupInfo() { return m_Groups; } + void SetTbssDatasets(std::vector< std::pair > files) + { + m_MetaFiles = files; + } + void SetMeasurementInfo(std::string s) { m_MeasurementInfo = s; } std::string GetMeasurementInfo() { return m_MeasurementInfo; } protected: virtual ~TbssImporter(){} std::string m_File; DataImageType::Pointer m_Data; std::vector< std::pair > m_Groups; + std::vector< std::pair > m_MetaFiles; std::string m_MeasurementInfo; + + mitk::TbssImage::MetaDataFunction RetrieveTbssFunction(std::string s); + + }; } #include "mitkTbssImporter.cpp" #endif // __mitkTbssImporter_h