Salome HOME
create boundary 2D mesh and integer criteria field (0 or 1), for filtoo
authorsecher <secher>
Mon, 5 Feb 2007 09:50:22 +0000 (09:50 +0000)
committersecher <secher>
Mon, 5 Feb 2007 09:50:22 +0000 (09:50 +0000)
src/FILTERGUI/FILTER_msg_en.po
src/FILTERGUI/SelectField.cxx
src/FILTERGUI/SelectField.h
src/FILTERGUI/SelectParams.cxx
src/FILTERGUI/SelectParams.h

index bb1788d56dc19a621de289eae1c9ca0bca14a262..8f05252846060daef16d5e42633340665522fc85 100644 (file)
@@ -180,6 +180,14 @@ msgstr "Name"
 msgid "FILTER_TYPE"
 msgstr "Type"
 
+#: SelectField.cxx:74
+msgid "FILTER_SEL_3D"
+msgstr "Select a reference field on a 3D mesh"
+
+#: SelectField.cxx:78
+msgid "FILTER_DIM"
+msgstr "Dimension"
+
 #: SelectField.cxx:91
 msgid "FILTER_MESH"
 msgstr "Mesh"
index 2e2e5b0769f32cf1652054125086e9b797969a68..a3368a5ff1617f2a1c5d1c5ab02822880aca141b 100644 (file)
@@ -35,7 +35,8 @@ SelectField::SelectField(FilterGUI* theModule,const QString& file,
     _file(file),
     _mesh(0),
     _field(0),
-    _ts(0)
+    _ts(0),
+    _dimMesh(-1)
 {
   QListViewItem *element;
 
@@ -68,24 +69,35 @@ SelectField::SelectField(FilterGUI* theModule,const QString& file,
 
   int row = 0;
 
-  // 0)  tree to visualize meshes and fields
+  // 0)  label to select field on 3D mesh
+  _myGroupLayout->addWidget( new QLabel(tr("FILTER_SEL_3D"),_GroupC1), row, 0 );
+  row++;
+
+  // 1)  tree to visualize meshes and fields
   _myList = new QListView( _GroupC1, "List of fields" );
   _myList->setMinimumSize( 400, 400 );
   _myList->setMaximumSize( 400, 400 );
   _myList->setRootIsDecorated(true);
   _myList->addColumn(tr("FILTER_NAME"));
   _myList->addColumn(tr("FILTER_TYPE"));
+  _myList->addColumn(tr("FILTER_DIM"));
 
   for(int i=0;i<numberOfMeshes;i++){
-    element = new QListViewItem( _myList, meshesNames[i], tr("FILTER_MESH") );
+    _dimMesh = _med->getMesh(meshesNames[i])->getMeshDimension();
+    char strd[4];
+    sprintf(strd,"%dD\0",_dimMesh);
+    element = new QListViewItem( _myList, meshesNames[i], tr("FILTER_MESH") ,strd);
     element->setExpandable(true);
     _myList->setOpen(element,true);
 
     for (int j=0; j<numberOfFields; j++){
       deque<DT_IT_> myIteration = _med->getFieldIteration (fieldsNames[j]);
       string meshName = _med->getField(fieldsNames[j],myIteration[0].dt,myIteration[0].it)->getSupport()->getMesh()->getName();
-      if( strcmp(meshName.c_str(),meshesNames[i].c_str()) == 0)
-       new QListViewItem( element, fieldsNames[j], tr("FILTER_FIELD") );
+      if( strcmp(meshName.c_str(),meshesNames[i].c_str()) == 0){
+       QListViewItem *elem = new QListViewItem( element, fieldsNames[j], tr("FILTER_FIELD") );
+       if(_dimMesh != 3)
+         elem->setSelectable(false);
+      }
     }
 
     element->setSelectable(false);
@@ -93,13 +105,13 @@ SelectField::SelectField(FilterGUI* theModule,const QString& file,
   _myGroupLayout->addWidget( _myList, row, 0 );
   row++;
 
-  // 1)  label for time steps
+  // 2)  label for time steps
   _myLab = new QLabel(tr("FILTER_SEL_TS"),_GroupC1);
   _myLab->hide();
   _myGroupLayout->addWidget( _myLab, row, 0 );
   row++;
 
-  // 2)  slider to visualize time steps
+  // 3)  slider to visualize time steps
   _mySlider = new QSlider(_GroupC1);
   _mySlider->setOrientation(Qt::Horizontal);
   _mySlider->setTickmarks(QSlider::Below);
@@ -108,7 +120,7 @@ SelectField::SelectField(FilterGUI* theModule,const QString& file,
   _mySlider->hide();
   row++;
 
-  // 3) buttons Close and Help
+  // 4) buttons Ok, Cancel and Help
   _GroupButtons = new QGroupBox(_GroupC1, "GroupButtons");
   _GroupButtons->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, 0, 0, _GroupButtons->sizePolicy().hasHeightForWidth()));
 //   _GroupButtons->setGeometry(QRect(10, 10, 281, 48));
@@ -153,7 +165,7 @@ SelectField::~SelectField()
 void SelectField::fieldSelected(QListViewItem *lvi)
 {
   if(lvi){
-    if( strcmp(lvi->text(1),"Field") == 0){
+    if( (strcmp(lvi->text(1),"Field") == 0) && (_dimMesh == 3) ){
       _field = lvi->text(0);
       _mesh = lvi->parent()->text(0);
       deque<DT_IT_> myIteration = _med->getFieldIteration (lvi->text(0));
index 35eeba8e3ea079ee41f99fdf2a3452f9b50078e9..2ee4979a0a036b40372595792d1a295659197dbb 100644 (file)
@@ -69,7 +69,7 @@ protected slots:
   virtual void     ClickOnHelp();
 
 private:
-  int _ts;
+  int _ts, _dimMesh;
   QGridLayout *_myGroupLayout, *_GroupButtonsLayout, *_lay;
   QGroupBox* _GroupC1, *_GroupButtons;
   QFrame *_fr;
index 60ddc5468aef8c62725e406c4ed1535ff07a4b8f..b52824a714475c28dfdaf7feedaa350fdd344b86 100644 (file)
@@ -21,7 +21,7 @@
 #include <stdlib.h>
 #include <math.h>
 #include "SelectParams.h"
-#include "utilities.h"
+#include "MEDMEM_MedMeshDriver.hxx"
 
 #include <SUIT_FileDlg.h>
 
 SelectParams::SelectParams(FilterGUI* theModule,SelectField *sel,
                           const char* name,
                           bool modal, WFlags fl)
-  : QDialog(FILTER::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),  _size(1024),_sel(sel)
+  : QDialog(FILTER::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),  _size(1024),_sel(sel),_criteria(NULL),_boundary(NULL)
 {
   if(sel){
 
     // read reference field values
-    ::MEDMEM::MED *med = sel->getMED();
+    _med = sel->getMED();
 
     // Get reference field and time step
     _inputFile = sel->getFile();
@@ -61,16 +61,25 @@ SelectParams::SelectParams(FilterGUI* theModule,SelectField *sel,
       throw SALOME_Exception("Salome Exception");
     }
 
-    deque<DT_IT_> myIteration = med->getFieldIteration (_inputField);
-    MEDMEM::FIELD_* field = med->getField(_inputField,myIteration[_inputTS].dt,myIteration[_inputTS].it);
+    // read of input mesh
+    _mesh = _med->getMesh(_inputMesh);
+    _mesh->read();
+
+    // read of input field
+    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);
+      _myDField = (MEDMEM::FIELD<double>*)field;
+      _myDField->read();
       _myIField = NULL;
     }
     else{
-      _myIField = new MEDMEM::FIELD<int>(MEDMEM::MED_DRIVER,_inputFile,_inputField,myIteration[_inputTS].dt,myIteration[_inputTS].it);
+      _myIField = (MEDMEM::FIELD<int>*)field;
+      _myIField->read();
       _myDField = NULL;
     }
+
+    // Build QT widgets
     buildFrame();
   }
   // if no reference field selection: throw exception
@@ -88,16 +97,29 @@ SelectParams::SelectParams(FilterGUI* theModule,SelectField *sel,
 SelectParams::~SelectParams()
 {
   cout << "SelectParams: destructor called" << endl;
+
+  // destrcution of histogram arrays
   delete _x;
   delete _y;
-  if(_myIField){
+
+  // destruction of support of reference field: reference filed is destroyed
+  // by destruction of med object in _sel destruction
+  if(_myIField)
     delete _myIField->getSupport();
-    delete _myIField;
-  }
-  if(_myDField){
+  if(_myDField)
     delete _myDField->getSupport();
-    delete _myDField;
+
+  // destruction of criteria: support and field
+  if(_criteria){
+    delete _criteria->getSupport();
+    delete _criteria;
   }
+  
+  // destruction of criteria: support and field
+  if(_boundary)
+    delete _boundary;
+  
+  // destruction of SelectField object and MED object in it
   delete _sel;
 }
 
@@ -328,7 +350,7 @@ void SelectParams::buildFrame()
   _GroupC2->setMaximumSize( 500, 500 );
   setMinimumSize( 750, 500 );
   setMaximumSize( 750, 500 );
-//   this->show();  /* displays Dialog */
+
 }
 
 void SelectParams::enterSHisto()
@@ -580,14 +602,21 @@ void SelectParams::process()
 {
   string command;
 
-  // have to call ensight driver MED to generate input for filtoo
-
   MESSAGE("Input MED File : "<<_inputFile);
   MESSAGE("Input Mesh : "<<_inputMesh);
   MESSAGE("Input Field : "<<_inputField);
   MESSAGE("Input Time Step : "<<_inputTS);
   MESSAGE("Output file name: " << _myOFN->text() );
 
+  // generate MED integer field (0 or 1) for filtoo input
+  generateCriteria();
+
+  // generate MED boundary of geometry
+  generateBoundary();
+
+  // have to call ensight driver MED to generate input ensight mesh ,
+  // input ensight boundary mesh and input criteria ensight field for filtoo
+
   // send filtoo command
   command = "cd /export/home/secher/filtoo/example;filtoo -f s -o sf > /tmp/filter.log";
   MESSAGE(command);
@@ -600,6 +629,282 @@ void SelectParams::process()
 
 }
 
+void SelectParams::generateBoundary()
+{
+  int nbTria3=0;
+  int nbQuad4=0;
+  int nbTria6=0;
+  int nbQuad8=0;
+  const int *faces3, *faces4, *faces6, *faces8;
+
+  // get support of faces on boundary
+  MEDMEM::SUPPORT *supF = _mesh->getBoundaryElements(MED_EN::MED_FACE);
+
+  // get support of nodes on boundary
+  MEDMEM::SUPPORT *supN = _mesh->getBoundaryElements(MED_EN::MED_NODE);
+
+  // number of faces on boundary
+  int nbFaces = supF->getNumberOfElements(MED_ALL_ELEMENTS);
+
+  // type of face on boundary
+  const MED_EN::medGeometryElement* geotype = supF->getTypes();
+
+  // number of type of face on boundary
+  int nbTypes = supF->getNumberOfTypes();
+  for(int i=0;i<nbTypes;i++){
+    switch(geotype[i]){
+    case MED_TRIA3:
+      // number of tria3 on boundary
+      nbTria3 = supF->getNumberOfElements(MED_TRIA3);
+      // array of number of tria6 of boundary
+      faces3 = supF->getNumber(MED_TRIA3);
+      break;
+    case MED_QUAD4:
+      // number of quad4 on boundary
+      nbQuad4 = supF->getNumberOfElements(MED_QUAD4);
+      // array of number of tria6 of boundary
+      faces4 = supF->getNumber(MED_QUAD4);
+      break;
+    case MED_TRIA6:
+      // number of tria6 on boundary
+      nbTria6 = supF->getNumberOfElements(MED_TRIA6);
+      // array of number of tria6 of boundary
+      faces6 = supF->getNumber(MED_TRIA6);
+      break;
+    case MED_QUAD8:
+      // number of quad8 on boundary
+      nbQuad8 = supF->getNumberOfElements(MED_QUAD8);
+      // array of number of tria6 of boundary
+      faces8 = supF->getNumber(MED_QUAD8);
+      break;
+    default:
+      MESSAGE("OTHER FACE THAN TRIA3 OR QUAD4 : " << geotype[i]);
+      throw SALOME_Exception("Salome Exception");
+      break;
+    }
+  }
+
+  // number of nodes on boundary
+  int nbNodes = supN->getNumberOfElements(MED_ALL_ELEMENTS);
+
+  MESSAGE(nbFaces<< " FACES " << nbTria3 << " TRIA3 " << nbQuad4 << " QUAD4 " << nbTria6 << " TRIA6 " << nbQuad8 << " QUAD8 " << nbNodes << " NODES on BOUNDARY");
+
+  // array of number of faces of boundary
+  const int *faces = supF->getNumber(MED_ALL_ELEMENTS);
+  // array of number of nodes of boundary
+  const int *nodes = supN->getNumber(MED_ALL_ELEMENTS);
+
+  // array of coordinates of nodes in input 3D mesh
+  const double *coord = _mesh->getCoordinates(MED_FULL_INTERLACE);
+
+  // space dimension of input mesh
+  int spaceDim = _mesh->getSpaceDimension();
+
+  // array of coordinates of nodes in boundary
+  double *coordB = new double[spaceDim*nbNodes];
+
+  map<int,int> ONNodes;
+  for(int i=0;i<nbNodes;i++){
+    for(int j=0;j<spaceDim;j++)
+      coordB[spaceDim*i+j] = coord[(nodes[i]-1)*spaceDim+j];
+    ONNodes[nodes[i]] = i+1;
+  }
+
+  // size of nodal connectivity of the faces of boundary
+  int nbElem = 3*nbTria3 + 4*nbQuad4 + 6*nbTria6 + 8*nbQuad8;
+
+  // allocation of array of nodal connectivity of the faces of boudary
+  int *connB = new int[nbElem];
+
+  int ind=0;
+
+  // array of nodal connectivity of the tria3 of input 3D mesh
+  if( nbTria3 > 0 ){
+    const int *conn3 = _mesh->getConnectivity(MED_FULL_INTERLACE,MED_NODAL,MED_FACE,MED_TRIA3);
+    for(int i=0;i<nbTria3;i++){
+      for(int j=0;j<3;j++)
+       connB[ind+j] = ONNodes[conn3[(faces3[i]-1)*3+j]];
+      ind+=3;
+    }
+  }
+  // array of nodal connectivity of the quad4 of input 3D mesh
+  if( nbQuad4 > 0 ){
+    const int *conn4 = _mesh->getConnectivity(MED_FULL_INTERLACE,MED_NODAL,MED_FACE,MED_QUAD4);
+    for(int i=0;i<nbQuad4;i++){
+      for(int j=0;j<4;j++)
+       connB[ind+j] = ONNodes[conn4[(faces4[i]-1)*4+j]];
+      ind+=4;
+    }
+  }
+  // array of nodal connectivity of the tria6 of input 3D mesh
+  if( nbTria6 > 0 ){
+    const int *conn6 = _mesh->getConnectivity(MED_FULL_INTERLACE,MED_NODAL,MED_FACE,MED_TRIA6);
+    for(int i=0;i<nbTria6;i++){
+      for(int j=0;j<6;j++)
+       connB[ind+j] = ONNodes[conn6[(faces6[i]-1)*6+j]];
+      ind+=6;
+    }
+  }
+  // array of nodal connectivity of the quad4 of input 3D mesh
+  if( nbQuad8 > 0 ){
+    const int *conn8 = _mesh->getConnectivity(MED_FULL_INTERLACE,MED_NODAL,MED_FACE,MED_QUAD8);
+    for(int i=0;i<nbQuad8;i++){
+      for(int j=0;j<8;j++)
+       connB[ind+j] = ONNodes[conn8[(faces8[i]-1)*8+j]];
+      ind+=8;
+    }
+  }
+  // boundary mesh creation   
+  _boundary = new MESHING();
+  
+  _boundary->setName( "Boundary" );
+
+  int nbOfClassicalTypesFace[4];
+  medGeometryElement classicalTypesFace[4];
+  ind=0;
+  if( nbTria3 > 0 ){
+    nbOfClassicalTypesFace[ind] = nbTria3;
+    classicalTypesFace[ind] = MED_EN::MED_TRIA3;
+    ind++;
+  }
+  if( nbQuad4 > 0 ){
+    nbOfClassicalTypesFace[ind] = nbQuad4;
+    classicalTypesFace[ind] = MED_EN::MED_QUAD4;
+    ind++;
+  }
+  if( nbTria6 > 0 ){
+    nbOfClassicalTypesFace[ind] = nbTria6;
+    classicalTypesFace[ind] = MED_EN::MED_TRIA6;
+    ind++;
+  }
+  if( nbQuad8 > 0 ){
+    nbOfClassicalTypesFace[ind] = nbQuad8;
+    classicalTypesFace[ind] = MED_EN::MED_QUAD8;
+    ind++;
+  }
+
+  _boundary->setNumberOfTypes(ind, MED_EN::MED_CELL) ;
+  _boundary->setTypes( classicalTypesFace, MED_EN::MED_CELL) ;
+  _boundary->setNumberOfElements(nbOfClassicalTypesFace, MED_EN::MED_CELL);
+
+  if( nbTria3 > 0 )
+    _boundary->setConnectivity( connB, MED_EN::MED_CELL, MED_EN::MED_TRIA3);
+  if( nbQuad4 > 0 )
+    _boundary->setConnectivity( connB+3*nbTria3, MED_EN::MED_CELL, MED_EN::MED_QUAD4);
+  if( nbTria6 > 0 )
+    _boundary->setConnectivity( connB+3*nbTria3+4*nbQuad4, MED_EN::MED_CELL, MED_EN::MED_TRIA6);
+  if( nbQuad8 > 0 )
+    _boundary->setConnectivity( connB+3*nbTria3+4*nbQuad4+6*nbTria6, MED_EN::MED_CELL, MED_EN::MED_QUAD8);
+
+  _boundary->setMeshDimension(3);
+  _boundary->setSpaceDimension(3);
+  _boundary->setNumberOfNodes(nbNodes);
+  _boundary->setCoordinates(3, nbNodes, coordB, "CARTESIAN",
+                         MED_EN::MED_FULL_INTERLACE);
+
+  // Set coordinates names
+  string coordname[3] = { "x", "y", "z" } ;
+  _boundary->setCoordinatesNames(coordname) ;
+
+  // Set coordinates units
+  string coordunit[3] = { "m", "m", "m" } ;
+  _boundary->setCoordinatesUnits(coordunit) ;
+
+  // write the boundary mesh in a MED file for test
+//   MED_MESH_WRONLY_DRIVER myMeshDriver("/home/secher/mymesh.med",_boundary);
+//   int current=_boundary->addDriver(myMeshDriver);
+//   _boundary->write(current);
+
+  // support destruction
+  delete supF;
+  delete supN;
+
+  // connectivity destruction
+  delete [] connB;
+
+  // coordinate destruction
+  delete [] coordB;
+
+}
+
+void SelectParams::generateCriteria()
+{
+  double val, min, max;
+  bool isGVal;
+  MED_EN::medEntityMesh typ;
+
+  // if reference field is on elements create reference field on nodes
+  if(_myDField)
+    typ = _myDField->getSupport()->getEntity();
+  else
+    typ = _myIField->getSupport()->getEntity();
+
+  switch(typ){
+  case MED_CELL:
+    MESSAGE("REFERENCE FIELD ON CELL");
+    return;
+  case MED_FACE:
+    MESSAGE("REFERENCE FIELD ON FACE");
+    return;
+  case MED_EDGE:
+    MESSAGE("REFERENCE FIELD ON EDGE");
+    return;
+  case MED_NODE:
+    MESSAGE("REFERENCE FIELD ON NODES");
+    break;
+  case MED_ALL_ENTITIES:
+    MESSAGE("REFERENCE FIELD ON ALL ELEMENTS");
+    return;
+  }
+
+  // create support on nodes
+  SUPPORT *sup = new SUPPORT(_mesh,"Support",MED_NODE);
+
+  // create integer field on nodes
+  _criteria = new FIELD<int>(sup,1);
+
+  // read number of nodes
+  int NumberOf = sup->getNumberOfElements(MED_ALL_ELEMENTS);
+
+  for (int i=1; i<NumberOf+1; i++){
+
+    // read reference field value
+    if(_myDField)
+      val = _myDField->getValueIJ(i,1);
+    else
+      val = (double)_myIField->getValueIJ(i,1);
+
+    // set criteria field value
+    if( _myOneThresh->isChecked() ){
+      if( _myExt->isChecked() )
+       if( val >= _fthresh ) isGVal = true;
+        else isGVal = false;
+      else
+       if( val <= _fthresh ) isGVal = true;
+        else isGVal = false;
+    }
+    else{
+      min = _fthresh;
+      max = _sthresh;
+      if(_sthresh < _fthresh){ 
+       min = _sthresh;
+       max = _fthresh;
+      }
+      if( _myExt->isChecked() )
+       if( (val <= min) || (val >= max) ) isGVal = true;
+        else isGVal = false;   
+      else
+       if( (val >= min) && (val <= max) ) isGVal = true;
+        else isGVal = false;   
+    }
+    if( isGVal )
+      _criteria->setValueIJ(i,1,1);
+    else
+      _criteria->setValueIJ(i,1,0);
+  }
+}
+
 void SelectParams::calcRateRed()
 {
   int i1, i2, i;
index d1898ebf69b21657fdc8a6b8ac5c3828542599dd..d43aa03f41de373127cbad02bb5c5c270b88245c 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "utilities.h"
 #include "MEDMEM_Med.hxx"
+#include "MEDMEM_Meshing.hxx"
 
 #include "SelectField.h"
 #include <qwt_plot.h>
@@ -63,6 +64,8 @@ protected:
   virtual void     displayFThresh();
   virtual void     displaySThresh();
   virtual void     enableWidgets();
+  virtual void     generateCriteria();
+  virtual void     generateBoundary();
 
 protected slots:
   virtual void     enterSHisto();
@@ -99,11 +102,14 @@ private:
   QwtDiMap _qmap;
   QFrame *_fr;
   QString _inputFile, _inputMesh, _inputField;
-  FIELD<double> * _myDField;
-  FIELD<int> * _myIField;
   int _inputTS;
   SelectField *_sel;
-
+  ::MEDMEM::MED *_med;
+  MEDMEM::MESH* _mesh;
+  FIELD<double> * _myDField;
+  FIELD<int> * _myIField;
+  FIELD<int> *_criteria;
+  MESHING* _boundary;
 };
 
 #endif