https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add traits for windows and factor code.
* mln/trait/windows.hh: New.
* mln/trait/window: New.
* mln/trait/window/props.hh: New.
* mln/trait/window/print.hh: New.
* mln/core/macros.hh (mln_regular): New.
* mln/core/neighb.hh (operator<<): New.
* mln/core/concept/weighted_window.hh (include): Update.
* mln/core/concept/neighborhood.hh: Likewise.
* mln/core/concept/window.hh: Likewise.
(window_size_check, window_support_check): New.
(window_definition_check): New.
(operator<<): New.
* mln/core/concept/object.hh: New metal include.
* mln/core/internal/dpsites_impl.hh: Rename as...
* mln/core/internal/classical_window_base.hh: ...this.
(is_centered, is_symmetric, sym): New.
(delta): Rely on...
(delta_): ...this new method.
(print, print_): New.
* mln/geom/shift.hh: Revamp.
* mln/core/window.hh,
* mln/win/cube3d.hh,
* mln/win/line.hh,
* mln/win/rectangle2d.hh,
* mln/win/diag2d.hh,
* mln/win/backdiag2d.hh,
* mln/win/multiple.hh,
* mln/win/cuboid3d.hh,
* mln/win/octagon2d.hh,
* mln/win/disk2d.hh: Update and factor code.
core/concept/neighborhood.hh | 1
core/concept/object.hh | 1
core/concept/weighted_window.hh | 1
core/concept/window.hh | 154 ++++++++++++++++++++++++++++++++-
core/internal/classical_window_base.hh | 136 +++++++++++++++++++++--------
core/macros.hh | 6 +
core/neighb.hh | 7 +
core/window.hh | 43 ++++++---
geom/shift.hh | 53 +++++++++--
trait/window/print.hh | 119 +++++++++++++++++++++++++
trait/window/props.hh | 136 +++++++++++++++++++++++++++++
trait/windows.hh | 113 ++++++++++++++++++++++++
win/backdiag2d.hh | 64 ++-----------
win/cube3d.hh | 64 ++-----------
win/cuboid3d.hh | 69 ++------------
win/diag2d.hh | 64 ++-----------
win/disk2d.hh | 66 ++------------
win/line.hh | 87 ++++++------------
win/multiple.hh | 96 +++++++++++++++-----
win/octagon2d.hh | 64 ++-----------
win/rectangle2d.hh | 68 ++------------
21 files changed, 893 insertions(+), 519 deletions(-)
Index: mln/trait/windows.hh
--- mln/trait/windows.hh (revision 0)
+++ mln/trait/windows.hh (revision 0)
@@ -0,0 +1,113 @@
+// Copyright (C) 2008 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_TRAIT_WINDOWS_HH
+# define MLN_TRAIT_WINDOWS_HH
+
+/*! \file mln/trait/windows.hh
+ *
+ * \brief Some base trait types for windows.
+ */
+
+# include <mln/trait/undef.hh>
+# include <mln/trait/window/props.hh>
+
+
+/// Shortcut to the window property about the 'size' method presence.
+# define mln_trait_window_size(W) typename mln::trait::window_< W >::size
+
+/// Shortcut to the window property about the 'support' it is designed for.
+# define mln_trait_window_support(W) typename mln::trait::window_< W
>::support
+
+/// Shortcut to the window property about its definition.
+# define mln_trait_window_definition(W) typename mln::trait::window_< W
>::definition
+
+
+# define mln_internal_add_classical_window_trait(W) \
+ \
+ namespace win { struct W; } \
+ \
+ namespace trait \
+ { \
+ \
+ template <> \
+ struct window_< win::W > : classical_window_ \
+ { \
+ }; \
+ \
+ } \
+ \
+ struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_u_m_n
+
+
+namespace mln
+{
+
+ namespace trait
+ {
+
+ /// Pack of 'undefined' type values for properties of windows.
+ template <typename W>
+ struct undefined_window_
+ {
+ typedef undef size; // Fixed or unknown.
+ typedef undef support; // Regular or irregular.
+ typedef undef definition; // Unique, n_ary, or varying.
+ };
+
+
+ /*! \brief The trait pack structure for properties of windows.
+ *
+ * This structure is specialized for every concrete class of site
+ * set so that properties are properly defined.
+ *
+ * \see mln::doc::Window for the documentation of the "window"
+ * concept.
+ */
+ template <typename W>
+ struct window_ : undefined_window_<W>
+ {
+ };
+
+
+ // \internal Trait for classical windows.
+ struct classical_window_
+ {
+ typedef mln::trait::window::size::fixed size;
+ typedef mln::trait::window::support::regular support;
+ typedef mln::trait::window::definition::unique definition;
+ };
+
+ } // end of namespace mln::trait
+
+} // end of namespace mln
+
+
+# include <mln/trait/window/print.hh>
+
+
+#endif // ! MLN_TRAIT_WINDOWS_HH
Index: mln/trait/window/props.hh
--- mln/trait/window/props.hh (revision 0)
+++ mln/trait/window/props.hh (revision 0)
@@ -0,0 +1,136 @@
+// Copyright (C) 2008 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_TRAIT_WINDOW_PROPS_HH
+# define MLN_TRAIT_WINDOW_PROPS_HH
+
+/*! \file mln/trait/window/props.hh
+ *
+ * \brief Properties of window classes.
+ *
+ * \todo Precise the differences (?) between dynamic, growing, and
+ * free...
+ */
+
+# include <string>
+# include <mln/trait/undef.hh>
+
+
+
+// Properties of windows.
+// ========================
+
+// size: /any/
+// |
+// + -- fixed
+// |
+// + -- unknown
+
+// support: /any/
+// |
+// + -- regular
+// |
+// + -- irregular
+
+// definition: /any/
+// |
+// + -- unique
+// |
+// + -- /multiple/
+// |
+// + -- n_ary
+// |
+// + -- varying
+
+
+namespace mln
+{
+
+ namespace trait
+ {
+
+ namespace window
+ {
+
+
+ /// Window property about the 'size' method presence.
+ struct size
+ {
+ /// Base class for the window 'size' property.
+ struct any { protected: any() {} };
+
+ /// Property that states that the size is fixed.
+ struct fixed : any { std::string name() const { return "size::fixed"; } };
+
+ /// Property that states that the size is not fixed so unknown.
+ struct unknown : any { std::string name() const { return "size::unknown"; }
};
+ };
+
+
+ /// Window property about the 'support' it is designed for.
+ struct support
+ {
+ /// Base class for the window 'support' property.
+ struct any { protected: any() {} };
+
+ /// Property that states that the window is designed for a regular support.
+ struct regular : any { std::string name() const { return "support::regular";
} };
+
+ /// Property that states that the window is not designed for a regular support.
+ struct irregular : any { std::string name() const { return
"support::irregular"; } };
+ };
+
+
+ /// Window property about how the window is defined.
+ struct definition
+ {
+ /// Base class for the window 'definition' property.
+ struct any { protected: any() {} };
+
+ /// Property that states that the definition is unique.
+ struct unique : any { std::string name() const { return "definition::unique";
} };
+
+ /// Abstract property that states that the definition is multiple.
+ struct multiple : any { protected: multiple() {} };
+
+ /// Property that states that this window has n definitions.
+ struct n_ary : multiple { std::string name() const { return
"definition::n_ary"; } };
+
+ /// Property that states that this window has a varying definition.
+ struct varying : multiple { std::string name() const { return
"definition::varying"; } };
+ };
+
+
+ } // end of namespace mln::trait::window
+
+ } // end of namespace mln::trait
+
+
+} // end of namespace mln
+
+
+#endif // ! MLN_TRAIT_WINDOW_PROPS_HH
Index: mln/trait/window/print.hh
--- mln/trait/window/print.hh (revision 0)
+++ mln/trait/window/print.hh (revision 0)
@@ -0,0 +1,119 @@
+// Copyright (C) 2008 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_TRAIT_WINDOW_PRINT_HH
+# define MLN_TRAIT_WINDOW_PRINT_HH
+
+/*! \file mln/trait/window/print.hh
+ *
+ * \brief Print the collection of traits for a window type.
+ */
+
+# include <iostream>
+
+# include <mln/trait/windows.hh>
+# include <mln/metal/is_a.hh>
+# include <mln/metal/bexpr.hh>
+
+
+
+namespace mln
+{
+
+ // Forward declaration.
+ template <typename E> struct Window;
+ template <typename E> struct Weighted_Window;
+ template <typename E> struct Neighborhood;
+
+
+ namespace trait
+ {
+
+ namespace window
+ {
+
+ template <typename T>
+ void print(std::ostream& ostr = std::cout);
+
+ template <typename T>
+ void print(const Neighborhood<T>& nbh, std::ostream& ostr =
std::cout);
+
+ template <typename T>
+ void print(const Window<T>& win, std::ostream& ostr = std::cout);
+
+ template <typename T>
+ void print(const Weighted_Window<T>& w_win, std::ostream& ostr =
std::cout);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T>
+ inline
+ void print(std::ostream& ostr)
+ {
+ metal::or_< mlc_is_a(T, Neighborhood),
+ metal::or_< mlc_is_a(T, Window),
+ mlc_is_a(T, Weighted_Window) >
+ >::check();
+ typedef mln::trait::window_<T> the;
+ ostr << "{ "
+ << typename the::size() .name() << ", "
+ << typename the::support() .name() << ", "
+ << typename the::definition() .name() << " }" <<
std::endl;
+ }
+
+ template <typename T>
+ inline
+ void print(const Neighborhood<T>&, std::ostream& ostr)
+ {
+ print<T>(ostr);
+ }
+
+ template <typename T>
+ inline
+ void print(const Window<T>&, std::ostream& ostr)
+ {
+ print<T>(ostr);
+ }
+
+ template <typename T>
+ inline
+ void print(const Weighted_Window<T>&, std::ostream& ostr)
+ {
+ print<T>(ostr);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::trait::window
+
+ } // end of namespace mln::trait
+
+} // end of namespace mln
+
+
+#endif // ! MLN_TRAIT_WINDOW_PRINT_HH
Index: mln/core/macros.hh
--- mln/core/macros.hh (revision 2446)
+++ mln/core/macros.hh (working copy)
@@ -299,6 +299,12 @@
# define mln_r_element_(T) T::r_element
/// \}
+/// Shortcuts to access the regular type associated to T.
+/// \{
+# define mln_regular(T) typename T::regular
+# define mln_regular_(T) T::regular
+/// \}
+
/// Shortcuts to access the result type associated to T.
/// \{
# define mln_result(T) typename T::result
Index: mln/core/neighb.hh
--- mln/core/neighb.hh (revision 2446)
+++ mln/core/neighb.hh (working copy)
@@ -105,6 +105,13 @@
};
+ template <typename W>
+ inline
+ std::ostream& operator<<(std::ostream&ostr, const neighb<W>&
nbh)
+ {
+ return ostr << nbh.win();
+ }
+
namespace convert
{
Index: mln/core/concept/weighted_window.hh
--- mln/core/concept/weighted_window.hh (revision 2446)
+++ mln/core/concept/weighted_window.hh (working copy)
@@ -35,6 +35,7 @@
# include <mln/core/concept/object.hh>
# include <mln/core/concept/iterator.hh>
+# include <mln/trait/windows.hh>
namespace mln
Index: mln/core/concept/object.hh
--- mln/core/concept/object.hh (revision 2446)
+++ mln/core/concept/object.hh (working copy)
@@ -43,6 +43,7 @@
# include <mln/trace/all.hh>
# include <mln/metal/is_a.hh>
# include <mln/metal/is.hh>
+# include <mln/metal/is_not.hh>
# include <mln/metal/ret.hh>
Index: mln/core/concept/neighborhood.hh
--- mln/core/concept/neighborhood.hh (revision 2446)
+++ mln/core/concept/neighborhood.hh (working copy)
@@ -33,6 +33,7 @@
*/
# include <mln/core/concept/object.hh>
+# include <mln/trait/windows.hh>
namespace mln
Index: mln/core/concept/window.hh
--- mln/core/concept/window.hh (revision 2446)
+++ mln/core/concept/window.hh (working copy)
@@ -32,10 +32,13 @@
* \brief Definition of the concept of mln::Window.
*
* \todo Operator== should test if the cmp is possible.
+ *
+ * \todo Activate run_extra() below.
*/
# include <mln/core/concept/object.hh>
# include <mln/core/concept/iterator.hh>
+# include <mln/trait/windows.hh>
# include <mln/core/site_set/p_array.hh>
@@ -82,20 +85,124 @@
bool operator==(const Window<Wl>& lhs, const Window<Wr>& rhs);
+ template <typename W>
+ std::ostream& operator<<(std::ostream& ostr, const Window<W>&
win);
+
+
# ifndef MLN_INCLUDE_ONLY
+ namespace internal
+ {
+
+ // size: fixed or unknown.
+
+ template <typename trait_size, typename E>
+ struct window_size_check
+ {
+ static void run() { /* No requirement. */ }
+ };
+
+ template <typename E>
+ struct window_size_check< mln::trait::window::size::fixed, E >
+ {
+ static void run()
+ {
+ unsigned (E::*m)() const = & E::size;
+ m = 0;
+ }
+ };
+
+ // support: regular or irregular.
+
+ template <typename trait_support, typename E>
+ struct window_support_check
+ {
+ static void run() { /* No requirement. */ }
+ };
+
+ template <typename E>
+ struct window_support_check< mln::trait::window::support::regular, E >
+ {
+ static void run_extra()
+ {
+ bool (E::*m1)() const = &E::is_centered;
+ m1 = 0;
+ bool (E::*m2)() const = &E::is_symmetric;
+ m2 = 0;
+ void (E::*m3)() = &E::sym;
+ m3 = 0;
+ unsigned (E::*m4)() const = &E::delta;
+ m4 = 0;
+ }
+ static void run(mln::trait::window::definition::unique)
+ {
+ typedef mln_dpsite(E) D;
+ const D& (E::*m)(unsigned) const = &E::dp;
+ m = 0;
+ run_extra();
+ }
+ static void run(mln::trait::window::definition::n_ary)
+ {
+ // run_extra();
+ }
+ static void run(mln::trait::window::definition::varying)
+ {
+ /* No requirement. */
+ }
+ static void run()
+ {
+ run(mln_trait_window_definition(E)());
+ }
+ };
+
+ // definition: unique, n_ary, or varying.
+
+ template <typename trait_definition, typename E>
+ struct window_definition_check
+ {
+ static void run() { /* No requirement. */ }
+ };
+
+ template <typename E>
+ struct window_definition_check< mln::trait::window::definition::multiple, E >
+ {
+ static void run()
+ {
+ typedef mln_element(E) W;
+ void (E::*m1)(unsigned, const W&) = &E::set_window;
+ m1 = 0;
+ const W& (E::*m2)(unsigned) const = &E::window;
+ m2 = 0;
+ unsigned (E::*m3)() const = &E::nwindows;
+ m3 = 0;
+ }
+ };
+
+ } // end of namespace mln::internal
+
+
template <typename E>
inline
Window<E>::Window()
{
+ // Check properties.
+ mlc_not_equal( mln_trait_window_size(E), mln::trait::undef )::check();
+ mlc_not_equal( mln_trait_window_support(E), mln::trait::undef )::check();
+ mlc_not_equal( mln_trait_window_definition(E), mln::trait::undef )::check();
+
+ // Check associated types.
typedef mln_site(E) site;
typedef mln_psite(E) psite;
typedef mln_dpsite(E) dpsite;
-
typedef mln_qiter(E) qiter;
typedef mln_fwd_qiter(E) fwd_qiter;
typedef mln_bkd_qiter(E) bkd_qiter;
+
+ // Check methods depending upon properties.
+ internal::window_size_check < mln_trait_window_size(E), E >::run();
+ internal::window_support_check < mln_trait_window_support(E), E >::run();
+ internal::window_definition_check< mln_trait_window_definition(E), E >::run();
}
template <typename Wl, typename Wr>
@@ -105,6 +212,51 @@
return exact(lhs).std_vector() == exact(rhs).std_vector();
}
+
+ // Operator <<.
+
+ namespace internal
+ {
+
+ template <typename W>
+ inline
+ void print(trait::window::definition::unique,
+ std::ostream& ostr, const W& win) // FIXME: Add Window<W> to win?
+ {
+ win.print(ostr);
+ }
+
+ template <typename W>
+ inline
+ void print(trait::window::definition::multiple,
+ std::ostream& ostr, const W& win) // FIXME: Add Window<W> to win?
+ {
+ ostr << "[";
+ const unsigned nw = win.nwindows();
+ for (unsigned w = 0; w < nw; ++w)
+ {
+ ostr << " #" << w << ':';
+ win.window(w).print(ostr);
+ }
+ ostr << " ]";
+ }
+
+ } // end of namespace mln
+
+ template <typename W>
+ inline
+ std::ostream& operator<<(std::ostream& ostr, const Window<W>&
win)
+ {
+ mlc_is(mln_trait_window_support(W),
+ trait::window::support::regular)::check();
+ mlc_is_not(mln_trait_window_definition(W),
+ trait::window::definition::varying)::check();
+ // FIXME: test on is_empty?
+ internal::print(mln_trait_window_definition(W)(),
+ ostr, exact(win));
+ return ostr;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: mln/core/window.hh
--- mln/core/window.hh (revision 2446)
+++ mln/core/window.hh (working copy)
@@ -53,11 +53,28 @@
namespace mln
{
- // Fwd decls.
+ // Forward declarations.
+ template <typename D> class window;
template <typename V> class dpsites_fwd_piter;
template <typename V> class dpsites_bkd_piter;
+
+ namespace trait
+ {
+
+ template <typename D>
+ struct window_< mln::window<D> >
+ {
+ typedef trait::window::size::fixed size;
+ typedef trait::window::support::regular support;
+ typedef trait::window::definition::unique definition;
+ };
+
+ } // end of namespace trait
+
+
+
/*! \brief Generic window class.
*
* This type of window is just like a set of delta-points. The
@@ -68,6 +85,10 @@
{
public:
+ /// Regular window associated type.
+ typedef window<D> regular;
+
+
/*! \brief Constructor without argument.
*
* The constructed window is empty.
@@ -154,17 +175,15 @@
/// Hook to the set of D.
const util::set<D>& dps_hook_() const;
+ /// Print the window definition into \p ostr.
+ void print(std::ostream& ostr) const;
+
private:
util::set<D> dps_;
};
- // FIXME: Doc!
- template <typename D>
- std::ostream& operator<<(std::ostream& ostr, const window<D>&
win);
-
-
/*! \brief Equality comparison between windows \p lhs and \p rhs.
*
@@ -347,15 +366,17 @@
return dps_;
}
- // Operators.
-
template <typename D>
- std::ostream&
- operator<<(std::ostream& ostr, const window<D>& win)
+ inline
+ void
+ window<D>::print(std::ostream& ostr) const
{
- return ostr << win.dps_hook_();
+ ostr << dps_;
}
+
+ // Operators.
+
template <typename D>
bool
operator==(const window<D>& lhs, const window<D>& rhs)
Index: mln/core/internal/classical_window_base.hh
--- mln/core/internal/classical_window_base.hh (revision 2440)
+++ mln/core/internal/classical_window_base.hh (working copy)
@@ -25,16 +25,17 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_CORE_INTERNAL_DPSITES_IMPL_HH
-# define MLN_CORE_INTERNAL_DPSITES_IMPL_HH
+#ifndef MLN_CORE_INTERNAL_CLASSICAL_WINDOW_BASE_HH
+# define MLN_CORE_INTERNAL_CLASSICAL_WINDOW_BASE_HH
-/*! \file mln/core/internal/dpsites_impl.hh
+/*! \file mln/core/internal/classical_window_base.hh
*
* \brief Definition of a base class for classes based on a set of dpoints.
*
- * \todo Rename as dpsites_impl.
- *
* \todo Remove the .vect() method.
+ *
+ * \todo Add a test that overridden delta_() and win.delta() give the
+ * same result.
*/
# include <mln/core/window.hh>
@@ -52,10 +53,15 @@
*
*/
template <typename D, typename E>
- class dpsites_impl
+ class classical_window_base : public window_base<D, E>
{
public:
+
+ /// Regular window associated type.
+ typedef window<D> regular;
+
+
/// Forward site iterator associated type.
typedef dpsites_fwd_piter<E> fwd_qiter;
@@ -66,41 +72,50 @@
typedef fwd_qiter qiter;
- /*! \brief Test if the window is centered.
- *
- * \return True if the delta-point 0 belongs to the window.
- */
- bool is_centered() const;
+ /// Give the number of delta-points.
+ unsigned size() const;
- /*! \brief Test if the window is empty (null size; no delta-point).
- */
+ /// Test if the window is empty (null size; no delta-point).
bool is_empty() const;
- /*! \brief Give the maximum coordinate gap between the window
- center and a window point.
- */
+
+ /// Test if the window is centered; return true.
+ bool is_centered() const;
+
+ /// Test if the window is symmetric; return true.
+ bool is_symmetric() const;
+
+ /// Apply a central symmetry to the target window; a no-op here.
+ void sym();
+
+
+ /// Give the maximum coordinate gap between the window center
+ /// and a window point.
unsigned delta() const;
- /// Give the number of delta-points.
- unsigned size() const;
/// Test if the delta-point \p dp belongs to the window.
bool has(const D& dp) const;
- // Give the \p i-th delta-point.
+ /// Give the \p i-th delta-point.
const D& dp(unsigned i) const;
- // Give the vector of delta-points.
+ /// Give the vector of delta-points.
const std::vector<D>& vect() const;
- // Give the vector of delta-points.
+ /// Give the vector of delta-points.
const std::vector<D>& std_vector() const;
+ /// Print into \p ostr the window definition.
+ void print(std::ostream& ostr) const;
+
protected:
- dpsites_impl();
+ classical_window_base();
void insert(const D& d);
+ unsigned delta_() const; // Default implementation based on win_.
+ void print_(std::ostream& ostr) const; // Default implementation based on
win_.
mln::window<D> win_;
};
@@ -111,43 +126,76 @@
template <typename D, typename E>
inline
- dpsites_impl<D,E>::dpsites_impl()
+ classical_window_base<D,E>::classical_window_base()
{
}
template <typename D, typename E>
inline
- bool dpsites_impl<D,E>::is_centered() const
+ unsigned
+ classical_window_base<D,E>::size() const
{
- return win_.is_centered();
+ return win_.size();
}
template <typename D, typename E>
inline
- bool dpsites_impl<D,E>::is_empty() const
+ bool
+ classical_window_base<D,E>::is_empty() const
{
return win_.is_empty();
}
template <typename D, typename E>
inline
- unsigned dpsites_impl<D,E>::delta() const
+ bool
+ classical_window_base<D,E>::is_centered() const
{
- return win_.delta();
+ mln_invariant(win_.is_centered());
+ return true;
+ }
+
+ template <typename D, typename E>
+ inline
+ bool
+ classical_window_base<D,E>::is_symmetric() const
+ {
+ mln_invariant(win_.is_symmetric());
+ return true;
+ }
+
+ template <typename D, typename E>
+ inline
+ void
+ classical_window_base<D,E>::sym()
+ {
+ mln_invariant(win_.is_symmetric());
+ // No-op.
}
template <typename D, typename E>
inline
unsigned
- dpsites_impl<D,E>::size() const
+ classical_window_base<D,E>::delta() const
{
- return win_.size();
+ // void *v = (void*)(& classical_window_base<D,E>::delta_);
+ // void *w = (void*)(& E::delta_);
+ // std::cout << v << ' ' << w << std::endl;
+ return exact(this)->delta_();
+ }
+
+ template <typename D, typename E>
+ inline
+ unsigned
+ classical_window_base<D,E>::delta_() const
+ {
+ return win_.delta();
}
template <typename D, typename E>
inline
const D&
- dpsites_impl<D,E>::dp(unsigned i) const
+ classical_window_base<D,E>::dp(unsigned i) const
{
mln_precondition(i < size());
return win_.dp(i);
@@ -156,7 +204,7 @@
template <typename D, typename E>
inline
const std::vector<D>&
- dpsites_impl<D,E>::std_vector() const
+ classical_window_base<D,E>::std_vector() const
{
return win_.std_vector();
}
@@ -164,7 +212,7 @@
template <typename D, typename E>
inline
const std::vector<D>&
- dpsites_impl<D,E>::vect() const
+ classical_window_base<D,E>::vect() const
{
return std_vector();
}
@@ -172,7 +220,7 @@
template <typename D, typename E>
inline
bool
- dpsites_impl<D,E>::has(const D& dp) const
+ classical_window_base<D,E>::has(const D& dp) const
{
return win_.has(dp);
}
@@ -180,11 +228,27 @@
template <typename D, typename E>
inline
void
- dpsites_impl<D,E>::insert(const D& d)
+ classical_window_base<D,E>::insert(const D& d)
{
win_.insert(d);
}
+ template <typename D, typename E>
+ inline
+ void
+ classical_window_base<D,E>::print(std::ostream& ostr) const
+ {
+ exact(this)->print_(ostr);
+ }
+
+ template <typename D, typename E>
+ inline
+ void
+ classical_window_base<D,E>::print_(std::ostream& ostr) const
+ {
+ ostr << win_;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace internal
@@ -192,4 +256,4 @@
} // end of namespace mln
-#endif // ! MLN_CORE_INTERNAL_DPSITES_IMPL_HH
+#endif // ! MLN_CORE_INTERNAL_CLASSICAL_WINDOW_BASE_HH
Index: mln/geom/shift.hh
--- mln/geom/shift.hh (revision 2446)
+++ mln/geom/shift.hh (working copy)
@@ -45,27 +45,66 @@
/// Shift a window \p win with a delta-point \p dp.
template <typename W>
- window<mln_dpsite(W)>
+ mln_regular(W)
shift(const Window<W>& win, const mln_dpsite(W)& dp);
# ifndef MLN_INCLUDE_ONLY
+ namespace impl
+ {
+
template <typename W>
inline
- window<mln_dpsite(W)>
- shift(const Window<W>& win_, const mln_dpsite(W)& dp)
+ mln_regular(W)
+ shift_(trait::window::definition::unique,
+ const W& win, const mln_dpsite(W)& dp)
{
- mlc_is_a(mln_site(W), Gpoint)::check();
- const W& win = exact(win_);
-
- window<mln_dpsite(W)> tmp;
+ mlc_is(mln_trait_window_size(W),
+ trait::window::size::fixed)::check();
+ mln_regular(W) tmp;
unsigned n = win.size();
for (unsigned i = 0; i < n; ++i)
tmp.insert(win.dp(i) + dp);
return tmp;
}
+ template <typename W>
+ inline
+ mln_regular(W)
+ shift_(trait::window::definition::multiple,
+ const W& win, const mln_dpsite(W)& dp)
+ {
+ mln_regular(W) tmp(win.function());
+ const unsigned nw = win.nwindows();
+ for (unsigned w = 0; w < nw; ++w)
+ tmp.set_window(w, geom::shift(win.window(w), dp));
+ return tmp;
+ }
+
+ } // end of namespace mln::geom::impl
+
+
+ // Facade.
+ template <typename W>
+ inline
+ mln_regular(W)
+ shift(const Window<W>& win, const mln_dpsite(W)& dp)
+ {
+ trace::entering("geom::shift");
+
+ mlc_is(mln_trait_window_support(W),
+ trait::window::support::regular)::check();
+ mlc_is_not(mln_trait_window_definition(W),
+ trait::window::definition::varying)::check();
+
+ mln_regular(W) tmp = impl::shift_(mln_trait_window_definition(W)(),
+ exact(win), dp);
+
+ trace::exiting("geom::shift");
+ return tmp;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::geom
Index: mln/win/cube3d.hh
--- mln/win/cube3d.hh (revision 2446)
+++ mln/win/cube3d.hh (working copy)
@@ -33,14 +33,16 @@
* \brief Definition of the mln::win::cube3d window.
*/
-# include <mln/core/internal/window_base.hh>
-# include <mln/core/internal/dpsites_impl.hh>
+# include <mln/core/internal/classical_window_base.hh>
# include <mln/core/alias/dpoint3d.hh>
namespace mln
{
+ mln_internal_add_classical_window_trait(cube3d);
+
+
namespace win
{
@@ -63,8 +65,7 @@
* o o o \n
* is defined with length = 3.
*/
- struct cube3d : public internal::window_base< dpoint3d, cube3d >,
- public internal::dpsites_impl< dpoint3d, cube3d >
+ struct cube3d : public internal::classical_window_base< dpoint3d, cube3d >
{
/*! \brief Constructor.
*
@@ -74,18 +75,6 @@
*/
cube3d(unsigned length);
- /*! \brief Test if the window is centered.
- *
- * \return True.
- */
- bool is_centered() const;
-
- /*! \brief Test if the window is symmetric.
- *
- * \return true.
- */
- bool is_symmetric() const;
-
/*! \brief Give the cube length, that is, its height.
*/
unsigned length() const;
@@ -93,29 +82,15 @@
/*! \brief Give the maximum coordinate gap between the window
* center and a window point.
*/
- unsigned delta() const;
+ unsigned delta_() const;
- /// Apply a central symmetry to the target window.
- cube3d& sym();
+ void print_(std::ostream& ostr) const;
protected:
unsigned length_;
};
- /*! \brief Print a cube3d window \p win into the output
- * stream \p ostr.
- *
- * \param[in,out] ostr An output stream.
- * \param[in] win A cube3d window.
- *
- * \return The modified output stream \p ostr.
- *
- * \relates mln::win::cube3d
- */
- std::ostream& operator<<(std::ostream& ostr, const cube3d& win);
-
-
# ifndef MLN_INCLUDE_ONLY
@@ -132,40 +107,21 @@
}
inline
- bool cube3d::is_centered() const
- {
- return true;
- }
-
- inline
- bool cube3d::is_symmetric() const
- {
- return true;
- }
-
- inline
unsigned cube3d::length() const
{
return length_;
}
inline
- unsigned cube3d::delta() const
+ unsigned cube3d::delta_() const
{
return length_ / 2;
}
inline
- cube3d& cube3d::sym()
- {
- return *this;
- }
-
- inline
- std::ostream& operator<<(std::ostream& ostr, const cube3d& win)
+ void cube3d::print_(std::ostream& ostr) const
{
- ostr << "[cube3d: length=" << win.length() <<
']';
- return ostr;
+ ostr << "[cube3d: length=" << length_ << ']';
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/win/line.hh
--- mln/win/line.hh (revision 2446)
+++ mln/win/line.hh (working copy)
@@ -33,14 +33,29 @@
* \brief Definition of the mln::win::line window.
*/
-# include <mln/core/internal/window_base.hh>
-# include <mln/core/internal/dpsites_impl.hh>
+# include <mln/core/internal/classical_window_base.hh>
# include <mln/core/dpoint.hh>
namespace mln
{
+ // Forward declaration.
+ namespace win { template <typename M, unsigned i, typename C> struct line; }
+
+
+ namespace trait
+ {
+
+ template <typename M, unsigned i, typename C>
+ struct window_< mln::win::line<M,i,C> > : classical_window_
+ {
+ };
+
+ } // end of namespace trait
+
+
+
namespace win
{
@@ -56,8 +71,7 @@
* \see mln::win::hline2d for an exemple of his use.
*/
template <typename M, unsigned i, typename C>
- struct line : public internal::window_base< dpoint<M, C>, line<M,i,C>
>,
- public internal::dpsites_impl< dpoint<M, C>, line<M,i,C> >
+ struct line : public internal::classical_window_base< dpoint<M, C>,
line<M,i,C> >
{
/*! \brief Constructor.
*
@@ -67,49 +81,24 @@
*/
line(unsigned length);
- /*! \brief Test if the window is centered.
- *
- * \return True.
- */
- bool is_centered() const;
-
- /*! \brief Test if the window is symmetric.
- *
- * \return true.
- */
- bool is_symmetric() const;
-
- /*! \brief Give the hline length, that is, its width.
- */
+ /// Give the line length.
unsigned length() const;
+ /// Give the line size, that is, its length.
+ unsigned size() const;
+
/*! \brief Give the maximum coordinate gap between the window
* center and a window point.
*/
- unsigned delta() const;
+ unsigned delta_() const;
- /// Apply a central symmetry to the target window.
- line<M,i,C>& sym();
+ void print_(std::ostream& ostr) const;
protected:
unsigned length_;
};
- /*! \brief Print an line window \p win into the output
- * stream \p ostr.
- *
- * \param[in,out] ostr An output stream.
- * \param[in] win An line window.
- *
- * \return The modified output stream \p ostr.
- *
- * \relates mln::win::line
- */
- template <typename M, unsigned i, typename C>
- std::ostream& operator<<(std::ostream& ostr, const
line<M,i,C>& win);
-
-
# ifndef MLN_INCLUDE_ONLY
@@ -133,20 +122,6 @@
template <typename M, unsigned i, typename C>
inline
- bool line<M,i,C>::is_centered() const
- {
- return true;
- }
-
- template <typename M, unsigned i, typename C>
- inline
- bool line<M,i,C>::is_symmetric() const
- {
- return true;
- }
-
- template <typename M, unsigned i, typename C>
- inline
unsigned line<M,i,C>::length() const
{
return length_;
@@ -154,24 +129,24 @@
template <typename M, unsigned i, typename C>
inline
- unsigned line<M,i,C>::delta() const
+ unsigned line<M,i,C>::size() const
{
- return length_ / 2;
+ return length_;
}
template <typename M, unsigned i, typename C>
inline
- line<M,i,C>& line<M,i,C>::sym()
+ unsigned line<M,i,C>::delta_() const
{
- return *this;
+ return length_ / 2;
}
template <typename M, unsigned i, typename C>
inline
- std::ostream& operator<<(std::ostream& ostr, const
line<M,i,C>& win)
+ void
+ line<M,i,C>::print_(std::ostream& ostr) const
{
- ostr << "[line: length=" << win.length() <<
']';
- return ostr;
+ ostr << "[line: length=" << length_ << ']';
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/win/rectangle2d.hh
--- mln/win/rectangle2d.hh (revision 2446)
+++ mln/win/rectangle2d.hh (working copy)
@@ -35,8 +35,7 @@
* \todo Reactivate includes at EOF.
*/
-# include <mln/core/internal/window_base.hh>
-# include <mln/core/internal/dpsites_impl.hh>
+# include <mln/core/internal/classical_window_base.hh>
# include <mln/core/alias/dpoint2d.hh>
# include <mln/core/def/coord.hh>
@@ -44,6 +43,9 @@
namespace mln
{
+ mln_internal_add_classical_window_trait(rectangle2d);
+
+
namespace win
{
@@ -58,8 +60,7 @@
* o o o o o \n
* is defined with height = 3 and width = 5.
*/
- struct rectangle2d : public internal::window_base< dpoint2d, rectangle2d >,
- public internal::dpsites_impl< dpoint2d, rectangle2d >
+ struct rectangle2d : public internal::classical_window_base< dpoint2d, rectangle2d
>
{
/*! \brief Constructor.
*
@@ -71,18 +72,6 @@
rectangle2d(unsigned height, unsigned width);
- /*! \brief Test if the window is centered.
- *
- * \return True.
- */
- bool is_centered() const;
-
- /*! \brief Test if the window is symmetric.
- *
- * \return true.
- */
- bool is_symmetric() const;
-
/// Give the rectangle height.
unsigned height() const;
@@ -95,34 +84,20 @@
/*! \brief Give the maximum coordinate gap between the window
* center and a window point.
*/
- unsigned delta() const;
-
- /// Apply a central symmetry to the target window; a no-op here.
- void sym();
+ unsigned delta_() const;
/// Give the std vector of delta-points.
const std::vector<dpoint2d>& std_vector() const;
+ void print_(std::ostream& ostr) const;
+
protected:
unsigned height_, width_;
};
- /*! \brief Print a rectangle window \p win into the output stream \p
- * ostr.
- *
- * \param[in,out] ostr An output stream.
- * \param[in] win A rectangle window.
- *
- * \return The modified output stream \p ostr.
- *
- * \relates mln::win::rectangle2d
- */
- std::ostream& operator<<(std::ostream& ostr, const rectangle2d&
win);
-
-
# ifndef MLN_INCLUDE_ONLY
@@ -141,18 +116,6 @@
}
inline
- bool rectangle2d::is_centered() const
- {
- return true;
- }
-
- inline
- bool rectangle2d::is_symmetric() const
- {
- return true;
- }
-
- inline
unsigned rectangle2d::height() const
{
return height_;
@@ -171,19 +134,12 @@
}
inline
- unsigned rectangle2d::delta() const
+ unsigned rectangle2d::delta_() const
{
return width_ > height_ ? width_ / 2 : height_ / 2;
}
inline
- void
- rectangle2d::sym()
- {
- // No-op.
- }
-
- inline
const std::vector<dpoint2d>&
rectangle2d::std_vector() const
{
@@ -191,10 +147,10 @@
}
inline
- std::ostream& operator<<(std::ostream& ostr, const rectangle2d&
win)
+ void
+ rectangle2d::print_(std::ostream& ostr) const
{
- ostr << "[rectangle2d: width=" << win.width() <<
", height=" << win.height() << ']';
- return ostr;
+ ostr << "[rectangle2d: width=" << width_ << ",
height=" << height_ << ']';
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/win/diag2d.hh
--- mln/win/diag2d.hh (revision 2446)
+++ mln/win/diag2d.hh (working copy)
@@ -33,14 +33,16 @@
* \brief Definition of the mln::win::diag2d window.
*/
-# include <mln/core/internal/window_base.hh>
-# include <mln/core/internal/dpsites_impl.hh>
+# include <mln/core/internal/classical_window_base.hh>
# include <mln/core/alias/dpoint2d.hh>
namespace mln
{
+ mln_internal_add_classical_window_trait(diag2d);
+
+
namespace win
{
@@ -57,8 +59,7 @@
* o \n
* is defined with length = 5.
*/
- struct diag2d : public internal::window_base< dpoint2d, diag2d >,
- public internal::dpsites_impl< dpoint2d, diag2d >
+ struct diag2d : public internal::classical_window_base< dpoint2d, diag2d >
{
/*! \brief Constructor.
*
@@ -68,18 +69,6 @@
*/
diag2d(unsigned length);
- /*! \brief Test if the window is centered.
- *
- * \return True.
- */
- bool is_centered() const;
-
- /*! \brief Test if the window is symmetric.
- *
- * \return true.
- */
- bool is_symmetric() const;
-
/*! \brief Give the diagonal length, that is, its width.
*/
unsigned length() const;
@@ -87,29 +76,15 @@
/*! \brief Give the maximum coordinate gap between the window
* center and a window point.
*/
- unsigned delta() const;
+ unsigned delta_() const;
- /// Apply a central symmetry to the target window.
- diag2d& sym();
+ void print_(std::ostream& ostr) const;
protected:
unsigned length_;
};
- /*! \brief Print an diagonal line window \p win into the output
- * stream \p ostr.
- *
- * \param[in,out] ostr An output stream.
- * \param[in] win A diagonal line window.
- *
- * \return The modified output stream \p ostr.
- *
- * \relates mln::win::diag2d
- */
- std::ostream& operator<<(std::ostream& ostr, const diag2d& win);
-
-
# ifndef MLN_INCLUDE_ONLY
@@ -124,40 +99,21 @@
}
inline
- bool diag2d::is_centered() const
- {
- return true;
- }
-
- inline
- bool diag2d::is_symmetric() const
- {
- return true;
- }
-
- inline
unsigned diag2d::length() const
{
return length_;
}
inline
- unsigned diag2d::delta() const
+ unsigned diag2d::delta_() const
{
return length_ / 2;
}
inline
- diag2d& diag2d::sym()
- {
- return *this;
- }
-
- inline
- std::ostream& operator<<(std::ostream& ostr, const diag2d& win)
+ void diag2d::print_(std::ostream& ostr) const
{
- ostr << "[diag 2d: length=" << win.length() <<
']';
- return ostr;
+ ostr << "[diag 2d: length=" << length_ << ']';
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/win/backdiag2d.hh
--- mln/win/backdiag2d.hh (revision 2446)
+++ mln/win/backdiag2d.hh (working copy)
@@ -33,14 +33,16 @@
* \brief Definition of the mln::win::backdiag2d window.
*/
-# include <mln/core/internal/window_base.hh>
-# include <mln/core/internal/dpsites_impl.hh>
+# include <mln/core/internal/classical_window_base.hh>
# include <mln/core/alias/dpoint2d.hh>
namespace mln
{
+ mln_internal_add_classical_window_trait(backdiag2d);
+
+
namespace win
{
@@ -57,8 +59,7 @@
* o \n
* is defined with length = 5.
*/
- struct backdiag2d : public internal::window_base< dpoint2d, backdiag2d >,
- public internal::dpsites_impl< dpoint2d, backdiag2d >
+ struct backdiag2d : public internal::classical_window_base< dpoint2d, backdiag2d
>
{
/*! \brief Constructor.
*
@@ -68,18 +69,6 @@
*/
backdiag2d(unsigned length);
- /*! \brief Test if the window is centered.
- *
- * \return True.
- */
- bool is_centered() const;
-
- /*! \brief Test if the window is symmetric.
- *
- * \return true.
- */
- bool is_symmetric() const;
-
/*! \brief Give the diagonal length, that is, its width.
*/
unsigned length() const;
@@ -87,29 +76,15 @@
/*! \brief Give the maximum coordinate gap between the window
* center and a window point.
*/
- unsigned delta() const;
+ unsigned delta_() const;
- /// Apply a central symmetry to the target window.
- backdiag2d& sym();
+ void print_(std::ostream& ostr) const;
protected:
unsigned length_;
};
- /*! \brief Print an diagonal line window \p win into the output
- * stream \p ostr.
- *
- * \param[in,out] ostr An output stream.
- * \param[in] win A diagonal line window.
- *
- * \return The modified output stream \p ostr.
- *
- * \relates mln::win::backdiag2d
- */
- std::ostream& operator<<(std::ostream& ostr, const backdiag2d&
win);
-
-
# ifndef MLN_INCLUDE_ONLY
@@ -124,40 +99,21 @@
}
inline
- bool backdiag2d::is_centered() const
- {
- return true;
- }
-
- inline
- bool backdiag2d::is_symmetric() const
- {
- return true;
- }
-
- inline
unsigned backdiag2d::length() const
{
return length_;
}
inline
- unsigned backdiag2d::delta() const
+ unsigned backdiag2d::delta_() const
{
return length_ / 2;
}
inline
- backdiag2d& backdiag2d::sym()
- {
- return *this;
- }
-
- inline
- std::ostream& operator<<(std::ostream& ostr, const backdiag2d&
win)
+ void backdiag2d::print_(std::ostream& ostr) const
{
- ostr << "[diag 2d: length=" << win.length() <<
']';
- return ostr;
+ ostr << "[backdiag 2d: length=" << length_ <<
']';
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/win/multiple.hh
--- mln/win/multiple.hh (revision 2446)
+++ mln/win/multiple.hh (working copy)
@@ -42,13 +42,33 @@
namespace mln
{
+ // Forward declarations.
namespace win
{
-
- // Forward declaration.
+ template <typename W, typename F> class multiple;
template <typename W, typename F> class multiple_qiter;
+ }
+
+ namespace trait
+ {
+
+ template <typename W, typename F>
+ struct window_< win::multiple<W,F> >
+ {
+ typedef trait::window::size::fixed size;
+ typedef trait::window::support::regular support;
+ typedef trait::window::definition::n_ary definition;
+ };
+
+ } // end of namespace trait
+
+
+
+ namespace win
+ {
+
template <typename W, typename F>
class multiple : public internal::window_base< mln_dpsite(W), multiple<W,F>
>
{
@@ -58,10 +78,14 @@
typedef mln_psite(W) psite;
typedef mln_site(W) site;
+ typedef multiple< window<dpsite>, F > regular;
+
typedef multiple_qiter<W,F> fwd_qiter;
typedef multiple_qiter<W,F> bkd_qiter;
typedef multiple_qiter<W,F> qiter;
+ typedef W element;
+
multiple();
multiple(const F& f);
@@ -72,9 +96,13 @@
const W& window(unsigned i) const;
+ unsigned nwindows() const;
+
+ const F& function() const;
+
unsigned size() const;
- unsigned size_around(const mln_psite(W)& p) const;
+// unsigned size_around(const mln_psite(W)& p) const;
const mln_dpsite(W)& ith_dp_around(unsigned i, const mln_psite(W)& p)
const;
@@ -86,11 +114,9 @@
util::array<W> win_;
F f_;
- unsigned size_;
};
-
template <typename W, typename F>
class multiple_qiter
: public internal::site_relative_iterator_base< multiple<W,F>,
@@ -120,7 +146,8 @@
private:
unsigned i_;
- unsigned n_() const;
+ unsigned size_;
+// unsigned n_() const;
};
@@ -148,7 +175,7 @@
bool
multiple<W,F>::is_empty() const
{
- return size_ == 0;
+ return win_.is_empty();
}
template <typename W, typename F>
@@ -157,6 +184,8 @@
multiple<W,F>::set_window(unsigned i, const W& win)
{
mln_precondition(i == win_.nelements());
+ if (i >= 1)
+ mln_precondition(win.size() == win_[0].size());
win_.append(win);
}
@@ -172,9 +201,25 @@
template <typename W, typename F>
inline
unsigned
+ multiple<W,F>::nwindows() const
+ {
+ return win_.nelements();
+ }
+
+ template <typename W, typename F>
+ inline
+ const F&
+ multiple<W,F>::function() const
+ {
+ return f_;
+ }
+
+ template <typename W, typename F>
+ inline
+ unsigned
multiple<W,F>::size() const
{
- mln_precondition(win_.nelements() >= 1);
+ mln_precondition(win_.nelements() >= 2); // Multiple cannot be just 1 element.
unsigned s = win_[0].size();
for (unsigned i = 1; i < win_.nelements(); ++i)
mln_precondition(win_[i].size() == s);
@@ -205,14 +250,14 @@
return true;
}
- template <typename W, typename F>
- inline
- unsigned
- multiple<W,F>::size_around(const mln_psite(W)& p) const
- {
- mln_precondition(f_(p) < win_.nelements());
- return win_[f_(p)].size();
- }
+// template <typename W, typename F>
+// inline
+// unsigned
+// multiple<W,F>::size_around(const mln_psite(W)& p) const
+// {
+// mln_precondition(f_(p) < win_.nelements());
+// return win_[f_(p)].size();
+// }
template <typename W, typename F>
inline
@@ -242,6 +287,7 @@
// We have to first change the center so that 'invalidate' can
// work when changing the target.
this->change_target(w);
+ size_ = w.size(); // FIXME: In a local change_target!
}
template <typename W, typename F>
@@ -249,7 +295,7 @@
bool
multiple_qiter<W,F>::is_valid_() const
{
- return i_ < n_();
+ return i_ < size_;
}
template <typename W, typename F>
@@ -257,7 +303,7 @@
void
multiple_qiter<W,F>::invalidate_()
{
- i_ = n_();
+ i_ = size_;
}
template <typename W, typename F>
@@ -284,13 +330,13 @@
return *this->c_ + this->s_->ith_dp_around(i_, *this->c_);
}
- template <typename W, typename F>
- inline
- unsigned
- multiple_qiter<W,F>::n_() const
- {
- return this->s_->size_around(*this->c_);
- }
+// template <typename W, typename F>
+// inline
+// unsigned
+// multiple_qiter<W,F>::size_() const
+// {
+// return this->s_->size_around(*this->c_);
+// }
# endif // ! MLN_INCLUDE_ONLY
Index: mln/win/cuboid3d.hh
--- mln/win/cuboid3d.hh (revision 2446)
+++ mln/win/cuboid3d.hh (working copy)
@@ -31,14 +31,16 @@
/// \file mln/win/cuboid3d.hh
/// \brief Definition of the mln::win::cuboid3d window.
-# include <mln/core/internal/window_base.hh>
-# include <mln/core/internal/dpsites_impl.hh>
+# include <mln/core/internal/classical_window_base.hh>
# include <mln/core/alias/dpoint3d.hh>
namespace mln
{
+ mln_internal_add_classical_window_trait(cuboid3d);
+
+
namespace win
{
@@ -73,8 +75,7 @@
Reference:
http://en.wikipedia.org/wiki/Cuboid
*/
- struct cuboid3d : public internal::window_base< dpoint3d, cuboid3d >,
- public internal::dpsites_impl< dpoint3d, cuboid3d >
+ struct cuboid3d : public internal::classical_window_base< dpoint3d, cuboid3d >
{
/// \brief Constructor.
///
@@ -86,16 +87,6 @@
cuboid3d(unsigned depth, unsigned height, unsigned width);
- /// Properties of the window.
- /// \{
- /// \brief Test if the window is centered.
- /// \return \c true (always).
- bool is_centered() const;
- /// \brief Test if the window is symmetric.
- /// \return \c true (always).
- bool is_symmetric() const;
- /// \}
-
/// Accessors.
/// \{
/// \brief Return the depth of the cuboid.
@@ -111,10 +102,9 @@
/// \brief Give the maximum coordinate gap between the center of
/// the window and a point of the window.
- unsigned delta() const;
+ unsigned delta_() const;
- /// Apply a central symmetry to the target window.
- cuboid3d& sym();
+ void print_(std::ostream& ostr) const;
protected:
/// The depth of the cuboid (expressed as a number of slices).
@@ -126,17 +116,6 @@
};
- /// \brief Print a cuboid window \a win into the output stream \a ostr.
- ///
- /// \param[in,out] ostr An output stream.
- /// \param[in] win A cuboid window.
- ///
- /// \return The modified output stream \a ostr.
- ///
- /// \relates mln::win::cuboid3d
- std::ostream& operator<<(std::ostream& ostr, const cuboid3d& win);
-
-
# ifndef MLN_INCLUDE_ONLY
@@ -157,20 +136,6 @@
}
inline
- bool
- cuboid3d::is_centered() const
- {
- return true;
- }
-
- inline
- bool
- cuboid3d::is_symmetric() const
- {
- return true;
- }
-
- inline
unsigned
cuboid3d::depth() const
{
@@ -200,7 +165,7 @@
inline
unsigned
- cuboid3d::delta() const
+ cuboid3d::delta_() const
{
if (depth_ > height_)
if (depth_ > width_)
@@ -219,20 +184,12 @@
}
inline
- cuboid3d&
- cuboid3d::sym()
- {
- return *this;
- }
-
- inline
- std::ostream&
- operator<<(std::ostream& ostr, const cuboid3d& win)
+ void
+ cuboid3d::print_(std::ostream& ostr) const
{
- ostr << "[cuboid3d: width=" << win.depth()
- << ", depth=" << win.width()
- << ", height=" << win.height() << ']';
- return ostr;
+ ostr << "[cuboid3d: width=" << depth_
+ << ", depth=" << width_
+ << ", height=" << height_ << ']';
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/win/octagon2d.hh
--- mln/win/octagon2d.hh (revision 2446)
+++ mln/win/octagon2d.hh (working copy)
@@ -33,14 +33,16 @@
* \brief Definition of the mln::win::octagon2d window.
*/
-# include <mln/core/internal/window_base.hh>
-# include <mln/core/internal/dpsites_impl.hh>
+# include <mln/core/internal/classical_window_base.hh>
# include <mln/core/alias/dpoint2d.hh>
namespace mln
{
+ mln_internal_add_classical_window_trait(octagon2d);
+
+
namespace win
{
@@ -61,8 +63,7 @@
* o o o \n
* is defined with L = 7 (l = 1).
*/
- struct octagon2d : public internal::window_base< dpoint2d, octagon2d >,
- public internal::dpsites_impl< dpoint2d, octagon2d >
+ struct octagon2d : public internal::classical_window_base< dpoint2d, octagon2d
>
{
/*! \brief Constructor.
*
@@ -72,18 +73,6 @@
*/
octagon2d(unsigned length);
- /*! \brief Test if the window is centered.
- *
- * \return True.
- */
- bool is_centered() const;
-
- /*! \brief Test if the window is symmetric.
- *
- * \return true.
- */
- bool is_symmetric() const;
-
/*! \brief Give the octagon length, that is, its width.
*/
unsigned length() const;
@@ -91,33 +80,19 @@
/*! \brief Give the maximum coordinate gap between the window
* center and a window point.
*/
- unsigned delta() const;
+ unsigned delta_() const;
/*! \brief Give the area.
*/
unsigned area() const;
- /// Apply a central symmetry to the target window.
- octagon2d& sym();
+ void print_(std::ostream& ostr) const;
protected:
unsigned length_;
};
- /*! \brief Print an octagon window \p win into the output
- * stream \p ostr.
- *
- * \param[in,out] ostr An output stream.
- * \param[in] win An octagon window.
- *
- * \return The modified output stream \p ostr.
- *
- * \relates mln::win::octagon2d
- */
- std::ostream& operator<<(std::ostream& ostr, const octagon2d&
win);
-
-
# ifndef MLN_INCLUDE_ONLY
@@ -153,25 +128,13 @@
}
inline
- bool octagon2d::is_centered() const
- {
- return true;
- }
-
- inline
- bool octagon2d::is_symmetric() const
- {
- return true;
- }
-
- inline
unsigned octagon2d::length() const
{
return length_;
}
inline
- unsigned octagon2d::delta() const
+ unsigned octagon2d::delta_() const
{
return length_ / 2;
}
@@ -184,16 +147,9 @@
}
inline
- octagon2d& octagon2d::sym()
- {
- return *this;
- }
-
- inline
- std::ostream& operator<<(std::ostream& ostr, const octagon2d& win)
+ void octagon2d::print_(std::ostream& ostr) const
{
- ostr << "[octagon2d: length=" << win.length() <<
']';
- return ostr;
+ ostr << "[octagon2d: length=" << length_ <<
']';
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/win/disk2d.hh
--- mln/win/disk2d.hh (revision 2446)
+++ mln/win/disk2d.hh (working copy)
@@ -33,14 +33,16 @@
* \brief Definition of the mln::win::disk2d window.
*/
-# include <mln/core/internal/window_base.hh>
-# include <mln/core/internal/dpsites_impl.hh>
+# include <mln/core/internal/classical_window_base.hh>
# include <mln/core/alias/dpoint2d.hh>
namespace mln
{
+ mln_internal_add_classical_window_trait(disk2d);
+
+
namespace win
{
@@ -49,8 +51,7 @@
* An disk2d is centered and symmetric.
*
*/
- struct disk2d : public internal::window_base< dpoint2d, disk2d >,
- public internal::dpsites_impl< dpoint2d, disk2d >
+ struct disk2d : public internal::classical_window_base< dpoint2d, disk2d >
{
/*! \brief Constructor.
*
@@ -59,48 +60,22 @@
*/
disk2d(unsigned length);
- /*! \brief Test if the window is centered.
- *
- * \return True.
- */
- bool is_centered() const;
-
- /*! \brief Test if the window is symmetric.
- *
- * \return true.
- */
- bool is_symmetric() const;
-
- /*! \brief Give the disk length, that is, its width.
+ /*! \brief Give the disk diameter.
*/
unsigned length() const;
/*! \brief Give the maximum coordinate gap between the window
* center and a window point.
*/
- unsigned delta() const;
+ unsigned delta_() const;
- /// Apply a central symmetry to the target window.
- disk2d& sym();
+ void print_(std::ostream& ostr) const;
protected:
unsigned length_;
};
- /*! \brief Print an disk window \p win into the output
- * stream \p ostr.
- *
- * \param[in,out] ostr An output stream.
- * \param[in] win A disk window.
- *
- * \return The modified output stream \p ostr.
- *
- * \relates mln::win::disk2d
- */
- std::ostream& operator<<(std::ostream& ostr, const disk2d& win);
-
-
# ifndef MLN_INCLUDE_ONLY
@@ -118,40 +93,21 @@
}
inline
- bool disk2d::is_centered() const
- {
- return true;
- }
-
- inline
- bool disk2d::is_symmetric() const
- {
- return true;
- }
-
- inline
unsigned disk2d::length() const
{
return length_;
}
inline
- unsigned disk2d::delta() const
+ unsigned disk2d::delta_() const
{
return length_ / 2;
}
inline
- disk2d& disk2d::sym()
- {
- return *this;
- }
-
- inline
- std::ostream& operator<<(std::ostream& ostr, const disk2d& win)
+ void disk2d::print_(std::ostream& ostr) const
{
- ostr << "[disk2d: length=" << win.length() <<
']';
- return ostr;
+ ostr << "[disk2d: length=" << length_ << ']';
}
# endif // ! MLN_INCLUDE_ONLY