
Index: ChangeLog from Damien Thivolle <damien@lrde.epita.fr> * tests/utils: New. * tests/utils/tests: New. * tests/utils/tests/clone: New. * tests/utils/Makefile.am: New. * oln/utils: New. * oln/utils/clone.hh: New. Clone images. * oln/makefile.src: Add new file. * oln/core/value_box.hh: Add operators for value_box<I> because it does not match template <typename II> value_box<II>. * oln/core/abstract/op.hh: Add missing initialization. * oln/core/1d/image1d.hh: Add constructor for size1d. * oln/core/2d/image2d.hh: Add constructor for size2d. * oln/core/3d/image3d.hh: Add constructor for size3d. oln/core/1d/image1d.hh | 9 +++- oln/core/2d/image2d.hh | 5 ++ oln/core/3d/image3d.hh | 9 +++- oln/core/abstract/op.hh | 8 +++- oln/core/value_box.hh | 28 +++++++++++++- oln/makefile.src | 3 + oln/utils/clone.hh | 95 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/utils/Makefile.am | 5 ++ tests/utils/tests/clone | 35 +++++++++++++++++ 9 files changed, 189 insertions(+), 8 deletions(-) Index: tests/utils/tests/clone --- tests/utils/tests/clone (revision 0) +++ tests/utils/tests/clone (revision 0) @@ -0,0 +1,35 @@ +#include "data.hh" + +#include <ntg/all.hh> + +#include <oln/basics2d.hh> +#include <oln/utils/clone.hh> +#include <oln/io/read_image.hh> +#include <oln/level/compare.hh> +#include <oln/level/fill.hh> + + +bool check() +{ + oln::image2d<ntg::int_u8> ima1; + oln::image2d<ntg::int_u8> ima2; + oln::image2d<ntg::int_u8> ima_copy; + + ima1 = oln::io::read(rdata("lena.pgm")); + ima2 = oln::io::read(rdata("lena.pgm")); + ima_copy = oln::utils::clone(ima1); + + oln::level::fill(ima1, 0); + if (oln::level::is_equal(ima2, ima_copy)) + { + std::cout << "OK" << std::endl; + return false; + } + else + { + std::cout << "FAIL" << std::endl; + return true; + } +} + + Index: tests/utils/Makefile.am --- tests/utils/Makefile.am (revision 0) +++ tests/utils/Makefile.am (revision 0) @@ -0,0 +1,5 @@ +include ../check/Makefile.runtests +include ../check/Makefile.check + + +check-local: check-runtests Index: oln/utils/clone.hh --- oln/utils/clone.hh (revision 0) +++ oln/utils/clone.hh (revision 0) @@ -0,0 +1,95 @@ +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLN_UTILS_CLONE_HH +# define OLN_UTILS_CLONE_HH + +# include <oln/core/abstract/op.hh> +# include <oln/core/abstract/piter.hh> + +namespace oln { + + // fwd decl + namespace utils { + template <typename I> struct clone_type; + } + + // category + template <typename I> + struct set_category < utils::clone_type<I> > + { + typedef category::image ret; + }; + + // super_type + template <typename I> + struct set_super_type < utils::clone_type<I> > + { + typedef abstract::op<I, utils::clone_type<I> > ret; + }; + + + + namespace utils { + + template <typename I> + struct clone_type : abstract::op<I, clone_type<I> > + { + typedef abstract::op<I, clone_type<I> > super_type; + + mlc::box<I> input_; + + clone_type(I& input) : input_(input) + {} + + void impl_run() + { + I ima(input_->size()); + oln_type_of(I, fwd_piter) it(input_->size()); + + for_all(it) + { + ima[it] = (*input_)[it]; + } + + *this->image_ = ima; + } + }; + + + template <typename I> + clone_type<I> clone(abstract::image<I>& ima) + { + clone_type<I> tmp(ima.exact()); + tmp.run(); + return tmp; + } + } +} + + +#endif // ! OLN_UTILS_CLONE_HH Index: oln/makefile.src --- oln/makefile.src (revision 80) +++ oln/makefile.src (working copy) @@ -61,4 +61,5 @@ io/write_image.hh \ io/write_image_2d_pnm.hh \ level/compare.hh \ - level/fill.hh + level/fill.hh \ + utils/clone.hh Index: oln/core/value_box.hh --- oln/core/value_box.hh (revision 80) +++ oln/core/value_box.hh (working copy) @@ -98,6 +98,12 @@ return ! this->operator==(rhs); } + /*! \brief operator < + ** + ** Define the main comparison operator for value_box. <= >= and > + ** are computed using integre operators \see ntg/core/global_ops.hh:138. + */ + template <typename V> bool operator<(const V& rhs) const { @@ -110,6 +116,15 @@ return this->value() < value.value(); } + /*! \brief specialized version for value_box<I> + ** + ** FIXME: why do we need this class ??? + */ + bool operator<(const value_box<I>& rhs) const + { + return this->value() < value.value(); + } + /*! \brief op= ** FIXME:... ** \return (*this) @@ -138,7 +153,13 @@ return *this; } + value_box& operator=(const value_box<I>& rhs) + { + ima_->set(p_, rhs.value()); // automatic conversion from rhs to value_type + return *this; + } + /*! \brief Set ** ** NEW code @@ -275,11 +296,16 @@ } template <typename II> - bool operator<(const value_box<II>& rhs) const + bool operator<(const value_box<const II>& rhs) const { return this->value() < rhs.value(); } + bool operator<(const value_box<const I>& rhs) const + { + return this->value() < rhs.value(); + } + /*! \brief Assignment (op=) is declared but undefined. */ Index: oln/core/abstract/op.hh --- oln/core/abstract/op.hh (revision 80) +++ oln/core/abstract/op.hh (working copy) @@ -58,7 +58,10 @@ this->exact_ptr = (E*)(void*)(this); } - op() {} + op() + { + this->exact_ptr = (E*)(void*)(this); + } void run() { @@ -74,7 +77,8 @@ template <typename E> struct void_op : public mlc::any<E> { - void_op() {} + void_op() + {} void run() { Index: oln/core/1d/image1d.hh --- oln/core/1d/image1d.hh (revision 80) +++ oln/core/1d/image1d.hh (working copy) @@ -120,12 +120,17 @@ this->exact_ptr = this; } - image1d(coord_t nindices) : - super_type(size1d(nindices)) + image1d(const size1d& size) : super_type(size) { this->exact_ptr = this; } + image1d(coord_t nindices, size_t border = 2) : + super_type(size1d(nindices, border)) + { + this->exact_ptr = this; + } + image1d(image1d& rhs) : super_type(rhs) { Index: oln/core/2d/image2d.hh --- oln/core/2d/image2d.hh (revision 80) +++ oln/core/2d/image2d.hh (working copy) @@ -129,6 +129,11 @@ this->exact_ptr = this; } + image2d(const size2d& size) : super_type(size) + { + this->exact_ptr = this; + } + image2d(coord_t nrows, coord_t ncols, size_t border = 2) : super_type(size2d(nrows, ncols, border)) { Index: oln/core/3d/image3d.hh --- oln/core/3d/image3d.hh (revision 80) +++ oln/core/3d/image3d.hh (working copy) @@ -115,12 +115,17 @@ this->exact_ptr = this; } - image3d(coord_t nslices, coord_t nrows, coord_t ncols) : - super_type(size3d(nslices, nrows, ncols)) + image3d(const size3d& size) : super_type(size) { this->exact_ptr = this; } + image3d(coord_t nslices, coord_t nrows, coord_t ncols, size_t border = 2) : + super_type(size3d(nslices, nrows, ncols, border)) + { + this->exact_ptr = this; + } + image3d(image3d& rhs) : super_type(rhs) {