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
September 2007
- 7 participants
- 135 discussions
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Start the image traits mechanism.
The big deal of image traits!
* mln/trait/images.hh: Add contents.
* mln/core/concept/image.hh: Include above file.
* tests/trait_images.cc: New.
The "data kind" trait is updated.
* mln/trait/kind.hh: New.
* mln/value/kind.hh: Remove; obsolete.
* mln/core/macros.hh (mln_value_kind): Move to...
* mln/value/props.hh: ...here.
(mln_kind): Remove; too ambiguous.
(<whatever>_kind): Update.
* mln/morpho/min.hh,
* mln/morpho/plus.hh,
* mln/morpho/minus.hh,
* mln/morpho/complementation.hh,
* mln/morpho/dilation.hh,
* mln/morpho/erosion.hh,
* mln/morpho/hit_or_miss.hh,
* mln/value/int_u_sat.hh,
* mln/value/rgb.hh,
* mln/value/rgb8_non_templated.hh,
* mln/value/int_s.hh,
* mln/value/int_u.hh,
* mln/value/label.hh: Update.
Then declare traits for a couple of classes.
* mln/core/image2d_b.hh,
* mln/core/sub_image.hh (image_): New trait.
Misc.
* mln/fun/x2x/translation.hh,
* mln/fun/x2x/rotation.hh: Change layout.
* mln/core/point.hh (point_to_): New in internal.
(operator vec): Use point_to_ to help g++-2.95.
* mln/metal/mat.hh (operator-): Fix sig.
(mult): New; just for the record.
Sort operators.
* mln/metal/bool.hh (to_bool): New; for completion.
* mln/metal/if.hh: Update.
* mln/metal/binary_arith_trait.hh: New overload.
mln/core/concept/image.hh | 1
mln/core/image2d_b.hh | 19 ++++
mln/core/macros.hh | 3
mln/core/point.hh | 22 ++++
mln/core/sub_image.hh | 20 ++++
mln/fun/x2x/rotation.hh | 1
mln/metal/binary_arith_trait.hh | 6 +
mln/metal/bool.hh | 2
mln/metal/if.hh | 2
mln/metal/mat.hh | 124 ++++++++++++++++-----------
mln/morpho/complementation.hh | 4
mln/morpho/dilation.hh | 4
mln/morpho/erosion.hh | 4
mln/morpho/hit_or_miss.hh | 4
mln/morpho/min.hh | 8 -
mln/morpho/minus.hh | 4
mln/morpho/plus.hh | 4
mln/trait/images.hh | 179 ++++++++++++++++++++++++++++++++++++++++
mln/trait/kind.hh | 61 +++++++++++++
mln/value/int_s.hh | 2
mln/value/int_u.hh | 2
mln/value/int_u_sat.hh | 2
mln/value/label.hh | 2
mln/value/props.hh | 35 ++++---
mln/value/rgb.hh | 2
mln/value/rgb8_non_templated.hh | 2
tests/trait_images.cc | 49 ++++++++++
27 files changed, 470 insertions(+), 98 deletions(-)
Index: tests/trait_images.cc
--- tests/trait_images.cc (revision 0)
+++ tests/trait_images.cc (revision 0)
@@ -0,0 +1,49 @@
+// 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.
+
+/*! \file tests/trait_ch_value.cc
+ *
+ * \brief Tests on mln::trait::ch_value.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/core/sub_image.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ typedef image2d_b<int> I;
+
+ std::cout << "image2d_b: ";
+ mln::trait::print<I>(std::cout);
+
+ std::cout << std::endl
+ << "sub_image< image2d_b >: ";
+ mln::trait::print< sub_image<I, box2d> >(std::cout);
+}
Index: mln/trait/images.hh
--- mln/trait/images.hh (revision 1198)
+++ mln/trait/images.hh (working copy)
@@ -33,6 +33,17 @@
* \brief Forward declarations of all image types.
*/
+# include <iostream>
+# include <string>
+
+# include <mln/value/props.hh>
+# include <mln/metal/if.hh>
+# include <mln/metal/bool.hh>
+
+
+
+# define mln_trait_image_data(I) typename mln::trait::image_< I >::data
+
namespace mln
{
@@ -54,6 +65,174 @@
template <typename T, typename I> class cast_image_;
namespace value { template <unsigned n, typename I> struct stack_image; }
+
+
+ namespace trait
+ {
+
+ struct undef { std::string str() const { return "undef"; } };
+
+
+ template <typename I>
+ struct undefined_image_
+ {
+ // related to I::value
+ typedef undef kind; // color, gray, binary < label, data
+ typedef undef quant; // low or high
+ typedef undef value; // scalar, vectorial, structed
+
+ // related to I::pset
+ typedef undef access; // random, browse
+ typedef undef space; // one_d, two_d, three_d
+ typedef undef size; // huge or regular
+ typedef undef support; // irregular, aligned < regular
+
+ // global
+ typedef undef border; // none, stored, computed
+ typedef undef data; // linear < stored, computed
+ typedef undef io; // read_only < read_write
+ typedef undef speed; // slow, fast, or fastest
+ };
+
+
+ template <typename I>
+ struct image_ : undefined_image_<I>
+ {
+ };
+
+
+ template <typename I>
+ void print(std::ostream& ostr)
+ {
+ typedef image_<I> the;
+ ostr << "{ "
+ << the::data().str() << ", "
+ << the::kind().str() << ", "
+ << the::quant().str() << ", "
+ << the::value().str() << ", "
+ << the::access().str() << ", "
+ << the::space().str() << ", "
+ << the::size().str() << ", "
+ << the::support().str() << ", "
+ << the::border().str() << ", "
+ << the::io().str() << ", "
+ << the::speed().str() << " }" << std::endl;
+ }
+
+
+ struct data
+ {
+ struct computed { std::string str() const { return "data::computed"; } };
+ struct stored { std::string str() const { return "data::stored"; } };
+ struct linear : stored { std::string str() const { return "data::linear"; } };
+ };
+
+ struct quant
+ {
+ struct low { std::string str() const { return "quant::low"; } };
+ struct high { std::string str() const { return "quant::high"; } };
+ };
+
+ struct value
+ {
+ struct scalar { std::string str() const { return "value::scalar"; } };
+ struct vectorial { std::string str() const { return "value::vectorial"; } };
+ struct structed { std::string str() const { return "value::structed"; } };
+ };
+
+
+ struct access
+ {
+ struct random { std::string str() const { return "access::random"; } };
+ struct iterative { std::string str() const { return "access::iterative"; } };
+ };
+
+ struct space
+ {
+ struct one_d { std::string str() const { return "space::one_d"; } };
+ struct two_d { std::string str() const { return "space::two_d"; } };
+ struct three_d { std::string str() const { return "space::three_d"; } };
+ };
+
+ struct size
+ {
+ struct huge { std::string str() const { return "size::huge"; } };
+ struct regular { std::string str() const { return "size::regular"; } };
+ };
+
+ struct support
+ {
+ struct irregular { std::string str() const { return "support::irregular"; } };
+ struct regular { std::string str() const { return "support::regular"; } };
+ struct aligned : regular { std::string str() const { return "support::aligned"; } };
+ };
+
+ struct border
+ {
+ struct none { std::string str() const { return "border::none"; } };
+ struct stored { std::string str() const { return "border::stored"; } };
+ struct computed { std::string str() const { return "border::computed"; } };
+ };
+
+ struct io
+ {
+ struct read_only { std::string str() const { return "io::read_only"; } };
+ struct read_write { std::string str() const { return "io::read_write"; } };
+ };
+
+ struct speed
+ {
+ struct slow { std::string str() const { return "speed::slow"; } };
+ struct fast { std::string str() const { return "speed::fast"; } };
+ struct fastest { std::string str() const { return "speed::fastest"; } };
+ };
+
+
+
+
+ template <typename I>
+ struct default_image_ : undefined_image_<I>
+ {
+ private:
+ typedef mln_value(I) T_;
+ typedef metal::bool_<( mln_value_card_(T_) != 0 )> is_high_quant_;
+ public:
+ typedef mln_value_kind(T_) kind;
+ typedef mlc_if( is_high_quant_, trait::quant::high, trait::quant::low ) quant;
+ // FIXME: typedef undef value; // scalar, vectorial, structed
+ };
+
+
+ template <typename I>
+ struct default_image_morpher_ : default_image_<I>
+ {
+ private:
+ typedef typename I::delegatee D_;
+ public:
+
+ // value-related => delegation
+ typedef typename image_<D_>::kind kind;
+ typedef typename image_<D_>::quant quant;
+ typedef typename image_<D_>::value value;
+
+ // domain-related => delegation
+ typedef typename image_<D_>::access access;
+ typedef typename image_<D_>::space space;
+ typedef typename image_<D_>::size size;
+ typedef typename image_<D_>::support support;
+
+ // mostly global-related => delegation
+ typedef typename image_<D_>::border border;
+ typedef typename image_<D_>::data data;
+ typedef typename image_<D_>::io io;
+
+ // *but* speed is fast by default (not fastest!)
+ typedef trait::speed::fast speed;
+ };
+
+
+ } // end of namespace mln::trait
+
} // end of namespace mln
Index: mln/trait/kind.hh
--- mln/trait/kind.hh (revision 0)
+++ mln/trait/kind.hh (revision 0)
@@ -0,0 +1,61 @@
+// 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_KIND_HH
+# define MLN_TRAIT_KIND_HH
+
+/*! \file mln/core/trait/kind.hh
+ *
+ * \brief Kind of values in images.
+ */
+
+# include <iostream>
+# include <string>
+
+
+namespace mln
+{
+
+ namespace trait
+ {
+
+ struct kind
+ {
+ struct color { std::string str() const { return "kind::color"; } };
+ struct gray { std::string str() const { return "kind::gray"; } };
+ struct label { std::string str() const { return "kind::label"; } };
+ struct logic : label { std::string str() const { return "kind::logic"; } };
+ struct binary : logic { std::string str() const { return "kind::binary"; } };
+ struct data { std::string str() const { return "kind::data"; } };
+ };
+
+ } // end of namespace mln::trait
+
+} // end of namespace mln
+
+
+#endif // ! MLN_TRAIT_KIND_HH
Index: mln/fun/x2x/translation.hh
Index: mln/fun/x2x/rotation.hh
--- mln/fun/x2x/rotation.hh (revision 1198)
+++ mln/fun/x2x/rotation.hh (working copy)
@@ -118,7 +118,6 @@
rotation<n,C>::inv() const
{
typename rotation::invert res(-alpha_, dir_);
-
return res;
}
Index: mln/core/macros.hh
--- mln/core/macros.hh (revision 1198)
+++ mln/core/macros.hh (working copy)
@@ -160,9 +160,6 @@
# define mln_value(T) typename T::value
# define mln_value_(T) T::value
-/// Shortcut to the kind of values for an image with type \c I.
-# define mln_value_kind(I) typename mln::value::props< mln_value(I) >::kind
-
/// Shortcut to test if the values of an image with type \c I are lowly quantifized.
# define mln_is_value_lowq(I) mln_is_lowq( mln_value(I) )
Index: mln/core/point.hh
--- mln/core/point.hh (revision 1198)
+++ mln/core/point.hh (working copy)
@@ -48,6 +48,20 @@
template <typename M, typename C> struct dpoint_;
+ namespace internal
+ {
+
+ template <typename M, typename C>
+ struct point_to_
+ {
+ typedef metal::vec<M::dim, C> metal_vec;
+ typedef h_vec<M::dim, C> h_vec;
+ };
+
+ } // end of namespace mln::internal
+
+
+
/*! \brief Generic point class.
*
* Parameters are \c n the dimension of the space and \c C the
@@ -107,10 +121,10 @@
typedef metal::vec<M::dim, C> vec_t;
/// Hook to coordinates.
- operator metal::vec<M::dim, C>() const;
+ operator typename internal::point_to_<M, C>::metal_vec () const;
/// Hook to homogene coordinate.
- operator h_vec<M::dim, C>() const;
+ operator typename internal::point_to_<M, C>::h_vec () const;
protected:
metal::vec<M::dim, C> coord_;
@@ -172,13 +186,13 @@
}
template <typename M, typename C>
- point_<M,C>::operator metal::vec<M::dim, C>() const
+ point_<M,C>::operator typename internal::point_to_<M, C>::metal_vec () const
{
return coord_;
}
template <typename M, typename C>
- point_<M,C>::operator h_vec<M::dim, C>() const
+ point_<M,C>::operator typename internal::point_to_<M, C>::h_vec () const
{
return coord_;
}
Index: mln/core/image2d_b.hh
--- mln/core/image2d_b.hh (revision 1198)
+++ mln/core/image2d_b.hh (working copy)
@@ -208,6 +208,25 @@
void init_(tag::image_t, mln::image2d_b<T>& target, const J& model);
+ namespace trait
+ {
+
+ template <typename T>
+ struct image_< image2d_b<T> > : default_image_< image2d_b<T> >
+ {
+ typedef trait::access::random access;
+ typedef trait::space::two_d space;
+ typedef trait::size::regular size;
+ typedef trait::support::aligned support;
+
+ typedef trait::border::stored border;
+ typedef trait::data::linear data;
+ typedef trait::io::read_write io;
+ typedef trait::speed::fastest speed;
+ };
+
+ } // end of namespace mln::trait
+
# ifndef MLN_INCLUDE_ONLY
Index: mln/core/sub_image.hh
--- mln/core/sub_image.hh (revision 1198)
+++ mln/core/sub_image.hh (working copy)
@@ -95,6 +95,26 @@
void init_(tag::image_t, sub_image<I,S>& target, const J& model);
+ namespace trait
+ {
+
+ template <typename I, typename S>
+ struct image_< sub_image<I,S> > : default_image_morpher_< sub_image<I,S> >
+ {
+ private:
+ typedef mln_trait_image_data(I) I_data_;
+ typedef mlc_equal(I_data_, trait::data::linear) I_data_are_linear_;
+ public:
+
+ typedef trait::border::none border; // no more accessible border
+
+ typedef mlc_if( I_data_are_linear_,
+ trait::data::stored, // if linear then just stored
+ I_data_ ) data; // otherwise like I
+ };
+
+ } // end of namespace mln::trait
+
# ifndef MLN_INCLUDE_ONLY
Index: mln/core/concept/image.hh
--- mln/core/concept/image.hh (revision 1198)
+++ mln/core/concept/image.hh (working copy)
@@ -37,6 +37,7 @@
# include <mln/core/trait/all.hh> // FIXME: Move out of core!
# include <mln/trait/concrete.hh> // FIXME: Should be in all.hh!
+# include <mln/trait/images.hh>
# include <mln/metal/is_a.hh>
# include <mln/tag/init.hh>
Index: mln/metal/mat.hh
--- mln/metal/mat.hh (revision 1198)
+++ mln/metal/mat.hh (working copy)
@@ -75,16 +75,42 @@
T data_[n][m];
};
+ }
+
+
+ namespace trait
+ {
+
+ template <typename L, typename R>
+ struct mult;
+
+
+ template <unsigned n, unsigned o, typename T,
+ unsigned m, typename U>
+ struct mult< metal::mat<n,o,T>, metal::mat<o,m,U> >
+ {
+ typedef metal::mat< n, m, mlc_bin_arith(T,U) > ret;
+ };
+
+ template <unsigned n, unsigned m, typename T,
+ typename U>
+ struct mult< metal::mat<n,m,T>, U >
+ {
+ typedef metal::mat< n, m, mlc_bin_arith(T,U) > ret;
+ };
+
+ }
+
+
+ namespace metal
+ {
+
// eq
template <unsigned n, unsigned m, typename T, typename U>
bool
operator=(const mat<n,m,T>& lhs, const mat<n,m,U>& rhs);
- template <unsigned n, unsigned m, typename T, typename U>
- bool
- operator!=(const mat<n,m,T>& lhs, const mat<n,m,U>& rhs);
-
// +
template <unsigned n, unsigned m, typename T, typename U>
@@ -103,40 +129,46 @@
template <unsigned n, unsigned m, typename T, typename U>
mat<n,m,mlc_bin_arith(T,U)>
- operator-(mat<n,m,T>& lhs, const mat<n,m,U>& rhs);
+ operator-(const mat<n,m,T>& lhs, const mat<n,m,U>& rhs);
template <unsigned n, unsigned m, typename T>
mat<n,m,T>
operator-(const mat<n,m,T>& lhs);
- // *
-
- template <unsigned n, unsigned m, unsigned o, typename T, typename U>
- mat<n,m,T>&
- operator*=(mat<n,o,T>& lhs, mat<o,m,U>& rhs);
+ // Operator *.
- template <unsigned n, unsigned m, unsigned o, typename T, typename U>
+ template <unsigned n, unsigned o, typename T,
+ unsigned m, typename U>
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,mlc_bin_arith(T,U)>
+ operator*(const mat<n,m,T>& lhs, const U& rhs);
+
+ // *+
+ template <unsigned n, unsigned m, unsigned o, typename T, typename U>
+ mat<n,m,T>&
+ operator*=(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& rhs);
+ // Operator /.
+
template <unsigned n, unsigned m, typename T, typename U>
mat<n,m,mlc_bin_arith(T,U)>
- operator*(const U& scalar, mat<n,m,T>& lhs);
+ operator/(const mat<n,m,T>& lhs, const U& scalar);
- // /
+ // /
template <unsigned n, unsigned m, typename T, typename U>
- mat<n,m,T>
+ 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)>
- operator/(mat<n,m,T>& lhs, const U& scalar);
-
// <<
template <unsigned n, unsigned m, typename T>
@@ -218,6 +250,7 @@
return n * m;
}
+
// eq
template <unsigned n, unsigned m, typename T, typename U>
@@ -231,14 +264,7 @@
return true;
}
- template <unsigned n, unsigned m, typename T, typename U>
- bool
- operator!=(const mat<n,m,T>& lhs, const mat<n,m,U>& rhs)
- {
- return not (lhs = rhs);
- }
-
- // +
+ // +
template <unsigned n, unsigned m, typename T, typename U>
mat<n,m,T>&
@@ -249,9 +275,12 @@
lhs(i, j) += rhs(i, j);
return lhs;
}
+
+ // Operator +.
+
template <unsigned n, unsigned m, typename T, typename U>
mat<n,m,mlc_bin_arith(T,U)>
- operator+(mat<n,m,T>& lhs, const mat<n,m,U>& rhs)
+ operator+(const mat<n,m,T>& lhs, const mat<n,m,U>& rhs)
{
mat<n,m,mlc_bin_arith(T,U)> tmp;
for (unsigned i = 0; i < n; ++i)
@@ -260,7 +289,7 @@
return tmp;
}
- // -
+ // -
template <unsigned n, unsigned m, typename T, typename U>
mat<n,m,T>&
@@ -271,9 +300,12 @@
lhs(i, j) -= rhs(i, j);
return lhs;
}
+
+ // Operators -.
+
template <unsigned n, unsigned m, typename T, typename U>
mat<n,m,mlc_bin_arith(T,U)>
- operator-(mat<n,m,T>& lhs, const mat<n,m,U>& rhs)
+ operator-(const mat<n,m,T>& lhs, const mat<n,m,U>& rhs)
{
mat<n,m,mlc_bin_arith(T,U)> tmp;
for (unsigned i = 0; i < n; ++i)
@@ -284,12 +316,12 @@
template <unsigned n, unsigned m, typename T>
mat<n,m,T>
- operator-(const mat<n,m,T>& lhs)
+ operator-(const mat<n,m,T>& rhs)
{
mat<n,m,T> tmp;
for (unsigned i = 0; i < n; ++i)
for (unsigned j = 0; i < m; ++i)
- tmp(i, j) = - lhs(i, j);
+ tmp(i, j) = - rhs(i, j);
return tmp;
}
@@ -297,9 +329,9 @@
template <unsigned n, unsigned m, unsigned o, typename T, typename U>
mat<n,m,T>&
- operator*=(mat<n,o,T>& lhs, mat<o,m,U>& rhs)
+ operator*=(mat<n,o,T>& lhs, const mat<o,m,U>& rhs)
{
- lhs = lhs * rhs;
+ lhs = lhs * rhs; // FIXME: OK?
return lhs;
}
@@ -315,12 +347,10 @@
// Operators *.
- namespace internal
- {
-
- template <unsigned n, unsigned m, unsigned o, typename T, typename U>
+ template <unsigned n, unsigned o, typename T,
+ unsigned m, typename U>
mat<n,m,mlc_bin_arith(T,U)>
- multiply_(const mat<n,o,T>& lhs, const mat<o,m,U>& rhs)
+ operator*(const mat<n,o,T>& lhs, const mat<o,m,U>& rhs)
{
mat<n,m,mlc_bin_arith(T,U)> tmp;
for (unsigned i = 0; i < n; ++i)
@@ -336,7 +366,7 @@
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)
+ operator*(const mat<n,m,T>& lhs, const U& rhs)
{
mat<n,m,mlc_bin_arith(T,U)> tmp;
for (unsigned i = 0; i < n; ++i)
@@ -345,20 +375,10 @@
return tmp;
}
- } // 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)
- {
- return internal::multiply_(lhs, rhs);
- }
-
// /
template <unsigned n, unsigned m, typename T, typename U>
- mat<n,m,T>
+ mat<n,m,T>&
operator/=(mat<n,m,T>& lhs, const U& scalar)
{
for (unsigned i = 0; i < n; ++i)
@@ -367,9 +387,11 @@
return lhs;
}
+ // Operator /.
+
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& scalar)
+ operator/(const mat<n,m,T>& lhs, const U& scalar)
{
mat<n,m,mlc_bin_arith(T,U)> tmp;
for (unsigned i = 0; i < n; ++i)
Index: mln/metal/bool.hh
--- mln/metal/bool.hh (revision 1198)
+++ mln/metal/bool.hh (working copy)
@@ -55,6 +55,7 @@
{
typedef true_ type;
static const bool value = true;
+ enum { to_bool = true };
};
template <>
@@ -62,6 +63,7 @@
{
typedef false_ type;
static const bool value = false;
+ enum { to_bool = false };
};
Index: mln/metal/if.hh
--- mln/metal/if.hh (revision 1198)
+++ mln/metal/if.hh (working copy)
@@ -71,7 +71,7 @@
* FIXME: Doc!
*/
template <typename Cond, typename Then, typename Else>
- struct if_ : internal::helper_if_< Cond::value, Then, Else >
+ struct if_ : internal::helper_if_< Cond::to_bool, Then, Else >
{
// ret is inherited.
};
Index: mln/metal/binary_arith_trait.hh
--- mln/metal/binary_arith_trait.hh (revision 1198)
+++ mln/metal/binary_arith_trait.hh (working copy)
@@ -43,6 +43,12 @@
struct binary_arith_trait;
+ template <typename T>
+ struct binary_arith_trait< T, T >
+ {
+ typedef T ret;
+ };
+
template <>
struct binary_arith_trait<int, float>
{
Index: mln/morpho/min.hh
--- mln/morpho/min.hh (revision 1198)
+++ mln/morpho/min.hh (working copy)
@@ -60,7 +60,7 @@
{
template <typename I, typename J, typename O>
- void min_(value::binary_kind, // binary => morphology on sets
+ void min_(trait::kind::logic, // binary => morphology on sets
const Image<I>& lhs, const Image<J>& rhs,
Image<O>& output)
{
@@ -78,7 +78,7 @@
// in place
template <typename I, typename J>
- void min_inplace_(value::binary_kind, // binary => morphology on sets
+ void min_inplace_(trait::kind::logic, // binary => morphology on sets
Image<I>& lhs, const Image<J>& rhs)
{
return logical::and_inplace(lhs, rhs);
@@ -101,14 +101,14 @@
{
mln_precondition(exact(rhs).domain() = exact(lhs).domain());
mln_precondition(exact(output).domain() = exact(lhs).domain());
- impl::min_(mln_value_kind(I)(), exact(lhs), exact(rhs), output);
+ impl::min_(mln_value_kind(mln_value(I))(), exact(lhs), exact(rhs), output);
}
template <typename I, typename J>
void min_inplace(Image<I>& lhs, const Image<J>& rhs)
{
mln_precondition(exact(rhs).domain() = exact(lhs).domain());
- impl::min_inplace_(mln_value_kind(I)(), exact(lhs), exact(rhs));
+ impl::min_inplace_(mln_value_kind(mln_value(I))(), exact(lhs), exact(rhs));
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/morpho/plus.hh
--- mln/morpho/plus.hh (revision 1198)
+++ mln/morpho/plus.hh (working copy)
@@ -60,7 +60,7 @@
{
template <typename I, typename J, typename O>
- void plus_(value::binary_kind, // binary => morphology on sets
+ void plus_(trait::kind::logic, // binary => morphology on sets
const Image<I>& lhs, const Image<J>& rhs,
Image<O>& output)
{
@@ -85,7 +85,7 @@
{
mln_precondition(exact(rhs).domain() = exact(lhs).domain());
mln_precondition(exact(output).domain() = exact(lhs).domain());
- impl::plus_(mln_value_kind(I)(), exact(lhs), exact(rhs), output);
+ impl::plus_(mln_value_kind(mln_value(I))(), exact(lhs), exact(rhs), output);
}
template <typename I, typename J>
Index: mln/morpho/minus.hh
--- mln/morpho/minus.hh (revision 1198)
+++ mln/morpho/minus.hh (working copy)
@@ -60,7 +60,7 @@
{
template <typename I, typename J, typename O>
- void minus_(value::binary_kind, // binary => morphology on sets
+ void minus_(trait::kind::logic, // binary => morphology on sets
const Image<I>& lhs, const Image<J>& rhs,
Image<O>& output)
{
@@ -85,7 +85,7 @@
{
mln_precondition(exact(rhs).domain() = exact(lhs).domain());
mln_precondition(exact(output).domain() = exact(lhs).domain());
- impl::minus_(mln_value_kind(I)(), exact(lhs), exact(rhs), output);
+ impl::minus_(mln_value_kind(mln_value(I))(), exact(lhs), exact(rhs), output);
}
template <typename I, typename J>
Index: mln/morpho/complementation.hh
--- mln/morpho/complementation.hh (revision 1198)
+++ mln/morpho/complementation.hh (working copy)
@@ -61,7 +61,7 @@
{
template <typename I, typename O>
- void complementation_(value::binary_kind, // binary => morphology on sets
+ void complementation_(trait::kind::logic, // binary => morphology on sets
const Image<I>& input,
Image<O>& output)
{
@@ -85,7 +85,7 @@
void complementation(const Image<I>& input, Image<O>& output)
{
mln_precondition(exact(output).domain() = exact(input).domain());
- impl::complementation_(mln_value_kind(I)(), exact(input), output);
+ impl::complementation_(mln_value_kind(mln_value(I))(), exact(input), output);
}
template <typename I>
Index: mln/morpho/dilation.hh
--- mln/morpho/dilation.hh (revision 1198)
+++ mln/morpho/dilation.hh (working copy)
@@ -112,7 +112,7 @@
// Stage 2: dispatch w.r.t. the value kind.
template <typename I, typename W, typename O>
- void dilation_wrt_value(value::binary_kind, // binary => morphology on sets
+ void dilation_wrt_value(trait::kind::logic, // binary => morphology on sets
const Image<I>& input, const Window<W>& win, Image<O>& output)
{
return impl::dilation_on_set(exact(input), exact(win), output);
@@ -134,7 +134,7 @@
template <typename I, typename W, typename O>
void dilation_wrt_win(const Image<I>& input, const Window<W>& win, Image<O>& output)
{
- dilation_wrt_value(mln_value_kind(I)(), exact(input), exact(win), output);
+ dilation_wrt_value(mln_value_kind(mln_value(I))(), exact(input), exact(win), output);
// |
// --> call stage 2: dispatch w.r.t. the value kind
}
Index: mln/morpho/erosion.hh
--- mln/morpho/erosion.hh (revision 1198)
+++ mln/morpho/erosion.hh (working copy)
@@ -115,7 +115,7 @@
// Stage 2: dispatch w.r.t. the value kind.
template <typename I, typename W, typename O>
- void erosion_wrt_value(value::binary_kind, // binary => morphology on sets
+ void erosion_wrt_value(trait::kind::logic, // binary => morphology on sets
const Image<I>& input, const Window<W>& win, Image<O>& output)
{
return impl::erosion_on_set(exact(input), exact(win), output);
@@ -137,7 +137,7 @@
template <typename I, typename W, typename O>
void erosion_wrt_win(const Image<I>& input, const Window<W>& win, Image<O>& output)
{
- erosion_wrt_value(mln_value_kind(I)(), exact(input), exact(win), output);
+ erosion_wrt_value(mln_value_kind(mln_value(I))(), exact(input), exact(win), output);
// |
// --> call stage 2: dispatch w.r.t. the value kind
}
Index: mln/morpho/hit_or_miss.hh
--- mln/morpho/hit_or_miss.hh (revision 1198)
+++ mln/morpho/hit_or_miss.hh (working copy)
@@ -115,7 +115,7 @@
// On sets.
template <typename I, typename Wh, typename Wm, typename O>
- void hit_or_miss_(value::binary_kind, // binary => morphology on sets
+ void hit_or_miss_(trait::kind::logic, // binary => morphology on sets
const Image<I>& input,
const Window<Wh>& win_hit, const Window<Wm>& win_miss,
Image<O>& output)
@@ -190,7 +190,7 @@
Image<O>& output)
{
impl::hit_or_miss_preconditions_(input, win_hit, win_miss, output);
- impl::hit_or_miss_(mln_value_kind(I)(), input, win_hit, win_miss, output);
+ impl::hit_or_miss_(mln_value_kind(mln_value(I))(), input, win_hit, win_miss, output);
}
template <typename I, typename Wh, typename Wm, typename O>
Index: mln/value/int_u_sat.hh
--- mln/value/int_u_sat.hh (revision 1198)
+++ mln/value/int_u_sat.hh (working copy)
@@ -102,7 +102,7 @@
static const int_u_sat<n> min() { return 0; }
static const int_u_sat<n> max() { return card_ - 1; }
static const unsigned nbits = n;
- typedef data_kind kind;
+ typedef trait::kind::data kind;
typedef float sum;
};
Index: mln/value/props.hh
--- mln/value/props.hh (revision 1198)
+++ mln/value/props.hh (working copy)
@@ -39,7 +39,8 @@
# include <cfloat>
# include <mln/core/macros.hh>
-# include <mln/value/kind.hh>
+# include <mln/trait/kind.hh>
+
# include <mln/metal/bool.hh>
# include <mln/metal/vec.hh>
# include <mln/metal/mat.hh>
@@ -57,9 +58,11 @@
/// Get the number of values for value type \c T.
# define mln_card_(T) mln::value::props< T >::card_
+# define mln_value_card_(T) mln::value::props< T >::card_ // Better than the above name.
+
/// Get the kind of value type \c T.
-# define mln_kind(T) typename mln::value::props< T >::kind
+# define mln_value_kind(T) typename mln::value::props< T >::kind
/// Test is the value type \c T is low quantized.
@@ -84,7 +87,7 @@
template <typename T>
struct props
{
- typedef data_kind kind;
+ typedef trait::kind::data kind;
static const std::size_t card_ = 0;
};
@@ -116,7 +119,7 @@
static const bool min() { return false; }
static const bool max() { return true; }
static const std::size_t card_ = 2;
- typedef binary_kind kind;
+ typedef trait::kind::binary kind;
};
@@ -128,7 +131,7 @@
static const unsigned char min() { return 0; }
static const unsigned char max() { return 255; }
static const std::size_t card_ = 256;
- typedef data_kind kind;
+ typedef trait::kind::data kind;
typedef float sum;
};
@@ -138,7 +141,7 @@
static const signed char min() { return -128; }
static const signed char max() { return 127; }
static const std::size_t card_ = 256;
- typedef data_kind kind;
+ typedef trait::kind::data kind;
typedef float sum;
};
@@ -148,7 +151,7 @@
static const unsigned short min() { return 0; }
static const unsigned short max() { return 65535; }
static const std::size_t card_ = 65536;
- typedef data_kind kind;
+ typedef trait::kind::data kind;
typedef float sum;
};
@@ -158,7 +161,7 @@
static const signed short min() { return -32768; }
static const signed short max() { return 32767; }
static const std::size_t card_ = 65536;
- typedef data_kind kind;
+ typedef trait::kind::data kind;
typedef float sum;
};
@@ -167,7 +170,7 @@
{
static const unsigned int min() { return 0; }
static const unsigned int max() { return UINT_MAX; }
- typedef data_kind kind;
+ typedef trait::kind::data kind;
static const std::size_t card_ = 0;
typedef float sum;
};
@@ -177,7 +180,7 @@
{
static const signed int min() { return INT_MIN; }
static const signed int max() { return INT_MAX; }
- typedef data_kind kind;
+ typedef trait::kind::data kind;
static const std::size_t card_ = 0;
typedef float sum;
};
@@ -187,7 +190,7 @@
{
static const unsigned long int min() { return 0; }
static const unsigned long int max() { return ULONG_MAX; }
- typedef data_kind kind;
+ typedef trait::kind::data kind;
static const std::size_t card_ = 0;
typedef float sum;
};
@@ -197,7 +200,7 @@
{
static const signed long int min() { return LONG_MIN; }
static const signed long int max() { return LONG_MAX; }
- typedef data_kind kind;
+ typedef trait::kind::data kind;
static const std::size_t card_ = 0;
typedef float sum;
};
@@ -211,7 +214,7 @@
static const float min() { return FLT_MIN; }
static const float max() { return FLT_MAX; }
static const float epsilon() { return 0.00001f; }
- typedef data_kind kind;
+ typedef trait::kind::data kind;
static const std::size_t card_ = 0;
typedef float sum;
};
@@ -222,7 +225,7 @@
static const double min() { return DBL_MIN; }
static const double max() { return DBL_MAX; }
static const double epsilon() { return 0.0000001; }
- typedef data_kind kind;
+ typedef trait::kind::data kind;
static const std::size_t card_ = 0;
typedef double sum;
};
@@ -234,7 +237,7 @@
{
static const metal::vec<n,T> min() { return make::vec<n>(mln_min(T)); }
static const metal::vec<n,T> max() { return make::vec<n>(mln_max(T)); }
- typedef data_kind kind;
+ typedef trait::kind::data kind;
static const std::size_t card_ = n * mln_card_(T);
typedef mlc_bin_arith(float,T) sum;
};
@@ -244,7 +247,7 @@
{
static const metal::mat<n,m,T> min() { return make::mat<n,m>(mln_min(T)); }
static const metal::mat<n,m,T> max() { return make::mat<n,m>(mln_max(T)); }
- typedef data_kind kind;
+ typedef trait::kind::data kind;
static const std::size_t card_ = n * m * mln_card_(T);
typedef mlc_bin_arith(float,T) sum;
};
Index: mln/value/rgb.hh
--- mln/value/rgb.hh (revision 1198)
+++ mln/value/rgb.hh (working copy)
@@ -133,7 +133,7 @@
static const std::size_t card_ = metal::pow<2, nbits>::value;
static const rgb<n> max() { rgb<n> c(props< int_u<n> >::max); return c; }
static const rgb<n> min() { const rgb<n> c(props< int_u<n> >::min()); return c; }
- typedef color_kind kind;
+ typedef trait::kind::color kind;
typedef float_x3_t sum;
typedef uchar_x3_t interop;
};
Index: mln/value/rgb8_non_templated.hh
--- mln/value/rgb8_non_templated.hh (revision 1198)
+++ mln/value/rgb8_non_templated.hh (working copy)
@@ -106,7 +106,7 @@
{
static const unsigned nbits = 24;
static const std::size_t card_ = metal::pow<2, nbits>::value;
- typedef color_kind kind;
+ typedef trait::kind::color kind;
typedef float_x3_t sum;
typedef uchar_x3_t interop;
};
Index: mln/value/int_s.hh
--- mln/value/int_s.hh (revision 1198)
+++ mln/value/int_s.hh (working copy)
@@ -105,7 +105,7 @@
static const int_s<n> max() { return metal::pow<2, n-1>::value - 1; }
static const int_s<n> min() { return - max(); }
static const unsigned nbits = n;
- typedef data_kind kind;
+ typedef trait::kind::data kind;
typedef float sum;
};
Index: mln/value/int_u.hh
--- mln/value/int_u.hh (revision 1198)
+++ mln/value/int_u.hh (working copy)
@@ -101,7 +101,7 @@
static const int_u<n> min() { return 0; }
static const int_u<n> max() { return card_ - 1; }
static const unsigned nbits = n;
- typedef data_kind kind;
+ typedef trait::kind::data kind;
typedef float sum;
typedef int interop;
};
Index: mln/value/label.hh
--- mln/value/label.hh (revision 1198)
+++ mln/value/label.hh (working copy)
@@ -129,7 +129,7 @@
static const label<n> min; // = 0
static const label<n> max; // = card_ - 1
static const unsigned nbits = n;
- typedef label_kind kind;
+ typedef trait::kind::label kind;
};
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-28 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add test for mesh image.
* mesh_image.cc: New test for mesh image.
---
mesh_image.cc | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 96 insertions(+)
Index: trunk/milena/tests/mesh_image.cc
===================================================================
--- trunk/milena/tests/mesh_image.cc (revision 0)
+++ trunk/milena/tests/mesh_image.cc (revision 1198)
@@ -0,0 +1,96 @@
+// 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.
+
+/*! \file tests/mesh_image.cc
+ *
+ * \brief Tests on mln::mesh_image.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/core/point2d.hh>
+#include <mln/debug/println.hh>
+#include <mln/util/graph.hh>
+#include <mln/core/mesh_p.hh>
+#include <mln/core/mesh_psite.hh>
+#include <mln/draw/mesh.hh>
+#include <mln/core/mesh_image.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.consistency ();
+ // 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);
+
+ std::cout << im.domain() << std::endl;
+}
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-28 Simon Nivault <simon.nivault(a)lrde.epita.fr>
Add traits for multiply and promotions.
* mln/core/ops.hh: A + B -> B + A, Idem for *.
* mln/core/trait/mult.hh: New.
* mln/core/trait/promote.hh: New.
---
ops.hh | 43 +++++++++++++++++++
trait/mult.hh | 122 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
trait/promote.hh | 106 +++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 271 insertions(+)
Index: trunk/milena/mln/core/trait/mult.hh
===================================================================
--- trunk/milena/mln/core/trait/mult.hh (revision 0)
+++ trunk/milena/mln/core/trait/mult.hh (revision 1197)
@@ -0,0 +1,122 @@
+// Copyright (C) 2006 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_MULT_HH
+# define MLN_TRAIT_MULT_HH
+
+
+# define mln_mult(T, U) typename mln::trait::mult< T , U >::ret
+
+
+
+namespace mln
+{
+
+ namespace metal
+ {
+
+ template <unsigned n, typename T>
+ class vec;
+
+ template <unsigned n, unsigned m, typename T>
+ class mat;
+
+ } // end of namespace mln::metal
+
+ namespace trait
+ {
+
+ template <typename T, typename U>
+ struct mult;
+
+
+ template <>
+ struct mult<int, float>
+ {
+ typedef float ret;
+ };
+ template <>
+ struct mult<float, int>
+ {
+ typedef float ret;
+ };
+
+ template <>
+ struct mult<int, double>
+ {
+ typedef double ret;
+ };
+ template <>
+ struct mult<double, int>
+ {
+ typedef double ret;
+ };
+
+ template <>
+ struct mult<double, float>
+ {
+ typedef double ret;
+ };
+ template <>
+ struct mult<float, double>
+ {
+ typedef double ret;
+ };
+
+ template <unsigned n, typename T, typename U>
+ struct mult<metal::vec<n, T>, U>
+ {
+ typedef metal::vec<n, mln_mult(T, U)> ret;
+ }
+ template <typename U, unsigned n, typename T>
+ struct mult<U, metal::vec<n, T>>
+ {
+ typedef metal::vec<n, mln_mult(T, U)> ret;
+ }
+
+ template <unsigned n, unsigned m, typename T, typename U>
+ struct mult<metal::mat<n, m, T>, U>
+ {
+ typedef metal::mat<n, m, mln_mult(T, U)> ret;
+ }
+ template <typename U, unsigned n, unsigned m, typename T>
+ struct mult<U, metal::mat<n, m, T>>
+ {
+ typedef metal::mat<n, m, mln_mult(T, U)> ret;
+ }
+
+ template <unsigned n, unsigned o, typename T, unsigned m, typename U>
+ struct mult<metal::mat<n, o, T>, metal::mat<o, m, U> >
+ {
+ typedef metal::mat<n, m, mln_mult(T, U)> ret;
+ };
+
+ } // end of namespace mln::trait
+
+} // end of namespace mln
+
+#endif // ! MLN_TRAIT_MULT_HH
Index: trunk/milena/mln/core/trait/promote.hh
===================================================================
--- trunk/milena/mln/core/trait/promote.hh (revision 0)
+++ trunk/milena/mln/core/trait/promote.hh (revision 1197)
@@ -0,0 +1,106 @@
+// Copyright (C) 2006 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_PROMOTE_HH
+# define MLN_TRAIT_PROMOTE_HH
+
+
+# define mln_promote(T, U) typename mln::trait::promote< T , U >::ret
+
+
+
+namespace mln
+{
+
+ namespace metal
+ {
+
+ template <unsigned n, typename T>
+ class vec;
+
+ template <unsigned n, unsigned m, typename T>
+ class mat;
+
+ } // end of namespace mln::metal
+
+ namespace trait
+ {
+
+ template <typename T, typename U>
+ struct promote;
+
+
+ template <>
+ struct promote<int, float>
+ {
+ typedef float ret;
+ };
+ template <>
+ struct promote<float, int>
+ {
+ typedef float ret;
+ };
+
+ template <>
+ struct promote<int, double>
+ {
+ typedef double ret;
+ };
+ template <>
+ struct promote<double, int>
+ {
+ typedef double ret;
+ };
+
+ template <>
+ struct promote<double, float>
+ {
+ typedef double ret;
+ };
+ template <>
+ struct promote<float, double>
+ {
+ typedef double ret;
+ };
+
+ template <unsigned n, typename T, typename U>
+ struct promote<metal::vec<n, T>, metal::vec<n, U> >
+ {
+ typedef metal::vec<n, mln_promote(T, U)> ret;
+ };
+
+ template <unsigned n, unsigned m, typename T, typename U>
+ struct promote<metal::mat<n, m, T>, metal::mat<n, m, U> >
+ {
+ typedef metal::mat<n, m, mln_promote(T, U)> ret;
+ };
+
+ } // end of namespace mln::trait
+
+} // end of namespace mln
+
+#endif // ! MLN_TRAIT_PROMOTE_HH
Index: trunk/milena/mln/core/ops.hh
===================================================================
--- trunk/milena/mln/core/ops.hh (revision 1196)
+++ trunk/milena/mln/core/ops.hh (revision 1197)
@@ -94,6 +94,34 @@
bool operator<=(const Object<O1>& lhs, const Object<O2>& rhs);
+ // Operator +.
+
+ // FIXME: Doc!
+ template <typename O>
+ mlc_bin_arith(int, O)
+ operator+(int lhs, const Object<O>& rhs)
+ {
+ return exact(rhs) + lhs;
+ }
+
+ // FIXME: Doc!
+ template <typename O>
+ mlc_bin_arith(float, O)
+ operator+(float lhs, const Object<O>& rhs)
+ {
+ return exact(rhs) + lhs;
+ }
+
+ // FIXME: Doc!
+ template <typename O>
+ mlc_bin_arith(double, O)
+ operator+(double lhs, const Object<O>& rhs)
+ {
+ return exact(rhs) + lhs;
+ }
+
+ // Operator *.
+
// FIXME: Doc!
template <typename O>
mlc_bin_arith(int, O)
@@ -102,6 +130,21 @@
return exact(rhs) * lhs;
}
+ // FIXME: Doc!
+ template <typename O>
+ mlc_bin_arith(float, O)
+ operator*(float lhs, const Object<O>& rhs)
+ {
+ return exact(rhs) * lhs;
+ }
+
+ // FIXME: Doc!
+ template <typename O>
+ mlc_bin_arith(double, O)
+ operator*(double lhs, const Object<O>& rhs)
+ {
+ return exact(rhs) * lhs;
+ }
# ifndef MLN_INCLUDE_ONLY
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-28 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add mesh.hh in mln/draw.
* mesh.hh: Draw a mesh_image into an image.
---
mesh.hh | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 100 insertions(+)
Index: trunk/milena/mln/draw/mesh.hh
===================================================================
--- trunk/milena/mln/draw/mesh.hh (revision 0)
+++ trunk/milena/mln/draw/mesh.hh (revision 1196)
@@ -0,0 +1,100 @@
+// 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_DRAW_MESH_HH
+# define MLN_DRAW_MESH_HH
+
+/*! \file mln/draw/mesh.hh
+ *
+ * \brief Draw an image of type mesh_image into anothor kind of image.
+ *
+ */
+
+# include <mln/pw/image.hh>
+# include <mln/level/fill.hh>
+# include <mln/draw/line.hh>
+# include <mln/core/mesh_p.hh>
+# include <mln/core/mesh_image.hh>
+
+namespace mln
+{
+ namespace draw
+ {
+
+ template <typename I, typename P>
+ void
+ mesh(Image<I>& ima, const mesh_p<P>& m,
+ mln_value(I) node_v,
+ mln_value(I) link_v);
+
+ template <typename I, typename P, typename V>
+ void
+ mesh(Image<I>& ima, const mesh_image<P, V>& mesh);
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I, typename P>
+ void
+ mesh(Image<I>& ima, const mesh_p<P>& m,
+ mln_value(I) node_v,
+ mln_value(I) link_v)
+ {
+ 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],
+ link_v);
+
+ for (unsigned i = 0; i < m.gr_.nb_node_; ++i)
+ 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 < mesh.domain().gr_.nb_link_; ++i)
+ line (exact(ima),
+ mesh.access_location_link_node1 (i),
+ mesh.access_location_link_node2 (i),
+ 1);
+
+ for (unsigned i = 0; i < mesh.domain().gr_.nb_node_; ++i)
+ exact(ima)(mesh.domain().loc_[i]) = mesh.data_values ()[i];
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of draw
+
+} // end of mln
+
+#endif // MLN_MESH_PSITE_HH
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-28 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add mesh_image in mln/core.
* mesh_image.hh: New class of image.
* mesh_p.hh: New.
* mesh_p_piter.hh: New.
* mesh_psite.hh: New.
---
mesh_image.hh | 177 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
mesh_p.hh | 119 +++++++++++++++++++++++++++++++++++++
mesh_p_piter.hh | 158 +++++++++++++++++++++++++++++++++++++++++++++++++
mesh_psite.hh | 101 +++++++++++++++++++++++++++++++
4 files changed, 555 insertions(+)
Index: trunk/milena/mln/core/mesh_psite.hh
===================================================================
--- trunk/milena/mln/core/mesh_psite.hh (revision 0)
+++ trunk/milena/mln/core/mesh_psite.hh (revision 1195)
@@ -0,0 +1,101 @@
+// 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.
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_MESH_PSITE_HH
+# define MLN_MESH_PSITE_HH
+
+/*! \file mln/core/mesh_p.hh
+ *
+ * \brief Definition of mln::mesh_psite.
+ */
+
+namespace mln
+{
+
+ template<typename P> class mesh_p;
+
+ template<typename P>
+ struct mesh_psite : public Point_Site< mesh_psite<P> >
+ {
+ typedef mln_mesh(P) mesh;
+ enum { dim = P::dim };
+ typedef P point;
+ typedef mln_dpoint(P) dpoint;
+ typedef mln_coord(P) coord;
+
+ mesh_psite(unsigned i, mesh_p<P>* m_ptr);
+ P to_point() const;
+ operator P() const;
+ const point* pointer_() const;
+ coord operator[](unsigned i) const;
+
+ unsigned i_;
+ mesh_p<P>* m_ptr_;
+ };
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template<typename P>
+ mesh_psite<P>::mesh_psite(unsigned i, mesh_p<P>* m_ptr)
+ : i_(i) ,
+ m_ptr_(m_ptr)
+ {
+ }
+
+ template<typename P>
+ P
+ mesh_psite<P>::to_point() const
+ {
+ return m_ptr_->loc_[i_];
+ }
+
+ template<typename P>
+ mesh_psite<P>::operator P() const
+ {
+ return m_ptr_->loc_[i_];
+ }
+
+ template<typename P>
+ const P*
+ mesh_psite<P>::pointer_() const
+ {
+ return 0;
+ }
+
+ template<typename P>
+ mln_coord(P)
+ mesh_psite<P>::operator[](unsigned i) const
+ {
+ return to_point()[i];
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
+} // end of mln
+
+#endif // MLN_MESH_PSITE_HH
Index: trunk/milena/mln/core/mesh_p.hh
===================================================================
--- trunk/milena/mln/core/mesh_p.hh (revision 0)
+++ trunk/milena/mln/core/mesh_p.hh (revision 1195)
@@ -0,0 +1,119 @@
+// 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.
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_MESH_P_HH
+# define MLN_MESH_P_HH
+
+# include <mln/core/concept/point.hh>
+# include <mln/core/internal/point_set_base.hh>
+# include <mln/accu/bbox.hh>
+# include <mln/util/graph.hh>
+# include <mln/core/mesh_psite.hh>
+# include <mln/core/mesh_p_piter.hh>
+
+/*! \file mln/core/mesh_p.hh
+ *
+ * \brief Definition of mln::mesh_p.
+ */
+
+namespace mln
+{
+
+ template<typename P> class mesh_p_piter_;
+
+ template<typename P>
+ struct mesh_p : public internal::point_set_base_< P, mesh_p<P> >
+ {
+ mesh_p (util::graph<void>& gr,
+ std::vector<P>& loc);
+
+ /// Point_Site associated type.
+ typedef mesh_psite<P> psite;
+
+ /// Forward Point_Iterator associated type.
+ typedef mesh_p_piter_<P> fwd_piter;
+
+ /// Backward Point_Iterator associated type.
+ typedef mesh_p_piter_<P> bkd_piter; // FIXME
+
+ std::size_t npoints() const;
+
+ /// Give the exact bounding box.
+ const box_<P>& bbox() const;
+
+ bool has(const psite& p) const;
+
+ util::graph<void> gr_;
+ std::vector<P> loc_;
+ box_<P> bb_;
+ };
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template<typename P>
+ mesh_p<P>::mesh_p (util::graph<void>& gr,
+ std::vector<P>& loc)
+ : gr_ (gr),
+ loc_ (loc)
+ {
+ accu::bbox<P> a;
+ for (unsigned i = 0; i < loc.size(); ++i)
+ a.take(loc[i]);
+ bb_ = a.to_result();
+ }
+
+ template<typename P>
+ std::size_t
+ mesh_p<P>::npoints() const
+ {
+ return this->gr_.nb_node_;
+ }
+
+ template<typename P>
+ const box_<P>&
+ mesh_p<P>::bbox() const
+ {
+ return bb_;
+ }
+
+ template<typename P>
+ bool
+ mesh_p<P>::has(const psite& p) const
+ {
+ for (unsigned i = 0; i < loc_.size(); ++i)
+ if (loc_[i] == p)
+ return true;
+ return false;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of mln
+
+
+#endif // MLN_MESH_P_HH
Index: trunk/milena/mln/core/mesh_p_piter.hh
===================================================================
--- trunk/milena/mln/core/mesh_p_piter.hh (revision 0)
+++ trunk/milena/mln/core/mesh_p_piter.hh (revision 1195)
@@ -0,0 +1,158 @@
+// 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.
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_CORE_MESH_P_PITER_HH
+# define MLN_CORE_MESH_P_PITER_HH
+
+# include <mln/core/internal/point_iterator_base.hh>
+# include <mln/core/mesh_p.hh>
+
+/*! \file mln/core/mesh_psite.hh
+ *
+ * \brief Definition of a graph.
+ */
+
+namespace mln
+{
+
+ template<typename P> class mesh_p_piter_;
+
+ 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);
+
+ /// Give a hook to the point address.
+ const P* pointer_() const;
+
+ /// 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_();
+
+ /// Convert the iterator into a point.
+ operator P() const;
+
+ protected:
+ const std::vector<P>& loc_;
+ unsigned i_;
+ P p_;
+ };
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template<typename P>
+ mesh_p_piter_<P>::mesh_p_piter_(const mesh_p<P>& s)
+ : loc_(s.loc_)
+ {
+ invalidate();
+ }
+
+
+ template<typename P>
+ const P*
+ mesh_p_piter_<P>::pointer_() const
+ {
+ return & p_;
+ }
+
+
+ template<typename P>
+ mln_coord(P)
+ mesh_p_piter_<P>::operator[](unsigned i) const
+ {
+ return p_[i];
+ }
+
+
+ template<typename P>
+ bool
+ mesh_p_piter_<P>::is_valid() const
+ {
+ return i_ != loc_.size();
+ }
+
+
+ template<typename P>
+ void
+ mesh_p_piter_<P>::invalidate()
+ {
+ i_ = loc_.size();
+ }
+
+
+ template<typename P>
+ void
+ mesh_p_piter_<P>::start()
+ {
+ i_ = 0;
+ if (is_valid())
+ p_ = loc_[i_];
+ }
+
+
+ template<typename P>
+ void
+ mesh_p_piter_<P>::next_()
+ {
+ ++i_;
+ if (is_valid())
+ p_ = loc_[i_];
+ }
+
+
+ template<typename P>
+ mesh_p_piter_<P>::operator P() const
+ {
+ mln_precondition(is_valid());
+ return p_;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of mln
+
+
+#endif // MLN_MESH_P_PITER_HH
Index: trunk/milena/mln/core/mesh_image.hh
===================================================================
--- trunk/milena/mln/core/mesh_image.hh (revision 0)
+++ trunk/milena/mln/core/mesh_image.hh (revision 1195)
@@ -0,0 +1,177 @@
+// 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 mesh_image.
+ */
+
+# include <mln/core/internal/image_identity.hh>
+# include <mln/metal/vec.hh>
+# include <mln/core/mesh_p.hh>
+# include <mln/core/mesh_psite.hh>
+# include <vector>
+
+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>& mesh, std::vector<V>& val);
+
+ std::vector<V> val_;
+ mesh_p<P> mesh_;
+ };
+
+ } // end of namespace mln::internal
+
+ /*! \brief FIXME
+ *
+ */
+ template <typename P, typename V>
+ struct mesh_image : public internal::image_primary_< mesh_p<P>, mesh_image<P, V> >
+ {
+
+ typedef mln::internal::image_base_< mesh_p<P>, mesh_image<P, V> > super_;
+
+ /// Value associated type.
+ typedef V value;
+
+ /// Return type of read-write access.
+ typedef V& lvalue;
+
+ /// Return type of read-only access.
+ typedef const V& rvalue;
+
+ /// Value set associated type.
+ typedef mln::value::set<value> vset;
+
+
+ /// Skeleton.
+ typedef mesh_image< tag::psite_<P>, tag::value_<V> > skeleton;
+
+ /// Constructors.
+ mesh_image(mesh_p<P>& mesh, std::vector<V>& val);
+ mesh_image();
+
+ /// Read-only access of pixel value at point site \p p.
+ const V& operator()(const mesh_psite<P>& p) const;
+
+ /// Read-write access of pixel value at point site \p p.
+ 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>& domain() 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),
+ mesh_ (mesh)
+ {
+ }
+
+ } // end of namespace mln::internal
+
+ template <typename P, typename V>
+ mesh_image<P, V>::mesh_image(mesh_p<P>& mesh, std::vector<V>& val)
+ {
+ this->data_ = new internal::data_< mesh_image<P, V> > (mesh, val);
+ }
+
+ template <typename P, typename V>
+ mesh_image<P, V>::mesh_image()
+ {
+ }
+
+ template <typename P, typename V>
+ const V&
+ mesh_image<P, V>::operator()(const mesh_psite<P>& p) const
+ {
+ mln_precondition(p.m_ptr_ == & this->data_->mesh_);
+ mln_precondition(p.i_ < this->data_->val_.size());
+ return this->data_->val_[p.i_];
+ }
+
+ template <typename P, typename V>
+ V&
+ mesh_image<P, V>::operator()(const mesh_psite<P>& p)
+ {
+ mln_precondition(p.m_ptr_ == & this->data_->mesh_);
+ mln_precondition(p.i_ < this->data_->val_.size());
+ return this->data_->val_[p.i_];
+ }
+
+ 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>::domain() const
+ {
+ mln_precondition(this->has_data());
+ return this->data_->mesh_;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_MESH_IMAGE_HH
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-28 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add graph in mln/util.
* graph.hh: New.
---
graph.hh | 182 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 182 insertions(+)
Index: trunk/milena/mln/util/graph.hh
===================================================================
--- trunk/milena/mln/util/graph.hh (revision 0)
+++ trunk/milena/mln/util/graph.hh (revision 1194)
@@ -0,0 +1,182 @@
+// 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.
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_UTIL_GRAPH_HH
+# define MLN_UTIL_GRAPH_HH
+
+# include <mln/core/concept/object.hh>
+# include <cstddef>
+# include <iostream>
+# include <vector>
+
+/*! \file mln/util/graph.hh
+ *
+ * \brief Definition of a graph.
+ */
+
+
+namespace mln
+{
+ namespace util
+ {
+
+ template<typename T>
+ struct s_node
+ {
+ T data;
+ std::vector<unsigned> links;
+ };
+
+ template<>
+ struct s_node<void>
+ {
+ std::vector<unsigned> links;
+ };
+
+ template<typename T>
+ struct s_edge
+ {
+ T data;
+ unsigned node1;
+ unsigned node2;
+ };
+
+ template<>
+ struct s_edge <void>
+ {
+ unsigned node1;
+ unsigned node2;
+ };
+
+ template<typename N, typename E = void>
+ struct graph
+ {
+ graph ();
+
+ void add_node (void);
+ void add_edge (unsigned n1, unsigned n2);
+ void coherence () const;
+ void print_debug () const;
+ unsigned nb_node_;
+ unsigned nb_link_;
+ std::vector<struct s_node<N>*> nodes_;
+ std::vector<struct s_edge<E>*> links_;
+ };
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template<typename N, typename E>
+ graph<N, E>::graph ()
+ : nb_node_ (0),
+ nb_link_ (0),
+ nodes_ (0),
+ links_ (0)
+ {
+ }
+
+ template<typename N, typename E>
+ void
+ graph<N, E>::add_node (void)
+ {
+ struct s_node<N>* n = new struct s_node<N>;
+
+ nodes_.push_back (n);
+ ++nb_node_;
+ }
+
+ template<typename N, typename E>
+ void
+ graph<N, E>::add_edge (unsigned n1, unsigned n2)
+ {
+ mln_precondition(n1 < this->nb_node_);
+ mln_precondition(n2 < this->nb_node_);
+
+ struct s_edge<E>* edge;
+
+ edge = new struct s_edge<E>;
+ edge->node1 = n1;
+ edge->node2 = n2;
+ links_.push_back (edge);
+ ++nb_link_;
+ nodes_[n1]->links.push_back (n2);
+ nodes_[n2]->links.push_back (n1);
+ }
+
+ template<typename N, typename E>
+ void
+ graph<N, E>::coherence () const
+ {
+ mln_precondition(nodes_.size () == this->nb_node_);
+ mln_precondition(links_.size () == this->nb_link_);
+ typename std::vector<struct s_node <N>*>::const_iterator it = nodes_.begin ();
+ for (; it != nodes_.end (); ++it)
+ {
+ typename std::vector<unsigned>::const_iterator it2 = (*it)->links.begin ();
+ for (; it2 != (*it)->links.end (); ++it2)
+ mln_precondition((*it2) < nb_node_);
+ }
+
+ typename std::vector<struct s_edge<E>*>::const_iterator it3 = links_.begin ();
+ for (; it3 != links_.end (); ++it3)
+ {
+ mln_precondition((*it3)->node1 < nb_node_);
+ mln_precondition((*it3)->node2 < nb_node_);
+ }
+ }
+
+ template<typename N, typename E>
+ void
+ graph<N, E>::print_debug () const
+ {
+ std::cout << "nodes :"
+ << std::endl;
+
+ typename std::vector<struct s_node<N>*>::const_iterator it = nodes_.begin ();
+ int i = 0;
+ for (; it != nodes_.end (); ++it, ++i)
+ {
+ std::cout << "node number = "
+ << i
+ << " nbh : ";
+ typename std::vector<unsigned>::const_iterator it2 = (*it)->links.begin ();
+ for (; it2 != (*it)->links.end (); ++it2)
+ {
+ std::cout << (*it2)
+ << " ";
+ }
+ std::cout << std::endl;
+ }
+ std::cout << std::endl;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of util
+
+} // end of mln
+
+#endif // MLN_GRAPH_HH
1
0
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
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-28 Simon Nivault <simon.nivault(a)lrde.epita.fr>
Fix for compiling.
* mln/core/point.hh: Include h_vec.
---
point.hh | 1 +
1 file changed, 1 insertion(+)
Index: trunk/milena/mln/core/point.hh
===================================================================
--- trunk/milena/mln/core/point.hh (revision 1191)
+++ trunk/milena/mln/core/point.hh (revision 1192)
@@ -37,6 +37,7 @@
# include <mln/core/internal/coord_impl.hh>
# include <mln/fun/i2v/all.hh>
# include <mln/metal/vec.hh>
+# include <mln/core/h_vec.hh>
namespace mln
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-28 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Update mesh_image.
* main_mesh_image.cc,
* mesh_image.hh,
* mesh_p.hh,
* mesh_psite.hh: Update.
---
main_mesh_image.cc | 7 ++-----
mesh_image.hh | 4 ++++
mesh_p.hh | 39 ++++++++++++++++++++++++++++++++++++++-
mesh_psite.hh | 11 ++++++-----
4 files changed, 50 insertions(+), 11 deletions(-)
Index: trunk/milena/sandbox/duhamel/main_mesh_image.cc
===================================================================
--- trunk/milena/sandbox/duhamel/main_mesh_image.cc (revision 1190)
+++ trunk/milena/sandbox/duhamel/main_mesh_image.cc (revision 1191)
@@ -45,8 +45,6 @@
mesh_p<point2d> m(g, v);
- draw::mesh (ima, m, 7, 1);
-
std::vector<int> val;
val.push_back (2);
@@ -56,9 +54,8 @@
val.push_back (6);
val.push_back (7);
- mesh_image<point2d, int> im (m, val);
-
- draw::mesh (ima, im);
+ mesh_image<point2d, int> m_ima (m, val);
+ draw::mesh (ima, m_ima);
debug::println (ima);
}
Index: trunk/milena/sandbox/duhamel/mesh_image.hh
===================================================================
--- trunk/milena/sandbox/duhamel/mesh_image.hh (revision 1190)
+++ trunk/milena/sandbox/duhamel/mesh_image.hh (revision 1191)
@@ -197,6 +197,10 @@
{
// 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];
}
Index: trunk/milena/sandbox/duhamel/mesh_psite.hh
===================================================================
--- trunk/milena/sandbox/duhamel/mesh_psite.hh (revision 1190)
+++ trunk/milena/sandbox/duhamel/mesh_psite.hh (revision 1191)
@@ -10,15 +10,16 @@
{
public:
mesh_psite () {}
- mesh_psite (unsigned i, mesh_p<P>* m_ptr) :
- i_ (i),
- m_ptr_ (m_ptr)
+ 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_];}
+ // P to_point () {return m_ptr_->loc_[i_];}
private:
unsigned i_;
- mesh_p<P>* m_ptr_;
+ // mesh_p<P>* m_ptr_;
};
} // end of mln
#endif // MLN_MESH_PSITE_HH
Index: trunk/milena/sandbox/duhamel/mesh_p.hh
===================================================================
--- trunk/milena/sandbox/duhamel/mesh_p.hh (revision 1190)
+++ trunk/milena/sandbox/duhamel/mesh_p.hh (revision 1191)
@@ -1,13 +1,15 @@
#ifndef MLN_MESH_P_HH
# define MLN_MESH_P_HH
+# include <mln/core/concept/point.hh>
#include "graph.hh"
+# include "mesh_psite.hh"
namespace mln
{
template<typename P>
- class mesh_p
+ class mesh_p// : public Point_Set<mesh_p<P> >
{
public:
mesh_p () {}
@@ -21,6 +23,41 @@
~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;
+
+ /// Backward Point_Iterator associated type.
+ typedef P bkd_piter;
+ //END FIXME
+
+ std::size_t npoints() const
+ {
+ 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;
+// }
+
util::graph<void> gr_;
std::vector<P> loc_;
};
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-28 Simon Nivault <simon.nivault(a)lrde.epita.fr>
Add homogen vector.
* mln/core/h_vec.hh: New.
* mln/core/point.hh: Know be casted as homogen vector.
* tests/h_vec.cc: New.
---
mln/core/h_vec.hh | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
mln/core/point.hh | 10 ++++++
tests/h_vec.cc | 62 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 155 insertions(+)
Index: trunk/milena/tests/h_vec.cc
===================================================================
--- trunk/milena/tests/h_vec.cc (revision 0)
+++ trunk/milena/tests/h_vec.cc (revision 1190)
@@ -0,0 +1,62 @@
+// 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.
+
+/*! \file tests/h_vec.cc
+ *
+ * \brief Tests on mln::h_vec.
+ */
+
+#include <mln/core/h_vec.hh>
+#include <mln/core/point3d.hh>
+
+using namespace mln;
+
+
+void run_in_3d(const metal::vec<3, int>&)
+{
+}
+
+void run_in_3d_h(const h_vec<3, int>&)
+{
+}
+
+
+int main()
+{
+
+ metal::vec<3, int> x;
+ h_vec<3, int> w = x;
+
+ typedef h_vec<3, int> p3d;
+ p3d p;
+ run_in_3d(p);
+
+ point3d k;
+ run_in_3d(k);
+ run_in_3d_h(k);
+
+}
Index: trunk/milena/mln/core/point.hh
===================================================================
--- trunk/milena/mln/core/point.hh (revision 1189)
+++ trunk/milena/mln/core/point.hh (revision 1190)
@@ -107,6 +107,9 @@
/// Hook to coordinates.
operator metal::vec<M::dim, C>() const;
+ /// Hook to homogene coordinate.
+ operator h_vec<M::dim, C>() const;
+
protected:
metal::vec<M::dim, C> coord_;
};
@@ -172,6 +175,13 @@
return coord_;
}
+ template <typename M, typename C>
+ point_<M,C>::operator h_vec<M::dim, C>() const
+ {
+ return coord_;
+ }
+
+
# endif // ! MLN_INCLUDE_ONLY
Index: trunk/milena/mln/core/h_vec.hh
===================================================================
--- trunk/milena/mln/core/h_vec.hh (revision 0)
+++ trunk/milena/mln/core/h_vec.hh (revision 1190)
@@ -0,0 +1,83 @@
+// 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_H_VEC_HH
+# define MLN_CORE_H_VEC_HH
+
+/*! \file mln/core/h_vec.hh
+ *
+ * \brief Definition of the mln::h_vec alias and of its
+ * construction routine.
+ */
+
+# include <mln/metal/vec.hh>
+
+
+namespace mln
+{
+
+
+ template <unsigned dim, typename T>
+ struct h_vec : public metal::vec<dim + 1, T>
+ {
+ h_vec()
+ : metal::vec<dim + 1, T>(make::vec<dim + 1, T>(0))
+ {
+ this->data_[dim] = 1;
+ }
+
+ h_vec(const metal::vec<dim, T>& x);
+
+ operator metal::vec<dim, T>() const;
+ };
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <unsigned dim, typename T>
+ h_vec<dim,T>::h_vec(const metal::vec<dim, T>& x)
+ {
+ for (unsigned i = 0; i < dim; ++i)
+ this->data_[i] = x[i];
+ this->data_[dim] = 1;
+ }
+
+ template <unsigned dim, typename T>
+ h_vec<dim,T>::operator metal::vec<dim,T>() const
+ {
+ metal::vec<dim,T> x;
+ for (unsigned i = 0; i < dim; ++i)
+ x[i] = this->data_[i] / this->data_[dim];
+ return x;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+
+#endif // ! MLN_CORE_H_VEC_HH
1
0