ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkNumericTraitsVectorPixel.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 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:
34 
40 
41 public:
42 
44  using ValueType = T;
46 
49 
52 
56 
59 
62 
65 
68 
74  static const Self max(const Self &)
75  {
76  return Self( NumericTraits< T >::max() );
77  }
78 
79  static const Self min(const Self &)
80  {
81  return Self( NumericTraits< T >::min() );
82  }
83 
84  static const Self max()
85  {
86  return Self( NumericTraits< T >::max() );
87  }
88 
89  static const Self min()
90  {
91  return Self( NumericTraits< T >::min() );
92  }
93 
94  static const Self NonpositiveMin()
95  {
97  }
98 
99  static const Self ZeroValue()
100  {
102  }
103 
104  static const Self OneValue()
105  {
107  }
108 
109  static const Self NonpositiveMin(const Self &)
110  {
111  return NonpositiveMin();
112  }
113 
114  static const Self ZeroValue(const Self &)
115  {
116  return ZeroValue();
117  }
118 
119  static const Self OneValue(const Self &)
120  {
121  return OneValue();
122  }
123 
124  static bool IsPositive( const Self & a)
125  {
126  bool flag = false;
127  for (unsigned int i=0; i < GetLength( a ); i++)
128  {
130  {
131  flag = true;
132  }
133  }
134  return flag;
135  }
136 
137  static bool IsNonpositive( const Self & a)
138  {
139  bool flag = false;
140  for (unsigned int i=0; i < GetLength( a ); i++)
141  {
142  if ( ! (a[i] > 0.0 ) )
143  {
144  flag = true;
145  }
146  }
147  return flag;
148  }
149 
150  static bool IsNegative( const Self & a)
151  {
152  bool flag = false;
153  for (unsigned int i=0; i < GetLength( a ); i++)
154  {
155  if ( a[i] < 0.0 )
156  {
157  flag = true;
158  }
159  }
160  return flag;
161  }
162 
163  static bool IsNonnegative( const Self & a)
164  {
165  bool flag = false;
166  for (unsigned int i=0; i < GetLength( a ); i++)
167  {
168  if ( ! (a[i] < 0.0 ))
169  {
170  flag = true;
171  }
172  }
173  return flag;
174  }
175 
176  static constexpr bool IsSigned = NumericTraits< ValueType >::IsSigned;
177  static constexpr bool IsInteger = NumericTraits< ValueType >::IsInteger;
178  static constexpr bool IsComplex = NumericTraits< ValueType >::IsComplex;
179 
183  static void SetLength(Vector< T, D > & m, const unsigned int s)
184  {
185  if ( s != D )
186  {
187  itkGenericExceptionMacro(<< "Cannot set the size of a Vector of length "
188  << D << " to " << s);
189  }
191  }
193 
195  static unsigned int GetLength(const Vector< T, D > &)
196  {
197  return D;
198  }
199 
201  static unsigned int GetLength()
202  {
203  return D;
204  }
205 
206  static void AssignToArray( const Self & v, MeasurementVectorType & mv )
207  {
208  mv = v;
209  }
210 
211  template<typename TArray>
212  static void AssignToArray( const Self & v, TArray & mv )
213  {
214  for( unsigned int i=0; i<D; i++ )
215  {
216  mv[i] = v[i];
217  }
218  }
219 
223  static const Self ITKCommon_EXPORT Zero;
224  static const Self ITKCommon_EXPORT One;
225 };
226 } // end namespace itk
227 
228 #endif // itkNumericTraitsVectorPixel_h
static void AssignToArray(const Self &v, MeasurementVectorType &mv)
typename NumericTraits< T >::AbsType ElementAbsType
Define numeric traits for std::vector.
static const Self ITKCommon_EXPORT One
static const Self NonpositiveMin(const Self &)
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
typename NumericTraits< T >::PrintType ElementPrintType
static const Self ITKCommon_EXPORT Zero
typename NumericTraits< T >::FloatType ElementFloatType
typename NumericTraits< T >::AccumulateType ElementAccumulateType
static void SetLength(Vector< T, D > &m, const unsigned int s)
static void AssignToArray(const Self &v, TArray &mv)
typename NumericTraits< T >::RealType ElementRealType
static unsigned int GetLength(const Vector< T, D > &)