ITK  4.8.0
Insight Segmentation and Registration Toolkit
itkPoint.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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  * http://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 
27 namespace itk
28 {
50 template< typename TCoordRep, unsigned int NPointDimension = 3 >
51 class Point:public FixedArray< TCoordRep, NPointDimension >
52 {
53 public:
55  typedef Point Self;
57 
60  typedef TCoordRep ValueType;
61  typedef TCoordRep CoordRepType;
62 
64 
66  itkStaticConstMacro(PointDimension, unsigned int, NPointDimension);
67 
70  typedef typename BaseArray::Iterator Iterator;
72 
74  static unsigned int GetPointDimension()
75  { return NPointDimension; }
76 
79 
81  Point() {}
82 
84  template< typename TPointValueType >
86  template< typename TPointValueType >
87  Point(const TPointValueType r[NPointDimension]):BaseArray(r) {}
88  Point(const ValueType r[NPointDimension]):BaseArray(r) {}
89  template< typename TPointValueType >
90  Point(const TPointValueType & v):BaseArray(v) {}
91  Point(const ValueType & v):BaseArray(v) {}
93 
95  Point & operator=(const Self & r);
96 
97  Point & operator=(const ValueType r[NPointDimension]);
98 
100  bool
101  operator==(const Self & pt) const
102  {
103  bool same = true;
104 
105  for ( unsigned int i = 0; i < NPointDimension && same; ++i )
106  { same = ( ( *this )[i] == pt[i] ); }
107  return same;
108  }
109 
111  bool
112  operator!=(const Self & pt) const
113  {
114  bool same = true;
115 
116 CLANG_PRAGMA_PUSH
117 CLANG_SUPPRESS_Wfloat_equal
118  for ( unsigned int i = 0; i < NPointDimension && same; ++i )
119  { same = ( ( *this )[i] == pt[i] ); }
120 CLANG_PRAGMA_POP
121  return !same;
122  }
123 
125  const Self & operator+=(const VectorType & vec);
126 
128  const Self & operator-=(const VectorType & vec);
129 
131  VectorType operator-(const Self & pnt) const;
132 
134  Self operator+(const VectorType & vec) const;
135 
137  Self operator-(const VectorType & vec) const;
138 
141 
143  vnl_vector_ref< TCoordRep > GetVnlVector();
144 
146  vnl_vector< TCoordRep > GetVnlVector() const;
147 
150  itkLegacyMacro(vnl_vector_ref< TCoordRep > Get_vnl_vector(void));
151 
154  itkLegacyMacro(vnl_vector< TCoordRep > Get_vnl_vector(void) const);
155 
167  void SetToMidPoint(const Self &, const Self &);
168 
195  void SetToBarycentricCombination(const Self & A, const Self & B, double alpha);
197 
213  void SetToBarycentricCombination(const Self & A, const Self & B, const Self & C,
214  double weightA, double weightB);
216 
229  void SetToBarycentricCombination(const Self *P, const double *weights, unsigned int N);
231 
234  template< typename TCoordRepB >
236  {
237  for ( unsigned int i = 0; i < NPointDimension; i++ )
238  {
239  ( *this )[i] = static_cast< TCoordRep >( pa[i] );
240  }
241  }
243 
248  template< typename TCoordRepB >
250  {
252 
253  for ( unsigned int i = 0; i < NPointDimension; i++ )
254  {
255  const RealType component = static_cast< RealType >( pa[i] );
256  const RealType difference = static_cast< RealType >( ( *this )[i] ) - component;
257  sum += difference * difference;
258  }
259  return sum;
260  }
261 
265  template< typename TCoordRepB >
267  {
268  const double distance = std::sqrt(
269  static_cast< double >( this->SquaredEuclideanDistanceTo(pa) ) );
270 
271  return static_cast< RealType >( distance );
272  }
273 };
274 
275 template< typename T, unsigned int NPointDimension >
276 std::ostream & operator<<(std::ostream & os,
277  const Point< T, NPointDimension > & v);
278 
279 template< typename T, unsigned int NPointDimension >
280 std::istream & operator>>(std::istream & is,
281  Point< T, NPointDimension > & v);
282 
308 template< typename TPointContainer, typename TWeightContainer >
310 {
311 public:
313  typedef TPointContainer PointContainerType;
314  typedef typename PointContainerType::Pointer PointContainerPointer;
315  typedef typename PointContainerType::Element PointType;
316  typedef TWeightContainer WeightContainerType;
317 
320 
321  static PointType Evaluate(
322  const PointContainerPointer & points,
323  const WeightContainerType & weights);
324 };
325 } // end namespace itk
326 
327 #ifndef ITK_MANUAL_INSTANTIATION
328 #include "itkPoint.hxx"
329 #endif
330 
331 #endif
void CastFrom(const Point< TCoordRepB, NPointDimension > &pa)
Definition: itkPoint.h:235
bool operator==(const Self &pt) const
Definition: itkPoint.h:101
TCoordRep ValueType
Definition: itkPoint.h:60
void SetToBarycentricCombination(const Self &A, const Self &B, double alpha)
static const unsigned int PointDimension
Definition: itkPoint.h:66
VectorType GetVectorFromOrigin() const
vnl_vector_ref< TCoordRep > GetVnlVector()
Point(const TPointValueType r[NPointDimension])
Definition: itkPoint.h:87
std::istream & operator>>(std::istream &is, Point< T, NPointDimension > &v)
Point(const Point< TPointValueType, NPointDimension > &r)
Definition: itkPoint.h:85
Computes the barycentric combination of an array of N points.
Definition: itkPoint.h:309
TWeightContainer WeightContainerType
Definition: itkPoint.h:316
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:184
PointContainerType::Pointer PointContainerPointer
Definition: itkPoint.h:314
BaseArray::ConstIterator ConstIterator
Definition: itkPoint.h:71
BaseArray::Iterator Iterator
Definition: itkPoint.h:70
Point(const TPointValueType &v)
Definition: itkPoint.h:90
Simulate a standard C array with copy semnatics.
Definition: itkFixedArray.h:50
FixedArray< TCoordRep, NPointDimension > BaseArray
Definition: itkPoint.h:69
itkLegacyMacro(vnl_vector_ref< TCoordRep > Get_vnl_vector(void))
const Self & operator-=(const VectorType &vec)
VectorType operator-(const Self &pnt) const
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
PointContainerType::Element PointType
Definition: itkPoint.h:315
Vector< ValueType, NPointDimension > VectorType
Definition: itkPoint.h:78
Point Self
Definition: itkPoint.h:55
bool operator!=(const Self &pt) const
Definition: itkPoint.h:112
TCoordRep CoordRepType
Definition: itkPoint.h:61
NumericTraits< ValueType >::RealType RealType
Definition: itkPoint.h:63
Point(const ValueType r[NPointDimension])
Definition: itkPoint.h:88
FixedArray< TCoordRep, NPointDimension > Superclass
Definition: itkPoint.h:56
void SetToMidPoint(const Self &, const Self &)
Point(const ValueType &v)
Definition: itkPoint.h:91
static unsigned int GetPointDimension()
Definition: itkPoint.h:74
TPointContainer PointContainerType
Definition: itkPoint.h:313
static PointType Evaluate(const PointContainerPointer &points, const WeightContainerType &weights)
const Self & operator+=(const VectorType &vec)
RealType SquaredEuclideanDistanceTo(const Point< TCoordRepB, NPointDimension > &pa) const
Definition: itkPoint.h:249
RealType EuclideanDistanceTo(const Point< TCoordRepB, NPointDimension > &pa) const
Definition: itkPoint.h:266
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:51
Point & operator=(const Self &r)
Self operator+(const VectorType &vec) const