ITK  4.6.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 
135  static bool IsPositive( const Self & a)
136  {
137  bool flag = false;
138  for (unsigned int i=0; i < GetLength( a ); i++)
139  {
141  {
142  flag = true;
143  }
144  }
145  return flag;
146  }
147 
148  static bool IsNonpositive( const Self & a)
149  {
150  bool flag = false;
151  for (unsigned int i=0; i < GetLength( a ); i++)
152  {
153  if ( ! (a[i] > 0.0 ) )
154  {
155  flag = true;
156  }
157  }
158  return flag;
159  }
160 
161  static bool IsNegative( const Self & a)
162  {
163  bool flag = false;
164  for (unsigned int i=0; i < GetLength( a ); i++)
165  {
167  {
168  flag = true;
169  }
170  }
171  return flag;
172  }
173 
174  static bool IsNonnegative( const Self & a)
175  {
176  bool flag = false;
177  for (unsigned int i=0; i < GetLength( a ); i++)
178  {
179  if ( ! (a[i] < 0.0 ))
180  {
181  flag = true;
182  }
183  }
184  return flag;
185  }
186 
187 
189  static void SetLength(VariableLengthVector< T > & m, const unsigned int s)
190  {
191  m.SetSize(s);
193  }
195 
197  static unsigned int GetLength(const VariableLengthVector< T > & m)
198  {
199  return m.GetSize();
200  }
201 
202  static void AssignToArray( const Self & v, MeasurementVectorType & mv )
203  {
204  mv = v;
205  }
206 
207  template<typename TArray>
208  static void AssignToArray( const Self & v, TArray & mv )
209  {
210  for( unsigned int i=0; i<GetLength(v); i++ )
211  {
212  mv[i] = v[i];
213  }
214  }
215 
216 #if !defined(ITK_LEGACY_REMOVE)
217  //The extra #ifdef is need because the itkLegacyMacro
218  //can not format a static const member function properly
219  //in the case of removing the code.
220 
222  itkLegacyMacro(static const Self Zero(const Self & a))
223  {
224  Self b( a.Size() );
225 
227  return b;
228  }
230  itkLegacyMacro(static const Self One(const Self & a))
231  {
232  Self b( a.Size() );
233 
234  b.Fill(NumericTraits< T >::One);
235  return b;
236  }
237 #endif
238 
239 };
240 } // end namespace itk
241 
242 #endif // __itkNumericTraitsVariableLengthVector_h
unsigned int Size(void) const
static void AssignToArray(const Self &v, MeasurementVectorType &mv)
unsigned int GetSize(void) const
static const T Zero
Represents an array whose length can be defined at run-time.
static unsigned int GetLength()
static unsigned int GetLength(const VariableLengthVector< T > &m)
static void SetLength(VariableLengthVector< T > &m, const unsigned int s)
static const T One
void SetSize(unsigned int sz, bool destroyExistingData=true)
Define additional traits for native types such as int or float.
void Fill(TValue const &v)