URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-04 Simon Nivault <simon.nivault(a)lrde.epita.fr>
Add generic line.
* mln/core/win/line.hh: New.
* mln/core/win/hline2d.hh,
* mln/core/win/vline2d.hh: Now inherit of line.
* tests/win_hline2d.cc: New.
---
mln/core/win/hline2d.hh | 125 +-------------------------------
mln/core/win/line.hh | 185 ++++++++++++++++++++++++++++++++++++++++++++++++
mln/core/win/vline2d.hh | 125 +-------------------------------
tests/win_hline2d.cc | 48 ++++++++++++
4 files changed, 247 insertions(+), 236 deletions(-)
Index: trunk/milena/tests/win_hline2d.cc
===================================================================
--- trunk/milena/tests/win_hline2d.cc (revision 0)
+++ trunk/milena/tests/win_hline2d.cc (revision 1245)
@@ -0,0 +1,48 @@
+// 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.
+
+/*! \file tests/win_diag2d.cc
+ *
+ * \brief Tests on mln::win::diag2d.
+ */
+
+#include <mln/core/win/hline2d.hh>
+
+#include <mln/convert/to_image.hh>
+
+#include <mln/debug/println.hh>
+
+int main()
+{
+ using namespace mln;
+
+ const unsigned l = 5;
+ win::hline2d hline(l);
+
+ debug::println(convert::to_image(hline));
+}
+
Index: trunk/milena/mln/core/win/vline2d.hh
===================================================================
--- trunk/milena/mln/core/win/vline2d.hh (revision 1244)
+++ trunk/milena/mln/core/win/vline2d.hh (revision 1245)
@@ -33,10 +33,8 @@
* \brief Definition of the mln::win::vline2d window.
*/
-# include <mln/core/concept/window.hh>
-# include <mln/core/internal/dpoints_base.hh>
-# include <mln/core/dpoint2d.hh>
-# include <mln/core/dpoints_piter.hh>
+# include <mln/core/win/line.hh>
+# include <mln/core/grids.hh>
namespace mln
@@ -56,123 +54,14 @@
* o \n
* is defined with length = 5.
*/
- struct vline2d : public Window< vline2d >,
- public internal::dpoints_base_< dpoint2d, vline2d >
+ struct vline2d : public line<grid::square, 0, vline2d>
{
- /// Point associated type.
- typedef point2d point;
-
- /// Dpoint associated type.
- typedef dpoint2d dpoint;
-
- /*! \brief Point_Iterator type to browse a vline such as: "for each row
- * (increasing), for each column (increasing)."
- */
- typedef dpoints_fwd_piter<dpoint2d> fwd_qiter;
-
- /*! \brief Point_Iterator type to browse a vline such as: "for each row
- * (decreasing), for each column (decreasing)."
- */
- typedef dpoints_bkd_piter<dpoint2d> bkd_qiter;
-
- /*! \brief Same as fwd_qiter.
- */
- typedef fwd_qiter qiter;
-
- /*! \brief Constructor.
- *
- * \param[in] length Length, thus height, of the vertical line.
- *
- * \pre \p length is odd.
- */
- vline2d(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 vline length, that is, its height.
- */
- unsigned length() const;
-
- /*! \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.
- vline2d& sym();
-
- protected:
- unsigned length_;
- };
-
-
- /*! \brief Print a vertical 2D line window \p win into the output
- * stream \p ostr.
- *
- * \param[in,out] ostr An output stream.
- * \param[in] win A vertical 2D line window.
- *
- * \return The modified output stream \p ostr.
- *
- * \relates mln::win::vline2d
- */
- std::ostream& operator<<(std::ostream& ostr, const vline2d& win);
-
-
-
-# ifndef MLN_INCLUDE_ONLY
-
- vline2d::vline2d(unsigned length)
- : length_(length)
+ // Ctor.
+ vline2d(unsigned length)
+ : line<grid::square, 0, vline2d>(length)
{
- mln_precondition(length % 2 == 1);
- const int drow = length / 2;
- for (int row = - drow; row <= drow; ++row)
- insert(make::dpoint2d(row, 0));
}
-
- bool vline2d::is_centered() const
- {
- return true;
- }
-
- bool vline2d::is_symmetric() const
- {
- return true;
- }
-
- unsigned vline2d::length() const
- {
- return length_;
- }
-
- unsigned vline2d::delta() const
- {
- return length_ / 2;
- }
-
- vline2d& vline2d::sym()
- {
- return *this;
- }
-
- std::ostream& operator<<(std::ostream& ostr, const vline2d& win)
- {
- ostr << "[line2d: length=" << win.length() <<
']';
- return ostr;
- }
-
-# endif // ! MLN_INCLUDE_ONLY
+ };
} // end of namespace mln::win
Index: trunk/milena/mln/core/win/hline2d.hh
===================================================================
--- trunk/milena/mln/core/win/hline2d.hh (revision 1244)
+++ trunk/milena/mln/core/win/hline2d.hh (revision 1245)
@@ -33,10 +33,8 @@
* \brief Definition of the mln::win::hline2d window.
*/
-# include <mln/core/concept/window.hh>
-# include <mln/core/internal/dpoints_base.hh>
-# include <mln/core/dpoint2d.hh>
-# include <mln/core/dpoints_piter.hh>
+# include <mln/core/win/line.hh>
+# include <mln/core/grids.hh>
namespace mln
@@ -54,123 +52,14 @@
* o o x o o \n
* is defined with length = 5.
*/
- struct hline2d : public Window< hline2d >,
- public internal::dpoints_base_< dpoint2d, hline2d >
+ struct hline2d : public line<grid::square, 1, hline2d>
{
- /// Point associated type.
- typedef point2d point;
-
- /// Dpoint associated type.
- typedef dpoint2d dpoint;
-
- /*! \brief Point_Iterator type to browse a hline such as: "for each row
- * (increasing), for each column (increasing)."
- */
- typedef dpoints_fwd_piter<dpoint2d> fwd_qiter;
-
- /*! \brief Point_Iterator type to browse a hline such as: "for each row
- * (decreasing), for each column (decreasing)."
- */
- typedef dpoints_bkd_piter<dpoint2d> bkd_qiter;
-
- /*! \brief Same as fwd_qiter.
- */
- typedef fwd_qiter qiter;
-
- /*! \brief Constructor.
- *
- * \param[in] length Length, thus width, of the horizontal line.
- *
- * \pre \p length is odd.
- */
- hline2d(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.
- */
- unsigned length() const;
-
- /*! \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.
- hline2d& sym();
-
- protected:
- unsigned length_;
- };
-
-
- /*! \brief Print an horizontal 2D line window \p win into the output
- * stream \p ostr.
- *
- * \param[in,out] ostr An output stream.
- * \param[in] win An horizontal 2D line window.
- *
- * \return The modified output stream \p ostr.
- *
- * \relates mln::win::hline2d
- */
- std::ostream& operator<<(std::ostream& ostr, const hline2d& win);
-
-
-
-# ifndef MLN_INCLUDE_ONLY
-
- hline2d::hline2d(unsigned length)
- : length_(length)
+ // Ctor.
+ hline2d(unsigned length)
+ : line<grid::square, 1, hline2d>(length)
{
- mln_precondition(length % 2 == 1);
- const int dcol = length / 2;
- for (int col = - dcol; col <= dcol; ++col)
- insert(make::dpoint2d(0, col));
}
-
- bool hline2d::is_centered() const
- {
- return true;
- }
-
- bool hline2d::is_symmetric() const
- {
- return true;
- }
-
- unsigned hline2d::length() const
- {
- return length_;
- }
-
- unsigned hline2d::delta() const
- {
- return length_ / 2;
- }
-
- hline2d& hline2d::sym()
- {
- return *this;
- }
-
- std::ostream& operator<<(std::ostream& ostr, const hline2d& win)
- {
- ostr << "[line2d: length=" << win.length() <<
']';
- return ostr;
- }
-
-# endif // ! MLN_INCLUDE_ONLY
+ };
} // end of namespace mln::win
Index: trunk/milena/mln/core/win/line.hh
===================================================================
--- trunk/milena/mln/core/win/line.hh (revision 0)
+++ trunk/milena/mln/core/win/line.hh (revision 1245)
@@ -0,0 +1,185 @@
+// 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 MLN_CORE_WIN_LINE_HH
+# define MLN_CORE_WIN_LINE_HH
+
+/*! \file mln/core/win/line.hh
+ *
+ * \brief Definition of the mln::win::line window.
+ */
+
+# include <mln/core/concept/window.hh>
+# include <mln/core/internal/dpoints_base.hh>
+# include <mln/core/dpoint.hh>
+# include <mln/core/dpoints_piter.hh>
+
+
+namespace mln
+{
+
+ namespace win
+ {
+
+ template <typename M, unsigned i, typename E>
+ struct line : public Window<E>,
+ public internal::dpoints_base_
+ <dpoint_
+ <M, int>, point_
+ <M, int> >
+ {
+ /// Point associated type.
+ typedef point_<M, int> point;
+
+ /// Dpoint associated type.
+ typedef dpoint_<M, int> dpoint;
+
+ /// Point_Iterator type to browse a line forward
+ typedef dpoints_fwd_piter<dpoint> fwd_qiter;
+
+ /// Point_Iterator type to browse a line backward
+ typedef dpoints_bkd_piter<dpoint> bkd_qiter;
+
+ /// Same as fwd_qiter
+ typedef fwd_qiter qiter;
+
+ /*! \brief Constructor.
+ *
+ * \param[in] length Length of the line.
+ *
+ * \pre \p length is odd.
+ */
+ 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.
+ */
+ unsigned length() const;
+
+ /*! \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.
+ E& sym();
+
+ 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 E>
+ std::ostream& operator<<(std::ostream& ostr, const
line<M,i,E>& win);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename M, unsigned i, typename E>
+ line<M,i,E>::line(unsigned length)
+ : length_(length)
+ {
+ mln_precondition(i < M::dim);
+ mln_precondition(length % 2 == 1);
+ const int dcol = length / 2;
+ for (int col = - dcol; col <= dcol; ++col)
+ {
+ dpoint n;
+ n[i] = col;
+ insert(n);
+ }
+ }
+
+ template <typename M, unsigned i, typename E>
+ bool line<M,i,E>::is_centered() const
+ {
+ return true;
+ }
+
+ template <typename M, unsigned i, typename E>
+ bool line<M,i,E>::is_symmetric() const
+ {
+ return true;
+ }
+
+ template <typename M, unsigned i, typename E>
+ unsigned line<M,i,E>::length() const
+ {
+ return length_;
+ }
+
+ template <typename M, unsigned i, typename E>
+ unsigned line<M,i,E>::delta() const
+ {
+ return length_ / 2;
+ }
+
+ template <typename M, unsigned i, typename E>
+ E& line<M,i,E>::sym()
+ {
+ return exact(*this);
+ }
+
+ template <typename M, unsigned i, typename E>
+ std::ostream& operator<<(std::ostream& ostr, const
line<M,i,E>& win)
+ {
+ ostr << "[line: length=" << win.length() <<
']';
+ return ostr;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::win
+
+} // end of namespace mln
+
+
+
+#endif // ! MLN_CORE_WIN_LINE_HH