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

height.hh

00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory
00002 // (LRDE)
00003 //
00004 // This file is part of Olena.
00005 //
00006 // Olena is free software: you can redistribute it and/or modify it under
00007 // the terms of the GNU General Public License as published by the Free
00008 // Software Foundation, version 2 of the License.
00009 //
00010 // Olena is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software project without restriction.  Specifically, if other files
00020 // instantiate templates or use macros or inline functions from this
00021 // file, or you compile this file and link it with other files to produce
00022 // an executable, this file does not by itself cause the resulting
00023 // executable to be covered by the GNU General Public License.  This
00024 // exception does not however invalidate any other reasons why the
00025 // executable file might be covered by the GNU General Public License.
00026 
00027 #ifndef MLN_ACCU_SHAPE_HEIGHT_HH
00028 # define MLN_ACCU_SHAPE_HEIGHT_HH
00029 
00034 /*
00035 This accumulator uses an mln::util::pix (pixel) to update the
00036 height information of the component.
00037 
00038 The class mln/accu/height is not a general-purpose accumulator;
00039 it is used to implement height-based connected filters.
00040 \see mln::morpho::closing::height
00041 \see mln::morpho::opening::height
00042 */
00043 
00044 # include <mln/accu/internal/base.hh>
00045 # include <mln/core/concept/meta_accumulator.hh>
00046 
00047 # include <mln/util/pix.hh>
00048 # include <mln/math/min.hh>
00049 # include <mln/math/max.hh>
00050 
00051 namespace mln
00052 {
00053 
00054   namespace accu
00055   {
00056 
00057     namespace shape
00058     {
00059 
00066       //
00067       template <typename I>
00068       struct height
00069         : public mln::accu::internal::base< unsigned , height<I> >
00070       {
00078         typedef util::pix<I> argument;
00080         typedef typename argument::value value;
00081 
00082         height();
00083 
00086         void init();
00087         void take(const argument&);
00088         void take(const height<I>& other);
00089 
00091         void set_value(unsigned h);
00093 
00095         unsigned to_result() const;
00096 
00099         bool is_valid() const;
00100 
00101       protected:
00103         value min_level__;
00105         value max_level__;
00107         unsigned height_;
00108       };
00109 
00110 
00111     } // end of mln::accu::shape
00112 
00113 
00114     namespace meta
00115     {
00116 
00117       namespace shape
00118       {
00119 
00121         struct height : public Meta_Accumulator< height >
00122         {
00123           template <typename I>
00124           struct with
00125           {
00126             typedef accu::shape::height<I> ret;
00127           };
00128         };
00129 
00130       } // end of namespace mln::accu::meta::shape
00131 
00132     } // end of namespace mln::accu::meta
00133 
00134 
00135 # ifndef MLN_INCLUDE_ONLY
00136 
00137     namespace shape
00138     {
00139 
00140       template <typename I>
00141       inline
00142       height<I>::height()
00143       {
00144         init();
00145       }
00146 
00147       template <typename I>
00148       inline
00149       void
00150       height<I>::init()
00151       {
00152         min_level__ = mln_max(value);
00153         max_level__ = mln_min(value);
00154         height_ = 0;
00155       }
00156 
00157       template <typename I>
00158       inline
00159       void
00160       height<I>::take(const argument& t)
00161       {
00162         min_level__ = mln::math::min(min_level__, t.v());
00163         max_level__ = mln::math::max(max_level__, t.v());
00164         height_ = max_level__ - min_level__;
00165       }
00166 
00167       template <typename I>
00168       inline
00169       void
00170       height<I>::take(const height<I>& other)
00171       {
00172         min_level__ = mln::math::min(min_level__, other.min_level__);
00173         max_level__ = mln::math::max(max_level__, other.max_level__);
00174         height_ = max_level__ - min_level__;
00175       }
00176 
00177       template <typename I>
00178       inline
00179       unsigned
00180       height<I>::to_result() const
00181       {
00182         return height_;
00183       }
00184 
00185       template <typename I>
00186       inline
00187       void
00188       height<I>::set_value(unsigned h)
00189       {
00190         height_ = h;
00191         // Reset the other members.
00192         min_level__ = mln_max(value);
00193         max_level__ = mln_min(value);
00194       }
00195 
00196       template <typename I>
00197       inline
00198       bool
00199       height<I>::is_valid() const
00200       {
00201         return true;
00202       }
00203 
00204     } // end of namespace mln::accu::shape
00205 
00206 # endif // ! MLN_INCLUDE_ONLY
00207 
00208   } // end of namespace mln::accu
00209 
00210 } // end of namespace mln
00211 
00212 
00213 #endif // ! MLN_ACCU_SHAPE_HEIGHT_HH

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