00001 #ifndef HISTOGRAMUSER_H 00002 #define HISTOGRAMUSER_H 00003 00004 #include <qpointarray.h> 00005 #include <qobject.h> 00006 #include <iostream> 00007 00016 class HistogramUser : public QObject { 00017 Q_OBJECT 00018 protected: 00019 QPointArray mPnts[3]; 00020 unsigned char mCTable[3][256]; 00021 00022 virtual void calcCTable( ) { 00023 //\todo initialize variables to get rid of compiler errors 00024 double min1 = 0, min2 = 0, min3 = 0; 00025 double max1 = 0, max2 = 0, max3 = 0; 00026 double scaleX1 = 0, scaleX2 = 0, scaleX3 = 0; 00027 double m = 0; 00028 00029 QPointArray arr[3]; 00030 bool isColor = (!mPnts[1].isNull() && !mPnts[2].isNull()); 00031 00032 arr[0] = mPnts[0]; 00033 arr[1] = mPnts[1]; 00034 arr[2] = mPnts[2]; 00035 00036 min1 = arr[0].at(0).x(); 00037 max1 = arr[0].at(arr[0].size()-1).x(); 00038 if ( isColor ) { 00039 min2 = arr[1].at(0).x(); 00040 max2 = arr[1].at(arr[1].size()-1).x(); 00041 min3 = arr[2].at(0).x(); 00042 max3 = arr[2].at(arr[2].size()-1).x(); 00043 } 00044 00045 scaleX1 = (max1-min1) / 255.0; 00046 if ( isColor ) { 00047 scaleX2 = (max2-min2) / 255.0; 00048 scaleX3 = (max3-min3) / 255.0; 00049 } 00050 00051 mCTable[0][0] = arr[0].at(0).y(); 00052 mCTable[0][255] = arr[0].at(arr[0].size()-1).y(); 00053 00054 if ( isColor ) { 00055 mCTable[1][0] = arr[1].at(0).y(); 00056 mCTable[1][255] = arr[1].at(arr[1].size()-1).y(); 00057 00058 mCTable[2][0] = arr[2].at(0).y(); 00059 mCTable[2][255] = arr[2].at(arr[2].size()-1).y(); 00060 } 00061 00062 for ( int iVal=1; iVal < 255; iVal++ ) { 00063 double val1 = iVal*scaleX1 + min1; 00064 //\todo initialize variables to get rid of compiler errors 00065 double val2 = 0 ; 00066 double val3 = 0 ; 00067 00068 if ( isColor ) { 00069 val2 = iVal*scaleX2 + min2; 00070 val3 = iVal*scaleX3 + min3; 00071 } 00072 00073 unsigned int iPnt; 00074 00075 // FIND POINTS RED 00076 for ( iPnt=1; iPnt < arr[0].size(); iPnt++ ) { 00077 if ( arr[0].at(iPnt).x() > val1 ) 00078 break; 00079 } 00080 00081 m = (double)( arr[0].at(iPnt).y() - arr[0].at(iPnt-1).y() ) / 00082 (double)( arr[0].at(iPnt).x() - arr[0].at(iPnt-1).x() ); 00083 00084 mCTable[0][iVal] = (unsigned char)(m*(val1-arr[0].at(iPnt).x()) + arr[0].at(iPnt).y()); 00085 00086 if ( isColor ) { 00087 // FIND POINTS GREEN 00088 for ( iPnt=1; iPnt < arr[1].size(); iPnt++ ) { 00089 if ( arr[1].at(iPnt).x() > val2 ) 00090 break; 00091 } 00092 00093 m = (double)( arr[1].at(iPnt).y() - arr[1].at(iPnt-1).y() ) / 00094 (double)( arr[1].at(iPnt).x() - arr[1].at(iPnt-1).x() ); 00095 00096 mCTable[1][iVal] = (unsigned char)(m*(val2-arr[1].at(iPnt).x()) + arr[1].at(iPnt).y()); 00097 00098 // FIND POINTS RED 00099 for ( iPnt=1; iPnt < arr[2].size(); iPnt++ ) { 00100 if ( arr[2].at(iPnt).x() > val3 ) 00101 break; 00102 } 00103 00104 m = (double)( arr[2].at(iPnt).y() - arr[2].at(iPnt-1).y() ) / 00105 (double)( arr[2].at(iPnt).x() - arr[2].at(iPnt-1).x() ); 00106 00107 mCTable[2][iVal] = (unsigned char)(m*(val3-arr[2].at(iPnt).x()) + arr[2].at(iPnt).y()); 00108 } else { 00109 memcpy( mCTable[1], mCTable[0], 256 ); 00110 memcpy( mCTable[2], mCTable[0], 256 ); 00111 } 00112 00113 } 00114 } 00115 00116 public: 00117 00118 HistogramUser( ) { 00119 reset(); 00120 } 00121 00122 void reset( ) { 00123 // NULLING CTABLE 00124 for ( int i=0; i < 256; i++ ) { 00125 mCTable[0][i] = i; 00126 mCTable[1][i] = i; 00127 mCTable[2][i] = i; 00128 } 00129 } 00130 00131 virtual ~HistogramUser( ) { 00132 } 00133 00134 virtual const QPointArray* getHistPnts( ) { 00135 return mPnts; 00136 } 00137 00138 virtual void setHistPnts( QPointArray pnts[3] ) { 00139 mPnts[0] = pnts[0].copy(); 00140 mPnts[1] = pnts[1].copy(); 00141 mPnts[2] = pnts[2].copy(); 00142 calcCTable(); 00143 emit ctableChanged(); 00144 } 00145 00146 void scaleVal( unsigned char *data, int len ) { 00147 for ( int i=0; i < len; i+=4 ) { 00148 data[i+2] = mCTable[0][data[i+2]]; // reds 00149 data[i+1] = mCTable[1][data[i+1]]; // greens 00150 data[i] = mCTable[2][data[i]]; // blues 00151 } 00152 } 00153 00154 signals: 00155 void ctableChanged( ); 00156 }; 00157 00158 #endif 00159 00160 00161
Home |
Search |
Disclaimers & Privacy |
Contact Us GLIMSView Maintainer: dsoltesz@usgs.gov |