w_window1d.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_WINDOW1D_HH
00029 # define OLENA_CORE_W_WINDOW1D_HH
00030 
00031 # include <ntg/basics.hh>
00032 # include <oln/core/abstract/w_windownd.hh>
00033 # include <oln/core/accum.hh>
00034 # include <oln/core/winiter.hh>
00035 # include <oln/core/winneighb.hh>
00036 # include <oln/core/dpoint1d.hh>
00037 # include <oln/core/window1d.hh>
00038 # include <algorithm>
00039 
00040 namespace oln {
00041 
00042   template<class T>
00043   class w_window1d; // forward declaration
00044 
00048   template<class T>
00049   struct struct_elt_traits<w_window1d<T> >: public
00050   struct_elt_traits<abstract::w_windownd<w_window1d<T> > >
00051   {
00052     enum { dim = 1 }; 
00053     typedef T weight_type; 
00054     typedef point1d point_type; 
00055     typedef dpoint1d dpoint_type; 
00056     typedef winiter< w_window1d<T> > iter_type; 
00057     typedef winneighb< w_window1d<T> > neighb_type; 
00058   };
00059 
00066   template<class T>
00067   class w_window1d : public abstract::w_windownd<w_window1d<T> >
00068   {
00069 
00070     typedef abstract::w_windownd< w_window1d<T> > super_type;
00072 
00073   public:
00074 
00075     typedef w_window1d<T> self_type; 
00076 
00082     typedef typename struct_elt_traits< self_type >::iter_type   iter_type;
00083 
00084     typedef typename struct_elt_traits< self_type >::neighb_type neighb_type;
00086 
00092     typedef typename struct_elt_traits< self_type >::dpoint_type dpoint_type;
00093 
00094     typedef typename struct_elt_traits< self_type >::weight_type weight_type;
00096 
00097     friend class abstract::window_base<abstract::w_window<w_window1d>, w_window1d>;
00098 
00102     w_window1d(): super_type()
00103     {}
00104 
00109     w_window1d(unsigned size) : super_type(size)
00110     {}
00111 
00120     w_window1d<T>&
00121     add(const dpoint_type& dp, const weight_type& w)
00122     {
00123       return this->exact().add_(dp, w);
00124     }
00125 
00135     w_window1d<T>&
00136     add(coord col, const weight_type& weight)
00137     {
00138       return add(dpoint_type(col), weight);
00139     }
00140 
00146     const weight_type&
00147     set(const dpoint_type& dp, const weight_type& weight)
00148     {
00149       return this->exact().set_(dp, weight);
00150     }
00151 
00160     const weight_type&
00161     set(coord col, const weight_type& weight)
00162     {
00163       return set(dpoint_type(col), weight);
00164     }
00165 
00167     static std::string
00168     name()
00169     {
00170       return std::string("w_window1d<") + ntg_name(T) + ">";
00171     }
00172 
00173   protected:
00174 
00183     coord
00184     delta_update_(const dpoint_type& dp)
00185     {
00186       delta_(abs(dp.col()));
00187       return this->delta_;
00188     }
00189 
00190   };
00191 
00198   template<class T>
00199   w_window1d<T>
00200   mk_w_win_from_win(T weight, const window1d& win)
00201   {
00202     w_window1d<T> w_win(win.card());
00203     for (unsigned i = 0; i < win.card(); ++i)
00204       w_win.add(win.dp(i), weight);
00205     return w_win;
00206   }
00207 
00208 } // end of oln
00209 
00210 #endif // ! OLENA_CORE_W_WINDOW1D_HH

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