URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-27 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add test for draw mesh_image and update mesh_image.
Draw mesh.
* main_mesh_image.cc: New test draw_mesh.
Update.
* draw_mesh.hh,
* mesh_image.hh,
* main.cc: Update.
---
draw_mesh.hh | 30 ++++++++--------
main.cc | 10 +++--
main_mesh_image.cc | 64 +++++++++++++++++++++++++++++++++++
mesh_image.hh | 96 +++++++++++++++++++++++++++++++++++++++++------------
4 files changed, 162 insertions(+), 38 deletions(-)
Index: trunk/milena/sandbox/duhamel/main_mesh_image.cc
===================================================================
--- trunk/milena/sandbox/duhamel/main_mesh_image.cc (revision 0)
+++ trunk/milena/sandbox/duhamel/main_mesh_image.cc (revision 1188)
@@ -0,0 +1,64 @@
+#include <mln/core/image2d_b.hh>
+#include <mln/core/point2d.hh>
+#include <mln/debug/println.hh>
+#include "graph.hh"
+#include "mesh_p.hh"
+#include "mesh_psite.hh"
+#include "draw_mesh.hh"
+#include "mesh_image.hh"
+#include <mln/core/interpolated.hh>
+
+using namespace mln;
+
+int
+main (void)
+{
+ util::graph<void> g;
+
+ g.add_node ();
+ g.add_node ();
+ g.add_node ();
+ g.add_node ();
+ g.add_node ();
+ g.add_node ();
+
+ g.add_edge (0, 1);
+ g.add_edge (1, 2);
+ g.add_edge (2, 3);
+ g.add_edge (1, 3);
+ g.add_edge (4, 5);
+ g.add_edge (1, 4);
+
+ g.coherence ();
+ // g.print_debug ();
+
+ std::vector<point2d> v;
+ v.push_back (make::point2d (1,1));
+ v.push_back (make::point2d (10,1));
+ v.push_back (make::point2d (19,2));
+ v.push_back (make::point2d (19,19));
+ v.push_back (make::point2d (10,10));
+ v.push_back (make::point2d (1,19));
+
+
+ image2d_b<int> ima (20, 20, 1);
+
+ mesh_p<point2d> m(g, v);
+
+ draw::mesh (ima, m, 7, 1);
+
+ std::vector<int> val;
+
+ val.push_back (2);
+ val.push_back (3);
+ val.push_back (4);
+ val.push_back (5);
+ val.push_back (6);
+ val.push_back (7);
+
+ mesh_image<point2d, int> im (m, val);
+
+ draw::mesh (ima, im);
+
+ debug::println (ima);
+}
Index: trunk/milena/sandbox/duhamel/mesh_image.hh
===================================================================
--- trunk/milena/sandbox/duhamel/mesh_image.hh (revision 1187)
+++ trunk/milena/sandbox/duhamel/mesh_image.hh (revision 1188)
@@ -40,6 +40,7 @@
# include "mesh_p.hh"
# include "mesh_psite.hh"
# include <vector>
+# include <mln/core/box2d.hh>
namespace mln
{
@@ -53,10 +54,11 @@
template <typename P, typename V>
struct data_< mesh_image<P, V> >
{
- data_(mesh_p<P>& ima, std::vector<V>& val_);
+ data_(mesh_p<P>& mesh, std::vector<V>& val);
- mesh_p<P> mesh_;
std::vector<V> val_;
+ mesh_p<P> mesh_;
+ box2d b_;
};
} // end of namespace mln::internal
@@ -68,7 +70,7 @@
struct mesh_image : public internal::image_primary_< box2d, mesh_image<P, V>
>
{
- // typedef mln::internal::image_primary_< box2d, mesh_image<P, V> >
super_;
+ typedef mln::internal::image_base_< box2d, mesh_image<P, V> > super_;
/// Point_Site associated type.
typedef P psite;
@@ -77,7 +79,7 @@
typedef V value;
/// Return type of read-write access.
- typedef V& lvalue; // FIXME: Depends on lvalue presence in I.
+ typedef V& lvalue;
/// Return type of read-only access.
typedef V rvalue;
@@ -97,29 +99,40 @@
/// Test if this image has been initialized.
bool has_data() const;
-// /// Test if a pixel value is accessible at \p p
-// using super_::owns_;
+ const box2d& domain() 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<P::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();
+ /// Read-only access of pixel value at point site \p p.
+ rvalue operator()(const P& p) const;
+
+ /// Read-write access of pixel value at point site \p p.
+ lvalue operator()(const P& p);
+
V& operator()(const mln::metal::vec<P::dim, float>& v) const;
-// /// Give the set of values of the image.
-// const vset& values() const;
+ /// Give the set of values of the image.
+ const vset& values() const;
+
+ const std::vector<V>& data_values () const;
+
+ const mesh_p<P>& data_mesh () const;
};
+
# ifndef MLN_INCLUDE_ONLY
namespace internal
{
+
template <typename P, typename V>
data_< mesh_image<P, V> >::data_(mesh_p<P>& mesh,
std::vector<V>& val)
: val_ (val),
@@ -149,6 +162,14 @@
}
template <typename P, typename V>
+ const box2d&
+ mesh_image<P, V>::domain() const
+ {
+ mln_precondition(this->has_data());
+ return this->data_->b_;
+ }
+
+ template <typename P, typename V>
bool mesh_image<P, V>::owns_(const mln::metal::vec<P::dim, float>& v)
const
{
for (unsigned i = 0; i < this->data_->val_.size(); ++i)
@@ -161,21 +182,56 @@
V&
mesh_image<P, V>::operator()(const mln::metal::vec<P::dim, float>& v)
const
{
+ // FIXME
unsigned i = 0;
// for (i = 0; i < this->data_->val_.size(); ++i)
// if (this->data_->mesh_.loc_[i] == v)
// break;
- return this->data_->mesh_.gr.loc_[i];
+// mln_invariant(i == this->data_->val_.size());
+ return this->data_->val_[i];
+ }
+
+ template <typename P, typename V>
+ typename mesh_image<P, V>::rvalue
+ mesh_image<P, V>::operator()(const P& ) const
+ {
+ // FIXME
+ unsigned i = 0;
+ return this->data_->val_[i];
}
-// // FIXME : Should we remove this method? (and inherit it from
-// // identity morpher)
-// template <typename P, typename V>
-// const vset &
-// mesh_image<P, V>::values() const
-// {
-// return vset::the();
-// }
+ template <typename P, typename V>
+ typename mesh_image<P, V>::lvalue
+ mesh_image<P, V>::operator()(const P& )
+ {
+ // FIXME
+ unsigned i = 0;
+ return this->data_->val_[i];
+ }
+
+
+ // FIXME : Should we remove this method? (and inherit it from
+ // identity morpher)
+ template <typename P, typename V>
+ const mln::value::set<V> &
+ mesh_image<P, V>::values() const
+ {
+ return vset::the();
+ }
+
+ template <typename P, typename V>
+ const std::vector<V>&
+ mesh_image<P, V>::data_values () const
+ {
+ return this->data_->val_;
+ }
+
+ template <typename P, typename V>
+ const mesh_p<P>&
+ mesh_image<P, V>::data_mesh () const
+ {
+ return this->data_->mesh_;
+ }
# endif // ! MLN_INCLUDE_ONLY
Index: trunk/milena/sandbox/duhamel/draw_mesh.hh
===================================================================
--- trunk/milena/sandbox/duhamel/draw_mesh.hh (revision 1187)
+++ trunk/milena/sandbox/duhamel/draw_mesh.hh (revision 1188)
@@ -220,21 +220,21 @@
exact(ima)(m.loc_[i]) = node_v;
}
-// template <typename I, typename P, typename V>
-// void
-// mesh(Image<I>& ima, const mesh_image<P, V>& mesh)
-// {
-// // level::fill(ima, 0);
-
-// // for (unsigned i = 0; i < m.gr_.nb_link_; ++i)
-// // line (exact(ima),
-// // m.loc_[m.gr_.links_[i]->node1],
-// // m.loc_[m.gr_.links_[i]->node2],
-// // 1);
-
-// // for (unsigned i = 0; i < m.gr_.nb_node_; ++i)
-// // exact(ima)(m.loc_[i]) = mesh.val_[i];
-// }
+ template <typename I, typename P, typename V>
+ void
+ mesh(Image<I>& ima, const mesh_image<P, V>& mesh)
+ {
+ level::fill(ima, 0);
+
+ for (unsigned i = 0; i < mesh.data_mesh ().gr_.nb_link_; ++i)
+ line (exact(ima),
+ mesh.data_mesh ().loc_[mesh.data_mesh ().gr_.links_[i]->node1],
+ mesh.data_mesh ().loc_[mesh.data_mesh ().gr_.links_[i]->node2],
+ 1);
+
+ for (unsigned i = 0; i < mesh.data_mesh ().gr_.nb_node_; ++i)
+ exact(ima)(mesh.data_mesh ().loc_[i]) = mesh.data_values ()[i];
+ }
} // end of draw
Index: trunk/milena/sandbox/duhamel/main.cc
===================================================================
--- trunk/milena/sandbox/duhamel/main.cc (revision 1187)
+++ trunk/milena/sandbox/duhamel/main.cc (revision 1188)
@@ -49,12 +49,16 @@
std::vector<int> val;
- val.push_back (8);
+ val.push_back (2);
+ val.push_back (3);
+ val.push_back (4);
+ val.push_back (5);
val.push_back (6);
+ val.push_back (7);
- // mesh_image<point2d, int> im (m, val);
+ mesh_image<point2d, int> im (m, val);
- // draw::mesh (ima, im);
+ draw::mesh (ima, im);
debug::println (ima);
}