Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
itkDiffusionQballPrepareVisualizationImageFilter.cpp
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 __itkDiffusionQballPrepareVisualizationImageFilter_cpp
18 #define __itkDiffusionQballPrepareVisualizationImageFilter_cpp
19 
20 #include <time.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 
25 #include "itkImageRegionConstIterator.h"
26 #include "itkImageRegionConstIteratorWithIndex.h"
27 #include "itkImageRegionIterator.h"
28 #include "itkArray.h"
29 #include "vnl/vnl_vector.h"
31 
32 #define _USE_MATH_DEFINES
33 #include <math.h>
34 
35 namespace itk {
36 
37  //#define QBALL_RECON_PI M_PI
38 
39  template< class TOdfPixelType, int NrOdfDirections>
42  m_Threshold(0),
43  m_ScaleByGfaType(GfaFilterType::GFA_STANDARD),
44  m_DoScaleGfa(false),
45  m_GfaParam1(2),
46  m_GfaParam2(1)
47  {
48  // At least 1 inputs is necessary for a vector image.
49  // For images added one at a time we need at least six
50  this->SetNumberOfRequiredInputs( 1 );
51  }
52 
53  template< class TOdfPixelType,
54  int NrOdfDirections>
56  NrOdfDirections>
57  ::BeforeThreadedGenerateData()
58  {
59  if( m_NormalizationMethod == PV_GLOBAL_MAX )
60  {
61  typename InputImageType::Pointer inputImagePointer = NULL;
62  inputImagePointer = static_cast< InputImageType * >(
63  this->ProcessObject::GetInput(0) );
64 
65  typename GfaFilterType::Pointer filter = GfaFilterType::New();
66  filter->SetInput(inputImagePointer);
67  filter->SetNumberOfThreads(4);
68  filter->SetComputationMethod(GfaFilterType::GFA_MAX_ODF_VALUE);
69  filter->Update();
70 
71  typedef typename itk::MinimumMaximumImageCalculator< typename GfaFilterType::OutputImageType >
72  MaxFilterType;
73  typename MaxFilterType::Pointer maxFilter = MaxFilterType::New();
74  maxFilter->SetImage(filter->GetOutput());
75  maxFilter->ComputeMaximum();
76 
77  m_GlobalInputMaximum = maxFilter->GetMaximum();
78  }
79 
80  //if(m_DoScaleGfa)
81  {
82  typename InputImageType::Pointer inputImagePointer = NULL;
83  inputImagePointer = static_cast< InputImageType * >(
84  this->ProcessObject::GetInput(0) );
85 
86  typename GfaFilterType::Pointer filter = GfaFilterType::New();
87  filter->SetInput(inputImagePointer);
88  filter->SetNumberOfThreads(4);
89  filter->SetComputationMethod(m_ScaleByGfaType);
90  filter->SetParam1(m_GfaParam1);
91  filter->SetParam2(m_GfaParam2);
92  filter->Update();
93  m_GfaImage = filter->GetOutput();
94  }
95  }
96 
97  template< class TOdfPixelType,
98  int NrOdfDirections>
100  NrOdfDirections>
101  ::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread,
102  ThreadIdType )
103  {
104  typename OutputImageType::Pointer outputImage =
105  static_cast< OutputImageType * >(this->ProcessObject::GetOutput(0));
106  ImageRegionIterator< OutputImageType > oit(outputImage, outputRegionForThread);
107  oit.GoToBegin();
108 
110  typedef ImageRegionConstIterator< InputImageType > InputIteratorType;
111  typedef typename InputImageType::PixelType OdfVectorType;
112  typename InputImageType::Pointer inputImagePointer = NULL;
113  inputImagePointer = static_cast< InputImageType * >(
114  this->ProcessObject::GetInput(0) );
115  InputIteratorType git(inputImagePointer, outputRegionForThread );
116  git.GoToBegin();
117 
118  typedef ImageRegionConstIterator< GfaImageType > GfaIteratorType;
119  GfaIteratorType gfaIt(m_GfaImage, outputRegionForThread);
120 
121  while( !git.IsAtEnd() )
122  {
123  OdfVectorType b = git.Get();
124  OdfType odf = b.GetDataPointer();
125 
126  switch( m_NormalizationMethod )
127  {
128  case PV_NONE:
129  {
130  break;
131  }
132  case PV_MAX:
133  {
134  odf = odf.MaxNormalize();
135  break;
136  }
137  case PV_MIN_MAX:
138  {
139  odf = odf.MinMaxNormalize();
140  break;
141  }
142  case PV_GLOBAL_MAX:
143  {
144  odf *= 1.0/m_GlobalInputMaximum;
145  break;
146  }
147  case PV_MIN_MAX_INVERT:
148  {
149  odf = odf.MinMaxNormalize();
150  for(int i=0; i<NrOdfDirections; i++)
151  {
152  odf[i] = 1.0 - odf[i];
153  }
154  break;
155  }
156  }
157 
158  if(m_DoScaleGfa)
159  {
160  odf *= gfaIt.Get();
161  ++gfaIt;
162  }
163 
164  odf *= 0.5;
165  oit.Set( odf.GetDataPointer() );
166  ++oit;
167  ++git; // Gradient image iterator
168  }
169 
170  std::cout << "One Thread finished extraction" << std::endl;
171  }
172 
173  template< class TOdfPixelType,
174  int NrOdfDirections>
176  NrOdfDirections>
177  ::PrintSelf(std::ostream& os, Indent indent) const
178  {
179  Superclass::PrintSelf(os,indent);
180  os << indent << "m_Threshold: " <<
181  m_Threshold << std::endl;
182  }
183 
184 }
185 
186 #endif // __itkDiffusionQballPrepareVisualizationImageFilter_cpp
itk::SmartPointer< Self > Pointer
Represents an ODF for Q-Ball imaging.
unsigned short PixelType
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.