ITK  4.3.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 #ifndef ITK_MANUAL_INSTANTIATION
321 #include "itkPoint.hxx"
322 #endif
323 
324 #endif
325