URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-24 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Change images inheritance, and memory managment.
* mln/core/decorated_image.hh: Remove super_ typedef.
* mln/core/interpolated.hh: Inherit from identity morpher. Add memory
managment.
* mln/core/rle_image.hh,
* mln/core/sparse_image.hh,
* mln/core/internal/run_image.hh: Inherit from image_primary, move
domain_ attribute to the descendants classes rle_images and
sparse_image. Add memory managment to rle and sparse images.
* mln/core/safe.hh: Inherit from identity morpher. Add memory
managment.
* mln/value/stack.hh: Inherit from value morpher.
---
core/decorated_image.hh | 7 ----
core/internal/run_image.hh | 26 ----------------
core/interpolated.hh | 72 +++++++++++++++++++++++++++++----------------
core/rle_image.hh | 66 +++++++++++++++++++++++++++++++++++------
core/safe.hh | 62 ++++++++++++++++++++++++++++++--------
core/sparse_image.hh | 68 ++++++++++++++++++++++++++++++++++--------
value/stack.hh | 42 +++++---------------------
7 files changed, 217 insertions(+), 126 deletions(-)
Index: trunk/milena/mln/core/decorated_image.hh
===================================================================
--- trunk/milena/mln/core/decorated_image.hh (revision 1163)
+++ trunk/milena/mln/core/decorated_image.hh (revision 1164)
@@ -76,16 +76,13 @@
public internal::decorated_image_impl_< I, decorated_image<I,D> >,
public internal::image_identity_morpher_< I, mln_pset(I),
decorated_image<I,D> >
{
+ public:
typedef decorated_image<I, D> self_;
typedef internal::decorated_image_impl_< I, self_ > impl_;
- typedef internal::image_identity_morpher_< I, mln_pset(I), self_ > super_;
/// Return type of read-write access.
typedef typename internal::morpher_lvalue_<I>::ret lvalue;
- public:
-
-
/// Ctors
decorated_image();
decorated_image(I& ima, const D& deco);
@@ -110,8 +107,6 @@
/// Give the decoration.
D& decoration();
- protected:
- using super_::data_;
};
Index: trunk/milena/mln/core/internal/run_image.hh
===================================================================
--- trunk/milena/mln/core/internal/run_image.hh (revision 1163)
+++ trunk/milena/mln/core/internal/run_image.hh (revision 1164)
@@ -50,20 +50,9 @@
* Parameter \c E is the Exact type of the image.
*/
template <typename P, typename E>
- class run_image_ : public image_base_<run_pset_<P>, E>
+ class run_image_ : public internal::image_primary_< internal::run_pset_<P>,
E >
{
- public:
- typedef run_pset_<P> pset;
- typedef mln_psite(pset) psite;
-
- /// Give the definition domain.
- const pset& domain() const;
- /// Test if \p p is valid.
- bool owns_(const psite& site) const;
protected:
- /// domain of the image
- pset domain_;
-
run_image_();
};
@@ -74,19 +63,6 @@
{
}
- template <typename P, typename E>
- const typename run_image_<P, E>::pset&
- run_image_<P, E>::domain() const
- {
- return domain_;
- }
-
- template <typename P, typename E>
- bool
- run_image_<P, E>::owns_(const typename run_image_<P, E>::psite& site)
const
- {
- return domain_.has(site);
- }
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace internal
Index: trunk/milena/mln/core/rle_image.hh
===================================================================
--- trunk/milena/mln/core/rle_image.hh (revision 1163)
+++ trunk/milena/mln/core/rle_image.hh (revision 1164)
@@ -34,6 +34,7 @@
*/
# include <mln/core/internal/run_image.hh>
+# include <mln/core/internal/run_pset.hh>
# include <mln/core/internal/run_psite.hh>
# include <mln/value/set.hh>
# include <vector>
@@ -41,6 +42,26 @@
namespace mln
{
+ // Fwd decl.
+ template <typename P, typename T> struct rle_image;
+
+ namespace internal
+ {
+
+ template <typename P, typename T>
+ struct data_< rle_image<P,T> >
+ {
+ data_();
+
+ /// Image values.
+ std::vector<T> values_;
+
+ /// domain of the image
+ run_pset_<P> domain_;
+ };
+
+ } // end of namespace mln::internal
+
/*! \brief RLE image.
*
*
@@ -57,6 +78,7 @@
typedef const T rvalue;
typedef internal::run_psite<P> psite;
typedef mln::value::set<T> vset;
+ typedef internal::run_pset_<P> pset;
/// Skeleton.
@@ -80,24 +102,40 @@
/// Give the set of values of the image.
const vset& values() const;
- protected:
- /// Image values.
- std::vector<T> values_;
+ /// Give the definition domain.
+ const pset& domain() const;
+
};
# ifndef MLN_INCLUDE_ONLY
+ namespace internal
+ {
+
+ // internal::data_< rle_image<I,S> >
+
+ template <typename P, typename T>
+ data_< rle_image<P,T> >::data_()
+ {
+ }
+
+ } // end of namespace mln::internal
+
template <typename P, typename T>
rle_image<P, T>::rle_image()
{
+ // FIXME : ambiguity between empty constructor and constructor
+ // which allocate data_
+
+ // this->data_ = new internal::data_< rle_image<I,T> >();
}
template <typename P, typename T>
bool
rle_image<P, T>::has_data() const
{
- return values_.size() != 0;
+ return this->data_->values_.size() != 0;
}
template <typename P, typename T>
@@ -111,8 +149,8 @@
void
rle_image<P, T>::insert(const P& p, unsigned len, T value)
{
- this->domain_.insert(p, len);
- values_.push_back(value);
+ this->data_->domain_.insert(p, len);
+ this->data_->values_.push_back(value);
}
template <typename P, typename T>
@@ -121,8 +159,8 @@
const
{
mln_precondition(this->has_data() &&
- site.pset_pos_() < values_.size());
- return values_[site.pset_pos_()];
+ site.pset_pos_() < this->data_->values_.size());
+ return this->data_->values_[site.pset_pos_()];
}
template <typename P, typename T>
@@ -130,9 +168,17 @@
rle_image<P, T>::operator() (const typename rle_image<P, T>::psite&
site)
{
mln_precondition(this->has_data() &&
- site.pset_pos_() < values_.size());
- return values_[site.pset_pos_()];
+ site.pset_pos_() < this->data_->values_.size());
+ return this->data_->values_[site.pset_pos_()];
}
+
+ template <typename P, typename T>
+ const typename rle_image<P, T>::pset&
+ rle_image<P, T>::domain() const
+ {
+ return this->data_->domain_;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
Index: trunk/milena/mln/core/interpolated.hh
===================================================================
--- trunk/milena/mln/core/interpolated.hh (revision 1163)
+++ trunk/milena/mln/core/interpolated.hh (revision 1164)
@@ -35,18 +35,34 @@
# include <cmath>
-# include <mln/core/concept/image.hh>
+# include <mln/core/internal/image_identity_morpher.hh>
# include <mln/metal/vec.hh>
namespace mln
{
+ // Fwd decl.
+ template <typename I> struct interpolated;
+
+ namespace internal
+ {
+
+ template <typename I>
+ struct data_< interpolated<I> >
+ {
+ data_(I& ima);
+
+ I ima_;
+ };
+
+ } // end of namespace mln::internal
+
/*! \brief FIXME
*
*/
template <typename I>
- struct interpolated : public mln::internal::image_base_< mln_pset(I),
interpolated<I> >
+ struct interpolated : public mln::internal::image_identity_morpher_< I, mln_pset(I),
interpolated<I> >
{
/// Point_Site associated type.
typedef mln_psite(I) psite;
@@ -68,8 +84,9 @@
typedef interpolated< tag::image_<I> > skeleton;
- /// Constructor.
+ /// Constructors.
interpolated(I& ima);
+ interpolated();
/// Test if this image has been initialized.
@@ -81,9 +98,6 @@
/// Test if a pixel value is accessible at \p v.
bool owns_(const mln::metal::vec<I::point::dim, float>& v) const;
- /// Give the definition domain.
- const mln_pset(I)& domain() const;
-
/// Read-only access of pixel value at point site \p p.
mln_rvalue(I) operator()(const psite& p) const;
@@ -96,33 +110,48 @@
/// Give the set of values of the image.
const vset& values() const;
-
- protected:
- I& ima_;
};
# ifndef MLN_INCLUDE_ONLY
+ namespace internal
+ {
+
+ // internal::data_< interpolated<I,S> >
+
template <typename I>
- interpolated<I>::interpolated(I& ima)
+ data_< interpolated<I> >::data_(I& ima)
: ima_(ima)
{
+ }
+
+ } // end of namespace mln::internal
+
+ template <typename I>
+ interpolated<I>::interpolated(I& ima)
+ {
mln_precondition(ima.has_data());
+ this->data_ = new internal::data_< interpolated<I> >(ima);
+ }
+
+ template <typename I>
+ interpolated<I>::interpolated()
+ {
}
template <typename I>
bool interpolated<I>::has_data() const
{
- mln_invariant(ima_.has_data());
+ mln_invariant(this->data_->ima_.has_data());
return true;
}
template <typename I>
bool interpolated<I>::owns_(const psite& p) const
{
- return ima_.owns_(p);
+ return this->data_->ima_.owns_(p);
}
template <typename I>
@@ -131,29 +160,22 @@
mln_point(I) p;
for (unsigned i = 0; i < I::point::dim; ++i)
p[i] = static_cast<int>(round(v[i]));
- return ima_.owns_(p);
- }
-
- template <typename I>
- const mln_pset(I)&
- interpolated<I>::domain() const
- {
- return ima_.domain();
+ return this->data_->ima_.owns_(p);
}
template <typename I>
mln_rvalue(I)
interpolated<I>::operator()(const psite& p) const
{
- mln_precondition(ima_.owns_(p));
- return ima_(p);
+ mln_precondition(this->data_->ima_.owns_(p));
+ return this->data_->ima_(p);
}
template <typename I>
mln_lvalue(I)
interpolated<I>::operator()(const psite& p)
{
- return ima_(p);
+ return this->data_->ima_(p);
}
template <typename I>
@@ -163,8 +185,8 @@
mln_point(I) p;
for (unsigned i = 0; i < I::point::dim; ++i)
p[i] = static_cast<int>(round(v[i]));
- mln_assertion(ima_.owns_(p));
- return ima_(p);
+ mln_assertion(this->data_->ima_.owns_(p));
+ return this->data_->ima_(p);
}
template <typename I>
Index: trunk/milena/mln/core/safe.hh
===================================================================
--- trunk/milena/mln/core/safe.hh (revision 1163)
+++ trunk/milena/mln/core/safe.hh (revision 1164)
@@ -28,24 +28,43 @@
#ifndef MLN_CORE_SAFE_HH
# define MLN_CORE_SAFE_HH
-# include <mln/core/internal/image_adaptor.hh>
+# include <mln/core/internal/image_identity_morpher.hh>
namespace mln
{
+ // Fwd decl.
+ template <typename I> struct safe_image;
+
+ namespace internal
+ {
+
+ template <typename I>
+ struct data_< safe_image<I> >
+ {
+ data_(I& ima, const mln_value(I)& default_value);
+
+ I ima_;
+ mln_value(I) default_value_;
+ };
+
+ } // end of namespace mln::internal
+
+
// FIXME: Doc!
template <typename I>
- class safe_image : public internal::image_adaptor_< I, safe_image<I> >
+ class safe_image : public internal::image_identity_morpher_< I, mln_pset(I),
safe_image<I> >
{
- typedef internal::image_adaptor_< I, safe_image<I> > super_;
+ typedef internal::image_identity_morpher_< I, mln_pset(I), safe_image<I>
> super_;
public:
/// Skeleton.
typedef safe_image< tag::image_<I> > skeleton;
safe_image(I& ima, const mln_value(I)& default_value);
+ safe_image();
mln_rvalue(I) operator()(const mln_psite(I)& p) const;
@@ -54,9 +73,6 @@
/// Const promotion via convertion.
operator safe_image<const I>() const;
-
- protected:
- mln_value(I) default_value_;
};
@@ -73,12 +89,30 @@
# ifndef MLN_INCLUDE_ONLY
+ namespace internal
+ {
+
+ // internal::data_< safe_image<I,S> >
+
+ template <typename I>
+ data_< safe_image<I> >::data_(I& ima, const mln_value(I)&
default_value)
+ : ima_(ima),
+ default_value_(default_value)
+ {
+ }
+
+ } // end of namespace mln::internal
+
// safe_image<I>
template <typename I>
safe_image<I>::safe_image(I& ima, const mln_value(I)& default_value)
- : super_(ima),
- default_value_(default_value)
+ {
+ this->data_ = new internal::data_< safe_image<I> >(ima,
default_value);
+ }
+
+ template <typename I>
+ safe_image<I>::safe_image()
{
}
@@ -87,8 +121,8 @@
safe_image<I>::operator()(const mln_psite(I)& p) const
{
if (! this->owns_(p))
- return default_value_;
- return this->adaptee_(p);
+ return this->data_->default_value_;
+ return this->data_->ima_(p);
}
template <typename I>
@@ -97,15 +131,15 @@
{
static mln_value(I) forget_it_;
if (! this->owns_(p))
- // so default_value_ is returned but cannot be modified
- return forget_it_ = default_value_;
- return this->adaptee_(p);
+ // so data_->default_value_ is returned but cannot be modified
+ return forget_it_ = this->data_->default_value_;
+ return this->data_->ima_(p);
}
template <typename I>
safe_image<I>::operator safe_image<const I>() const
{
- safe_image<const I> tmp(this->adaptee_, default_value_);
+ safe_image<const I> tmp(this->data_->ima_,
this->data_->default_value_);
return tmp;
}
Index: trunk/milena/mln/core/sparse_image.hh
===================================================================
--- trunk/milena/mln/core/sparse_image.hh (revision 1163)
+++ trunk/milena/mln/core/sparse_image.hh (revision 1164)
@@ -34,6 +34,7 @@
*/
# include <mln/core/internal/run_image.hh>
+# include <mln/core/internal/run_pset.hh>
# include <mln/core/internal/run_psite.hh>
# include <mln/value/set.hh>
# include <vector>
@@ -41,6 +42,25 @@
namespace mln
{
+ // Fwd decl.
+ template <typename P, typename T> struct sparse_image;
+
+ namespace internal
+ {
+
+ template <typename P, typename T>
+ struct data_< sparse_image<P,T> >
+ {
+ data_();
+
+ /// Image values.
+ std::vector< std::vector<T> > values_;
+ /// domain of the image
+ run_pset_<P> domain_;
+ };
+
+ } // end of namespace mln::internal
+
/*! \brief Sparse image.
*
*
@@ -57,7 +77,7 @@
typedef const T rvalue;
typedef internal::run_psite<P> psite;
typedef mln::value::set<T> vset;
-
+ typedef internal::run_pset_<P> pset;
/// Skeleton.
typedef sparse_image< tag::psite_<P>, tag::value_<T> > skeleton;
@@ -80,23 +100,38 @@
/// Give the set of values of the image.
const vset& values() const;
- protected:
- /// Image values.
- std::vector< std::vector<value> > values_;
+ /// Give the definition domain.
+ const pset& domain() const;
};
# ifndef MLN_INCLUDE_ONLY
+ namespace internal
+ {
+
+ // internal::data_< sparse_image<I,S> >
+
+ template <typename P, typename T>
+ data_< sparse_image<P,T> >::data_()
+ {
+ }
+
+ } // end of namespace mln::internal
+
template <typename P, typename T>
sparse_image<P, T>::sparse_image()
{
+ // FIXME : ambiguity between empty constructor and constructor
+ // which allocate data_
+
+ // this->data_ = new internal::data_< rle_image<I,T> >();
}
template <typename P, typename T>
bool
sparse_image<P, T>::has_data() const
{
- return values_.size() != 0;
+ return this->data_->values_.size() != 0;
}
template <typename P, typename T>
@@ -111,8 +146,8 @@
sparse_image<P, T>::insert(const P& p, unsigned len,
const std::vector<T>& value)
{
- this->domain_.insert(p, len);
- values_.push_back(value);
+ this->data_->domain_.insert(p, len);
+ this->data_->values_.push_back(value);
}
template <typename P, typename T>
@@ -121,9 +156,9 @@
(const typename sparse_image<P, T>::psite& site) const
{
mln_precondition(this->has_data() &&
- site.pset_pos_() < values_.size() &&
- site.index_() < values_[site.pset_pos_()].size());
- return values_[site.pset_pos_()][site.index_()];
+ site.pset_pos_() < this->data_->values_.size() &&
+ site.index_() < this->data_->values_[site.pset_pos_()].size());
+ return this->data_->values_[site.pset_pos_()][site.index_()];
}
template <typename P, typename T>
@@ -132,9 +167,16 @@
(const typename sparse_image<P,T>::psite& site)
{
mln_precondition(this->has_data() &&
- site.pset_pos_() < values_.size() &&
- site.index_() < values_[site.pset_pos_()].size());
- return values_[site.pset_pos_()][site.index_()];
+ site.pset_pos_() < this->data_->values_.size() &&
+ site.index_() < this->data_->values_[site.pset_pos_()].size());
+ return this->data_->values_[site.pset_pos_()][site.index_()];
+ }
+
+ template <typename P, typename T>
+ const typename sparse_image<P, T>::pset&
+ sparse_image<P, T>::domain() const
+ {
+ return this->data_->domain_;
}
# endif // ! MLN_INCLUDE_ONLY
Index: trunk/milena/mln/value/stack.hh
===================================================================
--- trunk/milena/mln/value/stack.hh (revision 1163)
+++ trunk/milena/mln/value/stack.hh (revision 1164)
@@ -33,7 +33,7 @@
* \brief Definition of an image class FIXME
*/
-# include <mln/core/internal/image_base.hh>
+# include <mln/core/internal/image_value_morpher.hh>
# include <mln/metal/vec.hh>
# include <mln/value/set.hh>
@@ -59,6 +59,7 @@
public:
data_(const metal::vec<n,I>& imas);
metal::vec<n,I> imas_;
+ I& ima_;
};
}
@@ -97,10 +98,8 @@
*
*/
template <unsigned n, typename I>
- struct stack_image : public mln::internal::image_base_< mln_pset(I),
stack_image<n,I> >
+ struct stack_image : public mln::internal::image_value_morpher_< 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;
@@ -132,12 +131,6 @@
/// 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 mln_pset(I)& domain() const;
-
/// Read-only access of pixel value at point site \p p.
rvalue operator()(const psite& p) const;
value read_(const psite& p) const;
@@ -148,8 +141,6 @@
/// Give the set of values of the image.
const vset& values() const;
-
- using parent::data_;
};
@@ -173,7 +164,8 @@
template <unsigned n, typename I>
data_< value::stack_image<n,I> >::data_(const metal::vec<n,I>&
imas)
- : imas_(imas)
+ : imas_(imas),
+ ima_(imas_[0])
{
}
@@ -192,7 +184,7 @@
template <unsigned n, typename I>
stack_image<n,I>::stack_image(const metal::vec<n,I>& imas)
{
- data_ = new mln::internal::data_< stack_image<n, I> >(imas);
+ this->data_ = new mln::internal::data_< stack_image<n, I> >(imas);
for (unsigned i = 0; i < n; ++i)
{
mln_precondition(imas[i].has_data());
@@ -203,34 +195,18 @@
bool stack_image<n,I>::has_data() const
{
for (unsigned i = 0; i < n; ++i)
- mln_invariant(data_->imas_[i].has_data());
- return true;
- }
-
- template <unsigned n, typename I>
- bool stack_image<n,I>::owns_(const psite& p) const
- {
- for (unsigned i = 0; i < n; ++i)
- if (! data_->imas_[i].owns_(p))
- return false;
+ mln_invariant(this->data_->imas_[i].has_data());
return true;
}
template <unsigned n, typename I>
- const mln_pset(I)&
- stack_image<n,I>::domain() const
- {
- return data_->imas_[0].domain();
- }
-
- template <unsigned n, typename I>
metal::vec<n, mln_value(I)>
stack_image<n,I>::read_(const psite& p) const
{
mln_precondition(this->owns_(p));
metal::vec<n, mln_value(I)> tmp;
for (unsigned i = 0; i < n; ++i)
- tmp[i] = data_->imas_[i].operator()(p);
+ tmp[i] = this->data_->imas_[i].operator()(p);
return tmp;
}
@@ -248,7 +224,7 @@
mln_precondition(this->owns_(p));
// FIXME!!!
for (unsigned i = 0; i < n; ++i)
- data_->imas_[i].operator()(p) = v[i];
+ this->data_->imas_[i].operator()(p) = v[i];
}
template <unsigned n, typename I>