00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef TRACKS_H
00021 #define TRACKS_H
00022
00023 #include "mlist.h"
00024 #include "bucket2d.h"
00025
00035
00036 struct tframe;
00037 struct ttrack;
00038 struct tracks;
00039
00041 struct point2d {
00042 float u,v;
00043
00044 point2d(float u, float v) : u(u), v(v) {}
00045 point2d() {}
00046
00047 float dist(const point2d &a);
00048 };
00049
00052 struct tkeypoint : point2d {
00053
00055 mlist_elem<tkeypoint> points_in_frame;
00056
00058 mlist_elem<tkeypoint> matches;
00059
00061 tframe *frame;
00062
00066 ttrack *track;
00067
00068 tkeypoint() { frame=0; track=0; }
00069 tkeypoint(const tkeypoint &a) : point2d(a), frame(0), track(0) {}
00070
00073 void set(tframe *f, float u, float v);
00074 const tkeypoint &operator = (const tkeypoint &a);
00075
00077 int track_length();
00078
00080 bool track_is_longer(int l);
00081
00083 virtual void dispose() { delete this; }
00084 virtual ~tkeypoint();
00085
00087
00090 void unlink();
00091
00096 struct factory_t {
00097 virtual tkeypoint *create() { return new tkeypoint(); }
00098 virtual void destroy(tkeypoint *a) { delete a; }
00099 };
00100 };
00101
00102 class tracks;
00103
00108 struct tframe {
00112 bucket2d<tkeypoint> points;
00113
00115 mlist_elem<tframe> frames;
00116
00119 tframe(int w, int h, int bits) : points(w,h,bits) {}
00120
00122 virtual void append_to(tracks &track);
00123
00125 virtual ~tframe() {}
00126
00130 bool has_point_in(float u, float v, float r);
00131
00133 struct factory_t {
00134 virtual void destroy(tframe *a) { delete a; }
00135 };
00136 };
00137
00140 struct ttrack {
00141
00143 mlist_elem<ttrack> track_node;
00144
00149 tkeypoint *keypoints;
00150
00152 tracks *db;
00153
00155 int length;
00156
00157 ttrack(tracks *db) : db(db) { keypoints=0; length=0; }
00158 virtual ~ttrack() {}
00159
00163 virtual void point_added(tkeypoint *) { length++; }
00164
00166 virtual void point_removed(tkeypoint *) { length--; }
00167
00169 struct factory_t {
00170 virtual ttrack *create(tracks *db) { return new ttrack(db); }
00171 virtual void destroy(ttrack *a) { delete a; }
00172 };
00173 };
00174
00187 class tracks {
00188 public:
00189
00193 tracks(tkeypoint::factory_t *kf=0, tframe::factory_t *ff=0, ttrack::factory_t *tf = 0);
00194 ~tracks();
00195
00197 void set_match(tkeypoint *prev, tkeypoint *next);
00198
00200 void unset_match(tkeypoint *k);
00201
00203 struct frame_iterator {
00204 tframe *frame;
00205 tframe *operator ++() { return frame = frame->frames.next; }
00206 tframe *operator --() { return frame = frame->frames.prev; }
00207 bool end() { return frame == 0; }
00208 frame_iterator(tracks *t) { frame = t->frames; }
00209 frame_iterator(tframe *f) { frame = f; }
00210 tframe *elem() { return frame; }
00211 };
00212
00214 frame_iterator get_nth_frame_it(int n);
00215
00217 tframe *get_nth_frame(int n);
00218
00220 typedef bucket2d<tkeypoint>::iterator keypoint_frame_iterator;
00221
00223 struct keypoint_match_iterator {
00224 tkeypoint *point;
00225 tkeypoint *operator ++() { return point = point->matches.next; }
00226 tkeypoint *operator --() { return point = point->matches.prev; }
00227 tkeypoint &operator ->() { return *point; }
00228 tkeypoint *elem() { return point; }
00229 bool end() { return point==0; }
00230 keypoint_match_iterator(tkeypoint *p) : point(p) {}
00231 };
00232
00236 void remove_point_track(tkeypoint *point);
00237
00239 void remove_track_tail(tkeypoint *point);
00240
00243 void remove_unmatched_tracks(frame_iterator frame_it);
00244
00246 void remove_empty_frames();
00247
00249 void remove_frame(frame_iterator &f);
00250
00252 void remove_frame(tframe *frame);
00253
00254 tframe *frames;
00255 ttrack *all_tracks;
00256
00257 tkeypoint::factory_t *keypoint_factory;
00258 tframe::factory_t *tframe_factory;
00259 ttrack::factory_t *ttrack_factory;
00260 };
00261
00262 inline float point2d::dist(const point2d &a)
00263 {
00264 float du = u-a.u;
00265 float dv = v-a.v;
00266 return sqrtf(du*du + dv*dv);
00267 }
00268
00269 inline bool tkeypoint::track_is_longer(int l) {
00270 if (!track) return l==0;
00271 return track->length >=l;
00272
00273
00274
00275
00276
00277
00278
00279
00280 }
00281
00284 #endif