source: flair-src/trunk/lib/FlairVisionFilter/src/OpticalFlowData.cpp

Last change on this file was 338, checked in by Sanahuja Guillaume, 2 years ago

remove opencv dep

File size: 4.8 KB
Line 
1// created: 2012/04/12
2// filename: OpticalFlowData.cpp
3//
4// author: Guillaume Sanahuja
5// Copyright Heudiasyc UMR UTC/CNRS 7253
6//
7// version: $Id: $
8//
9// purpose: classe pour les données du flux optique
10//
11/*********************************************************************/
12
13#include "OpticalFlowData.h"
14#include "VisionFilter.h"
15#include <string.h>
16
17using std::string;
18
19class OpticalFlowData_impl {
20public:
21 OpticalFlowData_impl(flair::filter::OpticalFlowData* self,uint32_t max_features) {
22 this->self=self;
23 this->max_features=max_features;
24 nb_features=0;
25 pointsA=(IntPoint*)malloc(max_features*sizeof(IntPoint));
26 pointsB=(FloatPoint*)malloc(max_features*sizeof(FloatPoint));
27
28 found_features=(char*)malloc(max_features*sizeof(char));
29 features_error=(uint32_t*)malloc(max_features*sizeof(uint32_t));
30 }
31
32 ~OpticalFlowData_impl() {
33 free((char*)pointsA);
34 free((char*)pointsB);
35
36 free((char*)found_features);
37 free((char*)features_error);
38 }
39
40 void Resize(uint32_t value) {
41 IntPoint *new_pointsA;
42 FloatPoint *new_pointsB;
43 char *new_found_features;
44 uint32_t *new_features_error;
45
46 new_pointsA=(IntPoint*)malloc(value*sizeof(IntPoint));
47 new_pointsB=(FloatPoint*)malloc(value*sizeof(FloatPoint));
48 new_found_features=(char*)malloc(value*sizeof(char));
49 new_features_error=(uint32_t*)malloc(value*sizeof(uint32_t));
50
51 self->GetMutex();
52 if(value>max_features) {
53 memcpy(new_pointsA,pointsA,max_features*sizeof(IntPoint));
54 memcpy(new_pointsB,pointsB,max_features*sizeof(FloatPoint));
55 memcpy(new_found_features,found_features,max_features*sizeof(char));
56 memcpy(new_features_error,features_error,max_features*sizeof(uint32_t));
57 } else {
58 memcpy(new_pointsA,pointsA,value*sizeof(IntPoint));
59 memcpy(new_pointsB,pointsB,value*sizeof(FloatPoint));
60 memcpy(new_found_features,found_features,value*sizeof(char));
61 memcpy(new_features_error,features_error,value*sizeof(uint32_t));
62 if(nb_features>value) nb_features=value; //si nb_features est le nombre de point qui ont effectivement une correspondande, ça me parait louche. Sauf si les points sont classés et que ceux qui ont une correpondance sont toujours au début
63 }
64 max_features=value;
65 self->ReleaseMutex();
66
67 free((char*)pointsA);
68 free((char*)pointsB);
69 free((char*)found_features);
70 free((char*)features_error);
71
72 pointsA=new_pointsA;
73 pointsB=new_pointsB;
74 found_features=new_found_features;
75 features_error=new_features_error;
76 }
77
78 uint32_t max_features;
79 uint32_t nb_features;
80 IntPoint* pointsA;
81 FloatPoint* pointsB;
82 char *found_features;
83 uint32_t *features_error;
84
85private:
86 flair::filter::OpticalFlowData *self;
87};
88
89namespace flair {
90namespace filter {
91
92OpticalFlowData::OpticalFlowData(const Object* parent,uint32_t max_features,string name,uint32_t n): io_data(parent,name,n) {
93 pimpl_=new OpticalFlowData_impl(this,max_features);
94}
95
96OpticalFlowData::~OpticalFlowData() {
97 delete pimpl_;
98}
99
100IntPoint* OpticalFlowData::PointsA(void) const {
101 return pimpl_->pointsA;
102}
103
104FloatPoint* OpticalFlowData::PointsB(void) const {
105 return pimpl_->pointsB;
106}
107
108char *OpticalFlowData::FoundFeature(void) const {
109 return pimpl_->found_features;
110}
111
112uint32_t *OpticalFlowData::FeatureError(void) const {
113 return pimpl_->features_error;
114}
115
116// value is new max_features value
117void OpticalFlowData::Resize(uint32_t value) {
118 pimpl_->Resize(value);
119}
120
121void OpticalFlowData::RawRead(char* dst) const {
122 Warn("non implementé\n");
123}
124
125void OpticalFlowData::SetPointsA(const IntPoint* points) {
126 GetMutex();
127 memcpy(pimpl_->pointsA,points,pimpl_->max_features*sizeof(IntPoint));
128 ReleaseMutex();
129}
130
131void OpticalFlowData::SetPointsB(const FloatPoint* points) {
132 GetMutex();
133 memcpy(pimpl_->pointsB,points,pimpl_->max_features*sizeof(FloatPoint));
134 ReleaseMutex();
135}
136
137void OpticalFlowData::SetFoundFeature(const char *found_features) {
138 GetMutex();
139 memcpy(pimpl_->found_features,found_features,pimpl_->max_features*sizeof(char));
140 ReleaseMutex();
141}
142
143void OpticalFlowData::SetFeatureError(const uint32_t *features_error) {
144 GetMutex();
145 memcpy(pimpl_->features_error,features_error,pimpl_->max_features*sizeof(uint32_t));
146 ReleaseMutex();
147}
148
149uint32_t OpticalFlowData::MaxFeatures(void) const {
150 return pimpl_->max_features;
151}
152
153uint32_t OpticalFlowData::NbFeatures(void) const {
154 return pimpl_->nb_features;
155}
156
157void OpticalFlowData::SetNbFeatures(uint32_t value) {
158 GetMutex();
159 pimpl_->nb_features=value;
160 ReleaseMutex();
161}
162
163} // end namespace filter
164} // end namespace flair
Note: See TracBrowser for help on using the repository browser.