Commit 2655e8c7 authored by Thierry Geraud's avatar Thierry Geraud
Browse files

Add pset and pvec point sets.

	* tests/sort_points.cc: New.
	* tests/pset.cc: New.
	* tests/histo.cc: Update.
	* mln/histo/sort.hh: Rename as...
	* mln/level/sort_points.hh: ...this new file.
	(sort_points): New overload.
	* mln/histo/data.hh (vec): Rename as...
	(vect): ...this.
	* mln/core/dpoints_piter.hh: Update.
	* mln/core/pvec.hh: New.
	* mln/core/pset.hh: New.
	* mln/core/internal/set_of.hh: Update.
	* mln/accu/histo.hh: Update.
	* mln/accu/bbox.hh: New.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@1038 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 2df3dd07
2007-07-25 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Add pset and pvec point sets.
* tests/sort_points.cc: New.
* tests/pset.cc: New.
* tests/histo.cc: Update.
* mln/histo/sort.hh: Rename as...
* mln/level/sort_points.hh: ...this new file.
(sort_points): New overload.
* mln/histo/data.hh (vec): Rename as...
(vect): ...this.
* mln/core/dpoints_piter.hh: Update.
* mln/core/pvec.hh: New.
* mln/core/pset.hh: New.
* mln/core/internal/set_of.hh: Update.
* mln/accu/histo.hh: Update.
* mln/accu/bbox.hh: New.
2007-07-24 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Add int_s, an histogram class, and distributed sort.
......
// 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_BBOX_HH
# define MLN_ACCU_BBOX_HH
/*! \file mln/accu/bbox.hh
*
* \brief Define an accumulator that computes a bbox.
*/
# include <mln/core/concept/accumulator.hh>
# include <mln/core/box.hh>
namespace mln
{
namespace accu
{
/*! Generic bbox accumulator class.
*
* The parameter \c P is the type of points.
*/
template <typename P>
struct bbox : public Accumulator< bbox<P> >
{
typedef P value;
bbox();
void take(const P& p);
void init();
operator box_<P>() const;
const box_<P>& to_value() const;
bool is_valid() const;
protected:
bool is_valid_;
box_<P> b_;
};
# ifndef MLN_INCLUDE_ONLY
template <typename P>
bbox<P>::bbox()
{
init();
}
template <typename P>
void bbox<P>::take(const P& p)
{
if (! is_valid_)
{
b_.pmin() = p;
b_.pmax() = p;
is_valid_ = true;
return;
}
for (unsigned i = 0; i < P::dim; ++i)
if (p[i] < b_.pmin()[i])
b_.pmin()[i] = p[i];
else if (p[i] > b_.pmax()[i])
b_.pmax()[i] = p[i];
}
template <typename P>
void
bbox<P>::init()
{
is_valid_ = false;
}
template <typename P>
bbox<P>::operator box_<P>() const
{
mln_precondition(is_valid_);
return b_;
}
template <typename P>
const box_<P>&
bbox<P>::to_value() const
{
mln_precondition(is_valid_);
return b_;
}
template <typename P>
bool
bbox<P>::is_valid() const
{
return is_valid_;
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::accu
} // end of namespace mln
#endif // ! MLN_ACCU_BBOX_HH
......@@ -67,7 +67,7 @@ namespace mln
std::size_t nvalues() const;
std::size_t sum() const;
const std::vector<std::size_t>& vec() const;
const std::vector<std::size_t>& vect() const;
const S& vset() const;
......@@ -160,7 +160,7 @@ namespace mln
template <typename S>
const std::vector<std::size_t>&
histo<S>::vec() const
histo<S>::vect() const
{
return h_;
}
......
......@@ -51,7 +51,7 @@ namespace mln
*/
template <typename E>
struct Point_Iterator : public Iterator<E>,
public Generalized_Point<E>
public Generalized_Point<E>
{
/*
typedef psite;
......
......@@ -62,7 +62,7 @@ namespace mln
*/
template <typename E>
struct Point_Site : public Object<E>,
public Generalized_Point<E>
public Generalized_Point<E>
{
/*
const point* pointer_() const
......
......@@ -118,7 +118,7 @@ namespace mln
template <typename Dps, typename Pref>
dpoints_fwd_piter<D>::dpoints_fwd_piter(const Dps& dps,
const Generalized_Point<Pref>& p_ref)
: dps_(exact(dps).vec()),
: dps_(exact(dps).vect()),
p_ref_(* internal::force_exact<Pref>(p_ref).pointer_())
{
invalidate();
......
......@@ -59,6 +59,8 @@ namespace mln
*
* The parameter \c E is the element type, which shall not be
* const-qualified.
*
* \todo Add a remove method.
*/
template <typename E>
class set_of_
......@@ -123,7 +125,7 @@ namespace mln
*
* \return An array (std::vector) of elements.
*/
const std::vector<E>& vec() const;
const std::vector<E>& vect() const;
protected:
......@@ -245,7 +247,7 @@ namespace mln
template <typename E>
const std::vector<E>&
set_of_<E>::vec() const
set_of_<E>::vect() const
{
if (needs_update_)
update_();
......
// 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_PSET_HH
# define MLN_CORE_PSET_HH
/*! \file mln/core/pset.hh
*
* \brief Definition of a point set class based on std::set.
*/
# include <mln/core/concept/point_set.hh>
# include <mln/core/internal/set_of.hh>
# include <mln/accu/bbox.hh>
# include <mln/core/pvec.hh>
namespace mln
{
/*! \brief Point set class based on std::set.
*
* This is a mathematical set of points (not a multi-set). The
* parameter \p P shall be a Point type.
*
* \todo Test if \p P being a Point_Site is ok.
*/
template <typename P>
class pset : public Point_Set< pset<P> >,
private internal::set_of_<P>
{
typedef internal::set_of_<P> super_;
public:
/// Point associated type.
typedef mln_point(P) point;
/// Point_Site associated type.
typedef P psite;
/// Forward Point_Iterator associated type.
typedef pvec_fwd_piter_<P> fwd_piter;
/// Backward Point_Iterator associated type.
typedef internal::fixme bkd_piter;
/// Constructor.
pset();
/// Test is \p p belongs to this point set.
bool has(const P& p) const;
/// Return the corresponding std::vector of points.
using super_::vect;
/// Give the number of points.
std::size_t npoints() const;
/// Insert a point \p p.
pset<P>& insert(const P& p);
/// Return the \p i-th point.
const P& operator[](unsigned i) const;
/// Clear this set.
void clear();
/// Give the exact bounding box.
const box_<point>& bbox() const;
protected:
accu::bbox<P> bb_;
// FIXME: Add invariant bb_.is_valid() <=> npoints() != 0
};
# ifndef MLN_INCLUDE_ONLY
template <typename P>
pset<P>::pset()
{
}
template <typename P>
bool
pset<P>::has(const P& p) const
{
return this->super_::has(p);
}
template <typename P>
std::size_t
pset<P>::npoints() const
{
return this->super_::nelements();
}
template <typename P>
pset<P>&
pset<P>::insert(const P& p)
{
this->super_::insert(p);
bb_.take(p);
return *this;
}
template <typename P>
const P&
pset<P>::operator[](unsigned i) const
{
mln_precondition(i < npoints());
return this->super_::element(i);
}
template <typename P>
void
pset<P>::clear()
{
this->super_::clear();
bb_.init();
}
template <typename P>
const box_<mln_point(P)>&
pset<P>::bbox() const
{
mln_precondition(npoints() != 0);
return bb_.to_value();
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
#endif // ! MLN_CORE_PSET_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_CORE_PVEC_HH
# define MLN_CORE_PVEC_HH
/*! \file mln/core/pvec.hh
*
* \brief Definition of a point set class based on std::vector.
*/
# include <vector>
# include <mln/core/concept/point_set.hh>
# include <mln/core/internal/fixme.hh>
# include <mln/accu/bbox.hh>
namespace mln
{
// Fwd decls.
template <typename P> struct pvec_fwd_piter_;
template <typename P> struct pvec_bkd_piter_;
/*! \brief Point set class based on std::vector.
*
* This is a multi-set of points.
*
* \warning We have some troubles with point set comparison based on
* a call to npoints(). FIXME: Explain!
*/
template <typename P>
class pvec : public Point_Set< pvec<P> >
{
public:
/// Point associated type.
typedef mln_point(P) point;
/// Point_Site associated type.
typedef P psite;
/// Forward Point_Iterator associated type.
typedef pvec_fwd_piter_<P> fwd_piter;
/// Backward Point_Iterator associated type.
typedef internal::fixme bkd_piter;
/// Constructor.
pvec();
/// Constructor from a vector \p vect.
pvec(const std::vector<P>& vect);
/// Test is \p p belongs to this point set.
bool has(const P& p) const;
/// Give the number of points.
std::size_t npoints() const;
/// Give the exact bounding box.
const box_<point>& bbox() const;
/// Append a point \p p.
pvec<P>& append(const P& p);
/// Clear this set.
void clear();
/// Return the corresponding std::vector of points.
const std::vector<P>& vect() const;
/// Return the \p i-th point.
const P& operator[](unsigned i) const;
protected:
std::vector<P> vect_;
mutable accu::bbox<P> bb_;
mutable bool bb_needs_update_;
void update_bb_();
// FIXME: Add invariant bb_.is_valid() <=> npoints() != 0
};
/*! \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()
{
bb_needs_update_ = false;
}
template <typename P>
pvec<P>::pvec(const std::vector<P>& vect)
: vect_(vect)
{
bb_needs_update_ = true;
}
template <typename P>
void
pvec<P>::update_bb_()
{
bb_.clear();
for (unsigned i = 0; i < vect_.size(); ++i)
bb_.take(vect_[i]);
bb_needs_update_ = false;
}
template <typename P>
bool
pvec<P>::has(const P& p) const
{
for (unsigned i = 0; i < vect_.size(); ++i)
if (vect_[i] == p)
return true;
return false;
}
template <typename P>
std::size_t
pvec<P>::npoints() const
{
return vect_.size();
}
template <typename P>
const box_<mln_point(P)>&
pvec<P>::bbox() const
{
mln_precondition(npoints() != 0);
if (bb_needs_update_)
update_bb_();
return bb_.to_value();
}
template <typename P>
pvec<P>&
pvec<P>::append(const P& p)
{
vect_.push_back(p);
return *this;
}
template <typename P>
void
pvec<P>::clear()
{
vect_.clear();
bb_needs_update_ = false;
}
template <typename P>