ITK  5.0.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  using ValueType = T;
44  using Self = Array< T >;
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 constexpr bool IsSigned = NumericTraits< ValueType >::IsSigned;
113  static constexpr bool IsInteger = NumericTraits< ValueType >::IsInteger;
114  static constexpr 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 };
145 } // end namespace itk
146 
147 #endif // itkNumericTraitsArrayPixel_h
static const Self OneValue(const Self &a)
Array class with size defined at construction time.
Definition: itkArray.h:46
Define numeric traits for std::vector.
typename NumericTraits< T >::AbsType ElementAbsType
typename NumericTraits< T >::PrintType ElementPrintType
typename NumericTraits< T >::FloatType ElementFloatType
static void SetLength(Array< T > &m, const unsigned int s)
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:109
typename NumericTraits< T >::AccumulateType ElementAccumulateType
void SetSize(SizeValueType sz)
static const Self NonpositiveMin(const Self &a)
SizeValueType Size() const
Definition: itkArray.h:120
static void AssignToArray(const Self &v, MeasurementVectorType &mv)
static void AssignToArray(const Self &v, TArray &mv)
typename NumericTraits< T >::RealType ElementRealType
SizeValueType GetSize() const
Definition: itkArray.h:137
static unsigned int GetLength(const Array< T > &m)