r955: Add weighted window equipment and convolution.

https://svn.lrde.epita.fr/svn/oln/trunk/olena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Add weighted window equipment and convolution. * oln/core/2d/weighted_window2d.hh, * oln/core/gen/weighted_window.hh, * oln/core/concept/weighted_window.hh, * oln/core/internal/weighted_window.hh, * oln/core/internal/f_weighted_window.hh, * oln/core/internal/weighted_window_base.hh, * oln/core/internal/weighted_dpoints_impl.hh: New. * oln/linear: New directory. * oln/linear/convolution.hh, * oln/linear/lap_4.hh: New. * doc/tour/tour3.cc: Activate code. * oln/debug/fill.hh (n): New parameter. * oln/core/2d/image2d.hh (image2d): New ctor overload. * oln/core/equipment.hh (weight): New vtype. * oln/core/concept/image.hh: Add commentary. * oln/core/internal/window_base.hh (category): New. doc/tour/tour3.cc | 4 oln/core/2d/image2d.hh | 11 + oln/core/2d/weighted_window2d.hh | 115 +++++++++++++++++ oln/core/concept/image.hh | 2 oln/core/concept/weighted_window.hh | 71 ++++++++++ oln/core/equipment.hh | 3 oln/core/gen/weighted_window.hh | 86 ++++++++++++ oln/core/internal/f_weighted_window.hh | 99 ++++++++++++++ oln/core/internal/weighted_dpoints_impl.hh | 193 +++++++++++++++++++++++++++++ oln/core/internal/weighted_window.hh | 131 +++++++++++++++++++ oln/core/internal/weighted_window_base.hh | 104 +++++++++++++++ oln/core/internal/window_base.hh | 5 oln/debug/fill.hh | 17 +- oln/linear/convolution.hh | 154 +++++++++++++++++++++++ oln/linear/lap_4.hh | 82 ++++++++++++ 15 files changed, 1064 insertions(+), 13 deletions(-) Index: doc/tour/tour3.cc --- doc/tour/tour3.cc (revision 954) +++ doc/tour/tour3.cc (working copy) @@ -97,7 +97,7 @@ // 3 4 5 // 6 7 8 - /* HERE + // The algorithm defined at the end of this file is very close to // the one of the tour former file. The major difference is that it @@ -251,7 +251,7 @@ // 8: 4 7 0 - */ + // Last, the way a predicate is defined can also rely on some image // values. For that the user can on the fly provide an expression Index: oln/debug/fill.hh --- oln/debug/fill.hh (revision 954) +++ oln/debug/fill.hh (working copy) @@ -38,8 +38,8 @@ namespace debug { - template <typename I, typename V> - void fill(inplace_<I> in_out, const V values[]); + template <typename I, typename V, unsigned n> + void fill(inplace_<I> in_out, const V (&values)[n]); # ifndef OLN_INCLUDE_ONLY @@ -47,8 +47,8 @@ namespace impl { - template <typename I, typename V> - void fill_(Mutable_Image<I>& in_out, const V values[]) + template <typename I, typename V, unsigned n> + void fill_(Mutable_Image<I>& in_out, const V (&values)[n]) { unsigned i = 0; oln_piter(I) p(in_out.points()); @@ -58,16 +58,17 @@ } // end of namespace oln::impl - template <typename I, typename V> - void fill(inplace_<I> in_out, const V values[]) + template <typename I, typename V, unsigned n> + void fill(inplace_<I> in_out, const V (&values)[n]) { + // FIXME: Uncomment: precondition(n == in_out.points().npoints()); impl::fill_(in_out.unwrap(), values); } // Guard. - template <typename I, typename V> - void fill(const Image<I>&, const V[]) + template <typename I, typename V, unsigned n> + void fill(const Image<I>&, const V (&) [n]) { mlc::abort_<I>::check(); // FIXME: Add err msg. } Index: oln/core/2d/image2d.hh --- oln/core/2d/image2d.hh (revision 954) +++ oln/core/2d/image2d.hh (working copy) @@ -86,6 +86,7 @@ image2d(); image2d(const box2d& b); image2d(unsigned nrows, unsigned ncols); + image2d(int min_row, int min_col, int max_row, int max_col); bool impl_owns_(const point2d& p) const; @@ -129,6 +130,16 @@ } template <typename T> + image2d<T>::image2d(int min_row, int min_col, int max_row, int max_col) + { + precondition(max_row >= min_row and max_col >= min_col); + this->data_ = new data(new array_t(min_row, min_col, + max_row, max_col), + box2d(point2d(min_row, min_col), + point2d(max_row, max_col))); + } + + template <typename T> image2d<T>::image2d(unsigned nrows, unsigned ncols) { precondition(nrows != 0 and ncols != 0); Index: oln/core/2d/weighted_window2d.hh --- oln/core/2d/weighted_window2d.hh (revision 0) +++ oln/core/2d/weighted_window2d.hh (revision 0) @@ -0,0 +1,115 @@ +// Copyright (C) 2006, 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLN_CORE_2D_WEIGHTED_WINDOW2D_HH +# define OLN_CORE_2D_WEIGHTED_WINDOW2D_HH + +# include <cmath> +# include <oln/core/internal/weighted_window.hh> +# include <oln/core/2d/dpoint2d.hh> + + + +namespace oln +{ + + + // Fwd decl. + template <typename W> class weighted_window2d; + + +# define current weighted_window2d<W> +# define super internal::weighted_window_< current > + + + // Super type. + template <typename W> + struct super_trait_< current > + { + typedef super ret; + }; + + + // Virtual types. + template <typename W> + struct vtypes< current > + { + typedef W weight; + typedef point2d point; + }; + + + /// Generic classical weighted_window2d class. + + template <typename W> + class weighted_window2d : public super + { + public: + stc_using(weight); + + weighted_window2d(); + + template <unsigned n> + void impl_fill_with(const weight (&values)[n]); + + }; // end of class oln::weighted_window2d<W> + + + +# ifndef OLN_INCLUDE_ONLY + + template <typename W> + weighted_window2d<W>::weighted_window2d() + { + } + + template <typename W> + template <unsigned n> + void + weighted_window2d<W>::impl_fill_with(const weight (&values)[n]) + { + int h = int(std::sqrt(n)) / 2; + precondition((2 * h + 1) * (2 * h + 1) == n); + unsigned i = 0; + for (int drow = -h; drow <= h; ++drow) + for (int dcol = -h; dcol <= h; ++dcol) + { + if (values[i] != 0) + this->take(values[i], dpoint2d(drow, dcol)); + ++i; + } + } + +# endif // ! OLN_INCLUDE_ONLY + +# undef super +# undef current + +} // end of namespace oln + + +#endif // ! OLN_CORE_2D_WEIGHTED_WINDOW2D_HH Index: oln/core/equipment.hh --- oln/core/equipment.hh (revision 954) +++ oln/core/equipment.hh (working copy) @@ -157,6 +157,9 @@ # define oln_value(T) oln_typename_shortcut__(T, value) + // w + stc_decl_associated_type( weight ); + } // end of namespace oln Index: oln/core/gen/weighted_window.hh --- oln/core/gen/weighted_window.hh (revision 0) +++ oln/core/gen/weighted_window.hh (revision 0) @@ -0,0 +1,86 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLN_CORE_GEN_WEIGHTED_WINDOW_HH +# define OLN_CORE_GEN_WEIGHTED_WINDOW_HH + +# include <oln/core/internal/weighted_window.hh> + + +namespace oln +{ + + + // Fwd decl. + template <typename W, typename Dp> class weighted_window; + + + // Super type. + template <typename W, typename Dp> + struct super_trait_< weighted_window<W,Dp> > + { + typedef weighted_window<W,Dp> current__; + typedef internal::weighted_window_<current__> ret; + }; + + + // Virtual types. + template <typename W, typename Dp> + struct vtypes< weighted_window<W,Dp> > + { + typedef W weight; + typedef oln_point(Dp) point; + }; + + + /// Generic classical weighted_window class. + + template <typename W, typename Dp> + class weighted_window : public internal::weighted_window_< weighted_window<W,Dp> > + { + public: + + weighted_window(); + + }; // end of class oln::weighted_window<W,Dp> + + + +# ifndef OLN_INCLUDE_ONLY + + template <typename W, typename Dp> + weighted_window<W,Dp>::weighted_window() + { + } + +# endif // ! OLN_INCLUDE_ONLY + + +} // end of namespace oln + + +#endif // ! OLN_CORE_GEN_WEIGHTED_WINDOW_HH Index: oln/core/concept/image.hh --- oln/core/concept/image.hh (revision 954) +++ oln/core/concept/image.hh (working copy) @@ -127,7 +127,7 @@ stc_typename(box); stc_typename(pset); - stc_typename(dpoint); + stc_typename(dpoint); // FIXME: Move into Point_Wise_Accessible_Image // stc_typename(output); // FIXME: Uncomment! stc_typename(plain); Index: oln/core/concept/weighted_window.hh --- oln/core/concept/weighted_window.hh (revision 0) +++ oln/core/concept/weighted_window.hh (revision 0) @@ -0,0 +1,71 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLN_CORE_CONCEPT_WEIGHTED_WINDOW_HH +# define OLN_CORE_CONCEPT_WEIGHTED_WINDOW_HH + +# include <oln/core/equipment.hh> + + +namespace oln +{ + + /// Concept-class "Weighted_Window". + + template <typename Exact> + struct Weighted_Window : public Any<Exact> + { + +// stc_typename(grid); +// stc_typename(point); + + stc_typename(weight); + +// stc_typename(qiter); +// stc_typename(fwd_qiter); +// stc_typename(bkd_qiter); + + protected: + Weighted_Window(); + + }; // end of oln::Weighted_Window<Exact> + + + +# ifndef OLN_INCLUDE_ONLY + + template <typename Exact> + Weighted_Window<Exact>::Weighted_Window() + { + } + +# endif // ! OLN_INCLUDE_ONLY + +} // end of namespace oln + + +#endif // ! OLN_CORE_CONCEPT_WEIGHTED_WINDOW_HH Index: oln/core/internal/weighted_window.hh --- oln/core/internal/weighted_window.hh (revision 0) +++ oln/core/internal/weighted_window.hh (revision 0) @@ -0,0 +1,131 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLN_CORE_INTERNAL_WEIGHTED_WINDOW_HH +# define OLN_CORE_INTERNAL_WEIGHTED_WINDOW_HH + +# include <oln/core/internal/weighted_window_base.hh> +# include <oln/core/internal/weighted_dpoints_impl.hh> +// # include <oln/core/gen/dpoints_piter.hh> + + +namespace oln +{ + + + // Fwd decl. + namespace internal { template <typename Exact> class weighted_window_; } + + + // Super type. + template <typename Exact> + struct super_trait_< internal::weighted_window_<Exact> > + { + typedef internal::weighted_window_base_<Exact> ret; + }; + + + // Virtual types. + template <typename Exact> + struct vtypes< internal::weighted_window_<Exact> > + { + typedef stc_deferred(point) point__; + typedef stc::final< oln_dpoint(point__) > dpoint; +// typedef stc::final< dpoints_fwd_piter_<point__> > fwd_qiter; +// typedef stc::final< dpoints_bkd_piter_<point__> > bkd_qiter; + }; + + namespace internal + { + + /// Base implementation class for regular weighted_window classes. + + template <typename Exact> + class weighted_window_ : public weighted_window_base_<Exact>, + public weighted_dpoints_impl_< stc_deferred(weight), + stc_deferred(dpoint) > + { + typedef weighted_window_base_<Exact> super; + public: + + stc_using(weight); + stc_using(point); + typedef oln_dpoint(point) dpoint; + + Exact& take(const weight& w, const dpoint& dp); + Exact& impl_take(const weight& w, const dpoint& dp); + + template <unsigned n> + void fill_with(const weight (&values)[n]); + + protected: + weighted_window_(); + + }; // end of class oln::internal::weighted_window_<Exact> + + +# ifndef OLN_INCLUDE_ONLY + + template <typename Exact> + weighted_window_<Exact>::weighted_window_() + { + } + + template <typename Exact> + Exact& + weighted_window_<Exact>::take(const typename weighted_window_<Exact>::weight& w, + const typename weighted_window_<Exact>::dpoint& dp) + { + return exact(this)->impl_take(w, dp); + } + + template <typename Exact> + Exact& + weighted_window_<Exact>::impl_take(const typename weighted_window_<Exact>::weight& w, + const typename weighted_window_<Exact>::dpoint& dp) + { + this->take_(w, dp); // from weighted_dpoints_impl_. + return exact(*this); + } + + template <typename Exact> + template <unsigned n> + void + weighted_window_<Exact>::fill_with(const weight (&values)[n]) + { + precondition(this->size() == 0); + exact(this)->impl_fill_with(values); + } + + } // end of namespace oln::internal + +# endif // ! OLN_INCLUDE_ONLY + +} // end of namespace oln + + +#endif // ! OLN_CORE_INTERNAL_WEIGHTED_WINDOW_HH Index: oln/core/internal/f_weighted_window.hh --- oln/core/internal/f_weighted_window.hh (revision 0) +++ oln/core/internal/f_weighted_window.hh (revision 0) @@ -0,0 +1,99 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLN_CORE_INTERNAL_F_WEIGHTED_WINDOW_HH +# define OLN_CORE_INTERNAL_F_WEIGHTED_WINDOW_HH + +# include <oln/core/concept/dpoint.hh> +# include <oln/core/concept/weighted_window.hh> + + +# define oln_f_weighted_window(W, Dp) \ +typename oln::internal::f_weighted_window_< W, Dp >::ret + + +namespace oln +{ + + /// \{ + /// Forward declarations. + + // Dpoint types. + + struct dpoint1d; + struct dpoint2d; + struct dpoint3d; + template <typename G, typename C> class dpoint; + + // Weighted window types. + + template <typename W> struct weighted_window2d; + template <typename W, typename Dp> class weighted_window; + + /// \} + + + + namespace internal + { + + template <typename W, typename Dp> + struct weighted_window__; + + + /// \{ + /// Definitions. + + template <typename W, typename G, typename C> + struct weighted_window__< W, oln::dpoint<G, C> > + { + typedef weighted_window< W, oln::dpoint<G, C> > ret; + }; + + template <typename W> + struct weighted_window__< W, dpoint2d > + { + typedef weighted_window2d<W> ret; + }; + + // FIXME: 1D, 3D, 2D hex/tri... + + /// \} + + + template <typename W, typename Dp> + struct f_weighted_window_ : private mlc::assert_< mlc_is_a(Dp, Dpoint) >, + public weighted_window__<W, Dp> + { + }; + + } // end of namespace oln::internal + +} // end of namespace oln + + +#endif // ! OLN_CORE_INTERNAL_F_WEIGHTED_WINDOW_HH Index: oln/core/internal/weighted_window_base.hh --- oln/core/internal/weighted_window_base.hh (revision 0) +++ oln/core/internal/weighted_window_base.hh (revision 0) @@ -0,0 +1,104 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLN_CORE_INTERNAL_WEIGHTED_WINDOW_BASE_HH +# define OLN_CORE_INTERNAL_WEIGHTED_WINDOW_BASE_HH + +# include <oln/core/concept/weighted_window.hh> + + +namespace oln +{ + + + // Fwd decl. + namespace internal { template <typename Exact> class weighted_window_base_; } + + + // Super type. + template <typename Exact> + struct super_trait_< internal::weighted_window_base_<Exact> > + { + typedef Weighted_Window<Exact> ret; + }; + + + /// Virtual types. + template <typename Exact> + struct vtypes< internal::weighted_window_base_<Exact> > + { + +// typedef stc::abstract point; +// typedef stc::abstract fwd_qiter; +// typedef stc::abstract bkd_qiter; +// typedef stc::abstract weight; + +// typedef stc_deferred(point) point__; +// typedef stc_deferred(fwd_qiter) fwd_qiter__; + +// typedef stc::final< oln_grid(point__) > grid; +// typedef stc::final< fwd_qiter__ > qiter; + + typedef stc::final< stc::is<Weighted_Window> > category; + }; + + + namespace internal + { + + /// Base class for implementation of weighted_window classes. + + template <typename Exact> + class weighted_window_base_ : public Weighted_Window<Exact> + { + public: + + stc_typename(point); + stc_typename(weight); + + protected: + weighted_window_base_(); + + }; // end of class oln::internal::weighted_window_base_<Exact> + + + +# ifndef OLN_INCLUDE_ONLY + + template <typename Exact> + weighted_window_base_<Exact>::weighted_window_base_() + { + } + +# endif // ! OLN_INCLUDE_ONLY + + } // end of namespace oln::internal + +} // end of namespace oln + + +#endif // ! OLN_CORE_INTERNAL_WEIGHTED_WINDOW_BASE_HH Index: oln/core/internal/weighted_dpoints_impl.hh --- oln/core/internal/weighted_dpoints_impl.hh (revision 0) +++ oln/core/internal/weighted_dpoints_impl.hh (revision 0) @@ -0,0 +1,193 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLN_CORE_INTERNAL_WEIGHTED_DPOINTS_IMPL_HH +# define OLN_CORE_INTERNAL_WEIGHTED_DPOINTS_IMPL_HH + +# include <set> +# include <vector> +# include <ostream> +# include <oln/core/concept/dpoint.hh> +# include <oln/core/internal/utils.hh> + + +namespace oln +{ + + namespace internal + { + + template <typename W, typename Dp> + struct wdp_less_ + { + bool operator()(const internal::pair<W,Dp>& lhs, + const internal::pair<W,Dp>& rhs) const + { + return lhs.second < rhs.second; + } + }; + + /// Implementation for classes storing a set of weighted_dpoints. + + template <typename W, typename Dp> + class weighted_dpoints_impl_ + { + public: + + unsigned size() const; + + const W& w(unsigned i) const; + const Dp& dp(unsigned i) const; + + const std::vector<W>& weights() const; + const std::vector<Dp>& dpoints() const; + bool has(const Dp& dp) const; + + protected: + + weighted_dpoints_impl_(); + void take_(const W& w, const Dp& dp); + + std::vector<W> w_; + std::vector<Dp> dp_; + + private: + + void update_(); + + typedef std::set< internal::pair<W,Dp>, wdp_less_<W,Dp> > s_wdp_t; + + std::set<Dp> s_dp_; + s_wdp_t s_wdp_; + + }; // end of class oln::internal::weighted_dpoints_impl_<W,Dp> + + + template <typename W, typename Dp> + std::ostream& operator<<(std::ostream& ostr, + const weighted_dpoints_impl_<W,Dp>& wdps) + { + ostr << "[ "; + unsigned n = wdps.size(); + for (unsigned i = 0; i < n; ++i) + ostr << '{' << wdps.w(i) << ", " << wdps.dp(i) << (i == n - 1 ? "} ]" : "}, "); + return ostr; + } + + +# ifndef OLN_INCLUDE_ONLY + + // public: + + template <typename W, typename Dp> + unsigned + weighted_dpoints_impl_<W,Dp>::size() const + { + invariant(dp_.size() == w_.size()); + return dp_.size(); + } + + template <typename W, typename Dp> + const W& + weighted_dpoints_impl_<W,Dp>::w(unsigned i) const + { + precondition(i < w_.size()); + return w_[i]; + } + + template <typename W, typename Dp> + const Dp& + weighted_dpoints_impl_<W,Dp>::dp(unsigned i) const + { + precondition(i < dp_.size()); + return dp_[i]; + } + + template <typename W, typename Dp> + const std::vector<W>& + weighted_dpoints_impl_<W,Dp>::weights() const + { + return w_; + } + + template <typename W, typename Dp> + const std::vector<Dp>& + weighted_dpoints_impl_<W,Dp>::dpoints() const + { + return dp_; + } + + template <typename W, typename Dp> + bool + weighted_dpoints_impl_<W,Dp>::has(const Dp& dp) const + { + return s_dp_.find(dp) != s_dp_.end(); + } + + // protected: + + template <typename W, typename Dp> + weighted_dpoints_impl_<W,Dp>::weighted_dpoints_impl_() + { + mlc::assert_< mlc_is_a(Dp, Dpoint) >::check(); // FIXME: Add err msg. + } + + template <typename W, typename Dp> + void + weighted_dpoints_impl_<W,Dp>::take_(const W& w, const Dp& dp) + { + precondition(not this->has(dp)); + s_dp_.insert(dp); + internal::pair<W,Dp> tmp(w, dp); + s_wdp_.insert(tmp); + update_(); + } + + // private: + + template <typename W, typename Dp> + void + weighted_dpoints_impl_<W,Dp>::update_() + { + w_.clear(); + dp_.clear(); + typename s_wdp_t::const_iterator i; + for (i = s_wdp_.begin(); i != s_wdp_.end(); ++i) + { + w_ .push_back(i->first); + dp_.push_back(i->second); + } + } + +# endif // ! OLN_INCLUDE_ONLY + + } // end of namespace oln::internal + +} // end of namespace oln + + +#endif // ! OLN_CORE_INTERNAL_WEIGHTED_DPOINTS_IMPL_HH Index: oln/core/internal/window_base.hh --- oln/core/internal/window_base.hh (revision 954) +++ oln/core/internal/window_base.hh (working copy) @@ -60,6 +60,8 @@ typedef stc::final< oln_grid(point__) > grid; typedef stc::final< fwd_qiter__ > qiter; + + typedef stc::final< stc::is<Window> > category; }; @@ -88,8 +90,7 @@ { } -# endif - +# endif // ! OLN_INCLUDE_ONLY } // end of namespace oln::internal Index: oln/linear/convolution.hh --- oln/linear/convolution.hh (revision 0) +++ oln/linear/convolution.hh (revision 0) @@ -0,0 +1,154 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLN_LINEAR_CONVOLUTION_HH +# define OLN_LINEAR_CONVOLUTION_HH + +# include <oln/core/concept/image.hh> +# include <oln/core/concept/weighted_window.hh> + +# include <oln/core/internal/f_weighted_window.hh> +# include <oln/core/internal/f_ch_value.hh> + + +namespace oln +{ + + namespace linear + { + + // Fwd decls. + + template <typename V, typename I, typename J> + oln_plain_value(I, V) + convolution(const Image<I>& f, const Image<J>& g); + + template <typename V, typename I, typename W> + oln_plain_value(I, V) + convolution(const Image<I>& f, const Weighted_Window<W>& w_win); + + template <typename V, typename I, typename W, unsigned n> + oln_plain_value(I, V) + convolution(const Image<I>& f, const W (&values)[n]); + + +# ifndef OLN_INCLUDE_ONLY + + namespace impl + { + + // Generic versions. + + template <typename V, typename I, typename J> + oln_plain_value(I, V) + convolution_image_(const Point_Wise_Accessible_Image<I>& f, const Image<J>& g) + { + oln_plain_value(I, V) output; + prepare(output, with, f); + + oln_point(I) O; O.set_all(0); + oln_point(I) p_q; + + oln_piter(I) p(f.points()); + oln_piter(J) q(g.points()); + for_all(p) + { + V val = 0; + for_all(q) + { + oln_dpoint(I) dp = O - q.to_point(); + p_q = p.to_point() + dp; + if (f.has(p_q)) + val += g(q) * f(p_q); // FIXME: f(p + (O - q)); + } + output(p) = val; + } + return output; + } + + template <typename V, typename I, typename W> + oln_plain_value(I, V) + convolution_window_(const Point_Wise_Accessible_Image<I>& input, const W& win) + { + oln_plain_value(I, V) output; + prepare(output, with, input); + oln_piter(I) p(input.points()); + for_all(p) + { + V val = 0; + for (unsigned i = 0; i < win.size(); ++i) + { + oln_point(I) q = p.to_point() + win.dp(i); + if (input.has(q)) + val += win.w(i) * input(q); + } + output(p) = val; + } + return output; + } + + } // end of namespace oln::linear::impl + + + // Facades. + + template <typename V, typename I, typename J> + oln_plain_value(I, V) + convolution(const Image<I>& f, const Image<J>& g) + { + mlc::assert_< mlc_is_a(I, Point_Wise_Accessible_Image) >::check(); + oln_plain_value(I, V) output = impl::convolution_image_<V>(exact(f), exact(g)); + return output; + } + + template <typename V, typename I, typename W> + oln_plain_value(I, V) + convolution(const Image<I>& input, const Weighted_Window<W>& w_win) + { + mlc::assert_< mlc_is_a(I, Point_Wise_Accessible_Image) >::check(); + oln_plain_value(I, V) output = impl::convolution_window_<V>(exact(input), exact(w_win)); + return output; + } + + template <typename V, typename I, typename W, unsigned n> + oln_plain_value(I, V) + convolution(const Image<I>& input, const W (&values)[n]) + { + mlc::assert_< mlc_is_a(I, Point_Wise_Accessible_Image) >::check(); + oln_f_weighted_window(W, oln_dpoint(I)) w_win; + w_win.fill_with(values); + return linear::convolution<V>(input, w_win); + } + +# endif // ! OLN_INCLUDE_ONLY + + } // end of namespace oln::linear + +} // end of namespace oln + + +#endif // ! OLN_LINEAR_CONVOLUTION_HH Index: oln/linear/lap_4.hh --- oln/linear/lap_4.hh (revision 0) +++ oln/linear/lap_4.hh (revision 0) @@ -0,0 +1,82 @@ +// Copyright (C) 2007 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLN_LINEAR_LAP_4_HH +# define OLN_LINEAR_LAP_4_HH + +# include <oln/linear/convolution.hh> +# include <oln/core/2d/weighted_window2d.hh> + + +namespace oln +{ + + namespace linear + { + + // Fwd decl. + + template <typename V, typename I> + oln_plain_value(I, V) + lap_4(const Image_2D<I>& f); + + +# ifndef OLN_INCLUDE_ONLY + + namespace impl + { + + // Generic version. + + template <typename V, typename I> + oln_plain_value(I, V) + lap_4_(const Image_2D<I>& f) + { + int values[] = { 0, 1, 0, + 1, -4, 1, + 0, 1, 0 }; + return linear::convolution<V>(f, values); + } + + + } // end of namespace oln::linear::impl + + template <typename V, typename I> + oln_plain_value(I, V) + lap_4(const Image_2D<I>& f) + { + return impl::lap_4_<V>(f); + } + +# endif // ! OLN_INCLUDE_ONLY + + } // end of namespace oln::linear + +} // end of namespace oln + + +#endif // ! OLN_LINEAR_LAP_4_HH
participants (1)
-
Thierry GERAUD