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

n_max.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_LABELING_N_MAX_HH
00027 # define MLN_LABELING_N_MAX_HH
00028 
00029 # include <mln/core/concept/image.hh>
00030 # include <mln/accu/math/count.hh>
00031 # include <mln/labeling/compute.hh>
00032 # include <mln/util/array.hh>
00033 
00040 
00041 
00042 namespace mln
00043 {
00044 
00045   namespace labeling
00046   {
00047 
00048     template <typename L, typename V>
00049     util::array<L>
00050     n_max(const util::array<V>& in_arr, unsigned n);
00051 
00052 
00053     template <typename L>
00054     util::array<mln_value(L)>
00055     n_max(const Image<L>& lbl, const mln_value(L)& nlabels, unsigned n);
00056 
00057 
00058 # ifndef MLN_INCLUDE_ONLY
00059 
00060     template <typename L, typename V>
00061     util::array<L>
00062     n_max(const util::array<V>& in_arr, unsigned n)
00063     {
00064       trace::entering("mln::labeling::n_max");
00065 
00066       util::array<L> output(n + 1, 0);
00067 
00068       int swap = 0;
00069       for (unsigned i = 0; i < in_arr.nelements(); ++i)
00070       {
00071         if (in_arr[i] > in_arr[output[n]])
00072         {
00073           output[n] = i;
00074         }
00075         int j = n - 1;
00076         while (j > 0 && in_arr[output[j]] < in_arr[output[j + 1]])
00077         {
00078           swap = output[j];
00079           output[j] = output[j + 1];
00080           output[j + 1] = swap;
00081           --j;
00082         }
00083       }
00084 
00085       trace::exiting("mln::labeling::n_max");
00086       return output;
00087     }
00088 
00089 
00090     template <typename L>
00091     util::array<mln_value(L)>
00092     n_max(const Image<L>& lbl, const mln_value(L)& nlabels, unsigned n)
00093     {
00094       mln_precondition(exact(lbl).is_valid());
00095 
00096       typedef accu::math::count<mln_site(L)> accu_t;
00097       accu_t accu;
00098 
00099       util::array<mln_result(accu_t)>
00100         counts = labeling::compute(accu, lbl, nlabels);
00101 
00102       return n_max<mln_value(L)>(counts, n);
00103     }
00104 
00105 
00106 # endif // !MLN_INCLUDE_ONLY
00107 
00108   } // end of namespace mln::labeling
00109 
00110 } // end of namespace mln
00111 
00112 #endif // ! MLN_LABELING_N_MAX_HH

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