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_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; // forward declaration
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   // std win
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 } // end of oln
00214 
00215 #endif // OLENA_CORE_WINDOW1D_HH

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