ITK  4.8.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 "itkIndent.h"
22 #include "itkVector.h"
23 #include "vnl/vnl_vector_ref.h"
24 
25 namespace itk
26 {
66 template< typename T, unsigned int NVectorDimension = 3 >
67 class 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();
100 
102  vnl_vector< T > GetVnlVector() 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< typename TVectorValueType >
123  CovariantVector(const CovariantVector< TVectorValueType,
124  NVectorDimension > & r):BaseArray(r) {}
127 
129  template< typename Tt >
130  Self & operator=(const Tt & v)
131  {
133  return *this;
134  }
136 
138  CovariantVector & operator=(const Self & r);
139 
140  CovariantVector & operator=(const ValueType r[NVectorDimension]);
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  }
153 
155  template< typename 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 
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< typename 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() const;
221 
223  static unsigned int GetNumberOfComponents() { return NVectorDimension; }
224 
226  void Normalize();
227 
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< typename T, unsigned int NVectorDimension >
247 inline
248 CovariantVector< T, NVectorDimension >
250 {
251  return v.operator*(scalar);
252 }
253 
256 template< typename 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
itkLegacyMacro(void Set_vnl_vector(const vnl_vector< T > &))
void CastFrom(const CovariantVector< TCoordRepB, NVectorDimension > &pa)
void SetVnlVector(const vnl_vector< T > &)
Self & operator=(const Tt &v)
const Self & operator/=(const Tt &value)
static const unsigned int Dimension
Self operator*(const ValueType &val) const
CovariantVector< T, NVectorDimension > operator*(const T &scalar, const CovariantVector< T, NVectorDimension > &v)
FixedArray< T, NVectorDimension > BaseArray
NumericTraits< ValueType >::RealType RealValueType
CovariantVector(const ValueType r[Dimension])
Self operator-() const
Simulate a standard C array with copy semnatics.
Definition: itkFixedArray.h:50
ValueType operator*(const Self &vec) const
CovariantVector(const CovariantVector< TVectorValueType, NVectorDimension > &r)
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
ITKCommon_EXPORT void CrossProduct(CovariantVector< double, 3 > &, const Vector< double, 3 > &, const Vector< double, 3 > &)
const Self & operator-=(const Self &vec)
Self operator+(const Self &vec) const
FixedArray & operator=(const FixedArray< TFixedArrayValueType, VLength > &r)
Self operator/(const Tt &val) const
FixedArray< T, NVectorDimension > Superclass
const Self & operator+=(const Self &vec)
RealValueType GetSquaredNorm() const
static unsigned int GetNumberOfComponents()
RealValueType GetNorm() const
A templated class holding a n-Dimensional covariant vector.
vnl_vector_ref< T > GetVnlVector()
const Self & operator*=(const Tt &value)
static unsigned int GetCovariantVectorDimension()