#include <GroundModelViewer.h>
Public Slots | |
void | exportModels () |
void | minMaxProfiles () |
void | saveAsReport () |
Public Member Functions | |
GroundModelViewer (QWidget *parent=0) | |
~GroundModelViewer () | |
Protected Member Functions | |
virtual bool | hasCurves (DCReportBlock &) |
virtual void | report2plot (DCReportBlock &dcBlock, Point2D **points, const DCModelInfo &info) |
virtual void | setGlobalLimits (const Rect &) |
virtual void | setLimits (int i, const Rect &r) |
virtual void | setSampleCount (DCModelInfo *info, DCReportBlock &dcBlock) |
virtual void | setTitles (int i) |
virtual AbstractLine * | targetReferenceLine () const |
DinverDCGui::GroundModelViewer::GroundModelViewer | ( | QWidget * | parent = 0 | ) |
References DinverDCGui::DCModelViewer::addMenu(), exportModels(), minMaxProfiles(), saveAsReport(), DinverDCGui::DCModelViewer::setLimits(), QGpCoreTools::tr(), and TRACE.
: DCModelViewer(parent) { TRACE; Settings::getSize(this, "GroundModelViewer" ); setWindowTitle(tr("Ground profiles:")); // Tools menu // TODO: move tool menu to DCModelViewer (especially "Save as report") QMenu * m; QAction * a; m=addMenu(tr("&Tools")); a=new QAction(tr( "Add reference model" ), this); a->setStatusTip(tr( "Import any .model file and plot its Vp, Vs and density" )); connect(a, SIGNAL(triggered()), this, SLOT(setLimits()) ); m->addAction(a); a=new QAction(tr( "Add Min/Max profiles" ), this); a->setStatusTip(tr( "Compute the mininum and maximum profiles" )); connect(a, SIGNAL(triggered()), this, SLOT(minMaxProfiles()) ); m->addAction(a); m->addSeparator(); a=new QAction(tr("Save as report"), this); a->setStatusTip(tr("Save models and their curves in a .report file")); connect(a, SIGNAL(triggered()), this, SLOT(saveAsReport())); m->addAction(a); a=new QAction(tr("Export models"), this); a->setStatusTip(tr("Export profiles in a .model file, e.g. to process them with gpdc")); connect(a, SIGNAL(triggered()), this, SLOT(exportModels())); m->addAction(a); }
void DinverDCGui::GroundModelViewer::exportModels | ( | ) | [slot] |
References DinverDCGui::DCModelViewer::_models, QGpCoreWave::Profile::depths(), fileName, iModel, DinverDCCore::DCModelInfo::indexInReport(), MSG_ID, DinverDCCore::DCReportBlock::readProfiles(), QGpCoreWave::Profile::readReport(), DinverDCCore::DCModelInfo::report(), QGpCoreWave::Profile::resample(), DinverCore::ReportReader::stream(), QGpCoreWave::Seismic1DModel::toStream(), QGpCoreTools::tr(), TRACE, QGpCoreTools::unique(), DinverCore::ReportReader::userBlockVersion(), and QGpCoreWave::Profile::values().
Referenced by GroundModelViewer().
{ TRACE; QString fileName=Message::getSaveFileName(tr("Export models ..."), tr("Model file (*.model)")); if(fileName.length()>0) { QFile f(fileName); if( !f.open(QIODevice::WriteOnly) ) { Message::warning(MSG_ID, tr("Exporting models"), tr("Cannot open file for writing"), Message::cancel()); return; } QTextStream s(&f); qSort(_models.begin(),_models.end(), DCModelInfo::loadLessThan); int nModels=_models.count(); for(int iModel=0;iModel<nModels;iModel++) { DCModelInfo& info=*_models[iModel]; ReportReader& report=*info.report(); int version=report.userBlockVersion(info.indexInReport(), "DISP"); if(version>=0) { DCReportBlock dcBlock(report.stream()); dcBlock.readProfiles(version); Profile vp, vs, rho; if(dcBlock.vp()) vp.readReport(dcBlock.stream()); else continue; if(dcBlock.vs()) vs.readReport(dcBlock.stream()); else continue; if(dcBlock.rho()) rho.readReport(dcBlock.stream()); else continue; // These are raw profiles without the same depth sampling QVector<double> depths; depths << vp.depths(); depths << vs.depths(); depths << rho.depths(); qSort(depths); unique(depths); vp.resample(depths); vs.resample(depths); rho.resample(depths); Seismic1DModel * surfModel = DCReportBlock::surfaceWaveModel(depths, vp.values(), vs.values(), rho.values()); surfModel->toStream(s); delete surfModel; } } } }
virtual bool DinverDCGui::GroundModelViewer::hasCurves | ( | DCReportBlock & | ) | [inline, protected, virtual] |
Implements DinverDCGui::DCModelViewer.
{return true;}
void DinverDCGui::GroundModelViewer::minMaxProfiles | ( | ) | [slot] |
References DinverDCGui::DCModelViewer::_graphs, DinverDCGui::DCModelViewer::_models, DinverDCGui::DCModelViewer::_nGraphs, SciFigs::LineLayer::addLine(), SciFigs::GraphContentLayer::deepUpdate(), iModel, DinverDCCore::DCModelInfo::indexInReport(), SciFigs::Axis::maximum(), SciFigs::Axis::minimum(), DinverDCCore::DCReportBlock::readProfiles(), QGpCoreWave::Profile::readReport(), DinverDCCore::DCModelInfo::report(), QGpCoreTools::Curve< pointType >::resize(), SciFigs::AbstractLine::setPen(), SciFigs::LineLayer::setReferenceLine(), SciFigs::AbstractLine::setSymbol(), QGpCoreTools::Point2D::setX(), DinverCore::ReportReader::stream(), TRACE, QGpCoreWave::Profile::uniformAt(), DinverCore::ReportReader::userBlockVersion(), QGpCoreTools::Point2D::x(), and SciFigs::AxisWindow::yAxis().
Referenced by GroundModelViewer().
{ TRACE; int n=_nGraphs; if(n>5) n=5; // Take 100 samples on current axis limits and init vectors for all graphs Curve<Point2D> * minCurves=new Curve<Point2D>[n]; Curve<Point2D> * maxCurves=new Curve<Point2D>[n]; for(int i=0;i<n;i++) { Curve<Point2D>& vMin=minCurves[i]; vMin.resize(100); Curve<Point2D>& vMax=maxCurves[i]; vMax.resize(100); double minDepth=_graphs[i]->yAxis()->minimum(); double maxDepth=_graphs[i]->yAxis()->maximum(); double dDepth=(maxDepth-minDepth)*0.01; for(int j=0;j<100;j++) { double d=minDepth+j*dDepth; vMin[j].setX(1e99); vMax[j].setX( -1e99); vMin[j].setY(d); vMax[j].setY(d); } } // Check all profile and update min and max vectors qSort(_models.begin(),_models.end(), DCModelInfo::loadLessThan); int nModels=_models.count(); for(int iModel=0;iModel<nModels;iModel++) { DCModelInfo& info=*_models[iModel]; ReportReader& report=*info.report(); int version=report.userBlockVersion(info.indexInReport(), "DISP"); if(version>=0) { DCReportBlock dcBlock(report.stream()); dcBlock.readProfiles(version); for(int i=0;i<n;i++) { if(dcBlock.profile(i)) { Profile p; p.readReport(dcBlock.stream()); Curve<Point2D>& vMin=minCurves[i]; Curve<Point2D>& vMax=maxCurves[i]; for(int j=0;j<100;j++) { double v=p.uniformAt(vMin[j].y()); Point2D& pMin=vMin[j]; if(v<pMin.x()) pMin.setX(v); Point2D& pMax=vMax[j]; if(v>pMax.x()) pMax.setX(v); } } } } } // Min and max profiles are constructed, now add them as new layers for(int i=0;i<n;i++) { LineLayer * plot=new LineLayer(_graphs[i] ); plot->setObjectName("limits"); PlotLine2D * line=new PlotLine2D; line->setPen(Pen(Qt::black, 0.60, Qt::DashLine)); line->setSymbol(Symbol(Symbol::NoSymbol)); plot->setReferenceLine(line); static_cast<PlotLine2D *>(plot->addLine())->setCurve(minCurves[i]); static_cast<PlotLine2D *>(plot->addLine())->setCurve(maxCurves[i]); plot->deepUpdate(); } delete [] minCurves; delete [] maxCurves; }
void DinverDCGui::GroundModelViewer::report2plot | ( | DCReportBlock & | dcBlock, |
Point2D ** | points, | ||
const DCModelInfo & | info | ||
) | [protected, virtual] |
void DinverDCGui::GroundModelViewer::saveAsReport | ( | ) | [slot] |
Save models and their curves to a .report file
References DinverDCGui::DCModelViewer::_models, DinverCore::ReportWriter::addModel(), fileName, iModel, DinverDCCore::DCModelInfo::indexInReport(), misfit(), DinverCore::ReportReader::misfit(), MSG_ID, DinverCore::ReportWriter::open(), DinverDCCore::DCModelInfo::report(), DinverCore::Parameter::setRealValue(), DinverCore::ReportReader::stream(), QGpCoreTools::tr(), and TRACE.
Referenced by GroundModelViewer().
{ TRACE; QString fileName=Message::getSaveFileName(tr("Save as report ..."), tr("Report file (*.report)")); if (fileName.length()>0) { if(!ReportWriter::initReport(fileName, tr("Open report for writing"), ReportWriter::Ask)) { return; } ReportWriter outReport(fileName); if(!outReport.open()) { Message::warning(MSG_ID, tr("Saving as report"), tr("Cannot open file for writing"), Message::cancel()); return; } qSort(_models.begin(),_models.end(), DCModelInfo::loadLessThan); int nModels=_models.count(); for(int iModel=0;iModel<nModels;iModel++) { DCModelInfo& info=*_models[iModel]; ReportReader& inReport=*info.report(); QDataStream& s=inReport.stream(); double misfit=inReport.misfit(info.indexInReport()); int nParams; uint checksum; double val; qint64 blockOffset=s.device()->pos(); s >> nParams; s >> checksum; Parameter * params[nParams]; for (int id=0 ; id<nParams; id++) { s >> val; params[id]=new Parameter; params[id]->setRealValue(val); } outReport.addModel(misfit, checksum, nParams, params); for (int id=0; id<nParams; id++) delete params[id]; s.device()->seek(blockOffset); DCReportBlock::write(&outReport, &inReport); } } }
void DinverDCGui::GroundModelViewer::setGlobalLimits | ( | const Rect & | r | ) | [protected, virtual] |
Reimplemented from DinverDCGui::DCModelViewer.
References DinverDCGui::DCModelViewer::_graphs, DinverDCGui::DCModelViewer::_nGraphs, SciFigs::Axis::setRange(), TRACE, QGpCoreTools::Rect::y2(), and SciFigs::AxisWindow::yAxis().
void DinverDCGui::GroundModelViewer::setLimits | ( | int | i, |
const Rect & | r | ||
) | [protected, virtual] |
Implements DinverDCGui::DCModelViewer.
References DinverDCGui::DCModelViewer::_graphs, SciFigs::Axis::scaleType, SciFigs::Axis::setRange(), TRACE, QGpCoreTools::Rect::x1(), QGpCoreTools::Rect::x2(), and SciFigs::AxisWindow::xAxis().
{ TRACE; Axis * a=_graphs[i]->xAxis(); if(r.x1()>0.0) { switch(a->scaleType()) { case Scale::Log: case Scale::Inversed: a->setRange(r.x1() * 0.95, r.x2() * 1.05); break; case Scale::Linear: a->setRange(0.0, r.x2() * 1.05); break; } } else { if(r.x2()<0.0) { a->setRange(r.x1() * 1.05, r.x2() * 0.95); } else { a->setRange(r.x1() * 1.05, r.x2() * 1.05); } } }
void DinverDCGui::GroundModelViewer::setSampleCount | ( | DCModelInfo * | info, |
DCReportBlock & | dcBlock | ||
) | [protected, virtual] |
Implements DinverDCGui::DCModelViewer.
References DinverDCGui::DCModelViewer::_nGraphs, DinverDCCore::DCReportBlock::profile(), DinverDCCore::DCModelInfo::setSampleCount(), DinverDCCore::DCReportBlock::stream(), and TRACE.
{ TRACE; int ns; int n=_nGraphs; if(n>5) n=5; for(int i=0;i<n;i++) { if(dcBlock.profile(i)) { dcBlock.stream() >> ns; info->setSampleCount(i,2*ns); } else { info->setSampleCount(i,0); } } // For the sake of security, even if from the graphical interface it is not possible to have a number of // graphs greater than 5 for(int i=n;i<_nGraphs;i++) { info->setSampleCount(i,0); } }
void DinverDCGui::GroundModelViewer::setTitles | ( | int | i | ) | [protected, virtual] |
Implements DinverDCGui::DCModelViewer.
References DinverDCGui::DCModelViewer::_graphs, SciFigs::GraphicObject::setObjectName(), SciFigs::Axis::setReversedScale(), SciFigs::Axis::setScaleType(), SciFigs::Axis::setTitle(), SciFigs::Axis::setTitleInversedScale(), TRACE, w, SciFigs::AxisWindow::xAxis(), and SciFigs::AxisWindow::yAxis().
{ TRACE; AxisWindow * w=_graphs[i]; w->yAxis()->setTitle( "Depth (m)" ); w->yAxis()->setTitleInversedScale( "1/Depth (1/m)" ); w->yAxis()->setReversedScale(true); switch (i) { case 0: w->xAxis()->setTitle( "Vp (m/s)" ); w->xAxis()->setTitleInversedScale( "Slowness P (s/m)" ); w->setObjectName("vp"); break; case 1: w->xAxis()->setTitle( "Vs (m/s)" ); w->xAxis()->setTitleInversedScale( "Slowness S (s/m)" ); w->setObjectName("vs"); break; case 2: w->xAxis()->setTitle( "Density (t/m3)" ); w->xAxis()->setTitleInversedScale( "1/Density (m3/t)" ); w->setObjectName("rho"); break; case 3: w->xAxis()->setTitle( "Pitch" ); w->xAxis()->setTitleInversedScale( "1/Pitch" ); w->setObjectName("pitch"); break; default: w->xAxis()->setTitle( "Resistivity (ohm m)" ); w->xAxis()->setTitleInversedScale( "Conductivity (S/m)" ); w->xAxis()->setScaleType(Scale::Log); w->setObjectName("res"); break; } }
AbstractLine * DinverDCGui::GroundModelViewer::targetReferenceLine | ( | ) | const [protected, virtual] |
Implements DinverDCGui::DCModelViewer.
References SciFigs::AbstractLine::setPen(), SciFigs::AbstractLine::setSymbol(), and TRACE.
{ TRACE; PlotLine2D * line=new PlotLine2D; line->setPen(Pen( Qt::black, 0.6) ); line->setSymbol(Symbol()); return line; }