ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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 "itkVector.h"
22#include "vnl/vnl_vector_ref.h"
23
24namespace itk
25{
66template <typename T, unsigned int VVectorDimension = 3>
67class ITK_TEMPLATE_EXPORT CovariantVector : public FixedArray<T, VVectorDimension>
68{
69public:
73
76 using ValueType = T;
78
80 using ComponentType = T;
81
83 static constexpr unsigned int Dimension = VVectorDimension;
84
87
90
92 static unsigned int
94 {
95 return VVectorDimension;
96 }
97
99 void
100 SetVnlVector(const vnl_vector<T> &);
101
103 vnl_vector_ref<T>
105
107 [[nodiscard]] vnl_vector<T>
109
112 CovariantVector() = default;
113
117 explicit CovariantVector(const ValueType & r);
118
121 template <typename TVectorValueType>
126 : BaseArray(r)
127 {}
128
130 template <typename TCovariantVectorValueType>
131 Self &
137
140 operator=(const ValueType r[VVectorDimension]);
141
143 template <typename Tt>
144 inline const Self &
145 operator*=(const Tt & value)
146 {
147 for (unsigned int i = 0; i < VVectorDimension; ++i)
148 {
149 (*this)[i] = static_cast<ValueType>((*this)[i] * value);
150 }
151 return *this;
152 }
153
155 template <typename Tt>
156 const Self &
157 operator/=(const Tt & value)
158 {
159 for (unsigned int i = 0; i < VVectorDimension; ++i)
160 {
161 (*this)[i] = static_cast<ValueType>((*this)[i] / value);
162 }
163 return *this;
164 }
165
167 const Self &
168 operator+=(const Self & vec);
169
171 const Self &
172 operator-=(const Self & vec);
173
176 Self
177 operator-() const;
178
180 Self
181 operator+(const Self & vec) const;
182
184 Self
185 operator-(const Self & vec) const;
186
192 operator*(const Self & other) const;
193
198
201 inline Self
202 operator*(const ValueType & val) const
203 {
204 Self result;
205
206 for (unsigned int i = 0; i < VVectorDimension; ++i)
207 {
208 result[i] = static_cast<ValueType>((*this)[i] * val);
209 }
210 return result;
211 }
212
215 template <typename Tt>
216 inline Self
217 operator/(const Tt & val) const
218 {
219 Self result;
220
221 for (unsigned int i = 0; i < VVectorDimension; ++i)
222 {
223 result[i] = static_cast<ValueType>((*this)[i] / val);
224 }
225 return result;
226 }
227
229 [[nodiscard]] RealValueType
230 GetNorm() const;
231
233 static unsigned int
235 {
236 return VVectorDimension;
237 }
238
240 RealValueType
242
244 [[nodiscard]] RealValueType
246
249 template <typename TCoordinateB>
250 void
252 {
253 for (unsigned int i = 0; i < VVectorDimension; ++i)
254 {
255 (*this)[i] = static_cast<T>(pa[i]);
256 }
257 }
258};
259
262template <typename T, unsigned int VVectorDimension>
263inline CovariantVector<T, VVectorDimension>
265{
266 return v.operator*(scalar);
267}
268
271template <typename T, unsigned int VVectorDimension>
272inline T
274{
275 return covariant.operator*(contravariant);
276}
277
278ITKCommon_EXPORT void
280
281ITKCommon_EXPORT void
283
284ITKCommon_EXPORT void
286
287
288template <typename T, unsigned int VVectorDimension>
289inline void
294
295} // end namespace itk
296
297//
298// Numeric traits must be included after (optionally) including the explicit
299// instantiations control of this class, in case the implicit instantiation
300// needs to be disabled.
301//
302// NumericTraits must be included before (optionally) including the .hxx file,
303// in case the .hxx requires to use NumericTraits.
304//
306
307#ifndef ITK_MANUAL_INSTANTIATION
308# include "itkCovariantVector.hxx"
309#endif
310
311#endif
A templated class holding a n-Dimensional covariant vector.
ValueType operator*(const Self &other) const
FixedArray< double, VVectorDimension > Superclass
vnl_vector< T > GetVnlVector() const
RealValueType GetNorm() const
typename NumericTraits< ValueType >::RealType RealValueType
vnl_vector_ref< T > GetVnlVector()
Self operator+(const Self &vec) const
CovariantVector(const ValueType &r)
CovariantVector(const ValueType r[Dimension])
RealValueType Normalize()
const Self & operator*=(const Tt &value)
CovariantVector & operator=(const ValueType r[VVectorDimension])
void CastFrom(const CovariantVector< TCoordinateB, VVectorDimension > &pa)
void SetVnlVector(const vnl_vector< T > &)
Self operator-() const
CovariantVector(const CovariantVector< TVectorValueType, VVectorDimension > &r)
RealValueType GetSquaredNorm() const
static unsigned int GetNumberOfComponents()
ValueType operator*(const Vector< T, VVectorDimension > &other) const
FixedArray< double, VVectorDimension > BaseArray
CovariantVector()=default
Self operator-(const Self &vec) const
Self operator*(const ValueType &val) const
Self & operator=(const CovariantVector< TCovariantVectorValueType, VVectorDimension > &r)
Self operator/(const Tt &val) const
const Self & operator-=(const Self &vec)
const Self & operator/=(const Tt &value)
static unsigned int GetCovariantVectorDimension()
const Self & operator+=(const Self &vec)
FixedArray & operator=(const FixedArray< TFixedArrayValueType, VLength > &r)
A templated class holding a n-Dimensional vector.
Definition itkVector.h:63
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
void swap(Array< T > &a, Array< T > &b) noexcept
Definition itkArray.h:247
CovariantVector< T, VVectorDimension > operator*(const T &scalar, const CovariantVector< T, VVectorDimension > &v)
ITKCommon_EXPORT void CrossProduct(CovariantVector< double, 3 > &, const Vector< double, 3 > &, const Vector< double, 3 > &)