Medical Imaging Interaction Toolkit  2018.4.99-e1268d66
Medical Imaging Interaction Toolkit
mitkMVConstrainedCostFunctionDecorator.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 (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 
14 
15 #include <iostream>
16 
17 #include <mitkExceptionMacro.h>
18 
20  mitk::MVConstrainedCostFunctionDecorator::CalcMeasure(const ParametersType &parameters, const SignalType & /*signal*/) const
21 {
22  if (m_ConstraintChecker.IsNull()) mitkThrow()<<"Error. Cannot calc measure. Constraint checker is not set";
23  if (m_WrappedCostFunction.IsNull()) mitkThrow()<<"Error. Cannot calc measure. Wrapped metric is not set";
24 
26 
27  PenaltyValueType penalty = m_ConstraintChecker->GetPenaltySum(parameters);
28 
29  MeasureType measure;
30  measure.SetSize(m_WrappedCostFunction->GetNumberOfValues());
31  measure.Fill(penalty);
32 
34  {
35  MeasureType wrappedMeasure = m_WrappedCostFunction->GetValue(parameters);
36  if (wrappedMeasure.Size() != measure.Size()) mitkThrow()<<"Error. Cannot calc measure. Penalty measure and wrapped measure have different size. Penalty size:"<<measure.Size()<<"; wrapped measure size: "<<wrappedMeasure.Size();
37 
38  for(unsigned int i=0; i<measure.GetSize(); ++i)
39  {
40  measure[i] += wrappedMeasure[i];
41  }
42  if (penalty > 0)
43  {
45  }
46  }
47  else
48  {
49  auto penalties = m_ConstraintChecker->GetPenalties(parameters);
50  for (ParametersType::size_type pos = 0; pos < penalties.size(); ++pos)
51  {
52  if (penalties[pos] >= m_FailureThreshold)
53  {
55  break;
56  }
57  }
59  }
60 
61  return measure;
62 }
63 
64 double
67 {
68  return m_PenaltyCount / (double)m_EvaluationCount;
69 };
70 
71 double
74 {
75  return m_FailureCount / (double)m_EvaluationCount;
76 };
77 
78 mitk::MVConstrainedCostFunctionDecorator::ParametersType::size_type
81 {
82  return m_LastFailedParameter;
83 };
#define mitkThrow()
MeasureType CalcMeasure(const ParametersType &parameters, const SignalType &signal) const override
ConstraintCheckerBase::PenaltyValueType PenaltyValueType