ITK  6.0.0
Insight Toolkit
itkNumericTraitsVariableLengthVectorPixel.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 itkNumericTraitsVariableLengthVectorPixel_h
19 #define itkNumericTraitsVariableLengthVectorPixel_h
20 
22 
23 // This work is part of the National Alliance for Medical Image Computing
24 // (NAMIC), funded by the National Institutes of Health through the NIH Roadmap
25 // for Medical Research, Grant U54 EB005149.
26 
27 namespace itk
28 {
53 template <typename T>
55 {
56 public:
62 
64  using ValueType = T;
65 
67 
70 
73 
77 
80 
83 
86 
89 
95  static const Self
96  max(const Self & a)
97  {
98  Self b(a.Size());
99 
101  return b;
102  }
103 
104  static const Self
105  min(const Self & a)
106  {
107  Self b(a.Size());
108 
110  return b;
111  }
112 
113  static const Self
114  ZeroValue(const Self & a)
115  {
116  Self b(a.Size());
117 
118  b.Fill(T{});
119  return b;
120  }
121 
122  static const Self
123  OneValue(const Self & a)
124  {
125  Self b(a.Size());
126 
128  return b;
129  }
130 
131  static const Self
132  NonpositiveMin(const Self & a)
133  {
134  Self b(a.Size());
136  return b;
137  }
138 
139  static bool
140  IsPositive(const Self & a)
141  {
142  bool flag = false;
143  for (unsigned int i = 0; i < GetLength(a); ++i)
144  {
145  if (a[i] > ValueType{})
146  {
147  flag = true;
148  }
149  }
150  return flag;
151  }
152 
153  static bool
154  IsNonpositive(const Self & a)
155  {
156  bool flag = false;
157  for (unsigned int i = 0; i < GetLength(a); ++i)
158  {
159  if (!(a[i] > 0.0))
160  {
161  flag = true;
162  }
163  }
164  return flag;
165  }
166 
167  static bool
168  IsNegative(const Self & a)
169  {
170  bool flag = false;
171  for (unsigned int i = 0; i < GetLength(a); ++i)
172  {
173  if (a[i] < ValueType{})
174  {
175  flag = true;
176  }
177  }
178  return flag;
179  }
180 
181  static bool
182  IsNonnegative(const Self & a)
183  {
184  bool flag = false;
185  for (unsigned int i = 0; i < GetLength(a); ++i)
186  {
187  if (!(a[i] < 0.0))
188  {
189  flag = true;
190  }
191  }
192  return flag;
193  }
194 
195  static constexpr bool IsSigned = std::is_signed_v<ValueType>;
196  static constexpr bool IsInteger = std::is_integral_v<ValueType>;
198 
199 
201  static void
202  SetLength(VariableLengthVector<T> & m, const unsigned int s)
203  {
204  m.SetSize(s);
205  m.Fill(T{});
206  }
210  static unsigned int
212  {
213  return m.GetSize();
214  }
215 
216  static void
218  {
219  mv = v;
220  }
221 
222  template <typename TArray>
223  static void
224  AssignToArray(const Self & v, TArray & mv)
225  {
226  for (unsigned int i = 0; i < GetLength(v); ++i)
227  {
228  mv[i] = v[i];
229  }
230  }
231 };
232 } // end namespace itk
233 
234 #endif // itkNumericTraitsVariableLengthVector_h
itk::NumericTraits< VariableLengthVector< T > >::ElementAbsType
typename NumericTraits< T >::AbsType ElementAbsType
Definition: itkNumericTraitsVariableLengthVectorPixel.h:57
itk::NumericTraits< VariableLengthVector< T > >::IsNegative
static bool IsNegative(const Self &a)
Definition: itkNumericTraitsVariableLengthVectorPixel.h:168
itk::NumericTraits< VariableLengthVector< T > >::ElementFloatType
typename NumericTraits< T >::FloatType ElementFloatType
Definition: itkNumericTraitsVariableLengthVectorPixel.h:59
Self
AddImageFilter Self
Definition: itkAddImageFilter.h:89
itkVariableLengthVector.h
itk::VariableLengthVector::SetSize
void SetSize(unsigned int sz, TReallocatePolicy reallocatePolicy, TKeepValuesPolicy keepValues)
itk::VariableLengthVector::GetSize
unsigned int GetSize() const
Definition: itkVariableLengthVector.h:592
itk::NumericTraits::AccumulateType
double AccumulateType
Definition: itkNumericTraits.h:76
itk::NumericTraits< VariableLengthVector< T > >::OneValue
static const Self OneValue(const Self &a)
Definition: itkNumericTraitsVariableLengthVectorPixel.h:123
itk::NumericTraits< VariableLengthVector< T > >::ZeroValue
static const Self ZeroValue(const Self &a)
Definition: itkNumericTraitsVariableLengthVectorPixel.h:114
itk::NumericTraits< VariableLengthVector< T > >::IsNonnegative
static bool IsNonnegative(const Self &a)
Definition: itkNumericTraitsVariableLengthVectorPixel.h:182
itk::NumericTraits::IsSigned
static constexpr bool IsSigned
Definition: itkNumericTraits.h:135
itk::NumericTraits< VariableLengthVector< T > >::GetLength
static unsigned int GetLength(const VariableLengthVector< T > &m)
Definition: itkNumericTraitsVariableLengthVectorPixel.h:211
itk::NumericTraits::IsInteger
static constexpr bool IsInteger
Definition: itkNumericTraits.h:140
itk::NumericTraits::PrintType
T PrintType
Definition: itkNumericTraits.h:70
itk::VariableLengthVector::Size
unsigned int Size() const
Definition: itkVariableLengthVector.h:587
itk::VariableLengthVector
Represents an array whose length can be defined at run-time.
Definition: itkConstantBoundaryCondition.h:28
itk::NumericTraits< VariableLengthVector< T > >::min
static const Self min(const Self &a)
Definition: itkNumericTraitsVariableLengthVectorPixel.h:105
itk::NumericTraits
Define additional traits for native types such as int or float.
Definition: itkNumericTraits.h:60
itk::NumericTraits< VariableLengthVector< T > >::SetLength
static void SetLength(VariableLengthVector< T > &m, const unsigned int s)
Definition: itkNumericTraitsVariableLengthVectorPixel.h:202
itk::NumericTraits< VariableLengthVector< T > >::ValueType
T ValueType
Definition: itkNumericTraitsVariableLengthVectorPixel.h:64
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::NumericTraits::GetLength
static unsigned int GetLength()
Definition: itkNumericTraits.h:210
itk::NumericTraits::IsComplex
static constexpr bool IsComplex
Definition: itkNumericTraits.h:145
itk::NumericTraits< VariableLengthVector< T > >::ElementRealType
typename NumericTraits< T >::RealType ElementRealType
Definition: itkNumericTraitsVariableLengthVectorPixel.h:61
itk::NumericTraits< VariableLengthVector< T > >::AssignToArray
static void AssignToArray(const Self &v, TArray &mv)
Definition: itkNumericTraitsVariableLengthVectorPixel.h:224
itk::NumericTraits< VariableLengthVector< T > >::ScalarRealType
ElementRealType ScalarRealType
Definition: itkNumericTraitsVariableLengthVectorPixel.h:85
itk::VariableLengthVector::Fill
void Fill(const TValue &v)
itk::NumericTraits::RealType
double RealType
Definition: itkNumericTraits.h:86
itk::NumericTraits< VariableLengthVector< T > >::NonpositiveMin
static const Self NonpositiveMin(const Self &a)
Definition: itkNumericTraitsVariableLengthVectorPixel.h:132
AddImageFilter
Definition: itkAddImageFilter.h:81
itk::NumericTraits::FloatType
float FloatType
Definition: itkNumericTraits.h:83
itk::NumericTraits< VariableLengthVector< T > >::AssignToArray
static void AssignToArray(const Self &v, MeasurementVectorType &mv)
Definition: itkNumericTraitsVariableLengthVectorPixel.h:217
itk::NumericTraits< VariableLengthVector< T > >::max
static const Self max(const Self &a)
Definition: itkNumericTraitsVariableLengthVectorPixel.h:96
itk::NumericTraits< VariableLengthVector< T > >::ElementPrintType
typename NumericTraits< T >::PrintType ElementPrintType
Definition: itkNumericTraitsVariableLengthVectorPixel.h:60
itk::NumericTraits::AbsType
T AbsType
Definition: itkNumericTraits.h:73
itk::NumericTraits< VariableLengthVector< T > >::IsPositive
static bool IsPositive(const Self &a)
Definition: itkNumericTraitsVariableLengthVectorPixel.h:140
itk::NumericTraits< VariableLengthVector< T > >::ElementAccumulateType
typename NumericTraits< T >::AccumulateType ElementAccumulateType
Definition: itkNumericTraitsVariableLengthVectorPixel.h:58
itk::NumericTraits< VariableLengthVector< T > >::IsNonpositive
static bool IsNonpositive(const Self &a)
Definition: itkNumericTraitsVariableLengthVectorPixel.h:154