ITK  4.6.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  typedef T ValueType;
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 
179  static void SetLength(Vector< T, D > & m, const unsigned int s)
180  {
181  if ( s != D )
182  {
183  itkGenericExceptionMacro(<< "Cannot set the size of a Vector of length "
184  << D << " to " << s);
185  }
187  }
189 
191  static unsigned int GetLength(const Vector< T, D > &)
192  {
193  return D;
194  }
195 
197  static unsigned int GetLength()
198  {
199  return D;
200  }
201 
202  static void AssignToArray( const Self & v, MeasurementVectorType & mv )
203  {
204  mv = v;
205  }
206 
207  template<typename TArray>
208  static void AssignToArray( const Self & v, TArray & mv )
209  {
210  for( unsigned int i=0; i<D; i++ )
211  {
212  mv[i] = v[i];
213  }
214  }
215 
219  static const Self ITKCommon_EXPORT Zero;
220  static const Self ITKCommon_EXPORT One;
221 };
222 } // end namespace itk
223 
224 #endif // __itkNumericTraitsVectorPixel_h
NumericTraits< T >::AccumulateType ElementAccumulateType
static void AssignToArray(const Self &v, MeasurementVectorType &mv)
NumericTraits< T >::FloatType ElementFloatType
static const Self ITKCommon_EXPORT One
static const Self NonpositiveMin(const Self &)
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
static unsigned int GetLength()
Vector< ElementAccumulateType, D > AccumulateType
static const Self ITKCommon_EXPORT Zero
NumericTraits< T >::PrintType ElementPrintType
static void SetLength(Vector< T, D > &m, const unsigned int s)
static void AssignToArray(const Self &v, TArray &mv)
Define additional traits for native types such as int or float.
static unsigned int GetLength(const Vector< T, D > &)