neighborhood1d.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_NEIGHBORHOOD1D_HH
00029 # define OLENA_CORE_NEIGHBORHOOD1D_HH
00030 
00031 # include <oln/core/abstract/neighborhoodnd.hh>
00032 # include <oln/core/winiter.hh>
00033 # include <oln/core/accum.hh>
00034 # include <oln/core/window1d.hh>
00035 # include <algorithm>
00036 
00037 namespace oln {
00038 
00039   class neighborhood1d; // forward declaration
00040 
00044   template<>
00045   struct struct_elt_traits<neighborhood1d>: public
00046   struct_elt_traits<abstract::neighborhoodnd<neighborhood1d> >
00047   {
00048     enum { dim = 1 }; 
00049     typedef point1d point_type; 
00050     typedef dpoint1d dpoint_type; 
00051     typedef winiter< neighborhood1d > iter_type; 
00052     typedef winneighb< neighborhood1d > neighb_type; 
00053     typedef window1d win_type; 
00054   };
00055 
00064   class neighborhood1d :
00065     public abstract::neighborhoodnd< neighborhood1d >
00066   {
00067   public:
00068 
00069     typedef abstract::neighborhoodnd< neighborhood1d > super_type;
00071     typedef neighborhood1d self_type; 
00072 
00078     typedef struct_elt_traits< self_type >::iter_type   iter_type;
00079     typedef struct_elt_traits< self_type >::neighb_type neighb_type;
00080 
00086     typedef struct_elt_traits< self_type >::dpoint_type dpoint_type;
00087 
00088     friend class abstract::window_base<abstract::neighborhood<neighborhood1d>, neighborhood1d>;
00089 
00097     neighborhood1d&
00098     add(const dpoint_type& dp)
00099     {
00100       this->exact().add_(dp);
00101       return this->exact().add_(-dp);
00102     }
00103 
00112     neighborhood1d&
00113     add(coord col)
00114     {
00115       return this->add(dpoint_type(col));
00116     }
00117 
00121     neighborhood1d() : super_type()
00122     {}
00123 
00128     neighborhood1d(unsigned size) : super_type(size)
00129     {}
00130 
00136     neighborhood1d(unsigned n, const coord crd[]) : super_type()
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("neighborhood1d");
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   // standard neighborhood
00170 
00175   inline const neighborhood1d&
00176   neighb_c2()
00177   {
00178     static const coord crd[] = {  1 };
00179     static const neighborhood1d neighb(1, crd);
00180     return neighb;
00181   }
00182 
00192   inline neighborhood1d
00193   mk_neighb_segment(unsigned width)
00194   {
00195     precondition(width>= 3 && (width % 2) == 1);
00196     neighborhood1d neighb(width);
00197     int half_ncols = width / 2;
00198     for (coord col = 1; col <= half_ncols; ++col)
00199         neighb.add(col);
00200     return neighb;
00201   }
00202 
00208   inline window1d
00209   mk_win_from_neighb(const neighborhood1d& n)
00210   {
00211     window1d win(n.card());
00212     for (unsigned i = 0; i < n.card(); ++i)
00213       win.add(n.dp(i));
00214     return win;
00215   }
00216 
00217 
00218 } // end of oln
00219 
00220 #endif // OLENA_CORE_NEIGHBORHOOD1D_HH

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