ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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 {
90 }
91
92 static const Self
93 min(const Self &)
94 {
96 }
97
98 static const Self
100 {
102 }
103
104 static const Self
106 {
108 }
109
110 static const Self
115
116 static const Self
118 {
119 return Self{};
120 }
121
122 static const Self
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 }
158
160 static unsigned int
162 {
163 return D;
164 }
165
167 static unsigned int
169 {
170 return D;
171 }
172
173 static void
175 {
176 mv = v;
177 }
178
179 template <typename TArray>
180 static void
181 AssignToArray(const Self & v, TArray & mv)
182 {
183 for (unsigned int i = 0; i < D; ++i)
184 {
185 mv[i] = v[i];
186 }
187 }
188
192 static const Self ITKCommon_EXPORT Zero;
193 static const Self ITKCommon_EXPORT One;
194};
195
196// a macro to define and initialize static member variables,
197// NOTE: (T)(NumericTraits< T >::[Zero|One]) is needed to generate
198// a temporary variable that is initialized from the
199// constexpr [Zero|One] to be passed by const reference
200// to the GENERIC_ARRAY<T,D> constructor.
201#define itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, D) \
202 template <> \
203 ITKCommon_EXPORT const GENERIC_ARRAY<T, D> NumericTraits<GENERIC_ARRAY<T, D>>::Zero = \
204 MakeFilled<GENERIC_ARRAY<T, D>>(NumericTraits<T>::Zero); \
205 template <> \
206 ITKCommon_EXPORT const GENERIC_ARRAY<T, D> NumericTraits<GENERIC_ARRAY<T, D>>::One = \
207 MakeFilled<GENERIC_ARRAY<T, D>>(NumericTraits<T>::One); \
208 ITK_MACROEND_NOOP_STATEMENT
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 ITK_MACROEND_NOOP_STATEMENT
226} // end namespace itk
227
228#endif // itkNumericTraitsFixedArrayPixel_h
Simulate a standard C array with copy semantics.
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)
FixedArray< ElementAccumulateType, D > AccumulateType
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 &)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
constexpr TContainer MakeFilled(typename TContainer::const_reference value)