diff --git a/Modules/DiffusionImaging/DiffusionCore/Algorithms/itkAdcImageFilter.txx b/Modules/DiffusionImaging/DiffusionCore/Algorithms/itkAdcImageFilter.txx index e489503bc0..9b205df5ad 100644 --- a/Modules/DiffusionImaging/DiffusionCore/Algorithms/itkAdcImageFilter.txx +++ b/Modules/DiffusionImaging/DiffusionCore/Algorithms/itkAdcImageFilter.txx @@ -1,126 +1,130 @@ /*=================================================================== 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 __itkAdcImageFilter_txx #define __itkAdcImageFilter_txx #include #include #include #define _USE_MATH_DEFINES #include #include "itkImageRegionConstIterator.h" #include "itkImageRegionConstIteratorWithIndex.h" #include "itkImageRegionIterator.h" namespace itk { template< class TInPixelType, class TOutPixelType > AdcImageFilter< TInPixelType, TOutPixelType> ::AdcImageFilter() { this->SetNumberOfRequiredInputs( 1 ); } template< class TInPixelType, class TOutPixelType > void AdcImageFilter< TInPixelType, TOutPixelType> ::BeforeThreadedGenerateData() { + typename OutputImageType::Pointer outputImage = + static_cast< OutputImageType * >(this->ProcessObject::GetOutput(0)); + outputImage->FillBuffer(0.0); } template< class TInPixelType, class TOutPixelType > void AdcImageFilter< TInPixelType, TOutPixelType> ::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, ThreadIdType ) { typename OutputImageType::Pointer outputImage = static_cast< OutputImageType * >(this->ProcessObject::GetOutput(0)); ImageRegionIterator< OutputImageType > oit(outputImage, outputRegionForThread); oit.GoToBegin(); typedef ImageRegionConstIterator< InputImageType > InputIteratorType; typename InputImageType::Pointer inputImagePointer = NULL; inputImagePointer = static_cast< InputImageType * >( this->ProcessObject::GetInput(0) ); InputIteratorType git( inputImagePointer, outputRegionForThread ); git.GoToBegin(); while( !git.IsAtEnd() ) { typename InputImageType::PixelType pix = git.Get(); TOutPixelType outval = 0; double S0 = 0; int c = 0; for (int i=0; iGetVectorLength(); i++) { GradientDirectionType g = m_GradientDirections->GetElement(i); if (g.magnitude()<0.001) { S0 += pix[i]; c++; } } if (c>0) S0 /= c; if (S0>0) { c = 0; for (int i=0; iGetVectorLength(); i++) { GradientDirectionType g = m_GradientDirections->GetElement(i); if (g.magnitude()>0.001) { double twonorm = g.two_norm(); double b = m_B_value*twonorm*twonorm; if (b>0) { double S = pix[i]; outval += -std::log(S/S0)/b; c++; } } } if (c>0) outval /= c; } - oit.Set( outval ); + if (outval==outval && outval<10000) + oit.Set( outval ); ++oit; ++git; } std::cout << "One Thread finished calculation" << std::endl; } template< class TInPixelType, class TOutPixelType > void AdcImageFilter< TInPixelType, TOutPixelType> ::PrintSelf(std::ostream& os, Indent indent) const { Superclass::PrintSelf(os,indent); } } #endif // __itkAdcImageFilter_txx diff --git a/Modules/DiffusionImaging/DiffusionCore/Algorithms/itkDwiGradientLengthCorrectionFilter.cpp b/Modules/DiffusionImaging/DiffusionCore/Algorithms/itkDwiGradientLengthCorrectionFilter.cpp index aacbd0a8c4..1e34d32cea 100644 --- a/Modules/DiffusionImaging/DiffusionCore/Algorithms/itkDwiGradientLengthCorrectionFilter.cpp +++ b/Modules/DiffusionImaging/DiffusionCore/Algorithms/itkDwiGradientLengthCorrectionFilter.cpp @@ -1,67 +1,86 @@ /*=================================================================== 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. ===================================================================*/ /*========================================================================= Program: Tensor ToolKit - TTK Module: $URL: svn://scm.gforge.inria.fr/svn/ttk/trunk/Algorithms/itkElectrostaticRepulsionDiffusionGradientReductionFilter.txx $ Language: C++ Date: $Date: 2010-06-07 13:39:13 +0200 (Mo, 07 Jun 2010) $ Version: $Revision: 68 $ Copyright (c) INRIA 2010. All rights reserved. See LICENSE.txt 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. =========================================================================*/ #include "itkDwiGradientLengthCorrectionFilter.h" itk::DwiGradientLengthCorrectionFilter::DwiGradientLengthCorrectionFilter() - : m_ReferenceBValue(0) - , m_RoundingValue(0) - , m_ReferenceGradientDirectionContainer(0) - , m_OutputGradientDirectionContainer(0) + : m_ReferenceBValue(0) + , m_RoundingValue(0) + , m_ReferenceGradientDirectionContainer(0) + , m_OutputGradientDirectionContainer(0) { } itk::DwiGradientLengthCorrectionFilter::~DwiGradientLengthCorrectionFilter() { } void itk::DwiGradientLengthCorrectionFilter::GenerateData() { - if(m_ReferenceBValue == 0 || m_RoundingValue == 0 || m_ReferenceGradientDirectionContainer.IsNull()) - itkExceptionMacro("Wrong initialization"); - - m_OutputGradientDirectionContainer = GradientDirectionContainerType::New(); - - std::cout << m_ReferenceBValue << std::endl; - - GradientDirectionContainerType::ConstIterator it = m_ReferenceGradientDirectionContainer->Begin(); - for(; it != m_ReferenceGradientDirectionContainer->End(); ++it) - { - const double twonorm = it.Value().two_norm(); - const double currentBValue = m_ReferenceBValue*twonorm*twonorm ; - const double roundedBValue = int((currentBValue + 0.5 * m_RoundingValue)/m_RoundingValue)*m_RoundingValue; - const double f = std::sqrt(roundedBValue/m_ReferenceBValue); - GradientDirectionType grad = it.Value(); - m_OutputGradientDirectionContainer->push_back( grad.normalize() * f ); - } + if(m_ReferenceBValue == 0 || m_RoundingValue == 0 || m_ReferenceGradientDirectionContainer.IsNull()) + itkExceptionMacro("Wrong initialization"); + + m_OutputGradientDirectionContainer = GradientDirectionContainerType::New(); + + m_NewBValue = itk::NumericTraits::max(); + GradientDirectionContainerType::ConstIterator it = m_ReferenceGradientDirectionContainer->Begin(); + for(; it != m_ReferenceGradientDirectionContainer->End(); ++it) + { + const double twonorm = it.Value().two_norm(); + const double currentBValue = m_ReferenceBValue*twonorm*twonorm ; + const double roundedBValue = int((currentBValue + 0.5 * m_RoundingValue)/m_RoundingValue)*m_RoundingValue; + + if (roundedBValue1) + m_NewBValue = roundedBValue; + } + + it = m_ReferenceGradientDirectionContainer->Begin(); + for(; it != m_ReferenceGradientDirectionContainer->End(); ++it) + { + const double twonorm = it.Value().two_norm(); + const double currentBValue = m_ReferenceBValue*twonorm*twonorm ; + const double roundedBValue = int((currentBValue + 0.5 * m_RoundingValue)/m_RoundingValue)*m_RoundingValue; + + if (roundedBValue>1) + { + const double f = std::sqrt(roundedBValue/m_NewBValue); + GradientDirectionType grad = it.Value(); + m_OutputGradientDirectionContainer->push_back( grad.normalize() * f ); + } + else + { + GradientDirectionType grad; grad.fill(0.0); + m_OutputGradientDirectionContainer->push_back( grad ); + } + } } diff --git a/Modules/DiffusionImaging/DiffusionCore/Algorithms/itkDwiGradientLengthCorrectionFilter.h b/Modules/DiffusionImaging/DiffusionCore/Algorithms/itkDwiGradientLengthCorrectionFilter.h index 8ef298d1fc..4b62156cd1 100644 --- a/Modules/DiffusionImaging/DiffusionCore/Algorithms/itkDwiGradientLengthCorrectionFilter.h +++ b/Modules/DiffusionImaging/DiffusionCore/Algorithms/itkDwiGradientLengthCorrectionFilter.h @@ -1,72 +1,74 @@ /*=================================================================== 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 _itk_DwiGradientLengthCorrectionFilter_h_ #define _itk_DwiGradientLengthCorrectionFilter_h_ #include #include #include #include "DiffusionCoreExports.h" namespace itk { - class DiffusionCore_EXPORT DwiGradientLengthCorrectionFilter : public ProcessObject - { +class DiffusionCore_EXPORT DwiGradientLengthCorrectionFilter : public ProcessObject +{ - public: +public: typedef DwiGradientLengthCorrectionFilter Self; typedef SmartPointer Pointer; typedef SmartPointer ConstPointer; typedef ProcessObject Superclass; typedef vnl_vector_fixed< double, 3 > GradientDirectionType; typedef itk::VectorContainer< unsigned int, GradientDirectionType > GradientDirectionContainerType; /** Method for creation through the object factory. */ itkNewMacro(Self) itkTypeMacro(DwiGradientLengthCorrectionFilter,ProcessObject) void GenerateData(); virtual void Update(){ this->GenerateData(); } // input itkSetMacro(RoundingValue, int) itkSetMacro(ReferenceBValue, double) itkSetMacro(ReferenceGradientDirectionContainer, GradientDirectionContainerType::Pointer) // output itkGetMacro(OutputGradientDirectionContainer, GradientDirectionContainerType::Pointer) + itkGetMacro(NewBValue, double) - protected: - DwiGradientLengthCorrectionFilter(); + protected: + DwiGradientLengthCorrectionFilter(); ~DwiGradientLengthCorrectionFilter(); + double m_NewBValue; double m_ReferenceBValue; int m_RoundingValue; GradientDirectionContainerType::Pointer m_ReferenceGradientDirectionContainer; GradientDirectionContainerType::Pointer m_OutputGradientDirectionContainer; - }; +}; } // end of namespace #endif diff --git a/Modules/DiffusionImaging/DiffusionCore/IODataStructures/DiffusionWeightedImages/mitkDiffusionImage.txx b/Modules/DiffusionImaging/DiffusionCore/IODataStructures/DiffusionWeightedImages/mitkDiffusionImage.txx index 06cecb6a2a..006e59d3ba 100644 --- a/Modules/DiffusionImaging/DiffusionCore/IODataStructures/DiffusionWeightedImages/mitkDiffusionImage.txx +++ b/Modules/DiffusionImaging/DiffusionCore/IODataStructures/DiffusionWeightedImages/mitkDiffusionImage.txx @@ -1,420 +1,424 @@ /*=================================================================== 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 "itkImageRegionIterator.h" #include "itkImageRegionConstIterator.h" #include "mitkImageCast.h" template mitk::DiffusionImage::DiffusionImage() : m_VectorImage(0), m_Directions(0), m_OriginalDirections(0), m_B_Value(-1.0), m_VectorImageAdaptor(0) { MeasurementFrameType mf; for(int i=0; i<3; i++) for(int j=0; j<3; j++) mf[i][j] = 0; for(int i=0; i<3; i++) mf[i][i] = 1; m_MeasurementFrame = mf; } template mitk::DiffusionImage::~DiffusionImage() { // Remove Observer for m_Directions RemoveDirectionsContainerObserver(); } template void mitk::DiffusionImage ::InitializeFromVectorImage() { if(!m_VectorImage || !m_Directions || m_B_Value==-1.0) { MITK_INFO << "DiffusionImage could not be initialized. Set all members first!" << std::endl; return; } // find bzero index int firstZeroIndex = -1; for(GradientDirectionContainerType::ConstIterator it = m_Directions->Begin(); it != m_Directions->End(); ++it) { firstZeroIndex++; GradientDirectionType g = it.Value(); if(g[0] == 0 && g[1] == 0 && g[2] == 0 ) break; } typedef itk::Image ImgType; typename ImgType::Pointer img = ImgType::New(); img->SetSpacing( m_VectorImage->GetSpacing() ); // Set the image spacing img->SetOrigin( m_VectorImage->GetOrigin() ); // Set the image origin img->SetDirection( m_VectorImage->GetDirection() ); // Set the image direction img->SetLargestPossibleRegion( m_VectorImage->GetLargestPossibleRegion()); img->SetBufferedRegion( m_VectorImage->GetLargestPossibleRegion() ); img->Allocate(); int vecLength = m_VectorImage->GetVectorLength(); InitializeByItk( img.GetPointer(), 1, vecLength ); itk::ImageRegionIterator itw (img, img->GetLargestPossibleRegion() ); itw = itw.Begin(); itk::ImageRegionConstIterator itr (m_VectorImage, m_VectorImage->GetLargestPossibleRegion() ); itr = itr.Begin(); while(!itr.IsAtEnd()) { itw.Set(itr.Get().GetElement(firstZeroIndex)); ++itr; ++itw; } // init SetImportVolume(img->GetBufferPointer()); m_DisplayIndex = firstZeroIndex; MITK_INFO << "Diffusion-Image successfully initialized."; } template void mitk::DiffusionImage ::SetDisplayIndexForRendering(int displayIndex) { int index = displayIndex; int vecLength = m_VectorImage->GetVectorLength(); index = index > vecLength-1 ? vecLength-1 : index; if( m_DisplayIndex != index ) { typedef itk::Image ImgType; typename ImgType::Pointer img = ImgType::New(); CastToItkImage(this, img); itk::ImageRegionIterator itw (img, img->GetLargestPossibleRegion() ); itw = itw.Begin(); itk::ImageRegionConstIterator itr (m_VectorImage, m_VectorImage->GetLargestPossibleRegion() ); itr = itr.Begin(); while(!itr.IsAtEnd()) { itw.Set(itr.Get().GetElement(index)); ++itr; ++itw; } } m_DisplayIndex = index; } template bool mitk::DiffusionImage::AreAlike(GradientDirectionType g1, GradientDirectionType g2, double precision) { GradientDirectionType diff = g1 - g2; GradientDirectionType diff2 = g1 + g2; return diff.two_norm() < precision || diff2.two_norm() < precision; } template void mitk::DiffusionImage::CorrectDKFZBrokenGradientScheme(double precision) { GradientDirectionContainerType::Pointer directionSet = CalcAveragedDirectionSet(precision, m_Directions); if(directionSet->size() < 7) { MITK_INFO << "Too few directions, assuming and correcting DKFZ-bogus sequence details."; double v [7][3] = {{ 0, 0, 0 }, {-0.707057, 0, 0.707057 }, { 0.707057, 0, 0.707057 }, { 0, 0.707057, 0.707057 }, { 0, 0.707057, -0.707057 }, {-0.707057, 0.707057, 0 }, { 0.707057, 0.707057, 0 } }; int i=0; for(GradientDirectionContainerType::Iterator it = m_OriginalDirections->Begin(); it != m_OriginalDirections->End(); ++it) { it.Value().set(v[i++%7]); } ApplyMeasurementFrame(); } } template mitk::DiffusionImage::GradientDirectionContainerType::Pointer mitk::DiffusionImage::CalcAveragedDirectionSet(double precision, GradientDirectionContainerType::Pointer directions) { // save old and construct new direction container GradientDirectionContainerType::Pointer newDirections = GradientDirectionContainerType::New(); // fill new direction container for(GradientDirectionContainerType::ConstIterator gdcitOld = directions->Begin(); gdcitOld != directions->End(); ++gdcitOld) { // already exists? bool found = false; for(GradientDirectionContainerType::ConstIterator gdcitNew = newDirections->Begin(); gdcitNew != newDirections->End(); ++gdcitNew) { if(AreAlike(gdcitNew.Value(), gdcitOld.Value(), precision)) { found = true; break; } } // if not found, add it to new container if(!found) { newDirections->push_back(gdcitOld.Value()); } } return newDirections; } template void mitk::DiffusionImage::AverageRedundantGradients(double precision) { GradientDirectionContainerType::Pointer newDirs = CalcAveragedDirectionSet(precision, m_Directions); GradientDirectionContainerType::Pointer newOriginalDirs = CalcAveragedDirectionSet(precision, m_OriginalDirections); // if sizes equal, we do not need to do anything in this function if(m_Directions->size() == newDirs->size() || m_OriginalDirections->size() == newOriginalDirs->size()) return; GradientDirectionContainerType::Pointer oldDirections = m_OriginalDirections; m_Directions = newDirs; m_OriginalDirections = newOriginalDirs; // new image typename ImageType::Pointer oldImage = m_VectorImage; m_VectorImage = ImageType::New(); m_VectorImage->SetSpacing( oldImage->GetSpacing() ); // Set the image spacing m_VectorImage->SetOrigin( oldImage->GetOrigin() ); // Set the image origin m_VectorImage->SetDirection( oldImage->GetDirection() ); // Set the image direction m_VectorImage->SetLargestPossibleRegion( oldImage->GetLargestPossibleRegion() ); m_VectorImage->SetVectorLength( m_Directions->size() ); m_VectorImage->SetBufferedRegion( oldImage->GetLargestPossibleRegion() ); m_VectorImage->Allocate(); // average image data that corresponds to identical directions itk::ImageRegionIterator< ImageType > newIt(m_VectorImage, m_VectorImage->GetLargestPossibleRegion()); newIt.GoToBegin(); itk::ImageRegionIterator< ImageType > oldIt(oldImage, oldImage->GetLargestPossibleRegion()); oldIt.GoToBegin(); // initial new value of voxel typename ImageType::PixelType newVec; newVec.SetSize(m_Directions->size()); newVec.AllocateElements(m_Directions->size()); std::vector > dirIndices; for(GradientDirectionContainerType::ConstIterator gdcitNew = m_Directions->Begin(); gdcitNew != m_Directions->End(); ++gdcitNew) { dirIndices.push_back(std::vector(0)); for(GradientDirectionContainerType::ConstIterator gdcitOld = oldDirections->Begin(); gdcitOld != oldDirections->End(); ++gdcitOld) { if(AreAlike(gdcitNew.Value(), gdcitOld.Value(), precision)) { //MITK_INFO << gdcitNew.Value() << " " << gdcitOld.Value(); dirIndices[gdcitNew.Index()].push_back(gdcitOld.Index()); } } } //int ind1 = -1; while(!newIt.IsAtEnd()) { // progress //typename ImageType::IndexType ind = newIt.GetIndex(); //ind1 = ind.m_Index[2]; // init new vector with zeros newVec.Fill(0.0); // the old voxel value with duplicates typename ImageType::PixelType oldVec = oldIt.Get(); for(unsigned int i=0; i void mitk::DiffusionImage::ApplyMeasurementFrame() { RemoveDirectionsContainerObserver(); m_Directions = GradientDirectionContainerType::New(); int c = 0; for(GradientDirectionContainerType::ConstIterator gdcit = m_OriginalDirections->Begin(); gdcit != m_OriginalDirections->End(); ++gdcit) { vnl_vector vec = gdcit.Value(); vec = vec.pre_multiply(m_MeasurementFrame); m_Directions->InsertElement(c, vec); c++; } UpdateBValueMap(); AddDirectionsContainerObserver(); } // returns number of gradients template int mitk::DiffusionImage::GetNumDirections() { int gradients = m_OriginalDirections->Size(); for (int i=0; iSize(); i++) if (GetB_Value(i)<=0) { gradients--; } return gradients; } // returns number of not diffusion weighted images template int mitk::DiffusionImage::GetNumB0() { int b0 = 0; for (int i=0; iSize(); i++) if (GetB_Value(i)<=0) { b0++; } return b0; } // returns a list of indices belonging to the not diffusion weighted images template typename mitk::DiffusionImage::IndicesVector mitk::DiffusionImage::GetB0Indices() { IndicesVector indices; for (int i=0; iSize(); i++) if (GetB_Value(i)<=0) { indices.push_back(i); } return indices; } template bool mitk::DiffusionImage::IsMultiBval() { int gradients = m_OriginalDirections->Size(); for (int i=0; i0 && std::fabs(m_B_Value-GetB_Value(i))>50) return true; return false; } template void mitk::DiffusionImage::UpdateBValueMap() { m_B_ValueMap.clear(); GradientDirectionContainerType::ConstIterator gdcit; for( gdcit = this->m_Directions->Begin(); gdcit != this->m_Directions->End(); ++gdcit) - { - float currentBvalue = std::floor(GetB_Value(gdcit.Index())); - m_B_ValueMap[currentBvalue].push_back(gdcit.Index()); - } + m_B_ValueMap[GetB_Value(gdcit.Index())].push_back(gdcit.Index()); } template float mitk::DiffusionImage::GetB_Value(int i) { if(i > m_Directions->Size()-1) return -1; if(m_Directions->ElementAt(i).one_norm() <= 0.0) { return 0; } else { double twonorm = m_Directions->ElementAt(i).two_norm(); - return m_B_Value*twonorm*twonorm ; + double bval = m_B_Value*twonorm*twonorm; + + if (bval<0) + bval = ceil(bval - 0.5); + else + bval = floor(bval + 0.5); + + return bval; } } template void mitk::DiffusionImage::SetDirections(const std::vector > directions) { m_OriginalDirections = GradientDirectionContainerType::New(); for(unsigned int i=0; iInsertElement( i, directions[i].Get_vnl_vector() ); } this->ApplyMeasurementFrame(); } template void mitk::DiffusionImage::AddDirectionsContainerObserver() { // Add Modified Observer to invoke an UpdateBValueList by modifieng the DirectionsContainer (m_Directions) typedef DiffusionImage< TPixelType > Self; typedef itk::SimpleMemberCommand< Self > DCCommand ; typename DCCommand::Pointer command = DCCommand::New(); command->SetCallbackFunction(this, &Self::UpdateBValueMap); } template void mitk::DiffusionImage::RemoveDirectionsContainerObserver() { if(m_Directions){ m_Directions->RemoveAllObservers(); } } diff --git a/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkPreprocessingView.cpp b/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkPreprocessingView.cpp index 1510c6f734..08071d0d28 100644 --- a/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkPreprocessingView.cpp +++ b/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkPreprocessingView.cpp @@ -1,726 +1,731 @@ /*=================================================================== 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. ===================================================================*/ //#define MBILOG_ENABLE_DEBUG #include "QmitkPreprocessingView.h" #include "mitkDiffusionImagingConfigure.h" // qt includes #include // itk includes #include "itkTimeProbe.h" #include "itkB0ImageExtractionImageFilter.h" #include "itkB0ImageExtractionToSeparateImageFilter.h" #include "itkBrainMaskExtractionImageFilter.h" #include "itkCastImageFilter.h" #include "itkVectorContainer.h" #include #include #include #include // mitk includes #include "QmitkDataStorageComboBox.h" #include "QmitkStdMultiWidget.h" #include "mitkProgressBar.h" #include "mitkStatusBar.h" #include "mitkNodePredicateDataType.h" #include "mitkProperties.h" #include "mitkVtkResliceInterpolationProperty.h" #include "mitkLookupTable.h" #include "mitkLookupTableProperty.h" #include "mitkTransferFunction.h" #include "mitkTransferFunctionProperty.h" #include "mitkDataNodeObject.h" #include "mitkOdfNormalizationMethodProperty.h" #include "mitkOdfScaleByProperty.h" #include #include #include #include const std::string QmitkPreprocessingView::VIEW_ID = - "org.mitk.views.preprocessing"; + "org.mitk.views.preprocessing"; #define DI_INFO MITK_INFO("DiffusionImaging") typedef float TTensorPixelType; QmitkPreprocessingView::QmitkPreprocessingView() - : QmitkFunctionality(), - m_Controls(NULL), - m_MultiWidget(NULL), - m_DiffusionImage(NULL) + : QmitkFunctionality(), + m_Controls(NULL), + m_MultiWidget(NULL), + m_DiffusionImage(NULL) { } QmitkPreprocessingView::QmitkPreprocessingView(const QmitkPreprocessingView& other) { - Q_UNUSED(other) - throw std::runtime_error("Copy constructor not implemented"); + Q_UNUSED(other) + throw std::runtime_error("Copy constructor not implemented"); } QmitkPreprocessingView::~QmitkPreprocessingView() { } void QmitkPreprocessingView::CreateQtPartControl(QWidget *parent) { - if (!m_Controls) - { - // create GUI widgets - m_Controls = new Ui::QmitkPreprocessingViewControls; - m_Controls->setupUi(parent); - this->CreateConnections(); - - m_Controls->m_MeasurementFrameTable->horizontalHeader()->setResizeMode(QHeaderView::Stretch); - m_Controls->m_MeasurementFrameTable->verticalHeader()->setResizeMode(QHeaderView::Stretch); - } + if (!m_Controls) + { + // create GUI widgets + m_Controls = new Ui::QmitkPreprocessingViewControls; + m_Controls->setupUi(parent); + this->CreateConnections(); + + m_Controls->m_MeasurementFrameTable->horizontalHeader()->setResizeMode(QHeaderView::Stretch); + m_Controls->m_MeasurementFrameTable->verticalHeader()->setResizeMode(QHeaderView::Stretch); + } } void QmitkPreprocessingView::StdMultiWidgetAvailable (QmitkStdMultiWidget &stdMultiWidget) { - m_MultiWidget = &stdMultiWidget; + m_MultiWidget = &stdMultiWidget; } void QmitkPreprocessingView::StdMultiWidgetNotAvailable() { - m_MultiWidget = NULL; + m_MultiWidget = NULL; } void QmitkPreprocessingView::CreateConnections() { - if ( m_Controls ) - { - connect( (QObject*)(m_Controls->m_ButtonAverageGradients), SIGNAL(clicked()), this, SLOT(AverageGradients()) ); - connect( (QObject*)(m_Controls->m_ButtonExtractB0), SIGNAL(clicked()), this, SLOT(ExtractB0()) ); - connect( (QObject*)(m_Controls->m_ModifyMeasurementFrame), SIGNAL(clicked()), this, SLOT(DoApplyMesurementFrame()) ); - connect( (QObject*)(m_Controls->m_ReduceGradientsButton), SIGNAL(clicked()), this, SLOT(DoReduceGradientDirections()) ); - connect( (QObject*)(m_Controls->m_ShowGradientsButton), SIGNAL(clicked()), this, SLOT(DoShowGradientDirections()) ); - connect( (QObject*)(m_Controls->m_MirrorGradientToHalfSphereButton), SIGNAL(clicked()), this, SLOT(DoHalfSphereGradientDirections()) ); - connect( (QObject*)(m_Controls->m_MergeDwisButton), SIGNAL(clicked()), this, SLOT(MergeDwis()) ); - connect( (QObject*)(m_Controls->m_AdcAverage), SIGNAL(clicked()), this, SLOT(DoAdcAverage()) ); - connect( (QObject*)(m_Controls->m_B_ValueMap_Rounder_SpinBox), SIGNAL(valueChanged(int)), this, SLOT(UpdateDwiBValueMapRounder(int))); - connect( (QObject*)(m_Controls->m_CreateLengthCorrectedDwi), SIGNAL(clicked()), this, SLOT(DoLengthCorrection()) ); + if ( m_Controls ) + { + connect( (QObject*)(m_Controls->m_ButtonAverageGradients), SIGNAL(clicked()), this, SLOT(AverageGradients()) ); + connect( (QObject*)(m_Controls->m_ButtonExtractB0), SIGNAL(clicked()), this, SLOT(ExtractB0()) ); + connect( (QObject*)(m_Controls->m_ModifyMeasurementFrame), SIGNAL(clicked()), this, SLOT(DoApplyMesurementFrame()) ); + connect( (QObject*)(m_Controls->m_ReduceGradientsButton), SIGNAL(clicked()), this, SLOT(DoReduceGradientDirections()) ); + connect( (QObject*)(m_Controls->m_ShowGradientsButton), SIGNAL(clicked()), this, SLOT(DoShowGradientDirections()) ); + connect( (QObject*)(m_Controls->m_MirrorGradientToHalfSphereButton), SIGNAL(clicked()), this, SLOT(DoHalfSphereGradientDirections()) ); + connect( (QObject*)(m_Controls->m_MergeDwisButton), SIGNAL(clicked()), this, SLOT(MergeDwis()) ); + connect( (QObject*)(m_Controls->m_AdcAverage), SIGNAL(clicked()), this, SLOT(DoAdcAverage()) ); + connect( (QObject*)(m_Controls->m_B_ValueMap_Rounder_SpinBox), SIGNAL(valueChanged(int)), this, SLOT(UpdateDwiBValueMapRounder(int))); + connect( (QObject*)(m_Controls->m_CreateLengthCorrectedDwi), SIGNAL(clicked()), this, SLOT(DoLengthCorrection()) ); connect( (QObject*)(m_Controls->m_CalcAdcButton), SIGNAL(clicked()), this, SLOT(DoAdcCalculation()) ); - } + } } void QmitkPreprocessingView::DoLengthCorrection() { - if (m_DiffusionImage.IsNull()) - return; - - typedef mitk::DiffusionImage DiffusionImageType; - typedef itk::DwiGradientLengthCorrectionFilter FilterType; - - FilterType::Pointer filter = FilterType::New(); - filter->SetRoundingValue( m_Controls->m_B_ValueMap_Rounder_SpinBox->value()); - filter->SetReferenceBValue(m_DiffusionImage->GetB_Value()); - filter->SetReferenceGradientDirectionContainer(m_DiffusionImage->GetDirections()); - filter->Update(); - - DiffusionImageType::Pointer image = DiffusionImageType::New(); - image->SetVectorImage( m_DiffusionImage->GetVectorImage()); - image->SetB_Value( m_DiffusionImage->GetB_Value() ); - image->SetDirections( filter->GetOutputGradientDirectionContainer()); - image->InitializeFromVectorImage(); - - mitk::DataNode::Pointer imageNode = mitk::DataNode::New(); - imageNode->SetData( image ); - QString name = m_SelectedDiffusionNodes.front()->GetName().c_str(); - - imageNode->SetName((name+"_rounded").toStdString().c_str()); - GetDefaultDataStorage()->Add(imageNode); + if (m_DiffusionImage.IsNull()) + return; + + typedef mitk::DiffusionImage DiffusionImageType; + typedef itk::DwiGradientLengthCorrectionFilter FilterType; + + FilterType::Pointer filter = FilterType::New(); + filter->SetRoundingValue( m_Controls->m_B_ValueMap_Rounder_SpinBox->value()); + filter->SetReferenceBValue(m_DiffusionImage->GetB_Value()); + filter->SetReferenceGradientDirectionContainer(m_DiffusionImage->GetDirections()); + filter->Update(); + + DiffusionImageType::Pointer image = DiffusionImageType::New(); + image->SetVectorImage( m_DiffusionImage->GetVectorImage()); + image->SetB_Value( filter->GetNewBValue() ); + image->SetDirections( filter->GetOutputGradientDirectionContainer()); + image->InitializeFromVectorImage(); + + mitk::DataNode::Pointer imageNode = mitk::DataNode::New(); + imageNode->SetData( image ); + QString name = m_SelectedDiffusionNodes.front()->GetName().c_str(); + + imageNode->SetName((name+"_rounded").toStdString().c_str()); + GetDefaultDataStorage()->Add(imageNode); } void QmitkPreprocessingView::UpdateDwiBValueMapRounder(int i) { - if (m_DiffusionImage.IsNull()) - return; - m_DiffusionImage->UpdateBValueMap(); - UpdateBValueTableWidget(i); + if (m_DiffusionImage.IsNull()) + return; + m_DiffusionImage->UpdateBValueMap(); + UpdateBValueTableWidget(i); } void QmitkPreprocessingView::DoAdcAverage() { - if (m_DiffusionImage.IsNull()) - return; - - typedef mitk::DiffusionImage DiffusionImageType; - typedef itk::MultiShellAdcAverageReconstructionImageFilter FilterType; - typedef DiffusionImageType::BValueMap BValueMap; - - BValueMap originalShellMap = m_DiffusionImage->GetB_ValueMap(); - - GradientDirectionContainerType::Pointer gradientContainer = m_DiffusionImage->GetDirections(); - - FilterType::Pointer filter = FilterType::New(); - filter->SetInput(m_DiffusionImage->GetVectorImage()); - filter->SetOriginalGradientDirections(gradientContainer); - filter->SetOriginalBValueMap(originalShellMap); - filter->SetB_Value(m_DiffusionImage->GetB_Value()); - filter->Update(); - - DiffusionImageType::Pointer image = DiffusionImageType::New(); - image->SetVectorImage( filter->GetOutput() ); - image->SetB_Value( filter->GetTargetB_Value() ); - //image->SetOriginalDirections( filter->GetTargetGradientDirections() ); - image->SetDirections( filter->GetTargetGradientDirections() ); - //image->SetMeasurementFrame( m_DiffusionImage->GetMeasurementFrame() ); - image->InitializeFromVectorImage(); - - mitk::DataNode::Pointer imageNode = mitk::DataNode::New(); - imageNode->SetData( image ); - QString name = m_SelectedDiffusionNodes.front()->GetName().c_str(); - - imageNode->SetName((name+"_averaged").toStdString().c_str()); - GetDefaultDataStorage()->Add(imageNode); + typedef mitk::DiffusionImage DiffusionImageType; + typedef itk::MultiShellAdcAverageReconstructionImageFilter FilterType; + typedef DiffusionImageType::BValueMap BValueMap; + for (int i=0; i(m_SelectedDiffusionNodes.at(i)->GetData()); + BValueMap originalShellMap = inImage->GetB_ValueMap(); + + GradientDirectionContainerType::Pointer gradientContainer = inImage->GetDirections(); + + FilterType::Pointer filter = FilterType::New(); + filter->SetInput(inImage->GetVectorImage()); + filter->SetOriginalGradientDirections(gradientContainer); + filter->SetOriginalBValueMap(originalShellMap); + filter->SetB_Value(inImage->GetB_Value()); + filter->Update(); + + DiffusionImageType::Pointer outImage = DiffusionImageType::New(); + outImage->SetVectorImage( filter->GetOutput() ); + outImage->SetB_Value( filter->GetTargetB_Value() ); + //image->SetOriginalDirections( filter->GetTargetGradientDirections() ); + outImage->SetDirections( filter->GetTargetGradientDirections() ); + //image->SetMeasurementFrame( m_DiffusionImage->GetMeasurementFrame() ); + outImage->InitializeFromVectorImage(); + + mitk::DataNode::Pointer imageNode = mitk::DataNode::New(); + imageNode->SetData( outImage ); + QString name = m_SelectedDiffusionNodes.at(i)->GetName().c_str(); + + imageNode->SetName((name+"_averaged").toStdString().c_str()); + GetDefaultDataStorage()->Add(imageNode); + } } void QmitkPreprocessingView::DoAdcCalculation() { - if (m_DiffusionImage.IsNull()) - return; - - typedef mitk::DiffusionImage< DiffusionPixelType > DiffusionImageType; - typedef itk::AdcImageFilter< DiffusionPixelType, double > FilterType; - - FilterType::Pointer filter = FilterType::New(); - filter->SetInput(m_DiffusionImage->GetVectorImage()); - filter->SetGradientDirections(m_DiffusionImage->GetDirections()); - filter->SetB_value(m_DiffusionImage->GetB_Value()); - filter->Update(); - - mitk::Image::Pointer image = mitk::Image::New(); - image->InitializeByItk( filter->GetOutput() ); - image->SetVolume( filter->GetOutput()->GetBufferPointer() ); - mitk::DataNode::Pointer imageNode = mitk::DataNode::New(); - imageNode->SetData( image ); - QString name = m_SelectedDiffusionNodes.front()->GetName().c_str(); - - imageNode->SetName((name+"_ADC").toStdString().c_str()); - GetDefaultDataStorage()->Add(imageNode); -} + if (m_DiffusionImage.IsNull()) + return; + typedef mitk::DiffusionImage< DiffusionPixelType > DiffusionImageType; + typedef itk::AdcImageFilter< DiffusionPixelType, double > FilterType; -void QmitkPreprocessingView::UpdateBValueTableWidget(int i) -{ - foreach(QCheckBox * box, m_ReduceGradientCheckboxes) - { - m_Controls->m_ReductionFrame->layout()->removeWidget(box); - delete box; - } - foreach(QSpinBox * box, m_ReduceGradientSpinboxes) - { - m_Controls->m_ReductionFrame->layout()->removeWidget(box); - delete box; - } - m_ReduceGradientCheckboxes.clear(); - m_ReduceGradientSpinboxes.clear(); - - if (m_DiffusionImage.IsNull()) - { - m_Controls->m_B_ValueMap_TableWidget->clear(); - m_Controls->m_B_ValueMap_TableWidget->setRowCount(1); - QStringList headerList; - headerList << "b-Value" << "Number of gradients"; - m_Controls->m_B_ValueMap_TableWidget->setHorizontalHeaderLabels(headerList); - m_Controls->m_B_ValueMap_TableWidget->setItem(0,0,new QTableWidgetItem("-")); - m_Controls->m_B_ValueMap_TableWidget->setItem(0,1,new QTableWidgetItem("-")); - }else{ + for (int i=0; i(m_SelectedDiffusionNodes.at(i)->GetData()); + FilterType::Pointer filter = FilterType::New(); + filter->SetInput(inImage->GetVectorImage()); + filter->SetGradientDirections(inImage->GetDirections()); + filter->SetB_value(inImage->GetB_Value()); + filter->Update(); + + mitk::Image::Pointer image = mitk::Image::New(); + image->InitializeByItk( filter->GetOutput() ); + image->SetVolume( filter->GetOutput()->GetBufferPointer() ); + mitk::DataNode::Pointer imageNode = mitk::DataNode::New(); + imageNode->SetData( image ); + QString name = m_SelectedDiffusionNodes.at(i)->GetName().c_str(); + + imageNode->SetName((name+"_ADC").toStdString().c_str()); + GetDefaultDataStorage()->Add(imageNode); + } +} - typedef mitk::DiffusionImage::BValueMap BValueMap; - typedef mitk::DiffusionImage::BValueMap::iterator BValueMapIterator; - BValueMapIterator it; +void QmitkPreprocessingView::UpdateBValueTableWidget(int i) +{ - BValueMap roundedBValueMap; - GradientDirectionContainerType::ConstIterator gdcit; - for( gdcit = m_DiffusionImage->GetDirections()->Begin(); gdcit != m_DiffusionImage->GetDirections()->End(); ++gdcit) + foreach(QCheckBox * box, m_ReduceGradientCheckboxes) { - float currentBvalue = std::floor(m_DiffusionImage->GetB_Value(gdcit.Index())); - double rounded = int((currentBvalue + 0.5 * i)/i)*i; - roundedBValueMap[rounded].push_back(gdcit.Index()); + m_Controls->m_ReductionFrame->layout()->removeWidget(box); + delete box; } + foreach(QSpinBox * box, m_ReduceGradientSpinboxes) + { + m_Controls->m_ReductionFrame->layout()->removeWidget(box); + delete box; + } + m_ReduceGradientCheckboxes.clear(); + m_ReduceGradientSpinboxes.clear(); - m_Controls->m_B_ValueMap_TableWidget->clear(); - m_Controls->m_B_ValueMap_TableWidget->setRowCount(roundedBValueMap.size() ); - QStringList headerList; - headerList << "b-Value" << "Number of gradients"; - m_Controls->m_B_ValueMap_TableWidget->setHorizontalHeaderLabels(headerList); - - - QCheckBox* checkBox; - QSpinBox* spinBox; - int i = 0 ; - for(it = roundedBValueMap.begin() ;it != roundedBValueMap.end(); it++) + if (m_DiffusionImage.IsNull()) { - m_Controls->m_B_ValueMap_TableWidget->setItem(i,0,new QTableWidgetItem(QString::number(it->first))); - m_Controls->m_B_ValueMap_TableWidget->setItem(i,1,new QTableWidgetItem(QString::number(it->second.size()))); - - // Reduce Gradients GUI adaption - if(it->first != 0 && roundedBValueMap.size() > 1){ - checkBox = new QCheckBox(QString::number(it->first) + " with " + QString::number(it->second.size()) + " directions"); - checkBox->setEnabled(true); - checkBox->setChecked(true); - checkBox->setCheckable(true); - m_ReduceGradientCheckboxes.push_back(checkBox); - m_Controls->m_ReductionFrame->layout()->addWidget(checkBox); - - spinBox = new QSpinBox(); - spinBox->setValue(std::ceil((float)it->second.size()/2)); - spinBox->setMaximum(it->second.size()); - spinBox->setMinimum(0); - m_ReduceGradientSpinboxes.push_back(spinBox); - m_Controls->m_ReductionFrame->layout()->addWidget(spinBox); - } - i++; + m_Controls->m_B_ValueMap_TableWidget->clear(); + m_Controls->m_B_ValueMap_TableWidget->setRowCount(1); + QStringList headerList; + headerList << "b-Value" << "Number of gradients"; + m_Controls->m_B_ValueMap_TableWidget->setHorizontalHeaderLabels(headerList); + m_Controls->m_B_ValueMap_TableWidget->setItem(0,0,new QTableWidgetItem("-")); + m_Controls->m_B_ValueMap_TableWidget->setItem(0,1,new QTableWidgetItem("-")); + }else{ + + typedef mitk::DiffusionImage::BValueMap BValueMap; + typedef mitk::DiffusionImage::BValueMap::iterator BValueMapIterator; + + BValueMapIterator it; + + BValueMap roundedBValueMap; + GradientDirectionContainerType::ConstIterator gdcit; + for( gdcit = m_DiffusionImage->GetDirections()->Begin(); gdcit != m_DiffusionImage->GetDirections()->End(); ++gdcit) + { + float currentBvalue = std::floor(m_DiffusionImage->GetB_Value(gdcit.Index())); + double rounded = int((currentBvalue + 0.5 * i)/i)*i; + roundedBValueMap[rounded].push_back(gdcit.Index()); + } + + m_Controls->m_B_ValueMap_TableWidget->clear(); + m_Controls->m_B_ValueMap_TableWidget->setRowCount(roundedBValueMap.size() ); + QStringList headerList; + headerList << "b-Value" << "Number of gradients"; + m_Controls->m_B_ValueMap_TableWidget->setHorizontalHeaderLabels(headerList); + + + QCheckBox* checkBox; + QSpinBox* spinBox; + int i = 0 ; + for(it = roundedBValueMap.begin() ;it != roundedBValueMap.end(); it++) + { + m_Controls->m_B_ValueMap_TableWidget->setItem(i,0,new QTableWidgetItem(QString::number(it->first))); + m_Controls->m_B_ValueMap_TableWidget->setItem(i,1,new QTableWidgetItem(QString::number(it->second.size()))); + + // Reduce Gradients GUI adaption + if(it->first != 0 && roundedBValueMap.size() > 1){ + checkBox = new QCheckBox(QString::number(it->first) + " with " + QString::number(it->second.size()) + " directions"); + checkBox->setEnabled(true); + checkBox->setChecked(true); + checkBox->setCheckable(true); + m_ReduceGradientCheckboxes.push_back(checkBox); + m_Controls->m_ReductionFrame->layout()->addWidget(checkBox); + + spinBox = new QSpinBox(); + spinBox->setValue(std::ceil((float)it->second.size()/2)); + spinBox->setMaximum(it->second.size()); + spinBox->setMinimum(0); + m_ReduceGradientSpinboxes.push_back(spinBox); + m_Controls->m_ReductionFrame->layout()->addWidget(spinBox); + } + i++; + } } - } } void QmitkPreprocessingView::OnSelectionChanged( std::vector nodes ) { - bool foundDwiVolume = false; - m_DiffusionImage = NULL; - m_SelectedDiffusionNodes.clear(); + bool foundDwiVolume = false; + m_DiffusionImage = NULL; + m_SelectedDiffusionNodes.clear(); - // iterate selection - for( std::vector::iterator it = nodes.begin(); it != nodes.end(); ++it ) - { - mitk::DataNode::Pointer node = *it; + // iterate selection + for( std::vector::iterator it = nodes.begin(); it != nodes.end(); ++it ) + { + mitk::DataNode::Pointer node = *it; + + if( node.IsNotNull() && dynamic_cast*>(node->GetData()) ) + { + foundDwiVolume = true; + m_DiffusionImage = dynamic_cast*>(node->GetData()); + m_Controls->m_DiffusionImageLabel->setText(node->GetName().c_str()); + m_SelectedDiffusionNodes.push_back(node); + } + } - if( node.IsNotNull() && dynamic_cast*>(node->GetData()) ) + m_Controls->m_ButtonAverageGradients->setEnabled(foundDwiVolume); + m_Controls->m_ButtonExtractB0->setEnabled(foundDwiVolume); + m_Controls->m_CheckExtractAll->setEnabled(foundDwiVolume); + m_Controls->m_ModifyMeasurementFrame->setEnabled(foundDwiVolume); + m_Controls->m_MeasurementFrameTable->setEnabled(foundDwiVolume); + m_Controls->m_ReduceGradientsButton->setEnabled(foundDwiVolume); + m_Controls->m_ShowGradientsButton->setEnabled(foundDwiVolume); + m_Controls->m_MirrorGradientToHalfSphereButton->setEnabled(foundDwiVolume); + m_Controls->m_MergeDwisButton->setEnabled(foundDwiVolume); + m_Controls->m_B_ValueMap_Rounder_SpinBox->setEnabled(foundDwiVolume); + m_Controls->m_AdcAverage->setEnabled(foundDwiVolume); + m_Controls->m_CreateLengthCorrectedDwi->setEnabled(foundDwiVolume); + if(foundDwiVolume)m_Controls->m_B_ValueMap_Rounder_SpinBox->setValue(10); + m_Controls->m_CalcAdcButton->setEnabled(foundDwiVolume); + + UpdateBValueTableWidget(m_Controls->m_B_ValueMap_Rounder_SpinBox->value()); + + if (foundDwiVolume) { - foundDwiVolume = true; - m_DiffusionImage = dynamic_cast*>(node->GetData()); - m_Controls->m_DiffusionImageLabel->setText(node->GetName().c_str()); - m_SelectedDiffusionNodes.push_back(node); + m_Controls->m_InputData->setTitle("Input Data"); + vnl_matrix_fixed< double, 3, 3 > mf = m_DiffusionImage->GetMeasurementFrame(); + for (int r=0; r<3; r++) + for (int c=0; c<3; c++) + { + QTableWidgetItem* item = m_Controls->m_MeasurementFrameTable->item(r,c); + delete item; + item = new QTableWidgetItem(); + item->setTextAlignment(Qt::AlignCenter | Qt::AlignVCenter); + item->setText(QString::number(mf.get(r,c))); + m_Controls->m_MeasurementFrameTable->setItem(r,c,item); + } + } + else + { + for (int r=0; r<3; r++) + for (int c=0; c<3; c++) + { + QTableWidgetItem* item = m_Controls->m_MeasurementFrameTable->item(r,c); + delete item; + item = new QTableWidgetItem(); + m_Controls->m_MeasurementFrameTable->setItem(r,c,item); + } + + m_Controls->m_DiffusionImageLabel->setText("mandatory"); + m_Controls->m_InputData->setTitle("Please Select Input Data"); } - } - - m_Controls->m_ButtonAverageGradients->setEnabled(foundDwiVolume); - m_Controls->m_ButtonExtractB0->setEnabled(foundDwiVolume); - m_Controls->m_CheckExtractAll->setEnabled(foundDwiVolume); - m_Controls->m_ModifyMeasurementFrame->setEnabled(foundDwiVolume); - m_Controls->m_MeasurementFrameTable->setEnabled(foundDwiVolume); - m_Controls->m_ReduceGradientsButton->setEnabled(foundDwiVolume); - m_Controls->m_ShowGradientsButton->setEnabled(foundDwiVolume); - m_Controls->m_MirrorGradientToHalfSphereButton->setEnabled(foundDwiVolume); - m_Controls->m_MergeDwisButton->setEnabled(foundDwiVolume); - m_Controls->m_B_ValueMap_Rounder_SpinBox->setEnabled(foundDwiVolume); - m_Controls->m_AdcAverage->setEnabled(foundDwiVolume); - m_Controls->m_CreateLengthCorrectedDwi->setEnabled(foundDwiVolume); - if(foundDwiVolume)m_Controls->m_B_ValueMap_Rounder_SpinBox->setValue(10); - m_Controls->m_CalcAdcButton->setEnabled(foundDwiVolume); - - UpdateBValueTableWidget(m_Controls->m_B_ValueMap_Rounder_SpinBox->value()); - - if (foundDwiVolume) - { - m_Controls->m_InputData->setTitle("Input Data"); - vnl_matrix_fixed< double, 3, 3 > mf = m_DiffusionImage->GetMeasurementFrame(); - for (int r=0; r<3; r++) - for (int c=0; c<3; c++) - { - QTableWidgetItem* item = m_Controls->m_MeasurementFrameTable->item(r,c); - delete item; - item = new QTableWidgetItem(); - item->setTextAlignment(Qt::AlignCenter | Qt::AlignVCenter); - item->setText(QString::number(mf.get(r,c))); - m_Controls->m_MeasurementFrameTable->setItem(r,c,item); - } - } - else - { - for (int r=0; r<3; r++) - for (int c=0; c<3; c++) - { - QTableWidgetItem* item = m_Controls->m_MeasurementFrameTable->item(r,c); - delete item; - item = new QTableWidgetItem(); - m_Controls->m_MeasurementFrameTable->setItem(r,c,item); - } - - m_Controls->m_DiffusionImageLabel->setText("mandatory"); - m_Controls->m_InputData->setTitle("Please Select Input Data"); - } } void QmitkPreprocessingView::Activated() { - QmitkFunctionality::Activated(); + QmitkFunctionality::Activated(); } void QmitkPreprocessingView::Deactivated() { - QmitkFunctionality::Deactivated(); + QmitkFunctionality::Deactivated(); } void QmitkPreprocessingView::DoHalfSphereGradientDirections() { - GradientDirectionContainerType::Pointer gradientContainer = m_DiffusionImage->GetDirections(); + GradientDirectionContainerType::Pointer gradientContainer = m_DiffusionImage->GetDirections(); - for (int j=0; jSize(); j++) - if (gradientContainer->at(j)[0]<0) - gradientContainer->at(j) = -gradientContainer->at(j); - m_DiffusionImage->SetDirections(gradientContainer); + for (int j=0; jSize(); j++) + if (gradientContainer->at(j)[0]<0) + gradientContainer->at(j) = -gradientContainer->at(j); + m_DiffusionImage->SetDirections(gradientContainer); } void QmitkPreprocessingView::DoApplyMesurementFrame() { - if (m_DiffusionImage.IsNull()) - return; - - vnl_matrix_fixed< double, 3, 3 > mf; - for (int r=0; r<3; r++) - for (int c=0; c<3; c++) - { - QTableWidgetItem* item = m_Controls->m_MeasurementFrameTable->item(r,c); - if (!item) + if (m_DiffusionImage.IsNull()) return; - mf[r][c] = item->text().toDouble(); - } - m_DiffusionImage->SetMeasurementFrame(mf); + + vnl_matrix_fixed< double, 3, 3 > mf; + for (int r=0; r<3; r++) + for (int c=0; c<3; c++) + { + QTableWidgetItem* item = m_Controls->m_MeasurementFrameTable->item(r,c); + if (!item) + return; + mf[r][c] = item->text().toDouble(); + } + m_DiffusionImage->SetMeasurementFrame(mf); } void QmitkPreprocessingView::DoShowGradientDirections() { - if (m_DiffusionImage.IsNull()) - return; - - int maxIndex = 0; - int maxSize = m_DiffusionImage->GetDimension(0); - if (maxSizeGetDimension(1)) - { - maxSize = m_DiffusionImage->GetDimension(1); - maxIndex = 1; - } - if (maxSizeGetDimension(2)) - { - maxSize = m_DiffusionImage->GetDimension(2); - maxIndex = 2; - } - - mitk::Point3D origin = m_DiffusionImage->GetGeometry()->GetOrigin(); - mitk::PointSet::Pointer originSet = mitk::PointSet::New(); - - typedef mitk::DiffusionImage::BValueMap BValueMap; - typedef mitk::DiffusionImage::BValueMap::iterator BValueMapIterator; - BValueMap bValMap = m_DiffusionImage->GetB_ValueMap(); - - GradientDirectionContainerType::Pointer gradientContainer = m_DiffusionImage->GetDirections(); - mitk::Geometry3D::Pointer geometry = m_DiffusionImage->GetGeometry(); - int shellCount = 1; - for(BValueMapIterator it = bValMap.begin(); it!=bValMap.end(); ++it) - { - mitk::PointSet::Pointer pointset = mitk::PointSet::New(); - for (int j=0; jsecond.size(); j++) + if (m_DiffusionImage.IsNull()) + return; + + int maxIndex = 0; + int maxSize = m_DiffusionImage->GetDimension(0); + if (maxSizeGetDimension(1)) { - mitk::Point3D ip; - vnl_vector_fixed< double, 3 > v = gradientContainer->at(it->second[j]); - if (v.magnitude()>mitk::eps) - { - ip[0] = v[0]*maxSize*geometry->GetSpacing()[maxIndex]/2 + origin[0]-0.5*geometry->GetSpacing()[0] + geometry->GetSpacing()[0]*m_DiffusionImage->GetDimension(0)/2; - ip[1] = v[1]*maxSize*geometry->GetSpacing()[maxIndex]/2 + origin[1]-0.5*geometry->GetSpacing()[1] + geometry->GetSpacing()[1]*m_DiffusionImage->GetDimension(1)/2; - ip[2] = v[2]*maxSize*geometry->GetSpacing()[maxIndex]/2 + origin[2]-0.5*geometry->GetSpacing()[2] + geometry->GetSpacing()[2]*m_DiffusionImage->GetDimension(2)/2; - - pointset->InsertPoint(j, ip); - } - else if (originSet->IsEmpty()) - { - ip[0] = v[0]*maxSize*geometry->GetSpacing()[maxIndex]/2 + origin[0]-0.5*geometry->GetSpacing()[0] + geometry->GetSpacing()[0]*m_DiffusionImage->GetDimension(0)/2; - ip[1] = v[1]*maxSize*geometry->GetSpacing()[maxIndex]/2 + origin[1]-0.5*geometry->GetSpacing()[1] + geometry->GetSpacing()[1]*m_DiffusionImage->GetDimension(1)/2; - ip[2] = v[2]*maxSize*geometry->GetSpacing()[maxIndex]/2 + origin[2]-0.5*geometry->GetSpacing()[2] + geometry->GetSpacing()[2]*m_DiffusionImage->GetDimension(2)/2; - - originSet->InsertPoint(j, ip); - } + maxSize = m_DiffusionImage->GetDimension(1); + maxIndex = 1; } - if (it->firstGetDimension(2)) + { + maxSize = m_DiffusionImage->GetDimension(2); + maxIndex = 2; + } + + mitk::Point3D origin = m_DiffusionImage->GetGeometry()->GetOrigin(); + mitk::PointSet::Pointer originSet = mitk::PointSet::New(); - // add shell to datastorage + typedef mitk::DiffusionImage::BValueMap BValueMap; + typedef mitk::DiffusionImage::BValueMap::iterator BValueMapIterator; + BValueMap bValMap = m_DiffusionImage->GetB_ValueMap(); + + GradientDirectionContainerType::Pointer gradientContainer = m_DiffusionImage->GetDirections(); + mitk::Geometry3D::Pointer geometry = m_DiffusionImage->GetGeometry(); + int shellCount = 1; + for(BValueMapIterator it = bValMap.begin(); it!=bValMap.end(); ++it) + { + mitk::PointSet::Pointer pointset = mitk::PointSet::New(); + for (int j=0; jsecond.size(); j++) + { + mitk::Point3D ip; + vnl_vector_fixed< double, 3 > v = gradientContainer->at(it->second[j]); + if (v.magnitude()>mitk::eps) + { + ip[0] = v[0]*maxSize*geometry->GetSpacing()[maxIndex]/2 + origin[0]-0.5*geometry->GetSpacing()[0] + geometry->GetSpacing()[0]*m_DiffusionImage->GetDimension(0)/2; + ip[1] = v[1]*maxSize*geometry->GetSpacing()[maxIndex]/2 + origin[1]-0.5*geometry->GetSpacing()[1] + geometry->GetSpacing()[1]*m_DiffusionImage->GetDimension(1)/2; + ip[2] = v[2]*maxSize*geometry->GetSpacing()[maxIndex]/2 + origin[2]-0.5*geometry->GetSpacing()[2] + geometry->GetSpacing()[2]*m_DiffusionImage->GetDimension(2)/2; + + pointset->InsertPoint(j, ip); + } + else if (originSet->IsEmpty()) + { + ip[0] = v[0]*maxSize*geometry->GetSpacing()[maxIndex]/2 + origin[0]-0.5*geometry->GetSpacing()[0] + geometry->GetSpacing()[0]*m_DiffusionImage->GetDimension(0)/2; + ip[1] = v[1]*maxSize*geometry->GetSpacing()[maxIndex]/2 + origin[1]-0.5*geometry->GetSpacing()[1] + geometry->GetSpacing()[1]*m_DiffusionImage->GetDimension(1)/2; + ip[2] = v[2]*maxSize*geometry->GetSpacing()[maxIndex]/2 + origin[2]-0.5*geometry->GetSpacing()[2] + geometry->GetSpacing()[2]*m_DiffusionImage->GetDimension(2)/2; + + originSet->InsertPoint(j, ip); + } + } + if (it->firstSetData(pointset); + QString name = m_SelectedDiffusionNodes.front()->GetName().c_str(); + name += "_Shell_"; + name += QString::number(it->first); + node->SetName(name.toStdString().c_str()); + node->SetProperty("pointsize", mitk::FloatProperty::New((float)maxSize/50)); + int b0 = shellCount%2; + int b1 = 0; + int b2 = 0; + if (shellCount>4) + b2 = 1; + if (shellCount%4 >= 2) + b1 = 1; + + node->SetProperty("color", mitk::ColorProperty::New(b2, b1, b0)); + GetDefaultDataStorage()->Add(node, m_SelectedDiffusionNodes.front()); + shellCount++; + } + + // add origin to datastorage mitk::DataNode::Pointer node = mitk::DataNode::New(); - node->SetData(pointset); + node->SetData(originSet); QString name = m_SelectedDiffusionNodes.front()->GetName().c_str(); - name += "_Shell_"; - name += QString::number(it->first); + name += "_Origin"; node->SetName(name.toStdString().c_str()); node->SetProperty("pointsize", mitk::FloatProperty::New((float)maxSize/50)); - int b0 = shellCount%2; - int b1 = 0; - int b2 = 0; - if (shellCount>4) - b2 = 1; - if (shellCount%4 >= 2) - b1 = 1; - - node->SetProperty("color", mitk::ColorProperty::New(b2, b1, b0)); + node->SetProperty("color", mitk::ColorProperty::New(1,1,1)); GetDefaultDataStorage()->Add(node, m_SelectedDiffusionNodes.front()); - shellCount++; - } - - // add origin to datastorage - mitk::DataNode::Pointer node = mitk::DataNode::New(); - node->SetData(originSet); - QString name = m_SelectedDiffusionNodes.front()->GetName().c_str(); - name += "_Origin"; - node->SetName(name.toStdString().c_str()); - node->SetProperty("pointsize", mitk::FloatProperty::New((float)maxSize/50)); - node->SetProperty("color", mitk::ColorProperty::New(1,1,1)); - GetDefaultDataStorage()->Add(node, m_SelectedDiffusionNodes.front()); } void QmitkPreprocessingView::DoReduceGradientDirections() { - if (m_DiffusionImage.IsNull()) - return; - - typedef mitk::DiffusionImage DiffusionImageType; - typedef itk::ElectrostaticRepulsionDiffusionGradientReductionFilter FilterType; - typedef DiffusionImageType::BValueMap BValueMap; - - // GetShellSelection from GUI - BValueMap shellSlectionMap; - BValueMap originalShellMap = m_DiffusionImage->GetB_ValueMap(); - std::vector newNumGradientDirections; - int shellCounter = 0; - - foreach(QCheckBox * box , m_ReduceGradientCheckboxes) - { - if(box->isChecked()) + if (m_DiffusionImage.IsNull()) + return; + + typedef mitk::DiffusionImage DiffusionImageType; + typedef itk::ElectrostaticRepulsionDiffusionGradientReductionFilter FilterType; + typedef DiffusionImageType::BValueMap BValueMap; + + // GetShellSelection from GUI + BValueMap shellSlectionMap; + BValueMap originalShellMap = m_DiffusionImage->GetB_ValueMap(); + std::vector newNumGradientDirections; + int shellCounter = 0; + + foreach(QCheckBox * box , m_ReduceGradientCheckboxes) { - double BValue = (box->text().split(' ')).at(0).toDouble(); - shellSlectionMap[BValue] = originalShellMap[BValue]; - newNumGradientDirections.push_back(m_ReduceGradientSpinboxes.at(shellCounter)->value()); + if(box->isChecked()) + { + double BValue = (box->text().split(' ')).at(0).toDouble(); + shellSlectionMap[BValue] = originalShellMap[BValue]; + newNumGradientDirections.push_back(m_ReduceGradientSpinboxes.at(shellCounter)->value()); + } + shellCounter++; } - shellCounter++; - } - - if (newNumGradientDirections.empty()) - return; - - GradientDirectionContainerType::Pointer gradientContainer = m_DiffusionImage->GetDirections(); - FilterType::Pointer filter = FilterType::New(); - filter->SetInput(m_DiffusionImage->GetVectorImage()); - filter->SetOriginalGradientDirections(gradientContainer); - filter->SetNumGradientDirections(newNumGradientDirections); - filter->SetOriginalBValueMap(originalShellMap); - filter->SetShellSelectionBValueMap(shellSlectionMap); - filter->Update(); - - DiffusionImageType::Pointer image = DiffusionImageType::New(); - image->SetVectorImage( filter->GetOutput() ); - image->SetB_Value(m_DiffusionImage->GetB_Value()); - image->SetDirections(filter->GetGradientDirections()); - image->SetMeasurementFrame(m_DiffusionImage->GetMeasurementFrame()); - image->InitializeFromVectorImage(); - - mitk::DataNode::Pointer imageNode = mitk::DataNode::New(); - imageNode->SetData( image ); - QString name = m_SelectedDiffusionNodes.front()->GetName().c_str(); - - foreach(QSpinBox* box, m_ReduceGradientSpinboxes) - { - name += "_"; - name += QString::number(box->value()); - } - - imageNode->SetName(name.toStdString().c_str()); - GetDefaultDataStorage()->Add(imageNode); + + if (newNumGradientDirections.empty()) + return; + + GradientDirectionContainerType::Pointer gradientContainer = m_DiffusionImage->GetDirections(); + FilterType::Pointer filter = FilterType::New(); + filter->SetInput(m_DiffusionImage->GetVectorImage()); + filter->SetOriginalGradientDirections(gradientContainer); + filter->SetNumGradientDirections(newNumGradientDirections); + filter->SetOriginalBValueMap(originalShellMap); + filter->SetShellSelectionBValueMap(shellSlectionMap); + filter->Update(); + + DiffusionImageType::Pointer image = DiffusionImageType::New(); + image->SetVectorImage( filter->GetOutput() ); + image->SetB_Value(m_DiffusionImage->GetB_Value()); + image->SetDirections(filter->GetGradientDirections()); + image->SetMeasurementFrame(m_DiffusionImage->GetMeasurementFrame()); + image->InitializeFromVectorImage(); + + mitk::DataNode::Pointer imageNode = mitk::DataNode::New(); + imageNode->SetData( image ); + QString name = m_SelectedDiffusionNodes.front()->GetName().c_str(); + + foreach(QSpinBox* box, m_ReduceGradientSpinboxes) + { + name += "_"; + name += QString::number(box->value()); + } + + imageNode->SetName(name.toStdString().c_str()); + GetDefaultDataStorage()->Add(imageNode); } void QmitkPreprocessingView::MergeDwis() { - typedef mitk::DiffusionImage DiffusionImageType; - typedef DiffusionImageType::GradientDirectionContainerType GradientContainerType; + typedef mitk::DiffusionImage DiffusionImageType; + typedef DiffusionImageType::GradientDirectionContainerType GradientContainerType; - if (m_SelectedDiffusionNodes.size()<2) - return; + if (m_SelectedDiffusionNodes.size()<2) + return; - typedef itk::VectorImage DwiImageType; - typedef DwiImageType::PixelType DwiPixelType; - typedef DwiImageType::RegionType DwiRegionType; - typedef std::vector< DwiImageType::Pointer > DwiImageContainerType; + typedef itk::VectorImage DwiImageType; + typedef DwiImageType::PixelType DwiPixelType; + typedef DwiImageType::RegionType DwiRegionType; + typedef std::vector< DwiImageType::Pointer > DwiImageContainerType; - typedef std::vector< GradientContainerType::Pointer > GradientListContainerType; + typedef std::vector< GradientContainerType::Pointer > GradientListContainerType; - DwiImageContainerType imageContainer; - GradientListContainerType gradientListContainer; - std::vector< double > bValueContainer; + DwiImageContainerType imageContainer; + GradientListContainerType gradientListContainer; + std::vector< double > bValueContainer; - QString name = m_SelectedDiffusionNodes.front()->GetName().c_str(); - for (int i=0; i* >( m_SelectedDiffusionNodes.at(i)->GetData() ); - if ( dwi.IsNotNull() ) + QString name = m_SelectedDiffusionNodes.front()->GetName().c_str(); + for (int i=0; iGetVectorImage()); - gradientListContainer.push_back(dwi->GetDirections()); - bValueContainer.push_back(dwi->GetB_Value()); - if (i>0) - { - name += "+"; - name += m_SelectedDiffusionNodes.at(i)->GetName().c_str(); - } + DiffusionImageType::Pointer dwi = dynamic_cast< mitk::DiffusionImage* >( m_SelectedDiffusionNodes.at(i)->GetData() ); + if ( dwi.IsNotNull() ) + { + imageContainer.push_back(dwi->GetVectorImage()); + gradientListContainer.push_back(dwi->GetDirections()); + bValueContainer.push_back(dwi->GetB_Value()); + if (i>0) + { + name += "+"; + name += m_SelectedDiffusionNodes.at(i)->GetName().c_str(); + } + } } - } - - typedef itk::MergeDiffusionImagesFilter FilterType; - FilterType::Pointer filter = FilterType::New(); - filter->SetImageVolumes(imageContainer); - filter->SetGradientLists(gradientListContainer); - filter->SetBValues(bValueContainer); - filter->Update(); - - vnl_matrix_fixed< double, 3, 3 > mf; mf.set_identity(); - DiffusionImageType::Pointer image = DiffusionImageType::New(); - image->SetVectorImage( filter->GetOutput() ); - image->SetB_Value(filter->GetB_Value()); - image->SetDirections(filter->GetOutputGradients()); - image->SetMeasurementFrame(mf); - image->InitializeFromVectorImage(); - - mitk::DataNode::Pointer imageNode = mitk::DataNode::New(); - imageNode->SetData( image ); - imageNode->SetName(name.toStdString().c_str()); - GetDefaultDataStorage()->Add(imageNode); + + typedef itk::MergeDiffusionImagesFilter FilterType; + FilterType::Pointer filter = FilterType::New(); + filter->SetImageVolumes(imageContainer); + filter->SetGradientLists(gradientListContainer); + filter->SetBValues(bValueContainer); + filter->Update(); + + vnl_matrix_fixed< double, 3, 3 > mf; mf.set_identity(); + DiffusionImageType::Pointer image = DiffusionImageType::New(); + image->SetVectorImage( filter->GetOutput() ); + image->SetB_Value(filter->GetB_Value()); + image->SetDirections(filter->GetOutputGradients()); + image->SetMeasurementFrame(mf); + image->InitializeFromVectorImage(); + + mitk::DataNode::Pointer imageNode = mitk::DataNode::New(); + imageNode->SetData( image ); + imageNode->SetName(name.toStdString().c_str()); + GetDefaultDataStorage()->Add(imageNode); } void QmitkPreprocessingView::ExtractB0() { - typedef mitk::DiffusionImage DiffusionImageType; - typedef DiffusionImageType::GradientDirectionContainerType GradientContainerType; + typedef mitk::DiffusionImage DiffusionImageType; + typedef DiffusionImageType::GradientDirectionContainerType GradientContainerType; - int nrFiles = m_SelectedDiffusionNodes.size(); - if (!nrFiles) return; + int nrFiles = m_SelectedDiffusionNodes.size(); + if (!nrFiles) return; - // call the extraction withou averaging if the check-box is checked - if( this->m_Controls->m_CheckExtractAll->isChecked() ) - { - DoExtractBOWithoutAveraging(); - return; - } + // call the extraction withou averaging if the check-box is checked + if( this->m_Controls->m_CheckExtractAll->isChecked() ) + { + DoExtractBOWithoutAveraging(); + return; + } - mitk::DataStorage::SetOfObjects::const_iterator itemiter( m_SelectedDiffusionNodes.begin() ); - mitk::DataStorage::SetOfObjects::const_iterator itemiterend( m_SelectedDiffusionNodes.end() ); + mitk::DataStorage::SetOfObjects::const_iterator itemiter( m_SelectedDiffusionNodes.begin() ); + mitk::DataStorage::SetOfObjects::const_iterator itemiterend( m_SelectedDiffusionNodes.end() ); - std::vector nodes; - while ( itemiter != itemiterend ) // for all items - { + std::vector nodes; + while ( itemiter != itemiterend ) // for all items + { - DiffusionImageType* vols = - static_cast( - (*itemiter)->GetData()); + DiffusionImageType* vols = + static_cast( + (*itemiter)->GetData()); - std::string nodename; - (*itemiter)->GetStringProperty("name", nodename); + std::string nodename; + (*itemiter)->GetStringProperty("name", nodename); - // Extract image using found index - typedef itk::B0ImageExtractionImageFilter FilterType; - FilterType::Pointer filter = FilterType::New(); - filter->SetInput(vols->GetVectorImage()); - filter->SetDirections(vols->GetDirections()); - filter->Update(); + // Extract image using found index + typedef itk::B0ImageExtractionImageFilter FilterType; + FilterType::Pointer filter = FilterType::New(); + filter->SetInput(vols->GetVectorImage()); + filter->SetDirections(vols->GetDirections()); + filter->Update(); - mitk::Image::Pointer mitkImage = mitk::Image::New(); - mitkImage->InitializeByItk( filter->GetOutput() ); - mitkImage->SetVolume( filter->GetOutput()->GetBufferPointer() ); - mitk::DataNode::Pointer node=mitk::DataNode::New(); - node->SetData( mitkImage ); - node->SetProperty( "name", mitk::StringProperty::New(nodename + "_B0")); + mitk::Image::Pointer mitkImage = mitk::Image::New(); + mitkImage->InitializeByItk( filter->GetOutput() ); + mitkImage->SetVolume( filter->GetOutput()->GetBufferPointer() ); + mitk::DataNode::Pointer node=mitk::DataNode::New(); + node->SetData( mitkImage ); + node->SetProperty( "name", mitk::StringProperty::New(nodename + "_B0")); - GetDefaultDataStorage()->Add(node); + GetDefaultDataStorage()->Add(node); - ++itemiter; - } + ++itemiter; + } } void QmitkPreprocessingView::DoExtractBOWithoutAveraging() { - // typedefs - typedef mitk::DiffusionImage DiffusionImageType; - typedef DiffusionImageType::GradientDirectionContainerType GradientContainerType; - typedef itk::B0ImageExtractionToSeparateImageFilter< short, short> FilterType; - - // check number of selected objects, return if empty - int nrFiles = m_SelectedDiffusionNodes.size(); - if (!nrFiles) - return; + // typedefs + typedef mitk::DiffusionImage DiffusionImageType; + typedef DiffusionImageType::GradientDirectionContainerType GradientContainerType; + typedef itk::B0ImageExtractionToSeparateImageFilter< short, short> FilterType; + + // check number of selected objects, return if empty + int nrFiles = m_SelectedDiffusionNodes.size(); + if (!nrFiles) + return; - mitk::DataStorage::SetOfObjects::const_iterator itemiter( m_SelectedDiffusionNodes.begin() ); - mitk::DataStorage::SetOfObjects::const_iterator itemiterend( m_SelectedDiffusionNodes.end() ); + mitk::DataStorage::SetOfObjects::const_iterator itemiter( m_SelectedDiffusionNodes.begin() ); + mitk::DataStorage::SetOfObjects::const_iterator itemiterend( m_SelectedDiffusionNodes.end() ); - while ( itemiter != itemiterend ) // for all items - { - DiffusionImageType* vols = - static_cast( - (*itemiter)->GetData()); + while ( itemiter != itemiterend ) // for all items + { + DiffusionImageType* vols = + static_cast( + (*itemiter)->GetData()); - std::string nodename; - (*itemiter)->GetStringProperty("name", nodename); + std::string nodename; + (*itemiter)->GetStringProperty("name", nodename); - // Extract image using found index - FilterType::Pointer filter = FilterType::New(); - filter->SetInput(vols->GetVectorImage()); - filter->SetDirections(vols->GetDirections()); - filter->Update(); + // Extract image using found index + FilterType::Pointer filter = FilterType::New(); + filter->SetInput(vols->GetVectorImage()); + filter->SetDirections(vols->GetDirections()); + filter->Update(); - mitk::Image::Pointer mitkImage = mitk::Image::New(); - mitkImage->InitializeByItk( filter->GetOutput() ); - mitkImage->SetImportChannel( filter->GetOutput()->GetBufferPointer() ); - mitk::DataNode::Pointer node=mitk::DataNode::New(); - node->SetData( mitkImage ); - node->SetProperty( "name", mitk::StringProperty::New(nodename + "_B0_ALL")); + mitk::Image::Pointer mitkImage = mitk::Image::New(); + mitkImage->InitializeByItk( filter->GetOutput() ); + mitkImage->SetImportChannel( filter->GetOutput()->GetBufferPointer() ); + mitk::DataNode::Pointer node=mitk::DataNode::New(); + node->SetData( mitkImage ); + node->SetProperty( "name", mitk::StringProperty::New(nodename + "_B0_ALL")); - GetDefaultDataStorage()->Add(node); + GetDefaultDataStorage()->Add(node); - ++itemiter; - } + ++itemiter; + } } void QmitkPreprocessingView::AverageGradients() { - int nrFiles = m_SelectedDiffusionNodes.size(); - if (!nrFiles) return; + int nrFiles = m_SelectedDiffusionNodes.size(); + if (!nrFiles) return; - mitk::DataStorage::SetOfObjects::const_iterator itemiter( m_SelectedDiffusionNodes.begin() ); - mitk::DataStorage::SetOfObjects::const_iterator itemiterend( m_SelectedDiffusionNodes.end() ); + mitk::DataStorage::SetOfObjects::const_iterator itemiter( m_SelectedDiffusionNodes.begin() ); + mitk::DataStorage::SetOfObjects::const_iterator itemiterend( m_SelectedDiffusionNodes.end() ); - std::vector nodes; - while ( itemiter != itemiterend ) // for all items - { + std::vector nodes; + while ( itemiter != itemiterend ) // for all items + { - mitk::DiffusionImage* vols = - static_cast*>( - (*itemiter)->GetData()); + mitk::DiffusionImage* vols = + static_cast*>( + (*itemiter)->GetData()); - vols->AverageRedundantGradients(m_Controls->m_Blur->value()); + vols->AverageRedundantGradients(m_Controls->m_Blur->value()); - ++itemiter; - } + ++itemiter; + } }