Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
itkDiffusionQballGeneralizedFaImageFilter.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 #ifndef __itkDiffusionQballGeneralizedFaImageFilter_txx
18 #define __itkDiffusionQballGeneralizedFaImageFilter_txx
19 
20 #include <time.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 
24 #define _USE_MATH_DEFINES
25 #include <math.h>
26 
27 #include "itkImageRegionConstIterator.h"
28 #include "itkImageRegionConstIteratorWithIndex.h"
29 #include "itkImageRegionIterator.h"
30 #include "itkArray.h"
31 #include "vnl/vnl_vector.h"
32 #include "itkOrientationDistributionFunction.h"
33 
34 namespace itk {
35 
36  //#define QBALL_RECON_PI M_PI
37 
38  template< class TOdfPixelType,
39  class TGfaPixelType,
40  int NrOdfDirections>
41  DiffusionQballGeneralizedFaImageFilter< TOdfPixelType,
42  TGfaPixelType, NrOdfDirections>
43  ::DiffusionQballGeneralizedFaImageFilter() :
44  m_ComputationMethod(GFA_STANDARD)
45  {
46  // At least 1 inputs is necessary for a vector image.
47  // For images added one at a time we need at least six
48  this->SetNumberOfRequiredInputs( 1 );
49  }
50 
51  template< class TOdfPixelType,
52  class TGfaPixelType,
53  int NrOdfDirections>
54  void DiffusionQballGeneralizedFaImageFilter< TOdfPixelType,
55  TGfaPixelType, NrOdfDirections>
56  ::BeforeThreadedGenerateData()
57  {
58  }
59 
60  template< class TOdfPixelType,
61  class TGfaPixelType,
62  int NrOdfDirections>
63  void DiffusionQballGeneralizedFaImageFilter< TOdfPixelType,
64  TGfaPixelType, NrOdfDirections>
65  ::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread,
66  ThreadIdType )
67  {
68  typename OutputImageType::Pointer outputImage =
69  static_cast< OutputImageType * >(this->ProcessObject::GetOutput(0));
70 
71  ImageRegionIterator< OutputImageType > oit(outputImage, outputRegionForThread);
72  oit.GoToBegin();
73 
74  typedef itk::OrientationDistributionFunction<TOdfPixelType,NrOdfDirections> OdfType;
75  typedef ImageRegionConstIterator< InputImageType > InputIteratorType;
76  typedef typename InputImageType::PixelType OdfVectorType;
77  typename InputImageType::Pointer inputImagePointer = NULL;
78  inputImagePointer = static_cast< InputImageType * >(
79  this->ProcessObject::GetInput(0) );
80 
81  InputIteratorType git(inputImagePointer, outputRegionForThread );
82  git.GoToBegin();
83  while( !git.IsAtEnd() )
84  {
85  OdfVectorType b = git.Get();
86  TGfaPixelType outval = -1;
87 
88  switch( m_ComputationMethod )
89  {
90  case GFA_STANDARD:
91  {
92  OdfType odf = b.GetDataPointer();
93  outval = odf.GetGeneralizedFractionalAnisotropy();
94  break;
95  }
96  case GFA_QUANTILES_HIGH_LOW:
97  {
98  vnl_vector_fixed<TOdfPixelType,NrOdfDirections> sorted;
99  for(int i=0; i<NrOdfDirections; i++)
100  {
101  sorted[i] = b[i];
102  }
103  std::sort( sorted.begin(), sorted.end() );
104  double q60 = sorted[floor(0.6*(double)NrOdfDirections+0.5)];
105  double q95 = sorted[floor(0.95*(double)NrOdfDirections+0.5)];
106  outval = q95/q60 - 1.0;
107  break;
108  }
109  case GFA_QUANTILE_HIGH:
110  {
111  vnl_vector_fixed<TOdfPixelType,NrOdfDirections> sorted;
112  for(int i=0; i<NrOdfDirections; i++)
113  {
114  sorted[i] = b[i];
115  }
116  std::sort( sorted.begin(), sorted.end() );
117  //double q40 = sorted[floor(0.4*(double)NrOdfDirections+0.5)];
118  double q95 = sorted[floor(0.95*(double)NrOdfDirections+0.5)];
119  outval = q95;
120  break;
121  }
122  case GFA_MAX_ODF_VALUE:
123  {
124  outval = b.GetVnlVector().max_value();
125  break;
126  }
127  case GFA_DECONVOLUTION_COEFFS:
128  {
129  break;
130  }
131  case GFA_MIN_MAX_NORMALIZED_STANDARD:
132  {
133  OdfType odf = b.GetDataPointer();
134  odf = odf.MinMaxNormalize();
135  outval = odf.GetGeneralizedFractionalAnisotropy();
136  break;
137  }
138  case GFA_NORMALIZED_ENTROPY:
139  {
140  OdfType odf = b.GetDataPointer();
141  outval = odf.GetNormalizedEntropy();
142  break;
143  }
144  case GFA_NEMATIC_ORDER_PARAMETER:
145  {
146  OdfType odf = b.GetDataPointer();
147  outval = odf.GetNematicOrderParameter();
148  break;
149  }
150  case GFA_QUANTILE_LOW:
151  {
152  vnl_vector_fixed<TOdfPixelType,NrOdfDirections> sorted;
153  for(int i=0; i<NrOdfDirections; i++)
154  {
155  sorted[i] = b[i];
156  }
157  std::sort( sorted.begin(), sorted.end() );
158  //double q40 = sorted[floor(0.4*(double)NrOdfDirections+0.5)];
159  double q05 = sorted[floor(0.05*(double)NrOdfDirections+0.5)];
160  outval = q05;
161  break;
162  }
163  case GFA_MIN_ODF_VALUE:
164  {
165  outval = b.GetVnlVector().min_value();
166  break;
167  }
168  case GFA_QUANTILES_LOW_HIGH:
169  {
170  vnl_vector_fixed<TOdfPixelType,NrOdfDirections> sorted;
171  for(int i=0; i<NrOdfDirections; i++)
172  {
173  sorted[i] = b[i];
174  }
175  std::sort( sorted.begin(), sorted.end() );
176  double q05 = sorted[floor(0.05*(double)NrOdfDirections+0.5)];
177  double q40 = sorted[floor(0.4*(double)NrOdfDirections+0.5)];
178  outval = q40/q05 - 1.0;
179  break;
180  }
181  case GFA_STD_BY_MAX:
182  {
183  OdfType odf = b.GetDataPointer();
184  outval = odf.GetStdDevByMaxValue();
185  break;
186  }
187  case GFA_PRINCIPLE_CURVATURE:
188  {
189  OdfType odf = b.GetDataPointer();
190  outval = odf.GetPrincipleCurvature(m_Param1, m_Param2, 0);
191  break;
192  }
193  case GFA_GENERALIZED_GFA:
194  {
195  OdfType odf = b.GetDataPointer();
196  outval = odf.GetGeneralizedGFA(m_Param1, m_Param2);
197  break;
198  }
199  }
200 
201  oit.Set( outval );
202 
203  ++oit;
204  ++git; // Gradient image iterator
205  }
206 
207  std::cout << "One Thread finished calculation" << std::endl;
208  }
209 
210  template< class TOdfPixelType,
211  class TGfaPixelType,
212  int NrOdfDirections>
213  void DiffusionQballGeneralizedFaImageFilter< TOdfPixelType,
214  TGfaPixelType, NrOdfDirections>
215  ::PrintSelf(std::ostream& os, Indent indent) const
216  {
217  Superclass::PrintSelf(os,indent);
218  }
219 
220 }
221 
222 #endif // __itkDiffusionQballGeneralizedFaImageFilter_txx