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