• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

is_simple_2d.hh

00001 // Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE)
00002 //
00003 // This file is part of Olena.
00004 //
00005 // Olena is free software: you can redistribute it and/or modify it under
00006 // the terms of the GNU General Public License as published by the Free
00007 // Software Foundation, version 2 of the License.
00008 //
00009 // Olena is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 // As a special exception, you may use this file as part of a free
00018 // software project without restriction.  Specifically, if other files
00019 // instantiate templates or use macros or inline functions from this
00020 // file, or you compile this file and link it with other files to produce
00021 // an executable, this file does not by itself cause the resulting
00022 // executable to be covered by the GNU General Public License.  This
00023 // exception does not however invalidate any other reasons why the
00024 // executable file might be covered by the GNU General Public License.
00025 
00026 #ifndef MLN_TOPO_IS_SIMPLE_2D_HH
00027 # define MLN_TOPO_IS_SIMPLE_2D_HH
00028 
00033 
00034 #include <mln/core/concept/image.hh>
00035 #include <mln/core/concept/neighborhood.hh>
00036 
00037 #include <mln/core/alias/point2d.hh>
00038 #include <mln/core/alias/neighb2d.hh>
00039 
00040 
00041 namespace mln
00042 {
00043 
00056 
00057   template<typename I, typename N>
00058   bool
00059   is_simple_2d(const Image<I>& ima, const Neighborhood<N>& nbh, const mln_psite(I)& p);
00060 
00061 
00062 
00063   struct is_simple_2d_t
00064   {
00065     template<typename I, typename N>
00066     bool operator()(const Image<I>& ima,
00067                     const Neighborhood<N>& nbh,
00068                     const mln_psite(I)& p) const
00069     {
00070       return is_simple_2d(ima, nbh, p);
00071     }
00072   };
00073 
00074 
00075 
00076 # ifndef MLN_INCLUDE_ONLY
00077 
00078   static const unsigned char connectivity_number_c8[256] =
00079     {
00080       0,  1,  1,  1,   1,  2,  1,  1,   1,  1,  1,  1,   2,  2,  1,  1,
00081       1,  2,  1,  1,   1,  2,  1,  1,   2,  2,  1,  1,   2,  2,  1,  1,
00082       1,  2,  2,  2,   2,  3,  2,  2,   1,  1,  1,  1,   2,  2,  1,  1,
00083       2,  3,  2,  2,   2,  3,  2,  2,   2,  2,  1,  1,   2,  2,  1,  1,
00084 
00085       1,  2,  2,  2,   2,  3,  2,  2,   1,  1,  1,  1,   2,  2,  1,  1,
00086       1,  2,  1,  1,   1,  2,  1,  1,   1,  1,  1,  1,   1,  1,  1,  1,
00087       1,  2,  2,  2,   2,  3,  2,  2,   1,  1,  1,  1,   2,  2,  1,  1,
00088       1,  2,  1,  1,   1,  2,  1,  1,   1,  1,  1,  1,   1,  1,  1,  1,
00089 
00090       1,  2,  2,  2,   2,  3,  2,  2,   2,  2,  2,  2,   3,  3,  2,  2,
00091       1,  2,  1,  1,   1,  2,  1,  1,   2,  2,  1,  1,   2,  2,  1,  1,
00092       2,  3,  3,  3,   3,  4,  3,  3,   2,  2,  2,  2,   3,  3,  2,  2,
00093       2,  3,  2,  2,   2,  3,  2,  2,   2,  2,  1,  1,   2,  2,  1,  1,
00094 
00095       1,  2,  2,  2,   2,  3,  2,  2,   1,  1,  1,  1,   2,  2,  1,  1,
00096       1,  2,  1,  1,   1,  2,  1,  1,   1,  1,  1,  1,   1,  1,  1,  1,
00097       1,  2,  2,  2,   2,  3,  2,  2,   1,  1,  1,  1,   2,  2,  1,  1,
00098       1,  2,  1,  1,   1,  2,  1,  1,   1,  1,  1,  1,   1,  1,  1,  1
00099     };
00100 
00101 
00102   static const unsigned char connectivity_number_c4[256] =
00103     {
00104       0,  0,  1,  1,   0,  0,  1,  1,   1,  1,  2,  1,   1,  1,  2,  1,  
00105       1,  1,  2,  2,   1,  1,  1,  1,   2,  2,  3,  2,   2,  2,  2,  1,  
00106       0,  0,  1,  1,   0,  0,  1,  1,   1,  1,  2,  1,   1,  1,  2,  1,  
00107       1,  1,  2,  2,   1,  1,  1,  1,   2,  2,  3,  2,   2,  2,  2,  1,  
00108 
00109       1,  1,  2,  2,   1,  1,  2,  2,   2,  2,  3,  2,   2,  2,  3,  2,  
00110       2,  2,  3,  3,   2,  2,  2,  2,   3,  3,  4,  3,   3,  3,  3,  2,  
00111       1,  1,  2,  2,   1,  1,  2,  2,   1,  1,  2,  1,   1,  1,  2,  1,  
00112       2,  2,  3,  3,   2,  2,  2,  2,   2,  2,  3,  2,   2,  2,  2,  1,  
00113 
00114       0,  0,  1,  1,   0,  0,  1,  1,   1,  1,  2,  1,   1,  1,  2,  1,  
00115       1,  1,  2,  2,   1,  1,  1,  1,   2,  2,  3,  2,   2,  2,  2,  1,  
00116       0,  0,  1,  1,   0,  0,  1,  1,   1,  1,  2,  1,   1,  1,  2,  1,  
00117       1,  1,  2,  2,   1,  1,  1,  1,   2,  2,  3,  2,   2,  2,  2,  1,  
00118 
00119       1,  1,  2,  2,   1,  1,  2,  2,   2,  2,  3,  2,   2,  2,  3,  2,  
00120       1,  1,  2,  2,   1,  1,  1,  1,   2,  2,  3,  2,   2,  2,  2,  1,  
00121       1,  1,  2,  2,   1,  1,  2,  2,   1,  1,  2,  1,   1,  1,  2,  1,  
00122       1,  1,  2,  2,   1,  1,  1,  1,   1,  1,  2,  1,   1,  1,  1,  1  
00123     };
00124 
00125 
00126   template<typename I, typename N>
00127   inline
00128   unsigned
00129   connectivity_number_2d(const Image<I>& ima_, const Neighborhood<N>& nbh_,
00130                          const mln_psite(I)& p, bool b)
00131   {
00132     const I& ima = exact(ima_);
00133     const N& nbh = exact(nbh_);
00134 
00135     unsigned res = 0;
00136 
00137     mln_fwd_niter(neighb2d) n(c8(), p);
00138     for_all(n)
00139       {
00140         res = (res << 1);
00141         if (ima.has(n) && ima(n) == b)
00142           res = res | 1;
00143       }
00144 
00145     unsigned number;
00146 
00147     switch (nbh.size())
00148       {
00149       case 4:
00150         number = connectivity_number_c4[res];
00151         break;
00152       case 8:
00153         number = connectivity_number_c8[res];
00154         break;
00155       default:
00156         mln_assertion(0);
00157       }
00158 
00159     return number;
00160   }
00161 
00162 
00163   template<typename I, typename N>
00164   inline
00165   bool
00166   is_simple_2d(const Image<I>& ima, const Neighborhood<N>& nbh_, const mln_psite(I)& p)
00167   {
00168     const N& nbh = exact(nbh_);
00169     return
00170       connectivity_number_2d(ima, nbh.foreground(), p, true ) == 1 &&
00171       connectivity_number_2d(ima, nbh.background(), p, false) == 1;
00172   }
00173 
00174 # endif // MLN_INCLUDE_ONLY
00175 
00176 } // end of namespace mln
00177 
00178 #endif // ! MLN_TOPO_IS_SIMPLE_2D_HH

Generated on Thu Sep 8 2011 18:32:02 for Milena (Olena) by  doxygen 1.7.1