Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
itkDwiGradientLengthCorrectionFilter.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 
18 Program: Tensor ToolKit - TTK
19 Module: $URL: svn://scm.gforge.inria.fr/svn/ttk/trunk/Algorithms/itkElectrostaticRepulsionDiffusionGradientReductionFilter.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 
34 
36  : m_ReferenceBValue(0)
37  , m_RoundingValue(0)
38  , m_ReferenceGradientDirectionContainer(nullptr)
39  , m_OutputGradientDirectionContainer(nullptr)
40 {
41 }
42 
44 {
45 }
46 
48 {
49 
50  if(m_ReferenceBValue == 0 || m_RoundingValue == 0 || m_ReferenceGradientDirectionContainer.IsNull())
51  itkExceptionMacro("Wrong initialization");
52 
53  m_OutputGradientDirectionContainer = GradientDirectionContainerType::New();
54 
55  m_NewBValue = itk::NumericTraits<double>::max();
56  GradientDirectionContainerType::ConstIterator it = m_ReferenceGradientDirectionContainer->Begin();
57  for(; it != m_ReferenceGradientDirectionContainer->End(); ++it)
58  {
59  const double twonorm = it.Value().two_norm();
60  const double currentBValue = m_ReferenceBValue*twonorm*twonorm ;
61  const double roundedBValue = int((currentBValue + 0.5 * m_RoundingValue)/m_RoundingValue)*m_RoundingValue;
62 
63  if (roundedBValue<m_NewBValue && roundedBValue>1)
64  m_NewBValue = roundedBValue;
65  }
66 
67  it = m_ReferenceGradientDirectionContainer->Begin();
68  for(; it != m_ReferenceGradientDirectionContainer->End(); ++it)
69  {
70  const double twonorm = it.Value().two_norm();
71  const double currentBValue = m_ReferenceBValue*twonorm*twonorm ;
72  const double roundedBValue = int((currentBValue + 0.5 * m_RoundingValue)/m_RoundingValue)*m_RoundingValue;
73 
74  if (roundedBValue>1)
75  {
76  const double f = std::sqrt(roundedBValue/m_NewBValue);
77  GradientDirectionType grad = it.Value();
78  m_OutputGradientDirectionContainer->push_back( grad.normalize() * f );
79  }
80  else
81  {
82  GradientDirectionType grad; grad.fill(0.0);
83  m_OutputGradientDirectionContainer->push_back( grad );
84  }
85  }
86 }
static T max(T x, T y)
Definition: svm.cpp:70
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.