1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "SelectParams.h"
24 #include "utilities.h"
26 #include <SUIT_FileDlg.h>
28 #include "Utils_SALOME_Exception.hxx"
29 #include <SalomeApp_Tools.h>
32 #include <qgroupbox.h>
35 #include <qlineedit.h>
36 #include <qbuttongroup.h>
37 #include <qradiobutton.h>
38 #include <qpushbutton.h>
39 #include <qfiledialog.h>
41 SelectParams::SelectParams(SelectField *sel)
67 _x = new double[_size];
68 _y = new double[_size];
70 _inputFile = sel->getFile();
71 _inputMesh = sel->getMesh();
72 _inputField = sel->getField();
73 _inputTS = sel->getTimeStep();
74 if( _inputMesh.isNull() || _inputField.isNull() ){
75 MESSAGE("Select an input Field in MED file before filtering!!");
76 throw SALOME_Exception("Salome Exception");
80 MESSAGE("Select an input Field in MED file before filtering!!");
81 throw SALOME_Exception("Salome Exception");
86 SelectParams::~SelectParams()
88 cout << "destructor called" << endl;
96 // delete _myNbThresh;
98 // delete _myOneThresh;
99 // delete _myTwoThresh;
101 // delete _myVThresh;
102 // delete _myOutFile;
106 // delete _myGroupLayout;
107 // delete _myGroupLayout2;
115 QFrame* SelectParams::buildFrame()
117 QFrame* _fr = new QFrame( 0, "myframe" );
118 QGridLayout* _lay = new QGridLayout( _fr, 1, 2 );
120 QGroupBox* _GroupC1 = new QGroupBox( _fr, "GroupC1" );
121 _lay->addWidget( _GroupC1,0,0 );
123 _GroupC1->setTitle( tr( "FILTER_PARAMS" ) );
124 _GroupC1->setColumnLayout(0, Qt::Vertical );
125 _GroupC1->layout()->setSpacing( 0 );
126 _GroupC1->layout()->setMargin( 0 );
127 _myGroupLayout = new QGridLayout( _GroupC1->layout() );
128 _myGroupLayout->setAlignment( Qt::AlignTop );
129 _myGroupLayout->setSpacing( 6 );
130 _myGroupLayout->setMargin( 11 );
131 _myGroupLayout->setColStretch( 0, 0 );
132 _myGroupLayout->setColStretch( 1, 1 );
136 QString qs1(tr("FILTER_INPUT_FILE"));
137 qs1.append(basename(_inputFile));
138 _myGroupLayout->addWidget( new QLabel( qs1, _GroupC1 ), row, 0 );
141 QString qs2(tr("FILTER_INPUT_MESH"));
142 qs2.append(_inputMesh);
143 _myGroupLayout->addWidget( new QLabel( qs2, _GroupC1 ), row, 0 );
146 QString qs3(tr("FILTER_INPUT_FIELD"));
147 qs3.append(_inputField);
148 _myGroupLayout->addWidget( new QLabel( qs3, _GroupC1 ), row, 0 );
151 QString qs4(tr("FILTER_INPUT_TS"));
153 sprintf(strTS,"%d\0",_inputTS);
155 _myGroupLayout->addWidget( new QLabel( qs4, _GroupC1 ), row, 0 );
158 // 0) field function to calculate histogram (radiogroup)
159 _myFunc = new QButtonGroup( tr("FILTER_SELECT_FUNC"), _GroupC1 );
160 _myFunc->setExclusive( true );
161 _myFunc->setColumnLayout( 0, Qt::Horizontal );
163 _myFieldB = new QRadioButton( tr("FILTER_FIELD"), _myFunc );
164 _myFieldB->setChecked(true);
166 QGridLayout* convLay = new QGridLayout( _myFunc->layout() );
167 convLay->addWidget( _myFieldB, 0, 0 );
168 convLay->addWidget( _myCutNeg = new QRadioButton( tr("FILTER_GRADIENT"), _myFunc ), 0, 1 );
169 _myGroupLayout->addWidget( _myFunc, row, 0 );
172 // 1) display histogram button (pushbutton)
173 _myHisto = new QPushButton( "", _GroupC1 );
174 _myHisto->setText(tr("FILTER_DISPLAY_HISTO"));
175 _myHisto->setAutoDefault(TRUE);
176 _myHisto->setDefault(TRUE);
177 _myGroupLayout->addWidget( _myHisto, row, 0 );
180 // 2) scale of histogram (radiogroup)
181 _myFScale = new QButtonGroup( tr("FILTER_TYPE_DISPLAY"), _GroupC1 );
182 _myFScale->setExclusive( true );
183 _myFScale->setColumnLayout( 0, Qt::Horizontal );
185 _myLinear = new QRadioButton( tr("FILTER_LINEAR"), _myFScale );
186 _myLinear->setChecked(true);
187 _myLog = new QRadioButton( tr("FILTER_LOG"), _myFScale );
188 _myFScale->setDisabled(true);
190 QGridLayout* scaleLay = new QGridLayout( _myFScale->layout() );
191 scaleLay->addWidget( _myLinear, 0, 0 );
192 scaleLay->addWidget( _myLog, 0, 1 );
193 _myGroupLayout->addWidget( _myFScale, row, 0 );
196 // 3) number of thresholds (radiogroup)
197 _myNbThresh = new QButtonGroup( tr("FILTER_SEL_THRESH"), _GroupC1 );
198 _myNbThresh->setExclusive( true );
199 _myNbThresh->setColumnLayout( 0, Qt::Horizontal );
200 QGridLayout* nbtLay = new QGridLayout( _myNbThresh->layout() );
201 nbtLay->addWidget( _myOneThresh = new QRadioButton( tr("FILTER_ONE_THRESH"), _myNbThresh ), 0, 0 );
202 nbtLay->addWidget( _myTwoThresh = new QRadioButton( tr("FILTER_TWO_THRESH"), _myNbThresh ), 0, 1 );
203 _myGroupLayout->addWidget( _myNbThresh, row, 0 );
205 _myOneThresh->setChecked(true);
206 _myNbThresh->setDisabled(true);
209 // 4) reference area on thresholds (radiogroup)
210 _myArea = new QButtonGroup( tr("FILTER_REF_AREA"), _GroupC1 );
211 _myArea->setExclusive( true );
212 _myArea->setColumnLayout( 0, Qt::Horizontal );
213 QGridLayout* areaLay = new QGridLayout( _myArea->layout() );
214 areaLay->addWidget( _myInt = new QRadioButton( tr("FILTER_BOTTOM"), _myArea ), 0, 0 );
215 areaLay->addWidget( _myExt = new QRadioButton( tr("FILTER_UP"), _myArea ), 0, 1 );
216 _myGroupLayout->addWidget( _myArea, row, 0 );
218 _myExt->setChecked(true);
219 _myArea->setDisabled(true);
222 // 5) threshold values (line edit)
223 _myVThresh = new QButtonGroup( tr("FILTER_TRESH_VAL"), _GroupC1 );
224 _myVThresh->setExclusive( true );
225 _myVThresh->setColumnLayout( 0, Qt::Horizontal );
226 QGridLayout* ftLay = new QGridLayout( _myVThresh->layout() );
227 ftLay->addWidget( _myLFT = new QLabel( tr("FILTER_VAL_TRESH") , _myVThresh ), 0, 0 );
228 ftLay->addWidget( _myLEFT = new QLineEdit( "", _myVThresh ), 0, 1 );
229 ftLay->addWidget( _myLST = new QLabel( tr("FILTER_VAL_2_TRESH") , _myVThresh ), 1, 0 );
230 ftLay->addWidget( _myLEST = new QLineEdit( "", _myVThresh ), 1, 1 );
231 _myGroupLayout->addWidget( _myVThresh, row, 0 );
233 _myVThresh->setDisabled(true);
238 // 6) output file name (line edit)
239 _myOutFile = new QButtonGroup( tr("FILTER_OUT_FILE"), _GroupC1 );
240 _myOutFile->setExclusive( true );
241 _myOutFile->setColumnLayout( 0, Qt::Horizontal );
243 _myOFB = new QPushButton( "", _myOutFile );
244 _myOFB->setText(tr("FILTER_BROWSE"));
245 _myOFB->setAutoDefault(TRUE);
247 QGridLayout* outLay = new QGridLayout( _myOutFile->layout() );
248 outLay->addWidget( _myOFB, 0, 0 );
249 outLay->addWidget( _myOFN = new QLineEdit( "", _myOutFile ), 0, 1 );
250 _myGroupLayout->addWidget( _myOutFile, row, 0 );
252 _myOutFile->setDisabled(true);
255 // 8) process button (pushbutton)
256 _myProc = new QPushButton( "", _GroupC1 );
257 _myProc->setText(tr("FILTER_PROCESS"));
258 _myProc->setAutoDefault(TRUE);
259 _myGroupLayout->addWidget( _myProc, row, 0 );
260 _myProc->setDisabled(true);
263 _GroupC2 = new QGroupBox( _fr, "GroupC2" );
264 _lay->addWidget( _GroupC2,0,1 );
266 _GroupC2->setTitle( tr( "FILTER_HISTO" ) );
267 _GroupC2->setColumnLayout(0, Qt::Vertical );
268 _GroupC2->layout()->setSpacing( 0 );
269 _GroupC2->layout()->setMargin( 0 );
270 _myGroupLayout2 = new QGridLayout( _GroupC2->layout() );
272 // 9) histogram curve
273 _myPlot = new QwtPlot(_GroupC2);
274 _myHistoCurve = _myPlot->insertCurve( QString() );
275 _myPlot->setCurvePen( _myHistoCurve, QPen( Qt::red, 1 ) );
276 _myPlot->setCurveTitle( _myHistoCurve, "Histogram" );
278 _myGroupLayout2->addWidget( _myPlot, 0, 0 );
280 // 10) reduction rate (label)
281 QString qs5(tr("FILTER_RED_RATE"));
282 qs5.append(" = 0.5");
283 _myLRR = new QLabel( qs5, _GroupC2 );
284 _myGroupLayout2->addWidget( _myLRR, 1, 0 );
288 _myHistoFThresh = _myPlot->insertCurve( QString() );
289 _myPlot->setCurvePen( _myHistoFThresh, QPen( Qt::black, 1 ) );
290 _myHistoSThresh = _myPlot->insertCurve( QString() );
291 _myPlot->setCurvePen( _myHistoSThresh, QPen( Qt::black, 1 ) );
293 connect( _myHisto, SIGNAL(clicked()), this, SLOT(updateHisto()));
294 connect( _myLinear, SIGNAL(clicked()), this, SLOT(scaleSelected()));
295 connect( _myLog, SIGNAL(clicked()), this, SLOT(scaleSelected()));
296 connect( _myOneThresh, SIGNAL(clicked()), this, SLOT(nbThreshSelected()));
297 connect( _myTwoThresh, SIGNAL(clicked()), this, SLOT(nbThreshSelected()));
298 connect( _myInt, SIGNAL(clicked()), this, SLOT(areaSelected()));
299 connect( _myExt, SIGNAL(clicked()), this, SLOT(areaSelected()));
300 connect( _myLEFT, SIGNAL(returnPressed()), this, SLOT(enterFThresh()));
301 connect( _myLEST, SIGNAL(returnPressed()), this, SLOT(enterSThresh()));
302 connect( _myPlot, SIGNAL(plotMouseMoved(const QMouseEvent &)), this, SLOT(moveThresh(const QMouseEvent &)));
303 connect( _myOFB, SIGNAL(clicked()), this, SLOT(getOutFileName()));
304 connect( _myProc, SIGNAL(clicked()), this, SLOT(process()));
309 void SelectParams::scaleSelected()
311 if( _myLinear->isChecked() )
312 _myPlot->setAxisOptions(_myPlot->curveYAxis( _myHistoCurve ), QwtAutoScale::None );
314 _myPlot->setAxisOptions(_myPlot->curveYAxis( _myHistoCurve ), QwtAutoScale::Logarithmic );
318 void SelectParams::nbThreshSelected()
320 if( _myOneThresh->isChecked() ){
321 _myInt->setText(tr("FILTER_BOTTOM"));
322 _myExt->setText(tr("FILTER_UP"));
323 _myLFT->setText(tr("FILTER_VAL_TRESH"));
330 _myInt->setText(tr("FILTER_INT"));
331 _myExt->setText(tr("FILTER_EXT"));
332 _myLFT->setText(tr("FILTER_VAL_1_TRESH"));
333 if(_myLST->isHidden())
335 if(_myLEST->isHidden())
343 void SelectParams::areaSelected()
348 void SelectParams::enterFThresh()
354 void SelectParams::enterSThresh()
360 void SelectParams::calcHisto()
368 for(int i=0;i<_size;i++){
369 _x[i]=_xmin+(i*(_xmax-_xmin))/_size;
370 _y[i]=80.*exp(-_x[i]*_x[i]/400.);
374 _fthresh = (_xmin + _xmax)/2.0;
375 _sthresh = (_xmin + 3.*_xmax)/4.0;
376 sprintf(strth,"%g",_fthresh);
377 _myLEFT->setText(QString(strth));
378 sprintf(strth,"%g",_sthresh);
379 _myLEST->setText(QString(strth));
382 void SelectParams::displayHisto()
384 if(!_myFScale->isEnabled())
385 _myFScale->setEnabled(true);
386 if(!_myNbThresh->isEnabled())
387 _myNbThresh->setEnabled(true);
388 if(!_myArea->isEnabled())
389 _myArea->setEnabled(true);
390 if(!_myVThresh->isEnabled())
391 _myVThresh->setEnabled(true);
392 if(!_myOutFile->isEnabled())
393 _myOutFile->setEnabled(true);
394 if(!_myProc->isEnabled())
395 _myProc->setEnabled(true);
396 _myPlot->setAxisScale( _myPlot->curveXAxis( _myHistoCurve ), _xmin, _xmax );
397 _myPlot->setAxisScale( _myPlot->curveYAxis( _myHistoCurve ), _ymin, _ymax );
398 _myPlot->setCurveData( _myHistoCurve, _x, _y, _size );
399 if( _myLinear->isChecked() )
400 _myPlot->setAxisOptions(_myPlot->curveYAxis( _myHistoCurve ), QwtAutoScale::None );
402 _myPlot->setAxisOptions(_myPlot->curveYAxis( _myHistoCurve ), QwtAutoScale::Logarithmic );
403 _qmap = _myPlot->canvasMap(_myPlot->curveXAxis( _myHistoCurve ));
404 _qmap.setDblRange(_xmin,_xmax);
406 if(_GroupC2->isHidden())
410 void SelectParams::updateHisto()
415 if( _myTwoThresh->isChecked() )
420 void SelectParams::displayFThresh()
422 _fthresh = atof(_myLEFT->text());
424 for(int i=0;i<100;i++){
426 _yft[i]=((i-1)*_ymax)/100.0;
428 _myPlot->setCurveData( _myHistoFThresh, _xft, _yft, 100 );
432 void SelectParams::displaySThresh()
434 _sthresh = atof(_myLEST->text());
436 for(int i=0;i<100;i++){
438 _yst[i]=((i-1)*_ymax)/100.0;
440 _myPlot->setCurveData( _myHistoSThresh, _xst, _yst, 100 );
444 void SelectParams::clearSThresh()
446 _sthresh = atof(_myLEST->text());
448 for(int i=0;i<100;i++){
452 _myPlot->setCurveData( _myHistoSThresh, _xst, _yst, 100 );
456 void SelectParams::moveThresh(const QMouseEvent &e)
459 int delta = abs(e.x()-_qmap.transform(_fthresh));
461 sprintf(strth,"%g",_qmap.invTransform(e.x()));
462 _myLEFT->setText(QString(strth));
465 else if( _myTwoThresh->isChecked() ){
466 delta = abs(e.x()-_qmap.transform(_sthresh));
468 sprintf(strth,"%g",_qmap.invTransform(e.x()));
469 _myLEST->setText(QString(strth));
476 void SelectParams::getOutFileName()
478 QString file = QFileDialog::getSaveFileName("",
482 "Choose a file to save" );
484 _myOFN->setText(file);
486 // Selection du Fichier
487 // file = SUIT_FileDlg::getFileName(application()->desktop(),
490 // "Output MED file name",
494 void SelectParams::process()
498 MESSAGE("Input MED File : "<<_inputFile);
499 MESSAGE("Input Mesh : "<<_inputMesh);
500 MESSAGE("Input Field : "<<_inputField);
501 MESSAGE("Input Time Step : "<<_inputTS);
502 MESSAGE("Output file name: " << _myOFN->text() );
503 command = "cd /export/home/secher/filtoo/example;filtoo -f s -o sf > /tmp/filter.log";
505 system(command.c_str());
509 void SelectParams::calcRateRed()
512 int atot=0, asel=0, atot1;
516 i1 = (int)((double)_size * ( _fthresh - _xmin ) / ( _xmax - _xmin ));
517 if( _myOneThresh->isChecked() ){
521 for(i=i1;i<_size;i++)
523 if( _myExt->isChecked() )
527 i2 = (int)((double)_size * ( _sthresh - _xmin ) / ( _xmax - _xmin ));
539 for(i=i2;i<_size;i++)
541 if( _myExt->isChecked() )
544 rateRed = (double)asel / (double) atot;
546 QString qs(tr("FILTER_RED_RATE"));
548 sprintf(str," = %4.2g",rateRed);
550 _myLRR->setText( qs );