#include <qfiledialog.h>
SelectParams::SelectParams(SelectField *sel)
- : _size(1024),
+ : _size(128),
_myExpr( 0 ),
_myFunc( 0 ),
_myFieldB( 0 ),
_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<DT_IT_> myIteration = med->getFieldIteration (_inputField);
+ MEDMEM::FIELD_* field = med->getField(_inputField,myIteration[_inputTS].dt,myIteration[_inputTS].it);
+ if (dynamic_cast<MEDMEM::FIELD<double>*>(field)){
+ _myDField = new MEDMEM::FIELD<double>(MEDMEM::MED_DRIVER,_inputFile,_inputField,myIteration[_inputTS].dt,myIteration[_inputTS].it);
+ _myIField = NULL;
+ }
+ else{
+ _myIField = new MEDMEM::FIELD<int>(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");
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 );
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"));
_myLST->show();
if(_myLEST->isHidden())
_myLEST->show();
+ // draw two thresholds
displayFThresh();
displaySThresh();
}
void SelectParams::areaSelected()
{
+ // calculate reduction rate after thresholds selection
calcRateRed();
}
void SelectParams::calcHisto()
{
char strth[128];
- _xmin = -50.0;
- _xmax = 50.0;
- _ymin = 1.0;
+ vector<int> 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);
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()
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;
{
_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;
{
_sthresh = atof(_myLEST->text());
+ // erase second threshold curve
for(int i=0;i<100;i++){
_xst[i]=_sthresh;
_yst[i]=0.0;
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();
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();
void SelectParams::getOutFileName()
{
+ // get output MED file name
QString file = QFileDialog::getSaveFileName("",
"*.med",
_myOFB,
{
string command;
+ // send filtoo command
MESSAGE("Input MED File : "<<_inputFile);
MESSAGE("Input Mesh : "<<_inputMesh);
MESSAGE("Input Field : "<<_inputField);
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<i1;i++)
}
rateRed = (double)asel / (double) atot;
+ // display reduction rate value
QString qs(tr("FILTER_RED_RATE"));
char str[128];
sprintf(str," = %4.2g",rateRed);