Orfeo Toolbox  4.0
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) {}
92 
94  Point & operator=(const Self & r);
95 
96  Point & operator=(const ValueType r[NPointDimension]);
97 
99  bool
100  operator==(const Self & pt) const
101  {
102  bool same = true;
103 
104  for ( unsigned int i = 0; i < NPointDimension && same; i++ )
105  { same = ( ( *this )[i] == pt[i] ); }
106  return same;
107  }
108 
110  bool
111  operator!=(const Self & pt) const
112  {
113  bool same = true;
114 
115  for ( unsigned int i = 0; i < NPointDimension && same; i++ )
116  { same = ( ( *this )[i] == pt[i] ); }
117  return !same;
118  }
119 
121  const Self & operator+=(const VectorType & vec);
122 
124  const Self & operator-=(const VectorType & vec);
125 
127  VectorType operator-(const Self & pnt) const;
128 
130  Self operator+(const VectorType & vec) const;
131 
133  Self operator-(const VectorType & vec) const;
134 
137 
139  vnl_vector_ref< TCoordRep > GetVnlVector(void);
140 
142  vnl_vector< TCoordRep > GetVnlVector(void) const;
143 
146  itkLegacyMacro(vnl_vector_ref< TCoordRep > Get_vnl_vector(void));
147 
150  itkLegacyMacro(vnl_vector< TCoordRep > Get_vnl_vector(void) const);
151 
163  void SetToMidPoint(const Self &, const Self &);
164 
191  void SetToBarycentricCombination(const Self & A, const Self & B, double alpha);
192 
208  void SetToBarycentricCombination(const Self & A, const Self & B, const Self & C,
209  double weightA, double weightB);
210 
223  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  }
235 
240  template< typename TCoordRepB >
242  {
244 
245  for ( unsigned int i = 0; i < NPointDimension; i++ )
246  {
247  const RealType component = static_cast< RealType >( pa[i] );
248  const RealType difference = static_cast< RealType >( ( *this )[i] ) - component;
249  sum += difference * difference;
250  }
251  return sum;
252  }
253 
257  template< typename TCoordRepB >
259  {
260  const double distance = vcl_sqrt(
261  static_cast< double >( this->SquaredEuclideanDistanceTo(pa) ) );
262 
263  return static_cast< RealType >( distance );
264  }
265 };
266 
267 template< typename T, unsigned int NPointDimension >
268 std::ostream & operator<<(std::ostream & os,
269  const Point< T, NPointDimension > & v);
270 
271 template< typename T, unsigned int NPointDimension >
272 std::istream & operator>>(std::istream & is,
273  Point< T, NPointDimension > & v);
274 
300 template< typename TPointContainer, typename TWeightContainer >
302 {
303 public:
305  typedef TPointContainer PointContainerType;
306  typedef typename PointContainerType::Pointer PointContainerPointer;
307  typedef typename PointContainerType::Element PointType;
308  typedef TWeightContainer WeightContainerType;
309 
312 
313  static PointType Evaluate(
314  const PointContainerPointer & points,
315  const WeightContainerType & weights);
316 };
317 } // end namespace itk
318 
319 #ifndef ITK_MANUAL_INSTANTIATION
320 #include "itkPoint.hxx"
321 #endif
322 
323 #endif

Generated at Sat Mar 8 2014 15:23:09 for Orfeo Toolbox with doxygen 1.8.3.1