1 // This is prip/vdtop/vdtop_neighborhood.h
2 #ifndef vdtop_neighborhood_h_
3 #define vdtop_neighborhood_h_
4 //:
5 // \file
6 // \brief Provides vdtop_pixel neighborhoods class. Can be yet enhanced.
7 // \author Jocelyn Marchadier
8 // \date 06 May 2004
9 //
10 // \verbatim
11 //  Modifications
12 //   06 May 2004 Jocelyn Marchadier
13 // \endverbatim
14 
15 #include <vdtop/vdtop_pixel.h>
16 #include <vdtop/vdtop_freeman_code.h>
17 #include <vil/vil_image_view.h>
18 
19 template <class T>
20 class vdtop_8_neighborhood
21 {
22  public:
23   typedef vdtop_8_neighborhood<T> self_type ;
24   typedef typename vil_image_view<T>::iterator const * const_iterator ;
25 
set_center(vdtop_pixel<T> & pix)26   void set_center(vdtop_pixel<T> & pix)
27   {
28     vil_image_view<T> & img=pix.image() ;
29     std::ptrdiff_t istep=img.istep();
30     std::ptrdiff_t jstep=img.jstep();
31     typename vil_image_view<T>::iterator tmp=pix.position();
32     tmp+=istep ;
33     neighbors_[0]=tmp ;
34     tmp-=jstep ;
35     neighbors_[1]=tmp ;
36     tmp-=istep ;
37     neighbors_[2]=tmp ;
38     tmp-=istep ;
39     neighbors_[3]=tmp ;
40     tmp+=jstep ;
41     neighbors_[4]=tmp ;
42     tmp+=jstep ;
43     neighbors_[5]=tmp ;
44     tmp+=istep ;
45     neighbors_[6]=tmp ;
46     tmp+=istep ;
47     neighbors_[7]=tmp ;
48   }
49 
begin()50   const_iterator begin() const
51   {
52     return neighbors_ ;
53   }
end()54   const_iterator end() const
55   {
56     return neighbors_+8 ;
57   }
58 
neighbor_value(vdtop_freeman_code arg)59   const T& neighbor_value(vdtop_freeman_code arg) const
60   {
61     return *neighbors_[arg.code()] ;
62   }
63 
64  private:
65   typename vil_image_view<T>::iterator neighbors_[8] ;
66 };
67 
68 template <class T>
69 class vdtop_4_neighborhood
70 {
71  public:
72   typedef vdtop_4_neighborhood<T> self_type ;
73   typedef typename vil_image_view<T>::iterator const * const_iterator ;
74 
set_center(vdtop_pixel<T> & pix)75   void set_center(vdtop_pixel<T> & pix)
76   {
77     vil_image_view<T> & img=pix.image() ;
78     typename vil_image_view<T>::iterator tmp=pix.position();
79     std::ptrdiff_t istep=img.istep();
80     std::ptrdiff_t jstep=img.jstep();
81     tmp+=istep ;
82     neighbors_[0]=tmp ;
83     tmp-=jstep ;
84     tmp-=istep ;
85     neighbors_[1]=tmp ;
86     tmp-=istep ;
87     tmp+=jstep ;
88     neighbors_[2]=tmp ;
89     tmp+=istep ;
90     tmp+=jstep ;
91     neighbors_[3]=tmp ;
92   }
93 
begin()94   const_iterator begin() const
95   {
96     return neighbors_ ;
97   }
end()98   const_iterator end() const
99   {
100     return neighbors_+4 ;
101   }
102 
103  private:
104   typename vil_image_view<T>::iterator neighbors_[4] ;
105 };
106 
107 #endif
108