ITK  4.2.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 public:
54 
56  typedef T ValueType;
57 
59 
62 
65 
69 
72 
75 
78 
81 
87  static const Self max(const Self &)
88  {
89  return Self( NumericTraits< T >::max() );
90  }
91 
92  static const Self min(const Self &)
93  {
94  return Self( NumericTraits< T >::min() );
95  }
96 
97  static const Self max()
98  {
99  return Self( NumericTraits< T >::max() );
100  }
101 
102  static const Self min()
103  {
104  return Self( NumericTraits< T >::min() );
105  }
106 
107  static const Self NonpositiveMin()
108  {
110  }
111 
112  static const Self ZeroValue()
113  {
115  }
116 
117  static const Self OneValue()
118  {
120  }
121 
122  static const Self NonpositiveMin(const Self &)
123  {
124  return NonpositiveMin();
125  }
126 
127  static const Self ZeroValue(const Self &)
128  {
129  return ZeroValue();
130  }
131 
132  static const Self OneValue(const Self &)
133  {
134  return OneValue();
135  }
136 
140  static void SetLength(FixedArray< T, D > & m, const unsigned int s)
141  {
142  if ( s != D )
143  {
144  itkGenericExceptionMacro(<< "Cannot set the size of a FixedArray of length "
145  << D << " to " << s);
146  }
148  }
150 
152  static unsigned int GetLength(const FixedArray< T, D > &)
153  {
154  return D;
155  }
156 
158  static unsigned int GetLength()
159  {
160  return D;
161  }
162 
163  static void AssignToArray( const Self & v, MeasurementVectorType & mv )
164  {
165  mv = v;
166  }
167 
168  template<class TArray>
169  static void AssignToArray( const Self & v, TArray & mv )
170  {
171  for( unsigned int i=0; i<D; i++ )
172  {
173  mv[i] = v[i];
174  }
175  }
176 
180  static const Self ITKCommon_EXPORT Zero;
181  static const Self ITKCommon_EXPORT One;
182 };
183 
184 // a macro to define and initialize static member variables
185 #define itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, D) \
186  template< > \
187  const GENERIC_ARRAY< T, D > NumericTraits< GENERIC_ARRAY< T, D > >::Zero = GENERIC_ARRAY< T, D >( \
188  NumericTraits< T >::Zero); \
189  template< > \
190  const GENERIC_ARRAY< T, D > NumericTraits< GENERIC_ARRAY< T, D > >::One = GENERIC_ARRAY< T, D >( \
191  NumericTraits< T >::One);
192 
193 //
194 // List here the array dimension specializations of these static
195 // Traits:
196 //
197 #define itkStaticNumericTraitsGenericArrayDimensionsMacro(GENERIC_ARRAY, T) \
198  itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 1); \
199  itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 2); \
200  itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 3); \
201  itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 4); \
202  itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 5); \
203  itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 6); \
204  itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 7); \
205  itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 8); \
206  itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 9); \
207  itkStaticNumericTraitsGenericArrayMacro(GENERIC_ARRAY, T, 10);
208 } // end namespace itk
209 
210 #endif // __itkNumericTraitsFixedArrayPixel_h
211