diff --git a/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkFiberfoxView.cpp b/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkFiberfoxView.cpp
index eb198fabcb..2c85f47582 100644
--- a/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkFiberfoxView.cpp
+++ b/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkFiberfoxView.cpp
@@ -1,2579 +1,2579 @@
 /*===================================================================
 
 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.
 
 ===================================================================*/
 
 //misc
 #define _USE_MATH_DEFINES
 #include <math.h>
 
 // Blueberry
 #include <berryISelectionService.h>
 #include <berryIWorkbenchWindow.h>
 
 // Qmitk
 #include "QmitkFiberfoxView.h"
 
 // MITK
 #include <mitkImage.h>
 #include <mitkDiffusionImage.h>
 #include <mitkImageToItk.h>
 #include <mitkImageCast.h>
 #include <mitkProperties.h>
 #include <mitkPlanarFigureInteractor.h>
 #include <mitkDataStorage.h>
 #include <itkFibersFromPlanarFiguresFilter.h>
 #include <itkTractsToDWIImageFilter.h>
 #include <mitkTensorImage.h>
 #include <mitkILinkedRenderWindowPart.h>
 #include <mitkGlobalInteraction.h>
 #include <mitkImageToItk.h>
 #include <mitkImageCast.h>
 #include <mitkImageGenerator.h>
 #include <mitkNodePredicateDataType.h>
 #include <itkScalableAffineTransform.h>
 #include <mitkLevelWindowProperty.h>
 #include <mitkNodePredicateOr.h>
 #include <mitkNodePredicateAnd.h>
 #include <mitkNodePredicateNot.h>
 #include <boost/property_tree/ptree.hpp>
 #include <boost/property_tree/xml_parser.hpp>
 #include <boost/foreach.hpp>
 #include <QFileDialog>
 #include <QMessageBox>
 #include "usModuleRegistry.h"
 #include <mitkChiSquareNoiseModel.h>
 #include <itksys/SystemTools.hxx>
 #include <mitkIOUtil.h>
 #include <QScrollBar>
 #include <itkInvertIntensityImageFilter.h>
 #include <QDialogButtonBox>
 #include <itkAdcImageFilter.h>
 #include <itkShiftScaleImageFilter.h>
 
 #define _USE_MATH_DEFINES
 #include <math.h>
 
 QmitkFiberfoxWorker::QmitkFiberfoxWorker(QmitkFiberfoxView* view)
     : m_View(view)
 {
 
 }
 
 void QmitkFiberfoxWorker::run()
 {
     try{
         switch (m_FilterType)
         {
         case 0:
             m_View->m_TractsToDwiFilter->Update();
             break;
         case 1:
             m_View->m_ArtifactsToDwiFilter->Update();
             break;
         }
     }
     catch( ... )
     {
 
     }
     m_View->m_Thread.quit();
 }
 
 const std::string QmitkFiberfoxView::VIEW_ID = "org.mitk.views.fiberfoxview";
 
 QmitkFiberfoxView::QmitkFiberfoxView()
     : QmitkAbstractView()
     , m_Controls( 0 )
     , m_SelectedImage( NULL )
     , m_Worker(this)
     , m_ThreadIsRunning(false)
 {
     m_Worker.moveToThread(&m_Thread);
     connect(&m_Thread, SIGNAL(started()), this, SLOT(BeforeThread()));
     connect(&m_Thread, SIGNAL(started()), &m_Worker, SLOT(run()));
     connect(&m_Thread, SIGNAL(finished()), this, SLOT(AfterThread()));
     connect(&m_Thread, SIGNAL(terminated()), this, SLOT(AfterThread()));
     m_SimulationTimer = new QTimer(this);
 }
 
 void QmitkFiberfoxView::KillThread()
 {
     MITK_INFO << "Aborting DWI simulation.";
     switch (m_Worker.m_FilterType)
     {
     case 0:
         m_TractsToDwiFilter->SetAbortGenerateData(true);
         break;
     case 1:
         m_ArtifactsToDwiFilter->SetAbortGenerateData(true);
         break;
     }
     m_Controls->m_AbortSimulationButton->setEnabled(false);
     m_Controls->m_AbortSimulationButton->setText("Aborting simulation ...");
 }
 
 void QmitkFiberfoxView::BeforeThread()
 {
     m_SimulationTime = QTime::currentTime();
     m_SimulationTimer->start(100);
     m_Controls->m_AbortSimulationButton->setVisible(true);
     m_Controls->m_GenerateImageButton->setVisible(false);
     m_Controls->m_SimulationStatusText->setVisible(true);
     m_ThreadIsRunning = true;
 }
 
 void QmitkFiberfoxView::AfterThread()
 {
     UpdateSimulationStatus();
     m_SimulationTimer->stop();
     m_Controls->m_AbortSimulationButton->setVisible(false);
     m_Controls->m_AbortSimulationButton->setEnabled(true);
     m_Controls->m_AbortSimulationButton->setText("Abort simulation");
     m_Controls->m_GenerateImageButton->setVisible(true);
     m_ThreadIsRunning = false;
 
     QString statusText;
     FiberfoxParameters<double> parameters;
     mitk::DiffusionImage<short>::Pointer mitkImage = mitk::DiffusionImage<short>::New();
     switch (m_Worker.m_FilterType)
     {
     case 0:
     {
         statusText = QString(m_TractsToDwiFilter->GetStatusText().c_str());
         if (m_TractsToDwiFilter->GetAbortGenerateData())
         {
             MITK_INFO << "Simulation aborted.";
             return;
         }
 
         parameters = m_TractsToDwiFilter->GetParameters();
 
         mitkImage->SetVectorImage( m_TractsToDwiFilter->GetOutput() );
         mitkImage->SetReferenceBValue(parameters.m_Bvalue);
         mitkImage->SetDirections(parameters.GetGradientDirections());
         mitkImage->InitializeFromVectorImage();
         parameters.m_ResultNode->SetData( mitkImage );
 
         parameters.m_ResultNode->SetName(parameters.m_ParentNode->GetName()
                                          +"_D"+QString::number(parameters.m_ImageRegion.GetSize(0)).toStdString()
                                          +"-"+QString::number(parameters.m_ImageRegion.GetSize(1)).toStdString()
                                          +"-"+QString::number(parameters.m_ImageRegion.GetSize(2)).toStdString()
                                          +"_S"+QString::number(parameters.m_ImageSpacing[0]).toStdString()
                 +"-"+QString::number(parameters.m_ImageSpacing[1]).toStdString()
                 +"-"+QString::number(parameters.m_ImageSpacing[2]).toStdString()
                 +"_b"+QString::number(parameters.m_Bvalue).toStdString()
                 +"_"+parameters.m_SignalModelString
                 +parameters.m_ArtifactModelString);
 
         GetDataStorage()->Add(parameters.m_ResultNode, parameters.m_ParentNode);
 
         parameters.m_ResultNode->SetProperty( "levelwindow", mitk::LevelWindowProperty::New(m_TractsToDwiFilter->GetLevelWindow()) );
 
         if (m_Controls->m_VolumeFractionsBox->isChecked())
         {
             std::vector< itk::TractsToDWIImageFilter< short >::ItkDoubleImgType::Pointer > volumeFractions = m_TractsToDwiFilter->GetVolumeFractions();
             for (unsigned int k=0; k<volumeFractions.size(); k++)
             {
                 mitk::Image::Pointer image = mitk::Image::New();
                 image->InitializeByItk(volumeFractions.at(k).GetPointer());
                 image->SetVolume(volumeFractions.at(k)->GetBufferPointer());
 
                 mitk::DataNode::Pointer node = mitk::DataNode::New();
                 node->SetData( image );
                 node->SetName(parameters.m_ParentNode->GetName()+"_CompartmentVolume-"+QString::number(k).toStdString());
                 GetDataStorage()->Add(node, parameters.m_ParentNode);
             }
         }
         m_TractsToDwiFilter = NULL;
         break;
     }
     case 1:
     {
         statusText = QString(m_ArtifactsToDwiFilter->GetStatusText().c_str());
         if (m_ArtifactsToDwiFilter->GetAbortGenerateData())
         {
             MITK_INFO << "Simulation aborted.";
             return;
         }
 
         parameters = m_ArtifactsToDwiFilter->GetParameters().CopyParameters<double>();
 
         mitk::DiffusionImage<short>::Pointer diffImg = dynamic_cast<mitk::DiffusionImage<short>*>(parameters.m_ParentNode->GetData());
         mitkImage = mitk::DiffusionImage<short>::New();
         mitkImage->SetVectorImage( m_ArtifactsToDwiFilter->GetOutput() );
         mitkImage->SetReferenceBValue(diffImg->GetReferenceBValue());
         mitkImage->SetDirections(diffImg->GetDirections());
         mitkImage->InitializeFromVectorImage();
         parameters.m_ResultNode->SetData( mitkImage );
         parameters.m_ResultNode->SetName(parameters.m_ParentNode->GetName()+parameters.m_ArtifactModelString);
         GetDataStorage()->Add(parameters.m_ResultNode, parameters.m_ParentNode);
         m_ArtifactsToDwiFilter = NULL;
         break;
     }
     }
 
     mitk::BaseData::Pointer basedata = parameters.m_ResultNode->GetData();
     if (basedata.IsNotNull())
     {
         mitk::RenderingManager::GetInstance()->InitializeViews(
                     basedata->GetTimeGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true );
         mitk::RenderingManager::GetInstance()->RequestUpdateAll();
     }
 
     if (!parameters.m_OutputPath.empty())
     {
         try{
             QString outputFileName(parameters.m_OutputPath.c_str());
             outputFileName += parameters.m_ResultNode->GetName().c_str();
             outputFileName.replace(QString("."), QString("_"));
             outputFileName += ".dwi";
             QString status("Saving output image to ");
             status += outputFileName;
             m_Controls->m_SimulationStatusText->append(status);
             mitk::IOUtil::SaveBaseData(mitkImage, outputFileName.toStdString());
             m_Controls->m_SimulationStatusText->append("File saved successfully.");
         }
         catch (itk::ExceptionObject &e)
         {
             QString status("Exception during DWI writing: ");
             status += e.GetDescription();
             m_Controls->m_SimulationStatusText->append(status);
         }
         catch (...)
         {
             m_Controls->m_SimulationStatusText->append("Unknown exception during DWI writing!");
         }
     }
     parameters.m_FrequencyMap = NULL;
 }
 
 void QmitkFiberfoxView::UpdateSimulationStatus()
 {
     QString statusText;
     switch (m_Worker.m_FilterType)
     {
     case 0:
         statusText = QString(m_TractsToDwiFilter->GetStatusText().c_str());
         break;
     case 1:
         statusText = QString(m_ArtifactsToDwiFilter->GetStatusText().c_str());
         break;
     }
 
     if (QString::compare(m_SimulationStatusText,statusText)!=0)
     {
         m_Controls->m_SimulationStatusText->clear();
         statusText = "<pre>"+statusText+"</pre>";
         m_Controls->m_SimulationStatusText->setText(statusText);
         QScrollBar *vScrollBar = m_Controls->m_SimulationStatusText->verticalScrollBar();
         vScrollBar->triggerAction(QScrollBar::SliderToMaximum);
     }
 }
 
 // Destructor
 QmitkFiberfoxView::~QmitkFiberfoxView()
 {
     delete m_SimulationTimer;
 }
 
 void QmitkFiberfoxView::CreateQtPartControl( QWidget *parent )
 {
     // build up qt view, unless already done
     if ( !m_Controls )
     {
         // create GUI widgets from the Qt Designer's .ui file
         m_Controls = new Ui::QmitkFiberfoxViewControls;
         m_Controls->setupUi( parent );
 
         m_Controls->m_StickWidget1->setVisible(true);
         m_Controls->m_StickWidget2->setVisible(false);
         m_Controls->m_ZeppelinWidget1->setVisible(false);
         m_Controls->m_ZeppelinWidget2->setVisible(false);
         m_Controls->m_TensorWidget1->setVisible(false);
         m_Controls->m_TensorWidget2->setVisible(false);
 
         m_Controls->m_BallWidget1->setVisible(true);
         m_Controls->m_BallWidget2->setVisible(false);
         m_Controls->m_AstrosticksWidget1->setVisible(false);
         m_Controls->m_AstrosticksWidget2->setVisible(false);
         m_Controls->m_DotWidget1->setVisible(false);
         m_Controls->m_DotWidget2->setVisible(false);
 
         m_Controls->m_PrototypeWidget1->setVisible(false);
         m_Controls->m_PrototypeWidget2->setVisible(false);
         m_Controls->m_PrototypeWidget3->setVisible(false);
         m_Controls->m_PrototypeWidget4->setVisible(false);
 
         m_Controls->m_PrototypeWidget3->SetMinFa(0.0);
         m_Controls->m_PrototypeWidget3->SetMaxFa(0.15);
         m_Controls->m_PrototypeWidget4->SetMinFa(0.0);
         m_Controls->m_PrototypeWidget4->SetMaxFa(0.15);
         m_Controls->m_PrototypeWidget3->SetMinAdc(0.0);
         m_Controls->m_PrototypeWidget3->SetMaxAdc(0.001);
         m_Controls->m_PrototypeWidget4->SetMinAdc(0.003);
         m_Controls->m_PrototypeWidget4->SetMaxAdc(0.004);
 
         m_Controls->m_Comp4FractionFrame->setVisible(false);
         m_Controls->m_DiffusionPropsMessage->setVisible(false);
         m_Controls->m_GeometryMessage->setVisible(false);
         m_Controls->m_AdvancedSignalOptionsFrame->setVisible(false);
         m_Controls->m_AdvancedFiberOptionsFrame->setVisible(false);
         m_Controls->m_VarianceBox->setVisible(false);
         m_Controls->m_NoiseFrame->setVisible(false);
         m_Controls->m_GhostFrame->setVisible(false);
         m_Controls->m_DistortionsFrame->setVisible(false);
         m_Controls->m_EddyFrame->setVisible(false);
         m_Controls->m_SpikeFrame->setVisible(false);
         m_Controls->m_AliasingFrame->setVisible(false);
         m_Controls->m_MotionArtifactFrame->setVisible(false);
         m_ParameterFile = QDir::currentPath()+"/param.ffp";
 
         m_Controls->m_AbortSimulationButton->setVisible(false);
         m_Controls->m_SimulationStatusText->setVisible(false);
 
         m_Controls->m_FrequencyMapBox->SetDataStorage(this->GetDataStorage());
         mitk::TNodePredicateDataType<mitk::Image>::Pointer isMitkImage = mitk::TNodePredicateDataType<mitk::Image>::New();
         mitk::NodePredicateDataType::Pointer isDwi = mitk::NodePredicateDataType::New("DiffusionImage");
         mitk::NodePredicateDataType::Pointer isDti = mitk::NodePredicateDataType::New("TensorImage");
         mitk::NodePredicateDataType::Pointer isQbi = mitk::NodePredicateDataType::New("QBallImage");
         mitk::NodePredicateOr::Pointer isDiffusionImage = mitk::NodePredicateOr::New(isDwi, isDti);
         isDiffusionImage = mitk::NodePredicateOr::New(isDiffusionImage, isQbi);
         mitk::NodePredicateNot::Pointer noDiffusionImage = mitk::NodePredicateNot::New(isDiffusionImage);
         mitk::NodePredicateAnd::Pointer finalPredicate = mitk::NodePredicateAnd::New(isMitkImage, noDiffusionImage);
         m_Controls->m_FrequencyMapBox->SetPredicate(finalPredicate);
         m_Controls->m_Comp4VolumeFraction->SetDataStorage(this->GetDataStorage());
         m_Controls->m_Comp4VolumeFraction->SetPredicate(finalPredicate);
 
         connect( m_SimulationTimer, SIGNAL(timeout()), this, SLOT(UpdateSimulationStatus()) );
         connect((QObject*) m_Controls->m_AbortSimulationButton, SIGNAL(clicked()), (QObject*) this, SLOT(KillThread()));
         connect((QObject*) m_Controls->m_GenerateImageButton, SIGNAL(clicked()), (QObject*) this, SLOT(GenerateImage()));
         connect((QObject*) m_Controls->m_GenerateFibersButton, SIGNAL(clicked()), (QObject*) this, SLOT(GenerateFibers()));
         connect((QObject*) m_Controls->m_CircleButton, SIGNAL(clicked()), (QObject*) this, SLOT(OnDrawROI()));
         connect((QObject*) m_Controls->m_FlipButton, SIGNAL(clicked()), (QObject*) this, SLOT(OnFlipButton()));
         connect((QObject*) m_Controls->m_JoinBundlesButton, SIGNAL(clicked()), (QObject*) this, SLOT(JoinBundles()));
         connect((QObject*) m_Controls->m_VarianceBox, SIGNAL(valueChanged(double)), (QObject*) this, SLOT(OnVarianceChanged(double)));
         connect((QObject*) m_Controls->m_DistributionBox, SIGNAL(currentIndexChanged(int)), (QObject*) this, SLOT(OnDistributionChanged(int)));
         connect((QObject*) m_Controls->m_FiberDensityBox, SIGNAL(valueChanged(int)), (QObject*) this, SLOT(OnFiberDensityChanged(int)));
         connect((QObject*) m_Controls->m_FiberSamplingBox, SIGNAL(valueChanged(double)), (QObject*) this, SLOT(OnFiberSamplingChanged(double)));
         connect((QObject*) m_Controls->m_TensionBox, SIGNAL(valueChanged(double)), (QObject*) this, SLOT(OnTensionChanged(double)));
         connect((QObject*) m_Controls->m_ContinuityBox, SIGNAL(valueChanged(double)), (QObject*) this, SLOT(OnContinuityChanged(double)));
         connect((QObject*) m_Controls->m_BiasBox, SIGNAL(valueChanged(double)), (QObject*) this, SLOT(OnBiasChanged(double)));
         connect((QObject*) m_Controls->m_AddNoise, SIGNAL(stateChanged(int)), (QObject*) this, SLOT(OnAddNoise(int)));
         connect((QObject*) m_Controls->m_AddGhosts, SIGNAL(stateChanged(int)), (QObject*) this, SLOT(OnAddGhosts(int)));
         connect((QObject*) m_Controls->m_AddDistortions, SIGNAL(stateChanged(int)), (QObject*) this, SLOT(OnAddDistortions(int)));
         connect((QObject*) m_Controls->m_AddEddy, SIGNAL(stateChanged(int)), (QObject*) this, SLOT(OnAddEddy(int)));
         connect((QObject*) m_Controls->m_AddSpikes, SIGNAL(stateChanged(int)), (QObject*) this, SLOT(OnAddSpikes(int)));
         connect((QObject*) m_Controls->m_AddAliasing, SIGNAL(stateChanged(int)), (QObject*) this, SLOT(OnAddAliasing(int)));
         connect((QObject*) m_Controls->m_AddMotion, SIGNAL(stateChanged(int)), (QObject*) this, SLOT(OnAddMotion(int)));
 
         connect((QObject*) m_Controls->m_ConstantRadiusBox, SIGNAL(stateChanged(int)), (QObject*) this, SLOT(OnConstantRadius(int)));
         connect((QObject*) m_Controls->m_CopyBundlesButton, SIGNAL(clicked()), (QObject*) this, SLOT(CopyBundles()));
         connect((QObject*) m_Controls->m_TransformBundlesButton, SIGNAL(clicked()), (QObject*) this, SLOT(ApplyTransform()));
         connect((QObject*) m_Controls->m_AlignOnGrid, SIGNAL(clicked()), (QObject*) this, SLOT(AlignOnGrid()));
 
         connect((QObject*) m_Controls->m_Compartment1Box, SIGNAL(currentIndexChanged(int)), (QObject*) this, SLOT(Comp1ModelFrameVisibility(int)));
         connect((QObject*) m_Controls->m_Compartment2Box, SIGNAL(currentIndexChanged(int)), (QObject*) this, SLOT(Comp2ModelFrameVisibility(int)));
         connect((QObject*) m_Controls->m_Compartment3Box, SIGNAL(currentIndexChanged(int)), (QObject*) this, SLOT(Comp3ModelFrameVisibility(int)));
         connect((QObject*) m_Controls->m_Compartment4Box, SIGNAL(currentIndexChanged(int)), (QObject*) this, SLOT(Comp4ModelFrameVisibility(int)));
 
         connect((QObject*) m_Controls->m_AdvancedOptionsBox, SIGNAL( stateChanged(int)), (QObject*) this, SLOT(ShowAdvancedOptions(int)));
         connect((QObject*) m_Controls->m_AdvancedOptionsBox_2, SIGNAL( stateChanged(int)), (QObject*) this, SLOT(ShowAdvancedOptions(int)));
 
         connect((QObject*) m_Controls->m_SaveParametersButton, SIGNAL(clicked()), (QObject*) this, SLOT(SaveParameters()));
         connect((QObject*) m_Controls->m_LoadParametersButton, SIGNAL(clicked()), (QObject*) this, SLOT(LoadParameters()));
         connect((QObject*) m_Controls->m_OutputPathButton, SIGNAL(clicked()), (QObject*) this, SLOT(SetOutputPath()));
 
     }
 }
 
 template< class ScalarType >
 FiberfoxParameters< ScalarType > QmitkFiberfoxView::UpdateImageParameters()
 {
     FiberfoxParameters< ScalarType > parameters;
     parameters.m_OutputPath = "";
 
     string outputPath = m_Controls->m_SavePathEdit->text().toStdString();
     if (outputPath.compare("-")!=0)
     {
         parameters.m_OutputPath = outputPath;
         parameters.m_OutputPath += "/";
     }
 
     if (m_MaskImageNode.IsNotNull())
     {
         mitk::Image::Pointer mitkMaskImage = dynamic_cast<mitk::Image*>(m_MaskImageNode->GetData());
         mitk::CastToItkImage<ItkUcharImgType>(mitkMaskImage, parameters.m_MaskImage);
         itk::ImageDuplicator<ItkUcharImgType>::Pointer duplicator = itk::ImageDuplicator<ItkUcharImgType>::New();
         duplicator->SetInputImage(parameters.m_MaskImage);
         duplicator->Update();
         parameters.m_MaskImage = duplicator->GetOutput();
     }
 
     if (m_SelectedDWI.IsNotNull())  // use parameters of selected DWI
     {
         mitk::DiffusionImage<short>::Pointer dwi = dynamic_cast<mitk::DiffusionImage<short>*>(m_SelectedDWI->GetData());
         parameters.m_ImageRegion = dwi->GetVectorImage()->GetLargestPossibleRegion();
         parameters.m_ImageSpacing = dwi->GetVectorImage()->GetSpacing();
         parameters.m_ImageOrigin = dwi->GetVectorImage()->GetOrigin();
         parameters.m_ImageDirection = dwi->GetVectorImage()->GetDirection();
         parameters.m_Bvalue = dwi->GetReferenceBValue();
         parameters.SetGradienDirections(dwi->GetDirections());
     }
     else if (m_SelectedImage.IsNotNull())   // use geometry of selected image
     {
         mitk::Image::Pointer img = dynamic_cast<mitk::Image*>(m_SelectedImage->GetData());
         itk::Image< float, 3 >::Pointer itkImg = itk::Image< float, 3 >::New();
         CastToItkImage< itk::Image< float, 3 > >(img, itkImg);
 
         parameters.m_ImageRegion = itkImg->GetLargestPossibleRegion();
         parameters.m_ImageSpacing = itkImg->GetSpacing();
         parameters.m_ImageOrigin = itkImg->GetOrigin();
         parameters.m_ImageDirection = itkImg->GetDirection();
         parameters.SetNumWeightedGradients(m_Controls->m_NumGradientsBox->value());
         parameters.m_Bvalue = m_Controls->m_BvalueBox->value();
     }
     else    // use GUI parameters
     {
         parameters.m_ImageRegion.SetSize(0, m_Controls->m_SizeX->value());
         parameters.m_ImageRegion.SetSize(1, m_Controls->m_SizeY->value());
         parameters.m_ImageRegion.SetSize(2, m_Controls->m_SizeZ->value());
         parameters.m_ImageSpacing[0] = m_Controls->m_SpacingX->value();
         parameters.m_ImageSpacing[1] = m_Controls->m_SpacingY->value();
         parameters.m_ImageSpacing[2] = m_Controls->m_SpacingZ->value();
         parameters.m_ImageOrigin[0] = parameters.m_ImageSpacing[0]/2;
         parameters.m_ImageOrigin[1] = parameters.m_ImageSpacing[1]/2;
         parameters.m_ImageOrigin[2] = parameters.m_ImageSpacing[2]/2;
         parameters.m_ImageDirection.SetIdentity();
         parameters.SetNumWeightedGradients(m_Controls->m_NumGradientsBox->value());
         parameters.m_Bvalue = m_Controls->m_BvalueBox->value();
         parameters.GenerateGradientHalfShell();
     }
 
     // signal relaxation
     parameters.m_DoSimulateRelaxation = m_Controls->m_RelaxationBox->isChecked();
     parameters.m_SimulateKspaceAcquisition = parameters.m_DoSimulateRelaxation;
     if (parameters.m_DoSimulateRelaxation && m_SelectedBundles.size()>0 )
         parameters.m_ArtifactModelString += "_RELAX";
 
     // N/2 ghosts
     if (m_Controls->m_AddGhosts->isChecked())
     {
         parameters.m_SimulateKspaceAcquisition = true;
         parameters.m_ArtifactModelString += "_GHOST";
         parameters.m_KspaceLineOffset = m_Controls->m_kOffsetBox->value();
         parameters.m_ResultNode->AddProperty("Fiberfox.Ghost", DoubleProperty::New(parameters.m_KspaceLineOffset));
     }
     else
         parameters.m_KspaceLineOffset = 0;
 
     // Aliasing
     if (m_Controls->m_AddAliasing->isChecked())
     {
         parameters.m_SimulateKspaceAcquisition = true;
         parameters.m_ArtifactModelString += "_ALIASING";
         parameters.m_CroppingFactor = (100-m_Controls->m_WrapBox->value())/100;
         parameters.m_ResultNode->AddProperty("Fiberfox.Aliasing", DoubleProperty::New(m_Controls->m_WrapBox->value()));
     }
 
     // Spikes
     if (m_Controls->m_AddSpikes->isChecked())
     {
         parameters.m_SimulateKspaceAcquisition = true;
         parameters.m_Spikes = m_Controls->m_SpikeNumBox->value();
         parameters.m_SpikeAmplitude = m_Controls->m_SpikeScaleBox->value();
         parameters.m_ArtifactModelString += "_SPIKES";
         parameters.m_ResultNode->AddProperty("Fiberfox.Spikes.Number", IntProperty::New(parameters.m_Spikes));
         parameters.m_ResultNode->AddProperty("Fiberfox.Spikes.Amplitude", DoubleProperty::New(parameters.m_SpikeAmplitude));
     }
 
     // gibbs ringing
     parameters.m_DoAddGibbsRinging = m_Controls->m_AddGibbsRinging->isChecked();
     if (m_Controls->m_AddGibbsRinging->isChecked())
     {
         parameters.m_SimulateKspaceAcquisition = true;
         parameters.m_ResultNode->AddProperty("Fiberfox.Ringing", BoolProperty::New(true));
         parameters.m_ArtifactModelString += "_RINGING";
     }
 
     // add distortions
     if (m_Controls->m_AddDistortions->isChecked() && m_Controls->m_FrequencyMapBox->GetSelectedNode().IsNotNull())
     {
         mitk::DataNode::Pointer fMapNode = m_Controls->m_FrequencyMapBox->GetSelectedNode();
         mitk::Image* img = dynamic_cast<mitk::Image*>(fMapNode->GetData());
         ItkDoubleImgType::Pointer itkImg = ItkDoubleImgType::New();
         CastToItkImage< ItkDoubleImgType >(img, itkImg);
 
         if (parameters.m_ImageRegion.GetSize(0)==itkImg->GetLargestPossibleRegion().GetSize(0) &&
                 parameters.m_ImageRegion.GetSize(1)==itkImg->GetLargestPossibleRegion().GetSize(1) &&
                 parameters.m_ImageRegion.GetSize(2)==itkImg->GetLargestPossibleRegion().GetSize(2))
         {
             parameters.m_SimulateKspaceAcquisition = true;
             itk::ImageDuplicator<ItkDoubleImgType>::Pointer duplicator = itk::ImageDuplicator<ItkDoubleImgType>::New();
             duplicator->SetInputImage(itkImg);
             duplicator->Update();
             parameters.m_FrequencyMap = duplicator->GetOutput();
             parameters.m_ArtifactModelString += "_DISTORTED";
             parameters.m_ResultNode->AddProperty("Fiberfox.Distortions", BoolProperty::New(true));
         }
     }
 
     parameters.m_EddyStrength = 0;
     if (m_Controls->m_AddEddy->isChecked())
     {
         parameters.m_EddyStrength = m_Controls->m_EddyGradientStrength->value();
         parameters.m_ArtifactModelString += "_EDDY";
         parameters.m_ResultNode->AddProperty("Fiberfox.Eddy-strength", DoubleProperty::New(parameters.m_EddyStrength));
     }
 
     // Motion
     parameters.m_DoAddMotion = m_Controls->m_AddMotion->isChecked();
     parameters.m_DoRandomizeMotion = m_Controls->m_RandomMotion->isChecked();
     parameters.m_Translation[0] = m_Controls->m_MaxTranslationBoxX->value();
     parameters.m_Translation[1] = m_Controls->m_MaxTranslationBoxY->value();
     parameters.m_Translation[2] = m_Controls->m_MaxTranslationBoxZ->value();
     parameters.m_Rotation[0] = m_Controls->m_MaxRotationBoxX->value();
     parameters.m_Rotation[1] = m_Controls->m_MaxRotationBoxY->value();
     parameters.m_Rotation[2] = m_Controls->m_MaxRotationBoxZ->value();
     if ( m_Controls->m_AddMotion->isChecked() && m_SelectedBundles.size()>0 )
     {
         parameters.m_ArtifactModelString += "_MOTION";
         parameters.m_ResultNode->AddProperty("Fiberfox.Motion.Random", BoolProperty::New(parameters.m_DoRandomizeMotion));
         parameters.m_ResultNode->AddProperty("Fiberfox.Motion.Translation-x", DoubleProperty::New(parameters.m_Translation[0]));
         parameters.m_ResultNode->AddProperty("Fiberfox.Motion.Translation-y", DoubleProperty::New(parameters.m_Translation[1]));
         parameters.m_ResultNode->AddProperty("Fiberfox.Motion.Translation-z", DoubleProperty::New(parameters.m_Translation[2]));
         parameters.m_ResultNode->AddProperty("Fiberfox.Motion.Rotation-x", DoubleProperty::New(parameters.m_Rotation[0]));
         parameters.m_ResultNode->AddProperty("Fiberfox.Motion.Rotation-y", DoubleProperty::New(parameters.m_Rotation[1]));
         parameters.m_ResultNode->AddProperty("Fiberfox.Motion.Rotation-z", DoubleProperty::New(parameters.m_Rotation[2]));
     }
 
     // other imaging parameters
     parameters.m_tLine = m_Controls->m_LineReadoutTimeBox->value();
     parameters.m_tInhom = m_Controls->m_T2starBox->value();
     parameters.m_tEcho = m_Controls->m_TEbox->value();
     parameters.m_DoDisablePartialVolume = m_Controls->m_EnforcePureFiberVoxelsBox->isChecked();
     parameters.m_AxonRadius = m_Controls->m_FiberRadius->value();
     parameters.m_SignalScale = m_Controls->m_SignalScaleBox->value();
 
     // adjust echo time if needed
     if ( parameters.m_tEcho < parameters.m_ImageRegion.GetSize(1)*parameters.m_tLine )
     {
         this->m_Controls->m_TEbox->setValue( parameters.m_ImageRegion.GetSize(1)*parameters.m_tLine );
         parameters.m_tEcho = m_Controls->m_TEbox->value();
         QMessageBox::information( NULL, "Warning", "Echo time is too short! Time not sufficient to read slice. Automaticall adjusted to "+QString::number(parameters.m_tEcho)+" ms");
     }
 
     // Noise
     if (m_Controls->m_AddNoise->isChecked())
     {
         double noiseVariance = m_Controls->m_NoiseLevel->value();
         {
             switch (m_Controls->m_NoiseDistributionBox->currentIndex())
             {
             case 0:
             {
                 parameters.m_NoiseModel = new mitk::RicianNoiseModel<ScalarType>();
                 parameters.m_ArtifactModelString += "_RICIAN-";
                 parameters.m_ResultNode->AddProperty("Fiberfox.Noise-Distribution", StringProperty::New("Rician"));
                 break;
             }
             case 1:
             {
                 parameters.m_NoiseModel = new mitk::ChiSquareNoiseModel<ScalarType>();
                 parameters.m_ArtifactModelString += "_CHISQUARED-";
                 parameters.m_ResultNode->AddProperty("Fiberfox.Noise-Distribution", StringProperty::New("Chi-squared"));
                 break;
             }
             default:
             {
                 parameters.m_NoiseModel = new mitk::RicianNoiseModel<ScalarType>();
                 parameters.m_ArtifactModelString += "_RICIAN-";
                 parameters.m_ResultNode->AddProperty("Fiberfox.Noise-Distribution", StringProperty::New("Rician"));
             }
             }
         }
         parameters.m_NoiseModel->SetNoiseVariance(noiseVariance);
         parameters.m_ArtifactModelString += QString::number(noiseVariance).toStdString();
         parameters.m_ResultNode->AddProperty("Fiberfox.Noise-Variance", DoubleProperty::New(noiseVariance));
     }
 
     // adjusting line readout time to the adapted image size needed for the DFT
     unsigned int y = parameters.m_ImageRegion.GetSize(1);
     y += y%2;
     if ( y>parameters.m_ImageRegion.GetSize(1) )
         parameters.m_tLine *= (double)parameters.m_ImageRegion.GetSize(1)/y;
 
     // signal models
     m_PrototypeModel1.Clear();
     m_PrototypeModel3.Clear();
     m_PrototypeModel4.Clear();
 
     // compartment 1
     switch (m_Controls->m_Compartment1Box->currentIndex())
     {
     case 0:
         m_StickModel1.SetGradientList(parameters.GetGradientDirections());
         m_StickModel1.SetBvalue(parameters.m_Bvalue);
         m_StickModel1.SetDiffusivity(m_Controls->m_StickWidget1->GetD());
         m_StickModel1.SetT2(m_Controls->m_StickWidget1->GetT2());
         parameters.m_FiberModelList.push_back(&m_StickModel1);
         parameters.m_SignalModelString += "Stick";
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment1.Description", StringProperty::New("Intra-axonal compartment") );
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment1.Model", StringProperty::New("Stick") );
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment1.D", DoubleProperty::New(m_Controls->m_StickWidget1->GetD()) );
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment1.T2", DoubleProperty::New(m_StickModel1.GetT2()) );
         break;
     case 1:
         m_ZeppelinModel1.SetGradientList(parameters.GetGradientDirections());
         m_ZeppelinModel1.SetBvalue(parameters.m_Bvalue);
         m_ZeppelinModel1.SetDiffusivity1(m_Controls->m_ZeppelinWidget1->GetD1());
         m_ZeppelinModel1.SetDiffusivity2(m_Controls->m_ZeppelinWidget1->GetD2());
         m_ZeppelinModel1.SetDiffusivity3(m_Controls->m_ZeppelinWidget1->GetD2());
         m_ZeppelinModel1.SetT2(m_Controls->m_ZeppelinWidget1->GetT2());
         parameters.m_FiberModelList.push_back(&m_ZeppelinModel1);
         parameters.m_SignalModelString += "Zeppelin";
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment1.Description", StringProperty::New("Intra-axonal compartment") );
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment1.Model", StringProperty::New("Zeppelin") );
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment1.D1", DoubleProperty::New(m_Controls->m_ZeppelinWidget1->GetD1()) );
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment1.D2", DoubleProperty::New(m_Controls->m_ZeppelinWidget1->GetD2()) );
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment1.T2", DoubleProperty::New(m_ZeppelinModel1.GetT2()) );
         break;
     case 2:
         m_TensorModel1.SetGradientList(parameters.GetGradientDirections());
         m_TensorModel1.SetBvalue(parameters.m_Bvalue);
         m_TensorModel1.SetDiffusivity1(m_Controls->m_TensorWidget1->GetD1());
         m_TensorModel1.SetDiffusivity2(m_Controls->m_TensorWidget1->GetD2());
         m_TensorModel1.SetDiffusivity3(m_Controls->m_TensorWidget1->GetD3());
         m_TensorModel1.SetT2(m_Controls->m_TensorWidget1->GetT2());
         parameters.m_FiberModelList.push_back(&m_TensorModel1);
         parameters.m_SignalModelString += "Tensor";
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment1.Description", StringProperty::New("Intra-axonal compartment") );
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment1.Model", StringProperty::New("Tensor") );
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment1.D1", DoubleProperty::New(m_Controls->m_TensorWidget1->GetD1()) );
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment1.D2", DoubleProperty::New(m_Controls->m_TensorWidget1->GetD2()) );
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment1.D3", DoubleProperty::New(m_Controls->m_TensorWidget1->GetD3()) );
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment1.T2", DoubleProperty::New(m_ZeppelinModel1.GetT2()) );
         break;
     case 3:
         parameters.m_SimulateKspaceAcquisition = false;
         m_PrototypeModel1.SetGradientList(parameters.GetGradientDirections());
         m_PrototypeModel1.SetMaxNumKernels(m_Controls->m_PrototypeWidget1->GetNumberOfSamples());
         m_PrototypeModel1.SetFaRange(m_Controls->m_PrototypeWidget1->GetMinFa(), m_Controls->m_PrototypeWidget1->GetMaxFa());
         m_PrototypeModel1.SetAdcRange(m_Controls->m_PrototypeWidget1->GetMinAdc(), m_Controls->m_PrototypeWidget1->GetMaxAdc());
         parameters.m_FiberModelList.push_back(&m_PrototypeModel1);
         parameters.m_SignalModelString += "Prototype";
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment1.Description", StringProperty::New("Intra-axonal compartment") );
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment1.Model", StringProperty::New("Prototype") );
         break;
     }
 
     // compartment 2
     switch (m_Controls->m_Compartment2Box->currentIndex())
     {
     case 0:
         break;
     case 1:
         m_StickModel2.SetGradientList(parameters.GetGradientDirections());
         m_StickModel2.SetBvalue(parameters.m_Bvalue);
         m_StickModel2.SetDiffusivity(m_Controls->m_StickWidget2->GetD());
         m_StickModel2.SetT2(m_Controls->m_StickWidget2->GetT2());
         parameters.m_FiberModelList.push_back(&m_StickModel2);
         parameters.m_SignalModelString += "Stick";
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment2.Description", StringProperty::New("Inter-axonal compartment") );
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment2.Model", StringProperty::New("Stick") );
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment2.D", DoubleProperty::New(m_Controls->m_StickWidget2->GetD()) );
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment2.T2", DoubleProperty::New(m_StickModel2.GetT2()) );
         break;
     case 2:
         m_ZeppelinModel2.SetGradientList(parameters.GetGradientDirections());
         m_ZeppelinModel2.SetBvalue(parameters.m_Bvalue);
         m_ZeppelinModel2.SetDiffusivity1(m_Controls->m_ZeppelinWidget2->GetD1());
         m_ZeppelinModel2.SetDiffusivity2(m_Controls->m_ZeppelinWidget2->GetD2());
         m_ZeppelinModel2.SetDiffusivity3(m_Controls->m_ZeppelinWidget2->GetD2());
         m_ZeppelinModel2.SetT2(m_Controls->m_ZeppelinWidget2->GetT2());
         parameters.m_FiberModelList.push_back(&m_ZeppelinModel2);
         parameters.m_SignalModelString += "Zeppelin";
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment2.Description", StringProperty::New("Inter-axonal compartment") );
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment2.Model", StringProperty::New("Zeppelin") );
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment2.D1", DoubleProperty::New(m_Controls->m_ZeppelinWidget2->GetD1()) );
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment2.D2", DoubleProperty::New(m_Controls->m_ZeppelinWidget2->GetD2()) );
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment2.T2", DoubleProperty::New(m_ZeppelinModel2.GetT2()) );
         break;
     case 3:
         m_TensorModel2.SetGradientList(parameters.GetGradientDirections());
         m_TensorModel2.SetBvalue(parameters.m_Bvalue);
         m_TensorModel2.SetDiffusivity1(m_Controls->m_TensorWidget2->GetD1());
         m_TensorModel2.SetDiffusivity2(m_Controls->m_TensorWidget2->GetD2());
         m_TensorModel2.SetDiffusivity3(m_Controls->m_TensorWidget2->GetD3());
         m_TensorModel2.SetT2(m_Controls->m_TensorWidget2->GetT2());
         parameters.m_FiberModelList.push_back(&m_TensorModel2);
         parameters.m_SignalModelString += "Tensor";
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment2.Description", StringProperty::New("Inter-axonal compartment") );
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment2.Model", StringProperty::New("Tensor") );
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment2.D1", DoubleProperty::New(m_Controls->m_TensorWidget2->GetD1()) );
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment2.D2", DoubleProperty::New(m_Controls->m_TensorWidget2->GetD2()) );
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment2.D3", DoubleProperty::New(m_Controls->m_TensorWidget2->GetD3()) );
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment2.T2", DoubleProperty::New(m_ZeppelinModel2.GetT2()) );
         break;
     }
 
     // compartment 3
     switch (m_Controls->m_Compartment3Box->currentIndex())
     {
     case 0:
         m_BallModel1.SetGradientList(parameters.GetGradientDirections());
         m_BallModel1.SetBvalue(parameters.m_Bvalue);
         m_BallModel1.SetDiffusivity(m_Controls->m_BallWidget1->GetD());
         m_BallModel1.SetT2(m_Controls->m_BallWidget1->GetT2());
         parameters.m_NonFiberModelList.push_back(&m_BallModel1);
         parameters.m_SignalModelString += "Ball";
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment3.Description", StringProperty::New("Extra-axonal compartment 1") );
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment3.Model", StringProperty::New("Ball") );
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment3.D", DoubleProperty::New(m_Controls->m_BallWidget1->GetD()) );
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment3.T2", DoubleProperty::New(m_BallModel1.GetT2()) );
         break;
     case 1:
         m_AstrosticksModel1.SetGradientList(parameters.GetGradientDirections());
         m_AstrosticksModel1.SetBvalue(parameters.m_Bvalue);
         m_AstrosticksModel1.SetDiffusivity(m_Controls->m_AstrosticksWidget1->GetD());
         m_AstrosticksModel1.SetT2(m_Controls->m_AstrosticksWidget1->GetT2());
         m_AstrosticksModel1.SetRandomizeSticks(m_Controls->m_AstrosticksWidget1->GetRandomizeSticks());
         parameters.m_NonFiberModelList.push_back(&m_AstrosticksModel1);
         parameters.m_SignalModelString += "Astrosticks";
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment3.Description", StringProperty::New("Extra-axonal compartment 1") );
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment3.Model", StringProperty::New("Astrosticks") );
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment3.D", DoubleProperty::New(m_Controls->m_AstrosticksWidget1->GetD()) );
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment3.T2", DoubleProperty::New(m_AstrosticksModel1.GetT2()) );
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment3.RandomSticks", BoolProperty::New(m_Controls->m_AstrosticksWidget1->GetRandomizeSticks()) );
         break;
     case 2:
         m_DotModel1.SetGradientList(parameters.GetGradientDirections());
         m_DotModel1.SetT2(m_Controls->m_DotWidget1->GetT2());
         parameters.m_NonFiberModelList.push_back(&m_DotModel1);
         parameters.m_SignalModelString += "Dot";
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment3.Description", StringProperty::New("Extra-axonal compartment 1") );
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment3.Model", StringProperty::New("Dot") );
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment3.T2", DoubleProperty::New(m_DotModel1.GetT2()) );
         break;
     case 3:
         parameters.m_SimulateKspaceAcquisition = false;
         m_PrototypeModel3.SetGradientList(parameters.GetGradientDirections());
         m_PrototypeModel3.SetMaxNumKernels(m_Controls->m_PrototypeWidget3->GetNumberOfSamples());
         m_PrototypeModel3.SetFaRange(m_Controls->m_PrototypeWidget3->GetMinFa(), m_Controls->m_PrototypeWidget3->GetMaxFa());
         m_PrototypeModel3.SetAdcRange(m_Controls->m_PrototypeWidget3->GetMinAdc(), m_Controls->m_PrototypeWidget3->GetMaxAdc());
         parameters.m_NonFiberModelList.push_back(&m_PrototypeModel3);
         parameters.m_SignalModelString += "Prototype";
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment3.Description", StringProperty::New("Extra-axonal compartment 1") );
         parameters.m_ResultNode->AddProperty("Fiberfox.Compartment3.Model", StringProperty::New("Prototype") );
         break;
     }
 
     // compartment 4
     ItkDoubleImgType::Pointer comp4VolumeImage = NULL;
     ItkDoubleImgType::Pointer comp3VolumeImage = NULL;
     if (m_Controls->m_Compartment4Box->currentIndex()>0)
     {
         mitk::DataNode::Pointer volumeNode = m_Controls->m_Comp4VolumeFraction->GetSelectedNode();
         if (volumeNode.IsNull())
         {
             MITK_WARN << "No volume fraction image selected! Second extra-axonal compartment has been disabled.";
         }
         else
         {
             MITK_INFO << "Rescaling volume fraction image...";
             comp4VolumeImage = ItkDoubleImgType::New();
             mitk::Image* img = dynamic_cast<mitk::Image*>(volumeNode->GetData());
             CastToItkImage< ItkDoubleImgType >(img, comp4VolumeImage);
 
             double max = itk::NumericTraits<double>::min();
             double min = itk::NumericTraits<double>::max();
 
             itk::ImageRegionIterator< ItkDoubleImgType > it(comp4VolumeImage, comp4VolumeImage->GetLargestPossibleRegion());
             while(!it.IsAtEnd())
             {
                 if (parameters.m_MaskImage.IsNotNull() && parameters.m_MaskImage->GetPixel(it.GetIndex())<=0)
                 {
                     it.Set(0.0);
                     ++it;
                     continue;
                 }
 
                 if (it.Get()>max)
                     max = it.Get();
                 if (it.Get()<min)
                     min = it.Get();
                 ++it;
             }
             itk::ShiftScaleImageFilter< ItkDoubleImgType, ItkDoubleImgType >::Pointer scaler = itk::ShiftScaleImageFilter< ItkDoubleImgType, ItkDoubleImgType >::New();
             scaler->SetInput(comp4VolumeImage);
             scaler->SetShift(-min);
             scaler->SetScale(1/(max-min));
             scaler->Update();
             comp4VolumeImage = scaler->GetOutput();
 
             itk::ImageFileWriter< ItkDoubleImgType >::Pointer wr = itk::ImageFileWriter< ItkDoubleImgType >::New();
             wr->SetInput(comp4VolumeImage);
             wr->SetFileName("/local/comp4.nrrd");
             wr->Update();
 
 //            if (max>1 || min<0) // are volume fractions between 0 and 1?
 //            {
 //                itk::RescaleIntensityImageFilter<ItkDoubleImgType,ItkDoubleImgType>::Pointer rescaler = itk::RescaleIntensityImageFilter<ItkDoubleImgType,ItkDoubleImgType>::New();
 //                rescaler->SetInput(0, comp4VolumeImage);
 //                rescaler->SetOutputMaximum(1);
 //                rescaler->SetOutputMinimum(0);
 //                rescaler->Update();
 //                comp4VolumeImage = rescaler->GetOutput();
 //            }
 
             itk::InvertIntensityImageFilter< ItkDoubleImgType, ItkDoubleImgType >::Pointer inverter = itk::InvertIntensityImageFilter< ItkDoubleImgType, ItkDoubleImgType >::New();
             inverter->SetMaximum(1.0);
             inverter->SetInput(comp4VolumeImage);
             inverter->Update();
             comp3VolumeImage = inverter->GetOutput();
         }
     }
 
     if (comp4VolumeImage.IsNotNull())
         switch (m_Controls->m_Compartment4Box->currentIndex())
         {
         case 0:
             break;
         case 1:
         {
             m_BallModel2.SetGradientList(parameters.GetGradientDirections());
             m_BallModel2.SetBvalue(parameters.m_Bvalue);
             m_BallModel2.SetDiffusivity(m_Controls->m_BallWidget2->GetD());
             m_BallModel2.SetT2(m_Controls->m_BallWidget2->GetT2());
             m_BallModel2.SetVolumeFractionImage(comp4VolumeImage);
             parameters.m_NonFiberModelList.back()->SetVolumeFractionImage(comp3VolumeImage);
             parameters.m_NonFiberModelList.push_back(&m_BallModel2);
             parameters.m_SignalModelString += "Ball";
             parameters.m_ResultNode->AddProperty("Fiberfox.Compartment4.Description", StringProperty::New("Extra-axonal compartment 2") );
             parameters.m_ResultNode->AddProperty("Fiberfox.Compartment4.Model", StringProperty::New("Ball") );
             parameters.m_ResultNode->AddProperty("Fiberfox.Compartment4.D", DoubleProperty::New(m_Controls->m_BallWidget2->GetD()) );
             parameters.m_ResultNode->AddProperty("Fiberfox.Compartment4.T2", DoubleProperty::New(m_BallModel2.GetT2()) );
             break;
         }
         case 2:
         {
             m_AstrosticksModel2.SetGradientList(parameters.GetGradientDirections());
             m_AstrosticksModel2.SetBvalue(parameters.m_Bvalue);
             m_AstrosticksModel2.SetDiffusivity(m_Controls->m_AstrosticksWidget2->GetD());
             m_AstrosticksModel2.SetT2(m_Controls->m_AstrosticksWidget2->GetT2());
             m_AstrosticksModel2.SetRandomizeSticks(m_Controls->m_AstrosticksWidget2->GetRandomizeSticks());
             parameters.m_NonFiberModelList.back()->SetVolumeFractionImage(comp3VolumeImage);
             m_AstrosticksModel2.SetVolumeFractionImage(comp4VolumeImage);
             parameters.m_NonFiberModelList.push_back(&m_AstrosticksModel2);
             parameters.m_SignalModelString += "Astrosticks";
             parameters.m_ResultNode->AddProperty("Fiberfox.Compartment4.Description", StringProperty::New("Extra-axonal compartment 2") );
             parameters.m_ResultNode->AddProperty("Fiberfox.Compartment4.Model", StringProperty::New("Astrosticks") );
             parameters.m_ResultNode->AddProperty("Fiberfox.Compartment4.D", DoubleProperty::New(m_Controls->m_AstrosticksWidget2->GetD()) );
             parameters.m_ResultNode->AddProperty("Fiberfox.Compartment4.T2", DoubleProperty::New(m_AstrosticksModel2.GetT2()) );
             parameters.m_ResultNode->AddProperty("Fiberfox.Compartment4.RandomSticks", BoolProperty::New(m_Controls->m_AstrosticksWidget2->GetRandomizeSticks()) );
             break;
         }
         case 3:
         {
             m_DotModel2.SetGradientList(parameters.GetGradientDirections());
             m_DotModel2.SetT2(m_Controls->m_DotWidget2->GetT2());
             m_DotModel2.SetVolumeFractionImage(comp4VolumeImage);
             parameters.m_NonFiberModelList.back()->SetVolumeFractionImage(comp3VolumeImage);
             parameters.m_NonFiberModelList.push_back(&m_DotModel2);
             parameters.m_SignalModelString += "Dot";
             parameters.m_ResultNode->AddProperty("Fiberfox.Compartment4.Description", StringProperty::New("Extra-axonal compartment 2") );
             parameters.m_ResultNode->AddProperty("Fiberfox.Compartment4.Model", StringProperty::New("Dot") );
             parameters.m_ResultNode->AddProperty("Fiberfox.Compartment4.T2", DoubleProperty::New(m_DotModel2.GetT2()) );
             break;
         }
         case 4:
         {
             parameters.m_SimulateKspaceAcquisition = false;
             m_PrototypeModel4.SetGradientList(parameters.GetGradientDirections());
             m_PrototypeModel4.SetMaxNumKernels(m_Controls->m_PrototypeWidget4->GetNumberOfSamples());
             m_PrototypeModel4.SetFaRange(m_Controls->m_PrototypeWidget4->GetMinFa(), m_Controls->m_PrototypeWidget4->GetMaxFa());
             m_PrototypeModel4.SetAdcRange(m_Controls->m_PrototypeWidget4->GetMinAdc(), m_Controls->m_PrototypeWidget4->GetMaxAdc());
             m_PrototypeModel4.SetVolumeFractionImage(comp4VolumeImage);
             parameters.m_NonFiberModelList.back()->SetVolumeFractionImage(comp3VolumeImage);
             parameters.m_NonFiberModelList.push_back(&m_PrototypeModel4);
             parameters.m_SignalModelString += "Prototype";
             parameters.m_ResultNode->AddProperty("Fiberfox.Compartment4.Description", StringProperty::New("Extra-axonal compartment 2") );
             parameters.m_ResultNode->AddProperty("Fiberfox.Compartment4.Model", StringProperty::New("Prototype") );
             break;
         }
         }
 
     parameters.m_DiffusionDirectionMode = FiberfoxParameters<ScalarType>::FIBER_TANGENT_DIRECTIONS;
 
     parameters.m_ResultNode->AddProperty("Fiberfox.SignalScale", IntProperty::New(parameters.m_SignalScale));
     parameters.m_ResultNode->AddProperty("Fiberfox.FiberRadius", IntProperty::New(parameters.m_AxonRadius));
     parameters.m_ResultNode->AddProperty("Fiberfox.Tinhom", DoubleProperty::New(parameters.m_tInhom));
     parameters.m_ResultNode->AddProperty("Fiberfox.Tline", DoubleProperty::New(parameters.m_tLine));
     parameters.m_ResultNode->AddProperty("Fiberfox.TE", DoubleProperty::New(parameters.m_tEcho));
     parameters.m_ResultNode->AddProperty("Fiberfox.b-value", DoubleProperty::New(parameters.m_Bvalue));
     parameters.m_ResultNode->AddProperty("Fiberfox.NoPartialVolume", BoolProperty::New(parameters.m_DoDisablePartialVolume));
     parameters.m_ResultNode->AddProperty("Fiberfox.Relaxation", BoolProperty::New(parameters.m_DoSimulateRelaxation));
     parameters.m_ResultNode->AddProperty("binary", BoolProperty::New(false));
 
     return parameters;
 }
 
 void QmitkFiberfoxView::SaveParameters()
 {
     FiberfoxParameters<double> ffParamaters = UpdateImageParameters<double>();
 
     QString filename = QFileDialog::getSaveFileName(
                 0,
                 tr("Save Parameters"),
                 m_ParameterFile,
                 tr("Fiberfox Parameters (*.ffp)") );
 
     if(filename.isEmpty() || filename.isNull())
         return;
     if(!filename.endsWith(".ffp"))
         filename += ".ffp";
 
     m_ParameterFile = filename;
 
     boost::property_tree::ptree parameters;
 
     // fiber generation parameters
     parameters.put("fiberfox.fibers.realtime", m_Controls->m_RealTimeFibers->isChecked());
     parameters.put("fiberfox.fibers.showadvanced", m_Controls->m_AdvancedOptionsBox->isChecked());
     parameters.put("fiberfox.fibers.distribution", m_Controls->m_DistributionBox->currentIndex());
     parameters.put("fiberfox.fibers.variance", m_Controls->m_VarianceBox->value());
     parameters.put("fiberfox.fibers.density", m_Controls->m_FiberDensityBox->value());
     parameters.put("fiberfox.fibers.spline.sampling", m_Controls->m_FiberSamplingBox->value());
     parameters.put("fiberfox.fibers.spline.tension", m_Controls->m_TensionBox->value());
     parameters.put("fiberfox.fibers.spline.continuity", m_Controls->m_ContinuityBox->value());
     parameters.put("fiberfox.fibers.spline.bias", m_Controls->m_BiasBox->value());
     parameters.put("fiberfox.fibers.constantradius", m_Controls->m_ConstantRadiusBox->isChecked());
     parameters.put("fiberfox.fibers.rotation.x", m_Controls->m_XrotBox->value());
     parameters.put("fiberfox.fibers.rotation.y", m_Controls->m_YrotBox->value());
     parameters.put("fiberfox.fibers.rotation.z", m_Controls->m_ZrotBox->value());
     parameters.put("fiberfox.fibers.translation.x", m_Controls->m_XtransBox->value());
     parameters.put("fiberfox.fibers.translation.y", m_Controls->m_YtransBox->value());
     parameters.put("fiberfox.fibers.translation.z", m_Controls->m_ZtransBox->value());
     parameters.put("fiberfox.fibers.scale.x", m_Controls->m_XscaleBox->value());
     parameters.put("fiberfox.fibers.scale.y", m_Controls->m_YscaleBox->value());
     parameters.put("fiberfox.fibers.scale.z", m_Controls->m_ZscaleBox->value());
     parameters.put("fiberfox.fibers.includeFiducials", m_Controls->m_IncludeFiducials->isChecked());
     parameters.put("fiberfox.fibers.includeFiducials", m_Controls->m_IncludeFiducials->isChecked());
 
     // image generation parameters
     parameters.put("fiberfox.image.basic.size.x", ffParamaters.m_ImageRegion.GetSize(0));
     parameters.put("fiberfox.image.basic.size.y", ffParamaters.m_ImageRegion.GetSize(1));
     parameters.put("fiberfox.image.basic.size.z", ffParamaters.m_ImageRegion.GetSize(2));
     parameters.put("fiberfox.image.basic.spacing.x", ffParamaters.m_ImageSpacing[0]);
     parameters.put("fiberfox.image.basic.spacing.y", ffParamaters.m_ImageSpacing[1]);
     parameters.put("fiberfox.image.basic.spacing.z", ffParamaters.m_ImageSpacing[2]);
     parameters.put("fiberfox.image.basic.numgradients", ffParamaters.GetNumWeightedVolumes());
     parameters.put("fiberfox.image.basic.bvalue", ffParamaters.m_Bvalue);
     parameters.put("fiberfox.image.showadvanced", m_Controls->m_AdvancedOptionsBox_2->isChecked());
     parameters.put("fiberfox.image.signalScale", ffParamaters.m_SignalScale);
     parameters.put("fiberfox.image.tEcho", ffParamaters.m_tEcho);
     parameters.put("fiberfox.image.tLine", m_Controls->m_LineReadoutTimeBox->value());
     parameters.put("fiberfox.image.tInhom", ffParamaters.m_tInhom);
     parameters.put("fiberfox.image.axonRadius", ffParamaters.m_AxonRadius);
     parameters.put("fiberfox.image.doSimulateRelaxation", ffParamaters.m_DoSimulateRelaxation);
     parameters.put("fiberfox.image.doDisablePartialVolume", ffParamaters.m_DoDisablePartialVolume);
     parameters.put("fiberfox.image.outputvolumefractions", m_Controls->m_VolumeFractionsBox->isChecked());
 
     parameters.put("fiberfox.image.artifacts.addnoise", m_Controls->m_AddNoise->isChecked());
     parameters.put("fiberfox.image.artifacts.noisedistribution", m_Controls->m_NoiseDistributionBox->currentIndex());
     parameters.put("fiberfox.image.artifacts.noisevariance", m_Controls->m_NoiseLevel->value());
     parameters.put("fiberfox.image.artifacts.addghost", m_Controls->m_AddGhosts->isChecked());
     parameters.put("fiberfox.image.artifacts.kspaceLineOffset", m_Controls->m_kOffsetBox->value());
     parameters.put("fiberfox.image.artifacts.distortions", m_Controls->m_AddDistortions->isChecked());
     parameters.put("fiberfox.image.artifacts.addeddy", m_Controls->m_AddEddy->isChecked());
     parameters.put("fiberfox.image.artifacts.eddyStrength", m_Controls->m_EddyGradientStrength->value());
     parameters.put("fiberfox.image.artifacts.addringing", m_Controls->m_AddGibbsRinging->isChecked());
     parameters.put("fiberfox.image.artifacts.addspikes", m_Controls->m_AddSpikes->isChecked());
     parameters.put("fiberfox.image.artifacts.spikesnum", m_Controls->m_SpikeNumBox->value());
     parameters.put("fiberfox.image.artifacts.spikesscale", m_Controls->m_SpikeScaleBox->value());
     parameters.put("fiberfox.image.artifacts.addaliasing", m_Controls->m_AddAliasing->isChecked());
     parameters.put("fiberfox.image.artifacts.aliasingfactor", m_Controls->m_WrapBox->value());
     parameters.put("fiberfox.image.artifacts.doAddMotion", m_Controls->m_AddMotion->isChecked());
     parameters.put("fiberfox.image.artifacts.randomMotion", m_Controls->m_RandomMotion->isChecked());
     parameters.put("fiberfox.image.artifacts.translation0", m_Controls->m_MaxTranslationBoxX->value());
     parameters.put("fiberfox.image.artifacts.translation1", m_Controls->m_MaxTranslationBoxY->value());
     parameters.put("fiberfox.image.artifacts.translation2", m_Controls->m_MaxTranslationBoxZ->value());
     parameters.put("fiberfox.image.artifacts.rotation0", m_Controls->m_MaxRotationBoxX->value());
     parameters.put("fiberfox.image.artifacts.rotation1", m_Controls->m_MaxRotationBoxY->value());
     parameters.put("fiberfox.image.artifacts.rotation2", m_Controls->m_MaxRotationBoxZ->value());
 
     parameters.put("fiberfox.image.compartment1.index", m_Controls->m_Compartment1Box->currentIndex());
     parameters.put("fiberfox.image.compartment2.index", m_Controls->m_Compartment2Box->currentIndex());
     parameters.put("fiberfox.image.compartment3.index", m_Controls->m_Compartment3Box->currentIndex());
     parameters.put("fiberfox.image.compartment4.index", m_Controls->m_Compartment4Box->currentIndex());
 
     parameters.put("fiberfox.image.compartment1.stick.d", m_Controls->m_StickWidget1->GetD());
     parameters.put("fiberfox.image.compartment1.stick.t2", m_Controls->m_StickWidget1->GetT2());
     parameters.put("fiberfox.image.compartment1.zeppelin.d1", m_Controls->m_ZeppelinWidget1->GetD1());
     parameters.put("fiberfox.image.compartment1.zeppelin.d2", m_Controls->m_ZeppelinWidget1->GetD2());
     parameters.put("fiberfox.image.compartment1.zeppelin.t2", m_Controls->m_ZeppelinWidget1->GetT2());
     parameters.put("fiberfox.image.compartment1.tensor.d1", m_Controls->m_TensorWidget1->GetD1());
     parameters.put("fiberfox.image.compartment1.tensor.d2", m_Controls->m_TensorWidget1->GetD2());
     parameters.put("fiberfox.image.compartment1.tensor.d3", m_Controls->m_TensorWidget1->GetD3());
     parameters.put("fiberfox.image.compartment1.tensor.t2", m_Controls->m_TensorWidget1->GetT2());
     parameters.put("fiberfox.image.compartment1.prototype.minFA", m_Controls->m_PrototypeWidget1->GetMinFa());
     parameters.put("fiberfox.image.compartment1.prototype.maxFA", m_Controls->m_PrototypeWidget1->GetMaxFa());
     parameters.put("fiberfox.image.compartment1.prototype.minADC", m_Controls->m_PrototypeWidget1->GetMinAdc());
     parameters.put("fiberfox.image.compartment1.prototype.maxADC", m_Controls->m_PrototypeWidget1->GetMaxAdc());
     parameters.put("fiberfox.image.compartment1.prototype.numSamples", m_Controls->m_PrototypeWidget1->GetNumberOfSamples());
 
     parameters.put("fiberfox.image.compartment2.stick.d", m_Controls->m_StickWidget2->GetD());
     parameters.put("fiberfox.image.compartment2.stick.t2", m_Controls->m_StickWidget2->GetT2());
     parameters.put("fiberfox.image.compartment2.zeppelin.d1", m_Controls->m_ZeppelinWidget2->GetD1());
     parameters.put("fiberfox.image.compartment2.zeppelin.d2", m_Controls->m_ZeppelinWidget2->GetD2());
     parameters.put("fiberfox.image.compartment2.zeppelin.t2", m_Controls->m_ZeppelinWidget2->GetT2());
     parameters.put("fiberfox.image.compartment2.tensor.d1", m_Controls->m_TensorWidget2->GetD1());
     parameters.put("fiberfox.image.compartment2.tensor.d2", m_Controls->m_TensorWidget2->GetD2());
     parameters.put("fiberfox.image.compartment2.tensor.d3", m_Controls->m_TensorWidget2->GetD3());
     parameters.put("fiberfox.image.compartment2.tensor.t2", m_Controls->m_TensorWidget2->GetT2());
 
     parameters.put("fiberfox.image.compartment3.ball.d", m_Controls->m_BallWidget1->GetD());
     parameters.put("fiberfox.image.compartment3.ball.t2", m_Controls->m_BallWidget1->GetT2());
     parameters.put("fiberfox.image.compartment3.astrosticks.d", m_Controls->m_AstrosticksWidget1->GetD());
     parameters.put("fiberfox.image.compartment3.astrosticks.t2", m_Controls->m_AstrosticksWidget1->GetT2());
     parameters.put("fiberfox.image.compartment3.astrosticks.randomize", m_Controls->m_AstrosticksWidget1->GetRandomizeSticks());
     parameters.put("fiberfox.image.compartment3.dot.t2", m_Controls->m_DotWidget1->GetT2());
     parameters.put("fiberfox.image.compartment3.prototype.minFA", m_Controls->m_PrototypeWidget3->GetMinFa());
     parameters.put("fiberfox.image.compartment3.prototype.maxFA", m_Controls->m_PrototypeWidget3->GetMaxFa());
     parameters.put("fiberfox.image.compartment3.prototype.minADC", m_Controls->m_PrototypeWidget3->GetMinAdc());
     parameters.put("fiberfox.image.compartment3.prototype.maxADC", m_Controls->m_PrototypeWidget3->GetMaxAdc());
     parameters.put("fiberfox.image.compartment3.prototype.numSamples", m_Controls->m_PrototypeWidget3->GetNumberOfSamples());
 
     parameters.put("fiberfox.image.compartment4.ball.d", m_Controls->m_BallWidget2->GetD());
     parameters.put("fiberfox.image.compartment4.ball.t2", m_Controls->m_BallWidget2->GetT2());
     parameters.put("fiberfox.image.compartment4.astrosticks.d", m_Controls->m_AstrosticksWidget2->GetD());
     parameters.put("fiberfox.image.compartment4.astrosticks.t2", m_Controls->m_AstrosticksWidget2->GetT2());
     parameters.put("fiberfox.image.compartment4.astrosticks.randomize", m_Controls->m_AstrosticksWidget2->GetRandomizeSticks());
     parameters.put("fiberfox.image.compartment4.dot.t2", m_Controls->m_DotWidget2->GetT2());
     parameters.put("fiberfox.image.compartment4.prototype.minFA", m_Controls->m_PrototypeWidget4->GetMinFa());
     parameters.put("fiberfox.image.compartment4.prototype.maxFA", m_Controls->m_PrototypeWidget4->GetMaxFa());
     parameters.put("fiberfox.image.compartment4.prototype.minADC", m_Controls->m_PrototypeWidget4->GetMinAdc());
     parameters.put("fiberfox.image.compartment4.prototype.maxADC", m_Controls->m_PrototypeWidget4->GetMaxAdc());
     parameters.put("fiberfox.image.compartment4.prototype.numSamples", m_Controls->m_PrototypeWidget4->GetNumberOfSamples());
 
     boost::property_tree::xml_parser::write_xml(filename.toStdString(), parameters);
 }
 
 void QmitkFiberfoxView::LoadParameters()
 {
     QString filename = QFileDialog::getOpenFileName(0, tr("Load Parameters"), QString(itksys::SystemTools::GetFilenamePath(m_ParameterFile.toStdString()).c_str()), tr("Fiberfox Parameters (*.ffp)") );
     if(filename.isEmpty() || filename.isNull())
         return;
 
     m_ParameterFile = filename;
 
     boost::property_tree::ptree parameters;
     boost::property_tree::xml_parser::read_xml(filename.toStdString(), parameters);
 
     BOOST_FOREACH( boost::property_tree::ptree::value_type const& v1, parameters.get_child("fiberfox") )
     {
         if( v1.first == "fibers" )
         {
             m_Controls->m_RealTimeFibers->setChecked(v1.second.get<bool>("realtime"));
             m_Controls->m_AdvancedOptionsBox->setChecked(v1.second.get<bool>("showadvanced"));
             m_Controls->m_DistributionBox->setCurrentIndex(v1.second.get<int>("distribution"));
             m_Controls->m_VarianceBox->setValue(v1.second.get<double>("variance"));
             m_Controls->m_FiberDensityBox->setValue(v1.second.get<int>("density"));
             m_Controls->m_IncludeFiducials->setChecked(v1.second.get<bool>("includeFiducials"));
             m_Controls->m_ConstantRadiusBox->setChecked(v1.second.get<bool>("constantradius"));
 
             BOOST_FOREACH( boost::property_tree::ptree::value_type const& v2, v1.second )
             {
                 if( v2.first == "spline" )
                 {
                     m_Controls->m_FiberSamplingBox->setValue(v2.second.get<double>("sampling"));
                     m_Controls->m_TensionBox->setValue(v2.second.get<double>("tension"));
                     m_Controls->m_ContinuityBox->setValue(v2.second.get<double>("continuity"));
                     m_Controls->m_BiasBox->setValue(v2.second.get<double>("bias"));
                 }
                 if( v2.first == "rotation" )
                 {
                     m_Controls->m_XrotBox->setValue(v2.second.get<double>("x"));
                     m_Controls->m_YrotBox->setValue(v2.second.get<double>("y"));
                     m_Controls->m_ZrotBox->setValue(v2.second.get<double>("z"));
                 }
                 if( v2.first == "translation" )
                 {
                     m_Controls->m_XtransBox->setValue(v2.second.get<double>("x"));
                     m_Controls->m_YtransBox->setValue(v2.second.get<double>("y"));
                     m_Controls->m_ZtransBox->setValue(v2.second.get<double>("z"));
                 }
                 if( v2.first == "scale" )
                 {
                     m_Controls->m_XscaleBox->setValue(v2.second.get<double>("x"));
                     m_Controls->m_YscaleBox->setValue(v2.second.get<double>("y"));
                     m_Controls->m_ZscaleBox->setValue(v2.second.get<double>("z"));
                 }
             }
         }
         if( v1.first == "image" )
         {
             m_Controls->m_SizeX->setValue(v1.second.get<int>("basic.size.x"));
             m_Controls->m_SizeY->setValue(v1.second.get<int>("basic.size.y"));
             m_Controls->m_SizeZ->setValue(v1.second.get<int>("basic.size.z"));
             m_Controls->m_SpacingX->setValue(v1.second.get<double>("basic.spacing.x"));
             m_Controls->m_SpacingY->setValue(v1.second.get<double>("basic.spacing.y"));
             m_Controls->m_SpacingZ->setValue(v1.second.get<double>("basic.spacing.z"));
             m_Controls->m_NumGradientsBox->setValue(v1.second.get<int>("basic.numgradients"));
             m_Controls->m_BvalueBox->setValue(v1.second.get<int>("basic.bvalue"));
             m_Controls->m_AdvancedOptionsBox_2->setChecked(v1.second.get<bool>("showadvanced"));
             m_Controls->m_SignalScaleBox->setValue(v1.second.get<int>("signalScale"));
             m_Controls->m_TEbox->setValue(v1.second.get<double>("tEcho"));
             m_Controls->m_LineReadoutTimeBox->setValue(v1.second.get<double>("tLine"));
             m_Controls->m_T2starBox->setValue(v1.second.get<double>("tInhom"));
             m_Controls->m_FiberRadius->setValue(v1.second.get<double>("axonRadius"));
             m_Controls->m_RelaxationBox->setChecked(v1.second.get<bool>("doSimulateRelaxation"));
             m_Controls->m_EnforcePureFiberVoxelsBox->setChecked(v1.second.get<bool>("doDisablePartialVolume"));
             m_Controls->m_VolumeFractionsBox->setChecked(v1.second.get<bool>("outputvolumefractions"));
 
             m_Controls->m_AddNoise->setChecked(v1.second.get<bool>("artifacts.addnoise"));
             m_Controls->m_NoiseDistributionBox->setCurrentIndex(v1.second.get<int>("artifacts.noisedistribution"));
             m_Controls->m_NoiseLevel->setValue(v1.second.get<double>("artifacts.noisevariance"));
             m_Controls->m_AddGhosts->setChecked(v1.second.get<bool>("artifacts.addghost"));
             m_Controls->m_kOffsetBox->setValue(v1.second.get<double>("artifacts.kspaceLineOffset"));
             m_Controls->m_AddAliasing->setChecked(v1.second.get<bool>("artifacts.addaliasing"));
             m_Controls->m_WrapBox->setValue(v1.second.get<double>("artifacts.aliasingfactor"));
             m_Controls->m_AddDistortions->setChecked(v1.second.get<bool>("artifacts.distortions"));
             m_Controls->m_AddSpikes->setChecked(v1.second.get<bool>("artifacts.addspikes"));
             m_Controls->m_SpikeNumBox->setValue(v1.second.get<int>("artifacts.spikesnum"));
             m_Controls->m_SpikeScaleBox->setValue(v1.second.get<double>("artifacts.spikesscale"));
             m_Controls->m_AddEddy->setChecked(v1.second.get<bool>("artifacts.addeddy"));
             m_Controls->m_EddyGradientStrength->setValue(v1.second.get<double>("artifacts.eddyStrength"));
             m_Controls->m_AddGibbsRinging->setChecked(v1.second.get<bool>("artifacts.addringing"));
             m_Controls->m_AddMotion->setChecked(v1.second.get<bool>("artifacts.doAddMotion"));
             m_Controls->m_RandomMotion->setChecked(v1.second.get<bool>("artifacts.randomMotion"));
             m_Controls->m_MaxTranslationBoxX->setValue(v1.second.get<double>("artifacts.translation0"));
             m_Controls->m_MaxTranslationBoxY->setValue(v1.second.get<double>("artifacts.translation1"));
             m_Controls->m_MaxTranslationBoxZ->setValue(v1.second.get<double>("artifacts.translation2"));
             m_Controls->m_MaxRotationBoxX->setValue(v1.second.get<double>("artifacts.rotation0"));
             m_Controls->m_MaxRotationBoxY->setValue(v1.second.get<double>("artifacts.rotation1"));
             m_Controls->m_MaxRotationBoxZ->setValue(v1.second.get<double>("artifacts.rotation2"));
 
             m_Controls->m_Compartment1Box->setCurrentIndex(v1.second.get<int>("compartment1.index"));
             m_Controls->m_Compartment2Box->setCurrentIndex(v1.second.get<int>("compartment2.index"));
             m_Controls->m_Compartment3Box->setCurrentIndex(v1.second.get<int>("compartment3.index"));
             m_Controls->m_Compartment4Box->setCurrentIndex(v1.second.get<int>("compartment4.index"));
 
             m_Controls->m_StickWidget1->SetD(v1.second.get<double>("compartment1.stick.d"));
             m_Controls->m_StickWidget1->SetT2(v1.second.get<double>("compartment1.stick.t2"));
             m_Controls->m_ZeppelinWidget1->SetD1(v1.second.get<double>("compartment1.zeppelin.d1"));
             m_Controls->m_ZeppelinWidget1->SetD2(v1.second.get<double>("compartment1.zeppelin.d2"));
             m_Controls->m_ZeppelinWidget1->SetT2(v1.second.get<double>("compartment1.zeppelin.t2"));
             m_Controls->m_TensorWidget1->SetD1(v1.second.get<double>("compartment1.tensor.d1"));
             m_Controls->m_TensorWidget1->SetD2(v1.second.get<double>("compartment1.tensor.d2"));
             m_Controls->m_TensorWidget1->SetD3(v1.second.get<double>("compartment1.tensor.d3"));
             m_Controls->m_TensorWidget1->SetT2(v1.second.get<double>("compartment1.tensor.t2"));
             m_Controls->m_PrototypeWidget1->SetMinFa(v1.second.get<double>("compartment1.prototype.minFA"));
             m_Controls->m_PrototypeWidget1->SetMaxFa(v1.second.get<double>("compartment1.prototype.maxFA"));
             m_Controls->m_PrototypeWidget1->SetMinAdc(v1.second.get<double>("compartment1.prototype.minADC"));
             m_Controls->m_PrototypeWidget1->SetMaxAdc(v1.second.get<double>("compartment1.prototype.maxADC"));
             m_Controls->m_PrototypeWidget1->SetNumberOfSamples(v1.second.get<double>("compartment1.prototype.numSamples"));
 
             m_Controls->m_StickWidget2->SetD(v1.second.get<double>("compartment2.stick.d"));
             m_Controls->m_StickWidget2->SetT2(v1.second.get<double>("compartment2.stick.t2"));
             m_Controls->m_ZeppelinWidget2->SetD1(v1.second.get<double>("compartment2.zeppelin.d1"));
             m_Controls->m_ZeppelinWidget2->SetD2(v1.second.get<double>("compartment2.zeppelin.d2"));
             m_Controls->m_ZeppelinWidget2->SetT2(v1.second.get<double>("compartment2.zeppelin.t2"));
             m_Controls->m_TensorWidget2->SetD1(v1.second.get<double>("compartment2.tensor.d1"));
             m_Controls->m_TensorWidget2->SetD2(v1.second.get<double>("compartment2.tensor.d2"));
             m_Controls->m_TensorWidget2->SetD3(v1.second.get<double>("compartment2.tensor.d3"));
             m_Controls->m_TensorWidget2->SetT2(v1.second.get<double>("compartment2.tensor.t2"));
 
             m_Controls->m_BallWidget1->SetD(v1.second.get<double>("compartment3.ball.d"));
             m_Controls->m_BallWidget1->SetT2(v1.second.get<double>("compartment3.ball.t2"));
             m_Controls->m_AstrosticksWidget1->SetD(v1.second.get<double>("compartment3.astrosticks.d"));
             m_Controls->m_AstrosticksWidget1->SetT2(v1.second.get<double>("compartment3.astrosticks.t2"));
             m_Controls->m_AstrosticksWidget1->SetRandomizeSticks(v1.second.get<bool>("compartment3.astrosticks.randomize"));
             m_Controls->m_DotWidget1->SetT2(v1.second.get<double>("compartment3.dot.t2"));
             m_Controls->m_PrototypeWidget3->SetMinFa(v1.second.get<double>("compartment3.prototype.minFA"));
             m_Controls->m_PrototypeWidget3->SetMaxFa(v1.second.get<double>("compartment3.prototype.maxFA"));
             m_Controls->m_PrototypeWidget3->SetMinAdc(v1.second.get<double>("compartment3.prototype.minADC"));
             m_Controls->m_PrototypeWidget3->SetMaxAdc(v1.second.get<double>("compartment3.prototype.maxADC"));
             m_Controls->m_PrototypeWidget3->SetNumberOfSamples(v1.second.get<double>("compartment3.prototype.numSamples"));
 
             m_Controls->m_BallWidget2->SetD(v1.second.get<double>("compartment4.ball.d"));
             m_Controls->m_BallWidget2->SetT2(v1.second.get<double>("compartment4.ball.t2"));
             m_Controls->m_AstrosticksWidget2->SetD(v1.second.get<double>("compartment4.astrosticks.d"));
             m_Controls->m_AstrosticksWidget2->SetT2(v1.second.get<double>("compartment4.astrosticks.t2"));
             m_Controls->m_AstrosticksWidget2->SetRandomizeSticks(v1.second.get<bool>("compartment4.astrosticks.randomize"));
             m_Controls->m_DotWidget2->SetT2(v1.second.get<double>("compartment4.dot.t2"));
             m_Controls->m_PrototypeWidget4->SetMinFa(v1.second.get<double>("compartment4.prototype.minFA"));
             m_Controls->m_PrototypeWidget4->SetMaxFa(v1.second.get<double>("compartment4.prototype.maxFA"));
             m_Controls->m_PrototypeWidget4->SetMinAdc(v1.second.get<double>("compartment4.prototype.minADC"));
             m_Controls->m_PrototypeWidget4->SetMaxAdc(v1.second.get<double>("compartment4.prototype.maxADC"));
             m_Controls->m_PrototypeWidget4->SetNumberOfSamples(v1.second.get<double>("compartment4.prototype.numSamples"));
         }
     }
 }
 
 void QmitkFiberfoxView::ShowAdvancedOptions(int state)
 {
     if (state)
     {
         m_Controls->m_AdvancedFiberOptionsFrame->setVisible(true);
         m_Controls->m_AdvancedSignalOptionsFrame->setVisible(true);
         m_Controls->m_AdvancedOptionsBox->setChecked(true);
         m_Controls->m_AdvancedOptionsBox_2->setChecked(true);
     }
     else
     {
         m_Controls->m_AdvancedFiberOptionsFrame->setVisible(false);
         m_Controls->m_AdvancedSignalOptionsFrame->setVisible(false);
         m_Controls->m_AdvancedOptionsBox->setChecked(false);
         m_Controls->m_AdvancedOptionsBox_2->setChecked(false);
     }
 }
 
 void QmitkFiberfoxView::Comp1ModelFrameVisibility(int index)
 {
     m_Controls->m_StickWidget1->setVisible(false);
     m_Controls->m_ZeppelinWidget1->setVisible(false);
     m_Controls->m_TensorWidget1->setVisible(false);
     m_Controls->m_PrototypeWidget1->setVisible(false);
 
     switch (index)
     {
     case 0:
         m_Controls->m_StickWidget1->setVisible(true);
         break;
     case 1:
         m_Controls->m_ZeppelinWidget1->setVisible(true);
         break;
     case 2:
         m_Controls->m_TensorWidget1->setVisible(true);
         break;
     case 3:
         m_Controls->m_PrototypeWidget1->setVisible(true);
         break;
     }
 }
 
 void QmitkFiberfoxView::Comp2ModelFrameVisibility(int index)
 {
     m_Controls->m_StickWidget2->setVisible(false);
     m_Controls->m_ZeppelinWidget2->setVisible(false);
     m_Controls->m_TensorWidget2->setVisible(false);
 
     switch (index)
     {
     case 0:
         break;
     case 1:
         m_Controls->m_StickWidget2->setVisible(true);
         break;
     case 2:
         m_Controls->m_ZeppelinWidget2->setVisible(true);
         break;
     case 3:
         m_Controls->m_TensorWidget2->setVisible(true);
         break;
     }
 }
 
 void QmitkFiberfoxView::Comp3ModelFrameVisibility(int index)
 {
     m_Controls->m_BallWidget1->setVisible(false);
     m_Controls->m_AstrosticksWidget1->setVisible(false);
     m_Controls->m_DotWidget1->setVisible(false);
     m_Controls->m_PrototypeWidget3->setVisible(false);
 
     switch (index)
     {
     case 0:
         m_Controls->m_BallWidget1->setVisible(true);
         break;
     case 1:
         m_Controls->m_AstrosticksWidget1->setVisible(true);
         break;
     case 2:
         m_Controls->m_DotWidget1->setVisible(true);
         break;
     case 3:
         m_Controls->m_PrototypeWidget3->setVisible(true);
         break;
     }
 }
 
 void QmitkFiberfoxView::Comp4ModelFrameVisibility(int index)
 {
     m_Controls->m_BallWidget2->setVisible(false);
     m_Controls->m_AstrosticksWidget2->setVisible(false);
     m_Controls->m_DotWidget2->setVisible(false);
     m_Controls->m_PrototypeWidget4->setVisible(false);
     m_Controls->m_Comp4FractionFrame->setVisible(false);
 
     switch (index)
     {
     case 0:
         break;
     case 1:
         m_Controls->m_BallWidget2->setVisible(true);
         m_Controls->m_Comp4FractionFrame->setVisible(true);
         break;
     case 2:
         m_Controls->m_AstrosticksWidget2->setVisible(true);
         m_Controls->m_Comp4FractionFrame->setVisible(true);
         break;
     case 3:
         m_Controls->m_DotWidget2->setVisible(true);
         m_Controls->m_Comp4FractionFrame->setVisible(true);
         break;
     case 4:
         m_Controls->m_PrototypeWidget4->setVisible(true);
         m_Controls->m_Comp4FractionFrame->setVisible(true);
         break;
     }
 }
 
 void QmitkFiberfoxView::OnConstantRadius(int value)
 {
     if (value>0 && m_Controls->m_RealTimeFibers->isChecked())
         GenerateFibers();
 }
 
 void QmitkFiberfoxView::OnAddMotion(int value)
 {
     if (value>0)
         m_Controls->m_MotionArtifactFrame->setVisible(true);
     else
         m_Controls->m_MotionArtifactFrame->setVisible(false);
 }
 
 void QmitkFiberfoxView::OnAddAliasing(int value)
 {
     if (value>0)
         m_Controls->m_AliasingFrame->setVisible(true);
     else
         m_Controls->m_AliasingFrame->setVisible(false);
 }
 
 void QmitkFiberfoxView::OnAddSpikes(int value)
 {
     if (value>0)
         m_Controls->m_SpikeFrame->setVisible(true);
     else
         m_Controls->m_SpikeFrame->setVisible(false);
 }
 
 void QmitkFiberfoxView::OnAddEddy(int value)
 {
     if (value>0)
         m_Controls->m_EddyFrame->setVisible(true);
     else
         m_Controls->m_EddyFrame->setVisible(false);
 }
 
 void QmitkFiberfoxView::OnAddDistortions(int value)
 {
     if (value>0)
         m_Controls->m_DistortionsFrame->setVisible(true);
     else
         m_Controls->m_DistortionsFrame->setVisible(false);
 }
 
 void QmitkFiberfoxView::OnAddGhosts(int value)
 {
     if (value>0)
         m_Controls->m_GhostFrame->setVisible(true);
     else
         m_Controls->m_GhostFrame->setVisible(false);
 }
 
 void QmitkFiberfoxView::OnAddNoise(int value)
 {
     if (value>0)
         m_Controls->m_NoiseFrame->setVisible(true);
     else
         m_Controls->m_NoiseFrame->setVisible(false);
 }
 
 void QmitkFiberfoxView::OnDistributionChanged(int value)
 {
     if (value==1)
         m_Controls->m_VarianceBox->setVisible(true);
     else
         m_Controls->m_VarianceBox->setVisible(false);
 
     if (m_Controls->m_RealTimeFibers->isChecked())
         GenerateFibers();
 }
 
 void QmitkFiberfoxView::OnVarianceChanged(double)
 {
     if (m_Controls->m_RealTimeFibers->isChecked())
         GenerateFibers();
 }
 
 void QmitkFiberfoxView::OnFiberDensityChanged(int)
 {
     if (m_Controls->m_RealTimeFibers->isChecked())
         GenerateFibers();
 }
 
 void QmitkFiberfoxView::OnFiberSamplingChanged(double)
 {
     if (m_Controls->m_RealTimeFibers->isChecked())
         GenerateFibers();
 }
 
 void QmitkFiberfoxView::OnTensionChanged(double)
 {
     if (m_Controls->m_RealTimeFibers->isChecked())
         GenerateFibers();
 }
 
 void QmitkFiberfoxView::OnContinuityChanged(double)
 {
     if (m_Controls->m_RealTimeFibers->isChecked())
         GenerateFibers();
 }
 
 void QmitkFiberfoxView::OnBiasChanged(double)
 {
     if (m_Controls->m_RealTimeFibers->isChecked())
         GenerateFibers();
 }
 
 void QmitkFiberfoxView::AlignOnGrid()
 {
     for (unsigned int i=0; i<m_SelectedFiducials.size(); i++)
     {
         mitk::PlanarEllipse::Pointer pe = dynamic_cast<mitk::PlanarEllipse*>(m_SelectedFiducials.at(i)->GetData());
         mitk::Point3D wc0 = pe->GetWorldControlPoint(0);
 
         mitk::DataStorage::SetOfObjects::ConstPointer parentFibs = GetDataStorage()->GetSources(m_SelectedFiducials.at(i));
         for( mitk::DataStorage::SetOfObjects::const_iterator it = parentFibs->begin(); it != parentFibs->end(); ++it )
         {
             mitk::DataNode::Pointer pFibNode = *it;
             if ( pFibNode.IsNotNull() && dynamic_cast<mitk::FiberBundleX*>(pFibNode->GetData()) )
             {
                 mitk::DataStorage::SetOfObjects::ConstPointer parentImgs = GetDataStorage()->GetSources(pFibNode);
                 for( mitk::DataStorage::SetOfObjects::const_iterator it2 = parentImgs->begin(); it2 != parentImgs->end(); ++it2 )
                 {
                     mitk::DataNode::Pointer pImgNode = *it2;
                     if ( pImgNode.IsNotNull() && dynamic_cast<mitk::Image*>(pImgNode->GetData()) )
                     {
                         mitk::Image::Pointer img = dynamic_cast<mitk::Image*>(pImgNode->GetData());
                         mitk::BaseGeometry::Pointer geom = img->GetGeometry();
                         itk::Index<3> idx;
                         geom->WorldToIndex(wc0, idx);
 
                         mitk::Point3D cIdx; cIdx[0]=idx[0]; cIdx[1]=idx[1]; cIdx[2]=idx[2];
                         mitk::Point3D world;
                         geom->IndexToWorld(cIdx,world);
 
                         mitk::Vector3D trans = world - wc0;
                         pe->GetGeometry()->Translate(trans);
 
                         break;
                     }
                 }
                 break;
             }
         }
     }
 
     for(unsigned int i=0; i<m_SelectedBundles2.size(); i++ )
     {
         mitk::DataNode::Pointer fibNode = m_SelectedBundles2.at(i);
 
         mitk::DataStorage::SetOfObjects::ConstPointer sources = GetDataStorage()->GetSources(fibNode);
         for( mitk::DataStorage::SetOfObjects::const_iterator it = sources->begin(); it != sources->end(); ++it )
         {
             mitk::DataNode::Pointer imgNode = *it;
             if ( imgNode.IsNotNull() && dynamic_cast<mitk::Image*>(imgNode->GetData()) )
             {
                 mitk::DataStorage::SetOfObjects::ConstPointer derivations = GetDataStorage()->GetDerivations(fibNode);
                 for( mitk::DataStorage::SetOfObjects::const_iterator it2 = derivations->begin(); it2 != derivations->end(); ++it2 )
                 {
                     mitk::DataNode::Pointer fiducialNode = *it2;
                     if ( fiducialNode.IsNotNull() && dynamic_cast<mitk::PlanarEllipse*>(fiducialNode->GetData()) )
                     {
                         mitk::PlanarEllipse::Pointer pe = dynamic_cast<mitk::PlanarEllipse*>(fiducialNode->GetData());
                         mitk::Point3D wc0 = pe->GetWorldControlPoint(0);
 
                         mitk::Image::Pointer img = dynamic_cast<mitk::Image*>(imgNode->GetData());
                         mitk::BaseGeometry::Pointer geom = img->GetGeometry();
                         itk::Index<3> idx;
                         geom->WorldToIndex(wc0, idx);
                         mitk::Point3D cIdx; cIdx[0]=idx[0]; cIdx[1]=idx[1]; cIdx[2]=idx[2];
                         mitk::Point3D world;
                         geom->IndexToWorld(cIdx,world);
 
                         mitk::Vector3D trans = world - wc0;
                         pe->GetGeometry()->Translate(trans);
                     }
                 }
 
                 break;
             }
         }
     }
 
     for(unsigned int i=0; i<m_SelectedImages.size(); i++ )
     {
         mitk::Image::Pointer img = dynamic_cast<mitk::Image*>(m_SelectedImages.at(i)->GetData());
 
         mitk::DataStorage::SetOfObjects::ConstPointer derivations = GetDataStorage()->GetDerivations(m_SelectedImages.at(i));
         for( mitk::DataStorage::SetOfObjects::const_iterator it = derivations->begin(); it != derivations->end(); ++it )
         {
             mitk::DataNode::Pointer fibNode = *it;
             if ( fibNode.IsNotNull() && dynamic_cast<mitk::FiberBundleX*>(fibNode->GetData()) )
             {
                 mitk::DataStorage::SetOfObjects::ConstPointer derivations2 = GetDataStorage()->GetDerivations(fibNode);
                 for( mitk::DataStorage::SetOfObjects::const_iterator it2 = derivations2->begin(); it2 != derivations2->end(); ++it2 )
                 {
                     mitk::DataNode::Pointer fiducialNode = *it2;
                     if ( fiducialNode.IsNotNull() && dynamic_cast<mitk::PlanarEllipse*>(fiducialNode->GetData()) )
                     {
                         mitk::PlanarEllipse::Pointer pe = dynamic_cast<mitk::PlanarEllipse*>(fiducialNode->GetData());
                         mitk::Point3D wc0 = pe->GetWorldControlPoint(0);
 
                         mitk::BaseGeometry::Pointer geom = img->GetGeometry();
                         itk::Index<3> idx;
                         geom->WorldToIndex(wc0, idx);
                         mitk::Point3D cIdx; cIdx[0]=idx[0]; cIdx[1]=idx[1]; cIdx[2]=idx[2];
                         mitk::Point3D world;
                         geom->IndexToWorld(cIdx,world);
 
                         mitk::Vector3D trans = world - wc0;
                         pe->GetGeometry()->Translate(trans);
                     }
                 }
             }
         }
     }
 
     mitk::RenderingManager::GetInstance()->RequestUpdateAll();
     if (m_Controls->m_RealTimeFibers->isChecked())
         GenerateFibers();
 }
 
 void QmitkFiberfoxView::OnFlipButton()
 {
     if (m_SelectedFiducial.IsNull())
         return;
 
     std::map<mitk::DataNode*, QmitkPlanarFigureData>::iterator it = m_DataNodeToPlanarFigureData.find(m_SelectedFiducial.GetPointer());
     if( it != m_DataNodeToPlanarFigureData.end() )
     {
         QmitkPlanarFigureData& data = it->second;
         data.m_Flipped += 1;
         data.m_Flipped %= 2;
     }
 
     if (m_Controls->m_RealTimeFibers->isChecked())
         GenerateFibers();
 }
 
 QmitkFiberfoxView::GradientListType QmitkFiberfoxView::GenerateHalfShell(int NPoints)
 {
     NPoints *= 2;
     GradientListType pointshell;
 
     int numB0 = NPoints/20;
     if (numB0==0)
         numB0=1;
     GradientType g;
     g.Fill(0.0);
     for (int i=0; i<numB0; i++)
         pointshell.push_back(g);
 
     if (NPoints==0)
         return pointshell;
 
     vnl_vector<double> theta; theta.set_size(NPoints);
     vnl_vector<double> phi; phi.set_size(NPoints);
     double C = sqrt(4*M_PI);
     phi(0) = 0.0;
     phi(NPoints-1) = 0.0;
     for(int i=0; i<NPoints; i++)
     {
         theta(i) = acos(-1.0+2.0*i/(NPoints-1.0)) - M_PI / 2.0;
         if( i>0 && i<NPoints-1)
         {
             phi(i) = (phi(i-1) + C /
                       sqrt(NPoints*(1-(-1.0+2.0*i/(NPoints-1.0))*(-1.0+2.0*i/(NPoints-1.0)))));
             // % (2*DIST_POINTSHELL_PI);
         }
     }
 
     for(int i=0; i<NPoints; i++)
     {
         g[2] = sin(theta(i));
         if (g[2]<0)
             continue;
         g[0] = cos(theta(i)) * cos(phi(i));
         g[1] = cos(theta(i)) * sin(phi(i));
         pointshell.push_back(g);
     }
 
     return pointshell;
 }
 
 template<int ndirs>
 std::vector<itk::Vector<double,3> > QmitkFiberfoxView::MakeGradientList()
 {
     std::vector<itk::Vector<double,3> > retval;
     vnl_matrix_fixed<double, 3, ndirs>* U =
             itk::PointShell<ndirs, vnl_matrix_fixed<double, 3, ndirs> >::DistributePointShell();
 
 
     // Add 0 vector for B0
     int numB0 = ndirs/10;
     if (numB0==0)
         numB0=1;
     itk::Vector<double,3> v;
     v.Fill(0.0);
     for (int i=0; i<numB0; i++)
     {
         retval.push_back(v);
     }
 
     for(int i=0; i<ndirs;i++)
     {
         itk::Vector<double,3> v;
         v[0] = U->get(0,i); v[1] = U->get(1,i); v[2] = U->get(2,i);
         retval.push_back(v);
     }
 
     return retval;
 }
 
 void QmitkFiberfoxView::OnAddBundle()
 {
     if (m_SelectedImage.IsNull())
         return;
 
     mitk::DataStorage::SetOfObjects::ConstPointer children = GetDataStorage()->GetDerivations(m_SelectedImage);
 
     mitk::FiberBundleX::Pointer bundle = mitk::FiberBundleX::New();
     mitk::DataNode::Pointer node = mitk::DataNode::New();
     node->SetData( bundle );
     QString name = QString("Bundle_%1").arg(children->size());
     node->SetName(name.toStdString());
     m_SelectedBundles.push_back(node);
     UpdateGui();
 
     GetDataStorage()->Add(node, m_SelectedImage);
 }
 
 void QmitkFiberfoxView::OnDrawROI()
 {
     if (m_SelectedBundles.empty())
         OnAddBundle();
     if (m_SelectedBundles.empty())
         return;
 
     mitk::DataStorage::SetOfObjects::ConstPointer children = GetDataStorage()->GetDerivations(m_SelectedBundles.at(0));
 
     mitk::PlanarEllipse::Pointer figure = mitk::PlanarEllipse::New();
 
     mitk::DataNode::Pointer node = mitk::DataNode::New();
     node->SetData( figure );
     node->SetBoolProperty("planarfigure.3drendering", true);
 
     QList<mitk::DataNode::Pointer> nodes = this->GetDataManagerSelection();
     for( int i=0; i<nodes.size(); i++)
         nodes.at(i)->SetSelected(false);
 
     m_SelectedFiducial = node;
 
     QString name = QString("Fiducial_%1").arg(children->size());
     node->SetName(name.toStdString());
     node->SetSelected(true);
 
     this->DisableCrosshairNavigation();
 
     mitk::PlanarFigureInteractor::Pointer figureInteractor = dynamic_cast<mitk::PlanarFigureInteractor*>(node->GetDataInteractor().GetPointer());
     if(figureInteractor.IsNull())
     {
         figureInteractor = mitk::PlanarFigureInteractor::New();
         us::Module* planarFigureModule = us::ModuleRegistry::GetModule( "MitkPlanarFigure" );
         figureInteractor->LoadStateMachine("PlanarFigureInteraction.xml", planarFigureModule );
         figureInteractor->SetEventConfig( "PlanarFigureConfig.xml", planarFigureModule );
         figureInteractor->SetDataNode( node );
     }
 
     UpdateGui();
     GetDataStorage()->Add(node, m_SelectedBundles.at(0));
 }
 
 bool CompareLayer(mitk::DataNode::Pointer i,mitk::DataNode::Pointer j)
 {
     int li = -1;
     i->GetPropertyValue("layer", li);
     int lj = -1;
     j->GetPropertyValue("layer", lj);
     return li<lj;
 }
 
 void QmitkFiberfoxView::GenerateFibers()
 {
     if (m_SelectedBundles.empty())
     {
         if (m_SelectedFiducial.IsNull())
             return;
 
         mitk::DataStorage::SetOfObjects::ConstPointer parents = GetDataStorage()->GetSources(m_SelectedFiducial);
         for( mitk::DataStorage::SetOfObjects::const_iterator it = parents->begin(); it != parents->end(); ++it )
             if(dynamic_cast<mitk::FiberBundleX*>((*it)->GetData()))
                 m_SelectedBundles.push_back(*it);
 
         if (m_SelectedBundles.empty())
             return;
     }
 
     vector< vector< mitk::PlanarEllipse::Pointer > > fiducials;
     vector< vector< unsigned int > > fliplist;
     for (unsigned int i=0; i<m_SelectedBundles.size(); i++)
     {
         mitk::DataStorage::SetOfObjects::ConstPointer children = GetDataStorage()->GetDerivations(m_SelectedBundles.at(i));
         std::vector< mitk::DataNode::Pointer > childVector;
         for( mitk::DataStorage::SetOfObjects::const_iterator it = children->begin(); it != children->end(); ++it )
             childVector.push_back(*it);
         sort(childVector.begin(), childVector.end(), CompareLayer);
 
         vector< mitk::PlanarEllipse::Pointer > fib;
         vector< unsigned int > flip;
         float radius = 1;
         int count = 0;
         for( std::vector< mitk::DataNode::Pointer >::const_iterator it = childVector.begin(); it != childVector.end(); ++it )
         {
             mitk::DataNode::Pointer node = *it;
 
             if ( node.IsNotNull() && dynamic_cast<mitk::PlanarEllipse*>(node->GetData()) )
             {
                 mitk::PlanarEllipse* ellipse = dynamic_cast<mitk::PlanarEllipse*>(node->GetData());
                 if (m_Controls->m_ConstantRadiusBox->isChecked())
                 {
                     ellipse->SetTreatAsCircle(true);
                     mitk::Point2D c = ellipse->GetControlPoint(0);
                     mitk::Point2D p = ellipse->GetControlPoint(1);
                     mitk::Vector2D v = p-c;
                     if (count==0)
                     {
                         radius = v.GetVnlVector().magnitude();
                         ellipse->SetControlPoint(1, p);
                     }
                     else
                     {
                         v.Normalize();
                         v *= radius;
                         ellipse->SetControlPoint(1, c+v);
                     }
                 }
                 fib.push_back(ellipse);
 
                 std::map<mitk::DataNode*, QmitkPlanarFigureData>::iterator it = m_DataNodeToPlanarFigureData.find(node.GetPointer());
                 if( it != m_DataNodeToPlanarFigureData.end() )
                 {
                     QmitkPlanarFigureData& data = it->second;
                     flip.push_back(data.m_Flipped);
                 }
                 else
                     flip.push_back(0);
             }
             count++;
         }
         if (fib.size()>1)
         {
             fiducials.push_back(fib);
             fliplist.push_back(flip);
         }
         else if (fib.size()>0)
             m_SelectedBundles.at(i)->SetData( mitk::FiberBundleX::New() );
 
         mitk::RenderingManager::GetInstance()->RequestUpdateAll();
     }
 
     itk::FibersFromPlanarFiguresFilter::Pointer filter = itk::FibersFromPlanarFiguresFilter::New();
     filter->SetFiducials(fiducials);
     filter->SetFlipList(fliplist);
 
     switch(m_Controls->m_DistributionBox->currentIndex()){
     case 0:
         filter->SetFiberDistribution(itk::FibersFromPlanarFiguresFilter::DISTRIBUTE_UNIFORM);
         break;
     case 1:
         filter->SetFiberDistribution(itk::FibersFromPlanarFiguresFilter::DISTRIBUTE_GAUSSIAN);
         filter->SetVariance(m_Controls->m_VarianceBox->value());
         break;
     }
 
     filter->SetDensity(m_Controls->m_FiberDensityBox->value());
     filter->SetTension(m_Controls->m_TensionBox->value());
     filter->SetContinuity(m_Controls->m_ContinuityBox->value());
     filter->SetBias(m_Controls->m_BiasBox->value());
     filter->SetFiberSampling(m_Controls->m_FiberSamplingBox->value());
     filter->Update();
     vector< mitk::FiberBundleX::Pointer > fiberBundles = filter->GetFiberBundles();
 
     for (unsigned int i=0; i<fiberBundles.size(); i++)
     {
         m_SelectedBundles.at(i)->SetData( fiberBundles.at(i) );
         if (fiberBundles.at(i)->GetNumFibers()>50000)
             m_SelectedBundles.at(i)->SetVisibility(false);
     }
 
     mitk::RenderingManager::GetInstance()->RequestUpdateAll();
 }
 
 void QmitkFiberfoxView::GenerateImage()
 {
     if (m_SelectedBundles.empty() && m_SelectedDWI.IsNull())
     {
         mitk::Image::Pointer image = mitk::ImageGenerator::GenerateGradientImage<unsigned int>(
                     m_Controls->m_SizeX->value(),
                     m_Controls->m_SizeY->value(),
                     m_Controls->m_SizeZ->value(),
                     m_Controls->m_SpacingX->value(),
                     m_Controls->m_SpacingY->value(),
                     m_Controls->m_SpacingZ->value());
 
         mitk::DataNode::Pointer node = mitk::DataNode::New();
         node->SetData( image );
         node->SetName("Dummy");
         unsigned int window = m_Controls->m_SizeX->value()*m_Controls->m_SizeY->value()*m_Controls->m_SizeZ->value();
         unsigned int level = window/2;
         mitk::LevelWindow lw; lw.SetLevelWindow(level, window);
         node->SetProperty( "levelwindow", mitk::LevelWindowProperty::New( lw ) );
         GetDataStorage()->Add(node);
         m_SelectedImage = node;
 
         mitk::BaseData::Pointer basedata = node->GetData();
         if (basedata.IsNotNull())
         {
             mitk::RenderingManager::GetInstance()->InitializeViews( basedata->GetTimeGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true );
             mitk::RenderingManager::GetInstance()->RequestUpdateAll();
         }
         UpdateGui();
     }
     else if (!m_SelectedBundles.empty())
         SimulateImageFromFibers(m_SelectedBundles.at(0));
     else if (m_SelectedDWI.IsNotNull())
         SimulateForExistingDwi(m_SelectedDWI);
 }
 
 void QmitkFiberfoxView::SimulateForExistingDwi(mitk::DataNode* imageNode)
 {
     if (!dynamic_cast<mitk::DiffusionImage<short>*>(imageNode->GetData()))
         return;
 
     FiberfoxParameters<short> parameters = UpdateImageParameters<short>();
 
     if (parameters.m_NoiseModel==NULL &&
             parameters.m_Spikes==0 &&
             parameters.m_FrequencyMap.IsNull() &&
             parameters.m_KspaceLineOffset<=0.000001 &&
             !parameters.m_DoAddGibbsRinging &&
             !(parameters.m_EddyStrength>0) &&
             parameters.m_CroppingFactor>0.999)
     {
         QMessageBox::information( NULL, "Simulation cancelled", "No valid artifact enabled! Motion artifacts and relaxation effects can NOT be added to an existing diffusion weighted image.");
         return;
     }
 
     mitk::DiffusionImage<short>::Pointer diffImg = dynamic_cast<mitk::DiffusionImage<short>*>(imageNode->GetData());
     m_ArtifactsToDwiFilter = itk::AddArtifactsToDwiImageFilter< short >::New();
     m_ArtifactsToDwiFilter->SetInput(diffImg->GetVectorImage());
     parameters.m_ParentNode = imageNode;
     m_ArtifactsToDwiFilter->SetParameters(parameters);
     m_Worker.m_FilterType = 1;
     m_Thread.start(QThread::LowestPriority);
 }
 
 void QmitkFiberfoxView::SimulateImageFromFibers(mitk::DataNode* fiberNode)
 {
     mitk::FiberBundleX::Pointer fiberBundle = dynamic_cast<mitk::FiberBundleX*>(fiberNode->GetData());
     if (fiberBundle->GetNumFibers()<=0)
         return;
 
     FiberfoxParameters<double> parameters = UpdateImageParameters<double>();
 
     m_TractsToDwiFilter = itk::TractsToDWIImageFilter< short >::New();
     parameters.m_ParentNode = fiberNode;
     if (m_SelectedDWI.IsNotNull())
     {
         mitk::DiffusionImage<short>::Pointer diffImg = dynamic_cast<mitk::DiffusionImage<short>*>(m_SelectedDWI->GetData());
 
         bool doSampling = false;
         for (unsigned int i=0; i<parameters.m_FiberModelList.size(); i++)
             if ( dynamic_cast< RawShModel<double>* >(parameters.m_FiberModelList[i]) )
                 doSampling = true;
         for (unsigned int i=0; i<parameters.m_NonFiberModelList.size(); i++)
             if ( dynamic_cast< RawShModel<double>* >(parameters.m_NonFiberModelList[i]) )
                 doSampling = true;
 
         // sample prototype signals
         if ( doSampling )
         {
             const int shOrder = 2;
 
             typedef itk::DiffusionTensor3DReconstructionImageFilter< short, short, double > TensorReconstructionImageFilterType;
             TensorReconstructionImageFilterType::Pointer filter = TensorReconstructionImageFilterType::New();
             filter->SetGradientImage( diffImg->GetDirections(), diffImg->GetVectorImage() );
             filter->SetBValue(diffImg->GetReferenceBValue());
             filter->Update();
             itk::Image< itk::DiffusionTensor3D< double >, 3 >::Pointer tensorImage = filter->GetOutput();
 
             const int NumCoeffs = (shOrder*shOrder + shOrder + 2)/2 + shOrder;
             typedef itk::AnalyticalDiffusionQballReconstructionImageFilter<short,short,float,shOrder,QBALL_ODFSIZE> QballFilterType;
-            typename QballFilterType::Pointer qballfilter = QballFilterType::New();
+            QballFilterType::Pointer qballfilter = QballFilterType::New();
             qballfilter->SetGradientImage( diffImg->GetDirections(), diffImg->GetVectorImage() );
             qballfilter->SetBValue(diffImg->GetReferenceBValue());
             qballfilter->SetLambda(0.006);
             qballfilter->SetNormalizationMethod(QballFilterType::QBAR_RAW_SIGNAL);
             qballfilter->Update();
             QballFilterType::CoefficientImageType::Pointer itkFeatureImage = qballfilter->GetCoefficientImage();
 
             itk::AdcImageFilter< short, double >::Pointer adcFilter = itk::AdcImageFilter< short, double >::New();
             adcFilter->SetInput(diffImg->GetVectorImage());
             adcFilter->SetGradientDirections(diffImg->GetDirections());
             adcFilter->SetB_value(diffImg->GetReferenceBValue());
             adcFilter->Update();
             ItkDoubleImgType::Pointer adcImage = adcFilter->GetOutput();
 
             int b0Index;
             for (unsigned int i=0; i<diffImg->GetDirectionsWithoutMeasurementFrame()->Size(); i++)
                 if ( diffImg->GetDirectionsWithoutMeasurementFrame()->GetElement(i).magnitude()<0.001 )
                 {
                     b0Index = i;
                     break;
                 }
 
             double max = 0;
             {
                 itk::ImageRegionIterator< itk::VectorImage< short, 3 > >  it(diffImg->GetVectorImage(), diffImg->GetVectorImage()->GetLargestPossibleRegion());
                 while(!it.IsAtEnd())
                 {
                     if (parameters.m_MaskImage.IsNotNull() && parameters.m_MaskImage->GetPixel(it.GetIndex())<=0)
                     {
                         ++it;
                         continue;
                     }
                     if (it.Get()[b0Index]>max)
                         max = it.Get()[b0Index];
                     ++it;
                 }
             }
 
             MITK_INFO << "Sampling signal kernels.";
 
             itk::ImageRegionIterator< itk::Image< itk::DiffusionTensor3D< double >, 3 > >  it(tensorImage, tensorImage->GetLargestPossibleRegion());
             while(!it.IsAtEnd())
             {
                 bool skipPixel = false;
                 if (parameters.m_MaskImage.IsNotNull() && parameters.m_MaskImage->GetPixel(it.GetIndex())<=0)
                 {
                     ++it;
                     continue;
                 }
                 for (unsigned int i=0; i<diffImg->GetDirections()->Size(); i++)
                 {
                     if (diffImg->GetVectorImage()->GetPixel(it.GetIndex())[i]!=diffImg->GetVectorImage()->GetPixel(it.GetIndex())[i] || diffImg->GetVectorImage()->GetPixel(it.GetIndex())[i]<=0 || diffImg->GetVectorImage()->GetPixel(it.GetIndex())[i]>diffImg->GetVectorImage()->GetPixel(it.GetIndex())[b0Index])
                     {
                         skipPixel = true;
                         break;
                     }
                 }
                 if (skipPixel)
                 {
                     ++it;
                     continue;
                 }
 
                 typedef itk::DiffusionTensor3D<double>    TensorType;
                 TensorType::EigenValuesArrayType eigenvalues;
                 TensorType::EigenVectorsMatrixType eigenvectors;
                 TensorType tensor = it.Get();
                 double FA = tensor.GetFractionalAnisotropy();
                 double ADC = adcImage->GetPixel(it.GetIndex());
                 QballFilterType::CoefficientImageType::PixelType itkv = itkFeatureImage->GetPixel(it.GetIndex());
                 vnl_vector_fixed< double, NumCoeffs > coeffs;
                 for (unsigned int c=0; c<itkv.Size(); c++)
                     coeffs[c] = itkv[c]/max;
 
                 for (unsigned int i=0; i<parameters.m_FiberModelList.size(); i++)
                 {
                     RawShModel<double>* model = dynamic_cast< RawShModel<double>* >(parameters.m_FiberModelList[i]);
                     if ( model && model->GetMaxNumKernels()>model->GetNumberOfKernels() && FA>model->GetFaRange().first && FA<model->GetFaRange().second && ADC>model->GetAdcRange().first && ADC<model->GetAdcRange().second)
                     {
                         if (model->SetShCoefficients( coeffs, (double)diffImg->GetVectorImage()->GetPixel(it.GetIndex())[b0Index]/max ))
                         {
                             tensor.ComputeEigenAnalysis(eigenvalues, eigenvectors);
                             itk::Vector<double,3> dir;
                             dir[0] = eigenvectors(2, 0);
                             dir[1] = eigenvectors(2, 1);
                             dir[2] = eigenvectors(2, 2);
                             model->m_PrototypeMaxDirection.push_back(dir);
                             MITK_INFO << "WM KERNEL: " << it.GetIndex() << " (" << model->GetNumberOfKernels() << ")";
                         }
                     }
                 }
                 for (unsigned int i=0; i<parameters.m_NonFiberModelList.size(); i++)
                 {
                     RawShModel<double>* model = dynamic_cast< RawShModel<double>* >(parameters.m_NonFiberModelList[i]);
                     if ( model && model->GetMaxNumKernels()>model->GetNumberOfKernels() && FA>model->GetFaRange().first && FA<model->GetFaRange().second && ADC>model->GetAdcRange().first && ADC<model->GetAdcRange().second)
                     {
                         if (model->SetShCoefficients( coeffs, (double)diffImg->GetVectorImage()->GetPixel(it.GetIndex())[b0Index]/max ))
                             MITK_INFO << "CSF/GM KERNEL: " << it.GetIndex() << " (" << model->GetNumberOfKernels() << ")";
                     }
                 }
                 ++it;
             }
 
             for (unsigned int i=0; i<parameters.m_FiberModelList.size(); i++)
             {
                 RawShModel<double>* model = dynamic_cast< RawShModel<double>* >(parameters.m_FiberModelList[i]);
                 if ( model && model->GetNumberOfKernels()<=0 )
                 {
                     QMessageBox::information( NULL, "Simulation cancelled", "No suitable voxels found for fiber compartment "+QString::number(i));
                     return;
                 }
             }
             for (unsigned int i=0; i<parameters.m_NonFiberModelList.size(); i++)
             {
                 RawShModel<double>* model = dynamic_cast< RawShModel<double>* >(parameters.m_NonFiberModelList[i]);
                 if ( model && model->GetNumberOfKernels()<=0 )
                 {
                     QMessageBox::information( NULL, "Simulation cancelled", "No suitable voxels found for non-fiber compartment "+QString::number(i));
                     return;
                 }
             }
         }
     }
     else if ( m_Controls->m_Compartment1Box->currentIndex()==3 || m_Controls->m_Compartment3Box->currentIndex()==3 || m_Controls->m_Compartment4Box->currentIndex()==4 )
     {
         QMessageBox::information( NULL, "Simulation cancelled", "Prototype signal but no diffusion-weighted image selected to sample signal from.");
         return;
     }
 
     m_TractsToDwiFilter->SetParameters(parameters);
     m_TractsToDwiFilter->SetFiberBundle(fiberBundle);
     m_Worker.m_FilterType = 0;
     m_Thread.start(QThread::LowestPriority);
 }
 
 void QmitkFiberfoxView::ApplyTransform()
 {
     vector< mitk::DataNode::Pointer > selectedBundles;
     for(unsigned int i=0; i<m_SelectedImages.size(); i++ )
     {
         mitk::DataStorage::SetOfObjects::ConstPointer derivations = GetDataStorage()->GetDerivations(m_SelectedImages.at(i));
         for( mitk::DataStorage::SetOfObjects::const_iterator it = derivations->begin(); it != derivations->end(); ++it )
         {
             mitk::DataNode::Pointer fibNode = *it;
             if ( fibNode.IsNotNull() && dynamic_cast<mitk::FiberBundleX*>(fibNode->GetData()) )
                 selectedBundles.push_back(fibNode);
         }
     }
     if (selectedBundles.empty())
         selectedBundles = m_SelectedBundles2;
 
     if (!selectedBundles.empty())
     {
         for (std::vector<mitk::DataNode::Pointer>::const_iterator it = selectedBundles.begin(); it!=selectedBundles.end(); ++it)
         {
             mitk::FiberBundleX::Pointer fib = dynamic_cast<mitk::FiberBundleX*>((*it)->GetData());
             fib->RotateAroundAxis(m_Controls->m_XrotBox->value(), m_Controls->m_YrotBox->value(), m_Controls->m_ZrotBox->value());
             fib->TranslateFibers(m_Controls->m_XtransBox->value(), m_Controls->m_YtransBox->value(), m_Controls->m_ZtransBox->value());
             fib->ScaleFibers(m_Controls->m_XscaleBox->value(), m_Controls->m_YscaleBox->value(), m_Controls->m_ZscaleBox->value());
 
             // handle child fiducials
             if (m_Controls->m_IncludeFiducials->isChecked())
             {
                 mitk::DataStorage::SetOfObjects::ConstPointer derivations = GetDataStorage()->GetDerivations(*it);
                 for( mitk::DataStorage::SetOfObjects::const_iterator it2 = derivations->begin(); it2 != derivations->end(); ++it2 )
                 {
                     mitk::DataNode::Pointer fiducialNode = *it2;
                     if ( fiducialNode.IsNotNull() && dynamic_cast<mitk::PlanarEllipse*>(fiducialNode->GetData()) )
                     {
                         mitk::PlanarEllipse* pe = dynamic_cast<mitk::PlanarEllipse*>(fiducialNode->GetData());
                         mitk::BaseGeometry* geom = pe->GetGeometry();
 
                         // translate
                         mitk::Vector3D world;
                         world[0] = m_Controls->m_XtransBox->value();
                         world[1] = m_Controls->m_YtransBox->value();
                         world[2] = m_Controls->m_ZtransBox->value();
                         geom->Translate(world);
 
                         // calculate rotation matrix
                         double x = m_Controls->m_XrotBox->value()*M_PI/180;
                         double y = m_Controls->m_YrotBox->value()*M_PI/180;
                         double z = m_Controls->m_ZrotBox->value()*M_PI/180;
 
                         itk::Matrix< double, 3, 3 > rotX; rotX.SetIdentity();
                         rotX[1][1] = cos(x);
                         rotX[2][2] = rotX[1][1];
                         rotX[1][2] = -sin(x);
                         rotX[2][1] = -rotX[1][2];
 
                         itk::Matrix< double, 3, 3 > rotY; rotY.SetIdentity();
                         rotY[0][0] = cos(y);
                         rotY[2][2] = rotY[0][0];
                         rotY[0][2] = sin(y);
                         rotY[2][0] = -rotY[0][2];
 
                         itk::Matrix< double, 3, 3 > rotZ; rotZ.SetIdentity();
                         rotZ[0][0] = cos(z);
                         rotZ[1][1] = rotZ[0][0];
                         rotZ[0][1] = -sin(z);
                         rotZ[1][0] = -rotZ[0][1];
 
                         itk::Matrix< double, 3, 3 > rot = rotZ*rotY*rotX;
 
                         // transform control point coordinate into geometry translation
                         geom->SetOrigin(pe->GetWorldControlPoint(0));
                         mitk::Point2D cp; cp.Fill(0.0);
                         pe->SetControlPoint(0, cp);
 
                         // rotate fiducial
                         geom->GetIndexToWorldTransform()->SetMatrix(rot*geom->GetIndexToWorldTransform()->GetMatrix());
 
                         // implicit translation
                         mitk::Vector3D trans;
                         trans[0] = geom->GetOrigin()[0]-fib->GetGeometry()->GetCenter()[0];
                         trans[1] = geom->GetOrigin()[1]-fib->GetGeometry()->GetCenter()[1];
                         trans[2] = geom->GetOrigin()[2]-fib->GetGeometry()->GetCenter()[2];
                         mitk::Vector3D newWc = rot*trans;
                         newWc = newWc-trans;
                         geom->Translate(newWc);
 
                         pe->Modified();
                     }
                 }
             }
         }
     }
     else
     {
         for (unsigned int i=0; i<m_SelectedFiducials.size(); i++)
         {
             mitk::PlanarEllipse* pe = dynamic_cast<mitk::PlanarEllipse*>(m_SelectedFiducials.at(i)->GetData());
             mitk::BaseGeometry* geom = pe->GetGeometry();
 
             // translate
             mitk::Vector3D world;
             world[0] = m_Controls->m_XtransBox->value();
             world[1] = m_Controls->m_YtransBox->value();
             world[2] = m_Controls->m_ZtransBox->value();
             geom->Translate(world);
 
             // calculate rotation matrix
             double x = m_Controls->m_XrotBox->value()*M_PI/180;
             double y = m_Controls->m_YrotBox->value()*M_PI/180;
             double z = m_Controls->m_ZrotBox->value()*M_PI/180;
             itk::Matrix< double, 3, 3 > rotX; rotX.SetIdentity();
             rotX[1][1] = cos(x);
             rotX[2][2] = rotX[1][1];
             rotX[1][2] = -sin(x);
             rotX[2][1] = -rotX[1][2];
             itk::Matrix< double, 3, 3 > rotY; rotY.SetIdentity();
             rotY[0][0] = cos(y);
             rotY[2][2] = rotY[0][0];
             rotY[0][2] = sin(y);
             rotY[2][0] = -rotY[0][2];
             itk::Matrix< double, 3, 3 > rotZ; rotZ.SetIdentity();
             rotZ[0][0] = cos(z);
             rotZ[1][1] = rotZ[0][0];
             rotZ[0][1] = -sin(z);
             rotZ[1][0] = -rotZ[0][1];
             itk::Matrix< double, 3, 3 > rot = rotZ*rotY*rotX;
 
             // transform control point coordinate into geometry translation
             geom->SetOrigin(pe->GetWorldControlPoint(0));
             mitk::Point2D cp; cp.Fill(0.0);
             pe->SetControlPoint(0, cp);
 
             // rotate fiducial
             geom->GetIndexToWorldTransform()->SetMatrix(rot*geom->GetIndexToWorldTransform()->GetMatrix());
             pe->Modified();
         }
         if (m_Controls->m_RealTimeFibers->isChecked())
             GenerateFibers();
     }
     mitk::RenderingManager::GetInstance()->RequestUpdateAll();
 }
 
 void QmitkFiberfoxView::CopyBundles()
 {
     if ( m_SelectedBundles.size()<1 ){
         QMessageBox::information( NULL, "Warning", "Select at least one fiber bundle!");
         MITK_WARN("QmitkFiberProcessingView") << "Select at least one fiber bundle!";
         return;
     }
 
     for (std::vector<mitk::DataNode::Pointer>::const_iterator it = m_SelectedBundles.begin(); it!=m_SelectedBundles.end(); ++it)
     {
         // find parent image
         mitk::DataNode::Pointer parentNode;
         mitk::DataStorage::SetOfObjects::ConstPointer parentImgs = GetDataStorage()->GetSources(*it);
         for( mitk::DataStorage::SetOfObjects::const_iterator it2 = parentImgs->begin(); it2 != parentImgs->end(); ++it2 )
         {
             mitk::DataNode::Pointer pImgNode = *it2;
             if ( pImgNode.IsNotNull() && dynamic_cast<mitk::Image*>(pImgNode->GetData()) )
             {
                 parentNode = pImgNode;
                 break;
             }
         }
 
         mitk::FiberBundleX::Pointer fib = dynamic_cast<mitk::FiberBundleX*>((*it)->GetData());
         mitk::FiberBundleX::Pointer newBundle = fib->GetDeepCopy();
         QString name((*it)->GetName().c_str());
         name += "_copy";
 
         mitk::DataNode::Pointer fbNode = mitk::DataNode::New();
         fbNode->SetData(newBundle);
         fbNode->SetName(name.toStdString());
         fbNode->SetVisibility(true);
         if (parentNode.IsNotNull())
             GetDataStorage()->Add(fbNode, parentNode);
         else
             GetDataStorage()->Add(fbNode);
 
         // copy child fiducials
         if (m_Controls->m_IncludeFiducials->isChecked())
         {
             mitk::DataStorage::SetOfObjects::ConstPointer derivations = GetDataStorage()->GetDerivations(*it);
             for( mitk::DataStorage::SetOfObjects::const_iterator it2 = derivations->begin(); it2 != derivations->end(); ++it2 )
             {
                 mitk::DataNode::Pointer fiducialNode = *it2;
                 if ( fiducialNode.IsNotNull() && dynamic_cast<mitk::PlanarEllipse*>(fiducialNode->GetData()) )
                 {
                     mitk::PlanarEllipse::Pointer pe = mitk::PlanarEllipse::New();
                     pe->DeepCopy(dynamic_cast<mitk::PlanarEllipse*>(fiducialNode->GetData()));
                     mitk::DataNode::Pointer newNode = mitk::DataNode::New();
                     newNode->SetData(pe);
                     newNode->SetName(fiducialNode->GetName());
                     newNode->SetBoolProperty("planarfigure.3drendering", true);
                     GetDataStorage()->Add(newNode, fbNode);
 
                 }
             }
         }
     }
     mitk::RenderingManager::GetInstance()->RequestUpdateAll();
 }
 
 void QmitkFiberfoxView::JoinBundles()
 {
     if ( m_SelectedBundles.size()<2 ){
         QMessageBox::information( NULL, "Warning", "Select at least two fiber bundles!");
         MITK_WARN("QmitkFiberProcessingView") << "Select at least two fiber bundles!";
         return;
     }
 
     std::vector<mitk::DataNode::Pointer>::const_iterator it = m_SelectedBundles.begin();
     mitk::FiberBundleX::Pointer newBundle = dynamic_cast<mitk::FiberBundleX*>((*it)->GetData());
     QString name("");
     name += QString((*it)->GetName().c_str());
     ++it;
     for (; it!=m_SelectedBundles.end(); ++it)
     {
         newBundle = newBundle->AddBundle(dynamic_cast<mitk::FiberBundleX*>((*it)->GetData()));
         name += "+"+QString((*it)->GetName().c_str());
     }
 
     mitk::DataNode::Pointer fbNode = mitk::DataNode::New();
     fbNode->SetData(newBundle);
     fbNode->SetName(name.toStdString());
     fbNode->SetVisibility(true);
     GetDataStorage()->Add(fbNode);
     mitk::RenderingManager::GetInstance()->RequestUpdateAll();
 }
 
 void QmitkFiberfoxView::UpdateGui()
 {
     m_Controls->m_FiberBundleLabel->setText("<font color='red'>mandatory</font>");
     m_Controls->m_GeometryFrame->setEnabled(true);
     m_Controls->m_GeometryMessage->setVisible(false);
     m_Controls->m_DiffusionPropsMessage->setVisible(false);
     m_Controls->m_FiberGenMessage->setVisible(true);
 
     m_Controls->m_TransformBundlesButton->setEnabled(false);
     m_Controls->m_CopyBundlesButton->setEnabled(false);
     m_Controls->m_GenerateFibersButton->setEnabled(false);
     m_Controls->m_FlipButton->setEnabled(false);
     m_Controls->m_CircleButton->setEnabled(false);
     m_Controls->m_BvalueBox->setEnabled(true);
     m_Controls->m_NumGradientsBox->setEnabled(true);
     m_Controls->m_JoinBundlesButton->setEnabled(false);
     m_Controls->m_AlignOnGrid->setEnabled(false);
 
     if (m_SelectedFiducial.IsNotNull())
     {
         m_Controls->m_TransformBundlesButton->setEnabled(true);
         m_Controls->m_FlipButton->setEnabled(true);
         m_Controls->m_AlignOnGrid->setEnabled(true);
     }
 
     if (m_SelectedImage.IsNotNull() || !m_SelectedBundles.empty())
     {
         m_Controls->m_TransformBundlesButton->setEnabled(true);
         m_Controls->m_CircleButton->setEnabled(true);
         m_Controls->m_FiberGenMessage->setVisible(false);
         m_Controls->m_AlignOnGrid->setEnabled(true);
     }
 
     if (m_MaskImageNode.IsNotNull() || m_SelectedImage.IsNotNull())
     {
         m_Controls->m_GeometryMessage->setVisible(true);
         m_Controls->m_GeometryFrame->setEnabled(false);
     }
 
     if (m_SelectedDWI.IsNotNull())
     {
         m_Controls->m_DiffusionPropsMessage->setVisible(true);
         m_Controls->m_BvalueBox->setEnabled(false);
         m_Controls->m_NumGradientsBox->setEnabled(false);
         m_Controls->m_GeometryMessage->setVisible(true);
         m_Controls->m_GeometryFrame->setEnabled(false);
     }
 
     if (!m_SelectedBundles.empty())
     {
         m_Controls->m_CopyBundlesButton->setEnabled(true);
         m_Controls->m_GenerateFibersButton->setEnabled(true);
         m_Controls->m_FiberBundleLabel->setText(m_SelectedBundles.at(0)->GetName().c_str());
 
         if (m_SelectedBundles.size()>1)
             m_Controls->m_JoinBundlesButton->setEnabled(true);
     }
 }
 
 void QmitkFiberfoxView::OnSelectionChanged( berry::IWorkbenchPart::Pointer, const QList<mitk::DataNode::Pointer>& nodes )
 {
     m_SelectedBundles2.clear();
     m_SelectedImages.clear();
     m_SelectedFiducials.clear();
     m_SelectedFiducial = NULL;
     m_SelectedBundles.clear();
     m_SelectedImage = NULL;
     m_SelectedDWI = NULL;
     m_MaskImageNode = NULL;
     m_Controls->m_TissueMaskLabel->setText("<font color='grey'>optional</font>");
 
     // iterate all selected objects, adjust warning visibility
     for( int i=0; i<nodes.size(); i++)
     {
         mitk::DataNode::Pointer node = nodes.at(i);
 
         if ( node.IsNotNull() && dynamic_cast<mitk::DiffusionImage<short>*>(node->GetData()) )
         {
             m_SelectedDWI = node;
             m_SelectedImage = node;
             m_SelectedImages.push_back(node);
         }
         else if( node.IsNotNull() && dynamic_cast<mitk::Image*>(node->GetData()) )
         {
             m_SelectedImages.push_back(node);
             m_SelectedImage = node;
             bool isbinary = false;
             node->GetPropertyValue<bool>("binary", isbinary);
             if (isbinary)
             {
                 m_MaskImageNode = node;
                 m_Controls->m_TissueMaskLabel->setText(m_MaskImageNode->GetName().c_str());
             }
         }
         else if ( node.IsNotNull() && dynamic_cast<mitk::FiberBundleX*>(node->GetData()) )
         {
             m_SelectedBundles2.push_back(node);
             if (m_Controls->m_RealTimeFibers->isChecked())
             {
                 m_SelectedBundles.push_back(node);
                 mitk::FiberBundleX::Pointer newFib = dynamic_cast<mitk::FiberBundleX*>(node->GetData());
                 if (newFib->GetNumFibers()!=m_Controls->m_FiberDensityBox->value())
                     GenerateFibers();
             }
             else
                 m_SelectedBundles.push_back(node);
         }
         else if ( node.IsNotNull() && dynamic_cast<mitk::PlanarEllipse*>(node->GetData()) )
         {
             m_SelectedFiducials.push_back(node);
             m_SelectedFiducial = node;
             m_SelectedBundles.clear();
             mitk::DataStorage::SetOfObjects::ConstPointer parents = GetDataStorage()->GetSources(node);
             for( mitk::DataStorage::SetOfObjects::const_iterator it = parents->begin(); it != parents->end(); ++it )
             {
                 mitk::DataNode::Pointer pNode = *it;
                 if ( pNode.IsNotNull() && dynamic_cast<mitk::FiberBundleX*>(pNode->GetData()) )
                     m_SelectedBundles.push_back(pNode);
             }
         }
     }
     UpdateGui();
 }
 
 
 void QmitkFiberfoxView::EnableCrosshairNavigation()
 {
     MITK_DEBUG << "EnableCrosshairNavigation";
 
     // enable the crosshair navigation
     if (mitk::ILinkedRenderWindowPart* linkedRenderWindow =
             dynamic_cast<mitk::ILinkedRenderWindowPart*>(this->GetRenderWindowPart()))
     {
         MITK_DEBUG << "enabling linked navigation";
         linkedRenderWindow->EnableLinkedNavigation(true);
         //        linkedRenderWindow->EnableSlicingPlanes(true);
     }
 
     if (m_Controls->m_RealTimeFibers->isChecked())
         GenerateFibers();
 }
 
 void QmitkFiberfoxView::DisableCrosshairNavigation()
 {
     MITK_DEBUG << "DisableCrosshairNavigation";
 
     // disable the crosshair navigation during the drawing
     if (mitk::ILinkedRenderWindowPart* linkedRenderWindow =
             dynamic_cast<mitk::ILinkedRenderWindowPart*>(this->GetRenderWindowPart()))
     {
         MITK_DEBUG << "disabling linked navigation";
         linkedRenderWindow->EnableLinkedNavigation(false);
         //        linkedRenderWindow->EnableSlicingPlanes(false);
     }
 }
 
 void QmitkFiberfoxView::NodeRemoved(const mitk::DataNode* node)
 {
     mitk::DataNode* nonConstNode = const_cast<mitk::DataNode*>(node);
     std::map<mitk::DataNode*, QmitkPlanarFigureData>::iterator it = m_DataNodeToPlanarFigureData.find(nonConstNode);
 
     if (dynamic_cast<FiberBundleX*>(node->GetData()))
     {
         m_SelectedBundles.clear();
         m_SelectedBundles2.clear();
     }
     else if (dynamic_cast<Image*>(node->GetData()))
         m_SelectedImages.clear();
 
     if( it != m_DataNodeToPlanarFigureData.end() )
     {
         QmitkPlanarFigureData& data = it->second;
 
         // remove observers
         data.m_Figure->RemoveObserver( data.m_EndPlacementObserverTag );
         data.m_Figure->RemoveObserver( data.m_SelectObserverTag );
         data.m_Figure->RemoveObserver( data.m_StartInteractionObserverTag );
         data.m_Figure->RemoveObserver( data.m_EndInteractionObserverTag );
 
         m_DataNodeToPlanarFigureData.erase( it );
     }
 }
 
 void QmitkFiberfoxView::NodeAdded( const mitk::DataNode* node )
 {
     // add observer for selection in renderwindow
     mitk::PlanarFigure* figure = dynamic_cast<mitk::PlanarFigure*>(node->GetData());
     bool isPositionMarker (false);
     node->GetBoolProperty("isContourMarker", isPositionMarker);
     if( figure && !isPositionMarker )
     {
         MITK_DEBUG << "figure added. will add interactor if needed.";
         mitk::PlanarFigureInteractor::Pointer figureInteractor
                 = dynamic_cast<mitk::PlanarFigureInteractor*>(node->GetDataInteractor().GetPointer());
 
         mitk::DataNode* nonConstNode = const_cast<mitk::DataNode*>( node );
         if(figureInteractor.IsNull())
         {
             figureInteractor = mitk::PlanarFigureInteractor::New();
             us::Module* planarFigureModule = us::ModuleRegistry::GetModule( "MitkPlanarFigure" );
             figureInteractor->LoadStateMachine("PlanarFigureInteraction.xml", planarFigureModule );
             figureInteractor->SetEventConfig( "PlanarFigureConfig.xml", planarFigureModule );
             figureInteractor->SetDataNode( nonConstNode );
         }
 
         MITK_DEBUG << "will now add observers for planarfigure";
         QmitkPlanarFigureData data;
         data.m_Figure = figure;
 
         //        // add observer for event when figure has been placed
         typedef itk::SimpleMemberCommand< QmitkFiberfoxView > SimpleCommandType;
         //        SimpleCommandType::Pointer initializationCommand = SimpleCommandType::New();
         //        initializationCommand->SetCallbackFunction( this, &QmitkFiberfoxView::PlanarFigureInitialized );
         //        data.m_EndPlacementObserverTag = figure->AddObserver( mitk::EndPlacementPlanarFigureEvent(), initializationCommand );
 
         // add observer for event when figure is picked (selected)
         typedef itk::MemberCommand< QmitkFiberfoxView > MemberCommandType;
         MemberCommandType::Pointer selectCommand = MemberCommandType::New();
         selectCommand->SetCallbackFunction( this, &QmitkFiberfoxView::PlanarFigureSelected );
         data.m_SelectObserverTag = figure->AddObserver( mitk::SelectPlanarFigureEvent(), selectCommand );
 
         // add observer for event when interaction with figure starts
         SimpleCommandType::Pointer startInteractionCommand = SimpleCommandType::New();
         startInteractionCommand->SetCallbackFunction( this, &QmitkFiberfoxView::DisableCrosshairNavigation);
         data.m_StartInteractionObserverTag = figure->AddObserver( mitk::StartInteractionPlanarFigureEvent(), startInteractionCommand );
 
         // add observer for event when interaction with figure starts
         SimpleCommandType::Pointer endInteractionCommand = SimpleCommandType::New();
         endInteractionCommand->SetCallbackFunction( this, &QmitkFiberfoxView::EnableCrosshairNavigation);
         data.m_EndInteractionObserverTag = figure->AddObserver( mitk::EndInteractionPlanarFigureEvent(), endInteractionCommand );
 
         m_DataNodeToPlanarFigureData[nonConstNode] = data;
     }
 }
 
 void QmitkFiberfoxView::PlanarFigureSelected( itk::Object* object, const itk::EventObject& )
 {
     mitk::TNodePredicateDataType<mitk::PlanarFigure>::Pointer isPf = mitk::TNodePredicateDataType<mitk::PlanarFigure>::New();
 
     mitk::DataStorage::SetOfObjects::ConstPointer allPfs = this->GetDataStorage()->GetSubset( isPf );
     for ( mitk::DataStorage::SetOfObjects::const_iterator it = allPfs->begin(); it!=allPfs->end(); ++it)
     {
         mitk::DataNode* node = *it;
 
         if( node->GetData() == object )
         {
             node->SetSelected(true);
             m_SelectedFiducial = node;
         }
         else
             node->SetSelected(false);
     }
     UpdateGui();
     this->RequestRenderWindowUpdate();
 }
 
 void QmitkFiberfoxView::SetFocus()
 {
     m_Controls->m_CircleButton->setFocus();
 }
 
 
 void QmitkFiberfoxView::SetOutputPath()
 {
     // SELECT FOLDER DIALOG
 
     string outputPath = QFileDialog::getExistingDirectory(NULL, "Save images to...", QString(outputPath.c_str())).toStdString();
 
     if (outputPath.empty())
         m_Controls->m_SavePathEdit->setText("-");
     else
     {
         outputPath += "/";
         m_Controls->m_SavePathEdit->setText(QString(outputPath.c_str()));
     }
 }
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 22e1d53838..96d82570d6 100644
--- a/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkPreprocessingView.cpp
+++ b/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkPreprocessingView.cpp
@@ -1,1766 +1,1775 @@
 /*===================================================================
 
 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 <QMessageBox>
 
 // itk includes
 #include "itkTimeProbe.h"
 #include "itkB0ImageExtractionImageFilter.h"
 #include "itkB0ImageExtractionToSeparateImageFilter.h"
 #include "itkBrainMaskExtractionImageFilter.h"
 #include "itkCastImageFilter.h"
 #include "itkVectorContainer.h"
 #include <itkElectrostaticRepulsionDiffusionGradientReductionFilter.h>
 #include <itkMergeDiffusionImagesFilter.h>
 #include <itkDwiGradientLengthCorrectionFilter.h>
 #include <itkDwiNormilzationFilter.h>
 
 // Multishell includes
 #include <itkRadialMultishellToSingleshellImageFilter.h>
 
 // Multishell Functors
 #include <itkADCAverageFunctor.h>
 #include <itkKurtosisFitFunctor.h>
 #include <itkBiExpFitFunctor.h>
 #include <itkADCFitFunctor.h>
 
 // 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 <mitkPointSet.h>
 #include <itkAdcImageFilter.h>
 #include <itkBrainMaskExtractionImageFilter.h>
 #include <mitkImageCast.h>
 #include <mitkRotationOperation.h>
 #include <QTableWidgetItem>
 #include <QTableWidget>
 #include <mitkInteractionConst.h>
 #include <mitkImageAccessByItk.h>
 #include <itkResampleDwiImageFilter.h>
 #include <itkResampleImageFilter.h>
 #include <itkImageDuplicator.h>
 #include <itkMaskImageFilter.h>
 #include <mitkNodePredicateProperty.h>
 #include <mitkNodePredicateAnd.h>
 #include <mitkNodePredicateNot.h>
 #include <mitkNodePredicateOr.h>
 #include <itkCropImageFilter.h>
 #include <itkDiffusionTensor3DReconstructionImageFilter.h>
 #include <itkRemoveDwiChannelFilter.h>
 #include <itkExtractDwiChannelFilter.h>
 
 const std::string QmitkPreprocessingView::VIEW_ID =
         "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)
 {
 }
 
 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);
 
         m_Controls->m_DirectionMatrixTable->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
         m_Controls->m_DirectionMatrixTable->verticalHeader()->setResizeMode(QHeaderView::Stretch);
     }
 }
 
 void QmitkPreprocessingView::StdMultiWidgetAvailable (QmitkStdMultiWidget &stdMultiWidget)
 {
     m_MultiWidget = &stdMultiWidget;
 }
 
 void QmitkPreprocessingView::StdMultiWidgetNotAvailable()
 {
     m_MultiWidget = NULL;
 }
 
 void QmitkPreprocessingView::CreateConnections()
 {
     if ( m_Controls )
     {
         m_Controls->m_NormalizationMaskBox->SetDataStorage(this->GetDataStorage());
         mitk::TNodePredicateDataType<mitk::Image>::Pointer isMitkImage = mitk::TNodePredicateDataType<mitk::Image>::New();
         mitk::NodePredicateDataType::Pointer isDwi = mitk::NodePredicateDataType::New("DiffusionImage");
         mitk::NodePredicateDataType::Pointer isDti = mitk::NodePredicateDataType::New("TensorImage");
         mitk::NodePredicateDataType::Pointer isQbi = mitk::NodePredicateDataType::New("QBallImage");
         mitk::NodePredicateOr::Pointer isDiffusionImage = mitk::NodePredicateOr::New(isDwi, isDti);
         isDiffusionImage = mitk::NodePredicateOr::New(isDiffusionImage, isQbi);
         mitk::NodePredicateNot::Pointer noDiffusionImage = mitk::NodePredicateNot::New(isDiffusionImage);
         mitk::NodePredicateAnd::Pointer finalPredicate = mitk::NodePredicateAnd::New(isMitkImage, noDiffusionImage);
         mitk::NodePredicateProperty::Pointer isBinaryPredicate = mitk::NodePredicateProperty::New("binary", mitk::BoolProperty::New(true));
         finalPredicate = mitk::NodePredicateAnd::New(finalPredicate, isBinaryPredicate);
         m_Controls->m_NormalizationMaskBox->SetPredicate(finalPredicate);
 
         m_Controls->m_ExtractBrainMask->setVisible(false);
         m_Controls->m_BrainMaskIterationsBox->setVisible(false);
         m_Controls->m_ResampleIntFrame->setVisible(false);
         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_ProjectSignalButton), SIGNAL(clicked()), this, SLOT(DoProjectSignal()) );
         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()) );
         connect( (QObject*)(m_Controls->m_NormalizeImageValuesButton), SIGNAL(clicked()), this, SLOT(DoDwiNormalization()) );
         connect( (QObject*)(m_Controls->m_ModifyDirection), SIGNAL(clicked()), this, SLOT(DoApplyDirectionMatrix()) );
         connect( (QObject*)(m_Controls->m_ModifySpacingButton), SIGNAL(clicked()), this, SLOT(DoApplySpacing()) );
         connect( (QObject*)(m_Controls->m_ModifyOriginButton), SIGNAL(clicked()), this, SLOT(DoApplyOrigin()) );
         connect( (QObject*)(m_Controls->m_ResampleImageButton), SIGNAL(clicked()), this, SLOT(DoResampleImage()) );
         connect( (QObject*)(m_Controls->m_ResampleTypeBox), SIGNAL(currentIndexChanged(int)), this, SLOT(DoUpdateInterpolationGui(int)) );
         connect( (QObject*)(m_Controls->m_CropImageButton), SIGNAL(clicked()), this, SLOT(DoCropImage()) );
         connect( (QObject*)(m_Controls->m_RemoveGradientButton), SIGNAL(clicked()), this, SLOT(DoRemoveGradient()) );
         connect( (QObject*)(m_Controls->m_ExtractGradientButton), SIGNAL(clicked()), this, SLOT(DoExtractGradient()) );
 
 
         //        connect( (QObject*)(m_Controls->m_ExtractBrainMask), SIGNAL(clicked()), this, SLOT(DoExtractBrainMask()) );
     }
 }
 
 void QmitkPreprocessingView::DoRemoveGradient()
 {
     if (m_DiffusionImage.IsNull())
         return;
 
     std::vector< unsigned int > channelsToRemove; channelsToRemove.push_back(m_Controls->m_RemoveGradientBox->value());
     itk::RemoveDwiChannelFilter< short >::Pointer filter = itk::RemoveDwiChannelFilter< short >::New();
     filter->SetInput(m_DiffusionImage->GetVectorImage());
     filter->SetChannelIndices(channelsToRemove);
     filter->SetDirections(m_DiffusionImage->GetDirections());
     filter->Update();
 
     MitkDwiType::Pointer image = MitkDwiType::New();
     image->SetVectorImage( filter->GetOutput() );
     image->SetReferenceBValue( m_DiffusionImage->GetReferenceBValue() );
     image->SetDirections( filter->GetNewDirections() );
     image->InitializeFromVectorImage();
 
     mitk::DataNode::Pointer imageNode = mitk::DataNode::New();
     imageNode->SetData( image );
     QString name = m_SelectedDiffusionNodes.back()->GetName().c_str();
     imageNode->SetName((name+"_removedgradients").toStdString().c_str());
     GetDefaultDataStorage()->Add(imageNode, m_SelectedDiffusionNodes.back());
     mitk::RenderingManager::GetInstance()->InitializeViews( imageNode->GetData()->GetTimeGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true );
     mitk::RenderingManager::GetInstance()->RequestUpdateAll();
 }
 
 void QmitkPreprocessingView::DoExtractGradient()
 {
     if (m_DiffusionImage.IsNull())
         return;
 
     unsigned int channel = m_Controls->m_ExtractGradientBox->value();
     itk::ExtractDwiChannelFilter< short >::Pointer filter = itk::ExtractDwiChannelFilter< short >::New();
     filter->SetInput(m_DiffusionImage->GetVectorImage());
     filter->SetChannelIndex(channel);
     filter->Update();
 
     mitk::Image::Pointer mitkImage = mitk::Image::New();
     mitkImage->InitializeByItk( filter->GetOutput() );
     mitkImage->SetImportChannel( filter->GetOutput()->GetBufferPointer() );
 
     mitk::DataNode::Pointer imageNode = mitk::DataNode::New();
     imageNode->SetData( mitkImage );
     QString name = m_SelectedDiffusionNodes.back()->GetName().c_str();
     imageNode->SetName((name+"_direction-"+QString::number(channel)).toStdString().c_str());
     GetDefaultDataStorage()->Add(imageNode, m_SelectedDiffusionNodes.back());
 
     mitk::RenderingManager::GetInstance()->InitializeViews(imageNode->GetData()->GetTimeGeometry(),mitk::RenderingManager::REQUEST_UPDATE_ALL, true);
 }
 
 void QmitkPreprocessingView::DoCropImage()
 {
     if (m_DiffusionImage.IsNotNull())
     {
         ItkDwiType::SizeType lower;
         ItkDwiType::SizeType upper;
         lower[0] = m_Controls->m_XstartBox->value();
         lower[1] = m_Controls->m_YstartBox->value();
         lower[2] = m_Controls->m_ZstartBox->value();
         upper[0] = m_Controls->m_XendBox->value();
         upper[1] = m_Controls->m_YendBox->value();
         upper[2] = m_Controls->m_ZendBox->value();
 
         itk::CropImageFilter< ItkDwiType, ItkDwiType >::Pointer cropper = itk::CropImageFilter< ItkDwiType, ItkDwiType >::New();
         cropper->SetLowerBoundaryCropSize(lower);
         cropper->SetUpperBoundaryCropSize(upper);
         cropper->SetInput(m_DiffusionImage->GetVectorImage());
         cropper->Update();
 
         MitkDwiType::Pointer image = MitkDwiType::New();
         image->SetVectorImage( cropper->GetOutput() );
         image->SetReferenceBValue( m_DiffusionImage->GetReferenceBValue() );
         image->SetDirections( m_DiffusionImage->GetDirections() );
         image->InitializeFromVectorImage();
 
         mitk::DataNode::Pointer imageNode = mitk::DataNode::New();
         imageNode->SetData( image );
         QString name = m_SelectedDiffusionNodes.back()->GetName().c_str();
         imageNode->SetName((name+"_cropped").toStdString().c_str());
         GetDefaultDataStorage()->Add(imageNode, m_SelectedDiffusionNodes.back());
         mitk::RenderingManager::GetInstance()->InitializeViews( imageNode->GetData()->GetTimeGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true );
         mitk::RenderingManager::GetInstance()->RequestUpdateAll();
 
         mitk::RenderingManager::GetInstance()->InitializeViews( imageNode->GetData()->GetTimeGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true );
         mitk::RenderingManager::GetInstance()->RequestUpdateAll();
     }
     else if(m_SelectedImage.IsNotNull())
     {
         AccessFixedDimensionByItk(m_SelectedImage, TemplatedCropImage,3);
     }
 }
 
 template < typename TPixel, unsigned int VImageDimension >
 void QmitkPreprocessingView::TemplatedCropImage( itk::Image<TPixel, VImageDimension>* itkImage)
 {
     ItkDwiType::SizeType lower;
     ItkDwiType::SizeType upper;
     lower[0] = m_Controls->m_XstartBox->value();
     lower[1] = m_Controls->m_YstartBox->value();
     lower[2] = m_Controls->m_ZstartBox->value();
     upper[0] = m_Controls->m_XendBox->value();
     upper[1] = m_Controls->m_YendBox->value();
     upper[2] = m_Controls->m_ZendBox->value();
 
     typedef itk::Image<TPixel, VImageDimension> ImageType;
     typename itk::CropImageFilter< ImageType, ImageType >::Pointer cropper = itk::CropImageFilter< ImageType, ImageType >::New();
     cropper->SetLowerBoundaryCropSize(lower);
     cropper->SetUpperBoundaryCropSize(upper);
     cropper->SetInput(itkImage);
     cropper->Update();
 
     mitk::Image::Pointer image = mitk::Image::New();
     image->InitializeByItk( cropper->GetOutput() );
     image->SetVolume( cropper->GetOutput()->GetBufferPointer() );
     mitk::DataNode::Pointer imageNode = mitk::DataNode::New();
     imageNode->SetData( image );
     QString name = m_SelectedImageNode->GetName().c_str();
 
     imageNode->SetName((name+"_cropped").toStdString().c_str());
     GetDefaultDataStorage()->Add(imageNode, m_SelectedImageNode);
 
     mitk::RenderingManager::GetInstance()->InitializeViews( imageNode->GetData()->GetTimeGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true );
     mitk::RenderingManager::GetInstance()->RequestUpdateAll();
 }
 
 void QmitkPreprocessingView::DoApplySpacing()
 {
     if (m_DiffusionImage.IsNotNull())
     {
         mitk::Vector3D spacing;
         spacing[0] = m_Controls->m_HeaderSpacingX->value();
         spacing[1] = m_Controls->m_HeaderSpacingY->value();
         spacing[2] = m_Controls->m_HeaderSpacingZ->value();
 
         MitkDwiType::Pointer image = m_DiffusionImage->Clone();
         image->GetVectorImage()->SetSpacing(spacing);
         image->InitializeFromVectorImage();
 
         mitk::DataNode::Pointer imageNode = mitk::DataNode::New();
         imageNode->SetData( image );
         QString name = m_SelectedDiffusionNodes.back()->GetName().c_str();
         imageNode->SetName((name+"_newspacing").toStdString().c_str());
         GetDefaultDataStorage()->Add(imageNode, m_SelectedDiffusionNodes.back());
         mitk::RenderingManager::GetInstance()->InitializeViews( imageNode->GetData()->GetTimeGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true );
         mitk::RenderingManager::GetInstance()->RequestUpdateAll();
     }
     else if(m_SelectedImage.IsNotNull())
     {
         AccessFixedDimensionByItk(m_SelectedImage, TemplatedSetImageSpacing,3);
     }
 }
 
 template < typename TPixel, unsigned int VImageDimension >
 void QmitkPreprocessingView::TemplatedSetImageSpacing( itk::Image<TPixel, VImageDimension>* itkImage)
 {
     mitk::Vector3D spacing;
     spacing[0] = m_Controls->m_HeaderSpacingX->value();
     spacing[1] = m_Controls->m_HeaderSpacingY->value();
     spacing[2] = m_Controls->m_HeaderSpacingZ->value();
 
     typedef itk::ImageDuplicator< itk::Image<TPixel, VImageDimension> > DuplicateFilterType;
     typename DuplicateFilterType::Pointer duplicator = DuplicateFilterType::New();
     duplicator->SetInputImage( itkImage );
     duplicator->Update();
     typename itk::Image<TPixel, VImageDimension>::Pointer newImage = duplicator->GetOutput();
     newImage->SetSpacing(spacing);
 
     mitk::Image::Pointer image = mitk::Image::New();
     image->InitializeByItk( newImage.GetPointer() );
     image->SetVolume( newImage->GetBufferPointer() );
     mitk::DataNode::Pointer imageNode = mitk::DataNode::New();
     imageNode->SetData( image );
     QString name = m_SelectedImageNode->GetName().c_str();
 
     imageNode->SetName((name+"_newspacing").toStdString().c_str());
     GetDefaultDataStorage()->Add(imageNode, m_SelectedImageNode);
     mitk::RenderingManager::GetInstance()->InitializeViews( imageNode->GetData()->GetTimeGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true );
     mitk::RenderingManager::GetInstance()->RequestUpdateAll();
 }
 
 void QmitkPreprocessingView::DoApplyOrigin()
 {
     if (m_DiffusionImage.IsNotNull())
     {
         mitk::Vector3D origin;
         origin[0] = m_Controls->m_HeaderOriginX->value();
         origin[1] = m_Controls->m_HeaderOriginY->value();
         origin[2] = m_Controls->m_HeaderOriginZ->value();
 
         MitkDwiType::Pointer image = m_DiffusionImage->Clone();
         image->GetVectorImage()->SetOrigin(origin);
         image->InitializeFromVectorImage();
 
         mitk::DataNode::Pointer imageNode = mitk::DataNode::New();
         imageNode->SetData( image );
         QString name = m_SelectedDiffusionNodes.back()->GetName().c_str();
         imageNode->SetName((name+"_neworigin").toStdString().c_str());
         GetDefaultDataStorage()->Add(imageNode, m_SelectedDiffusionNodes.back());
         mitk::RenderingManager::GetInstance()->InitializeViews( imageNode->GetData()->GetTimeGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true );
         mitk::RenderingManager::GetInstance()->RequestUpdateAll();
     }
     else if(m_SelectedImage.IsNotNull())
     {
         AccessFixedDimensionByItk(m_SelectedImage, TemplatedSetImageOrigin,3);
     }
 }
 
 template < typename TPixel, unsigned int VImageDimension >
 void QmitkPreprocessingView::TemplatedSetImageOrigin( itk::Image<TPixel, VImageDimension>* itkImage)
 {
     mitk::Vector3D origin;
     origin[0] = m_Controls->m_HeaderOriginX->value();
     origin[1] = m_Controls->m_HeaderOriginY->value();
     origin[2] = m_Controls->m_HeaderOriginZ->value();
 
     typedef itk::ImageDuplicator< itk::Image<TPixel, VImageDimension> > DuplicateFilterType;
     typename DuplicateFilterType::Pointer duplicator = DuplicateFilterType::New();
     duplicator->SetInputImage( itkImage );
     duplicator->Update();
     typename itk::Image<TPixel, VImageDimension>::Pointer newImage = duplicator->GetOutput();
     newImage->SetOrigin(origin);
 
     mitk::Image::Pointer image = mitk::Image::New();
     image->InitializeByItk( newImage.GetPointer() );
     image->SetVolume( newImage->GetBufferPointer() );
     mitk::DataNode::Pointer imageNode = mitk::DataNode::New();
     imageNode->SetData( image );
     QString name = m_SelectedImageNode->GetName().c_str();
 
     imageNode->SetName((name+"_neworigin").toStdString().c_str());
     GetDefaultDataStorage()->Add(imageNode, m_SelectedImageNode);
     mitk::RenderingManager::GetInstance()->InitializeViews( imageNode->GetData()->GetTimeGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true );
     mitk::RenderingManager::GetInstance()->RequestUpdateAll();
 }
 
 void QmitkPreprocessingView::DoUpdateInterpolationGui(int i)
 {
     switch (i)
     {
     case 0:
     {
         m_Controls->m_ResampleIntFrame->setVisible(false);
         m_Controls->m_ResampleDoubleFrame->setVisible(true);
         break;
     }
     case 1:
     {
         m_Controls->m_ResampleIntFrame->setVisible(false);
         m_Controls->m_ResampleDoubleFrame->setVisible(true);
 
         if (m_DiffusionImage.IsNotNull())
         {
             ItkDwiType::Pointer itkDwi = m_DiffusionImage->GetVectorImage();
             m_Controls->m_ResampleDoubleX->setValue(itkDwi->GetSpacing()[0]);
             m_Controls->m_ResampleDoubleY->setValue(itkDwi->GetSpacing()[1]);
             m_Controls->m_ResampleDoubleZ->setValue(itkDwi->GetSpacing()[2]);
         }
         else if (m_SelectedImage.IsNotNull())
         {
             mitk::BaseGeometry* geom = m_SelectedImage->GetGeometry();
             m_Controls->m_ResampleDoubleX->setValue(geom->GetSpacing()[0]);
             m_Controls->m_ResampleDoubleY->setValue(geom->GetSpacing()[1]);
             m_Controls->m_ResampleDoubleZ->setValue(geom->GetSpacing()[2]);
         }
         break;
     }
     case 2:
     {
         m_Controls->m_ResampleIntFrame->setVisible(true);
         m_Controls->m_ResampleDoubleFrame->setVisible(false);
 
         if (m_DiffusionImage.IsNotNull())
         {
             ItkDwiType::Pointer itkDwi = m_DiffusionImage->GetVectorImage();
             m_Controls->m_ResampleIntX->setValue(itkDwi->GetLargestPossibleRegion().GetSize(0));
             m_Controls->m_ResampleIntY->setValue(itkDwi->GetLargestPossibleRegion().GetSize(1));
             m_Controls->m_ResampleIntZ->setValue(itkDwi->GetLargestPossibleRegion().GetSize(2));
         }
         else if (m_SelectedImage.IsNotNull())
         {
             mitk::BaseGeometry* geom = m_SelectedImage->GetGeometry();
             m_Controls->m_ResampleIntX->setValue(geom->GetExtent(0));
             m_Controls->m_ResampleIntY->setValue(geom->GetExtent(1));
             m_Controls->m_ResampleIntZ->setValue(geom->GetExtent(2));
         }
         break;
     }
     default:
     {
         m_Controls->m_ResampleIntFrame->setVisible(false);
         m_Controls->m_ResampleDoubleFrame->setVisible(true);
     }
     }
 }
 
 void QmitkPreprocessingView::DoExtractBrainMask()
 {
     //    if (m_SelectedImage.IsNull())
     //        return;
 
     //    typedef itk::Image<unsigned short, 3> ShortImageType;
     //    ShortImageType::Pointer itkImage = ShortImageType::New();
     //    mitk::CastToItkImage(m_SelectedImage, itkImage);
 
     //    typedef itk::BrainMaskExtractionImageFilter< unsigned char > FilterType;
     //    FilterType::Pointer filter = FilterType::New();
     //    filter->SetInput(itkImage);
     //    filter->SetMaxNumIterations(m_Controls->m_BrainMaskIterationsBox->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 );
     //    imageNode->SetName("BRAINMASK");
     //    GetDefaultDataStorage()->Add(imageNode);
 }
 
 void QmitkPreprocessingView::DoResampleImage()
 {
     if (m_DiffusionImage.IsNotNull())
     {
         typedef itk::ResampleDwiImageFilter< short > ResampleFilter;
         ResampleFilter::Pointer resampler = ResampleFilter::New();
         resampler->SetInput(m_DiffusionImage->GetVectorImage());
 
         switch (m_Controls->m_ResampleTypeBox->currentIndex())
         {
         case 0:
         {
             itk::Vector< double, 3 > samplingFactor;
             samplingFactor[0] = m_Controls->m_ResampleDoubleX->value();
             samplingFactor[1] = m_Controls->m_ResampleDoubleY->value();
             samplingFactor[2] = m_Controls->m_ResampleDoubleZ->value();
             resampler->SetSamplingFactor(samplingFactor);
             break;
         }
         case 1:
         {
             itk::Vector< double, 3 > newSpacing;
             newSpacing[0] = m_Controls->m_ResampleDoubleX->value();
             newSpacing[1] = m_Controls->m_ResampleDoubleY->value();
             newSpacing[2] = m_Controls->m_ResampleDoubleZ->value();
             resampler->SetNewSpacing(newSpacing);
             break;
         }
         case 2:
         {
             itk::ImageRegion<3> newRegion;
             newRegion.SetSize(0, m_Controls->m_ResampleIntX->value());
             newRegion.SetSize(1, m_Controls->m_ResampleIntY->value());
             newRegion.SetSize(2, m_Controls->m_ResampleIntZ->value());
             resampler->SetNewImageSize(newRegion);
             break;
         }
         default:
         {
             MITK_WARN << "Unknown resampling parameters!";
             return;
         }
         }
 
         QString outAdd;
         switch (m_Controls->m_InterpolatorBox->currentIndex())
         {
         case 0:
         {
             resampler->SetInterpolation(ResampleFilter::Interpolate_NearestNeighbour);
             outAdd = "NearestNeighbour";
             break;
         }
         case 1:
         {
             resampler->SetInterpolation(ResampleFilter::Interpolate_Linear);
             outAdd = "Linear";
             break;
         }
         case 2:
         {
             resampler->SetInterpolation(ResampleFilter::Interpolate_BSpline);
             outAdd = "BSpline";
             break;
         }
         case 3:
         {
             resampler->SetInterpolation(ResampleFilter::Interpolate_WindowedSinc);
             outAdd = "WindowedSinc";
             break;
         }
         default:
         {
             resampler->SetInterpolation(ResampleFilter::Interpolate_NearestNeighbour);
             outAdd = "NearestNeighbour";
         }
         }
 
         resampler->Update();
 
         typedef mitk::DiffusionImage<DiffusionPixelType>  DiffusionImageType;
         DiffusionImageType::Pointer image = DiffusionImageType::New();
         image->SetVectorImage( resampler->GetOutput() );
         image->SetReferenceBValue( m_DiffusionImage->GetReferenceBValue() );
         image->SetDirections( m_DiffusionImage->GetDirections() );
         image->InitializeFromVectorImage();
 
         mitk::DataNode::Pointer imageNode = mitk::DataNode::New();
         imageNode->SetData( image );
         QString name = m_SelectedDiffusionNodes.back()->GetName().c_str();
 
         imageNode->SetName((name+"_resampled_"+outAdd).toStdString().c_str());
         GetDefaultDataStorage()->Add(imageNode, m_SelectedDiffusionNodes.back());
     }
     else if (m_SelectedImage.IsNotNull())
     {
         AccessFixedDimensionByItk(m_SelectedImage, TemplatedResampleImage,3);
     }
 }
 
 
 template < typename TPixel, unsigned int VImageDimension >
 void QmitkPreprocessingView::TemplatedResampleImage( itk::Image<TPixel, VImageDimension>* itkImage)
 {
     itk::Vector< double, 3 > newSpacing;
     itk::ImageRegion<3>   newRegion;
 
     switch (m_Controls->m_ResampleTypeBox->currentIndex())
     {
     case 0:
     {
         itk::Vector< double, 3 > sampling;
         sampling[0] = m_Controls->m_ResampleDoubleX->value();
         sampling[1] = m_Controls->m_ResampleDoubleY->value();
         sampling[2] = m_Controls->m_ResampleDoubleZ->value();
 
         newSpacing = itkImage->GetSpacing();
         newSpacing[0] /= sampling[0];
         newSpacing[1] /= sampling[1];
         newSpacing[2] /= sampling[2];
         newRegion = itkImage->GetLargestPossibleRegion();
         newRegion.SetSize(0, newRegion.GetSize(0)*sampling[0]);
         newRegion.SetSize(1, newRegion.GetSize(1)*sampling[1]);
         newRegion.SetSize(2, newRegion.GetSize(2)*sampling[2]);
 
         break;
     }
     case 1:
     {
         newSpacing[0] = m_Controls->m_ResampleDoubleX->value();
         newSpacing[1] = m_Controls->m_ResampleDoubleY->value();
         newSpacing[2] = m_Controls->m_ResampleDoubleZ->value();
 
         itk::Vector< double, 3 > oldSpacing = itkImage->GetSpacing();
         itk::Vector< double, 3 > sampling;
         sampling[0] = oldSpacing[0]/newSpacing[0];
         sampling[1] = oldSpacing[1]/newSpacing[1];
         sampling[2] = oldSpacing[2]/newSpacing[2];
         newRegion = itkImage->GetLargestPossibleRegion();
         newRegion.SetSize(0, newRegion.GetSize(0)*sampling[0]);
         newRegion.SetSize(1, newRegion.GetSize(1)*sampling[1]);
         newRegion.SetSize(2, newRegion.GetSize(2)*sampling[2]);
         break;
     }
     case 2:
     {
         newRegion.SetSize(0, m_Controls->m_ResampleIntX->value());
         newRegion.SetSize(1, m_Controls->m_ResampleIntY->value());
         newRegion.SetSize(2, m_Controls->m_ResampleIntZ->value());
 
         itk::ImageRegion<3> oldRegion = itkImage->GetLargestPossibleRegion();
         itk::Vector< double, 3 > sampling;
         sampling[0] = (double)newRegion.GetSize(0)/oldRegion.GetSize(0);
         sampling[1] = (double)newRegion.GetSize(1)/oldRegion.GetSize(1);
         sampling[2] = (double)newRegion.GetSize(2)/oldRegion.GetSize(2);
 
         newSpacing = itkImage->GetSpacing();
         newSpacing[0] /= sampling[0];
         newSpacing[1] /= sampling[1];
         newSpacing[2] /= sampling[2];
         break;
     }
     default:
     {
         MITK_WARN << "Unknown resampling parameters!";
         return;
     }
     }
 
     itk::Point<double,3> origin = itkImage->GetOrigin();
     origin[0] -= itkImage->GetSpacing()[0]/2;
     origin[1] -= itkImage->GetSpacing()[1]/2;
     origin[2] -= itkImage->GetSpacing()[2]/2;
     origin[0] += newSpacing[0]/2;
     origin[1] += newSpacing[1]/2;
     origin[2] += newSpacing[2]/2;
 
     typedef itk::Image<TPixel, VImageDimension> ImageType;
     typename ImageType::Pointer outImage = ImageType::New();
     outImage->SetSpacing( newSpacing );
     outImage->SetOrigin( origin );
     outImage->SetDirection( itkImage->GetDirection() );
     outImage->SetLargestPossibleRegion( newRegion );
     outImage->SetBufferedRegion( newRegion );
     outImage->SetRequestedRegion( newRegion );
     outImage->Allocate();
 
     typedef itk::ResampleImageFilter<ImageType, ImageType> ResampleFilter;
     typename ResampleFilter::Pointer resampler = ResampleFilter::New();
     resampler->SetInput(itkImage);
     resampler->SetOutputParametersFromImage(outImage);
 
     QString outAdd;
     switch (m_Controls->m_InterpolatorBox->currentIndex())
     {
     case 0:
     {
         typename itk::NearestNeighborInterpolateImageFunction<ImageType>::Pointer interp = itk::NearestNeighborInterpolateImageFunction<ImageType>::New();
         resampler->SetInterpolator(interp);
         outAdd = "NearestNeighbour";
         break;
     }
     case 1:
     {
         typename itk::LinearInterpolateImageFunction<ImageType>::Pointer interp = itk::LinearInterpolateImageFunction<ImageType>::New();
         resampler->SetInterpolator(interp);
         outAdd = "Linear";
         break;
     }
     case 2:
     {
         typename itk::BSplineInterpolateImageFunction<ImageType>::Pointer interp = itk::BSplineInterpolateImageFunction<ImageType>::New();
         resampler->SetInterpolator(interp);
         outAdd = "BSpline";
         break;
     }
     case 3:
     {
         typename itk::WindowedSincInterpolateImageFunction<ImageType, 3>::Pointer interp = itk::WindowedSincInterpolateImageFunction<ImageType, 3>::New();
         resampler->SetInterpolator(interp);
         outAdd = "WindowedSinc";
         break;
     }
     default:
     {
         typename itk::NearestNeighborInterpolateImageFunction<ImageType>::Pointer interp = itk::NearestNeighborInterpolateImageFunction<ImageType>::New();
         resampler->SetInterpolator(interp);
         outAdd = "NearestNeighbour";
     }
     }
 
     resampler->Update();
 
     mitk::Image::Pointer image = mitk::Image::New();
     image->InitializeByItk( resampler->GetOutput() );
     image->SetVolume( resampler->GetOutput()->GetBufferPointer() );
     mitk::DataNode::Pointer imageNode = mitk::DataNode::New();
     imageNode->SetData( image );
     QString name = m_SelectedImageNode->GetName().c_str();
 
     imageNode->SetName((name+"_resampled_"+outAdd).toStdString().c_str());
     GetDefaultDataStorage()->Add(imageNode, m_SelectedImageNode);
 }
 
 void QmitkPreprocessingView::DoApplyDirectionMatrix()
 {
     if (m_DiffusionImage.IsNotNull())
     {
         MitkDwiType::Pointer newDwi = m_DiffusionImage->Clone();
         ItkDwiType::DirectionType newDirection;
         for (int r=0; r<3; r++)
             for (int c=0; c<3; c++)
             {
                 QTableWidgetItem* item = m_Controls->m_DirectionMatrixTable->item(r,c);
                 if (!item)
                     return;
                 newDirection[r][c] = item->text().toDouble();
             }
 
         ItkDwiType::Pointer itkDwi = newDwi->GetVectorImage();
 
         typedef mitk::DiffusionImage<DiffusionPixelType>  MitkDwiType;
         vnl_matrix_fixed< double,3,3 > oldInverseDirection = itkDwi->GetDirection().GetInverse();
         MitkDwiType::GradientDirectionContainerType::Pointer oldGradients = m_DiffusionImage->GetDirectionsWithoutMeasurementFrame();
         MitkDwiType::GradientDirectionContainerType::Pointer newGradients = MitkDwiType::GradientDirectionContainerType::New();
 
         for (unsigned int i=0; i<oldGradients->Size(); i++)
         {
             MitkDwiType::GradientDirectionType g = oldGradients->GetElement(i);
             double mag = g.magnitude();
             MitkDwiType::GradientDirectionType newG = oldInverseDirection*g;
             newG = newDirection.GetVnlMatrix()*newG;
             newG.normalize();
             newGradients->InsertElement(i, newG*mag);
         }
 
         newDwi->SetDirections(newGradients);
         itkDwi->SetDirection(newDirection);
         newDwi->InitializeFromVectorImage();
 
         mitk::DataNode::Pointer imageNode = mitk::DataNode::New();
         imageNode->SetData( newDwi );
         QString name = m_SelectedDiffusionNodes.back()->GetName().c_str();
         imageNode->SetName((name+"_newdirection").toStdString().c_str());
         GetDefaultDataStorage()->Add(imageNode, m_SelectedDiffusionNodes.back());
 
         mitk::RenderingManager::GetInstance()->InitializeViews( imageNode->GetData()->GetTimeGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true );
         mitk::RenderingManager::GetInstance()->RequestUpdateAll();
     }
     else if (m_SelectedImage.IsNotNull())
     {
         AccessFixedDimensionByItk(m_SelectedImage, TemplatedApplyRotation,3);
     }
 }
 
 template < typename TPixel, unsigned int VImageDimension >
 void QmitkPreprocessingView::TemplatedApplyRotation( itk::Image<TPixel, VImageDimension>* itkImage)
 {
     ItkDwiType::DirectionType newDirection;
     for (int r=0; r<3; r++)
         for (int c=0; c<3; c++)
         {
             QTableWidgetItem* item = m_Controls->m_DirectionMatrixTable->item(r,c);
             if (!item)
                 return;
             newDirection[r][c] = item->text().toDouble();
         }
     typedef itk::Image<TPixel, VImageDimension> ImageType;
 
     typename ImageType::Pointer newImage = ImageType::New();
     newImage->SetSpacing( itkImage->GetSpacing() );
     newImage->SetOrigin( itkImage->GetOrigin() );
     newImage->SetDirection( newDirection );
     newImage->SetLargestPossibleRegion( itkImage->GetLargestPossibleRegion() );
     newImage->SetBufferedRegion( itkImage->GetLargestPossibleRegion() );
     newImage->SetRequestedRegion( itkImage->GetLargestPossibleRegion() );
     newImage->Allocate();
     newImage->FillBuffer(0);
 
     itk::ImageRegionIterator< itk::Image<TPixel, VImageDimension> > it(itkImage, itkImage->GetLargestPossibleRegion());
     while(!it.IsAtEnd())
     {
         newImage->SetPixel(it.GetIndex(), it.Get());
         ++it;
     }
 
     mitk::Image::Pointer newMitkImage = mitk::Image::New();
     newMitkImage->InitializeByItk(newImage.GetPointer());
     newMitkImage->SetVolume(newImage->GetBufferPointer());
 
     mitk::DataNode::Pointer imageNode = mitk::DataNode::New();
     imageNode->SetData( newMitkImage );
     QString name = m_SelectedImageNode->GetName().c_str();
     imageNode->SetName((name+"_newdirection").toStdString().c_str());
     GetDefaultDataStorage()->Add(imageNode, m_SelectedImageNode);
 
     mitk::RenderingManager::GetInstance()->InitializeViews( imageNode->GetData()->GetTimeGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true );
     mitk::RenderingManager::GetInstance()->RequestUpdateAll();
 }
 
 void QmitkPreprocessingView::DoProjectSignal()
 {
     switch(m_Controls->m_ProjectionMethodBox->currentIndex())
     {
     case 0:
         DoADCAverage();
         break;
     case 1:
         DoAKCFit();
         break;
     case 2:
         DoBiExpFit();
         break;
     default:
         DoADCAverage();
     }
 }
 
 void QmitkPreprocessingView::DoDwiNormalization()
 {
     if (m_DiffusionImage.IsNull())
         return;
 
     int b0Index = -1;
     for (unsigned int i=0; i<m_DiffusionImage->GetNumberOfChannels(); i++)
     {
         GradientDirectionType g = m_DiffusionImage->GetDirections()->GetElement(i);
         if (g.magnitude()<0.001)
         {
             b0Index = i;
             break;
         }
     }
     if (b0Index==-1)
         return;
 
     typedef mitk::DiffusionImage<DiffusionPixelType>  DiffusionImageType;
     typedef itk::DwiNormilzationFilter<short>  FilterType;
 
     FilterType::Pointer filter = FilterType::New();
     filter->SetInput(m_DiffusionImage->GetVectorImage());
     filter->SetGradientDirections(m_DiffusionImage->GetDirections());
 
     UcharImageType::Pointer itkImage = NULL;
     if (m_Controls->m_NormalizationMaskBox->GetSelectedNode().IsNotNull())
     {
         itkImage = UcharImageType::New();
         mitk::CastToItkImage(dynamic_cast<mitk::Image*>(m_Controls->m_NormalizationMaskBox->GetSelectedNode()->GetData()), itkImage);
         filter->SetMaskImage(itkImage);
     }
 
     // determin normalization reference
-    //    {
-    //        itk::AdcImageFilter< short, double >::Pointer adcFilter = itk::AdcImageFilter< short, double >::New();
-    //        adcFilter->SetInput(m_DiffusionImage->GetVectorImage());
-    //        adcFilter->SetGradientDirections(m_DiffusionImage->GetDirections());
-    //        adcFilter->SetB_value(m_DiffusionImage->GetReferenceBValue());
-    //        adcFilter->Update();
-    //        ItkDoubleImageType::Pointer adcImage = adcFilter->GetOutput();
-    //        itk::ImageRegionIterator<ItkDoubleImageType> inIt(adcImage, adcImage->GetLargestPossibleRegion());
-    //        double max = 0.0030;
-    //        double ref = 0;
-    //        unsigned int count = 0;
-    //        while ( !inIt.IsAtEnd() )
-    //        {
-    //            if (itkImage.IsNotNull() && itkImage->GetPixel(inIt.GetIndex())<=0)
-    //            {
-    //                ++inIt;
-    //                continue;
-    //            }
-    //            if (inIt.Get()>max && inIt.Get()<0.004)
-    //            {
-    //                ref += m_DiffusionImage->GetVectorImage()->GetPixel(inIt.GetIndex())[b0Index];
-    //                count++;
-    //            }
-    //            ++inIt;
-    //        }
-    //        if (count>0)
-    //        {
-    //            ref /= count;
-    //            filter->SetUseGlobalReference(true);
-    //            filter->SetReference(ref);
-    //        }
-    //    }
-
-    // normalize relative to mean white matter signal intensity
+    switch(m_Controls->m_NormalizationReferenceBox->currentIndex())
+    {
+    case 0: // normalize relative to mean white matter signal intensity
     {
         typedef itk::DiffusionTensor3DReconstructionImageFilter< short, short, double > TensorReconstructionImageFilterType;
         TensorReconstructionImageFilterType::Pointer dtFilter = TensorReconstructionImageFilterType::New();
         dtFilter->SetGradientImage( m_DiffusionImage->GetDirections(), m_DiffusionImage->GetVectorImage() );
         dtFilter->SetBValue(m_DiffusionImage->GetReferenceBValue());
         dtFilter->Update();
         itk::Image< itk::DiffusionTensor3D< double >, 3 >::Pointer tensorImage = dtFilter->GetOutput();
         itk::ImageRegionIterator< itk::Image< itk::DiffusionTensor3D< double >, 3 > > inIt(tensorImage, tensorImage->GetLargestPossibleRegion());
         double ref = 0;
         unsigned int count = 0;
         while ( !inIt.IsAtEnd() )
         {
             if (itkImage.IsNotNull() && itkImage->GetPixel(inIt.GetIndex())<=0)
             {
                 ++inIt;
                 continue;
             }
 
             double FA = inIt.Get().GetFractionalAnisotropy();
             if (FA>0.4 && FA<0.99)
             {
                 ref += m_DiffusionImage->GetVectorImage()->GetPixel(inIt.GetIndex())[b0Index];
                 count++;
             }
             ++inIt;
         }
         if (count>0)
         {
             ref /= count;
             filter->SetUseGlobalReference(true);
             filter->SetReference(ref);
         }
+        break;
+    }
+    case 1: // normalize relative to mean CSF signal intensity
+    {
+        itk::AdcImageFilter< short, double >::Pointer adcFilter = itk::AdcImageFilter< short, double >::New();
+        adcFilter->SetInput(m_DiffusionImage->GetVectorImage());
+        adcFilter->SetGradientDirections(m_DiffusionImage->GetDirections());
+        adcFilter->SetB_value(m_DiffusionImage->GetReferenceBValue());
+        adcFilter->Update();
+        ItkDoubleImageType::Pointer adcImage = adcFilter->GetOutput();
+        itk::ImageRegionIterator<ItkDoubleImageType> inIt(adcImage, adcImage->GetLargestPossibleRegion());
+        double max = 0.0030;
+        double ref = 0;
+        unsigned int count = 0;
+        while ( !inIt.IsAtEnd() )
+        {
+            if (itkImage.IsNotNull() && itkImage->GetPixel(inIt.GetIndex())<=0)
+            {
+                ++inIt;
+                continue;
+            }
+            if (inIt.Get()>max && inIt.Get()<0.004)
+            {
+                ref += m_DiffusionImage->GetVectorImage()->GetPixel(inIt.GetIndex())[b0Index];
+                count++;
+            }
+            ++inIt;
+        }
+        if (count>0)
+        {
+            ref /= count;
+            filter->SetUseGlobalReference(true);
+            filter->SetReference(ref);
+        }
+        break;
+    }
+    case 2:
+    {
+        filter->SetUseGlobalReference(false);
+    }
     }
     filter->Update();
 
     DiffusionImageType::Pointer image = DiffusionImageType::New();
     image->SetVectorImage( filter->GetOutput() );
     image->SetReferenceBValue( m_DiffusionImage->GetReferenceBValue() );
     image->SetDirections( m_DiffusionImage->GetDirections() );
     image->InitializeFromVectorImage();
 
     mitk::DataNode::Pointer imageNode = mitk::DataNode::New();
     imageNode->SetData( image );
     QString name = m_SelectedDiffusionNodes.back()->GetName().c_str();
 
     imageNode->SetName((name+"_normalized").toStdString().c_str());
     GetDefaultDataStorage()->Add(imageNode, m_SelectedDiffusionNodes.back());
 }
 
 void QmitkPreprocessingView::DoLengthCorrection()
 {
     if (m_DiffusionImage.IsNull())
         return;
 
     typedef mitk::DiffusionImage<DiffusionPixelType>  DiffusionImageType;
     typedef itk::DwiGradientLengthCorrectionFilter  FilterType;
 
     FilterType::Pointer filter = FilterType::New();
     filter->SetRoundingValue( m_Controls->m_B_ValueMap_Rounder_SpinBox->value());
     filter->SetReferenceBValue(m_DiffusionImage->GetReferenceBValue());
     filter->SetReferenceGradientDirectionContainer(m_DiffusionImage->GetDirections());
     filter->Update();
 
     DiffusionImageType::Pointer image = DiffusionImageType::New();
     image->SetVectorImage( m_DiffusionImage->GetVectorImage());
     image->SetReferenceBValue( filter->GetNewBValue() );
     image->SetDirections( filter->GetOutputGradientDirectionContainer());
     image->InitializeFromVectorImage();
 
     mitk::DataNode::Pointer imageNode = mitk::DataNode::New();
     imageNode->SetData( image );
     QString name = m_SelectedDiffusionNodes.back()->GetName().c_str();
 
     imageNode->SetName((name+"_rounded").toStdString().c_str());
     GetDefaultDataStorage()->Add(imageNode, m_SelectedDiffusionNodes.back());
 }
 
 void QmitkPreprocessingView::UpdateDwiBValueMapRounder(int i)
 {
     if (m_DiffusionImage.IsNull())
         return;
     //m_DiffusionImage->UpdateBValueMap();
     UpdateBValueTableWidget(i);
 }
 
 void QmitkPreprocessingView::CallMultishellToSingleShellFilter(itk::DWIVoxelFunctor * functor, mitk::DiffusionImage<DiffusionPixelType>::Pointer ImPtr, QString imageName, mitk::DataNode* parent)
 {
     typedef itk::RadialMultishellToSingleshellImageFilter<DiffusionPixelType, DiffusionPixelType> FilterType;
 
     // filter input parameter
     const mitk::DiffusionImage<DiffusionPixelType>::BValueMap
             &originalShellMap  = ImPtr->GetBValueMap();
 
     const mitk::DiffusionImage<DiffusionPixelType>::ImageType
             *vectorImage       = ImPtr->GetVectorImage();
 
     const mitk::DiffusionImage<DiffusionPixelType>::GradientDirectionContainerType::Pointer
             gradientContainer = ImPtr->GetDirections();
 
     const unsigned int
             &bValue            = ImPtr->GetReferenceBValue();
 
     mitk::DataNode::Pointer imageNode = 0;
 
     // filter call
     FilterType::Pointer filter = FilterType::New();
     filter->SetInput(vectorImage);
     filter->SetOriginalGradientDirections(gradientContainer);
     filter->SetOriginalBValueMap(originalShellMap);
     filter->SetOriginalBValue(bValue);
     filter->SetFunctor(functor);
     filter->Update();
 
     // create new DWI image
     mitk::DiffusionImage<DiffusionPixelType>::Pointer outImage = mitk::DiffusionImage<DiffusionPixelType>::New();
     outImage->SetVectorImage( filter->GetOutput() );
     outImage->SetReferenceBValue( m_Controls->m_targetBValueSpinBox->value() );
     outImage->SetDirections( filter->GetTargetGradientDirections() );
     outImage->InitializeFromVectorImage();
 
     imageNode = mitk::DataNode::New();
     imageNode->SetData( outImage );
     imageNode->SetName(imageName.toStdString().c_str());
     GetDefaultDataStorage()->Add(imageNode, parent);
 
     //  if(m_Controls->m_OutputRMSErrorImage->isChecked()){
     //    // create new Error image
     //    FilterType::ErrorImageType::Pointer errImage = filter->GetErrorImage();
     //    mitk::Image::Pointer mitkErrImage = mitk::Image::New();
     //    mitkErrImage->InitializeByItk<FilterType::ErrorImageType>(errImage);
     //    mitkErrImage->SetVolume(errImage->GetBufferPointer());
 
     //    imageNode = mitk::DataNode::New();
     //    imageNode->SetData( mitkErrImage );
     //    imageNode->SetName((imageName+"_Error").toStdString().c_str());
     //    GetDefaultDataStorage()->Add(imageNode);
     //  }
 }
 
 void QmitkPreprocessingView::DoBiExpFit()
 {
     itk::BiExpFitFunctor::Pointer functor = itk::BiExpFitFunctor::New();
 
     for (unsigned int i=0; i<m_SelectedDiffusionNodes.size(); i++)
     {
         mitk::DiffusionImage<DiffusionPixelType>::Pointer inImage =
                 dynamic_cast< mitk::DiffusionImage<DiffusionPixelType>* >(m_SelectedDiffusionNodes.at(i)->GetData());
 
         QString name(m_SelectedDiffusionNodes.at(i)->GetName().c_str());
 
         const mitk::DiffusionImage<DiffusionPixelType>::BValueMap & originalShellMap = inImage->GetBValueMap();
         mitk::DiffusionImage<DiffusionPixelType>::BValueMap::const_iterator it = originalShellMap.begin();
         ++it;/* skip b=0*/ unsigned int s = 0; /*shell index */
         vnl_vector<double> bValueList(originalShellMap.size()-1);
         while(it != originalShellMap.end())
             bValueList.put(s++,(it++)->first);
 
         const double targetBValue = m_Controls->m_targetBValueSpinBox->value();
         functor->setListOfBValues(bValueList);
         functor->setTargetBValue(targetBValue);
         CallMultishellToSingleShellFilter(functor,inImage,name + "_BiExp", m_SelectedDiffusionNodes.at(i));
     }
 }
 
 void QmitkPreprocessingView::DoAKCFit()
 {
     itk::KurtosisFitFunctor::Pointer functor = itk::KurtosisFitFunctor::New();
 
     for (unsigned int i=0; i<m_SelectedDiffusionNodes.size(); i++)
     {
         mitk::DiffusionImage<DiffusionPixelType>::Pointer inImage =
                 dynamic_cast< mitk::DiffusionImage<DiffusionPixelType>* >(m_SelectedDiffusionNodes.at(i)->GetData());
 
         QString name(m_SelectedDiffusionNodes.at(i)->GetName().c_str());
 
         const mitk::DiffusionImage<DiffusionPixelType>::BValueMap & originalShellMap = inImage->GetBValueMap();
         mitk::DiffusionImage<DiffusionPixelType>::BValueMap::const_iterator it = originalShellMap.begin();
         ++it;/* skip b=0*/ unsigned int s = 0; /*shell index */
         vnl_vector<double> bValueList(originalShellMap.size()-1);
         while(it != originalShellMap.end())
             bValueList.put(s++,(it++)->first);
 
         const double targetBValue = m_Controls->m_targetBValueSpinBox->value();
         functor->setListOfBValues(bValueList);
         functor->setTargetBValue(targetBValue);
         CallMultishellToSingleShellFilter(functor,inImage,name + "_AKC", m_SelectedDiffusionNodes.at(i));
     }
 }
 
 void QmitkPreprocessingView::DoADCFit()
 {
     // later
 }
 
 void QmitkPreprocessingView::DoADCAverage()
 {
     itk::ADCAverageFunctor::Pointer functor = itk::ADCAverageFunctor::New();
 
     for (unsigned int i=0; i<m_SelectedDiffusionNodes.size(); i++)
     {
         mitk::DiffusionImage<DiffusionPixelType>::Pointer inImage =
                 dynamic_cast< mitk::DiffusionImage<DiffusionPixelType>* >(m_SelectedDiffusionNodes.at(i)->GetData());
 
         QString name(m_SelectedDiffusionNodes.at(i)->GetName().c_str());
 
         const mitk::DiffusionImage<DiffusionPixelType>::BValueMap & originalShellMap = inImage->GetBValueMap();
         mitk::DiffusionImage<DiffusionPixelType>::BValueMap::const_iterator it = originalShellMap.begin();
         ++it;/* skip b=0*/ unsigned int s = 0; /*shell index */
         vnl_vector<double> bValueList(originalShellMap.size()-1);
         while(it != originalShellMap.end())
             bValueList.put(s++,(it++)->first);
 
         const double targetBValue = m_Controls->m_targetBValueSpinBox->value();
         functor->setListOfBValues(bValueList);
         functor->setTargetBValue(targetBValue);
         CallMultishellToSingleShellFilter(functor,inImage,name + "_ADC", m_SelectedDiffusionNodes.at(i));
     }
 }
 
 void QmitkPreprocessingView::DoAdcCalculation()
 {
     if (m_DiffusionImage.IsNull())
         return;
 
     typedef mitk::DiffusionImage< DiffusionPixelType >            DiffusionImageType;
     typedef itk::AdcImageFilter< DiffusionPixelType, double >     FilterType;
 
 
     for (unsigned int i=0; i<m_SelectedDiffusionNodes.size(); i++)
     {
         DiffusionImageType::Pointer inImage = dynamic_cast< DiffusionImageType* >(m_SelectedDiffusionNodes.at(i)->GetData());
         FilterType::Pointer filter = FilterType::New();
         filter->SetInput(inImage->GetVectorImage());
         filter->SetGradientDirections(inImage->GetDirections());
         filter->SetB_value(inImage->GetReferenceBValue());
         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, m_SelectedDiffusionNodes.at(i));
     }
 }
 
 
 void QmitkPreprocessingView::UpdateBValueTableWidget(int i)
 {
     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{
 
         typedef mitk::DiffusionImage<short>::BValueMap BValueMap;
         typedef mitk::DiffusionImage<short>::BValueMap::iterator BValueMapIterator;
 
         BValueMapIterator it;
 
         BValueMap roundedBValueMap = m_DiffusionImage->GetBValueMap();
 
         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);
 
         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)));
             QTableWidgetItem* item = m_Controls->m_B_ValueMap_TableWidget->item(i,0);
             item->setFlags(item->flags() & ~Qt::ItemIsEditable);
             m_Controls->m_B_ValueMap_TableWidget->setItem(i,1,new QTableWidgetItem(QString::number(it->second.size())));
             i++;
         }
     }
 
 }
 
 
 template < typename TPixel, unsigned int VImageDimension >
 void QmitkPreprocessingView::TemplatedUpdateGui( itk::Image<TPixel, VImageDimension>* itkImage)
 {
     for (int r=0; r<3; r++)
         for (int c=0; c<3; c++)
         {
             QTableWidgetItem* item = m_Controls->m_DirectionMatrixTable->item(r,c);
             delete item;
             item = new QTableWidgetItem();
             item->setTextAlignment(Qt::AlignCenter | Qt::AlignVCenter);
             item->setText(QString::number(itkImage->GetDirection()[r][c]));
             m_Controls->m_DirectionMatrixTable->setItem(r,c,item);
         }
 }
 
 void QmitkPreprocessingView::OnSelectionChanged( std::vector<mitk::DataNode*> nodes )
 {
     bool foundDwiVolume = false;
     bool foundImageVolume = false;
     m_DiffusionImage = NULL;
     m_SelectedImage = NULL;
     m_SelectedImageNode = NULL;
     m_SelectedDiffusionNodes.clear();
 
     // iterate selection
     for( std::vector<mitk::DataNode*>::iterator it = nodes.begin(); it != nodes.end(); ++it )
     {
         mitk::DataNode::Pointer node = *it;
 
         if( node.IsNotNull() && dynamic_cast<mitk::DiffusionImage<short>*>(node->GetData()) )
         {
             foundDwiVolume = true;
             foundImageVolume = true;
             m_DiffusionImage = dynamic_cast<mitk::DiffusionImage<DiffusionPixelType>*>(node->GetData());
             m_Controls->m_DiffusionImageLabel->setText(node->GetName().c_str());
             m_SelectedDiffusionNodes.push_back(node);
         }
         else if( node.IsNotNull() && dynamic_cast<mitk::Image*>(node->GetData()) )
         {
             foundImageVolume = true;
             m_SelectedImage = dynamic_cast<mitk::Image*>(node->GetData());
             m_Controls->m_DiffusionImageLabel->setText(node->GetName().c_str());
             m_SelectedImageNode = node;
         }
     }
 
     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_ProjectSignalButton->setEnabled(foundDwiVolume);
     m_Controls->m_CreateLengthCorrectedDwi->setEnabled(foundDwiVolume);
     m_Controls->m_CalcAdcButton->setEnabled(foundDwiVolume);
     m_Controls->m_targetBValueSpinBox->setEnabled(foundDwiVolume);
     m_Controls->m_NormalizeImageValuesButton->setEnabled(foundDwiVolume);
     m_Controls->m_DirectionMatrixTable->setEnabled(foundImageVolume);
     m_Controls->m_ModifyDirection->setEnabled(foundImageVolume);
     m_Controls->m_ExtractBrainMask->setEnabled(foundImageVolume);
     m_Controls->m_ResampleImageButton->setEnabled(foundImageVolume);
     m_Controls->m_ModifySpacingButton->setEnabled(foundImageVolume);
     m_Controls->m_ModifyOriginButton->setEnabled(foundImageVolume);
     m_Controls->m_CropImageButton->setEnabled(foundImageVolume);
     m_Controls->m_RemoveGradientButton->setEnabled(foundDwiVolume);
     m_Controls->m_ExtractGradientButton->setEnabled(foundDwiVolume);
 
     // reset sampling frame to 1 and update all ealted components
     m_Controls->m_B_ValueMap_Rounder_SpinBox->setValue(1);
 
     UpdateBValueTableWidget(m_Controls->m_B_ValueMap_Rounder_SpinBox->value());
     DoUpdateInterpolationGui(m_Controls->m_ResampleTypeBox->currentIndex());
 
     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++)
             {
                 // Measurement frame
                 {
                     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);
                 }
 
                 // Direction matrix
                 {
                     QTableWidgetItem* item = m_Controls->m_DirectionMatrixTable->item(r,c);
                     delete item;
                     item = new QTableWidgetItem();
                     item->setTextAlignment(Qt::AlignCenter | Qt::AlignVCenter);
                     item->setText(QString::number(m_DiffusionImage->GetVectorImage()->GetDirection()[r][c]));
                     m_Controls->m_DirectionMatrixTable->setItem(r,c,item);
                 }
             }
 
         //calculate target bValue for MultishellToSingleShellfilter
         const mitk::DiffusionImage<DiffusionPixelType>::BValueMap & bValMap = m_DiffusionImage->GetBValueMap();
         mitk::DiffusionImage<DiffusionPixelType>::BValueMap::const_iterator it = bValMap.begin();
         unsigned int targetBVal = 0;
         while(it != bValMap.end())
             targetBVal += (it++)->first;
         targetBVal /= (float)bValMap.size()-1;
         m_Controls->m_targetBValueSpinBox->setValue(targetBVal);
 
         m_Controls->m_HeaderSpacingX->setValue(m_DiffusionImage->GetGeometry()->GetSpacing()[0]);
         m_Controls->m_HeaderSpacingY->setValue(m_DiffusionImage->GetGeometry()->GetSpacing()[1]);
         m_Controls->m_HeaderSpacingZ->setValue(m_DiffusionImage->GetGeometry()->GetSpacing()[2]);
         m_Controls->m_HeaderOriginX->setValue(m_DiffusionImage->GetGeometry()->GetOrigin()[0]);
         m_Controls->m_HeaderOriginY->setValue(m_DiffusionImage->GetGeometry()->GetOrigin()[1]);
         m_Controls->m_HeaderOriginZ->setValue(m_DiffusionImage->GetGeometry()->GetOrigin()[2]);
         m_Controls->m_XstartBox->setMaximum(m_DiffusionImage->GetGeometry()->GetExtent(0)-1);
         m_Controls->m_YstartBox->setMaximum(m_DiffusionImage->GetGeometry()->GetExtent(1)-1);
         m_Controls->m_ZstartBox->setMaximum(m_DiffusionImage->GetGeometry()->GetExtent(2)-1);
         m_Controls->m_XendBox->setMaximum(m_DiffusionImage->GetGeometry()->GetExtent(0)-1);
         m_Controls->m_YendBox->setMaximum(m_DiffusionImage->GetGeometry()->GetExtent(1)-1);
         m_Controls->m_ZendBox->setMaximum(m_DiffusionImage->GetGeometry()->GetExtent(2)-1);
         m_Controls->m_RemoveGradientBox->setMaximum(m_DiffusionImage->GetDirections()->Size()-1);
         m_Controls->m_ExtractGradientBox->setMaximum(m_DiffusionImage->GetDirections()->Size()-1);
     }
     else if (foundImageVolume)
     {
         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_HeaderSpacingX->setValue(m_SelectedImage->GetGeometry()->GetSpacing()[0]);
         m_Controls->m_HeaderSpacingY->setValue(m_SelectedImage->GetGeometry()->GetSpacing()[1]);
         m_Controls->m_HeaderSpacingZ->setValue(m_SelectedImage->GetGeometry()->GetSpacing()[2]);
         m_Controls->m_HeaderOriginX->setValue(m_SelectedImage->GetGeometry()->GetOrigin()[0]);
         m_Controls->m_HeaderOriginY->setValue(m_SelectedImage->GetGeometry()->GetOrigin()[1]);
         m_Controls->m_HeaderOriginZ->setValue(m_SelectedImage->GetGeometry()->GetOrigin()[2]);
         m_Controls->m_XstartBox->setMaximum(m_SelectedImage->GetGeometry()->GetExtent(0)-1);
         m_Controls->m_YstartBox->setMaximum(m_SelectedImage->GetGeometry()->GetExtent(1)-1);
         m_Controls->m_ZstartBox->setMaximum(m_SelectedImage->GetGeometry()->GetExtent(2)-1);
         m_Controls->m_XendBox->setMaximum(m_SelectedImage->GetGeometry()->GetExtent(0)-1);
         m_Controls->m_YendBox->setMaximum(m_SelectedImage->GetGeometry()->GetExtent(1)-1);
         m_Controls->m_ZendBox->setMaximum(m_SelectedImage->GetGeometry()->GetExtent(2)-1);
 
         AccessFixedDimensionByItk(m_SelectedImage, TemplatedUpdateGui,3);
     }
     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);
                 }
                 {
                     QTableWidgetItem* item = m_Controls->m_DirectionMatrixTable->item(r,c);
                     delete item;
                     item = new QTableWidgetItem();
                     m_Controls->m_DirectionMatrixTable->setItem(r,c,item);
                 }
             }
 
         m_Controls->m_DiffusionImageLabel->setText("<font color='red'>mandatory</font>");
         m_Controls->m_InputData->setTitle("Please Select Input Data");
     }
 }
 
 void QmitkPreprocessingView::Activated()
 {
     QmitkFunctionality::Activated();
 }
 
 void QmitkPreprocessingView::Deactivated()
 {
     QmitkFunctionality::Deactivated();
 }
 
 void QmitkPreprocessingView::DoHalfSphereGradientDirections()
 {
 
     MitkDwiType::Pointer newDwi = m_DiffusionImage->Clone();
     GradientDirectionContainerType::Pointer gradientContainer = newDwi->GetDirections();
 
     for (unsigned int j=0; j<gradientContainer->Size(); j++)
         if (gradientContainer->at(j)[0]<0)
             gradientContainer->at(j) = -gradientContainer->at(j);
 
     newDwi->SetDirections(gradientContainer);
 
     mitk::DataNode::Pointer imageNode = mitk::DataNode::New();
     imageNode->SetData( newDwi );
     QString name = m_SelectedDiffusionNodes.back()->GetName().c_str();
     imageNode->SetName((name+"_halfsphere").toStdString().c_str());
     GetDefaultDataStorage()->Add(imageNode, m_SelectedDiffusionNodes.back());
 }
 
 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)
                 return;
             mf[r][c] = item->text().toDouble();
         }
 
     MitkDwiType::Pointer newDwi = m_DiffusionImage->Clone();
     newDwi->SetMeasurementFrame(mf);
 
     mitk::DataNode::Pointer imageNode = mitk::DataNode::New();
     imageNode->SetData( newDwi );
     QString name = m_SelectedDiffusionNodes.back()->GetName().c_str();
     imageNode->SetName((name+"_new-MF").toStdString().c_str());
     GetDefaultDataStorage()->Add(imageNode, m_SelectedDiffusionNodes.back());
 }
 
 void QmitkPreprocessingView::DoShowGradientDirections()
 {
     if (m_DiffusionImage.IsNull())
         return;
 
     int maxIndex = 0;
     unsigned int maxSize = m_DiffusionImage->GetDimension(0);
     if (maxSize<m_DiffusionImage->GetDimension(1))
     {
         maxSize = m_DiffusionImage->GetDimension(1);
         maxIndex = 1;
     }
     if (maxSize<m_DiffusionImage->GetDimension(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<short>::BValueMap BValueMap;
     typedef mitk::DiffusionImage<short>::BValueMap::iterator BValueMapIterator;
     BValueMap bValMap =  m_DiffusionImage->GetBValueMap();
 
     GradientDirectionContainerType::Pointer gradientContainer = m_DiffusionImage->GetDirections();
     mitk::BaseGeometry::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 (unsigned int j=0; j<it->second.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->first<mitk::eps)
             continue;
 
         // add shell to datastorage
         mitk::DataNode::Pointer node = mitk::DataNode::New();
         node->SetData(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(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<DiffusionPixelType>              DiffusionImageType;
     typedef itk::ElectrostaticRepulsionDiffusionGradientReductionFilter<DiffusionPixelType, DiffusionPixelType> FilterType;
     typedef DiffusionImageType::BValueMap BValueMap;
 
     // GetShellSelection from GUI
     BValueMap shellSlectionMap;
     BValueMap originalShellMap = m_DiffusionImage->GetBValueMap();
     std::vector<unsigned int> newNumGradientDirections;
     int shellCounter = 0;
 
     QString name = m_SelectedDiffusionNodes.front()->GetName().c_str();
     for (int i=0; i<m_Controls->m_B_ValueMap_TableWidget->rowCount(); i++)
     {
         double BValue = m_Controls->m_B_ValueMap_TableWidget->item(i,0)->text().toDouble();
         shellSlectionMap[BValue] = originalShellMap[BValue];
         unsigned int num = m_Controls->m_B_ValueMap_TableWidget->item(i,1)->text().toUInt();
         newNumGradientDirections.push_back(num);
         name += "_";
         name += QString::number(num);
         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->SetReferenceBValue(m_DiffusionImage->GetReferenceBValue());
     image->SetDirections(filter->GetGradientDirections());
     image->SetMeasurementFrame(m_DiffusionImage->GetMeasurementFrame());
     image->InitializeFromVectorImage();
 
     mitk::DataNode::Pointer imageNode = mitk::DataNode::New();
     imageNode->SetData( image );
 
     imageNode->SetName(name.toStdString().c_str());
     GetDefaultDataStorage()->Add(imageNode, m_SelectedDiffusionNodes.back());
 }
 
 void QmitkPreprocessingView::MergeDwis()
 {
     typedef mitk::DiffusionImage<DiffusionPixelType>              DiffusionImageType;
     typedef DiffusionImageType::GradientDirectionContainerType    GradientContainerType;
 
     if (m_SelectedDiffusionNodes.size()<2)
         return;
 
     typedef itk::VectorImage<DiffusionPixelType,3>                  DwiImageType;
     typedef DwiImageType::PixelType                        DwiPixelType;
     typedef DwiImageType::RegionType                       DwiRegionType;
     typedef std::vector< DwiImageType::Pointer >  DwiImageContainerType;
 
     typedef std::vector< GradientContainerType::Pointer >  GradientListContainerType;
 
     DwiImageContainerType       imageContainer;
     GradientListContainerType   gradientListContainer;
     std::vector< double >       bValueContainer;
 
     QString name = m_SelectedDiffusionNodes.front()->GetName().c_str();
     for (unsigned int i=0; i<m_SelectedDiffusionNodes.size(); i++)
     {
         DiffusionImageType::Pointer dwi = dynamic_cast< mitk::DiffusionImage<DiffusionPixelType>* >( m_SelectedDiffusionNodes.at(i)->GetData() );
         if ( dwi.IsNotNull() )
         {
             imageContainer.push_back(dwi->GetVectorImage());
             gradientListContainer.push_back(dwi->GetDirections());
             bValueContainer.push_back(dwi->GetReferenceBValue());
             if (i>0)
             {
                 name += "+";
                 name += m_SelectedDiffusionNodes.at(i)->GetName().c_str();
             }
         }
     }
 
     typedef itk::MergeDiffusionImagesFilter<short> 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->SetReferenceBValue(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<DiffusionPixelType>              DiffusionImageType;
     typedef DiffusionImageType::GradientDirectionContainerType    GradientContainerType;
 
     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;
     }
 
     mitk::DataStorage::SetOfObjects::const_iterator itemiter( m_SelectedDiffusionNodes.begin() );
     mitk::DataStorage::SetOfObjects::const_iterator itemiterend( m_SelectedDiffusionNodes.end() );
 
     std::vector<mitk::DataNode::Pointer> nodes;
     while ( itemiter != itemiterend ) // for all items
     {
 
         DiffusionImageType* vols =
                 static_cast<DiffusionImageType*>(
                     (*itemiter)->GetData());
 
         std::string nodename;
         (*itemiter)->GetStringProperty("name", nodename);
 
         // Extract image using found index
         typedef itk::B0ImageExtractionImageFilter<short, short> 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"));
 
         GetDefaultDataStorage()->Add(node, (*itemiter));
 
         ++itemiter;
     }
 }
 
 void QmitkPreprocessingView::DoExtractBOWithoutAveraging()
 {
     // typedefs
     typedef mitk::DiffusionImage<DiffusionPixelType>              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() );
 
     while ( itemiter != itemiterend ) // for all items
     {
         DiffusionImageType* vols =
                 static_cast<DiffusionImageType*>(
                     (*itemiter)->GetData());
 
         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();
 
         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, (*itemiter));
 
         /*A reinitialization is needed to access the time channels via the ImageNavigationController
     The Global-Geometry can not recognize the time channel without a re-init.
     (for a new selection in datamanger a automatically updated of the Global-Geometry should be done - if it contains the time channel)*/
         mitk::RenderingManager::GetInstance()->InitializeViews(node->GetData()->GetTimeGeometry(),mitk::RenderingManager::REQUEST_UPDATE_ALL, true);
 
         ++itemiter;
     }
 }
 
 void QmitkPreprocessingView::AverageGradients()
 {
     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() );
 
     while ( itemiter != itemiterend ) // for all items
     {
         mitk::DiffusionImage<DiffusionPixelType>* mitkDwi =
                 static_cast<mitk::DiffusionImage<DiffusionPixelType>*>(
                     (*itemiter)->GetData());
 
         MitkDwiType::Pointer newDwi = mitkDwi->Clone();
         newDwi->AverageRedundantGradients(m_Controls->m_Blur->value());
 
         mitk::DataNode::Pointer imageNode = mitk::DataNode::New();
         imageNode->SetData( newDwi );
         QString name = (*itemiter)->GetName().c_str();
         imageNode->SetName((name+"_averaged").toStdString().c_str());
         GetDefaultDataStorage()->Add(imageNode, (*itemiter));
 
         ++itemiter;
     }
 }
diff --git a/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkPreprocessingViewControls.ui b/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkPreprocessingViewControls.ui
index feec6d9844..393f8ac3eb 100644
--- a/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkPreprocessingViewControls.ui
+++ b/Plugins/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkPreprocessingViewControls.ui
@@ -1,1526 +1,1574 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <ui version="4.0">
  <class>QmitkPreprocessingViewControls</class>
  <widget class="QWidget" name="QmitkPreprocessingViewControls">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>639</width>
-    <height>1030</height>
+    <height>1148</height>
    </rect>
   </property>
   <property name="minimumSize">
    <size>
     <width>0</width>
     <height>0</height>
    </size>
   </property>
   <property name="acceptDrops">
    <bool>false</bool>
   </property>
   <property name="windowTitle">
    <string>QmitkPreprocessingViewControls</string>
   </property>
   <property name="autoFillBackground">
    <bool>true</bool>
   </property>
   <layout class="QVBoxLayout" name="verticalLayout">
    <item>
     <widget class="QGroupBox" name="m_InputData">
      <property name="title">
       <string>Please Select Input Data</string>
      </property>
      <layout class="QGridLayout" name="gridLayout_2">
       <item row="0" column="0">
        <widget class="QLabel" name="label_5">
         <property name="toolTip">
          <string/>
         </property>
         <property name="text">
          <string>Image:</string>
         </property>
        </widget>
       </item>
       <item row="0" column="1">
        <widget class="QLabel" name="m_DiffusionImageLabel">
         <property name="text">
          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; color:#ff0000;&quot;&gt;mandatory&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
         </property>
         <property name="wordWrap">
          <bool>true</bool>
         </property>
        </widget>
       </item>
      </layout>
     </widget>
    </item>
    <item>
     <widget class="QTabWidget" name="tabWidget">
      <property name="currentIndex">
       <number>0</number>
      </property>
      <widget class="QWidget" name="tab_4">
       <attribute name="title">
        <string>Gradients</string>
       </attribute>
       <layout class="QGridLayout" name="gridLayout_6">
        <item row="5" column="0">
         <spacer name="verticalSpacer_5">
          <property name="orientation">
           <enum>Qt::Vertical</enum>
          </property>
          <property name="sizeHint" stdset="0">
           <size>
            <width>20</width>
            <height>40</height>
           </size>
          </property>
         </spacer>
        </item>
        <item row="3" column="0">
         <widget class="QFrame" name="frame_2">
          <property name="frameShape">
           <enum>QFrame::NoFrame</enum>
          </property>
          <property name="frameShadow">
           <enum>QFrame::Raised</enum>
          </property>
          <layout class="QGridLayout" name="gridLayout_10">
           <property name="leftMargin">
            <number>0</number>
           </property>
           <property name="topMargin">
            <number>0</number>
           </property>
           <property name="rightMargin">
            <number>0</number>
           </property>
           <property name="bottomMargin">
            <number>0</number>
           </property>
           <property name="horizontalSpacing">
            <number>6</number>
           </property>
           <item row="5" column="0">
            <widget class="QCommandLinkButton" name="m_MirrorGradientToHalfSphereButton">
             <property name="enabled">
              <bool>false</bool>
             </property>
             <property name="toolTip">
              <string>Sometimes the gradient directions are not located on one half sphere.</string>
             </property>
             <property name="statusTip">
              <string/>
             </property>
             <property name="whatsThis">
              <string notr="true"/>
             </property>
             <property name="text">
              <string>Mirror gradients to half sphere</string>
             </property>
            </widget>
           </item>
           <item row="3" column="0">
            <widget class="QCommandLinkButton" name="m_CreateLengthCorrectedDwi">
             <property name="enabled">
              <bool>false</bool>
             </property>
             <property name="text">
              <string>Round b-values</string>
             </property>
            </widget>
           </item>
           <item row="7" column="0">
            <widget class="QCommandLinkButton" name="m_ReduceGradientsButton">
             <property name="enabled">
              <bool>false</bool>
             </property>
             <property name="toolTip">
              <string>Retain only the specified number of gradient directions and according image volumes. The retained directions are spread equally over the half sphere using an iterative energy repulsion strategy.</string>
             </property>
             <property name="statusTip">
              <string/>
             </property>
             <property name="whatsThis">
              <string notr="true"/>
             </property>
             <property name="text">
              <string>Reduce number of gradients</string>
             </property>
            </widget>
           </item>
           <item row="3" column="1">
            <layout class="QFormLayout" name="formLayout">
             <item row="0" column="0">
              <widget class="QLabel" name="label_2">
               <property name="toolTip">
                <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Define the sampling frame the b-Values are rounded with.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
               </property>
               <property name="text">
                <string>Sampling frame:</string>
               </property>
              </widget>
             </item>
             <item row="0" column="1">
              <widget class="QSpinBox" name="m_B_ValueMap_Rounder_SpinBox">
               <property name="enabled">
                <bool>false</bool>
               </property>
               <property name="toolTip">
                <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Round b-values to nearest multiple of this value (click &amp;quot;Round b-value&amp;quot; to create new image with these values).&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
               </property>
               <property name="correctionMode">
                <enum>QAbstractSpinBox::CorrectToNearestValue</enum>
               </property>
               <property name="minimum">
                <number>1</number>
               </property>
               <property name="maximum">
                <number>10000</number>
               </property>
               <property name="singleStep">
                <number>10</number>
               </property>
              </widget>
             </item>
            </layout>
           </item>
           <item row="4" column="0">
            <widget class="QCommandLinkButton" name="m_ShowGradientsButton">
             <property name="enabled">
              <bool>false</bool>
             </property>
             <property name="toolTip">
              <string>Generate pointset displaying the gradient vectors (applied measurement frame).</string>
             </property>
             <property name="statusTip">
              <string/>
             </property>
             <property name="whatsThis">
              <string notr="true"/>
             </property>
             <property name="text">
              <string>Show gradients</string>
             </property>
            </widget>
           </item>
          </layout>
         </widget>
        </item>
        <item row="0" column="0">
         <widget class="QTableWidget" name="m_B_ValueMap_TableWidget">
          <property name="sizePolicy">
           <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
            <horstretch>0</horstretch>
            <verstretch>0</verstretch>
           </sizepolicy>
          </property>
          <property name="verticalScrollBarPolicy">
           <enum>Qt::ScrollBarAsNeeded</enum>
          </property>
          <property name="horizontalScrollBarPolicy">
           <enum>Qt::ScrollBarAlwaysOff</enum>
          </property>
          <attribute name="horizontalHeaderCascadingSectionResizes">
           <bool>true</bool>
          </attribute>
          <attribute name="horizontalHeaderDefaultSectionSize">
           <number>100</number>
          </attribute>
          <attribute name="horizontalHeaderStretchLastSection">
           <bool>true</bool>
          </attribute>
          <attribute name="verticalHeaderVisible">
           <bool>false</bool>
          </attribute>
          <attribute name="verticalHeaderCascadingSectionResizes">
           <bool>true</bool>
          </attribute>
          <column>
           <property name="text">
            <string>b-Value</string>
           </property>
          </column>
          <column>
           <property name="text">
            <string>Number of gradients</string>
           </property>
          </column>
         </widget>
        </item>
        <item row="0" column="1">
         <spacer name="horizontalSpacer_5">
          <property name="orientation">
           <enum>Qt::Horizontal</enum>
          </property>
          <property name="sizeHint" stdset="0">
           <size>
            <width>40</width>
            <height>20</height>
           </size>
          </property>
         </spacer>
        </item>
       </layout>
      </widget>
      <widget class="QWidget" name="tab_5">
       <attribute name="title">
        <string>Image Values</string>
       </attribute>
       <layout class="QGridLayout" name="gridLayout_8">
        <item row="3" column="0">
         <spacer name="verticalSpacer">
          <property name="orientation">
           <enum>Qt::Vertical</enum>
          </property>
          <property name="sizeHint" stdset="0">
           <size>
            <width>20</width>
            <height>40</height>
           </size>
          </property>
         </spacer>
        </item>
+       <item row="0" column="0">
+        <widget class="QFrame" name="frame_3">
+         <property name="frameShape">
+          <enum>QFrame::NoFrame</enum>
+         </property>
+         <property name="frameShadow">
+          <enum>QFrame::Raised</enum>
+         </property>
+         <layout class="QGridLayout" name="gridLayout_11">
+          <property name="leftMargin">
+           <number>0</number>
+          </property>
+          <property name="topMargin">
+           <number>0</number>
+          </property>
+          <property name="rightMargin">
+           <number>0</number>
+          </property>
+          <property name="bottomMargin">
+           <number>0</number>
+          </property>
+          <property name="horizontalSpacing">
+           <number>0</number>
+          </property>
+          <item row="1" column="1">
+           <widget class="QFrame" name="frame">
+            <property name="frameShape">
+             <enum>QFrame::NoFrame</enum>
+            </property>
+            <property name="frameShadow">
+             <enum>QFrame::Raised</enum>
+            </property>
+            <layout class="QFormLayout" name="formLayout_2">
+             <property name="leftMargin">
+              <number>0</number>
+             </property>
+             <property name="topMargin">
+              <number>0</number>
+             </property>
+             <property name="rightMargin">
+              <number>0</number>
+             </property>
+             <property name="bottomMargin">
+              <number>0</number>
+             </property>
+             <item row="0" column="1">
+              <widget class="QDoubleSpinBox" name="m_Blur">
+               <property name="toolTip">
+                <string comment="Accumulates the information that was acquired with multiple repetitions for one gradient. Vectors do not have to be precisely equal in order to be merged, if a &quot;Merge radius&quot; &gt; 0 is configured." extracomment="Accumulates the information that was acquired with multiple repetitions for one gradient. Vectors do not have to be precisely equal in order to be merged, if a &quot;Merge radius&quot; &gt; 0 is configured.">Accumulates the information that was acquired with multiple repetitions for one gradient. Vectors do not have to be precisely equal in order to be merged, if a &quot;Merge radius&quot; &gt; 0 is configured.</string>
+               </property>
+               <property name="statusTip">
+                <string comment="Accumulates the information that was acquired with multiple repetitions for one gradient. Vectors do not have to be precisely equal in order to be merged, if a &quot;Merge radius&quot; &gt; 0 is configured." extracomment="Accumulates the information that was acquired with multiple repetitions for one gradient. Vectors do not have to be precisely equal in order to be merged, if a &quot;Merge radius&quot; &gt; 0 is configured.">Accumulates the information that was acquired with multiple repetitions for one gradient. Vectors do not have to be precisely equal in order to be merged, if a &quot;Merge radius&quot; &gt; 0 is configured.</string>
+               </property>
+               <property name="whatsThis">
+                <string comment="Accumulates the information that was acquired with multiple repetitions for one gradient. Vectors do not have to be precisely equal in order to be merged, if a &quot;Merge radius&quot; &gt; 0 is configured." extracomment="Accumulates the information that was acquired with multiple repetitions for one gradient. Vectors do not have to be precisely equal in order to be merged, if a &quot;Merge radius&quot; &gt; 0 is configured.">Accumulates the information that was acquired with multiple repetitions for one gradient. Vectors do not have to be precisely equal in order to be merged, if a &quot;Merge radius&quot; &gt; 0 is configured.</string>
+               </property>
+               <property name="decimals">
+                <number>6</number>
+               </property>
+               <property name="maximum">
+                <double>2.000000000000000</double>
+               </property>
+               <property name="singleStep">
+                <double>0.000100000000000</double>
+               </property>
+               <property name="value">
+                <double>0.001000000000000</double>
+               </property>
+              </widget>
+             </item>
+             <item row="0" column="0">
+              <widget class="QLabel" name="label">
+               <property name="toolTip">
+                <string comment="Accumulates the information that was acquired with multiple repetitions for one gradient. Vectors do not have to be precisely equal in order to be merged, if a &quot;Merge radius&quot; &gt; 0 is configured." extracomment="Accumulates the information that was acquired with multiple repetitions for one gradient. Vectors do not have to be precisely equal in order to be merged, if a &quot;Merge radius&quot; &gt; 0 is configured.">Accumulates the information that was acquired with multiple repetitions for one gradient. Vectors do not have to be precisely equal in order to be merged, if a &quot;Merge radius&quot; &gt; 0 is configured.</string>
+               </property>
+               <property name="statusTip">
+                <string comment="Accumulates the information that was acquired with multiple repetitions for one gradient. Vectors do not have to be precisely equal in order to be merged, if a &quot;Merge radius&quot; &gt; 0 is configured." extracomment="Accumulates the information that was acquired with multiple repetitions for one gradient. Vectors do not have to be precisely equal in order to be merged, if a &quot;Merge radius&quot; &gt; 0 is configured.">Accumulates the information that was acquired with multiple repetitions for one gradient. Vectors do not have to be precisely equal in order to be merged, if a &quot;Merge radius&quot; &gt; 0 is configured.</string>
+               </property>
+               <property name="whatsThis">
+                <string comment="Accumulates the information that was acquired with multiple repetitions for one gradient. Vectors do not have to be precisely equal in order to be merged, if a &quot;Merge radius&quot; &gt; 0 is configured." extracomment="Accumulates the information that was acquired with multiple repetitions for one gradient. Vectors do not have to be precisely equal in order to be merged, if a &quot;Merge radius&quot; &gt; 0 is configured.">Accumulates the information that was acquired with multiple repetitions for one gradient. Vectors do not have to be precisely equal in order to be merged, if a &quot;Merge radius&quot; &gt; 0 is configured.</string>
+               </property>
+               <property name="text">
+                <string>Merge radius</string>
+               </property>
+              </widget>
+             </item>
+            </layout>
+           </widget>
+          </item>
+          <item row="6" column="0">
+           <widget class="QCommandLinkButton" name="m_MergeDwisButton">
+            <property name="enabled">
+             <bool>false</bool>
+            </property>
+            <property name="toolTip">
+             <string>Merges selected DWIs of same dimension. If several b-values are present, the resulting image will contain multiple b-shells.</string>
+            </property>
+            <property name="statusTip">
+             <string/>
+            </property>
+            <property name="whatsThis">
+             <string notr="true"/>
+            </property>
+            <property name="text">
+             <string>Merge selected DWIs</string>
+            </property>
+           </widget>
+          </item>
+          <item row="3" column="0">
+           <widget class="QCommandLinkButton" name="m_NormalizeImageValuesButton">
+            <property name="enabled">
+             <bool>false</bool>
+            </property>
+            <property name="toolTip">
+             <string>Each image value is normalized with the corresponding baseline signal value.</string>
+            </property>
+            <property name="statusTip">
+             <string/>
+            </property>
+            <property name="whatsThis">
+             <string notr="true"/>
+            </property>
+            <property name="text">
+             <string>Normalize image values</string>
+            </property>
+           </widget>
+          </item>
+          <item row="2" column="1">
+           <widget class="QFrame" name="frame_4">
+            <property name="frameShape">
+             <enum>QFrame::NoFrame</enum>
+            </property>
+            <property name="frameShadow">
+             <enum>QFrame::Raised</enum>
+            </property>
+            <layout class="QGridLayout" name="gridLayout_4">
+             <property name="leftMargin">
+              <number>0</number>
+             </property>
+             <property name="topMargin">
+              <number>0</number>
+             </property>
+             <property name="rightMargin">
+              <number>0</number>
+             </property>
+             <property name="bottomMargin">
+              <number>0</number>
+             </property>
+             <property name="spacing">
+              <number>0</number>
+             </property>
+             <item row="0" column="0">
+              <widget class="QSpinBox" name="m_targetBValueSpinBox">
+               <property name="enabled">
+                <bool>false</bool>
+               </property>
+               <property name="toolTip">
+                <string>Target b-value</string>
+               </property>
+               <property name="maximum">
+                <number>100000</number>
+               </property>
+               <property name="singleStep">
+                <number>500</number>
+               </property>
+              </widget>
+             </item>
+             <item row="0" column="1">
+              <widget class="QComboBox" name="m_ProjectionMethodBox">
+               <property name="toolTip">
+                <string>Select projection method.</string>
+               </property>
+               <item>
+                <property name="text">
+                 <string>ADC Average</string>
+                </property>
+               </item>
+               <item>
+                <property name="text">
+                 <string>AKC</string>
+                </property>
+               </item>
+               <item>
+                <property name="text">
+                 <string>Bi-Exponential</string>
+                </property>
+               </item>
+              </widget>
+             </item>
+            </layout>
+           </widget>
+          </item>
+          <item row="1" column="0">
+           <widget class="QCommandLinkButton" name="m_ButtonAverageGradients">
+            <property name="enabled">
+             <bool>false</bool>
+            </property>
+            <property name="toolTip">
+             <string>Multiple acquistions of one gradient direction can be averaged. Due to rounding errors, similar gradients often differ in the last decimal positions. The Merge radius allows to average them by taking all directions within a certain radius into account.</string>
+            </property>
+            <property name="statusTip">
+             <string/>
+            </property>
+            <property name="whatsThis">
+             <string notr="true"/>
+            </property>
+            <property name="text">
+             <string>Average repetitions</string>
+            </property>
+           </widget>
+          </item>
+          <item row="2" column="0">
+           <widget class="QCommandLinkButton" name="m_ProjectSignalButton">
+            <property name="enabled">
+             <bool>false</bool>
+            </property>
+            <property name="toolTip">
+             <string>Project image values onto one b-shell.</string>
+            </property>
+            <property name="text">
+             <string>Project onto shell</string>
+            </property>
+           </widget>
+          </item>
+          <item row="3" column="1">
+           <widget class="QFrame" name="frame_6">
+            <property name="frameShape">
+             <enum>QFrame::NoFrame</enum>
+            </property>
+            <property name="frameShadow">
+             <enum>QFrame::Raised</enum>
+            </property>
+            <layout class="QGridLayout" name="gridLayout_19">
+             <property name="leftMargin">
+              <number>0</number>
+             </property>
+             <property name="topMargin">
+              <number>0</number>
+             </property>
+             <property name="rightMargin">
+              <number>0</number>
+             </property>
+             <property name="bottomMargin">
+              <number>0</number>
+             </property>
+             <property name="verticalSpacing">
+              <number>0</number>
+             </property>
+             <item row="0" column="1">
+              <widget class="QmitkDataStorageComboBox" name="m_NormalizationMaskBox">
+               <property name="toolTip">
+                <string>Select binary mask image.</string>
+               </property>
+              </widget>
+             </item>
+             <item row="0" column="0">
+              <widget class="QmitkDataStorageComboBox" name="m_NormalizationReferenceBox">
+               <property name="toolTip">
+                <string>Select normalization reference.</string>
+               </property>
+               <item>
+                <property name="text">
+                 <string>White matter</string>
+                </property>
+               </item>
+               <item>
+                <property name="text">
+                 <string>CSF</string>
+                </property>
+               </item>
+               <item>
+                <property name="text">
+                 <string>Voxel-wise baseline</string>
+                </property>
+               </item>
+              </widget>
+             </item>
+            </layout>
+           </widget>
+          </item>
+         </layout>
+        </widget>
+       </item>
        <item row="1" column="0">
         <widget class="QGroupBox" name="groupBox_2">
          <property name="title">
           <string>Resample image</string>
          </property>
          <layout class="QGridLayout" name="gridLayout_12">
           <item row="1" column="0">
            <widget class="QFrame" name="m_ResampleDoubleFrame">
             <property name="frameShape">
              <enum>QFrame::NoFrame</enum>
             </property>
             <property name="frameShadow">
              <enum>QFrame::Raised</enum>
             </property>
             <layout class="QGridLayout" name="gridLayout_5">
              <property name="leftMargin">
               <number>0</number>
              </property>
              <property name="topMargin">
               <number>0</number>
              </property>
              <property name="rightMargin">
               <number>0</number>
              </property>
              <property name="bottomMargin">
               <number>0</number>
              </property>
              <property name="spacing">
               <number>0</number>
              </property>
              <item row="0" column="1">
               <widget class="QDoubleSpinBox" name="m_ResampleDoubleY">
                <property name="minimum">
                 <double>0.010000000000000</double>
                </property>
                <property name="value">
                 <double>2.000000000000000</double>
                </property>
               </widget>
              </item>
              <item row="0" column="0">
               <widget class="QDoubleSpinBox" name="m_ResampleDoubleX">
                <property name="minimum">
                 <double>0.010000000000000</double>
                </property>
                <property name="value">
                 <double>2.000000000000000</double>
                </property>
               </widget>
              </item>
              <item row="0" column="2">
               <widget class="QDoubleSpinBox" name="m_ResampleDoubleZ">
                <property name="minimum">
                 <double>0.010000000000000</double>
                </property>
                <property name="value">
                 <double>2.000000000000000</double>
                </property>
               </widget>
              </item>
             </layout>
            </widget>
           </item>
           <item row="0" column="0">
            <widget class="QComboBox" name="m_ResampleTypeBox">
             <item>
              <property name="text">
               <string>Sampling factor</string>
              </property>
             </item>
             <item>
              <property name="text">
               <string>New image spacing</string>
              </property>
             </item>
             <item>
              <property name="text">
               <string>New image size</string>
              </property>
             </item>
            </widget>
           </item>
           <item row="3" column="0">
            <widget class="QFrame" name="frame_5">
             <property name="frameShape">
              <enum>QFrame::NoFrame</enum>
             </property>
             <property name="frameShadow">
              <enum>QFrame::Raised</enum>
             </property>
             <layout class="QGridLayout" name="gridLayout_14">
              <property name="leftMargin">
               <number>0</number>
              </property>
              <property name="topMargin">
               <number>0</number>
              </property>
              <property name="rightMargin">
               <number>0</number>
              </property>
              <property name="bottomMargin">
               <number>0</number>
              </property>
              <property name="spacing">
               <number>0</number>
              </property>
              <item row="0" column="0">
               <widget class="QLabel" name="label_3">
                <property name="text">
                 <string>Interpolator:</string>
                </property>
               </widget>
              </item>
              <item row="0" column="1">
               <widget class="QComboBox" name="m_InterpolatorBox">
                <item>
                 <property name="text">
                  <string>Nearest neighbour</string>
                 </property>
                </item>
                <item>
                 <property name="text">
                  <string>Linear</string>
                 </property>
                </item>
                <item>
                 <property name="text">
                  <string>B-spline</string>
                 </property>
                </item>
                <item>
                 <property name="text">
                  <string>Windowed sinc</string>
                 </property>
                </item>
               </widget>
              </item>
              <item row="1" column="0">
               <widget class="QCommandLinkButton" name="m_ResampleImageButton">
                <property name="enabled">
                 <bool>false</bool>
                </property>
                <property name="toolTip">
                 <string/>
                </property>
                <property name="statusTip">
                 <string/>
                </property>
                <property name="whatsThis">
                 <string notr="true"/>
                </property>
                <property name="text">
                 <string>Resample image</string>
                </property>
               </widget>
              </item>
             </layout>
            </widget>
           </item>
           <item row="2" column="0">
            <widget class="QFrame" name="m_ResampleIntFrame">
             <property name="frameShape">
              <enum>QFrame::NoFrame</enum>
             </property>
             <property name="frameShadow">
              <enum>QFrame::Raised</enum>
             </property>
             <layout class="QGridLayout" name="gridLayout_13">
              <property name="leftMargin">
               <number>0</number>
              </property>
              <property name="topMargin">
               <number>0</number>
              </property>
              <property name="rightMargin">
               <number>0</number>
              </property>
              <property name="bottomMargin">
               <number>0</number>
              </property>
              <property name="spacing">
               <number>0</number>
              </property>
              <item row="0" column="0">
               <widget class="QSpinBox" name="m_ResampleIntX">
                <property name="minimum">
                 <number>1</number>
                </property>
                <property name="maximum">
                 <number>10000</number>
                </property>
               </widget>
              </item>
              <item row="0" column="1">
               <widget class="QSpinBox" name="m_ResampleIntY">
                <property name="minimum">
                 <number>1</number>
                </property>
                <property name="maximum">
                 <number>10000</number>
                </property>
               </widget>
              </item>
              <item row="0" column="2">
               <widget class="QSpinBox" name="m_ResampleIntZ">
                <property name="minimum">
                 <number>1</number>
                </property>
                <property name="maximum">
                 <number>10000</number>
                </property>
               </widget>
              </item>
             </layout>
            </widget>
           </item>
          </layout>
         </widget>
        </item>
-       <item row="0" column="0">
-        <widget class="QFrame" name="frame_3">
-         <property name="frameShape">
-          <enum>QFrame::NoFrame</enum>
-         </property>
-         <property name="frameShadow">
-          <enum>QFrame::Raised</enum>
-         </property>
-         <layout class="QGridLayout" name="gridLayout_11">
-          <property name="leftMargin">
-           <number>0</number>
-          </property>
-          <property name="topMargin">
-           <number>0</number>
-          </property>
-          <property name="rightMargin">
-           <number>0</number>
-          </property>
-          <property name="bottomMargin">
-           <number>0</number>
-          </property>
-          <property name="horizontalSpacing">
-           <number>0</number>
-          </property>
-          <item row="2" column="0">
-           <widget class="QCommandLinkButton" name="m_ProjectSignalButton">
-            <property name="enabled">
-             <bool>false</bool>
-            </property>
-            <property name="toolTip">
-             <string>Project image values onto one b-shell.</string>
-            </property>
-            <property name="text">
-             <string>Project onto shell</string>
-            </property>
-           </widget>
-          </item>
-          <item row="1" column="1">
-           <widget class="QFrame" name="frame">
-            <property name="frameShape">
-             <enum>QFrame::NoFrame</enum>
-            </property>
-            <property name="frameShadow">
-             <enum>QFrame::Raised</enum>
-            </property>
-            <layout class="QFormLayout" name="formLayout_2">
-             <property name="leftMargin">
-              <number>0</number>
-             </property>
-             <property name="topMargin">
-              <number>0</number>
-             </property>
-             <property name="rightMargin">
-              <number>0</number>
-             </property>
-             <property name="bottomMargin">
-              <number>0</number>
-             </property>
-             <item row="0" column="1">
-              <widget class="QDoubleSpinBox" name="m_Blur">
-               <property name="toolTip">
-                <string comment="Accumulates the information that was acquired with multiple repetitions for one gradient. Vectors do not have to be precisely equal in order to be merged, if a &quot;Merge radius&quot; &gt; 0 is configured." extracomment="Accumulates the information that was acquired with multiple repetitions for one gradient. Vectors do not have to be precisely equal in order to be merged, if a &quot;Merge radius&quot; &gt; 0 is configured.">Accumulates the information that was acquired with multiple repetitions for one gradient. Vectors do not have to be precisely equal in order to be merged, if a &quot;Merge radius&quot; &gt; 0 is configured.</string>
-               </property>
-               <property name="statusTip">
-                <string comment="Accumulates the information that was acquired with multiple repetitions for one gradient. Vectors do not have to be precisely equal in order to be merged, if a &quot;Merge radius&quot; &gt; 0 is configured." extracomment="Accumulates the information that was acquired with multiple repetitions for one gradient. Vectors do not have to be precisely equal in order to be merged, if a &quot;Merge radius&quot; &gt; 0 is configured.">Accumulates the information that was acquired with multiple repetitions for one gradient. Vectors do not have to be precisely equal in order to be merged, if a &quot;Merge radius&quot; &gt; 0 is configured.</string>
-               </property>
-               <property name="whatsThis">
-                <string comment="Accumulates the information that was acquired with multiple repetitions for one gradient. Vectors do not have to be precisely equal in order to be merged, if a &quot;Merge radius&quot; &gt; 0 is configured." extracomment="Accumulates the information that was acquired with multiple repetitions for one gradient. Vectors do not have to be precisely equal in order to be merged, if a &quot;Merge radius&quot; &gt; 0 is configured.">Accumulates the information that was acquired with multiple repetitions for one gradient. Vectors do not have to be precisely equal in order to be merged, if a &quot;Merge radius&quot; &gt; 0 is configured.</string>
-               </property>
-               <property name="decimals">
-                <number>6</number>
-               </property>
-               <property name="maximum">
-                <double>2.000000000000000</double>
-               </property>
-               <property name="singleStep">
-                <double>0.000100000000000</double>
-               </property>
-               <property name="value">
-                <double>0.001000000000000</double>
-               </property>
-              </widget>
-             </item>
-             <item row="0" column="0">
-              <widget class="QLabel" name="label">
-               <property name="toolTip">
-                <string comment="Accumulates the information that was acquired with multiple repetitions for one gradient. Vectors do not have to be precisely equal in order to be merged, if a &quot;Merge radius&quot; &gt; 0 is configured." extracomment="Accumulates the information that was acquired with multiple repetitions for one gradient. Vectors do not have to be precisely equal in order to be merged, if a &quot;Merge radius&quot; &gt; 0 is configured.">Accumulates the information that was acquired with multiple repetitions for one gradient. Vectors do not have to be precisely equal in order to be merged, if a &quot;Merge radius&quot; &gt; 0 is configured.</string>
-               </property>
-               <property name="statusTip">
-                <string comment="Accumulates the information that was acquired with multiple repetitions for one gradient. Vectors do not have to be precisely equal in order to be merged, if a &quot;Merge radius&quot; &gt; 0 is configured." extracomment="Accumulates the information that was acquired with multiple repetitions for one gradient. Vectors do not have to be precisely equal in order to be merged, if a &quot;Merge radius&quot; &gt; 0 is configured.">Accumulates the information that was acquired with multiple repetitions for one gradient. Vectors do not have to be precisely equal in order to be merged, if a &quot;Merge radius&quot; &gt; 0 is configured.</string>
-               </property>
-               <property name="whatsThis">
-                <string comment="Accumulates the information that was acquired with multiple repetitions for one gradient. Vectors do not have to be precisely equal in order to be merged, if a &quot;Merge radius&quot; &gt; 0 is configured." extracomment="Accumulates the information that was acquired with multiple repetitions for one gradient. Vectors do not have to be precisely equal in order to be merged, if a &quot;Merge radius&quot; &gt; 0 is configured.">Accumulates the information that was acquired with multiple repetitions for one gradient. Vectors do not have to be precisely equal in order to be merged, if a &quot;Merge radius&quot; &gt; 0 is configured.</string>
-               </property>
-               <property name="text">
-                <string>Merge radius</string>
-               </property>
-              </widget>
-             </item>
-            </layout>
-           </widget>
-          </item>
-          <item row="1" column="0">
-           <widget class="QCommandLinkButton" name="m_ButtonAverageGradients">
-            <property name="enabled">
-             <bool>false</bool>
-            </property>
-            <property name="toolTip">
-             <string>Multiple acquistions of one gradient direction can be averaged. Due to rounding errors, similar gradients often differ in the last decimal positions. The Merge radius allows to average them by taking all directions within a certain radius into account.</string>
-            </property>
-            <property name="statusTip">
-             <string/>
-            </property>
-            <property name="whatsThis">
-             <string notr="true"/>
-            </property>
-            <property name="text">
-             <string>Average repetitions</string>
-            </property>
-           </widget>
-          </item>
-          <item row="3" column="1">
-           <widget class="QmitkDataStorageComboBox" name="m_NormalizationMaskBox">
-            <property name="toolTip">
-             <string>Select projection method.</string>
-            </property>
-           </widget>
-          </item>
-          <item row="2" column="1">
-           <widget class="QFrame" name="frame_4">
-            <property name="frameShape">
-             <enum>QFrame::NoFrame</enum>
-            </property>
-            <property name="frameShadow">
-             <enum>QFrame::Raised</enum>
-            </property>
-            <layout class="QGridLayout" name="gridLayout_4">
-             <property name="leftMargin">
-              <number>0</number>
-             </property>
-             <property name="topMargin">
-              <number>0</number>
-             </property>
-             <property name="rightMargin">
-              <number>0</number>
-             </property>
-             <property name="bottomMargin">
-              <number>0</number>
-             </property>
-             <property name="spacing">
-              <number>0</number>
-             </property>
-             <item row="0" column="0">
-              <widget class="QSpinBox" name="m_targetBValueSpinBox">
-               <property name="enabled">
-                <bool>false</bool>
-               </property>
-               <property name="toolTip">
-                <string>Target b-value</string>
-               </property>
-               <property name="maximum">
-                <number>100000</number>
-               </property>
-               <property name="singleStep">
-                <number>500</number>
-               </property>
-              </widget>
-             </item>
-             <item row="0" column="1">
-              <widget class="QComboBox" name="m_ProjectionMethodBox">
-               <property name="toolTip">
-                <string>Select projection method.</string>
-               </property>
-               <item>
-                <property name="text">
-                 <string>ADC Average</string>
-                </property>
-               </item>
-               <item>
-                <property name="text">
-                 <string>AKC</string>
-                </property>
-               </item>
-               <item>
-                <property name="text">
-                 <string>Bi-Exponential</string>
-                </property>
-               </item>
-              </widget>
-             </item>
-            </layout>
-           </widget>
-          </item>
-          <item row="3" column="0">
-           <widget class="QCommandLinkButton" name="m_NormalizeImageValuesButton">
-            <property name="enabled">
-             <bool>false</bool>
-            </property>
-            <property name="toolTip">
-             <string>Each image value is normalized with the corresponding baseline signal value.</string>
-            </property>
-            <property name="statusTip">
-             <string/>
-            </property>
-            <property name="whatsThis">
-             <string notr="true"/>
-            </property>
-            <property name="text">
-             <string>Normalize image values</string>
-            </property>
-           </widget>
-          </item>
-          <item row="5" column="0">
-           <widget class="QCommandLinkButton" name="m_MergeDwisButton">
-            <property name="enabled">
-             <bool>false</bool>
-            </property>
-            <property name="toolTip">
-             <string>Merges selected DWIs of same dimension. If several b-values are present, the resulting image will contain multiple b-shells.</string>
-            </property>
-            <property name="statusTip">
-             <string/>
-            </property>
-            <property name="whatsThis">
-             <string notr="true"/>
-            </property>
-            <property name="text">
-             <string>Merge selected DWIs</string>
-            </property>
-           </widget>
-          </item>
-         </layout>
-        </widget>
-       </item>
       </layout>
      </widget>
      <widget class="QWidget" name="tab_3">
       <attribute name="title">
        <string>Header</string>
       </attribute>
       <layout class="QGridLayout" name="gridLayout_7">
        <item row="7" column="0">
         <spacer name="verticalSpacer_2">
          <property name="orientation">
           <enum>Qt::Vertical</enum>
          </property>
          <property name="sizeHint" stdset="0">
           <size>
            <width>20</width>
            <height>40</height>
           </size>
          </property>
         </spacer>
        </item>
        <item row="2" column="0">
         <widget class="QGroupBox" name="groupBox_3">
          <property name="title">
           <string>Voxel size</string>
          </property>
          <layout class="QGridLayout" name="gridLayout_16">
           <property name="leftMargin">
            <number>0</number>
           </property>
           <property name="rightMargin">
            <number>0</number>
           </property>
           <property name="bottomMargin">
            <number>0</number>
           </property>
           <item row="0" column="0">
            <widget class="QDoubleSpinBox" name="m_HeaderSpacingX">
             <property name="decimals">
              <number>4</number>
             </property>
            </widget>
           </item>
           <item row="0" column="1">
            <widget class="QDoubleSpinBox" name="m_HeaderSpacingY">
             <property name="decimals">
              <number>4</number>
             </property>
            </widget>
           </item>
           <item row="0" column="2">
            <widget class="QDoubleSpinBox" name="m_HeaderSpacingZ">
             <property name="decimals">
              <number>4</number>
             </property>
             <property name="minimum">
              <double>0.000000000000000</double>
             </property>
             <property name="maximum">
              <double>99.989999999999995</double>
             </property>
            </widget>
           </item>
           <item row="1" column="0">
            <widget class="QCommandLinkButton" name="m_ModifySpacingButton">
             <property name="enabled">
              <bool>false</bool>
             </property>
             <property name="toolTip">
              <string/>
             </property>
             <property name="statusTip">
              <string/>
             </property>
             <property name="whatsThis">
              <string notr="true"/>
             </property>
             <property name="text">
              <string>Set new voxel size</string>
             </property>
            </widget>
           </item>
          </layout>
         </widget>
        </item>
        <item row="3" column="0">
         <widget class="QGroupBox" name="groupBox_6">
          <property name="title">
           <string>Image size</string>
          </property>
          <layout class="QGridLayout" name="gridLayout_15">
           <property name="leftMargin">
            <number>0</number>
           </property>
           <property name="rightMargin">
            <number>0</number>
           </property>
           <property name="bottomMargin">
            <number>0</number>
           </property>
           <item row="1" column="0">
            <widget class="QLabel" name="label_6">
             <property name="text">
              <string>y:</string>
             </property>
            </widget>
           </item>
           <item row="1" column="1">
            <widget class="QSpinBox" name="m_YstartBox">
             <property name="toolTip">
              <string>Number of pixels to remove on lower image bound.</string>
             </property>
             <property name="maximum">
              <number>999999999</number>
             </property>
            </widget>
           </item>
           <item row="2" column="2">
            <widget class="QSpinBox" name="m_ZendBox">
             <property name="toolTip">
              <string>Number of pixels to remove on upper image bound.</string>
             </property>
             <property name="maximum">
              <number>999999999</number>
             </property>
            </widget>
           </item>
           <item row="0" column="2">
            <widget class="QSpinBox" name="m_XendBox">
             <property name="toolTip">
              <string>Number of pixels to remove on upper image bound.</string>
             </property>
             <property name="maximum">
              <number>999999999</number>
             </property>
            </widget>
           </item>
           <item row="0" column="1">
            <widget class="QSpinBox" name="m_XstartBox">
             <property name="toolTip">
              <string>Number of pixels to remove on lower image bound.</string>
             </property>
             <property name="maximum">
              <number>999999999</number>
             </property>
            </widget>
           </item>
           <item row="0" column="0">
            <widget class="QLabel" name="label_4">
             <property name="text">
              <string>x:</string>
             </property>
            </widget>
           </item>
           <item row="2" column="1">
            <widget class="QSpinBox" name="m_ZstartBox">
             <property name="toolTip">
              <string>Number of pixels to remove on lower image bound.</string>
             </property>
             <property name="maximum">
              <number>999999999</number>
             </property>
            </widget>
           </item>
           <item row="1" column="2">
            <widget class="QSpinBox" name="m_YendBox">
             <property name="toolTip">
              <string>Number of pixels to remove on upper image bound.</string>
             </property>
             <property name="maximum">
              <number>999999999</number>
             </property>
            </widget>
           </item>
           <item row="2" column="0">
            <widget class="QLabel" name="label_7">
             <property name="text">
              <string>z:</string>
             </property>
            </widget>
           </item>
           <item row="3" column="0">
            <widget class="QCommandLinkButton" name="m_CropImageButton">
             <property name="enabled">
              <bool>false</bool>
             </property>
             <property name="toolTip">
              <string/>
             </property>
             <property name="statusTip">
              <string/>
             </property>
             <property name="whatsThis">
              <string notr="true"/>
             </property>
             <property name="text">
              <string>Crop image</string>
             </property>
            </widget>
           </item>
          </layout>
         </widget>
        </item>
        <item row="1" column="0">
         <widget class="QGroupBox" name="groupBox_5">
          <property name="title">
           <string>Origin</string>
          </property>
          <layout class="QGridLayout" name="gridLayout_17">
           <property name="leftMargin">
            <number>0</number>
           </property>
           <property name="rightMargin">
            <number>0</number>
           </property>
           <property name="bottomMargin">
            <number>0</number>
           </property>
           <item row="0" column="0">
            <widget class="QDoubleSpinBox" name="m_HeaderOriginX">
             <property name="decimals">
              <number>4</number>
             </property>
             <property name="minimum">
              <double>-999999999.000000000000000</double>
             </property>
             <property name="maximum">
              <double>999999999.000000000000000</double>
             </property>
            </widget>
           </item>
           <item row="0" column="2">
            <widget class="QDoubleSpinBox" name="m_HeaderOriginZ">
             <property name="decimals">
              <number>4</number>
             </property>
             <property name="minimum">
              <double>-999999999.000000000000000</double>
             </property>
             <property name="maximum">
              <double>999999999.000000000000000</double>
             </property>
            </widget>
           </item>
           <item row="0" column="1">
            <widget class="QDoubleSpinBox" name="m_HeaderOriginY">
             <property name="decimals">
              <number>4</number>
             </property>
             <property name="minimum">
              <double>-99999999.000000000000000</double>
             </property>
             <property name="maximum">
              <double>999999999.000000000000000</double>
             </property>
            </widget>
           </item>
           <item row="1" column="0">
            <widget class="QCommandLinkButton" name="m_ModifyOriginButton">
             <property name="enabled">
              <bool>false</bool>
             </property>
             <property name="toolTip">
              <string/>
             </property>
             <property name="statusTip">
              <string/>
             </property>
             <property name="whatsThis">
              <string notr="true"/>
             </property>
             <property name="text">
              <string>Set new origin</string>
             </property>
            </widget>
           </item>
          </layout>
         </widget>
        </item>
        <item row="2" column="1">
         <spacer name="horizontalSpacer_3">
          <property name="orientation">
           <enum>Qt::Horizontal</enum>
          </property>
          <property name="sizeHint" stdset="0">
           <size>
            <width>40</width>
            <height>20</height>
           </size>
          </property>
         </spacer>
        </item>
        <item row="5" column="0">
         <widget class="QGroupBox" name="groupBox">
          <property name="title">
           <string>Direction matrix</string>
          </property>
          <layout class="QGridLayout" name="gridLayout_3">
           <property name="leftMargin">
            <number>0</number>
           </property>
           <property name="topMargin">
            <number>9</number>
           </property>
           <property name="rightMargin">
            <number>0</number>
           </property>
           <property name="bottomMargin">
            <number>0</number>
           </property>
           <item row="0" column="0">
            <widget class="QTableWidget" name="m_DirectionMatrixTable">
             <property name="enabled">
              <bool>false</bool>
             </property>
             <property name="sizePolicy">
              <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
               <horstretch>0</horstretch>
               <verstretch>0</verstretch>
              </sizepolicy>
             </property>
             <property name="minimumSize">
              <size>
               <width>0</width>
               <height>0</height>
              </size>
             </property>
             <property name="cursor" stdset="0">
              <cursorShape>IBeamCursor</cursorShape>
             </property>
             <property name="autoFillBackground">
              <bool>true</bool>
             </property>
             <property name="verticalScrollBarPolicy">
              <enum>Qt::ScrollBarAlwaysOff</enum>
             </property>
             <property name="horizontalScrollBarPolicy">
              <enum>Qt::ScrollBarAlwaysOff</enum>
             </property>
             <property name="showGrid">
              <bool>true</bool>
             </property>
             <property name="cornerButtonEnabled">
              <bool>false</bool>
             </property>
             <attribute name="horizontalHeaderVisible">
              <bool>false</bool>
             </attribute>
             <attribute name="horizontalHeaderCascadingSectionResizes">
              <bool>true</bool>
             </attribute>
             <attribute name="horizontalHeaderHighlightSections">
              <bool>true</bool>
             </attribute>
             <attribute name="horizontalHeaderMinimumSectionSize">
              <number>0</number>
             </attribute>
             <attribute name="verticalHeaderVisible">
              <bool>false</bool>
             </attribute>
             <attribute name="verticalHeaderCascadingSectionResizes">
              <bool>true</bool>
             </attribute>
             <attribute name="verticalHeaderHighlightSections">
              <bool>true</bool>
             </attribute>
             <row>
              <property name="text">
               <string>New Row</string>
              </property>
             </row>
             <row>
              <property name="text">
               <string>New Row</string>
              </property>
             </row>
             <row>
              <property name="text">
               <string>New Row</string>
              </property>
             </row>
             <column>
              <property name="text">
               <string>New Column</string>
              </property>
             </column>
             <column>
              <property name="text">
               <string>New Column</string>
              </property>
             </column>
             <column>
              <property name="text">
               <string>New Column</string>
              </property>
             </column>
            </widget>
           </item>
           <item row="1" column="0">
            <widget class="QCommandLinkButton" name="m_ModifyDirection">
             <property name="enabled">
              <bool>false</bool>
             </property>
             <property name="toolTip">
              <string>Diffusion encoding gradient directions are rotated accordingly.</string>
             </property>
             <property name="statusTip">
              <string/>
             </property>
             <property name="whatsThis">
              <string notr="true"/>
             </property>
             <property name="text">
              <string>Apply new direction</string>
             </property>
            </widget>
           </item>
           <item row="0" column="1">
            <spacer name="horizontalSpacer_2">
             <property name="orientation">
              <enum>Qt::Horizontal</enum>
             </property>
             <property name="sizeHint" stdset="0">
              <size>
               <width>40</width>
               <height>20</height>
              </size>
             </property>
            </spacer>
           </item>
          </layout>
         </widget>
        </item>
        <item row="6" column="0">
         <widget class="QGroupBox" name="groupBox_4">
          <property name="sizePolicy">
           <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
            <horstretch>0</horstretch>
            <verstretch>0</verstretch>
           </sizepolicy>
          </property>
          <property name="title">
           <string>Measurment frame</string>
          </property>
          <layout class="QGridLayout" name="gridLayout">
           <property name="leftMargin">
            <number>0</number>
           </property>
           <property name="rightMargin">
            <number>0</number>
           </property>
           <property name="bottomMargin">
            <number>0</number>
           </property>
           <item row="0" column="1">
            <spacer name="horizontalSpacer">
             <property name="orientation">
              <enum>Qt::Horizontal</enum>
             </property>
             <property name="sizeHint" stdset="0">
              <size>
               <width>40</width>
               <height>20</height>
              </size>
             </property>
            </spacer>
           </item>
           <item row="0" column="0">
            <widget class="QTableWidget" name="m_MeasurementFrameTable">
             <property name="enabled">
              <bool>false</bool>
             </property>
             <property name="sizePolicy">
              <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
               <horstretch>0</horstretch>
               <verstretch>0</verstretch>
              </sizepolicy>
             </property>
             <property name="minimumSize">
              <size>
               <width>0</width>
               <height>0</height>
              </size>
             </property>
             <property name="cursor" stdset="0">
              <cursorShape>IBeamCursor</cursorShape>
             </property>
             <property name="autoFillBackground">
              <bool>true</bool>
             </property>
             <property name="verticalScrollBarPolicy">
              <enum>Qt::ScrollBarAlwaysOff</enum>
             </property>
             <property name="horizontalScrollBarPolicy">
              <enum>Qt::ScrollBarAlwaysOff</enum>
             </property>
             <property name="showGrid">
              <bool>true</bool>
             </property>
             <property name="cornerButtonEnabled">
              <bool>false</bool>
             </property>
             <attribute name="horizontalHeaderVisible">
              <bool>false</bool>
             </attribute>
             <attribute name="horizontalHeaderCascadingSectionResizes">
              <bool>true</bool>
             </attribute>
             <attribute name="horizontalHeaderHighlightSections">
              <bool>true</bool>
             </attribute>
             <attribute name="horizontalHeaderMinimumSectionSize">
              <number>0</number>
             </attribute>
             <attribute name="verticalHeaderVisible">
              <bool>false</bool>
             </attribute>
             <attribute name="verticalHeaderCascadingSectionResizes">
              <bool>true</bool>
             </attribute>
             <attribute name="verticalHeaderHighlightSections">
              <bool>true</bool>
             </attribute>
             <row>
              <property name="text">
               <string>New Row</string>
              </property>
             </row>
             <row>
              <property name="text">
               <string>New Row</string>
              </property>
             </row>
             <row>
              <property name="text">
               <string>New Row</string>
              </property>
             </row>
             <column>
              <property name="text">
               <string>New Column</string>
              </property>
             </column>
             <column>
              <property name="text">
               <string>New Column</string>
              </property>
             </column>
             <column>
              <property name="text">
               <string>New Column</string>
              </property>
             </column>
            </widget>
           </item>
           <item row="1" column="0">
            <widget class="QCommandLinkButton" name="m_ModifyMeasurementFrame">
             <property name="enabled">
              <bool>false</bool>
             </property>
             <property name="toolTip">
              <string>Diffusion encoding gradient directions are rotated accordingly.</string>
             </property>
             <property name="statusTip">
              <string/>
             </property>
             <property name="whatsThis">
              <string notr="true"/>
             </property>
             <property name="text">
              <string>Apply new measurement frame</string>
             </property>
            </widget>
           </item>
          </layout>
         </widget>
        </item>
        <item row="4" column="0">
         <widget class="QGroupBox" name="groupBox_7">
          <property name="title">
           <string>Remove or extract gradient volumes</string>
          </property>
          <layout class="QGridLayout" name="gridLayout_18">
           <item row="0" column="0">
            <widget class="QCommandLinkButton" name="m_RemoveGradientButton">
             <property name="enabled">
              <bool>false</bool>
             </property>
             <property name="toolTip">
              <string>Generate pointset displaying the gradient vectors (applied measurement frame).</string>
             </property>
             <property name="statusTip">
              <string/>
             </property>
             <property name="whatsThis">
              <string notr="true"/>
             </property>
             <property name="text">
              <string>Remove</string>
             </property>
            </widget>
           </item>
           <item row="1" column="0">
            <widget class="QCommandLinkButton" name="m_ExtractGradientButton">
             <property name="enabled">
              <bool>false</bool>
             </property>
             <property name="toolTip">
              <string>Generate pointset displaying the gradient vectors (applied measurement frame).</string>
             </property>
             <property name="statusTip">
              <string/>
             </property>
             <property name="whatsThis">
              <string notr="true"/>
             </property>
             <property name="text">
              <string>Extract</string>
             </property>
            </widget>
           </item>
           <item row="1" column="1">
            <widget class="QSpinBox" name="m_ExtractGradientBox"/>
           </item>
           <item row="0" column="1">
            <widget class="QSpinBox" name="m_RemoveGradientBox"/>
           </item>
          </layout>
         </widget>
        </item>
       </layout>
      </widget>
      <widget class="QWidget" name="tab_2">
       <attribute name="title">
        <string>Other</string>
       </attribute>
       <layout class="QGridLayout" name="gridLayout_9">
        <item row="0" column="1">
         <widget class="QCheckBox" name="m_CheckExtractAll">
          <property name="toolTip">
           <string>Create a 3D+t data set containing all b0 images as timesteps</string>
          </property>
          <property name="text">
           <string>Disable averaging</string>
          </property>
         </widget>
        </item>
        <item row="0" column="0">
         <widget class="QCommandLinkButton" name="m_ButtonExtractB0">
          <property name="enabled">
           <bool>false</bool>
          </property>
          <property name="toolTip">
           <string>If multiple baseline acquisitions are present, the default behaviour is to output an averaged image.</string>
          </property>
          <property name="statusTip">
           <string/>
          </property>
          <property name="whatsThis">
           <string notr="true"/>
          </property>
          <property name="text">
           <string>Extract baseline image</string>
          </property>
         </widget>
        </item>
        <item row="3" column="0">
         <spacer name="verticalSpacer_3">
          <property name="orientation">
           <enum>Qt::Vertical</enum>
          </property>
          <property name="sizeHint" stdset="0">
           <size>
            <width>20</width>
            <height>40</height>
           </size>
          </property>
         </spacer>
        </item>
        <item row="1" column="0">
         <widget class="QCommandLinkButton" name="m_CalcAdcButton">
          <property name="enabled">
           <bool>false</bool>
          </property>
          <property name="toolTip">
           <string>If multiple baseline acquisitions are present, the default behaviour is to output an averaged image.</string>
          </property>
          <property name="statusTip">
           <string/>
          </property>
          <property name="whatsThis">
           <string notr="true"/>
          </property>
          <property name="text">
           <string>Calculate ADC map</string>
          </property>
         </widget>
        </item>
        <item row="2" column="0">
         <widget class="QCommandLinkButton" name="m_ExtractBrainMask">
          <property name="enabled">
           <bool>false</bool>
          </property>
          <property name="toolTip">
           <string>If multiple baseline acquisitions are present, the default behaviour is to output an averaged image.</string>
          </property>
          <property name="statusTip">
           <string/>
          </property>
          <property name="whatsThis">
           <string notr="true"/>
          </property>
          <property name="text">
           <string>Estimate binary brain mask</string>
          </property>
         </widget>
        </item>
        <item row="2" column="1">
         <widget class="QSpinBox" name="m_BrainMaskIterationsBox">
          <property name="toolTip">
           <string>Maximum number of iterations.</string>
          </property>
          <property name="maximum">
           <number>10000</number>
          </property>
          <property name="value">
           <number>10000</number>
          </property>
         </widget>
        </item>
       </layout>
      </widget>
     </widget>
    </item>
   </layout>
  </widget>
  <layoutdefault spacing="6" margin="11"/>
  <customwidgets>
   <customwidget>
    <class>QmitkDataStorageComboBox</class>
    <extends>QComboBox</extends>
    <header location="global">QmitkDataStorageComboBox.h</header>
   </customwidget>
  </customwidgets>
  <tabstops>
   <tabstop>m_B_ValueMap_Rounder_SpinBox</tabstop>
   <tabstop>m_Blur</tabstop>
   <tabstop>m_targetBValueSpinBox</tabstop>
   <tabstop>m_ProjectionMethodBox</tabstop>
-  <tabstop>m_NormalizationMaskBox</tabstop>
   <tabstop>m_ResampleTypeBox</tabstop>
   <tabstop>m_ResampleDoubleX</tabstop>
   <tabstop>m_ResampleDoubleY</tabstop>
   <tabstop>m_ResampleDoubleZ</tabstop>
   <tabstop>m_ResampleIntX</tabstop>
   <tabstop>m_ResampleIntY</tabstop>
   <tabstop>m_ResampleIntZ</tabstop>
   <tabstop>m_InterpolatorBox</tabstop>
   <tabstop>m_HeaderSpacingX</tabstop>
   <tabstop>m_HeaderSpacingY</tabstop>
   <tabstop>m_HeaderSpacingZ</tabstop>
   <tabstop>m_HeaderOriginX</tabstop>
   <tabstop>m_HeaderOriginY</tabstop>
   <tabstop>m_HeaderOriginZ</tabstop>
   <tabstop>m_DirectionMatrixTable</tabstop>
   <tabstop>m_MeasurementFrameTable</tabstop>
   <tabstop>m_CheckExtractAll</tabstop>
   <tabstop>m_BrainMaskIterationsBox</tabstop>
   <tabstop>tabWidget</tabstop>
   <tabstop>m_B_ValueMap_TableWidget</tabstop>
   <tabstop>m_CreateLengthCorrectedDwi</tabstop>
   <tabstop>m_ShowGradientsButton</tabstop>
   <tabstop>m_MirrorGradientToHalfSphereButton</tabstop>
   <tabstop>m_ReduceGradientsButton</tabstop>
   <tabstop>m_ButtonAverageGradients</tabstop>
   <tabstop>m_ProjectSignalButton</tabstop>
   <tabstop>m_NormalizeImageValuesButton</tabstop>
   <tabstop>m_MergeDwisButton</tabstop>
   <tabstop>m_ResampleImageButton</tabstop>
   <tabstop>m_ModifySpacingButton</tabstop>
   <tabstop>m_ModifyOriginButton</tabstop>
   <tabstop>m_ModifyDirection</tabstop>
   <tabstop>m_ModifyMeasurementFrame</tabstop>
   <tabstop>m_ButtonExtractB0</tabstop>
   <tabstop>m_CalcAdcButton</tabstop>
   <tabstop>m_ExtractBrainMask</tabstop>
  </tabstops>
  <resources/>
  <connections/>
 </ui>