void SimpleFilter<Scalar>::precalculate(int order, int mask) { if(mask & (H2D_FN_DX | H2D_FN_DY | H2D_FN_DXX | H2D_FN_DYY | H2D_FN_DXY)) throw Hermes::Exceptions::Exception("Filter not defined for derivatives."); Quad2D* quad = this->quads[this->cur_quad]; int np = quad->get_num_points(order, this->element->get_mode()); struct Function<Scalar>::Node* node = this->new_node(H2D_FN_VAL, np); // precalculate all solutions for (int i = 0; i < this->num; i++) this->sln[i]->set_quad_order(order, item[i]); for (int j = 0; j < this->num_components; j++) { // obtain corresponding tables Scalar* tab[H2D_MAX_COMPONENTS]; for (int i = 0; i < this->num; i++) { int a = 0, b = 0, mask = item[i]; if(mask >= 0x40) { a = 1; mask >>= 6; } while (!(mask & 1)) { mask >>= 1; b++; } tab[i] = this->sln[i]->get_values(this->num_components == 1 ? a : j, b); if(tab[i] == nullptr) throw Hermes::Exceptions::Exception("Value of 'item%d' is incorrect in filter definition.", i + 1); } Hermes::vector<Scalar*> values; for(int i = 0; i < this->num; i++) values.push_back(tab[i]); // apply the filter filter_fn(np, values, node->values[j][0]); }
void SimpleFilter::precalculate(int order, int mask) { if (mask & (H2D_FN_DX | H2D_FN_DY | H2D_FN_DXX | H2D_FN_DYY | H2D_FN_DXY)) error("Filter not defined for derivatives."); Quad2D* quad = quads[cur_quad]; int np = quad->get_num_points(order); Node* node = new_node(H2D_FN_VAL, np); // precalculate all solutions for (int i = 0; i < num; i++) sln[i]->set_quad_order(order, item[i]); for (int j = 0; j < num_components; j++) { // obtain corresponding tables scalar* tab[10]; for (int i = 0; i < num; i++) { int a = 0, b = 0, mask = item[i]; if (mask >= 0x40) { a = 1; mask >>= 6; } while (!(mask & 1)) { mask >>= 1; b++; } tab[i] = sln[i]->get_values(num_components == 1 ? a : j, b); if (tab[i] == NULL) error("Value of 'item%d' is incorrect in filter definition.", i+1); } Tuple<scalar*> values; for(int i = 0; i < this->num; i++) values.push_back(tab[i]); // apply the filter filter_fn(np, values, node->values[j][0]); }
DArray DArray_find(DArray array, DArray_find_fn *filter_fn, void* args) { if (DArray_is_empty(array)) return NULL; DArray filtered = DArray_create(array->element_size, array->size); for (int i = 0; i < DArray_count(array); i++) { void *item = DArray_get(array, i); if (filter_fn(item, args)) DArray_push(filtered, item); } return filtered; }
/** * Selectively remove pose channels. */ void BKE_pose_channels_remove( Object *ob, bool (*filter_fn)(const char *bone_name, void *user_data), void *user_data) { /* Erase any associated pose channel, along with any references to them */ if (ob->pose) { bPoseChannel *pchan, *pchan_next; bConstraint *con; for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan_next) { pchan_next = pchan->next; if (filter_fn(pchan->name, user_data)) { /* Bone itself is being removed */ BKE_pose_channel_free(pchan); if (ob->pose->chanhash) { BLI_ghash_remove(ob->pose->chanhash, pchan->name, NULL, NULL); } BLI_freelinkN(&ob->pose->chanbase, pchan); } else { /* Maybe something the bone references is being removed instead? */ for (con = pchan->constraints.first; con; con = con->next) { const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con); ListBase targets = {NULL, NULL}; bConstraintTarget *ct; if (cti && cti->get_constraint_targets) { cti->get_constraint_targets(con, &targets); for (ct = targets.first; ct; ct = ct->next) { if (ct->tar == ob) { if (ct->subtarget[0]) { if (filter_fn(ct->subtarget, user_data)) { con->flag |= CONSTRAINT_DISABLE; ct->subtarget[0] = 0; } } } } if (cti->flush_constraint_targets) cti->flush_constraint_targets(con, &targets, 0); } } if (pchan->bbone_prev) { if (filter_fn(pchan->bbone_prev->name, user_data)) pchan->bbone_prev = NULL; } if (pchan->bbone_next) { if (filter_fn(pchan->bbone_next->name, user_data)) pchan->bbone_next = NULL; } if (pchan->custom_tx) { if (filter_fn(pchan->custom_tx->name, user_data)) pchan->custom_tx = NULL; } } } } }