pixelHSV.h

Go to the documentation of this file.
00001 
00015 #ifndef _DLRCOMPUTERVISION_PIXELHSV_H_
00016 #define _DLRCOMPUTERVISION_PIXELHSV_H_
00017 
00018 #include <dlrCommon/types.h>
00019 
00020 namespace dlr {
00021 
00022   namespace computerVision {
00023     
00024     template<class TYPE>
00025     struct PixelHSV
00026     {
00027     public:
00028 
00033       PixelHSV()
00034         : hue(), saturation(), value() {}
00035 
00036     
00046       PixelHSV(const TYPE& hue, const TYPE& saturation, const TYPE& value)
00047         : hue(hue), saturation(saturation), value(value) {}
00048 
00049 
00053       ~PixelHSV() {}
00054 
00055     
00067       template<class Iter>
00068       inline Iter&
00069       copyFromIterator(Iter& iter);
00070 
00071 
00083       template<class Iter>
00084       inline Iter&
00085       copyToIterator(Iter& iter);
00086 
00087 
00088       /* ====== Public data members ====== */
00089 
00090       TYPE hue;
00091       TYPE saturation;
00092       TYPE value;
00093 
00094 
00095       /* ====== Static member functions ====== */
00096 
00105       static inline bool
00106       isContiguous();
00107 
00108     };
00109 
00110 
00111     typedef PixelHSV<UnsignedInt8> PixelHSV8;
00112     typedef PixelHSV<UnsignedInt16> PixelHSV16;
00113     typedef PixelHSV<Int16> PixelHSVSigned16;
00114     typedef PixelHSV<Int32> PixelHSVSigned32;
00115     typedef PixelHSV<Float32> PixelHSVFloat32;
00116     typedef PixelHSV<Float64> PixelHSVFloat64;
00117 
00118 
00133     template<class TYPE>
00134     inline PixelHSV<TYPE>
00135     operator-(const PixelHSV<TYPE>& pixel0, const PixelHSV<TYPE>& pixel1);
00136 
00137   
00149     template<class TYPE>
00150     inline bool
00151     operator==(const PixelHSV<TYPE>& pixel0, const PixelHSV<TYPE>& pixel1);
00152 
00153   } // namespace computerVision
00154 
00155 } // namespace dlr
00156   
00157 /* ============ Definitions of inline & template functions ============ */
00158 
00159 
00160 namespace dlr {
00161 
00162   namespace computerVision {
00163     
00164     // This member function copies the pixel component values, in
00165     // order, from consecutive iterator targets, incrementing the
00166     // iterator after each copy.
00167     template<class TYPE>
00168     template<class Iter>
00169     inline Iter&
00170     PixelHSV<TYPE>::
00171     copyFromIterator(Iter& iter)
00172     {
00173       hue = *(iter++);
00174       saturation = *(iter++);
00175       value = *(iter++);
00176       return iter;
00177     }
00178 
00179 
00180     // This member function assigns the pixel component values, in
00181     // order, to consecutive iterator targets, incrementing the
00182     // iterator after each assignment.
00183     template<class TYPE>
00184     template<class Iter>
00185     inline Iter&
00186     PixelHSV<TYPE>::
00187     copyToIterator(Iter& iter)
00188     {
00189       *(iter++) = hue;
00190       *(iter++) = saturation;
00191       *(iter++) = value;
00192       return iter;
00193     }
00194 
00195 
00196     // This static member function indicates whether or not a pixel
00197     // instance is memory identical to a contiguous array of Component
00198     // type.
00199     template<class TYPE>
00200     inline bool
00201     PixelHSV<TYPE>::
00202     isContiguous()
00203     {
00204       TYPE dummy;
00205       TYPE* typePtr = &dummy;
00206       PixelHSV<TYPE>* pixelPtr = reinterpret_cast<PixelHSV<TYPE>*>(typePtr);
00207       PixelHSV<TYPE>* pixelPtr2 = pixelPtr + 1;
00208       return
00209         ((reinterpret_cast<TYPE*>(&(pixelPtr2->hue)) == &(typePtr[3]))
00210          && (reinterpret_cast<TYPE*>(&(pixelPtr2->saturation)) == &(typePtr[4]))
00211          && (reinterpret_cast<TYPE*>(&(pixelPtr2->value)) == &(typePtr[5])));
00212     }
00213 
00214 
00215     // This operator subtracts the values of the individual color
00216     // components of its arguments.
00217     template<class TYPE>
00218     inline PixelHSV<TYPE>
00219     operator-(const PixelHSV<TYPE>& pixel0, const PixelHSV<TYPE>& pixel1)
00220     {
00221       return PixelHSV<TYPE>(
00222         pixel0.hue - pixel1.hue,
00223         pixel0.saturation - pixel1.saturation,
00224         pixel0.value - pixel1.value);
00225     }
00226 
00227 
00228     // This operator returns true if the contents of the two argments
00229     // are identical, false otherwise.
00230     template<class TYPE>
00231     inline bool
00232     operator==(const PixelHSV<TYPE>& pixel0, const PixelHSV<TYPE>& pixel1)
00233     {
00234       return (pixel0.hue == pixel1.hue
00235               && pixel0.saturation == pixel1.saturation
00236               && pixel0.value == pixel1.value);
00237     }
00238 
00239   } // namespace computerVision
00240   
00241 } // namespace dlr
00242 
00243 #endif /* #ifndef _DLRCOMPUTERVISION_PIXELHSV_H_ */

Generated on Wed Nov 25 12:15:05 2009 for dlrComputerVision Utility Library by  doxygen 1.5.8