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

is_simple_point.hh

00001 // Copyright (C) 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_SKELETON_IS_SIMPLE_POINT_HH
00027 # define MLN_TOPO_SKELETON_IS_SIMPLE_POINT_HH
00028 
00033 
00034 # include <mln/core/concept/image.hh>
00035 # include <mln/core/alias/point2d.hh>
00036 # include <mln/core/alias/neighb2d.hh>
00037 
00038 namespace mln
00039 {
00040 
00041   namespace topo
00042   {
00043 
00044     namespace skeleton
00045     {
00046 
00063       template <typename I, typename N>
00064       bool
00065       is_simple_point(const Image<I>& ima,
00066                       const Neighborhood<N>& nbh,
00067                       const mln_site(I)& p);
00068 
00069 
00070 # ifndef MLN_INCLUDE_ONLY
00071 
00072 
00073       namespace internal
00074       {
00075 
00076 
00077         static const unsigned char nb_connexity_c8[256] =
00078         {
00079           0,  1,  1,  1,   1,  2,  1,  1,   1,  1,  1,  1,   2,  2,  1,  1,
00080           1,  2,  1,  1,   1,  2,  1,  1,   2,  2,  1,  1,   2,  2,  1,  1,
00081           1,  2,  2,  2,   2,  3,  2,  2,   1,  1,  1,  1,   2,  2,  1,  1,
00082           2,  3,  2,  2,   2,  3,  2,  2,   2,  2,  1,  1,   2,  2,  1,  1,
00083 
00084           1,  2,  2,  2,   2,  3,  2,  2,   1,  1,  1,  1,   2,  2,  1,  1,
00085           1,  2,  1,  1,   1,  2,  1,  1,   1,  1,  1,  1,   1,  1,  1,  1,
00086           1,  2,  2,  2,   2,  3,  2,  2,   1,  1,  1,  1,   2,  2,  1,  1,
00087           1,  2,  1,  1,   1,  2,  1,  1,   1,  1,  1,  1,   1,  1,  1,  1,
00088 
00089           1,  2,  2,  2,   2,  3,  2,  2,   2,  2,  2,  2,   3,  3,  2,  2,
00090           1,  2,  1,  1,   1,  2,  1,  1,   2,  2,  1,  1,   2,  2,  1,  1,
00091           2,  3,  3,  3,   3,  4,  3,  3,   2,  2,  2,  2,   3,  3,  2,  2,
00092           2,  3,  2,  2,   2,  3,  2,  2,   2,  2,  1,  1,   2,  2,  1,  1,
00093 
00094           1,  2,  2,  2,   2,  3,  2,  2,   1,  1,  1,  1,   2,  2,  1,  1,
00095           1,  2,  1,  1,   1,  2,  1,  1,   1,  1,  1,  1,   1,  1,  1,  1,
00096           1,  2,  2,  2,   2,  3,  2,  2,   1,  1,  1,  1,   2,  2,  1,  1,
00097           1,  2,  1,  1,   1,  2,  1,  1,   1,  1,  1,  1,   1,  1,  1,  1
00098         };
00099 
00100         static const unsigned char nb_connexity_c4[256] =
00101         {
00102           0,  0,  1,  1,   0,  0,  1,  1,   1,  1,  2,  1,   1,  1,  2,  1,
00103           1,  1,  2,  2,   1,  1,  1,  1,   2,  2,  3,  2,   2,  2,  2,  1,
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 
00107           1,  1,  2,  2,   1,  1,  2,  2,   2,  2,  3,  2,   2,  2,  3,  2,
00108           2,  2,  3,  3,   2,  2,  2,  2,   3,  3,  4,  3,   3,  3,  3,  2,
00109           1,  1,  2,  2,   1,  1,  2,  2,   1,  1,  2,  1,   1,  1,  2,  1,
00110           2,  2,  3,  3,   2,  2,  2,  2,   2,  2,  3,  2,   2,  2,  2,  1,
00111 
00112           0,  0,  1,  1,   0,  0,  1,  1,   1,  1,  2,  1,   1,  1,  2,  1,
00113           1,  1,  2,  2,   1,  1,  1,  1,   2,  2,  3,  2,   2,  2,  2,  1,
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 
00117           1,  1,  2,  2,   1,  1,  2,  2,   2,  2,  3,  2,   2,  2,  3,  2,
00118           1,  1,  2,  2,   1,  1,  1,  1,   2,  2,  3,  2,   2,  2,  2,  1,
00119           1,  1,  2,  2,   1,  1,  2,  2,   1,  1,  2,  1,   1,  1,  2,  1,
00120           1,  1,  2,  2,   1,  1,  1,  1,   1,  1,  2,  1,   1,  1,  1,  1
00121         };
00122 
00123 
00124 
00125         template <typename I, typename N>
00126         inline
00127         unsigned
00128         nb_connexity2d(const I& ima,
00129                        const N& nbh,
00130                        const mln_site(I)& p,
00131                        bool object)
00132         {
00133           unsigned res = 0;
00134 
00135           mln_bkd_niter(N) n(c8(), p);
00136           for_all(n)
00137           {
00138             res = (res << 1);
00139             if (ima.domain().has(n) && ima(n) == object)
00140               res = res | 1;
00141           }
00142 
00143           if (nbh == c8())
00144             return nb_connexity_c8[res];
00145           else
00146           {
00147             mln_assertion(nbh == c4());
00148             return nb_connexity_c4[res];
00149           }
00150         }
00151 
00152 
00153         template <typename N>
00154         neighb2d
00155         complement2d(const Neighborhood<N>& nbh_)
00156         {
00157           const N& nbh = exact(nbh_);
00158           mln_precondition(nbh.is_valid());
00159           mln_precondition(nbh == c4() || nbh == c8());
00160 
00161           if (nbh == c4())
00162             return c8();
00163           else
00164             return c4();
00165         }
00166 
00167 
00168         // Tests.
00169 
00170         template <typename I, typename N>
00171         inline
00172         void
00173         is_simple_point_tests(const Image<I>& ima_,
00174                               const Neighborhood<N>& nbh_,
00175                               const mln_site(I)& p)
00176         {
00177           const I& ima = exact(ima_);
00178           const N& nbh = exact(nbh_);
00179 
00180           mln_assertion(nbh == c4() || nbh == c8());
00181           mln_precondition(ima.is_valid());
00182           mln_precondition(nbh.is_valid());
00183 
00184           (void) ima;
00185           (void) nbh;
00186           (void) p;
00187         }
00188 
00189       } // end of namespace mln::topo::skeleton::internal
00190 
00191 
00192 
00193       // Implementations
00194 
00195       namespace impl
00196       {
00197 
00198         template <typename I, typename N>
00199         inline
00200         bool
00201         is_simple_point2d(const Image<I>& ima_,
00202                           const Neighborhood<N>& nbh_,
00203                           const point2d& p)
00204         {
00205           const I& ima = exact(ima_);
00206           const N& nbh = exact(nbh_);
00207 
00208           internal::is_simple_point_tests(ima, nbh, p);
00209 
00210           bool b = (internal::nb_connexity2d(ima, nbh, p, true) == 1)
00211             && (internal::nb_connexity2d(ima, internal::complement2d(nbh),
00212                                          p, false) == 1);
00213 
00214           trace::exiting("topo::skeleton::is_simple_point2d");
00215           return b;
00216         }
00217 
00218       } // end of namespace mln::topo::skeleton::impl
00219 
00220 
00221 
00222 
00223       // Dispatch
00224 
00225       namespace internal
00226       {
00227 
00228         template <typename I, typename N>
00229         inline
00230         bool
00231         is_simple_point_dispatch(const Image<I>& ima,
00232                                  const Neighborhood<N>& nbh,
00233                                  const point2d& p)
00234         {
00235           return impl::is_simple_point2d(ima, nbh, p);
00236         }
00237 
00238 
00239         template <typename I, typename N>
00240         inline
00241         bool
00242         is_simple_point_dispatch(const Image<I>& ima,
00243                                  const Neighborhood<N>& nbh,
00244                                  const mln_site(I)& p)
00245         {
00247           mlc_abort(I)::check();
00248           return false;
00249         }
00250 
00251       } // end of namespace mln::topo::skeleton::internal
00252 
00253 
00254 
00255 
00256 
00257       // Facade
00258 
00259       template <typename I, typename N>
00260       inline
00261       bool
00262       is_simple_point(const Image<I>& ima,
00263                       const Neighborhood<N>& nbh,
00264                       const mln_site(I)& p)
00265       {
00266         trace::entering("topo::skeleton::is_simple_point2d");
00267 
00268         internal::is_simple_point_tests(ima, nbh, p);
00269 
00270         bool b = internal::is_simple_point_dispatch(ima, nbh, p);
00271 
00272         trace::exiting("topo::skeleton::is_simple_point2d");
00273         return b;
00274       }
00275 
00276 
00277 # endif // MLN_TOPO_SKELETON_INCLUDE_ONLY
00278 
00279     } // end of namespace mln::topo::skeleton
00280 
00281   } // end of namespace mln::topo
00282 
00283 } // end of namespace mln
00284 
00285 #endif // ! MLN_TOPO_SKELETON_IS_SIMPLE_POINT_HH

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