diff --git a/common/geometryutils.cpp b/common/geometryutils.cpp index 88cefbe..69c0aaa 100644 --- a/common/geometryutils.cpp +++ b/common/geometryutils.cpp @@ -12,6 +12,50 @@ float mLineWidth=0.75; QString OilField; + +double GetData(int RepCode, char *buffer) +{ + double yy; + if (!buffer) return 0; + switch (RepCode) + { + case REPR_INT: //0 + yy = (double)(*((int*)buffer)); + break; + case REPR_SHORT: //1 + yy = (double)(*((short *)buffer)); + break; + case REPR_LONG://2 + yy = (double)(*((long *)buffer)); + break; + case REPR_FLOAT://3 + yy = (double)(*((float *)buffer)); + break; + case REPR_DOUBLE://4 + yy = (double)(*((double *)buffer)); + break; + case REPR_CHAR://5 + yy = (double)(*((char *)buffer)); + break; + case REPR_UCHAR://6 + yy = (double)(*((unsigned char *)buffer)); + break; + case REPR_USHORT://7 + yy = (double)(*((unsigned short *)buffer)); + break; + case REPR_UINT://8 + yy = (double)(*((unsigned int *)buffer)); + break; + case REPR_ULONG://9 + yy = (double)(*((unsigned long *)buffer)); + break; + case REPR_STRING://10 + yy = -99999; + break; + } + return yy; +} + QString setdec(QString text,int dec,bool all) { if(text.size()==0) return text; diff --git a/common/geometryutils.h b/common/geometryutils.h index 84e7504..f279359 100644 --- a/common/geometryutils.h +++ b/common/geometryutils.h @@ -168,6 +168,7 @@ typedef struct GEOLITH_Table char Dest[64]; } GeoLith_DATA; +double GetData(int RepCode, char *buffer); QString GetProjectFolder(); QString GetLogdataPath(); diff --git a/logPlus/formdraw.cpp b/logPlus/formdraw.cpp index ef9fb06..f33fcff 100644 --- a/logPlus/formdraw.cpp +++ b/logPlus/formdraw.cpp @@ -41,7 +41,6 @@ extern QString g_prjname; extern int g_iSupport3D; -double GetData(int RepCode,char *buffer); extern void AppendConsole(Priority priority, const QString &output); //曲线绘制(多个) @@ -148,6 +147,15 @@ void FormDraw::setDrawData(QStringList listdt, QJsonObject objInfo) if ("waveObject" == strType) { + curv->m_iY1 = m_iY1; + curv->m_iY2 = m_iY2; + curv->m_nMode = pInfo->getFillTypeIndex(); + //curv->m_fmin = pInfo->getVMin(); + //curv->m_fmax = pInfo->getVMax(); + curv->m_nColorNum = pInfo->m_nColorNum; + curv->m_nSchemeIndex = pInfo->m_nSchemeIndex; + curv->m_fScaleV = pInfo->getVMax(); + int _nSamples = 0; if (g_iSupport3D) { @@ -155,17 +163,9 @@ void FormDraw::setDrawData(QStringList listdt, QJsonObject objInfo) } else { - initWave(curv, m_strSlfName, strLineName, _nSamples); + //curv->initWave2(m_strSlfName, strLineName); + curv->initWave(m_strSlfName, strLineName); } - curv->m_nMode = pInfo->getFillTypeIndex(); - //curv->m_fmin = pInfo->getVMin(); - //curv->m_fmax = pInfo->getVMax(); - curv->m_nColorNum = pInfo->m_nColorNum; - curv->m_nSchemeIndex = pInfo->m_nSchemeIndex; - curv->initColorTable(); - curv->updateWave(); - float f = 264 / pInfo->getVMax(); - curv->m_colorMap->data()->setValueRange(QCPRange(curv->m_fmin, curv->m_fmax*f)); } // 深度 else if("depthObject" == strType) @@ -2501,49 +2501,6 @@ void FormDraw::initForm(QMyCustomPlot *widget, QString strSlfName, QString strLi //AppendConsole(PAI_INFO, "FormDraw initForm end"); } -double GetData(int RepCode,char *buffer) -{ - double yy; - if(!buffer) return 0; - switch(RepCode) - { - case REPR_INT: //0 - yy=(double)(*((int*)buffer)); - break; - case REPR_SHORT: //1 - yy=(double)(*((short *)buffer)); - break; - case REPR_LONG://2 - yy=(double)(*((long *)buffer)); - break; - case REPR_FLOAT://3 - yy=(double)(*((float *)buffer)); - break; - case REPR_DOUBLE://4 - yy=(double)(*((double *)buffer)); - break; - case REPR_CHAR://5 - yy=(double)(*((char *)buffer)); - break; - case REPR_UCHAR://6 - yy=(double)(*((unsigned char *)buffer)); - break; - case REPR_USHORT://7 - yy=(double)(*((unsigned short *)buffer)); - break; - case REPR_UINT://8 - yy=(double)(*((unsigned int *)buffer)); - break; - case REPR_ULONG://9 - yy=(double)(*((unsigned long *)buffer)); - break; - case REPR_STRING://10 - yy=-99999; - break; - } - return yy; -} - void FormDraw::initWave(QMyCustomPlot *widget, QString strSlfName, QString strWaveName, int &_nSamples) { CLogIO *logio=new CLogIO(); @@ -3178,146 +3135,6 @@ void FormDraw::DrawImageNew_NoFilter(QMyCustomPlot *widget, QString strSlfName, //widget->rescaleAxes(); } - -void FormDraw::initWave2(QMyCustomPlot *widget, QString strSlfName, QString strWaveName) -{ - CLogIO *logio=new CLogIO(); - logio->Open(strSlfName.toStdString().c_str(),CSlfIO::modeRead); - // - int index=logio->OpenWave(strWaveName.toStdString().c_str()); - if(index<0) { - delete logio; - return; - } - - - Slf_WAVE _wave; - logio->GetWaveInfo(index, &_wave); - float _SDep,_EDep,_Rlev; -// _SDep = _wave.StartDepth; -// _EDep = _wave.EndDepth; - - m_iY2 = 0 - _wave.StartDepth; - m_iY1 = 0 - _wave.EndDepth; - - _SDep = 0.0 - m_iY2; - _EDep = 0.0 - m_iY1; - _Rlev = _wave.DepLevel; - int m_Record=(float)(fabs((_EDep-_SDep)/_Rlev+0.5)); - - int _nSamples = _wave.TimeSamples; - - char *value=new char[(_nSamples+1)*m_Record*_wave.CodeLen+1]; - logio->ReadWave(index,_SDep,m_Record,(void *)value); - logio->CloseWave(index); - delete logio; - - bool bFistValue=false; - float vmax = (float)_nSamples; - float vmin = 0; - // - double** wavedata; - wavedata = new double*[_nSamples]; - for(int kk = 0;kk<_nSamples;kk++){ - wavedata[kk] = new double[m_Record]; - } - - for (int i=0; ival)vmin=val; - } - } - delete[] value; - -// m_iY1 = 0.0 -_EDep; -// m_iY2 = 0.0 -_SDep; - //------------------------ - widget->m_iX1 = vmin; - widget->m_iX2 = vmax; - widget->m_iY1 = m_iY1; - widget->m_iY2 = m_iY2; - // - widget->xAxis->setRange(vmin, vmax); - widget->yAxis->setRange(m_iY1, m_iY2); - widget->axisRect()->setupFullAxesBox(); - // - widget->xAxis->ticker()->setTickCount(10);//x个主刻度 - widget->yAxis->ticker()->setTickCount(60);//y个主刻度 - - //对调XY轴,在最前面设置 -// QCPAxis *yAxis = widget->yAxis; -// QCPAxis *xAxis = widget->xAxis; -// widget->xAxis = yAxis; -// widget->yAxis = xAxis; - - //注意,不对调XY轴 - widget->m_bX2Y = false; - float nPerHight = 50;//25 - float nSpace = 1; - for (int i=0; i x; - QVector y; - widget->addGraph(); - QString strLineName = ""; - if(strLineName=="") - { - strLineName = QString("曲线 %1").arg(widget->graphCount()); - } - widget->graph()->setName(strLineName); - - for(int kk = 0;kk<_nSamples;kk++) - { - //double val = wavedata[kk][m_Record-i-1]; - double val = wavedata[kk][i]; - if(val==-9999) - { - continue; - } - - //x.append(_nSamples-kk-1); - float tempValue = -(_SDep + nPerHight*_Rlev*i + (val*200*2)/vmax); - x.append(kk); - //float tempValue = -(_SDep + nSpace*i + (val*nPerHight*_Rlev*2)/vmax); - y.append(tempValue); - } - - widget->graph()->setData(x, y); - widget->graph()->setLineStyle((QCPGraph::LineStyle)(1));//曲线 - widget->graph()->setScatterStyle(QCPScatterStyle((QCPScatterStyle::ScatterShape)(1))); - // - QPen graphPen; - QColor newlineColor = QColor(std::rand()%245+10, std::rand()%245+10, std::rand()%245+10); - graphPen.setColor(newlineColor); - double width = 1; - graphPen.setWidthF(width); - graphPen.setStyle(Qt::SolidLine);//实线 - widget->graph()->setPen(graphPen); - //widget->replot(); - - if(i>=20) - break; - } -} - - //表格曲线 void FormDraw::initTableLine(QMyCustomPlot *widget, QString strSlfName, QString strLineName) { diff --git a/logPlus/formdraw.h b/logPlus/formdraw.h index 81ae41f..5651018 100644 --- a/logPlus/formdraw.h +++ b/logPlus/formdraw.h @@ -105,6 +105,7 @@ public: //波列 void initWave(QMyCustomPlot *widget, QString strSlfName, QString strWaveName, int &_nSamples); void initWave_3D(QMyCustomPlot *widget, QString strSlfName, QString strWaveName, int &_nSamples); + // 绘图类型-波形 void initWave2(QMyCustomPlot *widget, QString strSlfName, QString strWaveName); //图像-3d成图 diff --git a/logPlus/forminfo.cpp b/logPlus/forminfo.cpp index 0b2d388..c47e758 100644 --- a/logPlus/forminfo.cpp +++ b/logPlus/forminfo.cpp @@ -82,8 +82,8 @@ void FormInfo::initProperty(QJsonObject obj) QString strType = obj.value("Type").toString(); if ("waveObject" == strType) { - m_strDrawType = obj.value("DrawType").toString(); - m_strFillType = obj.value("FillType").toString(); + m_nDrawType = obj.value("DrawType").toInt(); + m_nFillType = obj.value("FillType").toInt(); m_strAmp = obj.value("Amp").toString(); m_fMaxAmp = obj.value("MaxAmp").toDouble(); m_nSchemeIndex = obj.value("SchemeIndex").toInt(); @@ -146,8 +146,8 @@ QJsonObject FormInfo::makeJson() } else if (m_strType == "waveObject") { - rootObj["DrawType"] = m_strDrawType; - rootObj["FillType"] = m_strFillType; + rootObj["DrawType"] = m_nDrawType; + rootObj["FillType"] = m_nFillType; rootObj["Amp"] = m_strAmp; rootObj["MaxAmp"] = m_fMaxAmp; @@ -571,10 +571,15 @@ bool FormInfo::setInfoProperty(QString strProName, QVariant val) { this->m_curveScaleFont = val.value(); } + else if ("类型" == strProName) + { + bDraw = true; + this->m_nDrawType = val.toInt(); + } else if ("方式" == strProName) { bDraw = true; - this->m_strFillType = val.toString(); + this->m_nFillType = val.toInt(); } else if ("左刻度" == strProName) { @@ -614,7 +619,7 @@ bool FormInfo::setInfoProperty(QString strProName, QVariant val) int FormInfo::getFillTypeIndex() { - return m_strFillType.toInt(); + return m_nFillType; } //修改曲线选择状态 iSelect=0未知,1标准曲线,2主曲线,3从曲线 diff --git a/logPlus/forminfo.h b/logPlus/forminfo.h index 5a10261..7ab1f07 100644 --- a/logPlus/forminfo.h +++ b/logPlus/forminfo.h @@ -98,8 +98,8 @@ public: int m_nJg; - QString m_strDrawType; // 绘图类型 - QString m_strFillType; // 填充类型 + int m_nDrawType; // 绘图类型 + int m_nFillType; // 填充类型 QString m_strAmp; // 幅度刻度 float m_fMaxAmp; // 最大振幅 bool m_bShowScale; // 显示刻度 diff --git a/logPlus/formtrack.cpp b/logPlus/formtrack.cpp index 9ec8b7f..9408121 100644 --- a/logPlus/formtrack.cpp +++ b/logPlus/formtrack.cpp @@ -365,6 +365,8 @@ void FormTrack::s_addWave(QString strSlfName, QString strWellName, QString strTr formInfo->setVMax(vmax); formInfo->setVMin(vmin); + formInfo->m_nDrawType = 2; + formInfo->m_nFillType = 1; formInfo->m_curveNameFont = QFont("黑体", 12); formInfo->m_curveUnitFont = QFont("黑体", 10); formInfo->m_curveScaleFont = QFont("黑体", 10); diff --git a/logPlus/qmycustomplot.cpp b/logPlus/qmycustomplot.cpp index 90720f5..77fd99d 100644 --- a/logPlus/qmycustomplot.cpp +++ b/logPlus/qmycustomplot.cpp @@ -16,6 +16,7 @@ #include "transparentdraggableSelectRect.h" #include "transparentdraggableRightList.h" #include "qtcommonclass.h" +#include "slf.h" //是否隐藏刻度 extern int g_iShow; @@ -103,6 +104,265 @@ QMyCustomPlot::QMyCustomPlot(QWidget *parent, QString strSlfName, QString strWel connect(CallManage::getInstance(), SIGNAL(sig_changeDrawProperty(QVariantList)), this, SLOT(s_changeDrawProperty(QVariantList))); } +void QMyCustomPlot::initWave(QString strSlfName, QString strWaveName) +{ + CLogIO *logio = new CLogIO(); + logio->Open(strSlfName.toStdString().c_str(), CSlfIO::modeRead); + // + int index = logio->OpenWave(strWaveName.toStdString().c_str()); + if (index < 0) { + delete logio; + return; + } + + QMyCustomPlot* widget = this; + Slf_WAVE _wave; + logio->GetWaveInfo(index, &_wave); + float _SDep, _EDep, _Rlev; + _SDep = _wave.StartDepth; + _EDep = _wave.EndDepth; + // _SDep = 0.0 - m_iY2; + // _EDep = 0.0 - m_iY1; + _Rlev = _wave.DepLevel; + int m_Record = (float)(fabs((_EDep - _SDep) / _Rlev + 0.5)); + + int _nSamples = _wave.TimeSamples; + + char *value = new char[(_nSamples + 1)*m_Record*_wave.CodeLen + 1]; + logio->ReadWave(index, _SDep, m_Record, (void *)value); + logio->CloseWave(index); + delete logio; + + bool bFistValue = false; + float vmax = -9999;//(float)_nSamples; + float vmin = -9999; + // + double** wavedata = widget->getWavedata(_nSamples, m_Record); + //wavedata = new double*[_nSamples]; + //for(int kk = 0;kk<_nSamples;kk++){ + // wavedata[kk] = new double[m_Record]; + //} + + for (int i = 0; i < m_Record; i++) + { + for (int kk = 0; kk < _nSamples; kk++) + { + double val = GetData(_wave.RepCode, (char *)&value[(kk)*_wave.CodeLen + i * _nSamples*_wave.CodeLen]); + wavedata[kk][i] = val; + if (val == -9999) + { + continue; + } + if (bFistValue == false) + { + //最大值,最小值默认采用第一个有效值 + bFistValue = true; + vmax = vmin = val; + } + // + if (vmax < val)vmax = val; + if (vmin > val)vmin = val; + } + } + delete[] value; + + // m_iY1 = 0.0 -_EDep; + // m_iY2 = 0.0 -_SDep; + //------------------------ + widget->m_iX1 = vmin; + widget->m_iX2 = vmax; + widget->m_iY1 = m_iY1; + widget->m_iY2 = m_iY2; + // + widget->xAxis->setRange(vmin, vmax); + widget->yAxis->setRange(m_iY1, m_iY2); + widget->axisRect()->setupFullAxesBox(); + // + widget->xAxis->ticker()->setTickCount(10);//x个主刻度 + widget->yAxis->ticker()->setTickCount(60);//y个主刻度 + + //对调XY轴,在最前面设置 + QCPAxis *yAxis = widget->yAxis; + QCPAxis *xAxis = widget->xAxis; + widget->xAxis = yAxis; + widget->yAxis = xAxis; + + widget->m_fmin = vmin; + widget->m_fmax = vmax; + + //------------------- + // set up the QCPColorMap: + if (widget->m_colorMap == NULL) + { + QCPColorMap *colorMap = new QCPColorMap(widget->xAxis, widget->yAxis); + widget->m_colorMap = colorMap; + + int nx = m_Record; + int ny = _nSamples; + colorMap->data()->setSize(nx, ny); // 我们希望彩色地图有nx*ny的数据点 + //colorMap->data()->setRange(QCPRange(m_iY1, m_iY2), QCPRange(vmin, vmax)); // 并在键(x)和值(y)维上跨越坐标范围-4..4 + colorMap->data()->setRange(QCPRange(0 - _EDep, 0 - _SDep), QCPRange(vmin, vmax)); + // :现在,我们通过访问颜色贴图的QCPColorMapData实例来分配一些数据: + this->updateWave(); + + // 添加色标: + QCPColorScale *colorScale = new QCPColorScale(widget); + colorMap->setColorScale(colorScale); // 将颜色图与色标关联 + // 重新缩放数据维度(颜色),以使所有数据点都位于颜色渐变显示的范围内: + colorMap->rescaleDataRange(); + + this->setSchemeIndex(m_nSchemeIndex, m_nColorNum); + } + else + { + this->updateWave(); + } +} + +void QMyCustomPlot::initWave2(QString strSlfName, QString strWaveName) +{ + QMyCustomPlot* widget = this; + CLogIO *logio = new CLogIO(); + logio->Open(strSlfName.toStdString().c_str(), CSlfIO::modeRead); + // + int index = logio->OpenWave(strWaveName.toStdString().c_str()); + if (index < 0) { + delete logio; + return; + } + + float vmax = 264;// (float)_nSamples; + float vmin = 0; + + widget->m_iX1 = vmin; + widget->m_iX2 = vmax; + // + widget->xAxis->setRange(vmin, vmax); + widget->yAxis->setRange(m_iY1, m_iY2); + widget->axisRect()->setupFullAxesBox(); + // + widget->xAxis->setTicks(false); + widget->yAxis->setTicks(false); + widget->xAxis2->setTicks(false); + widget->yAxis2->setTicks(false); + + //注意,不对调XY轴 + widget->m_bX2Y = false; + + Slf_WAVE _wave; + logio->GetWaveInfo(index, &_wave); + + float m_SDep = _wave.StartDepth; + float m_EDep = _wave.EndDepth; + float m_Rlev = _wave.DepLevel; + int m_Record = (float)(fabs((m_EDep - m_SDep) / m_Rlev + 0.5)); + int _nSamples = _wave.TimeSamples; + + char *value = new char[(_nSamples + 1)*m_Record*_wave.CodeLen + 1]; + logio->ReadWave(index, m_SDep, m_Record, (void *)value); + logio->CloseWave(index); + delete logio; + + MyDataTypeEnum vVdl; + int lpoint = 0; + int nPoint = _nSamples; + float detp = -m_iY2; + float edepc = -m_iY1; + float m_PlotSdep = -m_iY2; + float m_MoveDep = 0.0f; + float m_MaxRange = 1023.0f; + float m_Base = 0.0f; + float DifBase = (m_MaxRange - m_Base) / 1; + + int nStep = 600;// mWaveMes.m_WaveSpace; + if (nStep < 1) nStep = 1; + float m_r = m_Rlev * nStep; + detp = int((detp - m_PlotSdep) / m_r)*m_r + m_PlotSdep; + + int nidx = 0; + for (float dep1 = detp - m_r; dep1 < edepc + m_MoveDep + m_r; dep1 += m_r) + { + if (dep1 >= m_EDep || dep1 + m_r < m_SDep) + { + continue; + } + + int iIndex = Slf_Int(dep1 + m_MoveDep, m_SDep, m_Rlev); + if (iIndex < 0) { + continue; + } + + QVector vals; + if (iIndex < 0 || iIndex >= m_Record) + continue; + + vals.resize(nPoint); + vVdl.vchar = &((char *)value)[iIndex*_nSamples*_wave.CodeLen]; + + float nmy = 0; + for (int i = 0; i < nPoint; i++) + { + float ch = 0.0f; + if (i + lpoint < 0) + ch = 0; + else if (i + lpoint < _nSamples) { + if (_wave.RepCode == REPR_CHAR) { + ch = vVdl.vchar[i + lpoint]; + } + else if (_wave.RepCode == REPR_UCHAR) { + ch = vVdl.vuchar[i + lpoint]; + } + else if (_wave.RepCode == REPR_SHORT) { + ch = vVdl.vshort[i + lpoint]; + if (ch == -32767) ch = 0; + } + else if (_wave.RepCode == REPR_USHORT) { + ch = vVdl.vushort[i + lpoint]; + if ((short)ch == -32767) ch = 0; + } + else if (_wave.RepCode == REPR_FLOAT) { + ch = vVdl.vfloat[i + lpoint]; + } + //else + //ch = GetData(_wave.RepCode, (char *)&vVdl.vchar[(i + lpoint)*_wave.CodeLen]); + if (ch == -9999.0 || ch == -99999.0 || ch == -999.25) + ch = 0; + } + else ch = 0; + vals[i] = ch; + if (ch > nmy) + { + nmy = ch; + } + //if (objViewInfo->m_Logarithmic == AXIS_LOGARITHMIC || + // objViewInfo->m_maxRange == -99999) { + // if (vmin > ch) vmin = ch; + // if (vmax < ch) vmax = ch; + //} + } + + QVector vx; + QVector vy; + for (int i = 0; i < nPoint; i++) + { + vx << i; + vy << (-dep1 - 1) + vals[i] / nmy; + } + + QCPGraph * graph = widget->graph(nidx); + if (graph == NULL) + { + graph = widget->addGraph(); + //graph->setPen(QPen(clor)); + } + graph->setData(vx, vy); + nidx++; + } + widget->replot(); + + delete[]value; +} + void QMyCustomPlot::initColorTable() { this->setSchemeIndex(m_nSchemeIndex, m_nColorNum); @@ -978,7 +1238,40 @@ void QMyCustomPlot::s_changeDrawProperty(QVariantList vlist) { QString strProperty = vlist.at(5).toString(); QString strValue = vlist.at(6).toString(); - if ("方式" == strProperty) + if ("类型" == strProperty) + { + if (strValue == "0") + { + if (this->m_colorMap) + this->m_colorMap->setVisible(false); + for (int i = 0; i < graphCount(); i++) + { + graph(i)->setVisible(true); + } + + if (this->m_bX2Y) + { + QCPAxis *yAxis = this->yAxis; + QCPAxis *xAxis = this->xAxis; + this->xAxis = yAxis; + this->yAxis = xAxis; + this->m_bX2Y = false; + } + this->initWave2(m_strSlfName, m_strLineName); + } + else if (strValue == "2") + { + if (this->m_colorMap) + this->m_colorMap->setVisible(true); + for (int i = 0; i < graphCount(); i++) + { + graph(i)->setVisible(false); + } + this->m_bX2Y = true; + this->initWave(m_strSlfName, m_strLineName); + } + } + else if ("方式" == strProperty) { m_nMode = strValue.toFloat(); this->updateWave(); diff --git a/logPlus/qmycustomplot.h b/logPlus/qmycustomplot.h index 25ccc46..9f53d15 100644 --- a/logPlus/qmycustomplot.h +++ b/logPlus/qmycustomplot.h @@ -21,6 +21,10 @@ public: { } + void initWave(QString strSlfName, QString strWaveName); + void initWave2(QString strSlfName, QString strWaveName); + + void initColorTable(); void setSchemeIndex(int nidx, int colorNum); double** getWavedata(int nrow, int ncol); @@ -73,6 +77,7 @@ public: int m_nCol = 0; // 0.全周 1.正半周 2.负半周 int m_nMode = 1; + float m_fScaleV = 264.0f; float m_fmin; float m_fmax; int m_nColorNum = 256;