URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-26 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add mesh_image.
* draw_mesh.hh: Update.
* mesh_image.hh: New.
---
draw_mesh.hh | 3
mesh_image.hh | 186 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 188 insertions(+), 1 deletion(-)
Index: trunk/milena/sandbox/duhamel/mesh_image.hh
===================================================================
--- trunk/milena/sandbox/duhamel/mesh_image.hh (revision 0)
+++ trunk/milena/sandbox/duhamel/mesh_image.hh (revision 1181)
@@ -0,0 +1,186 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_CORE_MESH_IMAGE_HH
+# define MLN_CORE_MESH_IMAGE_HH
+
+/*! \file mln/core/mesh_image.hh
+ *
+ * \brief Definition of an image class FIXME
+ */
+
+# include <cmath>
+
+# include <mln/core/internal/image_identity.hh>
+# include <mln/metal/vec.hh>
+# include "mesh_p.hh"
+
+namespace mln
+{
+
+ // Fwd decl.
+ template <typename P, typename V> struct mesh_image;
+
+ namespace internal
+ {
+
+ template <typename P, typename V>
+ struct data_< mesh_image<P, V> >
+ {
+ data_(Mesh_p<P>& ima);
+
+ Mesh_p<P> mesh_;
+ std::vector<V> val_;
+ };
+
+ } // end of namespace mln::internal
+
+ /*! \brief FIXME
+ *
+ */
+ template <typename P, typename V>
+ struct mesh_image : public mln::internal::image_identity_< I, mln_pset(I),
mesh_image<I> >
+ {
+
+// typedef mln::internal::image_identity_< I, mln_pset(I), mesh_image<I>
> super_;
+
+// /// Point_Site associated type.
+// typedef mln_psite(I) psite;
+
+// /// Value associated type.
+// typedef mln_value(V) value;
+
+// /// Return type of read-write access.
+// typedef mln_lvalue(V) lvalue; // FIXME: Depends on lvalue presence in I.
+
+// /// Return type of read-only access.
+// typedef mln_rvalue(I) rvalue;
+
+// /// Value set associated type.
+// typedef mln::value::set<value> vset;
+
+
+// /// Skeleton.
+// typedef mesh_image< tag::image_<I> > skeleton;
+
+
+ /// Constructors.
+ mesh_image(mesh_p& mesh, std::vector<V>& val);
+ mesh_image();
+
+
+ /// Test if this image has been initialized.
+ bool has_data() const;
+
+ /// Test if a pixel value is accessible at \p p.
+ using super_::owns_;
+
+ /// Test if a pixel value is accessible at \p v.
+ bool owns_(const mln::metal::vec<I::point::dim, float>& v) const;
+
+ /// Read-only access of pixel value at point site \p p.
+ /// Mutable access is only OK for reading (not writing).
+ using super_::operator();
+
+ mln_value(I) operator()(const mln::metal::vec<I::point::dim, float>& v)
const;
+
+
+ /// Give the set of values of the image.
+ const vset& values() const;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace internal
+ {
+
+ // internal::data_< mesh_image<I,S> >
+
+ template <typename P, typename V>
+ data_< mesh_image<P, V> >::data_(I& ima)
+ : ima_(ima)
+ {
+ }
+
+ } // end of namespace mln::internal
+
+ template <typename P, typename V>
+ mesh_image<I>::mesh_image(I& ima)
+ {
+ mln_precondition(ima.has_data());
+ this->data_ = new internal::data_< mesh_image<I> >(ima);
+ }
+
+ template <typename P, typename V>
+ mesh_image<I>::mesh_image()
+ {
+ }
+
+ template <typename P, typename V>
+ bool mesh_image<I>::has_data() const
+ {
+ mln_invariant(this->data_->ima_.has_data());
+ return true;
+ }
+
+ template <typename P, typename V>
+ bool mesh_image<I>::owns_(const mln::metal::vec<I::point::dim, float>&
v) const
+ {
+ mln_point(I) p;
+ for (unsigned i = 0; i < I::point::dim; ++i)
+ p[i] = static_cast<int>(round(v[i]));
+ return this->data_->ima_.owns_(p);
+ }
+
+ template <typename P, typename V>
+ mln_value(I)
+ mesh_image<I>::operator()(const mln::metal::vec<I::point::dim, float>&
v) const
+ {
+ mln_point(I) p;
+ for (unsigned i = 0; i < I::point::dim; ++i)
+ p[i] = static_cast<int>(round(v[i]));
+ mln_assertion(this->data_->ima_.owns_(p));
+ return this->data_->ima_(p);
+ }
+
+ // FIXME : Should we remove this method? (and inherit it from
+ // identity morpher)
+ template <typename P, typename V>
+ const mln::value::set<mln_value(I) >&
+ mesh_image<I>::values() const
+ {
+ return vset::the();
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_MESH_IMAGE_HH
Index: trunk/milena/sandbox/duhamel/draw_mesh.hh
===================================================================
--- trunk/milena/sandbox/duhamel/draw_mesh.hh (revision 1180)
+++ trunk/milena/sandbox/duhamel/draw_mesh.hh (revision 1181)
@@ -7,6 +7,7 @@
//# include <mln/pw/cst.hh>
# include <mln/level/fill.hh>
//# include <mln/metal/is_a.hh>
+# include <mln/draw/line.hh>
# include "mesh_p.hh"
namespace mln
@@ -209,7 +210,7 @@
level::fill(ima, 0);
for (unsigned i = 0; i < m.gr_.nb_link_; ++i)
- bresenham (exact(ima),
+ line (exact(ima),
m.loc_[m.gr_.links_[i]->node1],
m.loc_[m.gr_.links_[i]->node2],
link_v);