logplus/ModuleConsole/modelparaset.cpp

1893 lines
36 KiB
C++
Raw Normal View History

2026-01-16 17:18:41 +08:00
#include "modelparaset.h"
#include "FaultLine.h"
#include <qcolordialog.h>
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<FaultLine>();
lineCells=new QList<Cell *>();
appointPoint=new Point3D();
nearPoints=new QList<Point3D>();
m_pColorTable=new PaiColorTableData("Color Scheme",true);
m_pColorTable->SetCurrentSchemeIndex(5);
blockNum=40;
m_pColorTable->ChangeColorNum(blockNum);
//////////////////////////////////////////
QList<QRgb> 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<<endDepth;
ds<<GetColorFromCOLORREF( m_endColor);
ds<<GetColorFromCOLORREF( m_curColor);
ds<<GetColorFromCOLORREF( m_staColor);
int n=m_colData.count();
ds<<n;
for(int i=0;i<n;i++)
{
QColor clr=GetColorFromCOLORREF(m_colData[i]);
ds<<clr;
}
ds<<m_staData.count();
for(int i=0;i<n;i++)
{
float s,e;
ds<<m_staData[i];
ds<<m_endData[i];
}
ds<< blockNum;
ds<<isGradientMod;
ds<<isIntenseMod;
ds<<isLogMod;
ds<<itemStart;
ds<<itemEnd;
ds<<isHsvMod;
ds<<GetColorFromCOLORREF( itemStaColor);
ds<<GetColorFromCOLORREF( itemEndColor);
}
else
{
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<n;i++)
{
QColor clr;
ds>>clr;
COLORREF c=RGB(clr.red(),clr.green(),clr.blue());;
m_colData.append(c);
}
ds>>n;
for(int i=0;i<n;i++)
{
float s,e;
ds>>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<<minx;
ds<<maxx;
ds<<miny;
ds<<maxy;
ds<<dx;
ds<<dy;
ds<<isShowLight;
ds<<isShowAttributeLegend;
ds<<isChooseRange;
//QList<QString> layerName1;
int count=layerName1.count();
ds<<count;
for(int i=0;i<count;i++)
{
ds<<layerName1[i];
}
//QList<QString> layerName2;
count=layerName2.count();
ds<<count;
for(int i=0;i<count;i++)
{
ds<<layerName2[i];
}
//QList<QString> modelLayerName;
count=modelLayerName.count();
ds<<count;
for(int i=0;i<count;i++)
{
ds<<modelLayerName[i];
}
//QList<bool> IsBuild;
count=IsBuild.count();
ds<<count;
for(int i=0;i<count;i++)
{
ds<<IsBuild[i];
}
//QList<bool> IsShowModel;
count=IsShowModel.count();
ds<<count;
for(int i=0;i<count;i++)
{
ds<<IsShowModel[i];
}
//QList<bool> IsShowLineModel;
count=IsShowLineModel.count();
ds<<count;
for(int i=0;i<count;i++)
{
ds<<IsShowLineModel[i];
}
//QList<int> layerNumber;
count=layerNumber.count();
ds<<count;
for(int i=0;i<count;i++)
{
ds<<layerNumber[i];
}
ds<<Attribute;
//QList<bool> IsBuildAttrModel;
count=IsBuildAttrModel.count();
ds<<count;
for(int i=0;i<count;i++)
{
ds<<IsBuildAttrModel[i];
}
//QList<bool> IsShowAttrModel;
count=IsShowAttrModel.count();
ds<<count;
for(int i=0;i<count;i++)
{
ds<<IsShowAttrModel[i];
}
//QList<int> getValueWay;
count=getValueWay.count();
ds<<count;
for(int i=0;i<count;i++)
{
ds<<getValueWay[i];
}
SerializableColorPanel(ds);
}
else
{
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<count;i++)
{
QString layername;
ds>>layername;
layerName1.append(layername);
}
ds>>count;
for(int i=0;i<count;i++)
{
QString layername;
ds>>layername;
layerName2.append(layername);
}
//QList<QString> modelLayerName;
ds>>count;
for(int i=0;i<count;i++)
{
QString layername;
ds>>layername;
modelLayerName.append(layername);
}
//QList<bool> IsBuild;
ds>>count;
for(int i=0;i<count;i++)
{
bool isbuild;
ds>>isbuild;
IsBuild.append(isbuild);
}
//QList<bool> IsShowModel;
ds>>count;
for(int i=0;i<count;i++)
{
bool isshow;
ds>>isshow;
IsShowModel.append(isshow);
}
//QList<bool> IsShowLineModel;
ds>>count;
for(int i=0;i<count;i++)
{
bool isshow;
ds>>isshow;
IsShowLineModel.append(isshow);
}
//QList<int> layerNumber;
ds>>count;
for(int i=0;i<count;i++)
{
int layernum;
ds>>layernum;
layerNumber.append(layernum);
}
ds>>Attribute;
//QList<bool> IsBuildAttrModel;
ds>>count;
for(int i=0;i<count;i++)
{
bool isbuild;
ds>>isbuild;
IsBuildAttrModel.append(isbuild);
}
//QList<bool> IsShowAttrModel;
ds>>count;
for(int i=0;i<count;i++)
{
bool isshow;
ds>>isshow;
IsShowAttrModel.append(isshow);
}
//QList<int> getValueWay;
ds>>count;
for(int i=0;i<count;i++)
{
int getvalue;
ds>>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;//<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ʼ<EFBFBD><CABC>ɫ
float m=0,n=0,temp=0,preSta=0,preEnd=0;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
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();//<2F><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><E9B3A4>
preStaColor=m_colData[0];
preEndColor=m_colData[nItem-1];
if (startDepth>m_endData[nItem-1])//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܵ<EFBFBD><DCB5><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>ȴ<EFBFBD><C8B4>ڼ<EFBFBD><DABC><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD>ȣ<EFBFBD><C8A3>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3>Դ˴<D4B4><CBB4><EFBFBD><EFBFBD>ݳ<EFBFBD>ʼ<EFBFBD><CABC>
{
m_staData.clear();
m_endData.clear();
m_colData.clear();
Initial();
return FALSE;
}
for(i=0;i<nItem;i++)//<2F><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0>Ҫ<EFBFBD><D2AA><EFBFBD>ܵĶϵ<C4B6>
{
if (startDepth>=m_staData[i]&&startDepth<m_endData[i])
break;
}
virStaColor=m_colData[i];//<2F><>ȡ<EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ɫ
if (i==0)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>λ<EFBFBD>ڵ<EFBFBD>һ<EFBFBD><D2BB>ʱ
{
if (startDepth!=m_staData[i])//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>Ȳ<EFBFBD><C8B2><EFBFBD><EFBFBD>ڼ<EFBFBD><DABC><EFBFBD>ǰ<EFBFBD><C7B0>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
{
i++;//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
}
}
if (isGradientMod==1)
{
if (i==nItem-2)
{
virStaColor=m_colData[i];
virEndColor=m_colData[i+1];
m_staData.removeAt(i+1);
m_endData.removeAt(i+1);
m_colData.removeAt(i+1);
itemStart=i+1;
itemEnd=i+1+blockNum;
itemStaColor=virStaColor;
itemEndColor=virEndColor;
Initial();
if (isLogMod==1)
{
for (int k=i+1;k<i+1+blockNum;k++)
{
float m,n;
m=m_staData[k]/(endDepth/startDepth);
n=m_endData[k]/(endDepth/startDepth);
m_staData.removeAt(k);
m_staData.insert(k,m);
m_endData.removeAt(k);
m_endData.insert(k,n);
}
}
return TRUE;
}
}
if (i==nItem-1)
{
virStaColor=m_colData[i-1];
virEndColor=m_colData[i];
m_staData.removeAt(i);
m_endData.removeAt(i);
m_colData.removeAt(i);
itemStart=i;
itemEnd=i+blockNum;
itemStaColor=virStaColor;
itemEndColor=virEndColor;
Initial();
//if (isLogMod==1)
//{
// for (int k=i;k<i+blockNum;k++)
// {
// float m,n;
// m=m_staData[k)/(endDepth/startDepth);
// n=m_endData[k)/(endDepth/startDepth);
// m_staData.removeAt(k);
// m_staData.insert(k,m);
// m_endData.removeAt(k);
// m_endData.insert(k,n);
// }
//}
return TRUE;
}
if (i>0)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>ݲ<EFBFBD><DDB2>ڵ<EFBFBD>һ<EFBFBD><D2BB>ʱ
{
m_endData.removeAt(i-1);//ʹ<><CAB9><EFBFBD>ܺ<EFBFBD><DCBA><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>
m_endData.insert(i-1,startDepth);
}
if (endDepth>m_endData[nItem-1])//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD>ݴ<EFBFBD><DDB4>ڼ<EFBFBD><DABC><EFBFBD>ǰ<EFBFBD><C7B0>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>
{
virEndColor=m_endColor;
int k;
for (k=i;k<nItem;k++)
{
m_staData.removeAt(i);//<2F>Ƴ<EFBFBD><C6B3><EFBFBD>ǰ<EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD>Ϣ
m_endData.removeAt(i);
m_colData.removeAt(i);
}
//<2F>Ӽ<EFBFBD><D3BC><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>ݴ<EFBFBD>ֱ<EFBFBD>ӳ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
itemStart=i;
itemEnd=blockNum;
itemStaColor=virStaColor;
itemEndColor=virEndColor;
Initial();
if (isLogMod==1)
{
for (k=i;k<i+blockNum;k++)
{
float m,n;
m=m_staData[k]/(endDepth/startDepth);
n=m_endData[k]/(endDepth/startDepth);
m_staData.removeAt(k);
m_staData.insert(k,m);
m_endData.removeAt(k);
m_endData.insert(k,n);
}
}
}
else
{
for(j=0;j<nItem;j++)//<2F><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0>Ҫ<EFBFBD><D2AA><EFBFBD>ܵĶϵ<C4B6>
{
if (endDepth<=m_endData[j])
break;
}
virEndColor=m_colData[j];//<2F><>ȡ<EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹ<EFBFBD><D6B9>ɫ
if (i==j&&j<nItem-1&&j!=0)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>ͬһ<CDAC>У<EFBFBD><D0A3><EFBFBD><EFBFBD>Ҳ<EFBFBD><D2B2>ڵ<EFBFBD>һ<EFBFBD>к<EFBFBD><D0BA><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ʱ
{
m_endData.removeAt(i-1);//<2F><>֤<EFBFBD><D6A4><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
m_endData.insert(i-1,startDepth);
}
if (j<nItem-1)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD>ݲ<EFBFBD><DDB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ʱ
{
m_staData.removeAt(j+1);//<2F><>֤<EFBFBD><D6A4><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
m_staData.insert(j+1,endDepth);
}
if (isGradientMod==0)
{
if (j==nItem-1)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ʱ
{
preSta=m_staData[j];
preEnd=m_endData[j]; //<2F><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>
preColor=m_colData[j];
}
}
else
{
if (j==nItem-2)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ʱ
{
preEnd=m_endData[j+1]; //<2F><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>
preColor=m_colData[j+1];
virEndColor=m_colData[j+1];
}
}
int k;
for (k=i;k<=j;k++)
{
m_staData.removeAt(i);//<2F>Ƴ<EFBFBD><C6B3><EFBFBD>ǰ<EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD>Ϣ
m_endData.removeAt(i);
m_colData.removeAt(i);
}
r_sta = GetRValue(virStaColor);//<2F><>ȡRGBֵ
g_sta = GetGValue(virStaColor);
b_sta = GetBValue(virStaColor);
r_end = GetRValue(virEndColor);
g_end = GetGValue(virEndColor);
b_end = GetBValue(virEndColor);
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(virStaColor,h_sta,s_sta,v_sta);
RgbToHsl(virEndColor,h_end,s_end,v_end);
}
}
m=startDepth;
for (k=i;k<i+blockNum;k++)
{
if (isGradientMod==0)
{
if (isHsvMod)
{
h_cur=h_sta+(k-i)*(h_end-h_sta)/(blockNum-1);
s_cur=s_sta+(k-i)*(s_end-s_sta)/(blockNum-1);
v_cur=v_sta+(k-i)*(v_end-v_sta)/(blockNum-1);
}
else
{
r_cur=r_sta+(k-i)*(r_end-r_sta)/(blockNum-1);
g_cur=g_sta+(k-i)*(g_end-g_sta)/(blockNum-1);
b_cur=b_sta+(k-i)*(b_end-b_sta)/(blockNum-1);
}
}
else
{
if (isHsvMod)
{
h_cur=h_sta+(k-i)*(h_end-h_sta)/blockNum;
s_cur=s_sta+(k-i)*(s_end-s_sta)/blockNum;
v_cur=v_sta+(k-i)*(v_end-v_sta)/blockNum;
}
else
{
r_cur=r_sta+(k-i)*(r_end-r_sta)/blockNum;
g_cur=g_sta+(k-i)*(g_end-g_sta)/blockNum;
b_cur=b_sta+(k-i)*(b_end-b_sta)/blockNum;
}
}
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,m_curColor);
}
}
else
m_curColor=RGB(r_cur,g_cur,b_cur);
if (isLogMod==1)
{
temp=log10(endDepth/startDepth)/(blockNum*1.0);
n=pow(10,(temp*(k-i+1)+log10(startDepth)));
}
else
{
temp=(endDepth-startDepth)/(blockNum*1.0);
n=m+temp;
}
m_staData.insert(k,m);//<2F><><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EBB5BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
m_endData.insert(k,n);
m_colData.insert(k,m_curColor);
m=n;
}
n=endDepth;
m_endData.removeAt(i+blockNum-1);
m_endData.insert(i+blockNum-1,n);//ȷ<><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD>
}
if (isGradientMod==1)
{
if (j==nItem-2)
{
m_staData.append(preEnd);
m_endData.append(preEnd);
m_colData.append(preColor);
}
}
else
{
if (j==nItem-1)
{
m_staData.insert(i+blockNum,endDepth);
m_endData.insert(i+blockNum,preEnd);
m_colData.insert(i+blockNum,preColor);
}
}
return TRUE;
}
BOOL ModelParaSet::Initial()
{
if(!m_pColorTable) return FALSE;
float m=0,n=0,temp=0;
int i=0;
m_pColorTable->ChangeColorNum(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<itemEnd;i++)
{
if (isGradientMod==0)
{
r_cur=r_sta+(i-itemStart)*(r_end-r_sta)/(blockNum-1);
g_cur=g_sta+(i-itemStart)*(g_end-g_sta)/(blockNum-1);
b_cur=b_sta+(i-itemStart)*(b_end-b_sta)/(blockNum-1);
}
else
{
r_cur=r_sta+(i-itemStart)*(r_end-r_sta)/blockNum;
g_cur=g_sta+(i-itemStart)*(g_end-g_sta)/blockNum;
b_cur=b_sta+(i-itemStart)*(b_end-b_sta)/blockNum;
}
m_curColor=RGB(r_cur,g_cur,b_cur);
if (isLogMod==1)
{
if(startDepth==0)startDepth=0.01;
temp=log10(endDepth/startDepth)/(blockNum*1.0);
n=pow(10,(temp*(i+1-itemStart)+log10(startDepth)));
}
else
{
temp=(endDepth-startDepth)/(blockNum*1.0);
n=m+temp;
}
m_staData.append(m);
m_endData.append(n);
m_colData.append(m_curColor);
m=n;
}
}
n=endDepth;
m_endData.removeAt(itemEnd-1);
m_endData.insert(itemEnd-1,n);
m_staData.removeAt(itemStart);
m_staData.insert(itemStart,startDepth);
if (isGradientMod==0)
{
m_colData.removeAt(itemEnd-1);
m_colData.insert(itemEnd-1,m_endColor);
}
else
{
m_staData.append(endDepth);
m_endData.append(endDepth);
m_colData.append(m_endColor);
}
QList<QRgb> rgbList=m_pColorTable->GetRgb();
m_colData.clear();
for(int i=0;i<rgbList.size();i++)
{
QColor acolor=rgbList.at(i);
m_colData.append(RGB(acolor.red(),acolor.green(),acolor.blue()));
}
return TRUE;
}
void ModelParaSet::SelectStaColor()
{
QColorDialog color;
m_staColor = color.getRgba();
//if (IDOK==dlg.DoModal())
//{
// m_staColor=dlg.m_cc.rgbResult;
//}
}
void ModelParaSet::SelectEndColor()
{
//CColorDialog dlg;
//dlg.m_cc.Flags|=CC_FULLOPEN|CC_RGBINIT;
//dlg.m_cc.rgbResult=m_endColor;
//if (IDOK==dlg.DoModal())
//{
// m_endColor=dlg.m_cc.rgbResult;
//}
QColorDialog color;
m_endColor = color.getRgba();
}
BOOL ModelParaSet::Delete()
{
m_staData.clear();
m_endData.clear();
m_colData.clear();
return TRUE;
}
void ModelParaSet::Save()
{
// CFileDialog m_nFileDlg(FALSE);
//m_nFileDlg.m_ofn.lpstrFilter="color files(*.clr)\0*.clr\0\0";
//m_nFileDlg.m_ofn.lpstrDefExt="clr";
//if (IDOK==m_nFileDlg.DoModal())
//{
// CFile file(m_nFileDlg.GetFileName(),CFile::modeCreate|CFile::modeWrite);
// CArchive ar(&file,CArchive::store);
// Serialize(ar);
// int nItem=m_staData.count();
// ar.Close();
// // <20>ر<EFBFBD><D8B1>ļ<EFBFBD>
// file.Close();
//}
}
BOOL ModelParaSet::Open(int model,float startDepth,float endDepth)
{
//CFileDialog m_nFileDlg(TRUE);
//m_nFileDlg.m_ofn.lpstrFilter = "color file(*.clr)\0*.clr\0\0";
//COLORREF colData;
//int nItem,selection;
//float staData=0,endData=0;
//if (IDOK == m_nFileDlg.DoModal())
//{
// CFile file(m_nFileDlg.GetFileName(),CFile::modeRead);
// // <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB> CArchive <20><><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// CArchive ar(&file,CArchive::load);
// m_staData.clear();
// m_endData.clear();
// m_colData.clear();
// m_nSelection.clear();
// Serialize(ar);
// int i;
//
// nItem=m_colData.count();
// if(nItem>0)
// {
// 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<nItem; i++)
// {
// staData=(m_staData[i]-oldStartV)*temp+startDepth;
// m_staData.removeAt(i);
// m_staData.insert(i,staData);
// endData=(m_endData[i)-oldStartV)*temp+startDepth;
// m_endData.removeAt(i);
// m_endData.insert(i,endData);
// }
// }
// }
// // <20>ر<EFBFBD><D8B1>ĵ<EFBFBD>
// ar.Close();
// // <20>ر<EFBFBD><D8B1>ļ<EFBFBD>
// file.Close();
//}
//else
// return FALSE;
return TRUE;
}
COLORREF ModelParaSet::GetColor(float value)
{
int model=isGradientMod;
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.count()-1;i++)
{
if (value>=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.count()-1;i++)
{
if (value>=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.count()-1;i++)
{
if (value>=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 <float> m_staOldData;
QList <float> m_endOldData;
QList <COLORREF> m_colOldData;
QList <int> 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<m_endData.count()-1;i++)
{
if (m_endOldData[i]!=m_endData[i])
{
break;
}
}
if (i==nItem)
{
return FALSE;
}
temp=m_endOldData[nItem-1];
if (tempData>=temp)
{
if(col==2 && row==m_endOldData.count()-1 && tempData>=m_endOldData[row])
return TRUE;
if (row<nItem-1)
{
for (j=row;j<nItem-1;j++)
{
m_staData.removeAt(row+1);
m_endData.removeAt(row+1);
m_colData.removeAt(m_colData.count()-1);
}
}
//m_endData.removeAt(row);
//m_endData.insert(row,tempData);
m_endData[row]=tempData;
if (col==1)
{
if (isGradientMod==0)
{
if(row!=0)
{
m_staData.removeAt(row);
m_endData.removeAt(row);
m_colData.removeAt(row);
}
}
}
}
else
{
if(col==1 && row==0 && tempData<=m_staOldData[0])
return TRUE;
if(col==2 && row==m_endOldData.count()-1 && tempData>=m_endOldData[row])
return TRUE;
for(i=0;i<m_staData.count();i++)
{
if (tempData>=m_staOldData[i]&&tempData<m_endOldData[i])
{
break;
}
}
if (row<i)
{
if (col==1)
{
for (j=row;j<i;j++)
{
m_staData.removeAt(row+1);
m_endData.removeAt(row);
m_colData.removeAt(m_colData.count()-1);
}
}
else
{
if (row==0)
{
if (i<nItem-1)
{
m_staData.removeAt(row+2);
m_endData.removeAt(row+1);
m_colData.removeAt(m_colData.count()-1);
}
}
for (j=row;j<i-1;j++)
{
m_staData.removeAt(row+2);
m_endData.removeAt(row+1);
m_colData.removeAt(m_colData.count()-1);
}
}
}
else
{
if (col==1)
{
if (row!=(i+1))
{
for (j=i;j<row;j++)
{
m_staData.removeAt(i);
m_endData.removeAt(i-1);
m_colData.removeAt(m_colData.count()-1);
}
}
}
else
{
if (i!=0)
{
for (j=i;j<=row;j++)
{
m_staData.removeAt(i);
m_endData.removeAt(i-1);
m_colData.removeAt(m_colData.count()-1);
}
}
else
{
for (j=i;j<row;j++)
{
m_staData.removeAt(i+1);
m_endData.removeAt(i);
m_colData.removeAt(m_colData.count()-1);
}
}
}
}
}
return TRUE;
}
void ModelParaSet::HsvToRgb(float H, float S, float V, float &R, float &G, float &B)
{
int i;
float f, p, q, t;
if( S == 0 )
{
// achromatic (grey)
R = G = B = V;
return;
}
H /= 60; // sector 0 to 5
i = int( H );
f = H - i; // factorial part of h
p = (V * ( 1 - S ));
q = (V * ( 1 - S * f ));
t = (V * ( 1 - S * ( 1 - f ) ));
switch(i)
{
case 0:
R = V;
G = t;
B = p;
break;
case 1:
R = q;
G = V;
B = p;
break;
case 2:
R = p;
G = V;
B = t;
break;
case 3:
R = p;
G = q;
B = V;
break;
case 4:
R = t;
G = p;
B = V;
break;
default: // case 5:
R = V;
G = p;
B = q;
break;
}
}
void ModelParaSet::RgbToHsv(float R, float G, float B, float &H, float &S, float &V)
{
// 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 );
V = max; // v
delta = max - min;
if( max != 0 )
S = float(delta)/ max; // s
else
{
// r = g = b = 0 // s = 0, v is undefined
S = 0;
H = 0;
return;
}
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;
}
void ModelParaSet::RgbToHsl(COLORREF color, float &H, float &S, float &L)
{
float R,G,B;
R=GetRValue(color)/255.0;
G=GetGValue(color)/255.0;
B=GetBValue(color)/255.0;
// 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 && g<b)
{
h = 60.0f*(g-b)/(maxVal-minVal) + 360.0f;
}
else if(maxVal==g)
{
h = 60.0f*(b-r)/(maxVal-minVal) + 120.0f;
}
else if(maxVal==b)
{
h = 60.0f*(r-g)/(maxVal-minVal) + 240.0f;
}
// luminance
l = (maxVal+minVal)/2.0f;
// saturation
if(l == 0 || maxVal == minVal)
{
s = 0;
}
else if(0<l && l<=0.5f)
{
s = (maxVal-minVal)/(maxVal+minVal);
}
else if(l>0.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 && g<b)
{
h = 60.0f*(g-b)/(maxVal-minVal) + 360.0f;
}
else if(maxVal==g)
{
h = 60.0f*(b-r)/(maxVal-minVal) + 120.0f;
}
else if(maxVal==b)
{
h = 60.0f*(r-g)/(maxVal-minVal) + 240.0f;
}
// luminance
l = (maxVal+minVal)/2.0f;
// saturation
if(l == 0 || maxVal == minVal)
{
s = 0;
}
else if(0<l && l<=0.5f)
{
s = (maxVal-minVal)/(maxVal+minVal);
}
else if(l>0.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(m<b)
m=b;
}
else
if(m<c)
m=c;
return m;
}
float ModelParaSet::MinV(float a, float b, float c)
{
float m=a;
if(b>c)
{
if(m>c)
m=c;
}
else
if(m>b)
m=b;
return m;
}