ITK  6.0.0
Insight Toolkit
itkNumericTraitsStdVector.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
19#ifndef itkNumericTraitsStdVector_h
20#define itkNumericTraitsStdVector_h
21
22#include "itkMath.h"
23#include <vector>
24
25// This work is part of the National Alliance for Medical Image Computing
26// (NAMIC), funded by the National Institutes of Health through the NIH Roadmap
27// for Medical Research, Grant U54 EB005149.
28
29namespace itk
30{
55template <typename T>
56class NumericTraits<std::vector<T>>
57{
58public:
64
66 using ValueType = T;
67
68 using Self = std::vector<T>;
69
71 using AbsType = std::vector<ElementAbsType>;
72
74 using AccumulateType = std::vector<ElementAccumulateType>;
75
78 using FloatType = std::vector<ElementFloatType>;
79
80 // TODO: this won't really print well, at least not without defining an operator
81 // to push to a stream.
83 using PrintType = std::vector<ElementPrintType>;
84
86 using RealType = std::vector<ElementRealType>;
87
90
93
99 static const Self
100 max(const Self & a)
101 {
102 Self b(a.Size(), NumericTraits<T>::max());
103 return b;
104 }
107 static const Self
108 min(const Self & a)
109 {
110 Self b(a.Size(), NumericTraits<T>::min());
111 return b;
112 }
113
114 static const Self
115 ZeroValue(const Self & a)
116 {
117 Self b(a.Size(), T{});
118 return b;
119 }
120
121 static const Self
122 OneValue(const Self & a)
123 {
124 Self b(a.Size(), NumericTraits<T>::OneValue());
125 return b;
126 }
127
128 static const Self
130 {
132 return b;
133 }
134
135 static constexpr bool IsSigned = std::is_signed_v<ValueType>;
136 static constexpr bool IsInteger = std::is_integral_v<ValueType>;
138
140 static void
141 SetLength(std::vector<T> & m, const unsigned int s)
142 {
143 // since std::vector often holds types that have no NumericTraits::ZeroValue(),
144 // allow resize() to call the type's default constructor
145 m.clear();
146 m.resize(s);
147 }
151 static unsigned int
152 GetLength(const std::vector<T> & m)
153 {
154 return itk::Math::CastWithRangeCheck<unsigned int>(m.size());
155 }
156
157 static void
159 {
160 mv = v;
161 }
162
163 template <typename TArray>
164 static void
165 AssignToArray(const Self & v, TArray & mv)
166 {
167 for (unsigned int i = 0; i < GetLength(v); ++i)
168 {
169 mv[i] = v[i];
170 }
171 }
172};
173} // end namespace itk
174
175#endif // itkNumericTraitsStdVector_h
Pixel-wise addition of two images.
static void AssignToArray(const Self &v, TArray &mv)
std::vector< ElementPrintType > PrintType
static void AssignToArray(const Self &v, MeasurementVectorType &mv)
std::vector< ElementAccumulateType > AccumulateType
static const Self ZeroValue(const Self &a)
static const Self NonpositiveMin(const Self &a)
typename NumericTraits< T >::RealType ElementRealType
typename NumericTraits< T >::AbsType ElementAbsType
static unsigned int GetLength(const std::vector< T > &m)
std::vector< ElementFloatType > FloatType
typename NumericTraits< T >::PrintType ElementPrintType
static const Self OneValue(const Self &a)
typename NumericTraits< T >::AccumulateType ElementAccumulateType
typename NumericTraits< T >::FloatType ElementFloatType
static void SetLength(std::vector< T > &m, const unsigned int s)
Define additional traits for native types such as int or float.
static constexpr bool IsInteger
static constexpr bool IsSigned
static unsigned int GetLength()
static constexpr bool IsComplex
AddImageFilter Self
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
STL namespace.