source: flair-src/trunk/lib/FlairFilter/src/EulerDerivative_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.1 KB
Line 
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 prev_value = (cvmatrix *)init_value;
38 } else {
39 // if NULL, assume dimension 1, and init=0
40 cvmatrix_descriptor *desc = new cvmatrix_descriptor(1, 1);
41 desc->SetElementName(0, 0, "output");
42 prev_value = new cvmatrix(self, desc, floatType, name);
43 prev_value->SetValue(0, 0, 0);
44 }
45
46 // init UI
47 GroupBox *reglages_groupbox = new GroupBox(position, name);
48 T = new DoubleSpinBox(reglages_groupbox->NewRow(), "period, 0 for auto:",
49 " s", 0, 1, 0.01);
50
51 // init output matrix of same size as init
52 cvmatrix_descriptor *desc =
53 new cvmatrix_descriptor(prev_value->Rows(), prev_value->Cols());
54
55 for (int i = 0; i < prev_value->Rows(); i++) {
56 for (int j = 0; j < prev_value->Cols(); j++) {
57 desc->SetElementName(i, j, prev_value->Name(i, j));
58 }
59 }
60
61 output = new cvmatrix(self, desc,
62 prev_value->GetDataType().GetElementDataType(), name);
63}
64
65EulerDerivative_impl::~EulerDerivative_impl() {}
66
67void EulerDerivative_impl::UpdateFrom(const io_data *data) {
68 float delta_t;
69 cvmatrix *input = (cvmatrix *)data;
70
71 // on prend une fois pour toute les mutex et on fait des accès directs
72 output->GetMutex();
73 input->GetMutex();
74
75 if (first_update == true) {
76 for (int i = 0; i < input->Rows(); i++) {
77 for (int j = 0; j < input->Cols(); j++) {
78 output->SetValueNoMutex(i, j, prev_value->ValueNoMutex(i, j));
79 prev_value->SetValueNoMutex(i, j, input->ValueNoMutex(i, j));
80 }
81 }
82 first_update = false;
83 } else {
84 if (T->Value() == 0) {
85 delta_t = (float)(data->DataTime() - previous_time) / 1000000000.;
86 } else {
87 delta_t = T->Value();
88 }
89
90 for (int i = 0; i < input->Rows(); i++) {
91 for (int j = 0; j < input->Cols(); j++) {
92 output->SetValueNoMutex(
93 i, j, (input->ValueNoMutex(i, j) - prev_value->ValueNoMutex(i, j)) /
94 delta_t);
95 prev_value->SetValueNoMutex(i, j, input->ValueNoMutex(i, j));
96 }
97 }
98 }
99
100 input->ReleaseMutex();
101 output->ReleaseMutex();
102
103 output->SetDataTime(data->DataTime());
104 previous_time = data->DataTime();
105}
Note: See TracBrowser for help on using the repository browser.