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 operator*(const Self & other) const;
199 
202  ValueType operator*(const Vector<T, VVectorDimension> & other) const;
203 
206  inline Self operator*(const ValueType & val) const
207  {
208  Self result;
209 
210  for (unsigned int i = 0; i < VVectorDimension; ++i)
211  {
212  result[i] = static_cast<ValueType>((*this)[i] * val);
213  }
214  return result;
215  }
216 
219  template <typename Tt>
220  inline Self
221  operator/(const Tt & val) const
222  {
223  Self result;
224 
225  for (unsigned int i = 0; i < VVectorDimension; ++i)
226  {
227  result[i] = static_cast<ValueType>((*this)[i] / val);
228  }
229  return result;
230  }
231 
233  RealValueType
234  GetNorm() const;
235 
237  static unsigned int
239  {
240  return VVectorDimension;
241  }
242 
244  RealValueType
245  Normalize();
246 
248  RealValueType
249  GetSquaredNorm() const;
250 
253  template <typename TCoordinateB>
254  void
256  {
257  for (unsigned int i = 0; i < VVectorDimension; ++i)
258  {
259  (*this)[i] = static_cast<T>(pa[i]);
260  }
261  }
262 };
267 template <typename T, unsigned int VVectorDimension>
269 {
270  return v.operator*(scalar);
271 }
272 
275 template <typename T, unsigned int VVectorDimension>
276 inline T operator*(const Vector<T, VVectorDimension> & contravariant,
277  const CovariantVector<T, VVectorDimension> & covariant)
278 {
279  return covariant.operator*(contravariant);
280 }
281 
282 ITKCommon_EXPORT void
283 CrossProduct(CovariantVector<double, 3> &, const Vector<double, 3> &, const Vector<double, 3> &);
284 
285 ITKCommon_EXPORT void
286 CrossProduct(CovariantVector<float, 3> &, const Vector<float, 3> &, const Vector<float, 3> &);
287 
288 ITKCommon_EXPORT void
289 CrossProduct(CovariantVector<int, 3>, const Vector<int, 3> &, const Vector<int, 3> &);
290 
291 
292 template <typename T, unsigned int VVectorDimension>
293 inline void
295 {
296  a.swap(b);
297 }
298 
299 } // end namespace itk
300 
301 //
302 // Numeric traits must be included after (optionally) including the explicit
303 // instantiations control of this class, in case the implicit instantiation
304 // needs to be disabled.
305 //
306 // NumericTraits must be included before (optionally) including the .hxx file,
307 // in case the .hxx requires to use NumericTraits.
308 //
310 
311 #ifndef ITK_MANUAL_INSTANTIATION
312 # include "itkCovariantVector.hxx"
313 #endif
314 
315 #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:221
itk::operator*
CovariantVector< T, VVectorDimension > operator*(const T &scalar, const CovariantVector< T, VVectorDimension > &v)
Definition: itkCovariantVector.h:268
Self
AddImageFilter Self
Definition: itkAddImageFilter.h:89
itk::CovariantVector::operator*
Self operator*(const ValueType &val) const
Definition: itkCovariantVector.h:206
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:238
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::FixedArray< T, VVectorDimension >::swap
void swap(FixedArray &other)
Definition: itkFixedArray.h:425
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:255
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