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

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

lic

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