Commit 7e1da0e6 authored by Thierry Geraud's avatar Thierry Geraud
Browse files

Clean-up windows!

	* mln/core/internal/dpoints_base.hh: New.
	* mln/core/concept/doc/weighted_window.hh: New.
	* mln/core/w_window.hh
	(element, nelements): Rename as...
	(dp, ndpoints): ...these.
	(sym_): Add body.
	Update.
	* mln/core/window.hh (super_): Update.
	(qiter): Remove; obsolete.
	(point, dpoint, is_centered, delta): Remove; factored.
	* mln/core/dpoints_pixter.hh: Update.
	* mln/core/concept/weighted_window.hh
	(is_symmetric): Remove; too ambiguous.
	* mln/core/win/vline2d.hh: Update inheritance.
	* mln/core/win/hline2d.hh: Likewise.
	* mln/core/win/rectangle2d.hh: Likewise.
	(qiter): Remove; obsolete.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@1045 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent dc84877e
2007-07-27 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Clean-up windows!
* mln/core/internal/dpoints_base.hh: New.
* mln/core/concept/doc/weighted_window.hh: New.
* mln/core/w_window.hh
(element, nelements): Rename as...
(dp, ndpoints): ...these.
(sym_): Add body.
Update.
* mln/core/window.hh (super_): Update.
(qiter): Remove; obsolete.
(point, dpoint, is_centered, delta): Remove; factored.
* mln/core/dpoints_pixter.hh: Update.
* mln/core/concept/weighted_window.hh
(is_symmetric): Remove; too ambiguous.
* mln/core/win/vline2d.hh: Update inheritance.
* mln/core/win/hline2d.hh: Likewise.
* mln/core/win/rectangle2d.hh: Likewise.
(qiter): Remove; obsolete.
2007-07-27 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Add weighted windows and related tools + a generic convolution.
......
// 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.
/*! \file mln/core/concept/doc/weighted_window.hh
* \brief This file documents the concept of mln::Weighted_Window.
*/
namespace mln
{
namespace doc
{
/*! \brief Documentation class for mln::Weighted_Window.
*
* A weighted_window is the definition of a set of points located
* around a central point, with a weight associated to each point.
*
* \see mln::Weighted_Window
*/
template <typename E>
struct Weighted_Window : public Object<E>
{
/*! \brief Point_Iterator type associated to this weighted_window to browse its
* points in a forward way.
*/
typedef void fwd_qiter;
/*! \brief Point_Iterator type associated to this weighted_window to browse its
* points in a backward way.
*/
typedef void bkd_qiter;
/*! \brief Test if the weighted window is empty.
*
* A weighted_window of null size is empty.
*/
bool is_empty() const;
/*! \brief Test if the weighted_window is centered.
*
* A weighted window is centered is the origin belongs to it.
*/
bool is_centered() const;
/*! \brief Give the maximum coordinate gap between the window
center and a window point.
*/
unsigned delta() const;
/*! \brief Give the symmetrical weighted_window.
*/
E sym_() const;
};
} // end of namespace mln::doc
} // end of namespace mln
......@@ -50,30 +50,30 @@ namespace mln
struct Weighted_Window : public Object<E>
{
/*
typedef fwd_qiter;
typedef bkd_piter;
typedef point;
typedef dpoint;
typedef fwd_qiter;
typedef bkd_qiter;
E sym_() const;
*/
/// Test if the weighted window is empty; final method.
bool is_empty() const
{
return exact(this)->window().is_empty();
}
/// Test if the weighted window is centered; final method.
bool is_centered() const
{
return exact(this)->window().is_centered();
}
bool is_symmetric() const
{
return exact(this)->window().is_symmetric();
}
// FIXME: Remove because too ambiguous: bool is_symmetric() const
/// Give the maximum coordinate gap.
unsigned delta() const
{
return exact(this)->window().delta();
......@@ -84,7 +84,7 @@ namespace mln
};
/*! \brief Compute the symmetrical weighted_window of \p rhs.
/*! \brief Compute the symmetrical weighted window of \p rhs.
*
* \relates mln::Weighted_Window
*/
......
......@@ -170,12 +170,12 @@ namespace mln
void
dpoints_fwd_pixter<I>::init_(const Dps& dps)
{
for (unsigned i = 0; i < dps.nelements(); ++i)
offset_.push_back(this->image_.offset(dps.element(i)));
for (unsigned i = 0; i < dps.ndpoints(); ++i)
offset_.push_back(this->image_.offset(dps.dp(i)));
// offset_[0] is absolute
// other offsets are relative:
if (dps.nelements() > 1)
for (unsigned i = dps.nelements() - 1; i > 0; --i)
if (dps.ndpoints() > 1)
for (unsigned i = dps.ndpoints() - 1; i > 0; --i)
offset_[i] -= offset_[i - 1];
invalidate();
}
......
// 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_CORE_INTERNAL_DPOINTS_BASE_HH
# define MLN_CORE_INTERNAL_DPOINTS_BASE_HH
/*! \file mln/core/internal/dpoints_base_.hh
*
* \brief Definition of a base class for classes based on a set of dpoints.
*/
# include <mln/core/internal/set_of.hh>
# include <mln/fun/i2v/all.hh>
# include <mln/norm/infty.hh>
namespace mln
{
namespace internal
{
/*! \brief FIXME.
*/
template <typename D, typename E>
class dpoints_base_ : protected internal::set_of_<D>
{
typedef internal::set_of_<D> super_;
public:
/// Point associated type.
typedef mln_point(D) point;
/// Dpoint associated type.
typedef D dpoint;
/*! \brief Test if the window is centered.
*
* \return True if the delta-point 0 belongs to the window.
*/
bool is_centered() const;
/*! \brief Test if the window is empty (null size; no delta-point).
*/
bool is_empty() const;
/*! \brief Give the maximum coordinate gap between the window
center and a window point.
*/
unsigned delta() const;
/// Give the number of delta-points.
unsigned ndpoints() const;
/// Test if the delta-point \p dp belongs to the window.
bool has(const D& dp) const;
// Give the \p i-th delta-point.
const D& dp(unsigned i) const;
// Give the vector of delta-points.
const std::vector<D>& vect() const;
protected:
dpoints_base_();
};
# ifndef MLN_INCLUDE_ONLY
template <typename D, typename E>
dpoints_base_<D,E>::dpoints_base_()
{
}
template <typename D, typename E>
bool dpoints_base_<D,E>::is_centered() const
{
static const D origin = all(0);
return this->super_::has(origin);
}
template <typename D, typename E>
bool dpoints_base_<D,E>::is_empty() const
{
return this->super_::is_empty();
}
template <typename D, typename E>
unsigned dpoints_base_<D,E>::delta() const
{
unsigned d = 0;
const unsigned n = ndpoints();
for (unsigned i = 0; i < n; ++i)
{
unsigned dd = norm::infty(dp(i).to_vec());
if (dd > d)
d = dd;
}
return d;
}
template <typename D, typename E>
unsigned
dpoints_base_<D,E>::ndpoints() const
{
return this->super_::nelements();
}
template <typename D, typename E>
const D&
dpoints_base_<D,E>::dp(unsigned i) const
{
mln_precondition(i < ndpoints());
return this->element(i);
}
template <typename D, typename E>
const std::vector<D>&
dpoints_base_<D,E>::vect() const
{
return this->super_::vect();
}
template <typename D, typename E>
bool
dpoints_base_<D,E>::has(const D& dp) const
{
return this->super_::has(dp);
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace internal
} // end of namespace mln
#endif // ! MLN_CORE_INTERNAL_DPOINTS_BASE_HH
......@@ -62,21 +62,21 @@ namespace mln
/// Dpoint associated type.
typedef D dpoint;
/// Point_Iterator type to browse the points of a generic w_window.
/// Point_Iterator type to browse (forward) the points of a generic w_window.
typedef with_w_< dpoints_fwd_piter<D>, W > fwd_qiter;
/// Point_Iterator type to browse the points of a generic w_window.
/// Point_Iterator type to browse (backward) the points of a generic w_window.
typedef with_w_< dpoints_bkd_piter<D>, W > bkd_qiter;
/// Constructor without argument.
w_window_();
/// Give the corresponding window.
const window_<D>& window() const;
/// Give the symmetrical w_window.
w_window_<D,W> sym_() const;
/// Insert a delta-point \p d and its associated weight \p w.
w_window_<D,W>& insert(const D& d, const W& w);
/// Give the \p i-th weight.
W weight(unsigned i) const;
......@@ -84,17 +84,22 @@ namespace mln
/// Give access to the vector of weights.
const std::vector<W>& weights() const;
// Give the \p i-th delta-point.
const D& dp(unsigned i) const;
/// Give the number of delta-points.
unsigned ndpoints() const;
/// Give access to the vector of delta-points.
const std::vector<D>& vect() const;
/// Insert a delta-point \p d and its associated weight \p w.
w_window_<D,W>& insert(const D& d, const W& w);
/// Give the corresponding window.
const window_<D>& window() const;
/// Give the number of elements (pairs of delta-point/weight).
unsigned nelements() const;
// FIXME: Rename as dpoint(i); same in mln/core/dpoints_pixter.hh:174.
const D& element(unsigned i) const;
/// Give the symmetrical w_window.
w_window_<D,W> sym_() const;
protected:
......@@ -154,7 +159,7 @@ namespace mln
std::ostream& operator<<(std::ostream& ostr, const w_window_<D,W>& wwin)
{
ostr << '[';
for (unsigned i = 0; i < wwin.window().nelements(); ++i)
for (unsigned i = 0; i < wwin.window().ndpoints(); ++i)
ostr << wwin.vect()[i] << ':' << wwin.weight(i) << ' ';
return ostr << ']';
}
......@@ -172,34 +177,34 @@ namespace mln
}
template <typename D, typename W>
const std::vector<D>&
w_window_<D,W>::vect() const
const D&
w_window_<D,W>::dp(unsigned i) const
{
return win_.vect();
mln_precondition(i < win_.ndpoints());
mln_invariant(wei_.size() == win_.ndpoints());
return win_.dp(i);
}
template <typename D, typename W>
const std::vector<W>&
w_window_<D,W>::weights() const
unsigned
w_window_<D,W>::ndpoints() const
{
return wei_;
mln_invariant(wei_.size() == win_.ndpoints());
return win_.ndpoints();
}
template <typename D, typename W>
unsigned
w_window_<D,W>::nelements() const
const std::vector<D>&
w_window_<D,W>::vect() const
{
mln_invariant(wei_.size() == win_.nelements());
return win_.nelements();
return win_.vect();
}
template <typename D, typename W>
const D&
w_window_<D,W>::element(unsigned i) const
const std::vector<W>&
w_window_<D,W>::weights() const
{
mln_precondition(i < wei_.size());
mln_invariant(wei_.size() == win_.nelements());
return win_.element(i);
return wei_;
}
template <typename D, typename W>
......@@ -207,7 +212,7 @@ namespace mln
w_window_<D,W>::weight(unsigned i) const
{
mln_precondition(i < wei_.size());
mln_invariant(wei_.size() == win_.nelements());
mln_invariant(wei_.size() == win_.ndpoints());
return wei_[i];
}
......@@ -215,24 +220,27 @@ namespace mln
w_window_<D,W>&
w_window_<D,W>::insert(const D& d, const W& w)
{
mln_invariant(wei_.size() == win_.ndpoints());
if (win_.has(d))
// no-op
return *this;
// memorization: d_i -> w_i
std::map<D, W> memo_wei_;
for (unsigned i = 0; i < win_.nelements(); ++i)
memo_wei_[win_.element(i)] = wei_[i];
for (unsigned i = 0; i < win_.ndpoints(); ++i)
memo_wei_[win_.dp(i)] = wei_[i];
// insertion of d and w:
win_.insert(d);
memo_wei_[d] = w;
// re-mapping: w_i <- d_i
wei_.resize(win_.nelements());
for (unsigned i = 0; i < win_.nelements(); ++i)
wei_[i] = memo_wei_[win_.element(i)];
wei_.resize(win_.ndpoints());
for (unsigned i = 0; i < win_.ndpoints(); ++i)
wei_[i] = memo_wei_[win_.dp(i)];
mln_invariant(wei_.size() == win_.ndpoints());
return *this;
}
......@@ -241,7 +249,8 @@ namespace mln
w_window_<D,W>
w_window_<D,W>::sym_() const
{
// FIXME
w_window_<D,W> tmp(*this);
tmp.win_ = - this->win_;
return *this;
}
......
......@@ -34,7 +34,7 @@
*/
# include <mln/core/concept/window.hh>
# include <mln/core/internal/set_of.hh>
# include <mln/core/internal/dpoints_base.hh>
# include <mln/core/dpoint2d.hh>
# include <mln/core/dpoints_piter.hh>
......@@ -55,7 +55,7 @@ namespace mln
* is defined with length = 5.
*/
struct hline2d : public Window< hline2d >,
public mln::internal::set_of_<dpoint2d>
public internal::dpoints_base_< dpoint2d, hline2d >
{
/// Point associated type.
typedef point2d point;
......
......@@ -34,7 +34,7 @@
*/
# include <mln/core/concept/window.hh>
# include <mln/core/internal/set_of.hh>
# include <mln/core/internal/dpoints_base.hh>
# include <mln/core/dpoint2d.hh>
# include <mln/core/dpoints_piter.hh>
......@@ -57,7 +57,7 @@ namespace mln
* is defined with height = 3 and width = 5.
*/
struct rectangle2d : public Window< rectangle2d >,
public mln::internal::set_of_<dpoint2d>
public internal::dpoints_base_< dpoint2d, rectangle2d >
{
/// Point associated type.
typedef point2d point;
......@@ -75,9 +75,6 @@ namespace mln
*/
typedef dpoints_bkd_piter<dpoint2d> bkd_qiter;
/*! \brief Same as fwd_qiter.
*/
typedef fwd_qiter qiter;
/*! \brief Constructor.
*
......@@ -88,6 +85,7 @@ namespace mln
*/
rectangle2d(unsigned height, unsigned width);
/*! \brief Test if the window is centered.
*
* \return True.
......
......@@ -34,7 +34,7 @@
*/
# include <mln/core/concept/window.hh>
# include <mln/core/internal/set_of.hh>
# include <mln/core/internal/dpoints_base.hh>
# include <mln/core/dpoint2d.hh>
# include <mln/core/dpoints_piter.hh>
......@@ -57,7 +57,7 @@ namespace mln
* is defined with length = 5.
*/
struct vline2d : public Window< vline2d >,
public mln::internal::set_of_<dpoint2d>
public internal::dpoints_base_< dpoint2d, vline2d >
{
/// Point associated type.
typedef point2d point;
......
......@@ -35,13 +35,11 @@
# include <mln/core/concept/window.hh>
# include <mln/core/concept/generalized_point.hh>
# include <mln/core/internal/set_of.hh>
# include <mln/core/internal/dpoints_base.hh>
# include <mln/core/dpoint.hh>
# include <mln/core/box.hh>
# include <mln/convert/to_dpoint.hh>
# include <mln/fun/i2v/all.hh>
# include <mln/norm/infty.hh>
namespace mln
......@@ -58,14 +56,11 @@ namespace mln
* parameter is \c D, type of delta-point.
*/
template <typename D>
struct window_ : public Window< window_<D> >,
public internal::set_of_<D>
class window_ : public Window< window_<D> >,
public internal::dpoints_base_<D, window_<D> >
{
/// Point associated type.
typedef mln_point(D) point;
/// Dpoint associated type.
typedef D dpoint;
typedef internal::dpoints_base_<D, window_<D> > super_;
public:
/*! \brief Point_Iterator type to browse the points of a generic window
* w.r.t. the ordering of delta-points.
......@@ -75,11 +70,7 @@ namespace mln
/*! \brief Point_Iterator type to browse the points of a generic window
* w.r.t. the reverse ordering of delta-points.
*/
typedef internal::fixme bkd_qiter;
/*! \brief Same as fwd_qiter.
*/