Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkBaseDataCompare.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 mitkBaseDataCompare_h_included
14 #define mitkBaseDataCompare_h_included
15 
16 #include "mitkBaseData.h"
17 
18 namespace mitk
19 {
45  {
46  private:
53  virtual bool InternalAreEqual(const BaseData &left,
54  const BaseData &right,
56  bool verbose = false) = 0;
57 
61  bool AreSameClasses(const BaseData *left, const BaseData *right, bool verbose = false);
62 
63  public:
76  bool AreEqual(const BaseData *left, const BaseData *right, ScalarType eps = mitk::eps, bool verbose = false);
77 
81  static void RegisterCoreEquals();
82  };
83 
91  template <class T>
93  {
94  private:
95  bool InternalAreEqual(const BaseData &left,
96  const BaseData &right,
98  bool verbose = false) override
99  {
100  try
101  {
102  const T &leftT = dynamic_cast<const T &>(left);
103  const T &rightT = dynamic_cast<const T &>(right);
104 
105  return mitk::Equal(leftT, rightT, eps, verbose);
106  }
107  catch (const std::exception &e)
108  {
109  MITK_ERROR << "Bad cast in BaseDataCompareT<>::InternalAreEqual()" << e.what();
110  }
111 
112  return false;
113  }
114  };
115 
126  template <class T>
128  {
129  private:
130  bool InternalAreEqual(const BaseData &left,
131  const BaseData &right,
133  bool verbose = false) override
134  {
135  try
136  {
137  const T &leftT = dynamic_cast<const T &>(left);
138  const T &rightT = dynamic_cast<const T &>(right);
139 
140  T &leftTNonConst = const_cast<T &>(leftT);
141  T &rightTNonConst = const_cast<T &>(rightT);
142 
143  return mitk::Equal(leftTNonConst, rightTNonConst, eps, verbose);
144  }
145  catch (const std::exception &e)
146  {
147  MITK_ERROR << "Bad cast in BaseDataCompareTNonConst<>::InternalAreEqual(): " << e.what();
148  }
149 
150  return false;
151  }
152  };
153 
154 } // namespace
155 
156 #endif
Base of all data objects.
Definition: mitkBaseData.h:37
#define MITK_ERROR
Definition: mitkLogMacros.h:20
double ScalarType
Implementation of BaseDataCompare that uses a non-const version of mitk:Equal() for comparisons...
DataCollection - Class to facilitate loading/accessing structured data.
Implementation of BaseDataCompare that uses mitk:Equal() for comparisons.
bool AreEqual(const BaseData *left, const BaseData *right, ScalarType eps=mitk::eps, bool verbose=false)
Main interface method, compares two given BaseData instances.
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.
static void RegisterCoreEquals()
Register core type comparators that come with mitk::Equal() functions.
MITKCORE_EXPORT const ScalarType eps
Interface to compare two BaseData objects for (near) equality.