Ignore:
Timestamp:
04/08/16 15:40:57 (6 years ago)
Author:
Bayard Gildas
Message:

sources reformatted with flair-format-dir script

File:
1 edited

Legend:

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

    r10 r15  
    2929using namespace flair::filter;
    3030
    31 ButterworthLowPass_impl::ButterworthLowPass_impl(ButterworthLowPass* self,const LayoutPosition* position,string name,int order)
    32 {
    33     //init UI
    34     GroupBox* reglages_groupbox=new GroupBox(position,name);
    35         T=new DoubleSpinBox(reglages_groupbox->NewRow(),"period, 0 for auto"," s",0,10,0.01);
    36         cutoff=new DoubleSpinBox(reglages_groupbox->NewRow(),"cutoff frequency"," Hz",0,10000,0.1,2,1);
     31ButterworthLowPass_impl::ButterworthLowPass_impl(ButterworthLowPass *self,
     32                                                 const LayoutPosition *position,
     33                                                 string name, int order) {
     34  // init UI
     35  GroupBox *reglages_groupbox = new GroupBox(position, name);
     36  T = new DoubleSpinBox(reglages_groupbox->NewRow(), "period, 0 for auto", " s",
     37                        0, 10, 0.01);
     38  cutoff = new DoubleSpinBox(reglages_groupbox->NewRow(), "cutoff frequency",
     39                             " Hz", 0, 10000, 0.1, 2, 1);
    3740
    38     cvmatrix_descriptor* desc=new cvmatrix_descriptor(1,1);
    39     desc->SetElementName(0,0,"output");
    40     output=new cvmatrix(self,desc,floatType,name);
     41  cvmatrix_descriptor *desc = new cvmatrix_descriptor(1, 1);
     42  desc->SetElementName(0, 0, "output");
     43  output = new cvmatrix(self, desc, floatType, name);
    4144
    42     output->SetValue(0,0,0);
     45  output->SetValue(0, 0, 0);
    4346
    44         f= new PoleFilter(order);
     47  f = new PoleFilter(order);
    4548
    46     if(T->Value()!=0) f->setup(1./T->Value(), cutoff->Value());
    47         f->reset();
     49  if (T->Value() != 0)
     50    f->setup(1. / T->Value(), cutoff->Value());
     51  f->reset();
    4852
    49         first_update=true;
     53  first_update = true;
    5054}
    5155
    52 ButterworthLowPass_impl::~ButterworthLowPass_impl()
    53 {
    54     delete f;
     56ButterworthLowPass_impl::~ButterworthLowPass_impl() { delete f; }
     57
     58void ButterworthLowPass_impl::UpdateFrom(const io_data *data) {
     59  float result;
     60  cvmatrix *input = (cvmatrix *)data;
     61
     62  if (T->ValueChanged() || cutoff->ValueChanged()) {
     63    if (T->Value() != 0) {
     64      f->setup(1. / T->Value(), cutoff->Value());
     65    } else {
     66      first_update = true;
     67    }
     68  }
     69
     70  // on prend une fois pour toute les mutex et on fait des accès directs
     71  output->GetMutex();
     72  input->GetMutex();
     73
     74  if (T->Value() == 0) {
     75    float delta_t = (float)(data->DataTime() - previous_time) / 1000000000.;
     76    f->setup(1. / delta_t, cutoff->Value());
     77  }
     78
     79  if (first_update == true) {
     80    first_update = false;
     81  } else {
     82    result = f->filter(input->ValueNoMutex(0, 0));
     83    output->SetValueNoMutex(0, 0, result);
     84  }
     85
     86  input->ReleaseMutex();
     87  output->ReleaseMutex();
     88
     89  output->SetDataTime(data->DataTime());
     90  previous_time = data->DataTime();
    5591}
    56 
    57 void ButterworthLowPass_impl::UpdateFrom(const io_data *data)
    58 {
    59     float result;
    60     cvmatrix *input=(cvmatrix*)data;
    61 
    62     if(T->ValueChanged() || cutoff->ValueChanged())
    63     {
    64         if(T->Value()!=0)
    65         {
    66             f->setup (1./T->Value(), cutoff->Value());
    67         }
    68         else
    69         {
    70             first_update=true;
    71         }
    72     }
    73 
    74     //on prend une fois pour toute les mutex et on fait des accès directs
    75     output->GetMutex();
    76     input->GetMutex();
    77 
    78     if(T->Value()==0)
    79     {
    80         float delta_t=(float)(data->DataTime()-previous_time)/1000000000.;
    81         f->setup (1./delta_t, cutoff->Value());
    82     }
    83 
    84     if(first_update==true)
    85     {
    86         first_update=false;
    87     }
    88     else
    89     {
    90         result = f->filter(input->ValueNoMutex(0,0));
    91         output->SetValueNoMutex(0,0,result);
    92     }
    93 
    94     input->ReleaseMutex();
    95     output->ReleaseMutex();
    96 
    97     output->SetDataTime(data->DataTime());
    98     previous_time=data->DataTime();
    99 }
    100 
Note: See TracChangeset for help on using the changeset viewer.