1154: Fixes and add impl::init_with_ for two image2d_b and sub_image.

https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Fixes and add impl::init_with_ for two image2d_b and sub_image. * tests/core_clone.cc: New. * mln/core/point.hh: Fix. * mln/core/internal/image_base.hh (hook_data_): New. * mln/core/internal/image_morpher.hh: Fix typo. * mln/core/image2d_b.hh (init_with): Rename as... (init_with_): ...this. (init_with_): Inactivate version with image. (init_with_): New in impl. * mln/core/sub_image.hh (init_with_): New in impl. Update ctors. * mln/border/get.hh: Fix. mln/border/get.hh | 2 - mln/core/image2d_b.hh | 51 +++++++++++++++++----------- mln/core/internal/image_base.hh | 3 + mln/core/internal/image_morpher.hh | 2 - mln/core/point.hh | 4 +- mln/core/sub_image.hh | 48 ++++++++++++++++++++++++-- tests/core_clone.cc | 67 +++++++++++++++++++++++++++++++++++++ 7 files changed, 149 insertions(+), 28 deletions(-) Index: tests/core_clone.cc --- tests/core_clone.cc (revision 0) +++ tests/core_clone.cc (revision 0) @@ -0,0 +1,67 @@ +// 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. + +/*! \file tests/core_clone.cc + * + * \brief Tests on mln::clone. + */ + +#include <mln/core/image2d_b.hh> +#include <mln/core/sub_image.hh> + +#include <mln/debug/iota.hh> +#include <mln/debug/println.hh> + +#include <mln/core/clone.hh> + + + +int main() +{ + using namespace mln; + image2d_b<int> ima(3, 3, 51); + debug::iota(ima); + + { + box2d b = make::box2d(2,2); + std::cout << border::get( clone(ima | b) ) << std::endl; + } + +// { +// image2d_b<int> ima_ = clone(ima); +// std::cout << ima_.border() << std::endl; +// ima_(make::point2d(1,1)) = 51; +// debug::println(ima); +// } + +// { +// image2d_b<int> ima_( ima ); +// ima_(make::point2d(1,1)) = 51; +// debug::println(ima); +// } + +} Index: mln/core/point.hh --- mln/core/point.hh (revision 1153) +++ mln/core/point.hh (working copy) @@ -102,7 +102,7 @@ typedef metal::vec<dim, C> vec_t; /// Hook to coordinates. - operator metal::vec<dim, C>() const; + operator metal::vec<M::dim, C>() const; protected: metal::vec<dim, C> coord_; @@ -159,7 +159,7 @@ } template <typename M, typename C> - point_<M,C>::operator metal::vec<dim, C>() const + point_<M,C>::operator metal::vec<M::dim, C>() const { return coord_; } Index: mln/core/internal/image_base.hh --- mln/core/internal/image_base.hh (revision 1153) +++ mln/core/internal/image_base.hh (working copy) @@ -171,6 +171,9 @@ /// Copy constructor. image_base_(const image_base_& rhs); + + const util::tracked_ptr< internal::data_<E> >& hook_data_() const { return data_; } + protected: image_base_(); Index: mln/core/internal/image_morpher.hh --- mln/core/internal/image_morpher.hh (revision 1153) +++ mln/core/internal/image_morpher.hh (working copy) @@ -110,7 +110,7 @@ image_morpher_<I,S,E>::has_data() const { return - this->data != 0 && + this->data_ != 0 && this->delegatee_() != 0 && this->delegatee_()->has_data(); } Index: mln/core/image2d_b.hh --- mln/core/image2d_b.hh (revision 1153) +++ mln/core/image2d_b.hh (working copy) @@ -150,18 +150,18 @@ /// Initialize an empty image. - void init_with(const box2d& b, unsigned bdr = border::thickness); + void init_with_(const box2d& b, unsigned bdr = border::thickness); - /// Initialize an empty image. - template <typename I> - void init_with(const Image<I>& other) // FIXME: Remove this soon obsolete code! - { - mln_precondition(this->data_ = 0); - mln_precondition(exact(other).has_data()); - this->data_ = new internal::data_< image2d_b<T> >(exact(other).bbox(), - exact(other).border()); - } +// /// Initialize an empty image. +// template <typename I> +// void init_with_(const Image<I>& other) // FIXME: Remove this soon obsolete code! +// { +// mln_precondition(this->data_ = 0); +// mln_precondition(exact(other).has_data()); +// this->data_ = new internal::data_< image2d_b<T> >(exact(other).bbox(), +// exact(other).border()); +// } /// Test if \p p is valid. @@ -217,13 +217,8 @@ namespace impl { - template <typename T, typename I> - void init_with_(image2d_b<T>& target, const I& model) - { - box2d b = model.domain(); - unsigned bdr = border::get(model); - target = image2d_b<T>(b, bdr); - } + template <typename T, typename J> + void init_with_(image2d_b<T>& target, const J& model); } // end of namespace mln::impl @@ -232,6 +227,22 @@ # ifndef MLN_INCLUDE_ONLY + // impl::init_with_ + + namespace impl + { + + template <typename T, typename J> + void init_with_(image2d_b<T>& target, const J& model) + { + box2d b = model.bbox(); + unsigned bdr = border::get(model); + target.init_with_(b, bdr); + } + + } // end of namespace mln::impl + + // internal::data_< image2d_b<T> > namespace internal @@ -312,18 +323,18 @@ template <typename T> image2d_b<T>::image2d_b(int nrows, int ncols, unsigned bdr) { - init_with(make::box2d(nrows, ncols), bdr); + init_with_(make::box2d(nrows, ncols), bdr); } template <typename T> image2d_b<T>::image2d_b(const box2d& b, unsigned bdr) { - init_with(b, bdr); + init_with_(b, bdr); } template <typename T> void - image2d_b<T>::init_with(const box2d& b, unsigned bdr) + image2d_b<T>::init_with_(const box2d& b, unsigned bdr) { mln_precondition(! this->has_data()); this->data_ = new internal::data_< image2d_b<T> >(b, bdr); Index: mln/core/sub_image.hh --- mln/core/sub_image.hh (revision 1153) +++ mln/core/sub_image.hh (working copy) @@ -47,14 +47,15 @@ { data_(I& ima, const S& pset); - I& ima_; - const S& pset_; + I ima_; + S pset_; }; } // end of namespace mln::internal + // FIXME: Doc! template <typename I, typename S> @@ -69,6 +70,9 @@ /// Constructor. sub_image(I& ima, const S& pset); + /// Initialization. + void init_with_(I& ima, const S& pset); + /// Give the definition domain. const S& domain() const; @@ -78,6 +82,7 @@ + template <typename I, typename S> sub_image<const I, S> operator|(const Image<I>& ima, const Point_Set<S>& pset); @@ -86,8 +91,35 @@ + namespace impl + { + + template <typename I, typename S, typename J> + void init_with_(sub_image<I,S>& target, const J& model); + + } // end of namespace mln::impl + + + # ifndef MLN_INCLUDE_ONLY + // impl::init_with_ + + namespace impl + { + + template <typename I, typename S, typename J> + void init_with_(sub_image<I,S>& target, const J& model) + { + I ima; + init_with_(ima, model); // rec + S pset = model.domain(); + target.init_with_(ima, pset); + } + + } // end of namespace mln::impl + + // internal::data_< sub_image<I,S> > namespace internal @@ -106,14 +138,22 @@ // sub_image<I,S> template <typename I, typename S> + sub_image<I,S>::sub_image() + { + } + + template <typename I, typename S> sub_image<I,S>::sub_image(I& ima, const S& pset) { - this->data_ = new internal::data_< sub_image<I,S> >(ima, pset); + init_with_(ima, pset); } template <typename I, typename S> - sub_image<I,S>::sub_image() + void + sub_image<I,S>::init_with_(I& ima, const S& pset) { + mln_precondition(! this->has_data()); + this->data_ = new internal::data_< sub_image<I,S> >(ima, pset); } template <typename I, typename S> Index: mln/border/get.hh --- mln/border/get.hh (revision 1153) +++ mln/border/get.hh (working copy) @@ -59,7 +59,7 @@ template <typename I, typename S, typename E> unsigned get__(const mln::internal::image_morpher_<I,S,E>& ima) { - return border::get(ima.delegatee_()); + return border::get(*ima.delegatee_()); } template <typename S, typename E>
participants (1)
-
Thierry Geraud