Medical Imaging Interaction Toolkit  2021.10.99-9c07a326
Medical Imaging Interaction Toolkit
mitkModelFitFunctorPolicy.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef MODELFITFUNCTOR_POLICY_H
14 #define MODELFITFUNCTOR_POLICY_H
15 
16 #include "itkIndex.h"
18 #include "MitkModelFitExports.h"
19 
20 namespace mitk
21 {
22 
24  {
25  public:
28 
31 
34 
36 
38  {};
39 
41 
42  unsigned int GetNumberOfOutputs() const
43  {
44  unsigned int result = 0;
45 
46  if (m_Functor.IsNotNull() && m_ModelParameterizer.IsNotNull())
47  {
48  ParameterizerType::ModelBasePointer tempModel = m_ModelParameterizer->GenerateParameterizedModel();
49  result = m_Functor->GetNumberOfOutputs(tempModel);
50  }
51 
52  return result;
53  }
54 
56  {
57  if (!functor)
58  {
59  itkGenericExceptionMacro( << "Error. Functor is Null.");
60  }
61 
62  m_Functor = functor;
63  }
64 
65  void SetModelParameterizer(const ParameterizerType* parameterizer)
66  {
67  if (!parameterizer)
68  {
69  itkGenericExceptionMacro( << "Error. Parameterizer is Null.");
70  }
71 
72  m_ModelParameterizer = parameterizer;
73  }
74 
75  bool operator!=(const ModelFitFunctorPolicy& other) const
76  {
77  return !(*this == other);
78  }
79 
80  bool operator==(const ModelFitFunctorPolicy& other) const
81  {
82  return (this->m_Functor == other.m_Functor) &&
83  (this->m_ModelParameterizer == other.m_ModelParameterizer);
84  }
85 
86  inline OutputPixelArrayType operator()(const InputPixelArrayType& value,
87  const IndexType& currentIndex) const
88  {
89  if (!m_Functor)
90  {
91  itkGenericExceptionMacro( << "Error. Cannot process operator(). Functor is Null.");
92  }
93 
94  if (!m_ModelParameterizer)
95  {
96  itkGenericExceptionMacro( << "Error. Cannot process operator(). Parameterizer is Null.");
97  }
98 
99  ParameterizerType::ModelBasePointer parameterizedModel =
100  m_ModelParameterizer->GenerateParameterizedModel(currentIndex);
101  ParameterizerType::ParametersType initialParams = m_ModelParameterizer->GetInitialParameterization(
102  currentIndex);
103  OutputPixelArrayType result = m_Functor->Compute(value, parameterizedModel, initialParams);
104 
105  return result;
106  }
107 
108  private:
109 
110  FunctorConstPointer m_Functor;
111  ParameterizerConstPointer m_ModelParameterizer;
112  };
113 
114 }
115 
116 
117 #endif // LEVENBERGMARQUARDTMODELFITFUNCTOR_H
bool operator!=(const ModelFitFunctorPolicy &other) const
std::vector< ParameterImagePixelType > InputPixelArrayType
DataCollection - Class to facilitate loading/accessing structured data.
void SetModelFitFunctor(const mitk::ModelFitFunctorBase *functor)
ModelFitFunctorBase::InputPixelArrayType OutputPixelArrayType
#define MITKMODELFIT_EXPORT
ModelFitFunctorBase::InputPixelArrayType InputPixelArrayType
mitk::ModelParameterizerBase ParameterizerType
ModelFitFunctorBase::ConstPointer FunctorConstPointer
OutputPixelArrayType operator()(const InputPixelArrayType &value, const IndexType &currentIndex) const
ParameterizerType::ConstPointer ParameterizerConstPointer
bool operator==(const ModelFitFunctorPolicy &other) const
ModelBaseType::ParametersType ParametersType
void SetModelParameterizer(const ParameterizerType *parameterizer)