optv 0.2.6__tar.gz → 0.2.9__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. optv-0.2.9/PKG-INFO +10 -0
  2. {optv-0.2.6 → optv-0.2.9}/liboptv/include/optv/track.h +2 -2
  3. {optv-0.2.6 → optv-0.2.9}/liboptv/include/optv/tracking_frame_buf.h +65 -5
  4. {optv-0.2.6 → optv-0.2.9}/liboptv/include/optv/tracking_run.h +1 -1
  5. {optv-0.2.6 → optv-0.2.9}/liboptv/src/epi.c +5 -0
  6. {optv-0.2.6 → optv-0.2.9}/liboptv/src/segmentation.c +18 -0
  7. {optv-0.2.6 → optv-0.2.9}/liboptv/src/track.c +87 -9
  8. {optv-0.2.6 → optv-0.2.9}/liboptv/src/tracking_frame_buf.c +78 -38
  9. {optv-0.2.6 → optv-0.2.9}/liboptv/src/tracking_run.c +2 -2
  10. {optv-0.2.6 → optv-0.2.9}/optv/calibration.c +2500 -3827
  11. optv-0.2.9/optv/calibration.pxd +34 -0
  12. {optv-0.2.6 → optv-0.2.9}/optv/correspondences.c +1698 -2757
  13. optv-0.2.9/optv/correspondences.pxd +32 -0
  14. {optv-0.2.6 → optv-0.2.9}/optv/epipolar.c +1542 -2693
  15. optv-0.2.9/optv/epipolar.pxd +14 -0
  16. {optv-0.2.6 → optv-0.2.9}/optv/image_processing.c +1491 -2625
  17. optv-0.2.9/optv/image_processing.pxd +9 -0
  18. {optv-0.2.6 → optv-0.2.9}/optv/imgcoord.c +1833 -3082
  19. optv-0.2.9/optv/imgcoord.pxd +16 -0
  20. {optv-0.2.6 → optv-0.2.9}/optv/orientation.c +2971 -4188
  21. optv-0.2.9/optv/orientation.pxd +36 -0
  22. {optv-0.2.6 → optv-0.2.9}/optv/parameters.c +2760 -4312
  23. optv-0.2.9/optv/parameters.pxd +66 -0
  24. {optv-0.2.6 → optv-0.2.9}/optv/segmentation.c +2294 -2604
  25. optv-0.2.9/optv/segmentation.pxd +14 -0
  26. {optv-0.2.6 → optv-0.2.9}/optv/tracker.c +872 -318
  27. optv-0.2.9/optv/tracker.pxd +30 -0
  28. {optv-0.2.6 → optv-0.2.9}/optv/tracking_framebuf.c +2180 -3252
  29. optv-0.2.9/optv/tracking_framebuf.pxd +53 -0
  30. {optv-0.2.6 → optv-0.2.9}/optv/transforms.c +1751 -2843
  31. optv-0.2.9/optv/transforms.pxd +33 -0
  32. optv-0.2.9/optv/vec_utils.pxd +8 -0
  33. optv-0.2.9/optv.egg-info/PKG-INFO +10 -0
  34. {optv-0.2.6 → optv-0.2.9}/optv.egg-info/SOURCES.txt +14 -0
  35. optv-0.2.9/optv.egg-info/requires.txt +3 -0
  36. optv-0.2.9/pyproject.toml +16 -0
  37. {optv-0.2.6 → optv-0.2.9}/setup.py +12 -9
  38. optv-0.2.9/test/test_burgers.py +115 -0
  39. {optv-0.2.6 → optv-0.2.9}/test/test_corresp.py +7 -7
  40. {optv-0.2.6 → optv-0.2.9}/test/test_epipolar.py +2 -2
  41. {optv-0.2.6 → optv-0.2.9}/test/test_framebuf.py +18 -18
  42. {optv-0.2.6 → optv-0.2.9}/test/test_orientation.py +1 -1
  43. {optv-0.2.6 → optv-0.2.9}/test/test_parameters_bindings.py +120 -120
  44. {optv-0.2.6 → optv-0.2.9}/test/test_segmentation.py +20 -1
  45. {optv-0.2.6 → optv-0.2.9}/test/test_tracker.py +30 -20
  46. {optv-0.2.6 → optv-0.2.9}/test/test_trafo_bindings.py +1 -1
  47. optv-0.2.6/PKG-INFO +0 -10
  48. optv-0.2.6/optv.egg-info/PKG-INFO +0 -10
  49. optv-0.2.6/optv.egg-info/requires.txt +0 -2
  50. {optv-0.2.6 → optv-0.2.9}/README.txt +0 -0
  51. {optv-0.2.6 → optv-0.2.9}/liboptv/include/optv/calibration.h +0 -0
  52. {optv-0.2.6 → optv-0.2.9}/liboptv/include/optv/correspondences.h +0 -0
  53. {optv-0.2.6 → optv-0.2.9}/liboptv/include/optv/epi.h +0 -0
  54. {optv-0.2.6 → optv-0.2.9}/liboptv/include/optv/image_processing.h +0 -0
  55. {optv-0.2.6 → optv-0.2.9}/liboptv/include/optv/imgcoord.h +0 -0
  56. {optv-0.2.6 → optv-0.2.9}/liboptv/include/optv/lsqadj.h +0 -0
  57. {optv-0.2.6 → optv-0.2.9}/liboptv/include/optv/multimed.h +0 -0
  58. {optv-0.2.6 → optv-0.2.9}/liboptv/include/optv/orientation.h +0 -0
  59. {optv-0.2.6 → optv-0.2.9}/liboptv/include/optv/parameters.h +0 -0
  60. {optv-0.2.6 → optv-0.2.9}/liboptv/include/optv/ray_tracing.h +0 -0
  61. {optv-0.2.6 → optv-0.2.9}/liboptv/include/optv/segmentation.h +0 -0
  62. {optv-0.2.6 → optv-0.2.9}/liboptv/include/optv/sortgrid.h +0 -0
  63. {optv-0.2.6 → optv-0.2.9}/liboptv/include/optv/trafo.h +0 -0
  64. {optv-0.2.6 → optv-0.2.9}/liboptv/include/optv/vec_utils.h +0 -0
  65. {optv-0.2.6 → optv-0.2.9}/liboptv/src/calibration.c +0 -0
  66. {optv-0.2.6 → optv-0.2.9}/liboptv/src/correspondences.c +0 -0
  67. {optv-0.2.6 → optv-0.2.9}/liboptv/src/image_processing.c +0 -0
  68. {optv-0.2.6 → optv-0.2.9}/liboptv/src/imgcoord.c +0 -0
  69. {optv-0.2.6 → optv-0.2.9}/liboptv/src/lsqadj.c +0 -0
  70. {optv-0.2.6 → optv-0.2.9}/liboptv/src/multimed.c +0 -0
  71. {optv-0.2.6 → optv-0.2.9}/liboptv/src/orientation.c +0 -0
  72. {optv-0.2.6 → optv-0.2.9}/liboptv/src/parameters.c +0 -0
  73. {optv-0.2.6 → optv-0.2.9}/liboptv/src/ray_tracing.c +0 -0
  74. {optv-0.2.6 → optv-0.2.9}/liboptv/src/sortgrid.c +0 -0
  75. {optv-0.2.6 → optv-0.2.9}/liboptv/src/trafo.c +0 -0
  76. {optv-0.2.6 → optv-0.2.9}/liboptv/src/vec_utils.c +0 -0
  77. {optv-0.2.6 → optv-0.2.9}/optv/__init__.py +0 -0
  78. {optv-0.2.6 → optv-0.2.9}/optv.egg-info/dependency_links.txt +0 -0
  79. {optv-0.2.6 → optv-0.2.9}/optv.egg-info/top_level.txt +0 -0
  80. {optv-0.2.6 → optv-0.2.9}/setup.cfg +0 -0
  81. {optv-0.2.6 → optv-0.2.9}/test/test_calibration_binding.py +0 -0
  82. {optv-0.2.6 → optv-0.2.9}/test/test_image_processing.py +0 -0
  83. {optv-0.2.6 → optv-0.2.9}/test/test_img_coord.py +0 -0
optv-0.2.9/PKG-INFO ADDED
@@ -0,0 +1,10 @@
1
+ Metadata-Version: 2.1
2
+ Name: optv
3
+ Version: 0.2.9
4
+ Summary: UNKNOWN
5
+ Home-page: UNKNOWN
6
+ License: UNKNOWN
7
+ Platform: UNKNOWN
8
+
9
+ UNKNOWN
10
+
@@ -36,8 +36,8 @@ foundpix;
36
36
 
37
37
  int candsearch_in_pix(target next[], int num_targets, double x, double y,
38
38
  double dl, double dr, double du, double dd, int p[4], control_par *cpar);
39
- int candsearch_in_pixrest(target next[], int num_targets, double x, double y,
40
- double dl, double dr, double du, double dd, int p[4], control_par *cpar);
39
+ int candsearch_in_pix_rest(target next[], int num_targets, double x, double y,
40
+ double dl, double dr, double du, double dd, int p[], control_par *cpar);
41
41
  int sort_candidates_by_freq (foundpix item[16], int num_cams);
42
42
  void searchquader(vec3d point, double xr[4], double xl[4], double yd[4], \
43
43
  double yu[4], track_par *tpar, control_par *cpar, Calibration **cal);
@@ -82,11 +82,72 @@ int write_frame(frame *self, char *corres_file_base, char *linkage_file_base,
82
82
  char *prio_file_base, char **target_file_base, int frame_num);
83
83
 
84
84
 
85
+ /*
86
+ * Following is the frame buffer class, that holds a given number of frame structs,
87
+ * and treats them as a deque (doube-ended queue, a queue that can advance forward
88
+ * or backward).
89
+ *
90
+ * The memory locations are advanced with fb_next()/fb_prev(). Filling out the new
91
+ * frame that joined the queue and flushing out the frame that exited the queue
92
+ * are respectively done using fb_read_frame_at_end() and fb_write_frame_from_start().
93
+ *
94
+ * To make it possible to read frames from different sources, we use a
95
+ * base-class/child-class structure. framebuf_base is the base class, and implements
96
+ * only the memory-advance methods. The filling-out of frames is done by
97
+ * "virtual" functions. That is to say, fb_read_frame_at_end, for example,
98
+ * only forwards the call to a function that really reads the data.
99
+ *
100
+ * The virtual functions are placed in the "vtable" by the constructor - the
101
+ * function that allocates and populates the child class.
102
+ *
103
+ * In tracking_framebuf.c and here there's an example child-class that reads
104
+ * frame information from *_target files. This is the original mode of
105
+ * liboptv. The struct framebuf *inherits* from framebuf_base (by incorporating
106
+ * the base as 1st member - the order is important). fb_init(), the constructor,
107
+ * then populates the vtable with fb_disk_* functions. These are the derived
108
+ * implementations of the base-class virtual functions.
109
+ *
110
+ * There is also a virtual destructor, fb_free(), which delegates to the free()
111
+ * virtual function, and implemented in the example by fb_disk_free().
112
+ *
113
+ * Note: fb_disk_free does not release the strings it holds, as I don't remember if
114
+ * it owns them.
115
+ *
116
+ * Yes, in C++ it's easier :)
117
+ */
118
+
119
+ // Virtual function table definitions for frame buffer objects:
120
+ typedef struct framebuf_base* fbp;
85
121
  typedef struct {
122
+ void (*free)(fbp self);
123
+ int (*read_frame_at_end)(fbp self, int frame_num, int read_links);
124
+ int (*write_frame_from_start)(fbp self, int frame_num);
125
+ } fb_vtable;
126
+
127
+ typedef struct framebuf_base {
128
+ fb_vtable *_vptr;
129
+
86
130
  /* _ring_vec is the underlying double-size vector, buf is the pointer to
87
131
  the start of the ring. */
88
132
  frame **buf, **_ring_vec;
89
133
  int buf_len, num_cams;
134
+ } framebuf_base;
135
+
136
+ // These just call the corresponding virtual function.
137
+ // Actual implementations are below each child class.
138
+ void fb_free(framebuf_base *self);
139
+ int fb_read_frame_at_end(framebuf_base *self, int frame_num, int read_links);
140
+ int fb_write_frame_from_start(framebuf_base *self, int frame_num);
141
+
142
+ // Non-virtual methods of the base class.
143
+ void fb_base_init(framebuf_base *new_buf, int buf_len, int num_cams, int max_targets);
144
+ void fb_next(framebuf_base *self);
145
+ void fb_prev(framebuf_base *self);
146
+
147
+ // child class that reads from _target files.
148
+ typedef struct {
149
+ framebuf_base base; // must be 1st member.
150
+
90
151
  char *corres_file_base, *linkage_file_base, *prio_file_base;
91
152
  char **target_file_base;
92
153
  } framebuf;
@@ -94,10 +155,9 @@ typedef struct {
94
155
  void fb_init(framebuf *new_buf, int buf_len, int num_cams, int max_targets,\
95
156
  char *corres_file_base, char* linkage_file_base, char *prio_file_base,
96
157
  char **target_file_base);
97
- void fb_free(framebuf *self);
98
- void fb_next(framebuf *self);
99
- void fb_prev(framebuf *self);
100
- int fb_read_frame_at_end(framebuf *self, int frame_num, int read_links);
101
- int fb_write_frame_from_start(framebuf *self, int frame_num);
158
+
159
+ void fb_disk_free(framebuf_base *self);
160
+ int fb_disk_read_frame_at_end(framebuf_base *self, int frame_num, int read_links);
161
+ int fb_disk_write_frame_from_start(framebuf_base *self, int frame_num);
102
162
 
103
163
  #endif
@@ -12,7 +12,7 @@
12
12
  #include "tracking_frame_buf.h"
13
13
 
14
14
  typedef struct {
15
- framebuf *fb;
15
+ framebuf_base *fb;
16
16
  sequence_par *seq_par;
17
17
  track_par *tpar;
18
18
  volume_par *vpar;
@@ -201,6 +201,11 @@ int find_candidate (coord_2d *crd, target *pix, int num,
201
201
  continue;
202
202
 
203
203
  p2 = crd[j].pnr;
204
+
205
+ if (p2 >= num) {
206
+ printf("pnr out of range: %d\n", p2);
207
+ return -1;
208
+ }
204
209
 
205
210
  /* quality of each parameter is a ratio of the values of the
206
211
  size n, nx, ny and sum of grey values sumg */
@@ -65,10 +65,14 @@ int targ_rec (unsigned char *img, target_par *targ_par, int xmin,
65
65
  thres = targ_par->gvthres[num_cam];
66
66
  disco = targ_par->discont;
67
67
 
68
+ // printf("thres %d disco %d \n", thres, disco);
69
+
68
70
  /* copy image to a temporary mask */
69
71
  img0 = (unsigned char *) calloc (imx*imy, 1);
70
72
  memcpy(img0, img, imx*imy);
71
73
 
74
+ // printf("in segmentation.c memcpy succeded\n");
75
+
72
76
  /* Make sure the min/max coordinates don't cause us to access memory
73
77
  outside the image memory.
74
78
  */
@@ -191,10 +195,24 @@ int targ_rec (unsigned char *img, target_par *targ_par, int xmin,
191
195
 
192
196
  xn = x;
193
197
  yn = y;
198
+ // printf("%d %d %d \n",n_targets, xn, yn);
194
199
  }
195
200
  } /* end of if-loop */
196
201
  }
197
202
  free(img0);
203
+ /* protect pix from zero memory */
204
+ if (n_targets < 1){
205
+ pix[0].n = 1;
206
+ pix[0].nx = 1;
207
+ pix[0].ny = 1;
208
+ pix[0].sumg = 1;
209
+ pix[0].x = 1;
210
+ pix[0].y = 1;
211
+ pix[0].tnr = CORRES_NONE;
212
+ pix[0].pnr = 1;
213
+ n_targets++;
214
+ }
215
+ // printf("final n_targets %d\n",n_targets);
198
216
  return(n_targets);
199
217
  }
200
218
 
@@ -30,6 +30,9 @@
30
30
  #include "track.h"
31
31
  #include <stdlib.h>
32
32
  #include <stdio.h>
33
+ #define _USE_MATH_DEFINES
34
+ #include <math.h>
35
+
33
36
 
34
37
  /* internal-use defines, not needed by the outside world. */
35
38
  #define TR_UNUSED -1
@@ -257,7 +260,7 @@ int candsearch_in_pix (target next[], int num_targets, double cent_x, double cen
257
260
 
258
261
  j0 -= 12; if (j0 < 0) j0 = 0; /* due to trunc */
259
262
  for (j = j0; j<num_targets; j++) { /* candidate search */
260
- if (next[j].tnr != -1 ) {
263
+ if (next[j].tnr != TR_UNUSED ) {
261
264
  if (next[j].y > ymax ) break; /* finish search */
262
265
  if (next[j].x > xmin && next[j].x < xmax \
263
266
  && next[j].y > ymin && next[j].y < ymax) {
@@ -299,6 +302,74 @@ int candsearch_in_pix (target next[], int num_targets, double cent_x, double cen
299
302
  return (counter);
300
303
  }
301
304
 
305
+ /* candsearch_in_pix_rest searches for a nearest candidate in unmatched target list
306
+ *
307
+ * Arguments:
308
+ * target next[] - array of targets (pointer, x,y, n, nx,ny, sumg, track ID),
309
+ * assumed to be y sorted.
310
+ * int num_targets - target array length.
311
+ * double cent_x, cent_y - image coordinates of the position of a particle [pixel]
312
+ * double dl, dr, du, dd - respectively the left, right, up, down distance to
313
+ * the search area borders from its center, [pixel]
314
+ * int p[] - indices in ``next`` of the candidates found.
315
+ * control_par *cpar array of parameters (cpar->imx,imy are needed)
316
+ *
317
+ * Returns:
318
+ * int, the number of candidates found, between 0 - 1
319
+ */
320
+
321
+ int candsearch_in_pix_rest (target next[], int num_targets, double cent_x, double cent_y,
322
+ double dl, double dr, double du, double dd, int p[], control_par *cpar) {
323
+
324
+ int j, j0, dj;
325
+ int counter = 0;
326
+ double d, dmin = 1e20, xmin, xmax, ymin, ymax;
327
+ // double d1, d2, d3, d4;
328
+
329
+ xmin = cent_x - dl; xmax = cent_x + dr; ymin = cent_y - du; ymax = cent_y + dd;
330
+
331
+ if(xmin<0.0) xmin = 0.0;
332
+ if(xmax > cpar->imx)
333
+ xmax = cpar->imx;
334
+ if(ymin<0.0) ymin = 0.0;
335
+ if(ymax > cpar->imy)
336
+ ymax = cpar->imy;
337
+
338
+ p[0] = PT_UNUSED;
339
+
340
+ if (cent_x >= 0.0 && cent_x <= cpar->imx ) {
341
+ if (cent_y >= 0.0 && cent_y <= cpar->imy ) {
342
+
343
+ /* binarized search for start point of candidate search */
344
+ for (j0 = num_targets/2, dj = num_targets/4; dj>1; dj /= 2)
345
+ {
346
+ if (next[j0].y < ymin) j0 += dj;
347
+ else j0 -= dj;
348
+ }
349
+
350
+ j0 -= 12; if (j0 < 0) j0 = 0; /* due to trunc */
351
+ for (j = j0; j<num_targets; j++) { /* candidate search */
352
+ if (next[j].tnr == TR_UNUSED ) {
353
+ if (next[j].y > ymax ) break; /* finish search */
354
+ if (next[j].x > xmin && next[j].x < xmax \
355
+ && next[j].y > ymin && next[j].y < ymax) {
356
+ d = sqrt ((cent_x-next[j].x)*(cent_x-next[j].x) + \
357
+ (cent_y-next[j].y)*(cent_y-next[j].y));
358
+
359
+ if (d < dmin) {
360
+ dmin = d;
361
+ p[0] = j;
362
+ }
363
+ }
364
+ }
365
+ }
366
+
367
+ if ( p[0] != PT_UNUSED ) counter++;
368
+ } /* if y is within the image boundaries */
369
+ } /* if x is within the image boundaries */
370
+ return (counter);
371
+ }
372
+
302
373
  /* searchquader defines the search region, using tracking parameters
303
374
  * dvxmin, ... dvzmax (but within the image boundaries), per camera
304
375
  * Its primary objective is to provide a safe search region in each camera
@@ -568,14 +639,20 @@ int assess_new_position(vec3d pos, vec2d targ_pos[],
568
639
  double right, left, down, up; /* search rectangle limits */
569
640
 
570
641
  left = right = up = down = ADD_PART;
642
+
643
+ for (cam = 0; cam < TR_MAX_CAMS; cam++) {
644
+ targ_pos[cam][0] = targ_pos[cam][1] = COORD_UNUSED;
645
+ }
646
+
571
647
  for (cam = 0; cam < run->cpar->num_cams; cam++) {
572
648
  point_to_pixel(pixel, pos, run->cal[cam], run->cpar);
573
- targ_pos[cam][0] = targ_pos[cam][1] = COORD_UNUSED;
574
649
 
575
650
  /* here we shall use only the 1st neigbhour */
576
- num_cands = candsearch_in_pix (frm->targets[cam], frm->num_targets[cam],
651
+ num_cands = candsearch_in_pix_rest (frm->targets[cam], frm->num_targets[cam],
577
652
  pixel[0], pixel[1], left, right, up, down,
578
653
  cand_inds[cam], run->cpar);
654
+
655
+ // printf("num_cands after pix_rest is %d\n",num_cands);
579
656
 
580
657
  if (num_cands > 0) {
581
658
  _ix = cand_inds[cam][0]; // first nearest neighbour
@@ -678,7 +755,7 @@ void trackcorr_c_loop (tracking_run *run_info, int step) {
678
755
 
679
756
  /* Shortcuts into the tracking_run struct */
680
757
  Calibration **cal;
681
- framebuf *fb;
758
+ framebuf_base *fb;
682
759
  track_par *tpar;
683
760
  volume_par *vpar;
684
761
  control_par *cpar;
@@ -719,7 +796,7 @@ void trackcorr_c_loop (tracking_run *run_info, int step) {
719
796
  } else {
720
797
  vec_copy(X[2], X[1]);
721
798
  for (j = 0; j < fb->num_cams; j++) {
722
- if (curr_corres->p[j] == -1) {
799
+ if (curr_corres->p[j] == CORRES_NONE) {
723
800
  point_to_pixel (v1[j], X[2], cal[j], cpar);
724
801
  } else {
725
802
  _ix = curr_corres->p[j];
@@ -999,7 +1076,7 @@ double trackback_c (tracking_run *run_info)
999
1076
  track_par *tpar;
1000
1077
  volume_par *vpar;
1001
1078
  control_par *cpar;
1002
- framebuf *fb;
1079
+ framebuf_base *fb;
1003
1080
  Calibration **cal;
1004
1081
 
1005
1082
  /* Shortcuts to inside current frame */
@@ -1023,8 +1100,8 @@ double trackback_c (tracking_run *run_info)
1023
1100
 
1024
1101
  /* sequence loop */
1025
1102
  for (step = seq_par->last - 1; step > seq_par->first; step--) {
1026
- printf ("Time step: %d, seqnr: %d:\n",
1027
- step - seq_par->first, step);
1103
+ // printf ("Time step: %d, seqnr: %d:\n",
1104
+ // step - seq_par->first, step);
1028
1105
 
1029
1106
  for (h = 0; h < fb->buf[1]->num_parts; h++) {
1030
1107
  curr_path_inf = &(fb->buf[1]->path_info[h]);
@@ -1170,7 +1247,8 @@ double trackback_c (tracking_run *run_info)
1170
1247
  if (curr_path_inf->prev != PREV_NONE ) count1++;
1171
1248
  } /* end of creation of links with decision check */
1172
1249
 
1173
- printf ("step: %d, curr: %d, next: %d, links: %d, lost: %d, add: %d",
1250
+
1251
+ printf ("step: %d, curr: %d, next: %d, links: %d, lost: %d, add: %d \n",
1174
1252
  step, fb->buf[1]->num_parts, fb->buf[2]->num_parts, count1,
1175
1253
  fb->buf[1]->num_parts - count1, num_added);
1176
1254
 
@@ -556,33 +556,26 @@ int write_frame(frame *self, char *corres_file_base, char *linkage_file_base,
556
556
  return 1;
557
557
  }
558
558
 
559
- /* fb_init() allocates a frame buffer object and creates the frames
560
- * it buffers. The buffer is a ring-buffer based on a double-size vector.
561
- *
562
- * Arguments:
563
- * int buf_len - number of frames in the buffer.
564
- * int num_cams - number of cameras per frame.
565
- * int max_targets - number of elements to allocate for the different buffers
566
- * held by a frame.
567
- * char *rt_file_base
568
- *
569
- * Returns:
570
- * a pointer to the new dynamically allocated frame-buffer structure.
571
- */
559
+ // ----- Virtual functions redirection
572
560
 
573
- void fb_init(framebuf *new_buf, int buf_len, int num_cams, int max_targets,\
574
- char *corres_file_base, char *linkage_file_base, char *prio_file_base,
575
- char **target_file_base)
576
- {
561
+ void fb_free(framebuf_base *self) {
562
+ self->_vptr->free(self);
563
+ }
564
+
565
+ int fb_read_frame_at_end(framebuf_base *self, int frame_num, int read_links) {
566
+ return self->_vptr->read_frame_at_end(self, frame_num, read_links);
567
+ }
568
+
569
+ int fb_write_frame_from_start(framebuf_base *self, int frame_num) {
570
+ return self->_vptr->write_frame_from_start(self, frame_num);
571
+ }
572
+
573
+ void fb_base_init(framebuf_base *new_buf, int buf_len, int num_cams, int max_targets) {
577
574
  frame *alloc_frame;
578
-
575
+
579
576
  new_buf->buf_len = buf_len;
580
577
  new_buf->num_cams = num_cams;
581
- new_buf->corres_file_base = corres_file_base;
582
- new_buf->linkage_file_base = linkage_file_base;
583
- new_buf->prio_file_base = prio_file_base;
584
- new_buf->target_file_base = target_file_base;
585
-
578
+
586
579
  new_buf->_ring_vec = (frame **) calloc(buf_len*2, sizeof(frame *));
587
580
  new_buf->buf = new_buf->_ring_vec + buf_len;
588
581
 
@@ -600,15 +593,11 @@ void fb_init(framebuf *new_buf, int buf_len, int num_cams, int max_targets,\
600
593
  }
601
594
  /* Leaves new_buf->buf pointing to the beginning of _ring_vec,
602
595
  which is what we want. */
596
+
597
+ new_buf->_vptr = (fb_vtable*) malloc(sizeof(fb_vtable));
603
598
  }
604
599
 
605
- /* fb_free() frees all memory allocated for the frames and ring vector in a
606
- * framebuf object.
607
- *
608
- * Arguments:
609
- * framebuf *self - the framebuf holding the memory to free.
610
- */
611
- void fb_free(framebuf *self) {
600
+ void fb_base_free(framebuf_base *self) {
612
601
  self->buf = self->_ring_vec;
613
602
 
614
603
  while (self->buf != self->_ring_vec + self->buf_len) {
@@ -620,6 +609,53 @@ void fb_free(framebuf *self) {
620
609
 
621
610
  free(self->_ring_vec);
622
611
  self->_ring_vec = NULL;
612
+
613
+ free(self->_vptr);
614
+ self->_vptr = NULL;
615
+ }
616
+
617
+ // -------- Specific Implementations of virtual functions.
618
+
619
+ /* fb_init() allocates a frame buffer object and creates the frames
620
+ * it buffers. The buffer is a ring-buffer based on a double-size vector.
621
+ *
622
+ * Arguments:
623
+ * int buf_len - number of frames in the buffer.
624
+ * int num_cams - number of cameras per frame.
625
+ * int max_targets - number of elements to allocate for the different buffers
626
+ * held by a frame.
627
+ * char *rt_file_base
628
+ *
629
+ * Returns:
630
+ * a pointer to the new dynamically allocated frame-buffer structure.
631
+ */
632
+
633
+ void fb_init(framebuf *new_buf, int buf_len, int num_cams, int max_targets,\
634
+ char *corres_file_base, char *linkage_file_base, char *prio_file_base,
635
+ char **target_file_base)
636
+ {
637
+ fb_base_init(&new_buf->base, buf_len, num_cams, max_targets);
638
+
639
+ // Subclass-specific parameters:
640
+ new_buf->corres_file_base = corres_file_base;
641
+ new_buf->linkage_file_base = linkage_file_base;
642
+ new_buf->prio_file_base = prio_file_base;
643
+ new_buf->target_file_base = target_file_base;
644
+
645
+ // Set up the virtual functions table:
646
+ new_buf->base._vptr->free = fb_disk_free;
647
+ new_buf->base._vptr->read_frame_at_end = fb_disk_read_frame_at_end;
648
+ new_buf->base._vptr->write_frame_from_start = fb_disk_write_frame_from_start;
649
+ }
650
+
651
+ /* fb_free() frees all memory allocated for the frames and ring vector in a
652
+ * framebuf object.
653
+ *
654
+ * Arguments:
655
+ * framebuf *self - the framebuf holding the memory to free.
656
+ */
657
+ void fb_disk_free(framebuf_base *self_base) {
658
+ fb_base_free(self_base);
623
659
  }
624
660
 
625
661
  /* fb_next() advances the start pointer of the frame buffer, resetting it to the
@@ -628,7 +664,7 @@ void fb_free(framebuf *self) {
628
664
  * Arguments:
629
665
  * framebuf *self - the framebuf to advance.
630
666
  */
631
- void fb_next(framebuf *self) {
667
+ void fb_next(framebuf_base *self) {
632
668
  self->buf++;
633
669
  if (self->buf - self->_ring_vec >= self->buf_len)
634
670
  self->buf = self->_ring_vec;
@@ -640,7 +676,7 @@ void fb_next(framebuf *self) {
640
676
  * Arguments:
641
677
  * framebuf *self - the framebuf to advance.
642
678
  */
643
- void fb_prev(framebuf *self) {
679
+ void fb_prev(framebuf_base *self) {
644
680
  self->buf--;
645
681
  if (self->buf < self->_ring_vec)
646
682
  self->buf = self->_ring_vec + self->buf_len - 1;
@@ -656,13 +692,15 @@ void fb_prev(framebuf *self) {
656
692
  * Returns:
657
693
  * True on success, false on failure.
658
694
  */
659
- int fb_read_frame_at_end(framebuf *self, int frame_num, int read_links) {
695
+ int fb_disk_read_frame_at_end(framebuf_base *self_base, int frame_num, int read_links) {
696
+ framebuf* self = (framebuf*)self_base;
697
+
660
698
  if (read_links) {
661
- return read_frame(self->buf[self->buf_len - 1], self->corres_file_base,
699
+ return read_frame(self->base.buf[self->base.buf_len - 1], self->corres_file_base,
662
700
  self->linkage_file_base, self->prio_file_base,
663
701
  self->target_file_base, frame_num);
664
702
  } else {
665
- return read_frame(self->buf[self->buf_len - 1], self->corres_file_base,
703
+ return read_frame(self->base.buf[self->base.buf_len - 1], self->corres_file_base,
666
704
  NULL, NULL, self->target_file_base, frame_num);
667
705
  }
668
706
  }
@@ -670,14 +708,16 @@ int fb_read_frame_at_end(framebuf *self, int frame_num, int read_links) {
670
708
  /* fb_write_frame_from_start() writes the frame to the first position in the ring.
671
709
  *
672
710
  * Arguments:
673
- * framebuf *self - the framebuf object doing the reading.
711
+ * *self - the framebuf object doing the reading.
674
712
  * int frame_num - number of the frame to write in the sequence of frames.
675
713
  *
676
714
  * Returns:
677
715
  * True on success, false on failure.
678
716
  */
679
- int fb_write_frame_from_start(framebuf *self, int frame_num) {
680
- return write_frame(self->buf[0], self->corres_file_base,
717
+ int fb_disk_write_frame_from_start(framebuf_base *self_base, int frame_num) {
718
+ framebuf* self = (framebuf*)self_base;
719
+
720
+ return write_frame(self->base.buf[0], self->corres_file_base,
681
721
  self->linkage_file_base, self->prio_file_base, self->target_file_base,
682
722
  frame_num);
683
723
  }
@@ -60,8 +60,8 @@ tracking_run *tr_new(sequence_par *seq_par, track_par *tpar,
60
60
  tr->cal = cal;
61
61
  tr->flatten_tol = flatten_tol;
62
62
 
63
- tr->fb = (framebuf *) malloc(sizeof(framebuf));
64
- fb_init(tr->fb, buf_len, cpar->num_cams, max_targets,
63
+ tr->fb = (framebuf_base*) malloc(sizeof(framebuf));
64
+ fb_init((framebuf*)tr->fb, buf_len, cpar->num_cams, max_targets,
65
65
  corres_file_base, linkage_file_base, prio_file_base, seq_par->img_base_name);
66
66
 
67
67
  tr->lmax = norm((tpar->dvxmin - tpar->dvxmax), \