ITK  4.13.0
Insight Segmentation and Registration Toolkit
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 ITK_TEMPLATE_EXPORT 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();
94 
96  vnl_vector< T > GetVnlVector() 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 
113 #if !defined( ITK_LEGACY_FUTURE_REMOVE )
114 
118  Vector(const ValueType & r);
119 #else
120 
123  explicit Vector(const ValueType & r);
124 #endif
125 
127  template< typename TVectorValueType >
131 
133  template< typename TVectorValueType >
135  {
136  BaseArray::operator=(r);
137  return *this;
138  }
140 
141  Vector & operator=(const ValueType r[NVectorDimension]);
142 
144  template< typename Tt >
145  inline const Self & operator*=(const Tt & value)
146  {
147  for ( unsigned int i = 0; i < NVectorDimension; i++ )
148  {
149  ( *this )[i] = static_cast< ValueType >( ( *this )[i] * value );
150  }
151  return *this;
152  }
154 
156  template< typename Tt >
157  inline const Self & operator/=(const Tt & value)
158  {
159  for ( unsigned int i = 0; i < NVectorDimension; i++ )
160  {
161  ( *this )[i] = static_cast< ValueType >( ( *this )[i] / value );
162  }
163  return *this;
164  }
166 
168  const Self & operator+=(const Self & vec);
169 
171  const Self & operator-=(const Self & vec);
172 
175  Self operator-() const;
176 
178  Self operator+(const Self & vec) const;
179 
181  Self operator-(const Self & vec) const;
182 
185  ValueType operator *(const Self & vec) const;
186 
189  inline Self operator*(const ValueType & 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 
202  template< typename Tt >
203  inline Self operator/(const Tt & value) const
204  {
205  Self result;
206 
207  for ( unsigned int i = 0; i < NVectorDimension; i++ )
208  {
209  result[i] = static_cast< ValueType >( ( *this )[i] / value );
210  }
211  return result;
212  }
213 
218  bool operator==(const Self & v) const
219  { return Superclass::operator==(v); }
220  bool operator!=(const Self & v) const
221  { return !operator==(v); }
223 
225  RealValueType GetNorm() const;
226 
228  RealValueType GetSquaredNorm() const;
229 
231  static unsigned int GetNumberOfComponents() { return NVectorDimension; }
232 
235  RealValueType Normalize();
236 
237  void SetNthComponent(int c, const ComponentType & v)
238  { this->operator[](c) = v; }
239 
242  template< typename TCoordRepB >
244  {
245  for ( unsigned int i = 0; i < NVectorDimension; i++ )
246  {
247  ( *this )[i] = static_cast< T >( pa[i] );
248  }
249  }
251 
252  template<typename TCoordRepB>
254  {
256  for (unsigned int i = 0; i < NVectorDimension; i++)
257  {
258  r[i] = static_cast<TCoordRepB> ((*this)[i]);
259  }
260  return r;
261  }
262 
263 };
264 
267 template< typename T, unsigned int NVectorDimension >
268 inline
269 Vector< T, NVectorDimension >
270 operator*(const T & scalar, const Vector< T, NVectorDimension > & v)
271 {
272  return v.operator*( scalar);
273 }
274 
276 template< typename T, unsigned int NVectorDimension >
277 std::ostream & operator<<(std::ostream & os,
278  const Vector< T, NVectorDimension > & v);
279 
281 template< typename T, unsigned int NVectorDimension >
282 std::istream & operator>>(std::istream & is,
283  Vector< T, NVectorDimension > & v);
284 
285 ITKCommon_EXPORT Vector< double, 3 > CrossProduct(const Vector< double, 3 > &,
286  const Vector< double, 3 > &);
287 
288 ITKCommon_EXPORT Vector< float, 3 > CrossProduct(const Vector< float, 3 > &,
289  const Vector< float, 3 > &);
290 
291 ITKCommon_EXPORT Vector< int, 3 > CrossProduct(const Vector< int, 3 > &,
292  const Vector< int, 3 > &);
293 } // end namespace itk
294 
295 #ifndef ITK_MANUAL_INSTANTIATION
296 #include "itkVector.hxx"
297 #endif
298 
299 #endif
Vector & operator=(const Vector< TVectorValueType, NVectorDimension > &r)
Definition: itkVector.h:134
ConstNeighborhoodIterator< TImage > operator-(const ConstNeighborhoodIterator< TImage > &it, const typename ConstNeighborhoodIterator< TImage >::OffsetType &ind)
Vector(const ValueType r[Dimension])
Definition: itkVector.h:129
std::istream & operator>>(std::istream &is, Point< T, NPointDimension > &v)
Self operator*(const ValueType &value) const
Definition: itkVector.h:189
CovariantVector< T, NVectorDimension > operator*(const T &scalar, const CovariantVector< T, NVectorDimension > &v)
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:192
FixedArray< T, NVectorDimension > Superclass
Definition: itkVector.h:67
Simulate a standard C array with copy semnatics.
Definition: itkFixedArray.h:50
static unsigned int GetNumberOfComponents()
Definition: itkVector.h:231
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
bool operator==(const Self &v) const
Definition: itkVector.h:218
FixedArray< T, NVectorDimension > BaseArray
Definition: itkVector.h:84
ConstNeighborhoodIterator< TImage > operator+(const ConstNeighborhoodIterator< TImage > &it, const typename ConstNeighborhoodIterator< TImage >::OffsetType &ind)
const Self & operator/=(const Tt &value)
Definition: itkVector.h:157
Self operator/(const Tt &value) const
Definition: itkVector.h:203
Self VectorType
Definition: itkVector.h:78
ITKCommon_EXPORT void CrossProduct(CovariantVector< double, 3 > &, const Vector< double, 3 > &, const Vector< double, 3 > &)
void CastFrom(const Vector< TCoordRepB, NVectorDimension > &pa)
Definition: itkVector.h:243
T ComponentType
Definition: itkVector.h:81
Vector(const Vector< TVectorValueType, NVectorDimension > &r)
Definition: itkVector.h:128
static unsigned int GetVectorDimension()
Definition: itkVector.h:87
void SetNthComponent(int c, const ComponentType &v)
Definition: itkVector.h:237
NumericTraits< ValueType >::RealType RealValueType
Definition: itkVector.h:72
bool operator!=(const Self &v) const
Definition: itkVector.h:220
const Self & operator*=(const Tt &value)
Definition: itkVector.h:145
bool ITKIOXML_EXPORT operator==(itk::FancyString &s, const std::string &)
Vector Self
Definition: itkVector.h:66