
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2007-09-27 Guillaume Duhamel <guillaume.duhamel@lrde.epita.fr> Update mesh_psite. * draw_mesh.hh, * graph.hh, * graph.hxx, * main.cc, * mesh_image.hh, * mesh_p.hh, * mesh_psite.hh: Update. --- draw_mesh.hh | 2 - graph.hh | 8 +++---- graph.hxx | 9 ++++---- main.cc | 6 +++-- mesh_image.hh | 62 +++++++++++++++++++++++++++++----------------------------- mesh_p.hh | 11 ++++------ mesh_psite.hh | 16 +++++++++----- 7 files changed, 60 insertions(+), 54 deletions(-) Index: trunk/milena/sandbox/duhamel/mesh_image.hh =================================================================== --- trunk/milena/sandbox/duhamel/mesh_image.hh (revision 1184) +++ trunk/milena/sandbox/duhamel/mesh_image.hh (revision 1185) @@ -38,6 +38,7 @@ # include <mln/core/internal/image_identity.hh> # include <mln/metal/vec.hh> # include "mesh_p.hh" +# include "mesh_psite.hh" # include <vector> namespace mln @@ -52,9 +53,9 @@ template <typename P, typename V> struct data_< mesh_image<P, V> > { - data_(Mesh_p<P>& ima, std::vector<V>& val_); + data_(mesh_p<P>& ima, std::vector<V>& val_); - Mesh_p<P> mesh_; + mesh_p<P> mesh_; std::vector<V> val_; }; @@ -67,7 +68,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_primary_< box2d, mesh_image<P, V> > super_; /// Point_Site associated type. typedef P psite; @@ -89,25 +90,24 @@ typedef mesh_image< tag::psite_<P>, tag::value_<V> > skeleton; /// Constructors. - mesh_image(Mesh_p<P>& mesh, std::vector<V>& val); + mesh_image(mesh_p<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. +// /// 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; + /// 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(); -// V operator()(const mln::metal::vec<I::point::dim, float>& v) const; - + V& operator()(const mln::metal::vec<P::dim, float>& v) const; // /// Give the set of values of the image. // const vset& values() const; @@ -121,7 +121,7 @@ { template <typename P, typename V> - data_< mesh_image<P, V> >::data_(Mesh_p<P>& mesh, std::vector<V>& val) + data_< mesh_image<P, V> >::data_(mesh_p<P>& mesh, std::vector<V>& val) : val_ (val), mesh_ (mesh) { @@ -130,7 +130,7 @@ } // end of namespace mln::internal template <typename P, typename V> - mesh_image<P, V>::mesh_image(Mesh_p<P>& mesh, std::vector<V>& val) + mesh_image<P, V>::mesh_image(mesh_p<P>& mesh, std::vector<V>& val) { // mln_precondition(ima.has_data()); this->data_ = new internal::data_< mesh_image<P, V> > (mesh, val); @@ -148,31 +148,31 @@ return true; } -// template <typename P, typename V> -// bool mesh_image<P, V>::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> + 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) + if (this->data_->mesh_.loc_[i] == v) + return true; + return false; + } -// 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); -// } + template <typename P, typename V> + V& + mesh_image<P, V>::operator()(const mln::metal::vec<P::dim, float>& v) const + { + 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]; + } // // 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 +// const vset & +// mesh_image<P, V>::values() const // { // return vset::the(); // } Index: trunk/milena/sandbox/duhamel/mesh_psite.hh =================================================================== --- trunk/milena/sandbox/duhamel/mesh_psite.hh (revision 1184) +++ trunk/milena/sandbox/duhamel/mesh_psite.hh (revision 1185) @@ -6,15 +6,19 @@ namespace mln { template<typename P> - class Mesh_psite + class mesh_psite { public: - Mesh_psite() {} - ~Mesh_psite() {} - P to_point () {return m_ptr->loc_[i];} + mesh_psite () {} + mesh_psite (unsigned i, mesh_p<P>* m_ptr) : + i_ (i), + m_ptr_ (m_ptr) + {} + ~mesh_psite() {} + P to_point () {return m_ptr_->loc_[i_];} private: - unsigned i; - Mesh_p<P>* m_ptr; + unsigned i_; + mesh_p<P>* m_ptr_; }; } // end of mln #endif // MLN_MESH_PSITE_HH Index: trunk/milena/sandbox/duhamel/graph.hh =================================================================== --- trunk/milena/sandbox/duhamel/graph.hh (revision 1184) +++ trunk/milena/sandbox/duhamel/graph.hh (revision 1185) @@ -68,14 +68,14 @@ }; template<typename N, typename E = void> - class Graph + class graph { public: - Graph () : + graph () : nb_node_ (0), nb_link_ (0) {} - Graph (unsigned nb_node, unsigned nb_link) : + graph (unsigned nb_node, unsigned nb_link) : nb_node_ (nb_node), nb_link_ (nb_link) {} - ~Graph () {} + ~graph () {} // void add_node (N& elt); void add_node (void); Index: trunk/milena/sandbox/duhamel/draw_mesh.hh =================================================================== --- trunk/milena/sandbox/duhamel/draw_mesh.hh (revision 1184) +++ trunk/milena/sandbox/duhamel/draw_mesh.hh (revision 1185) @@ -204,7 +204,7 @@ template <typename I, typename P> void - mesh(Image<I>& ima, const Mesh_p<P>& m, + mesh(Image<I>& ima, const mesh_p<P>& m, mln_value(I) node_v, mln_value(I) link_v) { Index: trunk/milena/sandbox/duhamel/graph.hxx =================================================================== --- trunk/milena/sandbox/duhamel/graph.hxx (revision 1184) +++ trunk/milena/sandbox/duhamel/graph.hxx (revision 1185) @@ -11,7 +11,7 @@ template<typename N, typename E> inline void - Graph<N, E>::add_node (void) + graph<N, E>::add_node (void) { struct s_node<N>* n = new struct s_node<N>; @@ -23,7 +23,7 @@ template<typename N, typename E> inline void - Graph<N, E>::add_edge (unsigned n1, unsigned n2) + graph<N, E>::add_edge (unsigned n1, unsigned n2) { mln_precondition(n1 < this->nb_node_); mln_precondition(n2 < this->nb_node_); @@ -36,12 +36,13 @@ links_.push_back (edge); ++nb_link_; nodes_[n1]->links.push_back (n2); + nodes_[n2]->links.push_back (n1); } template<typename N, typename E> inline void - Graph<N, E>::coherence () const + graph<N, E>::coherence () const { mln_precondition(nodes_.size () == this->nb_node_); mln_precondition(links_.size () == this->nb_link_); @@ -64,7 +65,7 @@ template<typename N, typename E> inline void - Graph<N, E>::print_debug () const + graph<N, E>::print_debug () const { std::cout << "nodes :" << std::endl; Index: trunk/milena/sandbox/duhamel/main.cc =================================================================== --- trunk/milena/sandbox/duhamel/main.cc (revision 1184) +++ trunk/milena/sandbox/duhamel/main.cc (revision 1185) @@ -6,13 +6,14 @@ #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; + util::graph<void> g; g.add_node (); g.add_node (); @@ -42,7 +43,7 @@ image2d_b<int> ima (20, 20, 1); - Mesh_p<point2d> m(g, v); + mesh_p<point2d> m(g, v); draw::mesh (ima, m, 7, 1); @@ -52,6 +53,7 @@ val.push_back (6); // mesh_image<point2d, int> im (m, val); + // draw::mesh (ima, im); debug::println (ima); Index: trunk/milena/sandbox/duhamel/mesh_p.hh =================================================================== --- trunk/milena/sandbox/duhamel/mesh_p.hh (revision 1184) +++ trunk/milena/sandbox/duhamel/mesh_p.hh (revision 1185) @@ -7,23 +7,22 @@ { template<typename P> - class Mesh_p + class mesh_p { public: - Mesh_p () {} + mesh_p () {} - Mesh_p (util::Graph<void>& gr, + mesh_p (util::graph<void>& gr, std::vector<P>& loc) : gr_ (gr), loc_ (loc) { } - ~Mesh_p () {} + ~mesh_p () {} - util::Graph<void> gr_; + util::graph<void> gr_; std::vector<P> loc_; - // Mesh_psite<P> psite; }; } // end of mln