00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef OLENA_CORE_NEIGHBORHOOD1D_HH
00029 # define OLENA_CORE_NEIGHBORHOOD1D_HH
00030
00031 # include <oln/core/abstract/neighborhoodnd.hh>
00032 # include <oln/core/winiter.hh>
00033 # include <oln/core/accum.hh>
00034 # include <oln/core/window1d.hh>
00035 # include <algorithm>
00036
00037 namespace oln {
00038
00039 class neighborhood1d;
00040
00044 template<>
00045 struct struct_elt_traits<neighborhood1d>: public
00046 struct_elt_traits<abstract::neighborhoodnd<neighborhood1d> >
00047 {
00048 enum { dim = 1 };
00049 typedef point1d point_type;
00050 typedef dpoint1d dpoint_type;
00051 typedef winiter< neighborhood1d > iter_type;
00052 typedef winneighb< neighborhood1d > neighb_type;
00053 typedef window1d win_type;
00054 };
00055
00064 class neighborhood1d :
00065 public abstract::neighborhoodnd< neighborhood1d >
00066 {
00067 public:
00068
00069 typedef abstract::neighborhoodnd< neighborhood1d > super_type;
00071 typedef neighborhood1d self_type;
00072
00078 typedef struct_elt_traits< self_type >::iter_type iter_type;
00079 typedef struct_elt_traits< self_type >::neighb_type neighb_type;
00080
00086 typedef struct_elt_traits< self_type >::dpoint_type dpoint_type;
00087
00088 friend class abstract::window_base<abstract::neighborhood<neighborhood1d>, neighborhood1d>;
00089
00097 neighborhood1d&
00098 add(const dpoint_type& dp)
00099 {
00100 this->exact().add_(dp);
00101 return this->exact().add_(-dp);
00102 }
00103
00112 neighborhood1d&
00113 add(coord col)
00114 {
00115 return this->add(dpoint_type(col));
00116 }
00117
00121 neighborhood1d() : super_type()
00122 {}
00123
00128 neighborhood1d(unsigned size) : super_type(size)
00129 {}
00130
00136 neighborhood1d(unsigned n, const coord crd[]) : super_type()
00137 {
00138 for (unsigned i = 0; i < n; ++i)
00139 add(dpoint_type(crd[i]));
00140 }
00141
00143 static std::string
00144 name()
00145 {
00146 return std::string("neighborhood1d");
00147 }
00148
00149 protected:
00150
00159 coord
00160 delta_update_(const dpoint_type& dp)
00161 {
00162 delta_(abs(dp.col()));
00163 return delta_;
00164 }
00165
00166 };
00167
00168
00169
00170
00175 inline const neighborhood1d&
00176 neighb_c2()
00177 {
00178 static const coord crd[] = { 1 };
00179 static const neighborhood1d neighb(1, crd);
00180 return neighb;
00181 }
00182
00192 inline neighborhood1d
00193 mk_neighb_segment(unsigned width)
00194 {
00195 precondition(width>= 3 && (width % 2) == 1);
00196 neighborhood1d neighb(width);
00197 int half_ncols = width / 2;
00198 for (coord col = 1; col <= half_ncols; ++col)
00199 neighb.add(col);
00200 return neighb;
00201 }
00202
00208 inline window1d
00209 mk_win_from_neighb(const neighborhood1d& n)
00210 {
00211 window1d win(n.card());
00212 for (unsigned i = 0; i < n.card(); ++i)
00213 win.add(n.dp(i));
00214 return win;
00215 }
00216
00217
00218 }
00219
00220 #endif // OLENA_CORE_NEIGHBORHOOD1D_HH