* mln/value/graylevel_f.hh, * mln/value/internal/gray_f.hh: Move definitions... * mln/value/graylevel_f.hxx, * mln/value/internal/gray_f.hxx: ...here (new files). * headers.mk (nobase_include_HEADERS): Regen. --- milena/ChangeLog | 12 ++ milena/headers.mk | 2 + milena/mln/value/graylevel_f.hh | 255 +++++++++++---------------- milena/mln/value/graylevel_f.hxx | 319 +++++++++++++++++++++++++++++++++ milena/mln/value/internal/gray_f.hh | 320 +++------------------------------- milena/mln/value/internal/gray_f.hxx | 160 +++++++++++++++++ 6 files changed, 622 insertions(+), 446 deletions(-) create mode 100644 milena/mln/value/graylevel_f.hxx create mode 100644 milena/mln/value/internal/gray_f.hxx
diff --git a/milena/ChangeLog b/milena/ChangeLog index e294ca0..2a289ad 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,3 +1,15 @@ +2013-02-06 Roland Levillain roland@lrde.epita.fr + + Fix mutual dependencies between floating-point gray-level values. + + * mln/value/graylevel_f.hh, + * mln/value/internal/gray_f.hh: + Move definitions... + * mln/value/graylevel_f.hxx, + * mln/value/internal/gray_f.hxx: + ...here (new files). + * headers.mk (nobase_include_HEADERS): Regen. + 2013-02-05 Roland Levillain roland@lrde.epita.fr
Address more remaining clang++ errors in Milena. diff --git a/milena/headers.mk b/milena/headers.mk index dbd26e9..8997e6b 100644 --- a/milena/headers.mk +++ b/milena/headers.mk @@ -1225,6 +1225,7 @@ mln/value/gl8.hh \ mln/value/glf.hh \ mln/value/graylevel.hh \ mln/value/graylevel_f.hh \ +mln/value/graylevel_f.hxx \ mln/value/hsl.hh \ mln/value/int_s.hh \ mln/value/int_s16.hh \ @@ -1244,6 +1245,7 @@ mln/value/internal/encoding.hh \ mln/value/internal/essential.hh \ mln/value/internal/gray_.hh \ mln/value/internal/gray_f.hh \ +mln/value/internal/gray_f.hxx \ mln/value/internal/integer.hh \ mln/value/internal/iterable_set.hh \ mln/value/internal/limits.hh \ diff --git a/milena/mln/value/graylevel_f.hh b/milena/mln/value/graylevel_f.hh index 4194b25..1d6d217 100644 --- a/milena/mln/value/graylevel_f.hh +++ b/milena/mln/value/graylevel_f.hh @@ -1,4 +1,4 @@ -// Copyright (C) 2006, 2007, 2008, 2009, 2011 EPITA Research and +// Copyright (C) 2006, 2007, 2008, 2009, 2011, 2013 EPITA Research and // Development Laboratory (LRDE) // // This file is part of Olena. @@ -29,7 +29,7 @@
/// \file /// -/// Definition of the mln::value::graylevel_f class. +/// Declaration of the mln::value::graylevel_f class.
# include <iostream>
@@ -43,22 +43,43 @@ # include <mln/value/float01_f.hh> # include <mln/trait/value_.hh>
+/* Because of mutual dependencies between the implementations of + mln::value::graylevel_f and mln::value::internal::gray_f, we have + to ensure that only the interfaces of the required classes are + included here. Implementations are included later, at the bottom of + this file. */ + +# ifdef MLN_INCLUDE_ONLY +# include <mln/value/internal/gray_f.hh> +# else +# define MLN_INCLUDE_ONLY +# include <mln/value/internal/gray_f.hh> +# undef MLN_INCLUDE_ONLY +# endif +
namespace mln {
namespace literal { - /// { Forward declarations. + /// Forward declarations. + /// { struct black_t; struct medium_gray_t; struct white_t; /// } } + namespace value { - /// { Forward declarations. - namespace internal { struct gray_f; } + /// Forward declarations. + /// { + namespace internal + { + struct gray_f; + } + struct graylevel_f; template <unsigned n> struct graylevel; struct float01_f; @@ -248,227 +269,159 @@ namespace mln /// Op<<. std::ostream& operator<<(std::ostream& ostr, const graylevel_f& g);
+ + // Integer<I> == graylevel_f. + template <typename I> + bool + operator==(const Integer<I>& lhs, const graylevel_f& rhs); + + // graylevel_f == graylevel_f. + // Op glf == glf + bool + operator==(const graylevel_f& lhs, const graylevel_f& rhs); + + // graylevel_f + graylevel_f. mln_trait_op_plus_(graylevel_f, graylevel_f) - operator+(const graylevel_f& lhs, const graylevel_f& rhs); - + operator+(const graylevel_f& lhs, const graylevel_f& rhs);
// graylevel_f + graylevel<n>. template <unsigned n> mln_trait_op_plus(graylevel_f, graylevel<n>) - operator+(const graylevel_f& lhs, const graylevel<n>& rhs); + operator+(const graylevel_f& lhs, const graylevel<n>& rhs); // graylevel<n> + graylevel_f. template <unsigned n> mln_trait_op_plus(graylevel_f, graylevel<n>) - operator+(const graylevel<n>& lhs, const graylevel_f& rhs); + operator+(const graylevel<n>& lhs, const graylevel_f& rhs); + + // graylevel_f + another type + template <typename I> + void + operator+(const graylevel_f& lhs, const I& i); + // another type + graylevel_f + template <typename I> + void + operator+(const I& i, const graylevel_f& rhs); +
// graylevel_f - graylevel_f. mln_trait_op_minus_(graylevel_f, graylevel_f) - operator-(const graylevel_f& lhs, const graylevel_f& rhs); + operator-(const graylevel_f& lhs, const graylevel_f& rhs); + + // graylevel_f - another type + template <typename I> + void + operator-(const graylevel_f& lhs, const I& i); + // another type - graylevel_f + template <typename I> + void + operator-(const I& i, const graylevel_f& rhs); +
// graylevel_f * graylevel_f. mln_trait_op_times_(graylevel_f, graylevel_f) - operator*(const graylevel_f& lhs, const graylevel_f& rhs); + operator*(const graylevel_f& lhs, const graylevel_f& rhs);
+ /* FIXME: These operators are apparently implemented nowhere. + Implement them or remove these declarations. */ +#if 0 // With Builtins.
// graylevel_f * T. template <unsigned n, typename T> mln_trait_op_times(graylevel_f, T) - operator*(const graylevel_f& lhs, const T& rhs); + operator*(const graylevel_f& lhs, const T& rhs);
// T * graylevel_f. template <unsigned n, typename T> mln_trait_op_times(graylevel_f, T) - operator*(const T& lhs, const graylevel_f& rhs); + operator*(const T& lhs, const graylevel_f& rhs);
// graylevel_f / T. template <unsigned n, typename T> internal::gray_f - operator/(const graylevel_f& lhs, const T& rhs); + operator/(const graylevel_f& lhs, const T& rhs); +#endif +
// With Integer.
// graylevel_f * Integer<I>. template <typename I> mln_trait_op_times(graylevel_f, I) - operator*(const graylevel_f& lhs, const Integer<I>& rhs); + operator*(const graylevel_f& lhs, const Integer<I>& rhs);
// Integer<I> * graylevel_f. template <typename I> mln_trait_op_times(I, graylevel_f) - operator*(const Integer<I>& lhs, const graylevel_f& rhs); + operator*(const Integer<I>& lhs, const graylevel_f& rhs);
+ + /* FIXME: These operators are apparently implemented nowhere. + Implement them or remove these declarations. */ +#if 0 // graylevel_f / Integer<I>. template <typename I> mln_trait_op_div(graylevel_f, I) - operator/(const graylevel_f& lhs, const Integer<I>& rhs); + operator/(const graylevel_f& lhs, const Integer<I>& rhs);
// Integer<I> / graylevel_f. template <typename I> mln_trait_op_div(I, graylevel_f) - operator/(const Integer<I>& lhs, const graylevel_f& rhs); + operator/(const Integer<I>& lhs, const graylevel_f& rhs); +#endif +
// With Floating.
// graylevel_f * Floating<F>. template <typename F> mln_trait_op_times(graylevel_f, F) - operator*(const graylevel_f& lhs, const Floating<F>& rhs); + operator*(const graylevel_f& lhs, const Floating<F>& rhs);
- // Floating<F>, graylevel_f. + // Floating<F> * graylevel_f. template <typename F> mln_trait_op_times(F, graylevel_f) - operator*(const Floating<F>& lhs, const graylevel_f& rhs); + operator*(const Floating<F>& lhs, const graylevel_f& rhs);
+ /* FIXME: These operators are apparently implemented nowhere. + Implement them or remove these declarations. */ +#if 0 // graylevel_f / Floating<F>. template <typename F> mln_trait_op_div(graylevel_f, F) - operator/(const graylevel_f& lhs, const Floating<F>& rhs); + operator/(const graylevel_f& lhs, const Floating<F>& rhs);
// Floating<F> / graylevel_f. template <typename F> mln_trait_op_div(F, graylevel_f) - operator/(const Floating<F>& lhs, const graylevel_f& rhs); - - -# ifndef MLN_INCLUDE_ONLY - - // graylevel_f. - - inline - graylevel_f::graylevel_f() - { - } - - - inline - graylevel_f::graylevel_f(float val) - { - mln_precondition(val >= 0); - mln_precondition(val <= 1); - this->v_ = val; - } - - inline - graylevel_f& - graylevel_f::operator=(float val) - { - mln_precondition(val >= 0); - mln_precondition(val <= 1); - this->v_ = val; - return *this; - } - - template <unsigned n> - graylevel_f::graylevel_f(const graylevel<n>& rhs) - { - mln_precondition(rhs.to_float() >= 0); - mln_precondition(rhs.to_float() <= 1); - this->v_ = rhs.to_float(); - } + operator/(const Floating<F>& lhs, const graylevel_f& rhs); +#endif
- template <unsigned n> - graylevel_f& - graylevel_f::operator=(const graylevel<n>& rhs) - { - mln_precondition(rhs.to_float() >= 0); - mln_precondition(rhs.to_float() <= 1); - this->v_ = rhs.to_float(); - return *this; - }
- inline - graylevel_f::graylevel_f(const graylevel_f& rhs) - : Floating<graylevel_f>() - { - this->v_ = rhs.v_; - } + // With scalar_.
- inline - graylevel_f& - graylevel_f::operator=(const graylevel_f& rhs) - { - mln_precondition(rhs.v_ >= 0); - mln_precondition(rhs.v_ <= 1); - this->v_ = rhs.v_; - return *this; - } + // graylevel * scalar_<S> + template <typename S> + mln_trait_op_times(graylevel_f, S) + operator*(const graylevel_f& lhs, const scalar_<S>& rhs);
- inline - graylevel_f::graylevel_f(const mln::literal::black_t&) - { - this->v_ = 0.0f; - } - - inline - graylevel_f& - graylevel_f::operator=(const mln::literal::black_t&) - { - this->v_ = 0.0f; - return *this; - } - - inline - graylevel_f::graylevel_f(const mln::literal::medium_gray_t&) - { - this->v_ = 0.5f; - } - - inline - graylevel_f& - graylevel_f::operator=(const mln::literal::medium_gray_t&) - { - this->v_ = 0.5f; - return *this; - } - - inline - graylevel_f::graylevel_f(const mln::literal::white_t&) - { - this->v_ = 1.0f; - } - - inline - graylevel_f& - graylevel_f::operator=(const mln::literal::white_t&) - { - this->v_ = 1.0f; - return *this; - } - - template <unsigned n> - inline - graylevel_f::operator graylevel<n>() const - { - return graylevel<n>(internal::gray_f(*this)); - } - - inline - float - graylevel_f::value() const - { - return this->v_; - } - - // Operators. - - inline - std::ostream& operator<<(std::ostream& ostr, const graylevel_f& g) - { - return ostr << g.value() << "/gl_f"; // FIXME: Be more explicit!. - } - -# endif // ! MLN_INCLUDE_ONLY + // graylevel / scalar_<S> + template <typename S> + mln_trait_op_div(graylevel_f, S) + operator/(const graylevel_f& lhs, const scalar_<S>& rhs);
} // end of namespace mln::value
} // end of namespace mln
-//# include <mln/value/internal/gray_f.hh> -///# include <mln/value/internal/gray_.hh> +# ifndef MLN_INCLUDE_ONLY +# include <mln/value/graylevel_f.hxx> +# include <mln/value/internal/gray_f.hxx> +# endif // ! MLN_INCLUDE_ONLY +
#endif // ! MLN_VALUE_GRAYLEVEL_F_HH diff --git a/milena/mln/value/graylevel_f.hxx b/milena/mln/value/graylevel_f.hxx new file mode 100644 index 0000000..db40cc5 --- /dev/null +++ b/milena/mln/value/graylevel_f.hxx @@ -0,0 +1,319 @@ +// Copyright (C) 2006, 2007, 2008, 2009, 2011, 2013 EPITA Research and +// Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. +// +// As a special exception, you may use this file as part of a free +// software project without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to produce +// an executable, this file does not by itself cause the resulting +// executable to be covered by the GNU General Public License. This +// exception does not however invalidate any other reasons why the +// executable file might be covered by the GNU General Public License. + +#ifndef MLN_VALUE_GRAYLEVEL_F_HXX +# define MLN_VALUE_GRAYLEVEL_F_HXX + +/// \file +/// +/// Definition of the mln::value::graylevel_f class. + +# include <mln/value/graylevel_f.hh> + + +namespace mln +{ + + namespace value + { + + // graylevel_f. + + inline + graylevel_f::graylevel_f() + { + } + + + inline + graylevel_f::graylevel_f(float val) + { + mln_precondition(val >= 0); + mln_precondition(val <= 1); + this->v_ = val; + } + + inline + graylevel_f& + graylevel_f::operator=(float val) + { + mln_precondition(val >= 0); + mln_precondition(val <= 1); + this->v_ = val; + return *this; + } + + template <unsigned n> + graylevel_f::graylevel_f(const graylevel<n>& rhs) + { + mln_precondition(rhs.to_float() >= 0); + mln_precondition(rhs.to_float() <= 1); + this->v_ = rhs.to_float(); + } + + template <unsigned n> + graylevel_f& + graylevel_f::operator=(const graylevel<n>& rhs) + { + mln_precondition(rhs.to_float() >= 0); + mln_precondition(rhs.to_float() <= 1); + this->v_ = rhs.to_float(); + return *this; + } + + inline + graylevel_f::graylevel_f(const graylevel_f& rhs) + : Floating<graylevel_f>() + { + this->v_ = rhs.v_; + } + + inline + graylevel_f& + graylevel_f::operator=(const graylevel_f& rhs) + { + mln_precondition(rhs.v_ >= 0); + mln_precondition(rhs.v_ <= 1); + this->v_ = rhs.v_; + return *this; + } + + inline + graylevel_f::graylevel_f(const mln::literal::black_t&) + { + this->v_ = 0.0f; + } + + inline + graylevel_f& + graylevel_f::operator=(const mln::literal::black_t&) + { + this->v_ = 0.0f; + return *this; + } + + inline + graylevel_f::graylevel_f(const mln::literal::medium_gray_t&) + { + this->v_ = 0.5f; + } + + inline + graylevel_f& + graylevel_f::operator=(const mln::literal::medium_gray_t&) + { + this->v_ = 0.5f; + return *this; + } + + inline + graylevel_f::graylevel_f(const mln::literal::white_t&) + { + this->v_ = 1.0f; + } + + inline + graylevel_f& + graylevel_f::operator=(const mln::literal::white_t&) + { + this->v_ = 1.0f; + return *this; + } + + template <unsigned n> + inline + graylevel_f::operator graylevel<n>() const + { + return graylevel<n>(internal::gray_f(*this)); + } + + inline + float + graylevel_f::value() const + { + return this->v_; + } + + + // Operators. + + inline + std::ostream& operator<<(std::ostream& ostr, const graylevel_f& g) + { + return ostr << g.value() << "/gl_f"; // FIXME: Be more explicit!. + } + + + template <typename I> + inline + bool + operator==(const Integer<I>& lhs, const graylevel_f& rhs) + { + return rhs.value() == exact(lhs); + } + + inline + bool + operator==(const graylevel_f& lhs, const graylevel_f& rhs) + { + return rhs.value() == lhs.value(); + } + + + inline + mln_trait_op_plus_(graylevel_f, graylevel_f) + operator+(const graylevel_f& lhs, const graylevel_f& rhs) + { + return lhs.value() + rhs.value(); + } + + + template <unsigned n> + inline + mln_trait_op_plus(graylevel_f, graylevel<n>) + operator+(const graylevel_f& lhs, const graylevel<n>& rhs) + { + return lhs.value() + graylevel_f(rhs).value(); + } + + template <unsigned n> + inline + mln_trait_op_plus(graylevel_f, graylevel<n>) + operator+(const graylevel<n>& lhs, const graylevel_f& rhs) + { + return rhs.value() + graylevel_f(lhs).value(); + } + + template <typename I> + inline + void + operator+(const graylevel_f& lhs, const I& i) + { + (void) lhs; + (void) i; + typename + Object<I>::wrong_use_of_graylevel_f___Please_use_the__to_enc__method a; + } + + template <typename I> + inline + void + operator+(const I& i, const graylevel_f& rhs) + { + (void) i; + (void) rhs; + typename + Object<I>::wrong_use_of_graylevel_f___Please_use_the__to_enc__method a; + } + + + inline + mln_trait_op_minus_(graylevel_f, graylevel_f) + operator-(const graylevel_f& lhs, const graylevel_f& rhs) + { + return lhs.value() - rhs.value(); + } + + template <typename I> + inline + void + operator-(const graylevel_f& lhs, const I& i) + { + (void) lhs; + (void) i; + typename + Object<I>::wrong_use_of_graylevel_f___Please_use_the__to_enc__method a; + } + + template <typename I> + inline + void + operator-(const I& i, const graylevel_f& rhs) + { + (void) i; + (void) rhs; + typename + Object<I>::wrong_use_of_graylevel_f___Please_use_the__to_enc__method a; + } + + + inline + mln_trait_op_times_(graylevel_f, graylevel_f) + operator*(const graylevel_f& lhs, const graylevel_f& rhs) + { + return lhs.value() * rhs.value(); + } + + + + template <typename I> + inline + mln_trait_op_times(graylevel_f, I) + operator*(const graylevel_f& lhs, const Integer<I>& rhs) + { + return lhs.value() * int(exact(rhs)); + } + + template <typename F> + inline + mln_trait_op_times(graylevel_f, F) + operator*(const graylevel_f& lhs, const Floating<F>& rhs) + { + return lhs.value() * exact(rhs); + } + + template <typename F> + inline + mln_trait_op_times(F, graylevel_f) + operator*(const Floating<F>& lhs, const graylevel_f& rhs) + { + return rhs.value() * exact(lhs); + } + + + template <typename S> + inline + mln_trait_op_times(graylevel_f, S) + operator*(const graylevel_f& lhs, const scalar_<S>& rhs) + { + return lhs.value() * rhs.to_equiv(); + } + + template <typename S> + inline + mln_trait_op_div(graylevel_f, S) + operator/(const graylevel_f& lhs, const scalar_<S>& rhs) + { + mln_precondition(rhs.to_equiv() != S(0)); + return lhs.value() / rhs.to_equiv(); + } + + } // end of namespace mln::value + +} // end of namespace mln + + +#endif // ! MLN_VALUE_GRAYLEVEL_F_HXX diff --git a/milena/mln/value/internal/gray_f.hh b/milena/mln/value/internal/gray_f.hh index 79a443c..a24c2b5 100644 --- a/milena/mln/value/internal/gray_f.hh +++ b/milena/mln/value/internal/gray_f.hh @@ -1,4 +1,4 @@ -// Copyright (C) 2006, 2007, 2008, 2009, 2011 EPITA Research and +// Copyright (C) 2006, 2007, 2008, 2009, 2011, 2013 EPITA Research and // Development Laboratory (LRDE) // // This file is part of Olena. @@ -29,8 +29,7 @@
/// \file /// -/// Definition of the mln::value::gray_f class. - +/// Declarations of the mln::value::internal::gray_f class.
# include <iostream>
@@ -44,14 +43,28 @@ # include <mln/value/float01_f.hh> # include <mln/trait/value_.hh>
-# include <mln/value/graylevel_f.hh> +/* Because of mutual dependencies between the implementations of + mln::value::graylevel_f and mln::value::internal::gray_f, we have + to ensure that only the interfaces of the required classes are + included here. Implementations are included later, at the bottom of + this file. */ + +# ifdef MLN_INCLUDE_ONLY +# include <mln/value/graylevel_f.hh> +# else +# define MLN_INCLUDE_ONLY +# include <mln/value/graylevel_f.hh> +# undef MLN_INCLUDE_ONLY +# endif +
namespace mln {
namespace literal { - /// { Forward declarations. + /// Forward declarations. + /// { struct black_t; struct medium_gray_t; struct white_t; @@ -59,13 +72,16 @@ namespace mln } namespace value { - /// { Forward declarations. + /// Forward declarations. + /// { namespace internal { template <unsigned n> class gray_; struct gray_f; }
+ template <unsigned n> struct graylevel; + struct graylevel_f; struct float01_f; /// } } @@ -94,6 +110,7 @@ namespace mln typedef bool ret; };
+ /* FIXME: Dead code? */ // Necessary?? // template <typename F> // struct set_binary_< op::eq, @@ -204,297 +221,10 @@ namespace mln } // end of namespace mln
-# include <mln/value/internal/gray_.hh> - - -namespace mln -{ - - namespace value - { - - namespace internal - { - # ifndef MLN_INCLUDE_ONLY - - // gray_f. - - inline - gray_f::gray_f() - { - } - - inline - gray_f::gray_f(const gray_f& g) - : Floating<gray_f>() - { - this->v_ = g.v_; - } - - inline - gray_f& - gray_f::operator=(const gray_f& g) - { - this->v_ = g.v_; - return *this; - } - - template <unsigned n> - gray_f::gray_f(const gray_<n>& rhs) - { - static const float denom = float(metal::math::pow_int<2, n>::value) - 1.f; - this->v_ = float(rhs.value()) / denom; - } - - template <unsigned n> - gray_f& - gray_f::operator=(const gray_<n>& rhs) - { - static const float denom = float(metal::math::pow_int<2, n>::value) - 1.f; - this->v_ = float(rhs.value()) / denom; - return *this; - } - - inline - gray_f::gray_f(float val) - { - this->v_ = val; - } - - inline - gray_f& - gray_f::operator=(float val) - { - this->v_ = val; - return *this; - } - - inline - gray_f::gray_f(const graylevel_f& rhs) - { - this->v_ = rhs.value(); - } - - inline - gray_f& - gray_f::operator=(const graylevel_f& rhs) - { - this->v_ = rhs.value(); - return *this; - } - - template <unsigned m> - inline - gray_f::operator graylevel<m>() const - { - return graylevel<m>(int(round(this->v_ * (mlc_pow_int(2, m) - 1)))); - } - - - template <unsigned m> - inline - gray_f::operator gray_<m>() const - { - return gray_<m>(int(round(this->v_ * (mlc_pow_int(2, m) - 1)))); - } - - inline - gray_f::operator graylevel_f() const - { - return graylevel_f(this->v_); - } - - inline - float - gray_f::value() const - { - return this->v_; - } - - // Operators. - - inline - std::ostream& operator<<(std::ostream& ostr, const gray_f& g) - { - return ostr << g.value() << "/gl_f"; // FIXME: Be more explicit! - } - +# include <mln/value/internal/gray_f.hxx> +# include <mln/value/graylevel_f.hxx> # endif // ! MLN_INCLUDE_ONLY
- } // end of namespace mln::value::internal - - - // Graylevel_F operators. - - // Op glf == Int - - template <typename I> - inline - bool - operator==(const Integer<I>& lhs, const graylevel_f& rhs) - { - return rhs.value() == exact(lhs); - } - - // Op glf == glf - inline - bool - operator==(const graylevel_f& lhs, const graylevel_f& rhs) - { - return rhs.value() == lhs.value(); - } - - // Op glf + glf - inline - mln_trait_op_plus_(graylevel_f, graylevel_f) - operator+(const graylevel_f& lhs, const graylevel_f& rhs) - { - return lhs.value() + rhs.value(); - } - - // Op glf + gl<n> - template <unsigned n> - inline - mln_trait_op_plus(graylevel_f, graylevel<n>) - operator+(const graylevel_f& lhs, const graylevel<n>& rhs) - { - return lhs.value() + graylevel_f(rhs).value(); - } - - // Op gl<n> + glf - template <unsigned n> - inline - mln_trait_op_plus(graylevel_f, graylevel<n>) - operator+(const graylevel<n>& lhs, const graylevel_f& rhs) - { - return rhs.value() + graylevel_f(lhs).value(); - } - - - // Op glf + Another type - template <typename I> - inline - void - operator+(const graylevel_f& lhs, const I& i) - { - (void) lhs; - (void) i; - typename Object<I>::wrong_use_of_graylevel_f___Please_use_the__to_enc__method a; - } - - - // Op Another type + glf - template <typename I> - inline - void - operator+(const I& i, const graylevel_f& rhs) - { - (void) i; - (void) rhs; - typename Object<I>::wrong_use_of_graylevel_f___Please_use_the__to_enc__method a; - } - - - // Op glf - Another type - template <typename I> - inline - void - operator-(const graylevel_f& lhs, const I& i) - { - (void) lhs; - (void) i; - typename Object<I>::wrong_use_of_graylevel_f___Please_use_the__to_enc__method a; - } - - - // Op Another type - glf - template <typename I> - inline - void - operator-(const I& i, const graylevel_f& rhs) - { - (void) i; - (void) rhs; - typename Object<I>::wrong_use_of_graylevel_f___Please_use_the__to_enc__method a; - } - - // Op glf - glf - - inline - mln_trait_op_minus_(graylevel_f, graylevel_f) - operator-(const graylevel_f& lhs, const graylevel_f& rhs) - { - return lhs.value() - rhs.value(); - } - - // Op glf * glf - inline - mln_trait_op_times_(graylevel_f, graylevel_f) - operator*(const graylevel_f& lhs, const graylevel_f& rhs) - { - return lhs.value() * rhs.value(); - } - - // Op symm glf * Int - - template <typename I> - inline - mln_trait_op_times(graylevel_f, I) - operator*(const graylevel_f& lhs, const Integer<I>& rhs) - { - return lhs.value() * int(exact(rhs)); - } - - template <typename I> - inline - mln_trait_op_times(I, graylevel_f) - operator*(const Integer<I>& lhs, const graylevel_f& rhs) - { - return rhs.value() * int(exact(lhs)); - } - - // Op symm glf * Float - - template <typename F> - inline - mln_trait_op_times(graylevel_f, F) - operator*(const graylevel_f& lhs, const Floating<F>& rhs) - { - return lhs.value() * exact(rhs); - } - - template <typename F> - inline - mln_trait_op_times(F, graylevel_f) - operator*(const Floating<F>& lhs, const graylevel_f& rhs) - { - return rhs.value() * exact(lhs); - } - - - - // Op * scalar - template <typename S> - inline - mln_trait_op_times(graylevel_f, S) - operator*(const graylevel_f& lhs, const scalar_<S>& rhs) - { - return lhs.value() * rhs.to_equiv(); - } - - // Op / scalar - template <typename S> - inline - mln_trait_op_div(graylevel_f, S) - operator/(const graylevel_f& lhs, const scalar_<S>& rhs) - { - mln_precondition(rhs.to_equiv() != S(0)); - return lhs.value() / rhs.to_equiv(); - } - - } // end of namespace mln::value - -} // end of namespace mln
#endif // ! MLN_VALUE_INTERNAL_GRAY_F_HH diff --git a/milena/mln/value/internal/gray_f.hxx b/milena/mln/value/internal/gray_f.hxx new file mode 100644 index 0000000..c6863c3 --- /dev/null +++ b/milena/mln/value/internal/gray_f.hxx @@ -0,0 +1,160 @@ +// Copyright (C) 2006, 2007, 2008, 2009, 2011, 2013 EPITA Research and +// Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see http://www.gnu.org/licenses/. +// +// As a special exception, you may use this file as part of a free +// software project without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to produce +// an executable, this file does not by itself cause the resulting +// executable to be covered by the GNU General Public License. This +// exception does not however invalidate any other reasons why the +// executable file might be covered by the GNU General Public License. + +#ifndef MLN_VALUE_INTERNAL_GRAY_F_HXX +# define MLN_VALUE_INTERNAL_GRAY_F_HXX + +/// \file +/// +/// Definition of the mln::value::internal::gray_f class. + +# include <mln/value/internal/gray_f.hh> + +# include <mln/math/round.hh> + + +namespace mln +{ + + namespace value + { + + namespace internal + { + + // gray_f. + + inline + gray_f::gray_f() + { + } + + inline + gray_f::gray_f(const gray_f& g) + : Floating<gray_f>() + { + this->v_ = g.v_; + } + + inline + gray_f& + gray_f::operator=(const gray_f& g) + { + this->v_ = g.v_; + return *this; + } + + template <unsigned n> + gray_f::gray_f(const gray_<n>& rhs) + { + static const float denom = + float(metal::math::pow_int<2, n>::value) - 1.f; + this->v_ = float(rhs.value()) / denom; + } + + template <unsigned n> + gray_f& + gray_f::operator=(const gray_<n>& rhs) + { + static const float denom = + float(metal::math::pow_int<2, n>::value) - 1.f; + this->v_ = float(rhs.value()) / denom; + return *this; + } + + inline + gray_f::gray_f(float val) + { + this->v_ = val; + } + + inline + gray_f& + gray_f::operator=(float val) + { + this->v_ = val; + return *this; + } + + inline + gray_f::gray_f(const graylevel_f& rhs) + { + this->v_ = rhs.value(); + } + + inline + gray_f& + gray_f::operator=(const graylevel_f& rhs) + { + this->v_ = rhs.value(); + return *this; + } + + template <unsigned m> + inline + gray_f::operator graylevel<m>() const + { + return graylevel<m>(math::round<int>()(this->v_ + * (mlc_pow_int(2, m) - 1))); + } + + + template <unsigned m> + inline + gray_f::operator gray_<m>() const + { + return gray_<m>(math::round<int>()(this->v_ + * (mlc_pow_int(2, m) - 1))); + } + + inline + gray_f::operator graylevel_f() const + { + return graylevel_f(this->v_); + } + + inline + float + gray_f::value() const + { + return this->v_; + } + + // Operators. + + inline + std::ostream& operator<<(std::ostream& ostr, const gray_f& g) + { + return ostr << g.value() << "/gray_f"; // FIXME: Be more explicit! + } + + } // end of namespace mln::value::internal + + } // end of namespace mln::value + +} // end of namespace mln + +#endif // ! MLN_VALUE_INTERNAL_GRAY_F_HXX