ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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
28namespace itk
29{
52template <typename TCoordinate, unsigned int VPointDimension = 3>
53class ITK_TEMPLATE_EXPORT Point : public FixedArray<TCoordinate, VPointDimension>
54{
55public:
57 using Self = Point;
59
62 using ValueType = TCoordinate;
63 using CoordinateType = TCoordinate;
64#ifndef ITK_FUTURE_LEGACY_REMOVE
65 using CoordRepType ITK_FUTURE_DEPRECATED(
66 "ITK 6 discourages using `CoordRepType`. Please use `CoordinateType` instead!") = CoordinateType;
67#endif
68
70
72 static constexpr unsigned int PointDimension = VPointDimension;
73
76 using Iterator = typename BaseArray::Iterator;
78
80 static unsigned int
82 {
83 return VPointDimension;
84 }
85
88
91 Point() = default;
92
94 template <typename TPointValueType>
98
101 template <typename TPointValueType>
102 Point(const TPointValueType r[VPointDimension])
103 : BaseArray(r)
104 {}
105 Point(const ValueType r[VPointDimension])
106 : BaseArray(r)
107 {}
108
109#if defined(ITK_LEGACY_REMOVE)
111 Point(std::nullptr_t) = delete;
112
114 template <typename TPointValueType>
115 explicit Point(const TPointValueType & v)
116 : BaseArray(v)
117 {}
118 explicit Point(const ValueType & v)
119 : BaseArray(v)
120 {}
121#else
122
125 template <typename TPointValueType>
126 Point(const TPointValueType & v)
127 : BaseArray(v)
128 {}
129
130 Point(const ValueType & v)
131 : BaseArray(v)
132 {}
133#endif
134
136 explicit Point(const std::array<ValueType, VPointDimension> & stdArray)
137 : BaseArray(stdArray)
138 {}
139
141 Point &
142 operator=(const ValueType r[VPointDimension]);
143
145 bool
146 operator==(const Self & pt) const
147 {
148 return this->BaseArray::operator==(pt);
149 }
150
152
154 const Self &
155 operator+=(const VectorType & vec);
156
158 const Self &
159 operator-=(const VectorType & vec);
160
163 operator-(const Self & pnt) const;
164
166 Self
167 operator+(const VectorType & vec) const;
168
170 Self
171 operator-(const VectorType & vec) const;
172
176
178 vnl_vector_ref<TCoordinate>
180
182 vnl_vector<TCoordinate>
184
196 void
197 SetToMidPoint(const Self &, const Self &);
198
225 void
226 SetToBarycentricCombination(const Self & A, const Self & B, double alpha);
227
243 void
244 SetToBarycentricCombination(const Self & A, const Self & B, const Self & C, double weightForA, double weightForB);
245
258 void
259 SetToBarycentricCombination(const Self * P, const double * weights, unsigned int N);
260
263 template <typename TCoordinateB>
264 void
266 {
267 for (unsigned int i = 0; i < VPointDimension; ++i)
268 {
269 (*this)[i] = static_cast<TCoordinate>(pa[i]);
270 }
271 }
272
276
277 template <typename TCoordinateB>
280 {
281 RealType sum{};
282
283 for (unsigned int i = 0; i < VPointDimension; ++i)
284 {
285 const auto component = static_cast<RealType>(pa[i]);
286 const RealType difference = static_cast<RealType>((*this)[i]) - component;
287 sum += difference * difference;
288 }
289 return sum;
290 }
291
295 template <typename TCoordinateB>
298 {
299 const double distance = std::sqrt(static_cast<double>(this->SquaredEuclideanDistanceTo(pa)));
300
301 return static_cast<RealType>(distance);
302 }
303};
304
305template <typename T, unsigned int VPointDimension>
306std::ostream &
307operator<<(std::ostream & os, const Point<T, VPointDimension> & vct);
308
309template <typename T, unsigned int VPointDimension>
310std::istream &
311operator>>(std::istream & is, Point<T, VPointDimension> & vct);
312
339template <typename TPointContainer, typename TWeightContainer>
340class ITK_TEMPLATE_EXPORT BarycentricCombination
341{
342public:
344 using PointContainerType = TPointContainer;
345 using PointContainerPointer = typename PointContainerType::Pointer;
346 using PointType = typename PointContainerType::Element;
347 using WeightContainerType = TWeightContainer;
348
349 static PointType
350 Evaluate(const PointContainerPointer & points, const WeightContainerType & weights);
351};
352
353
354template <typename TCoordinate, unsigned int VPointDimension>
355inline void
360
361
363template <typename TValue, typename... TVariadic>
364auto
365MakePoint(const TValue firstValue, const TVariadic... otherValues)
366{
367 static_assert(std::conjunction_v<std::is_same<TVariadic, TValue>...>,
368 "The other values should have the same type as the first value.");
369
370 constexpr unsigned int dimension{ 1 + sizeof...(TVariadic) };
371 const std::array<TValue, dimension> stdArray{ { firstValue, otherValues... } };
372 return Point<TValue, dimension>{ stdArray };
373}
374
375} // end namespace itk
376
377#ifndef ITK_MANUAL_INSTANTIATION
378# include "itkPoint.hxx"
379#endif
380
381#endif
Computes the barycentric combination of an array of N points.
Definition itkPoint.h:341
static PointType Evaluate(const PointContainerPointer &points, const WeightContainerType &weights)
typename PointContainerType::Element PointType
Definition itkPoint.h:346
TWeightContainer WeightContainerType
Definition itkPoint.h:347
TPointContainer PointContainerType
Definition itkPoint.h:344
typename PointContainerType::Pointer PointContainerPointer
Definition itkPoint.h:345
bool operator==(const FixedArray &r) const
const ValueType * ConstIterator
ValueType * Iterator
A templated class holding a geometric point in n-Dimensional space.
Definition itkPoint.h:54
Point()=default
static constexpr unsigned int PointDimension
Definition itkPoint.h:72
const Self & operator+=(const VectorType &vec)
typename BaseArray::ConstIterator ConstIterator
Definition itkPoint.h:77
vnl_vector_ref< TCoordinate > GetVnlVector()
static unsigned int GetPointDimension()
Definition itkPoint.h:81
Point(std::nullptr_t)=delete
void CastFrom(const Point< TCoordinateB, VPointDimension > &pa)
Definition itkPoint.h:265
VectorType GetVectorFromOrigin() const
Point(const std::array< ValueType, VPointDimension > &stdArray)
Definition itkPoint.h:136
Point(const TPointValueType r[VPointDimension])
Definition itkPoint.h:102
typename NumericTraits< ValueType >::RealType RealType
Definition itkPoint.h:69
RealType EuclideanDistanceTo(const Point< TCoordinateB, VPointDimension > &pa) const
Definition itkPoint.h:297
void SetToMidPoint(const Self &, const Self &)
VectorType operator-(const Self &pnt) const
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Self)
Point(const ValueType r[VPointDimension])
Definition itkPoint.h:105
Point(const ValueType &v)
Definition itkPoint.h:118
Vector< ValueType, VPointDimension > VectorType
Definition itkPoint.h:87
void SetToBarycentricCombination(const Self &A, const Self &B, const Self &C, double weightForA, double weightForB)
void SetToBarycentricCombination(const Self &A, const Self &B, double alpha)
Point(const TPointValueType &v)
Definition itkPoint.h:115
FixedArray< CoordinateType, VPointDimension > BaseArray
Definition itkPoint.h:75
typename BaseArray::Iterator Iterator
Definition itkPoint.h:76
FixedArray< CoordinateType, VPointDimension > Superclass
Definition itkPoint.h:58
RealType SquaredEuclideanDistanceTo(const Point< TCoordinateB, VPointDimension > &pa) const
Definition itkPoint.h:279
Self operator+(const VectorType &vec) const
vnl_vector< TCoordinate > GetVnlVector() const
Point & operator=(const ValueType r[VPointDimension])
void SetToBarycentricCombination(const Self *P, const double *weights, unsigned int N)
bool operator==(const Self &pt) const
Definition itkPoint.h:146
const Self & operator-=(const VectorType &vec)
Point(const Point< TPointValueType, VPointDimension > &r)
Definition itkPoint.h:95
Self operator-(const VectorType &vec) const
A templated class holding a n-Dimensional vector.
Definition itkVector.h:63
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
void swap(Array< T > &a, Array< T > &b) noexcept
Definition itkArray.h:247
std::istream & operator>>(std::istream &is, Point< T, VPointDimension > &vct)
ITKCommon_EXPORT std::ostream & operator<<(std::ostream &out, typename AnatomicalOrientation::CoordinateEnum value)
auto MakePoint(const TValue firstValue, const TVariadic... otherValues)
Definition itkPoint.h:365