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
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
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
#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);
};
};
#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;
//=============================================================================
/*!
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 ;
ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting()) ;
_NS->init_orb( _orb ) ;
- //_myFilterI = 0;
_FILTERGen = this;
}
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() ;
+ }
+}
#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,
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
# 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@
}
}
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+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
_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"
virtual void contextMenuPopup( const QString&, QPopupMenu*, QString& );
+ SALOME_FILTER::FILTER_Gen_ptr InitFilterGen() const;
+
static void setOrb();
void EmitSignalCloseAllDialogs();
: 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 );
_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);
}
{
// 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)
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();
}
#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;
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:
QLabel *_myLab;
QSlider *_mySlider;
QPushButton* _buttonCancel, * _buttonHelp, * _buttonOk;
- ::MEDMEM::MED *_med;
+ SALOME_FILTER::FILTER_Gen_ptr _filter;
};
#endif
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();
_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();
// 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;
}
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");
}
}
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
void SelectParams::process() throw(SALOME_Exception)
{
+ int nbthresh;
string command;
MESSAGE("Input MED File : "<<_inputFile);
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"
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;
#define SELECTPARAMS_HEADER
#include "utilities.h"
-#include "MEDMEM_Med.hxx"
-#include "MEDMEM_Meshing.hxx"
#include "SelectField.h"
#include <qwt_plot.h>
#include <qdialog.h>
#include <SALOMEconfig.h>
-/* #include CORBA_CLIENT_HEADER(MED_Gen) */
class QLineEdit;
class QLabel;
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();
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;
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