ITK  5.1.0
Insight 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 {
67 template <typename T, unsigned int NVectorDimension = 3>
68 class ITK_TEMPLATE_EXPORT CovariantVector : public FixedArray<T, NVectorDimension>
69 {
70 public:
74 
77  using ValueType = T;
79 
81  using ComponentType = T;
82 
84  static constexpr unsigned int Dimension = NVectorDimension;
85 
88 
91 
93  static unsigned int
95  {
96  return NVectorDimension;
97  }
98 
100  void
101  SetVnlVector(const vnl_vector<T> &);
102 
104  vnl_vector_ref<T>
105  GetVnlVector();
106 
108  vnl_vector<T>
109  GetVnlVector() const;
110 
112  CovariantVector() = default;
113  CovariantVector(const CovariantVector &) = default;
114  CovariantVector(CovariantVector &&) = default;
116  operator=(const CovariantVector &) = default;
118  operator=(CovariantVector &&) = default;
119  ~CovariantVector() = default;
121 
125  explicit CovariantVector(const ValueType & r);
126 
129  template <typename TVectorValueType>
131  : BaseArray(r)
132  {}
134  : BaseArray(r)
135  {}
137 
139  template <typename TCovariantVectorValueType>
140  Self &
142  {
143  BaseArray::operator=(r);
144  return *this;
145  }
147 
150  operator=(const ValueType r[NVectorDimension]);
151 
153  template <typename Tt>
154  inline const Self &
155  operator*=(const Tt & value)
156  {
157  for (unsigned int i = 0; i < NVectorDimension; i++)
158  {
159  (*this)[i] = static_cast<ValueType>((*this)[i] * value);
160  }
161  return *this;
162  }
164 
166  template <typename Tt>
167  const Self &
168  operator/=(const Tt & value)
169  {
170  for (unsigned int i = 0; i < NVectorDimension; i++)
171  {
172  (*this)[i] = static_cast<ValueType>((*this)[i] / value);
173  }
174  return *this;
175  }
177 
179  const Self &
180  operator+=(const Self & vec);
181 
183  const Self &
184  operator-=(const Self & vec);
185 
188  Self
189  operator-() const;
190 
192  Self
193  operator+(const Self & vec) const;
194 
196  Self
197  operator-(const Self & vec) const;
198 
203  ValueType operator*(const Self & vec) const;
204 
207  ValueType operator*(const Vector<T, NVectorDimension> & vec) const;
208 
211  inline Self operator*(const ValueType & val) const
212  {
213  Self result;
214 
215  for (unsigned int i = 0; i < NVectorDimension; i++)
216  {
217  result[i] = static_cast<ValueType>((*this)[i] * val);
218  }
219  return result;
220  }
221 
224  template <typename Tt>
225  inline Self
226  operator/(const Tt & val) const
227  {
228  Self result;
229 
230  for (unsigned int i = 0; i < NVectorDimension; i++)
231  {
232  result[i] = static_cast<ValueType>((*this)[i] / val);
233  }
234  return result;
235  }
236 
238  RealValueType
239  GetNorm() const;
240 
242  static unsigned int
244  {
245  return NVectorDimension;
246  }
247 
249  RealValueType
250  Normalize();
251 
253  RealValueType
254  GetSquaredNorm() const;
255 
258  template <typename TCoordRepB>
259  void
261  {
262  for (unsigned int i = 0; i < NVectorDimension; i++)
263  {
264  (*this)[i] = static_cast<T>(pa[i]);
265  }
266  }
267 };
269 
272 template <typename T, unsigned int NVectorDimension>
274 {
275  return v.operator*(scalar);
276 }
277 
280 template <typename T, unsigned int NVectorDimension>
281 inline T operator*(const Vector<T, NVectorDimension> & contravariant,
282  const CovariantVector<T, NVectorDimension> & covariant)
283 {
284  return covariant.operator*(contravariant);
285 }
286 
287 ITKCommon_EXPORT void
288 CrossProduct(CovariantVector<double, 3> &, const Vector<double, 3> &, const Vector<double, 3> &);
289 
290 ITKCommon_EXPORT void
291 CrossProduct(CovariantVector<float, 3> &, const Vector<float, 3> &, const Vector<float, 3> &);
292 
293 ITKCommon_EXPORT void
294 CrossProduct(CovariantVector<int, 3>, const Vector<int, 3> &, const Vector<int, 3> &);
295 
296 
297 template <typename T, unsigned int NVectorDimension>
298 inline void
300 {
301  a.swap(b);
302 }
303 
304 } // end namespace itk
305 
306 //
307 // Numeric traits must be included after (optionally) including the explicit
308 // instantiations control of this class, in case the implicit instantiation
309 // needs to be disabled.
310 //
311 // NumericTraits must be included before (optionally) including the .hxx file,
312 // in case the .hxx requires to use NumericTraits.
313 //
315 
316 #ifndef ITK_MANUAL_INSTANTIATION
317 # include "itkCovariantVector.hxx"
318 #endif
319 
320 #endif
itk::CovariantVector::operator/
Self operator/(const Tt &val) const
Definition: itkCovariantVector.h:226
itk::CovariantVector< double, TPointDimension >::RealValueType
typename NumericTraits< ValueType >::RealType RealValueType
Definition: itkCovariantVector.h:78
itk::CovariantVector< double, TPointDimension >::ValueType
double ValueType
Definition: itkCovariantVector.h:77
itk::CovariantVector::CovariantVector
CovariantVector(const CovariantVector< TVectorValueType, NVectorDimension > &r)
Definition: itkCovariantVector.h:130
itk::swap
void swap(Array< T > &a, Array< T > &b)
Definition: itkArray.h:237
itk::Vector
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
itk::operator-
ConstNeighborhoodIterator< TImage > operator-(const ConstNeighborhoodIterator< TImage > &it, const typename ConstNeighborhoodIterator< TImage >::OffsetType &ind)
Definition: itkConstNeighborhoodIterator.h:678
itk::CovariantVector< double, TPointDimension >::ComponentType
double ComponentType
Definition: itkCovariantVector.h:81
itk::CovariantVector::operator*=
const Self & operator*=(const Tt &value)
Definition: itkCovariantVector.h:155
itk::CovariantVector::GetCovariantVectorDimension
static unsigned int GetCovariantVectorDimension()
Definition: itkCovariantVector.h:94
itk::CovariantVector::GetNumberOfComponents
static unsigned int GetNumberOfComponents()
Definition: itkCovariantVector.h:243
itkIndent.h
itkNumericTraitsCovariantVectorPixel.h
itk::CrossProduct
ITKCommon_EXPORT void CrossProduct(CovariantVector< double, 3 > &, const Vector< double, 3 > &, const Vector< double, 3 > &)
itk::FixedArray
Simulate a standard C array with copy semantics.
Definition: itkFixedArray.h:52
itk::CovariantVector::CastFrom
void CastFrom(const CovariantVector< TCoordRepB, NVectorDimension > &pa)
Definition: itkCovariantVector.h:260
itk::operator*
CovariantVector< T, NVectorDimension > operator*(const T &scalar, const CovariantVector< T, NVectorDimension > &v)
Definition: itkCovariantVector.h:273
itk::CovariantVector
A templated class holding a n-Dimensional covariant vector.
Definition: itkCovariantVector.h:68
itk::CovariantVector::operator/=
const Self & operator/=(const Tt &value)
Definition: itkCovariantVector.h:168
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkArray.h:26
itk::CovariantVector::CovariantVector
CovariantVector(const ValueType r[Dimension])
Definition: itkCovariantVector.h:133
itkVector.h
itk::FixedArray< T, NVectorDimension >::swap
void swap(FixedArray &other)
Definition: itkFixedArray.h:424
itk::operator+
ConstNeighborhoodIterator< TImage > operator+(const ConstNeighborhoodIterator< TImage > &it, const typename ConstNeighborhoodIterator< TImage >::OffsetType &ind)
Definition: itkConstNeighborhoodIterator.h:660
itk::CovariantVector::operator=
Self & operator=(const CovariantVector< TCovariantVectorValueType, NVectorDimension > &r)
Definition: itkCovariantVector.h:141
itk::NumericTraits::RealType
double RealType
Definition: itkNumericTraits.h:84
itk::CovariantVector::operator*
Self operator*(const ValueType &val) const
Definition: itkCovariantVector.h:211
itk::GTest::TypedefsAndConstructors::Dimension2::Dimension
constexpr unsigned int Dimension
Definition: itkGTestTypedefsAndConstructors.h:44