Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef mitkBaseDataCompare_h_included
18 #define mitkBaseDataCompare_h_included
19 
20 #include "mitkBaseData.h"
21 
22 namespace mitk
23 {
49  {
50  private:
57  virtual bool InternalAreEqual(const BaseData &left,
58  const BaseData &right,
60  bool verbose = false) = 0;
61 
65  bool AreSameClasses(const BaseData *left, const BaseData *right, bool verbose = false);
66 
67  public:
80  bool AreEqual(const BaseData *left, const BaseData *right, ScalarType eps = mitk::eps, bool verbose = false);
81 
85  static void RegisterCoreEquals();
86  };
87 
95  template <class T>
97  {
98  private:
99  virtual bool InternalAreEqual(const BaseData &left,
100  const BaseData &right,
102  bool verbose = false)
103  {
104  try
105  {
106  const T &leftT = dynamic_cast<const T &>(left);
107  const T &rightT = dynamic_cast<const T &>(right);
108 
109  return mitk::Equal(leftT, rightT, eps, verbose);
110  }
111  catch (const std::exception &e)
112  {
113  MITK_ERROR << "Bad cast in BaseDataCompareT<>::InternalAreEqual()" << e.what();
114  }
115 
116  return false;
117  }
118  };
119 
130  template <class T>
132  {
133  private:
134  virtual bool InternalAreEqual(const BaseData &left,
135  const BaseData &right,
137  bool verbose = false)
138  {
139  try
140  {
141  const T &leftT = dynamic_cast<const T &>(left);
142  const T &rightT = dynamic_cast<const T &>(right);
143 
144  T &leftTNonConst = const_cast<T &>(leftT);
145  T &rightTNonConst = const_cast<T &>(rightT);
146 
147  return mitk::Equal(leftTNonConst, rightTNonConst, eps, verbose);
148  }
149  catch (const std::exception &e)
150  {
151  MITK_ERROR << "Bad cast in BaseDataCompareTNonConst<>::InternalAreEqual(): " << e.what();
152  }
153 
154  return false;
155  }
156  };
157 
158 } // namespace
159 
160 #endif
Base of all data objects.
Definition: mitkBaseData.h:39
#define MITK_ERROR
Definition: mitkLogMacros.h:24
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.
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.