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/itkTensorToL2NormImageFilter.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_TensorToL2NormImageFilter_txx_
33 #define _itk_TensorToL2NormImageFilter_txx_
36 #include "itkTensorToL2NormImageFilter.h"
37 #include <itkImageRegionIterator.h>
38 #include <itkImageRegionConstIterator.h>
43 template <class TInputImage, class TOutputImage>
44 void TensorToL2NormImageFilter<TInputImage, TOutputImage>::ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, ThreadIdType threadId )
46 typedef ImageRegionIterator<OutputImageType> IteratorOutputType;
47 typedef ImageRegionConstIterator<InputImageType> IteratorInputType;
49 unsigned long numPixels = outputRegionForThread.GetNumberOfPixels();
50 unsigned long step = numPixels/100;
51 unsigned long progress = 0;
53 IteratorOutputType itOut(this->GetOutput(), outputRegionForThread);
54 IteratorInputType itIn(this->GetInput(), outputRegionForThread);
57 this->UpdateProgress (0.0);
59 while(!itOut.IsAtEnd())
61 if( this->GetAbortGenerateData() )
62 throw itk::ProcessAborted(__FILE__,__LINE__);
65 OutputPixelType out = static_cast<OutputPixelType>( 0.0 ); // be careful, overload in MedINRIA
67 InputPixelType T = itIn.Get();
69 if ( !(T[0]==0 && T[1]==0 && T[2]==0 && T[3]==0 && T[4]==0 && T[5]==0) )
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 ));
76 if( threadId==0 && step>0)
78 if( (progress%step)==0 )
79 this->UpdateProgress ( double(progress)/double(numPixels) );
91 this->UpdateProgress (1.0);