Medical Imaging Interaction Toolkit  2024.06.99-60d9b802
Medical Imaging Interaction Toolkit
mitkEqual.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 mitkEqual_h
14 #define mitkEqual_h
15 
16 #include <cmath>
17 #include <iomanip>
18 
19 #include "mitkLog.h"
20 #include "mitkNumericConstants.h"
21 
22 namespace mitk
23 {
31  template <typename DifferenceType>
32  inline bool DifferenceBiggerOrEqualEps(DifferenceType diff, mitk::ScalarType epsilon = mitk::eps)
33  {
34  return std::fabs(diff) >= epsilon;
35  }
36 
47  template <typename ElementToOutput1, typename ElementToOutput2>
49  ElementToOutput1 elem1, ElementToOutput2 elem2, mitk::ScalarType eps, bool verbose, bool isEqual)
50  {
51  if (verbose && !isEqual)
52  {
53  MITK_INFO << typeid(ElementToOutput1).name() << " and " << typeid(ElementToOutput2).name()
54  << " not equal. Lefthandside " << std::setprecision(12) << elem1 << " - Righthandside " << elem2
55  << " - epsilon " << eps;
56  }
57  }
58 
68  inline bool Equal(ScalarType scalar1, ScalarType scalar2, ScalarType eps = mitk::eps, bool verbose = false)
69  {
70  bool isEqual(!DifferenceBiggerOrEqualEps(scalar1 - scalar2, eps));
71 
72  ConditionalOutputOfDifference(scalar1, scalar2, eps, verbose, isEqual);
73 
74  return isEqual;
75  }
76 }
77 
78 #endif
mitk::eps
const MITKCORE_EXPORT ScalarType eps
MITK_INFO
#define MITK_INFO
Definition: mitkLog.h:209
mitk::Equal
MITKNEWMODULE_EXPORT bool Equal(mitk::ExampleDataStructure *leftHandSide, mitk::ExampleDataStructure *rightHandSide, mitk::ScalarType eps, bool verbose)
Returns true if the example data structures are considered equal.
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
mitkLog.h
mitkNumericConstants.h
mitk::DifferenceBiggerOrEqualEps
bool DifferenceBiggerOrEqualEps(DifferenceType diff, mitk::ScalarType epsilon=mitk::eps)
Definition: mitkEqual.h:32
mitk::ConditionalOutputOfDifference
void ConditionalOutputOfDifference(ElementToOutput1 elem1, ElementToOutput2 elem2, mitk::ScalarType eps, bool verbose, bool isEqual)
Definition: mitkEqual.h:48
mitk::ScalarType
double ScalarType
Definition: mitkNumericConstants.h:20