ITK  4.2.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 public:
41 
43  typedef T ValueType;
45 
48 
51 
55 
58 
61 
64 
67 
73  static const Self max(const Self &)
74  {
75  return Self( NumericTraits< T >::max() );
76  }
77 
78  static const Self min(const Self &)
79  {
80  return Self( NumericTraits< T >::min() );
81  }
82 
83  static const Self max()
84  {
85  return Self( NumericTraits< T >::max() );
86  }
87 
88  static const Self min()
89  {
90  return Self( NumericTraits< T >::min() );
91  }
92 
93  static const Self NonpositiveMin()
94  {
96  }
97 
98  static const Self ZeroValue()
99  {
101  }
102 
103  static const Self OneValue()
104  {
106  }
107 
108  static const Self NonpositiveMin(const Self &)
109  {
110  return NonpositiveMin();
111  }
112 
113  static const Self ZeroValue(const Self &)
114  {
115  return ZeroValue();
116  }
117 
118  static const Self OneValue(const Self &)
119  {
120  return OneValue();
121  }
122 
126  static void SetLength(Vector< T, D > & m, const unsigned int s)
127  {
128  if ( s != D )
129  {
130  itkGenericExceptionMacro(<< "Cannot set the size of a Vector of length "
131  << D << " to " << s);
132  }
134  }
136 
138  static unsigned int GetLength(const Vector< T, D > &)
139  {
140  return D;
141  }
142 
144  static unsigned int GetLength()
145  {
146  return D;
147  }
148 
149  static void AssignToArray( const Self & v, MeasurementVectorType & mv )
150  {
151  mv = v;
152  }
153 
154  template<class TArray>
155  static void AssignToArray( const Self & v, TArray & mv )
156  {
157  for( unsigned int i=0; i<D; i++ )
158  {
159  mv[i] = v[i];
160  }
161  }
162 
166  static const Self ITKCommon_EXPORT Zero;
167  static const Self ITKCommon_EXPORT One;
168 };
169 } // end namespace itk
170 
171 #endif // __itkNumericTraitsVectorPixel_h
172