ITK  4.2.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 
136  static void SetLength(VariableLengthVector< T > & m, const unsigned int s)
137  {
138  m.SetSize(s);
140  }
142 
144  static unsigned int GetLength(const VariableLengthVector< T > & m)
145  {
146  return m.GetSize();
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<GetLength(v); i++ )
158  {
159  mv[i] = v[i];
160  }
161  }
162 
163 #if !defined(ITK_LEGACY_REMOVE)
164  //The extra #ifdef is need because the itkLegacyMacro
165  //can not format a static const member function properly
166  //in the case of removing the code.
167 
169  itkLegacyMacro(static const Self Zero(const Self & a))
170  {
171  Self b( a.Size() );
172 
174  return b;
175  }
177  itkLegacyMacro(static const Self One(const Self & a))
178  {
179  Self b( a.Size() );
180 
181  b.Fill(NumericTraits< T >::One);
182  return b;
183  }
184 #endif
185 
186 };
187 } // end namespace itk
188 
189 #endif // __itkNumericTraitsVariableLengthVector_h
190