ITK  5.4.0
Insight Toolkit
itkNumericTraitsVariableLengthVectorPixel.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 itkNumericTraitsVariableLengthVectorPixel_h
19#define itkNumericTraitsVariableLengthVectorPixel_h
20
22
23// This work is part of the National Alliance for Medical Image Computing
24// (NAMIC), funded by the National Institutes of Health through the NIH Roadmap
25// for Medical Research, Grant U54 EB005149.
26
27namespace itk
28{
53template <typename T>
55{
56public:
62
64 using ValueType = T;
65
67
70
73
77
80
83
86
89
95 static const Self
96 max(const Self & a)
97 {
98 Self b(a.Size());
99
100 b.Fill(NumericTraits<T>::max());
101 return b;
102 }
103
104 static const Self
105 min(const Self & a)
106 {
107 Self b(a.Size());
108
109 b.Fill(NumericTraits<T>::min());
110 return b;
111 }
112
113 static const Self
114 ZeroValue(const Self & a)
115 {
116 Self b(a.Size());
117
118 b.Fill(T{});
119 return b;
120 }
121
122 static const Self
123 OneValue(const Self & a)
124 {
125 Self b(a.Size());
126
128 return b;
129 }
130
131 static const Self
133 {
134 Self b(a.Size());
136 return b;
137 }
138
139 static bool
140 IsPositive(const Self & a)
141 {
142 bool flag = false;
143 for (unsigned int i = 0; i < GetLength(a); ++i)
144 {
145 if (a[i] > ValueType{})
146 {
147 flag = true;
148 }
149 }
150 return flag;
151 }
152
153 static bool
155 {
156 bool flag = false;
157 for (unsigned int i = 0; i < GetLength(a); ++i)
158 {
159 if (!(a[i] > 0.0))
160 {
161 flag = true;
162 }
163 }
164 return flag;
165 }
166
167 static bool
168 IsNegative(const Self & a)
169 {
170 bool flag = false;
171 for (unsigned int i = 0; i < GetLength(a); ++i)
172 {
173 if (a[i] < ValueType{})
174 {
175 flag = true;
176 }
177 }
178 return flag;
179 }
180
181 static bool
183 {
184 bool flag = false;
185 for (unsigned int i = 0; i < GetLength(a); ++i)
186 {
187 if (!(a[i] < 0.0))
188 {
189 flag = true;
190 }
191 }
192 return flag;
193 }
194
195 static constexpr bool IsSigned = std::is_signed_v<ValueType>;
196 static constexpr bool IsInteger = std::is_integral_v<ValueType>;
198
199
201 static void
202 SetLength(VariableLengthVector<T> & m, const unsigned int s)
203 {
204 m.SetSize(s);
205 m.Fill(T{});
206 }
210 static unsigned int
212 {
213 return m.GetSize();
214 }
215
216 static void
218 {
219 mv = v;
220 }
221
222 template <typename TArray>
223 static void
224 AssignToArray(const Self & v, TArray & mv)
225 {
226 for (unsigned int i = 0; i < GetLength(v); ++i)
227 {
228 mv[i] = v[i];
229 }
230 }
231};
232} // end namespace itk
233
234#endif // itkNumericTraitsVariableLengthVector_h
Pixel-wise addition of two images.
static unsigned int GetLength(const VariableLengthVector< T > &m)
static void AssignToArray(const Self &v, MeasurementVectorType &mv)
static void SetLength(VariableLengthVector< T > &m, const unsigned int s)
Define additional traits for native types such as int or float.
static constexpr bool IsInteger
static constexpr bool IsSigned
static unsigned int GetLength()
static constexpr bool IsComplex
AddImageFilter Self
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....