]> SALOME platform Git repositories - modules/filter.git/commitdiff
Salome HOME
put MED processes in engine, and use corba between GUI and Engine
authorsecher <secher>
Fri, 16 Mar 2007 12:58:38 +0000 (12:58 +0000)
committersecher <secher>
Fri, 16 Mar 2007 12:58:38 +0000 (12:58 +0000)
configure.in.base
idl/FILTER_Gen.idl
src/FILTER/Filter_Gen_i.cxx
src/FILTER/Filter_Gen_i.hxx
src/FILTER/Makefile.in
src/FILTERGUI/FilterGUI.cxx
src/FILTERGUI/FilterGUI.h
src/FILTERGUI/SelectField.cxx
src/FILTERGUI/SelectField.h
src/FILTERGUI/SelectParams.cxx
src/FILTERGUI/SelectParams.h

index 3336816ccdf5db98b34e273e1fcfc49de3e29eeb..bffa2f4af53e4b536d74f138d23529485bca2106 100644 (file)
@@ -183,6 +183,22 @@ echo
 
 CHECK_QT
 
+echo
+echo ---------------------------------------------
+echo testing msg2qm
+echo ---------------------------------------------
+echo
+
+CHECK_MSG2QM
+
+echo
+echo ---------------------------------------------
+echo testing VTK
+echo ---------------------------------------------
+echo
+
+CHECK_VTK
+
 echo
 echo ---------------------------------------------
 echo testing HDF5
@@ -199,6 +215,22 @@ echo
 
 CHECK_MED2
 
+echo
+echo ---------------------------------------------
+echo BOOST Library
+echo ---------------------------------------------
+echo
+
+CHECK_BOOST
+
+echo
+echo ---------------------------------------------
+echo Testing OpenCascade
+echo ---------------------------------------------
+echo
+
+CHECK_CAS
+
 echo
 echo ---------------------------------------------
 echo Testing qwt
@@ -266,7 +298,7 @@ echo ---------------------------------------------
 echo
 
 echo Configure
-variables="cc_ok python_ok swig_ok threads_ok qt_ok hdf5_ok med2_ok omniORB_ok qwt_ok doxygen_ok graphviz_ok Kernel_ok Med_ok filtoo_ok"
+variables="cc_ok boost_ok python_ok swig_ok threads_ok qt_ok vtk_ok hdf5_ok med2_ok omniORB_ok occ_ok qwt_ok doxygen_ok graphviz_ok Kernel_ok Med_ok filtoo_ok"
 
 for var in $variables
 do
index ea89d2148fd5e677ee08a96446543e4c464b5769..14e76912193a6a98d62028abced7c0946a63002d 100644 (file)
 
 #include "SALOME_Exception.idl"
 #include "SALOME_Component.idl"
-#include "SALOMEDS.idl"
 
 module SALOME_FILTER
 {
-  interface FILTER_Gen : Engines::Component, SALOMEDS::Driver
-  {
-//     /*!
-//       it returns a Corba pointer %MESH on the mesh stored in the .med file
-//       <VAR>fileName</VAR> with the name <VAR>meshName</VAR>.
-//      */
-//     SALOME_FILTER::MESH readMeshInFile(in string fileName, in string studyName,
-//                                 in string meshName)
-//       raises(SALOME::SALOME_Exception);
+  struct DT_IT {
+    long dt;
+    long it;
+  };
 
-//     /*!
-//       it returns a Corba pointer %FIELD on the field instance with the order
-//       <VAR>ordre</VAR> at the iteration <VAR>iter</VAR>, stored in the .med
-//       file <VAR>fileName</VAR> with the name <VAR>fieldName</VAR>.
-//      */
-//     SALOME_FILTER::FIELD readFieldInFile(in string fileName, in string studyName,
-//                                   in string fieldName, in long ordre,
-//                                   in long iter)
-//       raises (SALOME::SALOME_Exception);
+  enum rfunc {F_FIELD,F_GRAD};
+  typedef rfunc ref_func;
+  typedef sequence<long> LongSeq;
+  typedef sequence<string> StrSeq;
+  typedef sequence<DT_IT> DTITSeq;
 
-//     /*!
-//       it returns a Corba pointer on the %MED object regrouping all objects
-//       (%MESH and %FIELD) stored in the file <VAR>fileName</VAR>. All instances
-//       of the fields are stored without their type.
-//     */
-//     SALOME_FILTER::MED readStructFile(in string fileName,
-//                                in string studyName)
-//       raises (SALOME::SALOME_Exception);
+  interface FILTER_Gen : Engines::Component
+  {
+    exception FilterError{
+      string error_msg;
+    };
 
-//     /*!
-//       It pushes all Corba pointers (%MED, %MESH, %FIELD) in the study named
-//       <VAR>studyName</VAR>. The %MED object regroups all objects
-//       (%MESH and %FIELD) stored in the file <VAR>fileName</VAR> and all
-//       instances of the fields are stored with their own type.
-//     */
-//     void readStructFileWithFieldType(in string fileName,
-//                                  in string studyName)
-//       raises (SALOME::SALOME_Exception);
+    void loadMED(in string inMEDFile);
+    void unloadMED();
+    StrSeq getMeshNames();
+    StrSeq getFieldNames();
+    long getMeshDimension(in string meshName);
+    DTITSeq getFieldIteration(in string fieldName);
+    string getMeshName(in string fieldName,in long dt,in long it);
+    void readReferenceField(in string meshName,in string fieldName,in long ts);
+    void buildGradient() raises(FilterError);
+    void getMinMax(out double min,out double max,in ref_func rf);
+    LongSeq getHistogram(in long size,in ref_func rf);
+    void generateCriteria(in long nbthresh,in double fthresh,in double thresh,in long areaFlag) raises(FilterError);
+    void createEnsightInputFiles();
+    void filtering();
+    void projectFieldsOnDecimateMesh() raises(FilterError);
+    void createMedOutputFile(in string outMedFile);
   };
 
 };
index 34be897408e635fb890a3a347c6ed0180765bb40..6c174439157b6e6d01f99f9327e7a082c431961c 100755 (executable)
@@ -33,6 +33,7 @@
 #include "Utils_CorbaException.hxx"
 #include "utilities.h"
 
+#include "MEDMEM_EnsightMeshDriver.hxx"
 #include <string>
 #include <deque>
 #include <map>
 #include <TCollection_AsciiString.hxx>
 #include <TColStd_SequenceOfAsciiString.hxx>
 #include <HDFascii.hxx>
-#include "SALOMEDS_Tool.hxx"
 
 using namespace std;
- Filter_Gen_i* Filter_Gen_i::_FILTERGen = NULL;
+using namespace SALOME_FILTER;
+Filter_Gen_i* Filter_Gen_i::_FILTERGen = NULL;
 
 //=============================================================================
 /*!
@@ -67,7 +68,7 @@ Filter_Gen_i:: Filter_Gen_i(CORBA::ORB_ptr orb,
                                PortableServer::ObjectId * contId,
                                const char *instanceName,
                                const char *interfaceName) :
-  Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
+  Engines_Component_i(orb, poa, contId, instanceName, interfaceName),_med(NULL),_newMed(NULL),_mesh(NULL),_newMesh(NULL),_myGradient(NULL),_myDField(NULL),_myIField(NULL),_criteria(NULL)
 {
   MESSAGE("activate object");
   _thisObj = this ;
@@ -79,7 +80,6 @@ Filter_Gen_i:: Filter_Gen_i(CORBA::ORB_ptr orb,
   ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting()) ;
   _NS->init_orb( _orb ) ;
 
-  //_myFilterI = 0;
   _FILTERGen = this;
 }
 
@@ -92,5 +92,593 @@ Filter_Gen_i:: Filter_Gen_i(CORBA::ORB_ptr orb,
 Filter_Gen_i::~Filter_Gen_i()
 {
   MESSAGE("Filter_Gen_i::~Filter_Gen_i");
+
+  // destruction of gradient field
+  if(_myGradient)
+    delete _myGradient;
+
+  // destruction of support of reference field: reference field is destroyed
+  // by destruction of med object
+  if(_myIField)
+    delete _myIField->getSupport();
+  if(_myDField)
+    delete _myDField->getSupport();
+
+ // destruction of criteria: support and field
+  if(_criteria){
+    delete _criteria->getSupport();
+    delete _criteria;
+  }
+
+  if(_med)
+    delete _med;
+}
+
+void Filter_Gen_i::loadMED(const char* inMedFile)
+{
+  SCRUTE(inMedFile);
+  _file = inMedFile;
+  _med = new ::MED(MED_DRIVER,_file);
+}
+
+void Filter_Gen_i::unloadMED()
+{
+  MESSAGE("unloadMED called");
+  // destruction of gradient field
+  if(_myGradient){
+    delete _myGradient;
+    _myGradient=NULL;
+  }
+
+  // destruction of support of reference field: reference field is destroyed
+  // by destruction of med object
+  if(_myIField){
+    delete _myIField->getSupport();
+    _myIField=NULL;
+  }
+  if(_myDField){
+    delete _myDField->getSupport();
+    _myDField=NULL;
+  }
+
+ // destruction of criteria: support and field
+  if(_criteria){
+    delete _criteria->getSupport();
+    delete _criteria;
+    _criteria=NULL;
+  }
+
+  if(_med){
+    delete _med;
+    _med=NULL;
+  }
+}
+
+StrSeq* Filter_Gen_i::getMeshNames()
+{
+  StrSeq *seq = new StrSeq();
+  deque<string> deq = _med->getMeshNames();
+  seq->length(deq.size());
+  for(int i=0;i<deq.size();i++)
+    (*seq)[i] = deq[i].c_str();
+  return seq;
+}
+  
+StrSeq * Filter_Gen_i::getFieldNames()
+{
+  StrSeq *seq = new StrSeq();
+  deque<string> deq = _med->getFieldNames();
+  seq->length(deq.size());
+  for(int i=0;i<deq.size();i++)
+     (*seq)[i] = deq[i].c_str();
+  return seq;
+}
+
+CORBA::Long  Filter_Gen_i::getMeshDimension(const char* meshName)
+{
+  return _med->getMesh(meshName)->getMeshDimension();
+}
+
+DTITSeq* Filter_Gen_i::getFieldIteration(const char* fieldName)
+{
+  DTITSeq *seq = new DTITSeq();
+  deque<DT_IT_> deq = _med->getFieldIteration(fieldName);
+  seq->length(deq.size());
+  for(int i=0;i<deq.size();i++){
+    (*seq)[i].dt = deq[i].dt;
+    (*seq)[i].it = deq[i].it;
+  }
+  return seq;
+}
+
+char* Filter_Gen_i::getMeshName(const char* fieldName,CORBA::Long dt,CORBA::Long it)
+{
+  return (char*)(_med->getField(fieldName,dt,it)->getSupport()->getMesh()->getName().c_str());
+}
+
+void Filter_Gen_i::readReferenceField(const char* meshName, const char* fieldName, CORBA::Long ts)
+{
+  // read of input mesh
+  _mesh = _med->getMesh(meshName);
+  _mesh->read();
+  
+  // read of input field
+  deque<DT_IT_> myIteration = _med->getFieldIteration (fieldName);
+  MEDMEM::FIELD_* field = _med->getField(fieldName,myIteration[ts].dt,myIteration[ts].it);
+  if (dynamic_cast<MEDMEM::FIELD<double>*>(field)){
+    _myDField = (MEDMEM::FIELD<double>*)field;
+    _myDField->read();
+    _myIField = NULL;
+  }
+  else{
+    _myIField = (MEDMEM::FIELD<int>*)field;
+    _myIField->read();
+    _myDField = NULL;
+  }
+}
+
+void Filter_Gen_i::buildGradient() throw(SALOME_FILTER::FILTER_Gen::FilterError)
+{
+  if(!_myGradient){
+    FIELD<double> * gradient;
+    try{
+      if(_myDField)
+       gradient = _myDField->buildGradient();
+      else
+       gradient = _myIField->buildGradient();
+      _myGradient = gradient->buildNorm2Field();
+      delete gradient;
+    }
+    catch(MEDEXCEPTION& Mex){
+      MESSAGE("SALOME_Exception: Can't calculate gradient");
+      throw SALOME_FILTER::FILTER_Gen::FilterError("Can't calculate gradient");
+    }
+  }
+}
+
+void Filter_Gen_i::getMinMax(CORBA::Double& imin, CORBA::Double& imax,ref_func rf)
+{
+  double min, max;
+
+  switch(rf){
+  case F_FIELD:
+    if (_myDField)
+      _myDField->getMinMax(min,max);
+    else{
+      int xmin, xmax;
+      _myIField->getMinMax(xmin,xmax);
+      min = (double)xmin;
+      max = (double)xmax;
+    }
+    break;
+  case F_GRAD:
+    _myGradient->getMinMax(min,max);
+    break;
+  }
+  imin = min;
+  imax = max;
+}
+
+LongSeq* Filter_Gen_i::getHistogram(CORBA::Long size,ref_func rf)
+{
+  int mysize = size;
+  vector<int> myh;
+
+  switch(rf){
+  case F_FIELD:
+    if (_myDField)
+      myh = _myDField->getHistogram(mysize);
+    else
+      myh = _myIField->getHistogram(mysize);
+    break;
+  case F_GRAD:
+    myh = _myGradient->getHistogram(mysize);
+    break;
+  }
+
+  LongSeq *seq = new LongSeq();
+  seq->length(myh.size());
+  for(int i=0;i<myh.size();i++)
+    (*seq)[i] = myh[i];
+  return seq;
+}
+
+void Filter_Gen_i::generateCriteria(CORBA::Long nbthresh,CORBA::Double fthresh,CORBA::Double sthresh,CORBA::Long areaFlag) throw(SALOME_FILTER::FILTER_Gen::FilterError)
+{
+  double val, min, max;
+  double sigmaV;
+  bool isGVal;
+  MED_EN::medEntityMesh typ;
+  const int *revC;
+  const int *indC;
+  FIELD<double> *volume;
+  set <int> listElements;
+  set <int>::iterator elemIt ;
+
+  if(_myDField)
+    typ = _myDField->getSupport()->getEntity();
+  else
+    typ = _myIField->getSupport()->getEntity();
+
+  // create support on nodes
+  SUPPORT *sup = new SUPPORT(_mesh,"Support",MED_NODE);
+
+  // create integer field on nodes
+  _criteria = new FIELD<int>(sup,1);
+
+  _criteria->setName("Criteria");
+
+  // read number of nodes
+  int NumberOf = sup->getNumberOfElements(MED_ALL_ELEMENTS);
+
+  // if reference field is on elements get reference field on nodes
+  switch(typ){
+  case MED_CELL:
+    if(_myDField){
+      // calculate reverse connectivity to have the list of elements which contains node i
+      revC = _myDField->getSupport()->getMesh()->getReverseConnectivity(MED_NODAL,typ);
+      indC = _myDField->getSupport()->getMesh()->getReverseConnectivityIndex(MED_NODAL,typ);
+      // calculate volume field on mesh
+      volume = _myDField->getSupport()->getMesh()->getVolume(_myDField->getSupport());
+    }
+    else{
+      // calculate reverse connectivity to have the list of elements which contains node i
+      revC = _myIField->getSupport()->getMesh()->getReverseConnectivity(MED_NODAL,typ);
+      indC = _myIField->getSupport()->getMesh()->getReverseConnectivityIndex(MED_NODAL,typ);
+      // calculate volume field on mesh
+      volume = _myIField->getSupport()->getMesh()->getVolume(_myIField->getSupport());
+    }
+    break;
+  default:
+    break;
+  }
+
+  for (int i=1; i<NumberOf+1; i++){
+
+    // if reference field is on elements get reference field on nodes
+    switch(typ){
+    case MED_CELL:
+      // listElements contains elements which contains a node of element i
+      listElements.clear();
+      
+      for(int j=indC[i-1];j<indC[i];j++){
+       // c element contains node i
+       int c=revC[j-1];
+       listElements.insert(c);
+      }
+
+      // calculate field value on node i 
+      sigmaV = 0.;
+      val = 0.;
+      for(elemIt=listElements.begin();elemIt!=listElements.end();elemIt++){
+       int elem = *elemIt;
+       double vol = volume->getValueIJ(elem,1);
+       if( vol != 0. ){
+         sigmaV += 1./vol;
+         if(_myDField)
+           val += _myDField->getValueIJ(elem,1)/vol;
+         else
+           val += ((double)_myIField->getValueIJ(elem,1))/vol;
+       }
+      }
+      val /= sigmaV;
+      break;
+    case MED_FACE:
+      throw SALOME_FILTER::FILTER_Gen::FilterError("Filter doesn't run on reference field on faces");
+      break;
+    case MED_EDGE:
+      throw SALOME_FILTER::FILTER_Gen::FilterError("Filter doesn't run on reference field on edges");
+      break;
+    case MED_NODE:
+      // read reference field value
+      if(_myDField)
+       val = _myDField->getValueIJ(i,1);
+      else
+       val = (double)_myIField->getValueIJ(i,1);
+      break;
+    case MED_ALL_ENTITIES:
+      throw SALOME_FILTER::FILTER_Gen::FilterError("Filter doesn't run on reference field on all entities");
+      break;
+    }
+
+    // set criteria field value
+    if( nbthresh == 1 ){
+      if( areaFlag )
+       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( areaFlag )
+       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 Filter_Gen_i::createEnsightInputFiles()
+{
+  int id;
+
+  MESSAGE("Calculate boundary");
+  // generate MED boundary of geometry
+  SUPPORT *supB = _mesh->getBoundaryElements(MED_FACE);
+
+  // call ensight driver MED to generate input ensight mesh ,
+  // input ensight boundary mesh and input criteria ensight field for filtoo
+  MESSAGE("Create ensight mesh");
+  ENSIGHT_MESH_DRIVER myMeshDriver("/tmp/input.geom",_mesh);
+  myMeshDriver.addSupport(supB);
+  id=_mesh->addDriver(myMeshDriver);
+  _mesh->write(id);
+
+  MESSAGE("Create ensight field");
+  ENSIGHT_FIELD_DRIVER<int> myFieldDriver("/tmp/input.data",_criteria);
+  id=_criteria->addDriver(myFieldDriver);
+  _criteria->write(id);
+}
+
+void Filter_Gen_i::filtering()
+{
+  string command;
+
+  MESSAGE("call filtoo");
+  // send filtoo command
+  command = "cd /tmp;filtoo -f input -o output > /tmp/filter.log";
+  MESSAGE(command);
+  system(command.c_str());
+
+  // destroy filtoo input files
+//   command = "cd /tmp;rm -f input.*";
+//   MESSAGE(command);
+//   system(command.c_str());
+}
+
+void Filter_Gen_i::projectFieldsOnDecimateMesh() throw(SALOME_FILTER::FILTER_Gen::FilterError)
+{
+  string command;
+
+  // have to call ensight driver MED to generate output MED file from filtoo output
+  MED _newMed(ENSIGHT_DRIVER,"/tmp/output.case");
+  _newMed.read();
+
+  // destroy filtoo output files
+//   command = "cd /tmp;rm -f output.*";
+//   MESSAGE(command);
+//   system(command.c_str());
+
+  // get new mesh name
+  deque<string> meshesNames = _newMed.getMeshNames();
+  int numberOfMeshes = meshesNames.size();
+  if( numberOfMeshes != 1)
+    throw SALOME_FILTER::FILTER_Gen::FilterError("Unvalid number of meshes in filtoo output");
+
+  // new mesh generated by filtoo
+  _newMesh = _newMed.getMesh(meshesNames[0]);
+
+  // create support on nodes on all new mesh
+  SUPPORT *newSup = new SUPPORT(_newMesh,"Support",MED_NODE);
+
+  // read the id of nodes of output mesh, in input mesh
+  readMapping();
+
+  // read connectivity of new mesh to get neighbour node of created node
+  _connL = _newMesh->getConnectivityLength(MED_FULL_INTERLACE,MED_NODAL,MED_CELL,MED_ALL_ELEMENTS);
+  _conn = _newMesh->getConnectivity(MED_FULL_INTERLACE,MED_NODAL,MED_CELL,MED_ALL_ELEMENTS);
+  _connI = _newMesh->getConnectivityIndex(MED_NODAL,MED_CELL);
+
+  // read number of nodes on new mesh
+  int numberOfNodes = newSup->getNumberOfElements(MED_ALL_ELEMENTS);
+  int numberOfComponents;
+
+  deque<string> fieldsNames = _med->getFieldNames();
+  int numberOfFields = fieldsNames.size();
+
+  try{
+
+    // loop on fields
+    for (int i=0; i<numberOfFields; i++){
+
+      // is the input field the reference field?
+      bool isReferenceField= false;
+      if(_myDField){
+       if( strcmp(_myDField->getName().c_str(),fieldsNames[i].c_str()) == 0)
+         isReferenceField = true;
+      }
+      else
+       if( strcmp(_myIField->getName().c_str(),fieldsNames[i].c_str()) == 0)
+         isReferenceField = true;
+
+      deque<DT_IT_> myIteration = _med->getFieldIteration (fieldsNames[i]);
+      string meshName = _med->getField(fieldsNames[i],myIteration[0].dt,myIteration[0].it)->getSupport()->getMesh()->getName();
+
+      // we process only fields on input mesh
+      if( strcmp(meshName.c_str(),_mesh->getName().c_str()) == 0){
+
+       // loop on time steps
+       int numberOfIteration = myIteration.size();
+       for(int j=0;j<numberOfIteration;j++){
+
+         // select input field
+         MEDMEM::FIELD_* field = _med->getField(fieldsNames[i],myIteration[j].dt,myIteration[j].it);
+         FIELD<double> *myDField = NULL;
+         FIELD<double> *newDField = NULL;
+         FIELD<int> *myIField = NULL;
+         FIELD<int> *newIField = NULL;
+
+         if (dynamic_cast<MEDMEM::FIELD<double>*>(field)){
+           if(!isReferenceField)
+             // read input field on input file
+             myDField = new FIELD<double>(MEDMEM::MED_DRIVER,_file,fieldsNames[i],myIteration[j].dt,myIteration[j].it);
+           else
+             myDField = _myDField;
+           // create new output field
+           newDField = new FIELD<double>(newSup,field->getNumberOfComponents());
+           newDField->setName(myDField->getName());
+         }
+         else{
+           if(!isReferenceField)
+             // read input field on input file
+             myIField = new FIELD<int>(MEDMEM::MED_DRIVER,_file,fieldsNames[i],myIteration[j].dt,myIteration[j].it);
+           else
+             myIField = _myIField;
+           // create new output field
+           newIField = new FIELD<int>(newSup,field->getNumberOfComponents());
+           newIField->setName(myIField->getName());
+         }
+         
+         // loop on nodes on new field
+         for (int k=1; k<numberOfNodes+1; k++){
+           // read number of nodes on input field
+           int l = getNodeNumber(k);
+           double dval;
+           int ival;
+           
+           for(int c=1;c<=numberOfComponents;c++){
+             // read value on input field
+             if(myDField)
+               dval = myDField->getValueIJ(l,c);
+             else
+               ival = myIField->getValueIJ(l,c);
+             
+             // write value on new field
+             if(newDField)
+               newDField->setValueIJ(k,c,dval);
+             else
+               newIField->setValueIJ(k,c,ival);
+           }
+         
+         }
+         if(newDField)
+           _newMed.addField(newDField);
+         else
+           _newMed.addField(newIField);
+         
+         // Destroy input field if not referecne field
+         if(!isReferenceField)
+           if(myDField){
+             delete myDField->getSupport();
+             delete myDField;
+           }
+           else{
+             delete myIField->getSupport();
+             delete myIField;
+           }
+         
+       }
+      }
+    }
+  }
+  catch(SALOME_Exception){
+    throw SALOME_FILTER::FILTER_Gen::FilterError("Unvalid decimate mlesh created by filtoo");
+  }
+}
+
+void Filter_Gen_i::readMapping()
+{
+  ifstream mapFile("/tmp/output.renum");
+
+  // read number of vertices to map
+  mapFile >> _nbvmap;
+  _map = new int[_nbvmap];
+  
+  for(int i=0;i<_nbvmap;i++)
+    mapFile >> _map[i];
+
+}
+
+int Filter_Gen_i::getNodeNumber(int num)
+{
+  int oldnum = _map[num];
+
+  // if new node get neighbour node
+  if(oldnum == 0)
+    oldnum = _map[getNeighbourVertex(num)];
+  
+  return oldnum;
 }
 
+int Filter_Gen_i::getNeighbourVertex(int num) throw(SALOME_Exception)
+{
+  int nnum;
+  int numberOfElements = _newMesh->getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS);
+
+  int index;
+  // get index of created node in connectivity array
+  for(index=0;index<_connL;index++){
+    if(_conn[index] == num){
+
+      // get index of element which contain created node
+      int i;
+      for(i=1;i<=numberOfElements;i++)
+       if(_connI[i] > index)
+         break;
+
+      // search neighbour node which are in old mesh
+      for(int j=_connI[i-1];j<_connI[i];j++){
+       nnum = _conn[j-1];
+       if( _map[nnum] != 0)
+         break;
+      }
+
+      // if neighbour node in old mesh: go out loop, else continue
+      if(_map[nnum]!=0)
+       break;
+    }
+  }
+
+  // if no neighbour node in old mesh: throw exception
+  if(_map[nnum]==0)
+    throw SALOME_Exception("None of the neighbour node are in old mesh!!");
+
+  return nnum;
+}
+
+void Filter_Gen_i::createMedOutputFile(const char *outMedFile)
+{
+  int id;
+
+  MESSAGE("Create ensight mesh");
+  id = _newMed->addDriver(MED_DRIVER,outMedFile);
+  _newMed->write(id);
+}
+
+
+//=============================================================================
+/*!
+ * C factory, accessible with dlsym, after dlopen
+ */
+//=============================================================================
+
+extern "C"
+{
+  PortableServer::ObjectId * FILTEREngine_factory(
+                              CORBA::ORB_ptr orb,
+                              PortableServer::POA_ptr poa,
+                              PortableServer::ObjectId * contId,
+                              const char *instanceName,
+                              const char *interfaceName)
+  {
+    MESSAGE("PortableServer::ObjectId * FilterEngine_factory()");
+    SCRUTE(interfaceName);
+    Filter_Gen_i * myFilter_Gen
+      = new Filter_Gen_i(orb, poa, contId, instanceName, interfaceName);
+    return myFilter_Gen->getId() ;
+  }
+}
index 53205294510da30cef1f4cb89124a7f303bb39b4..7d24408b139a718489ebf39783c2583b761a10ce 100644 (file)
 #include <SALOMEconfig.h>
 #include <map>
 #include CORBA_SERVER_HEADER(FILTER_Gen)
-#include CORBA_SERVER_HEADER(SALOME_ModuleCatalog)
+
+#include "utilities.h"
+#include "MEDMEM_Med.hxx"
+#include "Utils_SALOME_Exception.hxx"
 
 #include "SALOME_Component_i.hxx"
 #include "SALOME_NamingService.hxx"
 
-#include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
-
 class Filter_Gen_i:
   public POA_SALOME_FILTER::FILTER_Gen,
   public Engines_Component_i 
 {
-private:
-
 public:
   Filter_Gen_i();
   Filter_Gen_i(CORBA::ORB_ptr orb,
@@ -54,13 +53,54 @@ public:
            const char *interfaceName);
   virtual ~Filter_Gen_i();
 
+  void loadMED(const char* inMedFile);
+  void unloadMED();
+  SALOME_FILTER::StrSeq* getMeshNames();
+  SALOME_FILTER::StrSeq* getFieldNames();
+  CORBA::Long getMeshDimension(const char* meshName);
+  SALOME_FILTER::DTITSeq* getFieldIteration(const char* fieldName);
+  char* getMeshName(const char* fieldName,CORBA::Long dt,CORBA::Long it);
+  void readReferenceField(const char* meshName, const char* fieldName, CORBA::Long ts);
+  void buildGradient()  throw(SALOME_FILTER::FILTER_Gen::FilterError);
+  void getMinMax(CORBA::Double& imin, CORBA::Double& imax,SALOME_FILTER::ref_func rf);
+  SALOME_FILTER::LongSeq* getHistogram(CORBA::Long size,SALOME_FILTER::ref_func rf);
+  void generateCriteria(CORBA::Long nbthresh,CORBA::Double fthresh,CORBA::Double thresh,CORBA::Long areaFlag) throw(SALOME_FILTER::FILTER_Gen::FilterError);
+  void createEnsightInputFiles();
+  void filtering();
+  void projectFieldsOnDecimateMesh() throw(SALOME_FILTER::FILTER_Gen::FilterError);
+  void createMedOutputFile(const char* outMedFile);
 
 private :
+  void readMapping();
+  int getNodeNumber(int);
+  int getNeighbourVertex(int) throw(SALOME_Exception);
+
   static Filter_Gen_i*  _FILTERGen;    // Point to last created instance of the class
 
-  private:
   bool   _duringLoad;
   SALOME_NamingService *_NS;
+
+  int _nbvmap;
+  int *_map;
+  int _connL;
+  const int *_conn;
+  const int *_connI;
+  string _file;
+
+  ::MEDMEM::MED *_med, *_newMed;
+  MESH* _mesh, *_newMesh;
+  FIELD<double> * _myGradient;
+  FIELD<double> * _myDField;
+  FIELD<int> * _myIField;
+  FIELD<int> *_criteria;
+
 };
 
+extern "C"
+    PortableServer::ObjectId * FilterMEDEngine_factory(
+            CORBA::ORB_ptr orb,
+            PortableServer::POA_ptr poa,
+            PortableServer::ObjectId * contId,
+            const char *instanceName,
+            const char *interfaceName);
 #endif
index b23d0af3dcda7e42e68c72f921950c96023276a5..42a8f11f4d70fc9d0468034d924a66408231656f 100644 (file)
@@ -56,10 +56,11 @@ LDFLAGSFORBIN= -L$(top_builddir)/lib@LIB_LOCATION_SUFFIX@/salome
 
 # additionnal information to compil and link file
 
-CPPFLAGS += $(OCC_INCLUDES) $(MED2_INCLUDES)  $(HDF5_INCLUDES) ${KERNEL_CXXFLAGS}
+CPPFLAGS += $(OCC_INCLUDES) $(MED2_INCLUDES)  $(HDF5_INCLUDES) ${KERNEL_CXXFLAGS} $(MED_CXXFLAGS)
 CXXFLAGS += $(OCC_CXXFLAGS) ${KERNEL_CXXFLAGS}
 
 LDFLAGS+=  $(OCC_LIBS) $(HDF5_LIBS) ${KERNEL_LDFLAGS} \
-       -lSalomeContainer -lSalomeHDFPersist -lSalomeDS -lSalomeNS -lRegistry -lOpUtil
+       -lSalomeContainer -lSalomeHDFPersist -lSalomeDS -lSalomeNS -lRegistry -lOpUtil \
+       ${MED_LDFLAGS} -lMEDMEMImpl -lmedmem
 
 @CONCLUDE@
index a723e638deb57e5abe624a60996d1f419d283383..5735dcddc28dcc6335a4219eff39ece3b2f90602 100644 (file)
@@ -166,12 +166,32 @@ void FilterGUI::contextMenuPopup( const QString& client, QPopupMenu* menu, QStri
   }
 }
 
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+SALOME_FILTER::FILTER_Gen_ptr FilterGUI::InitFilterGen() const
+{
+  SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( application() );
+  Engines::Component_var comp =
+    SALOME_LifeCycleCORBA(app->namingService()).FindOrLoad_Component( "FactoryServer", "FILTER" );
+
+  MESSAGE("_________________________________________");
+  SALOME_FILTER::FILTER_Gen_var clr = SALOME_FILTER::FILTER_Gen::_narrow(comp);
+  ASSERT(!CORBA::is_nil(clr));
+  return clr._retn();
+}
+
 QString FilterGUI::engineIOR() const
 {
-//   SALOME_FILTER::MED_Gen_ptr aMedGen = InitMedGen();
-//   if ( !CORBA::is_nil( aMedGen) )
-//     return QString( getApp()->orb()->object_to_string( aMedGen ));
-  return QString( "" );
+  QString anIOR( "" );
+  SALOME_FILTER::FILTER_Gen_ptr aFilterGen = InitFilterGen();
+  if ( !CORBA::is_nil( aFilterGen) ){
+    CORBA::String_var objStr = getApp()->orb()->object_to_string( aFilterGen );
+    anIOR = QString( objStr.in() );
+  }
+  return anIOR;
 }
 
 void FilterGUI::windows( QMap<int, int>& mappa ) const
@@ -292,6 +312,9 @@ bool FilterGUI::OnGUIEvent (int theCommandID)
            _sel = NULL;
          }
          catch ( SALOME_Exception& S_ex ) {
+           delete _sel;
+           _sel=NULL;
+           MESSAGE("Select an input Field in MED file before filtering!!");
            QMessageBox::information( application()->desktop(),
                                      "Filtering",
                                      "Unable to select parameters for filtering.\n"
index 9ec37d3876094a798bc3e21f8a78742f5042a119..6dd8229e38a237fd9045030b2de0c75d198f4bd2 100644 (file)
@@ -39,6 +39,8 @@ public:
 
   virtual void contextMenuPopup( const QString&, QPopupMenu*, QString& );
 
+  SALOME_FILTER::FILTER_Gen_ptr InitFilterGen() const;
+
   static void setOrb();
 
   void EmitSignalCloseAllDialogs();
index a3368a5ff1617f2a1c5d1c5ab02822880aca141b..942d79d7bdf194534ce8b816ec2b88e60eb878ef 100644 (file)
@@ -33,20 +33,21 @@ SelectField::SelectField(FilterGUI* theModule,const QString& file,
   : QDialog(FILTER::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
     myFilterGUI( theModule ),
     _file(file),
-    _mesh(0),
-    _field(0),
+    _mesh(NULL),
+    _field(NULL),
     _ts(0),
     _dimMesh(-1)
 {
   QListViewItem *element;
 
   SCRUTE(_file);
-  _med = new ::MED(MED_DRIVER,_file);
-  deque<string> meshesNames = _med->getMeshNames();
-  int numberOfMeshes = meshesNames.size();
-  
-  deque<string> fieldsNames = _med->getFieldNames();
-  int numberOfFields = fieldsNames.size();
+  _filter = myFilterGUI->InitFilterGen();
+  _filter->loadMED(_file);
+  SALOME_FILTER::StrSeq* meshesNames = _filter->getMeshNames();
+  int numberOfMeshes = (*meshesNames).length();
+
+  SALOME_FILTER::StrSeq* fieldsNames = _filter->getFieldNames();
+  int numberOfFields = (*fieldsNames).length();
 
   QGridLayout* _lay = new QGridLayout( this, 1, 1 );
 
@@ -83,18 +84,18 @@ SelectField::SelectField(FilterGUI* theModule,const QString& file,
   _myList->addColumn(tr("FILTER_DIM"));
 
   for(int i=0;i<numberOfMeshes;i++){
-    _dimMesh = _med->getMesh(meshesNames[i])->getMeshDimension();
+    _dimMesh = _filter->getMeshDimension((*meshesNames)[i]);
     char strd[4];
     sprintf(strd,"%dD\0",_dimMesh);
-    element = new QListViewItem( _myList, meshesNames[i], tr("FILTER_MESH") ,strd);
+    element = new QListViewItem( _myList, QString((*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){
-       QListViewItem *elem = new QListViewItem( element, fieldsNames[j], tr("FILTER_FIELD") );
+      SALOME_FILTER::DTITSeq *myIteration = _filter->getFieldIteration((*fieldsNames)[j]);
+      string meshName = _filter->getMeshName((*fieldsNames)[j],(*myIteration)[0].dt,(*myIteration)[0].it);
+      if( strcmp(meshName.c_str(),(*meshesNames)[i]) == 0){
+       QListViewItem *elem = new QListViewItem( element, QString((*fieldsNames)[j]), tr("FILTER_FIELD") );
        if(_dimMesh != 3)
          elem->setSelectable(false);
       }
@@ -159,7 +160,7 @@ SelectField::~SelectField()
 {
   // no need to delete child widgets, Qt does it all for us
   cout << "SelectField: destructor called" << endl;
-  delete _med;
+  _filter->unloadMED();
 }
 
 void SelectField::fieldSelected(QListViewItem *lvi)
@@ -168,11 +169,12 @@ void SelectField::fieldSelected(QListViewItem *lvi)
     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));
-      int numberOfIteration = myIteration.size();
+//       deque<DT_IT_> myIteration = _filterMED->getFieldIteration(lvi->text(0));
+      SALOME_FILTER::DTITSeq *myIteration = _filter->getFieldIteration(lvi->text(0));
+      int numberOfIteration = (*myIteration).length();
       if( numberOfIteration > 1 ){
-       _mySlider->setRange(myIteration[0].dt,
-                           myIteration[numberOfIteration-1].dt);
+       _mySlider->setRange((*myIteration)[0].dt,
+                           (*myIteration)[numberOfIteration-1].dt);
        _myLab->show();
        _mySlider->show();
       }
index 2ee4979a0a036b40372595792d1a295659197dbb..7b7ef941cbb7b9db1604262fd5c52465b6a4f67d 100644 (file)
 #define SELECTFIELD_HEADER
 
 #include "utilities.h"
-#include "MEDMEM_Med.hxx"
 #include "SalomeApp_Application.h"
 #include <SalomeApp_Module.h>
 #include <SUIT_Desktop.h>
 #include <qdialog.h>
 #include "FilterGUI.h"
 #include "FILTERGUI_Utils.h"
+#include CORBA_SERVER_HEADER(FILTER_Gen)
 
 #include <SALOMEconfig.h>
 class QListView;
@@ -56,7 +56,7 @@ public:
   QString getMesh() { return _mesh; }
   QString getField() { return _field; }
   int getTimeStep() { return _ts; }
-  ::MEDMEM::MED * getMED() { return _med; }
+  SALOME_FILTER::FILTER_Gen_ptr getFilter() {return _filter;} /* current filter object */
   FilterGUI* myFilterGUI;              /* Current FilterGUI object */
 
 protected:
@@ -78,7 +78,7 @@ private:
   QLabel *_myLab;
   QSlider *_mySlider;
   QPushButton* _buttonCancel, * _buttonHelp, * _buttonOk;
-  ::MEDMEM::MED *_med;
+  SALOME_FILTER::FILTER_Gen_ptr _filter;
 };
 
 #endif
index 9f27db0c2ce7eb5f0a2e86e3ef5f6db4695c959e..346a59da498663078d57ea59bbf0788431fdabd5 100644 (file)
 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),_myGradient(NULL)
+  : QDialog(FILTER::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),_size(1024),_sel(sel)
 {
+  MESSAGE("SelectParams constructor");
   if(sel){
-
     // read reference field values
-    _med = sel->getMED();
+    _filter = sel->getFilter();
 
     // Get reference field and time step
     _inputFile = sel->getFile();
@@ -57,29 +57,10 @@ SelectParams::SelectParams(FilterGUI* theModule,SelectField *sel,
     _inputField = sel->getField();
     _inputTS = sel->getTimeStep();
 
-    // if no reference field selection: throw exception
-    if( _inputMesh.isNull() || _inputField.isNull() ){
-      delete sel;
+    if( _inputFile.isEmpty() || _inputMesh.isEmpty() || _inputField.isEmpty())
       throw SALOME_Exception("Select an input Field in MED file before filtering!!");
-    }
-
-    // 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 = (MEDMEM::FIELD<double>*)field;
-      _myDField->read();
-      _myIField = NULL;
-    }
-    else{
-      _myIField = (MEDMEM::FIELD<int>*)field;
-      _myIField->read();
-      _myDField = NULL;
-    }
+    
+    _filter->readReferenceField(_inputMesh,_inputField,_inputTS);
 
     // Build QT widgets
     buildFrame();
@@ -101,25 +82,8 @@ SelectParams::~SelectParams()
   // destrcution of histogram arrays
   delete _x;
   delete _y;
-
-  // 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
-  if(_criteria){
-    delete _criteria->getSupport();
-    delete _criteria;
-  }
   
-  // destruction of SelectField object and MED object in it
+  // destruction of SelectField object and Filter object in it
   delete _sel;
 }
 
@@ -356,23 +320,18 @@ 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." );
-    }
+  try{
+    _filter->buildGradient();
+  }
+  catch(SALOME_FILTER::FILTER_Gen::FilterError){
+    _myFieldB->setChecked(true);
+    QMessageBox::information( this,
+                             "Filtering",
+                             "Unable to calculate gradient on vector field.\n"
+                             "You must select a reference scalar field." );
+  }
+  catch(...){
+    MESSAGE("unknownException");
   }
 }
 
@@ -457,27 +416,26 @@ void SelectParams::enterSThresh()
 void SelectParams::calcHisto()
 {
   char strth[128];
-  vector<int> myh;
+  CORBA::Double min, max;
+  CORBA::Long size = _size;
+  SALOME_FILTER::LongSeq* histo;
 
   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);
-    }
+    _filter->getMinMax(min,max,SALOME_FILTER::F_FIELD);
+    histo = _filter->getHistogram(size,SALOME_FILTER::F_FIELD);
   }
   else{
     // calculate histogram values on gradient
-    _myGradient->getMinMax(_xmin,_xmax);
-    myh = _myGradient->getHistogram(_size);
+     _filter->getMinMax(min,max,SALOME_FILTER::F_GRAD);
+    histo = _filter->getHistogram(size,SALOME_FILTER::F_GRAD);
   }
+  _xmin = min;
+  _xmax = max;
+  vector<int> myh(_size);
+  for(int i=0;i<_size;i++)
+    myh[i] = (*histo)[i];
+
   if( _myLinear->isChecked() )
     _ymin = 0.0;
   else
@@ -630,6 +588,7 @@ void SelectParams::getOutFileName()
 
 void SelectParams::process() throw(SALOME_Exception)
 {
+  int nbthresh;
   string command;
 
   MESSAGE("Input MED File : "<<_inputFile);
@@ -643,9 +602,13 @@ void SelectParams::process() throw(SALOME_Exception)
   MESSAGE("Generate Criteria");
   // generate MED integer field (0 or 1) for filtoo input
   try{
-    generateCriteria();
+    if( _myOneThresh->isChecked() )
+      nbthresh = 1;
+    else
+      nbthresh = 2;
+    _filter->generateCriteria(nbthresh,_fthresh,_sthresh,_myExt->isChecked());
   }
-  catch ( SALOME_Exception& S_ex ){
+  catch (SALOME_FILTER::FILTER_Gen::FilterError){
     QMessageBox::information( this,
                              "Filtering",
                              "Unable to process filtering.\n"
@@ -654,367 +617,28 @@ void SelectParams::process() throw(SALOME_Exception)
     return;
   }
 
-  MESSAGE("Calculate boundary");
-  // generate MED boundary of geometry
-  SUPPORT *supB = _mesh->getBoundaryElements(MED_FACE);
-
-  // call ensight driver MED to generate input ensight mesh ,
-  // input ensight boundary mesh and input criteria ensight field for filtoo
-  MESSAGE("Create ensight mesh");
-  int id;
-  ENSIGHT_MESH_DRIVER myMeshDriver("/tmp/input.geom",_mesh);
-  myMeshDriver.addSupport(supB);
-  id=_mesh->addDriver(myMeshDriver);
-  _mesh->write(id);
-  MESSAGE("Create ensight field");
-  ENSIGHT_FIELD_DRIVER<int> myFieldDriver("/tmp/input.data",_criteria);
-  id=_criteria->addDriver(myFieldDriver);
-  _criteria->write(id);
-
-  MESSAGE("call filtoo");
-  // send filtoo command
-  command = "cd /tmp;filtoo -f input -o output > /tmp/filter.log";
-  MESSAGE(command);
-  system(command.c_str());
-
-  // destroy filtoo input files
-//   command = "cd /tmp;rm -f input.*";
-//   MESSAGE(command);
-//   system(command.c_str());
-  // have to call ensight driver MED to generate output MED file from filtoo output
-  MED _newMed(ENSIGHT_DRIVER,"/tmp/output.case");
-  _newMed.read();
-
-  // project input fileds on new mesh
-  projectFields();
+  // create ensight input files to filtoo
+  _filter->createEnsightInputFiles();
 
-  // destroy filtoo output files
-//   command = "cd /tmp;rm -f output.*";
-//   MESSAGE(command);
-//   system(command.c_str());
+  // call filtoo
+  _filter->filtering();
+  // project input fields on new mesh
+  try{
+    _filter->projectFieldsOnDecimateMesh();
+  }
+  catch (SALOME_FILTER::FILTER_Gen::FilterError& ex){
+    throw SALOME_Exception(ex.error_msg);
+  }
 
   // create new MED file with new mesh and fields
-  id = _newMed.addDriver(MED_DRIVER,_myOFN->text());
-  _newMed.write(id);
+  _filter->createMedOutputFile(_myOFN->text());
 
   // close the window
   accept();
 
 }
 
-void SelectParams::projectFields()
-{
-  
-  // get new mesh name
-  deque<string> meshesNames = _newMed->getMeshNames();
-  int numberOfMeshes = meshesNames.size();
-  if( numberOfMeshes != 1)
-    throw SALOME_Exception("Unvalid number of meshes in filtoo output");
-
-  // new mesh generated by filtoo
-  _newMesh = _newMed->getMesh(meshesNames[0]);
-
-  // create support on nodes on all new mesh
-  SUPPORT *newSup = new SUPPORT(_newMesh,"Support",MED_NODE);
-
-  // read the id of nodes of output mesh, in input mesh
-  readMapping();
-
-  // read connectivity of new mesh to get neighbour node of created node
-  _connL = _newMesh->getConnectivityLength(MED_FULL_INTERLACE,MED_NODAL,MED_CELL,MED_ALL_ELEMENTS);
-  _conn = _newMesh->getConnectivity(MED_FULL_INTERLACE,MED_NODAL,MED_CELL,MED_ALL_ELEMENTS);
-  _connI = _newMesh->getConnectivityIndex(MED_NODAL,MED_CELL);
-
-  // read number of nodes on new mesh
-  int numberOfNodes = newSup->getNumberOfElements(MED_ALL_ELEMENTS);
-  int numberOfComponents;
-
-  deque<string> fieldsNames = _med->getFieldNames();
-  int numberOfFields = fieldsNames.size();
-
-  // loop on fields
-  for (int i=0; i<numberOfFields; i++){
-
-    // is the input field the reference field?
-    bool isReferenceField= false;
-    if(_myDField)
-      if( strcmp(_myDField->getName().c_str(),fieldsNames[i].c_str()) == 0)
-       isReferenceField = true;
-    else
-      if( strcmp(_myIField->getName().c_str(),fieldsNames[i].c_str()) == 0)
-       isReferenceField = true;
-
-    deque<DT_IT_> myIteration = _med->getFieldIteration (fieldsNames[i]);
-    string meshName = _med->getField(fieldsNames[i],myIteration[0].dt,myIteration[0].it)->getSupport()->getMesh()->getName();
-
-    // we process only fields on input mesh
-    if( strcmp(meshName.c_str(),_mesh->getName().c_str()) == 0){
-
-      // loop on time steps
-      int numberOfIteration = myIteration.size();
-      for(int j=0;j<numberOfIteration;j++){
-
-       // select input field
-       MEDMEM::FIELD_* field = _med->getField(fieldsNames[i],myIteration[j].dt,myIteration[j].it);
-       FIELD<double> *myDField = NULL;
-       FIELD<double> *newDField = NULL;
-       FIELD<int> *myIField = NULL;
-       FIELD<int> *newIField = NULL;
-
-       if (dynamic_cast<MEDMEM::FIELD<double>*>(field)){
-         if(!isReferenceField)
-           // read input field on input file
-           myDField = new FIELD<double>(MEDMEM::MED_DRIVER,_inputFile,fieldsNames[i],myIteration[j].dt,myIteration[j].it);
-         else
-           myDField = _myDField;
-         // create new output field
-         newDField = new FIELD<double>(newSup,field->getNumberOfComponents());
-         newDField->setName(myDField->getName());
-       }
-       else{
-         if(!isReferenceField)
-           // read input field on input file
-           myIField = new FIELD<int>(MEDMEM::MED_DRIVER,_inputFile,fieldsNames[i],myIteration[j].dt,myIteration[j].it);
-         else
-           myIField = _myIField;
-         // create new output field
-         newIField = new FIELD<int>(newSup,field->getNumberOfComponents());
-         newIField->setName(myIField->getName());
-       }
-       
-       // loop on nodes on new field
-       for (int k=1; k<numberOfNodes+1; k++){
-         // read number of nodes on input field
-         int l = getNodeNumber(k);
-         double dval;
-         int ival;
-         
-         for(int c=1;c<=numberOfComponents;c++){
-           // read value on input field
-           if(myDField)
-             dval = myDField->getValueIJ(l,c);
-           else
-             ival = myIField->getValueIJ(l,c);
-         
-           // write value on new field
-           if(newDField)
-             newDField->setValueIJ(k,c,dval);
-           else
-             newIField->setValueIJ(k,c,ival);
-         }
-         
-       }
-       if(newDField)
-         _newMed->addField(newDField);
-       else
-         _newMed->addField(newIField);
-       
-       // Destroy input field if not referecne field
-       if(!isReferenceField)
-         if(myDField){
-           delete myDField->getSupport();
-           delete myDField;
-         }
-         else{
-           delete myIField->getSupport();
-           delete myIField;
-         }
-       
-      }
-    }
-  }
-
-}
-
-void SelectParams::readMapping()
-{
-  ifstream mapFile("/tmp/output.renum");
-
-  // read number of vertices to map
-  mapFile >> _nbvmap;
-  _map = new int[_nbvmap];
-  
-  for(int i=0;i<_nbvmap;i++)
-    mapFile >> _map[i];
-
-}
-
-int SelectParams::getNodeNumber(int num)
-{
-  int oldnum = _map[num];
-
-  // if new node get neighbour node
-  if(oldnum == 0)
-    oldnum = _map[getNeighbourVertex(num)];
-  
-  return oldnum;
-}
-
-int SelectParams::getNeighbourVertex(int num) throw(SALOME_Exception)
-{
-  int nnum;
-  int numberOfElements = _newMesh->getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS);
-
-  int index;
-  // get index of created node in connectivity array
-  for(index=0;index<_connL;index++){
-    if(_conn[index] == num){
-
-      // get index of element which contain created node
-      int i;
-      for(i=1;i<=numberOfElements;i++)
-       if(_connI[i] > index)
-         break;
-
-      // search neighbour node which are in old mesh
-      for(int j=_connI[i-1];j<_connI[i];j++){
-       nnum = _conn[j-1];
-       if( _map[nnum] != 0)
-         break;
-      }
-
-      // if neighbour node in old mesh: go out loop, else continue
-      if(_map[nnum]!=0)
-       break;
-    }
-  }
-
-  // if no neighbour node in old mesh: throw exception
-  if(_map[nnum]==0)
-    throw SALOME_Exception("None of the neighbour node are in old mesh!!");
-
-  return nnum;
-}
-
-void SelectParams::generateCriteria() throw(SALOME_Exception)
-{
-  double val, min, max;
-  double sigmaV;
-  bool isGVal;
-  MED_EN::medEntityMesh typ;
-  const int *revC;
-  const int *indC;
-  FIELD<double> *volume;
-  set <int> listElements;
-  set <int>::iterator elemIt ;
-
-  if(_myDField)
-    typ = _myDField->getSupport()->getEntity();
-  else
-    typ = _myIField->getSupport()->getEntity();
-
-  // create support on nodes
-  SUPPORT *sup = new SUPPORT(_mesh,"Support",MED_NODE);
-
-  // create integer field on nodes
-  _criteria = new FIELD<int>(sup,1);
-
-  _criteria->setName("Criteria");
-
-  // read number of nodes
-  int NumberOf = sup->getNumberOfElements(MED_ALL_ELEMENTS);
-
-  // if reference field is on elements get reference field on nodes
-  switch(typ){
-  case MED_CELL:
-    if(_myDField){
-      // calculate reverse connectivity to have the list of elements which contains node i
-      revC = _myDField->getSupport()->getMesh()->getReverseConnectivity(MED_NODAL,typ);
-      indC = _myDField->getSupport()->getMesh()->getReverseConnectivityIndex(MED_NODAL,typ);
-      // calculate volume field on mesh
-      volume = _myDField->getSupport()->getMesh()->getVolume(_myDField->getSupport());
-    }
-    else{
-      // calculate reverse connectivity to have the list of elements which contains node i
-      revC = _myIField->getSupport()->getMesh()->getReverseConnectivity(MED_NODAL,typ);
-      indC = _myIField->getSupport()->getMesh()->getReverseConnectivityIndex(MED_NODAL,typ);
-      // calculate volume field on mesh
-      volume = _myIField->getSupport()->getMesh()->getVolume(_myIField->getSupport());
-    }
-    break;
-  default:
-    break;
-  }
-
-  for (int i=1; i<NumberOf+1; i++){
-
-    // if reference field is on elements get reference field on nodes
-    switch(typ){
-    case MED_CELL:
-      // listElements contains elements which contains a node of element i
-      listElements.clear();
-      
-      for(int j=indC[i-1];j<indC[i];j++){
-       // c element contains node i
-       int c=revC[j-1];
-       listElements.insert(c);
-      }
-
-      // calculate field value on node i 
-      sigmaV = 0.;
-      val = 0.;
-      for(elemIt=listElements.begin();elemIt!=listElements.end();elemIt++){
-       int elem = *elemIt;
-       double vol = volume->getValueIJ(elem,1);
-       if( vol != 0. ){
-         sigmaV += 1./vol;
-         if(_myDField)
-           val += _myDField->getValueIJ(elem,1)/vol;
-         else
-           val += ((double)_myIField->getValueIJ(elem,1))/vol;
-       }
-      }
-      val /= sigmaV;
-      break;
-    case MED_FACE:
-      throw SALOME_Exception("Filter doesn't run on reference field on faces");
-      break;
-    case MED_EDGE:
-      throw SALOME_Exception("Filter doesn't run on reference field on edges");
-      break;
-    case MED_NODE:
-      // read reference field value
-      if(_myDField)
-       val = _myDField->getValueIJ(i,1);
-      else
-       val = (double)_myIField->getValueIJ(i,1);
-      break;
-    case MED_ALL_ENTITIES:
-      throw SALOME_Exception("Filter doesn't run on reference field on all entities");
-      break;
-    }
-
-    // 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 51a3d62c6f82623b6a27f41a3a76f7d08e152ba6..6771b5b6f95f398b0722d30fca80ca0e0bab0a34 100644 (file)
@@ -22,8 +22,6 @@
 #define SELECTPARAMS_HEADER
 
 #include "utilities.h"
-#include "MEDMEM_Med.hxx"
-#include "MEDMEM_Meshing.hxx"
 
 #include "SelectField.h"
 #include <qwt_plot.h>
@@ -33,7 +31,6 @@
 #include <qdialog.h>
 
 #include <SALOMEconfig.h>
-/* #include CORBA_CLIENT_HEADER(MED_Gen) */
 
 class QLineEdit;
 class QLabel;
@@ -64,11 +61,6 @@ protected:
   virtual void     displayFThresh();
   virtual void     displaySThresh();
   virtual void     enableWidgets();
-  virtual void     generateCriteria() throw(SALOME_Exception);
-  virtual void     projectFields();
-  virtual void     readMapping();
-  virtual int      getNodeNumber(int);
-  virtual int      getNeighbourVertex(int) throw(SALOME_Exception) ;
 
 protected slots:
   virtual void     gradSelected();
@@ -92,11 +84,6 @@ private:
   double _fthresh, _sthresh;
   double *_x, *_y;
   double _xft[100], _yft[100], _xst[100], _yst[100];
-  int _nbvmap;
-  int *_map;
-  int _connL;
-  const int *_conn;
-  const int *_connI;
 
   QLineEdit *_myLESH, *_myFThresh, *_myExpr, *_myLEST, *_myLEFT, *_myOFN;
   QButtonGroup *_myHSize, *_myFunc, *_myFScale, *_myNbThresh, *_myArea, *_myVThresh, *_myOutFile;
@@ -111,12 +98,7 @@ private:
   QString _inputFile, _inputMesh, _inputField;
   int _inputTS;
   SelectField *_sel;
-  ::MEDMEM::MED *_med, *_newMed;
-  MESH* _mesh, *_newMesh;
-  FIELD<double> * _myGradient;
-  FIELD<double> * _myDField;
-  FIELD<int> * _myIField;
-  FIELD<int> *_criteria;
+  SALOME_FILTER::FILTER_Gen_ptr _filter;
 };
 
 #endif