619: New facilities related to windows and q-iterators.

2006-10-11 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr> New facilities related to windows and q-iterators. * tests/window2d.cc: New. * tests/Makefile.am (window2d_SOURCES): New. * oln/debug/print.hh (format): New. (print): Update; use format to correctly print 'unsigned char'. * oln/level/fill.hh: Separate header and implementation. (fill): Use shortcut. * oln/core/typedefs.hh: New shortcuts oln_something(T) for oln_type_of(T, something). * oln/core/fwd_piter.hh (fwd_qiter_type): New. * oln/core/abstract/window.hh: New. * oln/core/2d/aliases.hh (window2d, fwd_qiter2d): New. * oln/core/gen/fwd_qiter_win.hh (include): Add abstract::window.hh. (fwd_qiter_win_): Update ctor signature. * oln/core/gen/window.hh (grid_type): New. (window_): Add inheritance from abstract::window. (impl_is_valid): New. (include): Update. * oln/basics2d.hh (include): Add window.hh and fwd_qiter_win.hh. * oln/Makefile.am (nobase_oln_HEADERS): Update. Index: tests/window2d.cc =================================================================== --- tests/window2d.cc (revision 0) +++ tests/window2d.cc (revision 0) @@ -0,0 +1,41 @@ +#include <oln/basics2d.hh> +#include <oln/debug/print.hh> +#include <oln/io/pnm.hh> +#include <oln/morpher/add_neighborhood.hh> + + +namespace test +{ + + template <typename I, typename W> + void run(const oln::abstract::image<I>& ima, + const oln::abstract::window<W>& win) + { + oln_piter(I) p(ima.topo()); + oln_qiter(I) q(p, win); + for_all(p) + { + std::cout << unsigned(ima(p)) << ": "; + for_all(q) + std::cout << unsigned(ima(q)) << " "; + std::cout << std::endl; + } + } + +} + + +int main() +{ + using namespace oln; + + image2d<unsigned char> ima = io::load_pgm("../img/lena32.pgm"); + debug::println(ima); + + window2d win; + win + .add(dpoint2d(-1, 0)) + .add(dpoint2d(-2, 0)); + + test::run(ima, win); +} Index: tests/Makefile.am =================================================================== --- tests/Makefile.am (revision 618) +++ tests/Makefile.am (working copy) @@ -26,6 +26,7 @@ image2d \ image3d \ npoints \ + window2d \ \ identity_morpher \ add_neighborhood_morpher \ @@ -43,6 +44,7 @@ image2d_SOURCES = image2d.cc image3d_SOURCES = image3d.cc npoints_SOURCES = npoints.cc +window2d_SOURCES = window2d.cc # Morphers. identity_morpher_SOURCES = identity_morpher.cc Index: oln/debug/print.hh =================================================================== --- oln/debug/print.hh (revision 618) +++ oln/debug/print.hh (working copy) @@ -44,24 +44,36 @@ /// Fwd decl. template <typename I> - void print(const abstract::image<I>& input, std::ostream& ostr); + void print(const abstract::image<I>& input, std::ostream& ostr = std::cout); /// Fwd decl. template <typename I> - void println(const abstract::image<I>& input, std::ostream& ostr); + void println(const abstract::image<I>& input, std::ostream& ostr = std::cout); # ifndef OLN_INCLUDE_ONLY namespace impl { + template <typename T> + const T& format(const T& value) + { + return value; + } + + unsigned format(const unsigned char& value) + { + return value; + } + + /// Generic version. template <typename I> void print(const abstract::image<I>& input, std::ostream& ostr) { oln_type_of(I, fwd_piter) p(input.topo()); for_all(p) - ostr << p.to_point() << ':' << ima(p) << ' '; + ostr << p.to_point() << ':' << format(input(p)) << ' '; } @@ -76,7 +88,7 @@ { point2d p(row, col); if (input.has(p)) - ostr << input(p); + ostr << format(input(p)); else ostr << '-'; ostr << ' '; Index: oln/level/fill.hh =================================================================== --- oln/level/fill.hh (revision 618) +++ oln/level/fill.hh (working copy) @@ -53,6 +53,8 @@ void fill(abstract::image<I>& input, const oln_type_of(I, value)& val); +# ifndef OLN_INCLUDE_ONLY + namespace impl { @@ -71,7 +73,7 @@ /// Facade. template <typename I> - void fill(abstract::image<I>& input, const oln_type_of(I, value)& val) + void fill(abstract::image<I>& input, const oln_value(I)& val) { // Precondition. mlc::assert_< @@ -82,6 +84,8 @@ impl::fill(input.exact(), val); } +# endif + } // end of namespace oln::level } // end of namespace oln Index: oln/core/typedefs.hh =================================================================== --- oln/core/typedefs.hh (revision 618) +++ oln/core/typedefs.hh (working copy) @@ -200,6 +200,63 @@ } // end of namespace oln + +/// \{ +/// Shortcuts formed such as "oln_something(T) means oln_type_of(T, something)". + +# define oln_coord(T) oln_type_of(T, coord) +# define oln_coord_(T) oln_type_of_(T, coord) + +# define oln_grid(T) oln_type_of(T, grid) +# define oln_grid_(T) oln_type_of_(T, grid) + +# define oln_point(T) oln_type_of(T, point) +# define oln_point_(T) oln_type_of_(T, point) + +# define oln_dpoint(T) oln_type_of(T, dpoint) +# define oln_dpoint_(T) oln_type_of_(T, dpoint) + +# define oln_value(T) oln_type_of(T, value) +# define oln_value_(T) oln_type_of_(T, value) + +# define oln_rvalue(T) oln_type_of(T, rvalue) +# define oln_rvalue_(T) oln_type_of_(T, rvalue) + +# define oln_lvalue(T) oln_type_of(T, lvalue) +# define oln_lvalue_(T) oln_type_of_(T, lvalue) + +# define oln_fwd_piter(T) oln_type_of(T, fwd_piter) +# define oln_fwd_piter_(T) oln_type_of_(T, fwd_piter) + +# define oln_bkd_piter(T) oln_type_of(T, bkd_piter) +# define oln_bkd_piter_(T) oln_type_of_(T, bkd_piter) + +# define oln_fwd_qiter(T) oln_type_of(T, fwd_qiter) +# define oln_fwd_qiter_(T) oln_type_of_(T, fwd_qiter) + +# define oln_bkd_qiter(T) oln_type_of(T, bkd_qiter) +# define oln_bkd_qiter_(T) oln_type_of_(T, bkd_qiter) + +# define oln_fwd_niter(T) oln_type_of(T, fwd_niter) +# define oln_fwd_niter_(T) oln_type_of_(T, fwd_niter) + +# define oln_bkd_niter(T) oln_type_of(T, bkd_niter) +# define oln_bkd_niter_(T) oln_type_of_(T, bkd_niter) + +# define oln_piter(T) oln_type_of(T, fwd_piter) +# define oln_piter_(T) oln_type_of_(T, fwd_piter) + +# define oln_qiter(T) oln_type_of(T, fwd_qiter) +# define oln_qiter_(T) oln_type_of_(T, fwd_qiter) + +# define oln_niter(T) oln_type_of(T, fwd_niter) +# define oln_niter_(T) oln_type_of_(T, fwd_niter) + +/// \} + + + + # include <oln/core/abstract/entry.hh> Index: oln/core/fwd_piter.hh =================================================================== --- oln/core/fwd_piter.hh (revision 618) +++ oln/core/fwd_piter.hh (working copy) @@ -127,7 +127,13 @@ typedef bkd_piter2d ret; }; + template <typename T> + struct single_vtype< image2d<T>, typedef_::fwd_qiter_type > + { + typedef fwd_qiter2d ret; + }; + } // end of namespace oln Index: oln/core/abstract/window.hh =================================================================== --- oln/core/abstract/window.hh (revision 0) +++ oln/core/abstract/window.hh (revision 0) @@ -0,0 +1,98 @@ +// Copyright (C) 2006 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 OLN_CORE_ABSTRACT_WINDOW_HH +# define OLN_CORE_ABSTRACT_WINDOW_HH + +# include <oln/core/typedefs.hh> + + +namespace oln +{ + + namespace abstract + { + + + /// Abstract window class. + template <typename E> + class window : public virtual stc::any__simple<E>, + public virtual oln::type + { + public: + + bool is_valid() const; + + struct decl + { + oln_virtual_typedef(grid); + + decl(); + }; + + protected: + + window(); + ~window(); + + }; // end of class oln::abstract::window<E> + + + +# ifndef OLN_INCLUDE_ONLY + + template <typename E> + bool window<E>::is_valid() const + { + return this->exact().impl_is_valid(); + } + + template <typename E> + window<E>::window() + { + } + + template <typename E> + window<E>::~window() + { + decl(); + } + + template <typename E> + window<E>::decl::decl() + { + } + +# endif + + + } // end of namespace oln::abstract + +} // end of namespace oln + + +#endif // ! OLN_CORE_ABSTRACT_WINDOW_HH Index: oln/core/2d/aliases.hh =================================================================== --- oln/core/2d/aliases.hh (revision 618) +++ oln/core/2d/aliases.hh (working copy) @@ -38,10 +38,12 @@ template <typename C> class point2d_; template <typename C> class dpoint2d_; template <typename D> class neighb_; + template <typename D> class window_; template <typename P> class bbox_; template <typename P> class topo_lbbox_; template <typename P> class fwd_piter_bbox_; template <typename P> class bkd_piter_bbox_; + template <typename P> class fwd_qiter_win_; class grid2d; /// \} @@ -52,12 +54,16 @@ typedef dpoint2d_<int> dpoint2d; typedef neighb_<dpoint2d> neighb2d; + typedef window_<dpoint2d> window2d; typedef bbox_<point2d> bbox2d; typedef topo_lbbox_<point2d> topo2d; + typedef fwd_piter_bbox_<point2d> fwd_piter2d; typedef bkd_piter_bbox_<point2d> bkd_piter2d; + typedef fwd_qiter_win_<point2d> fwd_qiter2d; + typedef point2d_<float> point2df; typedef dpoint2d_<float> dpoint2df; /// \} Index: oln/core/gen/fwd_qiter_win.hh =================================================================== --- oln/core/gen/fwd_qiter_win.hh (revision 618) +++ oln/core/gen/fwd_qiter_win.hh (working copy) @@ -29,6 +29,7 @@ # define OLN_CORE_GEN_FWD_QITER_WIN_HH # include <oln/core/abstract/iterator_on_points.hh> +# include <oln/core/abstract/window.hh> # include <oln/core/gen/window.hh> @@ -70,12 +71,13 @@ public: - template <typename P, typename D> + template <typename P, typename W> fwd_qiter_win_(const abstract::iterator_on_points<P>& it, - const window_<D>& win); - template <typename P, typename D> + const abstract::window<W>& win); + + template <typename P, typename W> fwd_qiter_win_(const abstract::point<P>& p, - const window_<D>& win); + const abstract::window<W>& win); void impl_start(); @@ -103,22 +105,22 @@ # ifndef OLN_INCLUDE_ONLY template <typename point_t> - template <typename P, typename D> + template <typename P, typename W> fwd_qiter_win_<point_t>::fwd_qiter_win_(const abstract::iterator_on_points<P>& it, - const window_<D>& win) + const abstract::window<W>& win) : p_ref_(it.point_adr()), - win_(win) + win_(win.exact()) { precondition(win_.card() > 0); i_ = -1; } template <typename point_t> - template <typename P, typename D> + template <typename P, typename W> fwd_qiter_win_<point_t>::fwd_qiter_win_(const abstract::point<P>& p, - const window_<D>& win) + const abstract::window<W>& win) : p_ref_(&(p.exact())), - win_(win) + win_(win.exact()) { precondition(win_.card() > 0); i_ = -1; Index: oln/core/gen/window.hh =================================================================== --- oln/core/gen/window.hh (revision 618) +++ oln/core/gen/window.hh (working copy) @@ -33,14 +33,27 @@ # include <vector> # include <mlc/assert.hh> # include <oln/core/abstract/dpoint.hh> +# include <oln/core/abstract/window.hh> namespace oln { + // Fwd decl. + template <typename dpoint> class window_; + + + template <typename dpoint> + struct vtypes< window_<dpoint> > + { + typedef oln_type_of(dpoint, grid) grid_type; + }; + + /// Abstract forward dpoint iterator class. template <typename dpoint> - class window_ : private mlc::assert_< mlc_is_a(dpoint, abstract::dpoint) > + class window_ : public abstract::window< window_<dpoint> >, + private mlc::assert_< mlc_is_a(dpoint, abstract::dpoint) > { typedef window_<dpoint> self_t; @@ -51,11 +64,13 @@ window_<dpoint>& add(const dpoint& dp); template <typename D> - window_<dpoint>& add(const abstract::dpoint<D>& dp); + window_<dpoint>& add(const abstract::dpoint<D>& dp); + dpoint dp(unsigned i) const; + unsigned card() const; - dpoint dp(unsigned i) const; + bool impl_is_valid() const; protected: @@ -107,6 +122,13 @@ } template <typename dpoint> + bool + window_<dpoint>::impl_is_valid() const + { + return v_.size() != 0; + } + + template <typename dpoint> void window_<dpoint>::update_() { Index: oln/basics2d.hh =================================================================== --- oln/basics2d.hh (revision 618) +++ oln/basics2d.hh (working copy) @@ -44,6 +44,9 @@ # include <oln/core/gen/fwd_piter_bbox.hh> # include <oln/core/gen/bkd_piter_bbox.hh> +# include <oln/core/gen/window.hh> +# include <oln/core/gen/fwd_qiter_win.hh> + # include <oln/core/gen/neighb.hh> # include <oln/core/2d/neighb2d.hh> Index: oln/Makefile.am =================================================================== --- oln/Makefile.am (revision 618) +++ oln/Makefile.am (working copy) @@ -85,6 +85,7 @@ core/abstract/point_set.hh \ core/abstract/topology.hh \ core/abstract/value.hh \ + core/abstract/window.hh \ \ core/automatic/image.hh \ core/automatic/image_being_mutable.hh \
participants (1)
-
Thierry GERAUD