
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2007-09-27 Matthieu Garrigues <garrigues@lrde.epita.fr> Fix in plain image. * mln/core/plain.hh, * tests/plain.cc: Fix. --- mln/core/plain.hh | 25 +++++++++++++++++-------- tests/plain.cc | 22 ++++++++++++++++++++++ 2 files changed, 39 insertions(+), 8 deletions(-) Index: trunk/milena/tests/plain.cc =================================================================== --- trunk/milena/tests/plain.cc (revision 1185) +++ trunk/milena/tests/plain.cc (revision 1186) @@ -34,6 +34,7 @@ #include <mln/core/plain.hh> #include <mln/value/int_u8.hh> +#include <mln/level/compare.hh> #include <mln/io/pgm/load.hh> #include <mln/io/pgm/save.hh> @@ -47,6 +48,27 @@ plain< image2d_b<int_u8> > lena = io::pgm::load<int_u8>("../img/lena.pgm"); + image2d_b<int_u8> ima; + image2d_b<int_u8> ima2; + + ima = lena; + + ima(make::point2d(0,0)) = 124; + + mln_assertion(ima != lena); + + ima2 = lena; + ima = lena; + + mln_assertion(ima == ima2); + + ima(make::point2d(0,0)) = 124; + mln_assertion(ima != ima2); + + ima = ima2; + + ima(make::point2d(0,0)) = 124; + mln_assertion(ima == ima2); } } Index: trunk/milena/mln/core/plain.hh =================================================================== --- trunk/milena/mln/core/plain.hh (revision 1185) +++ trunk/milena/mln/core/plain.hh (revision 1186) @@ -53,7 +53,7 @@ template <typename I> struct data_< plain<I> > { - data_(I& ima); + data_(const I& ima); I ima_; }; @@ -95,6 +95,9 @@ /// Assignment operator. plain& operator=(const I& rhs); + + /// Convertion into an I image + operator I () const; }; @@ -104,21 +107,20 @@ namespace internal { - // internal::data_< plain<I,S> > + // internal::data_< plain<I> > template <typename I> - data_< plain<I> >::data_(I& ima) - : ima_(ima) + data_< plain<I> >::data_(const I& ima) + : ima_(clone(ima)) { } } // end of namespace mln::internal template <typename I> - plain<I>::plain(const I& ima_) + plain<I>::plain(const I& ima) { - mln_precondition(ima_.has_data()); - I ima = clone(ima_); + mln_precondition(ima.has_data()); this->data_ = new internal::data_< plain<I> >(ima); } @@ -126,11 +128,18 @@ plain<I>& plain<I>::operator=(const I& rhs) { + mln_precondition(rhs.has_data()); this->destroy(); - this->data_ = new internal::data_< plain<I> >(clone(rhs)); + this->data_ = new internal::data_< plain<I> >(rhs); return *this; } + template <typename I> + plain<I>::operator I () const + { + return clone(this->data_->ima_); + } + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln