ITK  4.2.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 public:
40 
42  typedef T ValueType;
43  typedef Array< T > Self;
44 
47 
50 
54 
57 
60 
63 
66 
72  static const Self max(const Self & a)
73  {
74  Self b( a.Size() );
75 
77  return b;
78  }
79 
80  static const Self min(const Self & a)
81  {
82  Self b( a.Size() );
83 
85  return b;
86  }
87 
88  static const Self ZeroValue(const Self & a)
89  {
90  Self b( a.Size() );
91 
93  return b;
94  }
95 
96  static const Self OneValue(const Self & a)
97  {
98  Self b( a.Size() );
99 
101  return b;
102  }
103 
104  static const Self NonpositiveMin(const Self & a)
105  {
106  Self b( a.Size() );
108  return b;
109  }
110 
112  static void SetLength(Array< T > & m, const unsigned int s)
113  {
114  m.SetSize(s);
116  }
118 
120  static unsigned int GetLength(const Array< T > & m)
121  {
122  return m.GetSize();
123  }
124 
125  static void AssignToArray( const Self & v, MeasurementVectorType & mv )
126  {
127  mv = v;
128  }
129 
130  template<class TArray>
131  static void AssignToArray( const Self & v, TArray & mv )
132  {
133  for( unsigned int i=0; i<GetLength(v); i++ )
134  {
135  mv[i] = v[i];
136  }
137  }
138 
139 #if !defined(ITK_LEGACY_REMOVE)
140  //The extra #ifdef is need because the itkLegacyMacro
141  //can not format a static const member function properly
142  //in the case of removing the code.
143 
145  itkLegacyMacro(static const Self Zero(const Self & a))
146  {
147  Self b( a.Size() );
149  return b;
150  }
152 
154  itkLegacyMacro(static const Self One(const Self & a))
155  {
156  Self b( a.Size() );
157  b.Fill(NumericTraits< T >::One);
158  return b;
159  }
160 #endif
161 
162 
163 };
164 } // end namespace itk
165 
166 #endif // __itkNumericTraitsArrayPixel_h
167