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 "itkIndent.h"
22#include "itkVector.h"
23#include "vnl/vnl_vector_ref.h"
24
25namespace itk
26{
67template <typename T, unsigned int VVectorDimension = 3>
68class ITK_TEMPLATE_EXPORT CovariantVector : public FixedArray<T, VVectorDimension>
69{
70public:
74
77 using ValueType = T;
79
81 using ComponentType = T;
82
84 static constexpr unsigned int Dimension = VVectorDimension;
85
88
91
93 static unsigned int
95 {
96 return VVectorDimension;
97 }
98
100 void
101 SetVnlVector(const vnl_vector<T> &);
102
104 vnl_vector_ref<T>
106
108 vnl_vector<T>
110
113 CovariantVector() = default;
114
118 explicit CovariantVector(const ValueType & r);
119
122 template <typename TVectorValueType>
127 : BaseArray(r)
128 {}
129
131 template <typename TCovariantVectorValueType>
132 Self &
138
141 operator=(const ValueType r[VVectorDimension]);
142
144 template <typename Tt>
145 inline const Self &
146 operator*=(const Tt & value)
147 {
148 for (unsigned int i = 0; i < VVectorDimension; ++i)
149 {
150 (*this)[i] = static_cast<ValueType>((*this)[i] * value);
151 }
152 return *this;
153 }
154
156 template <typename Tt>
157 const Self &
158 operator/=(const Tt & value)
159 {
160 for (unsigned int i = 0; i < VVectorDimension; ++i)
161 {
162 (*this)[i] = static_cast<ValueType>((*this)[i] / value);
163 }
164 return *this;
165 }
166
168 const Self &
169 operator+=(const Self & vec);
170
172 const Self &
173 operator-=(const Self & vec);
174
177 Self
178 operator-() const;
179
181 Self
182 operator+(const Self & vec) const;
183
185 Self
186 operator-(const Self & vec) const;
187
193 operator*(const Self & other) const;
194
199
202 inline Self
203 operator*(const ValueType & val) const
204 {
205 Self result;
206
207 for (unsigned int i = 0; i < VVectorDimension; ++i)
208 {
209 result[i] = static_cast<ValueType>((*this)[i] * val);
210 }
211 return result;
212 }
213
216 template <typename Tt>
217 inline Self
218 operator/(const Tt & val) const
219 {
220 Self result;
221
222 for (unsigned int i = 0; i < VVectorDimension; ++i)
223 {
224 result[i] = static_cast<ValueType>((*this)[i] / val);
225 }
226 return result;
227 }
228
230 RealValueType
231 GetNorm() const;
232
234 static unsigned int
236 {
237 return VVectorDimension;
238 }
239
241 RealValueType
243
247
250 template <typename TCoordinateB>
251 void
253 {
254 for (unsigned int i = 0; i < VVectorDimension; ++i)
255 {
256 (*this)[i] = static_cast<T>(pa[i]);
257 }
258 }
259};
260
263template <typename T, unsigned int VVectorDimension>
264inline CovariantVector<T, VVectorDimension>
266{
267 return v.operator*(scalar);
268}
269
272template <typename T, unsigned int VVectorDimension>
273inline T
275{
276 return covariant.operator*(contravariant);
277}
278
279ITKCommon_EXPORT void
281
282ITKCommon_EXPORT void
284
285ITKCommon_EXPORT void
287
288
289template <typename T, unsigned int VVectorDimension>
290inline void
295
296} // end namespace itk
297
298//
299// Numeric traits must be included after (optionally) including the explicit
300// instantiations control of this class, in case the implicit instantiation
301// needs to be disabled.
302//
303// NumericTraits must be included before (optionally) including the .hxx file,
304// in case the .hxx requires to use NumericTraits.
305//
307
308#ifndef ITK_MANUAL_INSTANTIATION
309# include "itkCovariantVector.hxx"
310#endif
311
312#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 > &)