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

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

filter and meta

File size: 2.9 KB
Line 
1// created: 2011/05/01
2// filename: EulerDerivative.cpp
3//
4// author: Guillaume Sanahuja
5// Copyright Heudiasyc UMR UTC/CNRS 7253
6//
7// version: $Id: $
8//
9// purpose: objet permettant le calcul d'une derivee d'Euler
10//
11//
12/*********************************************************************/
13
14#include "EulerDerivative.h"
15#include "EulerDerivative_impl.h"
16#include <cvmatrix.h>
17#include <Layout.h>
18#include <GroupBox.h>
19#include <DoubleSpinBox.h>
20
21using std::string;
22using namespace flair::core;
23using namespace flair::gui;
24using namespace flair::filter;
25
26EulerDerivative_impl::EulerDerivative_impl(EulerDerivative* self,const LayoutPosition* position,string name,const cvmatrix* init_value)
27{
28 first_update=true;
29
30 if(init_value!=NULL)
31 {
32 prev_value=(cvmatrix*)init_value;
33 }
34 else
35 {
36 //if NULL, assume dimension 1, and init=0
37 cvmatrix_descriptor* desc=new cvmatrix_descriptor(1,1);
38 desc->SetElementName(0,0,"output");
39 prev_value=new cvmatrix(self,desc,floatType,name);
40 prev_value->SetValue(0,0,0);
41 }
42
43 //init UI
44 GroupBox* reglages_groupbox=new GroupBox(position,name);
45 T=new DoubleSpinBox(reglages_groupbox->NewRow(),"period, 0 for auto:"," s",0,1,0.01);
46
47 //init output matrix of same size as init
48 cvmatrix_descriptor* desc=new cvmatrix_descriptor(prev_value->Rows(),prev_value->Cols());
49
50 for(int i=0;i<prev_value->Rows();i++)
51 {
52 for(int j=0;j<prev_value->Cols();j++)
53 {
54 desc->SetElementName(i,j,prev_value->Name(i,j));
55 }
56 }
57
58 output=new cvmatrix(self,desc,prev_value->GetDataType().GetElementDataType(),name);
59}
60
61EulerDerivative_impl::~EulerDerivative_impl()
62{
63
64}
65
66void EulerDerivative_impl::UpdateFrom(const io_data *data)
67{
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 {
77 for(int i=0;i<input->Rows();i++)
78 {
79 for(int j=0;j<input->Cols();j++)
80 {
81 output->SetValueNoMutex(i,j,prev_value->ValueNoMutex(i,j));
82 prev_value->SetValueNoMutex(i,j,input->ValueNoMutex(i,j));
83 }
84 }
85 first_update=false;
86 }
87 else
88 {
89 if(T->Value()==0)
90 {
91 delta_t=(float)(data->DataTime()-previous_time)/1000000000.;
92 }
93 else
94 {
95 delta_t=T->Value();
96 }
97
98 for(int i=0;i<input->Rows();i++)
99 {
100 for(int j=0;j<input->Cols();j++)
101 {
102 output->SetValueNoMutex(i,j,(input->ValueNoMutex(i,j)-prev_value->ValueNoMutex(i,j))/delta_t);
103 prev_value->SetValueNoMutex(i,j,input->ValueNoMutex(i,j));
104 }
105 }
106 }
107
108 input->ReleaseMutex();
109 output->ReleaseMutex();
110
111 output->SetDataTime(data->DataTime());
112 previous_time=data->DataTime();
113}
114
Note: See TracBrowser for help on using the repository browser.