Commit 69c35966 authored by Roland Levillain's avatar Roland Levillain
Browse files

Complete delta-point pixel iterators.

	* mln/core/dpoints_pixter.hh: Aesthetic changes.
	Add some more documentation.
	(dpoints_fwd_pixter(const Generalized_Pixel<Pref>& const Dps&)):
	Use const_cast instead of legacy casts.
	(mln::dpoints_bkd_pixter<I>): New pixel iterator class.
	* mln/core/pixel.hh (mln::pixel<I>::pixel (I&)): Don't set member
	value_ptr_ to 0, since the super class' ctor already takes care of
	this.
	* mln/core/image1d.hh
	(mln::trait::bkd_qixter< image1d<T>, W >)
	(mln::trait::bkd_qixter< const image1d<T>, W >)
	(mln::trait::fwd_nixter< image1d<T>, W >)
	(mln::trait::fwd_nixter< const image1d<T>, W >)
	(mln::trait::bkd_nixter< image1d<T>, W >)
	(mln::trait::bkd_nixter< const image1d<T>, W >)
	* mln/core/image2d.hh
	(mln::trait::bkd_qixter< image2d<T>, W >)
	(mln::trait::bkd_qixter< const image2d<T>, W >)
	(mln::trait::bkd_nixter< image2d<T>, W >)
	(mln::trait::bkd_nixter< const image2d<T>, W >)
	* mln/core/image3d.hh
	(mln::trait::bkd_qixter< image3d<T>, W >)
	(mln::trait::bkd_qixter< const image3d<T>, W >)
	(mln::trait::fwd_nixter< image3d<T>, W >)
	(mln::trait::fwd_nixter< const image3d<T>, W >)
	(mln::trait::bkd_nixter< image3d<T>, W >)
	(mln::trait::bkd_nixter< const image3d<T>, W >):
	Define these specialisations.
	* mln/core/internal/force_exact.hh (mln::internal::force_exact):
	Use ptrdiff_t instead of int to store the pointer difference.
	Remove dead code.
	* mln/core/macros.hh
	(mln_fwd_qixter_, mln_bkd_qixter_, mln_qixter_)
	(mln_fwd_nixter_, mln_bkd_nixter_, mln_nixter_):
	New macros.
	* tests/dpoints_pixter.cc: Move...
	* tests/core/dpoints_pixter.cc: ...here.
	Exercise mln::dpoints_bkd_pixter as well.
	* tests/Makefile.am (check_PROGRAMS): Remove dpoints_pixter.
	(dpoints_pixter_SOURCES): Move...
	* tests/core/Makefile.am: ...here.
	(check_PROGRAMS): Add dpoints_pixter.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@1913 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 01c98c67
2008-05-05 Roland Levillain <roland@lrde.epita.fr>
Complete delta-point pixel iterators.
* mln/core/dpoints_pixter.hh: Aesthetic changes.
Add some more documentation.
(dpoints_fwd_pixter(const Generalized_Pixel<Pref>& const Dps&)):
Use const_cast instead of legacy casts.
(mln::dpoints_bkd_pixter<I>): New pixel iterator class.
* mln/core/pixel.hh (mln::pixel<I>::pixel (I&)): Don't set member
value_ptr_ to 0, since the super class' ctor already takes care of
this.
* mln/core/image1d.hh
(mln::trait::bkd_qixter< image1d<T>, W >)
(mln::trait::bkd_qixter< const image1d<T>, W >)
(mln::trait::fwd_nixter< image1d<T>, W >)
(mln::trait::fwd_nixter< const image1d<T>, W >)
(mln::trait::bkd_nixter< image1d<T>, W >)
(mln::trait::bkd_nixter< const image1d<T>, W >)
* mln/core/image2d.hh
(mln::trait::bkd_qixter< image2d<T>, W >)
(mln::trait::bkd_qixter< const image2d<T>, W >)
(mln::trait::bkd_nixter< image2d<T>, W >)
(mln::trait::bkd_nixter< const image2d<T>, W >)
* mln/core/image3d.hh
(mln::trait::bkd_qixter< image3d<T>, W >)
(mln::trait::bkd_qixter< const image3d<T>, W >)
(mln::trait::fwd_nixter< image3d<T>, W >)
(mln::trait::fwd_nixter< const image3d<T>, W >)
(mln::trait::bkd_nixter< image3d<T>, W >)
(mln::trait::bkd_nixter< const image3d<T>, W >):
Define these specialisations.
* mln/core/internal/force_exact.hh (mln::internal::force_exact):
Use ptrdiff_t instead of int to store the pointer difference.
Remove dead code.
* mln/core/macros.hh
(mln_fwd_qixter_, mln_bkd_qixter_, mln_qixter_)
(mln_fwd_nixter_, mln_bkd_nixter_, mln_nixter_):
New macros.
* tests/dpoints_pixter.cc: Move...
* tests/core/dpoints_pixter.cc: ...here.
Exercise mln::dpoints_bkd_pixter as well.
* tests/Makefile.am (check_PROGRAMS): Remove dpoints_pixter.
(dpoints_pixter_SOURCES): Move...
* tests/core/Makefile.am: ...here.
(check_PROGRAMS): Add dpoints_pixter.
2008-05-01 Roland Levillain <roland@lrde.epita.fr>
Add adjaceny tests for mln::p_line_graph.
......
// 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,11 +28,10 @@
#ifndef MLN_CORE_DPOINTS_PIXTER_HH
# define MLN_CORE_DPOINTS_PIXTER_HH
/*! \file mln/core/dpoints_pixter.hh
*
* \brief Definition of forward and backward mln::dpoint_ based
* iterators for pixels iterations.
*/
/// \file mln/core/dpoints_pixter.hh
///
/// \brief Definition of forward and backward mln::dpoint-based
/// iterators for pixels iterations.
# include <cassert>
# include <vector>
......@@ -42,88 +41,183 @@
# include <mln/core/internal/pixel_impl.hh>
namespace mln
{
/*! \brief A generic forward iterator on pixels of windows and of
* neighborhoods.
*
* The parameter \c I is the image type.
*/
/*------------------------.
| dpoints_fwd_pixter<I>. |
`------------------------*/
/// \brief A generic forward iterator on the pixels of a
/// dpoint-based window or neighborhood.
///
/// Parameter \c I is the image type.
template <typename I>
class dpoints_fwd_pixter : public Pixel_Iterator< dpoints_fwd_pixter<I> >,
public internal::pixel_impl_< I, dpoints_fwd_pixter<I> >
class dpoints_fwd_pixter
: public Pixel_Iterator< dpoints_fwd_pixter<I> >,
public internal::pixel_impl_< I, dpoints_fwd_pixter<I> >
{
typedef typename internal::pixel_impl_< I, dpoints_fwd_pixter<I> > super_;
public:
/*! \brief Constructor.
*
* \param[in] image Image subject to iteration.
* \param[in] dps Object that can provide a set of delta-points.
* \param[in] p_ref Center point to iterate around.
*/
public:
/// \brief Constructor (using an image).
///
/// \param[in] image The image to iterate over.
/// \param[in] dps An object (neighborhood or window) that can
/// provide a set of delta-points.
/// \param[in] p_ref Center (resp. reference) point of the
/// neighborhood (resp. window).
template <typename Dps, typename Pref>
dpoints_fwd_pixter(I& image,
const Dps& dps,
const Point_Site<Pref>& p_ref);
/*! \brief Constructor.
*
* \param[in] pxl_ref Center (generalized) pixel to iterate around.
* \param[in] dps Object that can provide a set of delta-points.
*/
/// \brief Constructor (using a generalized pixel).
///
/// \param[in] pxl_ref Center (generalized) pixel to iterate around.
/// \param[in] dps An object (neighborhood or window) that can
/// provide a set of delta-points.
template <typename Dps, typename Pref>
dpoints_fwd_pixter(const Generalized_Pixel<Pref>& pxl_ref,
const Dps& dps);
/// Manipulation.
/// \{
/// Start an iteration.
void start();
/// Go to the next pixel.
void next_();
/// Invalidate the iterator.
void invalidate();
/// 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 mln_value(I)& center_val() const;
private:
template <typename Dps>
void init_(const Dps& dps);
/// offset of each dpoints
private:
/// \brief Offset of each delta-point.
///
/// offset_[0] is absolute, while other offsets are relative
/// (i.e., offset_[i] is the memory difference to go from pixel
/// i-1 to pixel i.
std::vector<int> offset_;
/// current offset
/// Current offset.
// FIXME: Why not an iterator on vector offset_?
unsigned i_;
/// reference pixel / point in the image
/// \brief Reference value or pixel.
///
/// One and only one of these pointers should be non-null.
/// \{
/// Reference value the image
mln_qlf_value(I)** value_ref_;
// or:
/// Reference pixel / point in the image
const mln_point(I)* p_ref_;
/// \}
};
/*------------------------.
| dpoints_bkd_pixter<I>. |
`------------------------*/
/// \brief A generic backward iterator on the pixels of a
/// dpoint-based window or neighborhood.
///
/// Parameter \c I is the image type.
template <typename I>
class dpoints_bkd_pixter
: public Pixel_Iterator< dpoints_bkd_pixter<I> >,
public internal::pixel_impl_< I, dpoints_bkd_pixter<I> >
{
typedef typename internal::pixel_impl_< I, dpoints_bkd_pixter<I> > super_;
public:
/// \brief Constructor (using an image).
///
/// \param[in] image The image to iterate over.
/// \param[in] dps An object (neighborhood or window) that can
/// provide a set of delta-points.
/// \param[in] p_ref Center (resp. reference) point of the
/// neighborhood (resp. window).
template <typename Dps, typename Pref>
dpoints_bkd_pixter(I& image,
const Dps& dps,
const Point_Site<Pref>& p_ref);
/// \brief Constructor (using a generalized pixel).
///
/// \param[in] pxl_ref Center (generalized) pixel to iterate around.
/// \param[in] dps An object (neighborhood or window) that can
/// provide a set of delta-points.
template <typename Dps, typename Pref>
dpoints_bkd_pixter(const Generalized_Pixel<Pref>& pxl_ref,
const Dps& dps);
/// Manipulation.
/// \{
/// Start an iteration.
void start();
/// Go to the next pixel.
void next_();
/// Invalidate the iterator.
void invalidate();
/// 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 mln_value(I)& center_val() const;
private:
template <typename Dps>
void init_(const Dps& dps);
};
// FIXME: dpoints_bkd_pixter<I>
private:
/// \brief Offset of each delta-point.
///
/// offset_[dps.ndpoints() - 1] is absolute, while other offsets
/// are relative (i.e., offset_[i] is the memory difference to go
/// from pixel i+1 to pixel i.
std::vector<int> offset_;
/// Current offset.
// FIXME: Why not an iterator on vector offset_?
int i_;
/// \brief Reference value or pixel.
///
/// One and only one of these pointers should be non-null.
/// \{
/// Reference value the image
mln_qlf_value(I)** value_ref_;
/// Reference pixel / point in the image
const mln_point(I)* p_ref_;
/// \}
};
#ifndef MLN_INCLUDE_ONLY
// dpoints_fwd_pixter<I>
/*------------------------.
| dpoints_fwd_pixter<I>. |
`------------------------*/
template <typename I>
template <typename Dps, typename Pref>
......@@ -149,8 +243,8 @@ namespace mln
const Pref& pxl_ref = internal::force_exact<Pref>(pxl_ref_);
mln_precondition(pxl_ref.ima().has_data());
p_ref_ = 0;
// potential promotion from (T**) to (const T**) shall be forced:
value_ref_ = (mln_qlf_value(I)**)(void*)(pxl_ref.address_());
// Potential promotion from (T**) to (const T**) shall be forced.
value_ref_ = const_cast<mln_qlf_value(I)**>(pxl_ref.address_());
init_(dps);
}
......@@ -163,7 +257,7 @@ namespace mln
if (p_ref_)
return image_(*p_ref_);
else
return ** value_ref_;
return **value_ref_;
}
template <typename I>
......@@ -231,6 +325,117 @@ namespace mln
i_ = offset_.size();
}
/*------------------------.
| dpoints_bkd_pixter<I>. |
`------------------------*/
template <typename I>
template <typename Dps, typename Pref>
inline
dpoints_bkd_pixter<I>::dpoints_bkd_pixter(I& image,
const Dps& dps,
const Point_Site<Pref>& p_ref)
: super_(image)
{
mln_precondition(image.has_data());
p_ref_ = & exact(p_ref).to_point();
value_ref_ = 0;
init_(dps);
}
template <typename I>
template <typename Dps, typename Pref>
inline
dpoints_bkd_pixter<I>::dpoints_bkd_pixter(const Generalized_Pixel<Pref>& pxl_ref_,
const Dps& dps)
: super_(internal::force_exact<Pref>(pxl_ref_).ima())
{
const Pref& pxl_ref = internal::force_exact<Pref>(pxl_ref_);
mln_precondition(pxl_ref.ima().has_data());
p_ref_ = 0;
// Potential promotion from (T**) to (const T**) shall be forced.
value_ref_ = const_cast<mln_qlf_value(I)**>(pxl_ref.address_());
init_(dps);
}
template <typename I>
inline
const mln_value(I)&
dpoints_bkd_pixter<I>::center_val() 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>
inline
void
dpoints_bkd_pixter<I>::init_(const Dps& dps)
{
for (unsigned i = 0; i < dps.ndpoints(); ++i)
offset_.push_back(this->image_.offset(dps.dp(i)));
// offset_[ndpoints() - 1] is absolute
// other offsets are relative:
if (dps.ndpoints() > 1)
for (unsigned i = 0; i < dps.ndpoints() - 1; ++i)
offset_[i] -= offset_[i + 1];
invalidate();
}
template <typename I>
inline
void
dpoints_bkd_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>
inline
void
dpoints_bkd_pixter<I>::start()
{
i_ = offset_.size() - 1;
update();
}
template <typename I>
inline
void
dpoints_bkd_pixter<I>::next_()
{
--i_;
if (is_valid())
this->value_ptr_ += offset_[i_];
}
template <typename I>
inline
bool
dpoints_bkd_pixter<I>::is_valid() const
{
return i_ >= 0;
}
template <typename I>
inline
void
dpoints_bkd_pixter<I>::invalidate()
{
i_ = -1;
}
#endif // ! MLN_INCLUDE_ONLY
} // 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,10 +28,8 @@
#ifndef MLN_CORE_IMAGE1D_HH
# define MLN_CORE_IMAGE1D_HH
/*! \file mln/core/image1d.hh
*
* \brief Definition of the basic mln::image1d class.
*/
/// \file mln/core/image1d.hh
/// \brief Definition of the basic mln::image1d class.
# include <mln/core/internal/fixme.hh>
# include <mln/core/internal/image_primary.hh>
......@@ -553,11 +551,40 @@ namespace mln
template <typename T, typename W>
struct bkd_qixter< image1d<T>, W >
{
// FIXME: Implement dpoints_bkd_pixter.
typedef mln::internal::fixme ret;
typedef dpoints_bkd_pixter< image1d<T> > ret;
};
// FIXME: Nixters (see in image2d.hh)
template <typename T, typename W>
struct bkd_qixter< const image1d<T>, W >
{
typedef dpoints_bkd_pixter< const image1d<T> > ret;
};
// nixter
template <typename T, typename W>
struct fwd_nixter< image1d<T>, W >
{
typedef dpoints_fwd_pixter< image1d<T> > ret;
};
template <typename T, typename W>
struct fwd_nixter< const image1d<T>, W >
{
typedef dpoints_fwd_pixter< const image1d<T> > ret;
};
template <typename T, typename W>
struct bkd_nixter< image1d<T>, W >
{
typedef dpoints_bkd_pixter< image1d<T> > ret;
};
template <typename T, typename W>
struct bkd_nixter< const image1d<T>, W >
{
typedef dpoints_bkd_pixter< const image1d<T> > ret;
};
} // end of namespace mln::trait
......
// 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,10 +28,8 @@
#ifndef MLN_CORE_IMAGE2D_HH
# define MLN_CORE_IMAGE2D_HH
/*! \file mln/core/image2d.hh
*
* \brief Definition of the basic mln::image2d class.
*/
/// \file mln/core/image2d.hh
/// \brief Definition of the basic mln::image2d class.
# include <mln/core/internal/image_primary.hh>
# include <mln/core/internal/fixme.hh>
......@@ -581,8 +579,13 @@ namespace mln
template <typename T, typename W>
struct bkd_qixter< image2d<T>, W >
{
// FIXME: Implement dpoints_bkd_pixter.
typedef mln::internal::fixme ret;
typedef dpoints_bkd_pixter< image2d<T> > ret;
};
template <typename T, typename W>
struct bkd_qixter< const image2d<T>, W >
{
typedef dpoints_bkd_pixter< const image2d<T> > ret;
};
// nixter
......@@ -602,8 +605,13 @@ namespace mln
template <typename T, typename N>
struct bkd_nixter< image2d<T>, N >
{
// FIXME: Implement dpoints_bkd_pixter.
typedef mln::internal::fixme ret;
typedef dpoints_bkd_pixter< image2d<T> > ret;
};
template <typename T, typename N>
struct bkd_nixter< const image2d<T>, N >
{
typedef dpoints_bkd_pixter< const image2d<T> > ret;
};
} // end of namespace mln::trait
......
// 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,10 +28,8 @@
#ifndef MLN_CORE_IMAGE3D_HH
# define MLN_CORE_IMAGE3D_HH
/*! \file mln/core/image3d.hh
*
* \brief Definition of the basic mln::image3d class.
*/
/// \file mln/core/image3d.hh
/// \brief Definition of the basic mln::image3d class.
# include <mln/core/internal/fixme.hh>
# include <mln/core/internal/image_primary.hh>
......@@ -593,11 +591,40 @@ namespace mln
template <typename T, typename W>
struct bkd_qixter< image3d<T>, W >
{
// FIXME: Implement dpoints_bkd_pixter.
typedef mln::internal::fixme ret;
typedef dpoints_bkd_pixter< image3d<T> > ret;
};
// FIXME: Nixters (see in image2d.hh)
template <typename T, typename W>
struct bkd_qixter< const image3d<T>, W >
{
typedef dpoints_bkd_pixter< const image3d<T> > ret;
};
// nixter
template <typename T, typename W>
struct fwd_nixter< image3d<T>, W >
{
typedef dpoints_fwd_pixter< image3d<T> > ret;
};
template <typename T, typename W>
struct fwd_nixter< const image3d<T>, W >
{
typedef dpoints_fwd_pixter< const image3d<T> > ret;
};
template <typename T, typename W>
struct bkd_nixter< image3d<T>, W >
{
typedef dpoints_bkd_pixter< image3d<T> > ret;
};
template <typename T, typename W>
struct bkd_nixter< const image3d<T>, W >
{
typedef dpoints_bkd_pixter< const image3d<T> > ret;
};
} // end of namespace mln::trait
......
// 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,12 +28,10 @@
#ifndef MLN_CORE_INTERNAL_FORCE_EXACT_HH
# define MLN_CORE_INTERNAL_FORCE_EXACT_HH
/*! \file mln/core/internal/force_exact.hh
*
* \brief Definition of a violent cast for internal use only.
*
*/
/// \file mln/core/internal/force_exact.hh
/// \brief Definition of a violent cast for internal use only.
#include <cstddef>
namespace mln
......@@ -42,29 +40,22 @@ namespace mln
namespace internal
{
/*! \internal Violent cast.
* This cast is an alternative to the mln::exact cast.
* It is used for objects that do not derive from
* mln::Object.