ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkNumericTraitsArrayPixel.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 itkNumericTraitsArrayPixel_h
19 #define itkNumericTraitsArrayPixel_h
20 
21 #include "itkNumericTraits.h"
22 #include "itkArray.h"
23 
24 namespace itk
25 {
29 template< typename T >
30 class NumericTraits< Array< T > >
31 {
32 private:
33 
39 
40 public:
41 
43  typedef T ValueType;
44  typedef Array< T > Self;
45 
48 
51 
55 
58 
61 
64 
67 
73  static const Self max(const Self & a)
74  {
75  Self b( a.Size() );
76 
78  return b;
79  }
80 
81  static const Self min(const Self & a)
82  {
83  Self b( a.Size() );
84 
86  return b;
87  }
88 
89  static const Self ZeroValue(const Self & a)
90  {
91  Self b( a.Size() );
92 
94  return b;
95  }
96 
97  static const Self OneValue(const Self & a)
98  {
99  Self b( a.Size() );
100 
102  return b;
103  }
104 
105  static const Self NonpositiveMin(const Self & a)
106  {
107  Self b( a.Size() );
109  return b;
110  }
111 
112  static ITK_CONSTEXPR_VAR bool IsSigned = NumericTraits< ValueType >::IsSigned;
113  static ITK_CONSTEXPR_VAR bool IsInteger = NumericTraits< ValueType >::IsInteger;
114  static ITK_CONSTEXPR_VAR bool IsComplex = NumericTraits< ValueType >::IsComplex;
115 
117  static void SetLength(Array< T > & m, const unsigned int s)
118  {
119  m.SetSize(s);
121  }
123 
125  static unsigned int GetLength(const Array< T > & m)
126  {
127  return m.GetSize();
128  }
129 
130  static void AssignToArray( const Self & v, MeasurementVectorType & mv )
131  {
132  mv = v;
133  }
134 
135  template<typename TArray>
136  static void AssignToArray( const Self & v, TArray & mv )
137  {
138  for( unsigned int i=0; i<GetLength(v); i++ )
139  {
140  mv[i] = v[i];
141  }
142  }
143 
144 #if !defined(ITK_LEGACY_REMOVE)
145  //The extra #ifdef is need because the itkLegacyMacro
146  //can not format a static const member function properly
147  //in the case of removing the code.
148 
150  itkLegacyMacro(static const Self Zero(const Self & a))
151  {
152  Self b( a.Size() );
154  return b;
155  }
157 
159  itkLegacyMacro(static const Self One(const Self & a))
160  {
161  Self b( a.Size() );
162  b.Fill(NumericTraits< T >::OneValue());
163  return b;
164  }
165 #endif
166 
167 
168 };
169 } // end namespace itk
170 
171 #endif // itkNumericTraitsArrayPixel_h
static const Self OneValue(const Self &a)
Array class with size defined at construction time.
Definition: itkArray.h:50
Array< ElementAccumulateType > AccumulateType
static ITK_CONSTEXPR_VAR bool IsComplex
NumericTraits< T >::AccumulateType ElementAccumulateType
NumericTraits< T >::RealType ElementRealType
static void SetLength(Array< T > &m, const unsigned int s)
static ITK_CONSTEXPR_VAR bool IsInteger
static const Self ZeroValue(const Self &a)
static const Self min(const Self &a)
static const Self max(const Self &a)
void Fill(TValue const &v)
Definition: itkArray.h:113
static const T Zero
void SetSize(SizeValueType sz)
static const Self NonpositiveMin(const Self &a)
static unsigned int GetLength()
static void AssignToArray(const Self &v, MeasurementVectorType &mv)
SizeValueType GetSize(void) const
Definition: itkArray.h:141
static void AssignToArray(const Self &v, TArray &mv)
static ITK_CONSTEXPR_VAR bool IsSigned
static const T One
NumericTraits< T >::FloatType ElementFloatType
SizeValueType Size(void) const
Definition: itkArray.h:124
NumericTraits< T >::PrintType ElementPrintType
Define additional traits for native types such as int or float.
NumericTraits< T >::AbsType ElementAbsType
static unsigned int GetLength(const Array< T > &m)