00001 #ifndef Impala_Core_Array_Trait_RgbStretch_h 00002 #define Impala_Core_Array_Trait_RgbStretch_h 00003 00004 #include "Basis/NativeTypes.h" 00005 #include "Core/Array/Element/E1ToVec3Real64.h" 00006 00007 namespace Impala 00008 { 00009 namespace Core 00010 { 00011 namespace Array 00012 { 00013 namespace Trait 00014 { 00015 00016 00020 template<class ValT> 00021 class RgbStretch 00022 { 00023 public: 00025 RgbStretch(Real64 lowVal, Real64 highVal) 00026 { 00027 mLowVal = lowVal; 00028 mHighVal = highVal; 00029 mInterval = mHighVal - mLowVal; 00030 } 00031 00033 void 00034 DoIt(const ValT& pixV, UInt8* rgbPtr) 00035 { 00036 Element::Vec3Real64 v = Element::E1ToVec3Real64(pixV); 00037 *rgbPtr++ = (Int32) (((v.X() - mLowVal) / mInterval) * 255); 00038 *rgbPtr++ = (Int32) (((v.Y() - mLowVal) / mInterval) * 255); 00039 *rgbPtr++ = (Int32) (((v.Z() - mLowVal) / mInterval) * 255); 00040 } 00041 00042 private: 00043 Real64 mLowVal; 00044 Real64 mHighVal; 00045 Real64 mInterval; 00046 }; 00047 00049 template<> 00050 inline void 00051 RgbStretch<Real64> 00052 ::DoIt(const Real64& pixV, UInt8* rgbPtr) 00053 { 00054 Int32 v = (Int32) (((pixV - mLowVal) / mInterval) * 255); 00055 *rgbPtr++ = v; 00056 *rgbPtr++ = v; 00057 *rgbPtr++ = v; 00058 } 00059 00060 00064 template<class ValT> 00065 class RgbStretchClip 00066 { 00067 public: 00069 RgbStretchClip(Real64 lowVal, Real64 highVal) 00070 { 00071 mLowVal = lowVal; 00072 mHighVal = highVal; 00073 mInterval = mHighVal - mLowVal; 00074 } 00075 00077 void 00078 DoIt(const ValT& pixV, UInt8* rgbPtr) 00079 { 00080 Element::Vec3Real64 v = Element::E1ToVec3Real64(pixV); 00081 Real64 vx = v.X(); 00082 Real64 vy = v.Y(); 00083 Real64 vz = v.Z(); 00084 vx = (vx < mLowVal) ? mLowVal : (vx > mHighVal ? mHighVal : vx); 00085 vy = (vy < mLowVal) ? mLowVal : (vy > mHighVal ? mHighVal : vy); 00086 vz = (vz < mLowVal) ? mLowVal : (vz > mHighVal ? mHighVal : vz); 00087 *rgbPtr++ = (Int32) (((vx - mLowVal) / mInterval) * 255); 00088 *rgbPtr++ = (Int32) (((vy - mLowVal) / mInterval) * 255); 00089 *rgbPtr++ = (Int32) (((vz - mLowVal) / mInterval) * 255); 00090 } 00091 00092 private: 00093 Real64 mLowVal; 00094 Real64 mHighVal; 00095 Real64 mInterval; 00096 }; 00097 00098 } // namespace Trait 00099 } // namespace Array 00100 } // namespace Core 00101 } // namespace Impala 00102 00103 #endif