void setUp()
    {
        // reference files
        m_InputDwi = dynamic_cast<mitk::DiffusionImage<short>*>(mitk::IOUtil::LoadDataNode(GetTestDataFilePath("DiffusionImaging/Fiberfox/StickBall_RELAX.dwi"))->GetData());

        // parameter setup
        m_Parameters = FiberfoxParameters<short>();
        m_Parameters.m_SignalGen.m_ImageRegion = m_InputDwi->GetVectorImage()->GetLargestPossibleRegion();
        m_Parameters.m_SignalGen.m_ImageSpacing = m_InputDwi->GetVectorImage()->GetSpacing();
        m_Parameters.m_SignalGen.m_ImageOrigin = m_InputDwi->GetVectorImage()->GetOrigin();
        m_Parameters.m_SignalGen.m_ImageDirection = m_InputDwi->GetVectorImage()->GetDirection();
        m_Parameters.m_SignalGen.m_Bvalue = m_InputDwi->GetReferenceBValue();
        m_Parameters.m_SignalGen.SetGradienDirections(m_InputDwi->GetDirections());
    }
void StartSimulation(FiberfoxParameters<double> parameters, FiberBundleX::Pointer fiberBundle, mitk::DiffusionImage<short>::Pointer refImage, string message)
{
    itk::TractsToDWIImageFilter< short >::Pointer tractsToDwiFilter = itk::TractsToDWIImageFilter< short >::New();
    tractsToDwiFilter->SetUseConstantRandSeed(true);
    tractsToDwiFilter->SetParameters(parameters);
    tractsToDwiFilter->SetFiberBundle(fiberBundle);
    tractsToDwiFilter->Update();

    mitk::DiffusionImage<short>::Pointer testImage = mitk::DiffusionImage<short>::New();
    testImage->SetVectorImage( tractsToDwiFilter->GetOutput() );
    testImage->SetReferenceBValue(parameters.m_SignalGen.m_Bvalue);
    testImage->SetDirections(parameters.m_SignalGen.GetGradientDirections());
    testImage->InitializeFromVectorImage();

    if (refImage.IsNotNull())
    {
        bool cond = CompareDwi(testImage->GetVectorImage(), refImage->GetVectorImage());
        if (!cond)
        {
            MITK_INFO << "Saving test and rference image to " << mitk::IOUtil::GetTempPath();
            mitk::IOUtil::SaveBaseData(testImage, mitk::IOUtil::GetTempPath()+"testImage.dwi");
            mitk::IOUtil::SaveBaseData(refImage, mitk::IOUtil::GetTempPath()+"refImage.dwi");
        }
        MITK_TEST_CONDITION_REQUIRED(cond, message);
    }
}
    void StartSimulation(string testFileName)
    {
        mitk::DiffusionImage<short>::Pointer refImage = NULL;
        if (!testFileName.empty())
            CPPUNIT_ASSERT(refImage = dynamic_cast<mitk::DiffusionImage<short>*>(mitk::IOUtil::LoadDataNode(testFileName)->GetData()));

        itk::AddArtifactsToDwiImageFilter< short >::Pointer artifactsToDwiFilter = itk::AddArtifactsToDwiImageFilter< short >::New();
        artifactsToDwiFilter->SetUseConstantRandSeed(true);
        artifactsToDwiFilter->SetInput(m_InputDwi->GetVectorImage());
        artifactsToDwiFilter->SetParameters(m_Parameters);
        CPPUNIT_ASSERT_NO_THROW(artifactsToDwiFilter->Update());

        mitk::DiffusionImage<short>::Pointer testImage = mitk::DiffusionImage<short>::New();
        testImage->SetVectorImage( artifactsToDwiFilter->GetOutput() );
        testImage->SetReferenceBValue( m_Parameters.m_SignalGen.m_Bvalue);
        testImage->SetDirections( m_Parameters.m_SignalGen.GetGradientDirections());
        testImage->InitializeFromVectorImage();

        if (refImage.IsNotNull())
        {
            if (!CompareDwi(testImage->GetVectorImage(), refImage->GetVectorImage()))
                mitk::IOUtil::SaveBaseData(testImage, mitk::IOUtil::GetTempPath()+"testImage.dwi");
            CPPUNIT_ASSERT_MESSAGE(testFileName, CompareDwi(testImage->GetVectorImage(), refImage->GetVectorImage()));
        }
    }
    void StartSimulation(string testFileName)
    {
        mitk::DiffusionImage<short>::Pointer refImage = NULL;
        if (!testFileName.empty())
            CPPUNIT_ASSERT(refImage = dynamic_cast<mitk::DiffusionImage<short>*>(mitk::IOUtil::LoadDataNode(testFileName)->GetData()));

        itk::AddArtifactsToDwiImageFilter< short >::Pointer artifactsToDwiFilter = itk::AddArtifactsToDwiImageFilter< short >::New();
        artifactsToDwiFilter->SetUseConstantRandSeed(true);
        artifactsToDwiFilter->SetInput(m_InputDwi->GetVectorImage());
        artifactsToDwiFilter->SetParameters(m_Parameters);
        CPPUNIT_ASSERT_NO_THROW(artifactsToDwiFilter->Update());

        mitk::DiffusionImage<short>::Pointer testImage = mitk::DiffusionImage<short>::New();
        testImage->SetVectorImage( artifactsToDwiFilter->GetOutput() );
        testImage->SetB_Value(m_Parameters.m_Bvalue);
        testImage->SetDirections(m_Parameters.GetGradientDirections());
        testImage->InitializeFromVectorImage();

        if (refImage.IsNotNull())
        {
            bool ok = CompareDwi(testImage->GetVectorImage(), refImage->GetVectorImage());
            if (!ok)
            {
                mitk::IOUtil::SaveBaseData(testImage, "/tmp/test2.dwi");
                mitk::IOUtil::SaveBaseData(refImage, "/tmp/ref2.dwi");
            }
            CPPUNIT_ASSERT_MESSAGE(testFileName, ok);
        }
        else
        {
            mitk::IOUtil::SaveBaseData(testImage, "/local/distortions2.dwi");
        }
    }
void QmitkPreprocessingView::CallMultishellToSingleShellFilter(itk::DWIVoxelFunctor * functor, mitk::DiffusionImage<DiffusionPixelType>::Pointer ImPtr, QString imageName)
{
  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);

  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);
  }
}