ITK  6.0.0
Insight Toolkit
itkPoint.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * https://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkPoint_h
19 #define itkPoint_h
20 
21 
22 #include "itkNumericTraits.h"
23 #include "itkVector.h"
24 
25 #include "vnl/vnl_vector_ref.h"
26 #include "itkMath.h"
27 
28 namespace itk
29 {
52 template <typename TCoordinate, unsigned int VPointDimension = 3>
53 class ITK_TEMPLATE_EXPORT Point : public FixedArray<TCoordinate, VPointDimension>
54 {
55 public:
56 
58  using Self = Point;
60 
63  using ValueType = TCoordinate;
64  using CoordinateType = TCoordinate;
65 #ifndef ITK_FUTURE_LEGACY_REMOVE
66  using CoordRepType ITK_FUTURE_DEPRECATED(
67  "ITK 6 discourages using `CoordRepType`. Please use `CoordinateType` instead!") = CoordinateType;
68 #endif
69 
71 
73  static constexpr unsigned int PointDimension = VPointDimension;
74 
77  using Iterator = typename BaseArray::Iterator;
79 
81  static unsigned int
83  {
84  return VPointDimension;
85  }
86 
89 
92  Point() = default;
93 
95  template <typename TPointValueType>
97  : BaseArray(r)
98  {}
99 
101  template <typename TPointValueType>
102  Point(const TPointValueType r[VPointDimension])
103  : BaseArray(r)
104  {}
105  Point(const ValueType r[VPointDimension])
106  : BaseArray(r)
107  {}
110 #if defined(ITK_LEGACY_REMOVE)
111 
112  Point(std::nullptr_t) = delete;
113 
115  template <typename TPointValueType>
116  explicit Point(const TPointValueType & v)
117  : BaseArray(v)
118  {}
119  explicit Point(const ValueType & v)
120  : BaseArray(v)
121  {}
122 #else
123 
126  template <typename TPointValueType>
127  Point(const TPointValueType & v)
128  : BaseArray(v)
129  {}
130  Point(const ValueType & v)
131  : BaseArray(v)
132  {}
133 #endif
134 
137  explicit Point(const std::array<ValueType, VPointDimension> & stdArray)
138  : BaseArray(stdArray)
139  {}
140 
142  Point &
143  operator=(const ValueType r[VPointDimension]);
144 
146  bool
147  operator==(const Self & pt) const
148  {
149  return this->BaseArray::operator==(pt);
150  }
151 
152  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Self);
153 
155  const Self &
156  operator+=(const VectorType & vec);
157 
159  const Self &
160  operator-=(const VectorType & vec);
161 
163  VectorType
164  operator-(const Self & pnt) const;
165 
167  Self
168  operator+(const VectorType & vec) const;
169 
171  Self
172  operator-(const VectorType & vec) const;
173 
175  VectorType
176  GetVectorFromOrigin() const;
177 
179  vnl_vector_ref<TCoordinate>
180  GetVnlVector();
181 
183  vnl_vector<TCoordinate>
184  GetVnlVector() const;
185 
197  void
198  SetToMidPoint(const Self &, const Self &);
199 
226  void
227  SetToBarycentricCombination(const Self & A, const Self & B, double alpha);
245  void
246  SetToBarycentricCombination(const Self & A, const Self & B, const Self & C, double weightForA, double weightForB);
261  void
262  SetToBarycentricCombination(const Self * P, const double * weights, unsigned int N);
267  template <typename TCoordinateB>
268  void
270  {
271  for (unsigned int i = 0; i < VPointDimension; ++i)
272  {
273  (*this)[i] = static_cast<TCoordinate>(pa[i]);
274  }
275  }
282  template <typename TCoordinateB>
283  RealType
285  {
286  RealType sum{};
287 
288  for (unsigned int i = 0; i < VPointDimension; ++i)
289  {
290  const auto component = static_cast<RealType>(pa[i]);
291  const RealType difference = static_cast<RealType>((*this)[i]) - component;
292  sum += difference * difference;
293  }
294  return sum;
295  }
296 
300  template <typename TCoordinateB>
301  RealType
303  {
304  const double distance = std::sqrt(static_cast<double>(this->SquaredEuclideanDistanceTo(pa)));
305 
306  return static_cast<RealType>(distance);
307  }
308 };
309 
310 template <typename T, unsigned int VPointDimension>
311 std::ostream &
312 operator<<(std::ostream & os, const Point<T, VPointDimension> & vct);
313 
314 template <typename T, unsigned int VPointDimension>
315 std::istream &
316 operator>>(std::istream & is, Point<T, VPointDimension> & vct);
317 
344 template <typename TPointContainer, typename TWeightContainer>
345 class ITK_TEMPLATE_EXPORT BarycentricCombination
346 {
347 public:
348 
350  using PointContainerType = TPointContainer;
352  using PointType = typename PointContainerType::Element;
353  using WeightContainerType = TWeightContainer;
354 
355  static PointType
356  Evaluate(const PointContainerPointer & points, const WeightContainerType & weights);
357 };
358 
359 
360 template <typename TCoordinate, unsigned int VPointDimension>
361 inline void
363 {
364  a.swap(b);
365 }
366 
367 
369 template <typename TValue, typename... TVariadic>
370 auto
371 MakePoint(const TValue firstValue, const TVariadic... otherValues)
372 {
373  static_assert(std::conjunction_v<std::is_same<TVariadic, TValue>...>,
374  "The other values should have the same type as the first value.");
375 
376  constexpr unsigned int dimension{ 1 + sizeof...(TVariadic) };
377  const std::array<TValue, dimension> stdArray{ { firstValue, otherValues... } };
378  return Point<TValue, dimension>{ stdArray };
379 }
380 
381 } // end namespace itk
382 
383 #ifndef ITK_MANUAL_INSTANTIATION
384 # include "itkPoint.hxx"
385 #endif
386 
387 #endif
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::MakePoint
auto MakePoint(const TValue firstValue, const TVariadic... otherValues)
Definition: itkPoint.h:371
itk::Point::Point
Point(const Point< TPointValueType, VPointDimension > &r)
Definition: itkPoint.h:96
itk::BarycentricCombination
Computes the barycentric combination of an array of N points.
Definition: itkPoint.h:345
itk::BarycentricCombination::WeightContainerType
TWeightContainer WeightContainerType
Definition: itkPoint.h:353
itk::Point< double, Self::ImageDimension >::RealType
typename NumericTraits< ValueType >::RealType RealType
Definition: itkPoint.h:70
itk::Point::EuclideanDistanceTo
RealType EuclideanDistanceTo(const Point< TCoordinateB, VPointDimension > &pa) const
Definition: itkPoint.h:302
itk::Point::Point
Point(const ValueType &v)
Definition: itkPoint.h:119
itk::GTest::TypedefsAndConstructors::Dimension2::VectorType
ImageBaseType::SpacingType VectorType
Definition: itkGTestTypedefsAndConstructors.h:53
itk::Vector
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
itk::Point::CastFrom
void CastFrom(const Point< TCoordinateB, VPointDimension > &pa)
Definition: itkPoint.h:269
itk::operator-
ConstNeighborhoodIterator< TImage > operator-(const ConstNeighborhoodIterator< TImage > &it, const typename ConstNeighborhoodIterator< TImage >::OffsetType &ind)
Definition: itkConstNeighborhoodIterator.h:672
itk::Point::Point
Point(const ValueType r[VPointDimension])
Definition: itkPoint.h:105
itk::Point< double, Self::ImageDimension >::CoordinateType
double CoordinateType
Definition: itkPoint.h:64
itk::operator<<
ITKCommon_EXPORT std::ostream & operator<<(std::ostream &out, typename AnatomicalOrientation::CoordinateEnum value)
itk::FixedArray< double, VPointDimension >::ConstIterator
const ValueType * ConstIterator
Definition: itkFixedArray.h:72
itk::Point::Point
Point(const std::array< ValueType, VPointDimension > &stdArray)
Definition: itkPoint.h:137
itk::Point::SquaredEuclideanDistanceTo
RealType SquaredEuclideanDistanceTo(const Point< TCoordinateB, VPointDimension > &pa) const
Definition: itkPoint.h:284
itk::Point::Point
Point(const TPointValueType &v)
Definition: itkPoint.h:116
itk::Point::operator==
bool operator==(const Self &pt) const
Definition: itkPoint.h:147
itk::BarycentricCombination::PointType
typename PointContainerType::Element PointType
Definition: itkPoint.h:352
itk::operator==
bool operator==(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:552
itk::FixedArray
Simulate a standard C array with copy semantics.
Definition: itkFixedArray.h:53
itk::Point::Point
Point(const TPointValueType r[VPointDimension])
Definition: itkPoint.h:102
itk::Point::GetPointDimension
static unsigned int GetPointDimension()
Definition: itkPoint.h:82
itk::swap
void swap(Array< T > &a, Array< T > &b) noexcept
Definition: itkArray.h:242
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::BarycentricCombination::PointContainerPointer
typename PointContainerType::Pointer PointContainerPointer
Definition: itkPoint.h:351
itkVector.h
itk::operator+
ConstNeighborhoodIterator< TImage > operator+(const ConstNeighborhoodIterator< TImage > &it, const typename ConstNeighborhoodIterator< TImage >::OffsetType &ind)
Definition: itkConstNeighborhoodIterator.h:654
itkNumericTraits.h
itk::Point
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:53
itk::NumericTraits::RealType
double RealType
Definition: itkNumericTraits.h:86
AddImageFilter
Definition: itkAddImageFilter.h:81
itk::BarycentricCombination::PointContainerType
TPointContainer PointContainerType
Definition: itkPoint.h:350
itkMath.h
itk::operator>>
std::istream & operator>>(std::istream &is, Point< T, VPointDimension > &vct)
itk::FixedArray< double, VPointDimension >::Iterator
ValueType * Iterator
Definition: itkFixedArray.h:69
itk::FixedArray< double, VPointDimension >::ValueType
double ValueType
Definition: itkFixedArray.h:63