Changeset 16 in flair-src for trunk/demos/Sinus/src/MeanFilter.cpp


Ignore:
Timestamp:
Apr 8, 2016, 3:48:40 PM (5 years ago)
Author:
Bayard Gildas
Message:

Reformatting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/demos/Sinus/src/MeanFilter.cpp

    r14 r16  
    2222using namespace flair::gui;
    2323
    24 namespace flair { namespace filter {
     24namespace flair {
     25namespace filter {
    2526
    26 MeanFilter::MeanFilter(const IODevice* parent,const LayoutPosition* position,string name): IODevice(parent,name) {
    27     //interface initialisation
    28     groupBox=new GroupBox(position,name);
    29     numberOfElements=new SpinBox(groupBox->NewRow(),"numberOfElements:",1,MAX_NUMBER_OF_ELEMENTS,1);//saturated to MAX_NUMBER_OF_ELEMENTS
     27MeanFilter::MeanFilter(const IODevice *parent, const LayoutPosition *position,
     28                       string name)
     29    : IODevice(parent, name) {
     30  // interface initialisation
     31  groupBox = new GroupBox(position, name);
     32  numberOfElements = new SpinBox(groupBox->NewRow(), "numberOfElements:", 1,
     33                                 MAX_NUMBER_OF_ELEMENTS,
     34                                 1); // saturated to MAX_NUMBER_OF_ELEMENTS
    3035
    31     //init storage
    32     for(int i=0; i<MAX_NUMBER_OF_ELEMENTS; i++) previousValues[i]=0;
     36  // init storage
     37  for (int i = 0; i < MAX_NUMBER_OF_ELEMENTS; i++)
     38    previousValues[i] = 0;
    3339
    34     //1*1 output matrix
    35     cvmatrix_descriptor* desc=new cvmatrix_descriptor(1,1);
    36     desc->SetElementName(0,0,"mean filter");//name will be used for graphs and logs
    37     output=new cvmatrix(this,desc,floatType,name);
     40  // 1*1 output matrix
     41  cvmatrix_descriptor *desc = new cvmatrix_descriptor(1, 1);
     42  desc->SetElementName(0, 0,
     43                       "mean filter"); // name will be used for graphs and logs
     44  output = new cvmatrix(this, desc, floatType, name);
    3845
    39     AddDataToLog(output);
     46  AddDataToLog(output);
    4047}
    4148
    42 MeanFilter::~MeanFilter() {
    43 }
     49MeanFilter::~MeanFilter() {}
    4450
    45 cvmatrix *MeanFilter::GetMatrix() const {
    46     return output;
    47 }
     51cvmatrix *MeanFilter::GetMatrix() const { return output; }
    4852
    49 float MeanFilter::GetValue(void) const {
    50     return output->Value(0,0);
    51 }
     53float MeanFilter::GetValue(void) const { return output->Value(0, 0); }
    5254
    53 //UpdateFrom, where we implement the filter
    54 //this method is automatically called when the parent IODevice calls ProcessUpdate
    55 //in our case it is the sinus or the 1st orde law pass filter
     55// UpdateFrom, where we implement the filter
     56// this method is automatically called when the parent IODevice calls
     57// ProcessUpdate
     58// in our case it is the sinus or the 1st orde law pass filter
    5659//(see in Sinus::Run the call to ProcessUpdate)
    5760void MeanFilter::UpdateFrom(const io_data *data) {
    5861
    59     float result=0;
    60     //get input argument in a cvmatrix
    61     cvmatrix *input=(cvmatrix*)data;
     62  float result = 0;
     63  // get input argument in a cvmatrix
     64  cvmatrix *input = (cvmatrix *)data;
    6265
    63     //simple (and not efficent!) implementation of the filter
    64     previousValues[numberOfElements->Value()-1]=input->Value(0,0);
    65     for(int i=0; i<numberOfElements->Value(); i++) result+=previousValues[i];
    66     for(int i=1; i<numberOfElements->Value(); i++) previousValues[i-1]=previousValues[i];
     66  // simple (and not efficent!) implementation of the filter
     67  previousValues[numberOfElements->Value() - 1] = input->Value(0, 0);
     68  for (int i = 0; i < numberOfElements->Value(); i++)
     69    result += previousValues[i];
     70  for (int i = 1; i < numberOfElements->Value(); i++)
     71    previousValues[i - 1] = previousValues[i];
    6772
    68     //put the result in output matrix
    69     output->SetValue(0,0,result/numberOfElements->Value());
    70     //put corresponding time
    71     output->SetDataTime(data->DataTime());
     73  // put the result in output matrix
     74  output->SetValue(0, 0, result / numberOfElements->Value());
     75  // put corresponding time
     76  output->SetDataTime(data->DataTime());
    7277
    73     //ProcessUpdate is very important
    74     //we must call it after updating the output matrix
    75     //it allows:
    76     // -to save value in the logs
    77     // -to automatically call the next filter UpdateFrom method
    78     ProcessUpdate(output);
     78  // ProcessUpdate is very important
     79  // we must call it after updating the output matrix
     80  // it allows:
     81  // -to save value in the logs
     82  // -to automatically call the next filter UpdateFrom method
     83  ProcessUpdate(output);
    7984}
    80 }// end namespace filter
    81 }// end namespace flair
     85} // end namespace filter
     86} // end namespace flair
Note: See TracChangeset for help on using the changeset viewer.