Orfeo Toolbox  4.0
itkVector.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 __itkVector_h
19 #define __itkVector_h
20 
21 #include "itkFixedArray.h"
22 
23 #include "vnl/vnl_vector_ref.h" // GetVnlVector method return
24 
25 namespace itk
26 {
61 template< typename T, unsigned int NVectorDimension = 3 >
62 class Vector:public FixedArray< T, NVectorDimension >
63 {
64 public:
66  typedef Vector Self;
68 
71  typedef T ValueType;
73 
75  itkStaticConstMacro(Dimension, unsigned int, NVectorDimension);
76 
78  typedef Self VectorType;
79 
81  typedef T ComponentType;
82 
85 
87  static unsigned int GetVectorDimension() { return NVectorDimension; }
88 
90  void SetVnlVector(const vnl_vector< T > &);
91 
93  vnl_vector_ref< T > GetVnlVector(void);
94 
96  vnl_vector< T > GetVnlVector(void) const;
97 
100  itkLegacyMacro(void Set_vnl_vector(const vnl_vector< T > &));
101 
104  itkLegacyMacro(vnl_vector_ref< T > Get_vnl_vector(void));
105 
108  itkLegacyMacro(vnl_vector< T > Get_vnl_vector(void) const);
109 
112 
114  Vector(const ValueType & r);
115 
117  template< typename TVectorValueType >
120 
122  template< typename TVectorValueType >
124  {
126  return *this;
127  }
128 
129  Vector & operator=(const ValueType r[NVectorDimension]);
130 
132  template< typename Tt >
133  inline const Self & operator*=(const Tt & value)
134  {
135  for ( unsigned int i = 0; i < NVectorDimension; i++ )
136  {
137  ( *this )[i] = static_cast< ValueType >( ( *this )[i] * value );
138  }
139  return *this;
140  }
141 
143  template< typename Tt >
144  inline const Self & operator/=(const Tt & value)
145  {
146  for ( unsigned int i = 0; i < NVectorDimension; i++ )
147  {
148  ( *this )[i] = static_cast< ValueType >( ( *this )[i] / value );
149  }
150  return *this;
151  }
152 
154  const Self & operator+=(const Self & vec);
155 
157  const Self & operator-=(const Self & vec);
158 
161  Self operator-() const;
162 
164  Self operator+(const Self & vec) const;
165 
167  Self operator-(const Self & vec) const;
168 
171  ValueType operator *(const Self & vec) const;
172 
175  inline Self operator*(const ValueType & value) const
176  {
177  Self result;
178 
179  for ( unsigned int i = 0; i < NVectorDimension; i++ )
180  {
181  result[i] = static_cast< ValueType >( ( *this )[i] * value );
182  }
183  return result;
184  }
185 
188  template< typename Tt >
189  inline Self operator/(const Tt & value) const
190  {
191  Self result;
192 
193  for ( unsigned int i = 0; i < NVectorDimension; i++ )
194  {
195  result[i] = static_cast< ValueType >( ( *this )[i] / value );
196  }
197  return result;
198  }
199 
204  bool operator==(const Self & v) const
205  { return Superclass::operator==(v); }
206  bool operator!=(const Self & v) const
207  { return !operator==(v); }
208 
210  RealValueType GetNorm(void) const;
211 
213  RealValueType GetSquaredNorm(void) const;
214 
216  static unsigned int GetNumberOfComponents() { return NVectorDimension; }
217 
219  void Normalize(void);
220 
221  void SetNthComponent(int c, const ComponentType & v)
222  { this->operator[](c) = v; }
223 
226  template< typename TCoordRepB >
228  {
229  for ( unsigned int i = 0; i < NVectorDimension; i++ )
230  {
231  ( *this )[i] = static_cast< T >( pa[i] );
232  }
233  }
234 
235  template<typename TCoordRepB>
237  {
239  for (unsigned int i = 0; i < NVectorDimension; i++)
240  {
241  r[i] = static_cast<TCoordRepB> ((*this)[i]);
242  }
243  return r;
244  }
245 
246 };
247 
250 template< typename T, unsigned int NVectorDimension >
251 inline
252 Vector< T, NVectorDimension >
253 operator*(const T & scalar, const Vector< T, NVectorDimension > & v)
254 {
255  return v * scalar;
256 }
257 
259 template< typename T, unsigned int NVectorDimension >
260 std::ostream & operator<<(std::ostream & os,
261  const Vector< T, NVectorDimension > & v);
262 
264 template< typename T, unsigned int NVectorDimension >
265 std::istream & operator>>(std::istream & is,
266  Vector< T, NVectorDimension > & v);
267 
268 ITKCommon_EXPORT Vector< double, 3 > CrossProduct(const Vector< double, 3 > &,
269  const Vector< double, 3 > &);
270 
271 ITKCommon_EXPORT Vector< float, 3 > CrossProduct(const Vector< float, 3 > &,
272  const Vector< float, 3 > &);
273 
274 ITKCommon_EXPORT Vector< int, 3 > CrossProduct(const Vector< int, 3 > &,
275  const Vector< int, 3 > &);
276 } // end namespace itk
277 
278 #ifndef ITK_MANUAL_INSTANTIATION
279 #include "itkVector.hxx"
280 #endif
281 
282 #endif

Generated at Sat Mar 8 2014 15:40:44 for Orfeo Toolbox with doxygen 1.8.3.1