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
25namespace itk
26{
69template <typename T, unsigned int VVectorDimension = 3>
70class ITK_TEMPLATE_EXPORT CovariantVector : public FixedArray<T, VVectorDimension>
71{
72public:
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>
108
110 vnl_vector<T>
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
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
246
250
253 template <typename TCoordRepB>
254 void
256 {
257 for (unsigned int i = 0; i < VVectorDimension; ++i)
258 {
259 (*this)[i] = static_cast<T>(pa[i]);
260 }
261 }
262};
267template <typename T, unsigned int VVectorDimension>
269{
270 return v.operator*(scalar);
271}
272
275template <typename T, unsigned int VVectorDimension>
276inline T operator*(const Vector<T, VVectorDimension> & contravariant,
277 const CovariantVector<T, VVectorDimension> & covariant)
278{
279 return covariant.operator*(contravariant);
280}
281
282ITKCommon_EXPORT void
284
285ITKCommon_EXPORT void
287
288ITKCommon_EXPORT void
290
291
292template <typename T, unsigned int VVectorDimension>
293inline 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
Pixel-wise addition of two images.
A templated class holding a n-Dimensional covariant vector.
ValueType operator*(const Self &other) const
vnl_vector< T > GetVnlVector() const
RealValueType GetNorm() const
typename NumericTraits< ValueType >::RealType RealValueType
void CastFrom(const CovariantVector< TCoordRepB, VVectorDimension > &pa)
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 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
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)
Simulate a standard C array with copy semantics.
Definition: itkFixedArray.h:54
void swap(FixedArray &other)
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:63
AddImageFilter Self
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
void swap(Array< T > &a, Array< T > &b) noexcept
Definition: itkArray.h:242
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 > &)