00001
00015 #ifndef _DLRCOMPUTERVISION_PIXELRGB_H_
00016 #define _DLRCOMPUTERVISION_PIXELRGB_H_
00017
00018 #include <dlrCommon/types.h>
00019
00020 namespace dlr {
00021
00022 namespace computerVision {
00023
00024 template<class Type>
00025 struct PixelRGB
00026 {
00031 PixelRGB()
00032 : red(), green(), blue() {}
00033
00034
00044 PixelRGB(const Type& red, const Type& green, const Type& blue)
00045 : red(red), green(green), blue(blue) {}
00046
00047
00051 ~PixelRGB() {}
00052
00053
00065 template<class Iter>
00066 inline Iter&
00067 copyFromIterator(Iter& iter);
00068
00069
00081 template<class Iter>
00082 inline Iter&
00083 copyToIterator(Iter& iter);
00084
00085
00086
00087
00088 Type red;
00089 Type green;
00090 Type blue;
00091
00092
00093
00094
00104 template <class OtherType>
00105 inline PixelRGB<Type>&
00106 operator+=(const PixelRGB<OtherType>& other);
00107
00108
00118 template <class OtherType>
00119 inline PixelRGB<Type>&
00120 operator-=(const PixelRGB<OtherType>& other);
00121
00122
00132 template <class Scalar>
00133 inline PixelRGB<Type>&
00134 operator/=(const Scalar& scalar);
00135
00136
00137
00138
00147 static inline bool
00148 isContiguous();
00149
00150 };
00151
00152
00153 typedef PixelRGB<UnsignedInt8> PixelRGB8;
00154 typedef PixelRGB<UnsignedInt16> PixelRGB16;
00155 typedef PixelRGB<Int16> PixelRGBSigned16;
00156 typedef PixelRGB<Int32> PixelRGBSigned32;
00157 typedef PixelRGB<Float32> PixelRGBFloat32;
00158 typedef PixelRGB<Float64> PixelRGBFloat64;
00159
00160
00175 template<class Type>
00176 inline PixelRGB<Type>
00177 operator-(const PixelRGB<Type>& pixel0, const PixelRGB<Type>& pixel1);
00178
00179
00191 template<class Type>
00192 inline bool
00193 operator==(const PixelRGB<Type>& pixel0, const PixelRGB<Type>& pixel1);
00194
00195 }
00196
00197 }
00198
00199
00200
00201
00202 namespace dlr {
00203
00204 namespace computerVision {
00205
00206
00207
00208
00209 template<class Type>
00210 template<class Iter>
00211 inline Iter&
00212 PixelRGB<Type>::
00213 copyFromIterator(Iter& iter)
00214 {
00215 red = *(iter++);
00216 green = *(iter++);
00217 blue = *(iter++);
00218 return iter;
00219 }
00220
00221
00222
00223
00224
00225 template<class Type>
00226 template<class Iter>
00227 inline Iter&
00228 PixelRGB<Type>::
00229 copyToIterator(Iter& iter)
00230 {
00231 *(iter++) = red;
00232 *(iter++) = green;
00233 *(iter++) = blue;
00234 return iter;
00235 }
00236
00237
00238
00239
00240
00241 template<class Type>
00242 template <class OtherType>
00243 inline PixelRGB<Type>&
00244 PixelRGB<Type>::
00245 operator+=(const PixelRGB<OtherType>& other)
00246 {
00247 red += other.red;
00248 green += other.green;
00249 blue += other.blue;
00250 return *this;
00251 }
00252
00253
00254
00255
00256 template<class Type>
00257 template <class OtherType>
00258 inline PixelRGB<Type>&
00259 PixelRGB<Type>::
00260 operator-=(const PixelRGB<OtherType>& other)
00261 {
00262 red -= other.red;
00263 green -= other.green;
00264 blue -= other.blue;
00265 return *this;
00266 }
00267
00268
00269
00270
00271 template<class Type>
00272 template <class Scalar>
00273 inline PixelRGB<Type>&
00274 PixelRGB<Type>::
00275 operator/=(const Scalar& scalar)
00276 {
00277 red /= scalar;
00278 green /= scalar;
00279 blue /= scalar;
00280 return *this;
00281 }
00282
00283
00284
00285
00286
00287 template<class Type>
00288 inline bool
00289 PixelRGB<Type>::
00290 isContiguous()
00291 {
00292 Type dummy;
00293 Type* typePtr = &dummy;
00294 PixelRGB<Type>* pixelPtr = reinterpret_cast<PixelRGB<Type>*>(typePtr);
00295 PixelRGB<Type>* pixelPtr2 = pixelPtr + 1;
00296 return
00297 ((reinterpret_cast<Type*>(&(pixelPtr2->red)) == &(typePtr[3]))
00298 && (reinterpret_cast<Type*>(&(pixelPtr2->green)) == &(typePtr[4]))
00299 && (reinterpret_cast<Type*>(&(pixelPtr2->blue)) == &(typePtr[5])));
00300 }
00301
00302
00303
00304
00305 template<class Type>
00306 inline PixelRGB<Type>
00307 operator-(const PixelRGB<Type>& pixel0, const PixelRGB<Type>& pixel1)
00308 {
00309 return PixelRGB<Type>(
00310 pixel0.red - pixel1.red,
00311 pixel0.green - pixel1.green,
00312 pixel0.blue - pixel1.blue);
00313 }
00314
00315
00316
00317
00318 template<class Type>
00319 inline bool
00320 operator==(const PixelRGB<Type>& pixel0, const PixelRGB<Type>& pixel1)
00321 {
00322 return (pixel0.red == pixel1.red
00323 && pixel0.green == pixel1.green
00324 && pixel0.blue == pixel1.blue);
00325 }
00326
00327 }
00328
00329 }
00330
00331 #endif