Commit 8537be0a authored by Thierry Geraud's avatar Thierry Geraud
Browse files

Add subset notion in milena.

	Add materials.

	* mln/convert/to_image.hh: New.
	* mln/convert/to_window.hh: New.
	* mln/estim: New.
	* mln/estim/count.hh: New.
	* mln/debug/format.hh: New.
	* mln/geom: New.
	* mln/geom/pmin_pmax.hh: New.
	* mln/geom/bbox.hh: New.
	* mln/core/psubset.hh: New.
	* mln/core/psubset_piter.hh: New.
	* mln/core/concept/function.hh: New.
	* mln/core/internal/piter_adaptor.hh: New.
	* mln/fun/chess.hh: New.

	Add some tests.
	
	* tests/safe_image.cc: New.
	* tests/to_image.cc: New.
	* tests/psubset.cc: New.
	* tests/println.cc: New.
	
	Several improvements.
	
	* mln/debug/println.hh: Use debug::format.
	* mln/core/box.hh (len): Move...
	* mln/core/concept/box.hh: ...here.
	* mln/core/point.hh (zero): Turn into var.
	(point_): Bound ctor arg f.
	* mln/core/dpoint.hh: Likewise.
	* mln/core/neighb.hh (dpoint): New typedef.
	* mln/core/concept/image.hh: Remove obsolete commentary.
	* mln/core/concept/iterator.hh
	(for_all_remaining): New macro.
	* mln/core/concept/point_set.hh (operator<<): New.
	* mln/core/concept/neighborhood.hh
	(dpoint): Make it appear in commentary.
	* mln/core/concept/doc/neighborhood.hh (dpoint): New.
	* mln/core/concept/doc/box.hh: Cosmetics.
	* mln/core/window.hh (b_): New attribute.
	Update.
	* mln/core/image2d_b.hh (bbox): Remove; redundant.
	(at): New couple of methods.
	Update.
	* mln/core/internal/image_adaptor.hh: Fix.
	* mln/core/internal/image_base.hh: Add preconditions.
	* mln/core/internal/set_of.hh: Add a todo entry.
	* mln/core/safe_image.hh: Help g++-2.95.
	* mln/fun/all.hh: Add inheritance.
	
	Change mk_<object> into make::<object>.
	
	* mln/make: New directory.
	* mln/core/dpoint2d.hh (mk_dpoint2d): Move to...
	* mln/make/dpoint2d.hh: this new file.
	(mk_dpoint2d): Rename as...
	(dpoint2d): ...this.
	* mln/core/window2d.hh (mk_window2d): Move to...
	* mln/make/window2d.hh: this new file.
	(mk_window2d): Rename as...
	(window2d): ...this.
	* mln/core/box2d.hh (mk_box2d): Move to...
	* mln/make/box2d.hh: this new file.
	(mk_box2d): Rename as...
	(box2d): ...this.
	* mln/core/point2d.hh (mk_point2d): Move to...
	* mln/make/point2d.hh: this new file.
	(mk_point2d): Rename as...
	(point2d): ...this.
	* tests/window2d.cc,
	* tests/pixter_dpoint2d.cc,
	* tests/box2d.cc,
	* tests/point2d.cc,
	* tests/dpoint2d.cc,
	* tests/main.cc,
	* mln/core/neighb2d.hh,
	* mln/debug/println.hh,
	* mln/core/rectangle2d.hh,
	* mln/core/pixter2d_b.hh,
	* mln/io/save_pgm.hh,
	* mln/io/load_pgm.hh: Update.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@1010 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 5c0099f9
2007-07-13 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Add subset notion in milena.
Add materials.
* mln/convert/to_image.hh: New.
* mln/convert/to_window.hh: New.
* mln/estim: New.
* mln/estim/count.hh: New.
* mln/debug/format.hh: New.
* mln/geom: New.
* mln/geom/pmin_pmax.hh: New.
* mln/geom/bbox.hh: New.
* mln/core/psubset.hh: New.
* mln/core/psubset_piter.hh: New.
* mln/core/concept/function.hh: New.
* mln/core/internal/piter_adaptor.hh: New.
* mln/fun/chess.hh: New.
Add some tests.
* tests/safe_image.cc: New.
* tests/to_image.cc: New.
* tests/psubset.cc: New.
* tests/println.cc: New.
Several improvements.
* mln/debug/println.hh: Use debug::format.
* mln/core/box.hh (len): Move...
* mln/core/concept/box.hh: ...here.
* mln/core/point.hh (zero): Turn into var.
(point_): Bound ctor arg f.
* mln/core/dpoint.hh: Likewise.
* mln/core/neighb.hh (dpoint): New typedef.
* mln/core/concept/image.hh: Remove obsolete commentary.
* mln/core/concept/iterator.hh
(for_all_remaining): New macro.
* mln/core/concept/point_set.hh (operator<<): New.
* mln/core/concept/neighborhood.hh
(dpoint): Make it appear in commentary.
* mln/core/concept/doc/neighborhood.hh (dpoint): New.
* mln/core/concept/doc/box.hh: Cosmetics.
* mln/core/window.hh (b_): New attribute.
Update.
* mln/core/image2d_b.hh (bbox): Remove; redundant.
(at): New couple of methods.
Update.
* mln/core/internal/image_adaptor.hh: Fix.
* mln/core/internal/image_base.hh: Add preconditions.
* mln/core/internal/set_of.hh: Add a todo entry.
* mln/core/safe_image.hh: Help g++-2.95.
* mln/fun/all.hh: Add inheritance.
Change mk_<object> into make::<object>.
* mln/make: New directory.
* mln/core/dpoint2d.hh (mk_dpoint2d): Move to...
* mln/make/dpoint2d.hh: this new file.
(mk_dpoint2d): Rename as...
(dpoint2d): ...this.
* mln/core/window2d.hh (mk_window2d): Move to...
* mln/make/window2d.hh: this new file.
(mk_window2d): Rename as...
(window2d): ...this.
* mln/core/box2d.hh (mk_box2d): Move to...
* mln/make/box2d.hh: this new file.
(mk_box2d): Rename as...
(box2d): ...this.
* mln/core/point2d.hh (mk_point2d): Move to...
* mln/make/point2d.hh: this new file.
(mk_point2d): Rename as...
(point2d): ...this.
* tests/window2d.cc,
* tests/pixter_dpoint2d.cc,
* tests/box2d.cc,
* tests/point2d.cc,
* tests/dpoint2d.cc,
* tests/main.cc,
* mln/core/neighb2d.hh,
* mln/debug/println.hh,
* mln/core/rectangle2d.hh,
* mln/core/pixter2d_b.hh,
* mln/io/save_pgm.hh,
* mln/io/load_pgm.hh: Update.
2007-07-12 Nicolas Ballas <ballas@lrde.epita.fr>
Fix bug in pixter_dpoint2d.
......
// 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_IMAGE_HH
# define MLN_CONVERT_TO_IMAGE_HH
/*! \file mln/convert/to_image.hh
*
* \brief Convertions to mln::Image.
*/
# include <mln/core/image2d_b.hh>
# include <mln/core/concept/point_set.hh>
# include <mln/core/concept/window.hh>
# include <mln/core/concept/neighborhood.hh>
# include <mln/convert/to_window.hh>
# include <mln/geom/bbox.hh>
# include <mln/level/fill.hh>
namespace mln
{
namespace convert
{
/// Convert a point set \p pset into a binary image.
template <typename S>
image2d_b<bool> to_image(const Point_Set<S>& pset);
/// Convert a window \p win into a binary image.
template <typename W>
image2d_b<bool> to_image(const Window<W>& win);
/// Convert a neighborhood \p nbh into a binary image.
template <typename N>
image2d_b<bool> to_image(const Neighborhood<N>& nbh);
# ifndef MLN_INCLUDE_ONLY
template <typename S>
image2d_b<bool> to_image(const Point_Set<S>& pset_)
{
const S& pset = exact(pset_);
image2d_b<bool> ima(pset.bbox());
level::fill(ima, false);
mln_piter(S) p(pset);
for_all(p)
ima(p) = true;
return ima;
}
template <typename W>
image2d_b<bool> to_image(const Window<W>& win_)
{
const W& win = exact(win_);
mln_precondition(! win.is_empty());
typedef mln_point(W) P;
box2d b = geom::bbox(win);
image2d_b<bool> ima(b);
level::fill(ima, false);
mln_qiter(W) q(win, P::zero);
for_all(q)
ima(q) = true;
return ima;
}
template <typename N>
image2d_b<bool> to_image(const Neighborhood<N>& nbh)
{
return to_image(convert::to_window(nbh));
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::convert
} // end of namespace mln
#endif // ! MLN_CONVERT_TO_IMAGE_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_WINDOW_HH
# define MLN_CONVERT_TO_WINDOW_HH
/*! \file mln/convert/to_window.hh
*
* \brief Convertions to mln::Image.
*/
# include <mln/core/concept/neighborhood.hh>
# include <mln/core/window.hh>
namespace mln
{
namespace convert
{
/// Convert a neighborhood \p nbh into a window.
template <typename N>
window_<mln_dpoint(N)> to_window(const Neighborhood<N>& nbh);
# ifndef MLN_INCLUDE_ONLY
template <typename N>
window_<mln_dpoint(N)> to_window(const Neighborhood<N>& nbh_)
{
const N& nbh = exact(nbh_);
typedef mln_dpoint(N) D;
typedef mln_point(D) P;
window_<D> win;
mln_niter(N) n(nbh, P::zero);
for_all(n)
win.insert(n - P::zero);
return win;
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::convert
} // end of namespace mln
#endif // ! MLN_CONVERT_TO_WINDOW_HH
......@@ -90,11 +90,6 @@ namespace mln
*/
P& pmax();
/*! \brief Give the length of the \p i-th side.
* \pre i < dim
*/
unsigned len(unsigned i) const;
/*! \brief Constructor without argument.
*/
box_();
......@@ -157,14 +152,6 @@ namespace mln
return pmax_;
}
template <typename P>
unsigned
box_<P>::len(unsigned i) const
{
mln_precondition(i < P::dim);
return 1 + pmax_[i] - pmin_[i];
}
template <typename P>
box_<P>::box_()
{
......
......@@ -49,47 +49,10 @@ namespace mln
typedef box_<point2d> box2d;
/*! \brief Create an mln::box2d.
*
* \param[in] nrows Number of rows.
* \param[in] ncols Number of columns.
*
* \pre \p nrows != 0 and \p ncols != 0.
*
* \return A 2D box.
*/
box2d mk_box2d(unsigned nrows, unsigned ncols)
{
mln_precondition(nrows != 0 && ncols != 0);
box2d tmp(mk_point2d(0, 0),
mk_point2d(nrows - 1, ncols - 1));
return tmp;
}
} // end of namespace mln
/*! \brief Create an mln::box2d.
*
* \overload
*
* \param[in] min_row Index of the top most row.
* \param[in] max_row Index of the botton most row.
* \param[in] min_col Index of the left most column.
* \param[in] max_col Index of the right most column.
*
* \pre \p max_row >= \p min_row and \p max_col >= \p min_col.
*
* \return A 2D box.
*/
box2d mk_box2d(int min_row, int max_row,
int min_col, int max_col)
{
mln_precondition(max_row >= min_row && max_col >= min_col);
box2d tmp(mk_point2d(min_row, min_col),
mk_point2d(max_row, max_col));
return tmp;
}
} // end of namespace mln
# include <mln/make/box2d.hh>
#endif // ! MLN_CORE_BOX2D_HH
......@@ -52,10 +52,17 @@ namespace mln
/*
const point& pmin() const;
const point& pmax() const;
unsigned len(unsigned i) const; // FIXME: Doc!
*/
/*! \brief Return the bounding box of this point set.
/*! \brief Give the length of the \p i-th side of the box.
*
* \pre i < point::dim
*
* \warning This method is final for all box classes.
*/
unsigned len(unsigned i) const;
/*! \brief Give the bounding box of this point set.
*
* Return the bounding box of this point set, so that is itself.
* This method is declared by the mln::Point_Set concept.
......@@ -64,7 +71,7 @@ namespace mln
*/
const E& bbox() const;
/*! \brief Return the number of points of this box.
/*! \brief Give the number of points of this box.
*
* Return the number of points of this box. This method is
* declared by the mln::Point_Set concept.
......@@ -86,6 +93,12 @@ namespace mln
return exact(*this);
}
template <typename E>
unsigned Box<E>::len(unsigned i) const
{
return 1 + exact(this)->pmax()[i] - exact(this)->pmin()[i];
}
template <typename E>
Box<E>::Box()
{
......
......@@ -41,7 +41,7 @@ namespace mln
template <typename E>
struct Box : public Point_Set<E>
{
/*! \brief Return the box "minimum" point.
/*! \brief Give the box "minimum" point.
*
* Return the "minimum" point w.r.t. the ordering between points.
* For instance, with mln::box2d, this minimum is the top left
......@@ -49,7 +49,7 @@ namespace mln
*/
const point& pmin() const;
/*! \brief Return the box "maximum" point.
/*! \brief Give the box "maximum" point.
*
* Return the "maximum" point w.r.t. the ordering between points.
* For instance, with mln::box2d, this maximum is the bottom
......
......@@ -56,6 +56,9 @@ namespace mln
* neighbors in a backward way.
*/
typedef void bkd_niter;
/// Dpoint associated type.
typedef void dpoint;
};
} // end of namespace mln::doc
......
// 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_CONCEPT_FUNCTION_HH
# define MLN_CORE_CONCEPT_FUNCTION_HH
/*! \file mln/core/concept/function.hh
*
* \brief Definition of several concepts of functions.
*/
# include <mln/core/concept/object.hh>
namespace mln
{
/*! \brief Base class for implementation of function-objects.
*
* The parameter \a E is the exact type.
*/
template <typename E>
struct Function : public Object<E>
{
/*
An operator() has to be provided. Its signature depends
on the particular function-object one considers.
*/
protected:
Function();
};
// Value -> Value.
/// Base class for implementation of function-objects from value to
/// value.
template <typename E>
struct Function_v2v : public Function<E>
{
protected:
Function_v2v();
};
// Point -> Value.
/// Base class for implementation of function-objects from point to
/// value.
template <typename E>
struct Function_p2v : public Function_v2v<E>
{
protected:
Function_p2v();
};
// Point -> bool.
/// Base class for implementation of function-objects from point to
/// bool.
template <typename E>
struct Function_p2b : public Function_p2v<E>
{
protected:
Function_p2b();
};
// Point -> Point.
/// Base class for implementation of function-objects from point to
/// point.
template <typename E>
struct Function_p2p : public Function_p2v<E>
{
protected:
Function_p2p();
};
# ifndef MLN_INCLUDE_ONLY
template <typename E>
Function<E>::Function()
{
}
template <typename E>
Function_v2v<E>::Function_v2v()
{
}
template <typename E>
Function_p2v<E>::Function_p2v()
{
}
template <typename E>
Function_p2b<E>::Function_p2b()
{
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
#endif // ! MLN_CORE_CONCEPT_FUNCTION_HH
......@@ -55,7 +55,7 @@ namespace mln
bool has_data() const;
bool owns_(const psite& p) const; // default is like "has(p)"
bool owns_(const psite& p) const;
const pset& domain() const;
rvalue operator()(const psite& p) const;
......
......@@ -40,6 +40,14 @@
# define for_all(x) for(x.start(); x.is_valid(); x.next())
/*! \brief Loop to browse all the remaining elements targetted by the
* iterator \p x.
*/
# define for_all_remaining(x) \
if (! x.is_valid()) {} else while (x.next(), x.is_valid())
namespace mln
{
/*! \brief Base class for implementation classes that are iterators.
......
......@@ -50,6 +50,8 @@ namespace mln
typedef niter;
typedef fwd_niter;
typedef bkd_niter;
typedef dpoint;
*/
protected:
......@@ -65,6 +67,7 @@ namespace mln
typedef mln_niter(E) niter;
typedef mln_fwd_niter(E) fwd_niter;
typedef mln_bkd_niter(E) bkd_niter;
typedef mln_dpoint(E) dpoint;
}
# endif // ! MLN_INCLUDE_ONLY
......
......@@ -64,6 +64,20 @@ namespace mln
};
/*! \brief Print a point set \p pset into the output stream \p
* ostr.
*
* \param[in,out] ostr An output stream.
* \param[in] pset A point set.
*
* \return The modified output stream \p ostr.
*
* \relates mln::Point_Set
*/
template <typename S>
std::ostream& operator<<(std::ostream& ostr, const Point_Set<S>& pset);
# ifndef MLN_INCLUDE_ONLY
// fwd decl
......@@ -74,7 +88,8 @@ namespace mln
{
typedef mln_point(E) point;
typedef mln_psite(E) psite;
typedef mln_piter(E) piter;
typedef mln_piter(E) piter;
typedef mln_fwd_piter(E) fwd_piter;
typedef mln_bkd_piter(E) bkd_piter;
......@@ -86,6 +101,18 @@ namespace mln