ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkNumericTraitsFixedArrayPixel.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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  * http://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 >
44 class NumericTraits< FixedArray< T, D > >
45 {
46 private:
47 
53 
54 public:
55 
57  using ValueType = T;
58 
60 
63 
66 
70 
73 
76 
79 
82 
88  static const Self max(const Self &)
89  {
90  return Self( NumericTraits< T >::max() );
91  }
92 
93  static const Self min(const Self &)
94  {
95  return Self( NumericTraits< T >::min() );
96  }
97 
98  static const Self max()
99  {
100  return Self( NumericTraits< T >::max() );
101  }
102 
103  static const Self min()
104  {
105  return Self( NumericTraits< T >::min() );
106  }
107 
108  static const Self NonpositiveMin()
109  {
111  }
112 
113  static const Self ZeroValue()
114  {
116  }
117 
118  static const Self OneValue()
119  {
121  }
122 
123  static const Self NonpositiveMin(const Self &)
124  {
125  return NonpositiveMin();
126  }
127 
128  static const Self ZeroValue(const Self &)
129  {
130  return ZeroValue();
131  }
132 
133  static const Self OneValue(const Self &)
134  {
135  return OneValue();
136  }
137 
141  static void SetLength(FixedArray< T, D > & m, const unsigned int s)
142  {
143  if ( s != D )
144  {
145  itkGenericExceptionMacro(<< "Cannot set the size of a FixedArray of length "
146  << D << " to " << s);
147  }
149  }
151 
153  static unsigned int GetLength(const FixedArray< T, D > &)
154  {
155  return D;
156  }
157 
159  static unsigned int GetLength()
160  {
161  return D;
162  }
163 
164  static void AssignToArray( const Self & v, MeasurementVectorType & mv )
165  {
166  mv = v;
167  }
168 
169  template<typename TArray>
170  static void AssignToArray( const Self & v, TArray & mv )
171  {
172  for( unsigned int i=0; i<D; i++ )
173  {
174  mv[i] = v[i];
175  }
176  }
177 
181  static const Self ITKCommon_EXPORT Zero;
182  static const Self ITKCommon_EXPORT One;
183 };
184 
185 // a macro to define and initialize static member variables,
186 // NOTE: (T)(NumericTraits< T >::[Zero|One]) is needed to generate
187 // a temporary variable that is initialized from the
188 // constexpr [Zero|One] to be passed by const reference
189 // to the GENERIC_ARRAY<T,D> constructor.
190 #define itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, D) \
191  template< > \
192  ITKCommon_EXPORT const GENERIC_ARRAY< T, D > NumericTraits< GENERIC_ARRAY< T, D > >::Zero = \
193  GENERIC_ARRAY< T, D >( (T)(NumericTraits< T >::Zero) ); \
194  template< > \
195  ITKCommon_EXPORT const GENERIC_ARRAY< T, D > NumericTraits< GENERIC_ARRAY< T, D > >::One = \
196  GENERIC_ARRAY< T, D >( (T)(NumericTraits< T >::One) );
197 
198 //
199 // List here the array dimension specializations of these static
200 // Traits:
201 //
202 #define itkStaticNumericTraitsGenericArrayDimensionsMacro(GENERIC_ARRAY, T) \
203  itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 1); \
204  itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 2); \
205  itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 3); \
206  itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 4); \
207  itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 5); \
208  itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 6); \
209  itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 7); \
210  itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 8); \
211  itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 9); \
212  itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 10);
213 } // end namespace itk
214 
215 #endif // itkNumericTraitsFixedArrayPixel_h
static void AssignToArray(const Self &v, MeasurementVectorType &mv)
Define numeric traits for std::vector.
static unsigned int GetLength(const FixedArray< T, D > &)
static void AssignToArray(const Self &v, TArray &mv)
typename NumericTraits< T >::AbsType ElementAbsType
void Fill(const ValueType &)
Simulate a standard C array with copy semnatics.
Definition: itkFixedArray.h:51
typename NumericTraits< T >::AccumulateType ElementAccumulateType
typename NumericTraits< T >::PrintType ElementPrintType
typename NumericTraits< T >::RealType ElementRealType
typename NumericTraits< T >::FloatType ElementFloatType
static void SetLength(FixedArray< T, D > &m, const unsigned int s)