ITK  6.0.0
Insight Toolkit
itkCovariantVector.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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  * https://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 {
69 template <typename T, unsigned int VVectorDimension = 3>
70 class ITK_TEMPLATE_EXPORT CovariantVector : public FixedArray<T, VVectorDimension>
71 {
72 public:
76 
79  using ValueType = T;
81 
83  using ComponentType = T;
84 
86  static constexpr unsigned int Dimension = VVectorDimension;
87 
90 
93 
95  static unsigned int
97  {
98  return VVectorDimension;
99  }
100 
102  void
103  SetVnlVector(const vnl_vector<T> &);
104 
106  vnl_vector_ref<T>
107  GetVnlVector();
108 
110  vnl_vector<T>
111  GetVnlVector() const;
112 
115  CovariantVector() = default;
116 
120  explicit CovariantVector(const ValueType & r);
121 
124  template <typename TVectorValueType>
126  : BaseArray(r)
127  {}
129  : BaseArray(r)
130  {}
134  template <typename TCovariantVectorValueType>
135  Self &
137  {
138  BaseArray::operator=(r);
139  return *this;
140  }
145  operator=(const ValueType r[VVectorDimension]);
146 
148  template <typename Tt>
149  inline const Self &
150  operator*=(const Tt & value)
151  {
152  for (unsigned int i = 0; i < VVectorDimension; ++i)
153  {
154  (*this)[i] = static_cast<ValueType>((*this)[i] * value);
155  }
156  return *this;
157  }
161  template <typename Tt>
162  const Self &
163  operator/=(const Tt & value)
164  {
165  for (unsigned int i = 0; i < VVectorDimension; ++i)
166  {
167  (*this)[i] = static_cast<ValueType>((*this)[i] / value);
168  }
169  return *this;
170  }
174  const Self &
175  operator+=(const Self & vec);
176 
178  const Self &
179  operator-=(const Self & vec);
180 
183  Self
184  operator-() const;
185 
187  Self
188  operator+(const Self & vec) const;
189 
191  Self
192  operator-(const Self & vec) const;
193 
198  ValueType
199  operator*(const Self & other) const;
200 
203  ValueType
204  operator*(const Vector<T, VVectorDimension> & other) const;
205 
208  inline Self
209  operator*(const ValueType & val) const
210  {
211  Self result;
212 
213  for (unsigned int i = 0; i < VVectorDimension; ++i)
214  {
215  result[i] = static_cast<ValueType>((*this)[i] * val);
216  }
217  return result;
218  }
219 
222  template <typename Tt>
223  inline Self
224  operator/(const Tt & val) const
225  {
226  Self result;
227 
228  for (unsigned int i = 0; i < VVectorDimension; ++i)
229  {
230  result[i] = static_cast<ValueType>((*this)[i] / val);
231  }
232  return result;
233  }
234 
236  RealValueType
237  GetNorm() const;
238 
240  static unsigned int
242  {
243  return VVectorDimension;
244  }
245 
247  RealValueType
248  Normalize();
249 
251  RealValueType
252  GetSquaredNorm() const;
253 
256  template <typename TCoordinateB>
257  void
259  {
260  for (unsigned int i = 0; i < VVectorDimension; ++i)
261  {
262  (*this)[i] = static_cast<T>(pa[i]);
263  }
264  }
265 };
270 template <typename T, unsigned int VVectorDimension>
271 inline CovariantVector<T, VVectorDimension>
273 {
274  return v.operator*(scalar);
275 }
276 
279 template <typename T, unsigned int VVectorDimension>
280 inline T
282 {
283  return covariant.operator*(contravariant);
284 }
285 
286 ITKCommon_EXPORT void
287 CrossProduct(CovariantVector<double, 3> &, const Vector<double, 3> &, const Vector<double, 3> &);
288 
289 ITKCommon_EXPORT void
290 CrossProduct(CovariantVector<float, 3> &, const Vector<float, 3> &, const Vector<float, 3> &);
291 
292 ITKCommon_EXPORT void
293 CrossProduct(CovariantVector<int, 3>, const Vector<int, 3> &, const Vector<int, 3> &);
294 
295 
296 template <typename T, unsigned int VVectorDimension>
297 inline void
299 {
300  a.swap(b);
301 }
302 
303 } // end namespace itk
304 
305 //
306 // Numeric traits must be included after (optionally) including the explicit
307 // instantiations control of this class, in case the implicit instantiation
308 // needs to be disabled.
309 //
310 // NumericTraits must be included before (optionally) including the .hxx file,
311 // in case the .hxx requires to use NumericTraits.
312 //
314 
315 #ifndef ITK_MANUAL_INSTANTIATION
316 # include "itkCovariantVector.hxx"
317 #endif
318 
319 #endif
itk::CovariantVector::CovariantVector
CovariantVector(const ValueType r[Dimension])
Definition: itkCovariantVector.h:128
itk::CovariantVector::operator/=
const Self & operator/=(const Tt &value)
Definition: itkCovariantVector.h:163
itk::CovariantVector::CovariantVector
CovariantVector(const CovariantVector< TVectorValueType, VVectorDimension > &r)
Definition: itkCovariantVector.h:125
itk::CovariantVector::operator/
Self operator/(const Tt &val) const
Definition: itkCovariantVector.h:224
itk::operator*
CovariantVector< T, VVectorDimension > operator*(const T &scalar, const CovariantVector< T, VVectorDimension > &v)
Definition: itkCovariantVector.h:272
Self
AddImageFilter Self
Definition: itkAddImageFilter.h:89
itk::CovariantVector::operator*
Self operator*(const ValueType &val) const
Definition: itkCovariantVector.h:209
itk::CovariantVector< double, TPointDimension >::ComponentType
double ComponentType
Definition: itkCovariantVector.h:83
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:672
itk::CovariantVector::GetNumberOfComponents
static unsigned int GetNumberOfComponents()
Definition: itkCovariantVector.h:241
itk::CovariantVector< double, TPointDimension >::RealValueType
typename NumericTraits< ValueType >::RealType RealValueType
Definition: itkCovariantVector.h:80
itkIndent.h
itk::CovariantVector::GetCovariantVectorDimension
static unsigned int GetCovariantVectorDimension()
Definition: itkCovariantVector.h:96
itkNumericTraitsCovariantVectorPixel.h
itk::CrossProduct
ITKCommon_EXPORT void CrossProduct(CovariantVector< double, 3 > &, const Vector< double, 3 > &, const Vector< double, 3 > &)
itk::CovariantVector::operator*=
const Self & operator*=(const Tt &value)
Definition: itkCovariantVector.h:150
itk::CovariantVector::operator=
Self & operator=(const CovariantVector< TCovariantVectorValueType, VVectorDimension > &r)
Definition: itkCovariantVector.h:136
itk::FixedArray
Simulate a standard C array with copy semantics.
Definition: itkFixedArray.h:53
itk::CovariantVector
A templated class holding a n-Dimensional covariant vector.
Definition: itkCovariantVector.h:70
itk::swap
void swap(Array< T > &a, Array< T > &b) noexcept
Definition: itkArray.h:242
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itkVector.h
itk::operator+
ConstNeighborhoodIterator< TImage > operator+(const ConstNeighborhoodIterator< TImage > &it, const typename ConstNeighborhoodIterator< TImage >::OffsetType &ind)
Definition: itkConstNeighborhoodIterator.h:654
itk::NumericTraits::RealType
double RealType
Definition: itkNumericTraits.h:86
itk::CovariantVector::CastFrom
void CastFrom(const CovariantVector< TCoordinateB, VVectorDimension > &pa)
Definition: itkCovariantVector.h:258
AddImageFilter
Definition: itkAddImageFilter.h:81
itk::GTest::TypedefsAndConstructors::Dimension2::Dimension
constexpr unsigned int Dimension
Definition: itkGTestTypedefsAndConstructors.h:44
itk::CovariantVector< double, TPointDimension >::ValueType
double ValueType
Definition: itkCovariantVector.h:79