ITK  4.8.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 >::ZeroValue() );
116  return b;
117  }
118 
119  static const Self OneValue(const Self & a)
120  {
121  Self b( a.Size(), NumericTraits< T >::OneValue() );
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  // since std::vector often holds types that have no NumericTraits::ZeroValue(),
135  // allow resize() to call the type's default constructor
136  m.clear();
137  m.resize(s);
138  }
140 
142  static unsigned int GetLength(const std::vector< T > & m)
143  {
144  return m.size();
145  }
146 
147  static void AssignToArray( const Self & v, MeasurementVectorType & mv )
148  {
149  mv = v;
150  }
151 
152  template<typename TArray>
153  static void AssignToArray( const Self & v, TArray & mv )
154  {
155  for( unsigned int i=0; i<GetLength(v); i++ )
156  {
157  mv[i] = v[i];
158  }
159  }
160 
161 };
162 } // end namespace itk
163 
164 #endif // itkNumericTraitsStdVector_h
static const Self OneValue(const Self &a)
NumericTraits< T >::FloatType ElementFloatType
std::vector< ElementPrintType > PrintType
static void SetLength(std::vector< T > &m, const unsigned int s)
NumericTraits< T >::AccumulateType ElementAccumulateType
std::vector< ElementAccumulateType > AccumulateType
static T min(const T &)
std::vector< ElementFloatType > FloatType
static unsigned int GetLength(const std::vector< T > &m)
static unsigned int GetLength()
static T max(const T &)
static void AssignToArray(const Self &v, MeasurementVectorType &mv)
static const Self ZeroValue(const Self &a)
static const Self NonpositiveMin(const Self &a)
NumericTraits< T >::PrintType ElementPrintType
Define additional traits for native types such as int or float.
static void AssignToArray(const Self &v, TArray &mv)