Commit 8f2e494a authored by Christophe Geuzaine's avatar Christophe Geuzaine

Merge branch 'ExtensionOfGenericFieldInterface' into 'master'

Extension of generic field interface

See merge request !215
parents 309e3113 f7053b9a
Pipeline #2889 passed with stage
in 59 minutes and 27 seconds
......@@ -3020,21 +3020,38 @@ GenericField::~GenericField(){};
double GenericField::operator()(double x, double y, double z, GEntity *ge)
std::vector<double> sizes(cbs.size());
std::vector<ptrfunction>::iterator itcbs = cbs.begin();
std::vector<void *>::iterator itdata = user_data.begin();
for(std::vector<double>::iterator it = sizes.begin(); it != sizes.end();
it++, itdata++, itcbs++) {
bool ok = (*itcbs)(x, y, z, (*itdata), (*it));
if(!ok) {
std::vector<double> sizes(cbs_with_data.size() + cbs_extended_with_data.size());
std::vector<double>::iterator it = sizes.begin();
// Go over all callback functions
for(std::vector<std::pair<ptrfunction, void*> >::iterator itcbs = cbs_with_data.begin();
itcbs != cbs_with_data.end(); itcbs++, it++){
bool ok = (itcbs->first)(x, y, z, itcbs->second, (*it));
if (!ok){
Msg::Warning("GenericField::ERROR from callback ");
// Go over all extended callback functions
for (std::vector<std::pair<ptrfunctionextended, void*> >::iterator itcbs = cbs_extended_with_data.begin();
itcbs != cbs_extended_with_data.end(); itcbs++, it++){
bool ok = (itcbs->first)(x, y, z, ge, itcbs->second, (*it));
if (!ok){
Msg::Warning("GenericField::ERROR from callback ");
// Take minimum value
return (*std::min_element(sizes.begin(), sizes.end()));
void GenericField::setCallbackWithData(ptrfunction fct, void *data)
cbs_with_data.push_back(std::make_pair(fct, data));
void GenericField::setCallbackWithData(ptrfunctionextended fct, void *data)
cbs_extended_with_data.push_back(std::make_pair(fct, data));
......@@ -452,6 +452,8 @@ public:
// callback prototypes:
// this callback is called with a void* previously given to the GenericField !
typedef bool (*ptrfunction)(double, double, double, void *, double &);
// this callback also takes the GEntity object into account
typedef bool (*ptrfunctionextended)(double, double, double, void*, void*, double&);
......@@ -461,10 +463,11 @@ public:
// sets the callbacks
void setCallbackWithData(ptrfunction fct, void *data);
void setCallbackWithData(ptrfunctionextended fct, void *data);
std::vector<ptrfunction> cbs; // the callbacks
std::vector<void *> user_data; // the data to be sent to the callbacks
std::vector<std::pair<ptrfunction, void*> > cbs_with_data; // the callbacks with the data to be sent to them
std::vector<std::pair<ptrfunctionextended, void*> > cbs_extended_with_data; // the extended callbacks with the data to be sent to them
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment