ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkNumericTraitsVariableLengthVectorPixel.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 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:
57 
63 
65  typedef T ValueType;
66 
68 
71 
74 
78 
81 
84 
87 
90 
96  static const Self max(const Self & a)
97  {
98  Self b( a.Size() );
99 
101  return b;
102  }
103 
104  static const Self min(const Self & a)
105  {
106  Self b( a.Size() );
107 
109  return b;
110  }
111 
112  static const Self ZeroValue(const Self & a)
113  {
114  Self b( a.Size() );
115 
117  return b;
118  }
119 
120  static const Self OneValue(const Self & a)
121  {
122  Self b( a.Size() );
123 
125  return b;
126  }
127 
128  static const Self NonpositiveMin(const Self & a)
129  {
130  Self b( a.Size() );
132  return b;
133  }
134 
135  static bool IsPositive( const Self & a)
136  {
137  bool flag = false;
138  for (unsigned int i=0; i < GetLength( a ); i++)
139  {
141  {
142  flag = true;
143  }
144  }
145  return flag;
146  }
147 
148  static bool IsNonpositive( const Self & a)
149  {
150  bool flag = false;
151  for (unsigned int i=0; i < GetLength( a ); i++)
152  {
153  if ( ! (a[i] > 0.0 ) )
154  {
155  flag = true;
156  }
157  }
158  return flag;
159  }
160 
161  static bool IsNegative( const Self & a)
162  {
163  bool flag = false;
164  for (unsigned int i=0; i < GetLength( a ); i++)
165  {
167  {
168  flag = true;
169  }
170  }
171  return flag;
172  }
173 
174  static bool IsNonnegative( const Self & a)
175  {
176  bool flag = false;
177  for (unsigned int i=0; i < GetLength( a ); i++)
178  {
179  if ( ! (a[i] < 0.0 ))
180  {
181  flag = true;
182  }
183  }
184  return flag;
185  }
186 
187  static ITK_CONSTEXPR_VAR bool IsSigned = NumericTraits< ValueType >::IsSigned;
188  static ITK_CONSTEXPR_VAR bool IsInteger = NumericTraits< ValueType >::IsInteger;
189  static ITK_CONSTEXPR_VAR bool IsComplex = NumericTraits< ValueType >::IsComplex;
190 
191 
193  static void SetLength(VariableLengthVector< T > & m, const unsigned int s)
194  {
195  m.SetSize(s);
197  }
199 
201  static unsigned int GetLength(const VariableLengthVector< T > & m)
202  {
203  return m.GetSize();
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<GetLength(v); i++ )
215  {
216  mv[i] = v[i];
217  }
218  }
219 
220 #if !defined(ITK_LEGACY_REMOVE)
221  //The extra #ifdef is need because the itkLegacyMacro
222  //can not format a static const member function properly
223  //in the case of removing the code.
224 
226  itkLegacyMacro(static const Self Zero(const Self & a))
227  {
228  Self b( a.Size() );
229 
231  return b;
232  }
234  itkLegacyMacro(static const Self One(const Self & a))
235  {
236  Self b( a.Size() );
237 
238  b.Fill(NumericTraits< T >::OneValue());
239  return b;
240  }
241 #endif
242 
243 };
244 } // end namespace itk
245 
246 #endif // itkNumericTraitsVariableLengthVector_h
static ITK_CONSTEXPR_VAR bool IsComplex
unsigned int Size(void) const
static void AssignToArray(const Self &v, MeasurementVectorType &mv)
static ITK_CONSTEXPR_VAR bool IsInteger
unsigned int GetSize(void) const
static const T Zero
Represents an array whose length can be defined at run-time.
static unsigned int GetLength()
static unsigned int GetLength(const VariableLengthVector< T > &m)
static void SetLength(VariableLengthVector< T > &m, const unsigned int s)
static ITK_CONSTEXPR_VAR bool IsSigned
static const T One
Define additional traits for native types such as int or float.
void SetSize(unsigned int sz, TReallocatePolicy reallocatePolicy, TKeepValuesPolicy keepValues)
void Fill(TValue const &v)