URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-28 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add test for mesh image.
* mesh_image.cc: New test for mesh image.
---
mesh_image.cc | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 96 insertions(+)
Index: trunk/milena/tests/mesh_image.cc
===================================================================
--- trunk/milena/tests/mesh_image.cc (revision 0)
+++ trunk/milena/tests/mesh_image.cc (revision 1198)
@@ -0,0 +1,96 @@
+// 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/mesh_image.cc
+ *
+ * \brief Tests on mln::mesh_image.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/core/point2d.hh>
+#include <mln/debug/println.hh>
+#include <mln/util/graph.hh>
+#include <mln/core/mesh_p.hh>
+#include <mln/core/mesh_psite.hh>
+#include <mln/draw/mesh.hh>
+#include <mln/core/mesh_image.hh>
+
+using namespace mln;
+
+int
+main (void)
+{
+ util::graph<void> g;
+
+ g.add_node ();
+ g.add_node ();
+ g.add_node ();
+ g.add_node ();
+ g.add_node ();
+ g.add_node ();
+
+ g.add_edge (0, 1);
+ g.add_edge (1, 2);
+ g.add_edge (2, 3);
+ g.add_edge (1, 3);
+ g.add_edge (4, 5);
+ g.add_edge (1, 4);
+
+ g.consistency ();
+ // g.print_debug ();
+
+ std::vector<point2d> v;
+ v.push_back (make::point2d (1,1));
+ v.push_back (make::point2d (10,1));
+ v.push_back (make::point2d (19,2));
+ v.push_back (make::point2d (19,19));
+ v.push_back (make::point2d (10,10));
+ v.push_back (make::point2d (1,19));
+
+
+ image2d_b<int> ima (20, 20, 1);
+
+ mesh_p<point2d> m(g, v);
+
+ draw::mesh (ima, m, 7, 1);
+
+ std::vector<int> val;
+
+ val.push_back (2);
+ val.push_back (3);
+ val.push_back (4);
+ val.push_back (5);
+ val.push_back (6);
+ val.push_back (7);
+
+ mesh_image<point2d, int> im (m, val);
+
+ draw::mesh (ima, im);
+ debug::println (ima);
+
+ std::cout << im.domain() << std::endl;
+}
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-28 Simon Nivault <simon.nivault(a)lrde.epita.fr>
Add traits for multiply and promotions.
* mln/core/ops.hh: A + B -> B + A, Idem for *.
* mln/core/trait/mult.hh: New.
* mln/core/trait/promote.hh: New.
---
ops.hh | 43 +++++++++++++++++++
trait/mult.hh | 122 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
trait/promote.hh | 106 +++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 271 insertions(+)
Index: trunk/milena/mln/core/trait/mult.hh
===================================================================
--- trunk/milena/mln/core/trait/mult.hh (revision 0)
+++ trunk/milena/mln/core/trait/mult.hh (revision 1197)
@@ -0,0 +1,122 @@
+// Copyright (C) 2006 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_TRAIT_MULT_HH
+# define MLN_TRAIT_MULT_HH
+
+
+# define mln_mult(T, U) typename mln::trait::mult< T , U >::ret
+
+
+
+namespace mln
+{
+
+ namespace metal
+ {
+
+ template <unsigned n, typename T>
+ class vec;
+
+ template <unsigned n, unsigned m, typename T>
+ class mat;
+
+ } // end of namespace mln::metal
+
+ namespace trait
+ {
+
+ template <typename T, typename U>
+ struct mult;
+
+
+ template <>
+ struct mult<int, float>
+ {
+ typedef float ret;
+ };
+ template <>
+ struct mult<float, int>
+ {
+ typedef float ret;
+ };
+
+ template <>
+ struct mult<int, double>
+ {
+ typedef double ret;
+ };
+ template <>
+ struct mult<double, int>
+ {
+ typedef double ret;
+ };
+
+ template <>
+ struct mult<double, float>
+ {
+ typedef double ret;
+ };
+ template <>
+ struct mult<float, double>
+ {
+ typedef double ret;
+ };
+
+ template <unsigned n, typename T, typename U>
+ struct mult<metal::vec<n, T>, U>
+ {
+ typedef metal::vec<n, mln_mult(T, U)> ret;
+ }
+ template <typename U, unsigned n, typename T>
+ struct mult<U, metal::vec<n, T>>
+ {
+ typedef metal::vec<n, mln_mult(T, U)> ret;
+ }
+
+ template <unsigned n, unsigned m, typename T, typename U>
+ struct mult<metal::mat<n, m, T>, U>
+ {
+ typedef metal::mat<n, m, mln_mult(T, U)> ret;
+ }
+ template <typename U, unsigned n, unsigned m, typename T>
+ struct mult<U, metal::mat<n, m, T>>
+ {
+ typedef metal::mat<n, m, mln_mult(T, U)> ret;
+ }
+
+ template <unsigned n, unsigned o, typename T, unsigned m, typename U>
+ struct mult<metal::mat<n, o, T>, metal::mat<o, m, U> >
+ {
+ typedef metal::mat<n, m, mln_mult(T, U)> ret;
+ };
+
+ } // end of namespace mln::trait
+
+} // end of namespace mln
+
+#endif // ! MLN_TRAIT_MULT_HH
Index: trunk/milena/mln/core/trait/promote.hh
===================================================================
--- trunk/milena/mln/core/trait/promote.hh (revision 0)
+++ trunk/milena/mln/core/trait/promote.hh (revision 1197)
@@ -0,0 +1,106 @@
+// Copyright (C) 2006 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_TRAIT_PROMOTE_HH
+# define MLN_TRAIT_PROMOTE_HH
+
+
+# define mln_promote(T, U) typename mln::trait::promote< T , U >::ret
+
+
+
+namespace mln
+{
+
+ namespace metal
+ {
+
+ template <unsigned n, typename T>
+ class vec;
+
+ template <unsigned n, unsigned m, typename T>
+ class mat;
+
+ } // end of namespace mln::metal
+
+ namespace trait
+ {
+
+ template <typename T, typename U>
+ struct promote;
+
+
+ template <>
+ struct promote<int, float>
+ {
+ typedef float ret;
+ };
+ template <>
+ struct promote<float, int>
+ {
+ typedef float ret;
+ };
+
+ template <>
+ struct promote<int, double>
+ {
+ typedef double ret;
+ };
+ template <>
+ struct promote<double, int>
+ {
+ typedef double ret;
+ };
+
+ template <>
+ struct promote<double, float>
+ {
+ typedef double ret;
+ };
+ template <>
+ struct promote<float, double>
+ {
+ typedef double ret;
+ };
+
+ template <unsigned n, typename T, typename U>
+ struct promote<metal::vec<n, T>, metal::vec<n, U> >
+ {
+ typedef metal::vec<n, mln_promote(T, U)> ret;
+ };
+
+ template <unsigned n, unsigned m, typename T, typename U>
+ struct promote<metal::mat<n, m, T>, metal::mat<n, m, U> >
+ {
+ typedef metal::mat<n, m, mln_promote(T, U)> ret;
+ };
+
+ } // end of namespace mln::trait
+
+} // end of namespace mln
+
+#endif // ! MLN_TRAIT_PROMOTE_HH
Index: trunk/milena/mln/core/ops.hh
===================================================================
--- trunk/milena/mln/core/ops.hh (revision 1196)
+++ trunk/milena/mln/core/ops.hh (revision 1197)
@@ -94,6 +94,34 @@
bool operator<=(const Object<O1>& lhs, const Object<O2>& rhs);
+ // Operator +.
+
+ // FIXME: Doc!
+ template <typename O>
+ mlc_bin_arith(int, O)
+ operator+(int lhs, const Object<O>& rhs)
+ {
+ return exact(rhs) + lhs;
+ }
+
+ // FIXME: Doc!
+ template <typename O>
+ mlc_bin_arith(float, O)
+ operator+(float lhs, const Object<O>& rhs)
+ {
+ return exact(rhs) + lhs;
+ }
+
+ // FIXME: Doc!
+ template <typename O>
+ mlc_bin_arith(double, O)
+ operator+(double lhs, const Object<O>& rhs)
+ {
+ return exact(rhs) + lhs;
+ }
+
+ // Operator *.
+
// FIXME: Doc!
template <typename O>
mlc_bin_arith(int, O)
@@ -102,6 +130,21 @@
return exact(rhs) * lhs;
}
+ // FIXME: Doc!
+ template <typename O>
+ mlc_bin_arith(float, O)
+ operator*(float lhs, const Object<O>& rhs)
+ {
+ return exact(rhs) * lhs;
+ }
+
+ // FIXME: Doc!
+ template <typename O>
+ mlc_bin_arith(double, O)
+ operator*(double lhs, const Object<O>& rhs)
+ {
+ return exact(rhs) * lhs;
+ }
# ifndef MLN_INCLUDE_ONLY
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-28 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add mesh.hh in mln/draw.
* mesh.hh: Draw a mesh_image into an image.
---
mesh.hh | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 100 insertions(+)
Index: trunk/milena/mln/draw/mesh.hh
===================================================================
--- trunk/milena/mln/draw/mesh.hh (revision 0)
+++ trunk/milena/mln/draw/mesh.hh (revision 1196)
@@ -0,0 +1,100 @@
+// 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_DRAW_MESH_HH
+# define MLN_DRAW_MESH_HH
+
+/*! \file mln/draw/mesh.hh
+ *
+ * \brief Draw an image of type mesh_image into anothor kind of image.
+ *
+ */
+
+# include <mln/pw/image.hh>
+# include <mln/level/fill.hh>
+# include <mln/draw/line.hh>
+# include <mln/core/mesh_p.hh>
+# include <mln/core/mesh_image.hh>
+
+namespace mln
+{
+ namespace draw
+ {
+
+ template <typename I, typename P>
+ void
+ mesh(Image<I>& ima, const mesh_p<P>& m,
+ mln_value(I) node_v,
+ mln_value(I) link_v);
+
+ template <typename I, typename P, typename V>
+ void
+ mesh(Image<I>& ima, const mesh_image<P, V>& mesh);
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I, typename P>
+ void
+ mesh(Image<I>& ima, const mesh_p<P>& m,
+ mln_value(I) node_v,
+ mln_value(I) link_v)
+ {
+ level::fill(ima, 0);
+
+ for (unsigned i = 0; i < m.gr_.nb_link_; ++i)
+ line (exact(ima),
+ m.loc_[m.gr_.links_[i]->node1],
+ m.loc_[m.gr_.links_[i]->node2],
+ link_v);
+
+ for (unsigned i = 0; i < m.gr_.nb_node_; ++i)
+ exact(ima)(m.loc_[i]) = node_v;
+ }
+
+ template <typename I, typename P, typename V>
+ void
+ mesh(Image<I>& ima, const mesh_image<P, V>& mesh)
+ {
+ level::fill(ima, 0);
+
+ for (unsigned i = 0; i < mesh.domain().gr_.nb_link_; ++i)
+ line (exact(ima),
+ mesh.access_location_link_node1 (i),
+ mesh.access_location_link_node2 (i),
+ 1);
+
+ for (unsigned i = 0; i < mesh.domain().gr_.nb_node_; ++i)
+ exact(ima)(mesh.domain().loc_[i]) = mesh.data_values ()[i];
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of draw
+
+} // end of mln
+
+#endif // MLN_MESH_PSITE_HH
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-28 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add mesh_image in mln/core.
* mesh_image.hh: New class of image.
* mesh_p.hh: New.
* mesh_p_piter.hh: New.
* mesh_psite.hh: New.
---
mesh_image.hh | 177 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
mesh_p.hh | 119 +++++++++++++++++++++++++++++++++++++
mesh_p_piter.hh | 158 +++++++++++++++++++++++++++++++++++++++++++++++++
mesh_psite.hh | 101 +++++++++++++++++++++++++++++++
4 files changed, 555 insertions(+)
Index: trunk/milena/mln/core/mesh_psite.hh
===================================================================
--- trunk/milena/mln/core/mesh_psite.hh (revision 0)
+++ trunk/milena/mln/core/mesh_psite.hh (revision 1195)
@@ -0,0 +1,101 @@
+// 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.
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_MESH_PSITE_HH
+# define MLN_MESH_PSITE_HH
+
+/*! \file mln/core/mesh_p.hh
+ *
+ * \brief Definition of mln::mesh_psite.
+ */
+
+namespace mln
+{
+
+ template<typename P> class mesh_p;
+
+ template<typename P>
+ struct mesh_psite : public Point_Site< mesh_psite<P> >
+ {
+ typedef mln_mesh(P) mesh;
+ enum { dim = P::dim };
+ typedef P point;
+ typedef mln_dpoint(P) dpoint;
+ typedef mln_coord(P) coord;
+
+ mesh_psite(unsigned i, mesh_p<P>* m_ptr);
+ P to_point() const;
+ operator P() const;
+ const point* pointer_() const;
+ coord operator[](unsigned i) const;
+
+ unsigned i_;
+ mesh_p<P>* m_ptr_;
+ };
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template<typename P>
+ mesh_psite<P>::mesh_psite(unsigned i, mesh_p<P>* m_ptr)
+ : i_(i) ,
+ m_ptr_(m_ptr)
+ {
+ }
+
+ template<typename P>
+ P
+ mesh_psite<P>::to_point() const
+ {
+ return m_ptr_->loc_[i_];
+ }
+
+ template<typename P>
+ mesh_psite<P>::operator P() const
+ {
+ return m_ptr_->loc_[i_];
+ }
+
+ template<typename P>
+ const P*
+ mesh_psite<P>::pointer_() const
+ {
+ return 0;
+ }
+
+ template<typename P>
+ mln_coord(P)
+ mesh_psite<P>::operator[](unsigned i) const
+ {
+ return to_point()[i];
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
+} // end of mln
+
+#endif // MLN_MESH_PSITE_HH
Index: trunk/milena/mln/core/mesh_p.hh
===================================================================
--- trunk/milena/mln/core/mesh_p.hh (revision 0)
+++ trunk/milena/mln/core/mesh_p.hh (revision 1195)
@@ -0,0 +1,119 @@
+// 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.
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_MESH_P_HH
+# define MLN_MESH_P_HH
+
+# include <mln/core/concept/point.hh>
+# include <mln/core/internal/point_set_base.hh>
+# include <mln/accu/bbox.hh>
+# include <mln/util/graph.hh>
+# include <mln/core/mesh_psite.hh>
+# include <mln/core/mesh_p_piter.hh>
+
+/*! \file mln/core/mesh_p.hh
+ *
+ * \brief Definition of mln::mesh_p.
+ */
+
+namespace mln
+{
+
+ template<typename P> class mesh_p_piter_;
+
+ template<typename P>
+ struct mesh_p : public internal::point_set_base_< P, mesh_p<P> >
+ {
+ mesh_p (util::graph<void>& gr,
+ std::vector<P>& loc);
+
+ /// Point_Site associated type.
+ typedef mesh_psite<P> psite;
+
+ /// Forward Point_Iterator associated type.
+ typedef mesh_p_piter_<P> fwd_piter;
+
+ /// Backward Point_Iterator associated type.
+ typedef mesh_p_piter_<P> bkd_piter; // FIXME
+
+ std::size_t npoints() const;
+
+ /// Give the exact bounding box.
+ const box_<P>& bbox() const;
+
+ bool has(const psite& p) const;
+
+ util::graph<void> gr_;
+ std::vector<P> loc_;
+ box_<P> bb_;
+ };
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template<typename P>
+ mesh_p<P>::mesh_p (util::graph<void>& gr,
+ std::vector<P>& loc)
+ : gr_ (gr),
+ loc_ (loc)
+ {
+ accu::bbox<P> a;
+ for (unsigned i = 0; i < loc.size(); ++i)
+ a.take(loc[i]);
+ bb_ = a.to_result();
+ }
+
+ template<typename P>
+ std::size_t
+ mesh_p<P>::npoints() const
+ {
+ return this->gr_.nb_node_;
+ }
+
+ template<typename P>
+ const box_<P>&
+ mesh_p<P>::bbox() const
+ {
+ return bb_;
+ }
+
+ template<typename P>
+ bool
+ mesh_p<P>::has(const psite& p) const
+ {
+ for (unsigned i = 0; i < loc_.size(); ++i)
+ if (loc_[i] == p)
+ return true;
+ return false;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of mln
+
+
+#endif // MLN_MESH_P_HH
Index: trunk/milena/mln/core/mesh_p_piter.hh
===================================================================
--- trunk/milena/mln/core/mesh_p_piter.hh (revision 0)
+++ trunk/milena/mln/core/mesh_p_piter.hh (revision 1195)
@@ -0,0 +1,158 @@
+// 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.
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_CORE_MESH_P_PITER_HH
+# define MLN_CORE_MESH_P_PITER_HH
+
+# include <mln/core/internal/point_iterator_base.hh>
+# include <mln/core/mesh_p.hh>
+
+/*! \file mln/core/mesh_psite.hh
+ *
+ * \brief Definition of a graph.
+ */
+
+namespace mln
+{
+
+ template<typename P> class mesh_p_piter_;
+
+ template<typename P>
+ class mesh_p_piter_ : public internal::point_iterator_base_< P, mesh_p_piter_<P> >
+ {
+ typedef mesh_p_piter_<P> self_;
+ typedef internal::point_iterator_base_< P, self_ > super_;
+
+ public:
+
+ // Make definitions from super class available.
+ enum { dim = super_::dim };
+
+ mesh_p_piter_(const mesh_p<P>& s);
+
+ /// Give a hook to the point address.
+ const P* pointer_() const;
+
+ /// Read-only access to the \p i-th coordinate.
+ mln_coord(P) operator[](unsigned i) const;
+
+ /// Test if the iterator is valid.
+ bool is_valid() const;
+
+ /// Invalidate the iterator.
+ void invalidate();
+
+ /// Start an iteration.
+ void start();
+
+ /// Go to the next point.
+ void next_();
+
+ /// Convert the iterator into a point.
+ operator P() const;
+
+ protected:
+ const std::vector<P>& loc_;
+ unsigned i_;
+ P p_;
+ };
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template<typename P>
+ mesh_p_piter_<P>::mesh_p_piter_(const mesh_p<P>& s)
+ : loc_(s.loc_)
+ {
+ invalidate();
+ }
+
+
+ template<typename P>
+ const P*
+ mesh_p_piter_<P>::pointer_() const
+ {
+ return & p_;
+ }
+
+
+ template<typename P>
+ mln_coord(P)
+ mesh_p_piter_<P>::operator[](unsigned i) const
+ {
+ return p_[i];
+ }
+
+
+ template<typename P>
+ bool
+ mesh_p_piter_<P>::is_valid() const
+ {
+ return i_ != loc_.size();
+ }
+
+
+ template<typename P>
+ void
+ mesh_p_piter_<P>::invalidate()
+ {
+ i_ = loc_.size();
+ }
+
+
+ template<typename P>
+ void
+ mesh_p_piter_<P>::start()
+ {
+ i_ = 0;
+ if (is_valid())
+ p_ = loc_[i_];
+ }
+
+
+ template<typename P>
+ void
+ mesh_p_piter_<P>::next_()
+ {
+ ++i_;
+ if (is_valid())
+ p_ = loc_[i_];
+ }
+
+
+ template<typename P>
+ mesh_p_piter_<P>::operator P() const
+ {
+ mln_precondition(is_valid());
+ return p_;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of mln
+
+
+#endif // MLN_MESH_P_PITER_HH
Index: trunk/milena/mln/core/mesh_image.hh
===================================================================
--- trunk/milena/mln/core/mesh_image.hh (revision 0)
+++ trunk/milena/mln/core/mesh_image.hh (revision 1195)
@@ -0,0 +1,177 @@
+// 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_MESH_IMAGE_HH
+# define MLN_CORE_MESH_IMAGE_HH
+
+/*! \file mln/core/mesh_image.hh
+ *
+ * \brief Definition of an image class mesh_image.
+ */
+
+# include <mln/core/internal/image_identity.hh>
+# include <mln/metal/vec.hh>
+# include <mln/core/mesh_p.hh>
+# include <mln/core/mesh_psite.hh>
+# include <vector>
+
+namespace mln
+{
+
+ // Fwd decl.
+ template <typename P, typename V> struct mesh_image;
+
+ namespace internal
+ {
+
+ template <typename P, typename V>
+ struct data_< mesh_image<P, V> >
+ {
+ data_(mesh_p<P>& mesh, std::vector<V>& val);
+
+ std::vector<V> val_;
+ mesh_p<P> mesh_;
+ };
+
+ } // end of namespace mln::internal
+
+ /*! \brief FIXME
+ *
+ */
+ template <typename P, typename V>
+ struct mesh_image : public internal::image_primary_< mesh_p<P>, mesh_image<P, V> >
+ {
+
+ typedef mln::internal::image_base_< mesh_p<P>, mesh_image<P, V> > super_;
+
+ /// Value associated type.
+ typedef V value;
+
+ /// Return type of read-write access.
+ typedef V& lvalue;
+
+ /// Return type of read-only access.
+ typedef const V& rvalue;
+
+ /// Value set associated type.
+ typedef mln::value::set<value> vset;
+
+
+ /// Skeleton.
+ typedef mesh_image< tag::psite_<P>, tag::value_<V> > skeleton;
+
+ /// Constructors.
+ mesh_image(mesh_p<P>& mesh, std::vector<V>& val);
+ mesh_image();
+
+ /// Read-only access of pixel value at point site \p p.
+ const V& operator()(const mesh_psite<P>& p) const;
+
+ /// Read-write access of pixel value at point site \p p.
+ V& operator()(const mesh_psite<P>& p);
+
+ /// Give the set of values of the image.
+ const vset& values() const;
+
+ const std::vector<V>& data_values () const;
+
+ const mesh_p<P>& domain() const;
+};
+
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace internal
+ {
+ template <typename P, typename V>
+ data_< mesh_image<P, V> >::data_(mesh_p<P>& mesh, std::vector<V>& val)
+ : val_ (val),
+ mesh_ (mesh)
+ {
+ }
+
+ } // end of namespace mln::internal
+
+ template <typename P, typename V>
+ mesh_image<P, V>::mesh_image(mesh_p<P>& mesh, std::vector<V>& val)
+ {
+ this->data_ = new internal::data_< mesh_image<P, V> > (mesh, val);
+ }
+
+ template <typename P, typename V>
+ mesh_image<P, V>::mesh_image()
+ {
+ }
+
+ template <typename P, typename V>
+ const V&
+ mesh_image<P, V>::operator()(const mesh_psite<P>& p) const
+ {
+ mln_precondition(p.m_ptr_ == & this->data_->mesh_);
+ mln_precondition(p.i_ < this->data_->val_.size());
+ return this->data_->val_[p.i_];
+ }
+
+ template <typename P, typename V>
+ V&
+ mesh_image<P, V>::operator()(const mesh_psite<P>& p)
+ {
+ mln_precondition(p.m_ptr_ == & this->data_->mesh_);
+ mln_precondition(p.i_ < this->data_->val_.size());
+ return this->data_->val_[p.i_];
+ }
+
+ template <typename P, typename V>
+ const mln::value::set<V> &
+ mesh_image<P, V>::values() const
+ {
+ return vset::the();
+ }
+
+ template <typename P, typename V>
+ const std::vector<V>&
+ mesh_image<P, V>::data_values () const
+ {
+ return this->data_->val_;
+ }
+
+ template <typename P, typename V>
+ const mesh_p<P>&
+ mesh_image<P, V>::domain() const
+ {
+ mln_precondition(this->has_data());
+ return this->data_->mesh_;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_MESH_IMAGE_HH
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-28 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add graph in mln/util.
* graph.hh: New.
---
graph.hh | 182 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 182 insertions(+)
Index: trunk/milena/mln/util/graph.hh
===================================================================
--- trunk/milena/mln/util/graph.hh (revision 0)
+++ trunk/milena/mln/util/graph.hh (revision 1194)
@@ -0,0 +1,182 @@
+// 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.
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_UTIL_GRAPH_HH
+# define MLN_UTIL_GRAPH_HH
+
+# include <mln/core/concept/object.hh>
+# include <cstddef>
+# include <iostream>
+# include <vector>
+
+/*! \file mln/util/graph.hh
+ *
+ * \brief Definition of a graph.
+ */
+
+
+namespace mln
+{
+ namespace util
+ {
+
+ template<typename T>
+ struct s_node
+ {
+ T data;
+ std::vector<unsigned> links;
+ };
+
+ template<>
+ struct s_node<void>
+ {
+ std::vector<unsigned> links;
+ };
+
+ template<typename T>
+ struct s_edge
+ {
+ T data;
+ unsigned node1;
+ unsigned node2;
+ };
+
+ template<>
+ struct s_edge <void>
+ {
+ unsigned node1;
+ unsigned node2;
+ };
+
+ template<typename N, typename E = void>
+ struct graph
+ {
+ graph ();
+
+ void add_node (void);
+ void add_edge (unsigned n1, unsigned n2);
+ void coherence () const;
+ void print_debug () const;
+ unsigned nb_node_;
+ unsigned nb_link_;
+ std::vector<struct s_node<N>*> nodes_;
+ std::vector<struct s_edge<E>*> links_;
+ };
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template<typename N, typename E>
+ graph<N, E>::graph ()
+ : nb_node_ (0),
+ nb_link_ (0),
+ nodes_ (0),
+ links_ (0)
+ {
+ }
+
+ template<typename N, typename E>
+ void
+ graph<N, E>::add_node (void)
+ {
+ struct s_node<N>* n = new struct s_node<N>;
+
+ nodes_.push_back (n);
+ ++nb_node_;
+ }
+
+ template<typename N, typename E>
+ void
+ graph<N, E>::add_edge (unsigned n1, unsigned n2)
+ {
+ mln_precondition(n1 < this->nb_node_);
+ mln_precondition(n2 < this->nb_node_);
+
+ struct s_edge<E>* edge;
+
+ edge = new struct s_edge<E>;
+ edge->node1 = n1;
+ edge->node2 = n2;
+ links_.push_back (edge);
+ ++nb_link_;
+ nodes_[n1]->links.push_back (n2);
+ nodes_[n2]->links.push_back (n1);
+ }
+
+ template<typename N, typename E>
+ void
+ graph<N, E>::coherence () const
+ {
+ mln_precondition(nodes_.size () == this->nb_node_);
+ mln_precondition(links_.size () == this->nb_link_);
+ typename std::vector<struct s_node <N>*>::const_iterator it = nodes_.begin ();
+ for (; it != nodes_.end (); ++it)
+ {
+ typename std::vector<unsigned>::const_iterator it2 = (*it)->links.begin ();
+ for (; it2 != (*it)->links.end (); ++it2)
+ mln_precondition((*it2) < nb_node_);
+ }
+
+ typename std::vector<struct s_edge<E>*>::const_iterator it3 = links_.begin ();
+ for (; it3 != links_.end (); ++it3)
+ {
+ mln_precondition((*it3)->node1 < nb_node_);
+ mln_precondition((*it3)->node2 < nb_node_);
+ }
+ }
+
+ template<typename N, typename E>
+ void
+ graph<N, E>::print_debug () const
+ {
+ std::cout << "nodes :"
+ << std::endl;
+
+ typename std::vector<struct s_node<N>*>::const_iterator it = nodes_.begin ();
+ int i = 0;
+ for (; it != nodes_.end (); ++it, ++i)
+ {
+ std::cout << "node number = "
+ << i
+ << " nbh : ";
+ typename std::vector<unsigned>::const_iterator it2 = (*it)->links.begin ();
+ for (; it2 != (*it)->links.end (); ++it2)
+ {
+ std::cout << (*it2)
+ << " ";
+ }
+ std::cout << std::endl;
+ }
+ std::cout << std::endl;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of util
+
+} // end of mln
+
+#endif // MLN_GRAPH_HH
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-28 Simon Nivault <simon.nivault(a)lrde.epita.fr>
Add homogen vector.
* mln/core/h_vec.hh: New.
* mln/core/point.hh: Know be casted as homogen vector.
* tests/h_vec.cc: New.
---
mln/core/h_vec.hh | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
mln/core/point.hh | 10 ++++++
tests/h_vec.cc | 62 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 155 insertions(+)
Index: trunk/milena/tests/h_vec.cc
===================================================================
--- trunk/milena/tests/h_vec.cc (revision 0)
+++ trunk/milena/tests/h_vec.cc (revision 1190)
@@ -0,0 +1,62 @@
+// 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/h_vec.cc
+ *
+ * \brief Tests on mln::h_vec.
+ */
+
+#include <mln/core/h_vec.hh>
+#include <mln/core/point3d.hh>
+
+using namespace mln;
+
+
+void run_in_3d(const metal::vec<3, int>&)
+{
+}
+
+void run_in_3d_h(const h_vec<3, int>&)
+{
+}
+
+
+int main()
+{
+
+ metal::vec<3, int> x;
+ h_vec<3, int> w = x;
+
+ typedef h_vec<3, int> p3d;
+ p3d p;
+ run_in_3d(p);
+
+ point3d k;
+ run_in_3d(k);
+ run_in_3d_h(k);
+
+}
Index: trunk/milena/mln/core/point.hh
===================================================================
--- trunk/milena/mln/core/point.hh (revision 1189)
+++ trunk/milena/mln/core/point.hh (revision 1190)
@@ -107,6 +107,9 @@
/// Hook to coordinates.
operator metal::vec<M::dim, C>() const;
+ /// Hook to homogene coordinate.
+ operator h_vec<M::dim, C>() const;
+
protected:
metal::vec<M::dim, C> coord_;
};
@@ -172,6 +175,13 @@
return coord_;
}
+ template <typename M, typename C>
+ point_<M,C>::operator h_vec<M::dim, C>() const
+ {
+ return coord_;
+ }
+
+
# endif // ! MLN_INCLUDE_ONLY
Index: trunk/milena/mln/core/h_vec.hh
===================================================================
--- trunk/milena/mln/core/h_vec.hh (revision 0)
+++ trunk/milena/mln/core/h_vec.hh (revision 1190)
@@ -0,0 +1,83 @@
+// 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_H_VEC_HH
+# define MLN_CORE_H_VEC_HH
+
+/*! \file mln/core/h_vec.hh
+ *
+ * \brief Definition of the mln::h_vec alias and of its
+ * construction routine.
+ */
+
+# include <mln/metal/vec.hh>
+
+
+namespace mln
+{
+
+
+ template <unsigned dim, typename T>
+ struct h_vec : public metal::vec<dim + 1, T>
+ {
+ h_vec()
+ : metal::vec<dim + 1, T>(make::vec<dim + 1, T>(0))
+ {
+ this->data_[dim] = 1;
+ }
+
+ h_vec(const metal::vec<dim, T>& x);
+
+ operator metal::vec<dim, T>() const;
+ };
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <unsigned dim, typename T>
+ h_vec<dim,T>::h_vec(const metal::vec<dim, T>& x)
+ {
+ for (unsigned i = 0; i < dim; ++i)
+ this->data_[i] = x[i];
+ this->data_[dim] = 1;
+ }
+
+ template <unsigned dim, typename T>
+ h_vec<dim,T>::operator metal::vec<dim,T>() const
+ {
+ metal::vec<dim,T> x;
+ for (unsigned i = 0; i < dim; ++i)
+ x[i] = this->data_[i] / this->data_[dim];
+ return x;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+
+#endif // ! MLN_CORE_H_VEC_HH