Commit 2ad0f111 authored by Matthieu Garrigues's avatar Matthieu Garrigues
Browse files

Rewrite graylevel types.


	* mln/value/gray.hh: Rename as...
	* mln/value/internal/gray_.hh: ...this. Gray_<n> is a graylevel
	encoded on n bits. It can represent value greater than pow(2, n).
	* mln/value/internal/gray_f.hh: New, gray_f is a graylevel encoded on
	a float. It can represent value greater than 1.
	* mln/value/glf.hh: New, alias to graylevel_f.
	* mln/value/graylevel.hh: graylevel<n> is a graylevel encoded on n
	bits. its interoperability type is gray_<n>.
	* mln/value/graylevel_f.hh: New. graylevel_f is a graylevel encoded on
	a float01_f.
	* tests/value/graylevel.cc: Unit tests on graylevel.
	* tests/value/graylevel_f.cc: Unit tests on graylevel_f.
	* tests/value/graylevel_f_full.cc: Full tests on graylevel_f.
	* tests/value/graylevel_full.cc: Full tests on graylevel.

	Misc.

	* mln/trait/value_.hh: (mln_trait_value_nature_) New,
	(mln_trait_value_quant_) new,
	(mln_trait_value_kind_) new.
	* mln/metal/math/max.hh: (mlc_max) New,
	(mlc_max_int) new.
	* tests/arith/revert_full.cc: Add a test on int_u8.
	* mln/accu/count.hh: Add a fixme to add an take without argument.
	* mln/core/fi_adaptor.hh: Disable a precondition because it doesn't
	work on rgb values.

git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@1620 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent dfbe6353
2007-12-19 Matthieu Garrigues <garrigues@lrde.epita.fr>
Rewrite graylevel types.
* mln/value/gray.hh: Rename as...
* mln/value/internal/gray_.hh: ...this. Gray_<n> is a graylevel
encoded on n bits. It can represent value greater than pow(2, n).
* mln/value/internal/gray_f.hh: New, gray_f is a graylevel encoded on
a float. It can represent value greater than 1.
* mln/value/glf.hh: New, alias to graylevel_f.
* mln/value/graylevel.hh: graylevel<n> is a graylevel encoded on n
bits. its interoperability type is gray_<n>.
* mln/value/graylevel_f.hh: New. graylevel_f is a graylevel encoded on
a float01_f.
* tests/value/graylevel.cc: Unit tests on graylevel.
* tests/value/graylevel_f.cc: Unit tests on graylevel_f.
* tests/value/graylevel_f_full.cc: Full tests on graylevel_f.
* tests/value/graylevel_full.cc: Full tests on graylevel.
Misc.
* mln/trait/value_.hh: (mln_trait_value_nature_) New,
(mln_trait_value_quant_) new,
(mln_trait_value_kind_) new.
* mln/metal/math/max.hh: (mlc_max) New,
(mlc_max_int) new.
* tests/arith/revert_full.cc: Add a test on int_u8.
* mln/accu/count.hh: Add a fixme to add an take without argument.
* mln/core/fi_adaptor.hh: Disable a precondition because it doesn't
work on rgb values.
2007-12-19 Guillaume Duhamel <guillaume.duhamel@lrde.epita.fr>
Add briefs to fill out user documentation.
......
......@@ -58,6 +58,7 @@ namespace mln
count_();
void init();
// FIXME : should we add a take() without argument?
void take(const argument&);
void take(const count_<T>& other);
......
......@@ -244,7 +244,7 @@ namespace mln
data_< fi_adaptor<I> >::sync_with_adaptee_()
{
mln_precondition(fi_ima_.isValid());
mln_precondition(fi_ima_.getBitsPerPixel() == 8 * sizeof(mln_value(I)));
//FIXME: doesnt work for rgb: mln_precondition(fi_ima_.getBitsPerPixel() == 8 * sizeof(mln_value(I)));
deallocate_();
b_ = make::box2d(fi_ima_.getHeight(),
......
......@@ -36,6 +36,8 @@
# include <mln/metal/bool.hh>
# include <mln/metal/int.hh>
# define mlc_max(X, Y) typename mln::metal::math::max< X, Y >::ret
# define mlc_max_int(x, y) mln::metal::math::max_int< x, y >::value
namespace mln
{
......
......@@ -45,8 +45,11 @@
# define mln_trait_value_nature(V) typename mln::trait::value_< V >::nature
# define mln_trait_value_nature_(V) mln::trait::value_< V >::nature
# define mln_trait_value_kind(V) typename mln::trait::value_< V >::kind
# define mln_trait_value_kind_(V) mln::trait::value_< V >::kind
# define mln_trait_value_quant(V) typename mln::trait::value_< V >::quant
# define mln_trait_value_quant_(V) mln::trait::value_< V >::quant
# define mln_nbits(V) mln::trait::value_< V >::nbits
......
// Copyright (C) 2007 EPITA Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
// of the GNU General Public License version 2 as published by the
// Free Software Foundation.
//
// This library 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 this library; see the file COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02111-1307, USA.
//
// As a special exception, you may use this file as part of a free
// software library 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_GLF_HH
# define MLN_VALUE_GLF_HH
/*! \file mln/value/glf.hh
*
* \brief Define the alias value::glf.
*/
# include <mln/value/graylevel_f.hh>
namespace mln
{
namespace value
{
/// Alias for 8 bit graylevel.
typedef graylevel_f glf;
} // end of namespace mln::value
} // end of namespace mln
#endif // ! MLN_VALUE_GLF_HH
This diff is collapsed.
// Copyright (C) 2006, 2007 EPITA Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
// of the GNU General Public License version 2 as published by the
// Free Software Foundation.
//
// This library 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 this library; see the file COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02111-1307, USA.
//
// As a special exception, you may use this file as part of a free
// software library 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_HH
# define MLN_VALUE_GRAYLEVEL_F_HH
/*! \file mln/value/graylevel_f.hh
*
* \brief Definition of the mln::value::graylevel_f class.
*/
# include <iostream>
# include <mln/value/ops.hh>
# include <mln/core/contract.hh>
# include <mln/metal/math/pow.hh>
# include <mln/metal/bexpr.hh>
# include <mln/literal/ops.hh>
# include <mln/value/float01_f.hh>
# include <mln/value/internal/gray_.hh>
# include <mln/trait/value_.hh>
namespace mln
{
namespace literal
{
/// \{ Fwd decls.
struct black_t;
struct medium_gray_t;
struct white_t;
/// \}
}
namespace value
{
/// \{ Fwd decls.
namespace internal {class gray_f; }
struct graylevel_f;
template <unsigned n> struct graylevel;
struct float01_f;
/// \}
}
namespace trait
{
template < template <class, class> class Name>
struct set_precise_binary_< Name, mln::value::graylevel_f, mln::value::graylevel_f >
{
typedef mln::value::internal::gray_f ret;
};
template <>
struct set_precise_binary_< op::greater, mln::value::graylevel_f, mln::value::graylevel_f >
{
typedef bool ret;
};
template <>
struct set_precise_binary_< op::eq, mln::value::graylevel_f, mln::value::graylevel_f >
{
typedef bool ret;
};
/// Forward declaration.
template <typename T> struct value_;
// 'graylevel_f' as a value.
template <>
struct value_<mln::value::graylevel_f>
{
private:
typedef mln::value::graylevel_f self_;
typedef mln::value::float01_f equiv_;
public:
enum {
nbits = mln_nbits(equiv_),
card = 0
};
typedef trait::value::nature::floating nature;
typedef trait::value::kind::gray kind;
typedef mln_trait_value_quant_(equiv_) quant;
static const equiv_ min() { return 0; }
static const equiv_ max() { return 1; }
static const equiv_ epsilon() { return mln_epsilon(equiv_); }
typedef float sum;
};
} // end of namespace mln::trait
namespace value
{
/// General gray-level class on n bits.
struct graylevel_f
:
public Floating< graylevel_f >,
public internal::value_like_< float01_f, // Equivalent.
mln_enc_(float01_f),// Encoding.
internal::gray_f, // Interoperation.
graylevel_f > // Exact.
{
/// Constructor without argument.
graylevel_f();
/// Copy constructor.
graylevel_f(const graylevel_f& rhs);
/// Assigment.
graylevel_f& operator=(const graylevel_f& rhs);
/// Constructor from float.
graylevel_f(float val);
/// Assigment with float.
graylevel_f& operator=(float val);
/// Constructor from graylevel.
template <unsigned n>
graylevel_f(const graylevel<n>& rhs);
/// Assigment with graylevel.
template <unsigned n>
graylevel_f& operator=(const graylevel<n>& rhs);
/// Ctors with literals.
/// \{
graylevel_f(const literal::black_t&);
graylevel_f(const literal::medium_gray_t&);
graylevel_f(const literal::white_t&);
/// \}
/// Assigment with literals.
/// \{
graylevel_f& operator=(const literal::black_t&);
graylevel_f& operator=(const literal::medium_gray_t&);
graylevel_f& operator=(const literal::white_t&);
/// \}
/// Access to std type.
float value() const;
};
// Operators.
/// Op<<.
std::ostream& operator<<(std::ostream& ostr, const graylevel_f& g);
# ifndef MLN_INCLUDE_ONLY
// graylevel_f.
inline
graylevel_f::graylevel_f()
{
}
inline
graylevel_f::graylevel_f(float val)
{
this->v_ = val;
}
inline
graylevel_f&
graylevel_f::operator=(float val)
{
this->v_ = val;
return *this;
}
template <unsigned n>
graylevel_f::graylevel_f(const graylevel<n>& rhs)
{
this->v_ = rhs.to_float();
}
template <unsigned n>
graylevel_f&
graylevel_f::operator=(const graylevel<n>& rhs)
{
this->v_ = rhs.to_float();
}
inline
graylevel_f::graylevel_f(const graylevel_f& rhs)
{
this->v_ = rhs.v_;
}
inline
graylevel_f&
graylevel_f::operator=(const graylevel_f& rhs)
{
this->v_ = rhs.v_;
return *this;
}
inline
graylevel_f::graylevel_f(const literal::black_t&)
{
this->v_ = 0.0f;
}
inline
graylevel_f&
graylevel_f::operator=(const literal::black_t&)
{
this->v_ = 0.0f;
return *this;
}
inline
graylevel_f::graylevel_f(const literal::medium_gray_t&)
{
this->v_ = 0.5f;
}
inline
graylevel_f&
graylevel_f::operator=(const literal::medium_gray_t&)
{
this->v_ = 0.5f;
return *this;
}
inline
graylevel_f::graylevel_f(const literal::white_t&)
{
this->v_ = 1.0f;
}
inline
graylevel_f&
graylevel_f::operator=(const literal::white_t&)
{
this->v_ = 1.0f;
return *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
} // end of namespace mln::value
} // end of namespace mln
#endif // ! MLN_VALUE_GRAYLEVEL_F_HH
// Copyright (C) 2006, 2007 EPITA Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
// of the GNU General Public License version 2 as published by the
// Free Software Foundation.
//
// This library 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 this library; see the file COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02111-1307, USA.
//
// As a special exception, you may use this file as part of a free
// software library 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_HH
# define MLN_VALUE_INTERNAL_GRAY_F_HH
/*! \file mln/value/internal/gray_f.hh
*
* \brief Definition of the mln::value::gray_f class.
*/
# include <iostream>
# include <mln/value/ops.hh>
# include <mln/core/contract.hh>
# include <mln/metal/math/pow.hh>
# include <mln/math/two_pow.hh>
# include <mln/metal/bexpr.hh>
# include <mln/literal/ops.hh>
# include <mln/value/float01_f.hh>
# include <mln/value/gray.hh>
# include <mln/trait/value_.hh>
namespace mln
{
namespace literal
{
/// \{ Fwd decls.
struct black_t;
struct medium_gray_t;
struct white_t;
/// \}
}
namespace value
{
/// \{ Fwd decls.
class gray;
struct gray_f;
struct float01_f;
/// \}
}
namespace trait
{
template < template <class, class> class Name>
struct set_precise_binary_< Name, mln::value::gray_f, mln::value::gray_f >
{
typedef mln::value::gray_f ret;
};
struct set_precise_binary_< op::greater, mln::value::gray_f, mln::value::gray_f >
{
typedef bool ret;
};
struct set_precise_binary_< op::eq, mln::value::gray_f, mln::value::gray_f >
{
typedef bool ret;
};
// Nessecary??
// template <typename F>
// struct set_binary_< op::eq,
// mln::value::Floating, mln::value::gray_f,
// mln::value::Floating, F >
// {
// typedef bool ret;
// };
/// Forward declaration.
template <typename T> struct value_;
// 'gray_f' as a value.
template <>
struct value_<mln::value::gray_f>
{
private:
typedef mln::value::gray_f self_;
typedef float equiv_;
public:
enum {
nbits = mln_nbits(equiv_),
card = 0
};
typedef trait::value::nature::floating nature;
typedef trait::value::kind::gray kind;
typedef mln_trait_value_quant_(equiv_) quant;
static const equiv_ min() { return 0; }
static const equiv_ max() { return 1; }
static const equiv_ epsilon() { return mln_epsilon(equiv_); }
typedef float sum;
};
} // end of namespace mln::trait
namespace value
{
namespace internal
{
/// \internal General gray-level class on n bits.
struct gray_f
:
public Floating< gray_f >,
public internal::value_like_< float, // Equivalent.
float, // Encoding.
gray_f, // Interoperation.
gray_f > // Exact.
{
/// Constructor without argument.
gray_f();
/// \{ Constructors/assigments with gray_f.
gray_f(const gray_f& rhs);
gray_f& operator=(const gray_f& rhs);
/// \}
/// \{ Constructors/assigments with float.
gray_f(float val);
gray_f& operator=(float val);
/// \}
/// \{ Constructors/assigments with graylevel_f.
gray_f(const graylevel_f& val);
gray_f& operator=(const graylevel_f& val);
/// \}
/// Convertion to graylevel<n>
template <unsigned m>
operator graylevel<m>() const;
/// Convertion to graylevel_f
operator graylevel_f() const;
/// Access to std type.
float value() const;
};
// Operators.
/// \internal Op<<.
std::ostream& operator<<(std::ostream& ostr, const gray_f& g);
# ifndef MLN_INCLUDE_ONLY
// gray_f.
inline
gray_f::gray_f()
{
}