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

sources reformatted with flair-format-dir script

File:
1 edited

Legend:

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

    r10 r15  
    3131using namespace flair::filter;
    3232
    33 LowPassFilter_impl::LowPassFilter_impl(const LowPassFilter* self,const LayoutPosition* position,string name,const cvmatrix* init_value)
    34 {
    35     first_update=true;
     33LowPassFilter_impl::LowPassFilter_impl(const LowPassFilter *self,
     34                                       const LayoutPosition *position,
     35                                       string name,
     36                                       const cvmatrix *init_value) {
     37  first_update = true;
    3638
    37     if(init_value!=NULL)
    38     {
    39         prev_value=(cvmatrix*)init_value;
     39  if (init_value != NULL) {
     40    prev_value = (cvmatrix *)init_value;
     41  } else {
     42    // if NULL, assume dimension 1, and init=0
     43    cvmatrix_descriptor *desc = new cvmatrix_descriptor(1, 1);
     44    desc->SetElementName(0, 0, "output");
     45    prev_value = new cvmatrix(self, desc, floatType, name);
     46    prev_value->SetValue(0, 0, 0);
     47  }
     48
     49  // init UI
     50  GroupBox *reglages_groupbox = new GroupBox(position, name);
     51  T = new DoubleSpinBox(reglages_groupbox->NewRow(), "period, 0 for auto", " s",
     52                        0, 10, 0.01);
     53  freq = new DoubleSpinBox(reglages_groupbox->NewRow(), "cutoff frequency",
     54                           " Hz", 0, 10000, 0.1, 2, 1);
     55
     56  // init output matrix of same size as init
     57  cvmatrix_descriptor *desc =
     58      new cvmatrix_descriptor(prev_value->Rows(), prev_value->Cols());
     59
     60  for (int i = 0; i < prev_value->Rows(); i++) {
     61    for (int j = 0; j < prev_value->Cols(); j++) {
     62      desc->SetElementName(i, j, prev_value->Name(i, j));
    4063    }
    41     else
    42     {
    43         //if NULL, assume dimension 1, and init=0
    44         cvmatrix_descriptor* desc=new cvmatrix_descriptor(1,1);
    45         desc->SetElementName(0,0,"output");
    46         prev_value=new cvmatrix(self,desc,floatType,name);
    47         prev_value->SetValue(0,0,0);
    48     }
     64  }
    4965
    50     //init UI
    51     GroupBox* reglages_groupbox=new GroupBox(position,name);
    52         T=new DoubleSpinBox(reglages_groupbox->NewRow(),"period, 0 for auto"," s",0,10,0.01);
    53         freq=new DoubleSpinBox(reglages_groupbox->NewRow(),"cutoff frequency"," Hz",0,10000,0.1,2,1);
     66  output = new cvmatrix(self, desc,
     67                        prev_value->GetDataType().GetElementDataType(), name);
    5468
    55 
    56     //init output matrix of same size as init
    57     cvmatrix_descriptor* desc=new cvmatrix_descriptor(prev_value->Rows(),prev_value->Cols());
    58 
    59     for(int i=0;i<prev_value->Rows();i++)
    60     {
    61         for(int j=0;j<prev_value->Cols();j++)
    62         {
    63             desc->SetElementName(i,j,prev_value->Name(i,j));
    64         }
    65     }
    66 
    67     output=new cvmatrix(self,desc,prev_value->GetDataType().GetElementDataType(),name);
    68 
    69     output->SetValue(0,0,0);
     69  output->SetValue(0, 0, 0);
    7070}
    7171
    72 LowPassFilter_impl::~LowPassFilter_impl()
    73 {
     72LowPassFilter_impl::~LowPassFilter_impl() {}
     73
     74void LowPassFilter_impl::UpdateFrom(const io_data *data) {
     75  float delta_t;
     76  float result;
     77  cvmatrix *input = (cvmatrix *)data;
     78
     79  // on prend une fois pour toute les mutex et on fait des accès directs
     80  output->GetMutex();
     81  input->GetMutex();
     82
     83  if (first_update == true) {
     84    for (int i = 0; i < input->Rows(); i++) {
     85      for (int j = 0; j < input->Cols(); j++) {
     86        output->SetValueNoMutex(i, j, prev_value->ValueNoMutex(i, j));
     87        prev_value->SetValueNoMutex(i, j, input->ValueNoMutex(i, j));
     88      }
     89    }
     90    first_update = false;
     91  } else {
     92    if (T->Value() == 0) {
     93      delta_t = (float)(data->DataTime() - previous_time) / 1000000000.;
     94    } else {
     95      delta_t = T->Value();
     96    }
     97    for (int i = 0; i < input->Rows(); i++) {
     98      for (int j = 0; j < input->Cols(); j++) {
     99
     100        if (freq->Value() != 0) {
     101          output->SetValueNoMutex(i, j, (1 - 2 * PI * freq->Value() * delta_t) *
     102                                                prev_value->ValueNoMutex(i, j) +
     103                                            2 * PI * freq->Value() * delta_t *
     104                                                input->ValueNoMutex(i, j));
     105        } else {
     106          output->SetValueNoMutex(i, j, input->ValueNoMutex(i, j));
     107        }
     108        prev_value->SetValueNoMutex(i, j, output->ValueNoMutex(i, j));
     109      }
     110    }
     111  }
     112  input->ReleaseMutex();
     113  output->ReleaseMutex();
     114
     115  output->SetDataTime(data->DataTime());
     116  previous_time = data->DataTime();
    74117}
    75 
    76 void LowPassFilter_impl::UpdateFrom(const io_data *data)
    77 {
    78     float delta_t;
    79     float result;
    80     cvmatrix *input=(cvmatrix*)data;
    81 
    82     //on prend une fois pour toute les mutex et on fait des accès directs
    83     output->GetMutex();
    84     input->GetMutex();
    85 
    86     if(first_update==true)
    87     {
    88         for(int i=0;i<input->Rows();i++)
    89         {
    90             for(int j=0;j<input->Cols();j++)
    91             {
    92                 output->SetValueNoMutex(i,j,prev_value->ValueNoMutex(i,j));
    93                 prev_value->SetValueNoMutex(i,j,input->ValueNoMutex(i,j));
    94             }
    95         }
    96         first_update=false;
    97     }
    98     else
    99     {
    100         if(T->Value()==0)
    101         {
    102             delta_t=(float)(data->DataTime()-previous_time)/1000000000.;
    103         }
    104         else
    105         {
    106             delta_t=T->Value();
    107         }
    108         for(int i=0;i<input->Rows();i++)
    109         {
    110             for(int j=0;j<input->Cols();j++)
    111             {
    112 
    113                 if(freq->Value()!=0)
    114                 {
    115                     output->SetValueNoMutex(i,j,(1-2*PI*freq->Value()*delta_t)*prev_value->ValueNoMutex(i,j)+2*PI*freq->Value()*delta_t*input->ValueNoMutex(i,j));
    116                 }
    117                 else
    118                 {
    119                     output->SetValueNoMutex(i,j,input->ValueNoMutex(i,j));
    120                 }
    121                 prev_value->SetValueNoMutex(i,j,output->ValueNoMutex(i,j));
    122             }
    123         }
    124     }
    125     input->ReleaseMutex();
    126     output->ReleaseMutex();
    127 
    128     output->SetDataTime(data->DataTime());
    129     previous_time=data->DataTime();
    130 }
    131 
Note: See TracChangeset for help on using the changeset viewer.