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 { 26 /** \brief NumericTraits for Array 27 * \tparam T type of the array component 28 */ 29 template< typename T > 30 class NumericTraits< Array< T > > 31 { 32 private: 33 34 using ElementAbsType = typename NumericTraits< T >::AbsType; 35 using ElementAccumulateType = typename NumericTraits< T >::AccumulateType; 36 using ElementFloatType = typename NumericTraits< T >::FloatType; 37 using ElementPrintType = typename NumericTraits< T >::PrintType; 38 using ElementRealType = typename NumericTraits< T >::RealType; 39 40 public: 41 42 /** Return the type of the native component type. */ 43 using ValueType = T; 44 using Self = Array< T >; 45 46 /** Unsigned component type */ 47 using AbsType = Array< ElementAbsType >; 48 49 /** Accumulation of addition and multiplication. */ 50 using AccumulateType = Array< ElementAccumulateType >; 51 52 /** Typedef for operations that use floating point instead of real precision 53 */ 54 using FloatType = Array< ElementFloatType >; 55 56 /** Return the type that can be printed. */ 57 using PrintType = Array< ElementPrintType >; 58 59 /** Type for real-valued scalar operations. */ 60 using RealType = Array< ElementRealType >; 61 62 /** Type for real-valued scalar operations. */ 63 using ScalarRealType = ElementRealType; 64 65 /** Measurement vector type */ 66 using MeasurementVectorType = Self; 67 68 /** Component wise defined element 69 * 70 * \note minimum value for floating pointer types is defined as 71 * minimum positive normalize value. 72 */ max(const Self & a)73 static const Self max(const Self & a) 74 { 75 Self b( a.Size() ); 76 77 b.Fill( NumericTraits< T >::max() ); 78 return b; 79 } 80 min(const Self & a)81 static const Self min(const Self & a) 82 { 83 Self b( a.Size() ); 84 85 b.Fill( NumericTraits< T >::min() ); 86 return b; 87 } 88 ZeroValue(const Self & a)89 static const Self ZeroValue(const Self & a) 90 { 91 Self b( a.Size() ); 92 93 b.Fill(NumericTraits< T >::ZeroValue()); 94 return b; 95 } 96 OneValue(const Self & a)97 static const Self OneValue(const Self & a) 98 { 99 Self b( a.Size() ); 100 101 b.Fill(NumericTraits< T >::OneValue()); 102 return b; 103 } 104 NonpositiveMin(const Self & a)105 static const Self NonpositiveMin(const Self & a) 106 { 107 Self b( a.Size() ); 108 b.Fill( NumericTraits< T >::NonpositiveMin() ); 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 116 /** Set the length of the input array and fill it with zeros. */ SetLength(Array<T> & m,const unsigned int s)117 static void SetLength(Array< T > & m, const unsigned int s) 118 { 119 m.SetSize(s); 120 m.Fill(NumericTraits< T >::ZeroValue()); 121 } 122 123 /** Get the length of the input array. */ GetLength(const Array<T> & m)124 static unsigned int GetLength(const Array< T > & m) 125 { 126 return m.GetSize(); 127 } 128 AssignToArray(const Self & v,MeasurementVectorType & mv)129 static void AssignToArray( const Self & v, MeasurementVectorType & mv ) 130 { 131 mv = v; 132 } 133 134 template<typename TArray> AssignToArray(const Self & v,TArray & mv)135 static void AssignToArray( const Self & v, TArray & mv ) 136 { 137 for( unsigned int i=0; i<GetLength(v); i++ ) 138 { 139 mv[i] = v[i]; 140 } 141 } 142 143 }; 144 } // end namespace itk 145 146 #endif // itkNumericTraitsArrayPixel_h 147