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

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

modifs uav vrpn i686

File size: 3.9 KB
RevLine 
[122]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
15using std::string;
16
17namespace flair
18{
19namespace filter
20{
21
22OpticalFlowData::OpticalFlowData(const Object* parent,uint32_t max_features,string name,uint32_t n): io_data(parent,name,n)
23{
24 this->max_features=max_features;
25 nb_features=0;
26
27 pointsA=(CvPoint *)cvAlloc(max_features*sizeof(CvPoint));
28 pointsB=(CvPoint2D32f *)cvAlloc(max_features*sizeof(CvPoint2D32f));
29
30 found_features=(char *)cvAlloc(max_features*sizeof(char));
31 features_error=(uint32_t*)cvAlloc(max_features*sizeof(uint32_t));
32}
33
34OpticalFlowData::~OpticalFlowData()
35{
36 cvFree(&pointsA);
37 cvFree(&pointsB);
38
39 cvFree(&found_features);
40 cvFree(&features_error);
41}
42
43CvPoint* OpticalFlowData::PointsA(void) const
44{
45 return pointsA;
46}
47
48CvPoint2D32f* OpticalFlowData::PointsB(void) const
49{
50 return pointsB;
51}
52
53char *OpticalFlowData::FoundFeature(void) const
54{
55 return found_features;
56}
57
58uint32_t *OpticalFlowData::FeatureError(void) const
59{
60 return features_error;
61}
62
63// value is new max_features value
64void OpticalFlowData::Resize(uint32_t value) {
65 CvPoint *new_pointsA;
66 CvPoint2D32f *new_pointsB;
67 char *new_found_features;
68 uint32_t *new_features_error;
69
70 new_pointsA=(CvPoint *)cvAlloc(value*sizeof(CvPoint));
71 new_pointsB=(CvPoint2D32f *)cvAlloc(value*sizeof(CvPoint2D32f));
72 new_found_features=(char *)cvAlloc(value*sizeof(char));
73 new_features_error=(uint32_t *)cvAlloc(value*sizeof(uint32_t));
74
75 GetMutex();
76 if(value>max_features)
77 {
78 memcpy(new_pointsA,pointsA,max_features*sizeof(CvPoint));
79 memcpy(new_pointsB,pointsB,max_features*sizeof(CvPoint2D32f));
80 memcpy(new_found_features,found_features,max_features*sizeof(char));
81 memcpy(new_features_error,features_error,max_features*sizeof(uint32_t));
82 }
83 else
84 {
85 memcpy(new_pointsA,pointsA,value*sizeof(CvPoint));
86 memcpy(new_pointsB,pointsB,value*sizeof(CvPoint2D32f));
87 memcpy(new_found_features,found_features,value*sizeof(char));
88 memcpy(new_features_error,features_error,value*sizeof(uint32_t));
89 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
90 }
91 max_features=value;
92 ReleaseMutex();
93
94 cvFree(&pointsA);
95 cvFree(&pointsB);
96 cvFree(&found_features);
97 cvFree(&features_error);
98
99 pointsA=new_pointsA;
100 pointsB=new_pointsB;
101 found_features=new_found_features;
102 features_error=new_features_error;
103}
104
105void OpticalFlowData::CopyDatas(char* dst) const
106{
107 Warn("non implementé\n");
108}
109
110void OpticalFlowData::SetPointsA(const CvPoint* points)
111{
112 GetMutex();
113 memcpy(pointsA,points,max_features*sizeof(CvPoint));
114 ReleaseMutex();
115}
116
117void OpticalFlowData::SetPointsB(const CvPoint2D32f* points)
118{
119 GetMutex();
120 memcpy(pointsB,points,max_features*sizeof(CvPoint2D32f));
121 ReleaseMutex();
122}
123
124void OpticalFlowData::SetFoundFeature(const char *found_features)
125{
126 GetMutex();
127 memcpy(this->found_features,found_features,max_features*sizeof(char));
128 ReleaseMutex();
129}
130
131void OpticalFlowData::SetFeatureError(const uint32_t *features_error)
132{
133 GetMutex();
134 memcpy(this->features_error,features_error,max_features*sizeof(uint32_t));
135 ReleaseMutex();
136}
137
138uint32_t OpticalFlowData::MaxFeatures(void) const
139{
140 return max_features;
141}
142
143uint32_t OpticalFlowData::NbFeatures(void) const
144{
145 return nb_features;
146}
147
148void OpticalFlowData::SetNbFeatures(uint32_t value)
149{
150 GetMutex();
151 nb_features=value;
152 ReleaseMutex();
153}
154
155} // end namespace filter
156} // end namespace flair
Note: See TracBrowser for help on using the repository browser.