From acd66495bc40babfb1f092e6ea77330da7809b08 Mon Sep 17 00:00:00 2001 From: secher Date: Wed, 24 Jan 2007 09:25:11 +0000 Subject: [PATCH] calculate and draw histogram from MED reference field --- src/FILTERGUI/SelectField.h | 1 + src/FILTERGUI/SelectParams.cxx | 150 +++++++++++++++++++++++---------- src/FILTERGUI/SelectParams.h | 6 ++ 3 files changed, 113 insertions(+), 44 deletions(-) diff --git a/src/FILTERGUI/SelectField.h b/src/FILTERGUI/SelectField.h index 18f0ab9..2b6ffa7 100644 --- a/src/FILTERGUI/SelectField.h +++ b/src/FILTERGUI/SelectField.h @@ -48,6 +48,7 @@ public: QString getMesh() { return _mesh; } QString getField() { return _field; } int getTimeStep() { return _ts; } + ::MEDMEM::MED * getMED() { return _med; } protected: diff --git a/src/FILTERGUI/SelectParams.cxx b/src/FILTERGUI/SelectParams.cxx index e1bffbf..11fbfe9 100644 --- a/src/FILTERGUI/SelectParams.cxx +++ b/src/FILTERGUI/SelectParams.cxx @@ -39,7 +39,7 @@ #include SelectParams::SelectParams(SelectField *sel) - : _size(1024), + : _size(128), _myExpr( 0 ), _myFunc( 0 ), _myFieldB( 0 ), @@ -64,18 +64,36 @@ SelectParams::SelectParams(SelectField *sel) _lay( 0 ), _fr( 0 ) { + // Allocate histogram arrays _x = new double[_size]; _y = new double[_size]; + if(sel){ + // Get reference field and time step _inputFile = sel->getFile(); _inputMesh = sel->getMesh(); _inputField = sel->getField(); _inputTS = sel->getTimeStep(); + // if no reference field selection: throw exception if( _inputMesh.isNull() || _inputField.isNull() ){ MESSAGE("Select an input Field in MED file before filtering!!"); throw SALOME_Exception("Salome Exception"); } + + // read reference field values + ::MEDMEM::MED *med = sel->getMED(); + deque myIteration = med->getFieldIteration (_inputField); + MEDMEM::FIELD_* field = med->getField(_inputField,myIteration[_inputTS].dt,myIteration[_inputTS].it); + if (dynamic_cast*>(field)){ + _myDField = new MEDMEM::FIELD(MEDMEM::MED_DRIVER,_inputFile,_inputField,myIteration[_inputTS].dt,myIteration[_inputTS].it); + _myIField = NULL; + } + else{ + _myIField = new MEDMEM::FIELD(MEDMEM::MED_DRIVER,_inputFile,_inputField,myIteration[_inputTS].dt,myIteration[_inputTS].it); + _myDField = NULL; + } } + // if no reference field selection: throw exception else{ MESSAGE("Select an input Field in MED file before filtering!!"); throw SALOME_Exception("Salome Exception"); @@ -86,34 +104,37 @@ SelectParams::SelectParams(SelectField *sel) SelectParams::~SelectParams() { cout << "destructor called" << endl; -// delete _x; -// delete _y; -// delete _myExpr; -// delete _myFunc; -// delete _myFieldB; -// delete _myLinear; -// delete _myHisto; -// delete _myNbThresh; -// delete _myCutNeg; -// delete _myOneThresh; -// delete _myTwoThresh; -// delete _myArea; -// delete _myVThresh; -// delete _myOutFile; -// delete _myOFB; -// delete _myProc; -// delete _myFScale; -// delete _myGroupLayout; -// delete _myGroupLayout2; -// delete _myPlot; -// delete _GroupC1; -// delete _GroupC2; -// delete _lay; -// delete _fr; + delete _x; + delete _y; + if(_myIField) delete _myIField; + if(_myDField) delete _myDField; + delete _myExpr; + delete _myFunc; + delete _myFieldB; + delete _myLinear; + delete _myHisto; + delete _myNbThresh; + delete _myCutNeg; + delete _myOneThresh; + delete _myTwoThresh; + delete _myArea; + delete _myVThresh; + delete _myOutFile; + delete _myOFB; + delete _myProc; + delete _myFScale; + delete _myGroupLayout; + delete _myGroupLayout2; + delete _myPlot; + delete _GroupC1; + delete _GroupC2; + delete _lay; + delete _fr; } QFrame* SelectParams::buildFrame() { + // build widgets for select filtering parameters QFrame* _fr = new QFrame( 0, "myframe" ); QGridLayout* _lay = new QGridLayout( _fr, 1, 2 ); @@ -308,25 +329,35 @@ QFrame* SelectParams::buildFrame() void SelectParams::scaleSelected() { - if( _myLinear->isChecked() ) + // draw linear or log Y scale depend on user + if( _myLinear->isChecked() ){ + _ymin = 0.0; _myPlot->setAxisOptions(_myPlot->curveYAxis( _myHistoCurve ), QwtAutoScale::None ); - else + } + else{ + _ymin = 1.0; _myPlot->setAxisOptions(_myPlot->curveYAxis( _myHistoCurve ), QwtAutoScale::Logarithmic ); + } + _myPlot->setAxisScale( _myPlot->curveYAxis( _myHistoCurve ), _ymin, _ymax ); _myPlot->replot(); } void SelectParams::nbThreshSelected() { if( _myOneThresh->isChecked() ){ + // if one threshold choice between bottom and up for reference area _myInt->setText(tr("FILTER_BOTTOM")); _myExt->setText(tr("FILTER_UP")); _myLFT->setText(tr("FILTER_VAL_TRESH")); _myLST->hide(); _myLEST->hide(); + // draw first threshold displayFThresh(); + // erase second threshold clearSThresh(); } else{ + // if two thresholds choice between interior and exterior fir reference area _myInt->setText(tr("FILTER_INT")); _myExt->setText(tr("FILTER_EXT")); _myLFT->setText(tr("FILTER_VAL_1_TRESH")); @@ -334,6 +365,7 @@ void SelectParams::nbThreshSelected() _myLST->show(); if(_myLEST->isHidden()) _myLEST->show(); + // draw two thresholds displayFThresh(); displaySThresh(); } @@ -342,6 +374,7 @@ void SelectParams::nbThreshSelected() void SelectParams::areaSelected() { + // calculate reduction rate after thresholds selection calcRateRed(); } @@ -360,17 +393,32 @@ void SelectParams::enterSThresh() void SelectParams::calcHisto() { char strth[128]; - _xmin = -50.0; - _xmax = 50.0; - _ymin = 1.0; + vector myh; + + // calculate histogram values + if (_myDField){ + _myDField->getMinMax(_xmin,_xmax); + myh = _myDField->getHistogram(_size); + } + else{ + int xmin, xmax; + _myIField->getMinMax(xmin,xmax); + _xmin = (double)xmin; + _xmax = (double)xmax; + myh = _myIField->getHistogram(_size); + } + _ymin = 0.0; _ymax = 0.0; for(int i=0;i<_size;i++){ + // calculate absisses for histogram values _x[i]=_xmin+(i*(_xmax-_xmin))/_size; - _y[i]=80.*exp(-_x[i]*_x[i]/400.); + _y[i]=(double)myh[i]; if( _y[i] > _ymax ) _ymax = _y[i]; } + + // init thresholds values _fthresh = (_xmin + _xmax)/2.0; _sthresh = (_xmin + 3.*_xmax)/4.0; sprintf(strth,"%g",_fthresh); @@ -381,30 +429,32 @@ void SelectParams::calcHisto() void SelectParams::displayHisto() { - if(!_myFScale->isEnabled()) - _myFScale->setEnabled(true); - if(!_myNbThresh->isEnabled()) - _myNbThresh->setEnabled(true); - if(!_myArea->isEnabled()) - _myArea->setEnabled(true); - if(!_myVThresh->isEnabled()) - _myVThresh->setEnabled(true); - if(!_myOutFile->isEnabled()) - _myOutFile->setEnabled(true); - if(!_myProc->isEnabled()) - _myProc->setEnabled(true); + // give extrema values for each axis _myPlot->setAxisScale( _myPlot->curveXAxis( _myHistoCurve ), _xmin, _xmax ); _myPlot->setAxisScale( _myPlot->curveYAxis( _myHistoCurve ), _ymin, _ymax ); + // associate values to curve _myPlot->setCurveData( _myHistoCurve, _x, _y, _size ); if( _myLinear->isChecked() ) _myPlot->setAxisOptions(_myPlot->curveYAxis( _myHistoCurve ), QwtAutoScale::None ); else _myPlot->setAxisOptions(_myPlot->curveYAxis( _myHistoCurve ), QwtAutoScale::Logarithmic ); + // associate mapping to plot to move thresholds on display _qmap = _myPlot->canvasMap(_myPlot->curveXAxis( _myHistoCurve )); _qmap.setDblRange(_xmin,_xmax); _myPlot->replot(); - if(_GroupC2->isHidden()) +} + +void SelectParams::enableWidgets() +{ + if(_GroupC2->isHidden()){ + _myFScale->setEnabled(true); + _myNbThresh->setEnabled(true); + _myArea->setEnabled(true); + _myVThresh->setEnabled(true); + _myOutFile->setEnabled(true); + _myProc->setEnabled(true); _GroupC2->show(); + } } void SelectParams::updateHisto() @@ -415,12 +465,14 @@ void SelectParams::updateHisto() if( _myTwoThresh->isChecked() ) displaySThresh(); calcRateRed(); + enableWidgets(); } void SelectParams::displayFThresh() { _fthresh = atof(_myLEFT->text()); + // draw first threshold curve for(int i=0;i<100;i++){ _xft[i]=_fthresh; _yft[i]=((i-1)*_ymax)/100.0; @@ -433,6 +485,7 @@ void SelectParams::displaySThresh() { _sthresh = atof(_myLEST->text()); + // draw second threshold curve for(int i=0;i<100;i++){ _xst[i]=_sthresh; _yst[i]=((i-1)*_ymax)/100.0; @@ -445,6 +498,7 @@ void SelectParams::clearSThresh() { _sthresh = atof(_myLEST->text()); + // erase second threshold curve for(int i=0;i<100;i++){ _xst[i]=_sthresh; _yst[i]=0.0; @@ -456,8 +510,11 @@ void SelectParams::clearSThresh() void SelectParams::moveThresh(const QMouseEvent &e) { char strth[128]; + + // move threshold curve with mouse int delta = abs(e.x()-_qmap.transform(_fthresh)); if( delta < 5 ){ + // moving first threshold curve sprintf(strth,"%g",_qmap.invTransform(e.x())); _myLEFT->setText(QString(strth)); displayFThresh(); @@ -465,6 +522,7 @@ void SelectParams::moveThresh(const QMouseEvent &e) else if( _myTwoThresh->isChecked() ){ delta = abs(e.x()-_qmap.transform(_sthresh)); if( delta < 5 ){ + // moving second threshold curve sprintf(strth,"%g",_qmap.invTransform(e.x())); _myLEST->setText(QString(strth)); displaySThresh(); @@ -475,6 +533,7 @@ void SelectParams::moveThresh(const QMouseEvent &e) void SelectParams::getOutFileName() { + // get output MED file name QString file = QFileDialog::getSaveFileName("", "*.med", _myOFB, @@ -495,6 +554,7 @@ void SelectParams::process() { string command; + // send filtoo command MESSAGE("Input MED File : "<<_inputFile); MESSAGE("Input Mesh : "<<_inputMesh); MESSAGE("Input Field : "<<_inputField); @@ -513,6 +573,7 @@ void SelectParams::calcRateRed() double rateRed=0.0; char strth[128]; + // calculate reduction rate depend on reference area defined by threshold values i1 = (int)((double)_size * ( _fthresh - _xmin ) / ( _xmax - _xmin )); if( _myOneThresh->isChecked() ){ for(i=0;i #include @@ -56,6 +59,7 @@ protected: virtual void clearSThresh(); virtual void displayFThresh(); virtual void displaySThresh(); + virtual void enableWidgets(); protected slots: virtual void updateHisto(); @@ -89,6 +93,8 @@ private: QwtDiMap _qmap; QFrame *_fr; QString _inputFile, _inputMesh, _inputField; + FIELD * _myDField; + FIELD * _myIField; int _inputTS; }; -- 2.39.2