1 /*===================================================================
3 The Medical Imaging Interaction Toolkit (MITK)
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 See LICENSE.txt or http://www.mitk.org for details.
15 ===================================================================*/
16 /*=========================================================================
18 Program: Tensor ToolKit - TTK
19 Module: $URL: svn://scm.gforge.inria.fr/svn/ttk/trunk/Algorithms/itkTensorImageToQBallImageFilter.txx $
21 Date: $Date: 2010-06-07 13:39:13 +0200 (Mo, 07 Jun 2010) $
22 Version: $Revision: 68 $
24 Copyright (c) INRIA 2010. All rights reserved.
25 See LICENSE.txt for details.
27 This software is distributed WITHOUT ANY WARRANTY; without even
28 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
29 PURPOSE. See the above copyright notices for more information.
31 =========================================================================*/
32 #ifndef _itk_TensorImageToQBallImageFilter_txx_
33 #define _itk_TensorImageToQBallImageFilter_txx_
36 #include "itkTensorImageToQBallImageFilter.h"
37 #include <itkImageRegionIterator.h>
38 #include <itkImageRegionConstIterator.h>
39 #include <itkOrientationDistributionFunction.h>
43 template <class TInputScalarType, class TOutputScalarType>
45 TensorImageToQBallImageFilter<TInputScalarType, TOutputScalarType>
46 ::BeforeThreadedGenerateData()
48 typename OutputImageType::Pointer outImage = OutputImageType::New();
49 outImage->SetSpacing( this->GetInput()->GetSpacing() ); // Set the image spacing
50 outImage->SetOrigin( this->GetInput()->GetOrigin() ); // Set the image origin
51 outImage->SetDirection( this->GetInput()->GetDirection() ); // Set the image direction
52 outImage->SetLargestPossibleRegion( this->GetInput()->GetLargestPossibleRegion());
53 outImage->SetBufferedRegion( this->GetInput()->GetLargestPossibleRegion() );
54 outImage->SetRequestedRegion( this->GetInput()->GetLargestPossibleRegion() );
56 outImage->FillBuffer(0.0);
58 this->SetNumberOfRequiredOutputs (1);
59 this->SetNthOutput (0, outImage);
62 template <class TInputScalarType, class TOutputScalarType>
64 TensorImageToQBallImageFilter<TInputScalarType, TOutputScalarType>
65 ::ThreadedGenerateData (const OutputImageRegionType &outputRegionForThread, ThreadIdType threadId )
68 typedef ImageRegionIterator<OutputImageType> IteratorOutputType;
69 typedef ImageRegionConstIterator<InputImageType> IteratorInputType;
71 unsigned long numPixels = outputRegionForThread.GetNumberOfPixels();
72 unsigned long step = numPixels/100;
73 unsigned long progress = 0;
75 IteratorOutputType itOut (this->GetOutput(), outputRegionForThread);
76 IteratorInputType itIn (this->GetInput(), outputRegionForThread);
79 this->UpdateProgress (0.0);
82 while(!itIn.IsAtEnd())
84 if( this->GetAbortGenerateData() )
86 throw itk::ProcessAborted(__FILE__,__LINE__);
89 InputPixelType T = itIn.Get();
93 float tensorelems[6] = {
101 itk::DiffusionTensor3D<float> tensor(tensorelems);
103 itk::OrientationDistributionFunction<TOutputScalarType, QBALL_ODFSIZE> odf;
104 odf.InitFromTensor(tensor);
107 for( unsigned int i=0; i<QBALL_ODFSIZE; i++)
108 out[i] = odf.GetElement(i);
112 if( threadId==0 && step>0)
114 if( (progress%step)==0 )
116 this->UpdateProgress ( double(progress)/double(numPixels) );
127 this->UpdateProgress (1.0);
129 MITK_INFO << "one thread finished Q-Ball estimation";
131 } // end of namespace