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

pack.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_PACK_HH
00027 # define MLN_LABELING_PACK_HH
00028 
00033 
00034 # include <mln/core/concept/image.hh>
00035 
00036 # include <mln/make/relabelfun.hh>
00037 
00038 # include <mln/data/compute.hh>
00039 # include <mln/data/transform.hh>
00040 
00041 # include <mln/accu/label_used.hh>
00042 
00043 
00044 
00045 namespace mln
00046 {
00047 
00048   namespace labeling
00049   {
00050 
00058     //
00059     template <typename I>
00060     mln_concrete(I)
00061     pack(const Image<I>& label, mln_value(I)& new_nlabels,
00062          fun::i2v::array<mln_value(I)>& repack_fun);
00063 
00064 
00066     template <typename I>
00067     mln_concrete(I)
00068     pack(const Image<I>& label, mln_value(I)& new_nlabels);
00069 
00070 
00071 
00078     //
00079     template <typename I>
00080     void
00081     pack_inplace(Image<I>& label, mln_value(I)& new_nlabels,
00082                  fun::i2v::array<mln_value(I)>& repack_fun);
00083 
00084 
00086     template <typename I>
00087     void
00088     pack_inplace(Image<I>& label, mln_value(I)& new_nlabels);
00089 
00090 
00091 
00092 # ifndef MLN_INCLUDE_ONLY
00093 
00094 
00095     namespace internal
00096     {
00097 
00098       template <typename I>
00099       void
00100       pack_tests(const Image<I>& label, mln_value(I)& new_nlabels)
00101       {
00102         // FIXME: we may want to check that it is exactly a label.
00103         //mlc_is_a(mln_value(I), mln::value::Symbolic)::check();
00104         mln_precondition(exact(label).is_valid());
00105         (void) label;
00106         (void) new_nlabels;
00107       }
00108 
00109     } // end of mln::labeling::internal
00110 
00111 
00112 
00113     template <typename I>
00114     mln_concrete(I)
00115     pack(const Image<I>& label, mln_value(I)& new_nlabels)
00116     {
00117       fun::i2v::array<mln_value(I)> repack_fun;
00118       return pack(label, new_nlabels, repack_fun);
00119     }
00120 
00121 
00122     template <typename I>
00123     mln_concrete(I)
00124     pack(const Image<I>& label, mln_value(I)& new_nlabels,
00125          fun::i2v::array<mln_value(I)>& repack_fun)
00126     {
00127       trace::entering("labeling::pack");
00128 
00129       internal::pack_tests(label, new_nlabels);
00130 
00131       fun::i2v::array<bool>
00132         fv2b = data::compute(accu::meta::label_used(), label);
00133 
00134       mln_value(I) tmp_nlabels = fv2b.size() - 1;
00135 
00136       repack_fun = make::relabelfun(fv2b, tmp_nlabels, new_nlabels);
00137 
00138       mln_concrete(I)
00139         output = data::transform(label, repack_fun);
00140 
00141       trace::exiting("labeling::pack");
00142       return output;
00143     }
00144 
00145 
00146     template <typename I>
00147     void
00148     pack_inplace(Image<I>& label, mln_value(I)& new_nlabels)
00149     {
00150       fun::i2v::array<mln_value(I)> repack_fun;
00151       pack_inplace(label, new_nlabels, repack_fun);
00152     }
00153 
00154 
00155     template <typename I>
00156     void
00157     pack_inplace(Image<I>& label, mln_value(I)& new_nlabels,
00158                  fun::i2v::array<mln_value(I)>& repack_fun)
00159     {
00160       trace::entering("labeling::pack_inplace");
00161 
00162       internal::pack_tests(label, new_nlabels);
00163 
00164       fun::i2v::array<bool>
00165         fv2b = data::compute(accu::meta::label_used(), label);
00166 
00167       mln_value(I) tmp_nlabels = fv2b.size() - 1;
00168       repack_fun = make::relabelfun(fv2b, tmp_nlabels, new_nlabels);
00169 
00170       exact(label) = data::transform(label, repack_fun);
00171 
00172       trace::exiting("labeling::pack_inplace");
00173     }
00174 
00175 
00176 # endif // ! MLN_INCLUDE_ONLY
00177 
00178   } // end of namespace mln::labeling
00179 
00180 } // end of namespace mln
00181 
00182 
00183 #endif // ! MLN_LABELING_PACK_HH

Generated on Tue Oct 4 2011 15:24:18 for Milena (Olena) by  doxygen 1.7.1