ITK  4.2.0
Insight Segmentation and Registration Toolkit
itkNumericTraitsRGBPixel.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 __itkNumericTraitsRGBPixel_h
19 #define __itkNumericTraitsRGBPixel_h
20 
21 #include "itkNumericTraits.h"
22 #include "itkRGBPixel.h"
23 
24 namespace itk
25 {
42 template< typename T >
43 class NumericTraits< RGBPixel< T > >
44 {
45 private:
46 
52 public:
53 
55  typedef T ValueType;
56 
58 
61 
64 
68 
71 
74 
77 
80 
86  static const Self max(const Self &)
87  {
88  return Self( NumericTraits< T >::max() );
89  }
90 
91  static const Self min(const Self &)
92  {
93  return Self( NumericTraits< T >::min() );
94  }
95 
96  static const Self max()
97  {
98  return Self( NumericTraits< T >::max() );
99  }
100 
101  static const Self min()
102  {
103  return Self( NumericTraits< T >::min() );
104  }
105 
106  static const Self NonpositiveMin()
107  {
109  }
110 
111  static const Self ZeroValue()
112  {
114  }
115 
116  static const Self OneValue()
117  {
119  }
120 
121  static const Self NonpositiveMin(const Self &)
122  {
123  return NonpositiveMin();
124  }
125 
126  static const Self ZeroValue(const Self &)
127  {
128  return ZeroValue();
129  }
130 
131  static const Self OneValue(const Self &)
132  {
133  return OneValue();
134  }
135 
139  static void SetLength(RGBPixel< T > & m, const unsigned int s)
140  {
141  if ( s != 3 )
142  {
143  itkGenericExceptionMacro(<< "Cannot set the size of a RGBPixel to anything other "
144  "than 3.");
145  }
147  }
149 
151  static unsigned int GetLength(const RGBPixel< T > &)
152  {
153  return 3;
154  }
155 
157  static unsigned int GetLength()
158  {
159  return 3;
160  }
161 
162  static void AssignToArray( const Self & v, MeasurementVectorType & mv )
163  {
164  mv = v;
165  }
166 
167  template<class TArray>
168  static void AssignToArray( const Self & v, TArray & mv )
169  {
170  for( unsigned int i=0; i<3; i++ )
171  {
172  mv[i] = v[i];
173  }
174  }
175 
179  static const Self ITKCommon_EXPORT Zero;
180  static const Self ITKCommon_EXPORT One;
181 };
182 } // end namespace itk
183 
184 #endif // __itkNumericTraitsRGBPixel_h
185