[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 |
|
---|
| 25 | using std::string;
|
---|
| 26 | using namespace flair::core;
|
---|
| 27 | using namespace flair::gui;
|
---|
| 28 | using namespace flair::filter;
|
---|
| 29 |
|
---|
[15] | 30 | EulerDerivative_impl::EulerDerivative_impl(EulerDerivative *self,
|
---|
| 31 | const LayoutPosition *position,
|
---|
| 32 | string name,
|
---|
[214] | 33 | const Matrix *init_value) {
|
---|
| 34 | this->self = self;
|
---|
[147] | 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());
|
---|
[7] | 39 |
|
---|
[147] | 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 | }
|
---|
[214] | 45 | output = new Matrix(self, desc,init_value->GetDataType().GetElementDataType(), name);
|
---|
[148] | 46 | delete desc;
|
---|
[147] | 47 | for (int i = 0; i < init_value->Rows(); i++) {
|
---|
| 48 | for (int j = 0; j < init_value->Cols(); j++) {
|
---|
| 49 | output->SetValue(i, j, init_value->Value(i,j));
|
---|
| 50 | }
|
---|
| 51 | }
|
---|
[15] | 52 | } else {
|
---|
| 53 | // if NULL, assume dimension 1, and init=0
|
---|
| 54 | cvmatrix_descriptor *desc = new cvmatrix_descriptor(1, 1);
|
---|
| 55 | desc->SetElementName(0, 0, "output");
|
---|
[214] | 56 | output = new Matrix(self, desc, floatType, name);
|
---|
[148] | 57 | delete desc;
|
---|
[15] | 58 | }
|
---|
[147] | 59 |
|
---|
| 60 |
|
---|
| 61 | cvmatrix_descriptor *desc = new cvmatrix_descriptor(output->Rows(), output->Cols());
|
---|
[214] | 62 | prev_value = new Matrix(self, desc, output->GetDataType().GetElementDataType(), name);
|
---|
[7] | 63 |
|
---|
[147] | 64 |
|
---|
[15] | 65 | // init UI
|
---|
| 66 | GroupBox *reglages_groupbox = new GroupBox(position, name);
|
---|
| 67 | T = new DoubleSpinBox(reglages_groupbox->NewRow(), "period, 0 for auto:",
|
---|
| 68 | " s", 0, 1, 0.01);
|
---|
[7] | 69 | }
|
---|
| 70 |
|
---|
[15] | 71 | EulerDerivative_impl::~EulerDerivative_impl() {}
|
---|
[7] | 72 |
|
---|
[15] | 73 | void EulerDerivative_impl::UpdateFrom(const io_data *data) {
|
---|
| 74 | float delta_t;
|
---|
[214] | 75 | const Matrix* input = dynamic_cast<const Matrix*>(data);
|
---|
| 76 |
|
---|
| 77 | if (!input) {
|
---|
| 78 | self->Warn("casting %s to Matrix failed\n",data->ObjectName().c_str());
|
---|
| 79 | return;
|
---|
| 80 | }
|
---|
[7] | 81 |
|
---|
[15] | 82 | // on prend une fois pour toute les mutex et on fait des accès directs
|
---|
| 83 | output->GetMutex();
|
---|
| 84 | input->GetMutex();
|
---|
[7] | 85 |
|
---|
[15] | 86 | if (first_update == true) {
|
---|
| 87 | for (int i = 0; i < input->Rows(); i++) {
|
---|
| 88 | for (int j = 0; j < input->Cols(); j++) {
|
---|
| 89 | prev_value->SetValueNoMutex(i, j, input->ValueNoMutex(i, j));
|
---|
| 90 | }
|
---|
[7] | 91 | }
|
---|
[15] | 92 | first_update = false;
|
---|
| 93 | } else {
|
---|
| 94 | if (T->Value() == 0) {
|
---|
[223] | 95 | delta_t = (float)(data->DataDeltaTime()) / 1000000000.;
|
---|
[15] | 96 | } else {
|
---|
| 97 | delta_t = T->Value();
|
---|
| 98 | }
|
---|
[7] | 99 |
|
---|
[223] | 100 | if(delta_t!=0) {
|
---|
| 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 | }
|
---|
[15] | 108 | }
|
---|
[7] | 109 | }
|
---|
[15] | 110 | }
|
---|
[7] | 111 |
|
---|
[15] | 112 | input->ReleaseMutex();
|
---|
| 113 | output->ReleaseMutex();
|
---|
[7] | 114 |
|
---|
[15] | 115 | output->SetDataTime(data->DataTime());
|
---|
[7] | 116 | }
|
---|