Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
itkTensorImageToQBallImageFilter.txx
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 /*=========================================================================
17 
18 Program: Tensor ToolKit - TTK
19 Module: $URL: svn://scm.gforge.inria.fr/svn/ttk/trunk/Algorithms/itkTensorImageToQBallImageFilter.txx $
20 Language: C++
21 Date: $Date: 2010-06-07 13:39:13 +0200 (Mo, 07 Jun 2010) $
22 Version: $Revision: 68 $
23 
24 Copyright (c) INRIA 2010. All rights reserved.
25 See LICENSE.txt for details.
26 
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.
30 
31 =========================================================================*/
32 #ifndef _itk_TensorImageToQBallImageFilter_txx_
33 #define _itk_TensorImageToQBallImageFilter_txx_
34 #endif
35 
36 #include "itkTensorImageToQBallImageFilter.h"
37 #include <itkImageRegionIterator.h>
38 #include <itkImageRegionConstIterator.h>
39 #include <itkOrientationDistributionFunction.h>
40 
41 namespace itk
42 {
43  template <class TInputScalarType, class TOutputScalarType>
44  void
45  TensorImageToQBallImageFilter<TInputScalarType, TOutputScalarType>
46  ::BeforeThreadedGenerateData()
47  {
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() );
55  outImage->Allocate();
56  outImage->FillBuffer(0.0);
57 
58  this->SetNumberOfRequiredOutputs (1);
59  this->SetNthOutput (0, outImage);
60  }
61 
62  template <class TInputScalarType, class TOutputScalarType>
63  void
64  TensorImageToQBallImageFilter<TInputScalarType, TOutputScalarType>
65  ::ThreadedGenerateData (const OutputImageRegionType &outputRegionForThread, ThreadIdType threadId )
66  {
67 
68  typedef ImageRegionIterator<OutputImageType> IteratorOutputType;
69  typedef ImageRegionConstIterator<InputImageType> IteratorInputType;
70 
71  unsigned long numPixels = outputRegionForThread.GetNumberOfPixels();
72  unsigned long step = numPixels/100;
73  unsigned long progress = 0;
74 
75  IteratorOutputType itOut (this->GetOutput(), outputRegionForThread);
76  IteratorInputType itIn (this->GetInput(), outputRegionForThread);
77 
78  if( threadId==0 )
79  this->UpdateProgress (0.0);
80 
81 
82  while(!itIn.IsAtEnd())
83  {
84  if( this->GetAbortGenerateData() )
85  {
86  throw itk::ProcessAborted(__FILE__,__LINE__);
87  }
88 
89  InputPixelType T = itIn.Get();
90 
91  OutputPixelType out;
92 
93  float tensorelems[6] = {
94  (float)T[0],
95  (float)T[1],
96  (float)T[2],
97  (float)T[3],
98  (float)T[4],
99  (float)T[5],
100  };
101  itk::DiffusionTensor3D<float> tensor(tensorelems);
102 
103  itk::OrientationDistributionFunction<TOutputScalarType, QBALL_ODFSIZE> odf;
104  odf.InitFromTensor(tensor);
105  odf.Normalize();
106 
107  for( unsigned int i=0; i<QBALL_ODFSIZE; i++)
108  out[i] = odf.GetElement(i);
109 
110  itOut.Set(out);
111 
112  if( threadId==0 && step>0)
113  {
114  if( (progress%step)==0 )
115  {
116  this->UpdateProgress ( double(progress)/double(numPixels) );
117  }
118  }
119 
120  ++progress;
121  ++itIn;
122  ++itOut;
123  }
124 
125  if( threadId==0 )
126  {
127  this->UpdateProgress (1.0);
128  }
129  MITK_INFO << "one thread finished Q-Ball estimation";
130  }
131 } // end of namespace