Salome HOME
gradient calculation on field
authorsecher <secher>
Thu, 15 Feb 2007 15:03:43 +0000 (15:03 +0000)
committersecher <secher>
Thu, 15 Feb 2007 15:03:43 +0000 (15:03 +0000)
src/FILTERGUI/SelectParams.cxx
src/FILTERGUI/SelectParams.h

index 388b71bd954e03337d3eb3b1f1377d0f016b41ac..08a0beb8d0fbb3e48655253d9ab1ea74253e9379 100644 (file)
@@ -23,8 +23,6 @@
 #include "SelectParams.h"
 #include "MEDMEM_MedMeshDriver.hxx"
 #include "MEDMEM_EnsightMeshDriver.hxx"
-#include "MEDMEM_Family.hxx"
-#include "MEDMEM_Group.hxx"
 
 #include <SUIT_FileDlg.h>
 
@@ -46,7 +44,7 @@
 SelectParams::SelectParams(FilterGUI* theModule,SelectField *sel,
                           const char* name,
                           bool modal, WFlags fl) throw(SALOME_Exception)
-  : QDialog(FILTER::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),  _size(1024),_sel(sel),_criteria(NULL)
+  : QDialog(FILTER::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),_size(1024),_sel(sel),_criteria(NULL),_myGradient(NULL)
 {
   if(sel){
 
@@ -107,14 +105,18 @@ SelectParams::~SelectParams()
   delete _x;
   delete _y;
 
-  // destruction of support of reference field: reference filed is destroyed
+  // destruction of gradient field
+  if(_myGradient)
+    delete _myGradient;
+
+  // destruction of support of reference field: reference field is destroyed
   // by destruction of med object in _sel destruction
   if(_myIField)
     delete _myIField->getSupport();
   if(_myDField)
     delete _myDField->getSupport();
 
 // destruction of criteria: support and field
+ // destruction of criteria: support and field
   if(_criteria){
     delete _criteria->getSupport();
     delete _criteria;
@@ -177,7 +179,7 @@ void SelectParams::buildFrame()
 
   QGridLayout* convLay = new QGridLayout( _myFunc->layout() );
   convLay->addWidget( _myFieldB, 0, 0 );
-  convLay->addWidget( _myCutNeg = new QRadioButton( tr("FILTER_GRADIENT"), _myFunc ), 0, 1 );
+  convLay->addWidget( _myGradB = new QRadioButton( tr("FILTER_GRADIENT"), _myFunc ), 0, 1 );
   _myGroupLayout->addWidget( _myFunc, row, 0 );
   row++;
 
@@ -331,6 +333,7 @@ void SelectParams::buildFrame()
   _myHistoSThresh = _myPlot->insertCurve( QString() );
   _myPlot->setCurvePen( _myHistoSThresh, QPen( Qt::black, 1 ) );
 
+  connect( _myGradB, SIGNAL(clicked()), this, SLOT(gradSelected()));
   connect( _myLESH, SIGNAL(returnPressed()), this, SLOT(enterSHisto()));
   connect( _myHisto, SIGNAL(clicked()), this, SLOT(updateHisto()));
   connect( _myLinear, SIGNAL(clicked()), this, SLOT(scaleSelected()));
@@ -354,6 +357,28 @@ void SelectParams::buildFrame()
 
 }
 
+void SelectParams::gradSelected()
+{
+  if(!_myGradient){
+    FIELD<double> * gradient;
+    try{
+      if(_myDField)
+       gradient = _myDField->buildGradient();
+      else
+       gradient = _myIField->buildGradient();
+      _myGradient = gradient->buildNorm2Field();
+      delete gradient;
+    }
+    catch(MEDEXCEPTION& Mex){
+      _myFieldB->setChecked(true);
+      QMessageBox::information( this,
+                               "Filtering",
+                               "Unable to calculate gradient on vector field.\n"
+                               "You must select a reference scalar field." );
+    }
+  }
+}
+
 void SelectParams::enterSHisto()
 {
   // Deallocate old histogram arrays
@@ -437,18 +462,25 @@ void SelectParams::calcHisto()
   char strth[128];
   vector<int> myh;
 
-  // calculate histogram values
-  if (_myDField){
-    _myDField->getMinMax(_xmin,_xmax);
-    myh = _myDField->getHistogram(_size);
+  if( _myFieldB->isChecked() ){
+    // calculate histogram values on field
+    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);
+    }
   }
   else{
-    int xmin, xmax;
-    _myIField->getMinMax(xmin,xmax);
-    _xmin = (double)xmin;
-    _xmax = (double)xmax;
-    myh = _myIField->getHistogram(_size);
-  }                    
+    // calculate histogram values on gradient
+    _myGradient->getMinMax(_xmin,_xmax);
+    myh = _myGradient->getHistogram(_size);
+  }
   if( _myLinear->isChecked() )
     _ymin = 0.0;
   else
@@ -651,6 +683,14 @@ void SelectParams::process()
 
   // have to call ensight driver MED to generate output MED file from filtoo output
 
+  // create fields on new mesh
+  // if new nodes on new mesh: interpolation
+  // if input fields on cell, transform it on nodes
+
+  // destroy filtoo output files
+
+  // create new MED file with new mesh and fields
+
   // close the window
   accept();
 
index fe322874a2493da318f33867496afb988dc10d40..d561ee6fffd6fdd8a6503123778cc310b95f295c 100644 (file)
@@ -67,6 +67,7 @@ protected:
   virtual void     generateCriteria() throw(SALOME_Exception);
 
 protected slots:
+  virtual void     gradSelected();
   virtual void     enterSHisto();
   virtual void     updateHisto();
   virtual void     scaleSelected();
@@ -93,7 +94,7 @@ private:
   QLineEdit *_myLESH, *_myFThresh, *_myExpr, *_myLEST, *_myLEFT, *_myOFN;
   QButtonGroup *_myHSize, *_myFunc, *_myFScale, *_myNbThresh, *_myArea, *_myVThresh, *_myOutFile;
   QGridLayout *_myGroupLayout, *_myGroupLayout2, *_lay, *_GroupButtonsLayout;
-  QRadioButton *_myCutNeg, *_myInt, *_myExt, *_myOneThresh, *_myTwoThresh, *_myFieldB, *_myLinear, *_myLog;
+  QRadioButton *_myFieldB, *_myGradB, *_myInt, *_myExt, *_myOneThresh, *_myTwoThresh, *_myLinear, *_myLog;
   QPushButton *_myHisto, *_myOFB, *_myProc, * _buttonCancel, * _buttonHelp;
   QGroupBox* _GroupC1, *_GroupC2, *_GroupButtons;
   QwtPlot *_myPlot;
@@ -105,6 +106,7 @@ private:
   SelectField *_sel;
   ::MEDMEM::MED *_med;
   MESH* _mesh;
+  FIELD<double> * _myGradient;
   FIELD<double> * _myDField;
   FIELD<int> * _myIField;
   FIELD<int> *_criteria;