ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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 return Self(a.Size(), NumericTraits<T>::max());
99 }
100
101 static const Self
102 min(const Self & a)
103 {
104 return Self(a.Size(), NumericTraits<T>::min());
105 }
106
107 static const Self
108 ZeroValue(const Self & a)
109 {
110 return Self(a.Size(), T{});
111 }
112
113 static const Self
114 OneValue(const Self & a)
115 {
116 return Self(a.Size(), NumericTraits<T>::OneValue());
117 }
118
119 static const Self
121 {
122 return Self(a.Size(), NumericTraits<T>::NonpositiveMin());
123 }
124
125 static bool
126 IsPositive(const Self & a)
127 {
128 bool flag = false;
129 for (unsigned int i = 0; i < GetLength(a); ++i)
130 {
131 if (a[i] > ValueType{})
132 {
133 flag = true;
134 }
135 }
136 return flag;
137 }
138
139 static bool
141 {
142 bool flag = false;
143 for (unsigned int i = 0; i < GetLength(a); ++i)
144 {
145 if (!(a[i] > 0.0))
146 {
147 flag = true;
148 }
149 }
150 return flag;
151 }
152
153 static bool
154 IsNegative(const Self & a)
155 {
156 bool flag = false;
157 for (unsigned int i = 0; i < GetLength(a); ++i)
158 {
159 if (a[i] < ValueType{})
160 {
161 flag = true;
162 }
163 }
164 return flag;
165 }
166
167 static bool
169 {
170 bool flag = false;
171 for (unsigned int i = 0; i < GetLength(a); ++i)
172 {
173 if (!(a[i] < 0.0))
174 {
175 flag = true;
176 }
177 }
178 return flag;
179 }
180
181 static constexpr bool IsSigned = std::is_signed_v<ValueType>;
182 static constexpr bool IsInteger = std::is_integral_v<ValueType>;
184
185
187 static void
188 SetLength(VariableLengthVector<T> & m, const unsigned int s)
189 {
190 m.SetSize(s);
191 m.Fill(T{});
192 }
193
195 static unsigned int
197 {
198 return m.GetSize();
199 }
200
201 static void
203 {
204 mv = v;
205 }
206
207 template <typename TArray>
208 static void
209 AssignToArray(const Self & v, TArray & mv)
210 {
211 for (unsigned int i = 0; i < GetLength(v); ++i)
212 {
213 mv[i] = v[i];
214 }
215 }
216};
217} // end namespace itk
218
219#endif // itkNumericTraitsVariableLengthVector_h
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 T NonpositiveMin()
static constexpr T max(const T &)
static constexpr T min(const T &)
static constexpr unsigned int GetLength()
static constexpr bool IsComplex
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....