![]() |
ITK
4.2.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkRGBAPixel_h 00019 #define __itkRGBAPixel_h 00020 00021 // Undefine an eventual RGBAPixel macro 00022 #ifdef RGBAPixel 00023 #undef RGBAPixel 00024 #endif 00025 00026 #include "itkIndent.h" 00027 #include "itkFixedArray.h" 00028 #include "vnl/vnl_math.h" 00029 00030 namespace itk 00031 { 00058 template< typename TComponent = unsigned short > 00059 class RGBAPixel:public FixedArray< TComponent, 4 > 00060 { 00061 public: 00063 typedef RGBAPixel Self; 00064 typedef FixedArray< TComponent, 4 > Superclass; 00065 00067 itkStaticConstMacro(Dimension, unsigned int, 4); 00068 00070 itkStaticConstMacro(Length, unsigned int, 4); 00071 00073 typedef FixedArray< TComponent, 4 > BaseArray; 00074 00076 typedef TComponent ComponentType; 00077 typedef typename NumericTraits< ComponentType >::RealType LuminanceType; 00078 00080 RGBAPixel() { this->Fill(0); } 00081 RGBAPixel (const ComponentType & r) { this->Fill(r); } 00083 00085 template< class TRGBAPixelValueType > 00086 RGBAPixel(const RGBAPixel< TRGBAPixelValueType > & r):BaseArray(r) {} 00087 RGBAPixel(const ComponentType r[4]):BaseArray(r) {} 00089 00091 RGBAPixel & operator=(const Self & r); 00092 00093 RGBAPixel & operator=(const ComponentType r[4]); 00094 00096 Self operator+(const Self & vec) const; 00097 00098 Self operator-(const Self & vec) const; 00099 00100 const Self & operator+=(const Self & vec); 00101 00102 const Self & operator-=(const Self & vec); 00103 00104 Self operator *(const ComponentType & f) const; 00105 00106 bool operator==(const Self & vec) const; 00107 00109 static unsigned int GetNumberOfComponents() { return 4; } 00110 00112 ComponentType GetNthComponent(int c) const { return this->operator[](c); } 00113 00115 ComponentType GetScalarValue() const 00116 { 00117 return static_cast< ComponentType >( vcl_sqrt( 00118 static_cast< double >( this->operator[](0) ) 00119 * static_cast< double >( this->operator[](0) ) 00120 + static_cast< double >( this->operator[](1) ) 00121 * static_cast< double >( this->operator[](1) ) 00122 + static_cast< double >( this->operator[](2) ) 00123 * static_cast< double >( this->operator[](2) ) ) ); 00124 } 00125 00127 void SetNthComponent(int c, const ComponentType & v) { this->operator[](c) = v; } 00128 00130 void SetRed(ComponentType red) { this->operator[](0) = red; } 00131 00133 void SetGreen(ComponentType green) { this->operator[](1) = green; } 00134 00136 void SetBlue(ComponentType blue) { this->operator[](2) = blue; } 00137 00139 void SetAlpha(ComponentType alpha) { this->operator[](3) = alpha; } 00140 00142 void Set(ComponentType red, ComponentType green, ComponentType blue, ComponentType alpha) 00143 { 00144 this->operator[](0) = red; 00145 this->operator[](1) = green; 00146 this->operator[](2) = blue; 00147 this->operator[](3) = alpha; 00148 } 00150 00152 const ComponentType & GetRed(void) const { return this->operator[](0); } 00153 00155 const ComponentType & GetGreen(void) const { return this->operator[](1); } 00156 00158 const ComponentType & GetBlue(void) const { return this->operator[](2); } 00159 00161 const ComponentType & GetAlpha(void) const { return this->operator[](3); } 00162 00164 LuminanceType GetLuminance(void) const; 00165 }; 00166 00167 template< typename TComponent > 00168 ITK_EXPORT std::ostream & operator<<(std::ostream & os, 00169 const RGBAPixel< TComponent > & c); 00170 00171 template< typename TComponent > 00172 ITK_EXPORT std::istream & operator>>(std::istream & is, 00173 RGBAPixel< TComponent > & c); 00174 } // end namespace itk 00175 00176 // Define instantiation macro for this template. 00177 #define ITK_TEMPLATE_RGBAPixel(_, EXPORT, TypeX, TypeY) \ 00178 namespace itk \ 00179 { \ 00180 _( 1 ( class EXPORT RGBAPixel< ITK_TEMPLATE_1 TypeX > ) ) \ 00181 namespace Templates \ 00182 { \ 00183 typedef RGBAPixel< ITK_TEMPLATE_1 TypeX > RGBAPixel##TypeY; \ 00184 } \ 00185 } 00186 00187 #if ITK_TEMPLATE_EXPLICIT 00188 #include "Templates/itkRGBAPixel+-.h" 00189 #endif 00190 00191 // 00192 // Numeric traits must be included after (optionally) including the explicit 00193 // instantiations control of this class, in case the implicit instantiation 00194 // needs to be disabled. 00195 // 00196 // NumericTraits must be included before (optionally) including the .hxx file, 00197 // in case the .hxx requires to use NumericTraits. 00198 // 00199 #include "itkNumericTraitsRGBAPixel.h" 00200 00201 #if ITK_TEMPLATE_TXX 00202 #include "itkRGBAPixel.hxx" 00203 #endif 00204 00205 #endif 00206
1.7.6.1