last-svn-commit-544-g1dfe127 WIP: More comparisons on dilation (static windows and qixters).

--- milena/apps/bench/Makefile.am | 1 + milena/apps/bench/dilation-lena.cc | 45 +++ milena/apps/bench/static_array.hh | 134 +++++++++ .../bench/static_dpoints_pixter.hh} | 196 +++++++------- .../core/window.hh => apps/bench/static_window.hh} | 288 ++++++++++---------- 5 files changed, 420 insertions(+), 244 deletions(-) create mode 100644 milena/apps/bench/static_array.hh copy milena/{mln/core/dpoints_pixter.hh => apps/bench/static_dpoints_pixter.hh} (66%) copy milena/{mln/core/window.hh => apps/bench/static_window.hh} (51%) diff --git a/milena/apps/bench/Makefile.am b/milena/apps/bench/Makefile.am index 41b57f5..766f620 100644 --- a/milena/apps/bench/Makefile.am +++ b/milena/apps/bench/Makefile.am @@ -40,6 +40,7 @@ MOSTLYCLEANFILES = \ dilation-lena-out-gen.pgm \ dilation-lena-out-fast.pgm \ dilation-lena-out-faster.pgm \ + dilation-lena-out-fast_static.pgm \ gradient-lena-out.pgm \ gradient-spe-lena-out-0.pgm \ gradient-spe-lena-out-1.pgm \ diff --git a/milena/apps/bench/dilation-lena.cc b/milena/apps/bench/dilation-lena.cc index 1cb1198..ea37f19 100644 --- a/milena/apps/bench/dilation-lena.cc +++ b/milena/apps/bench/dilation-lena.cc @@ -37,6 +37,8 @@ #include <mln/util/timer.hh> +#include "apps/bench/static_window.hh" +#include "apps/bench/static_dpoints_pixter.hh" #include "apps/data.hh" @@ -134,6 +136,33 @@ namespace faster } } +namespace fast_static +{ + using namespace mln; + + template <typename I, typename W> + mln_concrete(I) dilation(const I& input, const W& win) + { + typedef mln_concrete(I) O; + O output; initialize(output, input); // Initialize output. + + mln_pixter(const I) pi(input); // Iterator on the pixels of `input'. + mln_pixter(O) po(output); // Iterator on the pixels of `output'. + + typedef mln::static_dpoints_fwd_pixter<const I, W::Size> mln_static_qixter; + mln_static_qixter q(pi, win); + for_all_2(pi, po) + { + // FIXME: Cheat: replace the accu::supremum by a maximum. + mln::accu::stat::max<mln_value(I)> sup; // Accumulator computing the supremum. + for_all(q) + sup.take(q.val()); + po.val() = sup.to_result(); + } + return output; + } +} + int main() { @@ -170,4 +199,20 @@ int main() t.stop(); std::cout << t.read() << std::endl; io::pgm::save(d, "dilation-lena-out-faster.pgm"); + + + const unsigned n = 5; + mln::dpoint2d dps[n] = { mln::dpoint2d( 0, -1), + mln::dpoint2d(-1, 0), + mln::dpoint2d( 0, 0), + mln::dpoint2d(+1, 0), + mln::dpoint2d( 0, +1) }; + mln::util::static_array<mln::dpoint2d, n> sa(dps, dps + n); + mln::static_window<mln::dpoint2d, n> static_win_c4p (sa); + + t.start(); + d = fast_static::dilation(lena, static_win_c4p); + t.stop(); + std::cout << t.read() << std::endl; + io::pgm::save(d, "dilation-lena-out-fast_static.pgm"); } diff --git a/milena/apps/bench/static_array.hh b/milena/apps/bench/static_array.hh new file mode 100644 index 0000000..ddf42bd --- /dev/null +++ b/milena/apps/bench/static_array.hh @@ -0,0 +1,134 @@ +// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to produce +// an executable, this file does not by itself cause the resulting +// executable to be covered by the GNU General Public License. This +// exception does not however invalidate any other reasons why the +// executable file might be covered by the GNU General Public License. + +#ifndef MLN_UTIL_STATIC_ARRAY_HH +# define MLN_UTIL_STATIC_ARRAY_HH + +// FIXME: Add documentation. + +# include <cstddef> +# include <algorithm> + +# include <mln/core/internal/window_base.hh> +# include <mln/core/concept/gdpoint.hh> + +# include <mln/metal/is_a.hh> +# include <mln/util/set.hh> +# include <mln/fun/i2v/all_to.hh> +# include <mln/norm/linfty.hh> +# include <mln/literal/zero.hh> + +namespace mln +{ + + namespace util + { + + template <typename T, std::size_t n> + class static_array + { + public: + // FIXME: Careful, this ctor initializes nothing. + static_array(); + + // FIXME: Find a better way to build this static array. + template <typename InputIterator> + static_array(InputIterator first, InputIterator last); + + T& operator[](std::size_t i); + const T& operator[](std::size_t i) const; + + bool has(const T& value) const; + + private: + T data_[n]; + }; + + + template <typename D, std::size_t n> + bool + operator==(const static_array<D, n>& lhs, const static_array<D, n>& rhs); + + +# ifndef MLN_INCLUDE_ONLY + + template <typename T, std::size_t n> + inline + static_array<T, n>::static_array() + { + } + + template <typename T, std::size_t n> + template <typename InputIterator> + inline + static_array<T, n>::static_array(InputIterator first, InputIterator last) + { + mln_precondition(std::distance(first, last) == n); + std::copy(first, last, data_); + } + + template <typename T, std::size_t n> + inline + T& + static_array<T, n>::operator[](std::size_t i) + { + return data_[i]; + } + + template <typename T, std::size_t n> + inline + const T& + static_array<T, n>::operator[](std::size_t i) const + { + return data_[i]; + } + + template <typename T, std::size_t n> + inline + bool + static_array<T, n>::has(const T& value) const + { + return std::find(data_, data_ + n, value) != data_ + n; + } + + + template <typename D, std::size_t n> + inline + bool + operator==(const static_array<D, n>& lhs, const static_array<D, n>& rhs) + { + for(std::size_t i = 0; i < n; ++i) + if (lhs[i] != rhs[i]) + return false; + return true; + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::util + +} // end of namespace mln + +#endif // ! MLN_UTIL_STATIC_ARRAY_HH diff --git a/milena/mln/core/dpoints_pixter.hh b/milena/apps/bench/static_dpoints_pixter.hh similarity index 66% copy from milena/mln/core/dpoints_pixter.hh copy to milena/apps/bench/static_dpoints_pixter.hh index 8020fcc..d7823ac 100644 --- a/milena/mln/core/dpoints_pixter.hh +++ b/milena/apps/bench/static_dpoints_pixter.hh @@ -1,4 +1,5 @@ -// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2007, 2008, 2009, 2010 EPITA Research and Development +// Laboratory (LRDE) // // This file is part of Olena. // @@ -23,8 +24,10 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. -#ifndef MLN_CORE_DPOINTS_PIXTER_HH -# define MLN_CORE_DPOINTS_PIXTER_HH +#ifndef MLN_CORE_STATIC_DPOINTS_PIXTER_HH +# define MLN_CORE_STATIC_DPOINTS_PIXTER_HH + +// FIXME: Review and update the documentation. /// \file /// @@ -41,24 +44,25 @@ # include <mln/core/internal/pixel_impl.hh> # include <mln/metal/converts_to.hh> +# include "apps/bench/static_array.hh" namespace mln { - /*------------------------. - | dpoints_fwd_pixter<I>. | - `------------------------*/ + /*----------------------------------. + | static_dpoints_fwd_pixter<I, n>. | + `----------------------------------*/ /// \brief A generic forward iterator on the pixels of a /// dpoint-based window or neighborhood. /// /// Parameter \c I is the image type. - template <typename I> - class dpoints_fwd_pixter - : public Pixel_Iterator< dpoints_fwd_pixter<I> >, - public internal::pixel_impl_< I, dpoints_fwd_pixter<I> > + template <typename I, unsigned n> + class static_dpoints_fwd_pixter + : public Pixel_Iterator< static_dpoints_fwd_pixter<I, n> >, + public internal::pixel_impl_< I, static_dpoints_fwd_pixter<I, n> > { - typedef typename internal::pixel_impl_< I, dpoints_fwd_pixter<I> > super_; + typedef typename internal::pixel_impl_< I, static_dpoints_fwd_pixter<I, n> > super_; public: /// \brief Constructor (using an image). @@ -69,9 +73,9 @@ namespace mln /// \param[in] p_ref Center (resp. reference) point of the /// neighborhood (resp. window). template <typename Dps, typename Pref> - dpoints_fwd_pixter(I& image, - const Dps& dps, - const Pref& p_ref); + static_dpoints_fwd_pixter(I& image, + const Dps& dps, + const Pref& p_ref); /// \brief Constructor (using a generalized pixel). /// @@ -79,8 +83,8 @@ namespace mln /// \param[in] dps An object (neighborhood or window) that can /// provide a set of delta-points. template <typename Dps, typename Pref> - dpoints_fwd_pixter(const Generalized_Pixel<Pref>& pxl_ref, - const Dps& dps); + static_dpoints_fwd_pixter(const Generalized_Pixel<Pref>& pxl_ref, + const Dps& dps); /// Manipulation. /// \{ @@ -112,9 +116,9 @@ namespace mln /// offset_[0] is absolute, while other offsets are relative /// (i.e., offset_[i] is the memory difference to go from pixel /// i-1 to pixel i. - std::vector<int> offset_; + util::static_array<int, n> offset_; /// Current offset. - typename std::vector<int>::const_iterator i_; + std::size_t i_; /// \brief Reference value or pixel. /// @@ -128,20 +132,20 @@ namespace mln }; - /*------------------------. - | dpoints_bkd_pixter<I>. | - `------------------------*/ + /*----------------------------------. + | static_dpoints_bkd_pixter<I, n>. | + `----------------------------------*/ /// \brief A generic backward iterator on the pixels of a /// dpoint-based window or neighborhood. /// /// Parameter \c I is the image type. - template <typename I> - class dpoints_bkd_pixter - : public Pixel_Iterator< dpoints_bkd_pixter<I> >, - public internal::pixel_impl_< I, dpoints_bkd_pixter<I> > + template <typename I, unsigned n> + class static_dpoints_bkd_pixter + : public Pixel_Iterator< static_dpoints_bkd_pixter<I, n> >, + public internal::pixel_impl_< I, static_dpoints_bkd_pixter<I, n> > { - typedef typename internal::pixel_impl_< I, dpoints_bkd_pixter<I> > super_; + typedef typename internal::pixel_impl_< I, static_dpoints_bkd_pixter<I, n> > super_; public: /// \brief Constructor (using an image). @@ -152,9 +156,9 @@ namespace mln /// \param[in] p_ref Center (resp. reference) point of the /// neighborhood (resp. window). template <typename Dps, typename Pref> - dpoints_bkd_pixter(I& image, - const Dps& dps, - const Pref& p_ref); + static_dpoints_bkd_pixter(I& image, + const Dps& dps, + const Pref& p_ref); /// \brief Constructor (using a generalized pixel). /// @@ -162,8 +166,8 @@ namespace mln /// \param[in] dps An object (neighborhood or window) that can /// provide a set of delta-points. template <typename Dps, typename Pref> - dpoints_bkd_pixter(const Generalized_Pixel<Pref>& pxl_ref, - const Dps& dps); + static_dpoints_bkd_pixter(const Generalized_Pixel<Pref>& pxl_ref, + const Dps& dps); /// Manipulation. /// \{ @@ -195,9 +199,9 @@ namespace mln /// offset_[dps.size() - 1] is absolute, while other offsets /// are relative (i.e., offset_[i] is the memory difference to go /// from pixel i+1 to pixel i. - std::vector<int> offset_; + util::static_array<int, n> offset_; /// Current offset. - typename std::vector<int>::const_reverse_iterator i_; + std::size_t i_; /// \brief Reference value or pixel. /// @@ -214,16 +218,16 @@ namespace mln #ifndef MLN_INCLUDE_ONLY - /*------------------------. - | dpoints_fwd_pixter<I>. | - `------------------------*/ + /*----------------------------------. + | static_dpoints_fwd_pixter<I, n>. | + `----------------------------------*/ - template <typename I> + template <typename I, unsigned n> template <typename Dps, typename Pref> inline - dpoints_fwd_pixter<I>::dpoints_fwd_pixter(I& image, - const Dps& dps, - const Pref& p_ref) + static_dpoints_fwd_pixter<I, n>::static_dpoints_fwd_pixter(I& image, + const Dps& dps, + const Pref& p_ref) : super_(image) { mln_precondition(image.is_valid()); @@ -235,11 +239,11 @@ namespace mln init_(dps); } - template <typename I> + template <typename I, unsigned n> template <typename Dps, typename Pref> inline - dpoints_fwd_pixter<I>::dpoints_fwd_pixter(const Generalized_Pixel<Pref>& pxl_ref_, - const Dps& dps) + static_dpoints_fwd_pixter<I, n>::static_dpoints_fwd_pixter(const Generalized_Pixel<Pref>& pxl_ref_, + const Dps& dps) : super_(internal::force_exact<Pref>(pxl_ref_).ima()) { const Pref& pxl_ref = internal::force_exact<Pref>(pxl_ref_); @@ -250,10 +254,10 @@ namespace mln init_(dps); } - template <typename I> + template <typename I, unsigned n> inline const mln_value(I)& - dpoints_fwd_pixter<I>::center_val() const + static_dpoints_fwd_pixter<I, n>::center_val() const { mln_invariant(value_ref_ != 0 || p_ref_ != 0); if (p_ref_) @@ -262,14 +266,14 @@ namespace mln return **value_ref_; } - template <typename I> + template <typename I, unsigned n> template <typename Dps> inline void - dpoints_fwd_pixter<I>::init_(const Dps& dps) + static_dpoints_fwd_pixter<I, n>::init_(const Dps& dps) { for (unsigned i = 0; i < dps.size(); ++i) - offset_.push_back(this->image_.delta_index(dps.dp(i))); + offset_[i] = this->image_.delta_index(dps.dp(i)); // offset_[0] is absolute // other offsets are relative: if (dps.size() > 1) @@ -278,66 +282,66 @@ namespace mln invalidate(); } - template <typename I> + template <typename I, unsigned n> inline void - dpoints_fwd_pixter<I>::update() + static_dpoints_fwd_pixter<I, n>::update() { if (is_valid()) { if (p_ref_) - this->value_ptr_ = & image_(*p_ref_) + *i_; + this->value_ptr_ = & image_(*p_ref_) + offset_[i_]; else - this->value_ptr_ = * value_ref_ + *i_; + this->value_ptr_ = * value_ref_ + offset_[i_]; } } - template <typename I> + template <typename I, unsigned n> inline void - dpoints_fwd_pixter<I>::start() + static_dpoints_fwd_pixter<I, n>::start() { - i_ = offset_.begin(); + i_ = 0; update(); } - template <typename I> + template <typename I, unsigned n> inline void - dpoints_fwd_pixter<I>::next_() + static_dpoints_fwd_pixter<I, n>::next_() { ++i_; if (is_valid()) - this->value_ptr_ += *i_; + this->value_ptr_ += offset_[i_]; } - template <typename I> + template <typename I, unsigned n> inline bool - dpoints_fwd_pixter<I>::is_valid() const + static_dpoints_fwd_pixter<I, n>::is_valid() const { - return i_ != offset_.end(); + return i_ < n; } - template <typename I> + template <typename I, unsigned n> inline void - dpoints_fwd_pixter<I>::invalidate() + static_dpoints_fwd_pixter<I, n>::invalidate() { - i_ = offset_.end(); + i_ = n; } - /*------------------------. - | dpoints_bkd_pixter<I>. | - `------------------------*/ + /*----------------------------------. + | static_dpoints_bkd_pixter<I, n>. | + `----------------------------------*/ - template <typename I> + template <typename I, unsigned n> template <typename Dps, typename Pref> inline - dpoints_bkd_pixter<I>::dpoints_bkd_pixter(I& image, - const Dps& dps, - const Pref& p_ref) + static_dpoints_bkd_pixter<I, n>::static_dpoints_bkd_pixter(I& image, + const Dps& dps, + const Pref& p_ref) : super_(image) { mln_precondition(image.is_valid()); @@ -346,11 +350,11 @@ namespace mln init_(dps); } - template <typename I> + template <typename I, unsigned n> template <typename Dps, typename Pref> inline - dpoints_bkd_pixter<I>::dpoints_bkd_pixter(const Generalized_Pixel<Pref>& pxl_ref_, - const Dps& dps) + static_dpoints_bkd_pixter<I, n>::static_dpoints_bkd_pixter(const Generalized_Pixel<Pref>& pxl_ref_, + const Dps& dps) : super_(internal::force_exact<Pref>(pxl_ref_).ima()) { const Pref& pxl_ref = internal::force_exact<Pref>(pxl_ref_); @@ -361,10 +365,10 @@ namespace mln init_(dps); } - template <typename I> + template <typename I, unsigned n> inline const mln_value(I)& - dpoints_bkd_pixter<I>::center_val() const + static_dpoints_bkd_pixter<I, n>::center_val() const { mln_invariant(value_ref_ != 0 || p_ref_ != 0); if (p_ref_) @@ -373,14 +377,14 @@ namespace mln return **value_ref_; } - template <typename I> + template <typename I, unsigned n> template <typename Dps> inline void - dpoints_bkd_pixter<I>::init_(const Dps& dps) + static_dpoints_bkd_pixter<I, n>::init_(const Dps& dps) { for (unsigned i = 0; i < dps.size(); ++i) - offset_.push_back(this->image_.delta_index(dps.dp(i))); + offset_[i] = this->image_.delta_index(dps.dp(i)); // offset_[size() - 1] is absolute // other offsets are relative: if (dps.size() > 1) @@ -389,53 +393,53 @@ namespace mln invalidate(); } - template <typename I> + template <typename I, unsigned n> inline void - dpoints_bkd_pixter<I>::update() + static_dpoints_bkd_pixter<I, n>::update() { if (is_valid()) { if (p_ref_) - this->value_ptr_ = & image_(*p_ref_) + *i_; + this->value_ptr_ = & image_(*p_ref_) + offset_[n - 1 - i_]; else - this->value_ptr_ = * value_ref_ + *i_; + this->value_ptr_ = * value_ref_ + offset_[n - 1 - i_]; } } - template <typename I> + template <typename I, unsigned n> inline void - dpoints_bkd_pixter<I>::start() + static_dpoints_bkd_pixter<I, n>::start() { - i_ = offset_.rbegin(); + i_ = 0; update(); } - template <typename I> + template <typename I, unsigned n> inline void - dpoints_bkd_pixter<I>::next_() + static_dpoints_bkd_pixter<I, n>::next_() { ++i_; if (is_valid()) - this->value_ptr_ += *i_; + this->value_ptr_ += offset_[n - 1 - i_]; } - template <typename I> + template <typename I, unsigned n> inline bool - dpoints_bkd_pixter<I>::is_valid() const + static_dpoints_bkd_pixter<I, n>::is_valid() const { - return i_ != offset_.rend(); + return i_ < n; } - template <typename I> + template <typename I, unsigned n> inline void - dpoints_bkd_pixter<I>::invalidate() + static_dpoints_bkd_pixter<I, n>::invalidate() { - i_ = offset_.rend(); + i_ = n; } #endif // ! MLN_INCLUDE_ONLY @@ -443,4 +447,4 @@ namespace mln } // end of namespace mln -#endif // ! MLN_CORE_DPOINTS_PIXTER_HH +#endif // ! MLN_CORE_STATIC_DPOINTS_PIXTER_HH diff --git a/milena/mln/core/window.hh b/milena/apps/bench/static_window.hh similarity index 51% copy from milena/mln/core/window.hh copy to milena/apps/bench/static_window.hh index 87f1940..fe8f791 100644 --- a/milena/mln/core/window.hh +++ b/milena/apps/bench/static_window.hh @@ -1,4 +1,4 @@ -// Copyright (C) 2007, 2008, 2009 EPITA Research and Development +// Copyright (C) 2007, 2008, 2009, 2010 EPITA Research and Development // Laboratory (LRDE) // // This file is part of Olena. @@ -24,8 +24,10 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. -#ifndef MLN_CORE_WINDOW_HH -# define MLN_CORE_WINDOW_HH +#ifndef MLN_CORE_STATIC_WINDOW_HH +# define MLN_CORE_STATIC_WINDOW_HH + +// FIXME: Review and update the documentation. /*! \file * @@ -50,12 +52,14 @@ # include <mln/norm/linfty.hh> # include <mln/literal/zero.hh> +# include "apps/bench/static_array.hh" + namespace mln { // Forward declarations. - template <typename D> class window; + template <typename D, unsigned n> class static_window; template <typename V> class dpsites_fwd_piter; template <typename V> class dpsites_bkd_piter; @@ -64,8 +68,8 @@ namespace mln namespace trait { - template <typename D> - struct window_< mln::window<D> > + template <typename D, unsigned n> + struct window_< mln::static_window<D, n> > { typedef trait::window::size::fixed size; typedef trait::window::support::regular support; @@ -81,20 +85,18 @@ namespace mln * This type of window is just like a set of delta-points. The * parameter is \c D, type of delta-point. */ - template <typename D> - class window : public internal::window_base< D, window<D> > + template <typename D, unsigned n> + class static_window : public internal::window_base< D, static_window<D, n> > { public: + enum { Size = n }; + /// Regular window associated type. - typedef window<D> regular; + typedef static_window<D, n> regular; - /*! \brief Constructor without argument. - * - * The constructed window is empty. - */ - window(); + static_window(const mln::util::static_array<D, n>& dps); /*! \brief Test if the window is centered. * @@ -116,12 +118,12 @@ namespace mln /*! \brief Site_Iterator type to browse the points of a basic window * w.r.t. the ordering of delta-points. */ - typedef dpsites_fwd_piter< window<D> > fwd_qiter; + typedef dpsites_fwd_piter< static_window<D, n> > fwd_qiter; /*! \brief Site_Iterator type to browse the points of a basic window * w.r.t. the reverse ordering of delta-points. */ - typedef dpsites_bkd_piter< window<D> > bkd_qiter; + typedef dpsites_bkd_piter< static_window<D, n> > bkd_qiter; /*! \brief Site_Iterator type to browse the points of a basic window * whatever the ordering of delta-points. @@ -136,8 +138,8 @@ namespace mln */ bool is_empty() const; - /// Clear the window. - void clear(); + // /// Clear the window. + // void clear(); /*! \brief Give the maximum coordinate gap between the window center and a window point. @@ -150,38 +152,35 @@ namespace mln /// Test if \p dp is in this window definition. bool has(const D& dp) const; - /// Insert a delta-point \p dp. - window<D>& insert(const D& dp); + // /// Insert a delta-point \p dp. + // static_window<D, n>& insert(const D& dp); - /// Insert another window \p win. - template <typename W> - window<D>& insert(const Window<W>& win); + // /// Insert another window \p win. + // template <typename W> + // static_window<D, n>& insert(const Window<W>& win); - /// \{ Insertion of a delta-point with different numbers of - /// arguments (coordinates) w.r.t. the dimension. - window<D>& insert(const mln_coord(D)& dind); // For 1D or index access. + // /// \{ Insertion of a delta-point with different numbers of + // /// arguments (coordinates) w.r.t. the dimension. + // static_window<D, n>& insert(const mln_coord(D)& dind); // For 1D or index access. - window<D>& insert(const mln_coord(D)& drow, - const mln_coord(D)& dcol); // For 2D. + // static_window<D, n>& insert(const mln_coord(D)& drow, + // const mln_coord(D)& dcol); // For 2D. - window<D>& insert(const mln_coord(D)& dsli, - const mln_coord(D)& drow, - const mln_coord(D)& dcol); // For 3D. + // static_window<D, n>& insert(const mln_coord(D)& dsli, + // const mln_coord(D)& drow, + // const mln_coord(D)& dcol); // For 3D. /// \} - /// Give the std vector of delta-points. - const std::vector<D>& std_vector() const; - /// Hook to the set of D. - const mln::util::set<D>& dps_hook_() const; + const mln::util::static_array<D, n>& dps_hook_() const; /// Print the window definition into \p ostr. void print(std::ostream& ostr) const; private: - util::set<D> dps_; + mln::util::static_array<D, n> dps_; unsigned delta_(int i) const; // For indices. unsigned delta_(const Gdpoint<D>& dp) const; // For grids delta-points. @@ -193,76 +192,77 @@ namespace mln * * \relates mln::window */ - template <typename D> - bool operator==(const window<D>& lhs, const window<D>& rhs); + template <typename D, unsigned n> + bool operator==(const static_window<D, n>& lhs, const static_window<D, n>& rhs); # ifndef MLN_INCLUDE_ONLY - // window<D> + // static_window<D, n> - template <typename D> + template <typename D, unsigned n> inline - window<D>::window() + static_window<D, n>::static_window(const mln::util::static_array<D, n>& dps) + : dps_(dps) { // FIXME HERE: Was: mln::metal::is_a<D, Dpoint>::check(); // mln::metal::is_a<D, Delta_Point_Site>::check(); } - template <typename D> + template <typename D, unsigned n> inline bool - window<D>::is_symmetric() const + static_window<D, n>::is_symmetric() const { - window<D> cpy = *this; + static_window<D, n> cpy = *this; cpy.sym(); return cpy == *this; } - template <typename D> + template <typename D, unsigned n> inline bool - window<D>::is_centered() const + static_window<D, n>::is_centered() const { return this->dps_.has(literal::zero); } - template <typename D> + template <typename D, unsigned n> inline void - window<D>::sym() + static_window<D, n>::sym() { - window<D> tmp; - const unsigned n = size(); - for (unsigned i = 0; i < n; ++i) - tmp.insert(- this->dp(i)); + util::static_array<D, n> rev; + // FIXME: Can't we use std::copy and reverse_iterators here? + for (std::size_t i = 0; i < n; ++i) + rev[i] = dps_[n - 1 - i]; + static_window<D, n> tmp(rev); *this = tmp; } - template <typename D> + template <typename D, unsigned n> inline bool - window<D>::is_empty() const + static_window<D, n>::is_empty() const { - return dps_.is_empty(); + return n == 0; } - template <typename D> - inline - void - window<D>::clear() - { - dps_.clear(); - } + // template <typename D, unsigned n> + // inline + // void + // static_window<D, n>::clear() + // { + // dps_.clear(); + // } - template <typename D> + template <typename D, unsigned n> inline unsigned - window<D>::delta() const + static_window<D, n>::delta() const { unsigned d = 0; - const unsigned n = size(); for (unsigned i = 0; i < n; ++i) { unsigned dd = delta_(dp(i)); @@ -272,122 +272,114 @@ namespace mln return d; } - template <typename D> + template <typename D, unsigned n> inline unsigned - window<D>::delta_(int i) const + static_window<D, n>::delta_(int i) const { return i; } - template <typename D> + template <typename D, unsigned n> inline unsigned - window<D>::delta_(const Gdpoint<D>& dp) const + static_window<D, n>::delta_(const Gdpoint<D>& dp) const { return norm::linfty(exact(dp).to_vec()); } - template <typename D> + template <typename D, unsigned n> inline unsigned - window<D>::size() const + static_window<D, n>::size() const { - return dps_.nelements(); + return n; } - template <typename D> + template <typename D, unsigned n> inline const D& - window<D>::dp(unsigned i) const + static_window<D, n>::dp(unsigned i) const { - mln_precondition(i < size()); + mln_precondition(i < n); return dps_[i]; } - template <typename D> + template <typename D, unsigned n> inline bool - window<D>::has(const D& dp) const + static_window<D, n>::has(const D& dp) const { return dps_.has(dp); } - template <typename D> - inline - const std::vector<D>& - window<D>::std_vector() const - { - return dps_.std_vector(); - } - - template <typename D> - inline - window<D>& - window<D>::insert(const D& dp) - { - dps_.insert(dp); - return *this; - } - - template <typename D> - template <typename W> - inline - window<D>& - window<D>::insert(const Window<W>& win_) - { - const W& win = exact(win_); - const unsigned n = win.size(); - for (unsigned i = 0; i < n; ++i) - dps_.insert(win.dp(i)); - return *this; - } - - template <typename D> - inline - window<D>& - window<D>::insert(const mln_coord(D)& dind) - { - mlc_bool(D::dim == 1)::check(); - D dp(dind); - return insert(dp); - } - - template <typename D> - inline - window<D>& - window<D>::insert(const mln_coord(D)& drow, - const mln_coord(D)& dcol) - { - mlc_bool(D::dim == 2)::check(); - D dp(drow, dcol); - return insert(dp); - } - - template <typename D> - inline - window<D>& - window<D>::insert(const mln_coord(D)& dsli, - const mln_coord(D)& drow, - const mln_coord(D)& dcol) - { - mlc_bool(D::dim == 3)::check(); - D dp(dsli, drow, dcol); - return insert(dp); - } - - template <typename D> + // template <typename D, unsigned n> + // inline + // static_window<D, n>& + // static_window<D, n>::insert(const D& dp) + // { + // dps_.insert(dp); + // return *this; + // } + + // template <typename D, unsigned n> + // template <typename W> + // inline + // static_window<D, n>& + // static_window<D, n>::insert(const Window<W>& win_) + // { + // const W& win = exact(win_); + // const unsigned n = win.size(); + // for (unsigned i = 0; i < n; ++i) + // dps_.insert(win.dp(i)); + // return *this; + // } + + // template <typename D, unsigned n> + // inline + // static_window<D, n>& + // static_window<D, n>::insert(const mln_coord(D)& dind) + // { + // mlc_bool(D::dim == 1)::check(); + // D dp(dind); + // return insert(dp); + // } + + // template <typename D, unsigned n> + // inline + // static_window<D, n>& + // static_window<D, n>::insert(const mln_coord(D)& drow, + // const mln_coord(D)& dcol) + // { + // mlc_bool(D::dim == 2)::check(); + // D dp(drow, dcol); + // return insert(dp); + // } + + // template <typename D, unsigned n> + // inline + // static_window<D, n>& + // static_window<D, n>::insert(const mln_coord(D)& dsli, + // const mln_coord(D)& drow, + // const mln_coord(D)& dcol) + // { + // mlc_bool(D::dim == 3)::check(); + // D dp(dsli, drow, dcol); + // return insert(dp); + // } + + template <typename D, unsigned n> inline - const util::set<D>& - window<D>::dps_hook_() const + const mln::util::static_array<D, n>& + static_window<D, n>::dps_hook_() const { return dps_; } - template <typename D> + template <typename D, unsigned n> inline void - window<D>::print(std::ostream& ostr) const + static_window<D, n>::print(std::ostream& ostr) const { ostr << dps_; } @@ -395,9 +387,9 @@ namespace mln // Operators. - template <typename D> + template <typename D, unsigned n> bool - operator==(const window<D>& lhs, const window<D>& rhs) + operator==(const static_window<D, n>& lhs, const static_window<D, n>& rhs) { return lhs.dps_hook_() == rhs.dps_hook_(); } @@ -410,4 +402,4 @@ namespace mln # include <mln/core/dpsites_piter.hh> -#endif // ! MLN_CORE_WINDOW_HH +#endif // ! MLN_CORE_STATIC_WINDOW_HH -- 1.7.2.5
participants (1)
-
Roland Levillain