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

Last change on this file since 216 was 214, checked in by Sanahuja Guillaume, 6 years ago

matrix

File size: 3.5 KB
RevLine 
[10]1// %flair:license{
[15]2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
[10]4// %flair:license}
[7]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"
[214]20#include <Matrix.h>
[7]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
[15]30EulerDerivative_impl::EulerDerivative_impl(EulerDerivative *self,
31 const LayoutPosition *position,
32 string name,
[214]33 const Matrix *init_value) {
[15]34 first_update = true;
[214]35 this->self = self;
[147]36
37 if (init_value != NULL) {
38 // init output matrix of same size as init
39 cvmatrix_descriptor *desc =new cvmatrix_descriptor(init_value->Rows(), init_value->Cols());
[7]40
[147]41 for (int i = 0; i < init_value->Rows(); i++) {
42 for (int j = 0; j < init_value->Cols(); j++) {
43 desc->SetElementName(i, j, init_value->Name(i, j));
44 }
45 }
[214]46 output = new Matrix(self, desc,init_value->GetDataType().GetElementDataType(), name);
[148]47 delete desc;
[147]48 for (int i = 0; i < init_value->Rows(); i++) {
49 for (int j = 0; j < init_value->Cols(); j++) {
50 output->SetValue(i, j, init_value->Value(i,j));
51 }
52 }
[15]53 } else {
54 // if NULL, assume dimension 1, and init=0
55 cvmatrix_descriptor *desc = new cvmatrix_descriptor(1, 1);
56 desc->SetElementName(0, 0, "output");
[214]57 output = new Matrix(self, desc, floatType, name);
[148]58 delete desc;
[15]59 }
[147]60
61
62 cvmatrix_descriptor *desc = new cvmatrix_descriptor(output->Rows(), output->Cols());
[214]63 prev_value = new Matrix(self, desc, output->GetDataType().GetElementDataType(), name);
[7]64
[147]65
[15]66 // init UI
67 GroupBox *reglages_groupbox = new GroupBox(position, name);
68 T = new DoubleSpinBox(reglages_groupbox->NewRow(), "period, 0 for auto:",
69 " s", 0, 1, 0.01);
[7]70}
71
[15]72EulerDerivative_impl::~EulerDerivative_impl() {}
[7]73
[15]74void EulerDerivative_impl::UpdateFrom(const io_data *data) {
75 float delta_t;
[214]76 const Matrix* input = dynamic_cast<const Matrix*>(data);
77
78 if (!input) {
79 self->Warn("casting %s to Matrix failed\n",data->ObjectName().c_str());
80 return;
81 }
[7]82
[15]83 // on prend une fois pour toute les mutex et on fait des accès directs
84 output->GetMutex();
85 input->GetMutex();
[7]86
[15]87 if (first_update == true) {
88 for (int i = 0; i < input->Rows(); i++) {
89 for (int j = 0; j < input->Cols(); j++) {
90 prev_value->SetValueNoMutex(i, j, input->ValueNoMutex(i, j));
91 }
[7]92 }
[15]93 first_update = false;
94 } else {
95 if (T->Value() == 0) {
96 delta_t = (float)(data->DataTime() - previous_time) / 1000000000.;
97 } else {
98 delta_t = T->Value();
99 }
[7]100
[15]101 for (int i = 0; i < input->Rows(); i++) {
102 for (int j = 0; j < input->Cols(); j++) {
103 output->SetValueNoMutex(
104 i, j, (input->ValueNoMutex(i, j) - prev_value->ValueNoMutex(i, j)) /
105 delta_t);
106 prev_value->SetValueNoMutex(i, j, input->ValueNoMutex(i, j));
107 }
[7]108 }
[15]109 }
[7]110
[15]111 input->ReleaseMutex();
112 output->ReleaseMutex();
[7]113
[15]114 output->SetDataTime(data->DataTime());
115 previous_time = data->DataTime();
[7]116}
Note: See TracBrowser for help on using the repository browser.