ITK  4.2.0
Insight Segmentation and Registration Toolkit
itkNumericTraitsStdVector.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 
19 #ifndef __itkNumericTraitsStdVector_h
20 #define __itkNumericTraitsStdVector_h
21 
22 #include "itkNumericTraits.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 
29 namespace itk
30 {
55 template< typename T >
56 class NumericTraits< std::vector< T > >
57 {
58 public:
59 
65 
67  typedef T ValueType;
68 
69  typedef std::vector< T > Self;
70 
72  typedef std::vector< ElementAbsType > AbsType;
73 
75  typedef std::vector< ElementAccumulateType > AccumulateType;
76 
79  typedef std::vector< ElementFloatType > FloatType;
80 
81  // TODO: this won't really print well, at least not without defining an operator
82  // to push to a stream.
84  typedef std::vector< ElementPrintType > PrintType;
85 
87  typedef std::vector< ElementRealType > RealType;
88 
91 
94 
100  static const Self max(const Self & a)
101  {
102  Self b( a.Size(), NumericTraits< T >::max() );
103  return b;
104  }
106 
107  static const Self min(const Self & a)
108  {
109  Self b( a.Size(), NumericTraits< T >::min() );
110  return b;
111  }
112 
113  static const Self ZeroValue(const Self & a)
114  {
115  Self b( a.Size(), NumericTraits< T >::Zero );
116  return b;
117  }
118 
119  static const Self OneValue(const Self & a)
120  {
121  Self b( a.Size(), NumericTraits< T >::One );
122  return b;
123  }
124 
125  static const Self NonpositiveMin(const Self & a)
126  {
127  Self b( a.Size(), NumericTraits< T >::NonpositiveMin() );
128  return b;
129  }
130 
132  static void SetLength(std::vector< T > & m, const unsigned int s)
133  {
134  m.resize(s);
135  }
136 
138  static unsigned int GetLength(const std::vector< T > & m)
139  {
140  return m.size();
141  }
142 
143  static void AssignToArray( const Self & v, MeasurementVectorType & mv )
144  {
145  mv = v;
146  }
147 
148  template<class TArray>
149  static void AssignToArray( const Self & v, TArray & mv )
150  {
151  for( unsigned int i=0; i<GetLength(v); i++ )
152  {
153  mv[i] = v[i];
154  }
155  }
156 
157 };
158 } // end namespace itk
159 
160 #endif // __itkNumericTraitsStdVector_h
161