Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
itkTensorToL2NormImageFilter.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/itkTensorToL2NormImageFilter.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_TensorToL2NormImageFilter_txx_
33 #define _itk_TensorToL2NormImageFilter_txx_
34 #endif
35 
36 #include "itkTensorToL2NormImageFilter.h"
37 #include <itkImageRegionIterator.h>
38 #include <itkImageRegionConstIterator.h>
39 
40 namespace itk
41 {
42 
43  template <class TInputImage, class TOutputImage>
44  void TensorToL2NormImageFilter<TInputImage, TOutputImage>::ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, ThreadIdType threadId )
45  {
46  typedef ImageRegionIterator<OutputImageType> IteratorOutputType;
47  typedef ImageRegionConstIterator<InputImageType> IteratorInputType;
48 
49  unsigned long numPixels = outputRegionForThread.GetNumberOfPixels();
50  unsigned long step = numPixels/100;
51  unsigned long progress = 0;
52 
53  IteratorOutputType itOut(this->GetOutput(), outputRegionForThread);
54  IteratorInputType itIn(this->GetInput(), outputRegionForThread);
55 
56  if( threadId==0 )
57  this->UpdateProgress (0.0);
58 
59  while(!itOut.IsAtEnd())
60  {
61  if( this->GetAbortGenerateData() )
62  throw itk::ProcessAborted(__FILE__,__LINE__);
63 
64 
65  OutputPixelType out = static_cast<OutputPixelType>( 0.0 ); // be careful, overload in MedINRIA
66 
67  InputPixelType T = itIn.Get();
68 
69  if ( !(T[0]==0 && T[1]==0 && T[2]==0 && T[3]==0 && T[4]==0 && T[5]==0) )
70  {
71  double sum = T[0]*T[0] + T[3]*T[3] + T[5]*T[5]
72  + T[1]*T[2]*2.0 + T[2]*T[4]*2.0 + T[1]*T[4]*2.0;
73  out = static_cast<OutputPixelType>( vcl_sqrt( sum ));
74  }
75 
76  if( threadId==0 && step>0)
77  {
78  if( (progress%step)==0 )
79  this->UpdateProgress ( double(progress)/double(numPixels) );
80  }
81 
82 
83  itOut.Set (out);
84  ++progress;
85  ++itOut;
86  ++itIn;
87 
88  }
89 
90  if( threadId==0 )
91  this->UpdateProgress (1.0);
92 
93  }
94 
95 
96 
97 } // end of namespace