URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-21 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Remove image_adaptor inheritance
* mln/core/decorated_image.hh:
* mln/core/image_if.hh:
* mln/value/stack.hh: Change image_adpator inheritance to image_base.
* mln/core/image3d_b.hh: Add a using super_::data_
---
core/decorated_image.hh | 86 ++++++++++++++++++++++++++++------
core/image3d_b.hh | 6 ++
core/image_if.hh | 121 ++++++++++++++++++++++++++++++++++++++++--------
value/stack.hh | 66 +++++++++++++++-----------
4 files changed, 220 insertions(+), 59 deletions(-)
Index: trunk/milena/mln/core/decorated_image.hh
===================================================================
--- trunk/milena/mln/core/decorated_image.hh (revision 1154)
+++ trunk/milena/mln/core/decorated_image.hh (revision 1155)
@@ -28,7 +28,8 @@
#ifndef MLN_CORE_DECORATED_IMAGE_HH
# define MLN_CORE_DECORATED_IMAGE_HH
-# include <mln/core/internal/image_adaptor.hh>
+# include <mln/core/internal/image_base.hh>
+
# include <mln/value/proxy.hh>
@@ -55,28 +56,42 @@
typedef mln::value::proxy<const E> lvalue;
};
- } // end of namespace::internal
+ template <typename I, typename D>
+ struct data_< decorated_image<I,D> >
+ {
+ data_(I& ima, const D& deco);
+
+ I ima_;
+ D deco_;
+ };
+
+ } // end of namespace mln::internal
// FIXME: Doc!
template <typename I, typename D>
- class decorated_image : public internal::image_adaptor_< I,
decorated_image<I,D> >,
+ class decorated_image : public internal::image_base_< mln_pset(I),
decorated_image<I,D> >,
public internal::decorated_image_impl_< I, decorated_image<I,D> >
{
typedef decorated_image<I, D> self_;
- typedef internal::image_adaptor_< I, self_ > super_;
typedef internal::decorated_image_impl_< I, self_ > impl_;
+ typedef internal::image_base_< mln_pset(I), decorated_image<I,D> >
super_;
public:
+ /// Ctors
+ decorated_image();
decorated_image(I& ima, const D& deco);
+ /// Dtor
~decorated_image();
typedef mln_value(I) value;
typedef mln::value::proxy<const self_> rvalue;
typedef typename impl_::lvalue lvalue;
+ /// Value_Set associated type.
+ typedef mln_vset(I) vset;
/// Skeleton.
typedef decorated_image< tag::image<I>, tag::data<D> > skeleton;
@@ -96,8 +111,14 @@
/// Give the decoration.
D& decoration();
- protected:
- D deco_;
+ /// FIXME : to put into a identity morpher
+ /// Give the definition domain.
+ const mln_pset(I)& domain() const;
+
+ /// Give the set of values.
+ const mln_vset(I)& values() const;
+
+ using super_::data_;
};
@@ -114,13 +135,31 @@
# ifndef MLN_INCLUDE_ONLY
+ namespace internal
+ {
+
+ // internal::data_< decorated_image<I,S> >
+
+ template <typename I, typename D>
+ data_< decorated_image<I,D> >::data_(I& ima, const D& deco)
+ : ima_(ima),
+ deco_(deco)
+ {
+ }
+
+ } // end of namespace mln::internal
+
// decorated_image<I,D>
template <typename I, typename D>
+ decorated_image<I,D>::decorated_image()
+ {
+ }
+
+ template <typename I, typename D>
decorated_image<I,D>::decorated_image(I& ima, const D& deco)
- : super_(ima),
- deco_(deco)
{
+ this->data_ = new internal::data_< decorated_image<I,D> >(ima, deco);
}
template <typename I, typename D>
@@ -157,8 +196,8 @@
decorated_image_impl_<I,E>::write_(const mln_psite(I)& p, const
mln_value(I)& v)
{
E& ima = internal::force_exact<E>(*this);
- ima.decoration().writing(ima.adaptee(), p, v);
- ima.adaptee()(p) = v;
+ ima.decoration().writing(ima.data_->ima_, p, v);
+ ima.data_->ima_(p) = v;
}
} // end of namespace mln::internal
@@ -167,31 +206,48 @@
mln_value(I)
decorated_image<I,D>::read_(const mln_psite(I)& p) const
{
- deco_.reading(this->adaptee_, p);
- return this->adaptee_(p);
+ this->data_->deco_.reading(this->data_->ima_, p);
+ return this->data_->ima_(p);
}
template <typename I, typename D>
decorated_image<I,D>::operator decorated_image<const I, D>() const
{
- decorated_image<const I, D> tmp(this->adaptee_, deco_);
+ decorated_image<const I, D> tmp(this->data_->ima_,
this->data_->deco_);
return tmp;
}
+
template <typename I, typename D>
const D&
decorated_image<I,D>::decoration() const
{
- return deco_;
+ return this->data_->deco_;
}
template <typename I, typename D>
D&
decorated_image<I,D>::decoration()
{
- return deco_;
+ return this->data_->deco_;
}
+ template <typename I, typename D>
+ const mln_pset(I)&
+ decorated_image<I,D>::domain() const
+ {
+ mln_precondition(exact(this)->has_data());
+ return this->data_->ima_.domain();
+ }
+
+ template <typename I, typename D>
+ const mln_vset(I)&
+ decorated_image<I,D>::values() const
+ {
+ return this->data_->ima_.values();
+ }
+
+
// decorate
template <typename I, typename D>
Index: trunk/milena/mln/core/image_if.hh
===================================================================
--- trunk/milena/mln/core/image_if.hh (revision 1154)
+++ trunk/milena/mln/core/image_if.hh (revision 1155)
@@ -30,25 +30,45 @@
/*! \file mln/core/image_if.hh
*
- * \brief Definition of a base class for image adaptors.
+ * \brief Definition of a image_if image.
*/
-# include <mln/core/internal/image_adaptor.hh>
+# include <mln/core/internal/image_base.hh>
# include <mln/core/pset_if.hh>
namespace mln
{
+ // Fwd decl.
+ template <typename I, typename F> struct image_if;
+
+
+ namespace internal
+ {
+ template <typename I, typename F>
+ struct data_< image_if<I,F> >
+ {
+ data_(I& ima, const F& f);
+
+ pset_if<mln_pset(I), F> pset_;
+ F f_;
+ I ima_;
+ };
+
+ } // end of namespace mln::internal
+
+
/*! \brief A base class for image adaptors.
*
*/
template <typename I, typename F>
- struct image_if : public internal::image_adaptor_< I,
- image_if<I,F>,
- pset_if<mln_pset(I),F> >
+ struct image_if : public internal::image_base_< pset_if<mln_pset(I), F>,
image_if<I,F> >
{
+ // Parent
+ typedef internal::image_base_< pset_if<mln_pset(I), F>, image_if<I,F>
> super_;
+
/// Skeleton.
typedef image_if< tag::image<I>, tag::function<F> > skeleton;
@@ -56,8 +76,10 @@
/// Point_Set associated type.
typedef pset_if<mln_pset(I), F> pset;
- /// Constructor from an \p adaptee image.
- image_if(I& adaptee, const F& f);
+ /// Constructor from an \p image.
+ image_if(I& ima, const F& f);
+
+ image_if();
/// Test if a pixel value is accessible at \p p.
bool owns_(const mln_psite(I)& p) const;
@@ -68,13 +90,35 @@
/// Const promotion via convertion.
operator image_if<const I, F>() const;
- protected:
-
- pset pset_;
- F f_;
+ using super_::data_;
typedef image_if<I,F> self_;
- typedef internal::image_adaptor_< I, self_, pset > super_;
+
+ /// FIXME : to put into an identity morpher
+
+ /// Point_Site associated type.
+ typedef mln_point(I) point;
+ typedef mln_psite(pset) psite;
+
+ /// Value_Set associated type.
+ typedef mln_vset(I) vset;
+
+ /// Value associated type.
+ typedef mln_value(I) value;
+
+ /// Return type of read-only access.
+ typedef mln_rvalue(I) rvalue;
+
+ typedef typename internal::morpher_lvalue_<I>::ret lvalue;
+
+ /// 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);
+
+ /// Give the set of values.
+ const vset& values() const;
};
@@ -91,35 +135,76 @@
# ifndef MLN_INCLUDE_ONLY
+ namespace internal
+ {
+
+ // internal::data_< image_if<I,S> >
+
template <typename I, typename F>
- image_if<I,F>::image_if(I& adaptee, const F& f)
- : super_(adaptee),
- pset_(adaptee.domain() | f),
+ data_< image_if<I,F> >::data_(I& ima, const F& f)
+ : ima_(ima),
+ pset_(ima.domain() | f),
f_(f)
{
}
+ } // end of namespace mln::internal
+
+ template <typename I, typename F>
+ image_if<I,F>::image_if()
+ {
+ }
+
+ template <typename I, typename F>
+ image_if<I,F>::image_if(I& ima, const F& f)
+ {
+ this->data_ = new internal::data_< image_if<I,F> >(ima, f);
+ }
+
template <typename I, typename F>
bool
image_if<I,F>::owns_(const mln_psite(I)& p) const
{
- return pset_.has(p);
+ return data_->pset_.has(p);
}
template <typename I, typename F>
const pset_if<mln_pset(I), F>&
image_if<I,F>::domain() const
{
- return pset_;
+ return data_->pset_;
}
template <typename I, typename F>
image_if<I,F>::operator image_if<const I, F>() const
{
- image_if<const I, F> tmp(this->adaptee_, this->f_);
+ image_if<const I, F> tmp(this->data_->ima_, this->data_->f_);
return tmp;
}
+
+ template <typename I, typename F>
+ typename image_if<I,F>::rvalue
+ image_if<I,F>::operator()(const psite& p) const
+ {
+ mln_precondition(exact(this)->owns_(p));
+ return data_->ima_(p);
+ }
+
+ template <typename I, typename F>
+ typename image_if<I,F>::lvalue
+ image_if<I,F>::operator()(const psite& p)
+ {
+ mln_precondition(exact(this)->owns_(p));
+ return data_->ima_(p);
+ }
+
+ template <typename I, typename F>
+ const mln_vset(I)&
+ image_if<I,F>::values() const
+ {
+ return data_->ima_.values();
+ }
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: trunk/milena/mln/core/image3d_b.hh
===================================================================
--- trunk/milena/mln/core/image3d_b.hh (revision 1154)
+++ trunk/milena/mln/core/image3d_b.hh (revision 1155)
@@ -113,6 +113,9 @@
// End of warning.
+ /// Parent type
+ typedef internal::image_primary_< box3d, image3d_b<T> > parent;
+
/// Value associated type.
typedef T value;
@@ -194,6 +197,9 @@
/// Give a hook to the value buffer.
T* buffer();
+
+ /// To use the track pointer inherited.
+ using parent::data_;
};
Index: trunk/milena/mln/value/stack.hh
===================================================================
--- trunk/milena/mln/value/stack.hh (revision 1154)
+++ trunk/milena/mln/value/stack.hh (revision 1155)
@@ -34,7 +34,6 @@
*/
# include <mln/core/internal/image_base.hh>
-# include <mln/core/internal/tracked_ptr.hh>
# include <mln/metal/vec.hh>
# include <mln/value/set.hh>
@@ -44,16 +43,31 @@
namespace mln
{
- namespace value
+ // Fwd decl.
+ namespace value { template <unsigned n, typename I> struct stack_image; }
+
+ namespace internal
{
- // Fwd decl.
- template <unsigned n, typename I> struct stack_image;
+ /*! \brief data structure for stack_image
+ *
+ */
+ template <unsigned n, typename I>
+ struct data_< value::stack_image<n, I> >
+ {
+ public:
+ data_(const metal::vec<n,I>& imas);
+ metal::vec<n,I> imas_;
+ };
- namespace internal
+ }
+
+ namespace value
{
+ namespace internal
+ {
template <unsigned n, typename I>
struct helper_stack_image_lvalue_
{
@@ -75,25 +89,9 @@
}
};
- } // end of namespace mln::value::internal
-
- /*! \brief data structure for stack_image
- *
- */
- template <unsigned n, typename I>
- struct stack_image_data
- {
- public:
- stack_image_data(const metal::vec<n,I>& imas);
- metal::vec<n,I> imas_;
- };
+ } // end of namespace mln::value::internal
- template <unsigned n, typename I>
- stack_image_data<n,I>::stack_image_data(const metal::vec<n,I>& imas)
- : imas_(imas)
- {
- }
/*! \brief FIXME
*
@@ -101,6 +99,8 @@
template <unsigned n, typename I>
struct stack_image : public mln::internal::image_base_< mln_pset(I),
stack_image<n,I> >
{
+ typedef mln::internal::image_base_< mln_pset(I), stack_image<n,I> >
parent;
+
/// Point_Site associated type.
typedef mln_psite(I) psite;
@@ -149,8 +149,7 @@
/// Give the set of values of the image.
const vset& values() const;
- protected:
- tracked_ptr< stack_image_data<n, I> > data_;
+ using parent::data_;
};
@@ -164,10 +163,25 @@
stack_image<2, I>
stack(Image<I>& ima1, Image<I>& ima2);
-
+ } // end of namespace mln::value
# ifndef MLN_INCLUDE_ONLY
+ namespace internal
+ {
+ // internal::data_< cast_image_<T,I> >
+
+ template <unsigned n, typename I>
+ data_< value::stack_image<n,I> >::data_(const metal::vec<n,I>&
imas)
+ : imas_(imas)
+ {
+ }
+
+ } // end of namespace mln::internal
+
+
+ namespace value
+ {
// stack_image<n, I>
template <unsigned n, typename I>
@@ -178,7 +192,7 @@
template <unsigned n, typename I>
stack_image<n,I>::stack_image(const metal::vec<n,I>& imas)
{
- data_ = new stack_image_data<n,I>(imas);
+ data_ = new mln::internal::data_< stack_image<n, I> >(imas);
for (unsigned i = 0; i < n; ++i)
{
mln_precondition(imas[i].has_data());