Commit 3e354f09 authored by Thierry Geraud's avatar Thierry Geraud
Browse files

Add some morphers and handle constness in pixterators.

	Add new morphers.
	
	* tests/cast_image.cc: New.
	* tests/assign.cc: New.
	* tests/fimage.cc: New.
	* mln/core/fimage.hh: New.
	* mln/level/assign.hh: New.
	* mln/value/cast.hh: New.

	* mln/core/safe.hh: Rename as...
	* mln/core/safe_image.hh: ...this.
	* tests/safe_image.cc: Update.
	* mln/core/vec.hh: Rename as...
	* mln/metal/vec.hh: ...this.
	
	Handle constness in pixel iterators.
	
	* mln/core/internal/pixel_impl.hh (value_): New.
	(address): Update.
	* mln/core/internal/pixel_iterator_base.hh
	(qualified_value, value_): New.
	* mln/core/pixter2d_b.hh (value_): Update.
	* mln/core/dpoints_pixter.hh (value_): Update.
	* mln/core/internal/image_adaptor.hh
	(vset, values): Fix missing.
	* mln/core/concept/generalized_pixel.hh
	(ctor): Comment check on address.
	* mln/core/concept/pixel_iterator.hh
	(ctor): Comment check on lvalue and op*.
	* mln/core/concept/fast_image.hh (offset): Fix missing const.
	* mln/core/image2d_b.hh: Likewise.
	* mln/core/concept/doc/image.hh: Cosmetic changes.
	* mln/level/fast_median.hh (input): Update.

	* TODO: Update.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@1034 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent ab3010b4
2007-07-23 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Add some morphers and handle constness in pixterators.
Add new morphers.
* tests/cast_image.cc: New.
* tests/assign.cc: New.
* tests/fimage.cc: New.
* mln/core/fimage.hh: New.
* mln/level/assign.hh: New.
* mln/value/cast.hh: New.
* mln/core/safe.hh: Rename as...
* mln/core/safe_image.hh: ...this.
* tests/safe_image.cc: Update.
* mln/core/vec.hh: Rename as...
* mln/metal/vec.hh: ...this.
Handle constness in pixel iterators.
* mln/core/internal/pixel_impl.hh (value_): New.
(address): Update.
* mln/core/internal/pixel_iterator_base.hh
(qualified_value, value_): New.
* mln/core/pixter2d_b.hh (value_): Update.
* mln/core/dpoints_pixter.hh (value_): Update.
* mln/core/internal/image_adaptor.hh
(vset, values): Fix missing.
* mln/core/concept/generalized_pixel.hh
(ctor): Comment check on address.
* mln/core/concept/pixel_iterator.hh
(ctor): Comment check on lvalue and op*.
* mln/core/concept/fast_image.hh (offset): Fix missing const.
* mln/core/image2d_b.hh: Likewise.
* mln/core/concept/doc/image.hh: Cosmetic changes.
* mln/level/fast_median.hh (input): Update.
* TODO: Update.
2007-07-23 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Some renaming and add phantom border routines.
......
......@@ -17,7 +17,6 @@ Weighted_Window
value::proxy to dispatch read/write + the corresponding image type
a mean_value object { sum; count } and operator+
value_cast<T>(image)
t_image to "transpose" the 0 and the i-th coordinates
image defined by f/pset
......@@ -45,6 +44,5 @@ reconstructions + their canvases
fast versions of level::fill and level::paste
histogram class
sorting points w.r.t. their value (array of offsets, psites, points)
border::* and no-op versions if not fast image
arith::inplace_plus et al.
linear:: for convolutions
......@@ -41,6 +41,7 @@ namespace mln
template <typename E>
struct Image : public Object<E>
{
/*! \brief Value associated type.
*
* \invariant This type is neither qualified by const, nor by
......@@ -61,6 +62,7 @@ namespace mln
*/
typedef void vset;
/*! \brief Test if the image have been initialized.
*/
bool has_data() const;
......
......@@ -49,8 +49,8 @@ namespace mln
/*
unsigned border();
int offset(const dpoint& dp);
unsigned offset(const point& p);
int offset(const dpoint& dp) const;
unsigned offset(const point& p) const;
point point_at_offset(unsigned o) const;
const value* buffer() const;
......@@ -75,9 +75,9 @@ namespace mln
typedef mln_fwd_pixter(E) fwd_pixter;
typedef mln_bkd_pixter(E) bkd_pixter;
int (E::*m1)(const dpoint&) = & E::offset;
int (E::*m1)(const dpoint&) const = & E::offset;
m1 = 0;
unsigned (E::*m2)(const point&) = & E::offset;
unsigned (E::*m2)(const point&) const = & E::offset;
m2 = 0;
point (E::*m3)(unsigned) const = & E::point_at_offset;
m3 = 0;
......
......@@ -77,8 +77,9 @@ namespace mln
typedef mln_rvalue(E) rvalue;
rvalue (E::*m1)() const = & E::operator*;
m1 = 0;
value** (E::*m2)() const = & E::address_;
m2 = 0;
// FIXME: Activate (so add qualif_value):
// value** (E::*m2)() const = & E::address_;
// m2 = 0;
}
# endif // ! MLN_INCLUDE_ONLY
......
......@@ -54,8 +54,9 @@ namespace mln
public Generalized_Pixel<E>
{
/*
typedef lvalue;
only if the iterator is constructed on a mutable image:
typedef lvalue;
lvalue operator*();
*/
protected:
......@@ -68,9 +69,9 @@ namespace mln
template <typename E>
Pixel_Iterator<E>::Pixel_Iterator()
{
typedef mln_lvalue(E) lvalue;
lvalue (E::*m)() = & E::operator*;
m = 0;
// typedef mln_lvalue(E) lvalue;
// lvalue (E::*m)() = & E::operator*;
// m = 0;
}
#endif // ! MLN_INCLUDE_ONLY
......
......@@ -55,11 +55,11 @@ namespace mln
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;
typedef typename internal::pixel_impl_< I, dpoints_fwd_pixter<I> > super_;
public:
/// Using super value type.
typedef mln_value(super) value;
typedef typename super_::value_ value_;
/*! \brief Constructor.
*
......@@ -111,7 +111,7 @@ namespace mln
unsigned i_;
/// reference pixel / point in the image
value** value_ref_;
value_** value_ref_;
// or:
const mln_point(I)* p_ref_;
......@@ -135,7 +135,7 @@ namespace mln
dpoints_fwd_pixter<I>::dpoints_fwd_pixter(I& image,
const Dps& dps,
const Generalized_Point<Pref>& p_ref)
: super(image)
: super_(image)
{
mln_precondition(image.has_data());
p_ref_ = internal::force_exact<Pref>(p_ref).pointer_();
......@@ -149,7 +149,7 @@ namespace mln
dpoints_fwd_pixter<I>::dpoints_fwd_pixter(I& image,
const Dps& dps,
const Generalized_Pixel<Pref>& p_ref)
: super(image)
: super_(image)
{
mln_precondition(image.has_data());
p_ref_ = 0;
......
// 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_FIMAGE_HH
# define MLN_CORE_FIMAGE_HH
/*! \file mln/core/fimage.hh
*
* \brief Definition of an image class FIXME
*/
# include <mln/core/internal/image_base.hh>
# include <mln/core/concept/function.hh>
# include <mln/value/set.hh>
namespace mln
{
/*! \brief FIXME
*
*/
template <typename F, typename S>
struct fimage : public internal::image_base_< S, fimage<F,S> >
{
/// Point_Site associated type.
typedef mln_psite(S) psite;
/// Point_Set associated type.
typedef S pset;
/// Value associated type.
typedef mln_result(F) value;
/// Return type of read-only access.
typedef mln_result(F) rvalue;
/// Return type of read-write access.
typedef void lvalue; // FIXME
/// Value set associated type.
typedef mln::value::set_<mln_result(F)> vset;
/// Constructor.
fimage(const Function_p2v<F>& f, const Point_Set<S>& ps);
/// Test if this image has been initialized.
bool has_data() const;
/// Test if a pixel value is accessible at \p p.
bool owns_(const psite& p) const;
/// Give the definition domain.
const S& domain() const;
/// Read-only access of pixel value at point site \p p.
mln_result(F) operator()(const psite& p) const;
/// Read-write access of pixel value at point site \p p.
void operator()(const psite& p);
/// Give the set of values of the image.
const vset& values() const;
/// Change value type. FIXME!
template <typename U>
struct change_value
{
typedef void ret;
};
protected:
F f_;
S pset_;
};
template <typename F, typename S>
fimage<F,S>
operator | (const Function_p2v<F>& f, const Point_Set<S>& ps)
{
fimage<F,S> tmp(f, ps);
return tmp;
}
# ifndef MLN_INCLUDE_ONLY
template <typename F, typename S>
fimage<F,S>::fimage(const Function_p2v<F>& f, const Point_Set<S>& ps)
: f_(exact(f)),
pset_(exact(ps))
{
}
template <typename F, typename S>
bool fimage<F,S>::has_data() const
{
return true;
}
template <typename F, typename S>
bool fimage<F,S>::owns_(const psite& p) const
{
return pset_.has(p);
}
template <typename F, typename S>
const S&
fimage<F,S>::domain() const
{
return pset_;
}
template <typename F, typename S>
mln_result(F)
fimage<F,S>::operator()(const psite& p) const
{
mln_precondition(pset_.has(p));
return f_(p);
}
template <typename F, typename S>
void
fimage<F,S>::operator()(const psite& p)
{
mln_invariant(0); // FIXME: Turn into a compile-time error...
}
template <typename F, typename S>
const mln::value::set_<mln_result(F)>&
fimage<F,S>::values() const
{
return vset::the();
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
#endif // ! MLN_CORE_FIMAGE_HH
......@@ -190,10 +190,10 @@ namespace mln
/// Fast Image method
/// Give the offset corresponding to the delta-point \p dp.
int offset(const dpoint2d& dp);
int offset(const dpoint2d& dp) const;
/// Give the offset corresponding to the point \p p.
unsigned offset(const point2d& p);
unsigned offset(const point2d& p) const;
/// Give the point corresponding to the offset \p o.
point2d point_at_offset(unsigned o) const;
......@@ -412,7 +412,7 @@ namespace mln
template <typename T>
int
image2d_b<T>::offset(const dpoint2d& dp)
image2d_b<T>::offset(const dpoint2d& dp) const
{
mln_precondition(this->has_data());
int o = dp[0] * vb_.len(1) + dp[1];
......@@ -421,7 +421,7 @@ namespace mln
template <typename T>
unsigned
image2d_b<T>::offset(const point2d& p)
image2d_b<T>::offset(const point2d& p) const
{
mln_precondition(this->owns_(p));
unsigned o = & this->operator()(p) - this->buffer_;
......@@ -534,6 +534,12 @@ namespace mln
typedef dpoints_fwd_pixter< image2d_b<T> > ret;
};
template <typename T, typename W>
struct fwd_qixter< const image2d_b<T>, W >
{
typedef dpoints_fwd_pixter< const image2d_b<T> > ret;
};
template <typename T, typename W>
struct bkd_qixter< image2d_b<T>, W >
{
......
......@@ -51,12 +51,16 @@ namespace mln
typename S = mln_pset(I) >
struct image_adaptor_ : public internal::image_base_< S, E >
{
/// Point_Site associated type.
typedef mln_psite(S) psite;
/// Point_Set associated type.
typedef S pset;
/// Value_Set associated type.
typedef mln_vset(I) vset;
/// Value associated type.
typedef mln_value(I) value;
......@@ -66,6 +70,7 @@ namespace mln
/// Return type of read-write access.
typedef mln_lvalue(I) lvalue;
/// Test if this image has been initialized.
bool has_data() const;
......@@ -75,12 +80,16 @@ namespace mln
/// Give the definition domain.
const S& domain() const;
/// Give the set of values.
const vset& values() const;
/// Read-only access of pixel value at point site \p p.
rvalue operator()(const psite& p) const;
/// Read-write access of pixel value at point site \p p.
lvalue operator()(const psite& p);
protected:
I& adaptee_;
......@@ -115,6 +124,13 @@ namespace mln
return adaptee_.domain();
}
template <typename I, typename E, typename S>
const mln_vset(I)&
image_adaptor_<I,E,S>::values() const
{
return adaptee_.values();
}
template <typename I, typename E, typename S>
typename image_adaptor_<I,E,S>::rvalue
image_adaptor_<I,E,S>::operator()(const psite& p) const
......
......@@ -62,6 +62,9 @@ namespace mln
/// Image rvalue type.
typedef mln_rvalue(I) rvalue;
/// Qualified value type.
typedef value value_;
/// pixel iterator value.
lvalue operator*();
......@@ -105,13 +108,16 @@ namespace mln
/// Image rvalue type.
typedef mln_rvalue(I) rvalue;
/// Qualified value type.
typedef const value value_;
/// Get the pixel iterator value.
rvalue operator*() const;
/// Address of the current iterator value/pixel.
value** address_() const;
const value** address_() const;
protected:
......@@ -197,11 +203,11 @@ namespace mln
}
template <typename I, typename E>
mln_value(I) **
const mln_value(I) **
pixel_impl_<const I, E>::address_() const
{
mln_precondition(is_valid_());
return (value**)(& this->value_ptr_);
return (const value**)(& this->value_ptr_);
}
#endif // ! MLN_INCLUDE_ONLY
......
......@@ -43,6 +43,22 @@ namespace mln
namespace internal
{
template <typename I>
struct qualified_value
{
typedef mln_value(I) ret;
};
template <typename I>
struct qualified_value< const I >
{
typedef const mln_value(I) ret;
};
/*! \brief A base class for pixel iterators.
*
*/
......@@ -51,8 +67,7 @@ namespace mln
public internal::pixel_impl_<I, E>
{
typedef internal::pixel_impl_<I, E> super_;
typedef mln_value(super_) value_;
public:
/// Start an iteration.
......@@ -64,6 +79,9 @@ namespace mln
/// Test if the iterator is valid.
bool is_valid() const;
/// Qualified (const or not) value type.
typedef typename qualified_value<I>::ret value_;
protected:
/// Beginning of the image.
......
......@@ -45,7 +45,8 @@ namespace mln
class fwd_pixter2d_b : public internal::pixel_iterator_base_< I, fwd_pixter2d_b<I> >
{
typedef internal::pixel_iterator_base_< I, fwd_pixter2d_b<I> > super_;
typedef mln_value(super_) value_;
typedef typename super_::value_ value_;
public:
/*! \brief Constructor.
......
......@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
#ifndef MLN_CORE_SAFE_IMAGE_HH
# define MLN_CORE_SAFE_IMAGE_HH
#ifndef MLN_CORE_SAFE_HH
# define MLN_CORE_SAFE_HH
# include <mln/core/internal/image_adaptor.hh>
......@@ -34,6 +34,7 @@
namespace mln
{
// FIXME: Doc!
template <typename I>
struct safe_image : public internal::image_adaptor_< I, safe_image<I> >
......@@ -100,4 +101,4 @@ namespace mln
} // end of namespace mln
#endif // ! MLN_CORE_SAFE_IMAGE_HH
#endif // ! MLN_CORE_SAFE_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_LEVEL_ASSIGN_HH
# define MLN_LEVEL_ASSIGN_HH
/*! \file mln/level/assign.hh
*
* \brief Assignment between a couple of images.
*/
# include <mln/core/concept/image.hh>
namespace mln
{
namespace level
{
/*! Assignment of image \p target with image \p data.
*
* \param[out] output The image to be assigned.
* \param[in] data The auxiliary image.
*
* \pre target.domain = data.domain
*
* \todo Overload in impl:: for mixed (fast, non-fast).
*
* \todo Overload in impl:: for (fast, fast) if same value using memcpy.
*/
template <typename L, typename R>
void assign(Image<L>& target, const Image<R>& data);
# ifndef MLN_INCLUDE_ONLY
namespace impl