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

Fix pixel iterators on sets of dpoints.

	* tests/fast_median.cc (test): New.
	* tests/naive_median.cc: Update.
	* mln/debug/iota.hh: New.
	* mln/core/pixel.hh (value_ptr_): New.
	* mln/core/dpoints_piter.hh (center_point): New.
	(update_p_): Rename as...
	(update): ...this.
	* mln/core/concept/genpixel.hh: Inactivate some code.
	* mln/core/dpoints_pixter.hh: Update.
	* mln/core/internal/pixel_iterator_base.hh: Clean-up.
	* mln/level/was.hmedian.hh (hmedian): Move...
	* mln/level/was.median.hh: ...here.
	* mln/level/was.hmedian.hh: Remove.
	* mln/level/fast_median.hh: Clean-up.
	Contents


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@1023 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 929123d9
2007-07-19 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Fix pixel iterators on sets of dpoints.
* tests/fast_median.cc (test): New.
* tests/naive_median.cc: Update.
* mln/debug/iota.hh: New.
* mln/core/pixel.hh (value_ptr_): New.
* mln/core/dpoints_piter.hh (center_point): New.
(update_p_): Rename as...
(update): ...this.
* mln/core/concept/genpixel.hh: Inactivate some code.
* mln/core/dpoints_pixter.hh: Update.
* mln/core/internal/pixel_iterator_base.hh: Clean-up.
* mln/level/was.hmedian.hh (hmedian): Move...
* mln/level/was.median.hh: ...here.
* mln/level/was.hmedian.hh: Remove.
* mln/level/fast_median.hh: Clean-up.
Contents
2007-07-18 Nicolas Ballas <ballas@lrde.epita.fr>
Change fast_iterator hierarchy.
......
......@@ -60,17 +60,22 @@ namespace mln
{
/*
typedef ima; // not const!
typede psite;
typedef rvalue;
typedef value;
// FIXME: lvalue?
const ima& image() const;
const psite& site() const; // FIXME ou cpy
// FIXME: Inactivated:
// typedef ima; // not const!
// typedef psite;
// const ima& image() const;
// const psite& site() const; // FIXME ou cpy
// value* address();
rvalue operator*() const;
lvalue operator*();
const value* address() const;
const value*& address() const;
*/
protected:
......@@ -89,7 +94,7 @@ namespace mln
* \relates mln::GenPixel
*/
template <typename P>
std::ostream& operator<<(std::ostream& ostr, const GenPixel<P>& p);
std::ostream& operator<<(std::ostream& ostr, const GenPixel<P>& pxl);
......@@ -101,17 +106,20 @@ namespace mln
{
typedef mln_value(E) value;
typedef mln_rvalue(E) rvalue;
typedef mln_ima(E) ima;
typedef mln_psite(E) psite;
const ima& (E::*m1)() const = & E::image;
m1 = 0;
const psite& (E::*m2)() const = & E::site;
m2 = 0;
// FIXME: Inactivated:
// typedef mln_ima(E) ima;
// typedef mln_psite(E) psite;
// const ima& (E::*m1)() const = & E::image;
// m1 = 0;
// const psite& (E::*m2)() const = & E::site;
// m2 = 0;
rvalue (E::*m3)() const = & E::operator*;
m3 = 0;
const value* (E::*m4)() const = & E::address;
m4 = 0;
// const value *const & (E::*m4)() const = & E::address;
// m4 = 0;
}
......
......@@ -71,13 +71,13 @@ namespace mln
* \param[in] p_ref Center point to iterate around.
*/
template <typename Dps, typename Pref>
dpoints_fwd_piter(const Dps& dps,
dpoints_fwd_piter(const Dps& dps, // FIXME: explicitly set_of_<D>?
const GenPoint<Pref>& p_ref);
/// Convertion to point.
operator mln_point(D) () const;
/// Address of the point.
/// Address of the point this iterator designates.
const point* pointer() const;
/// Test the iterator validity.
......@@ -95,13 +95,20 @@ namespace mln
/// Give the i-th coordinate.
coord operator[](unsigned i) const;
/// The point around which this iterator moves.
const point& center_point() const;
/// Force this iterator to update its location to take into
/// account that its center point may have moved.
void update();
private:
const std::vector<D>& dps_;
const point& p_ref_;
const point& p_ref_; // reference point (or "center point")
unsigned i_;
point p_;
void update_p_();
point p_; // location of this iterator; p_ makes this iterator be
// itself a potential center point (Cf. the pointer() method).
};
......@@ -120,7 +127,7 @@ namespace mln
template <typename D>
dpoints_fwd_piter<D>::operator mln_point(D) () const
{
assert(is_valid());
mln_precondition(is_valid());
return p_;
}
......@@ -150,7 +157,7 @@ namespace mln
dpoints_fwd_piter<D>::start()
{
i_ = 0;
update_p_();
update();
}
template <typename D>
......@@ -158,12 +165,19 @@ namespace mln
dpoints_fwd_piter<D>::next_()
{
++i_;
update_p_();
update();
}
template <typename D>
const mln_point(D)&
dpoints_fwd_piter<D>::center_point() const
{
return p_ref_;
}
template <typename D>
void
dpoints_fwd_piter<D>::update_p_()
dpoints_fwd_piter<D>::update()
{
if (is_valid())
p_ = p_ref_ + dps_[i_];
......@@ -173,6 +187,14 @@ namespace mln
mln_coord(D)
dpoints_fwd_piter<D>::operator[](unsigned i) const
{
mln_precondition(is_valid());
// below we test that no update is required
// meaning that p_ref_ has not moved or that
// the user has explicitly called update()
mln_precondition(p_ref_ + dps_[i_] == p_);
// FIXME: Explain this issue in the class documentation...
return p_[i];
}
......
......@@ -35,6 +35,7 @@
namespace mln
{
/*! \brief A generic forward iterator on image pixel of a windows and of
* neighborhoods.
*
......@@ -45,6 +46,7 @@ namespace mln
{
typedef typename internal::pixel_iterator_base_< I, dpoints_pixter<I> > super;
public:
/// Image pixel value
typedef mln_value(I) value;
/// Image pixel rvalue
......@@ -58,73 +60,149 @@ namespace mln
* \param[in] p_ref Center point to iterate around.
* \param[in] ima Image to iterate.
*/
template <typename Dps>
dpoints_pixter(const Dps& dps, const typename I::psite& p_ref,I& ima);
template <typename Dps, typename Pref>
dpoints_pixter(const Dps& dps,
const GenPoint<Pref>& p_ref,
I& image);
/// Set the iterator at the start.
template <typename Dps, typename Pref>
dpoints_pixter(const Dps& dps,
const GenPixel<Pref>& p_ref,
I& image);
/// Start an iteration.
void start();
/// Go to the next pixel.
void next_();
/// Invalidate the iterator.
void invalidate();
/// Is the iterator valid?
/// Test the iterator validity.
bool is_valid() const;
/// Force this iterator to update its location to take into
/// account that its center point may have moved.
void update();
/// The value around which this iterator moves.
const value& center_value() const;
private:
/// offset of each dpoints
std::vector<int> offset_;
/// current offset
std::vector<int>::iterator i_;
/// reference pixel in the image
value* pixref_;
int i_;
/// reference pixel / point in the image
value** value_ref_;
// or:
const mln_point(I)* p_ref_;
template <typename Dps>
void init_(const Dps& dps);
};
#ifndef MLN_INCLUDE_ONLY
template <typename I>
template <typename Dps, typename Pref>
dpoints_pixter<I>::dpoints_pixter(const Dps& dps,
const GenPoint<Pref>& p_ref,
I& image)
: super(image)
{
p_ref_ = internal::force_exact<Pref>(p_ref).pointer();
value_ref_ = 0;
init_(dps);
}
template <typename I>
template <typename Dps, typename Pref>
dpoints_pixter<I>::dpoints_pixter(const Dps& dps,
const GenPixel<Pref>& p_ref,
I& image)
: super(image)
{
p_ref_ = 0;
value_ref_ = internal::force_exact<Pref>(p_ref).address();
init_(dps);
}
template <typename I>
const mln_value(I)&
dpoints_pixter<I>::center_value() const
{
mln_invariant(value_ref_ != 0 || p_ref_ != 0);
if (p_ref_)
return image_(*p_ref_);
else
return ** value_ref_;
}
template <typename I>
template <typename Dps>
dpoints_pixter<I>::dpoints_pixter(const Dps& dps, const typename I::psite& ref, I& ima) : super(ima)
void
dpoints_pixter<I>::init_(const Dps& dps)
{
this->p_ = ref;
pixref_ = &ima(ref);
for (typename std::vector<typename I::dpoint>::const_iterator it = dps.vec().begin();
it != dps.vec().end();
++it)
offset_.push_back(ima.offset(*it));
for (unsigned i = 0; i < dps.nelements(); ++i)
offset_.push_back(this->image_.offset(dps.element(i)));
if (dps.nelements() > 1)
for (unsigned i = dps.nelements() - 1; i > 0; --i)
offset_[i] -= offset_[i - 1];
// offset_[0] is absolute; other offsets are relative.
invalidate();
}
template <typename I>
void dpoints_pixter<I>::update()
{
if (is_valid())
{
if (p_ref_)
this->value_ptr_ = & image_(*p_ref_) + offset_[i_];
else
this->value_ptr_ = * value_ref_ + offset_[i_];
}
}
template <typename I>
void dpoints_pixter<I>::start()
{
pixref_ = &ima_(this->p_);
i_ = offset_.begin();
this->current_value_ = pixref_ + *i_;
i_ = 0;
update();
}
template <typename I>
void dpoints_pixter<I>::next_()
{
++i_;
this->current_value_ = pixref_ + *i_;
this->value_ptr_ += offset_[i_];
}
template <typename I>
bool dpoints_pixter<I>::is_valid() const
{
return i_ != offset_.end();
return i_ != offset_.size();
}
template <typename I>
void dpoints_pixter<I>::invalidate()
{
i_ = offset_.end();
i_ = offset_.size();
}
#endif // ! MLN_INCLUDE_ONLY
}
} // end of namespace mln
#endif // MLN_CORE_DPOINTS_PIXTER_HH
......@@ -28,10 +28,9 @@
#ifndef MLN_CORE_INTERNAL_PIXEL_ITERATOR_BASE_HH
# define MLN_CORE_INTERNAL_PIXEL_ITERATOR_BASE_HH
/*! \file mln/core/internal/fast_iterator_base.hh
/*! \file mln/core/internal/pixel_iterator_base.hh
*
* \brief Base class for Fast_Iterator concept implementation.
* Usefull for code factorisation
* \brief Base class for Pixel_Iterator concept implementation classes.
*/
# include <mln/core/concept/pixel_iterator.hh>
......@@ -44,126 +43,158 @@ namespace mln
{
/*! \brief pixel_iterator_base_ class
*
*/
template <typename Image, typename Exact>
class pixel_iterator_base_ : public Pixel_Iterator<Exact>
template <typename I, typename E>
class pixel_iterator_base_ : public Pixel_Iterator<E>
{
public:
/// Image type.
typedef Image ima;
/// Image value type.
typedef mln_value(Image) value;
typedef mln_value(I) value;
/// Image lvalue type.
typedef mln_lvalue(Image) lvalue;
typedef mln_lvalue(I) lvalue;
/// Image rvalue type.
typedef mln_rvalue(Image) rvalue;
/// Image psite type.
typedef mln_psite(Image) psite;
typedef mln_rvalue(I) rvalue;
/// Get the image associated to the current pixel iterator.
const ima& image() const;
/// pixel iterator value.
lvalue operator* ();
/// Get the pixel iterator value.
rvalue operator* () const;
/// Address of the current iterator value/pixel.
const value* address() const;
/// Address of the current iterator value/pixel.
value* address();
value** address() const;
// FIXME: Inactivated:
// /// I type.
// typedef I ima;
/// psite associated to the iterator.
const psite& site() const;
/// psite associated to the iterator.
psite& site();
// /// Image psite type.
// typedef mln_psite(I) psite;
// /// Get the image associated to the current pixel iterator.
// const ima& image() const;
// /// psite associated to the iterator.
// const psite& site() const;
// /// psite associated to the iterator.
// psite& site();
// /// Address of the current iterator value/pixel.
// value* address();
protected:
/// Current pixel value
value* current_value_;
/// Current pixel / value
value* value_ptr_;
/// Image associated to the iterator
ima& ima_;
/// Psite of the pixel
psite p_;
I& image_;
// FIXME: Inactivated:
// /// Psite of the pixel
// psite p_;
pixel_iterator_base_(ima& source);
pixel_iterator_base_(I& image);
};
#ifndef MLN_INCLUDE_ONLY
template <typename Image, typename Exact>
pixel_iterator_base_<Image, Exact>::pixel_iterator_base_(ima& source) :
ima_(source)
template <typename I, typename E>
pixel_iterator_base_<I, E>::pixel_iterator_base_(I& image) :
image_(image),
value_ptr_(0)
{
}
template <typename Image, typename Exact>
const typename pixel_iterator_base_<Image, Exact>::ima&
pixel_iterator_base_<Image, Exact>::image() const
{
return ima_;
}
// template <typename I, typename E>
// const typename pixel_iterator_base_<I, E>::ima&
// pixel_iterator_base_<I, E>::image() const
// {
// return ima_;
// }
template <typename Image, typename Exact>
typename pixel_iterator_base_<Image, Exact>::lvalue
pixel_iterator_base_<Image, Exact>::operator* ()
template <typename I, typename E>
mln_lvalue(I)
pixel_iterator_base_<I, E>::operator* ()
{
assert(exact(this)->is_valid());
return *current_value_;
mln_precondition(exact(this)->is_valid());
mln_precondition(value_ptr_ != 0);
return *value_ptr_;
}
template <typename Image, typename Exact>
typename pixel_iterator_base_<Image, Exact>::rvalue
pixel_iterator_base_<Image, Exact>::operator* () const
template <typename I, typename E>
mln_rvalue(I)
pixel_iterator_base_<I, E>::operator* () const
{
assert(exact(this)->is_valid());
return *current_value_;
mln_precondition(exact(this)->is_valid());
mln_precondition(value_ptr_ != 0);
return *value_ptr_;
}
template <typename Image, typename Exact>
const typename pixel_iterator_base_<Image, Exact>::value*
pixel_iterator_base_<Image, Exact>::address() const
template <typename I, typename E>
mln_value(I) **
pixel_iterator_base_<I, E>::address() const
{
assert(exact(this)->is_valid());
return current_value_;
mln_precondition(exact(this)->is_valid());
mln_precondition(value_ptr_ != 0);
return & (mln_value(I)*)(value_ptr_);
}
template <typename Image, typename Exact>
typename pixel_iterator_base_<Image, Exact>::value*
pixel_iterator_base_<Image, Exact>::address()
{
assert(exact(this)->is_valid());
return current_value_;
}
// template <typename I, typename E>
// mln_value(I)*
// pixel_iterator_base_<I, E>::address()
// {
// mln_precondition(exact(this)->is_valid());
// return value_ptr_;
// }
// template <typename I, typename E>
// const typename pixel_iterator_base_<I, E>::psite&
// pixel_iterator_base_<I, E>::site() const
// {
// //FIXME: update psite
// return p_;
// }
// template <typename I, typename E>
// typename pixel_iterator_base_<I, E>::psite&
// pixel_iterator_base_<I, E>::site()
// {
// //FIXME: update psite
// return p_;
// }
template <typename Image, typename Exact>
const typename pixel_iterator_base_<Image, Exact>::psite&
pixel_iterator_base_<Image, Exact>::site() const
{
//FIXME: update psite
return p_;
}
template <typename Image, typename Exact>
typename pixel_iterator_base_<Image, Exact>::psite&
pixel_iterator_base_<Image, Exact>::site()
{
//FIXME: update psite
return p_;
}
// FIXME: Dead code
// #################
// /*! \brief pixel_iterator_base_ class
// */
// template <typename Exact, typename Image>
// class pixel_iterator_base_ : public Pixel_Iterator<Exact>
// template <typename E, typename I>
// class pixel_iterator_base_ : public Pixel_Iterator<E>
// {
// public:
// /// Image pixel value type.
// typedef mln_value(Image) value;
// /// Image pixel rvalue type.
// typedef mln_value(Image)& rvalue;
// /// Image pixel lvalue type
// typedef mln_value(Image) lvalue;
// /// I pixel value type.
// typedef mln_value(I) value;
// /// I pixel rvalue type.
// typedef mln_value(I)& rvalue;
// /// I pixel lvalue type
// typedef mln_value(I) lvalue;
// // Go to the beginning of the image.
// void start();
......@@ -193,46 +224,46 @@ namespace mln