#include "modelparaset.h" #include "FaultLine.h" #include ModelParaSet::ModelParaSet() { minx=0; maxx=0; miny=0; maxy=0; dx=10; dy=10; modelType=1; isChooseRange=false; isShowLight=true; isShowAttributeLegend=true; //segments=40; isShowLegend=true; isDxDyChange=false; startDepth=0; endDepth=100; contourLine=new ContourAttri(); faultlines=new QList(); lineCells=new QList(); appointPoint=new Point3D(); nearPoints=new QList(); m_pColorTable=new PaiColorTableData("Color Scheme",true); m_pColorTable->SetCurrentSchemeIndex(5); blockNum=40; m_pColorTable->ChangeColorNum(blockNum); ////////////////////////////////////////// QList rgbList=m_pColorTable->GetRgb(); QColor acolor=rgbList.at(0); m_staColor=RGB(acolor.red(),acolor.green(),acolor.blue()); acolor=rgbList.at(rgbList.size()-1); m_endColor=RGB(acolor.red(),acolor.green(),acolor.blue()); acolor=rgbList.at(rgbList.size()/2); m_curColor=RGB(acolor.red(),acolor.green(),acolor.blue()); isGradientMod=0; isIntenseMod=0; isLogMod=0; startDepth=0; //startDepth=0; endDepth=100; itemStart=0; itemEnd=blockNum; itemStaColor=m_staColor; itemEndColor=m_endColor; isHsvMod=0; m_nSelection.clear(); m_nSelection.append(isGradientMod); m_nSelection.append(isIntenseMod); m_nSelection.append(isLogMod); m_nSelection.append(blockNum); m_nSelection.append(isHsvMod); Initial(); } ModelParaSet::~ModelParaSet() { if(m_pColorTable) delete m_pColorTable; } ModelParaSet& ModelParaSet::operator=(const ModelParaSet & a) { /*minx=a.minx; maxx=a.maxx; miny=a.miny; maxy=a.maxy; dx=a.dx; dy=a.dy; modelType=a.modelType; isShowLight=a.isShowLight; isShowAttributeLegend=a.isShowAttributeLegend; isChooseRange=a.isChooseRange; layerName1=a.layerName1; layerName2=a.layerName2; modelLayerName=a.modelLayerName; IsBuild=a.IsBuild; IsShowModel=a.IsShowModel; IsShowLineModel=a.IsShowLineModel; layerNumber=a.layerNumber; Attribute=a.Attribute; IsBuildAttrModel=a.IsBuildAttrModel; IsShowAttrModel=a.IsShowAttrModel; getValueWay=a.getValueWay; segments=a.segments; segColor=a.segColor; startDepth=a.startDepth; endDepth=a.endDepth;*/ return *this; } QColor ModelParaSet::GetColorFromCOLORREF(COLORREF c) { int r=GetRValue(c); int g=GetGValue(c); int b=GetBValue(c); return QColor(r,g,b); } void ModelParaSet::SerializableColorPanel(QDataStream& ds) { if(ds.device()->isWritable()) { ds<< startDepth; ds<>startDepth; ds>>endDepth; QColor ec,cc,sc; ds>>ec>>cc>>sc; m_endColor=RGB(ec.red(),ec.green(),ec.blue()); m_curColor=RGB(cc.red(),cc.green(),cc.blue()); m_staColor=RGB(sc.red(),sc.green(),sc.blue()); int n; ds>>n; m_colData.clear(); m_staData.clear(); m_endData.clear(); for(int i=0;i>clr; COLORREF c=RGB(clr.red(),clr.green(),clr.blue());; m_colData.append(c); } ds>>n; for(int i=0;i>s; ds>>e; m_staData.append(s); m_endData.append(e); } ds>>blockNum; ds>>isGradientMod; ds>>isIntenseMod; ds>>isLogMod; ds>>itemStart; ds>>itemEnd; ds>>isHsvMod; ds>>GetColorFromCOLORREF(itemStaColor); ds>>GetColorFromCOLORREF(itemEndColor); } } void ModelParaSet::Serializable(QDataStream& ds) { if(ds.device()->isWritable()) { ds< layerName1; int count=layerName1.count(); ds< layerName2; count=layerName2.count(); ds< modelLayerName; count=modelLayerName.count(); ds< IsBuild; count=IsBuild.count(); ds< IsShowModel; count=IsShowModel.count(); ds< IsShowLineModel; count=IsShowLineModel.count(); ds< layerNumber; count=layerNumber.count(); ds< IsBuildAttrModel; count=IsBuildAttrModel.count(); ds< IsShowAttrModel; count=IsShowAttrModel.count(); ds< getValueWay; count=getValueWay.count(); ds<>minx; ds>>maxx; ds>>miny; ds>>maxy; ds>>dx; ds>>dy; ds>>isShowLight; ds>>isShowAttributeLegend; ds>>isChooseRange; int count; ds>>count; for(int i=0;i>layername; layerName1.append(layername); } ds>>count; for(int i=0;i>layername; layerName2.append(layername); } //QList modelLayerName; ds>>count; for(int i=0;i>layername; modelLayerName.append(layername); } //QList IsBuild; ds>>count; for(int i=0;i>isbuild; IsBuild.append(isbuild); } //QList IsShowModel; ds>>count; for(int i=0;i>isshow; IsShowModel.append(isshow); } //QList IsShowLineModel; ds>>count; for(int i=0;i>isshow; IsShowLineModel.append(isshow); } //QList layerNumber; ds>>count; for(int i=0;i>layernum; layerNumber.append(layernum); } ds>>Attribute; //QList IsBuildAttrModel; ds>>count; for(int i=0;i>isbuild; IsBuildAttrModel.append(isbuild); } //QList IsShowAttrModel; ds>>count; for(int i=0;i>isshow; IsShowAttrModel.append(isshow); } //QList getValueWay; ds>>count; for(int i=0;i>getvalue; getValueWay.append(getvalue); } SerializableColorPanel(ds); } } /////////////////////////////////////// BOOL ModelParaSet::ResetData(float startVal,float endVal) { startDepth=startVal; endDepth=endVal; blockNum=40; isGradientMod=0; isIntenseMod=0; isLogMod=0; itemStart=0; itemEnd=blockNum; itemStaColor=m_staColor; itemEndColor=m_endColor; isHsvMod=0; m_nSelection.clear(); m_nSelection.append(isGradientMod); m_nSelection.append(isIntenseMod); m_nSelection.append(isLogMod); m_nSelection.append(blockNum); m_nSelection.append(isHsvMod); Initial(); return TRUE; } BOOL ModelParaSet::Intense() { int nItem=0,i=0,j=0; COLORREF virStaColor,virEndColor,preStaColor,preEndColor,preColor;//加密时起始颜色 float m=0,n=0,temp=0,preSta=0,preEnd=0;//定义变量 int r_sta; int g_sta; int b_sta; int r_cur; int g_cur; int b_cur; int r_end; int g_end; int b_end; int r_temp; int g_temp; int b_temp; float h_sta,s_sta,v_sta; float h_cur,s_cur,v_cur; float h_end,s_end,v_end; float fr_sta,fg_sta,fb_sta; float fr_cur,fg_cur,fb_cur; float fr_end,fg_end,fb_end; nItem=m_staData.count();//获取当前数组长度 preStaColor=m_colData[0]; preEndColor=m_colData[nItem-1]; if (startDepth>m_endData[nItem-1])//如果加密的起始深度大于加密前的终止深度,移除所有数据,以此次数据初始化 { m_staData.clear(); m_endData.clear(); m_colData.clear(); Initial(); return FALSE; } for(i=0;i=m_staData[i]&&startDepth0)//当加密起始数据不在第一行时 { m_endData.removeAt(i-1);//使加密后起始数据与加密前连接 m_endData.insert(i-1,startDepth); } if (endDepth>m_endData[nItem-1])//如果加密终止数据大于加密前终止数据 { virEndColor=m_endColor; int k; for (k=i;kChangeColorNum(blockNum); int r_sta; int g_sta; int b_sta; int r_cur; int g_cur; int b_cur; int r_end; int g_end; int b_end; int r_temp; int g_temp; int b_temp; float h_sta,s_sta,v_sta; float h_cur,s_cur,v_cur; float h_end,s_end,v_end; float fr_sta,fg_sta,fb_sta; float fr_cur,fg_cur,fb_cur; float fr_end,fg_end,fb_end; r_sta = GetRValue(itemStaColor); g_sta = GetGValue(itemStaColor); b_sta = GetBValue(itemStaColor); r_end = GetRValue(itemEndColor); g_end = GetGValue(itemEndColor); b_end = GetBValue(itemEndColor); m_staData.clear(); m_endData.clear(); m_colData.clear(); if (isLogMod==0||isLogMod==1) { m=startDepth; for (i=itemStart;i rgbList=m_pColorTable->GetRgb(); m_colData.clear(); for(int i=0;i0) // { // float oldStartV=m_staData[0]; // float oldEndV=m_endData[nItem-1]; // if (endDepth!=0) // { // float temp=(endDepth-startDepth)/(oldEndV-oldStartV); // //float temp=(endDepth-startDepth)/(m_endData[nItem-1)-m_staData[0)); // for (i=0; i=m_endData[nItem-1]) { return m_colData[nItem-1]; } } else { if (value<=m_staData[0]) { return m_colData[0]; } if (value>=m_staData[nItem-1]) { return m_colData[nItem-1]; } } int i; for (i=0;i=m_staData[i]&&value<=m_staData[i+1]) break; } if (model==0) { colorResult=m_colData[i]; } else { staR=GetRValue(m_colData[i]); staG=GetGValue(m_colData[i]); staB=GetBValue(m_colData[i]); endR=GetRValue(m_colData[i+1]); endG=GetGValue(m_colData[i+1]); endB=GetBValue(m_colData[i+1]); tempR=staR+(endR-staR)*((value-m_staData[i])/(m_staData[i+1]-m_staData[i])); tempG=staG+(endG-staG)*((value-m_staData[i])/(m_staData[i+1]-m_staData[i])); tempB=staB+(endB-staB)*((value-m_staData[i])/(m_staData[i+1]-m_staData[i])); colorResult=RGB(tempR,tempG,tempB); } return colorResult; } COLORREF ModelParaSet::GetColor(int model,float value) { COLORREF colorResult; int tempR,tempG,tempB; int staR,staG,staB; int endR,endG,endB; int nItem; nItem=m_staData.count(); if (model==0) { if (value<=m_staData[0]) { return m_colData[0]; } if (value>=m_endData[nItem-1]) { return m_colData[nItem-1]; } } else { if (value<=m_staData[0]) { return m_colData[0]; } if (value>=m_staData[nItem-1]) { return m_colData[nItem-1]; } } int i; for (i=0;i=m_staData[i]&&value<=m_staData[i+1]) break; } if (model==0) { colorResult=m_colData[i]; } else { staR=GetRValue(m_colData[i]); staG=GetGValue(m_colData[i]); staB=GetBValue(m_colData[i]); endR=GetRValue(m_colData[i+1]); endG=GetGValue(m_colData[i+1]); endB=GetBValue(m_colData[i+1]); tempR=staR+(endR-staR)*((value-m_staData[i])/(m_staData[i+1]-m_staData[i])); tempG=staG+(endG-staG)*((value-m_staData[i])/(m_staData[i+1]-m_staData[i])); tempB=staB+(endB-staB)*((value-m_staData[i])/(m_staData[i+1]-m_staData[i])); colorResult=RGB(tempR,tempG,tempB); } return colorResult; } COLORREF ModelParaSet::Query(int model,float value) { COLORREF colorResult; int tempR,tempG,tempB; int staR,staG,staB; int endR,endG,endB; int nItem; nItem=m_staData.count(); if (model==0) { if (value<=m_staData[0]) { return m_colData[0]; } if (value>=m_endData[nItem-1]) { return m_colData[nItem-1]; } } else { if (value<=m_staData[0]) { return m_colData[0]; } if (value>=m_staData[nItem-1]) { return m_colData[nItem-1]; } } int i; for (i=0;i=m_staData[i]&&value<=m_staData[i+1]) break; } if (model==0) { colorResult=m_colData[i]; } else { staR=GetRValue(m_colData[i]); staG=GetGValue(m_colData[i]); staB=GetBValue(m_colData[i]); endR=GetRValue(m_colData[i+1]); endG=GetGValue(m_colData[i+1]); endB=GetBValue(m_colData[i+1]); tempR=staR+(endR-staR)*((value-m_staData[i])/(m_staData[i+1]-m_staData[i])); tempG=staG+(endG-staG)*((value-m_staData[i])/(m_staData[i+1]-m_staData[i])); tempB=staB+(endB-staB)*((value-m_staData[i])/(m_staData[i+1]-m_staData[i])); colorResult=RGB(tempR,tempG,tempB); } return colorResult; } BOOL ModelParaSet::Gradient(int sta, int end) { COLORREF itemStaColor,itemCurColor,itemEndColor; int r_sta; int g_sta; int b_sta; int r_cur; int g_cur; int b_cur; int r_end; int g_end; int b_end; int r_temp; int g_temp; int b_temp; float h_sta,s_sta,v_sta; float h_cur,s_cur,v_cur; float h_end,s_end,v_end; float fr_sta,fg_sta,fb_sta; float fr_cur,fg_cur,fb_cur; float fr_end,fg_end,fb_end; itemStaColor=m_colData[sta]; itemEndColor=m_colData[end]; r_sta = GetRValue(itemStaColor); g_sta = GetGValue(itemStaColor); b_sta = GetBValue(itemStaColor); r_end = GetRValue(itemEndColor); g_end = GetGValue(itemEndColor); b_end = GetBValue(itemEndColor); if (isHsvMod) { fr_sta=((float)r_sta)/255; fg_sta=((float)g_sta)/255; fb_sta=((float)b_sta)/255; fr_end=((float)r_end)/255; fg_end=((float)g_end)/255; fb_end=((float)b_end)/255; if (isHsvMod==1) { RgbToHsv(fr_sta,fg_sta,fb_sta,h_sta,s_sta,v_sta); RgbToHsv(fr_end,fg_end,fb_end,h_end,s_end,v_end); } else { // RgbToHsl(fr_sta,fg_sta,fb_sta,h_sta,s_sta,v_sta); // RgbToHsl(fr_end,fg_end,fb_end,h_end,s_end,v_end); RgbToHsl(itemStaColor,h_sta,s_sta,v_sta); RgbToHsl(itemEndColor,h_end,s_end,v_end); } } for (int i=sta;i<=end;i++) { if (isHsvMod) { h_cur=h_sta+(i-sta)*(h_end-h_sta)/(end-sta); s_cur=s_sta+(i-sta)*(s_end-s_sta)/(end-sta); v_cur=v_sta+(i-sta)*(v_end-v_sta)/(end-sta); } else { r_cur=r_sta+(i-sta)*(r_end-r_sta)/(end-sta); g_cur=g_sta+(i-sta)*(g_end-g_sta)/(end-sta); b_cur=b_sta+(i-sta)*(b_end-b_sta)/(end-sta); } if (isHsvMod) { if (isHsvMod==1) { HsvToRgb(h_cur,s_cur,v_cur,fr_cur,fg_cur,fb_cur); r_temp=(int)(fr_cur*255); g_temp=(int)(fg_cur*255); b_temp=(int)(fb_cur*255); m_curColor=RGB(r_temp,g_temp,b_temp); } else { // HslToRgb(h_cur,s_cur,v_cur,fr_cur,fg_cur,fb_cur); HslToRgb(h_cur,s_cur,v_cur,m_curColor); } } else m_curColor=RGB(r_cur,g_cur,b_cur); //m_colData.removeAt(i); //m_colData.insert(i,m_curColor); m_colData[i]=m_curColor; } return TRUE; } BOOL ModelParaSet::DataChange(int col, int row,int isGradientMod,float tempData) { QList m_staOldData; QList m_endOldData; QList m_colOldData; QList m_nSelection1; m_staOldData.append(m_staData); m_endOldData.append(m_endData); m_colOldData.append(m_colData); int i=0,j=0,min=0,max=0,nItem=0; float temp; if (col==1) { if (row==0) { //m_staData.removeAt(row); //m_staData.insert(row,tempData); m_staData[row]=tempData; } else { //m_staData.removeAt(row); //m_staData.insert(row,tempData); m_staData[row]=tempData; //m_endData.removeAt(row-1); //m_endData.insert(row-1,tempData); m_endData[row-1]=tempData; } } else { if (row==(m_staData.count()-1)) { //m_endData.removeAt(row); //m_endData.insert(row,tempData); m_endData[row]=tempData; } else { //m_staData.removeAt(row+1); //m_staData.insert(row+1,tempData); m_staData[row+1]=tempData; //m_endData.removeAt(row); //m_endData.insert(row,tempData); m_endData[row]=tempData; } } nItem=m_endData.count(); for(i=0;i=temp) { if(col==2 && row==m_endOldData.count()-1 && tempData>=m_endOldData[row]) return TRUE; if (row=m_endOldData[row]) return TRUE; for(i=0;i=m_staOldData[i]&&tempData=0.5) S=float(delta)/(2-delta); } if( R == max ) H = ( G - B ) / delta; // between yellow & magenta else if( G == max ) H = 2 + ( B - R ) / delta; // between cyan & yellow else H = 4 + ( R - G ) / delta; // between magenta & cyan H *= 60; // degrees if(H<0) H += 360; */ float h=0, s=0, l=0; // normalizes red-green-blue values float r =R; float g =G; float b =B; float minVal= MinV( R, G,B ); float maxVal= MaxV( R, G,B ); // hue if(maxVal == minVal) { h = 0; // undefined } else if(maxVal==r && g>=b) { h = 60.0f*(g-b)/(maxVal-minVal); } else if(maxVal==r && g0.5f) { s = (maxVal-minVal)/(2 - (maxVal+minVal)); //(maxVal-minVal > 0)? } H= (h>360)? 360 : ((h<0)?0:h); S= ((s>1)?1 : ((s<0)?0:s)); L = ((l>1)? 1 : ((l<0)?0:l)); } void ModelParaSet::RgbToHsl(float R, float G, float B, float &H, float &S, float &L) { // r,g,b values are from 0 to 1 // h = [0,360], s = [0,1], v = [0,1] // if s == 0, then h = -1 (undefined) /* float min, max, delta; min = MinV( R, G,B ); max = MaxV( R, G,B ); L =(max+min)/2 ; // v delta = max - min; if (max==min) { S=0; } else { if(L<0.5) S =float(delta)/(max+min); // s if (L>=0.5) S=float(delta)/(2-delta); } if( R == max ) H = ( G - B ) / delta; // between yellow & magenta else if( G == max ) H = 2 + ( B - R ) / delta; // between cyan & yellow else H = 4 + ( R - G ) / delta; // between magenta & cyan H *= 60; // degrees if(H<0) H += 360; */ float h=0, s=0, l=0; // normalizes red-green-blue values float r = R; float g =G; float b =B; float minVal= MinV( R, G,B ); float maxVal= MaxV( R, G,B ); // hue if(maxVal == minVal) { h = 0; // undefined } else if(maxVal==r && g>=b) { h = 60.0f*(g-b)/(maxVal-minVal); } else if(maxVal==r && g0.5f) { s = (maxVal-minVal)/(2 - (maxVal+minVal)); //(maxVal-minVal > 0)? } H= (h>360)? 360 : ((h<0)?0:h); S= ((s>1)?1 : ((s<0)?0:s)); // S=1; L = ((l>1)? 1 : ((l<0)?0:l)); } void ModelParaSet::HslToRgb(float H, float S, float L, int&r,int&g,int&b) { float h = H;// h must be [0, 360] float s =S;// s must be [0, 1] float l = L;// l must be [0, 1] float R,G,B; if(s == 0) { // achromatic color (gray scale) R = G = B =l; } else { float q = (l<0.5f)?(l * (1.0f+s)):(l+s - (l*s)); float p = (2.0f * l) - q; float Hk = h/360.0f; float T[3]; T[0] = Hk + 0.3333333f;// Tr0.3333333f=1.0/3.0 T[1] = Hk;// Tb T[2] = Hk - 0.3333333f;// Tg for(int i=0; i<3; i++) { if(T[i] < 0) T[i] += 1.0f; if(T[i] > 1) T[i] -= 1.0f; if((T[i]*6) < 1) { T[i] = p + ((q-p)*6.0f*T[i]); } else if((T[i]*2.0f) < 1) //(1.0/6.0)<=T[i] && T[i]<0.5 { T[i] = q; } else if((T[i]*3.0f) < 2) // 0.5<=T[i] && T[i]<(2.0/3.0) { T[i] = p + (q-p) * ((2.0f/3.0f) - T[i]) * 6.0f; } else T[i] = p; } R = T[0]*1.0f; G = T[1]*1.0f; B = T[2]*1.0f; } r = (int)((R>1)? 1 : ((R<0)?0 : R)); g= (int)((G>1)? 1 : ((G<0)?0 : G)); b = (int)((B>1)? 1 : ((B<0)?0 : B)); r=r*255; g=g*255; b=b*255; } void ModelParaSet::HslToRgb(float H, float S, float L, COLORREF &color) { float h = H;// h must be [0, 360] float s =S;// s must be [0, 1] float l = L;// l must be [0, 1] float R,G,B; if(s == 0) { // achromatic color (gray scale) R = G = B =l; } else { float q = (l<0.5f)?(l * (1.0f+s)):(l+s - (l*s)); float p = (2.0f * l) - q; float Hk = h/360.0f; float T[3]; T[0] = Hk + 0.3333333f;// Tr0.3333333f=1.0/3.0 T[1] = Hk;// Tb T[2] = Hk - 0.3333333f;// Tg for(int i=0; i<3; i++) { if(T[i] < 0) T[i] += 1.0f; if(T[i] > 1) T[i] -= 1.0f; if((T[i]*6) < 1) { T[i] = p + ((q-p)*6.0f*T[i]); } else if((T[i]*2.0f) < 1) //(1.0/6.0)<=T[i] && T[i]<0.5 { T[i] = q; } else if((T[i]*3.0f) < 2) // 0.5<=T[i] && T[i]<(2.0/3.0) { T[i] = p + (q-p) * ((2.0f/3.0f) - T[i]) * 6.0f; } else T[i] = p; } R = T[0]*1.0f; G = T[1]*1.0f; B = T[2]*1.0f; } float r,b,g; r = (int)((R>1)? 1 : ((R<0)?0 : R)); g= (int)((G>1)? 1 : ((G<0)?0 : G)); b = (int)((B>1)? 1 : ((B<0)?0 : B)); color=RGB(R*255,G*255,B*255); R=r; G=g; B=b; } void ModelParaSet::HslToRgb(float H, float S, float L, float &R, float &G, float &B) { float h = H;// h must be [0, 360] float s =S;// s must be [0, 1] float l = L;// l must be [0, 1] if(s == 0) { // achromatic color (gray scale) R = G = B =l; } else { float q = (l<0.5f)?(l * (1.0f+s)):(l+s - (l*s)); float p = (2.0f * l) - q; float Hk = h/360.0f; float T[3]; T[0] = Hk + 0.3333333f;// Tr0.3333333f=1.0/3.0 T[1] = Hk;// Tb T[2] = Hk - 0.3333333f;// Tg for(int i=0; i<3; i++) { if(T[i] < 0) T[i] += 1.0f; if(T[i] > 1) T[i] -= 1.0f; if((T[i]*6) < 1) { T[i] = p + ((q-p)*6.0f*T[i]); } else if((T[i]*2.0f) < 1) //(1.0/6.0)<=T[i] && T[i]<0.5 { T[i] = q; } else if((T[i]*3.0f) < 2) // 0.5<=T[i] && T[i]<(2.0/3.0) { T[i] = p + (q-p) * ((2.0f/3.0f) - T[i]) * 6.0f; } else T[i] = p; } R = T[0]*1.0f; G = T[1]*1.0f; B = T[2]*1.0f; } float r,b,g; r = (int)((R>1)? 1 : ((R<0)?0 : R)); g= (int)((G>1)? 1 : ((G<0)?0 : G)); b = (int)((B>1)? 1 : ((B<0)?0 : B)); R=r; G=g; B=b; } float ModelParaSet::MaxV(float a, float b, float c) { float m=a; if(b>c) { if(mc) { if(m>c) m=c; } else if(m>b) m=b; return m; }