https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Fixes.
* mln/trait/images.hh: New.
* mln/fun/x2x/translation.hh: Add a FIXME.
* mln/core/point.hh: Fix missing include.
* mln/core/internal/run_psite.hh: Typo.
* mln/core/ops.hh (operator*): New overload.
* mln/metal/mat.hh: Add inheritance.
(multiply_): New.
* mln/metal/binary_arith_trait.hh: Fix missing namespaces.
(mlc_bin_arith): New macro.
* mln/level/approx/median.hh: Add timer.
* mln/value/props.hh: Update.
* sandbox/duhamel/main_mesh_image.cc,
* sandbox/duhamel/mesh_image.hh,
* sandbox/duhamel/mesh_psite.hh,
* sandbox/duhamel/draw_mesh.hh,
* sandbox/duhamel/mesh_p.hh: Fix and update.
mln/core/internal/run_psite.hh | 9 ++
mln/core/ops.hh | 11 +++
mln/core/point.hh | 1
mln/fun/x2x/translation.hh | 1
mln/level/approx/median.hh | 27 ++++++-
mln/metal/binary_arith_trait.hh | 18 ++++-
mln/metal/mat.hh | 80 ++++++++++++++---------
mln/trait/images.hh | 60 +++++++++++++++++
mln/value/props.hh | 4 -
sandbox/duhamel/draw_mesh.hh | 10 +-
sandbox/duhamel/main_mesh_image.cc | 8 +-
sandbox/duhamel/mesh_image.hh | 91 +++++---------------------
sandbox/duhamel/mesh_p.hh | 125 ++++++++++++++++++++++++++++++-------
sandbox/duhamel/mesh_psite.hh | 54 ++++++++++++---
14 files changed, 343 insertions(+), 156 deletions(-)
Index: mln/trait/images.hh
--- mln/trait/images.hh (revision 0)
+++ mln/trait/images.hh (revision 0)
@@ -0,0 +1,60 @@
+// 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_TRAIT_IMAGES_HH
+# define MLN_TRAIT_IMAGES_HH
+
+/*! \file mln/core/trait/images.hh
+ *
+ * \brief Forward declarations of all image types.
+ */
+
+
+namespace mln
+{
+
+ // Primitive types.
+ template <typename T> struct image1d_b;
+ template <typename T> struct image2d_b;
+ template <typename T> struct image3d_b;
+ namespace pw { template <typename F, typename S> struct image; }
+ template <typename P, typename T> class rle_image;
+ template <typename P, typename T> class sparse_image;
+
+ // Morphers.
+ template <typename I, typename F> struct image_if;
+ template <typename I, typename D> class decorated_image;
+ template <typename I, typename S> class sub_image;
+ template <typename I> struct t_image;
+ template <typename I> class safe_image;
+ template <typename T, typename I> class cast_image_;
+ namespace value { template <unsigned n, typename I> struct stack_image; }
+
+} // end of namespace mln
+
+
+#endif // ! MLN_TRAIT_IMAGES_HH
Index: mln/fun/x2x/translation.hh
--- mln/fun/x2x/translation.hh (revision 1192)
+++ mln/fun/x2x/translation.hh (working copy)
@@ -96,6 +96,7 @@
translation<n,C>::operator()(const metal::vec<n,C>& v) const
{
typename translation::result res;
+ // FIXME: Why not "res = v + t_;"?
for (unsigned i = 0; i < n; ++i)
res[i] = v[i] + t_[i];
return res;
Index: mln/core/point.hh
--- mln/core/point.hh (revision 1192)
+++ mln/core/point.hh (working copy)
@@ -35,6 +35,7 @@
# include <mln/core/concept/point.hh>
# include <mln/core/internal/coord_impl.hh>
+# include <mln/core/h_vec.hh>
# include <mln/fun/i2v/all.hh>
# include <mln/metal/vec.hh>
# include <mln/core/h_vec.hh>
Index: mln/core/internal/run_psite.hh
--- mln/core/internal/run_psite.hh (revision 1192)
+++ mln/core/internal/run_psite.hh (working copy)
@@ -61,16 +61,22 @@
run_psite(P point, unsigned index, unsigned pset_pos);
operator P () const;
+
/// Return the point at the start of the current run.
P& range_start_();
+
/// Return the point at the start of the current run.
const P& range_start_() const;
+
/// Return the position of this psite in the point set.
unsigned pset_pos_() const;
+
/// Return the position of this psite in the point set.
unsigned& pset_pos_();
+
/// Return the position of this psite in the current range.
unsigned index_() const;
+
/// Return the position of this psite in the current range.
unsigned& index_();
@@ -78,10 +84,13 @@
mln_coord(P) operator[](unsigned i) const;
protected:
+
/// Start of the psite range.
P point_;
+
/// Position in the psite range.
unsigned range_index_;
+
/// Position of the psite in the point set.
unsigned pset_position_;
};
Index: mln/core/ops.hh
--- mln/core/ops.hh (revision 1192)
+++ mln/core/ops.hh (working copy)
@@ -34,6 +34,7 @@
# include <mln/core/concept/object.hh>
# include <mln/core/exact.hh>
+# include <mln/metal/binary_arith_trait.hh>
namespace mln
@@ -93,6 +94,16 @@
bool operator<=(const Object<O1>& lhs, const Object<O2>& rhs);
+ // FIXME: Doc!
+ template <typename O>
+ mlc_bin_arith(int, O)
+ operator*(int lhs, const Object<O>& rhs)
+ {
+ return exact(rhs) * lhs;
+ }
+
+
+
# ifndef MLN_INCLUDE_ONLY
template <typename O1, typename O2>
Index: mln/metal/mat.hh
--- mln/metal/mat.hh (revision 1192)
+++ mln/metal/mat.hh (working copy)
@@ -30,6 +30,7 @@
# include <iostream>
+# include <mln/core/concept/object.hh>
# include <mln/core/contract.hh>
# include <mln/metal/binary_arith_trait.hh>
@@ -42,7 +43,7 @@
{
template <unsigned n, unsigned m, typename T>
- class mat
+ class mat : public Object< mat<n,m,T> >
{
public:
@@ -91,7 +92,7 @@
operator+=(mat<n,m,T>& lhs, const mat<n,m,U>& rhs);
template <unsigned n, unsigned m, typename T, typename U>
- mat<n,m,typename binary_arith_trait<T,U>::ret>
+ mat<n,m,mlc_bin_arith(T,U)>
operator+(mat<n,m,T>& lhs, const mat<n,m,U>& rhs);
// -
@@ -101,7 +102,7 @@
operator-=(mat<n,m,T>& lhs, const mat<n,m,U>& rhs);
template <unsigned n, unsigned m, typename T, typename U>
- mat<n,m,typename binary_arith_trait<T,U>::ret>
+ mat<n,m,mlc_bin_arith(T,U)>
operator-(mat<n,m,T>& lhs, const mat<n,m,U>& rhs);
template <unsigned n, unsigned m, typename T>
@@ -115,15 +116,15 @@
operator*=(mat<n,o,T>& lhs, mat<o,m,U>& rhs);
template <unsigned n, unsigned m, unsigned o, typename T, typename U>
- mat<n,m,typename binary_arith_trait<T,U>::ret>
+ mat<n,m,mlc_bin_arith(T,U)>
operator*(const mat<n,o,T>& lhs, const mat<o,m,U>& rhs);
template <unsigned n, unsigned m, typename T, typename U>
mat<n,m,T>&
- operator*=(mat<n,m,T>& lhs, const U& scalar);
+ operator*=(mat<n,m,T>& lhs, const U& rhs);
template <unsigned n, unsigned m, typename T, typename U>
- mat<n,m,typename binary_arith_trait<T,U>::ret>
+ mat<n,m,mlc_bin_arith(T,U)>
operator*(const U& scalar, mat<n,m,T>& lhs);
// /
@@ -133,7 +134,7 @@
operator/=(mat<n,m,T>& lhs, const U& scalar);
template <unsigned n, unsigned m, typename T, typename U>
- mat<n,m,typename binary_arith_trait<T,U>::ret>
+ mat<n,m,mlc_bin_arith(T,U)>
operator/(mat<n,m,T>& lhs, const U& scalar);
// <<
@@ -249,10 +250,10 @@
return lhs;
}
template <unsigned n, unsigned m, typename T, typename U>
- mat<n,m,typename binary_arith_trait<T,U>::ret>
+ mat<n,m,mlc_bin_arith(T,U)>
operator+(mat<n,m,T>& lhs, const mat<n,m,U>& rhs)
{
- mat<n,m,typename binary_arith_trait<T,U>::ret> tmp;
+ mat<n,m,mlc_bin_arith(T,U)> tmp;
for (unsigned i = 0; i < n; ++i)
for (unsigned j = 0; j < m; ++j)
tmp[i][j] = lhs(i, j) + rhs(i, j);
@@ -271,10 +272,10 @@
return lhs;
}
template <unsigned n, unsigned m, typename T, typename U>
- mat<n,m,typename binary_arith_trait<T,U>::ret>
+ mat<n,m,mlc_bin_arith(T,U)>
operator-(mat<n,m,T>& lhs, const mat<n,m,U>& rhs)
{
- mat<n,m,typename binary_arith_trait<T,U>::ret> tmp;
+ mat<n,m,mlc_bin_arith(T,U)> tmp;
for (unsigned i = 0; i < n; ++i)
for (unsigned j = 0; j < m; ++j)
tmp(i, j) = lhs(i, j) - rhs(i, j);
@@ -292,7 +293,7 @@
return tmp;
}
- // *
+ // *
template <unsigned n, unsigned m, unsigned o, typename T, typename U>
mat<n,m,T>&
@@ -301,11 +302,27 @@
lhs = lhs * rhs;
return lhs;
}
+
+ template <unsigned n, unsigned m, typename T, typename U>
+ mat<n,m,T>&
+ operator*=(mat<n,m,T>& lhs, const U& scalar)
+ {
+ for (unsigned i = 0; i < n; ++i)
+ for (unsigned j = 0; j < m; ++j)
+ lhs(i, j) *= scalar;
+ return lhs;
+ }
+
+ // Operators *.
+
+ namespace internal
+ {
+
template <unsigned n, unsigned m, unsigned o, typename T, typename U>
- mat<n,m,typename binary_arith_trait<T,U>::ret>
- operator*(const mat<n,o,T>& lhs, const mat<o,m,U>& rhs)
+ mat<n,m,mlc_bin_arith(T,U)>
+ multiply_(const mat<n,o,T>& lhs, const mat<o,m,U>& rhs)
{
- mat<n,m,typename binary_arith_trait<T,U>::ret> tmp;
+ mat<n,m,mlc_bin_arith(T,U)> tmp;
for (unsigned i = 0; i < n; ++i)
for (unsigned j = 0; j < m; ++j)
{
@@ -316,24 +333,26 @@
return tmp;
}
- template <unsigned n, unsigned m, typename T, typename U>
- mat<n,m,T>&
- operator*=(mat<n,m,T>& lhs, const U& scalar)
+ template <unsigned n, unsigned m, typename T,
+ typename U>
+ mat<n,m,mlc_bin_arith(T,U)>
+ multiply_(mat<n,m,T>& lhs, const U& rhs)
{
+ mat<n,m,mlc_bin_arith(T,U)> tmp;
for (unsigned i = 0; i < n; ++i)
for (unsigned j = 0; j < m; ++j)
- lhs(i, j) *= scalar;
- return lhs;
+ tmp(i, j) = lhs(i, j) * rhs;
+ return tmp;
}
- template <unsigned n, unsigned m, typename T, typename U>
- mat<n,m,typename binary_arith_trait<T,U>::ret>
- operator*(const U& scalar, mat<n,m,T>& lhs)
+
+ } // end of namespace mln::metal::internal
+
+ template <unsigned n, unsigned m, typename T,
+ typename U>
+ mat<n,m,mlc_bin_arith(T,U)>
+ operator*(mat<n,m,T>& lhs, const U& rhs)
{
- mat<n,m,typename binary_arith_trait<T,U>::ret> tmp;
- for (unsigned i = 0; i < n; ++i)
- for (unsigned j = 0; j < m; ++j)
- tmp(i, j) = scalar * lhs(i, j);
- return tmp;
+ return internal::multiply_(lhs, rhs);
}
// /
@@ -347,11 +366,12 @@
lhs(i, j) /= scalar;
return lhs;
}
+
template <unsigned n, unsigned m, typename T, typename U>
- mat<n,m,typename binary_arith_trait<T,U>::ret>
+ mat<n,m,mlc_bin_arith(T,U)>
operator/(mat<n,m,T>& lhs, const U& scalar)
{
- mat<n,m,typename binary_arith_trait<T,U>::ret> tmp;
+ mat<n,m,mlc_bin_arith(T,U)> tmp;
for (unsigned i = 0; i < n; ++i)
for (unsigned j = 0; j < m; ++j)
tmp[i][j] = lhs(i, j) / scalar;
Index: mln/metal/binary_arith_trait.hh
--- mln/metal/binary_arith_trait.hh (revision 1192)
+++ mln/metal/binary_arith_trait.hh (working copy)
@@ -29,11 +29,18 @@
# define MLN_METAL_BINARY_ARITH_TRAIT_HH
- template <typename T, typename U>
- struct binary_arith_trait
+# define mlc_bin_arith(T, U) typename mln::metal::binary_arith_trait< T , U >::ret
+
+
+
+namespace mln
{
- typedef T ret;
- };
+
+ namespace metal
+ {
+
+ template <typename T, typename U>
+ struct binary_arith_trait;
template <>
@@ -69,5 +76,8 @@
typedef double ret;
};
+ } // end of namespace mln::metal
+
+} // end of namespace mln
#endif // ! MLN_METAL_BINARY_ARITH_TRAIT_HH
Index: mln/level/approx/median.hh
--- mln/level/approx/median.hh (revision 1192)
+++ mln/level/approx/median.hh (working copy)
@@ -42,6 +42,8 @@
# include <mln/core/win/diag2d.hh>
# include <mln/core/win/backdiag2d.hh>
+#include <time.h>
+
namespace mln
{
@@ -114,11 +116,26 @@
O
tmp1(output.domain()),
tmp2(output.domain());
-
- level::median(input, win::hline2d(len), tmp1);
- level::median(tmp1, win::vline2d(len), tmp2);
- level::median(tmp2, win::diag2d(len), tmp1);
- level::median(tmp1, win::backdiag2d(len), output);
+ {
+ clock_t c = clock();
+ level::median(input, win::diag2d(len), tmp1);
+ std::cout << float(clock() - c) / CLOCKS_PER_SEC << std::endl;
+ }
+ {
+ clock_t c = clock();
+ level::median(tmp1, win::backdiag2d(len), tmp2);
+ std::cout << float(clock() - c) / CLOCKS_PER_SEC << std::endl;
+ }
+ {
+ clock_t c = clock();
+ level::median(tmp2, win::hline2d(len), tmp1);
+ std::cout << float(clock() - c) / CLOCKS_PER_SEC << std::endl;
+ }
+ {
+ clock_t c = clock();
+ level::median(tmp1, win::vline2d(len), output);
+ std::cout << float(clock() - c) / CLOCKS_PER_SEC << std::endl;
+ }
}
Index: mln/value/props.hh
--- mln/value/props.hh (revision 1192)
+++ mln/value/props.hh (working copy)
@@ -236,7 +236,7 @@
static const metal::vec<n,T> max() { return make::vec<n>(mln_max(T)); }
typedef data_kind kind;
static const std::size_t card_ = n * mln_card_(T);
- typedef binary_arith_trait<float,T> sum;
+ typedef mlc_bin_arith(float,T) sum;
};
template <unsigned n, unsigned m, typename T>
@@ -246,7 +246,7 @@
static const metal::mat<n,m,T> max() { return make::mat<n,m>(mln_max(T)); }
typedef data_kind kind;
static const std::size_t card_ = n * m * mln_card_(T);
- typedef binary_arith_trait<float,T> sum;
+ typedef mlc_bin_arith(float,T) sum;
};
} // end of namespace mln::value
Index: sandbox/duhamel/main_mesh_image.cc
--- sandbox/duhamel/main_mesh_image.cc (revision 1192)
+++ sandbox/duhamel/main_mesh_image.cc (working copy)
@@ -45,6 +45,8 @@
mesh_p<point2d> m(g, v);
+ draw::mesh (ima, m, 7, 1);
+
std::vector<int> val;
val.push_back (2);
@@ -54,8 +56,10 @@
val.push_back (6);
val.push_back (7);
- mesh_image<point2d, int> m_ima (m, val);
- draw::mesh (ima, m_ima);
+ mesh_image<point2d, int> im (m, val);
+ draw::mesh (ima, im);
debug::println (ima);
+
+ std::cout << im.domain() << std::endl;
}
Index: sandbox/duhamel/mesh_image.hh
--- sandbox/duhamel/mesh_image.hh (revision 1192)
+++ sandbox/duhamel/mesh_image.hh (working copy)
@@ -67,13 +67,10 @@
*
*/
template <typename P, typename V>
- struct mesh_image : public internal::image_primary_< box2d, mesh_image<P, V>
>
+ struct mesh_image : public internal::image_primary_< mesh_p<P>,
mesh_image<P, V> >
{
- typedef mln::internal::image_base_< box2d, mesh_image<P, V> > super_;
-
- /// Point_Site associated type.
- typedef P psite;
+ typedef mln::internal::image_base_< mesh_p<P>, mesh_image<P, V> >
super_;
/// Value associated type.
typedef V value;
@@ -82,7 +79,7 @@
typedef V& lvalue;
/// Return type of read-only access.
- typedef V rvalue;
+ typedef const V& rvalue;
/// Value set associated type.
typedef mln::value::set<value> vset;
@@ -95,33 +92,18 @@
mesh_image(mesh_p<P>& mesh, std::vector<V>& val);
mesh_image();
-
- /// Test if this image has been initialized.
- bool has_data() const;
-
- 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.
- rvalue operator()(const P& p) const;
+ const V& operator()(const mesh_psite<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;
+ V& operator()(const mesh_psite<P>& p);
/// Give the set of values of the image.
const vset& values() const;
const std::vector<V>& data_values () const;
- const mesh_p<P>& data_mesh () const;
+ const mesh_p<P>& domain() const;
};
@@ -145,7 +127,6 @@
template <typename P, typename V>
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);
}
@@ -155,62 +136,25 @@
}
template <typename P, typename V>
- bool mesh_image<P, V>::has_data() const
- {
- mln_invariant(this->data_->val_.size() != 0);
- return true;
- }
-
- 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
+ const V&
+ mesh_image<P, V>::operator()(const mesh_psite<P>& p) 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>
- V&
- mesh_image<P, V>::operator()(const mln::metal::vec<P::dim, float>& v)
const
- {
- // FIXME
- unsigned i = 0;
+ mln_precondition(p.m_ptr_ = & this->data_->mesh_);
+ mln_precondition(p.i_ < this->data_->val_.size());
// for (i = 0; i < this->data_->val_.size(); ++i)
// if (this->data_->mesh_.loc_[i] = v)
// break;
// mln_invariant(i = this->data_->val_.size());
- return this->data_->val_[i];
+ return this->data_->val_[p.i_];
}
template <typename P, typename V>
- typename mesh_image<P, V>::rvalue
- mesh_image<P, V>::operator()(const P& ) const
- {
- // FIXME
- unsigned i = 0;
-// for (i = 0; i < this->data_->val_.size(); ++i)
-// if (this->data_->mesh_.loc_[i] = v)
-// break;
-// mln_invariant(i = this->data_->val_.size());
- return this->data_->val_[i];
- }
-
- template <typename P, typename V>
- typename mesh_image<P, V>::lvalue
- mesh_image<P, V>::operator()(const P& )
+ V&
+ mesh_image<P, V>::operator()(const mesh_psite<P>& p)
{
- // FIXME
- unsigned i = 0;
- return this->data_->val_[i];
+ mln_precondition(p.m_ptr_ = & this->data_->mesh_);
+ mln_precondition(p.i_ < this->data_->val_.size());
+ return this->data_->val_[p.i_];
}
@@ -232,8 +176,9 @@
template <typename P, typename V>
const mesh_p<P>&
- mesh_image<P, V>::data_mesh () const
+ mesh_image<P, V>::domain() const
{
+ mln_precondition(this->has_data());
return this->data_->mesh_;
}
Index: sandbox/duhamel/mesh_psite.hh
--- sandbox/duhamel/mesh_psite.hh (revision 1192)
+++ sandbox/duhamel/mesh_psite.hh (working copy)
@@ -1,25 +1,55 @@
#ifndef MLN_MESH_PSITE_HH
# define MLN_MESH_PSITE_HH
-# include "mesh_p.hh"
namespace mln
{
+
+ template<typename P> class mesh_p;
+
template<typename P>
- class mesh_psite
+ struct mesh_psite : public Point_Site< mesh_psite<P> >
{
- public:
- mesh_psite () {}
- mesh_psite (unsigned i// , mesh_p<P> * m_ptr
- ) :
- i_ (i)// ,
-// m_ptr_ (m_ptr)
+ typedef mln_mesh(P) mesh;
+ enum { dim = P::dim };
+ typedef P point;
+ typedef mln_dpoint(P) dpoint;
+ typedef mln_coord(P) coord;
+
+ 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:
+
+ ~mesh_psite()
+ {
+ }
+
+ P to_point() const
+ {
+ return m_ptr_->loc_[i_];
+ }
+
+ operator P() const
+ {
+ return m_ptr_->loc_[i_];
+ }
+
+ const point* pointer_() const { return 0; }
+
+ coord operator[](unsigned i) const
+ {
+ return to_point()[i];
+ }
+
unsigned i_;
- // mesh_p<P>* m_ptr_;
+ mesh_p<P>* m_ptr_;
};
+
} // end of mln
+
#endif // MLN_MESH_PSITE_HH
Index: sandbox/duhamel/draw_mesh.hh
--- sandbox/duhamel/draw_mesh.hh (revision 1192)
+++ sandbox/duhamel/draw_mesh.hh (working copy)
@@ -226,14 +226,14 @@
{
level::fill(ima, 0);
- for (unsigned i = 0; i < mesh.data_mesh ().gr_.nb_link_; ++i)
+ for (unsigned i = 0; i < mesh.domain().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],
+ mesh.domain().loc_[mesh.domain().gr_.links_[i]->node1],
+ mesh.domain().loc_[mesh.domain().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];
+ for (unsigned i = 0; i < mesh.domain().gr_.nb_node_; ++i)
+ exact(ima)(mesh.domain().loc_[i]) = mesh.data_values ()[i];
}
} // end of draw
Index: sandbox/duhamel/mesh_p.hh
--- sandbox/duhamel/mesh_p.hh (revision 1192)
+++ sandbox/duhamel/mesh_p.hh (working copy)
@@ -2,14 +2,20 @@
# define MLN_MESH_P_HH
# include <mln/core/concept/point.hh>
+# include <mln/core/internal/point_set_base.hh>
+# include <mln/core/internal/point_iterator_base.hh>
+# include <mln/accu/bbox.hh>
# include "graph.hh"
# include "mesh_psite.hh"
namespace mln
{
+ template<typename P> class mesh_p_piter_;
+
+
template<typename P>
- class mesh_p// : public Point_Set<mesh_p<P> >
+ class mesh_p : public internal::point_set_base_< P, mesh_p<P> >
{
public:
mesh_p () {}
@@ -19,28 +25,21 @@
: gr_ (gr),
loc_ (loc)
{
+ accu::bbox<P> a;
+ for (unsigned i = 0; i < loc.size(); ++i)
+ a.take(loc[i]);
+ bb_ = a.to_result();
}
- ~mesh_p () {}
-
- /// Mesh associated type.
- typedef mln_mesh(P) mesh;
-
/// Point_Site associated type.
typedef mesh_psite<P> psite;
- /// Point associated type.
- typedef P point;
-
- /// Dpoint associated type.
- typedef mln_dpoint(P) dpoint;
-
//FIXME
/// Forward Point_Iterator associated type.
- typedef P fwd_piter;
+ typedef mesh_p_piter_<P> fwd_piter;
/// Backward Point_Iterator associated type.
- typedef P bkd_piter;
+ typedef mesh_p_piter_<P> bkd_piter;
//END FIXME
std::size_t npoints() const
@@ -48,19 +47,99 @@
return this->gr_.nb_node_;
}
-// bool has(const P& p) const
-// {
-// typename std::vector<P>::const_iterator it = this->loc_.begin ();
-
-// for (; it != this->loc_.begin () ; ++it)
-// if (*it = p)
-// return true;
-// return false;
-// }
+ /// Give the exact bounding box.
+ const box_<P>& bbox() const
+ {
+ return bb_;
+ }
+
+ bool has(const psite& p) const
+ {
+ for (unsigned i = 0; i < loc_.size(); ++i)
+ if (loc_[i] = p)
+ return true;
+ return false;
+ }
util::graph<void> gr_;
std::vector<P> loc_;
+ box_<P> bb_;
+ };
+
+
+
+ template<typename P>
+ class mesh_p_piter_ : public internal::point_iterator_base_< P,
mesh_p_piter_<P> >
+ {
+ typedef mesh_p_piter_<P> self_;
+ typedef internal::point_iterator_base_< P, self_ > super_;
+ public:
+
+ // Make definitions from super class available.
+ enum { dim = super_::dim };
+
+ mesh_p_piter_(const mesh_p<P>& s)
+ : loc_(s.loc_)
+ {
+ invalidate();
+ }
+
+ /// Give a hook to the point address.
+ const P* pointer_() const
+ {
+ return & p_;
+ }
+
+ /// Read-only access to the \p i-th coordinate.
+ mln_coord(P) operator[](unsigned i) const
+ {
+ return p_[i];
+ }
+
+ /// Test if the iterator is valid.
+ bool is_valid() const
+ {
+ return i_ != loc_.size();
+ }
+
+ /// Invalidate the iterator.
+ void invalidate()
+ {
+ i_ = loc_.size();
+ }
+
+ /// Start an iteration.
+ void start()
+ {
+ i_ = 0;
+ if (is_valid())
+ p_ = loc_[i_];
+ }
+
+ /// Go to the next point.
+ void next_()
+ {
+ ++i_;
+ if (is_valid())
+ p_ = loc_[i_];
+ }
+
+ /// Convert the iterator into a point.
+ operator P() const
+ {
+ mln_precondition(is_valid());
+ return p_;
+ }
+
+ protected:
+ const std::vector<P>& loc_;
+ unsigned i_;
+ P p_;
};
+
+
+
} // end of mln
+
#endif // MLN_MESH_P_HH