close Warning: Can't use blame annotator:
svn blame failed on trunk/lib/FlairFilter/src/LowPassFilter_impl.cpp: 28 - Can't close file '/tmp/svn-Ev2iR7': No space left on device

source: flair-src/trunk/lib/FlairFilter/src/LowPassFilter_impl.cpp@ 318

Last change on this file since 318 was 318, checked in by Sanahuja Guillaume, 5 years ago
File size: 3.5 KB
RevLine 
1// %flair:license{
2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
4// %flair:license}
5// created: 2011/05/01
6// filename: LowPassFilter_impl.cpp
7//
8// author: Guillaume Sanahuja
9// Copyright Heudiasyc UMR UTC/CNRS 7253
10//
11// version: $Id: $
12//
13// purpose: objet permettant le calcul d'un filtre passe bas
14//
15//
16/*********************************************************************/
17
18#include "LowPassFilter_impl.h"
19#include "LowPassFilter.h"
20#include <Matrix.h>
21#include <Layout.h>
22#include <GroupBox.h>
23#include <SpinBox.h>
24#include <DoubleSpinBox.h>
25#include <typeinfo>
26#define PI ((float)3.14159265358979323846)
27
28using std::string;
29using namespace flair::core;
30using namespace flair::gui;
31using namespace flair::filter;
32
33LowPassFilter_impl::LowPassFilter_impl(const LowPassFilter *self,
34 const LayoutPosition *position,
35 string name,
36 const Matrix *init_value) {
37
38 if (init_value != NULL) {
39 // init output matrix of same size as init
40 MatrixDescriptor *desc =new MatrixDescriptor(init_value->Rows(), init_value->Cols());
41
42 for (int i = 0; i < init_value->Rows(); i++) {
43 for (int j = 0; j < init_value->Cols(); j++) {
44 desc->SetElementName(i, j, init_value->Name(i, j));
45 }
46 }
47 output = new Matrix(self, desc,init_value->GetDataType().GetElementDataType(), name);
48 for (int i = 0; i < init_value->Rows(); i++) {
49 for (int j = 0; j < init_value->Cols(); j++) {
50 output->SetValue(i, j, init_value->Value(i,j));
51 }
52 }
53 delete desc;
54 } else {
55 // if NULL, assume dimension 1, and init=0
56 MatrixDescriptor *desc = new MatrixDescriptor(1, 1);
57 desc->SetElementName(0, 0, "output");
58 output = new Matrix(self, desc, floatType, name);
59 delete desc;
60 }
61
62 // init UI
63 GroupBox *reglages_groupbox = new GroupBox(position, name);
64 T = new DoubleSpinBox(reglages_groupbox->NewRow(), "period, 0 for auto", " s",
65 0, 10, 0.01);
66 freq = new DoubleSpinBox(reglages_groupbox->NewRow(), "cutoff frequency",
67 " Hz", 0, 10000, 0.1, 2, 1);
68
69 this->self = self;
70}
71
72LowPassFilter_impl::~LowPassFilter_impl() {}
73
74void LowPassFilter_impl::UpdateFrom(const io_data *data) {
75 float delta_t;
76 const Matrix* input = dynamic_cast<const Matrix*>(data);
77
78 if (!input) {
79 self->Warn("casting %s to Matrix failed\n",data->ObjectName().c_str());
80 return;
81 }
82
83 // on prend une fois pour toute les mutex et on fait des accès directs
84 output->GetMutex();
85 input->GetMutex();
86
87 if (T->Value() == 0) {
88 delta_t = (float)(data->DataDeltaTime() ) / 1000000000.;
89 } else {
90 delta_t = T->Value();
91 }
92
93 if(delta_t!=0) {
94 for (int i = 0; i < input->Rows(); i++) {
95 for (int j = 0; j < input->Cols(); j++) {
96 float cutoff=freq->Value();
97 if (cutoff == 0 || freq->ValueChanged()) {
98 output->SetValueNoMutex(i, j, input->ValueNoMutex(i, j));
99 } else {
100 output->SetValueNoMutex(i, j, (1 - 2 * PI * cutoff * delta_t) *
101 output->ValueNoMutex(i, j) +
102 2 * PI * cutoff * delta_t *
103 input->ValueNoMutex(i, j));
104 }
105 }
106 }
107 }
108
109 input->ReleaseMutex();
110 output->ReleaseMutex();
111
112 output->SetDataTime(data->DataTime());
113}
Note: See TracBrowser for help on using the repository browser.