Olena-patches
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- 9625 discussions
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2008-03-04 Caroline Vigouroux <vigour_c(a)epita.fr>
Root Mean Square of error.
* load.cc: .
* moyenne.cc: New Root Mean Square function.
---
load.cc | 18 +++++++++++
moyenne.cc | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 115 insertions(+)
Index: trunk/milena/sandbox/vigouroux/load.cc
===================================================================
--- trunk/milena/sandbox/vigouroux/load.cc (revision 1762)
+++ trunk/milena/sandbox/vigouroux/load.cc (revision 1763)
@@ -24,6 +24,24 @@
#include <iostream>
+// template <typename I, typename O, typename W>
+// float moyenne (I& ima, O& out, W& win)
+// {
+// mln::value::rgb8 c2;
+// mln_piter(I) p(out.domain());
+// mln_qixter(I, W) q(ima, win, p);
+// for_all(p)
+// {
+// for_all(q)
+// {
+// q.val()
+// }
+// out(p) = c2;
+// }
+
+// return ();
+// }
+
template <typename I, typename O, typename W>
void test_fill(I& ima, O& out, W& win)
{
Index: trunk/milena/sandbox/vigouroux/moyenne.cc
===================================================================
--- trunk/milena/sandbox/vigouroux/moyenne.cc (revision 0)
+++ trunk/milena/sandbox/vigouroux/moyenne.cc (revision 1763)
@@ -0,0 +1,97 @@
+#include <mln/core/image2d.hh>
+#include <mln/value/int_u8.hh>
+#include "color/my_hsi.hh"
+#include "color/rgb_to_hsi.hh"
+#include <mln/display/save_and_show.hh>
+#include <mln/value/rgb.hh>
+#include <mln/value/rgb8.hh>
+
+#include <mln/io/ppm/load.hh>
+#include <mln/io/ppm/save.hh>
+#include <mln/math/round.hh>
+#include <mln/level/transform.hh>
+
+#include <mln/core/w_window2d_float.hh>
+#include <mln/border/thickness.hh>
+#include <mln/linear/convolve.hh>
+
+# include <mln/display/save.hh>
+# include <mln/display/show.hh>
+
+#include <mln/core/image2d.hh>
+#include <mln/win/rectangle2d.hh>
+#include <mln/make/pixel.hh>
+#include <cmath>
+
+#include <iostream>
+
+// template <typename I, typename O, typename W>
+// float moyenne (I& ima, O& out, W& win)
+// {
+// mln::value::rgb8 c2;
+// mln_piter(I) p(out.domain());
+// mln_qixter(I, W) q(ima, win, p);
+// for_all(p)
+// {
+// for_all(q)
+// {
+// q.val()
+// }
+// out(p) = c2;
+// }
+
+// return ();
+// }
+
+template <typename I, typename O, typename W>
+float moyenne (I& ima, O& out, W& win)
+{
+ mln::value::hsi_3x8 c_hsi;
+ mln::value::rgb8 c2;
+ float distred = 0;
+ float distgreen = 0;
+ float distblue = 0;
+ float sum = 0;
+ float nb_ct = 0;
+ float moy = 0;
+
+ mln_piter(I) p(out.domain());
+ mln_qixter(I, W) q(ima, win, p);
+ for_all(p)
+ {
+ for_all(q)
+ {
+ c_hsi = mln::fun::v2v::f_rgb_to_hsi_3x8(q.val());
+ c2 = mln::fun::v2v::f_hsi_to_rgb_3x8(c_hsi);
+ distred = c2.red() - q.val().red();
+ distgreen = c2.green() - q.val().green();
+ distblue = c2.blue() - q.val().blue();
+ }
+ nb_ct += 3;
+ sum += distred * distred + distblue * distblue + distgreen * distgreen;
+ out(p) = c2;
+ }
+ moy = sqrt(sum / nb_ct);
+ std::cout << "nb_point: " << nb_ct / 3 << std::endl;
+ return (moy);
+}
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+ image2d<mln::value::rgb8> lena;
+ io::ppm::load(lena, "../../img/lena.ppm");
+ image2d<mln::value::hsi_3x8> inter(lena.domain());
+ image2d<mln::value::rgb8> out(lena.domain());
+ const image2d<mln::value::rgb8> input = exact(lena);
+ float lol;
+
+ win::rectangle2d rect(3, 3);
+ lol = moyenne(input, out, rect);
+
+ std::cout << "moyenne: " << lol << std::endl;
+
+ display::save_and_show (out, "display", 50);
+}
+
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2008-03-04 Caroline Vigouroux <vigour_c(a)epita.fr>
test conversion with lena image.
* color/rgb_to_hsi.hh: .
* load.cc: test.
---
color/rgb_to_hsi.hh | 8 ++++----
load.cc | 38 ++++++++++++++++++++++++++++++--------
2 files changed, 34 insertions(+), 12 deletions(-)
Index: trunk/milena/sandbox/vigouroux/load.cc
===================================================================
--- trunk/milena/sandbox/vigouroux/load.cc (revision 1761)
+++ trunk/milena/sandbox/vigouroux/load.cc (revision 1762)
@@ -1,5 +1,7 @@
#include <mln/core/image2d.hh>
#include <mln/value/int_u8.hh>
+#include "color/my_hsi.hh"
+#include "color/rgb_to_hsi.hh"
#include <mln/display/save_and_show.hh>
#include <mln/value/rgb.hh>
#include <mln/value/rgb8.hh>
@@ -16,23 +18,43 @@
# include <mln/display/save.hh>
# include <mln/display/show.hh>
+#include <mln/core/image2d.hh>
+#include <mln/win/rectangle2d.hh>
+#include <mln/make/pixel.hh>
+
+#include <iostream>
+
+template <typename I, typename O, typename W>
+void test_fill(I& ima, O& out, W& win)
+{
+ mln::value::hsi_3x8 c_hsi;
+ mln::value::rgb8 c2;
+ mln_piter(I) p(out.domain());
+ mln_qixter(I, W) q(ima, win, p);
+ for_all(p)
+ {
+ for_all(q)
+ {
+ c_hsi = mln::fun::v2v::f_rgb_to_hsi_3x8(q.val());
+ c2 = mln::fun::v2v::f_hsi_to_rgb_3x8(c_hsi);
+ }
+ out(p) = c2;
+ }
+}
+
int main()
{
using namespace mln;
using value::int_u8;
image2d<mln::value::rgb8> lena;
io::ppm::load(lena, "../../img/lena.ppm");
-// image2d<mln::value::hsi_3x8> inter(lena.domain());
+ image2d<mln::value::hsi_3x8> inter(lena.domain());
image2d<mln::value::rgb8> out(lena.domain());
const image2d<mln::value::rgb8> input = exact(lena);
-// mln_piter(image2d<mln::value::rgb8>) p(input.domain());
-// for_all(p)
-// {
-// inter(p) = fun::v2v::f_rgb_to_hsi_3x8(p);
-
-// }
+ win::rectangle2d rect(3, 3);
+ test_fill(input, out, rect);
- display::save_and_show (lena, "display", 1);
+ display::save_and_show (out, "display", 50);
}
Index: trunk/milena/sandbox/vigouroux/color/rgb_to_hsi.hh
===================================================================
--- trunk/milena/sandbox/vigouroux/color/rgb_to_hsi.hh (revision 1761)
+++ trunk/milena/sandbox/vigouroux/color/rgb_to_hsi.hh (revision 1762)
@@ -45,10 +45,10 @@
float tmp = atan2(beta, alpha) / 3.1415 * 180.0;
- if (tmp < 0 or tmp > 1)
- {
- std::cout << "FIXME: " << tmp << std::endl;
- }
+// if (tmp < 0 or tmp > 1)
+// {
+// std::cout << "FIXME: " << tmp << std::endl;
+// }
hsi.hue() = atan2(beta, alpha) / 3.1415 * 180.0;
if (hsi.hue() < 0)
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Nicolas Ballas <ballas(a)lrde.epita.fr>
Add an image type based on boost adjacency_list.
* tests/core/bgraph_image.cc,
* tests/core/p_bgraph.cc: New test.
* mln/core/p_bgraph_piter.hh: Point Iterator on p_bgraph.
* mln/core/bgraph_image.hh: New image type (not fully tested yet).
* mln/core/p_bgraph.hh: New, Point Set based on a boost graph.
* mln/core/bgraph_psite.hh: New.
* mln/util/internal/boost_graph.hh,
* mln/util/internal/boost_graph_structure.hh: Fix some bugs.
mln/core/bgraph_image.hh | 309 +++++++++++++++++++++++++++++
mln/core/bgraph_psite.hh | 178 ++++++++++++++++
mln/core/p_bgraph.hh | 221 ++++++++++++++++++++
mln/core/p_bgraph_piter.hh | 244 ++++++++++++++++++++++
mln/util/internal/boost_graph.hh | 43 +++-
mln/util/internal/boost_graph_structure.hh | 12 -
tests/core/bgraph_image.cc | 94 ++++++++
tests/core/p_bgraph.cc | 87 ++++++++
8 files changed, 1178 insertions(+), 10 deletions(-)
Index: tests/core/bgraph_image.cc
--- tests/core/bgraph_image.cc (revision 0)
+++ tests/core/bgraph_image.cc (revision 0)
@@ -0,0 +1,94 @@
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// 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/core/bgraph_image.cc
+/// \brief Tests on mln::bgraph_image.
+
+#include <vector>
+#include <mln/core/point2d.hh>
+#include <mln/core/bgraph_image.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+
+ /*--------.
+ | Graph. |
+ `--------*/
+ using namespace mln;
+ typedef util::internal::boost_graph<point2d, util::empty> Graph;
+
+ // Make convenient labels for the vertices
+ const int num_vertices = 5;
+
+ // writing out the edges in the graph
+ typedef std::pair<int, int> Edge;
+ Edge edge_array[] = {
+ Edge(0, 1), Edge(0, 3), Edge(2, 0), Edge(3, 2),
+ Edge(2, 4), Edge(1, 3), Edge(3, 4)
+ };
+
+ const int num_edges = sizeof(edge_array)/sizeof(edge_array[0]);
+ // declare a graph object
+ Graph g(num_vertices);
+
+ // add the edges to the graph object
+ for (int i = 0; i < num_edges; ++i)
+ boost::add_edge(edge_array[i].first, edge_array[i].second, g);
+
+ g[0] = make::point2d(0, 0);
+ g[1] = make::point2d(0, 1);
+ g[2] = make::point2d(1, 0);
+ g[3] = make::point2d(1, 1);
+ g[4] = make::point2d(0, 2);
+
+ /*------------------.
+ | Boost Graph Image |
+ `-------------------*/
+
+ /*--------------.
+ | Vector values |
+ `--------------*/
+
+ typedef bgraph_image<point2d, int> ima_type;
+
+ std::vector<int> values;
+ values.push_back(1);
+ values.push_back(2);
+ values.push_back(3);
+ values.push_back(4);
+ values.push_back(5);
+
+ ima_type ima(g, values);
+ mln_piter_(ima_type) p(ima.domain());
+ for_all(p)
+ std::cout << ima(p) << std::endl;
+
+ return 0;
+}
Index: tests/core/p_bgraph.cc
--- tests/core/p_bgraph.cc (revision 0)
+++ tests/core/p_bgraph.cc (revision 0)
@@ -0,0 +1,87 @@
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// 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/core/p_bgraph.cc
+/// \brief Tests on mln::p_bgraph (the psite based on boost-graph).
+
+#include <mln/core/p_bgraph.hh>
+#include <mln/core/point2d.hh>
+#include <mln/util/internal/boost_graph.hh>
+#include <boost/typeof/std/utility.hpp>
+
+struct empty {};
+
+int main()
+{
+ /*--------------.
+ | boost_graph. |
+ `--------------*/
+
+ using namespace mln;
+ typedef util::internal::boost_graph<point2d, util::empty> Graph;
+
+ // Make convenient labels for the vertices
+ const int num_vertices = 5;
+
+ // writing out the edges in the graph
+ typedef std::pair<int, int> Edge;
+ Edge edge_array[] = {
+ Edge(0, 1), Edge(0, 3), Edge(2, 0), Edge(3, 2),
+ Edge(2, 4), Edge(1, 3), Edge(3, 4)
+ };
+
+ const int num_edges = sizeof(edge_array)/sizeof(edge_array[0]);
+ // declare a graph object
+ Graph g(num_vertices);
+
+ // add the edges to the graph object
+ for (int i = 0; i < num_edges; ++i)
+ boost::add_edge(edge_array[i].first, edge_array[i].second, g);
+
+ g[0] = make::point2d(0, 0);
+ g[1] = make::point2d(0, 1);
+ g[2] = make::point2d(1, 0);
+ g[3] = make::point2d(1, 1);
+ g[4] = make::point2d(0, 2);
+
+ /*-----------.
+ | p_bgraph. |
+ `-----------*/
+
+ /// Creation
+ p_bgraph<point2d> pset(g);
+
+ /// Iterator
+ p_bgraph_piter_<point2d> p(pset);
+
+ for (p.start(); p.is_valid(); p.next())
+ std::cout << p << std::endl;
+
+
+
+ return 0;
+}
Index: mln/core/p_bgraph_piter.hh
--- mln/core/p_bgraph_piter.hh (revision 0)
+++ mln/core/p_bgraph_piter.hh (revision 0)
@@ -0,0 +1,244 @@
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// 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_P_BGRAPH_PITER_HH
+# define MLN_CORE_P_BGRAPH_PITER_HH
+
+# include <utility>
+
+# include <mln/core/internal/point_iterator_base.hh>
+# include <mln/core/p_bgraph.hh>
+# include <mln/core/bgraph_psite.hh>
+
+/*! \file mln/core/p_bgraph_piter.hh
+ *
+ * \brief Definition of point iterator on boost-graph-based point set.
+ */
+
+namespace mln
+{
+ // Fwd decls.
+ template<typename P> class p_bgraph;
+ template<typename P> class bgraph_psite;
+
+
+ // FIXME: check the constraint due to the boost iterators
+ template<typename P>
+ class p_bgraph_piter_
+ : public internal::point_iterator_base_< P, p_bgraph_piter_<P> >
+ {
+ typedef p_bgraph_piter_<P> self_;
+ typedef internal::point_iterator_base_< P, self_ > super_;
+ typedef std::pair<typename p_bgraph<P>::node_iterator,
+ typename p_bgraph<P>::node_iterator> iterators_type_;
+
+ public:
+
+ // Make definitions from super class available.
+ enum { dim = super_::dim };
+ typedef bgraph_psite<P> psite;
+ typedef P point;
+
+ p_bgraph_piter_(const p_bgraph<P>& pg);
+
+ /// 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_();
+
+ /// Update the internal data of the iterator.
+ void update_();
+
+ /// Reference to the corresponding point.
+ const point& to_point () const;
+
+ /// Reference to the corresponding point site.
+ const psite& to_psite () const;
+
+ /// Convert the iterator into a point.
+ operator point() const;
+
+ /// Convert the iterator into a graph psite.
+ operator psite() const;
+
+ protected:
+ /// The p_graph this point site belongs to.
+ const p_bgraph<P>& pg_;
+
+ /// The psite corresponding to this iterator.
+ psite psite_;
+ /// The point corresponding to this iterator.
+ point p_;
+
+ private:
+ iterators_type_ iterators_;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template<typename P>
+ inline
+ p_bgraph_piter_<P>::p_bgraph_piter_(const p_bgraph<P>& pg)
+ : pg_(pg),
+ // Initialize psite_ to a dummy value.
+ psite_(pg, pg_.npoints()),
+ p_()
+ {
+ // Initialize the iterators
+ start();
+
+ // Invalidate id_.
+ invalidate();
+ }
+
+ template<typename P>
+ inline
+ mln_coord(P)
+ p_bgraph_piter_<P>::operator[](unsigned i) const
+ {
+ return p_[i];
+ }
+
+ template<typename P>
+ inline
+ bool
+ p_bgraph_piter_<P>::is_valid() const
+ {
+ return iterators_.first != iterators_.second;
+ }
+
+ template<typename P>
+ inline
+ void
+ p_bgraph_piter_<P>::invalidate()
+ {
+ iterators_.first == iterators_.second;
+ }
+
+ template<typename P>
+ inline
+ void
+ p_bgraph_piter_<P>::start()
+ {
+ /// FIXME: Hide implementation details?
+ iterators_ = boost::vertices(pg_.to_graph());
+ update_();
+ }
+
+ template<typename P>
+ inline
+ void
+ p_bgraph_piter_<P>::next_()
+ {
+ ++iterators_.first;
+ update_();
+ }
+
+ template<typename P>
+ inline
+ void
+ p_bgraph_piter_<P>::update_()
+ {
+ // Update psite_.
+ psite_ = bgraph_psite<P>(pg_, *iterators_.first);
+ // Update p_.
+ p_ = pg_.point_from_id(*iterators_.first);
+ }
+
+ template<typename P>
+ inline
+ const P&
+ p_bgraph_piter_<P>::to_point() const
+ {
+ /* We don't check whether the iterator is valid before returning
+ the value using
+
+ mln_precondition(is_valid());
+
+ since this method may be called *before* the iterator is
+ actually initialized. This is the case for instance when this
+ point iterator (say, P) is used to initialize another iterator
+ on window or neighborhood (say, Q); most of the time, for_all()
+ is responsible for the initialization of P, but it takes place
+ *after* the creation of Q. */
+ return p_;
+ }
+
+ template<typename P>
+ inline
+ const bgraph_psite<P>&
+ p_bgraph_piter_<P>::to_psite() const
+ {
+ /* We don't check whether the iterator is valid before returning
+ the value using
+
+ mln_precondition(is_valid());
+
+ since this method may be called *before* the iterator is
+ actually initialized. This is the case for instance when this
+ point iterator (say, P) is used to initialize another iterator
+ on window or neighborhood (say, Q); most of the time, for_all()
+ is responsible for the initialization of P, but it takes place
+ *after* the creation of Q. */
+
+ return psite_;
+ }
+
+ template<typename P>
+ inline
+ p_bgraph_piter_<P>::operator P() const
+ {
+ mln_precondition(is_valid());
+ return p_;
+ }
+
+ template<typename P>
+ inline
+ p_bgraph_piter_<P>::operator bgraph_psite<P>() const
+ {
+ mln_precondition(is_valid());
+ return psite_;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of mln
+
+
+#endif // MLN_P_BGRAPH_PITER_HH
Index: mln/core/bgraph_image.hh
--- mln/core/bgraph_image.hh (revision 0)
+++ mln/core/bgraph_image.hh (revision 0)
@@ -0,0 +1,309 @@
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// 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_BGRAPH_IMAGE_HH
+# define MLN_CORE_BGRAPH_IMAGE_HH
+
+/// \file mln/core/bgraph_image.hh
+/// \brief Definition of a boost-graph-based image.
+
+# include <mln/trait/images.hh>
+# include <mln/core/internal/image_primary.hh>
+# include <mln/metal/vec.hh>
+
+# include <mln/core/p_bgraph.hh>
+# include <mln/core/bgraph_psite.hh>
+# include <mln/value/set.hh>
+# include <vector>
+
+namespace mln
+{
+
+ // Fwd decl.
+ template <typename P, typename V> struct bgraph_image;
+
+ namespace internal
+ {
+
+ /// \internal Data structure for \c mln::bgraph_image<P,V>.
+ template <typename P, typename V>
+ struct data_< bgraph_image<P, V> >
+ {
+ data_(const p_bgraph<P>& g, const std::vector<V>& val);
+
+ std::vector<V> val_;
+ /* The graph point set is handled by address, so that we can
+ check the compatibility of images w.r.t. to their point
+ sites. We could use a safer (and more complex) facility to
+ ensure (memory) equality of line graph point sets, but using
+ addresses is simple and efficient enough for the moment. */
+ const p_bgraph<P>& pg_;
+ };
+
+ } // end of namespace mln::internal
+
+
+ namespace trait
+ {
+
+ template <typename P, typename V>
+ struct image_< bgraph_image<P, V> > :
+ default_image_< V, bgraph_image<P, V> >
+ {
+ typedef trait::image::category::primary category;
+
+ // FIXME: Is that right?
+ typedef trait::image::access::random access;
+ typedef typename trait::image::space_from_point<P>::ret space;
+ typedef trait::image::size::regular size;
+ typedef trait::image::support::irregular support;
+
+ typedef trait::image::border::none border;
+ typedef trait::image::data::stored data;
+ typedef trait::image::io::read_write io;
+ // FIXME: Is that right?
+ typedef trait::image::speed::fast speed;
+ };
+
+ } // end of namespace mln::trait
+
+ /*! \brief Kind of image based on a boost graph structure.
+ *
+ */
+ template <typename P, typename V>
+ struct bgraph_image :
+ public internal::image_primary_< p_bgraph<P>, bgraph_image<P, V> >
+ {
+
+ typedef mln::internal::image_base_< p_bgraph<P>, bgraph_image<P, V> >
+ super_;
+
+ /// Value associated type.
+ typedef V value;
+
+ /// Return type of read-write access.
+ ///
+ /// We use the associated type \c reference instead of a plain
+ /// reference on th value type (\v V), because it's the only way
+ /// to safely form a reference on the element in the case of a
+ /// std::vector<bool>.
+ typedef typename std::vector<V>::reference lvalue;
+
+ /// Return type of read-only access.
+ typedef typename std::vector<V>::const_reference rvalue;
+
+ /// Value set associated type.
+ typedef mln::value::set<value> vset;
+
+
+ /// Skeleton.
+ typedef bgraph_image< tag::psite_<P>, tag::value_<V> > skeleton;
+
+ /// Constructors.
+ /// \{
+ bgraph_image();
+ bgraph_image(const p_bgraph<P>& g);
+ bgraph_image(const p_bgraph<P>& g, const std::vector<V>& val);
+ /// \}
+
+ /// Initialize an empty image.
+ void init_(const p_bgraph<P>& g, const std::vector<V>& val);
+
+ /// Read-only access of pixel value at point site \p p.
+ rvalue operator()(const bgraph_psite<P>& p) const;
+
+ /// Read-write access of pixel value at point site \p p.
+ lvalue operator()(const bgraph_psite<P>& p);
+
+ /// Accessors.
+ /// \{
+ /// Return the domain of psites od the image.
+ const p_bgraph<P>& domain() const;
+ /// Return the domain of values of the image.
+ const vset& values() const;
+
+ /// Return the array of values associated to the nodes.
+ const std::vector<V>& node_values() const;
+ /// \}
+
+ /* FIXME: Do we want to provide these two methods? (at least, in
+ the interface of the class? */
+
+ /// Return the point of the first node adjacent to the edge with
+ /// id \a e.
+ const P& node1(const typename p_bgraph<P>::edge_id& e) const;
+ /// Return the point of the second node adjacent to the edge with
+ /// id \a e.
+ const P& node2(const typename p_bgraph<P>::edge_id& e) const;
+};
+
+ // Fwd decl.
+ template <typename P, typename V>
+ void init_(tag::image_t,
+ bgraph_image<P, V>& target, const bgraph_image<P, V>& model);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ /*-----------------.
+ | Initialization. |
+ `-----------------*/
+
+ template <typename P, typename V>
+ inline
+ void init_(tag::image_t,
+ bgraph_image<P, V>& target, const bgraph_image<P, V>& model)
+ {
+ target.init_(model.domain(), model.node_values ());
+ }
+
+ /*-------.
+ | Data. |
+ `-------*/
+
+ namespace internal
+ {
+ template <typename P, typename V>
+ inline
+ data_< bgraph_image<P, V> >::data_(const p_bgraph<P>& g,
+ const std::vector<V>& val)
+ : val_ (val),
+ pg_ (g)
+ {
+ }
+
+ } // end of namespace mln::internal
+
+ /*---------------.
+ | Construction. |
+ `---------------*/
+
+ template <typename P, typename V>
+ inline
+ bgraph_image<P, V>::bgraph_image()
+ {
+ }
+
+ template <typename P, typename V>
+ inline
+ bgraph_image<P, V>::bgraph_image(const p_bgraph<P>& g)
+ {
+ init_(g, std::vector<V>(g.npoints()));
+ }
+
+ template <typename P, typename V>
+ inline
+ bgraph_image<P, V>::bgraph_image(const p_bgraph<P>& g,
+ const std::vector<V>& val)
+ {
+ init_(g, val);
+ }
+
+ template <typename P, typename V>
+ inline
+ void
+ bgraph_image<P, V>::init_(const p_bgraph<P>& g, const std::vector<V>& val)
+ {
+ /* FIXME: We leak memory here: calling init_ twice loses the
+ previous content pointed by data_.
+
+ We should definitely write down formal guidelines on
+ initialization and memory management in general! */
+ this->data_ = new internal::data_< bgraph_image<P, V> > (g, val);
+ }
+
+ /*---------------.
+ | Manipulation. |
+ `---------------*/
+
+ template <typename P, typename V>
+ inline
+ typename bgraph_image<P, V>::rvalue
+ bgraph_image<P, V>::operator()(const bgraph_psite<P>& p) const
+ {
+ mln_precondition(&p.pg() == &this->data_->pg_);
+ mln_precondition(p.id() < this->data_->val_.size());
+ return this->data_->val_[p.id()];
+ }
+
+ template <typename P, typename V>
+ inline
+ typename bgraph_image<P, V>::lvalue
+ bgraph_image<P, V>::operator()(const bgraph_psite<P>& p)
+ {
+ mln_precondition(&p.pg() == &this->data_->pg_);
+ mln_precondition(p.id() < this->data_->val_.size());
+ return this->data_->val_[p.id()];
+ }
+
+ template <typename P, typename V>
+ inline
+ const mln::value::set<V> &
+ bgraph_image<P, V>::values() const
+ {
+ return vset::the();
+ }
+
+ template <typename P, typename V>
+ inline
+ const std::vector<V>&
+ bgraph_image<P, V>::node_values() const
+ {
+ return this->data_->val_;
+ }
+
+ template <typename P, typename V>
+ inline
+ const p_bgraph<P>&
+ bgraph_image<P, V>::domain() const
+ {
+ mln_precondition(this->has_data());
+ return this->data_->pg_;
+ }
+
+ template <typename P, typename V>
+ inline
+ const P&
+ bgraph_image<P, V>::node1(const typename p_bgraph<P>::edge_id& e) const
+ {
+ return this->domain().node1(e);
+ }
+
+ template <typename P, typename V>
+ inline
+ const P&
+ bgraph_image<P, V>::node2(const typename p_bgraph<P>::edge_id& e) const
+ {
+ return this->domain().node2(e);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_BGRAPH_IMAGE_HH
Index: mln/core/p_bgraph.hh
--- mln/core/p_bgraph.hh (revision 0)
+++ mln/core/p_bgraph.hh (revision 0)
@@ -0,0 +1,221 @@
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// 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_BGRAPH_P_HH
+# define MLN_CORE_BGRAPH_P_HH
+
+# include <utility>
+
+# include <mln/core/concept/point_site.hh>
+# include <mln/core/internal/point_set_base.hh>
+# include <mln/accu/bbox.hh>
+# include <mln/util/internal/boost_graph.hh>
+# include <mln/core/bgraph_psite.hh>
+# include <mln/core/p_bgraph_piter.hh>
+
+
+
+/// \file mln/core/p_bgraph.hh
+/// \brief Definition of a point set based on a boost graph.
+
+namespace mln
+{
+
+ template<typename P> class p_bgraph_piter_;
+
+ template<typename P>
+ struct p_bgraph
+ : public internal::point_set_base_< graph_psite<P>, p_bgraph<P> >
+ {
+ typedef util::internal::boost_graph<P, util::empty> graph;
+
+ /// Construct a graph psite set from a graph of points.
+ p_bgraph (graph& gr);
+
+ /// Point_Site associated type.
+ typedef bgraph_psite<P> psite;
+
+ /// Forward Point_Iterator associated type.
+ typedef p_bgraph_piter_<P> fwd_piter;
+
+ /// Backward Point_Iterator associated type.
+ typedef p_bgraph_piter_<P> bkd_piter;
+
+ /// Graph vertex/edge identifier
+ typedef typename graph::vertex_descriptor node_id;
+ typedef typename graph::edge_descriptor edge_id;
+
+ /// Graph vertex/edge iterator
+ typedef typename graph::vertex_iterator node_iterator;
+ typedef typename graph::edge_iterator edge_iterator;
+ typedef std::pair<node_iterator, node_iterator> node_iterators;
+
+
+ /// Return The number of points (i.e., nodes) in the graph.
+ std::size_t npoints() const;
+
+ /// Return The number of lines (i.e., edges) in the graph.
+ std::size_t nlines() const;
+
+ /// Give the exact bounding box.
+ const box_<P>& bbox() const;
+
+ bool has(const psite& p) const;
+
+ /// Return the graph point (FIXME site?) from an index
+ const P& point_from_id(const node_id& id) const;
+ P& point_from_id(const node_id& id);
+
+ /// Return the point contained in the first node adjacent
+ // to the edge id \a e.
+ const P& node1(const edge_id& e) const;
+ /// Return the point contained in the second node adjacent
+ /// to the edge id \a e.
+ const P& node2(const edge_id& e) const;
+
+ /// Return the graph associated to the p_bgraph domain:
+ const graph& to_graph() const;
+ graph& to_graph();
+
+
+ private:
+ graph gr_;
+ // FIXME: (Roland) Is it really useful/needed?
+ /* 2007-12-19: It seems so, since graph_image must implement a method
+ named bbox(). Now the question is: should each image type have a
+ bounding box? */
+ box_<P> bb_;
+ };
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template<typename P>
+ inline
+ p_bgraph<P>::p_bgraph (typename p_bgraph<P>::graph& gr)
+ : gr_ (gr)
+ {
+ // FIXME: Warning: if the underlying graph is updated later, this
+ // won't be taken into account by this p_bgraph!
+ accu::bbox<P> a;
+
+ for (node_iterators iter = boost::vertices(gr_);
+ iter.first != iter.second;
+ ++iter.first)
+ a.take(gr_[*iter.first]);
+ bb_ = a.to_result();
+ }
+
+ template<typename P>
+ inline
+ std::size_t
+ p_bgraph<P>::npoints() const
+ {
+ return boost::num_vertices((gr_));
+ }
+
+ template<typename P>
+ inline
+ std::size_t
+ p_bgraph<P>::nlines() const
+ {
+ return boost::num_edges(gr_.nedges());
+ }
+
+ template<typename P>
+ inline
+ const box_<P>&
+ p_bgraph<P>::bbox() const
+ {
+ return bb_;
+ }
+
+ template<typename P>
+ inline
+ bool
+ p_bgraph<P>::has(const psite& p) const
+ {
+ return
+ // Check whether P is compatible with this psite set.
+ (&p.pg() == this) &&
+ // Check that the node id of P belongs to the range of valid node ids.
+ (p.id() < this->npoints());
+ }
+
+
+ template <typename P>
+ const P&
+ p_bgraph<P>::point_from_id(const typename p_bgraph<P>::node_id& id) const
+ {
+ return this->gr_[id];
+ }
+
+ template <typename P>
+ P&
+ p_bgraph<P>::point_from_id(const typename p_bgraph<P>::node_id& id)
+ {
+ return this->gr_[id];
+ }
+
+
+ /// FIXME: Compare to p_bgraph, here we are loosing the vertex ordering
+ /// information. Is it bad??
+ template <typename P>
+ const P&
+ p_bgraph<P>::node1(const typename p_bgraph<P>::edge_id& e) const
+ {
+ return this->point_from_id(source(e, this->gr_));
+ }
+
+ /// FIXME: same as node1...
+ template <typename P>
+ const P&
+ p_bgraph<P>::node2(const typename p_bgraph<P>::edge_id& e) const
+ {
+ return this->point_from_id(target(e, this->gr_));
+ }
+
+ template <typename P>
+ const typename p_bgraph<P>::graph&
+ p_bgraph<P>::to_graph() const
+ {
+ return this->gr_;
+ }
+
+ template <typename P>
+ typename p_bgraph<P>::graph&
+ p_bgraph<P>::to_graph()
+ {
+ return this->gr_;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of mln
+
+
+#endif // MLN_CORE_BGRAPH_P_HH
Index: mln/core/bgraph_psite.hh
--- mln/core/bgraph_psite.hh (revision 0)
+++ mln/core/bgraph_psite.hh (revision 0)
@@ -0,0 +1,178 @@
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// 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_BGRAPH_PSITE_HH
+# define MLN_CORE_BGRAPH_PSITE_HH
+
+/// \file mln/core/bgraph_psite.hh
+/// \brief Definition of a boost-graph-based point site.
+
+# include <mln/core/p_graph.hh>
+
+
+namespace mln
+{
+
+ // Fwd decl.
+ template<typename P> class p_bgraph;
+
+
+ /// \brief Point site associated to a mln::graph_image.
+ template<typename P>
+ class bgraph_psite : public Point_Site< bgraph_psite<P> >
+ {
+ typedef bgraph_psite<P> self_;
+ typedef Point_Site< bgraph_psite<P> > super_;
+
+ public:
+ typedef mln_mesh(P) mesh;
+ enum { dim = P::dim };
+ typedef P point;
+ typedef mln_dpoint(P) dpoint;
+ typedef mln_coord(P) coord;
+
+ /// Construction and assignment.
+ /// \{
+ bgraph_psite(const p_bgraph<P>& pg_, typename p_bgraph<P>::node_id id);
+ bgraph_psite(const self_& rhs);
+ /// \pre This psite must have the same graph point set as \a rhs.
+ self_& operator= (const self_& rhs);
+ /// \}
+
+ /// Access to psite.
+ const self_& to_psite() const;
+
+ /// Access to point.
+ /// \{
+ operator P() const;
+ const point& to_point() const;
+ coord operator[](unsigned id) const;
+ /// \}
+
+ /// Return the p_graph this point site belongs to.
+ const p_bgraph<P>& pg() const;
+ /// Return the node id of this point site.
+ typename p_bgraph<P>::node_id id() const;
+
+ private:
+ /// The p_graph this point site belongs to.
+ const p_bgraph<P>& pg_;
+ /// The id of the node this psite is pointing towards.
+ typename p_bgraph<P>::node_id id_;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template<typename P>
+ inline
+ bgraph_psite<P>::bgraph_psite(const p_bgraph<P>& g,
+ typename p_bgraph<P>::node_id id)
+ : pg_(g),
+ id_(id)
+ {
+ }
+
+
+ /// FIXME: Is it normal to have to call super_() ?
+ template<typename P>
+ inline
+ bgraph_psite<P>::bgraph_psite(const bgraph_psite<P>& rhs)
+ : super_(),
+ pg_(rhs.pg_),
+ id_(rhs.id_)
+ {
+ }
+
+ template<typename P>
+ inline
+ bgraph_psite<P>&
+ bgraph_psite<P>::operator= (const bgraph_psite<P>& rhs)
+ {
+ if (&rhs == this)
+ return *this;
+ // Assigning a psite from a graph point set to a psite from
+ // another graph point set is meaningless.
+ mln_assertion(&pg_ == &rhs.pg_);
+ id_ = rhs.id_;
+ return *this;
+ }
+
+ template<typename P>
+ inline
+ const bgraph_psite<P>&
+ bgraph_psite<P>::to_psite() const
+ {
+ return *this;
+ }
+
+ template<typename P>
+ inline
+ bgraph_psite<P>::operator P() const
+ {
+ return pg_.point_from_id(id_);
+ }
+
+ template<typename P>
+ inline
+ const P&
+ bgraph_psite<P>::to_point() const
+ {
+ return pg_.point_from_id(id_);
+ }
+
+ template<typename P>
+ inline
+ mln_coord(P)
+ bgraph_psite<P>::operator[](unsigned i) const
+ {
+ return to_point()[i];
+ }
+
+ template<typename P>
+ inline
+ const p_bgraph<P>&
+ bgraph_psite<P>::pg() const
+ {
+ return pg_;
+ }
+
+ template<typename P>
+ inline
+ typename p_bgraph<P>::node_id
+ bgraph_psite<P>::id() const
+ {
+ return id_;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
+} // end of mln
+
+#endif // MLN_CORE_BGRAPH_PSITE_HH
Index: mln/util/internal/boost_graph.hh
--- mln/util/internal/boost_graph.hh (revision 1760)
+++ mln/util/internal/boost_graph.hh (working copy)
@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_UTIL_BOOST_GRAPH_HH
-# define MLN_UTIL_BOOST_GRAPH_HH
+#ifndef MLN_UTIL_INTERNAL_BOOST_GRAPH_HH
+# define MLN_UTIL_INTERNAL_BOOST_GRAPH_HH
/// \file mln/util/internal/boost_graph.hh
/// \brief Definition of the boost::adjacenly_list decorator.
@@ -39,12 +39,15 @@
namespace util
{
+ struct empty {};
+
namespace internal
{
/// \brief Boost graph decorator base
/// Graph class which rests on boost::adjacency_list class.
- template <typename VertexProperty, typename EdgeProperty>
+ template <typename VertexProperty = empty,
+ typename EdgeProperty = empty>
class boost_graph
{
typedef boost_graph<VertexProperty, EdgeProperty> self_type;
@@ -74,8 +77,12 @@
typedef typename decorated::edge_parallel_category
edge_parallel_category;
typedef typename decorated::vertex_property_type vertex_property_type;
+ typedef typename decorated::edge_property_type edge_property_type;
typedef typename decorated::graph_tag graph_tag;
+ /// Properties.
+ typedef typename decorated::vertex_bundled vertex_bundled;
+
/// Sizes.
typedef typename decorated::vertices_size_type vertices_size_type;
typedef typename decorated::edges_size_type edges_size_type;
@@ -108,6 +115,10 @@
const decorated&
graph() const;
+ /// Provides acces to the graph bundle properties
+ vertex_bundled& operator[](vertex_descriptor v);
+ const vertex_bundled& operator[](vertex_descriptor v) const;
+
protected:
decorated graph_;
@@ -161,19 +172,39 @@
}
template <typename VertexProp, typename EdgeProp>
- inline typename boost_graph<VertexProp, EdgeProp>::decorated&
+ inline
+ typename boost_graph<VertexProp, EdgeProp>::decorated&
boost_graph<VertexProp, EdgeProp>::graph()
{
return this->graph_;
}
template <typename VertexProp, typename EdgeProp>
- inline const typename boost_graph<VertexProp, EdgeProp>::decorated&
+ inline
+ const typename boost_graph<VertexProp, EdgeProp>::decorated&
boost_graph<VertexProp, EdgeProp>::graph() const
{
return this->graph_;
}
+ template <typename V, typename E>
+ inline
+ typename boost_graph<V, E>::vertex_bundled&
+ boost_graph<V, E>::operator[](typename boost_graph<V, E>::
+ vertex_descriptor v)
+ {
+ return this->graph_[v];
+ }
+
+ template <typename V, typename E>
+ inline
+ const typename boost_graph<V, E>::vertex_bundled&
+ boost_graph<V, E>::operator[](typename boost_graph<V, E>::
+ vertex_descriptor v) const
+ {
+ return this->graph_[v];
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::util::internal
@@ -186,4 +217,4 @@
# include "boost_graph_structure.hh"
# include "boost_graph_property.hh"
-#endif // ! MLN_UTIL_BOOST_GRAPH_HH
+#endif // ! MLN_UTIL_INTERNAL_BOOST_GRAPH_HH
Index: mln/util/internal/boost_graph_structure.hh
--- mln/util/internal/boost_graph_structure.hh (revision 1760)
+++ mln/util/internal/boost_graph_structure.hh (working copy)
@@ -64,7 +64,8 @@
std::pair<typename mlnu::boost_graph<VProp, EProp>::edge_descriptor, bool>
add_edge(typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor u,
typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor v,
- const typename mlnu::boost_graph<VProp, EProp>::EdgeProperties& p,
+ const typename mlnu::boost_graph<VProp, EProp>::
+ edge_property_type& p,
typename mlnu::boost_graph<VProp, EProp>& g);
/// \brief Removes the edge (u,v) from the graph.
@@ -122,7 +123,8 @@
/// Returns the vertex descriptor for the new vertex.
template <typename VProp, typename EProp>
typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor
- add_vertex(const typename mlnu::boost_graph<VProp, EProp>::VertexProperties& p,
+ add_vertex(const typename mlnu::boost_graph<VProp, EProp>::
+ vertex_property_type& p,
typename mlnu::boost_graph<VProp, EProp>& g);
/// \brief Removes all edges to and from vertex u.
@@ -170,7 +172,8 @@
bool>
add_edge(typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor u,
typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor v,
- const typename mlnu::boost_graph<VProp, EProp>::EdgeProperties& p,
+ const typename mlnu::boost_graph<VProp, EProp>::
+ edge_property_type& p,
typename mlnu::boost_graph<VProp, EProp>& g)
{
return add_edge(u, v, p, g.graph());
@@ -235,7 +238,8 @@
template <typename VProp, typename EProp>
typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor
- add_vertex(const typename mlnu::boost_graph<VProp, EProp>::VertexProperties& p,
+ add_vertex(const typename mlnu::boost_graph<VProp, EProp>::
+ vertex_property_type& p,
typename mlnu::boost_graph<VProp, EProp>& g)
{
return add_vertex(p, g.graph());
1
0
03 Mar '08
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2008-03-03 Caroline Vigouroux <vigour_c(a)epita.fr>
loading image and convertion in new color mode test.
* color/is_HSI.cc: test conversion.
* color/my_hsi.hh: correct a bug.
* color/rgb_to_hsi.hh: correct a bug.
* color/rgb_to_xyz.hh: correct a bug.
* color/tests.cc: test conversion.
* load.cc: New loader.
* tests.cc: New tests.
---
color/is_HSI.cc | 13 +++++++
color/my_hsi.hh | 94 ++++++++++++++++++++++++++--------------------------
color/rgb_to_hsi.hh | 66 +++++++++++++++++++++++++++++-------
color/rgb_to_xyz.hh | 3 -
color/tests.cc | 3 +
load.cc | 38 +++++++++++++++++++++
tests.cc | 31 +++++++++++++++++
7 files changed, 186 insertions(+), 62 deletions(-)
Index: trunk/milena/sandbox/vigouroux/load.cc
===================================================================
--- trunk/milena/sandbox/vigouroux/load.cc (revision 0)
+++ trunk/milena/sandbox/vigouroux/load.cc (revision 1760)
@@ -0,0 +1,38 @@
+#include <mln/core/image2d.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/display/save_and_show.hh>
+#include <mln/value/rgb.hh>
+#include <mln/value/rgb8.hh>
+
+#include <mln/io/ppm/load.hh>
+#include <mln/io/ppm/save.hh>
+#include <mln/math/round.hh>
+#include <mln/level/transform.hh>
+
+#include <mln/core/w_window2d_float.hh>
+#include <mln/border/thickness.hh>
+#include <mln/linear/convolve.hh>
+
+# include <mln/display/save.hh>
+# include <mln/display/show.hh>
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+ image2d<mln::value::rgb8> lena;
+ io::ppm::load(lena, "../../img/lena.ppm");
+// image2d<mln::value::hsi_3x8> inter(lena.domain());
+ image2d<mln::value::rgb8> out(lena.domain());
+ const image2d<mln::value::rgb8> input = exact(lena);
+
+// mln_piter(image2d<mln::value::rgb8>) p(input.domain());
+// for_all(p)
+// {
+// inter(p) = fun::v2v::f_rgb_to_hsi_3x8(p);
+
+// }
+
+ display::save_and_show (lena, "display", 1);
+}
+
Index: trunk/milena/sandbox/vigouroux/tests.cc
===================================================================
--- trunk/milena/sandbox/vigouroux/tests.cc (revision 0)
+++ trunk/milena/sandbox/vigouroux/tests.cc (revision 1760)
@@ -0,0 +1,31 @@
+#include <mln/core/image_if_value.hh>
+#include <mln/core/inplace.hh>
+#include <mln/core/w_window2d_int.hh>
+#include <mln/display/show.hh>
+#include <mln/io/ppm/save.hh>
+#include <mln/display/save_and_show.hh>
+#include <mln/level/fill.hh>
+
+#include "rgb_to_yuv.hh"
+#include "my_yuv.hh"
+
+#include "rgb_to_xyz.hh"
+#include "my_xyz.hh"
+
+#include "rgb_to_cmy.hh"
+#include "my_cmy.hh"
+
+#include "rgb_to_hsi.hh"
+#include "my_hsi.hh"
+
+int main()
+{
+ using namespace mln;
+
+ struct value::yuv<8> yuv(4, 4, 4);
+ std::cout << yuv.y() << std::endl;
+ std::cout << yuv.u() << std::endl;
+ std::cout << yuv.v() << std::endl;
+
+ return (0);
+}
Index: trunk/milena/sandbox/vigouroux/color/rgb_to_xyz.hh
===================================================================
--- trunk/milena/sandbox/vigouroux/color/rgb_to_xyz.hh (revision 1759)
+++ trunk/milena/sandbox/vigouroux/color/rgb_to_xyz.hh (revision 1760)
@@ -25,7 +25,7 @@
xyz.z(0.010 * rgb.green() + 0.990 * rgb.blue());
return (xyz);
-_ }
+ }
};
struct f_xyz_to_rgb
@@ -33,7 +33,6 @@
struct value::rgb<8>
doit(const struct value::xyz<8> xyz) const
{
- struct value::rgb<8> rgb;
int r;
int g;
int b;
Index: trunk/milena/sandbox/vigouroux/color/tests.cc
===================================================================
--- trunk/milena/sandbox/vigouroux/color/tests.cc (revision 1759)
+++ trunk/milena/sandbox/vigouroux/color/tests.cc (revision 1760)
@@ -9,6 +9,9 @@
#include "rgb_to_yuv.hh"
#include "my_yuv.hh"
+#include "rgb_to_xyz.hh"
+#include "my_xyz.hh"
+
#include "rgb_to_cmy.hh"
#include "my_cmy.hh"
Index: trunk/milena/sandbox/vigouroux/color/my_hsi.hh
===================================================================
--- trunk/milena/sandbox/vigouroux/color/my_hsi.hh (revision 1759)
+++ trunk/milena/sandbox/vigouroux/color/my_hsi.hh (revision 1760)
@@ -21,14 +21,14 @@
{
};
- template <typename F>
- class hsi_ : public HSI< hsi_<F> >
+ template <typename H, typename S, typename I>
+ class hsi_ : public HSI< hsi_<H,S,I> >
{
public:
- typedef F h_type;
- typedef F s_type;
- typedef F i_type;
+ typedef H h_type;
+ typedef S s_type;
+ typedef I i_type;
/// Constructor without argument.
hsi_()
@@ -36,50 +36,50 @@
}
/// Constructor from component values.
- hsi_(const F& h, const F& s, const F& i)
- : h_(h),
- s_(s),
- i_(i)
+ hsi_(const H& hue, const S& sat, const I& i)
+ : hue_(hue),
+ sat_(sat),
+ int_(i)
{
}
- /// Read-only access to the h component.
- const F& h() const
+ /// Read-only access to the hue component.
+ const H& hue() const
{
- return this->h_;
+ return this->hue_;
}
- const F& s() const
+ const S& sat() const
{
- return this->s_;
+ return this->sat_;
}
- const F& i() const
+ const I& i() const
{
- return this->i_;
+ return this->int_;
}
- /// Read-write access to the h component.
- F& h()
+ /// Read-write access to the hue component.
+ H& hue()
{
- return this->h_;
+ return this->hue_;
}
- F& s()
+ S& sat()
{
- return this->s_;
+ return this->sat_;
}
- F& i()
+ I& i()
{
- return this->i_;
+ return this->int_;
}
private:
- F h_;
- F s_;
- F i_;
+ H hue_;
+ S sat_;
+ I int_;
};
- typedef hsi_<float01_8> hsi_3x8;
+ typedef hsi_<float, float, float> hsi_3x8;
- typedef hsi_<double> hsi_d;
+ typedef hsi_<double, double, double> hsi_d;
@@ -91,32 +91,32 @@
hsi<n>();
/// Constructor from component values.
- hsi<n>(int h, int s, int i);
+ hsi<n>(double hue, double sat, double i);
/// Access to component values.
- double h() const { return this->h_; }
- double s() const { return this->s_; }
- double i() const { return this->i_; }
+ double hue() const { return this->hue_; }
+ double sat() const { return this->sat_; }
+ double i() const { return this->int_; }
/// Set component values.
- void h(double h)
+ void hue(double hue)
{
- this->h_ = h;
+ this->hue_ = hue;
}
- void s(double s)
+ void sat(double sat)
{
- this->s_ = s;
+ this->sat_ = sat;
}
void i(double i)
{
mln_precondition(i >= 0);
- this->i_ = i;
+ this->int_ = i;
}
private:
- double h_;
- double s_;
- double i_;
+ double hue_;
+ double sat_;
+ double int_;
};
@@ -125,19 +125,19 @@
template <unsigned n>
inline
hsi<n>::hsi()
- :h_(0), s_(0), i_(0)
+ :hue_(0), sat_(0), int_(0)
{
}
template <unsigned n>
inline
- hsi<n>::hsi(int h, int s, int i)
+ hsi<n>::hsi(double h, double sat, double i)
{
- mln_precondition(h >= 0);
- mln_precondition(s >= 0);
- mln_precondition(i >= 0);
- this->h_ = h;
- this->s_ = s;
+ mln_invariant(h >= 0);
+ mln_invariant(sat >= 0);
+ mln_invariant(i >= 0);
+ this->hue_ = h;
+ this->sat_ = sat;
this->i_ = i;
}
Index: trunk/milena/sandbox/vigouroux/color/is_HSI.cc
===================================================================
--- trunk/milena/sandbox/vigouroux/color/is_HSI.cc (revision 1759)
+++ trunk/milena/sandbox/vigouroux/color/is_HSI.cc (revision 1760)
@@ -16,5 +16,18 @@
std::cout << mlc_is_a(rgb8, HSI)::value << std::endl;
rgb8 c(255, 10, 1);
+ rgb8 other(10, 20, 30);
+
+ // Essai en 0 255
+
hsi_3x8 c_hsi = fun::v2v::f_rgb_to_hsi_3x8(c);
+ rgb8 c2 = fun::v2v::f_hsi_to_rgb_3x8(c_hsi);
+ std::cout << "c = " << c << std::endl;
+ std::cout << "c2 = " << c2 << std::endl;
+
+ hsi_3x8 c_cool = fun::v2v::f_rgb_to_hsi_3x8(other);
+ rgb8 coucou = fun::v2v::f_hsi_to_rgb_3x8(c_cool);
+
+ std::cout << "c = " << other << std::endl;
+ std::cout << "c2 = " << coucou << std::endl;
}
Index: trunk/milena/sandbox/vigouroux/color/rgb_to_hsi.hh
===================================================================
--- trunk/milena/sandbox/vigouroux/color/rgb_to_hsi.hh (revision 1759)
+++ trunk/milena/sandbox/vigouroux/color/rgb_to_hsi.hh (revision 1760)
@@ -1,3 +1,4 @@
+
#include <cmath>
#include <mln/core/image_if_value.hh>
@@ -49,11 +50,11 @@
std::cout << "FIXME: " << tmp << std::endl;
}
- hsi.h() = atan2(beta, alpha) / 3.1415 * 180.0;
- if (hsi.h() < 0)
- hsi.h() = hsi.h() + 360.0;
- mln_invariant(hsi.h() >= 0);
- hsi.s() = std::sqrt(alpha * alpha + beta * beta);
+ hsi.hue() = atan2(beta, alpha) / 3.1415 * 180.0;
+ if (hsi.hue() < 0)
+ hsi.hue() = hsi.hue() + 360.0;
+ mln_invariant(hsi.hue() >= 0);
+ hsi.sat() = std::sqrt(alpha * alpha + beta * beta);
hsi.i() = sqrt3_3 * rgb.red() + sqrt3_3 * rgb.green() + sqrt3_3 * rgb.blue();
return hsi;
@@ -66,6 +67,45 @@
// end of NEW
+ // NEW2
+
+ template <typename T_rgb>
+ struct f_hsi_to_rgb_ : public Function_v2v< f_hsi_to_rgb_<T_rgb> >
+ {
+ typedef T_rgb result;
+
+ template <typename T_hsi>
+ T_rgb operator()(const T_hsi& hsi) const
+ {
+ int r;
+ int g;
+ int b;
+
+ static const double sqrt3_3 = sqrt(3) / 3;
+ static const double inv_sqrt6 = 1 / sqrt(6);
+ static const double inv_sqrt2 = 1 / sqrt(2);
+
+ double h = hsi.hue() / 180.0 * 3.1415;
+ double alpha = hsi.sat() * cos(h);
+ double beta = hsi.sat() * sin(h);
+
+ r = int(sqrt3_3 * hsi.i() + 2 * inv_sqrt6 * beta);
+ g = int(sqrt3_3 * hsi.i() + inv_sqrt2 * alpha - inv_sqrt6 * beta);
+ b = int(sqrt3_3 * hsi.i() - inv_sqrt2 * alpha - inv_sqrt6 * beta);
+
+ T_rgb rgb(r, g, b);
+
+ return rgb;
+ }
+ };
+
+ typedef f_hsi_to_rgb_<value::rgb8> f_hsi_to_rgb_3x8_t;
+
+ f_hsi_to_rgb_3x8_t f_hsi_to_rgb_3x8;
+
+ // end of NEW2
+
+
} // end of namespace fun::v2v
} // end of namespace fun
@@ -88,11 +128,11 @@
double alpha = inv_sqrt2 * rgb.green() - inv_sqrt2 * rgb.blue();
double beta = 2 * inv_sqrt6 * rgb.red() - inv_sqrt6 * rgb.green() - inv_sqrt6 * rgb.blue();
- hsi.h(atan2(beta, alpha) / 3.1415 * 180.0);
- if (hsi.h() < 0)
- hsi.h(hsi.h() + 360.0);
- mln_precondition(hsi.h() >= 0);
- hsi.s(sqrt(alpha * alpha + beta * beta));
+ hsi.hue(atan2(beta, alpha) / 3.1415 * 180.0);
+ if (hsi.hue() < 0)
+ hsi.hue(hsi.hue() + 360.0);
+ mln_precondition(hsi.hue() >= 0);
+ hsi.sat(sqrt(alpha * alpha + beta * beta));
hsi.i(sqrt3_3 * rgb.red() + sqrt3_3 * rgb.green() + sqrt3_3 * rgb.blue());
return hsi;
@@ -113,9 +153,9 @@
double inv_sqrt6 = 1 / sqrt(6);
double inv_sqrt2 = 1 / sqrt(2);
- double h = hsi.h() / 180.0 * 3.1415;
- double alpha = hsi.s() * cos(h);
- double beta = hsi.s() * sin(h);
+ double h = hsi.hue() / 180.0 * 3.1415;
+ double alpha = hsi.sat() * cos(h);
+ double beta = hsi.sat() * sin(h);
r = int(sqrt3_3 * hsi.i() + 2 * inv_sqrt6 * beta);
g = int(sqrt3_3 * hsi.i() + inv_sqrt2 * alpha - inv_sqrt6 * beta);
1
0
https://svn.lrde.epita.fr/svn/oln/trunk
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Start a description of image types.
* milena/doc/tutorial/image_types.txt: New.
image_types.txt | 364 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 364 insertions(+)
Index: milena/doc/tutorial/image_types.txt
--- milena/doc/tutorial/image_types.txt (revision 0)
+++ milena/doc/tutorial/image_types.txt (revision 0)
@@ -0,0 +1,364 @@
+ -*- outline -*-
+
+
+* image interface
+
+** at a glance
+
+ima : domain -> destination
+ p -> ima(p)
+
+
+object type
+---------------------------
+ima I
+
+ima.domain I::pset
+ima.destination() I::vset
+
+p like I::site
+ima(p) like I::value
+
+
+impl detail:
+signature is "ima(p : psite) : rvalue"
+
+
+** about domain and destination
+
+ima.domain is usually a mathematical set. Yet it can be a
+multiset (a bag) but then weird things might happen...
+
+ima.destination is a set. Every value, that is ima(p) with p in
+ima.domain, is taken from this set. For instance, a color image can
+be defined with the destination being of type value::set<rgb_3x8>.
+
+Classically, some image types are defined by couples (p,v) where v +ima(p). A given cell, location in RAM or in a file, corresponds to a
+point p and stores the corresponding value. So when we have N points,
+we also have N value cells. To iterate over pixel values, we then
+iterate over the definition domain and access values through ima(p):
+
+code A)
+ for all p of ima.domain
+ | v = ima(p)
+ | print v.
+
+The set of possible taken values in ima is the destination set. If
+this set has a reasonable size, we can iterate over:
+
+code B)
+ for all v of ima.destination
+ | print v.
+
+Sometimes, the number of value cells is much less than the number of
+points. To access the image values, it is more efficient to iterate
+over those cells:
+
+code C)
+ for all v of ima.values
+ | print v.
+
+Consider for instance the following image:
+
++-----+
+| 2 |
+| 111|
+| 22 |
++-----+
+
+The value type is int_u2 (unsigned integer on 2 bit), that is, the
+type of the interval [0,3] of N. The image is defined by a run-length
+encoding with a single value per run. Precisely, this image is:
+
+{ ((a,1),2), ((b,3),1), ((c,2),2) }
+ ^^^ ^
+1st run |
+ value of the 1st run
+
+where a, b, and c designate the respective starting point of each run:
+
++-----+
+| a |
+| b |
+| c |
++-----+
+
+It leads to:
+ code A) 211122 because we browse points
+ code B) 0123 because we browse [0,3]N
+and with :
+ code C) 212 because we browse the image value cells;
+ those cells are depicted below.
+ v v v
+ { ((a,1),2), ((b,3),1), ((c,2),2) }
+
+
+** associated types
+
+mesh (? support)
+pset (? domain_t)
+site
+psite
+
+value
+rvalue
+lvalue
+vset
+
+coord
+dpoint
+
+fwd_piter
+bkd_piter
+
+skeleton
+
+
+** methods
+
+*** values
+
+bool has_data() const
+// FIXME: ? better name is is_allocated Nota bene: is_initialized means "has relevant data"!
+
+const pset& domain() const
+bool has(const psite& p) const
+bool owns_(const psite& p) const
+
+const box_<point>& bbox() const
+std::size_t npoints() const
+
+rvalue operator()(const psite& p) const
+lvalue operator()(const psite& p)
+
+const vset& destination() const // was: values()
+
+
+
+* properties
+
+
+** general
+
+
+*** category
+|
++ -- primary
+|
++ -- /morpher/
+ |
+ + -- identity_morpher
+ |
+ + -- domain_morpher
+ |
+ + -- value_morpher
+
+**** primary
+
+Image type instantiable at the first place (without any prior image
+being defined).
+
+**** morpher
+
+Image type that relies on another image type or on several
+ones; it looks like M<I>. In the following, ima' (of type I') is a
+morpher instance where ima (of type I) is the underlying pre-existing
+image.
+
+**** domain_morpher
+
+A morpher that only changes the definition domain;
+we have ima'.domain != ima.domain but I'::value = I::value and
+for all p in ima'.domain inter ima.domain, ima'(p) = ima(p).
+
+The resulting domain can be larger or smaller than the first one.
+
+FIXME: What about changing only the "extended domain" (via modifying
+the behavior of owns_)?
+
+**** value_morpher
+
+A morpher that only changes the values; we have ima'.domain =
+ima.domain but the function ima' is different from ima because either
+some values change (for some p, ima'(p) != ima(p)) or the type of
+values change.
+
+**** identity_morpher
+
+A morpher that does not change the domain nor the values.
+So ima'.domain = ima.domain and for all p, ima'(p) = ima(p).
+
+
+
+** related to value
+
+
+*** kind
+|
++ -- color
+|
++ -- gray
+|
++ ----------- label
+| |
+| +-- named
++ -- /logic/ |
+| | |
+| + -- /mvlogic/
+| | |
+| | + -- binary
+| | |
+| | + -- ternary
+| |
+| + -- fuzzy
+|
++ -- data
+|
+|
++ -- /map/
+ |
+ + -- distance
+
+FIXME: Apply change on mln.
+IDEA: map or field (for deformation field).
+
+Nota bene: mvlogic stands for "multi-valued logic".
+
+
+*** quant
+|
++ -- low
+|
++ -- high
+
+****
+
+*** value
+|
++ -- scalar
+|
++ -- vectorial
+|
++ -- structed
+|
++ -- pointer
+
+FIXME: Make the difference between homogeneous and heterogeneous
+vectors...
+
+
+
+** related to pset
+
+
+*** access
+|
++ -- random
+|
++ -- browsing
+
+
+*** space
+|
++ -- one_d
+|
++ -- two_d
+|
++ -- three_d
+
+
+*** size
+|
++ -- huge
+|
++ -- regular
+
+
+*** support
+|
++ -- irregular
+|
++ -- regular
+ |
+ + -- aligned
+
+
+** global
+
+
+*** border
+|
++ -- none
+|
++ -- /some/
+ |
+ + -- stored
+ |
+ + -- computed
+
+
+*** neighb
+|
++ -- none
+|
++ -- /some/
+
+
+*** data
+|
++ -- stored
+| |
+| + -- semilinear
+| |
+| + -- oneblock
+|
++ -- computed
+
+Was: stored > linear > raw.
+
+FIXME: What about mmap?
+
+
+*** io
+|
++ ------------------------ /read/
+| | \
+| | + -- read_only
+| |
++ -- /write/ |
+ | \ |
+ | + -- write_only |
+ | |
+ \_________________ |
+ \ |
+ read_write
+
+*** speed
+|
++ -- slow
+|
++ -- fast
+ |
+ + -- fastest
+
+fastest = ( data = oneblock
+ and border = stored
+ and support = aligned
+ and size = regular )
+
+
+* primary images
+
+** image2d<T>
+
+** fun_image<S,F>
+
+pset = S
+f : p -> v
+read_only
+
+
+* value morpher
+
+pset is
\ No newline at end of file
1
0
URL: https://svn.lrde.epita.fr/svn/scool/trunk
ChangeLog:
2008-03-01 Maxime van Noppen <yabo(a)lrde.epita.fr>
Migrate from SCOOP to Milena
* Makefile: Remove.
* pp-cxx-ng: New.
* scoolt-ng: New.
* pp-cxx/CxxProgram.str: Remove any.hh and find_exact.hh from generated code.
* pp-cxx/CxxType.str: Fix typo.
* scoolt/Decl.str: Remove the static stuff.
pp-cxx-ng/CxxDecl.meta | 1
pp-cxx-ng/CxxDecl.str | 90 ++++++++++++++++++
pp-cxx-ng/CxxExp.str | 31 ++++++
pp-cxx-ng/CxxFun.meta | 1
pp-cxx-ng/CxxFun.str | 69 +++++++++++++
pp-cxx-ng/CxxId.meta | 1
pp-cxx-ng/CxxId.str | 12 ++
pp-cxx-ng/CxxProgram.meta | 1
pp-cxx-ng/CxxProgram.str | 15 +++
pp-cxx-ng/CxxStm.meta | 1
pp-cxx-ng/CxxStm.str | 8 +
pp-cxx-ng/CxxType.meta | 1
pp-cxx-ng/CxxType.str | 25 +++++
pp-cxx-ng/Makefile.am | 21 ++++
pp-cxx-ng/pp-cxx.meta | 1
pp-cxx-ng/pp-cxx.str | 6 +
pp-cxx/CxxProgram.str | 5 -
pp-cxx/CxxType.str | 2
scoolt-ng/Access.str | 15 +++
scoolt-ng/Decl.str | 229 ++++++++++++++++++++++++++++++++++++++++++++++
scoolt-ng/Exp.str | 21 ++++
scoolt-ng/Makefile.am | 21 ++++
scoolt-ng/Program.str | 8 +
scoolt-ng/Stm.str | 21 ++++
scoolt-ng/Tools.str | 29 +++++
scoolt-ng/Type.str | 32 ++++++
scoolt-ng/scoolt.str | 184 ++++++++++++++++++++++++++++++++++++
scoolt/Decl.str | 39 +++----
28 files changed, 866 insertions(+), 24 deletions(-)
Index: trunk/src/Makefile (deleted)
===================================================================
Index: trunk/src/pp-cxx/CxxProgram.str
===================================================================
--- trunk/src/pp-cxx/CxxProgram.str (revision 49)
+++ trunk/src/pp-cxx/CxxProgram.str (revision 50)
@@ -8,8 +8,9 @@
CxxProgram(l) ->
V vs=1 [
V vs=0 [
- "#include <stc/any.hh>"
- "#include <stc/find_exact.hh>"
+ // FIXME: includes
+ //"#include <stc/any.hh>"
+ //"#include <stc/find_exact.hh>"
]
V vs=0 [ ~*<map(CxxTopLevelToAbox)> l ]
]
Index: trunk/src/pp-cxx/CxxType.str
===================================================================
--- trunk/src/pp-cxx/CxxType.str (revision 49)
+++ trunk/src/pp-cxx/CxxType.str (revision 50)
@@ -19,7 +19,7 @@
CxxTypeToAbox:
Typename -> S("typename")
- /* These function are actually macros */
+ /* These functions are actually macros */
CxxTypeToAbox:
CxxFunCall(idf, args) -> H hs=0 [ ~<CxxIdToAbox>idf "(" H hs=1 [ ~*<CxxListToAbox(CxxTypeToAbox <+ CxxExpToAbox|",")>args ] ")"]
Index: trunk/src/pp-cxx-ng/CxxProgram.meta
===================================================================
--- trunk/src/pp-cxx-ng/CxxProgram.meta (revision 0)
+++ trunk/src/pp-cxx-ng/CxxProgram.meta (revision 50)
@@ -0,0 +1 @@
+Meta([Syntax("Stratego-Box")])
Index: trunk/src/pp-cxx-ng/CxxDecl.meta
===================================================================
--- trunk/src/pp-cxx-ng/CxxDecl.meta (revision 0)
+++ trunk/src/pp-cxx-ng/CxxDecl.meta (revision 50)
@@ -0,0 +1 @@
+Meta([Syntax("Stratego-Box")])
Index: trunk/src/pp-cxx-ng/CxxFun.str
===================================================================
--- trunk/src/pp-cxx-ng/CxxFun.str (revision 0)
+++ trunk/src/pp-cxx-ng/CxxFun.str (revision 50)
@@ -0,0 +1,69 @@
+module CxxFun
+
+imports Cxx Box libstratego-lib CxxType CxxExp CxxStm CxxId
+
+rules
+
+ CxxTopLevelToAbox:
+ CxxFun(params, t, idf, args) ->
+ V vs=0
+ [
+ ~<CxxParamsToAbox> params
+ H hs=0
+ [
+ H hs=1 [ ~<CxxTypeToAbox> t ~<CxxIdToAbox> idf ] "(" H hs=1 [ ~*<CxxListToAbox(CxxArgDefToAbox|",")> args ] ")" ";"
+ ]
+ ]
+
+ CxxTopLevelToAbox:
+ CxxFun(params, t, idf, args, body) ->
+ V vs=0
+ [
+ ~<CxxParamsToAbox> params
+ H hs=0 [
+ H hs=1 [ ~<CxxTypeToAbox>t ~<CxxIdToAbox>idf] "(" H hs=1 [ ~*<CxxListToAbox(CxxArgDefToAbox|",")> args ] ")"
+ ]
+ V vs=0 is=2
+ [
+ "{"
+ ~*<map(CxxStmToAbox <+ CxxTopLevelToAbox)>body
+ ]
+ "}"
+ ]
+
+ CxxTopLevelToAbox:
+ CxxTypedef(t, idf) ->
+ H hs=0 [ H hs=1 [ "typedef" ~<CxxTypeToAbox> t ~S(idf)] ";" ]
+
+ CxxArgDefToAbox:
+ (t, idf) ->
+ H hs = 1
+ [
+ ~<CxxTypeToAbox>t
+ ~<CxxIdToAbox>idf
+ ]
+
+ CxxListToAbox(sub|sep):
+ [e| [h|tail] ] ->
+ [
+ H hs=1 [
+ H hs=0 [
+ ~<sub>e
+ ~S(sep)
+ ]
+ ~<CxxListToAbox(sub|sep)> [h|tail]
+ ]
+ ]
+
+ CxxListToAbox(sub|sep):
+ [e| [] ] ->
+ [
+ H hs=0 [
+ ~<sub>e
+ ]
+ ]
+
+ CxxListToAbox(sub|sep):
+ [] ->
+ [ H [] ]
+
Index: trunk/src/pp-cxx-ng/pp-cxx.str
===================================================================
--- trunk/src/pp-cxx-ng/pp-cxx.str (revision 0)
+++ trunk/src/pp-cxx-ng/pp-cxx.str (revision 50)
@@ -0,0 +1,6 @@
+module pp-cxx
+
+imports Cxx Box libstratego-lib CxxProgram
+
+strategies
+ pp-cxx = io-wrap(CxxProgramToAbox)
Index: trunk/src/pp-cxx-ng/CxxId.str
===================================================================
--- trunk/src/pp-cxx-ng/CxxId.str (revision 0)
+++ trunk/src/pp-cxx-ng/CxxId.str (revision 50)
@@ -0,0 +1,12 @@
+module CxxId
+
+imports Cxx Box libstratego-lib
+
+rules
+
+ CxxIdToAbox:
+ x -> S(x)
+ where not(<?CxxScope(_, _)> x)
+
+ CxxIdToAbox:
+ CxxScope(idf1, idf2) -> H hs=0 [ ~<CxxIdToAbox>idf1 "::" ~<CxxIdToAbox>idf2 ]
Index: trunk/src/pp-cxx-ng/CxxExp.str
===================================================================
--- trunk/src/pp-cxx-ng/CxxExp.str (revision 0)
+++ trunk/src/pp-cxx-ng/CxxExp.str (revision 50)
@@ -0,0 +1,31 @@
+module CxxExp
+
+imports Cxx Box libstratego-lib CxxId
+
+rules
+
+ CxxExpToAbox:
+ CxxInt(i) -> S(i)
+
+ CxxExpToStr:
+ CxxInt(i) -> i
+
+ CxxExpToStr:
+ CxxSum(e1, e2) -> <concat-strings> [<CxxExpToStr> e1, " + ", <CxxExpToStr> e2]
+
+ CxxExpToStr:
+ x -> x
+ where <is-string> x
+
+ /*
+ * Handle the CxxKeyword ctor.
+ * TODO: Generalize the type of exp.
+ */
+ CxxExpToAbox:
+ CxxKeyword(idf, exp) -> S(<concat-strings> [idf, " ", <CxxExpToStr> exp, ";"])
+
+ CxxExpToAbox:
+ CxxAffect(idf, exp) -> S(<concat-strings> [idf, " = ", <CxxExpToStr> exp, ";"])
+
+ CxxExpToAbox:
+ x -> S(x)
Index: trunk/src/pp-cxx-ng/CxxType.meta
===================================================================
--- trunk/src/pp-cxx-ng/CxxType.meta (revision 0)
+++ trunk/src/pp-cxx-ng/CxxType.meta (revision 50)
@@ -0,0 +1 @@
+Meta([Syntax("Stratego-Box")])
Index: trunk/src/pp-cxx-ng/CxxStm.str
===================================================================
--- trunk/src/pp-cxx-ng/CxxStm.str (revision 0)
+++ trunk/src/pp-cxx-ng/CxxStm.str (revision 50)
@@ -0,0 +1,8 @@
+module CxxStm
+
+imports Cxx Box libstratego-lib CxxType CxxExp CxxId
+
+rules
+
+ CxxStmToAbox:
+ CxxExpStm(e) -> <CxxExpToAbox> e
Index: trunk/src/pp-cxx-ng/CxxFun.meta
===================================================================
--- trunk/src/pp-cxx-ng/CxxFun.meta (revision 0)
+++ trunk/src/pp-cxx-ng/CxxFun.meta (revision 50)
@@ -0,0 +1 @@
+Meta([Syntax("Stratego-Box")])
Index: trunk/src/pp-cxx-ng/CxxProgram.str
===================================================================
--- trunk/src/pp-cxx-ng/CxxProgram.str (revision 0)
+++ trunk/src/pp-cxx-ng/CxxProgram.str (revision 50)
@@ -0,0 +1,15 @@
+module CxxProgram
+
+imports Cxx Box libstratego-lib CxxDecl CxxFun
+
+rules
+
+ CxxProgramToAbox:
+ CxxProgram(l) ->
+ V vs=1 [
+ V vs=0 [
+ "#include <stc/any.hh>"
+ "#include <stc/find_exact.hh>"
+ ]
+ V vs=0 [ ~*<map(CxxTopLevelToAbox)> l ]
+ ]
Index: trunk/src/pp-cxx-ng/CxxDecl.str
===================================================================
--- trunk/src/pp-cxx-ng/CxxDecl.str (revision 0)
+++ trunk/src/pp-cxx-ng/CxxDecl.str (revision 50)
@@ -0,0 +1,90 @@
+module CxxDecl
+
+imports Cxx Box libstratego-lib CxxType CxxExp CxxId
+
+rules
+
+ CxxTopLevelToAbox:
+ l ->
+ V vs=1 [
+ ~*<map(CxxTopLevelToAbox)>l
+ ]
+
+ CxxTopLevelToAbox:
+ CxxDecl(t, idf) -> H hs=0 [ H hs=1 [ ~<CxxTypeToAbox>t ~<CxxIdToAbox>idf ] ";"]
+
+ CxxTopLevelToAbox:
+ CxxDecl(t, idf, v) -> H hs=0 [ H hs=1 [ ~<CxxTypeToAbox>t ~<CxxIdToAbox>idf "=" ~<CxxExpToAbox> v] ";"]
+
+ CxxTopLevelToAbox:
+ CxxArrayDecl(t, idf, n) -> H hs=0 [ H hs=1 [ ~<CxxTypeToAbox> t ~<CxxIdToAbox> idf] "[" ~<CxxExpToAbox> n "]" ";" ]
+
+ CxxTopLevelToAbox:
+ CxxClassDecl(params, idf, parents) ->
+ V vs=0 [
+ ~<CxxParamsToAbox> params
+ H hs=0 [
+ H hs=1 [ "class" ~<CxxIdToAbox>idf ]
+ ~<CxxParentsToAbox>parents
+ ";"
+ ]
+ ]
+
+ CxxTopLevelToAbox:
+ CxxClassDecl(params, idf, parents) ->
+ V vs=0 [
+ ~<CxxParamsToAbox> params
+ H hs=0 [
+ H hs=1 [ "class" ~<CxxIdToAbox>idf ]
+ ~<CxxParentsToAbox>parents
+ ";"
+ ]
+ ]
+
+ CxxTopLevelToAbox:
+ CxxComment(txt) ->
+ H hs=1 [ "//" ~S(txt) ]
+
+// FIXME: MERGE!!!
+
+ CxxBodyToAbox:
+ CxxPublic(b) -> V is=2 [ "public:" V [ ~*<map(CxxTopLevelToAbox)> b ] ]
+
+ CxxBodyToAbox:
+ CxxProtected(b) -> V is=2 [ "private:" V [ ~*<map(CxxTopLevelToAbox)> b ] ]
+
+ CxxBodyToAbox:
+ CxxPrivate(b) -> V is=2 [ "private:" V [ ~*<map(CxxTopLevelToAbox)> b ] ]
+
+ CxxTopLevelToAbox:
+ CxxClassDecl(params, idf, parents, body) ->
+ V vs=0 [
+ ~<CxxParamsToAbox> params
+ H hs=0 [
+ H hs=1 [ "class" ~<CxxIdToAbox> idf ]
+ ~<CxxParentsToAbox> parents
+ ]
+ V vs=0 is=2 [ "{" V vs=1 [ ~*<map (CxxBodyToAbox)> body ] ]
+ H hs=0 [ "}" ";" ]
+ ]
+
+ CxxParamsToAbox:
+ [] -> H []
+
+ CxxParamsToAbox:
+ params -> H hs=1 [ "template" "<" ~<CxxListToAbox(CxxParamToAbox|",")> params ">" ]
+ where not(<?[]> params)
+
+ CxxParamToAbox:
+ (t, idf) -> H hs = 1 [ ~<CxxTypeToAbox> t ~<CxxIdToAbox> idf ]
+
+ CxxParentsToAbox:
+ [] -> H []
+
+ CxxParentsToAbox:
+ parents -> H hs=1 [ ":" ~<CxxListToAbox(CxxParentToAbox|",")>parents ]
+ where not(<?[]> parents)
+
+ CxxParentToAbox:
+ (modifier, t) ->
+ H hs=1 [ ~S(modifier) ~<CxxTypeToAbox>t ]
Index: trunk/src/pp-cxx-ng/pp-cxx.meta
===================================================================
--- trunk/src/pp-cxx-ng/pp-cxx.meta (revision 0)
+++ trunk/src/pp-cxx-ng/pp-cxx.meta (revision 50)
@@ -0,0 +1 @@
+Meta([Syntax("Stratego-Box")])
Index: trunk/src/pp-cxx-ng/CxxId.meta
===================================================================
--- trunk/src/pp-cxx-ng/CxxId.meta (revision 0)
+++ trunk/src/pp-cxx-ng/CxxId.meta (revision 50)
@@ -0,0 +1 @@
+Meta([Syntax("Stratego-Box")])
Index: trunk/src/pp-cxx-ng/Makefile.am
===================================================================
--- trunk/src/pp-cxx-ng/Makefile.am (revision 0)
+++ trunk/src/pp-cxx-ng/Makefile.am (revision 50)
@@ -0,0 +1,21 @@
+# Makefile.am -*-Makefile-*-
+
+MODULES = pp-cxx
+
+include $(top_srcdir)/config/Makefile.xt
+-include $(MODULES:=.c.dep)
+
+SCFLAGS = --main $* --verbose 0
+STRINCLUDES = -I $(top_builddir)/src/scl-syn \
+ -I $(top_builddir)/src/cxx-syn \
+ -I `dirname \`xtc get Stratego-Box.tbl\`` \
+ -I $(srcdir) \
+ -la stratego-lib
+
+libexec_PROGRAMS = pp-cxx
+
+nodist_pp_cxx_SOURCES = pp-cxx.c
+
+EXTRA_DIST = $(MODULES:=.str)
+
+CLEANFILES = $(MODULES:=.c) $(MODULES:=.c.dep)
Index: trunk/src/pp-cxx-ng/CxxType.str
===================================================================
--- trunk/src/pp-cxx-ng/CxxType.str (revision 0)
+++ trunk/src/pp-cxx-ng/CxxType.str (revision 50)
@@ -0,0 +1,25 @@
+module CxxType
+
+imports Cxx Box libstratego-lib CxxId
+
+rules
+
+ CxxTypeToAbox:
+ CxxType(idf) -> <CxxIdToAbox> idf
+
+ CxxTypeToAbox:
+ CxxRefType(t) -> H hs=0 [ ~<CxxTypeToAbox> t "&" ]
+
+ CxxTypeToAbox:
+ CxxType(idf, params) -> H hs=0 [ ~<CxxIdToAbox> idf "<" ~<CxxListToAbox(CxxTypeToAbox|",")> params ">" ]
+
+ CxxTypeToAbox:
+ CxxConstType(t) -> H [ "const" ~<CxxTypeToAbox> t]
+
+ CxxTypeToAbox:
+ Typename -> S("typename")
+
+ /* These function are actually macros */
+
+ CxxTypeToAbox:
+ CxxFunCall(idf, args) -> H hs=0 [ ~<CxxIdToAbox>idf "(" H hs=1 [ ~*<CxxListToAbox(CxxTypeToAbox <+ CxxExpToAbox|",")>args ] ")"]
Index: trunk/src/pp-cxx-ng/CxxStm.meta
===================================================================
--- trunk/src/pp-cxx-ng/CxxStm.meta (revision 0)
+++ trunk/src/pp-cxx-ng/CxxStm.meta (revision 50)
@@ -0,0 +1 @@
+Meta([Syntax("Stratego-Box")])
Index: trunk/src/scoolt/Tools.str
===================================================================
Index: trunk/src/scoolt/Decl.str
===================================================================
--- trunk/src/scoolt/Decl.str (revision 49)
+++ trunk/src/scoolt/Decl.str (revision 50)
@@ -79,10 +79,9 @@
ConstDec([], idf, cs, Class) ->
CxxClassDecl(
[(Typename, "T")],
- nidf,
+ idf,
[]
)
- where <conc-strings> (idf, "_") => nidf
/*
* Root Class declaration
@@ -90,23 +89,24 @@
*/
DeclToCxx:
ConstDec(specs, idf, Class, ClassVal(v)) ->
- <try(AddTypedef(|specs, idf)); AddClassComment(|idf)>
+ <AddClassComment(|idf)>
[
CxxClassDecl(
- [(Typename, "T")],
- nidf,
+ [(Typename, "E")],
+ idf,
[
- (
+ /*(
"public",
CxxType(CxxScope("stc", "any"), [CxxFunCall("stc_find_exact", [CxxType(nidf), CxxType("T")])])
- )
+ )*/
+ // FIXME: Add a way to specify if a root class should inherit from Object or not
],
<map (AccessToCxx)> v
//[]
)
]
- where <SclNewIdf>idf => nidf
- ; rules(CxxTypeToStc(|T): CxxType(idf) -> CxxType(<SclNewIdf>idf, [T]))
+ where
+ rules(AddTemplate(|T): CxxType(idf) -> CxxType(idf, [T]))
/*
* Final Class declaration
@@ -114,11 +114,11 @@
*/
DeclToCxx:
ConstDec(specs, idf, Class(p), v) ->
- <try(AddTypedef(|specs, idf)); AddClassComment(|idf)>
+ <AddClassComment(|idf)>
[
CxxClassDecl(
params,
- nidf,
+ idf,
[
(
"public",
@@ -132,24 +132,21 @@
; if
(
<one(?"final")> specs
- ; !idf => nidf
- ; <CxxTypeToStc(|CxxType(idf))>cxxp => parent
- )
- <+ (
- <SclNewIdf>idf => nidf
- ; <CxxTypeToStc(|CxxFunCall("stc_find_exact", [CxxType(nidf), CxxType("T")]))>cxxp => parent
+ ; <AddTemplate(|CxxType(idf))> cxxp => parent
)
+ <+
+ <AddTemplate(|CxxType("E"))> cxxp => parent
then
if <one(?"final")> specs then
- rules(CxxTypeToStcError: CxxType(idf) -> <concat-strings> [idf, " is final."])
+ rules(IsFinal: CxxType(idf) -> <concat-strings> [idf, " is final."])
; ![] => params
else
- rules(CxxTypeToStc(|T): CxxType(idf) -> CxxType(<SclNewIdf> idf, [T]))
- ; ![(Typename, "T")] => params
+ rules(AddTemplate(|T): CxxType(idf) -> CxxType(idf, [T]))
+ ; ![(Typename, "E")] => params
end
else
say(!<concat-strings> [idf, " cannot inherit from ", <CxxTypeToIdf> cxxp])
- ; if <CxxTypeToStcError> cxxp => error then
+ ; if <IsFinal> cxxp => error then
say(!error)
else
say(!<concat-strings> [<CxxTypeToIdf>cxxp, " does not exist."])
Index: trunk/src/scoolt-ng/Exp.str
===================================================================
--- trunk/src/scoolt-ng/Exp.str (revision 0)
+++ trunk/src/scoolt-ng/Exp.str (revision 50)
@@ -0,0 +1,21 @@
+module Exp
+
+imports libstratego-lib Cxx AsFix Scool
+
+rules
+
+ ExpToCxx:
+ Int(i) -> CxxInt(i)
+
+ ExpToCxx:
+ Var(v) -> v
+
+ ExpToCxx:
+ Sum(e1, e2) -> CxxSum(<ExpToCxx> e1, <ExpToCxx> e2)
+
+ ExpToCxx:
+ Affect(Var(v), e) -> CxxAffect(v, <ExpToCxx> e)
+ where <debug> e
+
+ ExpToCxx:
+ Cxx(s) -> s
Index: trunk/src/scoolt-ng/Tools.str
===================================================================
--- trunk/src/scoolt-ng/Tools.str (revision 0)
+++ trunk/src/scoolt-ng/Tools.str (revision 50)
@@ -0,0 +1,29 @@
+module Tools
+
+imports libstratego-lib Cxx AsFix Scool
+
+rules
+
+ SclNewIdf:
+ idf -> <conc-strings> (idf, "_")
+
+ CxxTypeToIdf:
+ CxxType(idf) -> idf
+ where <is-string> idf
+
+strategies
+
+ NewCount =
+ rules(count_:- _)
+
+ Count =
+ if count_ => res then
+ rules(count_:- _)
+ ; rules(count_: _ -> <sum> (res, 1))
+ else
+ rules(count_: _ -> 1)
+ end
+ ; count_
+
+ GetCount =
+ count_ <+ !0
Index: trunk/src/scoolt-ng/Access.str
===================================================================
--- trunk/src/scoolt-ng/Access.str (revision 0)
+++ trunk/src/scoolt-ng/Access.str (revision 50)
@@ -0,0 +1,15 @@
+module Access
+
+imports libstratego-lib Cxx Type Exp Stm Tools AsFix Scool
+
+rules
+
+ AccessToCxx:
+ Accessblock(Public, l) -> CxxPublic(<map (DeclToCxx)> l)
+
+ AccessToCxx:
+ Accessblock(Private, l) -> CxxPrivate(<map (DeclToCxx)> l)
+
+ AccessToCxx:
+ Accessblock(Protected, l) -> CxxProtected(<map (DeclToCxx)> l)
+
Index: trunk/src/scoolt-ng/Type.str
===================================================================
--- trunk/src/scoolt-ng/Type.str (revision 0)
+++ trunk/src/scoolt-ng/Type.str (revision 50)
@@ -0,0 +1,32 @@
+module Type
+
+imports libstratego-lib Cxx AsFix Scool
+
+rules
+
+ IsScalar:
+ t -> t
+ where
+ (
+ <eq> (t, "char")
+ <+ <eq> (t, "bool")
+ <+ <eq> (t, "short")
+ <+ <eq> (t, "int")
+ <+ <eq> (t, "float")
+ <+ <eq> (t, "double")
+ )
+
+ TypeToCxx:
+ Var(x) -> CxxType(x)
+
+ TypeToCxx:
+ RefType(t) -> CxxRefType(<TypeToCxx> t)
+
+ // Constify + Referencify a type
+ TypeToConstRefCxx:
+ Var(t) -> CxxConstType(CxxRefType(CxxType(t)))
+ where
+ (
+ <is-string> t
+ ; <not (IsScalar)> t
+ )
Index: trunk/src/scoolt-ng/Makefile.am
===================================================================
--- trunk/src/scoolt-ng/Makefile.am (revision 0)
+++ trunk/src/scoolt-ng/Makefile.am (revision 50)
@@ -0,0 +1,21 @@
+# Makefile.am -*-Makefile-*-
+
+MODULES = scoolt
+
+include $(top_srcdir)/config/Makefile.xt
+-include $(MODULES:=.c.dep)
+
+SCFLAGS = --main $* --verbose 0 --asfix
+STRINCLUDES = -I $(top_builddir)/src/scl-syn \
+ -I $(top_builddir)/src/cxx-syn \
+ -I `dirname \`xtc get Stratego-Box.tbl\`` \
+ -I $(srcdir) \
+ -la stratego-lib
+
+libexec_PROGRAMS = scoolt
+
+nodist_scoolt_SOURCES = scoolt.c
+
+EXTRA_DIST = $(MODULES:=.str)
+
+CLEANFILES = $(MODULES:=.c) $(MODULES:=.c.dep)
Index: trunk/src/scoolt-ng/Stm.str
===================================================================
--- trunk/src/scoolt-ng/Stm.str (revision 0)
+++ trunk/src/scoolt-ng/Stm.str (revision 50)
@@ -0,0 +1,21 @@
+module Stm
+
+imports libstratego-lib Cxx Type Exp AsFix Scool
+
+rules
+
+ StmToCxx:
+ ExpStm(e) -> CxxExpStm(<ExpToCxx> e)
+ where <debug> e
+
+ /* Handle the 'return' statement */
+ StmToCxx:
+ Return(e) -> CxxExpStm(CxxKeyword("return", <ExpToCxx> e))
+
+ StmToCxx:
+ VarDec([], idf, t, i) -> <DeclToCxx> VarDec([], idf, t, i)
+ where <debug> idf
+
+ StmToCxx:
+ x -> <DeclToCxx> x
+ where <debug> x
Index: trunk/src/scoolt-ng/scoolt.str
===================================================================
--- trunk/src/scoolt-ng/scoolt.str (revision 0)
+++ trunk/src/scoolt-ng/scoolt.str (revision 50)
@@ -0,0 +1,184 @@
+module scoolt
+
+imports libstratego-lib Cxx Program AsFix Scool
+
+strategies
+
+ scoolt = io-wrap(ProgramToCxx)
+
+
+
+/*
+ t-Program:
+ Program(l) -> Cxx(<collect-vtypes> l, <map(t-Decl)> l)
+
+
+
+ t-Decl:
+ VarDec(i, t) -> CxxVarDec(<t-Type> t, i)
+ where not(<?Var("type")> t)
+
+ t-Decl:
+ VarDec(i, t, v) -> CxxVarDec(<t-Type> t, i, <t-Exp> v)
+ where not(<?Var("type")> t)
+
+ t-Decl:
+ ConsDec(_, i, t) -> CxxVarDec(CxxConsType(<t-Type> t), i)
+ where not(<?Var("type")> t)
+
+ t-Decl:
+ ConsDec(_, i, t, v) -> CxxVarDec(CxxConsType(<t-Type> t), i, <t-Exp> v)
+ where not(<?Var("type")> t)
+
+
+
+
+ t-Decl:
+ ConsDec(_, i, t) -> CxxEscape(<concat-strings> ["/", "/ virtual typedef /abstract/ ", i, ";"] )
+ where <?Var("type")> t
+
+ t-Decl: // FIXME : vvvvvv
+ ConsDec(_, i, t, Var(v)) -> CxxEscape(<concat-strings> ["/", "/ virtual typedef ", v, " ", i, ";"] )
+ where <?Var("type")> t
+
+
+
+ t-Decl:
+ ConsDec(qualifiers, name, Class, ClassVal(l)) -> [CxxClassDec([CxxTemplateArg("E")], newname, CxxPublic, CxxTemplateType(CxxScope("stc", "any"), "E"), <map(t-ABlock)> l), CxxTypedef(CxxTemplateType(newname, "itself"), name)] where <conc-strings> (name, "_") => newname
+
+ t-Decl:
+ ConsDec(qualifiers, name, Class(parent), ClassVal(l)) -> [CxxClassDec([CxxTemplateArg("E")], newname, CxxPublic, CxxTemplateType(<t-r-Type> parent, "E"), <map(t-ABlock)> l), CxxTypedef(CxxTemplateType(newname, "itself"), name)] where <conc-strings> (name, "_") => newname; <not(one(?"final"))> qualifiers
+
+ t-Decl:
+ ConsDec(qualifiers, name, Class(parent)) -> [CxxClassDec([CxxTemplateArg("E")], newname, CxxPublic, CxxTemplateType(<t-r-Type> parent, "E"), []), CxxTypedef(CxxTemplateType(newname, "itself"), name)] where <conc-strings> (name, "_") => newname; <not(one(?"final"))> qualifiers
+
+ t-Decl:
+ ConsDec(qualifiers, name, Class) -> [CxxClassDec([CxxTemplateArg("E")], newname, CxxPublic, CxxTemplateType(CxxScope("stc", "any"), "E"), []), CxxTypedef(CxxTemplateType(newname, "itself"), name)] where <conc-strings> (name, "_") => newname
+
+ t-Decl:
+ ConsDec(qualifiers, name, Class(parent), ClassVal(l)) -> [CxxClassDec([CxxTemplateArg("E")], newname, CxxPublic, CxxTemplateType(<t-r-Type> parent, "E"), <map(t-ABlock)> l), CxxTypedef(CxxTemplateType(newname, "itself"), name)] where <conc-strings> (name, "_") => newname
+
+
+
+ t-Decl:
+ ConsDec(qualifiers, name, Class(parent), ClassVal(l)) ->
+ [CxxClassDec (
+ newname,
+ CxxPublic,
+ CxxTemplateType(<t-r-Type> parent, newname),
+ <map(t-ABlock)> l
+ ),
+ CxxTypedef(newname, name)
+ ]
+ where <conc-strings> (name, "_") => newname; <one(?"final")> qualifiers
+
+ t-ABlock:
+ Accessblock(acc, decs) -> CxxAccessBlock(<t-ASpecifier> acc, <map(t-Decl)> decs)
+
+ t-ASpecifier:
+ Public -> CxxPublic
+
+ t-ASpecifier:
+ Private -> CxxPrivate
+
+ t-Decl:
+ FunDec(_, name, args, ret, body) -> CxxFunDec(<t-Type> ret, name, <map(t-Arg)> args, <map(t-Stm + t-Decl)> body)
+
+
+ t-Decl:
+ BiFunDec(qualifiers, name, s-args, args, rettype, body) ->
+ CxxOverloadingCase( name,
+ CxxInt(index),
+ <t-StaticCond>s-args,
+ <t-Type>rettype,
+ <map(t-Arg)>args,
+ <map(t-Stm + t-Decl)>body
+ )
+ where
+ <one(?"overloading")> qualifiers
+ ; if not(<index-over> name) then
+// say(!"first"); debug
+ !1 => index
+ ; rules(index-over: name -> 2)
+ else
+// say(!"not first"); debug
+ <index-over> name => index
+ ; rules(index-over: name -> <add>(index, 1))
+ end
+
+
+
+ t-Arg:
+ (name, type, guard) -> <t-Arg> (name, type)
+
+ t-Arg:
+ (name, type) -> (<t-Type> type, name)
+
+
+
+ t-Type:
+ Var(n) -> n
+
+ t-r-Type:
+ Var(n) -> <conc-strings> (n, "_")
+
+ t-Exp:
+ Int(n) -> CxxInt(n)
+
+ t-Exp:
+ Mul(e1, e2) -> CxxMul(<t-Exp> e1, <t-Exp> e2)
+
+ t-Exp:
+ Var(n) -> CxxVar(n)
+
+ t-Exp:
+ Cpp(cxx) -> CxxEscape(cxx)
+
+ t-Stm:
+ Return(e) -> CxxReturn(<t-Exp> e)
+
+ t-Decl:
+ Cpp(cxx) -> CxxEscape(cxx)
+
+ t-StaticCond:
+ [] -> CxxStaticTrue
+
+ t-StaticCond:
+ [h|[]] -> <t-StaticCond> h
+
+ t-StaticCond:
+ [h|t] -> CxxStaticAnd(<t-StaticCond> h, <t-StaticCond> t)
+ where not(<?[]>t)
+
+ t-StaticCond:
+ (idf, type, Guard(guard)) -> <t-StaticCond> guard
+
+ t-StaticCond:
+ (idf, type) -> CxxStaticTrue
+
+ t-StaticCond:
+ Eq(e1, e2) -> CxxStaticEq(<t-Type> e1, <t-Type> e2)
+
+ t-StaticCond:
+ Or(e1, e2) -> CxxStaticOr(<t-StaticCond> e1, <t-StaticCond> e2)
+
+ t-StaticCond:
+ Inf(e1, e2) -> CxxStaticIsA(<t-Type> e1, <t-Type> e2)
+
+ t-StaticCond:
+ Var("true") -> CxxStaticTrue
+
+ t-StaticCond:
+ Var("false") -> CxxStaticFalse
+
+
+
+ strategies
+
+ collect-vtypes =
+ collect(?ConsDec(attr, _, Var("type")); where (<one(?"decl")> attr) )
+ ; map(?ConsDec(_, <id>, _))
+ ; make-set
+
+
+*/
Index: trunk/src/scoolt-ng/Decl.str
===================================================================
--- trunk/src/scoolt-ng/Decl.str (revision 0)
+++ trunk/src/scoolt-ng/Decl.str (revision 50)
@@ -0,0 +1,229 @@
+module Decl
+
+imports libstratego-lib Cxx Type Exp Stm Tools AsFix Scool Access
+
+rules
+
+ /*
+ * Variable declaration.
+ * Grammar: "var" idf ":" t ";"
+ */
+ DeclToCxx:
+ VarDec([], idf, t) -> CxxDecl(<TypeToCxx> t, idf)
+
+ /*
+ * Array declaration.
+ * Grammar: "var" idf ":" "array" "[" t "," n "]" ";"
+ */
+ DeclToCxx:
+ VarDec([], idf, StaticFunCall(st, [t, n])) ->
+ <if <eq> ("array", st) then
+ ! CxxArrayDecl(<TypeToCxx> t, idf, <ExpToCxx> n)
+ else
+ say(<concat-strings> ["Unkown construction: ", st])
+ ; <exit> 1
+ end>
+
+ /*
+ * Buffer declaration.
+ * Grammar: "var" idf ":" "buffer" "[" t "]" ";"
+ */
+ DeclToCxx:
+ VarDec([], idf, StaticFunCall(st, [t])) ->
+ <if <eq> ("buffer", st) then
+ ! CxxDecl(CxxType(CxxScope("std", "vector"), [<TypeToCxx> t]), idf)
+ else
+ say(<concat-strings> ["Unkown construction: ", st])
+ ; <exit> 1
+ end>
+
+ /*
+ * Variable declaration with initialisation.
+ * Grammar: "var" idf ":" t ":=" v ";"
+ */
+ DeclToCxx:
+ VarDec([], idf, t, v) -> CxxDecl(<TypeToCxx> t, idf, <ExpToCxx> v)
+
+ UnVar:
+ Var(x) -> x
+
+ /*
+ * Constant declaration.
+ * Grammar: idf ":" t ";"
+ */
+ DeclToCxx:
+ ConstDec([], idf, cs, t) ->
+ <if <eq> ("type", <UnVar> t) then
+ ! CxxDecl(<TypeToCxx> t, idf)
+ else
+ ! CxxDecl(CxxConstType(<TypeToCxx> t), idf)
+ end>
+ where not(<?Class> t)
+
+ /*
+ * Constant declaration with initialisation.
+ * Grammar: idf ":" t "=" v ";"
+ */
+ DeclToCxx:
+ ConstDec([], idf, t, v) -> CxxDecl(CxxConstType(<TypeToCxx> t), idf, <ExpToCxx> v)
+ where not(<?Class> t)
+
+ DeclToCxx:
+ ConstDec(["decl"], idf, cs, FunType(args, ret)) -> CxxFun([], <TypeToCxx> ret, idf, <map (ArgDefToCxx)> args)
+
+ /*
+ * Root Class predeclaration
+ * Grammar: idf ":" "class" ";"
+ */
+ DeclToCxx:
+ ConstDec([], idf, cs, Class) ->
+ CxxClassDecl(
+ [(Typename, "T")],
+ nidf,
+ []
+ )
+ where <conc-strings> (idf, "_") => nidf
+
+ /*
+ * Root Class declaration
+ * Grammar: specs idf ":" "class" "=" "{" v "}" ";"
+ */
+ DeclToCxx:
+ ConstDec(specs, idf, Class, ClassVal(v)) ->
+ <try(AddTypedef(|specs, idf)); AddClassComment(|idf)>
+ [
+ CxxClassDecl(
+ [(Typename, "T")],
+ nidf,
+ [
+ (
+ "public",
+ CxxType(CxxScope("stc", "any"), [CxxFunCall("stc_find_exact", [CxxType(nidf), CxxType("T")])])
+ )
+ ],
+ <map (AccessToCxx)> v
+ //[]
+ )
+ ]
+ where <SclNewIdf>idf => nidf
+ ; rules(CxxTypeToStc(|T): CxxType(idf) -> CxxType(<SclNewIdf>idf, [T]))
+
+ /*
+ * Final Class declaration
+ * Grammar: final idf ":" "class" "=" "{" v "}" ";"
+ */
+ DeclToCxx:
+ ConstDec(specs, idf, Class(p), v) ->
+ <try(AddTypedef(|specs, idf)); AddClassComment(|idf)>
+ [
+ CxxClassDecl(
+ params,
+ nidf,
+ [
+ (
+ "public",
+ parent
+ )
+ ],
+ [] // fixme
+ )
+ ]
+ where <TypeToCxx> p => cxxp
+ ; if
+ (
+ <one(?"final")> specs
+ ; !idf => nidf
+ ; <CxxTypeToStc(|CxxType(idf))>cxxp => parent
+ )
+ <+ (
+ <SclNewIdf>idf => nidf
+ ; <CxxTypeToStc(|CxxFunCall("stc_find_exact", [CxxType(nidf), CxxType("T")]))>cxxp => parent
+ )
+ then
+ if <one(?"final")> specs then
+ rules(CxxTypeToStcError: CxxType(idf) -> <concat-strings> [idf, " is final."])
+ ; ![] => params
+ else
+ rules(CxxTypeToStc(|T): CxxType(idf) -> CxxType(<SclNewIdf> idf, [T]))
+ ; ![(Typename, "T")] => params
+ end
+ else
+ say(!<concat-strings> [idf, " cannot inherit from ", <CxxTypeToIdf> cxxp])
+ ; if <CxxTypeToStcError> cxxp => error then
+ say(!error)
+ else
+ say(!<concat-strings> [<CxxTypeToIdf>cxxp, " does not exist."])
+ end
+ end
+
+ /*
+ * Handle class declarations with inheritance
+ * Grammar: idf ":" "class" "<" parent ";"
+ */
+ DeclToCxx:
+ ConstDec([], idf, cs, Class(parent)) -> CxxClassDecl([], idf, [("public", <TypeToCxx> parent)])
+ where <conc-strings> (idf, "_") => nidf
+
+ /*
+ * Handle functions
+ * Grammar: idf ":" "(" args ")" "->" t "=" "{" body "}"
+ * TODO: Handle templates
+ */
+ DeclToCxx:
+ FunDec([], idf, args, t, body) -> CxxFun([], <TypeToCxx> t, idf, <map(ArgDefToCxx)> args, <map(StmToCxx)> body)
+ //where <debug> body
+ //FunDec([], idf, args, t, body) -> <AddParameters(|<GetCount> 0)> CxxFun([], <TypeToCxx> t, idf, nargs, <map(StmToCxx)>body)
+ //where <NewCount; map(ArgDefToCxx)>args => nargs
+ /*
+ * Handle functions
+ * Grammar: idf ":" "(" args ")" "->" t "=>" Exp
+ * TODO: Handle templates
+ */
+ DeclToCxx:
+ FunDec([], idf, args, t, ExpStm(body)) -> CxxFun([], <TypeToCxx> t, idf, <map(ArgDefToCxx)> args, [<StmToCxx> Return(body)])
+ //where <debug> body
+
+ DeclToCxx:
+ StaticFunDec(l, idf, params, Class(), body) -> CxxClassDecl(<map (ParamToCxx)> params, idf, [], <map (AccessToCxx)> body)
+
+ DeclToCxx:
+ BiFunDec(l, idf, params, args, t, body) -> CxxFun(<map (ParamToCxx)> params, <TypeToCxx> t, idf, <map (ArgDefToCxx)> args, <map (StmToCxx)> body)
+
+ DeclToCxx:
+ BiFunDec(l, idf, params, args, t, ExpStm(body)) -> CxxFun(<map (ParamToCxx)> params, <TypeToCxx> t, idf, <map (ArgDefToCxx)> args, [<StmToCxx> Return(body)])
+
+ ParamToCxx:
+ (idf, Var(t), wclause) ->
+ <if <eq> (t, "type") then
+ ! (CxxType("class"), idf)
+ else
+ ! (CxxType(t), idf)
+ end>
+
+ ArgDefToCxx:
+ (idf, t) -> (<TypeToConstRefCxx <+ TypeToCxx> t, idf)
+ //(idf, t) -> (<TypeToCxx; try(CxxTypeToStc(|CxxType(p-idf)))> t, idf)
+ //where <concat-strings; SclNewIdf> ["T", <Count; int-to-string> 0] => p-idf
+
+ ArgDefToCxx:
+ FunArg(idf, t) -> <ArgDefToCxx> (idf, t)
+
+ AddTypedef(|specs, idf):
+ [x] -> [x, CxxTypedef(CxxType(<SclNewIdf>idf, [CxxType(CxxScope("stc", "itself"))]), idf)]
+ where <not(one(?"abstract"))> specs
+
+ AddClassComment(|idf):
+ l -> [CxxComment(<concat-strings> ["Class ", idf])|l]
+
+ AddParameters(|n):
+ CxxFun(p, t, idf, args, body) -> CxxFun(<Parameters(|n)> p, t, idf, args, body)
+ //where <debug> n
+
+ Parameters(|n):
+ l -> <Parameters(|<subt>(n, 1))>[(Typename, idf)|l]
+ where <not(?0)> n
+ ; <concat-strings; SclNewIdf> ["T", <int-to-string> n] => idf
+
+ Parameters(|n):
+ l -> l
+ where <?0> n
Index: trunk/src/scoolt-ng/Program.str
===================================================================
--- trunk/src/scoolt-ng/Program.str (revision 0)
+++ trunk/src/scoolt-ng/Program.str (revision 50)
@@ -0,0 +1,8 @@
+module Program
+
+imports libstratego-lib Cxx Decl AsFix Scool
+
+rules
+
+ ProgramToCxx:
+ Program(l) -> CxxProgram(<map(DeclToCxx)> l)
--
\__/ \__/
(00) Maxime `yabo` van Noppen (00)
___) \ Epita 2009 / (___
(_____/ Président de Prologin \_____)
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
sandbox:Subsampling function.
* sandbox/jardonnet/subsampling: New.
* sandbox/jardonnet/subsampling/subsampling_2d.hh: Subsamples 2d image.
* sandbox/jardonnet/subsampling/sub_sampled_image.hh: Draft morpher.
* sandbox/jardonnet/test: New temporary test directory.
* sandbox/jardonnet/test/test.cc: Base.
* sandbox/jardonnet/test/subsampling.cc: Subsampling test.
* sandbox/jardonnet/test/Makefile: New.
* tests/subsampling: New.
* tests/subsampling/type.cc: New.
mln/binarization/binarization.hh | 2
sandbox/jardonnet/subsampling/sub_sampled_image.hh | 226 +++++++++++++++++++++
sandbox/jardonnet/subsampling/subsampling_2d.hh | 117 ++++++++++
sandbox/jardonnet/test/Makefile | 8
sandbox/jardonnet/test/subsampling.cc | 22 ++
sandbox/jardonnet/test/test.cc | 12 +
tests/binarization/thresholding.cc | 2
tests/subsampling/type.cc | 15 +
8 files changed, 403 insertions(+), 1 deletion(-)
Index: tests/subsampling/type.cc
--- tests/subsampling/type.cc (revision 0)
+++ tests/subsampling/type.cc (revision 0)
@@ -0,0 +1,15 @@
+#include <mln/core/image2d.hh>
+#include <mln/core/sub_sampled_image.hh>
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ typedef image2d<int_u8> I;
+
+ I input;
+ sub_sampled_image<I> sima(input, point2d(1,1), 2);
+
+}
Index: tests/binarization/thresholding.cc
--- tests/binarization/thresholding.cc (revision 1757)
+++ tests/binarization/thresholding.cc (working copy)
@@ -30,6 +30,8 @@
* \brief Test on mln::binarization::thresholding
*/
+// FIXME for make check
+
#include <mln/core/image2d.hh>
#include <mln/binarization/thresholding.hh>
Index: mln/binarization/binarization.hh
--- mln/binarization/binarization.hh (revision 1757)
+++ mln/binarization/binarization.hh (working copy)
@@ -103,4 +103,4 @@
} // end of namespace mln
-#endif // ! MLN_BINARIZATION_THRESHOLDING_HH
+#endif // ! MLN_BINARIZATION_BINARIZATION_HH
Index: sandbox/jardonnet/test/test.cc
--- sandbox/jardonnet/test/test.cc (revision 0)
+++ sandbox/jardonnet/test/test.cc (revision 0)
@@ -0,0 +1,12 @@
+#include <mln/core/image2d.hh>
+
+# include <mln/geom/ncols.hh>
+# include <mln/geom/nrows.hh>
+
+
+int main()
+{
+ mln::image2d<int> i(5 / 3,5);
+
+ return mln::geom::nrows(i);
+}
Index: sandbox/jardonnet/test/subsampling.cc
--- sandbox/jardonnet/test/subsampling.cc (revision 0)
+++ sandbox/jardonnet/test/subsampling.cc (revision 0)
@@ -0,0 +1,22 @@
+#include <mln/core/image2d.hh>
+
+#include <mln/io/pgm/load.hh>
+#include <mln/io/pgm/save.hh>
+
+#include <sandbox/jardonnet/subsampling/subsampling_2d.hh>
+
+
+int main(int argc, char*)
+{
+ using namespace mln;
+ using value::int_u8;
+
+ image2d<int_u8> img;
+
+ io::pgm::load(img, "../../../img/lena.pgm");
+
+ std::cout << geom::nrows(img) << geom::ncols(img) << std::endl;
+ image2d<int_u8> output = subsampling::subsampling_2d(img, make::dpoint2d(1,1), argc);
+
+ io::pgm::save(output, "out1.pgm");
+}
Index: sandbox/jardonnet/test/Makefile
--- sandbox/jardonnet/test/Makefile (revision 0)
+++ sandbox/jardonnet/test/Makefile (revision 0)
@@ -0,0 +1,8 @@
+SOURCE=test.cc subsampling.cc
+FLAG=-Wall -W -I../../.. -g
+
+all:
+ g++ $(SOURCE) $(FLAG) -o '+a.out'
+
+sub:
+ g++ subsampling.cc $(FLAG) -o '+a.out'
Index: sandbox/jardonnet/subsampling/subsampling_2d.hh
--- sandbox/jardonnet/subsampling/subsampling_2d.hh (revision 0)
+++ sandbox/jardonnet/subsampling/subsampling_2d.hh (revision 0)
@@ -0,0 +1,117 @@
+// 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_SUBSAMPLING_SUBSAMPLING_2D_HH
+# define MLN_SUBSAMPLING_SUBSAMPLING_2D_HH
+
+/*! \file mln/binarization/threshold.hh
+ *
+ * \brief Threshold the contents of an image into another binary one.
+ */
+
+# include <mln/geom/ncols.hh>
+# include <mln/geom/nrows.hh>
+
+
+namespace mln
+{
+
+ namespace subsampling
+ {
+
+ /*! Subsampling FIXME : doxy
+ *
+ *
+ */
+ template <typename I>
+ inline
+ mln_concrete(I)
+ subsampling_2d(const Image<I>& input,
+ const mln_dpoint(I)& first_p,
+ const mln_coord(I)& gap);
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ template <typename I>
+ inline
+ mln_concrete(I)
+ subsampling_2d_(const I& input,
+ const mln_dpoint(I)& first_p,
+ const mln_coord(I)& gap)
+ {
+ trace::entering("subsampling_2d::impl::subsampling_2d_");
+ mln_concrete(I) output(geom::nrows(input) / gap,
+ geom::ncols(input) / gap);
+
+ for (unsigned j = 0; j < geom::ncols(output); ++j)
+ for (unsigned i = 0; i < geom::nrows(output); ++i)
+ {
+ point2d p1(i, j);
+ point2d p2(first_p[0] + i * gap, first_p[1] + j * gap);
+ std::cout << p1 << ' ' << p2 << std::endl;
+ output(p1) = input(p2);
+ }
+
+ trace::exiting("subsampling_2d::impl::subsampling_2d_");
+ return output;
+ }
+
+ } // end of namespace mln::subsampling_2d::impl
+
+
+ template <typename I>
+ inline
+ mln_concrete(I)
+ subsampling_2d(const Image<I>& input,
+ const mln_dpoint(I)& first_p,
+ const mln_coord(I)& gap)
+ {
+ trace::entering("subsampling::subsampling_2d");
+ mln_precondition(exact(input).has_data());
+
+ mln_concrete(I) output(geom::nrows(input) / gap,
+ geom::ncols(input) / gap);
+
+ std::cout << geom::nrows(output) << ' ' << geom::ncols(output) << std::endl;
+
+ output = impl::subsampling_2d_(exact(input), first_p, gap);
+
+ trace::exiting("subsampling::subsampling_2d");
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::subsampling_2d
+
+} // end of namespace mln
+
+
+#endif // ! MLN_SUBSAMPLING_SUBSAMPLING_2D_HH
Index: sandbox/jardonnet/subsampling/sub_sampled_image.hh
--- sandbox/jardonnet/subsampling/sub_sampled_image.hh (revision 0)
+++ sandbox/jardonnet/subsampling/sub_sampled_image.hh (revision 0)
@@ -0,0 +1,226 @@
+// 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_CORE_SUB_SAMPLED_IMAGE_HH
+# define MLN_CORE_SUB_SAMPLED_IMAGE_HH
+
+/*! \file mln/core/sub_sampled_image.hh
+ *
+ */
+
+# include <mln/core/internal/image_morpher.hh>
+# include <mln/convert/to_dpoint.hh>
+# include <mln/metal/vec.hh>
+# include <mln/value/set.hh>
+
+
+namespace mln
+{
+
+ // Fwd decl.
+ template <typename I> struct sub_sampled_image;
+
+ namespace internal
+ {
+
+ /// \internal Data structure for \c mln::t_image<I>.
+ template <typename I>
+ struct data_< sub_sampled_image<I> >
+ {
+ /// \brief Build the data object held by a sub_sampled_image.
+ ///
+ /// \param ima The underlying image.
+ /// \param box The bounding box (domain) of the morphed image.
+ data_(I& ima, mln::box_<mln_point(I)>& box);
+
+ /// Underlying image.
+ I ima_;
+
+ /// The bounding box of the morphed image.
+ mln::box_<mln_point(I)> box_;
+ };
+
+ } // end of namespace mln::internal
+
+ template <typename I>
+ class sub_sampled_image
+ : public internal::image_morpher_< I, mln_pset(I), sub_sampled_image<I> >
+ {
+ public:
+ /// Super type.
+ typedef
+ internal::image_morpher_< I, mln_pset(I), sub_sampled_image<I> > super_;
+
+ /// Point_Site associated type.
+ typedef mln_psite(I) psite;
+
+ /// Value associated type.
+ typedef mln_value(I) value;
+
+ /// Type returned by the read-write pixel value operator.
+ typedef typename internal::morpher_lvalue_<I>::ret lvalue;
+
+ /// Return type of read-only access.
+ typedef mln_rvalue(I) rvalue;
+
+ /// Value set associated type.
+ typedef mln::value::set<value> vset;
+
+ /// Skeleton.
+ typedef sub_sampled_image< tag::image_<I> > skeleton;
+
+
+ /// Give the definition domain.
+ const box_<mln_point(I)>& domain() const;
+
+ /// Test if this image has been initialized.
+ bool has_data() const;
+
+ /// Test if a pixel value is accessible at \p p.
+ bool owns_(const mln_point(I)& p) const;
+
+ /// Give the set of values of the image.
+ const vset& values() const;
+
+ /// Read-only access of pixel value at point site \p p.
+ mln_rvalue(I) operator()(const mln_point(I)& p) const;
+
+ /// Read-write access of pixel value at point site \p p.
+ lvalue operator()(const mln_point(I)& p);
+ public:
+ sub_sampled_image(I& ima, const mln_point(I)& first_p, int gap);
+
+ void set_sampling(const mln_point(I)& first_p, int gap);
+
+ protected:
+
+ /// Compute physical coordinates.
+ mln_point(I) translate_coords_(const mln_point(I)& p) const;
+
+ const mln_point(I)& first_p;
+ int gap;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace internal
+ {
+
+ // internal::data_< sub_sampled_image<I,S> >
+
+ template <typename I>
+ inline
+ data_< sub_sampled_image<I> >::data_(I& ima, mln::box_<mln_point(I)>& box)
+ : ima_(ima), box_(box)
+ {
+ }
+
+ } // end of namespace mln::internal
+
+
+ template <typename I>
+ sub_sampled_image<I>::sub_sampled_image(I& ima, const mln_point(I)& first_p, int gap)
+ : first_p(first_p), gap(gap)
+ {
+ box_<mln_point(I)> box(ima.bbox().pmin(),ima.bbox().pmax());
+ this->data_ = new internal::data_< sub_sampled_image<I> >(ima, box);
+ }
+
+
+ template <typename I>
+ inline
+ const box_<mln_point(I)>&
+ sub_sampled_image<I>::domain() const
+ {
+ mln_precondition(this->has_data());
+ return this->data_->box_;
+ }
+
+
+ template <typename I>
+ inline
+ const typename sub_sampled_image<I>::vset&
+ sub_sampled_image<I>::values() const
+ {
+ mln_precondition(this->delegatee_() != 0);
+ return this->delegatee_()->values();
+ }
+
+
+ template <typename I>
+ inline
+ bool sub_sampled_image<I>::has_data() const
+ {
+ mln_invariant(this->delegatee_()->has_data());
+ return true;
+ }
+
+
+ template <typename I>
+ inline
+ bool
+ sub_sampled_image<I>::owns_(const mln_point(I)& p) const
+ {
+ mln_precondition(this->has_data());
+ return this->delegatee_()->owns_(translate_coords_(p));
+ }
+
+ template <typename I>
+ inline
+ mln_rvalue(I)
+ sub_sampled_image<I>::operator()(const mln_point(I)& p) const
+ {
+ mln_precondition(this->owns_(p));
+ return (*this->delegatee_())(translate_coords_(p));
+ }
+
+ template <typename I>
+ inline
+ typename internal::morpher_lvalue_<I>::ret
+ sub_sampled_image<I>::operator()(const mln_point(I)& p)
+ {
+ mln_precondition(this->owns_(p));
+ return (*this->delegatee_())(translate_coords_(p));
+ }
+
+ template <typename I>
+ inline
+ mln_point(I)
+ sub_sampled_image<I>::translate_coords_(const mln_point(I)& p) const
+ {
+
+ return mln_point(I)(metal::vec<2, int>(p) * gap + metal::vec<2, int>(first_p));
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_SUB_SAMPLED_IMAGE_HH
1
0
https://svn.lrde.epita.fr/svn/oln/trunk
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
New sample code for Caroline (hsi and conversion).
* milena/sandbox/vigouroux/color/my_hsi.hh: .
* milena/sandbox/vigouroux/color/is_HSI.cc: New.
* milena/sandbox/vigouroux/color/rgb_to_hsi.hh
(fun::v2v::f_rgb_to_hsi_): New.
is_HSI.cc | 20 ++++++++++++
my_hsi.hh | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
rgb_to_hsi.hh | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++--------
3 files changed, 180 insertions(+), 13 deletions(-)
Index: milena/sandbox/vigouroux/color/my_hsi.hh
--- milena/sandbox/vigouroux/color/my_hsi.hh (revision 1756)
+++ milena/sandbox/vigouroux/color/my_hsi.hh (working copy)
@@ -4,13 +4,85 @@
#include <mln/value/int_u.hh>
#include <mln/metal/vec.hh>
+#include <mln/value/float01_8.hh>
+
#ifndef MLN_VALUE_HSI_HH
# define MLN_VALUE_HSI_HH
+
namespace mln
{
+
namespace value
{
+
+ template <typename E>
+ struct HSI
+ {
+ };
+
+ template <typename F>
+ class hsi_ : public HSI< hsi_<F> >
+ {
+ public:
+
+ typedef F h_type;
+ typedef F s_type;
+ typedef F i_type;
+
+ /// Constructor without argument.
+ hsi_()
+ {
+ }
+
+ /// Constructor from component values.
+ hsi_(const F& h, const F& s, const F& i)
+ : h_(h),
+ s_(s),
+ i_(i)
+ {
+ }
+
+ /// Read-only access to the h component.
+ const F& h() const
+ {
+ return this->h_;
+ }
+ const F& s() const
+ {
+ return this->s_;
+ }
+ const F& i() const
+ {
+ return this->i_;
+ }
+
+ /// Read-write access to the h component.
+ F& h()
+ {
+ return this->h_;
+ }
+ F& s()
+ {
+ return this->s_;
+ }
+ F& i()
+ {
+ return this->i_;
+ }
+
+ private:
+ F h_;
+ F s_;
+ F i_;
+ };
+
+ typedef hsi_<float01_8> hsi_3x8;
+
+ typedef hsi_<double> hsi_d;
+
+
+
template <unsigned n>
struct hsi
{
@@ -47,6 +119,9 @@
double i_;
};
+
+# ifndef MLN_INCLUDE_ONLY
+
template <unsigned n>
inline
hsi<n>::hsi()
@@ -65,7 +140,11 @@
this->s_ = s;
this->i_ = i;
}
- }
-}
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
#endif // ! MLN_VALUE_HSI_HH
Index: milena/sandbox/vigouroux/color/is_HSI.cc
--- milena/sandbox/vigouroux/color/is_HSI.cc (revision 0)
+++ milena/sandbox/vigouroux/color/is_HSI.cc (revision 0)
@@ -0,0 +1,20 @@
+#include <iostream>
+
+#include <mln/metal/is_a.hh>
+#include <mln/value/rgb8.hh>
+#include "my_hsi.hh"
+#include "rgb_to_hsi.hh"
+
+
+int main()
+{
+ using namespace mln;
+ using namespace mln::value;
+
+ typedef hsi_d C;
+ std::cout << mlc_is_a(C, HSI)::value << std::endl;
+ std::cout << mlc_is_a(rgb8, HSI)::value << std::endl;
+
+ rgb8 c(255, 10, 1);
+ hsi_3x8 c_hsi = fun::v2v::f_rgb_to_hsi_3x8(c);
+}
Index: milena/sandbox/vigouroux/color/rgb_to_hsi.hh
--- milena/sandbox/vigouroux/color/rgb_to_hsi.hh (revision 1756)
+++ milena/sandbox/vigouroux/color/rgb_to_hsi.hh (working copy)
@@ -1,3 +1,5 @@
+#include <cmath>
+
#include <mln/core/image_if_value.hh>
#include <mln/core/inplace.hh>
#include <mln/core/w_window2d_int.hh>
@@ -8,12 +10,75 @@
#include "my_hsi.hh"
-namespace mln {
- namespace convert {
+
+
+namespace mln
+{
+
+
+ namespace fun
+ {
+
+ namespace v2v
+ {
+
+ // NEW
+
+ template <typename T_hsi>
+ struct f_rgb_to_hsi_ : public Function_v2v< f_rgb_to_hsi_<T_hsi> >
+ {
+ typedef T_hsi result;
+
+ template <typename T_rgb>
+ T_hsi operator()(const T_rgb& rgb) const
+ {
+ // Locals.
+ static const double sqrt3_3 = std::sqrt(3) / 3;
+ static const double inv_sqrt6 = 1 / std::sqrt(6);
+ static const double inv_sqrt2 = 1 / std::sqrt(2);
+
+ T_hsi hsi;
+
+ double alpha = inv_sqrt2 * rgb.green() - inv_sqrt2 * rgb.blue();
+ double beta = 2 * inv_sqrt6 * rgb.red() - inv_sqrt6 * rgb.green() - inv_sqrt6 * rgb.blue();
+
+
+ float tmp = atan2(beta, alpha) / 3.1415 * 180.0;
+ if (tmp < 0 or tmp > 1)
+ {
+ std::cout << "FIXME: " << tmp << std::endl;
+ }
+
+ hsi.h() = atan2(beta, alpha) / 3.1415 * 180.0;
+ if (hsi.h() < 0)
+ hsi.h() = hsi.h() + 360.0;
+ mln_invariant(hsi.h() >= 0);
+ hsi.s() = std::sqrt(alpha * alpha + beta * beta);
+ hsi.i() = sqrt3_3 * rgb.red() + sqrt3_3 * rgb.green() + sqrt3_3 * rgb.blue();
+
+ return hsi;
+ }
+ };
+
+ typedef f_rgb_to_hsi_<value::hsi_3x8> f_rgb_to_hsi_3x8_t;
+
+ f_rgb_to_hsi_3x8_t f_rgb_to_hsi_3x8;
+
+ // end of NEW
+
+ } // end of namespace fun::v2v
+
+ } // end of namespace fun
+
+
+
+
+ namespace convert
+ {
+
struct f_rgb_to_hsi
{
- struct value::hsi<8>
- doit(const struct value::rgb<8> rgb) const
+ value::hsi<8> operator()(const value::rgb<8>& rgb) const
{
struct value::hsi<8> hsi;
double sqrt3_3 = sqrt(3) / 3;
@@ -30,14 +95,15 @@
hsi.s(sqrt(alpha * alpha + beta * beta));
hsi.i(sqrt3_3 * rgb.red() + sqrt3_3 * rgb.green() + sqrt3_3 * rgb.blue());
- return (hsi);
+ return hsi;
}
};
+
struct f_hsi_to_rgb
{
- struct value::rgb<8>
- doit(const struct value::hsi<8> hsi) const
+
+ value::rgb<8> doit(const value::hsi<8>& hsi) const
{
int r;
int g;
@@ -55,10 +121,12 @@
g = int(sqrt3_3 * hsi.i() + inv_sqrt2 * alpha - inv_sqrt6 * beta);
b = int(sqrt3_3 * hsi.i() - inv_sqrt2 * alpha - inv_sqrt6 * beta);
- struct value::rgb<8> rgb(r, g, b);
+ value::rgb<8> rgb(r, g, b);
- return (rgb);
+ return rgb;
}
};
- }
-}
+
+ } // end of FIXME
+
+} // end of FIXME
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Nicolas Ballas <ballas(a)lrde.epita.fr>
Add base decorator for boost graph.
* tests/util/boost_graph.cc: New.
* mln/util/internal/boost_graph.hh: New, boost graph base decorator.
* mln/util/internal/boost_graph_structure.hh,
* mln/util/internal/boost_graph_access.hh,
* mln/util/internal/boost_graph_property.hh: boost graph operations.
mln/util/internal/boost_graph.hh | 189 ++++++++++++++++++
mln/util/internal/boost_graph_access.hh | 293 +++++++++++++++++++++++++++++
mln/util/internal/boost_graph_property.hh | 171 ++++++++++++++++
mln/util/internal/boost_graph_structure.hh | 281 +++++++++++++++++++++++++++
tests/util/boost_graph.cc | 116 +++++++++++
5 files changed, 1050 insertions(+)
Index: tests/util/boost_graph.cc
--- tests/util/boost_graph.cc (revision 0)
+++ tests/util/boost_graph.cc (revision 0)
@@ -0,0 +1,116 @@
+// Copyright (C) 2007, 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.
+
+/// \file tests/util/graph.cc
+/// \brief test of mln::util::graph
+/// This test is a copy of the BGL quick tours example.
+
+#include <mln/util/internal/boost_graph.hh>
+#include <iostream>
+
+using namespace mln::util::internal;
+using namespace boost;
+
+struct empty {};
+
+template <class Graph>
+struct exercise_vertex
+{
+ typedef typename graph_traits<Graph>::vertex_descriptor Vertex;
+ exercise_vertex(Graph& g_) : g(g_) {}
+
+ void operator()(const Vertex& v) const
+ {
+ typedef graph_traits<Graph> GraphTraits;
+ typename property_map<Graph, vertex_index_t>::type
+ index = get(vertex_index, g);
+
+ std::cout << "out-edges: ";
+ typename GraphTraits::out_edge_iterator out_i, out_end;
+ typename GraphTraits::edge_descriptor e;
+ for (tie(out_i, out_end) = out_edges(v, g); out_i != out_end; ++out_i)
+ {
+ e = *out_i;
+ Vertex src = source(e, g), targ = target(e, g);
+ std::cout << "(" << index[src] << "," << index[targ] << ") ";
+ }
+ std::cout << std::endl;
+
+ std::cout << "adjacent vertices: ";
+ typename graph_traits<Graph>::adjacency_iterator ai;
+ typename graph_traits<Graph>::adjacency_iterator ai_end;
+ for (tie(ai, ai_end) = adjacent_vertices(v, g); ai != ai_end; ++ai)
+ std::cout << index[*ai] << " ";
+ std::cout << std::endl;
+ }
+
+ Graph& g;
+};
+
+int main ()
+{
+
+ typedef boost_graph<empty, empty> Graph;
+
+ // Make convenient labels for the vertices
+ const int num_vertices = 5;
+
+ // writing out the edges in the graph
+ typedef std::pair<int, int> Edge;
+ Edge edge_array[] = {
+ Edge(0, 1), Edge(0, 3), Edge(2, 0), Edge(3, 2),
+ Edge(2, 4), Edge(1, 3), Edge(3, 4)
+ };
+ const int num_edges = sizeof(edge_array)/sizeof(edge_array[0]);
+
+ // declare a graph object
+ Graph g(num_vertices);
+ typedef property_map<Graph, vertex_index_t>::type IndexMap;
+ IndexMap index = get(vertex_index, g);
+
+ // add the edges to the graph object
+ for (int i = 0; i < num_edges; ++i)
+ add_edge(edge_array[i].first, edge_array[i].second, g);
+
+ std::cout << "vertices(g) = ";
+ typedef graph_traits<Graph>::vertex_iterator vertex_iter;
+ std::pair<vertex_iter, vertex_iter> vp;
+ for (vp = vertices(g); vp.first != vp.second; ++vp.first)
+ std::cout << index[*vp.first] << " ";
+ std::cout << std::endl;
+
+ std::cout << "edges(g) = ";
+ graph_traits<Graph>::edge_iterator ei, ei_end;
+ for (tie(ei, ei_end) = edges(g); ei != ei_end; ++ei)
+ std::cout << "(" << index[source(*ei, g)]
+ << "," << index[target(*ei, g)] << ") ";
+ std::cout << std::endl;
+
+ std::for_each(vertices(g).first, vertices(g).second,
+ exercise_vertex<Graph>(g));
+ return 0;
+}
Index: mln/util/internal/boost_graph.hh
--- mln/util/internal/boost_graph.hh (revision 0)
+++ mln/util/internal/boost_graph.hh (revision 0)
@@ -0,0 +1,189 @@
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// 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_BOOST_GRAPH_HH
+# define MLN_UTIL_BOOST_GRAPH_HH
+
+/// \file mln/util/internal/boost_graph.hh
+/// \brief Definition of the boost::adjacenly_list decorator.
+
+# include <boost/graph/adjacency_list.hpp>
+
+namespace mln
+{
+
+ namespace util
+ {
+
+ namespace internal
+ {
+
+ /// \brief Boost graph decorator base
+ /// Graph class which rests on boost::adjacency_list class.
+ template <typename VertexProperty, typename EdgeProperty>
+ class boost_graph
+ {
+ typedef boost_graph<VertexProperty, EdgeProperty> self_type;
+
+ public:
+ /// Types declartation.
+ typedef boost::adjacency_list<boost::setS, boost::vecS,
+ boost::undirectedS,
+ VertexProperty, EdgeProperty> decorated;
+
+ /// Descriptors.
+ typedef typename decorated::vertex_descriptor vertex_descriptor;
+ typedef typename decorated::edge_descriptor edge_descriptor;
+
+ /// Iterators.
+ typedef typename decorated::vertex_iterator vertex_iterator;
+ typedef typename decorated::edge_iterator edge_iterator;
+ typedef typename decorated::out_edge_iterator out_edge_iterator;
+ typedef typename decorated::in_edge_iterator in_edge_iterator;
+ typedef typename decorated::adjacency_iterator adjacency_iterator;
+ typedef typename decorated::inv_adjacency_iterator
+ inv_adjacency_iterator;
+
+ /// Categories.
+ typedef typename decorated::directed_category directed_category;
+ typedef typename decorated::traversal_category traversal_category;
+ typedef typename decorated::edge_parallel_category
+ edge_parallel_category;
+ typedef typename decorated::vertex_property_type vertex_property_type;
+ typedef typename decorated::graph_tag graph_tag;
+
+ /// Sizes.
+ typedef typename decorated::vertices_size_type vertices_size_type;
+ typedef typename decorated::edges_size_type edges_size_type;
+ typedef typename decorated::degree_size_type degree_size_type;
+
+
+ /// Constructor(s).
+ boost_graph();
+ boost_graph(const boost_graph& lhs);
+ boost_graph(vertices_size_type n);
+
+ /// Assignment operator.
+ boost_graph&
+ operator=(const boost_graph& lhs);
+
+ /// Remove all of the edges and vertices from the graph.
+ void clear();
+
+ /// Swap the vertices, edges, and properties of this graph with
+ /// the vertices, edges, and properties of graph x.
+ void swap(boost_graph& rhs);
+
+ /// Internal methods:
+
+ /// Return the boost decorated graph.
+ decorated&
+ graph();
+
+ /// Return the boost decorated graph (const version).
+ const decorated&
+ graph() const;
+
+
+ protected:
+ decorated graph_;
+ /// add index on need
+ };
+
+ /// Graph method declaration
+
+ /// Implementation
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename VertexProp, typename EdgeProp>
+ boost_graph<VertexProp, EdgeProp>::boost_graph()
+ {
+ }
+
+ template <typename VertexProp, typename EdgeProp>
+ boost_graph<VertexProp, EdgeProp>::boost_graph(const boost_graph& lhs) :
+ graph_(lhs.graph_)
+ {
+ }
+
+ template <typename VertexProp, typename EdgeProp>
+ boost_graph<VertexProp, EdgeProp>::boost_graph(vertices_size_type n) :
+ graph_(n)
+ {
+ }
+
+ template <typename VertexProp, typename EdgeProp>
+ boost_graph<VertexProp, EdgeProp>&
+ boost_graph<VertexProp, EdgeProp>::operator=(const boost_graph& lhs)
+ {
+ if (&lhs == this)
+ return *this;
+ this->graph_ = lhs.graph_;
+ }
+
+ template <typename VertexProp, typename EdgeProp>
+ void
+ boost_graph<VertexProp, EdgeProp>::clear()
+ {
+ this->graph_.clear();
+ }
+
+ template <typename VertexProp, typename EdgeProp>
+ void
+ boost_graph<VertexProp, EdgeProp>::swap(boost_graph& rhs)
+ {
+ this->graph_.swap(rhs.graph_);
+ }
+
+ template <typename VertexProp, typename EdgeProp>
+ inline typename boost_graph<VertexProp, EdgeProp>::decorated&
+ boost_graph<VertexProp, EdgeProp>::graph()
+ {
+ return this->graph_;
+ }
+
+ template <typename VertexProp, typename EdgeProp>
+ inline const typename boost_graph<VertexProp, EdgeProp>::decorated&
+ boost_graph<VertexProp, EdgeProp>::graph() const
+ {
+ return this->graph_;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::util::internal
+
+ } // end of namespace mln::util
+
+} // end of namespace mln
+
+# include "boost_graph_access.hh"
+# include "boost_graph_structure.hh"
+# include "boost_graph_property.hh"
+
+#endif // ! MLN_UTIL_BOOST_GRAPH_HH
Index: mln/util/internal/boost_graph_structure.hh
--- mln/util/internal/boost_graph_structure.hh (revision 0)
+++ mln/util/internal/boost_graph_structure.hh (revision 0)
@@ -0,0 +1,281 @@
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// 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.
+
+
+/// \file mln/util/internal/boost_graph_struture.hh
+/// \brief Operations that interract with the boost_graph structure.
+
+#ifndef MLN_UTIL_INTERNAL_BOOST_GRAPH_STRUCTURE_HH_
+# define MLN_UTIL_INTERNAL_BOOST_GRAPH_STRUCTURE_HH_
+
+/// fwd declaration
+namespace mln
+{
+ namespace util
+ {
+ namespace internal
+ {
+ template <typename VertexProperty, typename EdgeProperty>
+ class boost_graph;
+ }
+ }
+}
+
+namespace boost
+{
+ namespace mlnu = mln::util::internal;
+
+ /// \brief Adds edge (u,v) to the graph and returns the edge descriptor for
+ /// the new edge.
+ template <typename VProp, typename EProp>
+ std::pair<typename mlnu::boost_graph<VProp, EProp>::edge_descriptor, bool>
+ add_edge(typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor u,
+ typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor v,
+ typename mlnu::boost_graph<VProp, EProp>& g);
+
+
+ /// \brief Adds edge (u,v) to the graph and attaches p as the value of the
+ /// edge's internal property storage.
+ template <typename VProp, typename EProp>
+ std::pair<typename mlnu::boost_graph<VProp, EProp>::edge_descriptor, bool>
+ add_edge(typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor u,
+ typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor v,
+ const typename mlnu::boost_graph<VProp, EProp>::EdgeProperties& p,
+ typename mlnu::boost_graph<VProp, EProp>& g);
+
+ /// \brief Removes the edge (u,v) from the graph.
+ template <typename VProp, typename EProp>
+ void
+ remove_edge(typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor u,
+ typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor v,
+ typename mlnu::boost_graph<VProp, EProp>& g);
+
+ /// \brief Removes the edge e from the graph.
+ /// This differs from the remove_edge(u, v, g) function in the case of
+ /// a multigraph. This remove_edge(e, g) function removes a single edge,
+ /// whereas the remove_edge(u, v, g) function removes all edges (u,v).
+ template <typename VProp, typename EProp>
+ void
+ remove_edge(typename mlnu::boost_graph<VProp, EProp>::edge_descriptor e,
+ typename mlnu::boost_graph<VProp, EProp>& g);
+
+
+ /// \brief Same as remove_edge(*iter, g)
+ template <typename VProp, typename EProp>
+ void
+ remove_edge(typename mlnu::boost_graph<VProp, EProp>::out_edge_iterator iter,
+ typename mlnu::boost_graph<VProp, EProp>& g);
+
+
+ /// \brief Removes all out-edges of vertex u from the graph that
+ /// satisfy the predicate.
+ template <typename VProp, typename EProp, class Predicate>
+ void
+ remove_out_edge_if(typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor u,
+ Predicate predicate,
+ typename mlnu::boost_graph<VProp, EProp>& g);
+
+ /// FIXME only available on directed graph
+ template <typename VProp, typename EProp, class Predicate>
+ void
+ remove_in_edge_if(typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor v,
+ Predicate predicate,
+ typename mlnu::boost_graph<VProp, EProp>& g);
+
+ /// \brief Removes all edges of vertex u from the graph that
+ /// satisfy the predicate.
+ template <typename VProp, typename EProp, class Predicate>
+ void remove_edge_if(Predicate predicate,
+ typename mlnu::boost_graph<VProp, EProp>& g);
+
+ /// \brief Adds a vertex to the graph.
+ /// Returns the vertex descriptor for the new vertex.
+ template <typename VProp, typename EProp>
+ typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor
+ add_vertex(typename mlnu::boost_graph<VProp, EProp>& g);
+
+ /// \brief Adds a vertex to the graph with the specified properties.
+ /// Returns the vertex descriptor for the new vertex.
+ template <typename VProp, typename EProp>
+ typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor
+ add_vertex(const typename mlnu::boost_graph<VProp, EProp>::VertexProperties& p,
+ typename mlnu::boost_graph<VProp, EProp>& g);
+
+ /// \brief Removes all edges to and from vertex u.
+ template <typename VProp, typename EProp>
+ void
+ clear_vertex(typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor u,
+ typename mlnu::boost_graph<VProp, EProp>& g);
+
+ /// \brief Removes all out-edges to and from vertex u.
+ template <typename VProp, typename EProp>
+ void
+ clear_out_edges(typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor u,
+ typename mlnu::boost_graph<VProp, EProp>& g);
+
+ /// FIXME: only define for the directed graphs.
+ template <typename VProp, typename EProp>
+ void
+ clear_in_edges(typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor u,
+ typename mlnu::boost_graph<VProp, EProp>& g);
+
+
+ /// \brief Remove vertex u from the vertex set of the graph.
+ /// It is assumed that there are no edges to or from vertex u
+ /// when it is removed
+ template <typename VProp, typename EProp>
+ void
+ remove_vertex(typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor u,
+ typename mlnu::boost_graph<VProp, EProp>& g);
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename VProp, typename EProp>
+ std::pair<typename mlnu::boost_graph<VProp, EProp>::edge_descriptor,
+ bool>
+ add_edge(typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor u,
+ typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor v,
+ typename mlnu::boost_graph<VProp, EProp>& g)
+ {
+ return add_edge(u, v, g.graph());
+ }
+
+
+ template <typename VProp, typename EProp>
+ std::pair<typename mlnu::boost_graph<VProp, EProp>::edge_descriptor,
+ bool>
+ add_edge(typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor u,
+ typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor v,
+ const typename mlnu::boost_graph<VProp, EProp>::EdgeProperties& p,
+ typename mlnu::boost_graph<VProp, EProp>& g)
+ {
+ return add_edge(u, v, p, g.graph());
+ }
+
+ template <typename VProp, typename EProp>
+ void
+ remove_edge(typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor u,
+ typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor v,
+ typename mlnu::boost_graph<VProp, EProp>& g)
+ {
+ return remove_edge(u, v, g.graph());
+ }
+
+ template <typename VProp, typename EProp>
+ void
+ remove_edge(typename mlnu::boost_graph<VProp, EProp>::edge_descriptor e,
+ typename mlnu::boost_graph<VProp, EProp>& g)
+ {
+ return remove_edge(e, g.graph());
+ }
+
+ template <typename VProp, typename EProp>
+ void
+ remove_edge(typename mlnu::boost_graph<VProp, EProp>::out_edge_iterator iter,
+ typename mlnu::boost_graph<VProp, EProp>& g)
+ {
+ return remove_edge(iter, g.graph());
+ }
+
+ template <typename VProp, typename EProp, class Predicate>
+ void
+ remove_out_edge_if(typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor u,
+ Predicate predicate,
+ typename mlnu::boost_graph<VProp, EProp>& g)
+ {
+ return remove_out_edge_if(u, predicate, g.graph());
+ }
+
+ template <typename VProp, typename EProp, class Predicate>
+ void
+ remove_in_edge_if(typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor v,
+ Predicate predicate,
+ typename mlnu::boost_graph<VProp, EProp>& g)
+ {
+ return remove_in_edge_if(v, predicate, g.graph());
+ }
+
+ template <typename VProp, typename EProp, class Predicate>
+ void remove_edge_if(Predicate predicate,
+ typename mlnu::boost_graph<VProp, EProp>& g)
+ {
+ return remove_edge_if(predicate, g.graph());
+ }
+
+ template <typename VProp, typename EProp>
+ typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor
+ add_vertex(typename mlnu::boost_graph<VProp, EProp>& g)
+ {
+ return add_vertex(g.graph());
+ }
+
+ template <typename VProp, typename EProp>
+ typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor
+ add_vertex(const typename mlnu::boost_graph<VProp, EProp>::VertexProperties& p,
+ typename mlnu::boost_graph<VProp, EProp>& g)
+ {
+ return add_vertex(p, g.graph());
+ }
+
+ template <typename VProp, typename EProp>
+ void
+ clear_vertex(typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor u,
+ typename mlnu::boost_graph<VProp, EProp>& g)
+ {
+ return clear_vertex(u, g.graph());
+ }
+
+ template <typename VProp, typename EProp>
+ void
+ clear_out_edges(typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor u,
+ typename mlnu::boost_graph<VProp, EProp>& g)
+ {
+ return clear_out_edges(u, g.graph());
+ }
+
+ template <typename VProp, typename EProp>
+ void
+ clear_in_edges(typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor u,
+ typename mlnu::boost_graph<VProp, EProp>& g)
+ {
+ return clear_in_edges(u, g.graph());
+ }
+
+
+ template <typename VProp, typename EProp>
+ void
+ remove_vertex(typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor u,
+ typename mlnu::boost_graph<VProp, EProp>& g)
+ {
+ return remove_vertex(u, g);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace boost
+
+#endif // ! MLN_UTIL_INTERNAL_BOOST_GRAPH_STRUCTURE_HH_
Index: mln/util/internal/boost_graph_access.hh
--- mln/util/internal/boost_graph_access.hh (revision 0)
+++ mln/util/internal/boost_graph_access.hh (revision 0)
@@ -0,0 +1,293 @@
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// 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.
+
+/// \file mln/util/internal/boost_graph_access.hh
+/// \brief boost_graph access operations.
+
+#ifndef MLN_UTIL_INTERNAL_BOOST_GRAPH_ACCESS_HH_
+# define MLN_UTIL_INTERNAL_BOOST_GRAPH_ACCESS_HH_
+
+
+# include <utility>
+
+/// fwd declaration
+namespace mln
+{
+ namespace util
+ {
+ namespace internal
+ {
+ template <typename VertexProperty, typename EdgeProperty>
+ class boost_graph;
+ }
+ }
+}
+
+namespace boost
+{
+ namespace mlnu = mln::util::internal;
+
+ /// \brief Returns an iterator-range providing access to the vertex
+ /// set of graph g.
+ template <typename VProp, typename EProp>
+ std::pair<typename mlnu::boost_graph<VProp, EProp>::vertex_iterator,
+ typename mlnu::boost_graph<VProp, EProp>::vertex_iterator>
+ vertices(const mlnu::boost_graph<VProp, EProp>& g);
+
+
+ /// \brief Returns an iterator-range providing access to
+ /// the edge set of graph g.
+ template <typename VProp, typename EProp>
+ std::pair<typename mlnu::boost_graph<VProp, EProp>::edge_iterator,
+ typename mlnu::boost_graph<VProp, EProp>::edge_iterator>
+ edges(const mlnu::boost_graph<VProp, EProp>& g);
+
+
+ /// \brief Returns an iterator-range providing access to the vertices
+ /// adjacent to vertex u in graph g.
+ template <typename VProp, typename EProp>
+ std::pair<typename mlnu::boost_graph<VProp, EProp>::adjacency_iterator,
+ typename mlnu::boost_graph<VProp, EProp>::adjacency_iterator>
+ adjacent_vertices(typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor u,
+ const mlnu::boost_graph<VProp, EProp>& g);
+
+
+ /// \brief Returns an iterator-range providing access to the vertices in
+ /// graph g to which u is adjacent. (inv is for inverse.)
+ template <typename VProp, typename EProp>
+ std::pair<typename mlnu::boost_graph<VProp, EProp>::inv_adjacency_iterator,
+ typename mlnu::boost_graph<VProp, EProp>::inv_adjacency_iterator>
+ inv_adjacent_vertices(typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor u,
+ const mlnu::boost_graph<VProp, EProp>& g);
+
+ /// \brief Returns an iterator-range providing access access to
+ /// all edges incident on vertex u.
+ template <typename VProp, typename EProp>
+ std::pair<typename mlnu::boost_graph<VProp, EProp>::out_edge_iterator,
+ typename mlnu::boost_graph<VProp, EProp>::out_edge_iterator>
+ out_edges(typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor u,
+ const mlnu::boost_graph<VProp, EProp>& g);
+
+ /// FIXME: this operation is undefined for undirected graph
+ template <typename VProp, typename EProp>
+ std::pair<typename mlnu::boost_graph<VProp, EProp>::in_edge_iterator,
+ typename mlnu::boost_graph<VProp, EProp>::in_edge_iterator>
+ in_edges(typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor v,
+ const mlnu::boost_graph<VProp, EProp>& g);
+
+
+ /// \brief Returns the source vertex of edge e.
+ template <typename VProp, typename EProp>
+ typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor
+ source(typename mlnu::boost_graph<VProp, EProp>::edge_descriptor e,
+ const mlnu::boost_graph<VProp, EProp>& g);
+
+ /// \brief Returns the target vertex of edge e.
+ template <typename VProp, typename EProp>
+ typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor
+ target(typename mlnu::boost_graph<VProp, EProp>::edge_descriptor e,
+ const mlnu::boost_graph<VProp, EProp>& g);
+
+ /// \brief Returns the number of edges leaving vertex u.
+ template <typename V, typename E>
+ typename mlnu::boost_graph<V, E>::degree_size_type
+ out_degree(typename mlnu::boost_graph<V, E>::vertex_descriptor u,
+ const mlnu::boost_graph<V, E>& g);
+
+ /// FIXME this operation is unavalaible for undirected graph.
+ template <typename VProp, typename EProp>
+ typename mlnu::boost_graph<VProp, EProp>::degree_size_type
+ in_degree(typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor u,
+ const mlnu::boost_graph<VProp, EProp>& g);
+
+ /// \brief Returns the number of vertices in the graph g.
+ template <typename VProp, typename EProp>
+ typename mlnu::boost_graph<VProp, EProp>::vertices_size_type
+ num_vertices(const mlnu::boost_graph<VProp, EProp>& g);
+
+ /// \brief Returns the number of edges in the graph g.
+ template <typename VProp, typename EProp>
+ typename mlnu::boost_graph<VProp, EProp>::edges_size_type
+ num_edges(const mlnu::boost_graph<VProp, EProp>& g);
+
+
+ /// \brief Returns the nth vertex in the graph's vertex list.
+ template <typename VProp, typename EProp>
+ typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor
+ vertex(typename mlnu::boost_graph<VProp, EProp>::vertices_size_type n,
+ const typename mlnu::boost_graph<VProp, EProp>& g);
+
+
+ /// \brief Returns an edge connecting vertex u to vertex v in graph g.
+ template <typename VProp, typename EProp>
+ std::pair<typename mlnu::boost_graph<VProp, EProp>::edge_descriptor, bool>
+ edge(typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor u,
+ typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor v,
+ const mlnu::boost_graph<VProp, EProp>& g);
+
+ /// \brief Returns a pair of out-edge iterators that give the range for all
+ /// the parallel edges from u to v.
+ template <typename VProp, typename EProp>
+ std::pair<typename mlnu::boost_graph<VProp, EProp>::out_edge_iterator,
+ typename mlnu::boost_graph<VProp, EProp>::out_edge_iterator>
+ edge_range(typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor u,
+ typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor v,
+ const mlnu::boost_graph<VProp, EProp>& g);
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename VProp, typename EProp>
+ std::pair<typename mlnu::boost_graph<VProp, EProp>::vertex_iterator,
+ typename mlnu::boost_graph<VProp, EProp>::vertex_iterator>
+ vertices(const mlnu::boost_graph<VProp, EProp>& g)
+ {
+ return vertices(g.graph());
+ }
+
+ template <typename VProp, typename EProp>
+ std::pair<typename mlnu::boost_graph<VProp, EProp>::edge_iterator,
+ typename mlnu::boost_graph<VProp, EProp>::edge_iterator>
+ edges(const mlnu::boost_graph<VProp, EProp>& g)
+ {
+ return edges(g.graph());
+ }
+
+ template <typename VProp, typename EProp>
+ std::pair<typename mlnu::boost_graph<VProp, EProp>::adjacency_iterator,
+ typename mlnu::boost_graph<VProp, EProp>::adjacency_iterator>
+ adjacent_vertices(typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor u,
+ const mlnu::boost_graph<VProp, EProp>& g)
+ {
+ return adjacent_vertices(u, g.graph());
+ }
+
+ template <typename VProp, typename EProp>
+ std::pair<typename mlnu::boost_graph<VProp, EProp>::inv_adjacency_iterator,
+ typename mlnu::boost_graph<VProp, EProp>::inv_adjacency_iterator>
+ inv_adjacent_vertices(typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor u,
+ const mlnu::boost_graph<VProp, EProp>& g)
+ {
+ return inv_adjacent_vertices(u, g.graph());
+ }
+
+ template <typename VProp, typename EProp>
+ std::pair<typename mlnu::boost_graph<VProp, EProp>::out_edge_iterator,
+ typename mlnu::boost_graph<VProp, EProp>::out_edge_iterator>
+ out_edges(typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor u,
+ const mlnu::boost_graph<VProp, EProp>& g)
+ {
+ return out_edges(u, g.graph());
+ }
+
+ template <typename VProp, typename EProp>
+ std::pair<typename mlnu::boost_graph<VProp, EProp>::in_edge_iterator,
+ typename mlnu::boost_graph<VProp, EProp>::in_edge_iterator>
+ in_edges(typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor v,
+ const mlnu::boost_graph<VProp, EProp>& g)
+ {
+ return in_edges(v, g.graph());
+ }
+
+ template <typename VProp, typename EProp>
+ typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor
+ source(typename mlnu::boost_graph<VProp, EProp>::edge_descriptor e,
+ const mlnu::boost_graph<VProp, EProp>& g)
+ {
+ return source(e, g.graph());
+ }
+
+ template <typename VProp, typename EProp>
+ typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor
+ target(typename mlnu::boost_graph<VProp, EProp>::edge_descriptor e,
+ const mlnu::boost_graph<VProp, EProp>& g)
+ {
+ return target(e, g.graph());
+ }
+
+ template <typename VProp, typename EProp>
+ typename mlnu::boost_graph<VProp, EProp>::degree_size_type
+ out_degree(typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor u,
+ const mlnu::boost_graph<VProp, EProp>& g)
+ {
+ return out_degree(u, g.graph());
+ }
+
+ template <typename VProp, typename EProp>
+ typename mlnu::boost_graph<VProp, EProp>::degree_size_type
+ in_degree(typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor u,
+ const mlnu::boost_graph<VProp, EProp>& g)
+ {
+ return in_degree(u, g.graph());
+ }
+
+ template <typename VProp, typename EProp>
+ typename mlnu::boost_graph<VProp, EProp>::vertices_size_type
+ num_vertices(const mlnu::boost_graph<VProp, EProp>& g)
+ {
+ return num_vertices(g.graph());
+ }
+
+ template <typename VProp, typename EProp>
+ typename mlnu::boost_graph<VProp, EProp>::edges_size_type
+ num_edges(const mlnu::boost_graph<VProp, EProp>& g)
+ {
+ return num_edges(g.graph());
+ }
+
+ template <typename VProp, typename EProp>
+ typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor
+ vertex(typename mlnu::boost_graph<VProp, EProp>::vertices_size_type n,
+ const typename mlnu::boost_graph<VProp, EProp>& g)
+ {
+ return vertex(n, g.graph());
+ }
+
+ template <typename VProp, typename EProp>
+ std::pair<typename mlnu::boost_graph<VProp, EProp>::edge_descriptor,
+ bool>
+ edge(typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor u,
+ typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor v,
+ const mlnu::boost_graph<VProp, EProp>& g)
+ {
+ return edge(u, v, g.graph());
+ }
+
+ template <typename VProp, typename EProp>
+ std::pair<typename mlnu::boost_graph<VProp, EProp>::out_edge_iterator,
+ typename mlnu::boost_graph<VProp, EProp>::out_edge_iterator>
+ edge_range(typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor u,
+ typename mlnu::boost_graph<VProp, EProp>::vertex_descriptor v,
+ const mlnu::boost_graph<VProp, EProp>& g)
+ {
+ return edge_range(u, v, g.graph());
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace boost
+
+#endif // ! MLN_UTIL_INTERNAL_BOOST_GRAPH_ACCESS_HH_
Index: mln/util/internal/boost_graph_property.hh
--- mln/util/internal/boost_graph_property.hh (revision 0)
+++ mln/util/internal/boost_graph_property.hh (revision 0)
@@ -0,0 +1,171 @@
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// 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.
+
+/// \file mln/util/internal/boost_graph_property.hh
+/// \brief boost_graph properties access operations.
+
+#ifndef MLN_UTIL_INTERNAL_BOOST_GRAPH_PROPERTY_HH_
+# define MLN_UTIL_INTERNAL_BOOST_GRAPH_PROPERTY_HH_
+
+# include <utility>
+# include <boost/graph/adjacency_list.hpp>
+
+/// fwd declaration
+namespace mln
+{
+ namespace util
+ {
+ namespace internal
+ {
+ template <typename VertexProperty, typename EdgeProperty>
+ class boost_graph;
+ }
+ }
+}
+
+namespace boost
+{
+ namespace mlnu = mln::util::internal;
+
+
+ /// \brief Returns the property map object for the vertex property
+ /// specified by PropertyTag.
+ template <typename VProp, typename EProp, typename PropertyTag>
+ typename property_map<typename mlnu::boost_graph<EProp, VProp>::decorated,
+ PropertyTag>::type
+ get(PropertyTag, typename mlnu::boost_graph<VProp, EProp>& g);
+
+
+ /// \brief Returns the property map object for the vertex property
+ /// specified by PropertyTag (const version).
+ template <typename VProp, typename EProp, typename PropertyTag>
+ typename property_map<typename mlnu::boost_graph<EProp, VProp>::decorated,
+ PropertyTag>::const_type
+ get(PropertyTag, const mlnu::boost_graph<VProp, EProp>& g);
+
+
+ /// \brief This returns the property value for x.
+ /// x is either a vertex or edge descriptor.
+ template <typename VProp, typename EProp, typename PropertyTag, typename X>
+ typename property_traits<
+ typename property_map<typename mlnu::boost_graph<EProp, VProp>::decorated,
+ PropertyTag>::const_type >::value_type
+ get(PropertyTag, const mlnu::boost_graph<VProp, EProp>& g, X x);
+
+
+ /// \brief This sets the property value for x to value.
+ /// x is either a vertex or edge descriptor.
+ template <typename VProp, typename EProp,
+ typename PropertyTag, typename X, typename Value>
+ void
+ put(PropertyTag, const mlnu::boost_graph<VProp, EProp>& g,
+ X x, const Value& value);
+
+
+ /// \brief Return the property specified by GraphPropertyTag.
+ template <typename EProp, typename VProp, typename GraphProperties,
+ typename GraphPropertyTag>
+ typename graph_property<typename mlnu::boost_graph<EProp, VProp>::decorated,
+ GraphPropertyTag>::type&
+ get_property(mlnu::boost_graph<VProp, EProp>& g, GraphPropertyTag);
+
+
+ /// \brief Return the property specified by GraphPropertyTag.
+ template <typename VProp, typename EProp,
+ typename GraphProperties, typename GraphPropertyTag>
+ const typename graph_property<
+ typename mlnu::boost_graph<EProp, VProp>::decorated,
+ GraphPropertyTag>::type&
+ get_property(const mlnu::boost_graph<VProp, EProp>& g,
+ GraphPropertyTag);
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename VProp, typename EProp, typename PropertyTag>
+ typename property_map<typename mlnu::boost_graph<EProp, VProp>::decorated,
+ PropertyTag>::type
+ get(PropertyTag property_tag,
+ typename mlnu::boost_graph<VProp, EProp>& g)
+ {
+ return get(property_tag, g.graph());
+ }
+
+ template <typename VProp, typename EProp, typename PropertyTag>
+ typename property_map<typename mlnu::boost_graph<EProp, VProp>::decorated,
+ PropertyTag>::const_type
+ get(PropertyTag property_tag,
+ const mlnu::boost_graph<VProp, EProp>& g)
+ {
+ return get(property_tag, g.graph());
+ }
+
+ template <typename VProp, typename EProp,
+ typename PropertyTag, typename X>
+ typename property_traits<
+ typename property_map<
+ typename mlnu::boost_graph<EProp, VProp>::decorated,
+ PropertyTag>::const_type>::value_type
+ get(PropertyTag property_tag, const mlnu::boost_graph<VProp, EProp>& g, X x)
+ {
+ return get(property_tag, g.graph(), x);
+ }
+
+ template <typename VProp, typename EProp,
+ typename PropertyTag, typename X, typename Value>
+ void
+ put(PropertyTag property_tag, const mlnu::boost_graph<VProp, EProp>& g,
+ X x, const Value& value)
+ {
+ put(property_tag, g.graph(), x, value);
+ }
+
+ template <typename EProp, typename VProp,
+ typename GraphProperties, typename GraphPropertyTag>
+ typename graph_property<typename mlnu::boost_graph<EProp, VProp>::decorated,
+ GraphPropertyTag>::type&
+ get_property(mlnu::boost_graph<VProp, EProp>& g,
+ GraphPropertyTag property_tag)
+ {
+ return get_property(g.graph(), property_tag);
+ }
+
+ template <typename VProp, typename EProp,
+ typename GraphProperties, typename GraphPropertyTag>
+ const typename graph_property<
+ typename mlnu::boost_graph<EProp, VProp>::decorated,
+ GraphPropertyTag>::type&
+ get_property(const mlnu::boost_graph<VProp, EProp>& g,
+ GraphPropertyTag property_tag)
+ {
+ return get_property(g.graph(), property_tag);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+}
+
+#endif // ! MLN_UTIL_INTERNAL_BOOST_GRAPH_PROPERTY_HH_
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Sample code for IRM segmentation.
* sandbox/geraud/irm.cc: New.
irm.cc | 178 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 178 insertions(+)
Index: sandbox/geraud/irm.cc
--- sandbox/geraud/irm.cc (revision 0)
+++ sandbox/geraud/irm.cc (revision 0)
@@ -0,0 +1,178 @@
+
+#include <iterator>
+#include <iostream>
+#include <algorithm>
+
+#include <mln/core/image2d.hh>
+
+#include <mln/core/neighb2d.hh>
+#include <mln/core/window2d.hh>
+#include <mln/core/image_if.hh>
+#include <mln/win/rectangle2d.hh>
+
+#include <mln/io/pgm/load.hh>
+#include <mln/io/pgm/save.hh>
+
+#include <mln/value/int_u8.hh>
+#include <mln/level/transform.hh>
+
+#include <mln/convert/to_window.hh>
+#include <mln/convert/to_image.hh>
+#include <mln/convert/to_fun.hh>
+
+#include <mln/morpho/gradient.hh>
+#include <mln/morpho/closing_area.hh>
+#include <mln/morpho/meyer_wst.hh>
+
+#include <mln/accu/mean.hh>
+#include <mln/level/take.hh>
+
+#include <mln/util/graph.hh>
+
+#include <mln/debug/println.hh>
+
+
+mln::value::int_u8 foo(unsigned u)
+{
+ return u = 0 ?
+ 0 : // wshed line
+ 1 + (u - 1) % 255; // basin
+}
+
+
+namespace mln
+{
+
+ template <typename I>
+ void doit(const I& irm,
+ const image2d<unsigned>& lbl,
+ unsigned nlabels)
+ {
+ {
+// accu::mean_<unsigned> m;
+
+// mln_piter(I) p(irm.domain());
+// for_all(p)
+// if (lbl(p) = 82)
+// m.take(irm(p));
+
+// level::take(irm | (pw::value(lbl) = pw::cst(82)), m);
+
+// std::cout << "reg 82 has mean = " << m << std::endl;
+ }
+
+ std::vector< accu::mean_<unsigned> > m(nlabels + 1);
+ mln_piter(I) p(irm.domain());
+ for_all(p)
+ m[lbl(p)].take(irm(p));
+
+// for (unsigned l = 1; l <= nlabels; ++l)
+// std::cout << l << ":" << m[l] << " ";
+// std::cout << std::endl;
+
+ accu::mean_<unsigned> mm;
+ mm.take(m[70]);
+ mm.take(m[77]);
+ mm.take(m[80]);
+ mm.take(m[82]);
+ mm.take(m[99]);
+ std::cout << mm.to_result() << std::endl;
+ }
+
+
+ template <typename I, typename N>
+ void mk_graph(const I& lbl,
+ N nbh,
+ unsigned nlabels)
+ {
+ std::vector< std::vector<bool> > adja(nlabels + 1);
+ for (unsigned l = 1; l <= nlabels; ++l)
+ adja[l].resize(l, false);
+
+ mln_piter(I) p(lbl.domain());
+ mln_niter(N) n(nbh, p);
+
+ // We compute the adjacency matrix of the RAG.
+ for_all(p)
+ if (lbl(p) = 0) // wshed
+ {
+ std::set<unsigned> s;
+ for_all(n) if (lbl.has(n))
+ {
+ if (lbl(n) = 0)
+ continue;
+ s.insert(lbl(n));
+ }
+ if (s.size() < 2)
+ {
+ std::cout << "#" << std::endl;
+ continue;
+ }
+ std::set<unsigned>::const_iterator l1, l2;
+ for (l1 = s.begin(); l1 != s.end(); ++l1)
+ {
+ l2 = l1;
+ for (++l2; l2 != s.end(); ++l2)
+ adja[*l2][*l1] = true;
+ }
+ }
+
+ unsigned count = 0;
+ for (unsigned l1 = 2; l1 <= nlabels; ++l1)
+ for (unsigned l2 = 1; l2 < l1; ++l2)
+ if (adja[l1][l2])
+ ++count;
+ std::cout << "link count = " << count << std::endl;
+
+ // Graph.
+ util::graph<> g;
+ // Nodes.
+ for (unsigned i = 0; i <= nlabels; ++i)
+ g.add_node();
+ // Edges.
+ for (unsigned l1 = 1; l1 <= nlabels; ++l1)
+ for (unsigned l2 = l1 + 1; l2 <= nlabels; ++l2)
+ if (adja[l1][l2])
+ g.add_edge(l1, l2);
+ g.print_debug (std::cout);
+
+ }
+
+} // end of namespace mln
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ image2d<int_u8> irm;
+ io::pgm::load(irm, "./+irm6cut.pgm");
+
+// io::pgm::save( morpho::gradient(irm, win::rectangle2d(3,3)),
+// "tmp_grad_3x3.pgm" );
+
+ window2d c4p = convert::to_window(c4());
+ c4p.insert(0,0);
+// debug::println(convert::to_image(c4p));
+ image2d<int_u8> grad = morpho::gradient(irm, c4p);
+ io::pgm::save( grad, "tmp_grad_c4p.pgm" );
+
+ image2d<int_u8> clo;
+ initialize(clo, irm);
+
+ morpho::closing_area(grad, c4(), 100, clo);
+ io::pgm::save( clo, "tmp_clo_a100.pgm" );
+
+ unsigned nbasins;
+ image2d<unsigned> wshed = morpho::meyer_wst(clo, c4(), nbasins);
+ std::cout << "nbasins = " << nbasins << std::endl;
+ io::pgm::save( level::transform(wshed, convert::to_fun(foo)),
+ "tmp_wshed.pgm" );
+
+// doit(irm, wshed, nbasins);
+ mk_graph(wshed, c4(), nbasins);
+
+// std::vector< accu::mean_<unsigned> >
+
+}
1
0