ITK  4.13.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 ITK_TEMPLATE_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();
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 
122  CovariantVector(const ValueType & r);
123 
126  template< typename TVectorValueType >
127  CovariantVector(const CovariantVector< TVectorValueType,
128  NVectorDimension > & r):BaseArray(r) {}
131 
133  template< typename Tt >
134  Self & operator=(const Tt & v)
135  {
136  BaseArray::operator=(v);
137  return *this;
138  }
140 
142  CovariantVector & operator=(const Self & r);
143 
144  CovariantVector & operator=(const ValueType r[NVectorDimension]);
145 
147  template< typename Tt >
148  inline const Self & operator*=(const Tt & value)
149  {
150  for ( unsigned int i = 0; i < NVectorDimension; i++ )
151  {
152  ( *this )[i] = static_cast< ValueType >( ( *this )[i] * value );
153  }
154  return *this;
155  }
157 
159  template< typename Tt >
160  const Self & operator/=(const Tt & value)
161  {
162  for ( unsigned int i = 0; i < NVectorDimension; i++ )
163  {
164  ( *this )[i] = static_cast< ValueType >( ( *this )[i] / value );
165  }
166  return *this;
167  }
169 
171  const Self & operator+=(const Self & vec);
172 
174  const Self & operator-=(const Self & vec);
175 
178  Self operator-() const;
179 
181  Self operator+(const Self & vec) const;
182 
184  Self operator-(const Self & vec) const;
185 
190  ValueType operator *(const Self & vec) const;
191 
194  ValueType operator *(const Vector< T, NVectorDimension > & vec) const;
195 
198  inline Self operator*(const ValueType & val) const
199  {
200  Self result;
201 
202  for ( unsigned int i = 0; i < NVectorDimension; i++ )
203  {
204  result[i] = static_cast< ValueType >( ( *this )[i] * val );
205  }
206  return result;
207  }
208 
211  template< typename Tt >
212  inline Self operator/(const Tt & val) const
213  {
214  Self result;
215 
216  for ( unsigned int i = 0; i < NVectorDimension; i++ )
217  {
218  result[i] = static_cast< ValueType >( ( *this )[i] / val );
219  }
220  return result;
221  }
222 
224  RealValueType GetNorm() const;
225 
227  static unsigned int GetNumberOfComponents() { return NVectorDimension; }
228 
230  RealValueType Normalize();
231 
233  RealValueType GetSquaredNorm() const;
234 
237  template< typename TCoordRepB >
239  {
240  for ( unsigned int i = 0; i < NVectorDimension; i++ )
241  {
242  ( *this )[i] = static_cast< T >( pa[i] );
243  }
244  }
245 };
247 
250 template< typename T, unsigned int NVectorDimension >
251 inline
252 CovariantVector< T, NVectorDimension >
254 {
255  return v.operator*(scalar);
256 }
257 
260 template< typename T, unsigned int NVectorDimension >
261 inline
262 T
264 {
265  return covariant.operator*( contravariant );
266 }
267 
268 ITKCommon_EXPORT void CrossProduct(CovariantVector< double, 3 > &,
269  const Vector< double, 3 > &,
270  const Vector< double, 3 > &);
271 
272 ITKCommon_EXPORT void CrossProduct(CovariantVector< float, 3 > &,
273  const Vector< float, 3 > &,
274  const Vector< float, 3 > &);
275 
276 ITKCommon_EXPORT void CrossProduct(CovariantVector< int, 3 >,
277  const Vector< int, 3 > &,
278  const Vector< int, 3 > &);
279 } // end namespace itk
280 
281 //
282 // Numeric traits must be included after (optionally) including the explicit
283 // instantiations control of this class, in case the implicit instantiation
284 // needs to be disabled.
285 //
286 // NumericTraits must be included before (optionally) including the .hxx file,
287 // in case the .hxx requires to use NumericTraits.
288 //
290 
291 #ifndef ITK_MANUAL_INSTANTIATION
292 #include "itkCovariantVector.hxx"
293 #endif
294 
295 #endif
void CastFrom(const CovariantVector< TCoordRepB, NVectorDimension > &pa)
Self & operator=(const Tt &v)
ConstNeighborhoodIterator< TImage > operator-(const ConstNeighborhoodIterator< TImage > &it, const typename ConstNeighborhoodIterator< TImage >::OffsetType &ind)
const Self & operator/=(const Tt &value)
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])
Simulate a standard C array with copy semnatics.
Definition: itkFixedArray.h:50
CovariantVector(const CovariantVector< TVectorValueType, NVectorDimension > &r)
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
ConstNeighborhoodIterator< TImage > operator+(const ConstNeighborhoodIterator< TImage > &it, const typename ConstNeighborhoodIterator< TImage >::OffsetType &ind)
ITKCommon_EXPORT void CrossProduct(CovariantVector< double, 3 > &, const Vector< double, 3 > &, const Vector< double, 3 > &)
Self operator/(const Tt &val) const
FixedArray< T, NVectorDimension > Superclass
static unsigned int GetNumberOfComponents()
A templated class holding a n-Dimensional covariant vector.
const Self & operator*=(const Tt &value)
static unsigned int GetCovariantVectorDimension()