
Index: ChangeLog from Nicolas Ballas <ballas@lrde.epita.fr> fix a bug on rle_encode, add a test. * olena/tests/core/3dtorle.cc: New test. * olena/tests/core/rle_image.cc: Update test. * olena/tests/core/Makefile.am: Update. * olena/oln/core/gen/rle_image.hh, * olena/oln/core/gen/rle_encode.hh: fix a bug. * olena/oln/core/concept/iterator_on_values.hh: change vit.to_point() to vit.to_value(). * olena/oln/core/internal/encoded_image.hh: small modifications. oln/core/concept/iterator_on_values.hh | 2 oln/core/gen/rle_encode.hh | 20 ++++++- oln/core/gen/rle_image.hh | 1 oln/core/internal/encoded_image.hh | 2 tests/core/3dtorle.cc | 91 +++++++++++++++++++++++++++++++++ tests/core/Makefile.am | 4 + tests/core/rle_image.cc | 6 ++ 7 files changed, 121 insertions(+), 5 deletions(-) Index: olena/tests/core/3dtorle.cc --- olena/tests/core/3dtorle.cc (revision 0) +++ olena/tests/core/3dtorle.cc (revision 0) @@ -0,0 +1,91 @@ +// Copyright (C) 2006 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#include <cassert> +#include <cmath> +#include <oln/core/3d/image3d.hh> +#include <oln/level/fill.hh> +#include <oln/debug/print.hh> +#include <ostream> +#include <oln/core/gen/rle_image.hh> +#include <oln/core/gen/rle_encode.hh> + +float my_sinus(const oln::point3d& p) +{ + return sin(p.sli() + p.row() + p.col()); +} + + +int +main() +{ + using namespace oln; + + // Fill a 3D image with a cos. + image3d<float> ima3d(100, 100, 100); + + level::fill(inplace(ima3d), my_sinus); + + + // Transform it into a 3 states image + // value < 0 => -1 + // value > 0 => 1 + // value next to 0 => 0 + image3d<short> ima3s(100, 100, 100); + image3d<float>::piter p(ima3d.points()); + for_all(p) + { + if (ima3d(p) < 0.05 && ima3d(p) > -0.05) + ima3s(p) = 0; + else + { + if (ima3d(p) < 0) + ima3s(p) = -1; + else + ima3s(p) = 1; + } + } + +// oln::debug::print(ima3s); +// std::cout << std::endl; + + // Encode ima3s into a rle_image + rle_image<point3d, short> ima3rle; + + + ima3rle = rle_encode(ima3s); + rle_image<point3d, short>::piter p1(ima3rle.points()); +// std::cout << "start test" << std::endl; +// for_all(p1) +// { +// // std::cout << "point: " << p1.to_point() << std::endl; +// // std::cout << "3s : " << ima3s(p1) << std::endl; +// // std::cout << "rle: " << ima3rle(p1) << std::endl; +// assert(ima3s(p1) == ima3rle(p1)); +// } + +} Index: olena/tests/core/rle_image.cc --- olena/tests/core/rle_image.cc (revision 953) +++ olena/tests/core/rle_image.cc (working copy) @@ -44,6 +44,12 @@ rle2 = rle_encode(ima2d); + oln::rle_image<oln::point2d, int>::piter p1(rle2.points()); + for_all(p1) + { + assert(ima2d(p1) == rle2(p1)); + } + // oln::debug::print(rle2); // std::cout << std::endl; Index: olena/tests/core/Makefile.am --- olena/tests/core/Makefile.am (revision 953) +++ olena/tests/core/Makefile.am (working copy) @@ -35,7 +35,8 @@ sparse_image \ stack \ subset \ - window2d + window2d \ + 3dtorle # Images and auxiliary structures. @@ -54,6 +55,7 @@ stack_SOURCES = stack.cc subset_SOURCES = subset.cc window2d_SOURCES = window2d.cc +3dtorle_SOURCES = 3dtorle.cc # Methods. at_SOURCES = at.cc Index: olena/oln/core/gen/rle_image.hh --- olena/oln/core/gen/rle_image.hh (revision 953) +++ olena/oln/core/gen/rle_image.hh (working copy) @@ -85,7 +85,6 @@ void insert(const point& p, unsigned len, value val); rvalue impl_read(const psite& p) const; lvalue impl_read_write(const psite& p); - }; # ifndef OLN_INCLUDE_ONLY Index: olena/oln/core/gen/rle_encode.hh --- olena/oln/core/gen/rle_encode.hh (revision 953) +++ olena/oln/core/gen/rle_encode.hh (working copy) @@ -38,6 +38,22 @@ { /*! + ** test if Point p1 and p2 are on the same line + */ + template <typename P> + bool + on_the_same_line(P p1, P p2) + { + unsigned dim = mlc_value(typename P::grid::dim); + bool same_line = true; + + for (int n = dim - 1; same_line && n > 0; --n) + same_line = p1[n] == p2[n]; + return same_line; + } + + + /*! ** encode an image class to a rle_image ** ** @param input has to respect the Image concept @@ -49,7 +65,7 @@ rle_encode(const Image<I>& input) { rle_image<typename I::point, typename I::value> output; - typename I::piter p (input.points()); + typename Image<I>::piter p (input.points()); unsigned len = 1; /// range point start typename I::point rstart; @@ -65,7 +81,7 @@ p.next(); while (p.is_valid()) { - if (rvalue == input(p)) + if (rvalue == input(p) && on_the_same_line(rstart, p.to_point())) ++len; else { Index: olena/oln/core/concept/iterator_on_values.hh --- olena/oln/core/concept/iterator_on_values.hh (revision 953) +++ olena/oln/core/concept/iterator_on_values.hh (working copy) @@ -85,7 +85,7 @@ template <typename Exact> std::ostream& operator<<(std::ostream& ostr, const Iterator_on_Values<Exact>& vit) { - return ostr << vit.to_point(); + return ostr << vit.to_value(); } # endif Index: olena/oln/core/internal/encoded_image.hh --- olena/oln/core/internal/encoded_image.hh (revision 953) +++ olena/oln/core/internal/encoded_image.hh (working copy) @@ -78,6 +78,8 @@ # ifndef OLN_INCLUDE_ONLY + + template <typename Exact> encoded_image_<Exact>::encoded_image_() {