URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-12-04 Simon Nivault <simon.nivault(a)lrde.epita.fr>
Add object based rle image and his test.
* mln/core/obased_rle_encode.hh: New.
* mln/core/obased_rle_image.hh: New.
* tests/core/Makefile.am: Add following test.
* tests/core/obased_rle_image.cc: New.
* mln/core/internal/run_image.hh: Fix compression routine.
* mln/core/mono_rle_encode.hh: Fix.
* mln/core/rle_encode.hh: Fix.
* tests/core/mono_rle_image.cc,
* tests/core/rle_image.cc: Display compression.
---
mln/core/internal/run_image.hh | 2
mln/core/mono_rle_encode.hh | 6
mln/core/obased_rle_encode.hh | 120 ++++++++++++++++
mln/core/obased_rle_image.hh | 292 +++++++++++++++++++++++++++++++++++++++++
mln/core/rle_encode.hh | 6
tests/core/Makefile.am | 2
tests/core/mono_rle_image.cc | 3
tests/core/obased_rle_image.cc | 78 ++++++++++
tests/core/rle_image.cc | 3
9 files changed, 507 insertions(+), 5 deletions(-)
Index: trunk/milena/tests/core/mono_rle_image.cc
===================================================================
--- trunk/milena/tests/core/mono_rle_image.cc (revision 1588)
+++ trunk/milena/tests/core/mono_rle_image.cc (revision 1589)
@@ -68,10 +68,11 @@
unsigned n;
image2d<unsigned> labels = labeling::blobs((pw::value(lena) > pw::cst(172u)) | lena.domain(),
c4(), n);
- std::cout << n << std::endl;
mono_rle_image<point2d, int_u8> rle = mono_rle_encode(level::transform(labels, fold_t()), 2);
+ std::cout << n << ", compression :" << rle.compression() << std::endl;
+
level::fill(cmp, literal::zero);
level::paste(rle, cmp);
Index: trunk/milena/tests/core/obased_rle_image.cc
===================================================================
--- trunk/milena/tests/core/obased_rle_image.cc (revision 0)
+++ trunk/milena/tests/core/obased_rle_image.cc (revision 1589)
@@ -0,0 +1,78 @@
+// 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/core/obased_rle_image.cc
+ *
+ * \brief Test on mln::obased_rle_image.hh.
+ */
+
+#include <mln/core/image2d.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/io/pgm/load.hh>
+#include <mln/pw/all.hh>
+#include <mln/core/neighb2d.hh>
+
+#include <mln/labeling/blobs.hh>
+#include <mln/level/transform.hh>
+#include <mln/level/paste.hh>
+#include <mln/level/compare.hh>
+#include <mln/io/pgm/save.hh>
+
+#include <mln/core/obased_rle_encode.hh>
+
+struct fold_t : public mln::Function_v2v< fold_t >
+{
+ typedef mln::value::int_u8 result;
+ result operator()(unsigned i) const { return i == 0 ? 0 : (i - 1) % 255 + 1; }
+};
+
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ image2d<int_u8> lena;
+ io::pgm::load(lena, "../../img/tiny.pgm");
+ image2d<int_u8> cmp(lena.domain());
+
+ unsigned n;
+ image2d<unsigned>
+ labels = labeling::blobs((pw::value(lena) > pw::cst(172u)) | lena.domain(),
+ c4(), n);
+
+ obased_rle_image<point2d, int_u8>
+ rle = obased_rle_encode(level::transform(labels, fold_t()));
+
+ std::cout << n << ", compression :" << rle.compression() << std::endl;
+
+ level::fill(cmp, literal::zero);
+ level::paste(rle, cmp);
+
+ mln_assertion(cmp == level::transform(labels, fold_t()));
+}
Index: trunk/milena/tests/core/rle_image.cc
===================================================================
--- trunk/milena/tests/core/rle_image.cc (revision 1588)
+++ trunk/milena/tests/core/rle_image.cc (revision 1589)
@@ -64,10 +64,11 @@
unsigned n;
image2d<unsigned> labels = labeling::blobs((pw::value(lena) > pw::cst(172u)) | lena.domain(),
c4(), n);
- std::cout << n << std::endl;
rle_image<point2d, int_u8> rle = rle_encode(level::transform(labels, fold_t()));
+ std::cout << n << ", compression :" << rle.compression() << std::endl;
+
level::fill(cmp, literal::zero);
level::paste(rle, cmp);
Index: trunk/milena/tests/core/Makefile.am
===================================================================
--- trunk/milena/tests/core/Makefile.am (revision 1588)
+++ trunk/milena/tests/core/Makefile.am (revision 1589)
@@ -8,6 +8,7 @@
exact \
initialize \
mono_rle_image \
+ obased_rle_image \
p_runs \
rle_image \
t_image
@@ -17,6 +18,7 @@
exact_SOURCES = exact.cc
initialize_SOURCES = initialize.cc
mono_rle_image_SOURCES = mono_rle_image.cc
+obased_rle_image_SOURCES = obased_rle_image.cc
p_runs_SOURCES = p_runs.cc
rle_image_SOURCES = rle_image.cc
t_image_SOURCES = t_image.cc
Index: trunk/milena/mln/core/mono_rle_encode.hh
===================================================================
--- trunk/milena/mln/core/mono_rle_encode.hh (revision 1588)
+++ trunk/milena/mln/core/mono_rle_encode.hh (revision 1589)
@@ -94,7 +94,11 @@
else
{
output.insert(p_run<P>(rstart, len));
- len = 0;
+ if ((len = (!ignore_zero || ima(p) != literal::zero)))
+ {
+ rstart = p;
+ rvalue = ima(p);
+ }
}
}
return output;
Index: trunk/milena/mln/core/internal/run_image.hh
===================================================================
--- trunk/milena/mln/core/internal/run_image.hh (revision 1588)
+++ trunk/milena/mln/core/internal/run_image.hh (revision 1589)
@@ -73,7 +73,7 @@
run_image_<T, P, E>::compression() const
{
return float(exact(this)->data_->size_mem()) /
- float (sizeof(T) * exact(this)->data_->domain_->bbox().npoints());
+ float (sizeof(T) * exact(this)->data_->domain_.bbox().npoints());
}
# endif // ! MLN_INCLUDE_ONLY
Index: trunk/milena/mln/core/obased_rle_encode.hh
===================================================================
--- trunk/milena/mln/core/obased_rle_encode.hh (revision 0)
+++ trunk/milena/mln/core/obased_rle_encode.hh (revision 1589)
@@ -0,0 +1,120 @@
+// 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_OBASED_RLE_ENCODE_HH
+# define MLN_CORE_OBASED_RLE_ENCODE_HH
+
+/*! \file mln/core/obased_rle_encode.hh
+ *
+ * \brief Definintion of function which encodes an image in obased_rle_image.
+ */
+
+# include <mln/core/obased_rle_image.hh>
+
+namespace mln
+{
+
+ /*!
+ ** encode an image class to a obased_rle_image
+ **
+ ** @param input has to respect the Image concept
+ **
+ ** @return obased_rle_image
+ */
+ template <typename I>
+ obased_rle_image<mln_point(I), mln_value(I)>
+ obased_rle_encode(const Image<I>& input, bool ignore_zero = true);
+
+# ifndef MLN_INCLUDE_ONLY
+ /*!
+ ** test if Point p1 and p2 are on the same line
+ */
+ template <typename P>
+ inline
+ bool
+ on_the_same_line(const P& p1, const P& p2)
+ {
+ const unsigned dim = P::dim;
+ bool same_line = true;
+
+ for (unsigned n = 0; same_line && n < dim - 1; ++n)
+ same_line = (p1[n] == p2[n]);
+ return same_line;
+ }
+
+ template <typename I>
+ inline
+ obased_rle_image<mln_point(I), mln_value(I)>
+ obased_rle_encode(const Image<I>& input, bool ignore_zero)
+ {
+ typedef mln_point(I) P;
+
+ const I& ima = exact(input);
+ mln_piter(I) p (exact(input).domain());
+ unsigned len = 0;
+ mln_point(I) rstart;
+ mln_value(I) rvalue;
+ std::set< mln_value(I) > sv;
+
+ for_all(p)
+ {
+ if (!ignore_zero || ima(p) != literal::zero)
+ sv.insert(ima(p));
+ }
+
+ obased_rle_image<mln_point(I), mln_value(I)> output(sv);
+ for_all(p)
+ if (!ignore_zero || ima(p) != literal::zero || len)
+ {
+ if (len == 0)
+ {
+ ++len;
+ rstart = p;
+ rvalue = ima(p);
+ }
+ else
+ if (rvalue == ima(p)
+ && on_the_same_line(rstart, mln_point(I)(p)))
+ ++len;
+ else
+ {
+ output.insert(p_run<P>(rstart, len), rvalue);
+ if ((len = (!ignore_zero || ima(p) != literal::zero)))
+ {
+ rstart = p;
+ rvalue = ima(p);
+ }
+ }
+ }
+ return output;
+ }
+
+#endif // ! MLN_INCLUDE_ONLY
+
+}
+
+#endif // ! MLN_CORE_OBASED_RLE_ENCODE_HH
Index: trunk/milena/mln/core/obased_rle_image.hh
===================================================================
--- trunk/milena/mln/core/obased_rle_image.hh (revision 0)
+++ trunk/milena/mln/core/obased_rle_image.hh (revision 1589)
@@ -0,0 +1,292 @@
+// 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_OBASED_RLE_IMAGE_HH
+# define MLN_CORE_OBASED_RLE_IMAGE_HH
+
+/*! \file mln/core/obased_rle_image.hh
+ *
+ * \brief Definition of an image with rle encoding.
+ */
+
+# include <mln/core/internal/run_image.hh>
+# include <mln/core/p_runs.hh>
+# include <mln/core/runs_psite.hh>
+# include <mln/core/box.hh>
+# include <mln/value/set.hh>
+# include <vector>
+
+namespace mln
+{
+
+ // Fwd decl.
+ template <typename P, typename T> struct obased_rle_image;
+
+
+ namespace internal
+ {
+
+ template <typename P, typename T>
+ struct data_< obased_rle_image<P,T> >
+ {
+ data_(const std::set<T>& values);
+
+ /// Objects.
+ std::vector< std::vector<unsigned> > obj_;
+
+ /// Bounding boxes of the objects.
+ std::vector< accu::bbox<P> > bbox_;
+
+ /// Value of Objects.
+ std::vector<T> values_;
+
+ /// domain of the image
+ p_runs_<P> domain_;
+
+ /// Return the size of the data in memory.
+ unsigned size_mem() const;
+ };
+
+ } // end of namespace mln::internal
+
+
+ namespace trait
+ {
+
+ template <typename P, typename T>
+ struct image_< obased_rle_image<P,T> > : default_image_< T, obased_rle_image<P,T> >
+ {
+ typedef trait::image::category::primary category;
+
+ typedef trait::image::access::browsing access;
+ // FIXME: Put the right dimension.
+ typedef trait::image::space::two_d space;
+ typedef trait::image::size::regular size;
+ typedef trait::image::support::aligned support;
+
+ typedef trait::image::border::none border;
+ typedef trait::image::data::linear data;
+ typedef trait::image::io::read_only io;
+ typedef trait::image::speed::slow speed;
+ };
+
+ } // end of namespace mln::trait
+
+
+ /*! \brief RLE image.
+ *
+ *
+ * Parameter \c P is the type of the image points.
+ * Parameter \c T is the type of the pixel values.
+ * This image is not point wise accessible.
+ */
+ template <typename P, typename T>
+ class obased_rle_image : public internal::run_image_< T, P, obased_rle_image<P, T> >
+ {
+ public:
+ typedef T value;
+ typedef T& lvalue;
+ typedef const T rvalue;
+ typedef runs_psite<P> psite;
+ typedef mln::value::set<T> vset;
+ typedef p_runs_<P> pset;
+
+
+ /// Skeleton.
+ typedef obased_rle_image< tag::psite_<P>, tag::value_<T> > skeleton;
+
+
+ obased_rle_image(const std::set<T>& values);
+
+ /// Add a new range to the image.
+ void insert(const p_run<P>& pr, T value);
+
+ /// Read-only access to the image value located at point \p p.
+ rvalue operator() (const psite& site) const;
+
+ /// Read-write access to the image value located at point \p p.
+ lvalue operator() (const psite& site);
+
+ /// Test if this image has been initialized.
+ bool has_data() const;
+
+ /// Give the set of values of the image.
+ const vset& values() const;
+
+ /// Give the definition domain.
+ const pset& domain() const;
+
+ /// Give the index vector of the i-th object.
+ const std::vector<unsigned>& object(unsigned i) const;
+
+ /// Give the bounding box of the i-th object.
+ const box_<P>& bbox_of_run(unsigned i) const;
+
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace internal
+ {
+
+ // internal::data_< obased_rle_image<P,T> >
+
+ template <typename P, typename T>
+ inline
+ data_< obased_rle_image<P,T> >::data_(const std::set<T>& values)
+ : obj_(values.size()),
+ bbox_(values.size())
+ {
+ std::copy(values.begin(), values.end(),
+ std::back_inserter(this->values_));
+ }
+
+ template <typename P, typename T>
+ inline
+ unsigned
+ data_< obased_rle_image<P,T> >::size_mem() const
+ {
+ return domain_.size_mem() + bbox_.size()
+ * (sizeof(T) + sizeof(box_<P>) + sizeof(std::vector<unsigned>))
+ + sizeof(unsigned) * domain_.nruns();
+ }
+
+ } // end of namespace mln::internal
+
+ template <typename P, typename T>
+ inline
+ obased_rle_image<P, T>::obased_rle_image(const std::set<T>& values)
+ {
+ this->data_ = new internal::data_< obased_rle_image<P,T> >(values);
+ }
+
+ template <typename P, typename T>
+ inline
+ bool
+ obased_rle_image<P, T>::has_data() const
+ {
+ return this->data_->values_.size() != 0;
+ }
+
+ template <typename P, typename T>
+ inline
+ const typename obased_rle_image<P, T>::vset&
+ obased_rle_image<P, T>::values() const
+ {
+ return vset::the();
+ }
+
+ template <typename P, typename T>
+ inline
+ void
+ obased_rle_image<P, T>::insert(const p_run<P>& pr, T value)
+ {
+ mln_assertion(this->data_->values_.size() == 0 || this->data_->domain_.nruns() == 0 ||
+ pr.first() > this->data_->domain_[this->data_->domain_.nruns() - 1].first());
+ this->data_->domain_.insert(pr);
+ unsigned i;
+ for (i = 0; i < this->data_->values_.size()
+ && this->data_->values_[i] != value; ++i)
+ ;
+ mln_assertion(i != this->data_->values_.size());
+ this->data_->obj_[i].push_back(this->data_->domain_.nruns() - 1);
+ this->data_->bbox_[i].take(pr.bbox().pmin());
+ this->data_->bbox_[i].take(pr.bbox().pmax());
+ }
+
+ template <typename P, typename T>
+ inline
+ typename obased_rle_image<P, T>::rvalue
+ obased_rle_image<P, T>::operator() (const typename obased_rle_image<P, T>::psite& site)
+ const
+ {
+ mln_precondition(this->has_data() &&
+ site.pset_pos_() < this->data_->domain_.nruns());
+ for (unsigned i = 0; i < this->data_->obj_.size(); ++i)
+ {
+ for (typename std::vector<unsigned>::const_iterator it = this->data_->obj_[i].begin();
+ it != this->data_->obj_[i].end(); it++)
+ if (*it == site.pset_pos_())
+ return this->data_->values_[i];
+ }
+ mln_assertion(false);
+ return this->data_->values_[0];
+ }
+
+ template <typename P, typename T>
+ inline
+ typename obased_rle_image<P, T>::lvalue
+ obased_rle_image<P, T>::operator() (const typename obased_rle_image<P, T>::psite& site)
+ {
+ mln_precondition(this->has_data() &&
+ site.pset_pos_() < this->data_->domain_.nruns());
+ for (unsigned i = 0; i < this->data_->obj_.size(); ++i)
+ {
+ for (typename std::vector<unsigned>::const_iterator it = this->data_->obj_[i].begin();
+ it != this->data_->obj_[i].end(); it++)
+ if (*it == site.pset_pos_())
+ return this->data_->values_[i];
+ }
+ mln_assertion(false);
+ return this->data_->values_[0];
+ }
+
+ template <typename P, typename T>
+ inline
+ const typename obased_rle_image<P, T>::pset&
+ obased_rle_image<P, T>::domain() const
+ {
+ return this->data_->domain_;
+ }
+
+ template <typename P, typename T>
+ inline
+ const std::vector<unsigned>&
+ obased_rle_image<P, T>::object(unsigned i) const
+ {
+ mln_assertion(i < this->data_->obj_.size());
+ return this->data_->obj_[i];
+ }
+
+ template <typename P, typename T>
+ inline
+ const box_<P>&
+ obased_rle_image<P, T>::bbox_of_run(unsigned i) const
+ {
+ mln_assertion(i < this->data_->bbox_.size());
+ return this->data_->bbox_[i];
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_OBASED_RLE_IMAGE_HH
Index: trunk/milena/mln/core/rle_encode.hh
===================================================================
--- trunk/milena/mln/core/rle_encode.hh (revision 1588)
+++ trunk/milena/mln/core/rle_encode.hh (revision 1589)
@@ -96,7 +96,11 @@
else
{
output.insert(p_run<P>(rstart, len), rvalue);
- len = 0;
+ if ((len = (!ignore_zero || ima(p) != literal::zero)))
+ {
+ rstart = p;
+ rvalue = ima(p);
+ }
}
}
return output;
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-12-04 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Work on values.
* mln/value/rgb.hh: (rgb<n>(const metal::vec<3, unsigned>& rhs)) New.
* tests/value/Makefile.am: Add rgb_full test.
* tests/value/int_u8.cc: Update include.
* tests/value_macros.hh: Rename as...
* tests/value/macros.hh: ...this.
* tests/value/rgb_full.cc: Test all operator of rgb, an interop
with int and int_u8.
---
mln/value/rgb.hh | 8 ++
tests/value/Makefile.am | 6 ++
tests/value/int_u8.cc | 2
tests/value/macros.hh | 104 ++++++++++++++++++++++++++++++++++++
tests/value/rgb_full.cc | 137 ++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 256 insertions(+), 1 deletion(-)
Index: trunk/milena/tests/value_macros.hh (deleted)
===================================================================
Index: trunk/milena/tests/value/rgb_full.cc
===================================================================
--- trunk/milena/tests/value/rgb_full.cc (revision 0)
+++ trunk/milena/tests/value/rgb_full.cc (revision 1587)
@@ -0,0 +1,137 @@
+// 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/value_rgb.cc
+ *
+ * \brief Tests on mln::value::rgb.
+ */
+
+#include <mln/value/rgb.hh>
+#include <mln/value/rgb8.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/literal/all.hh>
+
+
+#define sym_compare_assert(V1, OP, V2) \
+ \
+ mln_assertion(V1 OP V2);
+
+#define compute_rgb(V1, OP, V2) \
+ \
+ rgb8( \
+ V1.red() OP V2.red() , \
+ V1.green() OP V2.green() , \
+ V1.blue() OP V2.blue() \
+ )
+
+#define compute_rgb_sc(V1, OP, V2) \
+ \
+ rgb8( \
+ V1.red() OP V2 , \
+ V1.green() OP V2 , \
+ V1.blue() OP V2 \
+ )
+
+#define test_interop(T1, T2, OP, V1, V2) \
+{ \
+ T1 i = V1; \
+ T2 j = V2; \
+ \
+ i = i OP j; \
+ sym_compare_assert(i, ==, compute_rgb(V1, OP, V2)); \
+ sym_compare_assert(j, ==, V2); \
+ \
+ i = V1; \
+ j = V2; \
+ \
+ j = i OP j; \
+ sym_compare_assert(j, ==, compute_rgb(V1, OP, V2)); \
+ sym_compare_assert(i, ==, V1); \
+ \
+ i = V1; \
+ i OP##= i; \
+ sym_compare_assert(i, ==, compute_rgb(V1, OP, V1)); \
+ \
+ i = V1; \
+ j = V2; \
+ i OP##= j; \
+ sym_compare_assert(i, ==, compute_rgb(V1, OP, V2)); \
+ \
+ j OP##= j; \
+ sym_compare_assert(j, ==, compute_rgb(V2, OP, V2)); \
+ \
+ i = V1; \
+ j = V2; \
+ j OP##= i; \
+ sym_compare_assert(j, ==, compute_rgb(V2, OP, V1)); \
+ \
+ i = V1; \
+ i OP##= i; \
+ sym_compare_assert(i, ==, compute_rgb(V1, OP, V1)); \
+}
+
+
+// T1 is rgb, T2 is scalar
+#define test_interop_sc(T1, T2, OP, V1, V2) \
+{ \
+ T1 i = V1; \
+ T2 j = V2; \
+ \
+ i = i OP j; \
+ sym_compare_assert(i, ==, compute_rgb_sc(V1, OP, V2)); \
+ sym_compare_assert(j, ==, V2); \
+ \
+ i = V1; \
+ i OP##= i; \
+ sym_compare_assert(i, ==, compute_rgb(V1, OP, V1)); \
+ \
+ i = V1; \
+ j = V2; \
+ i OP##= j; \
+ sym_compare_assert(i, ==, compute_rgb_sc(V1, OP, V2)); \
+}
+
+int main()
+{
+ using namespace mln;
+ using value::rgb;
+ using value::rgb8;
+ using value::int_u8;
+
+ using literal::blue;
+ using literal::white;
+
+ {
+ test_interop(rgb8, rgb8, +, rgb8(4,5,6), rgb8(1,2,3));
+ test_interop(rgb8, rgb8, -, rgb8(4,5,6), rgb8(1,2,3))
+ test_interop_sc(rgb8, int, *, rgb8(4,5,6), 4);
+ test_interop_sc(rgb8, int, /, rgb8(40,50,60), 10);
+
+ test_interop_sc(rgb8, int_u8, *, rgb8(4,5,6), 4);
+ test_interop_sc(rgb8, int_u8, /, rgb8(40,50,60), 10);
+ }
+}
Index: trunk/milena/tests/value/macros.hh
===================================================================
--- trunk/milena/tests/value/macros.hh (revision 0)
+++ trunk/milena/tests/value/macros.hh (revision 1587)
@@ -0,0 +1,104 @@
+// 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/value_macros.hh
+ *
+ * \brief Utilities to tests value types.
+ */
+
+#define sym_compare_assert(V1, OP, V2) \
+ \
+ mln_assertion(V1 OP V2); \
+ mln_assertion(-V1 OP -V2); \
+ mln_assertion(V2 OP V1); \
+ mln_assertion(-V2 OP -V1);
+
+#define asym_compare_assert(V1, OP, V2) \
+ \
+ mln_assertion(V1 OP V2); \
+ mln_assertion(!(-V1 OP -V2)); \
+ mln_assertion(-V2 OP -V1); \
+ mln_assertion(!(V2 OP V1));
+
+// For unsigned types, V1 > V2 if op is minus
+#define test_interop(T1, T2, OP, V1, V2) \
+ \
+{ \
+ T1 i = V1; \
+ T2 j = V2; \
+ \
+ i = i OP j; \
+ sym_compare_assert(i, ==, float(V1 OP V2)); \
+ sym_compare_assert(j, ==, float(V2)); \
+ \
+ i = V1; \
+ j = V2; \
+ \
+ j = i OP j; \
+ sym_compare_assert(j, ==, float(V1 OP V2)); \
+ sym_compare_assert(i, ==, float(V1)); \
+ \
+ i = V1; \
+ i OP##= i; \
+ sym_compare_assert(i, ==, float(V1 OP V1)); \
+ \
+ i = V1; \
+ j = V2; \
+ i OP##= j; \
+ sym_compare_assert(i, ==, float(V1 OP V2)); \
+ \
+ j OP##= j; \
+ sym_compare_assert(j, ==, float(V2 OP V2)); \
+ \
+ i = V1; \
+ j = V2; \
+ j OP##= i; \
+ sym_compare_assert(j, ==, float(V2 OP V1)); \
+ \
+ i = V1; \
+ i OP##= i; \
+ sym_compare_assert(i, ==, float(((V1 OP V1)))); \
+}
+
+#define test_operator(T, OP, V1, V2) \
+ \
+{ \
+ T i = V1; \
+ T j = V2; \
+ \
+ i = i OP j; \
+ sym_compare_assert(i, ==, float(V1 OP V2)); \
+ sym_compare_assert(j, ==, float(V2)); \
+ \
+ i = V1; \
+ i OP##= i; \
+ sym_compare_assert(i, ==, float(V1 OP V1)); \
+ \
+ i = V1; \
+ j = V2; \
+ i OP##= j; \
+}
Index: trunk/milena/tests/value/int_u8.cc
===================================================================
--- trunk/milena/tests/value/int_u8.cc (revision 1586)
+++ trunk/milena/tests/value/int_u8.cc (revision 1587)
@@ -31,7 +31,7 @@
*/
#include <mln/value/int_u8.hh>
-#include <tests/value_macros.hh>
+#include <tests/value/macros.hh>
int main()
Index: trunk/milena/tests/value/Makefile.am
===================================================================
--- trunk/milena/tests/value/Makefile.am (revision 1586)
+++ trunk/milena/tests/value/Makefile.am (revision 1587)
@@ -24,6 +24,9 @@
scalar \
set
+check_full_PROGRAMS = \
+ rgb_full
+
bool_SOURCES = bool.cc
builtin_SOURCES = builtin.cc
equiv_SOURCES = equiv.cc
@@ -41,4 +44,7 @@
scalar_SOURCES = scalar.cc
set_SOURCES = set.cc
+rgb_full_SOURCES = rgb_full.cc
+
TESTS = $(check_PROGRAMS)
+TESTS_FULL = $(check_full_PROGRAMS)
Index: trunk/milena/mln/value/rgb.hh
===================================================================
--- trunk/milena/mln/value/rgb.hh (revision 1586)
+++ trunk/milena/mln/value/rgb.hh (revision 1587)
@@ -122,6 +122,7 @@
/// Constructor from a metal::vec.
rgb<n>(const metal::vec<3, int>& rhs);
+ rgb<n>(const metal::vec<3, unsigned>& rhs);
rgb<n>(const metal::vec<3, int_u<n> >& rhs);
/// \{ Constructors with literals.
@@ -188,6 +189,13 @@
template <unsigned n>
inline
+ rgb<n>::rgb(const metal::vec<3, unsigned>& v)
+ {
+ this->v_ = v;
+ }
+
+ template <unsigned n>
+ inline
rgb<n>::rgb(const metal::vec<3, int_u<n> >& v)
{
this->v_ = v;
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-12-04 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Move the tests of mln/value.
* tests/Makefile.am: Move the value tests...
* tests/value/Makefile.am: ...here.
* tests/value_bool.cc: Rename as...
* tests/value/bool.cc: ...this.
* tests/value_builtin.cc: Rename as...
* tests/value/builtin.cc: ...this.
* tests/value_equiv.cc: Rename as...
* tests/value/equiv.cc: ...this.
* tests/value_float01.cc: Rename as...
* tests/value/float01.cc: ...this.
* tests/value_float01_bis.cc: Rename as...
* tests/value/float01_bis.cc: ...this.
* tests/value_float01_f.cc: Rename as...
* tests/value/float01_f.cc: ...this.
* tests/value_graylevel.cc: Rename as...
* tests/value/graylevel.cc: ...this.
* tests/value_int_s.cc: Rename as...
* tests/value/int_s.cc: ...this.
* tests/value_int_s16.cc: Rename as...
* tests/value/int_s16.cc: ...this.
* tests/value_int_u8.cc: Rename as...
* tests/value/int_u8.cc: ...this.
* tests/value_interop.cc: Rename as...
* tests/value/interop.cc: ...this.
* tests/value_label.cc: Rename as...
* tests/value/label.cc: ...this.
* tests/value_quat.cc: Rename as...
* tests/value/quat.cc: ...this.
* tests/value_rgb8.cc: Rename as...
* tests/value/rgb8.cc: ...this.
* tests/value_scalar.cc: Rename as...
* tests/value/scalar.cc: ...this.
* tests/value_set.cc: Rename as...
* tests/value/set.cc: ...this.
---
Makefile.am | 27 ---
value/Makefile.am | 41 +++++
value/bool.cc | 45 +++++
value/builtin.cc | 120 +++++++++++++++
value/equiv.cc | 58 +++++++
value/float01.cc | 150 +++++++++++++++++++
value/float01_bis.cc | 58 +++++++
value/float01_f.cc | 43 +++++
value/graylevel.cc | 396 +++++++++++++++++++++++++++++++++++++++++++++++++++
value/int_s.cc | 51 ++++++
value/int_s16.cc | 213 +++++++++++++++++++++++++++
value/int_u8.cc | 197 +++++++++++++++++++++++++
value/interop.cc | 114 ++++++++++++++
value/label.cc | 49 ++++++
value/quat.cc | 72 +++++++++
value/rgb8.cc | 71 +++++++++
value/scalar.cc | 94 ++++++++++++
value/set.cc | 65 ++++++++
18 files changed, 1838 insertions(+), 26 deletions(-)
Index: trunk/milena/tests/value_scalar.cc (deleted)
===================================================================
Index: trunk/milena/tests/value_quat.cc (deleted)
===================================================================
Index: trunk/milena/tests/value_interop.cc (deleted)
===================================================================
Index: trunk/milena/tests/value_equiv.cc (deleted)
===================================================================
Index: trunk/milena/tests/value_set.cc (deleted)
===================================================================
Index: trunk/milena/tests/value_float01_bis.cc (deleted)
===================================================================
Index: trunk/milena/tests/value_float01_f.cc (deleted)
===================================================================
Index: trunk/milena/tests/value_builtin.cc (deleted)
===================================================================
Index: trunk/milena/tests/value_label.cc (deleted)
===================================================================
Index: trunk/milena/tests/value_int_s.cc (deleted)
===================================================================
Index: trunk/milena/tests/value_rgb8.cc (deleted)
===================================================================
Index: trunk/milena/tests/value_int_u8.cc (deleted)
===================================================================
Index: trunk/milena/tests/value_float01.cc (deleted)
===================================================================
Index: trunk/milena/tests/value_int_s16.cc (deleted)
===================================================================
Index: trunk/milena/tests/value_graylevel.cc (deleted)
===================================================================
Index: trunk/milena/tests/value_bool.cc (deleted)
===================================================================
Index: trunk/milena/tests/value/set.cc
===================================================================
--- trunk/milena/tests/value/set.cc (revision 0)
+++ trunk/milena/tests/value/set.cc (revision 1586)
@@ -0,0 +1,65 @@
+// 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/value_set.cc
+ *
+ * \brief Tests on mln::value::set_<T>.
+ */
+
+#include <mln/value/int_u8.hh>
+#include <mln/value/set.hh>
+
+
+
+template <typename T>
+void test()
+{
+ typedef mln::value::set<T> S;
+ S s;
+
+ mln_fwd_viter(S) v(s);
+ for_all(v)
+ std::cout << v << ' ';
+ std::cout << std::endl;
+
+ mln_bkd_viter(S) w(s);
+ for_all(w)
+ std::cout << w << ' ';
+ std::cout << std::endl;
+}
+
+
+
+int main()
+{
+ using namespace mln;
+
+ test<bool>();
+// test<unsigned char>();
+// test<unsigned short>();
+// test<value::int_u8>();
+}
Index: trunk/milena/tests/value/bool.cc
===================================================================
--- trunk/milena/tests/value/bool.cc (revision 0)
+++ trunk/milena/tests/value/bool.cc (revision 1586)
@@ -0,0 +1,45 @@
+// 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/value_bool.cc
+ *
+ * \brief Tests on mln::value::set.
+ */
+
+#include <mln/trait/value_.hh>
+#include <mln/value/set.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ mln_assertion(mln_card(bool) == 2);
+
+ value::set<bool> B;
+ std::cout << B << std::endl;
+}
Index: trunk/milena/tests/value/rgb8.cc
===================================================================
--- trunk/milena/tests/value/rgb8.cc (revision 0)
+++ trunk/milena/tests/value/rgb8.cc (revision 1586)
@@ -0,0 +1,71 @@
+// 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/value_rgb8.cc
+ *
+ * \brief Tests on mln::value::rgb8.
+ */
+
+#include <mln/value/rgb8.hh>
+#include <mln/literal/all.hh>
+
+
+int main()
+{
+ using namespace mln;
+ using value::rgb8;
+ using value::rgb;
+
+ using literal::blue;
+ using literal::white;
+
+ {
+ rgb8 v;
+ v.red() = 0;
+ v.green() = 1;
+ v.blue() = 2;
+ rgb8 c(0, 1, 2);
+
+ std::cout << c << std::endl;
+ std::cout << v << std::endl;
+
+ mln_assertion(c == c);
+ mln_assertion(c == v);
+ v.green() = 255;
+ std::cout << v << std::endl;
+
+ mln_assertion(v != c);
+
+ rgb<20> b = blue;
+ std::cout << b << std::endl;
+
+ rgb<20> w = white;
+ std::cout << w << std::endl;
+
+ mln_assertion(b != w);
+ }
+}
Index: trunk/milena/tests/value/float01_bis.cc
===================================================================
--- trunk/milena/tests/value/float01_bis.cc (revision 0)
+++ trunk/milena/tests/value/float01_bis.cc (revision 1586)
@@ -0,0 +1,58 @@
+// 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/value_float01_bis.cc
+ *
+ * \brief Tests on mln::value::float01.
+ */
+
+#include <iostream>
+#include <mln/value/float01_8.hh>
+#include <mln/value/float01_16.hh>
+
+int main()
+{
+ using namespace mln::value;
+
+// float01_8 a;
+
+ std::cout << "a = " << std::endl;
+ std::cout << "testsetestest\n"<< std::endl;
+
+// gl8 a = white;
+// gl16 b = white;
+// assert((a == b) == true);
+// gl8 c = (a + b) / 2;
+// assert(c == white);
+// c = a;
+// assert(c == white);
+
+// c = (a * 2) / 2;
+// assert(c == white);
+
+ std::cout << "testsetestest\n"<< std::endl;
+}
Index: trunk/milena/tests/value/scalar.cc
===================================================================
--- trunk/milena/tests/value/scalar.cc (revision 0)
+++ trunk/milena/tests/value/scalar.cc (revision 1586)
@@ -0,0 +1,94 @@
+// 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/value_scalar.cc
+ *
+ * \brief Tests on mln::value::scalar.
+ */
+
+#include <iostream>
+
+#include <mln/value/scalar.hh>
+#include <mln/value/int_u8.hh>
+
+
+template <typename T>
+void foo(const T& t)
+{
+ std::cout << mln::value::scalar(t) << std::endl;
+}
+
+namespace mln
+{
+ namespace trait
+ {
+// template <typename O1, typename O2>
+// struct set_binary_< op::less, Object,O1, Object,O2 > { typedef bool ret; };
+
+// template < typename Vl, typename Vr >
+// struct set_binary_< op::less, mln::value::Scalar, Vl, mln::value::Scalar, Vr >
+// {
+// typedef double ret;
+// };
+
+// template <typename B, typename O>
+// struct set_binary_< op::less,
+// mln::value::Integer, B,
+// mln::value::Scalar, O >
+// {
+// typedef bool ret;
+// };
+
+ }
+}
+
+
+int main()
+{
+ using namespace mln;
+
+// int i = 51;
+// foo(i);
+// foo( value::scalar(i) );
+
+
+ {
+ bool b;
+ value::int_u8 i, j;
+
+ b = 1 > value::scalar(j);
+
+ b = value::scalar(j) < value::scalar(j);
+
+// mln_trait_op_less_(value::scalar_< value::int_u8 >, value::scalar_< value::int_u8 >) tmp;
+// void* v = tmp;
+
+// mln_trait_op_less_(int, value::scalar_< value::int_u8 >) tmp;
+// void* v = tmp;
+ }
+
+}
Index: trunk/milena/tests/value/int_u8.cc
===================================================================
--- trunk/milena/tests/value/int_u8.cc (revision 0)
+++ trunk/milena/tests/value/int_u8.cc (revision 1586)
@@ -0,0 +1,197 @@
+// 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/value_int_u8.cc
+ *
+ * \brief Tests on mln::value::int_u8.
+ */
+
+#include <mln/value/int_u8.hh>
+#include <tests/value_macros.hh>
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ int_u8 i = 3, j;
+
+ {
+ int k = 0;
+ k += value::scalar(k);
+ }
+
+ // Assignment.
+ {
+ i = 51;
+ sym_compare_assert(i, ==, 51);
+
+ i = 51u;
+ sym_compare_assert(i, ==, 51);
+
+ signed char c = 51;
+ i = c;
+ sym_compare_assert(i, ==, 51);
+
+ j = i;
+ sym_compare_assert(j, ==, 51);
+
+ i = 3;
+ sym_compare_assert(3.0f, ==, i);
+ sym_compare_assert(i, !=, 2.99f);
+
+ // Error at run-time as expected :-)
+ // i = 256;
+ // i = -1;
+ // i = 255, ++i;
+ }
+
+
+ // Comparaison
+ {
+ int_u8 i = 42;
+ int_u8 j = 51;
+
+ asym_compare_assert(i, <, j);
+ asym_compare_assert(j, >, i);
+ asym_compare_assert(i, <, 12345.f);
+ asym_compare_assert(12345.f, >, i);
+
+ sym_compare_assert(i, !=, j);
+ sym_compare_assert(i, ==, 42.f);
+ sym_compare_assert(42.f, ==, i);
+ sym_compare_assert(i, !=, 69.f);
+ sym_compare_assert(69.f, !=, i);
+
+ }
+
+ // Addition.
+ {
+ test_operator(int_u8, +, 5, 1);
+ test_interop(int_u8, int, +, 5, -1);
+ test_interop(int_u8, char, +, 4, 2);
+ test_interop(int_u8, unsigned char, +, 4, 2);
+
+ int_u8 i = 234;
+
+ i++;
+ sym_compare_assert(i, ==, 235.f);
+
+ ++i;
+ sym_compare_assert(i, ==, 236.f);
+
+ i = +i;
+ sym_compare_assert(i, ==, 236.f);
+
+ }
+
+ // Soustraction
+ {
+ test_operator(int_u8, -, 100, 5);
+ test_interop(int_u8, int, -, 100, 5);
+ test_interop(int_u8, char, -, 100, 5);
+ test_interop(int_u8, unsigned char, -, 5, 5);
+
+ int_u8 c = 255;
+ c -= c;
+
+ sym_compare_assert(c, ==, 0.f);
+
+ int_u8 i = 236;
+
+ i--;
+ sym_compare_assert(i, ==, 235.f);
+
+ --i;
+ sym_compare_assert(i, ==, 234.f);
+
+ sym_compare_assert(-i, ==, -234.f);
+
+ sym_compare_assert(i * -2, !=, 0.f);
+ std::cout << (i) << " * -2 = "
+ << (i * -2) << ' '
+ << (-2 * i) << ' '
+ << (-2 * int(i))
+ << std::endl;
+ }
+
+ // Multiplication
+ {
+ test_operator(int_u8, *, 5, 1);
+ test_interop(int_u8, int, *, 5, 1);
+ test_interop(int_u8, char, *, 4, 2);
+ test_interop(int_u8, unsigned char, *, 4, 2);
+
+ int_u8 c = 255;
+
+ c *= 0;
+ sym_compare_assert(c, ==, 0.f);
+
+ i *= 2;
+ int k; k *= i;
+
+ unsigned char d = 0;
+ i *= d;
+ sym_compare_assert(i, ==, 0.f);
+
+ // Error at run-time as expected :-)
+ // i = 128;
+ // i *= 2;
+
+ }
+
+ // Division
+ {
+ test_operator(int_u8, /, 5, 1);
+ test_interop(int_u8, int, /, 5, 1);
+ test_interop(int_u8, char, /, 4, 2);
+ test_interop(int_u8, unsigned char, /, 4, 2);
+
+ int_u8 c = 200;
+
+ c /= 1;
+ sym_compare_assert(c, ==, 200.f);
+ c /= 2;
+ sym_compare_assert(c, ==, 100.f);
+
+ int_u8 d = 2;
+ c /= 2;
+ sym_compare_assert(c, ==, 50.f);
+
+ }
+
+
+ // Modulo
+ {
+ test_operator(int_u8, %, 5, 10);
+ test_interop(int_u8, int, %, 5, 10);
+ test_interop(int_u8, char, %, 4, 20);
+ test_interop(int_u8, unsigned char, %, 4, 20);
+ }
+
+}
Index: trunk/milena/tests/value/float01.cc
===================================================================
--- trunk/milena/tests/value/float01.cc (revision 0)
+++ trunk/milena/tests/value/float01.cc (revision 1586)
@@ -0,0 +1,150 @@
+// 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/value_float01.cc
+ *
+ * \brief Tests on mln::value::float01.
+ */
+
+#include <iostream>
+
+#include <mln/core/image2d.hh>
+#include <mln/debug/iota.hh>
+#include <mln/debug/println.hh>
+
+#include <mln/value/float01_8.hh>
+#include <mln/value/float01_16.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/level/transform.hh>
+
+#include <mln/io/pgm/load.hh>
+#include <mln/io/pgm/save.hh>
+
+#include <mln/win/rectangle2d.hh>
+#include <mln/level/median.hh>
+#include <mln/level/compare.hh>
+
+
+using namespace mln;
+using namespace mln::value;
+using mln::value::int_u8;
+
+float fi(int) { return 0.5; }
+int ii(int) { return 1; }
+
+float fd(double) { return 0.5; }
+int id(double) { return 1; }
+
+
+struct tofloat01 : mln::Function_v2v<tofloat01>
+{
+
+ typedef float01_<16> result;
+ result operator()(int_u8 v) const
+ {
+ result ret(double(v) / (mln_max(int_u8)));
+ // std::cout << v << "-> " << ret << std::endl;
+ return ret;
+ }
+};
+
+struct to8bits : mln::Function_v2v<to8bits>
+{
+
+ typedef int_u8 result;
+ result operator()(float01_<16> v) const
+ {
+ result ret = int(v.value() * 255);
+ //std::cout << v << "-> " << ret << std::endl;
+ return ret;
+ }
+};
+
+int main()
+{
+ win::rectangle2d rect(51, 51);
+ border::thickness = 52;
+
+ float01_8 a(0.5);
+ float01_16 b(0.5);
+
+ assert(approx_equal(b,a));
+
+ std::cout << b << std::endl;
+ b = b + 0.2;
+ std::cout << b << std::endl;
+ b = b - 0.2;
+ std::cout << b << std::endl;
+ b = b * 1.5;
+ std::cout << b << std::endl;
+ b = b / 4.6;
+ std::cout << b << std::endl;
+
+ b = b / 3;
+ std::cout << b << std::endl;
+ b = b * 1;
+ std::cout << b << std::endl;
+
+ a = fi(a);
+ a = ii(a);
+ a = fd(a);
+ a = id(a);
+
+ b = a;
+ a = b;
+ b = 0.34;
+ std::cout << b << std::endl;
+ b = 0;
+ std::cout << b << std::endl;
+ b = 1;
+ std::cout << b << std::endl;
+
+ {
+ std::cout << "convert" << std::endl;
+ image2d<int_u8>
+ lena = io::pgm::load<int_u8>("../img/lena.pgm"),
+ ref(lena.domain());
+
+ image2d<float01_16> out(lena.domain());
+ image2d<float01_16> tmp(lena.domain());
+
+ level::transform(lena, tofloat01(), tmp);
+
+ level::median(tmp, rect, out);
+ level::median(lena, rect, ref);
+
+
+ level::transform(out, to8bits(), lena);
+
+ io::pgm::save(lena, "out.pgm");
+ io::pgm::save(ref, "ref.pgm");
+ mln_assertion(lena == ref);
+ //debug::println(out);
+ }
+
+
+}
Index: trunk/milena/tests/value/builtin.cc
===================================================================
--- trunk/milena/tests/value/builtin.cc (revision 0)
+++ trunk/milena/tests/value/builtin.cc (revision 1586)
@@ -0,0 +1,120 @@
+// 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/value_builtin.cc
+ *
+ * \brief Tests on mln::trait::op with a builtin.
+ */
+
+#include <iostream>
+
+#include <mln/value/scalar.hh>
+#include <mln/value/int_u8.hh>
+
+
+namespace mln
+{
+ namespace trait
+ {
+
+ namespace op
+ {
+
+ template <typename T>
+ struct test;
+
+ template <typename L, typename R>
+ struct test_2;
+
+ }
+
+ // unary
+
+ template < typename S >
+ struct set_unary_< op::test, mln::value::Scalar, S >
+ {
+ typedef double ret;
+ };
+
+// template <typename I>
+// struct set_unary_< op::test,
+// mln::value::Integer, I >
+// {
+// typedef float ret;
+// };
+
+// template <typename I>
+// struct set_unary_< op::test,
+// mln::value::Built_In, I >
+// {
+// typedef bool ret;
+// };
+
+
+ // binary
+
+ template < typename S1, typename S2 >
+ struct set_binary_< op::test_2,
+ mln::value::Scalar, S1,
+ mln::value::Scalar, S2 >
+ {
+ typedef double ret;
+ };
+
+// template < typename I, typename S >
+// struct set_binary_< op::test_2,
+// mln::value::Integer, I,
+// mln::value::Scalar, S >
+// {
+// typedef float ret;
+// };
+
+// template < typename B, typename S >
+// struct set_binary_< op::test_2,
+// mln::value::Built_In, B,
+// mln::value::Scalar, S >
+// {
+// typedef bool ret;
+// };
+
+ }
+}
+
+
+int main()
+{
+ using namespace mln;
+
+ {
+ mln::trait::solve_binary< trait::op::test_2, int, value::scalar_< value::int_u8 > >::ret tmp;
+ double& d = tmp;
+ }
+ {
+ mln::trait::solve_unary< trait::op::test, int >::ret tmp;
+ double& d = tmp;
+ }
+}
Index: trunk/milena/tests/value/quat.cc
===================================================================
--- trunk/milena/tests/value/quat.cc (revision 0)
+++ trunk/milena/tests/value/quat.cc (revision 1586)
@@ -0,0 +1,72 @@
+// 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/value_quat.cc
+ *
+ * \brief Tests on mln::value::quat.
+ */
+
+#include <iostream>
+
+#include <mln/value/quat.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ value::quat q1(3.f, 4.f, 1.6f, 0.5f);
+ value::quat q2(1.2, make::vec(3, 6, 4));
+ value::quat q3(make::vec(1.3, 3., -6., 4.));
+
+ std::cout << q1 << std::endl;
+ std::cout << q2 << std::endl;
+ std::cout << q3 << std::endl;
+
+ std::cout << q1.s() << std::endl;
+
+ q1.s() = 2.6;
+ std::cout << q1 << std::endl;
+
+ std::cout << q1.v() << std::endl;
+
+ q2.v() = make::vec(1.4, 5.9, 3.1);
+ std::cout << q2 << std::endl;
+
+ std::cout << q2 * q3 << std::endl;
+
+ mln_assertion(! q3.is_unit());
+ q3.set_unit();
+ std::cout << q3 << std::endl;
+ mln_assertion(q3.is_unit());
+
+ std::cout << q2.conj() << std::endl;
+ std::cout << q2.inv() << std::endl;
+ std::cout << norm::l2(q2.to_vec()) << ' ' << norm::l2(q2.inv().to_vec()) << std::endl;
+ std::cout << q2.inv().inv() << std::endl;
+
+}
Index: trunk/milena/tests/value/float01_f.cc
===================================================================
--- trunk/milena/tests/value/float01_f.cc (revision 0)
+++ trunk/milena/tests/value/float01_f.cc (revision 1586)
@@ -0,0 +1,43 @@
+// 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/value_float01_f.cc
+ *
+ * \brief Tests on mln::value::float01_f.
+ */
+
+#include <iostream>
+#include <mln/value/float01_f.hh>
+
+int main()
+{
+ using mln::value::float01_f;
+
+ float01_f x = 0.5;
+ std::cout << x + 21.25 << std::endl;
+ x = x + 34;
+}
Index: trunk/milena/tests/value/int_s.cc
===================================================================
--- trunk/milena/tests/value/int_s.cc (revision 0)
+++ trunk/milena/tests/value/int_s.cc (revision 1586)
@@ -0,0 +1,51 @@
+// 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/value_int_s.cc
+ *
+ * \brief Tests on mln::value::int_s.
+ */
+
+#include <mln/value/int_s.hh>
+#include <mln/value/int_u.hh>
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_s;
+
+ {
+ int_s<7> i = 3;
+ i = 2;
+ mln_assertion(i == 2);
+ mln_assertion(i != 3);
+
+ mln_assertion(-i == -2);
+ mln_assertion(-3 * i == -6);
+ }
+}
Index: trunk/milena/tests/value/label.cc
===================================================================
--- trunk/milena/tests/value/label.cc (revision 0)
+++ trunk/milena/tests/value/label.cc (revision 1586)
@@ -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/value_label.cc
+ *
+ * \brief Tests on mln::value::label.
+ */
+
+#include <mln/value/int_u8.hh>
+#include <mln/value/label.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+ using value::label;
+
+ int_u8 i = 51;
+ label<8> l = 50;
+ ++l;
+ mln_assertion(l == l);
+ mln_assertion(i == l.to_enc());
+}
Index: trunk/milena/tests/value/interop.cc
===================================================================
--- trunk/milena/tests/value/interop.cc (revision 0)
+++ trunk/milena/tests/value/interop.cc (revision 1586)
@@ -0,0 +1,114 @@
+// 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/value_interop.cc
+ *
+ * \brief Tests interoperability on mln::value::*.
+ */
+
+#include <mln/value/int_u8.hh>
+#include <mln/value/int_s8.hh>
+#include <mln/value/int_u16.hh>
+#include <mln/value/float01_8.hh>
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+ using value::int_u16;
+ using value::float01_8;
+
+
+ // Tests on int_u<n> alone.
+ {
+ int_u8 i;
+ i = 51;
+ i *= 2;
+ }
+
+ using value::int_s8;
+
+
+// {
+// // Operations on int_u<n>
+// int_u8 i = 128;
+// int_u16 j = 42;
+// int_s8 k = 42;
+// float01_8 x;
+
+// (j = j + i) = i + j;
+// mln_assertion(j == (128 + 42));
+
+// (k = j - i) = i - j;
+// mln_assertion(k == (-42));
+
+// j = 2;
+// (j = j * i) = i * j;
+// mln_assertion(j == (2 * 128));
+
+// (x = (j / i) / ((j / i) + 0.1))
+// = (i / j) / ((i / j) + 0.1);
+
+// // std::cout << i + i << std::endl;
+// // float01_8 f = i / 200.5;
+// // std::cout << x << std::endl;
+// }
+
+// {
+// // Operations on int_u<n> and int / float
+// int_u16 j = 42;
+// int_s8 k = 42;
+// float x;
+
+// // int
+// (k = j - 123) = 123 - j;
+// (j = j + 123) = 123 + j;
+// (j = j * 4) = 4 * j;
+
+// (j = j / 4) = 4 / j;
+
+// // float
+// x = (j / 4.5 * 3.4 + 3.5 - 5.6) / 0.0234;
+// }
+
+
+// {
+// // Operations on int_u<n> and float01_8
+// int_u16 j = 42;
+// float01_8 x = 0.456;
+
+// x = x / j;
+// mln_assertion(x < 0 && x < 1);
+
+// x = x * j;
+// mln_assertion(x < 0 && x < 1);
+
+// x = x * j;
+// mln_assertion(x < 0 && x < 1);
+// }
+
+}
Index: trunk/milena/tests/value/int_s16.cc
===================================================================
--- trunk/milena/tests/value/int_s16.cc (revision 0)
+++ trunk/milena/tests/value/int_s16.cc (revision 1586)
@@ -0,0 +1,213 @@
+// 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/value_int_s16.cc
+ *
+ * \brief Tests on mln::value::int_s16.
+ */
+
+#include <mln/value/int_s16.hh>
+
+#define test_operator(T, OP, V1, V2) \
+ \
+{ \
+ T i = V1; \
+ T j = V2; \
+ \
+ i = i OP j; \
+ mln_assertion(i == (V1 OP V2)); \
+ mln_assertion(j == V2); \
+ \
+ i OP##= i; \
+ mln_assertion(i == (((V1 OP V2) OP (V1 OP V2)))); \
+}
+
+#define test_interop(T1, T2, OP, V1, V2) \
+ \
+{ \
+ T1 i = V1; \
+ T2 j = V2; \
+ \
+ i = i OP j; \
+ mln_assertion(i == (V1 OP V2)); \
+ mln_assertion(j == V2); \
+ \
+ i OP##= i; \
+ mln_assertion(i == (((V1 OP V2) OP (V1 OP V2)))); \
+}
+
+
+// test_operator
+
+int main()
+{
+ using namespace mln;
+ using value::int_s16;
+
+ int_s16 i = 3, j;
+
+ // Assignment.
+ {
+ i = 51;
+ mln_assertion(i == 51);
+
+ i = 51u;
+ mln_assertion(i == 51);
+
+ signed char c = 51;
+ i = c;
+ mln_assertion(i == 51);
+
+ j = i;
+ mln_assertion(j == 51);
+
+ i = 3;
+ mln_assertion(3.0f == i);
+ mln_assertion(i != 2.99f);
+
+ // Error at run-time as expected :-)
+ // i = 256;
+ // i = -1;
+ // i = 255, ++i;
+ }
+
+
+ // Comparaison
+ {
+ int_s16 i = 42;
+ int_s16 j = 51;
+
+ mln_assertion(i < j);
+ mln_assertion(j > i);
+ mln_assertion(i < 12345);
+ mln_assertion(12345 > i);
+
+ mln_assertion(i != j);
+ mln_assertion(i == 42);
+ mln_assertion(42 == i);
+ mln_assertion(i != 69);
+ mln_assertion(69 != i);
+
+ }
+
+ // Addition.
+ {
+ test_operator(int_s16, +, -5, 1);
+ test_interop(int_s16, int, +, 5, -1);
+ test_interop(int_s16, char, +, -4, 2);
+ test_interop(int_s16, unsigned char, +, 4, 2);
+
+ int_s16 i = 234;
+
+ i++;
+ mln_assertion(i == 235);
+
+ ++i;
+ mln_assertion(i == 236);
+
+ i = +i;
+ mln_assertion(i == 236);
+
+ }
+
+ // Soustraction
+ {
+ test_operator(int_s16, -, 100, 5);
+ test_interop(int_s16, int, -, 100, 5);
+ test_interop(int_s16, char, -, 100, 5);
+ test_interop(int_s16, unsigned char, -, 100, 5);
+
+ int_s16 c = 255;
+ c -= c;
+
+ mln_assertion(c == 0);
+
+ int_s16 i = 236;
+
+ i--;
+ mln_assertion(i == 235);
+
+ --i;
+ mln_assertion(i == 234);
+
+ mln_assertion(-i == -234);
+ }
+
+ // Multiplication
+ {
+ test_operator(int_s16, *, 5, 1);
+ test_interop(int_s16, int, *, 5, 1);
+ test_interop(int_s16, char, *, 4, 2);
+ test_interop(int_s16, unsigned char, *, 4, 2);
+
+ int_s16 c = 255;
+
+ c *= 0;
+ mln_assertion(c == 0);
+
+ i *= 2;
+ int k; k *= i;
+
+ unsigned char d = 0;
+ i *= d;
+ mln_assertion(i == 0);
+
+ // Error at run-time as expected :-)
+ // i = 128;
+ // i *= 2;
+
+ }
+
+ // Division
+ {
+ test_operator(int_s16, /, 5, 1);
+ test_interop(int_s16, int, /, 5, 1);
+ test_interop(int_s16, char, /, 4, 2);
+ test_interop(int_s16, unsigned char, /, 4, 2);
+
+ int_s16 c = 200;
+
+ c /= 1;
+ mln_assertion(c == 200);
+ c /= 2;
+ mln_assertion(c == 100);
+
+ int_s16 d = 2;
+ c /= 2;
+ mln_assertion(c == 50);
+
+ }
+
+
+ // Modulo
+ {
+ test_operator(int_s16, %, 5, 10);
+ test_interop(int_s16, int, %, 5, 10);
+ test_interop(int_s16, char, %, 4, 20);
+ test_interop(int_s16, unsigned char, %, 4, 20);
+ }
+}
Index: trunk/milena/tests/value/Makefile.am
===================================================================
--- trunk/milena/tests/value/Makefile.am (revision 1585)
+++ trunk/milena/tests/value/Makefile.am (revision 1586)
@@ -1,3 +1,44 @@
## Process this file through Automake to create Makefile.in -*- Makefile -*-
include $(top_srcdir)/milena/tests/tests.mk
+
+SUBDIRS = \
+ concept \
+ builtin
+
+check_PROGRAMS = \
+ bool \
+ builtin \
+ equiv \
+ float01_bis \
+ float01 \
+ float01_f \
+ graylevel \
+ interop \
+ int_s16 \
+ int_s \
+ int_u8 \
+ label \
+ quat \
+ rgb8 \
+ scalar \
+ set
+
+bool_SOURCES = bool.cc
+builtin_SOURCES = builtin.cc
+equiv_SOURCES = equiv.cc
+float01_bis_SOURCES = float01_bis.cc
+float01_SOURCES = float01.cc
+float01_f_SOURCES = float01_f.cc
+graylevel_SOURCES = graylevel.cc
+interop_SOURCES = interop.cc
+int_s16_SOURCES = int_s16.cc
+int_s_SOURCES = int_s.cc
+int_u8_SOURCES = int_u8.cc
+label_SOURCES = label.cc
+quat_SOURCES = quat.cc
+rgb8_SOURCES = rgb8.cc
+scalar_SOURCES = scalar.cc
+set_SOURCES = set.cc
+
+TESTS = $(check_PROGRAMS)
Index: trunk/milena/tests/value/equiv.cc
===================================================================
--- trunk/milena/tests/value/equiv.cc (revision 0)
+++ trunk/milena/tests/value/equiv.cc (revision 1586)
@@ -0,0 +1,58 @@
+// 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/value_equiv.cc
+ *
+ * \brief Tests on mln::value::equiv.
+ *
+ * \todo Rename "::to_equiv()" as "::to_equiv_()".
+ */
+
+#include <mln/value/int_u8.hh>
+#include <mln/value/equiv.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ value::int_u8 i = 51;
+
+ {
+ const unsigned& u = i.to_equiv();
+ mln_assertion(u == 51);
+ }
+ {
+ const unsigned& u = value::equiv(i);
+ mln_assertion(u == 51);
+ }
+ {
+ const unsigned& u = value::equiv( value::scalar(i) );
+ mln_assertion(u == 51);
+ }
+
+}
Index: trunk/milena/tests/value/graylevel.cc
===================================================================
--- trunk/milena/tests/value/graylevel.cc (revision 0)
+++ trunk/milena/tests/value/graylevel.cc (revision 1586)
@@ -0,0 +1,396 @@
+// 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/value_graylevel.cc
+ *
+ * \brief Tests on mln::value::graylevel. Tests operations between
+ * graylevel of different encodings.
+ *
+ */
+
+#include <mln/value/graylevel.hh>
+#include <mln/value/int_u8.hh>
+
+#include <mln/literal/black.hh>
+#include <mln/literal/white.hh>
+
+
+
+int main()
+{
+ using namespace mln::value;
+
+ using mln::literal::white;
+ using mln::literal::black;
+
+ gl8 a = 255;
+ gl8 b = 255;
+
+ // Constructions
+ {
+ gl8 x;
+
+ gl8 a = 12;
+ gl8 b(12);
+ mln_assertion(a == b);
+
+// gl16 c = 2335;
+// gl8 d = c;
+// mln_assertion(c == d);
+
+ gl8 d = 250;
+ gl16 c = d;
+ mln_assertion(c == d);
+
+ gl8 e = gray(white);
+ mln_assertion(e == white);
+
+ gl8 f = 12;
+ gl8 g = f;
+ gl8 h(f);
+
+ mln_assertion(f == g);
+ mln_assertion(h == g);
+ }
+
+ // Literals
+ {
+ gl8 a(white);
+ gl16 b(white);
+
+ mln_assertion(a == b);
+ mln_assertion(a.value() == float(255));
+ mln_assertion(b.value() == float(65535));
+ mln_assertion(a == white);
+ mln_assertion(b == white);
+
+ gl8 c = (gl16(white) + white) / 2;
+ std::cout << "gl8 c = (white + white) / 2; => c.value() == "
+ << int(c.value()) << std::endl;
+ mln_assertion(c == white);
+ mln_assertion(c.value() == float(255));
+
+ c = (gl8(white) + white) / 2;
+ mln_assertion(c == white);
+ mln_assertion(c.value() == float(255));
+
+ c = (gray(white) + white) / 2;
+ mln_assertion(c == white);
+ mln_assertion(c.value() == float(255));
+
+ a = black;
+ b = black;
+
+ mln_assertion(a == b);
+ mln_assertion(a.value() == float(0));
+ mln_assertion(b.value() == float(0));
+
+// c = (black + black) / 2;
+// mln_assertion(c == black);
+// mln_assertion(c.value() == float(0));
+ }
+
+ // Assigment
+ {
+ gl8 a;
+ gl16 b;
+
+ a = white;
+ mln_assertion(a == white);
+ mln_assertion(a.value() == float(255));
+
+ a = 23;
+ mln_assertion(a != white);
+ mln_assertion(a != black);
+ mln_assertion(a.value() == float(23));
+
+ b = 2;
+ mln_assertion(b != white);
+ mln_assertion(b != black);
+ mln_assertion(b.value() == float(2));
+
+ a = b;
+ mln_assertion(a.value() == float(2 / 257));
+
+ signed char c = 51;
+ a = c;
+ mln_assertion(a.value() == float(51));
+
+ // bounds
+ a = 255;
+ mln_assertion(a.value() == float(255));
+ a = 0;
+ mln_assertion(a.value() == float(0));
+ }
+
+ // Addition
+ {
+ gl8 a;
+ gl16 b;
+
+ // gl8 <- gl8 + gl8
+ a = 42;
+ a += a;
+ mln_assertion(a.value() == float(84));
+
+ a = 42;
+ a = a + a;
+ mln_assertion(a.value() == float(84));
+
+ // gl8 <- gl8 + gl16
+ a = 42;
+ b = 16969;
+ a = a + b;
+ mln_assertion(a.value() == float((42 + b.value() / 257) ));
+ a = 42;
+ b = 16969;
+ a += b;
+ mln_assertion(a.value() == float((42 + b.value() / 257) ));
+
+
+ // gl16 <- gl8 + gl16
+ a = 42;
+ b = 16969;
+ b += a;
+ mln_assertion(b.value() == float((42 * 257 + 16969) ));
+
+ a = 42;
+ b = 16969;
+ b = a + b;
+ mln_assertion(b.value() == float((42 * 257 + 16969) ));
+
+ // misc
+ a = 255;
+ b = 0;
+ a = a + b;
+ mln_assertion(a.value() == float(255));
+
+ a = 0;
+ b = 65535;
+ a = a + b;
+ mln_assertion(a.value() == float(255));
+ }
+
+
+ // Soustraction
+ {
+ gl8 a;
+ gl16 b;
+
+ // gl8 <- gl8 - gl8
+ a = 42;
+ a -= a;
+ mln_assertion(a == black);
+
+ a = 42;
+ a = a - a;
+ mln_assertion(a == black);
+
+ // gl8 <- gl8 - gl16
+ a = 42;
+ b = 5969;
+
+ a = b;
+ std::cout << "a.value() = " << int(a.value()) << std::endl;
+ std::cout << "should be " << (b.value() / 256) << std::endl;
+
+ a = 42;
+ a = a - b;
+ std::cout << int(a.value()) << ":" << (42 - b.value() / 256) << std::endl;
+ mln_assertion(a.value() == float((42 - b.value() / 256) ));
+ a = 42;
+ b = 16969;
+ a -= b;
+ mln_assertion(a.value() == float((42 - b.value() / 257) ));
+
+
+ // gl16 <- gl8 - gl16
+ a = 100;
+ b = 16969;
+ b -= a;
+ mln_assertion(b.value() == float((100 * 257 - 16969) ));
+
+ a = 100;
+ b = 16969;
+ b = a - b;
+ mln_assertion(b.value() == float((100 * 257 - 16969) ));
+
+ // misc
+ a = 255;
+ b = 0;
+ a = a - b;
+ mln_assertion(a.value() == float(255));
+
+ a = 0;
+ b = 65535;
+ a = a - b;
+ mln_assertion(a.value() == float(255));
+
+ // ...
+ {
+ graylevel<2> a = 2;
+ graylevel<3> b = 5;
+ graylevel<2> c;
+ graylevel<3> d;
+
+ c = a - b;
+ d = a - b;
+ mln_assertion(c == d);
+ }
+
+ {
+
+ // ...
+ gl8 a = 42;
+ gl16 b = 5969;
+ gl8 p;
+ p = b;
+ gl8 q;
+ gl8 r;
+
+ q = a - p;
+ r = a - b;
+ std::cout << int(q.value()) << " " << int(r.value()) << std::endl;
+ mln_assertion(q == r);
+
+ }
+
+ }
+
+ // Multiplication
+ {
+ gl8 a;
+ gl16 b;
+
+ // gl8 <- gl8 * gl8
+ a = 21;
+ a *= a;
+ mln_assertion(a.value() == 42);
+
+ a = 21;
+ a = a * a;
+ mln_assertion(a.value() == 42);
+
+ // gl8 <- gl8 * gl16
+ a = 10;
+ b = 5969;
+ a = a * b;
+ mln_assertion(a.value() == float((10 * b.value() / 257) ));
+
+ a = 10;
+ b = 16969;
+ a *= b;
+ mln_assertion(a.value() == float((10 * b.value() / 257) ));
+
+
+ // gl16 <- gl8 * gl16
+ a = 10;
+ b = 5969;
+ b *= a;
+ mln_assertion(b.value() == float((10 * 257 * 5969) ));
+
+ a = 10;
+ b = 5969;
+ b = a * b;
+ mln_assertion(b.value() == float((10 * 257 * 5969) ));
+
+ // misc
+ a = 255;
+ b = 0;
+ a = a * b;
+ mln_assertion(a == black);
+
+ a = 0;
+ b = 65535;
+ a = a * b;
+ mln_assertion(a == black);
+
+ // ...
+ {
+ graylevel<2> a = 2;
+ graylevel<3> b = 5;
+ graylevel<2> c;
+ graylevel<3> d;
+
+ c = a * b;
+ d = a * b;
+ mln_assertion(c == d);
+ }
+
+ {
+
+ // ...
+ gl8 a = 7;
+ gl16 b = 5969;
+
+ gl8 p;
+ p = b;
+
+ gl8 q;
+ gl8 r;
+
+ q = a * p;
+ r = a * b;
+ std::cout << int(q.value()) << " " << int(r.value()) << std::endl;
+ mln_assertion(q == r);
+
+ }
+
+ }
+
+
+ // Not exhaustive
+
+ // gl8 a(white);
+ // gl16 b(white);
+ // mln_assertion(a == b);
+ // // mln_assertion(-a == -b);
+
+ // mln_assertion(a.value() != b.value());
+
+ // {
+ // gl8 c = (a + b) / 2;
+ // mln_assertion(c == white);
+ // mln_assertion(c.value() == 255);
+
+ // c = a;
+ // mln_assertion(c == white);
+
+ // c = (a * 2) / 2;
+ // mln_assertion(c == white);
+
+ // c = c / 6;
+ // }
+
+ // {
+ // gl8 c = (white + white) / 2;
+ // mln_assertion(c == white);
+ // mln_assertion(c.value() == float(255));
+ // }
+
+ // gray g(black);
+}
Index: trunk/milena/tests/Makefile.am
===================================================================
--- trunk/milena/tests/Makefile.am (revision 1585)
+++ trunk/milena/tests/Makefile.am (revision 1586)
@@ -19,6 +19,7 @@
norm \
set \
util \
+ value \
win
check_PROGRAMS = \
@@ -131,19 +132,6 @@
trait_value \
translate_image \
\
- value_float01_bis \
- value_float01 \
- value_float01_f \
- value_graylevel \
- value_interop \
- value_int_s16 \
- value_int_s \
- value_int_u8 \
- value_label \
- value_quat \
- value_rgb8 \
- value_scalar \
- value_set \
vec \
\
window1d \
@@ -262,19 +250,6 @@
trait_value_SOURCES = trait_value.cc
translate_image_SOURCES = translate_image.cc
-value_float01_bis_SOURCES = value_float01_bis.cc
-value_float01_SOURCES = value_float01.cc
-value_float01_f_SOURCES = value_float01_f.cc
-value_graylevel_SOURCES = value_graylevel.cc
-value_interop_SOURCES = value_interop.cc
-value_int_s16_SOURCES = value_int_s16.cc
-value_int_s_SOURCES = value_int_s.cc
-value_int_u8_SOURCES = value_int_u8.cc
-value_label_SOURCES = value_label.cc
-value_quat_SOURCES = value_quat.cc
-value_rgb8_SOURCES = value_rgb8.cc
-value_scalar_SOURCES = value_scalar.cc
-value_set_SOURCES = value_set.cc
vec_SOURCES = vec.cc
window1d_SOURCES = window1d.cc
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-12-03 Simon Nivault <simon.nivault(a)lrde.epita.fr>
Generate mono_rle_image and add his test.
* mln/core/mono_rle_encode.hh: New.
* mln/core/mono_rle_image.hh: New.
* tests/core/mono_rle_image.cc: New.
* tests/core/Makefile.am: Add test.
* tests/core/rle_image.cc: Fix typo.
---
mln/core/mono_rle_encode.hh | 107 ++++++++++++++++++++
mln/core/mono_rle_image.hh | 230 +++++++++++++++++++++++++++++++++++++++++++
tests/core/Makefile.am | 2
tests/core/mono_rle_image.cc | 79 ++++++++++++++
tests/core/rle_image.cc | 4
5 files changed, 420 insertions(+), 2 deletions(-)
Index: trunk/milena/tests/core/mono_rle_image.cc
===================================================================
--- trunk/milena/tests/core/mono_rle_image.cc (revision 0)
+++ trunk/milena/tests/core/mono_rle_image.cc (revision 1583)
@@ -0,0 +1,79 @@
+// 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/mono_rle_iimage.cc
+ *
+ * \brief Test on mln::labeling::blobs.
+ */
+
+#include <mln/core/image2d.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/io/pgm/load.hh>
+#include <mln/pw/all.hh>
+#include <mln/core/neighb2d.hh>
+
+#include <mln/labeling/blobs.hh>
+#include <mln/level/transform.hh>
+#include <mln/level/paste.hh>
+#include <mln/level/compare.hh>
+#include <mln/io/pgm/save.hh>
+
+#include <mln/core/mono_rle_encode.hh>
+
+struct fold_t : public mln::Function_v2v< fold_t >
+{
+ typedef mln::value::int_u8 result;
+ result operator()(unsigned i) const { return i == 0 ? 0 : (i - 1) % 255 + 1; }
+};
+
+struct only_two_t : public mln::Function_v2v< only_two_t >
+{
+ typedef mln::value::int_u8 result;
+ result operator()(unsigned i) const { return i == 2 ? 2 : 0; }
+};
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ image2d<int_u8> lena;
+ io::pgm::load(lena, "../../img/tiny.pgm");
+ image2d<int_u8> cmp(lena.domain());
+
+ unsigned n;
+ image2d<unsigned> labels = labeling::blobs((pw::value(lena) > pw::cst(172u)) | lena.domain(),
+ c4(), n);
+ std::cout << n << std::endl;
+
+ mono_rle_image<point2d, int_u8> rle = mono_rle_encode(level::transform(labels, fold_t()), 2);
+
+ level::fill(cmp, literal::zero);
+ level::paste(rle, cmp);
+
+ mln_assertion(cmp == level::transform(labels, only_two_t()));
+}
Index: trunk/milena/tests/core/rle_image.cc
===================================================================
--- trunk/milena/tests/core/rle_image.cc (revision 1582)
+++ trunk/milena/tests/core/rle_image.cc (revision 1583)
@@ -25,9 +25,9 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/labeling/blobs.cc
+/*! \file tests/core/rle_image.cc
*
- * \brief Test on mln::labeling::blobs.
+ * \brief Test on mln::rle_image.hh.
*/
#include <mln/core/image2d.hh>
Index: trunk/milena/tests/core/Makefile.am
===================================================================
--- trunk/milena/tests/core/Makefile.am (revision 1582)
+++ trunk/milena/tests/core/Makefile.am (revision 1583)
@@ -7,6 +7,7 @@
clone \
exact \
initialize \
+ mono_rle_image \
p_runs \
rle_image \
t_image
@@ -15,6 +16,7 @@
clone_SOURCES = clone.cc
exact_SOURCES = exact.cc
initialize_SOURCES = initialize.cc
+mono_rle_image_SOURCES = mono_rle_image.cc
p_runs_SOURCES = p_runs.cc
rle_image_SOURCES = rle_image.cc
t_image_SOURCES = t_image.cc
Index: trunk/milena/mln/core/mono_rle_encode.hh
===================================================================
--- trunk/milena/mln/core/mono_rle_encode.hh (revision 0)
+++ trunk/milena/mln/core/mono_rle_encode.hh (revision 1583)
@@ -0,0 +1,107 @@
+// 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_MONO_RLE_ENCODE_HH
+# define MLN_CORE_MONO_RLE_ENCODE_HH
+
+/*! \file mln/core/mono_rle_encode.hh
+ *
+ * \brief Definintion of function which encodes an image in mono_rle_image.
+ */
+
+# include <mln/core/mono_rle_image.hh>
+
+namespace mln
+{
+
+ /*!
+ ** encode an image class to a mono_rle_image
+ **
+ ** @param input has to respect the Image concept
+ **
+ ** @return mono_rle_image
+ */
+ template <typename I>
+ mono_rle_image<mln_point(I), mln_value(I)>
+ mono_rle_encode(const Image<I>& input, mln_value(I) val);
+
+# ifndef MLN_INCLUDE_ONLY
+ /*!
+ ** test if Point p1 and p2 are on the same line
+ */
+ template <typename P>
+ inline
+ bool
+ on_the_same_line(const P& p1, const P& p2)
+ {
+ const unsigned dim = P::dim;
+ bool same_line = true;
+
+ for (unsigned n = 0; same_line && n < dim - 1; ++n)
+ same_line = (p1[n] == p2[n]);
+ return same_line;
+ }
+
+ template <typename I>
+ inline
+ mono_rle_image<mln_point(I), mln_value(I)>
+ mono_rle_encode(const Image<I>& input, mln_value(I) val)
+ {
+ typedef mln_point(I) P;
+
+ mono_rle_image<mln_point(I), mln_value(I)> output(val);
+ const I& ima = exact(input);
+ mln_piter(I) p (exact(input).domain());
+ unsigned len = 0;
+ mln_point(I) rstart;
+
+ for_all(p)
+ if (ima(p) == val || len)
+ {
+ if (len == 0)
+ {
+ ++len;
+ rstart = p;
+ }
+ else
+ if (val == ima(p)
+ && on_the_same_line(rstart, mln_point(I)(p)))
+ ++len;
+ else
+ {
+ output.insert(p_run<P>(rstart, len));
+ len = 0;
+ }
+ }
+ return output;
+ }
+
+#endif // ! MLN_INCLUDE_ONLY
+
+}
+
+#endif // ! MLN_CORE_MONO_RLE_ENCODE_HH
Index: trunk/milena/mln/core/mono_rle_image.hh
===================================================================
--- trunk/milena/mln/core/mono_rle_image.hh (revision 0)
+++ trunk/milena/mln/core/mono_rle_image.hh (revision 1583)
@@ -0,0 +1,230 @@
+// 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_MONO_RLE_IMAGE_HH
+# define MLN_CORE_MONO_RLE_IMAGE_HH
+
+/*! \file mln/core/mono_rle_image.hh
+ *
+ * \brief Definition of an image with rle encoding.
+ */
+
+# include <mln/core/internal/run_image.hh>
+# include <mln/core/p_runs.hh>
+# include <mln/core/runs_psite.hh>
+# include <mln/value/set.hh>
+# include <vector>
+
+namespace mln
+{
+
+ // Fwd decl.
+ template <typename P, typename T> struct mono_rle_image;
+
+
+ namespace internal
+ {
+
+ template <typename P, typename T>
+ struct data_< mono_rle_image<P,T> >
+ {
+ data_(const T& val);
+
+ /// Image value.
+ T value;
+
+ /// domain of the image
+ p_runs_<P> domain_;
+
+ /// Return the size of the data in memory.
+ unsigned size_mem() const;
+ };
+
+ } // end of namespace mln::internal
+
+
+ namespace trait
+ {
+
+ template <typename P, typename T>
+ struct image_< mono_rle_image<P,T> > : default_image_< T, mono_rle_image<P,T> >
+ {
+ typedef trait::image::category::primary category;
+
+ typedef trait::image::access::browsing access;
+ // FIXME: Put the right dimension.
+ typedef trait::image::space::two_d space;
+ typedef trait::image::size::regular size;
+ typedef trait::image::support::aligned support;
+
+ typedef trait::image::border::none border;
+ typedef trait::image::data::linear data;
+ typedef trait::image::io::read_only io;
+ typedef trait::image::speed::slow speed;
+ };
+
+ } // end of namespace mln::trait
+
+
+ /*! \brief Mono RLE image.
+ *
+ * RLE image with only one colour.
+ *
+ * Parameter \c P is the type of the image points.
+ * Parameter \c T is the type of the pixel values.
+ * This image is not point wise accessible.
+ */
+ template <typename P, typename T>
+ class mono_rle_image : public internal::run_image_< T, P, mono_rle_image<P, T> >
+ {
+ public:
+ typedef T value;
+ typedef T& lvalue;
+ typedef const T rvalue;
+ typedef runs_psite<P> psite;
+ typedef mln::value::set<T> vset;
+ typedef p_runs_<P> pset;
+
+
+ /// Skeleton.
+ typedef mono_rle_image< tag::psite_<P>, tag::value_<T> > skeleton;
+
+
+ mono_rle_image(const T& val);
+
+ /// Add a new range to the image.
+ void insert(const p_run<P>& pr);
+
+ /// Read-only access to the image value located at point \p p.
+ rvalue operator() (const psite& site) const;
+
+ /// Read-write access to the image value located at point \p p.
+ lvalue operator() (const psite& site);
+
+ /// Test if this image has been initialized.
+ bool has_data() const;
+
+ /// Give the set of values of the image.
+ const vset& values() const;
+
+ /// Give the definition domain.
+ const pset& domain() const;
+
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace internal
+ {
+
+ // internal::data_< mono_rle_image<I,S> >
+
+ template <typename P, typename T>
+ inline
+ data_< mono_rle_image<P,T> >::data_(const T& val)
+ : value(val)
+ {
+ }
+
+ template <typename P, typename T>
+ inline
+ unsigned
+ data_< mono_rle_image<P,T> >::size_mem() const
+ {
+ return sizeof(T) + domain_.size_mem();
+ }
+
+ } // end of namespace mln::internal
+
+ template <typename P, typename T>
+ inline
+ mono_rle_image<P, T>::mono_rle_image(const T& val)
+ {
+ this->data_ = new internal::data_< mono_rle_image<P,T> >(val);
+ }
+
+ template <typename P, typename T>
+ inline
+ bool
+ mono_rle_image<P, T>::has_data() const
+ {
+ return true;
+ }
+
+ template <typename P, typename T>
+ inline
+ const typename mono_rle_image<P, T>::vset&
+ mono_rle_image<P, T>::values() const
+ {
+ return vset::the();
+ }
+
+ template <typename P, typename T>
+ inline
+ void
+ mono_rle_image<P, T>::insert(const p_run<P>& pr)
+ {
+ if (this->data_->domain_.nruns() != 0)
+ mln_assertion(pr.first() > this->data_->domain_[this->data_->domain_.nruns() - 1].first());
+ this->data_->domain_.insert(pr);
+ }
+
+ template <typename P, typename T>
+ inline
+ typename mono_rle_image<P, T>::rvalue
+ mono_rle_image<P, T>::operator() (const typename mono_rle_image<P, T>::psite& site)
+ const
+ {
+ mln_precondition(site.pset_pos_() < this->data_->domain_.nruns());
+ return this->data_->value;
+ }
+
+ template <typename P, typename T>
+ inline
+ typename mono_rle_image<P, T>::lvalue
+ mono_rle_image<P, T>::operator() (const typename mono_rle_image<P, T>::psite& site)
+ {
+ mln_precondition(site.pset_pos_() < this->data_->domain_.nruns());
+ return this->data_->value;
+ }
+
+ template <typename P, typename T>
+ inline
+ const typename mono_rle_image<P, T>::pset&
+ mono_rle_image<P, T>::domain() const
+ {
+ return this->data_->domain_;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_MONO_RLE_IMAGE_HH