ITK  4.2.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< class 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< class TPointValueType >
86  Point(const ValueType r[NPointDimension]):BaseArray(r) {}
87  Point(const ValueType & v):BaseArray(v) {}
89 
91  Point & operator=(const Self & r);
92 
93  Point & operator=(const ValueType r[NPointDimension]);
94 
96  bool
97  operator==(const Self & pt) const
98  {
99  bool same = true;
100 
101  for ( unsigned int i = 0; i < NPointDimension && same; i++ )
102  { same = ( ( *this )[i] == pt[i] ); }
103  return same;
104  }
105 
107  bool
108  operator!=(const Self & pt) const
109  {
110  bool same = true;
111 
112  for ( unsigned int i = 0; i < NPointDimension && same; i++ )
113  { same = ( ( *this )[i] == pt[i] ); }
114  return !same;
115  }
116 
118  const Self & operator+=(const VectorType & vec);
119 
121  const Self & operator-=(const VectorType & vec);
122 
124  VectorType operator-(const Self & pnt) const;
125 
127  Self operator+(const VectorType & vec) const;
128 
130  Self operator-(const VectorType & vec) const;
131 
134 
136  vnl_vector_ref< TCoordRep > GetVnlVector(void);
137 
140 
143  itkLegacyMacro(vnl_vector_ref< TCoordRep > Get_vnl_vector(void));
144 
147  itkLegacyMacro(vnl_vector< TCoordRep > Get_vnl_vector(void) const);
148 
160  void SetToMidPoint(const Self &, const Self &);
161 
188  void SetToBarycentricCombination(const Self & A, const Self & B, double alpha);
190 
206  void SetToBarycentricCombination(const Self & A, const Self & B, const Self & C,
207  double weightA, double weightB);
209 
222  void SetToBarycentricCombination(const Self *P, const double *weights, unsigned int N);
224 
227  template< typename TCoordRepB >
229  {
230  for ( unsigned int i = 0; i < NPointDimension; i++ )
231  {
232  ( *this )[i] = static_cast< TCoordRep >( pa[i] );
233  }
234  }
236 
241  template< typename TCoordRepB >
243  {
245 
246  for ( unsigned int i = 0; i < NPointDimension; i++ )
247  {
248  const RealType component = static_cast< RealType >( pa[i] );
249  const RealType difference = static_cast< RealType >( ( *this )[i] ) - component;
250  sum += difference * difference;
251  }
252  return sum;
253  }
254 
258  template< typename TCoordRepB >
260  {
261  const double distance = vcl_sqrt(
262  static_cast< double >( this->SquaredEuclideanDistanceTo(pa) ) );
263 
264  return static_cast< RealType >( distance );
265  }
266 };
267 
268 template< class T, unsigned int NPointDimension >
269 ITK_EXPORT std::ostream & operator<<(std::ostream & os,
270  const Point< T, NPointDimension > & v);
271 
272 template< class T, unsigned int NPointDimension >
273 ITK_EXPORT std::istream & operator>>(std::istream & is,
274  Point< T, NPointDimension > & v);
275 
301 template< class TPointContainer, class TWeightContainer >
302 ITK_EXPORT class BarycentricCombination
303 {
304 public:
306  typedef TPointContainer PointContainerType;
307  typedef typename PointContainerType::Pointer PointContainerPointer;
308  typedef typename PointContainerType::Element PointType;
309  typedef TWeightContainer WeightContainerType;
310 
313 
314  static PointType Evaluate(
315  const PointContainerPointer & points,
316  const WeightContainerType & weights);
317 };
318 } // end namespace itk
319 
320 // Define instantiation macro for this template.
321 #define ITK_TEMPLATE_Point(_, EXPORT, TypeX, TypeY) \
322  namespace itk \
323  { \
324  _( 2 ( class EXPORT Point< ITK_TEMPLATE_2 TypeX > ) ) \
325  _( 1 ( EXPORT std::ostream & operator<<(std::ostream &, \
326  const Point< ITK_TEMPLATE_2 TypeX > &) ) ) \
327  _( 1 ( EXPORT std::istream & operator>>(std::istream &, \
328  Point< ITK_TEMPLATE_2 TypeX > &) ) ) \
329  namespace Templates \
330  { \
331  typedef Point< ITK_TEMPLATE_2 TypeX > Point##TypeY; \
332  } \
333  }
334 
335 #if ITK_TEMPLATE_EXPLICIT
336 #include "Templates/itkPoint+-.h"
337 #endif
338 
339 #if ITK_TEMPLATE_TXX
340 #include "itkPoint.hxx"
341 #endif
342 
343 #endif
344