1 // This is brl/bbas/bil/algo/bil_cedt.h
2 #ifndef bil_cedt_h
3 #define bil_cedt_h
4 //:
5 // \file
6 // \brief 2D Contour based Euclidean Distance Transform algorithm
7 // \author Vishal Jain & Huysen Tek Brown University
8 // \date June 16, 2005
9 //
10 
11 #include <vil/vil_image_view.h>
12 #include <vbl/vbl_array_2d.h>
13 
14 //:  2D Contour Euclidean Distance transform
15 class bil_cedt_heap;
16 class bil_cedt_contour;
17 class bil_cedt
18 {
19  public:
20     bil_cedt();
21     ~bil_cedt();
22 
23     bil_cedt(const vil_image_view<unsigned char>& im);
24 
25     bool compute_cedt();
26 
closest_point_x(int i,int j)27     double closest_point_x(int i, int j) const {return dx_(i,j);}
closest_point_y(int i,int j)28     double closest_point_y(int i, int j) const {return dy_(i,j);}
29 
cedtimg()30     vil_image_view<float> cedtimg() const {return dist_;}
31 
32  private:
33     vil_image_view<unsigned char> img_;
34     vbl_array_2d<double> dx_;
35     vbl_array_2d<double> dy_;
36     vil_image_view<float> dist_;
37 
38     int ni_;
39     int nj_;
40 
41     bool  find_dist_trans(vbl_array_2d<double> &level,bil_cedt_heap *heap);
42     void propagate_dist(bil_cedt_contour *pf, bil_cedt_heap *heap, vbl_array_2d<double> &surface,
43                         vbl_array_2d<unsigned char> &tag_array, vbl_array_2d<unsigned char> &dir_array,
44                         int y, int x, int dir);
45     void add_to_contour(bil_cedt_contour *pf, bil_cedt_heap *heap, vbl_array_2d<double> &surface,
46                         vbl_array_2d<unsigned char> &tag_array, vbl_array_2d<unsigned char> &dir_array,
47                         double dist_x, double dist_y, double dist,int y, int x, int dir, int position);
48     void initial_diagonal_propagate(bil_cedt_contour *pf, bil_cedt_heap *heap, vbl_array_2d<double> &surface,
49                                     vbl_array_2d<unsigned char> &tag_array, vbl_array_2d<unsigned char> &dir_array,
50                                     int y, int x, int dir);
51     int initial_direction(int x, int y);
52 };
53 
54 class bil_cedt_heap
55 {
56  public:
57     bil_cedt_heap(int nj,int ni);
58     ~bil_cedt_heap();
59 
60     double* data;
61     int * index;
62     int * rank;
63     int * loc;
64     int * locx;
65     int * locy;
66 
67     int size, end;
68     int N;
69     int ni_;
70     int nj_;
71 
72     void print_heap();
73     void remove_max();
74     void downheap(int k);
75     void insert( int pos, int location, double item);
76     void upheap( int k);
77 };
78 
79 class bil_cedt_contour
80 {
81  public:
82     bil_cedt_contour(int nj,int ni);
83     ~bil_cedt_contour();
84 
85     int * x;
86     int * y;
87     int * dir;
88 
89     int ptr;
90 };
91 
92 #endif // bil_cedt_h
93