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_W_WINDOW2D_HH
00029 # define OLENA_CORE_W_WINDOW2D_HH
00030
00031 # include <mlc/array/all.hh>
00032 # include <ntg/basics.hh>
00033 # include <oln/core/abstract/w_windownd.hh>
00034 # include <oln/core/accum.hh>
00035 # include <oln/core/winiter.hh>
00036 # include <oln/core/winneighb.hh>
00037 # include <oln/core/dpoint2d.hh>
00038 # include <oln/core/window2d.hh>
00039 # include <algorithm>
00040
00041 namespace oln {
00042
00043 template<class T>
00044 class w_window2d;
00045
00049 template<class T>
00050 struct struct_elt_traits<w_window2d<T> >: public
00051 struct_elt_traits<abstract::w_windownd<w_window2d<T> > >
00052 {
00053 enum { dim = 2 };
00054 typedef T weight_type;
00055 typedef point2d point_type;
00056 typedef dpoint2d dpoint_type;
00057 typedef winiter< w_window2d<T> > iter_type;
00058 typedef winneighb< w_window2d<T> > neighb_type;
00059 };
00060
00067 template<class T>
00068 class w_window2d : public abstract::w_windownd<w_window2d<T> >
00069 {
00070
00071 typedef abstract::w_windownd< w_window2d<T> > super_type;
00073
00074 public:
00075
00076 typedef w_window2d<T> self_type;
00077
00083 typedef typename struct_elt_traits< self_type >::iter_type iter_type;
00084
00085 typedef typename struct_elt_traits< self_type >::neighb_type neighb_type;
00087
00093 typedef typename struct_elt_traits< self_type >::dpoint_type dpoint_type;
00094
00095 typedef typename struct_elt_traits< self_type >::weight_type weight_type;
00097
00098 friend class abstract::window_base<abstract::w_window<w_window2d>, w_window2d>;
00099
00103 w_window2d(): super_type()
00104 {}
00105
00110 w_window2d(unsigned size) : super_type(size)
00111 {}
00112
00120 template<class I, class T2>
00121 w_window2d(const mlc::array2d<I, T2 >& arr) :
00122 super_type(I::card)
00123 {
00124 unsigned i = 0;
00125 for (coord row = -I::center_row; row <= I::nrows - I::center_row - 1; ++row)
00126 for (coord col = -I::center_col; col <= I::ncols - I::center_col - 1; ++col)
00127 add(row, col, arr[i++]);
00128 }
00129
00140 w_window2d<T>&
00141 add(coord row, coord col, const weight_type& weight)
00142 {
00143 return add(dpoint_type(row, col), weight);
00144 }
00145
00154 w_window2d<T>&
00155 add(const dpoint_type& dp, const weight_type& w)
00156 {
00157 return this->exact().add_(dp, w);
00158 }
00159
00165 const weight_type&
00166 set(const dpoint_type& dp, const weight_type& weight)
00167 {
00168 return this->exact().set_(dp, weight);
00169 }
00170
00180 const weight_type&
00181 set(coord row, coord col, const weight_type& weight)
00182 {
00183 return set(dpoint_type(row, col), weight);
00184 }
00185
00187 static std::string
00188 name()
00189 {
00190 return std::string("w_window2d<") + ntg_name(T) + ">";
00191 }
00192
00193 protected:
00194
00203 coord
00204 delta_update_(const dpoint_type& dp)
00205 {
00206 delta_(abs(dp.row()));
00207 delta_(abs(dp.col()));
00208 return this->delta_;
00209 }
00210
00211 };
00212
00219 template<class T>
00220 w_window2d<T>
00221 mk_w_win_from_win(T weight, const window2d& win)
00222 {
00223 w_window2d<T> w_win(win.card());
00224 for (unsigned i = 0; i < win.card(); ++i)
00225 w_win.add(win.dp(i), weight);
00226 return w_win;
00227 }
00228
00229 }
00230
00231 #endif // ! OLENA_CORE_W_WINDOW2D_HH