Medical Imaging Interaction Toolkit  2024.06.99-60d9b802
Medical Imaging Interaction Toolkit
mitkPoint.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 mitkPoint_h
14 #define mitkPoint_h
15 
16 #include <itkPoint.h>
17 
18 #include <mitkArray.h>
19 #include <mitkEqual.h>
20 #include <mitkNumericConstants.h>
21 
22 #include <nlohmann/json.hpp>
23 
24 namespace mitk
25 {
26  //##Documentation
27  //##@brief enumeration of the type a point can be
29  {
35  };
36 
37  template <class TCoordRep, unsigned int NPointDimension = 3>
38  class Point : public itk::Point<TCoordRep, NPointDimension>
39  {
40  public:
42  explicit Point<TCoordRep, NPointDimension>() : itk::Point<TCoordRep, NPointDimension>() {}
44  template <typename TPointValueType>
45  explicit Point(const Point<TPointValueType, NPointDimension> &r) : itk::Point<TCoordRep, NPointDimension>(r)
46  {
47  }
48 
49  template <typename TPointValueType>
50  explicit Point(const TPointValueType r[NPointDimension]) : itk::Point<TCoordRep, NPointDimension>(r)
51  {
52  }
53 
54  template <typename TPointValueType>
55  explicit Point(const TPointValueType &v) : itk::Point<TCoordRep, NPointDimension>(v)
56  {
57  }
58 
60  : itk::Point<TCoordRep, NPointDimension>(r)
61  {
62  }
63  Point<TCoordRep, NPointDimension>(const TCoordRep r[NPointDimension]) : itk::Point<TCoordRep, NPointDimension>(r) {}
64  Point<TCoordRep, NPointDimension>(const TCoordRep &v) : itk::Point<TCoordRep, NPointDimension>(v) {}
65  Point<TCoordRep, NPointDimension>(const itk::Point<TCoordRep, NPointDimension> &p)
66  : itk::Point<TCoordRep, NPointDimension>(p)
67  {
68  }
69 
70  template <typename... Args,
71  typename = std::enable_if_t<(sizeof...(Args) == NPointDimension)>>
72  explicit Point(Args... args)
73  {
74  size_t i = 0;
75  ((this->GetDataPointer()[i++] = static_cast<TCoordRep>(args)), ...);
76  }
77 
84  template <typename ArrayType>
85  void FillPoint(const ArrayType &array)
86  {
87  itk::FixedArray<TCoordRep, NPointDimension> *thisP =
88  dynamic_cast<itk::FixedArray<TCoordRep, NPointDimension> *>(this);
89  mitk::FillArray<ArrayType, TCoordRep, NPointDimension>(*thisP, array);
90  }
91 
97  template <typename ArrayType>
98  void ToArray(ArrayType array) const
99  {
100  mitk::ToArray<ArrayType, TCoordRep, NPointDimension>(array, *this);
101  }
102  };
103 
104  template <class TCoordRep, unsigned int NPointDimension>
106  {
107  j = nlohmann::json::array();
108 
109  for (size_t i = 0; i < NPointDimension; ++i)
110  j.push_back(p[i]);
111  }
112 
113  template <class TCoordRep, unsigned int NPointDimension>
115  {
116  for (size_t i = 0; i < NPointDimension; ++i)
117  j.at(i).get_to(p[i]);
118  }
119 
123 
127 
137  template <typename TCoordRep, unsigned int NPointDimension>
138  inline bool Equal(const itk::Point<TCoordRep, NPointDimension> &point1,
139  const itk::Point<TCoordRep, NPointDimension> &point2,
140  TCoordRep eps = mitk::eps,
141  bool verbose = false)
142  {
143  bool isEqual = true;
144  typename itk::Point<TCoordRep, NPointDimension>::VectorType diff = point1 - point2;
145  for (unsigned int i = 0; i < NPointDimension; i++)
146  {
147  if (DifferenceBiggerOrEqualEps(diff[i], eps))
148  {
149  isEqual = false;
150  break;
151  }
152  }
153 
154  ConditionalOutputOfDifference(point1, point2, eps, verbose, isEqual);
155 
156  return isEqual;
157  }
158 
159 } // namespace mitk
160 
161 #endif
mitk::PTEDGE
@ PTEDGE
Definition: mitkPoint.h:33
mitk::eps
const MITKCORE_EXPORT ScalarType eps
mitk::Point4I
Point< int, 4 > Point4I
Definition: mitkPoint.h:126
mitk::Point::FillPoint
void FillPoint(const ArrayType &array)
Definition: mitkPoint.h:85
mitk::Point::Point
Point(const Point< TPointValueType, NPointDimension > &r)
Definition: mitkPoint.h:45
mitk::PTUNDEFINED
@ PTUNDEFINED
Definition: mitkPoint.h:30
mitk::to_json
void to_json(nlohmann::json &j, const GenericLookupTable< T > &t)
Definition: mitkGenericLookupTable.h:98
mitk::Equal
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.
mitk::Point::Point
Point(const TPointValueType r[NPointDimension])
Definition: mitkPoint.h:50
mitk::from_json
void from_json(const nlohmann::json &, GenericLookupTable< T > &)
Definition: mitkGenericLookupTable.h:104
mitk::Point4D
Point< ScalarType, 4 > Point4D
Definition: mitkPoint.h:122
mitk::Point2I
Point< int, 2 > Point2I
Definition: mitkPoint.h:124
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
mitkArray.h
mitk::Point::ToArray
void ToArray(ArrayType array) const
Definition: mitkPoint.h:98
json
nlohmann::json json
Definition: mitkModelTestFixture.h:29
mitk::Point
Definition: mitkPoint.h:38
mitk::Point::Point
Point(const TPointValueType &v)
Definition: mitkPoint.h:55
mitk::Point2D
Point< ScalarType, 2 > Point2D
Definition: mitkPoint.h:120
mitk::Point3D
Point< ScalarType, 3 > Point3D
Definition: mitkPoint.h:121
mitkNumericConstants.h
mitk::Point::Point
Point(Args... args)
Definition: mitkPoint.h:72
mitk::PTEND
@ PTEND
Definition: mitkPoint.h:34
mitkEqual.h
itk
SET FUNCTIONS.
Definition: itkIntelligentBinaryClosingFilter.h:30
mitk::DifferenceBiggerOrEqualEps
bool DifferenceBiggerOrEqualEps(DifferenceType diff, mitk::ScalarType epsilon=mitk::eps)
Definition: mitkEqual.h:32
mitk::PointSpecificationType
PointSpecificationType
enumeration of the type a point can be
Definition: mitkPoint.h:28
mitk::ConditionalOutputOfDifference
void ConditionalOutputOfDifference(ElementToOutput1 elem1, ElementToOutput2 elem2, mitk::ScalarType eps, bool verbose, bool isEqual)
Definition: mitkEqual.h:48
mitk::Point3I
Point< int, 3 > Point3I
Definition: mitkPoint.h:125
mitk::PTCORNER
@ PTCORNER
Definition: mitkPoint.h:32
mitk::PTSTART
@ PTSTART
Definition: mitkPoint.h:31