Medical Imaging Interaction Toolkit  2022.04.99-01b95b17
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 /*
14  * mitkEqual.h
15  *
16  * Created on: Apr 14, 2014
17  * Author: wirkert
18  */
19 
20 #ifndef MITKEQUAL_H_
21 #define MITKEQUAL_H_
22 
23 #include <cmath>
24 #include <iomanip>
25 
26 #include "mitkLogMacros.h"
27 #include "mitkNumericConstants.h"
28 
29 namespace mitk
30 {
38  template <typename DifferenceType>
39  inline bool DifferenceBiggerOrEqualEps(DifferenceType diff, mitk::ScalarType epsilon = mitk::eps)
40  {
41  return std::fabs(diff) >= epsilon;
42  }
43 
54  template <typename ElementToOutput1, typename ElementToOutput2>
56  ElementToOutput1 elem1, ElementToOutput2 elem2, mitk::ScalarType eps, bool verbose, bool isEqual)
57  {
58  if (verbose && !isEqual)
59  {
60  MITK_INFO << typeid(ElementToOutput1).name() << " and " << typeid(ElementToOutput2).name()
61  << " not equal. Lefthandside " << std::setprecision(12) << elem1 << " - Righthandside " << elem2
62  << " - epsilon " << eps;
63  }
64  }
65 
75  inline bool Equal(ScalarType scalar1, ScalarType scalar2, ScalarType eps = mitk::eps, bool verbose = false)
76  {
77  bool isEqual(!DifferenceBiggerOrEqualEps(scalar1 - scalar2, eps));
78 
79  ConditionalOutputOfDifference(scalar1, scalar2, eps, verbose, isEqual);
80 
81  return isEqual;
82  }
83 }
84 
85 #endif /* MITKEQUAL_H_ */
void ConditionalOutputOfDifference(ElementToOutput1 elem1, ElementToOutput2 elem2, mitk::ScalarType eps, bool verbose, bool isEqual)
Definition: mitkEqual.h:55
MITKCORE_EXPORT const ScalarType eps
#define MITK_INFO
Definition: mitkLogMacros.h:18
double ScalarType
DataCollection - Class to facilitate loading/accessing structured data.
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.
bool DifferenceBiggerOrEqualEps(DifferenceType diff, mitk::ScalarType epsilon=mitk::eps)
Definition: mitkEqual.h:39