Commit c54f5439 authored by Thierry Geraud's avatar Thierry Geraud
Browse files

Add delta to windows in mln.

	* tests/erosion.cc: New.
	* mln/arith/minus.hh: New.
	* mln/core/point.hh,
	* mln/core/dpoint.hh (vec_t, to_vec): New.
	* mln/core/rectangle2d.hh,
	* mln/core/concept/window.hh,
	* mln/core/concept/doc/window.hh,
	* mln/core/window.hh (delta): New.
	* mln/level/fill.hh: New overload.
	* mln/norm: New.
	* mln/norm/infty.hh: New.
	* mln/accu/min.hh: New.
	* mln/accu/sum.hh: New.
	* mln/accu/max.hh: New.

	* tests/window2d.cc: Use delta.
	* tests/box2d.cc: Add assertion.
	* tests/dpoint2d.cc: Test to_vec.
	* mln/morpho/erosion.hh: Add dispatch.
	* mln/accu/mean.hh: Rewrite.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@1016 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent b5211ced
2007-07-17 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Add delta to windows in mln.
* tests/erosion.cc: New.
* mln/arith/minus.hh: New.
* mln/core/point.hh,
* mln/core/dpoint.hh (vec_t, to_vec): New.
* mln/core/rectangle2d.hh,
* mln/core/concept/window.hh,
* mln/core/concept/doc/window.hh,
* mln/core/window.hh (delta): New.
* mln/level/fill.hh: New overload.
* mln/norm: New.
* mln/norm/infty.hh: New.
* mln/accu/min.hh: New.
* mln/accu/sum.hh: New.
* mln/accu/max.hh: New.
* tests/window2d.cc: Use delta.
* tests/box2d.cc: Add assertion.
* tests/dpoint2d.cc: Test to_vec.
* mln/morpho/erosion.hh: Add dispatch.
* mln/accu/mean.hh: Rewrite.
2007-07-17 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Introduce accumulators and point-wise operations in mln.
......
// 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_ACCU_MAX_HH
# define MLN_ACCU_MAX_HH
/*! \file mln/accu/max.hh
*
* \brief Define an accumulator that computes a max.
*/
# include <mln/core/concept/accumulator.hh>
# include <mln/value/props.hh>
namespace mln
{
namespace accu
{
/*! Generic max accumulator class.
*
* The parameter \c V is the type of values.
*/
template <typename V>
struct max : public Accumulator< max<V> >
{
typedef V value;
max();
void take(const value& v);
void init();
operator V() const;
V to_value() const;
protected:
V v_;
};
# ifndef MLN_INCLUDE_ONLY
template <typename V>
max<V>::max()
{
init();
}
template <typename V>
void max<V>::take(const value& v)
{
if (v > v_)
v_ = v;
}
template <typename V>
void
max<V>::init()
{
v_ = mln_min(V);
}
template <typename V>
max<V>::operator V() const
{
return v_;
}
template <typename V>
V
max<V>::to_value() const
{
return v_;
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::accu
} // end of namespace mln
#endif // ! MLN_ACCU_MAX_HH
......@@ -33,7 +33,8 @@
* \brief Define an accumulator that computes a mean.
*/
# include <mln/core/concept/accumulator.hh>
# include <mln/accu/counter.hh>
# include <mln/accu/sum.hh>
namespace mln
......@@ -64,8 +65,8 @@ namespace mln
protected:
std::size_t count_;
S sum_;
accu::counter<V> count_;
accu::sum<V,S> sum_;
};
......@@ -81,16 +82,16 @@ namespace mln
template <typename V, typename S, typename M>
void mean<V,S,M>::take(const value& v)
{
++count_;
sum_ += v;
count_.take(v);
sum_.take(v);
}
template <typename V, typename S, typename M>
void
mean<V,S,M>::init()
{
count_ = 0;
sum_ = 0;
count_.init();
sum_.init();
}
template <typename V, typename S, typename M>
......@@ -103,7 +104,7 @@ namespace mln
M
mean<V,S,M>::to_value() const
{
return sum_ / count_;
return sum_.to_value() / count_.to_value();
}
# endif // ! MLN_INCLUDE_ONLY
......
// 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_ACCU_MIN_HH
# define MLN_ACCU_MIN_HH
/*! \file mln/accu/min.hh
*
* \brief Define an accumulator that computes a min.
*/
# include <mln/core/concept/accumulator.hh>
# include <mln/value/props.hh>
namespace mln
{
namespace accu
{
/*! Generic min accumulator class.
*
* The parameter \c V is the type of values.
*/
template <typename V>
struct min : public Accumulator< min<V> >
{
typedef V value;
min();
void take(const value& v);
void init();
operator V() const;
V to_value() const;
protected:
V v_;
};
# ifndef MLN_INCLUDE_ONLY
template <typename V>
min<V>::min()
{
init();
}
template <typename V>
void min<V>::take(const value& v)
{
if (v < v_)
v_ = v;
}
template <typename V>
void
min<V>::init()
{
v_ = mln_max(V);
}
template <typename V>
min<V>::operator V() const
{
return v_;
}
template <typename V>
V
min<V>::to_value() const
{
return v_;
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::accu
} // end of namespace mln
#endif // ! MLN_ACCU_MIN_HH
// 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_ACCU_SUM_HH
# define MLN_ACCU_SUM_HH
/*! \file mln/accu/sum.hh
*
* \brief Define an accumulator that computes a sum.
*/
# include <mln/core/concept/accumulator.hh>
namespace mln
{
namespace accu
{
/*! Generic sum accumulator class.
*
* Parameter \c V is the type of values that we sum. Parameter \c
* S is the type to store the sum value; the default type of
* \c S is \c V.
*/
template <typename V, typename S = V>
struct sum : public Accumulator< sum<V,S> >
{
typedef V value;
sum();
void take(const value& v);
void init();
operator S() const;
S to_value() const;
protected:
S sum_;
};
# ifndef MLN_INCLUDE_ONLY
template <typename V, typename S>
sum<V,S>::sum()
{
init();
}
template <typename V, typename S>
void sum<V,S>::take(const value& v)
{
sum_ += v;
}
template <typename V, typename S>
void
sum<V,S>::init()
{
sum_ = 0;
}
template <typename V, typename S>
sum<V,S>::operator S() const
{
return to_value;
}
template <typename V, typename S>
S
sum<V,S>::to_value() const
{
return sum_ / count_;
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::accu
} // end of namespace mln
#endif // ! MLN_ACCU_SUM_HH
// 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_ARITH_MINUS_HH
# define MLN_ARITH_MINUS_HH
/*! \file mln/arith/minus.hh
*
* \brief Point-wise substraction between images.
*/
# include <mln/core/concept/image.hh>
namespace mln
{
namespace arith
{
/*! Point-wise substraction of images \p lhs and \p rhs.
*
* \param[in] lhs First operand image.
* \param[in] rhs Second operand image.
* \param[out] output The result image.
*
* \pre \p output.domain == \p lhs.domain == \p rhs.domain
*/
template <typename L, typename R, typename O>
void minus(const Image<L>& lhs, const Image<R>& rhs, Image<O>& output);
# ifndef MLN_INCLUDE_ONLY
template <typename L, typename R, typename O>
void minus(const Image<L>& lhs_, const Image<R>& rhs_, Image<O>& output_)
{
const L& lhs = exact(lhs_);
const R& rhs = exact(rhs_);
O& output = exact(output_);
mln_precondition(rhs.domain() == lhs.domain());
mln_precondition(output.domain() == lhs.domain());
mln_piter(I) p(output.domain());
for_all(p)
output(p) = lhs(p) - rhs(p);
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::arith
} // end of namespace mln
#endif // ! MLN_ARITH_MINUS_HH
......@@ -76,6 +76,11 @@ namespace mln
*/
bool is_symmetric() const;
/*! \brief Give the maximum coordinate gap between the window
center and a window point.
*/
unsigned delta() const;
/*! \brief Give the symmetrical window.
*/
E sym_() const;
......
......@@ -59,6 +59,8 @@ namespace mln
bool is_centered() const;
bool is_symmetric() const;
unsigned delta() const;
E sym_() const;
*/
......@@ -93,8 +95,10 @@ namespace mln
m2 = 0;
bool (E::*m3)() const = & E::is_symmetric;
m3 = 0;
E (E::*m4)() const = & E::sym_;
unsigned (E::*m4)() const = & E::delta;
m4 = 0;
E (E::*m_)() const = & E::sym_;
m_ = 0;
}
template <typename W>
......
......@@ -96,6 +96,14 @@ namespace mln
/// Null delta-point (all coordinates are 0).
static const dpoint_<n,C> zero;
const C* coords_() const { return coord_; }
/// Type of the array of coordinates.
typedef const C (&vec_t)[n];
/// Hook to coordinates.
vec_t to_vec() const { return coord_; }
protected:
C coord_[n];
};
......
......@@ -96,6 +96,13 @@ namespace mln
/// Origin point (all coordinates are 0).
static const point_<n,C> zero;
/// Type of the array of coordinates.
typedef const C (&vec_t)[n];
/// Hook to coordinates.
vec_t to_vec() const { return coord_; }
protected:
C coord_[n];
};
......
......@@ -107,6 +107,11 @@ namespace mln
*/
unsigned width() const;
/*! \brief Give the maximum coordinate gap between the window
* center and a window point.
*/
unsigned delta() const;
/// Get the symmetrical window.
rectangle2d sym_() const;
......@@ -162,6 +167,11 @@ namespace mln
return 2 * half_width_ + 1;
}
unsigned rectangle2d::delta() const
{
return half_width_ > half_height_ ? half_width_ : half_height_;
}
rectangle2d rectangle2d::sym_() const
{
return *this;
......
......@@ -41,6 +41,7 @@
# include <mln/convert/to_dpoint.hh>
# include <mln/fun/all.hh>
# include <mln/norm/infty.hh>
namespace mln
......@@ -97,6 +98,11 @@ namespace mln
*/
bool is_symmetric() const;
/*! \brief Give the maximum coordinate gap between the window
center and a window point.
*/
unsigned delta() const;
/// Give the symmetrical window.
window_<D> sym_() const;
......@@ -128,6 +134,8 @@ namespace mln
# ifndef MLN_INCLUDE_ONLY
// window_<D>
template <typename D>
window_<D>::window_()
{
......@@ -146,6 +154,20 @@ namespace mln
return this->sym_() == *this;
}
template <typename D>
unsigned window_<D>::delta() const
{
unsigned d = 0;
const unsigned n = this->nelements();
for (unsigned i = 0; i < n; ++i)
{
unsigned dd = norm::infty(this->element(i).to_vec());
if (dd > d)
d = dd;
}
return d;
}
template <typename D>