diff --git a/Modules/DiffusionImaging/DiffusionIO/CMakeLists.txt b/Modules/DiffusionImaging/DiffusionIO/CMakeLists.txt index 134852a470..fd6007c431 100644 --- a/Modules/DiffusionImaging/DiffusionIO/CMakeLists.txt +++ b/Modules/DiffusionImaging/DiffusionIO/CMakeLists.txt @@ -1,7 +1,8 @@ MITK_CREATE_MODULE( SUBPROJECTS MITK-DTI + INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR} DEPENDS MitkConnectomics MitkQuantification MitkFiberTracking AUTOLOAD_WITH MitkCore WARNINGS_AS_ERRORS ) diff --git a/Modules/DiffusionImaging/DiffusionIO/files.cmake b/Modules/DiffusionImaging/DiffusionIO/files.cmake index 8d8f04bd0d..5686192842 100644 --- a/Modules/DiffusionImaging/DiffusionIO/files.cmake +++ b/Modules/DiffusionImaging/DiffusionIO/files.cmake @@ -1,39 +1,39 @@ set(CPP_FILES mitkDiffusionModuleActivator.cpp mitkNrrdTbssImageWriterFactory.cpp #mitkFiberBundleXIOFactory.cpp mitkConnectomicsNetworkReader.cpp mitkConnectomicsNetworkWriter.cpp mitkConnectomicsNetworkSerializer.cpp mitkConnectomicsNetworkDefinitions.cpp mitkNrrdTbssRoiImageIOFactory.cpp #mitkFiberBundleXWriterFactory.cpp mitkNrrdTbssRoiImageWriterFactory.cpp mitkNrrdTensorImageReader.cpp mitkNrrdTensorImageWriter.cpp mitkTensorImageSerializer.cpp mitkTensorImageSource.cpp mitkFiberTrackingObjectFactory.cpp mitkConnectomicsObjectFactory.cpp mitkQuantificationObjectFactory.cpp mitkNrrdTbssImageIOFactory.cpp mitkDiffusionCoreObjectFactory.cpp mitkDiffusionIOMimeTypes.cpp mitkNrrdDiffusionImageReader.cpp mitkNrrdDiffusionImageWriter.cpp - mitkDiffusionImageSerializer.cpp mitkNrrdQBallImageReader.cpp mitkNrrdQBallImageWriter.cpp mitkQBallImageSerializer.cpp mitkFiberBundleXReader.cpp mitkFiberBundleXWriter.cpp mitkFiberBundleXSerializer.cpp mitkFiberBundleXMapper2D.cpp mitkFiberBundleXMapper3D.cpp mitkCompositeMapper.cpp + ) diff --git a/Modules/DiffusionImaging/DiffusionIO/mitkDiffusionCoreObjectFactory.cpp b/Modules/DiffusionImaging/DiffusionIO/mitkDiffusionCoreObjectFactory.cpp index 6a33ecfd0e..9282a2e9d3 100644 --- a/Modules/DiffusionImaging/DiffusionIO/mitkDiffusionCoreObjectFactory.cpp +++ b/Modules/DiffusionImaging/DiffusionIO/mitkDiffusionCoreObjectFactory.cpp @@ -1,181 +1,159 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkDiffusionCoreObjectFactory.h" #include "mitkProperties.h" #include "mitkBaseRenderer.h" #include "mitkDataNode.h" #include "mitkNrrdDiffusionImageWriter.h" -#include "mitkDiffusionImage.h" #include "mitkCompositeMapper.h" -#include "mitkDiffusionImageMapper.h" #include "mitkGPUVolumeMapper3D.h" #include "mitkVolumeDataVtkMapper3D.h" typedef short DiffusionPixelType; -typedef mitk::DiffusionImage DiffusionImageShort; typedef std::multimap MultimapType; mitk::DiffusionCoreObjectFactory::DiffusionCoreObjectFactory() : CoreObjectFactoryBase() { static bool alreadyDone = false; if (!alreadyDone) { MITK_DEBUG << "DiffusionCoreObjectFactory c'tor" << std::endl; CreateFileExtensionsMap(); alreadyDone = true; } } mitk::DiffusionCoreObjectFactory::~DiffusionCoreObjectFactory() { } mitk::Mapper::Pointer mitk::DiffusionCoreObjectFactory::CreateMapper(mitk::DataNode* node, MapperSlotId id) { mitk::Mapper::Pointer newMapper=NULL; if ( id == mitk::BaseRenderer::Standard2D ) { std::string classname("QBallImage"); if(node->GetData() && classname.compare(node->GetData()->GetNameOfClass())==0) { newMapper = mitk::CompositeMapper::New(); newMapper->SetDataNode(node); node->SetMapper(3, ((CompositeMapper*)newMapper.GetPointer())->GetImageMapper()); } classname = "TensorImage"; if(node->GetData() && classname.compare(node->GetData()->GetNameOfClass())==0) { newMapper = mitk::CompositeMapper::New(); newMapper->SetDataNode(node); node->SetMapper(3, ((CompositeMapper*)newMapper.GetPointer())->GetImageMapper()); } - classname = "DiffusionImage"; - if(node->GetData() && classname.compare(node->GetData()->GetNameOfClass())==0) - { - newMapper = mitk::DiffusionImageMapper::New(); - newMapper->SetDataNode(node); - } - } else if ( id == mitk::BaseRenderer::Standard3D ) { std::string classname("QBallImage"); if(node->GetData() && classname.compare(node->GetData()->GetNameOfClass())==0) { newMapper = mitk::GPUVolumeMapper3D::New(); newMapper->SetDataNode(node); } classname = "TensorImage"; if(node->GetData() && classname.compare(node->GetData()->GetNameOfClass())==0) { newMapper = mitk::GPUVolumeMapper3D::New(); newMapper->SetDataNode(node); } - classname = "DiffusionImage"; - if(node->GetData() && classname.compare(node->GetData()->GetNameOfClass())==0) - { - newMapper = mitk::GPUVolumeMapper3D::New(); - newMapper->SetDataNode(node); - } } return newMapper; } void mitk::DiffusionCoreObjectFactory::SetDefaultProperties(mitk::DataNode* node) { std::string classname = "QBallImage"; if(node->GetData() && classname.compare(node->GetData()->GetNameOfClass())==0) { mitk::CompositeMapper::SetDefaultProperties(node); mitk::GPUVolumeMapper3D::SetDefaultProperties(node); } classname = "TensorImage"; if(node->GetData() && classname.compare(node->GetData()->GetNameOfClass())==0) { mitk::CompositeMapper::SetDefaultProperties(node); mitk::GPUVolumeMapper3D::SetDefaultProperties(node); } - classname = "DiffusionImage"; - if(node->GetData() && classname.compare(node->GetData()->GetNameOfClass())==0) - { - mitk::DiffusionImageMapper::SetDefaultProperties(node); - mitk::GPUVolumeMapper3D::SetDefaultProperties(node); - } } const char* mitk::DiffusionCoreObjectFactory::GetFileExtensions() { std::string fileExtension; this->CreateFileExtensions(m_FileExtensionsMap, fileExtension); return fileExtension.c_str(); } mitk::CoreObjectFactoryBase::MultimapType mitk::DiffusionCoreObjectFactory::GetFileExtensionsMap() { return m_FileExtensionsMap; } const char* mitk::DiffusionCoreObjectFactory::GetSaveFileExtensions() { std::string fileExtension; this->CreateFileExtensions(m_SaveFileExtensionsMap, fileExtension); return fileExtension.c_str(); } mitk::CoreObjectFactoryBase::MultimapType mitk::DiffusionCoreObjectFactory::GetSaveFileExtensionsMap() { return m_SaveFileExtensionsMap; } void mitk::DiffusionCoreObjectFactory::CreateFileExtensionsMap() { } struct RegisterDiffusionCoreObjectFactory{ RegisterDiffusionCoreObjectFactory() : m_Factory( mitk::DiffusionCoreObjectFactory::New() ) { mitk::CoreObjectFactory::GetInstance()->RegisterExtraFactory( m_Factory ); } ~RegisterDiffusionCoreObjectFactory() { mitk::CoreObjectFactory::GetInstance()->UnRegisterExtraFactory( m_Factory ); } mitk::DiffusionCoreObjectFactory::Pointer m_Factory; }; static RegisterDiffusionCoreObjectFactory registerDiffusionCoreObjectFactory; diff --git a/Modules/DiffusionImaging/DiffusionIO/mitkNrrdDiffusionImageReader.cpp b/Modules/DiffusionImaging/DiffusionIO/mitkNrrdDiffusionImageReader.cpp index fd381448fa..bd86415a15 100644 --- a/Modules/DiffusionImaging/DiffusionIO/mitkNrrdDiffusionImageReader.cpp +++ b/Modules/DiffusionImaging/DiffusionIO/mitkNrrdDiffusionImageReader.cpp @@ -1,420 +1,434 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef __mitkNrrdDiffusionImageReader_cpp #define __mitkNrrdDiffusionImageReader_cpp #include "mitkNrrdDiffusionImageReader.h" +#include +#include + + +// Diffusion properties +#include +#include +#include +#include + +// ITK includes +#include +#include +#include "itksys/SystemTools.hxx" #include "itkImageFileReader.h" #include "itkMetaDataObject.h" #include "itkNrrdImageIO.h" #include "itkNiftiImageIO.h" -#include -#include - -#include "itksys/SystemTools.hxx" #include "mitkCustomMimeType.h" #include "mitkDiffusionIOMimeTypes.h" -namespace mitk -{ - -NrrdDiffusionImageReader:: -NrrdDiffusionImageReader(const NrrdDiffusionImageReader & other) - : AbstractFileReader(other) -{ -} +#include +#include +#include +#include +#include "mitkIOUtil.h" -NrrdDiffusionImageReader* NrrdDiffusionImageReader::Clone() const +namespace mitk { - return new NrrdDiffusionImageReader(*this); -} - -NrrdDiffusionImageReader:: -~NrrdDiffusionImageReader() -{} + NrrdDiffusionImageReader:: + NrrdDiffusionImageReader(const NrrdDiffusionImageReader & other) + : AbstractFileReader(other) + { + } -NrrdDiffusionImageReader:: -NrrdDiffusionImageReader() - : mitk::AbstractFileReader( CustomMimeType( mitk::DiffusionIOMimeTypes::DWI_MIMETYPE_NAME() ), mitk::DiffusionIOMimeTypes::DWI_MIMETYPE_DESCRIPTION() ) -{ - m_ServiceReg = this->RegisterService(); -} + NrrdDiffusionImageReader* NrrdDiffusionImageReader::Clone() const + { + return new NrrdDiffusionImageReader(*this); + } -std::vector > -NrrdDiffusionImageReader:: -Read() -{ - std::vector > result; - // 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! + NrrdDiffusionImageReader:: + ~NrrdDiffusionImageReader() + {} - if(m_OutputCache.IsNull()) InternalRead(); + NrrdDiffusionImageReader:: + NrrdDiffusionImageReader() + : mitk::AbstractFileReader( CustomMimeType( mitk::DiffusionIOMimeTypes::DWI_MIMETYPE_NAME() ), mitk::DiffusionIOMimeTypes::DWI_MIMETYPE_DESCRIPTION() ) + { + m_ServiceReg = this->RegisterService(); + } - OutputType::Pointer resultImage = OutputType::New(); - resultImage->SetVectorImage(m_OutputCache->GetVectorImage()); - resultImage->SetReferenceBValue(m_OutputCache->GetReferenceBValue()); - resultImage->SetMeasurementFrame(m_OutputCache->GetMeasurementFrame()); - resultImage->SetDirections(m_OutputCache->GetDirections()); - resultImage->InitializeFromVectorImage(); + std::vector > + NrrdDiffusionImageReader:: + Read() + { + std::vector > result; - result.push_back(resultImage.GetPointer()); - return result; -} + // 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.IsNull()) InternalRead(); -void NrrdDiffusionImageReader::InternalRead() -{ - OutputType::Pointer outputForCache = OutputType::New(); - if ( this->GetInputLocation() == "") - { - throw itk::ImageFileReaderException(__FILE__, __LINE__, "Sorry, the filename to be read is empty!"); + result.push_back(m_OutputCache.GetPointer()); + return result; } - else + + + void NrrdDiffusionImageReader::InternalRead() { - try + OutputType::Pointer outputForCache = OutputType::New(); + if ( this->GetInputLocation() == "") { - const std::string& locale = "C"; - const std::string& currLocale = setlocale( LC_ALL, NULL ); - - if ( locale.compare(currLocale)!=0 ) + throw itk::ImageFileReaderException(__FILE__, __LINE__, "Sorry, the filename to be read is empty!"); + } + else + { + try { - try + const std::string& locale = "C"; + const std::string& currLocale = setlocale( LC_ALL, NULL ); + + if ( locale.compare(currLocale)!=0 ) { - setlocale(LC_ALL, locale.c_str()); + try + { + setlocale(LC_ALL, locale.c_str()); + } + catch(...) + { + MITK_INFO << "Could not set locale " << locale; + } } - catch(...) + + + MITK_INFO << "NrrdDiffusionImageReader: reading image information"; + VectorImageType::Pointer itkVectorImage; + + std::string ext = itksys::SystemTools::GetFilenameLastExtension(this->GetInputLocation()); + ext = itksys::SystemTools::LowerCase(ext); + if (ext == ".hdwi" || ext == ".dwi" || ext == ".nrrd") { - MITK_INFO << "Could not set locale " << locale; + typedef itk::ImageFileReader FileReaderType; + FileReaderType::Pointer reader = FileReaderType::New(); + reader->SetFileName(this->GetInputLocation()); + itk::NrrdImageIO::Pointer io = itk::NrrdImageIO::New(); + reader->SetImageIO(io); + reader->Update(); + itkVectorImage = reader->GetOutput(); } - } + else if(ext == ".fsl" || ext == ".fslgz") + { + // create temporary file with correct ending for nifti-io + std::string fname3 = "temp_dwi"; + fname3 += ext == ".fsl" ? ".nii" : ".nii.gz"; + itksys::SystemTools::CopyAFile(this->GetInputLocation().c_str(), fname3.c_str()); + + // create reader and read file + typedef itk::Image ImageType4D; + itk::NiftiImageIO::Pointer io2 = itk::NiftiImageIO::New(); + typedef itk::ImageFileReader FileReaderType; + FileReaderType::Pointer reader = FileReaderType::New(); + reader->SetFileName(fname3); + reader->SetImageIO(io2); + reader->Update(); + ImageType4D::Pointer img4 = reader->GetOutput(); + + // delete temporary file + itksys::SystemTools::RemoveFile(fname3.c_str()); + + // convert 4D file to vector image + itkVectorImage = VectorImageType::New(); + + VectorImageType::SpacingType spacing; + ImageType4D::SpacingType spacing4 = img4->GetSpacing(); + for(int i=0; i<3; i++) + spacing[i] = spacing4[i]; + itkVectorImage->SetSpacing( spacing ); // Set the image spacing + VectorImageType::PointType origin; + ImageType4D::PointType origin4 = img4->GetOrigin(); + for(int i=0; i<3; i++) + origin[i] = origin4[i]; + itkVectorImage->SetOrigin( origin ); // Set the image origin - MITK_INFO << "NrrdDiffusionImageReader: reading image information"; - ImageType::Pointer img; + VectorImageType::DirectionType direction; + ImageType4D::DirectionType direction4 = img4->GetDirection(); + for(int i=0; i<3; i++) + for(int j=0; j<3; j++) + direction[i][j] = direction4[i][j]; + itkVectorImage->SetDirection( direction ); // Set the image direction - std::string ext = itksys::SystemTools::GetFilenameLastExtension(this->GetInputLocation()); - ext = itksys::SystemTools::LowerCase(ext); - if (ext == ".hdwi" || ext == ".dwi") - { - typedef itk::ImageFileReader FileReaderType; - FileReaderType::Pointer reader = FileReaderType::New(); - reader->SetFileName(this->GetInputLocation()); - itk::NrrdImageIO::Pointer io = itk::NrrdImageIO::New(); - reader->SetImageIO(io); - reader->Update(); - img = reader->GetOutput(); + VectorImageType::RegionType region; + ImageType4D::RegionType region4 = img4->GetLargestPossibleRegion(); - int vecsize = img->GetVectorLength(); - std::cout << vecsize << std::endl; + VectorImageType::RegionType::SizeType size; + ImageType4D::RegionType::SizeType size4 = region4.GetSize(); + for(int i=0; i<3; i++) + size[i] = size4[i]; - } - else if(ext == ".fsl" || ext == ".fslgz") - { - // create temporary file with correct ending for nifti-io - std::string fname3 = "temp_dwi"; - fname3 += ext == ".fsl" ? ".nii" : ".nii.gz"; - itksys::SystemTools::CopyAFile(this->GetInputLocation().c_str(), fname3.c_str()); - - // create reader and read file - typedef itk::Image ImageType4D; - itk::NiftiImageIO::Pointer io2 = itk::NiftiImageIO::New(); - typedef itk::ImageFileReader FileReaderType; - FileReaderType::Pointer reader = FileReaderType::New(); - reader->SetFileName(fname3); - reader->SetImageIO(io2); - reader->Update(); - ImageType4D::Pointer img4 = reader->GetOutput(); - - // delete temporary file - itksys::SystemTools::RemoveFile(fname3.c_str()); - - // convert 4D file to vector image - img = ImageType::New(); - - ImageType::SpacingType spacing; - ImageType4D::SpacingType spacing4 = img4->GetSpacing(); - for(int i=0; i<3; i++) - spacing[i] = spacing4[i]; - img->SetSpacing( spacing ); // Set the image spacing - - ImageType::PointType origin; - ImageType4D::PointType origin4 = img4->GetOrigin(); - for(int i=0; i<3; i++) - origin[i] = origin4[i]; - img->SetOrigin( origin ); // Set the image origin - - ImageType::DirectionType direction; - ImageType4D::DirectionType direction4 = img4->GetDirection(); - for(int i=0; i<3; i++) - for(int j=0; j<3; j++) - direction[i][j] = direction4[i][j]; - img->SetDirection( direction ); // Set the image direction - - ImageType::RegionType region; - ImageType4D::RegionType region4 = img4->GetLargestPossibleRegion(); - - ImageType::RegionType::SizeType size; - ImageType4D::RegionType::SizeType size4 = region4.GetSize(); - - for(int i=0; i<3; i++) - size[i] = size4[i]; - - ImageType::RegionType::IndexType index; - ImageType4D::RegionType::IndexType index4 = region4.GetIndex(); - for(int i=0; i<3; i++) - index[i] = index4[i]; - - region.SetSize(size); - region.SetIndex(index); - img->SetRegions( region ); - - img->SetVectorLength(size4[3]); - img->Allocate(); - - itk::ImageRegionIterator it (img, img->GetLargestPossibleRegion() ); - typedef ImageType::PixelType VecPixType; - for (it.GoToBegin(); !it.IsAtEnd(); ++it) - { - VecPixType vec = it.Get(); - ImageType::IndexType currentIndex = it.GetIndex(); + VectorImageType::RegionType::IndexType index; + ImageType4D::RegionType::IndexType index4 = region4.GetIndex(); for(int i=0; i<3; i++) - index4[i] = currentIndex[i]; - for(unsigned int ind=0; indSetRegions( region ); + + itkVectorImage->SetVectorLength(size4[3]); + itkVectorImage->Allocate(); + + itk::ImageRegionIterator it ( itkVectorImage, itkVectorImage->GetLargestPossibleRegion() ); + typedef VectorImageType::PixelType VecPixType; + for (it.GoToBegin(); !it.IsAtEnd(); ++it) { - index4[3] = ind; - vec[ind] = img4->GetPixel(index4); + VecPixType vec = it.Get(); + VectorImageType::IndexType currentIndex = it.GetIndex(); + for(int i=0; i<3; i++) + index4[i] = currentIndex[i]; + for(unsigned int ind=0; indGetPixel(index4); + } + it.Set(vec); } - it.Set(vec); } - } - m_DiffusionVectors = GradientDirectionContainerType::New(); - m_OriginalDiffusionVectors = GradientDirectionContainerType::New(); - if (ext == ".hdwi" || ext == ".dwi") - { + // Diffusion Image information START + GradientDirectionContainerType::Pointer DiffusionVectors = GradientDirectionContainerType::New(); + GradientDirectionContainerType::Pointer OriginalDiffusionVectors = GradientDirectionContainerType::New(); + MeasurementFrameType MeasurementFrame; + float BValue = -1; + // Diffusion Image information END - itk::MetaDataDictionary imgMetaDictionary = img->GetMetaDataDictionary(); - std::vector imgMetaKeys = imgMetaDictionary.GetKeys(); - std::vector::const_iterator itKey = imgMetaKeys.begin(); - std::string metaString; + if (ext == ".hdwi" || ext == ".dwi" || ext == ".nrrd") + { - GradientDirectionType vect3d; + itk::MetaDataDictionary imgMetaDictionary = itkVectorImage->GetMetaDataDictionary(); + std::vector imgMetaKeys = imgMetaDictionary.GetKeys(); + std::vector::const_iterator itKey = imgMetaKeys.begin(); + std::string metaString; - int numberOfImages = 0; - int numberOfGradientImages = 0; - bool readb0 = false; - double xx, xy, xz, yx, yy, yz, zx, zy, zz; + GradientDirectionType vect3d; - for (; itKey != imgMetaKeys.end(); itKey ++) - { - double x,y,z; + int numberOfImages = 0; + int numberOfGradientImages = 0; + bool readb0 = false; + double xx, xy, xz, yx, yy, yz, zx, zy, zz; - itk::ExposeMetaData (imgMetaDictionary, *itKey, metaString); - if (itKey->find("DWMRI_gradient") != std::string::npos) + for (; itKey != imgMetaKeys.end(); itKey ++) { - sscanf(metaString.c_str(), "%lf %lf %lf\n", &x, &y, &z); - vect3d[0] = x; vect3d[1] = y; vect3d[2] = z; - m_DiffusionVectors->InsertElement( numberOfImages, vect3d ); - ++numberOfImages; - // If the direction is 0.0, this is a reference image - if (vect3d[0] == 0.0 && - vect3d[1] == 0.0 && - vect3d[2] == 0.0) + double x,y,z; + + itk::ExposeMetaData (imgMetaDictionary, *itKey, metaString); + if (itKey->find("DWMRI_gradient") != std::string::npos) { - continue; + sscanf(metaString.c_str(), "%lf %lf %lf\n", &x, &y, &z); + vect3d[0] = x; vect3d[1] = y; vect3d[2] = z; + DiffusionVectors->InsertElement( numberOfImages, vect3d ); + ++numberOfImages; + // If the direction is 0.0, this is a reference image + if (vect3d[0] == 0.0 && + vect3d[1] == 0.0 && + vect3d[2] == 0.0) + { + continue; + } + ++numberOfGradientImages;; } - ++numberOfGradientImages;; - } - else if (itKey->find("DWMRI_b-value") != std::string::npos) - { - readb0 = true; - m_B_Value = atof(metaString.c_str()); - } - else if (itKey->find("measurement frame") != std::string::npos) - { - sscanf(metaString.c_str(), " ( %lf , %lf , %lf ) ( %lf , %lf , %lf ) ( %lf , %lf , %lf ) \n", &xx, &xy, &xz, &yx, &yy, &yz, &zx, &zy, &zz); - - if (xx>10e-10 || xy>10e-10 || xz>10e-10 || - yx>10e-10 || yy>10e-10 || yz>10e-10 || - zx>10e-10 || zy>10e-10 || zz>10e-10 ) + else if (itKey->find("DWMRI_b-value") != std::string::npos) { - m_MeasurementFrame(0,0) = xx; - m_MeasurementFrame(0,1) = xy; - m_MeasurementFrame(0,2) = xz; - m_MeasurementFrame(1,0) = yx; - m_MeasurementFrame(1,1) = yy; - m_MeasurementFrame(1,2) = yz; - m_MeasurementFrame(2,0) = zx; - m_MeasurementFrame(2,1) = zy; - m_MeasurementFrame(2,2) = zz; + readb0 = true; + BValue = atof(metaString.c_str()); } - else + else if (itKey->find("measurement frame") != std::string::npos) { - m_MeasurementFrame(0,0) = 1; - m_MeasurementFrame(0,1) = 0; - m_MeasurementFrame(0,2) = 0; - m_MeasurementFrame(1,0) = 0; - m_MeasurementFrame(1,1) = 1; - m_MeasurementFrame(1,2) = 0; - m_MeasurementFrame(2,0) = 0; - m_MeasurementFrame(2,1) = 0; - m_MeasurementFrame(2,2) = 1; + sscanf(metaString.c_str(), " ( %lf , %lf , %lf ) ( %lf , %lf , %lf ) ( %lf , %lf , %lf ) \n", &xx, &xy, &xz, &yx, &yy, &yz, &zx, &zy, &zz); + + if (xx>10e-10 || xy>10e-10 || xz>10e-10 || + yx>10e-10 || yy>10e-10 || yz>10e-10 || + zx>10e-10 || zy>10e-10 || zz>10e-10 ) + { + MeasurementFrame(0,0) = xx; + MeasurementFrame(0,1) = xy; + MeasurementFrame(0,2) = xz; + MeasurementFrame(1,0) = yx; + MeasurementFrame(1,1) = yy; + MeasurementFrame(1,2) = yz; + MeasurementFrame(2,0) = zx; + MeasurementFrame(2,1) = zy; + MeasurementFrame(2,2) = zz; + } + else + { + MeasurementFrame(0,0) = 1; + MeasurementFrame(0,1) = 0; + MeasurementFrame(0,2) = 0; + MeasurementFrame(1,0) = 0; + MeasurementFrame(1,1) = 1; + MeasurementFrame(1,2) = 0; + MeasurementFrame(2,0) = 0; + MeasurementFrame(2,1) = 0; + MeasurementFrame(2,2) = 1; + } } } - } - - if(!readb0) - { - MITK_INFO << "BValue not specified in header file"; - } - } - else if(ext == ".fsl" || ext == ".fslgz") - { + if(!readb0) + { + MITK_INFO << "BValue not specified in header file"; + } - std::string line; - std::vector bvec_entries; - std::string fname = this->GetInputLocation(); - fname += ".bvecs"; - std::ifstream myfile (fname.c_str()); - if (myfile.is_open()) + } + else if(ext == ".fsl" || ext == ".fslgz") { - while ( myfile.good() ) + + std::string line; + std::vector bvec_entries; + std::string fname = this->GetInputLocation(); + fname += ".bvecs"; + std::ifstream myfile (fname.c_str()); + if (myfile.is_open()) { - getline (myfile,line); - char* pch = strtok (const_cast(line.c_str())," "); - while (pch != NULL) + while ( myfile.good() ) { - bvec_entries.push_back(atof(pch)); - pch = strtok (NULL, " "); + getline (myfile,line); + char* pch = strtok (const_cast(line.c_str())," "); + while (pch != NULL) + { + bvec_entries.push_back(atof(pch)); + pch = strtok (NULL, " "); + } } + myfile.close(); + } + else + { + MITK_INFO << "Unable to open bvecs file"; } - myfile.close(); - } - else - { - MITK_INFO << "Unable to open bvecs file"; - } - std::vector bval_entries; - std::string fname2 = this->GetInputLocation(); - fname2 += ".bvals"; - std::ifstream myfile2 (fname2.c_str()); - if (myfile2.is_open()) - { - while ( myfile2.good() ) + std::vector bval_entries; + std::string fname2 = this->GetInputLocation(); + fname2 += ".bvals"; + std::ifstream myfile2 (fname2.c_str()); + if (myfile2.is_open()) { - getline (myfile2,line); - char* pch = strtok (const_cast(line.c_str())," "); - while (pch != NULL) + while ( myfile2.good() ) { - bval_entries.push_back(atof(pch)); - pch = strtok (NULL, " "); + getline (myfile2,line); + char* pch = strtok (const_cast(line.c_str())," "); + while (pch != NULL) + { + bval_entries.push_back(atof(pch)); + pch = strtok (NULL, " "); + } } + myfile2.close(); + } + else + { + MITK_INFO << "Unable to open bvals file"; } - myfile2.close(); - } - else - { - MITK_INFO << "Unable to open bvals file"; - } - - m_B_Value = -1; - unsigned int numb = bval_entries.size(); - for(unsigned int i=0; i vec; - vec[0] = bvec_entries.at(i); - vec[1] = bvec_entries.at(i+numb); - vec[2] = bvec_entries.at(i+2*numb); - // Adjust the vector length to encode gradient strength - float factor = b_val/m_B_Value; - if(vec.magnitude() > 0) - { - vec[0] = sqrt(factor)*vec[0]; - vec[1] = sqrt(factor)*vec[1]; - vec[2] = sqrt(factor)*vec[2]; + vnl_vector_fixed< double, 3 > vec; + vec[0] = bvec_entries.at(i); + vec[1] = bvec_entries.at(i+numb); + vec[2] = bvec_entries.at(i+2*numb); + + // Adjust the vector length to encode gradient strength + float factor = b_val/BValue; + if(vec.magnitude() > 0) + { + vec[0] = sqrt(factor)*vec[0]; + vec[1] = sqrt(factor)*vec[1]; + vec[2] = sqrt(factor)*vec[2]; + } + + DiffusionVectors->InsertElement(i,vec); } - m_DiffusionVectors->InsertElement(i,vec); + for(int i=0; i<3; i++) + for(int j=0; j<3; j++) + MeasurementFrame[i][j] = i==j ? 1 : 0; } - for(int i=0; i<3; i++) - for(int j=0; j<3; j++) - m_MeasurementFrame[i][j] = i==j ? 1 : 0; - } + outputForCache = mitk::GrabItkImageMemory( itkVectorImage); - outputForCache->SetVectorImage(img); - outputForCache->SetReferenceBValue(m_B_Value); - outputForCache->SetMeasurementFrame(m_MeasurementFrame); - outputForCache->SetDirections(m_DiffusionVectors); + // create BValueMap + mitk::BValueMapProperty::BValueMap BValueMap = mitk::BValueMapProperty::CreateBValueMap(DiffusionVectors,BValue); + outputForCache->SetProperty( mitk::DiffusionPropertyHelper::GRADIENTCONTAINERPROPERTYNAME.c_str(), mitk::GradientDirectionsProperty::New( DiffusionVectors ) ); + outputForCache->SetProperty( mitk::DiffusionPropertyHelper::ORIGINALGRADIENTCONTAINERPROPERTYNAME.c_str(), mitk::GradientDirectionsProperty::New( OriginalDiffusionVectors ) ); + outputForCache->SetProperty( mitk::DiffusionPropertyHelper::MEASUREMENTFRAMEPROPERTYNAME.c_str(), mitk::MeasurementFrameProperty::New( MeasurementFrame ) ); + outputForCache->SetProperty( mitk::DiffusionPropertyHelper::BVALUEMAPPROPERTYNAME.c_str(), mitk::BValueMapProperty::New( BValueMap ) ); + outputForCache->SetProperty( mitk::DiffusionPropertyHelper::REFERENCEBVALUEPROPERTYNAME.c_str(), mitk::FloatProperty::New( BValue ) ); - // 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(); + // 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 + try + { + setlocale(LC_ALL, currLocale.c_str()); + } + catch(...) + { + MITK_INFO << "Could not reset locale " << currLocale; + } + } + catch(std::exception& e) { - setlocale(LC_ALL, currLocale.c_str()); + MITK_INFO << "Std::Exception while reading file!!"; + MITK_INFO << e.what(); + throw itk::ImageFileReaderException(__FILE__, __LINE__, e.what()); } catch(...) { - MITK_INFO << "Could not reset locale " << currLocale; + MITK_INFO << "Exception while reading file!!"; + throw itk::ImageFileReaderException(__FILE__, __LINE__, "Sorry, an error occurred while reading the requested vessel tree file!"); } } - 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!"); - } } -} } //namespace MITK #endif diff --git a/Modules/DiffusionImaging/DiffusionIO/mitkNrrdDiffusionImageReader.h b/Modules/DiffusionImaging/DiffusionIO/mitkNrrdDiffusionImageReader.h index f7c10669af..ac1fb1d29c 100644 --- a/Modules/DiffusionImaging/DiffusionIO/mitkNrrdDiffusionImageReader.h +++ b/Modules/DiffusionImaging/DiffusionIO/mitkNrrdDiffusionImageReader.h @@ -1,72 +1,73 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef __mitkNrrdDiffusionImageReader_h #define __mitkNrrdDiffusionImageReader_h #include "mitkCommon.h" -#include "itkVectorContainer.h" + +// MITK includes +#include "mitkImageSource.h" #include "mitkFileReader.h" -#include "vnl/vnl_vector_fixed.h" -#include "vnl/vnl_matrix_fixed.h" +#include + +// ITK includes #include "itkVectorImage.h" #include "mitkAbstractFileReader.h" -#include "mitkDiffusionImage.h" + + namespace mitk { /** \brief */ class NrrdDiffusionImageReader : public mitk::AbstractFileReader { public: NrrdDiffusionImageReader(const NrrdDiffusionImageReader & other); NrrdDiffusionImageReader(); virtual ~NrrdDiffusionImageReader(); using AbstractFileReader::Read; virtual std::vector > Read(); - typedef mitk::DiffusionImage OutputType; - typedef itk::VectorImage ImageType; - typedef vnl_vector_fixed< double, 3 > GradientDirectionType; - typedef vnl_matrix_fixed< double, 3, 3 > MeasurementFrameType; - typedef itk::VectorContainer< unsigned int,GradientDirectionType > GradientDirectionContainerType; + typedef short DiffusionPixelType; + + typedef mitk::Image OutputType; + typedef mitk::DiffusionPropertyHelper::ImageType VectorImageType; + typedef mitk::DiffusionPropertyHelper::GradientDirectionType GradientDirectionType; + typedef mitk::DiffusionPropertyHelper::MeasurementFrameType MeasurementFrameType; + typedef mitk::DiffusionPropertyHelper::GradientDirectionsContainerType GradientDirectionContainerType; protected: OutputType::Pointer m_OutputCache; itk::TimeStamp m_CacheTime; - GradientDirectionContainerType::Pointer m_OriginalDiffusionVectors; - GradientDirectionContainerType::Pointer m_DiffusionVectors; - float m_B_Value; - MeasurementFrameType m_MeasurementFrame; void InternalRead(); private: NrrdDiffusionImageReader* Clone() const; us::ServiceRegistration m_ServiceReg; }; } //namespace MITK - #endif // __mitkNrrdDiffusionImageReader_h diff --git a/Modules/DiffusionImaging/DiffusionIO/mitkNrrdDiffusionImageWriter.cpp b/Modules/DiffusionImaging/DiffusionIO/mitkNrrdDiffusionImageWriter.cpp index d9f7f745ba..94f152f17f 100644 --- a/Modules/DiffusionImaging/DiffusionIO/mitkNrrdDiffusionImageWriter.cpp +++ b/Modules/DiffusionImaging/DiffusionIO/mitkNrrdDiffusionImageWriter.cpp @@ -1,326 +1,332 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef __mitkNrrdDiffusionImageWriter__cpp #define __mitkNrrdDiffusionImageWriter__cpp #include "mitkNrrdDiffusionImageWriter.h" #include "itkMetaDataDictionary.h" #include "itkMetaDataObject.h" #include "itkNrrdImageIO.h" #include "itkNiftiImageIO.h" #include "itkImageFileWriter.h" #include "itksys/SystemTools.hxx" #include "mitkDiffusionIOMimeTypes.h" +#include "mitkImageCast.h" #include #include mitk::NrrdDiffusionImageWriter::NrrdDiffusionImageWriter() - : AbstractFileWriter(mitk::DiffusionImage::GetStaticNameOfClass(), CustomMimeType( mitk::DiffusionIOMimeTypes::DWI_MIMETYPE_NAME() ), mitk::DiffusionIOMimeTypes::DWI_MIMETYPE_DESCRIPTION()) + : AbstractFileWriter(mitk::Image::GetStaticNameOfClass(), CustomMimeType( mitk::DiffusionIOMimeTypes::DWI_MIMETYPE_NAME() ), mitk::DiffusionIOMimeTypes::DWI_MIMETYPE_DESCRIPTION()) { RegisterService(); } mitk::NrrdDiffusionImageWriter::NrrdDiffusionImageWriter(const mitk::NrrdDiffusionImageWriter& other) : AbstractFileWriter(other) { } mitk::NrrdDiffusionImageWriter::~NrrdDiffusionImageWriter() {} void mitk::NrrdDiffusionImageWriter::Write() { - InputType::ConstPointer input = dynamic_cast(this->GetInput()); + mitk::Image::ConstPointer input = dynamic_cast(this->GetInput()); + + VectorImageType::Pointer itkImg; + mitk::CastToItkImage(input,itkImg); + if (input.IsNull()) { MITK_ERROR <<"Sorry, input to NrrdDiffusionImageWriter is NULL!"; return; } if ( this->GetOutputLocation().empty() ) { MITK_ERROR << "Sorry, filename has not been set!"; return ; } const std::string& locale = "C"; const std::string& currLocale = setlocale( LC_ALL, NULL ); if ( locale.compare(currLocale)!=0 ) { try { setlocale(LC_ALL, locale.c_str()); } catch(...) { MITK_INFO << "Could not set locale " << locale; } } char keybuffer[512]; char valbuffer[512]; //itk::MetaDataDictionary dic = input->GetImage()->GetMetaDataDictionary(); - vnl_matrix_fixed measurementFrame = input->GetMeasurementFrame(); + vnl_matrix_fixed measurementFrame = mitk::DiffusionPropertyHelper::GetMeasurementFrame(input); if (measurementFrame(0,0) || measurementFrame(0,1) || measurementFrame(0,2) || measurementFrame(1,0) || measurementFrame(1,1) || measurementFrame(1,2) || measurementFrame(2,0) || measurementFrame(2,1) || measurementFrame(2,2)) { sprintf( valbuffer, " (%lf,%lf,%lf) (%lf,%lf,%lf) (%lf,%lf,%lf)", measurementFrame(0,0), measurementFrame(0,1), measurementFrame(0,2), measurementFrame(1,0), measurementFrame(1,1), measurementFrame(1,2), measurementFrame(2,0), measurementFrame(2,1), measurementFrame(2,2)); - itk::EncapsulateMetaData(input->GetVectorImage()->GetMetaDataDictionary(),std::string("measurement frame"),std::string(valbuffer)); + itk::EncapsulateMetaData(itkImg->GetMetaDataDictionary(),std::string("measurement frame"),std::string(valbuffer)); } sprintf( valbuffer, "DWMRI"); - itk::EncapsulateMetaData(input->GetVectorImage()->GetMetaDataDictionary(),std::string("modality"),std::string(valbuffer)); + itk::EncapsulateMetaData(itkImg->GetMetaDataDictionary(),std::string("modality"),std::string(valbuffer)); - if(input->GetDirections()->Size()) + if(mitk::DiffusionPropertyHelper::GetGradientContainer(input)->Size()) { - sprintf( valbuffer, "%1f", input->GetReferenceBValue() ); - itk::EncapsulateMetaData(input->GetVectorImage()->GetMetaDataDictionary(),std::string("DWMRI_b-value"),std::string(valbuffer)); + sprintf( valbuffer, "%1f", mitk::DiffusionPropertyHelper::GetReferenceBValue(input) ); + itk::EncapsulateMetaData(itkImg->GetMetaDataDictionary(),std::string("DWMRI_b-value"),std::string(valbuffer)); } - for(unsigned int i=0; iGetDirections()->Size(); i++) + for(unsigned int i=0; iSize(); i++) { sprintf( keybuffer, "DWMRI_gradient_%04d", i ); /*if(itk::ExposeMetaData(input->GetMetaDataDictionary(), std::string(keybuffer),tmp)) continue;*/ - sprintf( valbuffer, "%1f %1f %1f", input->GetDirections()->ElementAt(i).get(0), - input->GetDirections()->ElementAt(i).get(1), input->GetDirections()->ElementAt(i).get(2)); + sprintf( valbuffer, "%1f %1f %1f", mitk::DiffusionPropertyHelper::GetGradientContainer(input)->ElementAt(i).get(0), + mitk::DiffusionPropertyHelper::GetGradientContainer(input)->ElementAt(i).get(1), mitk::DiffusionPropertyHelper::GetGradientContainer(input)->ElementAt(i).get(2)); - itk::EncapsulateMetaData(input->GetVectorImage()->GetMetaDataDictionary(),std::string(keybuffer),std::string(valbuffer)); + itk::EncapsulateMetaData(itkImg->GetMetaDataDictionary(),std::string(keybuffer),std::string(valbuffer)); } typedef itk::VectorImage ImageType; std::string ext = itksys::SystemTools::GetFilenameLastExtension(this->GetOutputLocation()); ext = itksys::SystemTools::LowerCase(ext); // default extension is .dwi if( ext == "") { - ext = ".dwi"; + ext = ".nrrd"; this->SetOutputLocation(this->GetOutputLocation() + ext); } - if (ext == ".hdwi" || ext == ".dwi") + if (ext == ".hdwi" || ext == ".nrrd" || ext == ".dwi") { + + MITK_INFO << "Extension " << ext; itk::NrrdImageIO::Pointer io = itk::NrrdImageIO::New(); //io->SetNrrdVectorType( nrrdKindList ); io->SetFileType( itk::ImageIOBase::Binary ); io->UseCompressionOn(); typedef itk::ImageFileWriter WriterType; WriterType::Pointer nrrdWriter = WriterType::New(); nrrdWriter->UseInputMetaDataDictionaryOn(); - nrrdWriter->SetInput( input->GetVectorImage() ); + nrrdWriter->SetInput( itkImg ); nrrdWriter->SetImageIO(io); nrrdWriter->SetFileName(this->GetOutputLocation()); nrrdWriter->UseCompressionOn(); nrrdWriter->SetImageIO(io); try { nrrdWriter->Update(); } catch (itk::ExceptionObject e) { std::cout << e << std::endl; throw; } } else if (ext == ".fsl" || ext == ".fslgz") { MITK_INFO << "Writing Nifti-Image for FSL"; - ImageType::Pointer vecimg = input->GetVectorImage(); typedef itk::Image ImageType4D; ImageType4D::Pointer img4 = ImageType4D::New(); - ImageType::SpacingType spacing = vecimg->GetSpacing(); + ImageType::SpacingType spacing = itkImg->GetSpacing(); ImageType4D::SpacingType spacing4; for(int i=0; i<3; i++) spacing4[i] = spacing[i]; spacing4[3] = 1; img4->SetSpacing( spacing4 ); // Set the image spacing - ImageType::PointType origin = vecimg->GetOrigin(); + ImageType::PointType origin = itkImg->GetOrigin(); ImageType4D::PointType origin4; for(int i=0; i<3; i++) origin4[i] = origin[i]; origin4[3] = 0; img4->SetOrigin( origin4 ); // Set the image origin - ImageType::DirectionType direction = vecimg->GetDirection(); + ImageType::DirectionType direction = itkImg->GetDirection(); ImageType4D::DirectionType direction4; for(int i=0; i<3; i++) for(int j=0; j<3; j++) direction4[i][j] = direction[i][j]; for(int i=0; i<4; i++) direction4[i][3] = 0; for(int i=0; i<4; i++) direction4[3][i] = 0; direction4[3][3] = 1; img4->SetDirection( direction4 ); // Set the image direction - ImageType::RegionType region = vecimg->GetLargestPossibleRegion(); + ImageType::RegionType region = itkImg->GetLargestPossibleRegion(); ImageType4D::RegionType region4; ImageType::RegionType::SizeType size = region.GetSize(); ImageType4D::RegionType::SizeType size4; for(int i=0; i<3; i++) size4[i] = size[i]; - size4[3] = vecimg->GetVectorLength(); + size4[3] = itkImg->GetVectorLength(); ImageType::RegionType::IndexType index = region.GetIndex(); ImageType4D::RegionType::IndexType index4; for(int i=0; i<3; i++) index4[i] = index[i]; index4[3] = 0; region4.SetSize(size4); region4.SetIndex(index4); img4->SetRegions( region4 ); img4->Allocate(); - itk::ImageRegionIterator it (vecimg, vecimg->GetLargestPossibleRegion() ); + itk::ImageRegionIterator it (itkImg, itkImg->GetLargestPossibleRegion() ); typedef ImageType::PixelType VecPixType; for (it.GoToBegin(); !it.IsAtEnd(); ++it) { VecPixType vec = it.Get(); ImageType::IndexType currentIndex = it.GetIndex(); for(unsigned int ind=0; indSetPixel(index4, vec[ind]); } } // create copy of file with correct ending for mitk std::string fname3 = this->GetOutputLocation(); std::string::iterator itend = fname3.end(); if (ext == ".fsl") fname3.replace( itend-3, itend, "nii"); else fname3.replace( itend-5, itend, "nii.gz"); itk::NiftiImageIO::Pointer io4 = itk::NiftiImageIO::New(); typedef itk::VectorImage ImageType; typedef itk::ImageFileWriter WriterType4; WriterType4::Pointer nrrdWriter4 = WriterType4::New(); nrrdWriter4->UseInputMetaDataDictionaryOn(); nrrdWriter4->SetInput( img4 ); nrrdWriter4->SetFileName(fname3); nrrdWriter4->UseCompressionOn(); nrrdWriter4->SetImageIO(io4); try { nrrdWriter4->Update(); } catch (itk::ExceptionObject e) { std::cout << e << std::endl; throw; } itksys::SystemTools::CopyAFile(fname3.c_str(), this->GetOutputLocation().c_str()); - if(input->GetDirections()->Size()) + if(mitk::DiffusionPropertyHelper::GetGradientContainer(input)->Size()) { std::ofstream myfile; std::string fname = this->GetOutputLocation(); fname += ".bvals"; myfile.open (fname.c_str()); - for(unsigned int i=0; iGetDirections()->Size(); i++) + for(unsigned int i=0; iSize(); i++) { - double twonorm = input->GetDirections()->ElementAt(i).two_norm(); - myfile << input->GetReferenceBValue()*twonorm*twonorm << " "; + double twonorm = mitk::DiffusionPropertyHelper::GetGradientContainer(input)->ElementAt(i).two_norm(); + myfile << mitk::DiffusionPropertyHelper::GetReferenceBValue(input)*twonorm*twonorm << " "; } myfile.close(); std::ofstream myfile2; std::string fname2 = this->GetOutputLocation(); fname2 += ".bvecs"; myfile2.open (fname2.c_str()); for(int j=0; j<3; j++) { - for(unsigned int i=0; iGetDirections()->Size(); i++) + for(unsigned int i=0; iSize(); i++) { //need to modify the length - mitk::DiffusionImage::GradientDirectionContainerType::Pointer grads = input->GetDirections(); - mitk::DiffusionImage::GradientDirectionType direction = grads->ElementAt(i); + GradientDirectionContainerType::Pointer grads = mitk::DiffusionPropertyHelper::GetGradientContainer(input); + GradientDirectionType direction = grads->ElementAt(i); direction.normalize(); myfile2 << direction.get(j) << " "; //myfile2 << input->GetDirections()->ElementAt(i).get(j) << " "; } myfile2 << std::endl; } std::ofstream myfile3; std::string fname4 = this->GetOutputLocation(); fname4 += ".ttk"; myfile3.open (fname4.c_str()); - for(unsigned int i=0; iGetDirections()->Size(); i++) + for(unsigned int i=0; iSize(); i++) { for(int j=0; j<3; j++) { - myfile3 << input->GetDirections()->ElementAt(i).get(j) << " "; + myfile3 << mitk::DiffusionPropertyHelper::GetGradientContainer(input)->ElementAt(i).get(j) << " "; } myfile3 << std::endl; } } } try { setlocale(LC_ALL, currLocale.c_str()); } catch(...) { MITK_INFO << "Could not reset locale " << currLocale; } } mitk::NrrdDiffusionImageWriter* mitk::NrrdDiffusionImageWriter::Clone() const { return new NrrdDiffusionImageWriter(*this); } mitk::IFileWriter::ConfidenceLevel mitk::NrrdDiffusionImageWriter::GetConfidenceLevel() const { - InputType::ConstPointer input = dynamic_cast(this->GetInput()); + mitk::Image::ConstPointer input = dynamic_cast(this->GetInput()); if (input.IsNull() ) { return Unsupported; } else { return Supported; } } #endif //__mitkNrrdDiffusionImageWriter__cpp diff --git a/Modules/DiffusionImaging/DiffusionIO/mitkNrrdDiffusionImageWriter.h b/Modules/DiffusionImaging/DiffusionIO/mitkNrrdDiffusionImageWriter.h index 072621a361..1bedf714ce 100644 --- a/Modules/DiffusionImaging/DiffusionIO/mitkNrrdDiffusionImageWriter.h +++ b/Modules/DiffusionImaging/DiffusionIO/mitkNrrdDiffusionImageWriter.h @@ -1,55 +1,58 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef _MITK_NRRDDIFFVOL_WRITER__H_ #define _MITK_NRRDDIFFVOL_WRITER__H_ #include -#include +#include namespace mitk { /** * Writes diffusion volumes to a file * @ingroup Process */ class NrrdDiffusionImageWriter : public mitk::AbstractFileWriter { public: - typedef mitk::DiffusionImage InputType; - NrrdDiffusionImageWriter(); virtual ~NrrdDiffusionImageWriter(); using AbstractFileWriter::Write; virtual void Write(); virtual ConfidenceLevel GetConfidenceLevel() const; + typedef mitk::DiffusionPropertyHelper::ImageType VectorImageType; + typedef mitk::DiffusionPropertyHelper::GradientDirectionType GradientDirectionType; + typedef mitk::DiffusionPropertyHelper::MeasurementFrameType MeasurementFrameType; + typedef mitk::DiffusionPropertyHelper::GradientDirectionsContainerType GradientDirectionContainerType; + protected: NrrdDiffusionImageWriter(const NrrdDiffusionImageWriter& other); virtual mitk::NrrdDiffusionImageWriter* Clone() const; }; } // end of namespace mitk #endif