ITK  6.0.0
Insight Toolkit
itkNumericTraitsVectorPixel.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 itkNumericTraitsVectorPixel_h
19#define itkNumericTraitsVectorPixel_h
20
21#include "itkNumericTraits.h"
22#include "itkVector.h"
23
24namespace itk
25{
30template <typename T, unsigned int D>
32{
33private:
39
40public:
42 using ValueType = T;
44
47
50
54
57
60
63
66
72 static const Self
73 max(const Self &)
74 {
75 return MakeFilled<Self>(NumericTraits<T>::max());
76 }
77
78 static const Self
79 min(const Self &)
80 {
81 return MakeFilled<Self>(NumericTraits<T>::min());
82 }
83
84 static const Self
86 {
87 return MakeFilled<Self>(NumericTraits<T>::max());
88 }
89
90 static const Self
92 {
93 return MakeFilled<Self>(NumericTraits<T>::min());
94 }
95
96 static const Self
98 {
99 return MakeFilled<Self>(NumericTraits<T>::NonpositiveMin());
100 }
101
102 static const Self
104 {
105 return Self{};
106 }
107
108 static const Self
110 {
111 return MakeFilled<Self>(NumericTraits<T>::OneValue());
112 }
113
114 static const Self
116 {
117 return NonpositiveMin();
118 }
119
120 static const Self
122 {
123 return ZeroValue();
124 }
125
126 static const Self
127 OneValue(const Self &)
128 {
129 return OneValue();
130 }
131
132 static bool
133 IsPositive(const Self & a)
134 {
135 bool flag = false;
136 for (unsigned int i = 0; i < GetLength(a); ++i)
137 {
138 if (a[i] > ValueType{})
139 {
140 flag = true;
141 }
142 }
143 return flag;
144 }
145
146 static bool
148 {
149 bool flag = false;
150 for (unsigned int i = 0; i < GetLength(a); ++i)
151 {
152 if (!(a[i] > 0.0))
153 {
154 flag = true;
155 }
156 }
157 return flag;
158 }
159
160 static bool
161 IsNegative(const Self & a)
162 {
163 bool flag = false;
164 for (unsigned int i = 0; i < GetLength(a); ++i)
165 {
166 if (a[i] < 0.0)
167 {
168 flag = true;
169 }
170 }
171 return flag;
172 }
173
174 static bool
176 {
177 bool flag = false;
178 for (unsigned int i = 0; i < GetLength(a); ++i)
179 {
180 if (!(a[i] < 0.0))
181 {
182 flag = true;
183 }
184 }
185 return flag;
186 }
187
188 static constexpr bool IsSigned = std::is_signed_v<ValueType>;
189 static constexpr bool IsInteger = std::is_integral_v<ValueType>;
191
195 static void
196 SetLength(Vector<T, D> & m, const unsigned int s)
197 {
198 if (s != D)
199 {
200 itkGenericExceptionMacro("Cannot set the size of a Vector of length " << D << " to " << s);
201 }
202 m.Fill(T{});
203 }
207 static unsigned int
209 {
210 return D;
211 }
212
214 static unsigned int
216 {
217 return D;
218 }
219
220 static void
222 {
223 mv = v;
224 }
225
226 template <typename TArray>
227 static void
228 AssignToArray(const Self & v, TArray & mv)
229 {
230 for (unsigned int i = 0; i < D; ++i)
231 {
232 mv[i] = v[i];
233 }
234 }
235
239 static const Self ITKCommon_EXPORT Zero;
240 static const Self ITKCommon_EXPORT One;
241};
242} // end namespace itk
243
244#endif // itkNumericTraitsVectorPixel_h
Pixel-wise addition of two images.
void Fill(const ValueType &)
static const Self ITKCommon_EXPORT One
typename NumericTraits< T >::AbsType ElementAbsType
static const Self NonpositiveMin(const Self &)
static void AssignToArray(const Self &v, TArray &mv)
typename NumericTraits< T >::RealType ElementRealType
typename NumericTraits< T >::AccumulateType ElementAccumulateType
static unsigned int GetLength(const Vector< T, D > &)
static void SetLength(Vector< T, D > &m, const unsigned int s)
static void AssignToArray(const Self &v, MeasurementVectorType &mv)
static const Self ITKCommon_EXPORT Zero
typename NumericTraits< T >::PrintType ElementPrintType
typename NumericTraits< T >::FloatType ElementFloatType
Define additional traits for native types such as int or float.
static constexpr bool IsInteger
static constexpr bool IsSigned
static constexpr T NonpositiveMin()
static unsigned int GetLength()
static constexpr bool IsComplex
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....