close Warning: Can't use blame annotator:
svn blame failed on trunk/lib/FlairFilter/src/EulerDerivative_impl.cpp: 200029 - Couldn't perform atomic initialization

source: flair-src/trunk/lib/FlairFilter/src/EulerDerivative_impl.cpp@ 147

Last change on this file since 147 was 147, checked in by Sanahuja Guillaume, 7 years ago

modif euler/lowpass

File size: 3.3 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: EulerDerivative.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'une derivee d'Euler
14//
15//
16/*********************************************************************/
17
18#include "EulerDerivative.h"
19#include "EulerDerivative_impl.h"
20#include <cvmatrix.h>
21#include <Layout.h>
22#include <GroupBox.h>
23#include <DoubleSpinBox.h>
24
25using std::string;
26using namespace flair::core;
27using namespace flair::gui;
28using namespace flair::filter;
29
30EulerDerivative_impl::EulerDerivative_impl(EulerDerivative *self,
31 const LayoutPosition *position,
32 string name,
33 const cvmatrix *init_value) {
34 first_update = true;
35
36 if (init_value != NULL) {
37 // init output matrix of same size as init
38 cvmatrix_descriptor *desc =new cvmatrix_descriptor(init_value->Rows(), init_value->Cols());
39
40 for (int i = 0; i < init_value->Rows(); i++) {
41 for (int j = 0; j < init_value->Cols(); j++) {
42 desc->SetElementName(i, j, init_value->Name(i, j));
43 }
44 }
45 output = new cvmatrix(self, desc,init_value->GetDataType().GetElementDataType(), name);
46 for (int i = 0; i < init_value->Rows(); i++) {
47 for (int j = 0; j < init_value->Cols(); j++) {
48 output->SetValue(i, j, init_value->Value(i,j));
49 }
50 }
51 } else {
52 // if NULL, assume dimension 1, and init=0
53 cvmatrix_descriptor *desc = new cvmatrix_descriptor(1, 1);
54 desc->SetElementName(0, 0, "output");
55 output = new cvmatrix(self, desc, floatType, name);
56 output->SetValue(0, 0, 0);
57 }
58
59
60 cvmatrix_descriptor *desc = new cvmatrix_descriptor(output->Rows(), output->Cols());
61 prev_value = new cvmatrix(self, desc, output->GetDataType().GetElementDataType(), name);
62
63
64 // init UI
65 GroupBox *reglages_groupbox = new GroupBox(position, name);
66 T = new DoubleSpinBox(reglages_groupbox->NewRow(), "period, 0 for auto:",
67 " s", 0, 1, 0.01);
68}
69
70EulerDerivative_impl::~EulerDerivative_impl() {}
71
72void EulerDerivative_impl::UpdateFrom(const io_data *data) {
73 float delta_t;
74 cvmatrix *input = (cvmatrix *)data;
75
76 // on prend une fois pour toute les mutex et on fait des accès directs
77 output->GetMutex();
78 input->GetMutex();
79
80 if (first_update == true) {
81 for (int i = 0; i < input->Rows(); i++) {
82 for (int j = 0; j < input->Cols(); j++) {
83 prev_value->SetValueNoMutex(i, j, input->ValueNoMutex(i, j));
84 }
85 }
86 first_update = false;
87 } else {
88 if (T->Value() == 0) {
89 delta_t = (float)(data->DataTime() - previous_time) / 1000000000.;
90 } else {
91 delta_t = T->Value();
92 }
93
94 for (int i = 0; i < input->Rows(); i++) {
95 for (int j = 0; j < input->Cols(); j++) {
96 output->SetValueNoMutex(
97 i, j, (input->ValueNoMutex(i, j) - prev_value->ValueNoMutex(i, j)) /
98 delta_t);
99 prev_value->SetValueNoMutex(i, j, input->ValueNoMutex(i, j));
100 }
101 }
102 }
103
104 input->ReleaseMutex();
105 output->ReleaseMutex();
106
107 output->SetDataTime(data->DataTime());
108 previous_time = data->DataTime();
109}
Note: See TracBrowser for help on using the repository browser.