Commit 9705761c authored by Thierry Geraud's avatar Thierry Geraud
Browse files

Various clean-ups + add line2d.

	Clean-up functions.

	* mln/fun/i2v,
	* mln/fun/p2b,
	* mln/fun/p2v,
	* mln/fun/v2v: New directories.
	* mln/fun/chess.hh: Rename as...
	* mln/fun/p2b/chess.hh: New.
	* mln/fun/to_enc.hh: Rename as...
	* mln/fun/v2v/enc.hh: ...this.
	(to_enc): Rename as...
	(enc): ...this.
	* mln/fun/all.hh: Rename as...
	* mln/fun/i2v/all.hh: ...this.
	* mln/core/point.hh,
	* mln/core/window.hh,
	* mln/core/dpoint.hh,
	* mln/core/image2d_b.hh,
	* mln/level/to_enc.hh: Update.

	Clean-up windows.
	
	* mln/core/win: New directory.
	* mln/core/hline2d.hh: Rename as...
	* mln/core/win/hline2d.hh: ...this.
	* mln/core/rectangle2d.hh: Rename as...
	* mln/core/win/rectangle2d.hh: ...this.
	* mln/core/vline2d.hh: Rename as...
	* mln/core/win/vline2d.hh: ...this.
	* tests/median.cc,
	* tests/fast_median.cc,
	* tests/main.cc,
	* tests/to_image.cc,
	* tests/psubset.cc,
	* tests/fimage.cc,
	* tests/rectangle2d.cc,
	* tests/cast_image.cc,
	* tests/subimage.cc,
	* tests/hmedian.cc,
	* tests/erosion.cc,
	* tests/naive_median.cc,
	* mln/core/box2d.hh,
	* mln/morpho/erosion.hh,
	* mln/level/was.median.hh,
	* mln/level/median.hh,
	* mln/level/approx/median.hh: Update.

	Clean-up metal.
	
	* mlc/equal.hh: Rename as...
	* mln/metal/equal.hh: ...this.
	* mlc/same_coord.hh: Rename as...
	* mln/metal/same_coord.hh: ...this.
	* mlc/same_point.hh: Rename as...
	* mln/metal/same_point.hh: ...this.
	* mlc: Remove.
	* mln/core/concept/generalized_point.hh: Update.

	Light changes.
	
	* TODO: Update.
	* mln/core/dpoints_piter.hh
	(dpoints_bkd_piter): New; fake.
	* mln/core/fimage.hh: Add doc.
	* mln/core/pvec.hh
	(pvec_fwd_piter_, pvec_bkd_piter_): Move to...
	* mln/core/pvec_piter.hh: ...this new file.
	* mln/core/internal/fixme.hh: Add empty body.

	New stuff.
	
	* tests/line2d.cc: New.
	* mln/pw/all.hh: New.
	* mln/core/line2d.hh: New.
	* mln/math: New.
	* mln/math/min.hh: New.
	* mln/math/abs.hh: New.
	* mln/math/max.hh: New.
	* mln/math/all.hh: New.
	* mln/math/sign.hh: New.
	* mln/draw: New.
	* mln/draw/line.hh: New.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@1040 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 21d11b8f
2007-07-26 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Various clean-ups + add line2d.
Clean-up functions.
* mln/fun/i2v,
* mln/fun/p2b,
* mln/fun/p2v,
* mln/fun/v2v: New directories.
* mln/fun/chess.hh: Rename as...
* mln/fun/p2b/chess.hh: New.
* mln/fun/to_enc.hh: Rename as...
* mln/fun/v2v/enc.hh: ...this.
(to_enc): Rename as...
(enc): ...this.
* mln/fun/all.hh: Rename as...
* mln/fun/i2v/all.hh: ...this.
* mln/core/point.hh,
* mln/core/window.hh,
* mln/core/dpoint.hh,
* mln/core/image2d_b.hh,
* mln/level/to_enc.hh: Update.
Clean-up windows.
* mln/core/win: New directory.
* mln/core/hline2d.hh: Rename as...
* mln/core/win/hline2d.hh: ...this.
* mln/core/rectangle2d.hh: Rename as...
* mln/core/win/rectangle2d.hh: ...this.
* mln/core/vline2d.hh: Rename as...
* mln/core/win/vline2d.hh: ...this.
* tests/median.cc,
* tests/fast_median.cc,
* tests/main.cc,
* tests/to_image.cc,
* tests/psubset.cc,
* tests/fimage.cc,
* tests/rectangle2d.cc,
* tests/cast_image.cc,
* tests/subimage.cc,
* tests/hmedian.cc,
* tests/erosion.cc,
* tests/naive_median.cc,
* mln/core/box2d.hh,
* mln/morpho/erosion.hh,
* mln/level/was.median.hh,
* mln/level/median.hh,
* mln/level/approx/median.hh: Update.
Clean-up metal.
* mlc/equal.hh: Rename as...
* mln/metal/equal.hh: ...this.
* mlc/same_coord.hh: Rename as...
* mln/metal/same_coord.hh: ...this.
* mlc/same_point.hh: Rename as...
* mln/metal/same_point.hh: ...this.
* mlc: Remove.
* mln/core/concept/generalized_point.hh: Update.
Light changes.
* TODO: Update.
* mln/core/dpoints_piter.hh
(dpoints_bkd_piter): New; fake.
* mln/core/fimage.hh: Add doc.
* mln/core/pvec.hh
(pvec_fwd_piter_, pvec_bkd_piter_): Move to...
* mln/core/pvec_piter.hh: ...this new file.
* mln/core/internal/fixme.hh: Add empty body.
New stuff.
* tests/line2d.cc: New.
* mln/pw/all.hh: New.
* mln/core/line2d.hh: New.
* mln/math: New.
* mln/math/min.hh: New.
* mln/math/abs.hh: New.
* mln/math/max.hh: New.
* mln/math/all.hh: New.
* mln/math/sign.hh: New.
* mln/draw: New.
* mln/draw/line.hh: New.
2007-07-25 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Add a label type and labeling.
......
......@@ -30,18 +30,19 @@ built-in op objects -> reverse lhs/rhs
mlc into metal
+ look for "same_grid" etc.
rectangle2d, hlin2d, etc -> core/win/
* clean-up
select_function in fun::internal::selector_p2? etc.
value::cast(something) -> mln::cast_image or mln::fun::casted<F> etc.
* processing routines
reconstructions + their canvases
fast versions of level::fill and level::paste
histogram class
sorting points w.r.t. their value (array of offsets, psites, points)
arith::inplace_plus et al.
linear:: for convolutions
......@@ -44,7 +44,7 @@ namespace mln
/*! \brief Type alias for a box defined on the 2D square grid with
* integer coordinates.
*
* \see mln::rectangle2d.
* \see mln::win::rectangle2d.
*/
typedef box_<point2d> box2d;
......
......@@ -31,9 +31,9 @@
/*! \file mln/core/concept/generalized_point.hh
* \brief Definition of the concept of mln::Generalized_Point.
*/
# include <mlc/equal.hh>
# include <mlc/same_point.hh>
# include <mlc/same_coord.hh>
# include <mln/metal/equal.hh>
# include <mln/metal/same_point.hh>
# include <mln/metal/same_coord.hh>
# include <mln/core/concept/object.hh>
# include <mln/core/internal/force_exact.hh>
......@@ -225,10 +225,10 @@ namespace mln
template <typename Pl, typename Pr>
bool operator==(const Generalized_Point<Pl>& lhs, const Generalized_Point<Pr>& rhs)
{
// FIXME: mlc::same_grid<Pl, Pr>::check();
// FIXME: metal::same_grid<Pl, Pr>::check();
const Pl& lhs_ = internal::force_exact<Pl>(lhs);
const Pr& rhs_ = internal::force_exact<Pr>(rhs);
mlc::same_point<Pl, Pr>::check();
metal::same_point<Pl, Pr>::check();
for (unsigned i = 0; i < Pl::dim; ++i)
if (lhs_[i] != rhs_[i])
return false;
......@@ -238,7 +238,7 @@ namespace mln
template <typename Pl, typename Pr>
bool operator<(const Generalized_Point<Pl>& lhs, const Generalized_Point<Pr>& rhs)
{
// FIXME: mlc::same_grid<Pl, Pr>::check();
// FIXME: metal::same_grid<Pl, Pr>::check();
const Pl& lhs_ = internal::force_exact<Pl>(lhs);
const Pr& rhs_ = internal::force_exact<Pr>(rhs);
for (unsigned i = 0; i < Pl::dim; ++i)
......@@ -254,9 +254,9 @@ namespace mln
mln_dpoint(Pl)
operator-(const Generalized_Point<Pl>& lhs, const Generalized_Point<Pr>& rhs)
{
mlc::equal<mln_dpoint(Pl), mln_dpoint(Pr)>::check();
// FIXME: mlc::same_grid<Pl, Pr>::check();
mlc::same_coord<Pl, Pr>::check();
metal::equal<mln_dpoint(Pl), mln_dpoint(Pr)>::check();
// FIXME: metal::same_grid<Pl, Pr>::check();
metal::same_coord<Pl, Pr>::check();
const Pl& lhs_ = internal::force_exact<Pl>(lhs);
const Pr& rhs_ = internal::force_exact<Pr>(rhs);
mln_dpoint(Pl) tmp;
......
......@@ -35,7 +35,7 @@
# include <mln/core/concept/dpoint.hh>
# include <mln/core/internal/coord_impl.hh>
# include <mln/fun/all.hh>
# include <mln/fun/i2v/all.hh>
namespace mln
......
......@@ -112,6 +112,12 @@ namespace mln
};
// FIXME:
template <typename D>
class dpoints_bkd_piter : public internal::fixme
{};
# ifndef MLN_INCLUDE_ONLY
template <typename D>
......
......@@ -102,6 +102,9 @@ namespace mln
/*! \brief FIXME
*
*/
template <typename F, typename S>
fimage<F,S>
operator | (const Function_p2v<F>& f, const Point_Set<S>& ps)
......
......@@ -39,7 +39,7 @@
# include <mln/border/thickness.hh>
# include <mln/value/set.hh>
# include <mln/fun/all.hh>
# include <mln/fun/i2v/all.hh>
// FIXME:
......
......@@ -45,7 +45,8 @@ namespace mln
*
* \internal
*/
struct fixme;
struct fixme
{};
} // end of namespace mln::internal
......
// 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_LINE2D_HH
# define MLN_CORE_LINE2D_HH
/*! \file mln/core/line2d.hh
*
* \brief Definition of a point set class based on std::vector.
*/
# include <vector>
# include <mln/core/concept/point_set.hh>
# include <mln/core/pvec_piter.hh>
# include <mln/core/box2d.hh>
# include <mln/math/all.hh>
namespace mln
{
/*! \brief 2D line point set class.
*/
class line2d : public Point_Set< line2d >
{
public:
/// Point associated type.
typedef point2d point;
/// Point_Site associated type.
typedef point2d psite;
/// Forward Point_Iterator associated type.
typedef pvec_fwd_piter_<point2d> fwd_piter;
/// Backward Point_Iterator associated type.
typedef pvec_bkd_piter_<point2d> bkd_piter;
/// Constructor from point \p beg to point \p end.
line2d(const point2d& beg, const point2d& end);
/// Test is \p p belongs to this point set.
bool has(const point2d& p) const;
/// Give the number of points.
std::size_t npoints() const;
/// Give the exact bounding box.
const box_<point2d>& bbox() const;
/// Append a point \p p.
line2d& append(const point2d& p);
/// Return the corresponding std::vector of points.
const std::vector<point2d>& vect() const;
/// Return the \p i-th point.
const point2d& operator[](unsigned i) const;
protected:
point2d beg_, end_;
std::vector<point2d> vect_;
box2d bb_;
void compute_();
};
# ifndef MLN_INCLUDE_ONLY
line2d::line2d(const point2d& beg, const point2d& end)
: beg_(beg),
end_(end)
{
compute_();
}
void
line2d::compute_()
{
// vect_
dpoint2d dp = end_ - beg_;
int
srow = math::sign(dp.row()), drow = math::abs(dp.row()), ddrow = 2 * drow,
scol = math::sign(dp.col()), dcol = math::abs(dp.col()), ddcol = 2 * dcol,
row = beg_.row(),
col = beg_.row();
if ( dcol > drow )
{
int e = ddrow - dcol;
for (int i = 0; i < dcol; ++i)
{
vect_.push_back(make::point2d(row, col));
while (e >= 0)
{
row += srow;
e -= ddcol;
}
col += scol;
e += ddrow;
}
}
else
{
int e = ddcol - drow;
for (int i = 0; i < drow; ++i)
{
vect_.push_back(make::point2d(row, col));
while (e >= 0)
{
col += scol;
e -= ddrow;
}
row += srow;
e += ddcol;
}
}
vect_.push_back(make::point2d(row, col));
// bb_
bb_.pmin() = make::point2d(math::min(beg_.row(), end_.row()),
math::min(beg_.col(), end_.col()));
bb_.pmax() = make::point2d(math::max(beg_.row(), end_.row()),
math::max(beg_.col(), end_.col()));
}
bool
line2d::has(const point2d& p) const
{
if (! bb_.has(p))
return false;
// FIXME: Optimize!
for (unsigned i = 0; i < vect_.size(); ++i)
if (vect_[i] == p)
return true;
return false;
}
std::size_t
line2d::npoints() const
{
return vect_.size();
}
const box2d&
line2d::bbox() const
{
return bb_;
}
const std::vector<point2d>&
line2d::vect() const
{
return vect_;
}
const point2d&
line2d::operator[](unsigned i) const
{
mln_precondition(i < npoints());
return vect_[i];
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
#endif // ! MLN_CORE_LINE2D_HH
......@@ -35,7 +35,7 @@
# include <mln/core/concept/point.hh>
# include <mln/core/internal/coord_impl.hh>
# include <mln/fun/all.hh>
# include <mln/fun/i2v/all.hh>
namespace mln
......
......@@ -36,7 +36,6 @@
# include <vector>
# include <mln/core/concept/point_set.hh>
# include <mln/core/internal/fixme.hh>
# include <mln/accu/bbox.hh>
......@@ -54,6 +53,8 @@ namespace mln
*
* \warning We have some troubles with point set comparison based on
* a call to npoints(). FIXME: Explain!
*
* \todo Make it work with P being a Point_Site.
*/
template <typename P>
class pvec : public Point_Set< pvec<P> >
......@@ -61,7 +62,7 @@ namespace mln
public:
/// Point associated type.
typedef mln_point(P) point;
typedef P point;
/// Point_Site associated type.
typedef P psite;
......@@ -70,7 +71,7 @@ namespace mln
typedef pvec_fwd_piter_<P> fwd_piter;
/// Backward Point_Iterator associated type.
typedef internal::fixme bkd_piter;
typedef pvec_bkd_piter_<P> bkd_piter;
/// Constructor.
pvec();
......@@ -85,7 +86,7 @@ namespace mln
std::size_t npoints() const;
/// Give the exact bounding box.
const box_<point>& bbox() const;
const box_<P>& bbox() const;
/// Append a point \p p.
pvec<P>& append(const P& p);
......@@ -111,65 +112,8 @@ namespace mln
/*! \brief Forward iterator on points of a pvec<P>.
*
*/
template <typename P>
struct pvec_fwd_piter_
{
enum { dim = P::dim };
/// Point_Site associated type.
typedef P psite;
/// Point associated type.
typedef mln_point(P) point;
/// Dpoint associated type.
typedef mln_dpoint(P) dpoint;
/// Coordinate associated type.
typedef mln_coord(P) coord;
/// Coordinate associated type.
template <typename S>
pvec_fwd_piter_(const Point_Set<S>& s);
/// Give a hook to the point address.
const point* pointer_() const;
/// Read-only access to the \p i-th coordinate.
coord operator[](unsigned i) const;
/// Test if the iterator is valid.
bool is_valid() const;
/// Invalidate the iterator.
void invalidate();
/// Start an iteration.
void start();
/// Go to the next point.
void next_();
/// Convert the iterator into a point.
operator P() const;
protected:
const std::vector<P>& vect_;
point p_;
};
# ifndef MLN_INCLUDE_ONLY
// pvec<P>
template <typename P>
pvec<P>::pvec()
{
......@@ -211,7 +155,7 @@ namespace mln
}
template <typename P>
const box_<mln_point(P)>&
const box_<P>&
pvec<P>::bbox() const
{
mln_precondition(npoints() != 0);
......@@ -251,73 +195,12 @@ namespace mln
return vect_[i];
}
// pvec_fwd_piter_<P>
template <typename P>
template <typename S>
pvec_fwd_piter_<P>::pvec_fwd_piter_(const Point_Set<S>& s)
: vect_(exact(s).vect())
{
invalidate();
}
template <typename P>
const mln_point(P)*
pvec_fwd_piter_<P>::pointer_() const
{
return & p_;
}
template <typename P>
mln_coord(P)
pvec_fwd_piter_<P>::operator[](unsigned i) const
{
mln_precondition(i < dim);
mln_precondition(is_valid());
return p_[i];
}
template <typename P>
bool
pvec_fwd_piter_<P>::is_valid() const
{
return i < vect_.size();
}
template <typename P>
void
pvec_fwd_piter_<P>::invalidate()
{
i = vect_.size();
}
template <typename P>
void
pvec_fwd_piter_<P>::start()
{
i = 0;
}
template <typename P>
void
pvec_fwd_piter_<P>::next_()
{
++i;
}
template <typename P>
pvec_fwd_piter_<P>::operator P() const
{
mln_precondition(is_valid());
return p_;
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
# include <mln/core/pvec_piter.hh>
#endif // ! MLN_CORE_PVEC_HH
......@@ -25,146 +25,143 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
#ifndef MLN_CORE_HLINE2D_HH
# define MLN_CORE_HLINE2D_HH