Commit 9622c438 authored by Thierry Geraud's avatar Thierry Geraud
Browse files

Factor code for iterators on dpoints and update.

	* oln/core/internal/dpoints_piter_impl.hh: New; copy of...
	* oln/core/internal/dpoints_piter.hh: ...this. 
	* oln/debug/print_nbh.hh: Update.
	* oln/core/gen/dpoints_piter.hh (dpoints_fwd_piter_): Overload.
	Update inheritance.
	(dpoints_bkd_piter_): Update.
	(include): Update.
	* oln/core/internal/image_selectors.hh (Image_mutability): Add
	FIXME.
	* oln/core/internal/op_image_plus_nbh.hh: Better commentary.

	Minor fixes.
	
	* oln/accumulator/and.hh (include): Remove max_value.hh.
	(init): Use 'true'.
	(operator()): Use 'and'.
	* oln/accumulator/or.hh (include): Remove max_value.hh.
	(ultimate): Remove.
	(init): Use 'false'.
	(operator()): Use 'or'.
	* oln/core/concept/accumulator.hh: Add FIXME.
	* oln/core/internal/max_value.hh (oln_min): Remove.
	* oln/core/internal/min_value.hh: Add FIXME.
	* oln/morpho/dilation.hh: Fix.
	* oln/level/local.hh (local_): Update 'or on nbh' version.
	(local_): Inactivate other optimized versions.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@894 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent afe34437
2007-03-22 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Factor code for iterators on dpoints and update.
* oln/core/internal/dpoints_piter_impl.hh: New; copy of...
* oln/core/internal/dpoints_piter.hh: ...this.
* oln/debug/print_nbh.hh: Update.
* oln/core/gen/dpoints_piter.hh (dpoints_fwd_piter_): Overload.
Update inheritance.
(dpoints_bkd_piter_): Update.
(include): Update.
* oln/core/internal/image_selectors.hh (Image_mutability): Add
FIXME.
* oln/core/internal/op_image_plus_nbh.hh: Better commentary.
Minor fixes.
* oln/accumulator/and.hh (include): Remove max_value.hh.
(init): Use 'true'.
(operator()): Use 'and'.
* oln/accumulator/or.hh (include): Remove max_value.hh.
(ultimate): Remove.
(init): Use 'false'.
(operator()): Use 'or'.
* oln/core/concept/accumulator.hh: Add FIXME.
* oln/core/internal/max_value.hh (oln_min): Remove.
* oln/core/internal/min_value.hh: Add FIXME.
* oln/morpho/dilation.hh: Fix.
* oln/level/local.hh (local_): Update 'or on nbh' version.
(local_): Inactivate other optimized versions.
2007-03-21 Ugo Jardonnet <ugo.jardonnet@lrde.epita.fr>
Algo MorphoMath : and, or, opening, closing, elementary algo.
......
......@@ -29,7 +29,6 @@
# define OLN_ACCUMULATOR_AND_HH
# include <oln/core/concept/accumulator.hh>
# include <oln/core/internal/max_value.hh>
namespace oln
......@@ -68,7 +67,7 @@ namespace oln
void
and_<T>::init() const
{
this->val_ = oln_min(T);
this->val_ = true;
}
template <typename T>
......@@ -82,8 +81,7 @@ namespace oln
void
and_<T>::operator()(const T& val) const
{
if (val < this->val_)
this->val_ = val;
this->val_ = this->val_ and val;
}
# endif // ! OLN_INCLUDE_ONLY
......
......@@ -29,7 +29,6 @@
# define OLN_ACCUMULATOR_OR_HH
# include <oln/core/concept/accumulator.hh>
# include <oln/core/internal/max_value.hh>
namespace oln
......@@ -51,7 +50,6 @@ namespace oln
void operator()(const T& val) const;
mutable T ultimate;
private:
mutable T val_;
};
......@@ -69,8 +67,7 @@ namespace oln
void
or_<T>::init() const
{
this->val_ = oln_min(T);
this->ultimate = oln_max(T);
this->val_ = false;
}
template <typename T>
......@@ -84,8 +81,7 @@ namespace oln
void
or_<T>::operator()(const T& val) const
{
if (val < this->val_)
this->val_ = val;
this->val_ = this->val_ or val;
}
# endif // ! OLN_INCLUDE_ONLY
......
......@@ -60,7 +60,7 @@ namespace oln
Accumulator<Exact>::init_with(const T& val) const
{
exact(this)->init();
exact(this)->operator()(val);
exact(this)->operator()(val); // FIXME: Change to ->take(val)?
}
# endif // ! OLN_INCLUDE_ONLY
......
......@@ -28,121 +28,105 @@
#ifndef OLN_CORE_GEN_DPOINTS_PITER_HH
# define OLN_CORE_GEN_DPOINTS_PITER_HH
# include <oln/core/concept/iterator_on_points.hh>
# include <oln/core/internal/dpoints_impl.hh>
# include <oln/core/concept/window.hh>
# include <oln/core/concept/neighborhood.hh>
# include <oln/core/concept/image.hh>
# include <oln/core/internal/dpoints_piter_impl.hh>
namespace oln
{
/// Fwd decls.
// --------------------------- dpoints_fwd_piter_<P>
// Fwd decl.
template <typename P> class dpoints_fwd_piter_;
template <typename P> class dpoints_bkd_piter_;
// Super types.
// Super type.
template <typename P>
struct super_trait_< dpoints_fwd_piter_<P> >
{
typedef dpoints_fwd_piter_<P> current__;
typedef Iterator_on_Points<current__> ret;
};
template <typename P>
struct super_trait_< dpoints_bkd_piter_<P> >
{
typedef dpoints_bkd_piter_<P> current__;
typedef Iterator_on_Points<current__> ret;
};
/// Virtual types.
// Virtual type.
template <typename P>
struct vtypes< dpoints_fwd_piter_<P> >
{
typedef P point;
};
template <typename P>
struct vtypes< dpoints_bkd_piter_<P> >
{
typedef P point;
};
namespace internal
// Forward point iterator class on a set of dpoints.
template <typename P>
class dpoints_fwd_piter_ : public Iterator_on_Points< dpoints_fwd_piter_<P> >,
public internal::dpoints_fwd_piter_impl_<P>
{
public:
/// Class to factor some code.
// FIXME: Strenghten sigs (Pl is either a Point or an Iterator_on_Points).
template <typename P>
class dpoints_piter_impl_ : private mlc::assert_< mlc_is_a(P, Point) >
{
public:
template <typename Pl, typename W>
dpoints_fwd_piter_(const Pl& p, const Window<W>& win);
dpoints_piter_impl_(const dpoints_piter_impl_&);
void operator=(const dpoints_piter_impl_&);
template <typename Pl, typename I>
dpoints_fwd_piter_(const Pl& p, const Image_with_Nbh<I>& ima);
void impl_invalidate();
template <typename Pl, typename N>
dpoints_fwd_piter_(const Pl& p, const Neighborhood<N>& nbh);
bool impl_is_valid() const;
P impl_to_point() const;
const P* impl_point_adr() const;
}; // end of class oln::dpoints_fwd_piter_<P>
protected:
const P* p_ref_;
std::vector<typename P::dpoint> dps_;
unsigned n_, i_;
P p_;
// Ctor.
template <typename Pl>
dpoints_piter_impl_(const Pl& ref,
const internal::dpoints_impl_<typename P::dpoint>& data);
void update_p_();
};
// --------------------------- dpoints_bkd_piter_<P>
} // end of namespace oln::internal
// Fwd decl.
template <typename P> class dpoints_bkd_piter_;
/// Forward point iterator class on a set of dpoints.
// Super type.
template <typename P>
class dpoints_fwd_piter_ : public Iterator_on_Points< dpoints_fwd_piter_<P> >,
public internal::dpoints_piter_impl_<P>
struct super_trait_< dpoints_bkd_piter_<P> >
{
public:
template <typename Pl, typename X>
dpoints_fwd_piter_(const Pl& p, const X& win_or_nbh);
void impl_start();
void impl_next();
typedef dpoints_bkd_piter_<P> current__;
typedef Iterator_on_Points<current__> ret;
};
}; // end of class oln::dpoints_fwd_piter_<P>
// Virtual type.
template <typename P>
struct vtypes< dpoints_bkd_piter_<P> >
{
typedef P point;
};
/// Backward point iterator class on a set of dpoints.
template <typename P>
class dpoints_bkd_piter_ : public Iterator_on_Points< dpoints_bkd_piter_<P> >,
public internal::dpoints_piter_impl_<P>
public internal::dpoints_bkd_piter_impl_<P>
{
public:
template <typename Pl, typename X>
dpoints_bkd_piter_(const Pl& p, const X& win_or_nbh);
// FIXME: Strenghten sigs (Pl is either a Point or an Iterator_on_Points).
template <typename Pl, typename W>
dpoints_bkd_piter_(const Pl& p, const Window<W>& win);
void impl_start();
template <typename Pl, typename I>
dpoints_bkd_piter_(const Pl& p, const Image_with_Nbh<I>& ima);
void impl_next();
template <typename Pl, typename N>
dpoints_bkd_piter_(const Pl& p, const Neighborhood<N>& nbh);
}; // end of class oln::dpoints_bkd_piter_<P>
......@@ -150,128 +134,56 @@ namespace oln
# ifndef OLN_INCLUDE_ONLY
namespace internal
{
template <typename Pl>
const Pl* point_adr_(const Point<Pl>& p)
{
return exact(&p);
}
template <typename Pl>
const typename Pl::point* point_adr_(const Iterator_on_Points<Pl>& p)
{
return p.point_adr();
}
template <typename P>
template <typename Pl>
dpoints_piter_impl_<P>::dpoints_piter_impl_(const Pl& ref,
const internal::dpoints_impl_<typename P::dpoint>& data)
{
p_ref_ = point_adr_(ref);
dps_ = data.dpoints();
n_ = data.size();
i_ = n_;
postcondition(n_ != 0);
}
template <typename P>
void
dpoints_piter_impl_<P>::impl_invalidate()
{
i_ = n_;
}
template <typename P>
bool
dpoints_piter_impl_<P>::impl_is_valid() const
{
return i_ != n_;
}
template <typename P>
P
dpoints_piter_impl_<P>::impl_to_point() const
{
return p_;
}
template <typename P>
const P*
dpoints_piter_impl_<P>::impl_point_adr() const
{
return &p_;
}
template <typename P>
void
dpoints_piter_impl_<P>::update_p_()
{
p_ = *p_ref_+ dps_[i_];
}
} // end of namespace oln::internal
// fwd
template <typename P>
template <typename Pl, typename X>
dpoints_fwd_piter_<P>::dpoints_fwd_piter_(const Pl& p, const X& win_or_nbh)
template <typename Pl, typename W>
dpoints_fwd_piter_<P>::dpoints_fwd_piter_(const Pl& p, const Window<W>& win)
:
internal::dpoints_piter_impl_<P>(p, exact(win_or_nbh))
internal::dpoints_fwd_piter_impl_<P>(p, exact(win))
{
}
template <typename P>
void
dpoints_fwd_piter_<P>::impl_start()
template <typename Pl, typename I>
dpoints_fwd_piter_<P>::dpoints_fwd_piter_(const Pl& p, const Image_with_Nbh<I>& ima)
:
internal::dpoints_fwd_piter_impl_<P>(p, ima.nbhood())
{
this->i_ = 0;
this->update_p_();
}
template <typename P>
void
dpoints_fwd_piter_<P>::impl_next()
template <typename Pl, typename N>
dpoints_fwd_piter_<P>::dpoints_fwd_piter_(const Pl& p, const Neighborhood<N>& nbh)
:
internal::dpoints_fwd_piter_impl_<P>(p, exact(nbh))
{
if (++this->i_ == this->n_)
return;
this->update_p_();
}
// bkd
template <typename P>
template <typename Pl, typename X>
dpoints_bkd_piter_<P>::dpoints_bkd_piter_(const Pl& p, const X& win_or_nbh)
template <typename Pl, typename W>
dpoints_bkd_piter_<P>::dpoints_bkd_piter_(const Pl& p, const Window<W>& win)
:
internal::dpoints_piter_impl_<P>(p, exact(win_or_nbh))
internal::dpoints_bkd_piter_impl_<P>(p, exact(win))
{
}
template <typename P>
void
dpoints_bkd_piter_<P>::impl_start()
template <typename Pl, typename I>
dpoints_bkd_piter_<P>::dpoints_bkd_piter_(const Pl& p, const Image_with_Nbh<I>& ima)
:
internal::dpoints_bkd_piter_impl_<P>(p, ima.nbhood())
{
this->i_ = this->n_ - 1;
this->update_p_();
}
template <typename P>
void
dpoints_bkd_piter_<P>::impl_next()
template <typename Pl, typename N>
dpoints_bkd_piter_<P>::dpoints_bkd_piter_(const Pl& p, const Neighborhood<N>& nbh)
:
internal::dpoints_bkd_piter_impl_<P>(p, exact(nbh))
{
if (this->i_ == 0)
{
this->i_ = this->n_;
return;
}
--this->i_;
this->update_p_();
}
# endif
......
// Copyright (C) 2006, 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 OLN_CORE_INTERNAL_DPOINTS_PITER_IMPL_HH
# define OLN_CORE_INTERNAL_DPOINTS_PITER_IMPL_HH
# include <oln/core/concept/iterator_on_points.hh>
# include <oln/core/internal/dpoints_impl.hh>
namespace oln
{
namespace internal
{
/// Classes to factor code for iterators based on vector of dpoints.
template <typename P>
class dpoints_piter_impl_ : private mlc::assert_< mlc_is_a(P, Point) > // FIXME: Add err msg.
{
public:
// dpoints_piter_impl_(const dpoints_piter_impl_&);
void impl_invalidate();
bool impl_is_valid() const;
P impl_to_point() const;
const P* impl_point_adr() const;
protected:
template <typename Pl>
dpoints_piter_impl_(const Pl& p_ref,
const std::vector<typename P::dpoint>& dps);
void update_p_();
const P* p_ref_;
const std::vector<typename P::dpoint>& dps_;
unsigned n_, i_;
P p_;
};
// fwd
template <typename P>
class dpoints_fwd_piter_impl_ : public dpoints_piter_impl_<P>
{
public:
void impl_start();
void impl_next();
protected:
template <typename Pl>
dpoints_fwd_piter_impl_(const Pl& p_ref,
const dpoints_impl_<typename P::dpoint>& data);
};
// bkd
template <typename P>
class dpoints_bkd_piter_impl_ : public dpoints_piter_impl_<P>
{
public:
void impl_start();
void impl_next();
protected:
template <typename Pl>
dpoints_bkd_piter_impl_(const Pl& p_ref,
const dpoints_impl_<typename P::dpoint>& data);
};
# ifndef OLN_INCLUDE_ONLY
// point_adr_
template <typename Pl>
const Pl* point_adr_(const Point<Pl>& p)
{
return exact(&p);
}
template <typename Pl>
const typename Pl::point* point_adr_(const Iterator_on_Points<Pl>& p)
{
return p.point_adr();
}
// dpoints_piter_impl_<P>
template <typename P>
template <typename Pl>
dpoints_piter_impl_<P>::dpoints_piter_impl_(const Pl& p_ref,
const std::vector<typename P::dpoint>& dps)
: p_ref_(point_adr_(p_ref)),
dps_(dps),
n_(dps.size()),
i_(n_)
{
precondition(dps.size() != 0);
}
template <typename P>
void
dpoints_piter_impl_<P>::impl_invalidate()
{
this->i_ = this->n_;
}
template <typename P>
bool
dpoints_piter_impl_<P>::impl_is_valid() const
{
return this->i_ != this->n_;
}
template <typename P>
P
dpoints_piter_impl_<P>::impl_to_point() const
{
return this->p_;
}
template <typename P>
const P*
dpoints_piter_impl_<P>::impl_point_adr() const
{
return &(this->p_);
}
template <typename P>
void
dpoints_piter_impl_<P>::update_p_()
{
this->p_ = *(this->p_ref_) + this->dps_[i_];
}
// dpoints_fwd_piter_impl_<P>
template <typename P>
template <typename Pl>
dpoints_fwd_piter_impl_<P>::dpoints_fwd_piter_impl_(const Pl& p_ref,
const dpoints_impl_<typename P::dpoint>& data)
: dpoints_piter_impl_<P>(p_ref, data.dpoints())
{
}
template <typename P>
void
dpoints_fwd_piter_impl_<P>::impl_start()
{
this->i_ = 0;
this->update_p_();