Changeset 15 in flair-src for trunk/lib/FlairFilter/src/EulerDerivative_impl.cpp
- Timestamp:
- Apr 8, 2016, 3:40:57 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/FlairFilter/src/EulerDerivative_impl.cpp
r10 r15 28 28 using namespace flair::filter; 29 29 30 EulerDerivative_impl::EulerDerivative_impl(EulerDerivative* self,const LayoutPosition* position,string name,const cvmatrix* init_value) 31 { 32 first_update=true; 30 EulerDerivative_impl::EulerDerivative_impl(EulerDerivative *self, 31 const LayoutPosition *position, 32 string name, 33 const cvmatrix *init_value) { 34 first_update = true; 33 35 34 if(init_value!=NULL) 35 { 36 prev_value=(cvmatrix*)init_value; 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)); 37 58 } 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); 59 } 60 61 output = new cvmatrix(self, desc, 62 prev_value->GetDataType().GetElementDataType(), name); 63 } 64 65 EulerDerivative_impl::~EulerDerivative_impl() {} 66 67 void 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(); 45 88 } 46 89 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); 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 } 50 99 51 //init output matrix of same size as init52 cvmatrix_descriptor* desc=new cvmatrix_descriptor(prev_value->Rows(),prev_value->Cols());100 input->ReleaseMutex(); 101 output->ReleaseMutex(); 53 102 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); 103 output->SetDataTime(data->DataTime()); 104 previous_time = data->DataTime(); 63 105 } 64 65 EulerDerivative_impl::~EulerDerivative_impl()66 {67 68 }69 70 void 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 directs76 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 else92 {93 if(T->Value()==0)94 {95 delta_t=(float)(data->DataTime()-previous_time)/1000000000.;96 }97 else98 {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 TracChangeset
for help on using the changeset viewer.