ITK  5.4.0
Insight Toolkit
itkNumericTraitsVectorPixel.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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  * https://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 itkNumericTraitsVectorPixel_h
19 #define itkNumericTraitsVectorPixel_h
20 
21 #include "itkNumericTraits.h"
22 #include "itkVector.h"
23 
24 namespace itk
25 {
30 template <typename T, unsigned int D>
31 class NumericTraits<Vector<T, D>>
32 {
33 private:
39 
40 public:
42  using ValueType = T;
43  using Self = Vector<T, D>;
44 
47 
50 
54 
57 
60 
63 
66 
72  static const Self
73  max(const Self &)
74  {
75  return MakeFilled<Self>(NumericTraits<T>::max());
76  }
77 
78  static const Self
79  min(const Self &)
80  {
81  return MakeFilled<Self>(NumericTraits<T>::min());
82  }
83 
84  static const Self
85  max()
86  {
87  return MakeFilled<Self>(NumericTraits<T>::max());
88  }
89 
90  static const Self
91  min()
92  {
93  return MakeFilled<Self>(NumericTraits<T>::min());
94  }
95 
96  static const Self
98  {
99  return MakeFilled<Self>(NumericTraits<T>::NonpositiveMin());
100  }
101 
102  static const Self
104  {
105  return Self{};
106  }
107 
108  static const Self
110  {
111  return MakeFilled<Self>(NumericTraits<T>::OneValue());
112  }
113 
114  static const Self
116  {
117  return NonpositiveMin();
118  }
119 
120  static const Self
121  ZeroValue(const Self &)
122  {
123  return ZeroValue();
124  }
125 
126  static const Self
127  OneValue(const Self &)
128  {
129  return OneValue();
130  }
131 
132  static bool
133  IsPositive(const Self & a)
134  {
135  bool flag = false;
136  for (unsigned int i = 0; i < GetLength(a); ++i)
137  {
138  if (a[i] > ValueType{})
139  {
140  flag = true;
141  }
142  }
143  return flag;
144  }
145 
146  static bool
147  IsNonpositive(const Self & a)
148  {
149  bool flag = false;
150  for (unsigned int i = 0; i < GetLength(a); ++i)
151  {
152  if (!(a[i] > 0.0))
153  {
154  flag = true;
155  }
156  }
157  return flag;
158  }
159 
160  static bool
161  IsNegative(const Self & a)
162  {
163  bool flag = false;
164  for (unsigned int i = 0; i < GetLength(a); ++i)
165  {
166  if (a[i] < 0.0)
167  {
168  flag = true;
169  }
170  }
171  return flag;
172  }
173 
174  static bool
175  IsNonnegative(const Self & a)
176  {
177  bool flag = false;
178  for (unsigned int i = 0; i < GetLength(a); ++i)
179  {
180  if (!(a[i] < 0.0))
181  {
182  flag = true;
183  }
184  }
185  return flag;
186  }
187 
188  static constexpr bool IsSigned = std::is_signed_v<ValueType>;
189  static constexpr bool IsInteger = std::is_integral_v<ValueType>;
191 
195  static void
196  SetLength(Vector<T, D> & m, const unsigned int s)
197  {
198  if (s != D)
199  {
200  itkGenericExceptionMacro("Cannot set the size of a Vector of length " << D << " to " << s);
201  }
202  m.Fill(T{});
203  }
207  static unsigned int
209  {
210  return D;
211  }
212 
214  static unsigned int
216  {
217  return D;
218  }
219 
220  static void
222  {
223  mv = v;
224  }
225 
226  template <typename TArray>
227  static void
228  AssignToArray(const Self & v, TArray & mv)
229  {
230  for (unsigned int i = 0; i < D; ++i)
231  {
232  mv[i] = v[i];
233  }
234  }
235 
239  static const Self ITKCommon_EXPORT Zero;
240  static const Self ITKCommon_EXPORT One;
241 };
242 } // end namespace itk
243 
244 #endif // itkNumericTraitsVectorPixel_h
itk::NumericTraits< Vector< T, D > >::ElementPrintType
typename NumericTraits< T >::PrintType ElementPrintType
Definition: itkNumericTraitsVectorPixel.h:37
itk::NumericTraits< Vector< T, D > >::GetLength
static unsigned int GetLength(const Vector< T, D > &)
Definition: itkNumericTraitsVectorPixel.h:208
itk::NumericTraits< Vector< T, D > >::IsNonpositive
static bool IsNonpositive(const Self &a)
Definition: itkNumericTraitsVectorPixel.h:147
itk::NumericTraits< Vector< T, D > >::IsPositive
static bool IsPositive(const Self &a)
Definition: itkNumericTraitsVectorPixel.h:133
itk::NumericTraits< Vector< T, D > >::ValueType
T ValueType
Definition: itkNumericTraitsVectorPixel.h:42
itk::NumericTraits< Vector< T, D > >::ElementAbsType
typename NumericTraits< T >::AbsType ElementAbsType
Definition: itkNumericTraitsVectorPixel.h:34
itk::NumericTraits< Vector< T, D > >::AssignToArray
static void AssignToArray(const Self &v, MeasurementVectorType &mv)
Definition: itkNumericTraitsVectorPixel.h:221
itk::NumericTraits< Vector< T, D > >::max
static const Self max()
Definition: itkNumericTraitsVectorPixel.h:85
Self
AddImageFilter Self
Definition: itkAddImageFilter.h:89
itk::NumericTraits::NonpositiveMin
static constexpr T NonpositiveMin()
Definition: itkNumericTraits.h:98
itk::Vector
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
itk::NumericTraits< Vector< T, D > >::OneValue
static const Self OneValue()
Definition: itkNumericTraitsVectorPixel.h:109
itk::NumericTraits::AccumulateType
double AccumulateType
Definition: itkNumericTraits.h:75
itk::NumericTraits< Vector< T, D > >::ElementFloatType
typename NumericTraits< T >::FloatType ElementFloatType
Definition: itkNumericTraitsVectorPixel.h:36
itk::NumericTraits< Vector< T, D > >::min
static const Self min(const Self &)
Definition: itkNumericTraitsVectorPixel.h:79
itk::NumericTraits< Vector< T, D > >::OneValue
static const Self OneValue(const Self &)
Definition: itkNumericTraitsVectorPixel.h:127
itk::NumericTraits< Vector< T, D > >::ZeroValue
static const Self ZeroValue(const Self &)
Definition: itkNumericTraitsVectorPixel.h:121
itk::NumericTraits::IsSigned
static constexpr bool IsSigned
Definition: itkNumericTraits.h:134
itk::NumericTraits< Vector< T, D > >::max
static const Self max(const Self &)
Definition: itkNumericTraitsVectorPixel.h:73
itk::NumericTraits< Vector< T, D > >::Zero
static const Self ITKCommon_EXPORT Zero
Definition: itkNumericTraitsVectorPixel.h:239
itk::NumericTraits::IsInteger
static constexpr bool IsInteger
Definition: itkNumericTraits.h:139
itk::NumericTraits::OneValue
static T OneValue()
Definition: itkNumericTraits.h:157
itk::NumericTraits::PrintType
T PrintType
Definition: itkNumericTraits.h:69
itk::NumericTraits< Vector< T, D > >::NonpositiveMin
static const Self NonpositiveMin()
Definition: itkNumericTraitsVectorPixel.h:97
itk::NumericTraits< Vector< T, D > >::ZeroValue
static const Self ZeroValue()
Definition: itkNumericTraitsVectorPixel.h:103
itk::NumericTraits< Vector< T, D > >::GetLength
static unsigned int GetLength()
Definition: itkNumericTraitsVectorPixel.h:215
itk::NumericTraits< Vector< T, D > >::min
static const Self min()
Definition: itkNumericTraitsVectorPixel.h:91
itk::NumericTraits
Define additional traits for native types such as int or float.
Definition: itkNumericTraits.h:59
itk::NumericTraits< Vector< T, D > >::NonpositiveMin
static const Self NonpositiveMin(const Self &)
Definition: itkNumericTraitsVectorPixel.h:115
itk::NumericTraits< Vector< T, D > >::IsNegative
static bool IsNegative(const Self &a)
Definition: itkNumericTraitsVectorPixel.h:161
itk::NumericTraits::ZeroValue
static T ZeroValue()
Definition: itkNumericTraits.h:149
itk::NumericTraits< Vector< T, D > >::ElementAccumulateType
typename NumericTraits< T >::AccumulateType ElementAccumulateType
Definition: itkNumericTraitsVectorPixel.h:35
itk::NumericTraits< Vector< T, D > >::One
static const Self ITKCommon_EXPORT One
Definition: itkNumericTraitsVectorPixel.h:240
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::NumericTraits::GetLength
static unsigned int GetLength()
Definition: itkNumericTraits.h:209
itk::NumericTraits< Vector< T, D > >::ElementRealType
typename NumericTraits< T >::RealType ElementRealType
Definition: itkNumericTraitsVectorPixel.h:38
itk::NumericTraits::IsComplex
static constexpr bool IsComplex
Definition: itkNumericTraits.h:144
itkVector.h
itkNumericTraits.h
itk::NumericTraits::RealType
double RealType
Definition: itkNumericTraits.h:85
AddImageFilter
Definition: itkAddImageFilter.h:81
itk::NumericTraits::FloatType
float FloatType
Definition: itkNumericTraits.h:82
itk::NumericTraits< Vector< T, D > >::ScalarRealType
ElementRealType ScalarRealType
Definition: itkNumericTraitsVectorPixel.h:62
itk::NumericTraits::AbsType
T AbsType
Definition: itkNumericTraits.h:72
itk::NumericTraits< Vector< T, D > >::AssignToArray
static void AssignToArray(const Self &v, TArray &mv)
Definition: itkNumericTraitsVectorPixel.h:228
itk::FixedArray< T, VVectorDimension >::Fill
void Fill(const ValueType &)
itk::NumericTraits< Vector< T, D > >::SetLength
static void SetLength(Vector< T, D > &m, const unsigned int s)
Definition: itkNumericTraitsVectorPixel.h:196
itk::NumericTraits< Vector< T, D > >::IsNonnegative
static bool IsNonnegative(const Self &a)
Definition: itkNumericTraitsVectorPixel.h:175