Commit eaab599c authored by Roland Levillain's avatar Roland Levillain
Browse files

Overhaul 1-D, 2-D and 3-D pixters.

	* mln/core/macros.hh (mln_bkd_pixter_): New macro.
	* mln/core/internal/pixel_iterator_base.hh
	(mln::pixel_iterator_base_<I, E>::start)
	(mln::pixel_iterator_base_<I, E>::invalidate)
	(mln::pixel_iterator_base_<I, E>::is_valid):
	Remove methods.
	(mln::forward_pixel_iterator_base_<I, E>)
	(mln::backward_pixel_iterator_base_<I, E>):
	New classes.
	* mln/core/pixter1d.hh
	(mln::fwd_pixter1d<I>): Inherit from
	mln::internal::forward_pixel_iterator_base_.
	(mln::bkd_pixter1d<I>): New class.
	* mln/core/pixter2d.hh
	(mln::fwd_pixter2d<I>): Inherit from
	mln::internal::forward_pixel_iterator_base_.
	(mln::bkd_pixter2d<I>): Inherit from
	mln::internal::backward_pixel_iterator_base_.
	(mln::bkd_pixter2d<I>::start): Remove method.
	(mln::fwd_pixter2d<I>::fwd_pixter2d)
	(mln::bkd_pixter2d<I>::bkd_pixter2d):
	Use initialization lists instead of assignments.
	* mln/core/pixter3d.hh
	(mln::fwd_pixter3d<I>): Inherit from
	mln::internal::forward_pixel_iterator_base_.
	(mln::bkd_pixter3d<I>): New class.
	* mln/core/p_image2d_pixter.hh
	(mln::p_image2d_fwd_pixter<P>): Inherit from
	mln::internal::forward_pixel_iterator_base_.
	(mln::p_image2d_bkd_pixter<P>): Inherit from
	mln::internal::backward_pixel_iterator_base_.
	* mln/core/image1d.hh (mln::trait::bkd_pixter< image1d<T> >::ret):
	Set to bkd_pixter1d< const image1d<T> >.
	* mln/core/image2d.hh: Add FIXMEs.
	* mln/core/image3d.hh (mln::trait::bkd_pixter< image3d<T> >::ret):
	Set to bkd_pixter3d< const image3d<T> >.
	* tests/core/pixter1d.cc, tests/core/pixter2d.cc:
	New tests.
	* tests/core/image3d.cc: Rename as...
	* tests/core/pixter3d.cc: ...this.
	Exercise bkd_pixter3d.
	* tests/core/Makefile.am (check_PROGRAMS): Remove image3d.
	Add pixter1d, pixter2d and pixter3d.
	(image3d_SOURCES): Remove.
	(pixter1d_SOURCES, pixter2d_SOURCES, pixter3d_SOURCES): New.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@1911 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent e8e96e7f
2008-05-01 Roland Levillain <roland@lrde.epita.fr>
Overhaul 1-D, 2-D and 3-D pixters.
* mln/core/macros.hh (mln_bkd_pixter_): New macro.
* mln/core/internal/pixel_iterator_base.hh
(mln::pixel_iterator_base_<I, E>::start)
(mln::pixel_iterator_base_<I, E>::invalidate)
(mln::pixel_iterator_base_<I, E>::is_valid):
Remove methods.
(mln::forward_pixel_iterator_base_<I, E>)
(mln::backward_pixel_iterator_base_<I, E>):
New classes.
* mln/core/pixter1d.hh
(mln::fwd_pixter1d<I>): Inherit from
mln::internal::forward_pixel_iterator_base_.
(mln::bkd_pixter1d<I>): New class.
* mln/core/pixter2d.hh
(mln::fwd_pixter2d<I>): Inherit from
mln::internal::forward_pixel_iterator_base_.
(mln::bkd_pixter2d<I>): Inherit from
mln::internal::backward_pixel_iterator_base_.
(mln::bkd_pixter2d<I>::start): Remove method.
(mln::fwd_pixter2d<I>::fwd_pixter2d)
(mln::bkd_pixter2d<I>::bkd_pixter2d):
Use initialization lists instead of assignments.
* mln/core/pixter3d.hh
(mln::fwd_pixter3d<I>): Inherit from
mln::internal::forward_pixel_iterator_base_.
(mln::bkd_pixter3d<I>): New class.
* mln/core/p_image2d_pixter.hh
(mln::p_image2d_fwd_pixter<P>): Inherit from
mln::internal::forward_pixel_iterator_base_.
(mln::p_image2d_bkd_pixter<P>): Inherit from
mln::internal::backward_pixel_iterator_base_.
* mln/core/image1d.hh (mln::trait::bkd_pixter< image1d<T> >::ret):
Set to bkd_pixter1d< const image1d<T> >.
* mln/core/image2d.hh: Add FIXMEs.
* mln/core/image3d.hh (mln::trait::bkd_pixter< image3d<T> >::ret):
Set to bkd_pixter3d< const image3d<T> >.
* tests/core/pixter1d.cc, tests/core/pixter2d.cc:
New tests.
* tests/core/image3d.cc: Rename as...
* tests/core/pixter3d.cc: ...this.
Exercise bkd_pixter3d.
* tests/core/Makefile.am (check_PROGRAMS): Remove image3d.
Add pixter1d, pixter2d and pixter3d.
(image3d_SOURCES): Remove.
(pixter1d_SOURCES, pixter2d_SOURCES, pixter3d_SOURCES): New.
2008-05-01 Roland Levillain <roland@lrde.epita.fr>
Fix mln::fwd_pixter3d.
......
......@@ -533,7 +533,7 @@ namespace mln
template <typename T>
struct bkd_pixter< image1d<T> >
{
typedef mln::internal::fixme ret;
typedef bkd_pixter1d< const image1d<T> > ret;
};
// qixter
......@@ -553,9 +553,12 @@ namespace mln
template <typename T, typename W>
struct bkd_qixter< image1d<T>, W >
{
// FIXME: Implement dpoints_bkd_pixter.
typedef mln::internal::fixme ret;
};
// FIXME: Nixters (see in image2d.hh)
} // end of namespace mln::trait
} // end of namespace mln
......
......@@ -581,6 +581,7 @@ namespace mln
template <typename T, typename W>
struct bkd_qixter< image2d<T>, W >
{
// FIXME: Implement dpoints_bkd_pixter.
typedef mln::internal::fixme ret;
};
......@@ -601,6 +602,7 @@ namespace mln
template <typename T, typename N>
struct bkd_nixter< image2d<T>, N >
{
// FIXME: Implement dpoints_bkd_pixter.
typedef mln::internal::fixme ret;
};
......
......@@ -573,7 +573,7 @@ namespace mln
template <typename T>
struct bkd_pixter< image3d<T> >
{
typedef mln::internal::fixme ret;
typedef bkd_pixter3d< const image3d<T> > ret;
};
// qixter
......@@ -593,9 +593,12 @@ namespace mln
template <typename T, typename W>
struct bkd_qixter< image3d<T>, W >
{
// FIXME: Implement dpoints_bkd_pixter.
typedef mln::internal::fixme ret;
};
// FIXME: Nixters (see in image2d.hh)
} // end of namespace mln::trait
} // end of namespace mln
......
// Copyright (C) 2007 EPITA Research and Development Laboratory
// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
......@@ -28,58 +28,102 @@
#ifndef MLN_CORE_INTERNAL_PIXEL_ITERATOR_BASE_HH
# define MLN_CORE_INTERNAL_PIXEL_ITERATOR_BASE_HH
/*! \file mln/core/internal/pixel_iterator_base.hh
*
* \brief Base class to factor code for pixel iterator classes.
*/
/// \file mln/core/internal/pixel_iterator_base.hh
/// \brief Base classes factoring code for pixel iterator classes.
# include <mln/core/concept/pixel_iterator.hh>
# include <mln/core/internal/pixel_impl.hh>
# include <mln/core/trait/qlf_value.hh>
namespace mln
{
namespace internal
{
/*---------------------------------------.
| internal::pixel_iterator_base_<I, E>. |
`---------------------------------------*/
/*! \internal A base class for pixel iterators.
*
*/
/// \internal A base class for pixel iterators.
template <typename I, typename E>
class pixel_iterator_base_ : public Pixel_Iterator<E>,
public internal::pixel_impl_<I, E>
{
typedef internal::pixel_impl_<I, E> super_;
public:
protected:
/// Constructor.
pixel_iterator_base_(I& image);
protected:
/// Beginning of the image.
mln_qlf_value(I)* boi_;
/// End of the image (past-the-end).
mln_qlf_value(I)* eoi_;
};
/*-----------------------------------------------.
| internal::forward_pixel_iterator_base_<I, E>. |
`-----------------------------------------------*/
/// \internal A base class for forward pixel iterators.
template <typename I, typename E>
class forward_pixel_iterator_base_ : public pixel_iterator_base_<I, E>
{
typedef pixel_iterator_base_<I, E> super_;
public:
/// Manipulation
/// \{
/// Start an iteration.
void start();
/// Invalidate the iterator.
void invalidate();
/// Test if the iterator is valid.
bool is_valid() const;
/// \}
protected:
/// Constructor.
forward_pixel_iterator_base_(I& image);
};
/// Beginning of the image.
mln_qlf_value(I)* boi_;
/// End of the image (past-the-end).
mln_qlf_value(I)* eoi_;
/*------------------------------------------------.
| internal::backward_pixel_iterator_base_<I, E>. |
`------------------------------------------------*/
/// \internal A base class for backward pixel iterators.
template <typename I, typename E>
class backward_pixel_iterator_base_ : public pixel_iterator_base_<I, E>
{
typedef pixel_iterator_base_<I, E> super_;
public:
/// Manipulation
/// \{
/// Start an iteration.
void start();
/// Invalidate the iterator.
void invalidate();
/// Test if the iterator is valid.
bool is_valid() const;
/// \}
protected:
/// Constructor.
pixel_iterator_base_(I& image);
backward_pixel_iterator_base_(I& image);
};
#ifndef MLN_INCLUDE_ONLY
/*---------------------------------------.
| internal::pixel_iterator_base_<I, E>. |
`---------------------------------------*/
template <typename I, typename E>
inline
pixel_iterator_base_<I, E>::pixel_iterator_base_(I& image)
......@@ -89,33 +133,79 @@ namespace mln
I& ima = this->image_;
boi_ = & ima( ima.domain().pmin() ) - 1;
eoi_ = & ima( ima.domain().pmax() ) + 1;
invalidate();
exact(*this).invalidate();
}
/*-----------------------------------------------.
| internal::forward_pixel_iterator_base_<I, E>. |
`-----------------------------------------------*/
template <typename I, typename E>
inline
forward_pixel_iterator_base_<I, E>::forward_pixel_iterator_base_(I& image)
: super_(image)
{
}
template <typename I, typename E>
inline
void
forward_pixel_iterator_base_<I, E>::start()
{
this->value_ptr_ = this->boi_ + 1;
}
template <typename I, typename E>
inline
void
forward_pixel_iterator_base_<I, E>::invalidate()
{
this->value_ptr_ = this->eoi_;
}
template <typename I, typename E>
inline
bool
forward_pixel_iterator_base_<I, E>::is_valid() const
{
return this->value_ptr_ != this->eoi_;
}
/*------------------------------------------------.
| internal::backward_pixel_iterator_base_<I, E>. |
`------------------------------------------------*/
template <typename I, typename E>
inline
backward_pixel_iterator_base_<I, E>::backward_pixel_iterator_base_(I& image)
: super_(image)
{
}
// FIXME: Remove cause dangerous when bkd!!!
template <typename I, typename E>
inline
void
pixel_iterator_base_<I, E>::start()
backward_pixel_iterator_base_<I, E>::start()
{
this->value_ptr_ = boi_ + 1;
this->value_ptr_ = this->eoi_ - 1;
}
template <typename I, typename E>
inline
void
pixel_iterator_base_<I, E>::invalidate()
backward_pixel_iterator_base_<I, E>::invalidate()
{
this->value_ptr_ = eoi_;
this->value_ptr_ = this->boi_;
}
// FIXME: Remove casue not optimal!!!
template <typename I, typename E>
inline
bool
pixel_iterator_base_<I, E>::is_valid() const
backward_pixel_iterator_base_<I, E>::is_valid() const
{
return this->value_ptr_ != eoi_ && this->value_ptr_ != boi_;
return this->value_ptr_ != this->boi_;
}
#endif // ! MLN_INCLUDE_ONLY
......
......@@ -286,6 +286,8 @@
# define mln_fwd_pixter_(I) mln::trait::fwd_pixter< I >::ret
# define mln_bkd_pixter(I) typename mln::trait::bkd_pixter< I >::ret
# define mln_bkd_pixter_(I) mln::trait::bkd_pixter< I >::ret
# define mln_pixter(I) mln_fwd_pixter(I)
# define mln_pixter_(I) mln_fwd_pixter_(I)
......
// Copyright (C) 2007 EPITA Research and Development Laboratory
// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
......@@ -28,49 +28,51 @@
#ifndef MLN_CORE_P_IMAGE2D_PIXTER_HH
# define MLN_CORE_P_IMAGE2D_PIXTER_HH
/*! \file mln/core/p_image2d_pixter.hh
*
* \brief Pixel iterator class on a image 2d with border.
*/
/// \file mln/core/p_image2d_pixter.hh
/// \brief Pixel iterators on a mln::p_image2d.
# include <mln/core/internal/pixel_iterator_base.hh>
# include <mln/core/point2d.hh>
# include <mln/geom/size2d.hh>
namespace mln
{
/*--------------------------.
| p_image2d_fwd_pixter<P>. |
`--------------------------*/
template <typename P>
class p_image2d_fwd_pixter : public internal::pixel_iterator_base_< typename p_image2d<P>::image_type, p_image2d_fwd_pixter<P> >
class p_image2d_fwd_pixter
: public internal::forward_pixel_iterator_base_<
typename p_image2d<P>::image_type,
p_image2d_fwd_pixter<P>
>
{
typedef internal::pixel_iterator_base_< typename p_image2d<P>::image_type, p_image2d_fwd_pixter<P> > super_;
typedef internal::forward_pixel_iterator_base_<
typename p_image2d<P>::image_type,
p_image2d_fwd_pixter<P>
> super_;
public:
/// Image type.
typedef typename p_image2d<P>::image_type image;
/// Point type.
typedef point2d point;
/*! \brief Constructor.
*
* \param[in] image Image to iterate over its pixels.
*/
/// \brief Constructor.
/// \param[in] image The mln::p_image2d this pixel iterator is bound to.
p_image2d_fwd_pixter(p_image2d<P>& s);
/// Reference of the corresponding point.
const point to_point() const;
/// Start an iteration.
void start();
/// Go to the next pixel.
void next_();
void start();
/// Reference of the corresponding point.
const point to_point() const;
private:
/// Row offset.
unsigned row_offset_;
/// End of the current row.
......@@ -78,66 +80,74 @@ namespace mln
};
/*--------------------------.
| p_image2d_bkd_pixter<P>. |
`--------------------------*/
template <typename P>
class p_image2d_bkd_pixter : public internal::pixel_iterator_base_< typename image2d<P>::image_type, p_image2d_bkd_pixter<P> >
class p_image2d_bkd_pixter
: public internal::backward_pixel_iterator_base_<
typename image2d<P>::image_type,
p_image2d_bkd_pixter<P>
>
{
typedef internal::pixel_iterator_base_< typename image2d<P>::image_type, p_image2d_bkd_pixter<P> > super_;
typedef internal::backward_pixel_iterator_base_<
typename image2d<P>::image_type,
p_image2d_bkd_pixter<P>
> super_;
public:
/// Image type.
typedef typename p_image2d<P>::image_type image;
/// Point type.
typedef point2d point;
/*! \brief Constructor.
*
* \param[in] image Image to iterate over its pixels.
*/
/// \brief Constructor.
/// \param[in] image The mln::p_image2d this pixel iterator is bound to.
p_image2d_bkd_pixter(p_image2d<P>& s);
/// Start an iteration.
void start();
/// Go to the next pixel.
void next_();
void start();
/// Reference of the corresponding point.
const point to_point() const;
private:
/// Row offset.
unsigned row_offset_;
/// Beginning of the current row.
mln_qlf_value(image)* bor_;
};
#ifndef MLN_INCLUDE_ONLY
// Fwd.
/*--------------------------.
| p_image2d_fwd_pixter<P>. |
`--------------------------*/
template <typename P>
inline
p_image2d_fwd_pixter<P>::p_image2d_fwd_pixter(p_image2d<P>& s) :
super_(s.image_non_const())
p_image2d_fwd_pixter<P>::p_image2d_fwd_pixter(p_image2d<P>& s)
: super_(s.image_non_const())
{
mln_precondition(this->image_.has_data());
row_offset_ = geom::max_col(this->image_) - geom::min_col(this->image_) + 1;
eor_ = & this->image_.at(geom::min_row(this->image_), geom::max_col(this->image_)) + 1;
eor_ = & this->image_.at(geom::min_row(this->image_),
geom::max_col(this->image_)) + 1;
}
template <typename P>
inline
const typename p_image2d_fwd_pixter<P>::point
p_image2d_fwd_pixter<P>::to_point() const
void
p_image2d_fwd_pixter<P>::start()
{
return this->image_.point_at_offset(*this);
this->value_ptr_ = this->boi_ + 1;
while(this->is_valid() && !(*this->value_ptr_))
++this->value_ptr_;
}
template <typename P>
......@@ -150,35 +160,38 @@ namespace mln
++this->value_ptr_;
}
template <typename P>
inline
void
p_image2d_fwd_pixter<P>::start()
const typename p_image2d_fwd_pixter<P>::point
p_image2d_fwd_pixter<P>::to_point() const
{
this->value_ptr_ = this->boi_ + 1;
while(this->is_valid() && !(*this->value_ptr_))
++this->value_ptr_;
return this->image_.point_at_offset(*this);
}
// Bkd.
/*--------------------------.
| p_image2d_bkd_pixter<P>. |
`--------------------------*/
template <typename P>
inline
p_image2d_bkd_pixter<P>::p_image2d_bkd_pixter(p_image2d<P>& s) :
super_(s.image_non_const())
p_image2d_bkd_pixter<P>::p_image2d_bkd_pixter(p_image2d<P>& s)
: super_(s.image_non_const())
{
mln_precondition(this->image_.has_data());
row_offset_ = geom::max_col(this->image_) - geom::min_col(this->image_) + 1;
bor_ = & this->image_.at(geom::max_row(this->image_), geom::min_col(this->image_)) - 1;
bor_ = & this->image_.at(geom::max_row(this->image_),
geom::min_col(this->image_)) - 1;
}
template <typename P>
inline
const typename p_image2d_bkd_pixter<P>::point
p_image2d_bkd_pixter<P>::to_point() const
void
p_image2d_bkd_pixter<P>::start()
{
return this->image_.point_at_offset(*this);
this->value_ptr_ = this->eoi_ - 1;
while(this->is_valid() && !(*this->value_ptr_))
--this->value_ptr_;
}
template <typename P>
......@@ -193,12 +206,10 @@ namespace mln
template <typename P>
inline
void
p_image2d_bkd_pixter<P>::start()
const typename p_image2d_bkd_pixter<P>::point
p_image2d_bkd_pixter<P>::to_point() const
{
this->value_ptr_ = this->eoi_ - 1;
while(this->is_valid() && !(*this->value_ptr_))
--this->value_ptr_;
return this->image_.point_at_offset(*this);
}
#endif // ! MLN_INCLUDE_ONLY
......
// Copyright (C) 2007 EPITA Research and Development Laboratory
// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
......@@ -28,51 +28,75 @@
#ifndef MLN_CORE_PIXTER1D_HH
# define MLN_CORE_PIXTER1D_HH
/*! \file mln/core/pixter1d.hh
*
* \brief Pixel iterator class on a image 1d with border.
*/
/// \file mln/core/pixter1d.hh
/// \brief Pixel iterators on a 1-D image with border.
# include <mln/core/internal/pixel_iterator_base.hh>
# include <mln/core/point1d.hh>
# include <mln/geom/size1d.hh>
namespace mln
{
/*------------------.
| fwd_pixter1d<I>. |
`------------------*/
/// Forward pixel iterator on a 1-D image with border.
template <typename I>
class fwd_pixter1d : public internal::pixel_iterator_base_< I, fwd_pixter1d<I> >
class fwd_pixter1d :
public internal::forward_pixel_iterator_base_< I, fwd_pixter1d<I> >
{
typedef internal::pixel_iterator_base_< I, fwd_pixter1d<I> > super_;
typedef internal::forward_pixel_iterator_base_< I, fwd_pixter1d<I> > super_;
public:
/// Image type.
typedef I image;
/*! \brief Constructor.