ITK  5.4.0
Insight Toolkit
itkNumericTraitsFixedArrayPixel.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 itkNumericTraitsFixedArrayPixel_h
19#define itkNumericTraitsFixedArrayPixel_h
20
21#include "itkNumericTraits.h"
22#include "itkFixedArray.h"
23
24namespace itk
25{
43template <typename T, unsigned int D>
45{
46private:
52
53public:
55 using ValueType = T;
56
58
61
64
68
71
74
77
80
86 static const Self
87 max(const Self &)
88 {
89 return MakeFilled<Self>(NumericTraits<T>::max());
90 }
91
92 static const Self
93 min(const Self &)
94 {
95 return MakeFilled<Self>(NumericTraits<T>::min());
96 }
97
98 static const Self
100 {
101 return MakeFilled<Self>(NumericTraits<T>::max());
102 }
103
104 static const Self
106 {
107 return MakeFilled<Self>(NumericTraits<T>::min());
108 }
109
110 static const Self
112 {
113 return MakeFilled<Self>(NumericTraits<T>::NonpositiveMin());
114 }
115
116 static const Self
118 {
119 return Self{};
120 }
121
122 static const Self
124 {
125 return MakeFilled<Self>(NumericTraits<T>::OneValue());
126 }
127
128 static const Self
130 {
131 return NonpositiveMin();
132 }
133
134 static const Self
136 {
137 return ZeroValue();
138 }
139
140 static const Self
141 OneValue(const Self &)
142 {
143 return OneValue();
144 }
145
149 static void
150 SetLength(FixedArray<T, D> & m, const unsigned int s)
151 {
152 if (s != D)
153 {
154 itkGenericExceptionMacro("Cannot set the size of a FixedArray of length " << D << " to " << s);
155 }
156 m.Fill(T{});
157 }
161 static unsigned int
163 {
164 return D;
165 }
166
168 static unsigned int
170 {
171 return D;
172 }
173
174 static void
176 {
177 mv = v;
178 }
179
180 template <typename TArray>
181 static void
182 AssignToArray(const Self & v, TArray & mv)
183 {
184 for (unsigned int i = 0; i < D; ++i)
185 {
186 mv[i] = v[i];
187 }
188 }
189
193 static const Self ITKCommon_EXPORT Zero;
194 static const Self ITKCommon_EXPORT One;
195};
196
197// a macro to define and initialize static member variables,
198// NOTE: (T)(NumericTraits< T >::[Zero|One]) is needed to generate
199// a temporary variable that is initialized from the
200// constexpr [Zero|One] to be passed by const reference
201// to the GENERIC_ARRAY<T,D> constructor.
202#define itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, D) \
203 template <> \
204 ITKCommon_EXPORT const GENERIC_ARRAY<T, D> NumericTraits<GENERIC_ARRAY<T, D>>::Zero = \
205 MakeFilled<GENERIC_ARRAY<T, D>>(NumericTraits<T>::Zero); \
206 template <> \
207 ITKCommon_EXPORT const GENERIC_ARRAY<T, D> NumericTraits<GENERIC_ARRAY<T, D>>::One = \
208 MakeFilled<GENERIC_ARRAY<T, D>>(NumericTraits<T>::One);
209
210//
211// List here the array dimension specializations of these static
212// Traits:
213//
214#define itkStaticNumericTraitsGenericArrayDimensionsMacro(GENERIC_ARRAY, T) \
215 itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 1); \
216 itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 2); \
217 itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 3); \
218 itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 4); \
219 itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 5); \
220 itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 6); \
221 itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 7); \
222 itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 8); \
223 itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 9); \
224 itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 10);
225} // end namespace itk
226
227#endif // itkNumericTraitsFixedArrayPixel_h
Pixel-wise addition of two images.
Simulate a standard C array with copy semantics.
Definition: itkFixedArray.h:54
void Fill(const ValueType &)
typename NumericTraits< T >::AbsType ElementAbsType
static void AssignToArray(const Self &v, MeasurementVectorType &mv)
static unsigned int GetLength(const FixedArray< T, D > &)
typename NumericTraits< T >::FloatType ElementFloatType
static void AssignToArray(const Self &v, TArray &mv)
typename NumericTraits< T >::PrintType ElementPrintType
typename NumericTraits< T >::AccumulateType ElementAccumulateType
typename NumericTraits< T >::RealType ElementRealType
static void SetLength(FixedArray< T, D > &m, const unsigned int s)
Define additional traits for native types such as int or float.
static constexpr T NonpositiveMin()
AddImageFilter Self
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....