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-xshzku': No space left on device

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

Last change on this file since 137 was 15, checked in by Bayard Gildas, 8 years ago

sources reformatted with flair-format-dir script

File size: 3.6 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 <cvmatrix.h>
21#include <Layout.h>
22#include <GroupBox.h>
23#include <SpinBox.h>
24#include <DoubleSpinBox.h>
25
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 cvmatrix *init_value) {
37 first_update = true;
38
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));
63 }
64 }
65
66 output = new cvmatrix(self, desc,
67 prev_value->GetDataType().GetElementDataType(), name);
68
69 output->SetValue(0, 0, 0);
70}
71
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();
117}
Note: See TracBrowser for help on using the repository browser.