ITK  4.3.0
Insight Segmentation and Registration Toolkit
itkCovariantVector.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 __itkCovariantVector_h
19 #define __itkCovariantVector_h
20 
21 #include "vnl/vnl_vector_ref.h"
22 #include "itkIndent.h"
23 #include "itkVector.h"
24 
25 namespace itk
26 {
66 template< class T, unsigned int NVectorDimension = 3 >
67 class ITK_EXPORT CovariantVector:public FixedArray< T, NVectorDimension >
68 {
69 public:
73 
76  typedef T ValueType;
78 
80  typedef T ComponentType;
81 
83  itkStaticConstMacro(Dimension, unsigned int, NVectorDimension);
84 
87 
90 
92  static unsigned int GetCovariantVectorDimension()
93  { return NVectorDimension; }
94 
96  void SetVnlVector(const vnl_vector< T > &);
97 
99  vnl_vector_ref< T > GetVnlVector(void);
100 
102  vnl_vector< T > GetVnlVector(void) const;
103 
106  itkLegacyMacro(void Set_vnl_vector(const vnl_vector< T > &));
107 
110  itkLegacyMacro(vnl_vector_ref< T > Get_vnl_vector(void));
111 
114  itkLegacyMacro(vnl_vector< T > Get_vnl_vector(void) const);
115 
118  CovariantVector(const ValueType & r);
119 
122  template< class TVectorValueType >
123  CovariantVector(const CovariantVector< TVectorValueType,
124  NVectorDimension > & r):BaseArray(r) {}
125  CovariantVector(const ValueType r[Dimension]):BaseArray(r) {}
127 
129  template< class Tt >
130  Self & operator=(const Tt & v)
131  {
132  BaseArray::operator=(v);
133  return *this;
134  }
136 
138  CovariantVector & operator=(const Self & r);
139 
140  CovariantVector & operator=(const ValueType r[NVectorDimension]);
141 
143  template< class 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  }
153 
155  template< class Tt >
156  const Self & operator/=(const Tt & value)
157  {
158  for ( unsigned int i = 0; i < NVectorDimension; i++ )
159  {
160  ( *this )[i] = static_cast< ValueType >( ( *this )[i] / value );
161  }
162  return *this;
163  }
165 
167  const Self & operator+=(const Self & vec);
168 
170  const Self & operator-=(const Self & vec);
171 
174  Self operator-() const;
175 
177  Self operator+(const Self & vec) const;
178 
180  Self operator-(const Self & vec) const;
181 
186  ValueType operator *(const Self & vec) const;
187 
190  ValueType operator *(const Vector< T, NVectorDimension > & vec) const;
191 
194  inline Self operator*(const ValueType & val) const
195  {
196  Self result;
197 
198  for ( unsigned int i = 0; i < NVectorDimension; i++ )
199  {
200  result[i] = static_cast< ValueType >( ( *this )[i] * val );
201  }
202  return result;
203  }
204 
207  template< class Tt >
208  inline Self operator/(const Tt & val) const
209  {
210  Self result;
211 
212  for ( unsigned int i = 0; i < NVectorDimension; i++ )
213  {
214  result[i] = static_cast< ValueType >( ( *this )[i] / val );
215  }
216  return result;
217  }
218 
220  RealValueType GetNorm(void) const;
221 
223  static unsigned int GetNumberOfComponents() { return NVectorDimension; }
224 
226  void Normalize(void);
227 
229  RealValueType GetSquaredNorm(void) const;
230 
233  template< typename TCoordRepB >
235  {
236  for ( unsigned int i = 0; i < NVectorDimension; i++ )
237  {
238  ( *this )[i] = static_cast< T >( pa[i] );
239  }
240  }
241 };
243 
246 template< class T, unsigned int NVectorDimension >
247 inline
248 CovariantVector< T, NVectorDimension >
250 {
251  return v * scalar;
252 }
253 
256 template< class T, unsigned int NVectorDimension >
257 inline
258 T
260 {
261  return covariant.operator*( contravariant );
262 }
263 
264 ITKCommon_EXPORT void CrossProduct(CovariantVector< double, 3 > &,
265  const Vector< double, 3 > &,
266  const Vector< double, 3 > &);
267 
268 ITKCommon_EXPORT void CrossProduct(CovariantVector< float, 3 > &,
269  const Vector< float, 3 > &,
270  const Vector< float, 3 > &);
271 
272 ITKCommon_EXPORT void CrossProduct(CovariantVector< int, 3 >,
273  const Vector< int, 3 > &,
274  const Vector< int, 3 > &);
275 } // end namespace itk
276 
277 //
278 // Numeric traits must be included after (optionally) including the explicit
279 // instantiations control of this class, in case the implicit instantiation
280 // needs to be disabled.
281 //
282 // NumericTraits must be included before (optionally) including the .hxx file,
283 // in case the .hxx requires to use NumericTraits.
284 //
286 
287 #ifndef ITK_MANUAL_INSTANTIATION
288 #include "itkCovariantVector.hxx"
289 #endif
290 
291 #endif
292