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

graylevel_f.hh

00001 // Copyright (C) 2006, 2007, 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_VALUE_GRAYLEVEL_F_HH
00027 # define MLN_VALUE_GRAYLEVEL_F_HH
00028 
00032 
00033 # include <iostream>
00034 
00035 # include <mln/value/ops.hh>
00036 
00037 # include <mln/core/contract.hh>
00038 # include <mln/metal/math/pow.hh>
00039 # include <mln/metal/bexpr.hh>
00040 # include <mln/literal/ops.hh>
00041 
00042 # include <mln/value/float01_f.hh>
00043 # include <mln/trait/value_.hh>
00044 
00045 
00046 namespace mln
00047 {
00048 
00049   namespace literal
00050   {
00052     struct black_t;
00053     struct medium_gray_t;
00054     struct white_t;
00056   }
00057   namespace value
00058   {
00060     namespace internal {class gray_f; }
00061     struct graylevel_f;
00062     template <unsigned n> struct graylevel;
00063     struct float01_f;
00065   }
00066 
00067 
00068 
00069   namespace trait
00070   {
00071 
00072     template <>
00073     struct set_precise_binary_< op::plus, mln::value::graylevel_f, mln::value::graylevel_f >
00074     {
00075       typedef mln::value::internal::gray_f ret;
00076     };
00077 
00078     template <unsigned n>
00079     struct set_precise_binary_< op::plus, mln::value::graylevel_f, mln::value::graylevel<n> >
00080     {
00081       typedef mln::value::internal::gray_f ret;
00082     };
00083     template <unsigned n>
00084     struct set_precise_binary_< op::plus, mln::value::graylevel<n>, mln::value::graylevel_f  >
00085     {
00086       typedef mln::value::internal::gray_f ret;
00087     };
00088 
00089     template <>
00090     struct set_precise_binary_< op::minus, mln::value::graylevel_f, mln::value::graylevel_f >
00091     {
00092       typedef mln::value::internal::gray_f ret;
00093     };
00094 
00095     template <>
00096     struct set_precise_binary_< op::times, mln::value::graylevel_f, mln::value::graylevel_f >
00097     {
00098       typedef mln::value::internal::gray_f ret;
00099     };
00100 
00101     template <>
00102     struct set_precise_binary_< op::div, mln::value::graylevel_f, mln::value::graylevel_f >
00103     {
00104       typedef mln::value::internal::gray_f ret;
00105     };
00106 
00107     template < typename I >
00108     struct set_binary_< op::times,
00109                         mln::value::Integer, mln::value::graylevel_f,
00110                         mln::value::Integer, I >
00111     {
00112       typedef mln::value::internal::gray_f ret;
00113     };
00114 
00115     template < typename I >
00116     struct set_binary_< op::times,
00117                         mln::value::Integer, I,
00118                         mln::value::Integer, mln::value::graylevel_f >
00119     {
00120       typedef mln::value::internal::gray_f ret;
00121     };
00122 
00123 
00124     template < typename F >
00125     struct set_binary_< op::times,
00126                         mln::value::Integer,  mln::value::graylevel_f,
00127                         mln::value::Floating, F >
00128     {
00129       typedef mln::value::internal::gray_f ret;
00130     };
00131 
00132     template < typename F >
00133     struct set_binary_< op::times,
00134                         mln::value::Floating, F,
00135                         mln::value::Integer,  mln::value::graylevel_f >
00136     {
00137       typedef mln::value::internal::gray_f ret;
00138     };
00139 
00140 
00141     template < typename S >
00142     struct set_precise_binary_< op::times, mln::value::graylevel_f, mln::value::scalar_<S> >
00143     {
00144       typedef mln::value::internal::gray_f ret;
00145     };
00146 
00147     template < typename S >
00148     struct set_precise_binary_< op::div, mln::value::graylevel_f, mln::value::scalar_<S> >
00149     {
00150       typedef mln::value::internal::gray_f ret;
00151     };
00152 
00153 
00155     template <typename T> struct value_;
00156 
00157     // 'graylevel_f' as a value.
00158     template <>
00159     struct value_<mln::value::graylevel_f>
00160     {
00161     private:
00162       typedef mln::value::graylevel_f self_;
00163       typedef mln::value::float01_f equiv_;
00164 
00165     public:
00166 
00167       enum {
00168         dim = 1,
00169         nbits = mln_nbits(equiv_),
00170         card  = 0
00171       };
00172 
00173       typedef trait::value::nature::floating nature;
00174       typedef trait::value::kind::gray       kind;
00175       typedef mln_trait_value_quant_(equiv_)   quant;
00176 
00177       static const equiv_ min() { return 0; }
00178       static const equiv_ max() { return 1; }
00179       static const equiv_ epsilon() { return mln_epsilon(equiv_); }
00180 
00181       typedef float comp;
00182 
00183       typedef float sum;
00184     };
00185 
00186   } // end of namespace mln::trait
00187 
00188 
00189   namespace value
00190   {
00191 
00193     struct graylevel_f
00194       :
00195       public Floating< graylevel_f >,
00196 
00197       public internal::value_like_< float01_f,          // Equivalent.
00198                                     mln_enc_(float01_f),// Encoding.
00199                                     internal::gray_f,   // Interoperation.
00200                                     graylevel_f >       // Exact.
00201     {
00203       graylevel_f();
00205       graylevel_f(const graylevel_f& rhs);
00207       graylevel_f& operator=(const graylevel_f& rhs);
00208 
00209 
00211       graylevel_f(float val);
00213       graylevel_f& operator=(float val);
00214 
00216       template <unsigned n>
00217         graylevel_f(const graylevel<n>& rhs);
00219       template <unsigned n>
00220         graylevel_f& operator=(const graylevel<n>& rhs);
00221 
00224       graylevel_f(const mln::literal::black_t&);
00225       graylevel_f(const mln::literal::medium_gray_t&);
00226       graylevel_f(const mln::literal::white_t&);
00228 
00231       graylevel_f& operator=(const mln::literal::black_t&);
00232       graylevel_f& operator=(const mln::literal::medium_gray_t&);
00233       graylevel_f& operator=(const mln::literal::white_t&);
00235 
00237       template <unsigned n>
00238         operator graylevel<n>() const;
00239 
00241       float value() const;
00242     };
00243 
00244 
00245     // Operators.
00246 
00248     std::ostream& operator<<(std::ostream& ostr, const graylevel_f& g);
00249 
00250     // graylevel_f + graylevel_f.
00251     mln_trait_op_plus_(graylevel_f, graylevel_f)
00252       operator+(const graylevel_f& lhs, const graylevel_f& rhs);
00253 
00254 
00255     // graylevel_f + graylevel<n>.
00256     template <unsigned n>
00257     mln_trait_op_plus(graylevel_f, graylevel<n>)
00258       operator+(const graylevel_f& lhs, const graylevel<n>& rhs);
00259     // graylevel<n> + graylevel_f.
00260     template <unsigned n>
00261     mln_trait_op_plus(graylevel_f, graylevel<n>)
00262       operator+(const graylevel<n>& lhs, const graylevel_f& rhs);
00263 
00264     // graylevel_f - graylevel_f.
00265     mln_trait_op_minus_(graylevel_f, graylevel_f)
00266       operator-(const graylevel_f& lhs, const graylevel_f& rhs);
00267 
00268     // graylevel_f * graylevel_f.
00269     mln_trait_op_times_(graylevel_f, graylevel_f)
00270       operator*(const graylevel_f& lhs, const graylevel_f& rhs);
00271 
00272 
00273     // With Builtins.
00274 
00275     // graylevel_f * T.
00276     template <unsigned n, typename T>
00277     mln_trait_op_times(graylevel_f, T)
00278       operator*(const graylevel_f& lhs, const T& rhs);
00279 
00280     // T * graylevel_f.
00281     template <unsigned n, typename T>
00282     mln_trait_op_times(graylevel_f, T)
00283       operator*(const T& lhs, const graylevel_f& rhs);
00284 
00285     // graylevel_f / T.
00286     template <unsigned n, typename T>
00287     internal::gray_f
00288       operator/(const graylevel_f& lhs, const T& rhs);
00289 
00290     // With Integer.
00291 
00292     // graylevel_f * Integer<I>.
00293     template <typename I>
00294     mln_trait_op_times(graylevel_f, I)
00295       operator*(const graylevel_f& lhs, const Integer<I>& rhs);
00296 
00297     // Integer<I> * graylevel_f.
00298     template <typename I>
00299     mln_trait_op_times(I, graylevel_f)
00300       operator*(const Integer<I>& lhs, const graylevel_f& rhs);
00301 
00302     // graylevel_f / Integer<I>.
00303     template <typename I>
00304     mln_trait_op_div(graylevel_f, I)
00305       operator/(const graylevel_f& lhs, const Integer<I>& rhs);
00306 
00307     // Integer<I> / graylevel_f.
00308     template <typename I>
00309     mln_trait_op_div(I, graylevel_f)
00310       operator/(const Integer<I>& lhs, const graylevel_f& rhs);
00311 
00312     // With Floating.
00313 
00314     // graylevel_f * Floating<F>.
00315     template <typename F>
00316     mln_trait_op_times(graylevel_f, F)
00317       operator*(const graylevel_f& lhs, const Floating<F>& rhs);
00318 
00319     // Floating<F>, graylevel_f.
00320     template <typename F>
00321     mln_trait_op_times(F, graylevel_f)
00322       operator*(const Floating<F>& lhs, const graylevel_f& rhs);
00323 
00324 
00325     // graylevel_f / Floating<F>.
00326     template <typename F>
00327     mln_trait_op_div(graylevel_f, F)
00328       operator/(const graylevel_f& lhs, const Floating<F>& rhs);
00329 
00330     // Floating<F> / graylevel_f.
00331     template <typename F>
00332     mln_trait_op_div(F, graylevel_f)
00333       operator/(const Floating<F>& lhs, const graylevel_f& rhs);
00334 
00335 
00336 # ifndef MLN_INCLUDE_ONLY
00337 
00338     // graylevel_f.
00339 
00340     inline
00341     graylevel_f::graylevel_f()
00342     {
00343     }
00344 
00345 
00346     inline
00347     graylevel_f::graylevel_f(float val)
00348     {
00349       mln_precondition(val >= 0);
00350       mln_precondition(val <= 1);
00351       this->v_ = val;
00352     }
00353 
00354     inline
00355     graylevel_f&
00356     graylevel_f::operator=(float val)
00357     {
00358       mln_precondition(val >= 0);
00359       mln_precondition(val <= 1);
00360       this->v_ = val;
00361       return *this;
00362     }
00363 
00364     template <unsigned n>
00365     graylevel_f::graylevel_f(const graylevel<n>& rhs)
00366     {
00367       mln_precondition(rhs.to_float() >= 0);
00368       mln_precondition(rhs.to_float() <= 1);
00369       this->v_ = rhs.to_float();
00370     }
00371 
00372     template <unsigned n>
00373     graylevel_f&
00374     graylevel_f::operator=(const graylevel<n>& rhs)
00375     {
00376       mln_precondition(rhs.to_float() >= 0);
00377       mln_precondition(rhs.to_float() <= 1);
00378       this->v_ = rhs.to_float();
00379       return *this;
00380     }
00381 
00382     inline
00383     graylevel_f::graylevel_f(const graylevel_f& rhs)
00384       : Floating<graylevel_f>()
00385     {
00386       this->v_ = rhs.v_;
00387     }
00388 
00389     inline
00390     graylevel_f&
00391     graylevel_f::operator=(const graylevel_f& rhs)
00392     {
00393       mln_precondition(rhs.v_ >= 0);
00394       mln_precondition(rhs.v_ <= 1);
00395       this->v_ = rhs.v_;
00396       return *this;
00397     }
00398 
00399     inline
00400     graylevel_f::graylevel_f(const mln::literal::black_t&)
00401     {
00402       this->v_ = 0.0f;
00403     }
00404 
00405     inline
00406     graylevel_f&
00407     graylevel_f::operator=(const mln::literal::black_t&)
00408     {
00409       this->v_ = 0.0f;
00410       return *this;
00411     }
00412 
00413     inline
00414     graylevel_f::graylevel_f(const mln::literal::medium_gray_t&)
00415     {
00416       this->v_ = 0.5f;
00417     }
00418 
00419     inline
00420     graylevel_f&
00421     graylevel_f::operator=(const mln::literal::medium_gray_t&)
00422     {
00423       this->v_ = 0.5f;
00424       return *this;
00425     }
00426 
00427     inline
00428     graylevel_f::graylevel_f(const mln::literal::white_t&)
00429     {
00430       this->v_ = 1.0f;
00431     }
00432 
00433     inline
00434     graylevel_f&
00435     graylevel_f::operator=(const mln::literal::white_t&)
00436     {
00437       this->v_ = 1.0f;
00438       return *this;
00439     }
00440 
00441     template <unsigned n>
00442     inline
00443     graylevel_f::operator graylevel<n>() const
00444     {
00445       return graylevel<n>(internal::gray_f(*this));
00446     }
00447 
00448     inline
00449     float
00450     graylevel_f::value() const
00451     {
00452       return this->v_;
00453     }
00454 
00455     // Operators.
00456 
00457     inline
00458     std::ostream& operator<<(std::ostream& ostr, const graylevel_f& g)
00459     {
00460       return ostr << g.value() << "/gl_f"; // FIXME: Be more explicit!.
00461     }
00462 
00463 # endif // ! MLN_INCLUDE_ONLY
00464 
00465   } // end of namespace mln::value
00466 
00467 } // end of namespace mln
00468 
00469 
00470 //# include <mln/value/internal/gray_f.hh>
00472 
00473 #endif // ! MLN_VALUE_GRAYLEVEL_F_HH

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