proto-1.0 146: Update wins, nbhs and iters.

2005-04-14 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr> * oln/core/2d/fwd_niter2d.hh: Remove (obsolete; replaced by niter2d.hh). * oln/core/1d/niter1d.hh: New file. * oln/core/1d/bkd_piter1d.hh: New file. * oln/core/1d/qiter1d.hh: New file. * oln/core/1d/neighborhood1d.hh: New file. * oln/core/2d/niter2d.hh: New file. * oln/core/2d/qiter2d.hh: New file. * oln/core/3d/niter3d.hh: New file. * oln/core/3d/bkd_piter3d.hh: New file. * oln/core/3d/qiter3d.hh: New file. * oln/core/3d/neighborhood3d.hh: New file. * oln/core/gen/regular_bkd_niter.hh: New file. * oln/core/gen/regular_bkd_qiter.hh: New file. * oln/core/gen/regular_qiter.hh: New file. * oln/core/gen/regular_neighborhood.hh: New file. * oln/makefile.src: Update. * oln/basics1d.hh: Add includes. * oln/basics2d.hh: Likewise. * oln/basics3d.hh: Likewise. * oln/core/typedefs.hh: Add typedef decls. * oln/core/abstract/niter.hh (start_at_p): New method. (nbh_): Remove reference in type. * oln/core/abstract/qiter.hh (for_all_q): Rename as... (for_all_q_of_p): ...this. (grid_type): New property. (qiter): Rewrite. * oln/core/abstract/point.hh (fwd_less, bkd_less): New methods. * oln/core/abstract/dpoint.hh (fwd_less, bkd_less): New methods. (dim): New method. (operator!=, operator-): New operators. (fwd_less_dpoint): New function object type. * oln/core/abstract/neighborhood.hh: Rewrite. * oln/core/abstract/window.hh (grid_type): New property. (fwd_qiter_type): Rename as... (fwd_iter_type): ...this. (qiter.hh): New include. * oln/core/1d/dpoint1d.hh: Update. * oln/core/1d/image1d.hh: Likewise. * oln/core/1d/window1d.hh: Likewise. * oln/core/1d/point1d.hh: Likewise. * oln/core/2d/dpoint2d.hh: Likewise. * oln/core/2d/image2d.hh: Likewise. * oln/core/2d/window2d.hh: Likewise. * oln/core/2d/neighborhood2d.hh: Likewise. * oln/core/2d/point2d.hh: Likewise. * oln/core/3d/dpoint3d.hh: Likewise. * oln/core/3d/image3d.hh: Likewise. * oln/core/3d/window3d.hh: Likewise. * oln/core/3d/point3d.hh: Likewise. * oln/core/any/grid.hh: Likewise. * oln/core/any/point.hh: Likewise. * oln/core/any/dpoint.hh: Likewise. * oln/core/gen/regular_niter.hh: Likewise. * oln/core/gen/regular_fwd_niter.hh: Likewise. * oln/core/gen/regular_fwd_qiter.hh: Likewise. * oln/core/gen/regular_window.hh: Likewise. * oln/morpho/cc_tarjan.hh: Likewise. * oln/morpho/stat.hh: Likewise. * oln/morpho/geodesic_dilation.hh: Likewise. * oln/morpho/geodesic_erosion.hh: Add file and update. Index: oln/basics1d.hh =================================================================== --- oln/basics1d.hh (revision 144) +++ oln/basics1d.hh (working copy) @@ -34,5 +34,7 @@ # include <oln/core/1d/size1d.hh> # include <oln/core/1d/point1d.hh> # include <oln/core/1d/image1d.hh> +# include <oln/core/1d/window1d.hh> +# include <oln/core/1d/neighborhood1d.hh> #endif // ! OLENA_BASICS1D_HH Index: oln/basics2d.hh =================================================================== --- oln/basics2d.hh (revision 144) +++ oln/basics2d.hh (working copy) @@ -34,8 +34,6 @@ # include <oln/core/2d/size2d.hh> # include <oln/core/2d/point2d.hh> # include <oln/core/2d/image2d.hh> -# include <oln/core/2d/fwd_piter2d.hh> -# include <oln/core/2d/bkd_piter2d.hh> # include <oln/core/2d/window2d.hh> # include <oln/core/2d/neighborhood2d.hh> Index: oln/core/typedefs.hh =================================================================== --- oln/core/typedefs.hh (revision 144) +++ oln/core/typedefs.hh (working copy) @@ -28,9 +28,9 @@ #ifndef OLENA_CORE_TYPEDEFS_HH # define OLENA_CORE_TYPEDEFS_HH -// FIXME: rename this present file (?) +# include <iostream> - +# include <mlc/contract.hh> # include <mlc/types.hh> # include <mlc/cmp.hh> # include <mlc/typedef.hh> @@ -45,10 +45,16 @@ mlc_equip_namespace_with_properties(); - // category::image + // general mlc_decl_typedef(grid_type); + mlc_decl_typedef(iter_type); + mlc_decl_typedef(fwd_iter_type); + mlc_decl_typedef(bkd_iter_type); + + // category::image + mlc_decl_typedef(data_type); mlc_decl_typedef(value_type); mlc_decl_typedef(neighb_type); @@ -59,7 +65,6 @@ mlc_decl_typedef(image_type); mlc_decl_typedef(concrete_type); - mlc_decl_typedef(iter_type); mlc_decl_typedef(piter_type); mlc_decl_typedef(fwd_piter_type); mlc_decl_typedef(bkd_piter_type); Index: oln/core/abstract/niter.hh =================================================================== --- oln/core/abstract/niter.hh (revision 144) +++ oln/core/abstract/niter.hh (working copy) @@ -107,6 +107,12 @@ return this->exact().impl_cast_point(); } + void start_at_p(const point_type& p) + { + this->center_at(p); + this->start(); + } + void center_at(const point_type& p) { this->p_ = p; @@ -114,15 +120,15 @@ protected: - niter(const neighb_type& ima) : + const neighb_type nbh_; // copy is safe + point_type p_; + + niter(const neighb_type& nbh) : nbh_(nbh), p_() { } - const neighb_type& nbh_; - point_type p_; - ~niter() { get_props<category::niter, E>::ensure(); Index: oln/core/abstract/qiter.hh =================================================================== --- oln/core/abstract/qiter.hh (revision 144) +++ oln/core/abstract/qiter.hh (working copy) @@ -29,12 +29,13 @@ # define OLENA_CORE_ABSTRACT_QITER_HH # include <oln/core/abstract/iter.hh> +# include <oln/core/abstract/grid.hh> # include <oln/core/abstract/window.hh> # include <oln/core/typedefs.hh> -# define for_all_q( q ) \ - for(q.ensure_is_qiter(), q.start(); q.is_valid(); q.next()) +# define for_all_q_of_p(q, p) \ + for(q.ensure_is_qiter(), q.center_at(p), q.start(); q.is_valid(); q.next()) # define for_all_remaining_q( q ) \ for(q.ensure_is_piter(); q.is_valid(); q.next()) @@ -57,6 +58,7 @@ template <> struct set_default_props < category::qiter > { + typedef mlc::undefined_type grid_type; typedef mlc::undefined_type window_type; }; @@ -65,18 +67,21 @@ template <typename Q> struct get_props < category::qiter, Q > { + typedef oln_qit_type_of(Q, grid) grid_type; typedef oln_qit_type_of(Q, window) window_type; static void echo(std::ostream& ostr) { ostr << "props_of( oln::category::qiter, " << mlc_to_string(Q) << " ) =" << std::endl << "{" << std::endl + << "\t grid_type = " << mlc_to_string(grid_type) << std::endl << "\t window_type = " << mlc_to_string(window_type) << std::endl << "}" << std::endl; } static void ensure() { + mlc::is_ok< grid_type >::ensure(); mlc::is_ok< window_type >::ensure(); } }; @@ -89,22 +94,46 @@ struct qiter : public iter<E> { + typedef oln_qit_type_of(E, grid) grid_type; typedef oln_qit_type_of(E, window) window_type; + typedef oln_grd_type_of(grid_type, point) point_type; + void ensure_is_qiter() {} + operator point_type() const + { + precondition(this->is_valid()); + return this->exact().impl_cast_point(); + } + + void start_at_p(const point_type& p) + { + this->center_at(p); + this->start(); + } + + void center_at(const point_type& p) + { + this->p_ = p; + } + protected: + const window_type win_; // copy is safe + point_type p_; + qiter(const window_type& win) : - win_(win) + win_(win), + p_() { + mlc::eq< grid_type, oln_wn_type_of(window_type, grid) >::ensure(); } - const window_type& win_; - ~qiter() { get_props<category::qiter, E>::ensure(); + mlc_check_method_impl(E, const point_type, cast_point, , const); } }; Index: oln/core/abstract/point.hh =================================================================== --- oln/core/abstract/point.hh (revision 144) +++ oln/core/abstract/point.hh (working copy) @@ -130,11 +130,17 @@ return this->exact().impl_eq(rhs.exact()); } -// // FIXME: compiler error (cannot be overloaded) -// bool operator==(const any_point& rhs) const -// { -// return true; -// } + /// Anteriority w.r.t. to a fwd image browsing. + bool fwd_less(const exact_type& rhs) const + { + return this->exact().impl_fwd_less(rhs.exact()); + } + + /// Anteriority w.r.t. to a bkd image browsing. + bool bkd_less(const exact_type& rhs) const + { + return not *this == rhs and not this->fwd_less(rhs); + } /*! \brief Test difference of two points. Nota bene: this method ** is concrete (and based on abstract::point::operator==). @@ -143,7 +149,7 @@ */ bool operator!=(const exact_type& rhs) const { - return ! this->operator==(rhs); + return not this->operator==(rhs); } // FIXME: doc... @@ -184,11 +190,12 @@ { get_props<category::point, E>::ensure(); - mlc_check_method_impl(E, bool, eq, const exact_type&, const); - mlc_check_method_impl(E, const exact_type, plus, const dpoint_type&, const); - mlc_check_method_impl(E, const dpoint_type, minus, const exact_type&, const); - mlc_check_method_impl(E, const coord_type, nth, unsigned, const); - mlc_check_method_impl(E, coord_type&, nth, unsigned, ); + mlc_check_method_impl(E, bool, eq, const exact_type&, const); + mlc_check_method_impl(E, bool, fwd_less, const exact_type&, const); + mlc_check_method_impl(E, const exact_type, plus, const dpoint_type&, const); + mlc_check_method_impl(E, const dpoint_type, minus, const exact_type&, const); + mlc_check_method_impl(E, const coord_type, nth, unsigned, const); + mlc_check_method_impl(E, coord_type&, nth, unsigned, ); } }; Index: oln/core/abstract/dpoint.hh =================================================================== --- oln/core/abstract/dpoint.hh (revision 144) +++ oln/core/abstract/dpoint.hh (working copy) @@ -29,6 +29,7 @@ # define OLENA_CORE_ABSTRACT_DPOINT_HH # include <mlc/any.hh> +# include <mlc/contract.hh> # include <oln/core/coord.hh> # include <oln/core/typedefs.hh> @@ -62,39 +63,79 @@ return this->exact().impl_eq(rhs.exact()); } - /// Test difference between two dpoints. - bool operator!=(const exact_type& rhs) const + /// Anteriority w.r.t. to a fwd image browsing. + bool fwd_less(const exact_type& rhs) const { - return ! this->operator==(rhs); + return this->exact().impl_fwd_less(rhs.exact()); } - + + /// Anteriority w.r.t. to a bkd image browsing. + bool bkd_less(const exact_type& rhs) const + { + return ! *this == rhs && ! this->fwd_less(rhs); + } + const coord_t nth(unsigned i) const { - // FIXME: add precondition + precondition(i < this->dim()); return this->exact().impl_nth(i); } coord_t& nth(unsigned i) { - // FIXME: add precondition + precondition(i < this->dim()); return this->exact().impl_nth(i); } + unsigned dim() const + { + return this->exact().impl_dim(); + } + + + /// Test difference between two dpoints. + bool operator!=(const exact_type& rhs) const + { + return ! this->operator==(rhs); + } + + /// Unarity minus. + const exact_type operator-() const + { + exact_type tmp; + for (unsigned c = 0; c < this->dim(); ++c) + tmp.nth(c) = - this->nth(c); + return tmp; + } + protected: dpoint() {} ~dpoint() { - mlc_check_method_impl(E, bool, eq, const exact_type&, const); - mlc_check_method_impl(E, const coord_t, nth, unsigned, const); - mlc_check_method_impl(E, coord_t&, nth, unsigned, ); + mlc_check_method_impl(E, bool, eq, const exact_type&, const); + mlc_check_method_impl(E, bool, fwd_less, const exact_type&, const); + mlc_check_method_impl(E, const coord_t, nth, unsigned, const); + mlc_check_method_impl(E, coord_t&, nth, unsigned, ); + mlc_check_method_impl(E, unsigned, dim, , const); } }; } // end of namespace abstract + + struct fwd_less_dpoint + { + template <typename D> + bool operator()(const abstract::dpoint<D>& lhs, const abstract::dpoint<D>& rhs) const + { + return lhs.fwd_less(rhs.exact()); + } + }; + + } // end of namespace oln Index: oln/core/abstract/neighborhood.hh =================================================================== --- oln/core/abstract/neighborhood.hh (revision 144) +++ oln/core/abstract/neighborhood.hh (working copy) @@ -28,14 +28,7 @@ #ifndef OLENA_CORE_NEIGHBORHOOD_HH # define OLENA_CORE_NEIGHBORHOOD_HH -# include <vector> -# include <utility> -# include <iostream> - # include <oln/core/typedefs.hh> -# include <oln/core/coord.hh> -# include <oln/core/abstract/dpoint.hh> -# include <oln/core/accum.hh> # define oln_nbh_type_of(NeighborhoodType, Alias) \ @@ -60,7 +53,7 @@ }; - /// Retrieval of any image type properties (FIXME: say 'packing'). + /// Retrieval of any neighborhood type properties. template <typename N> struct get_props < category::neighborhood, N > @@ -72,10 +65,11 @@ static void echo(std::ostream& ostr) { ostr << "props_of( oln::category::neighborhood, " << mlc_to_string(N) << " ) =" << std::endl + << "{" << std::endl << "\t dpoint_type = " << mlc_to_string(dpoint_type) << std::endl << "\t size_type = " << mlc_to_string(size_type) << std::endl << "\t window_type = " << mlc_to_string(window_type) << std::endl - << std::endl; + << "}" << std::endl; } static void ensure() @@ -92,148 +86,31 @@ namespace abstract { /*! - ** Structuring elements (set of dpoints). + ** Class for neighborhoods. ** - ** This abstract class defines several virtual methods for its - ** subclasses. Its goal is to deal with a set of 'move' points. */ - template<class E> - class neighborhood : public mlc::any__best_memory<E> + template <typename E> + struct neighborhood : public mlc::any<E> { - // FIXME: rewrite this class - - public: - - typedef oln_nbh_type_of(E, dpoint) dpoint_type; - - typedef E exact_type; - - bool - has(const dpoint_type& dp) const - { - return this->exact().impl_has(dp.exact()); - } - - unsigned - card() const - { - return this->exact().impl_card(); - } - - exact_type& - add(const dpoint_type& dp) - { - return this->exact().impl_add(dp); - } - - dpoint_type - dp(unsigned i) const - { - return this->exact().impl_at(i); - } - - const dpoint_type - operator[](unsigned i) const - { - return this->exact().impl_at(i); - } - - coord_t - get_delta() const - { - return this->exact().impl_get_delta(); - } - - coord_t - delta_update(const dpoint_type& dp) - { - return this->exact().impl_delta_update(dp); - } - protected: + + neighborhood() + {} - bool - impl_has(const dpoint_type& dp) const - { - return std::find(dp_.begin(), dp_.end(), dp) != dp_.end(); - } - - exact_type& - impl_add(const dpoint_type& dp) - { - if (!(impl_has(dp))) - { - this->dp_.push_back(dp); - this->dp_.push_back(-dp); - } - this->delta_update(dp); - return this->exact(); - } - - coord_t - impl_get_delta() const - { - return delta_; - } - - unsigned - impl_card() const - { - return dp_.size(); - } - - const dpoint_type - impl_at(unsigned i) const - { - precondition(i < this->card()); - return dp_[i]; - } - - neighborhood() : dp_(), delta_(0) - {}; - - neighborhood(unsigned size) : dp_(), delta_(0) - { - dp_.reserve(size); - }; - - /// Attributes - - std::vector<dpoint_type> dp_; - max_accumulator<coord_t> delta_; - - /// Destructor. - ~neighborhood() { get_props<category::neighborhood, E>::ensure(); -// bool has(const dpoint_type& dp) const -// unsigned card() const -// exact_type& add(const dpoint_type& dp) -// dpoint_type dp(unsigned i) const -// const dpoint_type operator[](unsigned i) const -// coord_t get_delta() const -// coord_t delta_update(const dpoint_type& dp) } }; - } // end of abstract + } // end of namespace abstract::oln -} // end of oln +} // end of namespace oln -template<class E> -std::ostream& -operator<<(std::ostream& o, const oln::abstract::neighborhood<E>& se) -{ - unsigned c = se.card(); - o << "["; - for (unsigned i = 0; i < c; ++i) - o << se.dp(i); - o << "]"; - return o; -} +# include <oln/core/abstract/niter.hh> + #endif // ! OLENA_CORE_NEIGHBORHOOD_HH Index: oln/core/abstract/window.hh =================================================================== --- oln/core/abstract/window.hh (revision 144) +++ oln/core/abstract/window.hh (working copy) @@ -28,15 +28,7 @@ #ifndef OLENA_CORE_ABSTRACT_WINDOW_HH # define OLENA_CORE_ABSTRACT_WINDOW_HH -# include <vector> -# include <utility> -# include <iostream> - -# include <mlc/types.hh> # include <oln/core/typedefs.hh> -# include <oln/core/coord.hh> -# include <oln/core/abstract/dpoint.hh> -# include <oln/core/accum.hh> # define oln_wn_type_of(WindowType, Alias) \ @@ -54,34 +46,38 @@ template <> struct set_default_props < category::window > { + typedef mlc::undefined_type grid_type; typedef mlc::undefined_type dpoint_type; typedef mlc::undefined_type size_type; - typedef mlc::undefined_type fwd_qiter_type; + typedef mlc::undefined_type fwd_iter_type; }; template <typename W> struct get_props < category::window, W > { - typedef oln_wn_type_of(W, dpoint) dpoint_type; - typedef oln_wn_type_of(W, size) size_type; - typedef oln_wn_type_of(W, fwd_qiter) fwd_qiter_type; + typedef oln_wn_type_of(W, grid) grid_type; + typedef oln_wn_type_of(W, dpoint) dpoint_type; + typedef oln_wn_type_of(W, size) size_type; + typedef oln_wn_type_of(W, fwd_iter) fwd_iter_type; static void echo(std::ostream& ostr) { ostr << "props_of( oln::category::window, " << mlc_to_string(W) << " ) =" << std::endl << "{" << std::endl - << "\t dpoint_type = " << mlc_to_string(dpoint_type) << std::endl - << "\t size_type = " << mlc_to_string(size_type) << std::endl - << "\t fwd_qiter_type = " << mlc_to_string(fwd_qiter_type) << std::endl + << "\t grid_type = " << mlc_to_string(grid_type) << std::endl + << "\t dpoint_type = " << mlc_to_string(dpoint_type) << std::endl + << "\t size_type = " << mlc_to_string(size_type) << std::endl + << "\t fwd_iter_type = " << mlc_to_string(fwd_iter_type) << std::endl << "}" << std::endl; } static void ensure() { - mlc::is_ok< dpoint_type >::ensure(); - mlc::is_ok< size_type >::ensure(); - mlc::is_ok< fwd_qiter_type >::ensure(); + mlc::is_ok< grid_type >::ensure(); + mlc::is_ok< dpoint_type >::ensure(); + mlc::is_ok< size_type >::ensure(); + mlc::is_ok< fwd_iter_type >::ensure(); } }; @@ -117,5 +113,7 @@ } // end of namespace oln +# include <oln/core/abstract/qiter.hh> + #endif // ! OLENA_CORE_ABSTRACT_WINDOW_HH Index: oln/core/1d/dpoint1d.hh =================================================================== --- oln/core/1d/dpoint1d.hh (revision 144) +++ oln/core/1d/dpoint1d.hh (working copy) @@ -95,6 +95,11 @@ return this->index_ == rhs.index_; } + bool impl_fwd_less(const dpoint1d& rhs) const + { + return this->index_ < rhs.index_; + } + const coord_t impl_nth(unsigned i) const { precondition(i == 0); @@ -107,6 +112,11 @@ return index_; } + unsigned impl_dim() const + { + return 1; + } + coord_t index_; }; Index: oln/core/1d/niter1d.hh =================================================================== --- oln/core/1d/niter1d.hh (revision 0) +++ oln/core/1d/niter1d.hh (revision 0) @@ -0,0 +1,48 @@ +// 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 OLENA_CORE_1D_NITER1D_HH +# define OLENA_CORE_1D_NITER1D_HH + +# include <oln/core/1d/grid1d.hh> +# include <oln/core/1d/point1d.hh> +# include <oln/core/1d/dpoint1d.hh> +# include <oln/core/1d/neighborhood1d.hh> + +# include <oln/core/gen/regular_fwd_niter.hh> +# include <oln/core/gen/regular_bkd_niter.hh> + + +namespace oln { + + typedef regular_fwd_niter<grid1d> fwd_niter1d; + typedef regular_bkd_niter<grid1d> bkd_niter1d; + +} + + +#endif // ! OLENA_CORE_1D_NITER1D_HH Index: oln/core/1d/image1d.hh =================================================================== --- oln/core/1d/image1d.hh (revision 144) +++ oln/core/1d/image1d.hh (working copy) @@ -131,4 +131,8 @@ } // end of namespace oln +# include <oln/core/1d/fwd_piter1d.hh> +# include <oln/core/1d/bkd_piter1d.hh> + + #endif // ! OLENA_CORE_1D_IMAGE1D_HH Index: oln/core/1d/bkd_piter1d.hh =================================================================== --- oln/core/1d/bkd_piter1d.hh (revision 0) +++ oln/core/1d/bkd_piter1d.hh (revision 0) @@ -0,0 +1,103 @@ +// Copyright (C) 2001, 2002, 2003, 2004, 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 OLENA_CORE_1D_BKD_PITER1D_HH +# define OLENA_CORE_1D_BKD_PITER1D_HH + +# include <mlc/contract.hh> +# include <oln/core/abstract/piter.hh> +# include <oln/core/1d/point1d.hh> +# include <oln/core/1d/size1d.hh> + + +namespace oln { + + + // fwd decl + struct bkd_piter1d; + + // super type + template <> + struct set_super_type < bkd_piter1d > { typedef abstract::piter< bkd_piter1d > ret; }; + + // props + template <> + struct set_props < category::piter, bkd_piter1d > + { + typedef point1d point_type; + typedef size1d size_type; + }; + + + + struct bkd_piter1d : public abstract::piter< bkd_piter1d > + { + typedef bkd_piter1d self_type; + typedef abstract::piter<self_type> super_type; + + bkd_piter1d(const size1d& size) : + super_type(size) + { + this->invalidate(); + } + + friend class abstract::iter<self_type>; + friend class abstract::piter<self_type>; + + protected: + + void impl_start() + { + this->p_.index() = this->s_.nindices() - 1; + postcondition(this->p_.index().is_defined()); + } + + bool impl_is_valid() const + { + precondition(this->p_.index().is_defined()); + return this->p_.index() >= 0; + } + + void impl_next() + { + precondition(this->p_.index().is_defined()); + precondition(this->p_.index() >= 0 && this->p_.index() < this->s_.nindices()); + --this->p_.index(); + postcondition(this->p_.index().is_defined()); + } + + void impl_invalidate() + { + this->p_.index() = -1; + postcondition(this->p_.index().is_defined()); + } + + }; +} + + +#endif // ! OLENA_CORE_1D_BKD_PITER1D_HH Index: oln/core/1d/qiter1d.hh =================================================================== --- oln/core/1d/qiter1d.hh (revision 0) +++ oln/core/1d/qiter1d.hh (revision 0) @@ -0,0 +1,48 @@ +// 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 OLENA_CORE_1D_QITER1D_HH +# define OLENA_CORE_1D_QITER1D_HH + +# include <oln/core/1d/grid1d.hh> +# include <oln/core/1d/point1d.hh> +# include <oln/core/1d/dpoint1d.hh> +# include <oln/core/1d/window1d.hh> + +# include <oln/core/gen/regular_fwd_qiter.hh> +# include <oln/core/gen/regular_bkd_qiter.hh> + + +namespace oln { + + typedef regular_fwd_qiter<grid1d> fwd_qiter1d; + typedef regular_bkd_qiter<grid1d> bkd_qiter1d; + +} + + +#endif // ! OLENA_CORE_1D_QITER1D_HH Index: oln/core/1d/window1d.hh =================================================================== --- oln/core/1d/window1d.hh (revision 144) +++ oln/core/1d/window1d.hh (working copy) @@ -28,9 +28,10 @@ #ifndef OLENA_CORE_WINDOW1D_HH # define OLENA_CORE_WINDOW1D_HH -# include <oln/core/gen/regular_window.hh> # include <oln/core/1d/grid1d.hh> # include <oln/core/1d/dpoint1d.hh> +# include <oln/core/gen/regular_window.hh> +# include <oln/core/1d/qiter1d.hh> namespace oln { Index: oln/core/1d/neighborhood1d.hh =================================================================== --- oln/core/1d/neighborhood1d.hh (revision 0) +++ oln/core/1d/neighborhood1d.hh (revision 0) @@ -0,0 +1,50 @@ +// 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 OLENA_CORE_NEIGHBORHOOD1D_HH +# define OLENA_CORE_NEIGHBORHOOD1D_HH + +# include <oln/core/1d/window1d.hh> +# include <oln/core/gen/regular_neighborhood.hh> +# include <oln/core/1d/niter1d.hh> + + +namespace oln { + + typedef regular_neighborhood< grid1d > neighborhood1d; + + inline const neighborhood1d& + neighb_c2() + { + static const neighborhood1d neighb(win_c2_only()); + return neighb; + } + +} // end of namespace oln + + +#endif // OLENA_CORE_NEIGHBORHOOD2D_HH Index: oln/core/1d/point1d.hh =================================================================== --- oln/core/1d/point1d.hh (revision 144) +++ oln/core/1d/point1d.hh (working copy) @@ -96,6 +96,11 @@ return this->index_ == rhs.index_; } + bool impl_fwd_less(const point1d& rhs) const + { + return this->index_ < rhs.index_; + } + const coord_t impl_nth(unsigned i) const { precondition(i == 0); Index: oln/core/2d/dpoint2d.hh =================================================================== --- oln/core/2d/dpoint2d.hh (revision 144) +++ oln/core/2d/dpoint2d.hh (working copy) @@ -105,6 +105,13 @@ return this->row_ == rhs.row_ && this->col_ == rhs.col_; } + bool impl_fwd_less(const dpoint2d& rhs) const + { + return + this->row_ < rhs.row_ + || (this->row_ == rhs.row_ && this->col_ < rhs.col_); + } + const coord_t impl_nth(unsigned i) const { precondition(i < 2); @@ -123,6 +130,11 @@ return col_; } + unsigned impl_dim() const + { + return 2; + } + coord_t row_, col_; }; Index: oln/core/2d/fwd_niter2d.hh =================================================================== --- oln/core/2d/fwd_niter2d.hh (revision 145) +++ oln/core/2d/fwd_niter2d.hh (working copy) @@ -1,46 +0,0 @@ -// 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 OLENA_CORE_2D_FWD_NITER2D_HH -# define OLENA_CORE_2D_FWD_NITER2D_HH - -# include <oln/core/2d/grid2d.hh> -# include <oln/core/2d/point2d.hh> -# include <oln/core/2d/dpoint2d.hh> -# include <oln/core/2d/neighborhood2d.hh> - -# include <oln/core/gen/regular_fwd_niter.hh> - - -namespace oln { - - typedef regular_fwd_niter<grid2d> fwd_niter2d; - -} - - -#endif // ! OLENA_CORE_2D_FWD_NITER2D_HH Index: oln/core/2d/niter2d.hh =================================================================== --- oln/core/2d/niter2d.hh (revision 0) +++ oln/core/2d/niter2d.hh (revision 0) @@ -0,0 +1,48 @@ +// 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 OLENA_CORE_2D_NITER2D_HH +# define OLENA_CORE_2D_NITER2D_HH + +# include <oln/core/2d/grid2d.hh> +# include <oln/core/2d/point2d.hh> +# include <oln/core/2d/dpoint2d.hh> +# include <oln/core/2d/neighborhood2d.hh> + +# include <oln/core/gen/regular_fwd_niter.hh> +# include <oln/core/gen/regular_bkd_niter.hh> + + +namespace oln { + + typedef regular_fwd_niter<grid2d> fwd_niter2d; + typedef regular_bkd_niter<grid2d> bkd_niter2d; + +} + + +#endif // ! OLENA_CORE_2D_NITER2D_HH Index: oln/core/2d/image2d.hh =================================================================== --- oln/core/2d/image2d.hh (revision 144) +++ oln/core/2d/image2d.hh (working copy) @@ -31,6 +31,7 @@ # include <oln/core/abstract/image_with_data.hh> # include <oln/core/abstract/image_like_.hh> # include <oln/core/2d/array2d.hh> +# include <oln/core/2d/niter2d.hh> /*! \namespace oln @@ -51,7 +52,6 @@ // fwd decls struct fwd_piter2d; struct bkd_piter2d; - struct fwd_niter2d; template <typename T> class image2d; // super @@ -166,4 +166,8 @@ } // end of namespace oln +# include <oln/core/2d/fwd_piter2d.hh> +# include <oln/core/2d/bkd_piter2d.hh> + + #endif // ! OLENA_CORE_IMAGE2D_HH Index: oln/core/2d/qiter2d.hh =================================================================== --- oln/core/2d/qiter2d.hh (revision 0) +++ oln/core/2d/qiter2d.hh (revision 0) @@ -0,0 +1,48 @@ +// 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 OLENA_CORE_2D_QITER2D_HH +# define OLENA_CORE_2D_QITER2D_HH + +# include <oln/core/2d/grid2d.hh> +# include <oln/core/2d/point2d.hh> +# include <oln/core/2d/dpoint2d.hh> +# include <oln/core/2d/window2d.hh> + +# include <oln/core/gen/regular_fwd_qiter.hh> +# include <oln/core/gen/regular_bkd_qiter.hh> + + +namespace oln { + + typedef regular_fwd_qiter<grid2d> fwd_qiter2d; + typedef regular_bkd_qiter<grid2d> bkd_qiter2d; + +} + + +#endif // ! OLENA_CORE_2D_QITER2D_HH Index: oln/core/2d/window2d.hh =================================================================== --- oln/core/2d/window2d.hh (revision 144) +++ oln/core/2d/window2d.hh (working copy) @@ -28,9 +28,10 @@ #ifndef OLENA_CORE_WINDOW2D_HH # define OLENA_CORE_WINDOW2D_HH -# include <oln/core/gen/regular_window.hh> # include <oln/core/2d/dpoint2d.hh> # include <oln/core/2d/grid2d.hh> +# include <oln/core/gen/regular_window.hh> +# include <oln/core/2d/qiter2d.hh> namespace oln Index: oln/core/2d/neighborhood2d.hh =================================================================== --- oln/core/2d/neighborhood2d.hh (revision 144) +++ oln/core/2d/neighborhood2d.hh (working copy) @@ -28,106 +28,31 @@ #ifndef OLENA_CORE_NEIGHBORHOOD2D_HH # define OLENA_CORE_NEIGHBORHOOD2D_HH -# include <oln/core/coord.hh> -# include <oln/core/abstract/neighborhood.hh> -# include <oln/core/2d/dpoint2d.hh> -# include <oln/core/2d/size2d.hh> # include <oln/core/2d/window2d.hh> +# include <oln/core/gen/regular_neighborhood.hh> +# include <oln/core/2d/niter2d.hh> namespace oln { - class neighborhood2d; // forward declaration + typedef regular_neighborhood< grid2d > neighborhood2d; - // super_type - template <> - struct set_super_type< neighborhood2d > { typedef abstract::neighborhood< neighborhood2d > ret; }; - - template <> - struct set_props< category::neighborhood, neighborhood2d > - { - typedef dpoint2d dpoint_type; - typedef size2d size_type; - typedef window2d window_type; - }; - - - class neighborhood2d : public abstract::neighborhood< neighborhood2d > - { - - public: - - typedef abstract::neighborhood< neighborhood2d > super_type; - - /*! - ** \brief Construct a neighborhood of 2 dimensions. - */ - neighborhood2d() : - super_type() - { - } - - /*! - ** \brief Construct a neighborhood of 2 dimensions. - ** \arg size The number of element. - */ - neighborhood2d(unsigned size) : - super_type(size) - { - } - - /*! - ** \brief Construct a neighborhood of 2 dimensions from several points. - ** \arg n The number of element. - ** \arg crd The coordinates of the elements - */ - neighborhood2d(unsigned n, const coord_t crd[]) : - super_type(n) - { - for (unsigned i = 0; i < 2 * n; i += 2) - this->add(dpoint2d(crd[i], crd[i+1])); - } - - neighborhood2d& - add(const dpoint2d& dp) - { - return this->exact().impl_add(dp); - } - - neighborhood2d& - add(coord_t row, coord_t col) - { - dpoint2d dp(row, col); - return add(dp); - } - - coord_t - impl_delta_update(const dpoint2d& dp) - { - delta_(abs(dp.row())); - delta_(abs(dp.col())); - return delta_; - } - - }; - - inline const neighborhood2d& neighb_c4() { - static const coord_t crd[] = { 0,1, 1,0 }; - static const neighborhood2d neighb(2, crd); + static const neighborhood2d neighb(win_c4_only()); return neighb; } inline const neighborhood2d& neighb_c8() { - static const coord_t crd[] = { 0,1, 1,1, 1,0, 1,-1 }; - static const neighborhood2d neighb(4, crd); + static const neighborhood2d neighb(win_c8_only()); return neighb; } -} // end of oln +} // end of namespace oln + + #endif // OLENA_CORE_NEIGHBORHOOD2D_HH Index: oln/core/2d/point2d.hh =================================================================== --- oln/core/2d/point2d.hh (revision 144) +++ oln/core/2d/point2d.hh (working copy) @@ -108,6 +108,13 @@ return this->row_ == rhs.row_ && this->col_ == rhs.col_; } + bool impl_fwd_less(const point2d& rhs) const + { + return + this->row_ < rhs.row_ + || (this->row_ == rhs.row_ && this->col_ < rhs.col_); + } + const coord_t impl_nth(unsigned i) const { precondition(i < 2); Index: oln/core/3d/dpoint3d.hh =================================================================== --- oln/core/3d/dpoint3d.hh (revision 144) +++ oln/core/3d/dpoint3d.hh (working copy) @@ -99,6 +99,15 @@ return this->row_ == rhs.row_ && this->col_ == rhs.col_ && this->slice_ == rhs.slice_; } + bool impl_fwd_less(const dpoint3d& rhs) const + { + return + this->slice_ < rhs.slice_ + || (this->slice_ == rhs.slice_ + && (this->row_ < rhs.row_ + || (this->row_ == rhs.row_ && this->col_ < rhs.col_))); + } + const coord_t impl_nth(unsigned i) const { precondition(i < 3); @@ -132,6 +141,11 @@ return dummy; } + unsigned impl_dim() const + { + return 3; + } + coord_t slice_, row_, col_; }; Index: oln/core/3d/niter3d.hh =================================================================== --- oln/core/3d/niter3d.hh (revision 0) +++ oln/core/3d/niter3d.hh (revision 0) @@ -0,0 +1,48 @@ +// 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 OLENA_CORE_3D_NITER3D_HH +# define OLENA_CORE_3D_NITER3D_HH + +# include <oln/core/3d/grid3d.hh> +# include <oln/core/3d/point3d.hh> +# include <oln/core/3d/dpoint3d.hh> +# include <oln/core/3d/neighborhood3d.hh> + +# include <oln/core/gen/regular_fwd_niter.hh> +# include <oln/core/gen/regular_bkd_niter.hh> + + +namespace oln { + + typedef regular_fwd_niter<grid3d> fwd_niter3d; + typedef regular_bkd_niter<grid3d> bkd_niter3d; + +} + + +#endif // ! OLENA_CORE_3D_NITER3D_HH Index: oln/core/3d/image3d.hh =================================================================== --- oln/core/3d/image3d.hh (revision 144) +++ oln/core/3d/image3d.hh (working copy) @@ -131,4 +131,8 @@ } // end of namespace oln +# include <oln/core/3d/fwd_piter3d.hh> +# include <oln/core/3d/bkd_piter3d.hh> + + #endif // ! OLENA_CORE_3D_IMAGE3D_HH Index: oln/core/3d/bkd_piter3d.hh =================================================================== --- oln/core/3d/bkd_piter3d.hh (revision 0) +++ oln/core/3d/bkd_piter3d.hh (revision 0) @@ -0,0 +1,123 @@ +// Copyright (C) 2001, 2002, 2003, 2004, 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 OLENA_CORE_3D_BKD_PITER3D_HH +# define OLENA_CORE_3D_BKD_PITER3D_HH + +# include <mlc/contract.hh> + +# include <oln/core/abstract/piter.hh> +# include <oln/core/3d/point3d.hh> +# include <oln/core/3d/size3d.hh> + + +namespace oln { + + // fwd decl + struct bkd_piter3d; + + // props + template <> + struct set_props < category::piter, bkd_piter3d > + { + typedef point3d point_type; + typedef size3d size_type; + }; + + + + struct bkd_piter3d : public abstract::piter< bkd_piter3d > + { + typedef bkd_piter3d self_type; + typedef abstract::piter<self_type> super_type; + + bkd_piter3d(const size3d& size) : + super_type(size) + { + this->invalidate(); + } + + friend class abstract::iter<self_type>; + friend class abstract::piter<self_type>; + + protected: + + void impl_start() + { + this->p_.row() = this->s_.nrows() - 1; + this->p_.col() = this->s_.ncols() - 1; + this->p_.slice() = this->s_.nslices() - 1; + postcondition(this->p_.row().is_defined() && + this->p_.col().is_defined() && + this->p_.slice().is_defined()); + } + + bool impl_is_valid() const + { + precondition(this->p_.row().is_defined() && + this->p_.col().is_defined() && + this->p_.slice().is_defined()); + return this->p_.slice() >= 0; + } + + void impl_next() + { + precondition(this->p_.row().is_defined() && + this->p_.col().is_defined() && + this->p_.slice().is_defined()); + precondition(this->p_.row() >= 0 && this->p_.row() < this->s_.nrows() && + this->p_.col() >= 0 && this->p_.col() < this->s_.ncols() && + this->p_.slice() >= 0 && this->p_.slice() < this->s_.nslices()); + --this->p_.col(); + if (this->p_.col() >= 0) + return; + this->p_.col() = this->s_.ncols() - 1; +; --this->p_.row(); + if (this->p_.row() >= 0) + return; + this->p_.row() = this->s_.nrows() - 1; + --this->p_.slice(); + postcondition(this->p_.row().is_defined() && + this->p_.col().is_defined() && + this->p_.slice().is_defined()); + } + + void impl_invalidate() + { + this->p_.row() = -1; + this->p_.col() = -1; + this->p_.slice() = -1; + postcondition(this->p_.row().is_defined() && + this->p_.col().is_defined() && + this->p_.slice().is_defined()); + } + + }; +} + + +#endif // ! OLENA_CORE_3D_BKD_PITER3D_HH Index: oln/core/3d/qiter3d.hh =================================================================== --- oln/core/3d/qiter3d.hh (revision 0) +++ oln/core/3d/qiter3d.hh (revision 0) @@ -0,0 +1,48 @@ +// 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 OLENA_CORE_3D_QITER3D_HH +# define OLENA_CORE_3D_QITER3D_HH + +# include <oln/core/3d/grid3d.hh> +# include <oln/core/3d/point3d.hh> +# include <oln/core/3d/dpoint3d.hh> +# include <oln/core/3d/window3d.hh> + +# include <oln/core/gen/regular_fwd_qiter.hh> +# include <oln/core/gen/regular_bkd_qiter.hh> + + +namespace oln { + + typedef regular_fwd_qiter<grid3d> fwd_qiter3d; + typedef regular_bkd_qiter<grid3d> bkd_qiter3d; + +} + + +#endif // ! OLENA_CORE_3D_QITER3D_HH Index: oln/core/3d/window3d.hh =================================================================== --- oln/core/3d/window3d.hh (revision 144) +++ oln/core/3d/window3d.hh (working copy) @@ -28,9 +28,10 @@ #ifndef OLENA_CORE_WINDOW3D_HH # define OLENA_CORE_WINDOW3D_HH -# include <oln/core/gen/regular_window.hh> # include <oln/core/3d/dpoint3d.hh> # include <oln/core/3d/grid3d.hh> +# include <oln/core/gen/regular_window.hh> +# include <oln/core/3d/qiter3d.hh> namespace oln { Index: oln/core/3d/neighborhood3d.hh =================================================================== --- oln/core/3d/neighborhood3d.hh (revision 0) +++ oln/core/3d/neighborhood3d.hh (revision 0) @@ -0,0 +1,65 @@ +// 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 OLENA_CORE_NEIGHBORHOOD3D_HH +# define OLENA_CORE_NEIGHBORHOOD3D_HH + +# include <oln/core/3d/window3d.hh> +# include <oln/core/gen/regular_neighborhood.hh> +# include <oln/core/3d/niter3d.hh> + + +namespace oln { + + typedef regular_neighborhood< grid3d > neighborhood3d; + + inline const neighborhood3d& + neighb_c6() + { + static const neighborhood3d neighb(win_c6_only()); + return neighb; + } + + inline const neighborhood3d& + neighb_c18() + { + static const neighborhood3d neighb(win_c18_only()); + return neighb; + } + + inline const neighborhood3d& + neighb_c26() + { + static const neighborhood3d neighb(win_c26_only()); + return neighb; + } + + +} // end of namespace oln + + +#endif // OLENA_CORE_NEIGHBORHOOD3D_HH Index: oln/core/3d/point3d.hh =================================================================== --- oln/core/3d/point3d.hh (revision 144) +++ oln/core/3d/point3d.hh (working copy) @@ -104,6 +104,15 @@ this->col_ == rhs.col_; } + bool impl_fwd_less(const point3d& rhs) const + { + return + this->slice_ < rhs.slice_ + || (this->slice_ == rhs.slice_ + && (this->row_ < rhs.row_ + || (this->row_ == rhs.row_ && this->col_ < rhs.col_))); + } + const point3d impl_plus(const dpoint3d& rhs) const; const dpoint3d impl_minus(const point3d& rhs) const; Index: oln/core/any/grid.hh =================================================================== --- oln/core/any/grid.hh (revision 144) +++ oln/core/any/grid.hh (working copy) @@ -38,6 +38,7 @@ struct any_grid; struct any_point; struct any_dpoint; + struct any_size; struct any_coord; // super type @@ -54,6 +55,7 @@ typedef any_point point_type; typedef any_dpoint dpoint_type; typedef any_coord coord_type; + typedef any_size size_type; typedef mlc::value<unsigned,0> dimvalue_type; }; Index: oln/core/any/point.hh =================================================================== --- oln/core/any/point.hh (revision 144) +++ oln/core/any/point.hh (working copy) @@ -29,6 +29,7 @@ # define OLENA_CORE_ANY_POINT_HH # include <iostream> +# include <mlc/contract.hh> # include <oln/core/abstract/point.hh> # include <oln/core/abstract/dpoint.hh> # include <oln/core/any/grid.hh> @@ -53,6 +54,19 @@ struct any_point : public abstract::point < any_point > { + any_point() + {} + + friend class abstract::point<any_point>; + + protected: + + bool impl_fwd_less(const any_point& rhs) const + { + precondition(0); + return false; + } + bool impl_eq(const exact_type& rhs) const { return this->exact().impl_eq(rhs.exact()); Index: oln/core/any/dpoint.hh =================================================================== --- oln/core/any/dpoint.hh (revision 144) +++ oln/core/any/dpoint.hh (working copy) @@ -29,6 +29,7 @@ # define OLENA_CORE_ANY_DPOINT_HH # include <iostream> +# include <mlc/contract.hh> # include <oln/core/abstract/dpoint.hh> # include <oln/core/any/point.hh> @@ -45,6 +46,8 @@ struct any_dpoint : public abstract::dpoint < any_dpoint > { + any_dpoint() + {} template <typename D> const any_dpoint operator+(const abstract::dpoint<D>& rhs) const @@ -64,6 +67,12 @@ protected: + bool impl_fwd_less(const any_dpoint& rhs) const + { + precondition(0); + return false; + } + bool impl_eq(const any_dpoint& rhs) const { return true; @@ -82,6 +91,11 @@ return dummy; } + unsigned impl_dim() const + { + return 0; + } + }; } // end of namespace oln Index: oln/core/gen/regular_niter.hh =================================================================== --- oln/core/gen/regular_niter.hh (revision 144) +++ oln/core/gen/regular_niter.hh (working copy) @@ -28,13 +28,9 @@ #ifndef OLENA_CORE_GEN_REGULAR_NITER_HH # define OLENA_CORE_GEN_REGULAR_NITER_HH -# include <vector> - # include <mlc/contract.hh> # include <oln/core/abstract/niter.hh> -# include <oln/core/abstract/grid.hh> -# include <oln/core/abstract/point.hh> -# include <oln/core/abstract/dpoint.hh> +# include <oln/core/gen/regular_neighborhood.hh> namespace oln { @@ -52,12 +48,8 @@ template <typename G, typename E> struct set_props < category::niter, abstract::regular_niter<G,E> > { - typedef G grid_type; - typedef oln_grd_type_of(G, point) point_type; - typedef oln_grd_type_of(G, dpoint) dpoint_type; - - // FIXME: uncomment when class exists -// typedef regular_neighborhood<G> neighb_type; + typedef oln_grd_type_of(G, point) point_type; + typedef regular_neighborhood<G> neighb_type; }; @@ -67,27 +59,37 @@ template <typename G, typename E> struct regular_niter : public niter<E> { + typedef niter<E> super_type; - /// typedefs - typedef niter<E> super_type; - typedef oln_nit_type_of(E, point) point_type; - typedef oln_nit_type_of(E, dpoint) dpoint_type; - typedef oln_nit_type_of(E, neighb) neighb_type; + typedef oln_grd_type_of(G, coord) coord_type; + typedef oln_grd_type_of(G, point) point_type; + typedef oln_grd_type_of(G, dpoint) dpoint_type; - const point_type impl_cast_point() const + typedef oln_grd_type_of(G, dimvalue) dimvalue_type; + static const unsigned dim = dimvalue_type::val; + + regular_niter(const regular_neighborhood<G>& nbh) : + super_type(nbh) { + } + + const coord_type nth(unsigned i) const + { + precondition(i < dim); precondition(this->is_valid()); - return this->p_ + *(this->dp_cur_); + return point_type(*this).nth(i); } protected: - regular_niter(const neighb_type& nbh) : - super_type(nbh) + int pos_; + + const point_type impl_cast_point() const { + precondition(this->is_valid()); + return this->p_ + this->nbh_.dp(this->pos_); } - typename std::vector<dpoint_type>::const_iterator dp_cur_; }; } // end of namespace oln::abstract Index: oln/core/gen/regular_fwd_niter.hh =================================================================== --- oln/core/gen/regular_fwd_niter.hh (revision 144) +++ oln/core/gen/regular_fwd_niter.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2001, 2002, 2003, 2004, 2005 EPITA Research and Development Laboratory +// 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 @@ -28,12 +28,10 @@ #ifndef OLENA_CORE_GEN_REGULAR_FWD_NITER_HH # define OLENA_CORE_GEN_REGULAR_FWD_NITER_HH +# include <oln/core/gen/image_with_nbh.hh> # include <oln/core/gen/regular_niter.hh> -# include <oln/core/2d/neighborhood2d.hh> -# include <oln/core/gen/image_with_nbh.hh> - namespace oln { // fwd decl @@ -43,19 +41,12 @@ template <typename G> struct set_super_type < regular_fwd_niter<G> > { typedef abstract::regular_niter< G, regular_fwd_niter<G> > ret; }; - // props - template <typename G> - struct set_props < category::niter, regular_fwd_niter<G> > - { - typedef neighborhood2d neighb_type; // FIXME: see FIXME in regular_niter - }; - template <typename G> struct regular_fwd_niter : public abstract::regular_niter< G, regular_fwd_niter<G> > { typedef regular_fwd_niter<G> self_type; - typedef abstract::regular_niter< G, self_type > super_type; + typedef abstract::regular_niter<G, self_type> super_type; template <typename I> regular_fwd_niter(const abstract::image_with_nbh<I>& image) : @@ -69,24 +60,22 @@ void impl_start() { - this->dp_cur_ = this->dp_.begin(); + this->pos_ = 0; } void impl_next() { - precondition(this->is_valid()); - ++(this->dp_cur_); + ++(this->pos_); } bool impl_is_valid() const { - return this->dp_cur_ != this->dp_.end(); + return this->pos_ != this->nbh_.card(); } void impl_invalidate() { - this->dp_cur_ = this->dp_.end(); - postcondition(! this->is_valid()); + this->pos_ = this->nbh_.card(); } }; Index: oln/core/gen/regular_bkd_niter.hh =================================================================== --- oln/core/gen/regular_bkd_niter.hh (revision 0) +++ oln/core/gen/regular_bkd_niter.hh (revision 0) @@ -0,0 +1,87 @@ +// 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 OLENA_CORE_GEN_REGULAR_BKD_NITER_HH +# define OLENA_CORE_GEN_REGULAR_BKD_NITER_HH + +# include <oln/core/gen/image_with_nbh.hh> +# include <oln/core/gen/regular_niter.hh> + + +namespace oln { + + // fwd decl + template <typename G> struct regular_bkd_niter; + + // super type + template <typename G> + struct set_super_type < regular_bkd_niter<G> > { typedef abstract::regular_niter< G, regular_bkd_niter<G> > ret; }; + + + template <typename G> + struct regular_bkd_niter : public abstract::regular_niter< G, regular_bkd_niter<G> > + { + typedef regular_bkd_niter<G> self_type; + typedef abstract::regular_niter<G, self_type> super_type; + + template <typename I> + regular_bkd_niter(const abstract::image_with_nbh<I>& image) : + super_type(image.nbh_get()) + { + } + + friend class abstract::iter<self_type>; + + protected: + + void impl_start() + { + this->pos_ = this->nbh_.card() - 1; + } + + void impl_next() + { + --(this->pos_); + } + + bool impl_is_valid() const + { + return this->pos_ != -1; + } + + void impl_invalidate() + { + this->pos_ = -1; + } + + }; + + +} // end of namespace oln + + +#endif // ! OLENA_CORE_GEN_REGULAR_BKD_NITER_HH Index: oln/core/gen/regular_fwd_qiter.hh =================================================================== --- oln/core/gen/regular_fwd_qiter.hh (revision 144) +++ oln/core/gen/regular_fwd_qiter.hh (working copy) @@ -25,65 +25,35 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef OLENA_CORE_REGULAR_FWD_QITER_HH -# define OLENA_CORE_REGULAR_FWD_QITER_HH +#ifndef OLENA_CORE_GEN_REGULAR_FWD_QITER_HH +# define OLENA_CORE_GEN_REGULAR_FWD_QITER_HH -# include <oln/core/abstract/grid.hh> -# include <oln/core/abstract/qiter.hh> -# include <oln/core/gen/regular_window.hh> +# include <oln/core/gen/regular_qiter.hh> namespace oln { // fwd decl - template <typename G> - struct regular_fwd_qiter; + template <typename G> struct regular_fwd_qiter; // category template <typename G> - struct set_super_type< regular_fwd_qiter<G> > { typedef abstract::qiter< regular_fwd_qiter<G> > ret; }; + struct set_super_type< regular_fwd_qiter<G> > { typedef abstract::regular_qiter< G, regular_fwd_qiter<G> > ret; }; - // props - template <typename G> - struct set_props < category::qiter, regular_fwd_qiter<G> > - { - typedef regular_window<G> window_type; - }; - template <typename G> - struct regular_fwd_qiter : public abstract::qiter< regular_fwd_qiter<G> > + struct regular_fwd_qiter : public abstract::regular_qiter< G, regular_fwd_qiter<G> > { typedef regular_fwd_qiter<G> self_type; - typedef abstract::qiter<self_type> super_type; + typedef abstract::regular_qiter<G, self_type> super_type; - typedef oln_grd_type_of(G, coord) coord_type; - typedef oln_grd_type_of(G, dpoint) dpoint_type; - regular_fwd_qiter(const regular_window<G>& win) : super_type(win) { this->invalidate(); } - const coord_type nth(unsigned i) const - { - return this->win_[this->pos_].nth(i); - } - - coord_type& nth(unsigned i) - { - return this->win_[this->pos_].nth(i); - } - - operator dpoint_type() const - { - precondition(this->is_valid()); - return this->win_[this->pos_]; - } - friend class abstract::iter<self_type>; - friend class abstract::qiter<self_type>; protected: @@ -107,11 +77,9 @@ this->pos_ = this->win_.card(); } - unsigned pos_; - }; } // end of namespace oln -#endif // OLENA_CORE_REGULAR_FWD_QITER_HH +#endif // ! OLENA_CORE_GEN_REGULAR_FWD_QITER_HH Index: oln/core/gen/regular_bkd_qiter.hh =================================================================== --- oln/core/gen/regular_bkd_qiter.hh (revision 0) +++ oln/core/gen/regular_bkd_qiter.hh (revision 0) @@ -0,0 +1,86 @@ +// 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 OLENA_CORE_REGULAR_BKD_QITER_HH +# define OLENA_CORE_REGULAR_BKD_QITER_HH + +# include <oln/core/gen/regular_qiter.hh> + + +namespace oln { + + // bkd decl + template <typename G> + struct regular_bkd_qiter; + + // category + template <typename G> + struct set_super_type< regular_bkd_qiter<G> > { typedef abstract::regular_qiter< G, regular_bkd_qiter<G> > ret; }; + + + template <typename G> + struct regular_bkd_qiter : public abstract::regular_qiter< G, regular_bkd_qiter<G> > + { + typedef regular_bkd_qiter<G> self_type; + typedef abstract::regular_qiter<G, self_type> super_type; + + regular_bkd_qiter(const regular_window<G>& win) : + super_type(win) + { + this->invalidate(); + } + + friend class abstract::iter<self_type>; + + protected: + + void impl_start() + { + this->pos_ = this->win_.card() - 1; + } + + void impl_next() + { + --(this->pos_); + } + + bool impl_is_valid() const + { + return this->pos_ != -1; + } + + void impl_invalidate() + { + this->pos_ = -1; + } + + }; + +} // end of namespace oln + + +#endif // OLENA_CORE_REGULAR_BKD_QITER_HH Index: oln/core/gen/regular_qiter.hh =================================================================== --- oln/core/gen/regular_qiter.hh (revision 0) +++ oln/core/gen/regular_qiter.hh (revision 0) @@ -0,0 +1,100 @@ +// 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 OLENA_CORE_GEN_REGULAR_QITER_HH +# define OLENA_CORE_GEN_REGULAR_QITER_HH + +# include <oln/core/abstract/grid.hh> +# include <oln/core/abstract/qiter.hh> +# include <oln/core/gen/regular_window.hh> + + +namespace oln { + + // fwd decl + namespace abstract { + template <typename G, typename E> struct regular_qiter; + } + + // category + template <typename G, typename E> + struct set_super_type< abstract::regular_qiter<G,E> > { typedef abstract::qiter<E> ret; }; + + // props + template <typename G, typename E> + struct set_props < category::qiter, abstract::regular_qiter<G,E> > + { + typedef G grid_type; + typedef regular_window<G> window_type; + }; + + + namespace abstract + { + + template <typename G, typename E> + struct regular_qiter : public qiter<E> + { + typedef qiter<E> super_type; + + typedef oln_grd_type_of(G, coord) coord_type; + typedef oln_grd_type_of(G, point) point_type; + typedef oln_grd_type_of(G, dpoint) dpoint_type; + + typedef oln_grd_type_of(G, dimvalue) dimvalue_type; + static const unsigned dim = dimvalue_type::val; + + regular_qiter(const regular_window<G>& win) : + super_type(win) + { + } + + const coord_type nth(unsigned i) const + { + precondition(i < dim); + precondition(this->is_valid()); + return point_type(*this).nth(i); + } + + protected: + + int pos_; + + const point_type impl_cast_point() const + { + precondition(this->is_valid()); + return this->p_ + this->win_.dp(this->pos_); + } + + }; + + } // end of namespace abstract::oln + +} // end of namespace oln + + +#endif // OLENA_CORE_GEN_REGULAR_QITER_HH Index: oln/core/gen/regular_window.hh =================================================================== --- oln/core/gen/regular_window.hh (revision 144) +++ oln/core/gen/regular_window.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2001, 2002, 2003, 2004, 2005 EPITA Research and Development Laboratory +// 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 @@ -29,11 +29,15 @@ # define OLENA_CORE_GEN_REGULAR_WINDOW_HH # include <iostream> - +# include <algorithm> +# include <iterator> +# include <vector> +# include <set> + # include <mlc/contract.hh> -# include <oln/core/abstract/window.hh> # include <oln/core/abstract/grid.hh> -# include <oln/core/accum.hh> +# include <oln/core/abstract/dpoint.hh> +# include <oln/core/abstract/window.hh> namespace oln { @@ -49,15 +53,13 @@ template <typename G> struct set_props< category::window, regular_window<G> > { - typedef oln_grd_type_of(G, point) point_type; + typedef G grid_type; typedef oln_grd_type_of(G, dpoint) dpoint_type; typedef oln_grd_type_of(G, size) size_type; - typedef regular_fwd_qiter<G> fwd_qiter_type; + typedef regular_fwd_qiter<G> fwd_iter_type; // typedef regular_fwd_dpiter<G> fwd_dpiter_type; // FIXME: later... }; - - - + template <typename G> class regular_window : public abstract::window< regular_window<G> > { @@ -65,9 +67,11 @@ public: typedef regular_window<G> self_type; - typedef oln_wn_type_of(self_type, dpoint) dpoint_type; + typedef oln_grd_type_of(G, coord) coord_type; + typedef oln_grd_type_of(G, dpoint) dpoint_type; typedef oln_grd_type_of(G, dimvalue) dimvalue_type; + static const unsigned dim = dimvalue_type::val; regular_window() : @@ -76,8 +80,7 @@ { } - regular_window(unsigned n, - const oln_grd_type_of(G, coord) crd[]) : + regular_window(unsigned n, const coord_type crd[]) : dp_(), delta_(0) { @@ -92,71 +95,63 @@ } } - bool has(const dpoint_type& dp) const - { - return std::find(this->dp_.begin(), this->dp_.end(), dp) != dp_.end(); - } - self_type& add(const dpoint_type& dp) { - if (! this->has(dp)) - this->dp_.push_back(dp); - this->delta_update(dp); + this->dpset_.insert(dp); + this->dp_.clear(); + std::copy(this->dpset_.begin(), this->dpset_.end(), + std::back_inserter(this->dp_)); + this->delta_update_(dp); return *this; } - coord_t delta_update(const dpoint_type& dp) + coord_type delta() const { - for (unsigned c = 0; c < dim; ++c) - this->delta_(abs(dp.nth(c))); return this->delta_; } - coord_t get_delta() const - { - return this->delta_; - } - unsigned card() const { return this->dp_.size(); } - const dpoint_type at(unsigned i) const + const dpoint_type dp(unsigned i) const { precondition(i < this->card()); - return dp_[i]; + return this->dp_[i]; } - // FIXME: redundant... - dpoint_type dp(unsigned i) const + const self_type operator-() const { - return this->at(i); + self_type tmp; + for (unsigned i = 0; i < this->card(); ++i) + tmp.add(- this->dp_[i]); + return tmp; } - // FIXME: redundant... - const dpoint_type operator[](unsigned i) const + void sym() { - return this->at(i); + *this = - *this; } -// const self_type operator-() const -// { -// self_type tmp; -// for (unsigned i = 0; i < this->card(), ++i) -// tmp.add(- this->at(i)); -// return tmp; -// } - - void sym() + const std::vector<dpoint_type>& get_dp() const { - *this = - *this; + return this->dp_; } private: - + + std::set<dpoint_type, fwd_less_dpoint> dpset_; std::vector<dpoint_type> dp_; - max_accumulator<coord_t> delta_; + coord_type delta_; + + void delta_update_(const dpoint_type& dp) + { + for (unsigned c = 0; c < dim; ++c) + if (abs(dp.nth(c)) > this->delta_) + this->delta_ = abs(dp.nth(c)); + } + }; @@ -167,16 +162,12 @@ template<class G> std::ostream& operator<<(std::ostream& ostr, const oln::regular_window<G>& win) { - unsigned c = win.card(); ostr << "["; - for (unsigned i = 0; i < c; ++i) + for (unsigned i = 0; i < win.card(); ++i) ostr << win.dp(i); ostr << "]"; return ostr; } -# include <oln/core/gen/regular_fwd_qiter.hh> - - -#endif // OLENA_CORE_GEN_REGULAR_WINDOW_HH +#endif // ! OLENA_CORE_GEN_REGULAR_WINDOW_HH Index: oln/core/gen/regular_neighborhood.hh =================================================================== --- oln/core/gen/regular_neighborhood.hh (revision 0) +++ oln/core/gen/regular_neighborhood.hh (revision 0) @@ -0,0 +1,144 @@ +// 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 OLENA_CORE_GEN_REGULAR_NEIGHBORHOOD_HH +# define OLENA_CORE_GEN_REGULAR_NEIGHBORHOOD_HH + +# include <oln/core/abstract/neighborhood.hh> +# include <oln/core/gen/regular_window.hh> + + +namespace oln { + + // fwd decl + template <typename G> class regular_neighborhood; + + // super_type + template <typename G> struct set_super_type< regular_neighborhood<G> > { typedef abstract::neighborhood< regular_neighborhood<G> > ret; }; + + // props + template <typename G> + struct set_props< category::neighborhood, regular_neighborhood<G> > + { + typedef oln_grd_type_of(G, dpoint) dpoint_type; + typedef oln_grd_type_of(G, size) size_type; + typedef regular_window<G> window_type; + }; + + + + template <typename G> + class regular_neighborhood : public abstract::neighborhood< regular_neighborhood<G> > + { + + public: + + typedef regular_neighborhood<G> self_type; + + typedef oln_grd_type_of(G, coord) coord_type; + typedef oln_grd_type_of(G, dpoint) dpoint_type; + typedef oln_grd_type_of(G, dimvalue) dimvalue_type; + + static const unsigned dim = dimvalue_type::val; + + regular_neighborhood() + { + } + + regular_neighborhood(const regular_window<G>& win) + { + for (unsigned i = 0; i < win.card(); ++i) + this->add(win.dp(i)); + } + + regular_neighborhood(unsigned n, const coord_type crd[]) + { + precondition(n != 0); + // FIXME: size of crd wrt n + for (unsigned i = 0; i < n; ++i) + { + dpoint_type dp; + for (unsigned c = 0; c < dim; ++c) + dp.nth(c) = crd[i * dim + c]; + this->add(dp); + } + } + + self_type& add(const dpoint_type& dp) + { + precondition(dp != -dp); // means dp is not (0) + this->win_.add(dp); + this->win_.add(-dp); + return *this; + } + + coord_type delta() const + { + return this->win_.delta(); + } + + unsigned card() const + { + return this->win_.card(); + } + + const dpoint_type dp(unsigned i) const + { + precondition(i < this->card()); + return this->win_.dp(i); + } + + const std::vector<dpoint_type>& get_dp() const + { + return this->win_.get_dp(); + } + + const regular_neighborhood<G>& get_win() const + { + return this->win_; + } + + private: + + /// Only attribute (to delegate to). + regular_window<G> win_; + + }; + + +} // end of namespace oln + + + +template<class G> +std::ostream& operator<<(std::ostream& ostr, const oln::regular_neighborhood<G>& nbh) +{ + return ostr << nbh.get_win(); +} + + +#endif // OLENA_CORE_GEN_REGULAR_NEIGHBORHOOD_HH Index: oln/basics3d.hh =================================================================== --- oln/basics3d.hh (revision 144) +++ oln/basics3d.hh (working copy) @@ -33,7 +33,8 @@ # include <oln/core/3d/grid3d.hh> # include <oln/core/3d/size3d.hh> # include <oln/core/3d/point3d.hh> -# include <oln/core/3d/dpoint3d.hh> # include <oln/core/3d/image3d.hh> +# include <oln/core/3d/window3d.hh> +# include <oln/core/3d/neighborhood3d.hh> #endif // ! OLENA_BASICS3D_HH Index: oln/makefile.src =================================================================== --- oln/makefile.src (revision 144) +++ oln/makefile.src (working copy) @@ -22,28 +22,39 @@ convert/value_to_point.hh \ \ core/1d/array1d.hh \ + core/1d/bkd_piter1d.hh \ core/1d/dpoint1d.hh \ core/1d/fwd_piter1d.hh \ core/1d/image1d.hh \ + core/1d/neighborhood1d.hh \ + core/1d/niter1d.hh \ core/1d/point1d.hh \ + core/1d/qiter1d.hh \ core/1d/size1d.hh \ \ core/2d/array2d.hh \ core/2d/bkd_piter2d.hh \ core/2d/dpoint2d.hh \ - core/2d/fwd_niter2d.hh \ core/2d/fwd_piter2d.hh \ core/2d/image2d.hh \ core/2d/neighborhood2d.hh \ + core/2d/niter2d.hh \ core/2d/point2d.hh \ + core/2d/qiter2d.hh \ core/2d/size2d.hh \ core/2d/window2d.hh \ \ core/3d/array3d.hh \ + core/3d/bkd_piter3d.hh \ core/3d/dpoint3d.hh \ + core/3d/fwd_niter3d.hh \ core/3d/fwd_piter3d.hh \ + core/3d/fwd_qiter3d.hh \ core/3d/image3d.hh \ + core/3d/neighborhood3d.hh \ + core/3d/niter3d.hh \ core/3d/point3d.hh \ + core/3d/qiter3d.hh \ core/3d/size3d.hh \ \ core/abstract/data_storage.hh \ @@ -90,9 +101,13 @@ core/gen/identity.hh \ core/gen/image_with_nbh.hh \ core/gen/internal/value_box.hh \ - core/gen/regular_fwd_niter.hh.hh \ - core/gen/regular_fwd_qiter.hh.hh \ - core/gen/regular_niter.hh.hh \ + core/gen/regular_bkd_niter.hh \ + core/gen/regular_bkd_qiter.hh \ + core/gen/regular_fwd_niter.hh \ + core/gen/regular_fwd_qiter.hh \ + core/gen/regular_neighborhood.hh \ + core/gen/regular_niter.hh \ + core/gen/regular_qiter.hh \ core/gen/regular_window.hh \ \ core/pw/abstract/binary_function.hh \ Index: oln/morpho/cc_tarjan.hh =================================================================== --- oln/morpho/cc_tarjan.hh (revision 144) +++ oln/morpho/cc_tarjan.hh (working copy) @@ -156,7 +156,7 @@ { std::vector<dpoint2d> neighb = misc::get_inferior(this->ng); oln_type_of(I, bkd_piter) p(this->input.size()); - for_all(p) + for_all_p (p) if (this->input[p]) { make_set(p); @@ -174,7 +174,7 @@ oln_type_of(I, fwd_piter) p(this->input.size()); level::fill(this->output, 0); ncomps = 0; - for_all(p) + for_all_p (p) if (this->input[p]) { oln_type_of(I, point) q = parent[p]; Index: oln/morpho/stat.hh =================================================================== --- oln/morpho/stat.hh (revision 144) +++ oln/morpho/stat.hh (working copy) @@ -30,7 +30,8 @@ # include <mlc/cmp.hh> # include <ntg/bin.hh> -# include <oln/basics.hh> +# include <oln/core/abstract/image.hh> +# include <oln/core/abstract/window.hh> namespace oln { @@ -63,18 +64,19 @@ ** \arg win The window to use. */ static V - max(const I& input, const oln_type_of(I, point)& p, const W& win) + max(const abstract::image<I>& input, + const oln_type_of(I, point)& p, + const abstract::window<W>& win) { - // FIXME: test dim I == dim - mlc::eq<oln_type_of(I, size), oln_wn_type_of(W, size)>::ensure(); + mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); - oln_wn_type_of(W, fwd_qiter) dp(win); - dp.start(); - V val = input[p + dp]; - for_all_remaining (dp) - if (input.hold(p + dp)) - if (val < input[p + dp].value()) - val = input[p + dp].value(); + oln_wn_type_of(W, fwd_iter) q(win); + q.start_at_p(p); + V val = input[q]; + for_all_remaining_q (q) + if (input.hold(q)) + if (val < input[q].value()) + val = input[q].value(); return val; } @@ -89,18 +91,19 @@ ** \arg win The window to use. */ static V - min(const I& input, const oln_type_of(I, point)& p, const W& win) + min(const abstract::image<I>& input, + const oln_type_of(I, point)& p, + const abstract::window<W>& win) { - // FIXME: test dim I == dim W - mlc::eq<oln_type_of(I, size), oln_wn_type_of(W, size)>::ensure(); + mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); - oln_wn_type_of(W, fwd_qiter) dp(win); - dp.start(); - V val = input[p + dp]; - for_all_remaining (dp) - if (input.hold(p + dp)) - if (val > input[p + dp].value()) - val = input[p + dp].value(); + oln_wn_type_of(W, fwd_iter) q(win); + q.start_at(p); + V val = input[q]; + for_all_remaining (q) + if (input.hold(q)) + if (val > input[q].value()) + val = input[q].value(); return val; } @@ -112,25 +115,29 @@ struct stat_<I, W, ntg::bin> { static ntg::bin - max(const I& input, const oln_type_of(I, point)& p, const W& win) + max(const abstract::image<I>& input, + const oln_type_of(I, point)& p, + const abstract::window<W>& win) { - mlc::eq<oln_type_of(I, size), oln_wn_type_of(W, size)>::ensure(); - oln_wn_type_of(W, fwd_qiter) dp(win); - for_all (dp) - if (input.hold(p + dp)) - if (input[p + dp] == true) + mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); + oln_wn_type_of(W, fwd_iter) q(win); + for_all_q_of_p (q, p) + if (input.hold(q)) + if (input[q] == true) return true; return false; } static ntg::bin - min(const I& input, const oln_type_of(I, point)& p, const W& win) + min(const abstract::image<I>& input, + const oln_type_of(I, point)& p, + const abstract::window<W>& win) { - mlc::eq<oln_type_of(I, size), oln_wn_type_of(W, size)>::ensure(); - oln_wn_type_of(W, fwd_qiter) dp(win); - for_all (dp) - if (input.hold(p + dp)) - if (input[p + dp] == false) + mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure(); + oln_wn_type_of(W, fwd_iter) q(win); + for_all_q_of_p (q, p) + if (input.hold(q)) + if (input[q] == false) return false; return true; } Index: oln/morpho/geodesic_erosion.hh =================================================================== --- oln/morpho/geodesic_erosion.hh (revision 0) +++ oln/morpho/geodesic_erosion.hh (revision 0) @@ -0,0 +1,132 @@ +// Copyright (C) 2001, 2002, 2003, 2004, 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 OLENA_MORPHO_GEODESIC_EROSION_HH +# define OLENA_MORPHO_GEODESIC_EROSION_HH + +# include <mlc/cmp.hh> + +# include <oln/core/abstract/image_operator.hh> +# include <oln/morpho/stat.hh> +# include <oln/level/compare.hh> +# include <oln/convert/nbh_to_se.hh> +# include <oln/arith/max.hh> + +# include <oln/core/abstract/neighborhood.hh> +# include <oln/morpho/erosion.hh> + +namespace oln { + + namespace morpho { + + // fwd declaration + template <class I1, class I2> struct geodesic_erosion_ret; + + namespace proc { + + template<class I1, class I2> + oln_type_of(I1, concrete) + geodesic_erosion(const abstract::image_with_nbh<I1>& marker, + const abstract::image<I2>& mask) + { + mlc::eq<oln_type_of(I1, grid), oln_type_of(I2, grid)>::ensure(); + precondition(marker.size() == mask.size()); + precondition(level::is_greater_or_equal(marker, mask)); + oln_type_of(I1, concrete) output(marker.size()); + marker.border_adapt_copy(marker.nbh_get().delta()); + oln_type_of(I1, piter) p(marker); + for_all_p (p) + output[p] = arith::max(morpho::min(marker, p, convert::nbh_to_cse(marker.nbh_get())), + mask[p]); + return output; + } + + } // end of namespace oln::morpho::proc + + } // end of namespace oln::morpho + + + // super_type + template <class I1, class I2> + struct set_super_type< morpho::geodesic_erosion_ret<I1, I2> > + { + typedef abstract::image_binary_operator<oln_type_of(I1, concrete), I1, I2, morpho::geodesic_erosion_ret<I1, I2> > ret; + }; + + + namespace morpho { + + template <class I1, class I2> + struct geodesic_erosion_ret : public abstract::image_binary_operator<oln_type_of(I1, concrete), I1, I2, morpho::geodesic_erosion_ret<I1, I2> > + { + typedef abstract::image_binary_operator<oln_type_of(I1, concrete), I1, I2, geodesic_erosion_ret<I1, I2> > super_type; + + geodesic_erosion_ret(const abstract::image_with_nbh<I1>& marker, + const abstract::image<I2>& mask) : + super_type(marker, mask) + {} + }; + + + namespace safe { + + template <class I1, class I2> + struct geodesic_erosion : public geodesic_erosion_ret<I1, I2> + { + typedef geodesic_erosion_ret<I1, I2> super_type; + + geodesic_erosion(const abstract::image_with_nbh<I1>& marker, + const abstract::image<I2>& mask) : + super_type(marker, mask) + {} + + void impl_run() + { + mlc::eq<oln_type_of(I1, grid), oln_type_of(I2, grid)>::ensure(); + precondition((this->input1).size() == (this->input2).size()); + precondition(level::is_greater_or_equal(this->input2, this->input1)); + this->output = arith::max(erosion(this->input1.unbox(), this->input1.unbox().nbh_get()).output.unbox(), this->input2.unbox()).output; + } + }; + + } // end of namespace oln::morpho::safe + + template<class I1, class I2> + geodesic_erosion_ret<I1, I2> + geodesic_erosion(const abstract::image_with_nbh<I1>& marker, + const abstract::image<I2>& mask) + { + safe::geodesic_erosion<I1, I2> tmp(marker, mask); + tmp.run(); + return tmp; + } + + } // end of namespace oln::morpho + +} // end of namespace oln + +#endif // OLENA_MORPHO_GEODESIC_EROSION_HH
participants (1)
-
Thierry GERAUD