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

skeleton_constrained.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_MORPHO_SKELETON_CONSTRAINED_HH
00027 # define MLN_MORPHO_SKELETON_CONSTRAINED_HH
00028 
00034 
00035 # include <mln/core/concept/image.hh>
00036 # include <mln/core/concept/neighborhood.hh>
00037 # include <mln/core/site_set/p_queue_fast.hh>
00038 # include <mln/core/site_set/p_priority.hh>
00039 # include <mln/extension/adjust_duplicate.hh>
00040 # include <mln/data/fill.hh>
00041 
00042 
00043 namespace mln
00044 {
00045 
00046   namespace morpho
00047   {
00048 
00049     template <typename I,
00050               typename N, typename F,
00051               typename K, typename R>
00052     mln_ch_value(I, bool)
00053     skeleton_constrained(const Image<I>& input,
00054                          const Neighborhood<N>& nbh, const F& is_simple,
00055                          const Image<K>& constraint, const Image<R>& priority);
00056 
00057 
00058 
00059 # ifndef MLN_INCLUDE_ONLY
00060 
00061     template <typename I,
00062               typename N, typename F,
00063               typename K, typename R>
00064     inline
00065     mln_ch_value(I, bool)
00066     skeleton_constrained(const Image<I>& input_,
00067                          const Neighborhood<N>& nbh_, const F& is_simple,
00068                          const Image<K>& constraint_, const Image<R>& priority_)
00069     {
00070       trace::entering("morpho::skeleton_constrained");
00071 
00072       const I& input      = exact(input_);
00073       const N& nbh        = exact(nbh_);
00074       const K& constraint = exact(constraint_);
00075       const R& priority   = exact(priority_);
00076 
00077       mln_precondition(input.is_valid());
00078       mln_precondition(nbh.is_valid());
00079       mln_precondition(constraint.is_valid());
00080       mln_precondition(priority.is_valid());
00081 
00082       extension::adjust_duplicate(input, nbh);
00083 
00084       // FIXME: Tests!
00085 
00086       typedef mln_psite(I) P;
00087       typedef p_queue_fast<P> Q;
00088       p_priority<mln_value(R), Q> q;
00089 
00090       mln_ch_value(I, bool) output;
00091 
00092       // Initialization.
00093       {
00094         initialize(output, input);
00095         data::fill(output, input);
00096         extension::adjust_duplicate(output, nbh);
00097 
00098         mln_piter(I) p(input.domain());
00099         for_all(p)
00100           if (input(p) == false &&
00101               is_simple(input, nbh, p)) // p is a simple point of the background.
00102             {
00103               q.push(priority(p), p);
00104             }
00105       }
00106 
00107       // Propagation.
00108       {
00109         P p;
00110         mln_niter(N) n(nbh, p);
00111         while (! q.is_empty())
00112           {
00113             p = q.pop_front();
00114             for_all(n)
00115               if (output.has(n) &&
00116                   output(n) == true &&
00117                   constraint(n) == false &&
00118                   is_simple(output, nbh, n))
00119                 {
00120                   output(n) = false; // Remove n from object.
00121                   q.push(priority(n), n);
00122                 }
00123           }
00124       }
00125 
00126       trace::exiting("morpho::skeleton_constrained");
00127       return output;
00128     }
00129 
00130 # endif // ! MLN_INCLUDE_ONLY
00131 
00132   } // end of namespace mln::morpho
00133 
00134 } // end of namespace mln
00135 
00136 
00137 #endif // ! MLN_MORPHO_SKELETON_CONSTRAINED_HH

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