w_window2d.hh

00001 // Copyright (C) 2001, 2002, 2003, 2004  EPITA Research and Development Laboratory
00002 //
00003 // This file is part of the Olena Library.  This library is free
00004 // software; you can redistribute it and/or modify it under the terms
00005 // of the GNU General Public License version 2 as published by the
00006 // Free Software Foundation.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this library; see the file COPYING.  If not, write to
00015 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
00016 // MA 02111-1307, USA.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software library without restriction.  Specifically, if other files
00020 // instantiate templates or use macros or inline functions from this
00021 // file, or you compile this file and link it with other files to
00022 // produce an executable, this file does not by itself cause the
00023 // resulting executable to be covered by the GNU General Public
00024 // License.  This exception does not however invalidate any other
00025 // reasons why the executable file might be covered by the GNU General
00026 // Public License.
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; // forward declaration
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 } // end of oln
00230 
00231 #endif // ! OLENA_CORE_W_WINDOW2D_HH

Generated on Thu Apr 15 20:13:15 2004 for Olena by doxygen 1.3.6-20040222