Medical Imaging Interaction Toolkit  2026.06.00
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 
49  template <typename ElementToOutput1, typename ElementToOutput2>
51  ElementToOutput1 elem1, ElementToOutput2 elem2, mitk::ScalarType eps, bool verbose, bool isEqual)
52  {
53  if (verbose && !isEqual)
54  {
55  MITK_INFO << typeid(ElementToOutput1).name() << " and " << typeid(ElementToOutput2).name()
56  << " not equal. Lefthandside " << std::setprecision(12) << elem1 << " - Righthandside " << elem2
57  << " - epsilon " << eps;
58  }
59  }
60 
71  inline bool Equal(ScalarType scalar1, ScalarType scalar2, ScalarType eps = mitk::eps, bool verbose = false)
72  {
73  bool isEqual(!DifferenceBiggerOrEqualEps(scalar1 - scalar2, eps));
74 
75  ConditionalOutputOfDifference(scalar1, scalar2, eps, verbose, isEqual);
76 
77  return isEqual;
78  }
79 }
80 
81 #endif
#define MITK_INFO
Log an informational message.
Definition: mitkLog.h:358
Find image slices visible on a given plane.
MITKCORE_EXPORT const ScalarType eps
Epsilon value for floating point comparison (vnl_math::eps * 100).
void ConditionalOutputOfDifference(ElementToOutput1 elem1, ElementToOutput2 elem2, mitk::ScalarType eps, bool verbose, bool isEqual)
Conditionally output the difference between two elements to the log.
Definition: mitkEqual.h:50
bool DifferenceBiggerOrEqualEps(DifferenceType diff, mitk::ScalarType epsilon=mitk::eps)
Check if the absolute difference is bigger than or equal to a given epsilon.
Definition: mitkEqual.h:32
double ScalarType
Scalar type used throughout MITK for geometric computations.
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.