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

Make operations on windows more explicit.

	* mln/convert/to_std_set.hh: New.
	* mln/geom/sym.hh: New.
	* mln/geom/shift.hh: New.
	* mln/set: New directory.
	* mln/set/inter.hh: New.
	* mln/set/diff.hh: New.
	* mln/set/union.hh: New.
	* mln/set/sym_diff.hh: New.

	* mln/convert/to_image.hh: Typo.
	* mln/convert/to_window.hh (to_window): New overload.
	* mln/convert/to_dpoint.hh: Typo.
	* mln/core/w_window.hh (sym_): Rename as...
	(sym): ...this and update.
	* mln/core/window.hh: Likewise.
	(operator-): Remove the unary version.
	(operator+, operator-): Remove; now handle by...
	* mln/geom/shift.hh (shift): ...this.
	* mln/core/concept/weighted_window.hh: Update.
	(operator-): Remove.
	* mln/core/concept/window.hh: Likewise.
	* mln/core/concept/doc/weighted_window.hh,
	* mln/core/concept/doc/window.hh,
	* mln/core/win/vline2d.hh,
	* mln/core/win/hline2d.hh,
	* mln/core/win/rectangle2d.hh,
	* mln/morpho/includes.hh,
	* mln/morpho/closing.hh,
	* mln/morpho/opening.hh,
	* mln/level/was.median.hh,
	* mln/level/median.hh,
	* mln/level/fast_median.hh,
	* tests/rectangle2d.cc: Update.
	* mln/core/concept/value.hh: Fix warning.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@1062 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 45f9259e
2007-08-30 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Make operations on windows more explicit.
* mln/convert/to_std_set.hh: New.
* mln/geom/sym.hh: New.
* mln/geom/shift.hh: New.
* mln/set: New directory.
* mln/set/inter.hh: New.
* mln/set/diff.hh: New.
* mln/set/union.hh: New.
* mln/set/sym_diff.hh: New.
* mln/convert/to_image.hh: Typo.
* mln/convert/to_window.hh (to_window): New overload.
* mln/convert/to_dpoint.hh: Typo.
* mln/core/w_window.hh (sym_): Rename as...
(sym): ...this and update.
* mln/core/window.hh: Likewise.
(operator-): Remove the unary version.
(operator+, operator-): Remove; now handle by...
* mln/geom/shift.hh (shift): ...this.
* mln/core/concept/weighted_window.hh: Update.
(operator-): Remove.
* mln/core/concept/window.hh: Likewise.
* mln/core/concept/doc/weighted_window.hh,
* mln/core/concept/doc/window.hh,
* mln/core/win/vline2d.hh,
* mln/core/win/hline2d.hh,
* mln/core/win/rectangle2d.hh,
* mln/morpho/includes.hh,
* mln/morpho/closing.hh,
* mln/morpho/opening.hh,
* mln/level/was.median.hh,
* mln/level/median.hh,
* mln/level/fast_median.hh,
* tests/rectangle2d.cc: Update.
* mln/core/concept/value.hh: Fix warning.
2007-08-29 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Add morphological complementation.
......
......@@ -30,7 +30,7 @@
/*! \file mln/convert/to_dpoint.hh
*
* \brief Convertions to mln::Dpoint.
* \brief Conversions to mln::Dpoint.
*/
# include <mln/core/concept/generalized_point.hh>
......
......@@ -30,7 +30,7 @@
/*! \file mln/convert/to_image.hh
*
* \brief Convertions to mln::Image.
* \brief Conversions to mln::Image.
*/
# include <mln/core/image2d_b.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_CONVERT_TO_STD_SET_HH
# define MLN_CONVERT_TO_STD_SET_HH
/*! \file mln/convert/to_std_set.hh
*
* \brief Conversions to std::set.
*/
# include <set>
# include <algorithm>
# include <iterator>
# include <mln/core/window.hh>
namespace mln
{
namespace convert
{
/// Convert a window \p win into a std::set of delta-points.
template <typename W>
std::set<mln_dpoint(W)> to_std_set(const Window<W>& win);
# ifndef MLN_INCLUDE_ONLY
template <typename W>
std::set<mln_dpoint(W)> to_std_set(const Window<W>& win)
{
typedef mln_dpoint(W) D;
typedef mln_point(D) P;
std::set<D> s;
mln_qiter(W) q(exact(win), P::zero);
for_all(q)
s.insert(q - P::zero);
return s;
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::convert
} // end of namespace mln
#endif // ! MLN_CONVERT_TO_STD_SET_HH
......@@ -33,10 +33,14 @@
* \brief Conversions to mln::window.
*/
# include <set>
# include <mln/core/concept/dpoint.hh>
# include <mln/core/concept/neighborhood.hh>
# include <mln/core/window.hh>
# include <mln/pw/image.hh>
# include <mln/pw/cst.hh>
# include <mln/metal/is_a.hh>
namespace mln
......@@ -57,6 +61,10 @@ namespace mln
template <typename S, typename F>
window<mln_dpoint(S)> to_window(const Point_Set<S>& pset);
/// Convert an std::set \p s of delta-points into a window.
template <typename D>
window<D> to_window(const std::set<D>& s);
# ifndef MLN_INCLUDE_ONLY
......@@ -95,6 +103,17 @@ namespace mln
return to_window(pw::cst(true) | pset);
}
template <typename D>
window<D> to_window(const std::set<D>& s)
{
mln::metal::is_a<D, Dpoint>::check();
window<D> win;
for (typename std::set<D>::const_iterator i = s.begin();
i != s.end(); ++i)
win.insert(*i);
return win;
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::convert
......
......@@ -89,9 +89,9 @@ namespace mln
*/
const window& win() const;
/*! \brief Give the symmetrical weighted_window.
/*! \brief Apply a central symmetry to the target weighted window.
*/
E sym_() const;
E& sym();
};
} // end of namespace mln::doc
......
......@@ -81,9 +81,9 @@ namespace mln
*/
unsigned delta() const;
/*! \brief Give the symmetrical window.
/*! \brief Apply a central symmetry to the target window.
*/
E sym_() const;
E& sym();
};
} // end of namespace mln::doc
......
......@@ -115,7 +115,7 @@ namespace mln
template <typename T, typename S>
typename S::equiv
cast_(const T& dummy, const Value<S>& src)
cast_(const T&, const Value<S>& src)
{
return exact(src);
}
......
......@@ -58,7 +58,7 @@ namespace mln
typedef weight;
typedef window;
E sym_() const;
E& sym();
*/
/// Test if the weighted window is empty; final method.
......@@ -107,19 +107,13 @@ namespace mln
typedef mln_fwd_qiter(E) fwd_qiter;
typedef mln_bkd_qiter(E) bkd_qiter;
E (E::*m1)() const = & E::sym_;
E& (E::*m1)() = & E::sym;
m1 = 0;
const window& (E::*m2)() const = & E::win;
m2 = 0;
}
template <typename W>
W operator-(const Weighted_Window<W>& rhs)
{
return exact(rhs).sym_();
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
......
......@@ -39,6 +39,7 @@
namespace mln
{
/*! \brief Base class for implementation classes that are windows.
*
* \see mln::doc::Window for a complete documentation of this class
......@@ -61,7 +62,7 @@ namespace mln
unsigned delta() const;
E sym_() const;
E& sym();
*/
protected:
......@@ -69,22 +70,17 @@ namespace mln
};
/*! \brief Compute the symmetrical window of \p rhs.
*
* \relates mln::Window
*/
template <typename W>
W operator-(const Window<W>& rhs);
/*! \brief Equality comparison between windows \p lhs and \p rhs.
*
* \relates mln::Window
*
* \todo Move into mln/set/compare.hh and delegate to replace this special impl.
*/
template <typename Wl, typename Wr>
bool operator==(const Window<Wl>& lhs, const Window<Wr>& rhs);
# ifndef MLN_INCLUDE_ONLY
template <typename E>
......@@ -105,14 +101,8 @@ namespace mln
m3 = 0;
unsigned (E::*m4)() const = & E::delta;
m4 = 0;
E (E::*m_)() const = & E::sym_;
m_ = 0;
}
template <typename W>
W operator-(const Window<W>& rhs)
{
return exact(rhs).sym_();
E& (E::*m5)() = & E::sym;
m5 = 0;
}
template <typename Wl, typename Wr>
......
......@@ -104,8 +104,8 @@ namespace mln
const mln::window<D>& win() const;
/// Give the symmetrical w_window.
w_window<D,W> sym_() const;
/// Apply a central symmetry to the target window.
w_window<D,W>& sym();
protected:
......@@ -252,11 +252,13 @@ namespace mln
}
template <typename D, typename W>
w_window<D,W>
w_window<D,W>::sym_() const
w_window<D,W>&
w_window<D,W>::sym()
{
w_window<D,W> tmp(*this);
tmp.win_ = - this->win_;
w_window<D,W> tmp;
for (unsigned i = 0; i < this->ndpoints(); ++i)
tmp.insert(this->w(i), this->dp(i));
*this = tmp;
return *this;
}
......
......@@ -106,8 +106,8 @@ namespace mln
*/
unsigned delta() const;
/// Get the symmetrical window.
hline2d sym_() const;
/// Apply a central symmetry to the target window.
hline2d& sym();
protected:
unsigned length_;
......@@ -159,7 +159,7 @@ namespace mln
return length_ / 2;
}
hline2d hline2d::sym_() const
hline2d& hline2d::sym()
{
return *this;
}
......
......@@ -111,8 +111,8 @@ namespace mln
*/
unsigned delta() const;
/// Get the symmetrical window.
rectangle2d sym_() const;
/// Apply a central symmetry to the target window.
rectangle2d& sym();
protected:
unsigned height_, width_;
......@@ -171,7 +171,7 @@ namespace mln
return width_ > height_ ? width_ / 2 : height_ / 2;
}
rectangle2d rectangle2d::sym_() const
rectangle2d& rectangle2d::sym()
{
return *this;
}
......
......@@ -108,8 +108,8 @@ namespace mln
*/
unsigned delta() const;
/// Get the symmetrical window.
vline2d sym_() const;
/// Apply a central symmetry to the target window.
vline2d& sym();
protected:
unsigned length_;
......@@ -161,7 +161,7 @@ namespace mln
return length_ / 2;
}
vline2d vline2d::sym_() const
vline2d& vline2d::sym()
{
return *this;
}
......
......@@ -40,6 +40,7 @@
# include <mln/core/box.hh>
# include <mln/convert/to_dpoint.hh>
# include <mln/geom/sym.hh>
namespace mln
......@@ -87,8 +88,8 @@ namespace mln
/// Insert a delta-point \p dp.
window<D>& insert(const D& dp);
/// Give the symmetrical window.
window<D> sym_() const;
/// Apply a central symmetry to the target window.
window<D>& sym();
protected:
......@@ -96,24 +97,6 @@ namespace mln
};
// FIXME: Move both ops below to mln/core/concept/window.hh
/// Shift a window \p win with a delta-point \p dp.
template <typename W>
window<mln_dpoint(W)> operator+(const Window<W>& win,
const mln_dpoint(W)& dp);
/// Shift a window \p win with the delta-point (-\p dp).
template <typename W>
window<mln_dpoint(W)> operator-(const Window<W>& win,
const mln_dpoint(W)& dp);
/// Substract \p rhs from \p lhs.
// FIXME: Give details!
template <typename Wl, typename Wr>
window<mln_dpoint(Wl)> operator-(const Window<Wl>& lhs,
const Window<Wr>& rhs);
# ifndef MLN_INCLUDE_ONLY
......@@ -128,7 +111,7 @@ namespace mln
template <typename D>
bool window<D>::is_symmetric() const
{
return this->sym_() == *this;
return geom::sym(*this) == *this;
}
template <typename D>
......@@ -141,52 +124,15 @@ namespace mln
}
template <typename D>
window<D>
window<D>::sym_() const
window<D>&
window<D>::sym()
{
window<D> tmp;
const unsigned n = this->ndpoints();
for (unsigned i = 0; i < n; ++i)
tmp.insert(- this->dp(i));
return tmp;
}
// operators
template <typename W>
window<mln_dpoint(W)> operator+(const Window<W>& win,
const mln_dpoint(W)& dp)
{
typedef mln_point(W) P;
window<mln_dpoint(W)> tmp;
mln_qiter(W) q(win, P::zero);
for_all(q)
tmp.insert(convert::to_dpoint(q) + dp);
return tmp;
}
template <typename W>
window<mln_dpoint(W)> operator-(const Window<W>& win,
const mln_dpoint(W)& dp)
{
return win + (-dp);
}
template <typename W, typename Wr>
window<mln_dpoint(W)> operator-(const Window<W>& lhs,
const Window<Wr>& rhs)
{
typedef mln_point(W) P;
window<mln_dpoint(W)> tmp;
mln_qiter(W) q(lhs, P::zero);
for_all(q)
{
mln_dpoint(W) dp = convert::to_dpoint(q);
if (! exact(rhs).has(dp))
tmp.insert(dp);
}
return tmp;
*this = tmp;
return *this;
}
# 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_GEOM_SHIFT_HH
# define MLN_GEOM_SHIFT_HH
/*! \file mln/geom/shift.hh
*
* \brief Shift.
*/
# include <mln/core/window.hh>
namespace mln
{
namespace geom
{
/// Shift a window \p win with a delta-point \p dp.
template <typename W>
window<mln_dpoint(W)>
shift(const Window<W>& win, const mln_dpoint(W)& dp);
# ifndef MLN_INCLUDE_ONLY
template <typename W>
window<mln_dpoint(W)>
shift(const Window<W>& win, const mln_dpoint(W)& dp)
{
typedef mln_point(W) P;
window<mln_dpoint(W)> tmp;
mln_qiter(W) q(win, P::zero);
for_all(q)
tmp.insert(convert::to_dpoint(q) + dp);
return tmp;
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::geom
} // end of namespace mln
#endif // ! MLN_GEOM_SHIFT_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_GEOM_SYM_HH
# define MLN_GEOM_SYM_HH
/*! \file mln/geom/sym.hh
*
* \brief Give the symmetrical object.
*/
# include <mln/core/concept/window.hh>
namespace mln
{
namespace geom
{
/*! \brief Give the symmetrical window