* green/mln/value/rg.hh: New library file.
* green/mln/fun/v2v/rgb_to_rg.hh: New library file.
* green/mln/fun/v2v/rg_to_rgb.hh: New library file.
---
trunk/milena/sandbox/ChangeLog | 8 ++
.../milena/sandbox/green/mln/fun/v2v/rg_to_rgb.hh | 70 ++++++++++++
.../milena/sandbox/green/mln/fun/v2v/rgb_to_rg.hh | 70 ++++++++++++
trunk/milena/sandbox/green/mln/value/rg.hh | 116 ++++++++++++++++++++
4 files changed, 264 insertions(+), 0 deletions(-)
create mode 100644 trunk/milena/sandbox/green/mln/fun/v2v/rg_to_rgb.hh
create mode 100644 trunk/milena/sandbox/green/mln/fun/v2v/rgb_to_rg.hh
create mode 100644 trunk/milena/sandbox/green/mln/value/rg.hh
diff --git a/trunk/milena/sandbox/ChangeLog b/trunk/milena/sandbox/ChangeLog
index 9c03dec..8c48c64 100644
--- a/trunk/milena/sandbox/ChangeLog
+++ b/trunk/milena/sandbox/ChangeLog
@@ -1,5 +1,13 @@
2009-10-08 Yann Jacquelet <jacquelet(a)lrde.epita.fr>
+ Add a new (red,green) value type.
+
+ * green/mln/value/rg.hh: New library file.
+ * green/mln/fun/v2v/rgb_to_rg.hh: New library file.
+ * green/mln/fun/v2v/rg_to_rgb.hh: New library file.
+
+2009-10-08 Yann Jacquelet <jacquelet(a)lrde.epita.fr>
+
Add histogram accumulator which produce a 2d image result.
* green/mln/accu/stat/histo2d.hh: New library file.
diff --git a/trunk/milena/sandbox/green/mln/fun/v2v/rg_to_rgb.hh b/trunk/milena/sandbox/green/mln/fun/v2v/rg_to_rgb.hh
new file mode 100644
index 0000000..ca7ba51
--- /dev/null
+++ b/trunk/milena/sandbox/green/mln/fun/v2v/rg_to_rgb.hh
@@ -0,0 +1,70 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project 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_FUN_V2V_RG_TO_RGB_HH
+# define MLN_FUN_V2V_RG_TO_RGB_HH
+
+# include <mln/value/rgb.hh>
+# include <mln/value/rg.hh>
+# include <mln/core/contract.hh>
+
+/// \file
+///
+/// \brief Convert rg value to rgb
+
+namespace mln
+{
+
+ namespace fun
+ {
+
+ namespace v2v
+ {
+
+ /// \brief Convert rg value to rgb.
+ ///
+ /// \ingroup modfunv2v
+
+ template <unsigned n>
+ struct rg_to_rgb : Function_v2v< rg_to_rgb<n> >
+ {
+ typedef value::rg<n> argument;
+ typedef value::rgb<n> result;
+
+ result operator()(const argument& v) const
+ {
+ return value::rgb<n>(v.red(), v.green(), 127);
+ }
+ };
+
+ } // end of namespace mln::fun::v2v
+
+ } // end of namespace mln::fun
+
+} // end of namespace mln
+
+#endif // ! MLN_FUN_V2V_RG_TO_RGB_HH
diff --git a/trunk/milena/sandbox/green/mln/fun/v2v/rgb_to_rg.hh b/trunk/milena/sandbox/green/mln/fun/v2v/rgb_to_rg.hh
new file mode 100644
index 0000000..f5163ad
--- /dev/null
+++ b/trunk/milena/sandbox/green/mln/fun/v2v/rgb_to_rg.hh
@@ -0,0 +1,70 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project 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_FUN_V2V_RGB_TO_RG_HH
+# define MLN_FUN_V2V_RGB_TO_RG_HH
+
+# include <mln/value/rgb.hh>
+# include <mln/value/rg.hh>
+# include <mln/core/contract.hh>
+
+/// \file
+///
+/// \brief Convert rgb value to rg
+
+namespace mln
+{
+
+ namespace fun
+ {
+
+ namespace v2v
+ {
+
+ /// \brief Convert rgb value to rg.
+ ///
+ /// \ingroup modfunv2v
+
+ template <unsigned n>
+ struct rgb_to_rg : Function_v2v< rgb_to_rg<n> >
+ {
+ typedef value::rgb<n> argument;
+ typedef value::rg<n> result;
+
+ result operator()(const argument& v) const
+ {
+ return value::rg<n>(v);
+ }
+ };
+
+ } // end of namespace mln::fun::v2v
+
+ } // end of namespace mln::fun
+
+} // end of namespace mln
+
+#endif // ! MLN_FUN_V2V_RGB_TO_RG_HH
diff --git a/trunk/milena/sandbox/green/mln/value/rg.hh b/trunk/milena/sandbox/green/mln/value/rg.hh
new file mode 100644
index 0000000..f7205fc
--- /dev/null
+++ b/trunk/milena/sandbox/green/mln/value/rg.hh
@@ -0,0 +1,116 @@
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
+// Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project 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_VALUE_RG_HH
+# define MLN_VALUE_RG_HH
+
+
+#include <mln/value/concept/vectorial.hh>
+# include <mln/value/int_u.hh>
+
+#include <mln/trait/value_.hh>
+# include <mln/algebra/vec.hh>
+
+namespace mln
+{
+
+ namespace value
+ {
+
+ // Forward declaration.
+ template <unsigned n> struct rg;
+
+ } // end of namespace mln::value
+
+ namespace trait
+ {
+
+ template <unsigned n>
+ struct value_< mln::value::rg<n> >
+ {
+ enum {
+ dim = 2,
+ nbits = dim * n,
+ card = mln_value_card_from_(nbits)
+ };
+
+ typedef trait::value::nature::vectorial nature;
+ typedef trait::value::kind::color kind;
+ typedef trait::value::quant::high quant;
+
+ typedef void comp;
+ typedef mln::value::int_u<n> comp_0;
+ typedef mln::value::int_u<n> comp_1;
+
+ static comp_0 get_comp_0(const mln::value::rg<n>& v){return v.red(); }
+ static comp_1 get_comp_1(const mln::value::rg<n>& v){return v.green();}
+
+ typedef algebra::vec<dim, float> sum;
+
+ static const char* name()
+ {
+ static std::string s = std::string("rg").append(1, 8 + '0');
+ return s.c_str();
+ }
+ };
+
+ } // end of namespace mln::trait
+
+ namespace value
+ {
+ template <unsigned n>
+ struct rg :public mln::value::Vectorial< rg<n> >,
+ public internal::value_like_<
+ algebra::vec< 2, int_u<n> >, // Equivalent.
+ algebra::vec< 2, int_u<n> >, // Encoding.
+ algebra::vec< 2, int >, // Interoperation.
+ rg<n> > // Exact.
+ {
+ typedef int_u<n> t_red;
+ typedef int_u<n> t_green;
+
+ int_u<n> red() const {return this->v_[0];}
+ int_u<n>& red() {return this->v_[0];}
+ int_u<n> green() const {return this->v_[1];}
+ int_u<n>& green() {return this->v_[1];}
+
+ rg(){}
+ rg(const rgb8& val){this->v_[0] = val.red(); this->v_[1] = val.green();}
+
+ rg operator=(const rg& rhs)
+ {
+ if (&rhs != this)
+ this->v_ = rhs.v_;
+
+ return *this;
+ }
+ };
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+#endif // ! MLN_VALUE_RG_HH
--
1.5.6.5
* green/mln/accu/stat/histo2d.hh: New library file.
---
trunk/milena/sandbox/ChangeLog | 7 +
.../milena/sandbox/green/mln/accu/stat/histo2d.hh | 346 ++++++++++++++++++++
2 files changed, 353 insertions(+), 0 deletions(-)
create mode 100644 trunk/milena/sandbox/green/mln/accu/stat/histo2d.hh
diff --git a/trunk/milena/sandbox/ChangeLog b/trunk/milena/sandbox/ChangeLog
index 1d68213..9c03dec 100644
--- a/trunk/milena/sandbox/ChangeLog
+++ b/trunk/milena/sandbox/ChangeLog
@@ -1,5 +1,12 @@
2009-10-08 Yann Jacquelet <jacquelet(a)lrde.epita.fr>
+ Add histogram accumulator which produce a 2d image result.
+
+ * green/mln/accu/stat/histo2d.hh: New library file.
+
+
+2009-10-08 Yann Jacquelet <jacquelet(a)lrde.epita.fr>
+
Correct bad behaviour in kmean3d (see usage of zero label).
* green/mln/clustering/kmean3d.hh
diff --git a/trunk/milena/sandbox/green/mln/accu/stat/histo2d.hh b/trunk/milena/sandbox/green/mln/accu/stat/histo2d.hh
new file mode 100644
index 0000000..fbe9a42
--- /dev/null
+++ b/trunk/milena/sandbox/green/mln/accu/stat/histo2d.hh
@@ -0,0 +1,346 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project 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_ACCU_STAT_HISTO2D_HH
+# define MLN_ACCU_STAT_HISTO2D_HH
+
+/// \file
+///
+/// \brief Define a histogram as an accumulator which returns an image1d .
+///
+/// This source implements the discrete histogram version. The number of beans
+/// is infer from the number of greylevels. A typical rgb8 image has got
+/// 256x3 bins. Working with a 8 bit quantification in rgb is very costly.
+/// The following sample is a typical use of the histogram.
+///
+/// #include <mln/value/rgb.hh>
+/// #include <mln/core/image/image1d.hh>
+/// #include <mln/core/image/image3d.hh>
+/// #include <mln/io/ppm/load.hh>
+/// #include <mln/accu/stat/histo3d_rgb.hh>
+/// #include <mln/data/compute.hh>
+///
+/// #define OLENA_LENA ""/usr/local/share/olena/images/lena.ppm"
+///
+/// void test()
+/// {
+/// typedef mln::value::rgb<7> rgb7;
+/// mln::image2d<rgb7> img_ref;
+/// mln::image3d<unsigned> img_res;
+///
+/// mln::io::ppm::load(img_ref, OLENA_LENA);
+/// img_res=mln::data::compute(mln::accu::meta::stat::histo3d_rgb(),img_ref);
+/// }
+
+
+# include <iostream>
+
+# include <mln/accu/internal/base.hh>
+
+# include <mln/core/macros.hh>
+# include <mln/core/image/image2d.hh>
+# include <mln/core/alias/point2d.hh>
+# include <mln/core/alias/box2d.hh>
+
+# include <mln/trait/value/comp.hh>
+
+# include <mln/arith/plus.hh>
+
+# include <mln/trace/entering.hh>
+# include <mln/trace/exiting.hh>
+
+# include <mln/value/ops.hh>
+
+namespace mln
+{
+
+ namespace accu
+ {
+
+ namespace stat
+ {
+
+ // Forward declaration
+ template <typename V>
+ struct histo2d;
+
+ } // end of namespace mln::accu::stat
+
+ namespace meta
+ {
+
+ namespace stat
+ {
+
+ struct histo2d : public Meta_Accumulator<histo2d>
+ {
+ template <typename V>
+ struct with
+ {
+ typedef accu::stat::histo2d<V> ret;
+ };
+ };
+
+ } // end of namespace mln::accu::meta::stat
+
+ } // end of namespace mln::accu::meta
+
+ } // end of namespace mln::accu
+
+
+ namespace trait
+ {
+
+ template <typename V>
+ struct accumulator_< mln::accu::stat::histo2d<V> >
+ {
+ typedef accumulator::has_untake::no has_untake;
+ typedef accumulator::has_set_value::no has_set_value;
+ typedef accumulator::has_stop::no has_stop;
+ typedef accumulator::when_pix::use_v when_pix;
+ };
+
+ template <typename V>
+ struct set_precise_binary_<op::eq,
+ accu::stat::histo2d<V>,
+ accu::stat::histo2d<V> >
+ {
+ typedef bool ret;
+ };
+
+ } // end of namespace mln::trait
+
+ namespace accu
+ {
+
+ namespace stat
+ {
+
+ /// \brief Define an histogram which returns an image3d .
+ ///
+ /// Param V defines the space in which we count the values.
+ /// For instance, this histogram works image2d<rgb<2>> or
+ /// image2d<rgb<7>>. The histogram count the occurrence of each value.
+ /// The number of bins depends of the grayscale values, for 8 bits there
+ /// is 256x3 bins. Note that over
+ /// quantification works too.
+ ///
+ /// \ingroup modaccuvalues
+
+ template <typename V>
+ struct histo2d :
+ public mln::accu::internal::base<image2d<unsigned>, histo2d<V> >
+ {
+ typedef V argument;
+ typedef image2d<unsigned> result;
+ typedef result q_result;
+
+ /// Constructors
+ /// \{
+ /// \brief Initialize the size of the resulting image1d.
+ ///
+ /// Initialize the size the resulting image from the theorical dynamic
+ /// of the greylevel values (Use V to manage it).
+ histo2d();
+ /// \}
+
+
+ /// Manipulators.
+ /// \{
+ /// \brief Initialize the histogram with zero value.
+ ///
+ /// This method must be called just before starting the use of the
+ /// histogram. If it's not, resulting values won't converge to the
+ /// density.
+ void init();
+
+
+ /// \brief Update the histogram with the RGB pixel t.
+ /// \param[in] t a greylevel pixel of type V.
+ ///
+ /// The end user shouldn't call this method. In place of it, he can
+ /// go through the data compute interface.
+ void take(const argument& t);
+
+
+ /// \brief Update the histogram with an other histogram.
+ /// \param[in] other the other histogram.
+ void take(const histo2d<V>& other);
+ /// \}
+
+ /// Accessors.
+ /// \{
+ /// \brief Return the histogram as an image1d.
+ ///
+ /// This is the machinery to communicate with data compute interface.
+ /// The end user should'nt use it.
+ result to_result() const;
+ operator result () const;
+ /// \}
+
+ /// \brief Check whethever this accumulator is able to return a result.
+ ///
+ /// Depends if the resulting image1d is valid. We can assume it is quite
+ /// always the case.
+ bool is_valid() const;
+
+ protected:
+ result count_;
+ };
+
+ /// \brief Check wethever an histogram is equal to an other one.
+ /// \param[in] histo1 the first histogram to compare with.
+ /// \param[in] histo2 the second histogram.
+ ///
+ /// The operator compare all the bins from the two histogram.
+
+ template <typename V>
+ bool operator==(const histo2d<V>& histo1,
+ const histo2d<V>& histo2);
+
+#ifndef MLN_INCLUDE_ONLY
+
+ template <typename V>
+ inline
+ histo2d<V>::histo2d()
+ {
+ trace::entering("mln::accu::stat::histo2d::histo2d");
+ typedef mln_trait_value_comp(V,0) comp0;
+ typedef mln_trait_value_comp(V,1) comp1;
+
+ // comp keep a trace of the dimension of the theorical image.
+ // mln_min(comp) --> 0
+ // mln_max(comp) --> 2^(n-1) [127 for n=7][255 for n=8] ...
+
+ count_.init_(box2d(point2d(mln_min(comp0),
+ mln_min(comp1)),
+ point2d(mln_max(comp0),
+ mln_max(comp1))));
+
+ trace::exiting("mln::accu::stat::histo2d::histo2d");
+ }
+
+ template <typename V>
+ inline
+ void histo2d<V>::init()
+ {
+ trace::entering("mln::accu::stat::histo2d::init");
+
+ data::fill(count_, 0);
+ trace::exiting("mln::accu::stat::histo2d::init");
+ }
+
+ template <typename V>
+ inline
+ void histo2d<V>::take(const argument& t)
+ {
+ trace::entering("mln::accu::stat::histo2d::take");
+
+ // Just convert a greyscale value (int_u8 like) to a position for an
+ // iterator on the resulting image.
+ // Take care to the constructor : Point(slice, row, column)
+ ++count_(point2d(t.red(), t.green()));
+
+ trace::exiting("mln::accu::stat::histo2d::take");
+ }
+
+
+ template <typename V>
+ inline
+ void histo2d<V>::take(const histo2d<V>& other)
+ {
+ trace::entering("mln::accu::stat::histo2d::take");
+
+ count_ += other.count_;
+
+ trace::exiting("mln::accu::stat::histo2d::take");
+ }
+
+ template <typename V>
+ inline
+ typename histo2d<V>::result histo2d<V>::to_result() const
+ {
+ trace::entering("mln::accu::stat::histo2d::to_result");
+
+ trace::exiting("mln::accu::stat::histo2d::to_result");
+ return count_;
+ }
+
+ template <typename V>
+ inline
+ histo2d<V>::operator result() const
+ {
+ trace::entering("mln::accu::stat::histo2d::operator result");
+
+ trace::exiting("mln::accu::stat::histo2d::operator result");
+ return count_;
+ }
+
+ template <typename V>
+ inline
+ bool histo2d<V>::is_valid() const
+ {
+ trace::entering("mln::accu::stat::histo2d::is_valid");
+ bool result = count_.is_valid();
+
+ trace::exiting("mln::accu::stat::histo2d::is_valid");
+ return result;
+ }
+
+ template <typename V>
+ bool operator==(const histo2d<V>& histo1,
+ const histo2d<V>& histo2)
+ {
+ trace::entering("mln::accu::stat::operator==");
+
+ bool result = true;
+ const image2d<unsigned>& res1 = histo1.to_result();
+ const image2d<unsigned>& res2 = histo2.to_result();
+
+ mln_precondition(res1.is_valid());
+ mln_precondition(res2.is_valid());
+
+ mln_piter(image2d<unsigned>) p1(res1.domain());
+ mln_piter(image2d<unsigned>) p2(res2.domain());
+
+ for_all_2(p1, p2)
+ result &= (res1(p1) == res2(p2));
+
+ trace::exiting("mln::accu::stat::operator==");
+ return result;
+ }
+
+#endif // ! MLN_INCLUDE_ONLY
+
+
+ } // end of namespace mln::accu::stat
+
+ } // end of namespace mln::accu
+
+} // end of namespace mln
+
+#endif // ! MLN_ACCU_STAT_HISTO2D_HH
--
1.5.6.5
* mln/win/multiple.hh (mln::win::multiple_qiter<W,F>::change_target):
Set the size before delegating the call to the base class, so that
postconditions can be honored.
---
milena/ChangeLog | 8 ++++++++
milena/mln/win/multiple.hh | 2 +-
2 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 4caaa0a..a308bc3 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,13 @@
2009-10-06 Roland Levillain <roland(a)lrde.epita.fr>
+ Fix the instruction flow in multiple_qiter<W,F>::change_target.
+
+ * mln/win/multiple.hh (mln::win::multiple_qiter<W,F>::change_target):
+ Set the size before delegating the call to the base class, so that
+ postconditions can be honored.
+
+2009-10-06 Roland Levillain <roland(a)lrde.epita.fr>
+
Honor strict-aliasing rules in memset_.
* mln/data/memset_.hh (mln::data::impl::memset): Here.
diff --git a/milena/mln/win/multiple.hh b/milena/mln/win/multiple.hh
index a12bf83..18b65c8 100644
--- a/milena/mln/win/multiple.hh
+++ b/milena/mln/win/multiple.hh
@@ -340,8 +340,8 @@ namespace mln
void
multiple_qiter<W,F>::change_target(const multiple<W,F>& w)
{
- this->super_::change_target(w);
size_ = w.size();
+ this->super_::change_target(w);
}
template <typename W, typename F>
--
1.6.3.1