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 
24 namespace itk
25 {
43 template <typename T, unsigned int D>
45 {
46 private:
52 
53 public:
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
99  max()
100  {
101  return MakeFilled<Self>(NumericTraits<T>::max());
102  }
103 
104  static const Self
105  min()
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
135  ZeroValue(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
itk::NumericTraits< FixedArray< T, D > >::min
static const Self min()
Definition: itkNumericTraitsFixedArrayPixel.h:105
itk::NumericTraits< FixedArray< T, D > >::One
static const Self ITKCommon_EXPORT One
Definition: itkNumericTraitsFixedArrayPixel.h:194
itk::NumericTraits< FixedArray< T, D > >::OneValue
static const Self OneValue(const Self &)
Definition: itkNumericTraitsFixedArrayPixel.h:141
itk::NumericTraits< FixedArray< T, D > >::ElementPrintType
typename NumericTraits< T >::PrintType ElementPrintType
Definition: itkNumericTraitsFixedArrayPixel.h:50
Self
AddImageFilter Self
Definition: itkAddImageFilter.h:89
itk::NumericTraits::NonpositiveMin
static constexpr T NonpositiveMin()
Definition: itkNumericTraits.h:98
itk::NumericTraits< FixedArray< T, D > >::max
static const Self max(const Self &)
Definition: itkNumericTraitsFixedArrayPixel.h:87
itk::NumericTraits< FixedArray< T, D > >::Zero
static const Self ITKCommon_EXPORT Zero
Definition: itkNumericTraitsFixedArrayPixel.h:193
itk::NumericTraits::AccumulateType
double AccumulateType
Definition: itkNumericTraits.h:75
itk::NumericTraits< FixedArray< T, D > >::min
static const Self min(const Self &)
Definition: itkNumericTraitsFixedArrayPixel.h:93
itk::NumericTraits< FixedArray< T, D > >::AssignToArray
static void AssignToArray(const Self &v, MeasurementVectorType &mv)
Definition: itkNumericTraitsFixedArrayPixel.h:175
itk::NumericTraits< FixedArray< T, D > >::ScalarRealType
ElementRealType ScalarRealType
Definition: itkNumericTraitsFixedArrayPixel.h:76
itk::NumericTraits< FixedArray< T, D > >::SetLength
static void SetLength(FixedArray< T, D > &m, const unsigned int s)
Definition: itkNumericTraitsFixedArrayPixel.h:150
itk::NumericTraits< FixedArray< T, D > >::ElementAbsType
typename NumericTraits< T >::AbsType ElementAbsType
Definition: itkNumericTraitsFixedArrayPixel.h:47
itk::NumericTraits< FixedArray< T, D > >::NonpositiveMin
static const Self NonpositiveMin(const Self &)
Definition: itkNumericTraitsFixedArrayPixel.h:129
itk::NumericTraits< FixedArray< T, D > >::NonpositiveMin
static const Self NonpositiveMin()
Definition: itkNumericTraitsFixedArrayPixel.h:111
itk::NumericTraits::OneValue
static T OneValue()
Definition: itkNumericTraits.h:157
itk::NumericTraits::PrintType
T PrintType
Definition: itkNumericTraits.h:69
itkFixedArray.h
itk::NumericTraits< FixedArray< T, D > >::max
static const Self max()
Definition: itkNumericTraitsFixedArrayPixel.h:99
itk::NumericTraits< FixedArray< T, D > >::ValueType
T ValueType
Definition: itkNumericTraitsFixedArrayPixel.h:55
itk::NumericTraits< FixedArray< T, D > >::ElementRealType
typename NumericTraits< T >::RealType ElementRealType
Definition: itkNumericTraitsFixedArrayPixel.h:51
itk::FixedArray
Simulate a standard C array with copy semantics.
Definition: itkFixedArray.h:53
itk::NumericTraits< FixedArray< T, D > >::AssignToArray
static void AssignToArray(const Self &v, TArray &mv)
Definition: itkNumericTraitsFixedArrayPixel.h:182
itk::NumericTraits
Define additional traits for native types such as int or float.
Definition: itkNumericTraits.h:59
itk::NumericTraits< FixedArray< T, D > >::ZeroValue
static const Self ZeroValue()
Definition: itkNumericTraitsFixedArrayPixel.h:117
itk::NumericTraits::ZeroValue
static T ZeroValue()
Definition: itkNumericTraits.h:149
itk::NumericTraits< FixedArray< T, D > >::OneValue
static const Self OneValue()
Definition: itkNumericTraitsFixedArrayPixel.h:123
itk::NumericTraits< FixedArray< T, D > >::ZeroValue
static const Self ZeroValue(const Self &)
Definition: itkNumericTraitsFixedArrayPixel.h:135
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::NumericTraits< FixedArray< T, D > >::ElementAccumulateType
typename NumericTraits< T >::AccumulateType ElementAccumulateType
Definition: itkNumericTraitsFixedArrayPixel.h:48
itkNumericTraits.h
itk::NumericTraits< FixedArray< T, D > >::GetLength
static unsigned int GetLength()
Definition: itkNumericTraitsFixedArrayPixel.h:169
itk::NumericTraits::RealType
double RealType
Definition: itkNumericTraits.h:85
AddImageFilter
Definition: itkAddImageFilter.h:81
itk::NumericTraits::FloatType
float FloatType
Definition: itkNumericTraits.h:82
itk::NumericTraits< FixedArray< T, D > >::ElementFloatType
typename NumericTraits< T >::FloatType ElementFloatType
Definition: itkNumericTraitsFixedArrayPixel.h:49
itk::NumericTraits< FixedArray< T, D > >::GetLength
static unsigned int GetLength(const FixedArray< T, D > &)
Definition: itkNumericTraitsFixedArrayPixel.h:162
itk::NumericTraits::AbsType
T AbsType
Definition: itkNumericTraits.h:72
itk::FixedArray::Fill
void Fill(const ValueType &)