ITK  4.3.0
Insight Segmentation and Registration Toolkit
itkNumericTraitsArrayPixel.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 __itkNumericTraitsArrayPixel_h
19 #define __itkNumericTraitsArrayPixel_h
20 
21 #include "itkNumericTraits.h"
22 #include "itkArray.h"
23 
24 namespace itk
25 {
29 template< typename T >
30 class NumericTraits< Array< T > >
31 {
32 private:
33 
39 
40 public:
41 
43  typedef T ValueType;
44  typedef Array< T > Self;
45 
48 
51 
55 
58 
61 
64 
67 
73  static const Self max(const Self & a)
74  {
75  Self b( a.Size() );
76 
78  return b;
79  }
80 
81  static const Self min(const Self & a)
82  {
83  Self b( a.Size() );
84 
86  return b;
87  }
88 
89  static const Self ZeroValue(const Self & a)
90  {
91  Self b( a.Size() );
92 
94  return b;
95  }
96 
97  static const Self OneValue(const Self & a)
98  {
99  Self b( a.Size() );
100 
102  return b;
103  }
104 
105  static const Self NonpositiveMin(const Self & a)
106  {
107  Self b( a.Size() );
109  return b;
110  }
111 
113  static void SetLength(Array< T > & m, const unsigned int s)
114  {
115  m.SetSize(s);
117  }
119 
121  static unsigned int GetLength(const Array< T > & m)
122  {
123  return m.GetSize();
124  }
125 
126  static void AssignToArray( const Self & v, MeasurementVectorType & mv )
127  {
128  mv = v;
129  }
130 
131  template<class TArray>
132  static void AssignToArray( const Self & v, TArray & mv )
133  {
134  for( unsigned int i=0; i<GetLength(v); i++ )
135  {
136  mv[i] = v[i];
137  }
138  }
139 
140 #if !defined(ITK_LEGACY_REMOVE)
141  //The extra #ifdef is need because the itkLegacyMacro
142  //can not format a static const member function properly
143  //in the case of removing the code.
144 
146  itkLegacyMacro(static const Self Zero(const Self & a))
147  {
148  Self b( a.Size() );
150  return b;
151  }
153 
155  itkLegacyMacro(static const Self One(const Self & a))
156  {
157  Self b( a.Size() );
158  b.Fill(NumericTraits< T >::One);
159  return b;
160  }
161 #endif
162 
163 
164 };
165 } // end namespace itk
166 
167 #endif // __itkNumericTraitsArrayPixel_h
168