ITK  4.13.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 #include "itkMath.h"
27 
28 namespace itk
29 {
51 template< typename TCoordRep, unsigned int NPointDimension = 3 >
52 class ITK_TEMPLATE_EXPORT Point:public FixedArray< TCoordRep, NPointDimension >
53 {
54 public:
56  typedef Point Self;
58 
61  typedef TCoordRep ValueType;
62  typedef TCoordRep CoordRepType;
63 
65 
67  itkStaticConstMacro(PointDimension, unsigned int, NPointDimension);
68 
71  typedef typename BaseArray::Iterator Iterator;
73 
75  static unsigned int GetPointDimension()
76  { return NPointDimension; }
77 
80 
82  Point() {}
83 
85  template< typename TPointValueType >
87  template< typename TPointValueType >
88  Point(const TPointValueType r[NPointDimension]):BaseArray(r) {}
89  Point(const ValueType r[NPointDimension]):BaseArray(r) {}
90  template< typename TPointValueType >
91  Point(const TPointValueType & v):BaseArray(v) {}
92  Point(const ValueType & v):BaseArray(v) {}
94 
96  Point & operator=(const Self & r);
97 
98  Point & operator=(const ValueType r[NPointDimension]);
99 
101  bool
102  operator==(const Self & pt) const
103  {
104  bool same = true;
105 
106  for ( unsigned int i = 0; i < NPointDimension && same; ++i )
107  { same = ( Math::ExactlyEquals(( *this )[i], pt[i]) ); }
108  return same;
109  }
110 
112  bool
113  operator!=(const Self & pt) const
114  {
115  bool same = true;
116 
117  for ( unsigned int i = 0; i < NPointDimension && same; ++i )
118  { same = ( Math::ExactlyEquals(( *this )[i], pt[i]) ); }
119  return !same;
120  }
121 
123  const Self & operator+=(const VectorType & vec);
124 
126  const Self & operator-=(const VectorType & vec);
127 
129  VectorType operator-(const Self & pnt) const;
130 
132  Self operator+(const VectorType & vec) const;
133 
135  Self operator-(const VectorType & vec) const;
136 
138  VectorType GetVectorFromOrigin() const;
139 
141  vnl_vector_ref< TCoordRep > GetVnlVector();
142 
144  vnl_vector< TCoordRep > GetVnlVector() const;
145 
148  itkLegacyMacro(vnl_vector_ref< TCoordRep > Get_vnl_vector(void));
149 
152  itkLegacyMacro(vnl_vector< TCoordRep > Get_vnl_vector(void) const);
153 
165  void SetToMidPoint(const Self &, const Self &);
166 
193  void SetToBarycentricCombination(const Self & A, const Self & B, double alpha);
195 
211  void SetToBarycentricCombination(const Self & A, const Self & B, const Self & C,
212  double weightA, double weightB);
214 
227  void SetToBarycentricCombination(const Self *P, const double *weights, unsigned int N);
229 
232  template< typename TCoordRepB >
234  {
235  for ( unsigned int i = 0; i < NPointDimension; i++ )
236  {
237  ( *this )[i] = static_cast< TCoordRep >( pa[i] );
238  }
239  }
241 
246  template< typename TCoordRepB >
248  {
250 
251  for ( unsigned int i = 0; i < NPointDimension; i++ )
252  {
253  const RealType component = static_cast< RealType >( pa[i] );
254  const RealType difference = static_cast< RealType >( ( *this )[i] ) - component;
255  sum += difference * difference;
256  }
257  return sum;
258  }
259 
263  template< typename TCoordRepB >
265  {
266  const double distance = std::sqrt(
267  static_cast< double >( this->SquaredEuclideanDistanceTo(pa) ) );
268 
269  return static_cast< RealType >( distance );
270  }
271 };
272 
273 template< typename T, unsigned int NPointDimension >
274 std::ostream & operator<<(std::ostream & os,
275  const Point< T, NPointDimension > & v);
276 
277 template< typename T, unsigned int NPointDimension >
278 std::istream & operator>>(std::istream & is,
279  Point< T, NPointDimension > & v);
280 
306 template< typename TPointContainer, typename TWeightContainer >
307 class ITK_TEMPLATE_EXPORT BarycentricCombination
308 {
309 public:
311  typedef TPointContainer PointContainerType;
312  typedef typename PointContainerType::Pointer PointContainerPointer;
313  typedef typename PointContainerType::Element PointType;
314  typedef TWeightContainer WeightContainerType;
315 
318 
319  static PointType Evaluate(
320  const PointContainerPointer & points,
321  const WeightContainerType & weights);
322 };
323 } // end namespace itk
324 
325 #ifndef ITK_MANUAL_INSTANTIATION
326 #include "itkPoint.hxx"
327 #endif
328 
329 #endif
void CastFrom(const Point< TCoordRepB, NPointDimension > &pa)
Definition: itkPoint.h:233
bool operator==(const Self &pt) const
Definition: itkPoint.h:102
TCoordRep ValueType
Definition: itkPoint.h:61
ConstNeighborhoodIterator< TImage > operator-(const ConstNeighborhoodIterator< TImage > &it, const typename ConstNeighborhoodIterator< TImage >::OffsetType &ind)
Point(const TPointValueType r[NPointDimension])
Definition: itkPoint.h:88
std::istream & operator>>(std::istream &is, Point< T, NPointDimension > &v)
Point(const Point< TPointValueType, NPointDimension > &r)
Definition: itkPoint.h:86
Computes the barycentric combination of an array of N points.
Definition: itkPoint.h:307
TWeightContainer WeightContainerType
Definition: itkPoint.h:314
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:192
PointContainerType::Pointer PointContainerPointer
Definition: itkPoint.h:312
bool ExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Return the result of an exact comparison between two scalar values of potetially different types...
Definition: itkMath.h:710
BaseArray::ConstIterator ConstIterator
Definition: itkPoint.h:72
BaseArray::Iterator Iterator
Definition: itkPoint.h:71
Point(const TPointValueType &v)
Definition: itkPoint.h:91
Simulate a standard C array with copy semnatics.
Definition: itkFixedArray.h:50
FixedArray< TCoordRep, NPointDimension > BaseArray
Definition: itkPoint.h:70
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
PointContainerType::Element PointType
Definition: itkPoint.h:313
ConstNeighborhoodIterator< TImage > operator+(const ConstNeighborhoodIterator< TImage > &it, const typename ConstNeighborhoodIterator< TImage >::OffsetType &ind)
Vector< ValueType, NPointDimension > VectorType
Definition: itkPoint.h:79
Point Self
Definition: itkPoint.h:56
bool operator!=(const Self &pt) const
Definition: itkPoint.h:113
TCoordRep CoordRepType
Definition: itkPoint.h:62
NumericTraits< ValueType >::RealType RealType
Definition: itkPoint.h:64
Point(const ValueType r[NPointDimension])
Definition: itkPoint.h:89
FixedArray< TCoordRep, NPointDimension > Superclass
Definition: itkPoint.h:57
Point(const ValueType &v)
Definition: itkPoint.h:92
static unsigned int GetPointDimension()
Definition: itkPoint.h:75
TPointContainer PointContainerType
Definition: itkPoint.h:311
RealType SquaredEuclideanDistanceTo(const Point< TCoordRepB, NPointDimension > &pa) const
Definition: itkPoint.h:247
RealType EuclideanDistanceTo(const Point< TCoordRepB, NPointDimension > &pa) const
Definition: itkPoint.h:264
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:52