Orfeo Toolbox  3.16
itkVector.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkVector.h,v $
5  Language: C++
6  Date: $Date: 2009-03-03 15:11:37 $
7  Version: $Revision: 1.83 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __itkVector_h
18 #define __itkVector_h
19 
20 #include "itkFixedArray.h"
21 
22 #include "itkNumericTraits.h" // RealValueType type
23 #include <vnl/vnl_vector_ref.h> // Get_vnl_vector method return
24 
25 
26 namespace itk
27 {
28 
57 template<class T, unsigned int NVectorDimension=3>
58 class Vector : public FixedArray<T,NVectorDimension>
59 {
60 public:
62  typedef Vector Self;
64 
67  typedef T ValueType;
68  typedef typename NumericTraits< ValueType >::RealType RealValueType;
69 
71  itkStaticConstMacro(Dimension, unsigned int, NVectorDimension);
72 
74  typedef Self VectorType;
75 
77  typedef T ComponentType;
78 
81 
83  static unsigned int GetVectorDimension()
84  { return NVectorDimension; }
85 
87  void SetVnlVector( const vnl_vector<T> & );
88 
90  vnl_vector_ref<T> GetVnlVector( void );
91 
93  vnl_vector<T> GetVnlVector( void ) const;
94 
95 
98  void Set_vnl_vector( const vnl_vector<T> & );
99 
102  vnl_vector_ref<T> Get_vnl_vector( void );
103 
106  vnl_vector<T> Get_vnl_vector( void ) const;
107 
109  Vector(): BaseArray() { }
110  Vector(const ValueType& r);
111 
113  template< class TVectorValueType >
116 
118  template< class TVectorValueType >
120  {
122  return *this;
123  }
124 
125  Vector& operator= (const ValueType r[NVectorDimension]);
126 
128  template< class Tt > inline const Self& operator*=(const Tt &value)
129  {
130  for( unsigned int i=0; i<NVectorDimension; i++)
131  {
132  (*this)[i] = static_cast< ValueType >((*this)[i] * value);
133  }
134  return *this;
135  }
136 
138  template< class Tt > inline const Self& operator/=(const Tt &value)
139  {
140  for( unsigned int i=0; i<NVectorDimension; i++)
141  {
142  (*this)[i] = static_cast< ValueType >((*this)[i] / value);
143  }
144  return *this;
145  }
146 
148  const Self& operator+=(const Self &vec);
149 
151  const Self& operator-=(const Self &vec);
152 
155  Self operator-() const;
156 
158  Self operator+(const Self &vec) const;
159 
161  Self operator-(const Self &vec) const;
162 
165  ValueType operator*(const Self &vec) const;
166 
169  inline Self operator*(const ValueType& value) const
170  {
171  Self result;
172  for( unsigned int i=0; i<NVectorDimension; i++)
173  {
174  result[i] = static_cast< ValueType >((*this)[i] * value);
175  }
176  return result;
177  }
178 
181  template< class Tt > inline Self operator/(const Tt& value) const
182  {
183  Self result;
184  for( unsigned int i=0; i<NVectorDimension; i++)
185  {
186  result[i] = static_cast< ValueType >((*this)[i] / value);
187  }
188  return result;
189  }
190 
195  bool operator==(const Self& v) const
196  { return Superclass::operator==(v); }
197  bool operator!=(const Self& v) const
198  { return !operator==(v); }
199 
201  RealValueType GetNorm( void ) const;
202 
204  RealValueType GetSquaredNorm( void ) const;
205 
207  static unsigned int GetNumberOfComponents(){ return NVectorDimension;}
208 
210  void Normalize(void);
211 
212  void SetNthComponent(int c, const ComponentType& v)
213  { this->operator[](c) = v; }
214 
217  template < typename TCoordRepB >
219  {
220  for(unsigned int i=0; i<NVectorDimension; i++ )
221  {
222  (*this)[i] = static_cast<T>( pa[i] );
223  }
224  }
225 };
226 
229 template< class T, unsigned int NVectorDimension >
230 inline
231 Vector<T,NVectorDimension>
232 operator*(const T &scalar, const Vector<T,NVectorDimension> & v)
233 {
234  return v * scalar;
235 }
236 
237 template< class T, unsigned int NVectorDimension >
238 std::ostream& operator<<(std::ostream& os,
239  const Vector<T,NVectorDimension> & v);
240 
241 template< class T, unsigned int NVectorDimension >
242 std::istream& operator>>(std::istream& is,
243  Vector<T,NVectorDimension> & v);
244 
245 ITKCommon_EXPORT Vector<double,3> CrossProduct( const Vector<double,3> &,
246  const Vector<double,3> & );
247 
248 ITKCommon_EXPORT Vector<float,3> CrossProduct( const Vector<float,3> &,
249  const Vector<float,3> & );
250 
251 ITKCommon_EXPORT Vector<int,3> CrossProduct( const Vector<int,3> &,
252  const Vector<int,3> & );
253 
254 } // end namespace itk
255 
256 
257 // Define instantiation macro for this template.
258 #define ITK_TEMPLATE_Vector(_, EXPORT, x, y) namespace itk { \
259  _(2(class EXPORT Vector< ITK_TEMPLATE_2 x >)) \
260  _(1(EXPORT std::ostream& operator<<(std::ostream&, \
261  const Vector< ITK_TEMPLATE_2 x >&))) \
262  _(1(EXPORT std::istream& operator>>(std::istream&, \
263  Vector< ITK_TEMPLATE_2 x >&))) \
264  namespace Templates { typedef Vector< ITK_TEMPLATE_2 x > Vector##y; } \
265  }
266 
267 #if ITK_TEMPLATE_EXPLICIT
268 # include "Templates/itkVector+-.h"
269 #endif
270 
271 //
272 // Numeric traits must be included after (optionally) including the explicit
273 // instantiations control of this class, in case the implicit instantiation
274 // needs to be disabled.
275 //
276 // NumericTraits must be included before (optionally) including the .txx file,
277 // in case the .txx requires to use NumericTraits.
278 //
279 #include "itkNumericTraitsVectorPixel.h"
280 
281 #if ITK_TEMPLATE_TXX
282 # include "itkVector.txx"
283 #endif
284 
285 
286 #endif

Generated at Sun Feb 3 2013 00:11:24 for Orfeo Toolbox with doxygen 1.8.1.1