ITK  4.6.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  for ( unsigned int i = 0; i < NPointDimension && same; i++ )
117  { same = ( ( *this )[i] == pt[i] ); }
118  return !same;
119  }
120 
122  const Self & operator+=(const VectorType & vec);
123 
125  const Self & operator-=(const VectorType & vec);
126 
128  VectorType operator-(const Self & pnt) const;
129 
131  Self operator+(const VectorType & vec) const;
132 
134  Self operator-(const VectorType & vec) const;
135 
138 
140  vnl_vector_ref< TCoordRep > GetVnlVector(void);
141 
143  vnl_vector< TCoordRep > GetVnlVector(void) const;
144 
147  itkLegacyMacro(vnl_vector_ref< TCoordRep > Get_vnl_vector(void));
148 
151  itkLegacyMacro(vnl_vector< TCoordRep > Get_vnl_vector(void) const);
152 
164  void SetToMidPoint(const Self &, const Self &);
165 
192  void SetToBarycentricCombination(const Self & A, const Self & B, double alpha);
194 
210  void SetToBarycentricCombination(const Self & A, const Self & B, const Self & C,
211  double weightA, double weightB);
213 
226  void SetToBarycentricCombination(const Self *P, const double *weights, unsigned int N);
228 
231  template< typename TCoordRepB >
233  {
234  for ( unsigned int i = 0; i < NPointDimension; i++ )
235  {
236  ( *this )[i] = static_cast< TCoordRep >( pa[i] );
237  }
238  }
240 
245  template< typename TCoordRepB >
247  {
249 
250  for ( unsigned int i = 0; i < NPointDimension; i++ )
251  {
252  const RealType component = static_cast< RealType >( pa[i] );
253  const RealType difference = static_cast< RealType >( ( *this )[i] ) - component;
254  sum += difference * difference;
255  }
256  return sum;
257  }
258 
262  template< typename TCoordRepB >
264  {
265  const double distance = std::sqrt(
266  static_cast< double >( this->SquaredEuclideanDistanceTo(pa) ) );
267 
268  return static_cast< RealType >( distance );
269  }
270 };
271 
272 template< typename T, unsigned int NPointDimension >
273 std::ostream & operator<<(std::ostream & os,
274  const Point< T, NPointDimension > & v);
275 
276 template< typename T, unsigned int NPointDimension >
277 std::istream & operator>>(std::istream & is,
278  Point< T, NPointDimension > & v);
279 
305 template< typename TPointContainer, typename TWeightContainer >
307 {
308 public:
310  typedef TPointContainer PointContainerType;
311  typedef typename PointContainerType::Pointer PointContainerPointer;
312  typedef typename PointContainerType::Element PointType;
313  typedef TWeightContainer WeightContainerType;
314 
317 
318  static PointType Evaluate(
319  const PointContainerPointer & points,
320  const WeightContainerType & weights);
321 };
322 } // end namespace itk
323 
324 #ifndef ITK_MANUAL_INSTANTIATION
325 #include "itkPoint.hxx"
326 #endif
327 
328 #endif
void CastFrom(const Point< TCoordRepB, NPointDimension > &pa)
Definition: itkPoint.h:232
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
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:306
TWeightContainer WeightContainerType
Definition: itkPoint.h:313
vnl_vector_ref< TCoordRep > GetVnlVector(void)
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:184
PointContainerType::Pointer PointContainerPointer
Definition: itkPoint.h:311
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:312
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:310
static PointType Evaluate(const PointContainerPointer &points, const WeightContainerType &weights)
const Self & operator+=(const VectorType &vec)
Define additional traits for native types such as int or float.
RealType SquaredEuclideanDistanceTo(const Point< TCoordRepB, NPointDimension > &pa) const
Definition: itkPoint.h:246
RealType EuclideanDistanceTo(const Point< TCoordRepB, NPointDimension > &pa) const
Definition: itkPoint.h:263
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