Ignore:
Timestamp:
03/06/17 20:30:06 (7 years ago)
Author:
Sanahuja Guillaume
Message:

modifs pb crash fin simulateur

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/FlairFilter/src/ButterworthLowPass_impl.cpp

    r148 r162  
    3131ButterworthLowPass_impl::ButterworthLowPass_impl(ButterworthLowPass *self,
    3232                                                 const LayoutPosition *position,
    33                                                  string name, int order) {
     33                                                 string name, uint32_t order,uint32_t nbRow,uint32_t nbCol) {
    3434  // init UI
    3535  GroupBox *reglages_groupbox = new GroupBox(position, name);
     
    3939                             " Hz", 0, 10000, 0.1, 2, 1);
    4040
    41   cvmatrix_descriptor *desc = new cvmatrix_descriptor(1, 1);
    42   desc->SetElementName(0, 0, "output");
     41  cvmatrix_descriptor *desc = new cvmatrix_descriptor(nbRow, nbCol);
     42  //desc->SetElementName(0, 0, "output");
    4343  output = new cvmatrix(self, desc, floatType, name);
    4444  delete desc;
    4545
    46   f = new PoleFilter(order);
    47 
    48   if (T->Value() != 0) {
    49     f->setup(1. / T->Value(), cutoff->Value());
     46  f=(PoleFilter**)malloc(sizeof(PoleFilter*)*nbRow*nbCol);
     47 
     48  for(uint32_t i=0;i<nbRow;i++) {
     49    for(uint32_t j=0;j<nbCol;j++) {
     50      f[i*nbCol+j] = new PoleFilter(order);
     51      if (T->Value() != 0) {
     52        f[i*nbCol+j]->setup(1. / T->Value(), cutoff->Value());
     53      }
     54      f[i*nbCol+j]->reset();
     55    }
    5056  }
    51  
    52   f->reset();
    5357
    5458  first_update = true;
    5559  this->order=order;
     60  this->nbRow=nbRow;
     61  this->nbCol=nbCol;
    5662}
    5763
    58 ButterworthLowPass_impl::~ButterworthLowPass_impl() { delete f; }
     64ButterworthLowPass_impl::~ButterworthLowPass_impl() {
     65  for(uint32_t i=0;i<nbRow;i++) {
     66    for(uint32_t j=0;j<nbCol;j++) {
     67     delete f[i*nbCol+j];
     68    }
     69  }
     70  free(f);
     71}
    5972
    6073void ButterworthLowPass_impl::UpdateFrom(const io_data *data) {
    61   float result;
    6274  cvmatrix *input = (cvmatrix *)data;
    6375  float delta_t;
    6476 
    65   if (T->ValueChanged()) {
    66     if (T->Value() != 0) {
    67       f->setup(1. / T->Value(), cutoff->Value());
    68       settingsChanged(input->Value(0, 0));
     77  if (T->ValueChanged() && T->Value() != 0) {
     78    for(uint32_t i=0;i<nbRow;i++) {
     79      for(uint32_t j=0;j<nbCol;j++) {
     80        f[i*nbCol+j]->setup(1. / T->Value(), cutoff->Value());
     81        settingsChanged(f[i*nbCol+j],input->Value(i, j));
     82      }
    6983    }
    7084  }
     
    7286  if (T->Value() == 0) {
    7387    delta_t = (float)(data->DataTime() - previous_time) / 1000000000.;
    74     f->setup(1. / delta_t, cutoff->Value());
     88    for(uint32_t i=0;i<nbRow;i++) {
     89      for(uint32_t j=0;j<nbCol;j++) {
     90        f[i*nbCol+j]->setup(1. / delta_t, cutoff->Value());
     91      }
     92    }
    7593  } else {
    7694    delta_t=T->Value();
     
    82100
    83101  if (cutoff->ValueChanged()) {
    84     f->setup(1. / delta_t, cutoff->Value());
    85     settingsChanged(input->ValueNoMutex(0, 0));
     102    for(uint32_t i=0;i<nbRow;i++) {
     103      for(uint32_t j=0;j<nbCol;j++) {
     104        f[i*nbCol+j]->setup(1. / delta_t, cutoff->Value());
     105        settingsChanged(f[i*nbCol+j],input->ValueNoMutex(i, j));
     106      }
     107    }
    86108  }
    87109
     
    89111    first_update = false;
    90112  } else {
    91     result = f->filter(input->ValueNoMutex(0, 0));
    92     output->SetValueNoMutex(0, 0, result);
     113    for(uint32_t i=0;i<nbRow;i++) {
     114      for(uint32_t j=0;j<nbCol;j++) {
     115        float result = f[i*nbCol+j]->filter(input->ValueNoMutex(i, j));
     116        output->SetValueNoMutex(i, j, result);
     117      }
     118    }
    93119  }
    94120
     
    101127
    102128//ne gere pas les oscillations (s'arrete des qu'une valeure est bonne a 5%)
    103 void ButterworthLowPass_impl::settingsChanged(float inputValue) {
     129void ButterworthLowPass_impl::settingsChanged(PoleFilter*f,float inputValue) {
    104130  float result=f->filter(inputValue);
    105131 
Note: See TracChangeset for help on using the changeset viewer.