Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
mitkEqual.h
Go to the documentation of this file.
1 /*
2  * mitkEqual.h
3  *
4  * Created on: Apr 14, 2014
5  * Author: wirkert
6  */
7 
8 #ifndef MITKEQUAL_H_
9 #define MITKEQUAL_H_
10 
11 #include <iomanip>
12 
13 #include "mitkLogMacros.h"
14 #include "mitkNumericConstants.h"
15 
16 namespace mitk
17 {
25  template <typename DifferenceType>
26  inline bool DifferenceBiggerOrEqualEps(DifferenceType diff, mitk::ScalarType epsilon = mitk::eps)
27  {
28  return fabs(diff) >= epsilon;
29  }
30 
41  template <typename ElementToOutput1, typename ElementToOutput2>
43  ElementToOutput1 elem1, ElementToOutput2 elem2, mitk::ScalarType eps, bool verbose, bool isEqual)
44  {
45  if (verbose && !isEqual)
46  {
47  MITK_INFO << typeid(ElementToOutput1).name() << " and " << typeid(ElementToOutput2).name()
48  << " not equal. Lefthandside " << std::setprecision(12) << elem1 << " - Righthandside " << elem2
49  << " - epsilon " << eps;
50  }
51  }
52 
62  inline bool Equal(ScalarType scalar1, ScalarType scalar2, ScalarType eps = mitk::eps, bool verbose = false)
63  {
64  bool isEqual(!DifferenceBiggerOrEqualEps(scalar1 - scalar2, eps));
65 
66  ConditionalOutputOfDifference(scalar1, scalar2, eps, verbose, isEqual);
67 
68  return isEqual;
69  }
70 }
71 
72 #endif /* MITKEQUAL_H_ */
void ConditionalOutputOfDifference(ElementToOutput1 elem1, ElementToOutput2 elem2, mitk::ScalarType eps, bool verbose, bool isEqual)
Definition: mitkEqual.h:42
#define MITK_INFO
Definition: mitkLogMacros.h:22
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.
MITKCORE_EXPORT const ScalarType eps
bool DifferenceBiggerOrEqualEps(DifferenceType diff, mitk::ScalarType epsilon=mitk::eps)
Definition: mitkEqual.h:26