
https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox Index: ChangeLog from Alexandre Abraham <abraham@lrde.epita.fr> Mixin working for op_less. * abraham/tests/morpho/test_watershed_topo.cc: . * abraham/tests/morpho/Makefile: . * abraham/tests/value/mixin.cc: New. * abraham/mln/core/image/thru.hh: . * abraham/mln/value/mixin.hh: New. * abraham/mln/value/op_less.hh: New. * abraham/mln/value/shell.hh: . mln/core/image/thru.hh | 4 - mln/value/mixin.hh | 117 ++++++++++++++++++++++++++++++++++++ mln/value/op_less.hh | 46 ++++++++++++++ mln/value/shell.hh | 3 tests/morpho/Makefile | 2 tests/morpho/test_watershed_topo.cc | 46 ++++---------- tests/value/mixin.cc | 64 +++++++++++++++++++ 7 files changed, 247 insertions(+), 35 deletions(-) Index: abraham/tests/morpho/test_watershed_topo.cc --- abraham/tests/morpho/test_watershed_topo.cc (revision 2926) +++ abraham/tests/morpho/test_watershed_topo.cc (working copy) @@ -13,49 +13,33 @@ #include <string> #include <iostream> -int print_and_exit (std::string s) -{ - std::cerr << s << std::endl; - return 1; -} - -int main () +int main (int argc, const char * argv[]) { using namespace mln; using value::int_u8; typedef image2d<int_u8> image2dint; - image2dint input, mverif, wverif; - - // #define TEST - - // io::pgm::load(input, "./images/test_watershed.pgm"); - // io::pgm::load(input, "./images/little_test.pgm"); - io::pgm::load(input, "./images/test.pgm"); - // io::pgm::load(input, "../../img/dots.pgm"); - //io::pgm::load(input, "./images/+irm6.pgm"); - - // io::pgm::load(input, "./images/lena_light.pgm"); - // io::pgm::load(mverif, "./images/result_m_watershed.pgm"); - // io::pgm::load(wverif, "./images/result_topo_watershed.pgm"); - - morpho::topo_wst< image2d<int_u8>, neighb2d> n(input, c4()); + if (argc < 2) { + std::cerr << "usage: " << argv[0] << " in.pgm [other_files.pgm]" << std::endl; + return 1; + } - /* - image2dint::fwd_piter it(input.domain()); - for_all(it) + for (int i = 1; i < argc; ++i) { - input(it) = input(it)/17; - mverif(it) = mverif(it)/17; - } - */ - // io::tikz::save(input, "start.tex"); + image2dint ima; + io::pgm::load(ima, argv[i]); + + morpho::topo_wst< image2d<int_u8>, neighb2d> n(ima, c4()); n.go(); - io::pgm::save(n.pima, "out.pgm"); + std::string name(argv[i]); + name.erase(name.length() - 4); + + io::pgm::save(n.pima, name.append("_wsd.pgm")); + } return 0; } Index: abraham/tests/morpho/Makefile --- abraham/tests/morpho/Makefile (revision 2926) +++ abraham/tests/morpho/Makefile (working copy) @@ -2,7 +2,7 @@ OBJ=$(SRC:.cc=.o) EXEC=$(SRC:.cc=) CC=g++ -CXXFLAGS=-Wall -W -I ../../ -I ../../../../ -g +CXXFLAGS=-Wall -W -I ../../ -I ../../../../ -O3 -DNDEBUG all: $(EXEC) Index: abraham/tests/value/mixin.cc --- abraham/tests/value/mixin.cc (revision 0) +++ abraham/tests/value/mixin.cc (revision 0) @@ -0,0 +1,64 @@ +// 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/value/mixin.hh + * + * \brief Mixin types. + */ + + +#include <mln/value/mixin.hh> +#include <mln/value/rgb.hh> +#include <mln/value/rgb8.hh> + + +namespace mln +{ + + namespace value + { + template <unsigned int n> + struct op_less< mln::value::rgb<n> > + { + bool operator()(const mln::value::rgb<n> &a, const mln::value::rgb<n> &b) + { + return a.red() < b.red(); + } + }; + } +} + +int main () +{ + mln::value::rgb8 r(12, 13, 14); + mln::value::rgb8 s(13, 14, 15); + + std::cout + << ( *(mln::value::mixin<mln::value::rgb8, mln::value::op_less>*)(void*) &r < + *(mln::value::mixin<mln::value::rgb8, mln::value::op_less>*)(void*) &s ) + << std::endl; +} Index: abraham/mln/core/image/thru.hh --- abraham/mln/core/image/thru.hh (revision 2926) +++ abraham/mln/core/image/thru.hh (working copy) @@ -118,6 +118,8 @@ /// Mutable access is for reading and writing. lvalue operator()(const mln_psite(I)& p); + + F f; }; # ifndef MLN_INCLUDE_ONLY @@ -164,7 +166,7 @@ thru<F,I>::operator()(const mln_psite(I)& p) const { mln_precondition(this->data_->ima_.has(p)); - return F()( this->data_->ima_(p) ); + return f( this->data_->ima_(p) ); } template <typename F, typename I> Index: abraham/mln/value/mixin.hh --- abraham/mln/value/mixin.hh (revision 0) +++ abraham/mln/value/mixin.hh (revision 0) @@ -0,0 +1,117 @@ +// 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. + +#ifndef MLN_CORE_VALUE_MIXIN_HH +# define MLN_CORE_VALUE_MIXIN_HH + +# include <mln/core/concept/function.hh> +# include <mln/core/concept/image.hh> +# include <mln/value/internal/value_like.hh> +# include <mln/value/op_less.hh> // FIXME : include all modificators + +namespace mln +{ + namespace value + { + template <typename T, template <typename> class F> + struct mixin; + } + + namespace trait + { + + template <typename T, template <typename> class F> + struct value_< mln::value::mixin<T, F> > + : value_< T > // FIXME + { + }; + + } // end of namespace trait + + namespace value + { + + template <typename T, template <typename> class F> + struct mixin : T, Value < mixin<T, F> >, internal::value_like_ <T, mln_enc(T), mixin<T, F>, mixin<T, F> > + { + typedef T value; + + // Ctor ? + + // operator (T) (); + + }; + } + +# ifndef MLN_INCLUDE_ONLY + + namespace value + { + + template <typename T> + struct mixin <T, op_less> : T, Value < mixin<T, op_less> >, internal::value_like_ <T, mln_enc(T), mixin<T, op_less>, mixin<T, op_less> > + { + typedef mixin<T, op_less> exact; + + bool operator< (const exact &rhs) + { + static op_less<T> l; + return l((T)*this, (T)rhs); + } + }; + + // Ctor + + // template <typename T, template <typename> class F> + // mixin<T, F>::operator(T)() + // { + // return (T)*this; + // } + + } + +/* + template <typename F, typename I> + std::ostream& operator<<(std::ostream& ostr, value::shell<F, I> &s) + { + ostr << (typename value::shell<F, I>::value) s; + return ostr; + } + + template <typename F, typename I> + std::istream& operator>>(std::istream& istr, value::shell<F, I> &s) + { + (typename value::shell<F, I>::value) s >> istr; + return istr; + } +*/ + +# endif // MLN_INCLUDE_ONLY + +}; // end of namespace mln + +#endif // MLN_CORE_VALUE_MIXIN_HH Index: abraham/mln/value/op_less.hh --- abraham/mln/value/op_less.hh (revision 0) +++ abraham/mln/value/op_less.hh (revision 0) @@ -0,0 +1,46 @@ +// 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. + +#ifndef MLN_CORE_VALUE_OP_LESS_HH +# define MLN_CORE_VALUE_OP_LESS_HH + +namespace mln +{ + + namespace value + { + + template <typename T> + struct op_less + { + // Should have an operator() (T& lhs, T& rhs) + }; + + } // end of namespace value +} // end of namespace mln + +#endif // ! MLN_CORE_VALUE_OP_LESS_HH Index: abraham/mln/value/shell.hh --- abraham/mln/value/shell.hh (revision 2926) +++ abraham/mln/value/shell.hh (working copy) @@ -48,8 +48,7 @@ template <typename F, typename I> struct value_< mln::value::shell<F, I> > - : - value_< mln_result(F) > + : value_< mln_result(F) > { };