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_WINDOW1D_HH
00029 # define OLENA_CORE_WINDOW1D_HH
00030
00031 # include <oln/core/point1d.hh>
00032 # include <oln/core/dpoint1d.hh>
00033 # include <oln/core/abstract/windownd.hh>
00034 # include <oln/core/winiter.hh>
00035 # include <oln/core/accum.hh>
00036 # include <algorithm>
00037
00038 namespace oln {
00039
00040 class window1d;
00041
00045 template<>
00046 struct struct_elt_traits<window1d>: public
00047 struct_elt_traits<abstract::windownd<window1d> >
00048 {
00049 enum { dim = 1 };
00050 typedef point1d point_type;
00051 typedef dpoint1d dpoint_type;
00052 typedef winiter< window1d > iter_type;
00053 typedef winneighb< window1d > neighb_type;
00054 };
00055
00056
00063 class window1d : public abstract::windownd< window1d >
00064 {
00065
00066 public:
00067
00068 typedef abstract::windownd< window1d > super_type;
00070 typedef window1d self_type;
00071
00077 typedef struct_elt_traits< self_type >::iter_type iter_type;
00078
00079 typedef struct_elt_traits< self_type >::neighb_type neighb_type;
00081
00087 typedef struct_elt_traits< self_type >::dpoint_type dpoint_type;
00088
00089 friend class abstract::window_base<abstract::window<window1d>, window1d>;
00090
00098 window1d&
00099 add(const dpoint_type& dp)
00100 {
00101 return this->exact().add_(dp);
00102 }
00103
00112 window1d&
00113 add(coord col)
00114 {
00115 return this->add(dpoint_type(col));
00116 }
00117
00121 window1d() : super_type()
00122 {}
00123
00128 window1d(unsigned size) : super_type(size)
00129 {}
00130
00136 window1d(unsigned n, const coord crd[]) : super_type(n)
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("window1d");
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
00174 inline const window1d&
00175 win_c2_only()
00176 {
00177 static const coord crd[] = { -1, 1 };
00178 static const window1d win(2, crd);
00179 return win;
00180 }
00181
00186 inline const window1d&
00187 win_c2p()
00188 {
00189 static const coord crd[] = { -1, 0, 1 };
00190 static const window1d win(3, crd);
00191 return win;
00192 }
00193
00202 inline window1d
00203 mk_win_segment(unsigned width)
00204 {
00205 precondition(width>= 3 && (width % 2) == 1);
00206 window1d win(width);
00207 int half_ncols = width / 2;
00208 for (coord col = - half_ncols; col <= half_ncols; ++col)
00209 win.add(col);
00210 return win;
00211 }
00212
00213 }
00214
00215 #endif // OLENA_CORE_WINDOW1D_HH