diff --git a/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkNrrdTbssImageReader.cpp b/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkNrrdTbssImageReader.cpp index 30c45f200a..7adede503a 100644 --- a/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkNrrdTbssImageReader.cpp +++ b/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkNrrdTbssImageReader.cpp @@ -1,369 +1,385 @@ /*========================================================================= 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"; 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") != 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); } else if(itKey->find("gradient_x") != std::string::npos) { std::pair p; p.first = mitk::TbssImage::GRADIENT_X; p.second = atoi(metaString.c_str()); metaInfo.push_back(p); } else if(itKey->find("gradient_y") != std::string::npos) { std::pair p; p.first = mitk::TbssImage::GRADIENT_Y; p.second = atoi(metaString.c_str()); metaInfo.push_back(p); } else if(itKey->find("gradient_z") != std::string::npos) { std::pair p; p.first = mitk::TbssImage::GRADIENT_Z; p.second = atoi(metaString.c_str()); metaInfo.push_back(p); } + else if(itKey->find("tubular structure") != std::string::npos) + { + std::pair p; + p.first = mitk::TbssImage::TUBULAR_STRUCTURE; + p.second = atoi(metaString.c_str()); + metaInfo.push_back(p); + } + + else if(itKey->find("distance map") != std::string::npos) + { + std::pair p; + p.first = mitk::TbssImage::DISTANCE_MAP; + 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 3ed26ea4a7..de8316c295 100644 --- a/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkNrrdTbssImageWriter.cpp +++ b/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkNrrdTbssImageWriter.cpp @@ -1,204 +1,212 @@ /*========================================================================= 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; /* For the case of a tbss image containing data of the patients: Save info about the groups and the type of measurement */ if(!input->GetIsMeta()) { 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(); int i=0; while(it != groups.end()) { std::pair p = *it; 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); //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); } /* 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); 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"; } else if(meta == mitk::TbssImage::GRADIENT_X) { return "gradient_x"; } else if(meta == mitk::TbssImage::GRADIENT_Y) { return "gradient_y"; } else if(meta == mitk::TbssImage::GRADIENT_Z) { return "gradient_z"; } + else if(meta == mitk::TbssImage::TUBULAR_STRUCTURE) + { + return "tubular structure"; + } + else if(meta == mitk::TbssImage::DISTANCE_MAP) + { + return "distance map"; + } 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/mitkTbssGradientImage.h b/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkTbssGradientImage.h index 59806db86d..33a847d103 100644 --- a/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkTbssGradientImage.h +++ b/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkTbssGradientImage.h @@ -1,97 +1,94 @@ /*========================================================================= 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 __mitkTbssGradientImage__h #define __mitkTbssGradientImage__h #include "mitkImage.h" #include "itkVectorImage.h" #include "mitkImageCast.h" #include "MitkDiffusionImagingExports.h" namespace mitk { /** * \brief this class encapsulates tbss gradient images (vectorimages not * yet supported by mitkImage) */ class MitkDiffusionImaging_EXPORT TbssGradientImage : public Image { public: typedef itk::VectorImage ImageType; typedef itk::Index<3> IndexType; //typedef typename std::vector > RoiType; mitkClassMacro( TbssGradientImage, Image ) itkNewMacro(Self) - - - //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 InitializeFromVectorImage(); void SetDisplayIndexForRendering(int displayIndex); protected: TbssGradientImage(); virtual ~TbssGradientImage(){} ImageType::Pointer m_Image; int m_DisplayIndex; }; } // namespace mitk #endif /* __mitkTbssGradientImage__h */ diff --git a/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkTbssImage.cpp b/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkTbssImage.cpp index 402de5772f..553fe5171f 100644 --- a/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkTbssImage.cpp +++ b/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkTbssImage.cpp @@ -1,117 +1,119 @@ /*========================================================================= 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), m_ContainsGradient(false) + : m_IsMeta(false), + m_ContainsGradient(false), + m_ContainsMeanSkeleton(false), + m_ContainsSkeletonMask(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 e953386b04..bee8701825 100644 --- a/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkTbssImage.h +++ b/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkTbssImage.h @@ -1,171 +1,185 @@ /*========================================================================= 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, GRADIENT_X, GRADIENT_Y, GRADIENT_Z, + TUBULAR_STRUCTURE, + DISTANCE_MAP, 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; - } + itkGetMacro(IsMeta, bool) + itkGetMacro(ContainsGradient, bool) + itkGetMacro(ContainsMeanSkeleton, bool) + itkGetMacro(ContainsSkeletonMask, bool) + itkGetMacro(ContainsDistanceMap, bool) + itkSetMacro(IsMeta, bool) + itkSetMacro(ContainsGradient, bool) + itkSetMacro(ContainsMeanSkeleton, bool) + itkSetMacro(ContainsSkeletonMask, bool) + itkSetMacro(ContainsDistanceMap, bool) + + 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; bool m_ContainsGradient; + bool m_ContainsMeanSkeleton; + + bool m_ContainsSkeletonMask; + + bool m_ContainsDistanceMap; + + + }; /* // 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 79b0dad0f6..405d92b4c1 100644 --- a/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkTbssImporter.cpp +++ b/Modules/DiffusionImaging/IODataStructures/TbssImages/mitkTbssImporter.cpp @@ -1,337 +1,355 @@ /*========================================================================= 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 #include "itkNrrdImageIO.h" 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); 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; // Gradient images are vector images, so they will add more dimensions to the vector int vecLength = m_MetaFiles.size(); //Check if there is a gradient image for(int i=0; i < m_MetaFiles.size(); i++) { std::pair p = m_MetaFiles.at(i); if(RetrieveTbssFunction(p.first) == mitk::TbssImage::GRADIENT_X) { vecLength += 2; } } + int currIndex = 0; + for(int i=0; i < m_MetaFiles.size(); i++) { std::pair 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; if(pair.first == mitk::TbssImage::GRADIENT_X) { metaInfo.push_back(std::pair(mitk::TbssImage::GRADIENT_X, i)); metaInfo.push_back(std::pair(mitk::TbssImage::GRADIENT_Y, i+1)); metaInfo.push_back(std::pair(mitk::TbssImage::GRADIENT_Z, i+2)); VectorReaderType::Pointer fileReader = VectorReaderType::New(); fileReader->SetFileName(file); itk::NrrdImageIO::Pointer io = itk::NrrdImageIO::New(); fileReader->SetImageIO(io); fileReader->Update(); VectorImageType::Pointer img = fileReader->GetOutput(); VectorImageType::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(vecLength); m_Data->Allocate(); } /* Dealing with a gradient image, so the size of the vector need to be increased by 2 since this image contains 3 volumes. Old data should not be deleted*/ for(int x=0; x ix; ix[0] = x; ix[1] = y; ix[2] = z; itk::VariableLengthVector vec = img->GetPixel(ix); itk::VariableLengthVector pixel = m_Data->GetPixel(ix); for(int j=0; jSetPixel(ix, pixel); } } } + currIndex += img->GetVectorLength(); + tbssImg->SetContainsGradient(true); // Read vector image and add to m_Data } else { 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(vecLength); - /* - if(containsGradient) - { - m_Data->SetVectorLength(m_MetaFiles.size()+2); - } - else{ - m_Data->SetVectorLength(m_MetaFiles.size()); - }*/ + m_Data->SetVectorLength(vecLength); 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); + pixel.SetElement(currIndex, f); m_Data->SetPixel(ix, pixel); } } } } + if(pair.first == mitk::TbssImage::MEAN_FA_SKELETON) + { + tbssImg->SetContainsMeanSkeleton(true); + } + else if(pair.first == mitk::TbssImage::MEAN_FA_SKELETON_MASK) + { + tbssImg->SetContainsSkeletonMask(true); + } + else if(pair.first == mitk::TbssImage::DISTANCE_MAP) + { + tbssImg->SetContainsDistanceMap(true); + } + + currIndex++; + } 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; } else if(s == "gradient image") { return mitk::TbssImage::GRADIENT_X; } - + else if(s == "tubular structure") + { + return mitk::TbssImage::TUBULAR_STRUCTURE; + } + else if(s == "distance map") + { + return mitk::TbssImage::DISTANCE_MAP; + } return mitk::TbssImage::MISC; } } #endif // __mitkTbssImporter_cpp