Encore un probleme avec vcs, les modifications du patch 163 n'ont pas ete
commitees sur le repository, j'ai donc du le faire a la main...
--
Damien Thivolle
damien(a)lrde.epita.fr
Index: ChangeLog
from Damien Thivolle <damien(a)lrde.epita.fr>
* tests/utils/tests/invert: New.
* oln/funobj/invert.hh: Invert functor.
* oln/core/abstract/image_by_delegation.hh (image): Add missing method.
* oln/core/box.hh: Comment code that prevents from compiling with
g++-3.4.
* oln/core/pw/image.hh: Likewise.
* oln/utils/invert.hh: Inverted images implentation.
* oln/morpho/erosion.hh: Add a forward declaration to allow compilation
with g++-3.4.
oln/core/abstract/image_by_delegation.hh | 2
oln/core/box.hh | 6 +
oln/core/pw/image.hh | 28 ++++----
oln/funobj/invert.hh | 82 ++++++++++++++++++++++++
oln/morpho/erosion.hh | 26 ++++---
oln/utils/invert.hh | 103 +++++++++++++++++++++++++++++++
tests/utils/tests/invert | 38 +++++++++++
7 files changed, 258 insertions, 27 deletions
Index: tests/utils/tests/invert
--- tests/utils/tests/invert (revision 0)
+++ tests/utils/tests/invert (revision 0)
@@ -0,0 +1,38 @@
+#include "data.hh"
+
+#include <ntg/all.hh>
+
+#include <oln/basics2d.hh>
+#include <oln/utils/invert.hh>
+#include <oln/io/read_image.hh>
+#include <oln/level/compare.hh>
+
+
+bool check()
+{
+ oln::image2d<ntg::bin> ima_bin;
+ oln::image2d<ntg::int_u8> ima_int;
+ oln::image2d<ntg::rgb_8> ima_rgb;
+
+ ima_bin = oln::io::read(rdata("16x16.pbm"));
+ ima_int = oln::io::read(rdata("16x16.pgm"));
+ ima_rgb = oln::io::read(rdata("16x16.ppm"));
+
+ if (oln::level::is_equal(ima_bin,
+ oln::utils::invert(oln::utils::invert(ima_bin))) &&
+ oln::level::is_equal(ima_int,
+ oln::utils::invert(oln::utils::invert(ima_int))) &&
+ oln::level::is_equal(ima_rgb,
+ oln::utils::invert(oln::utils::invert(ima_rgb))))
+ {
+ std::cout << "OK" << std::endl;
+ return false;
+ }
+ else
+ {
+ std::cout << "FAIL" << std::endl;
+ return true;
+ }
+}
+
+
Index: oln/funobj/invert.hh
--- oln/funobj/invert.hh (revision 0)
+++ oln/funobj/invert.hh (revision 0)
@@ -0,0 +1,82 @@
+// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_FUNOBJ_INVERT_HH
+# define OLENA_FUNOBJ_INVERT_HH
+
+# include <mlc/contract.hh>
+
+# include <ntg/all.hh>
+
+namespace oln {
+
+ namespace funobj {
+
+ struct invert
+ {
+ template <typename V>
+ V operator()(const ntg::vect_value<V>& v) const
+ {
+ V ret;
+
+ for (unsigned i = 0; i < ntg_nb_comp(V); i++)
+ ret[i] = ntg_max_val(ntg_comp_type(V)) - v[i];
+ return ret;
+ }
+
+ template <typename V>
+ V operator()(const ntg::real_value<V>& v) const
+ {
+ V ret;
+
+ ret = ntg_max_val(V) - v;
+ return ret;
+ }
+
+ template <typename V>
+ V operator()(const ntg::enum_value<V>& v) const
+ {
+ V ret;
+ ntg_integer_type(V) max_val = ntg_max_val(V);
+ ntg_integer_type(V) value = v.exact();
+
+ ret = max_val - value;
+ return ret;
+ }
+
+ invert() {}
+
+ };
+
+ } // end of namespace funobj
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_FUNOBJ_INVERT_HH
+
+
Index: oln/core/abstract/image_by_delegation.hh
--- oln/core/abstract/image_by_delegation.hh (revision 161)
+++ oln/core/abstract/image_by_delegation.hh (working copy)
@@ -96,6 +96,7 @@
public:
+ I& image() { return this->image_.unbox(); }
I& impl_delegate() { return this->image_.unbox(); }
const I& impl_delegate() const { return this->image_.unbox(); }
};
@@ -128,6 +129,7 @@
public:
+ const I& image() const { return this->image_.unbox(); }
const I& impl_delegate() const { return this->image_.unbox(); }
};
Index: oln/core/box.hh
--- oln/core/box.hh (revision 161)
+++ oln/core/box.hh (working copy)
@@ -1,3 +1,4 @@
+
// Copyright (C) 2005 EPITA Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
@@ -130,7 +131,8 @@
template <typename II>
void operator=(const abstract::image<II>& rhs)
{
- mlc::false_type::ensure();
+ // FIXME: Does not work with g++-3.4.
+// mlc::false_type::ensure();
}
// FIXME: add versions for I2 (neq I) to produce explicit errors
@@ -218,7 +220,7 @@
return *this;
}
- /// Delegation relies on a constant image.
+ /// Delegation relies on a constant image.
const I& impl_delegate() const
{
return this->image_;
Index: oln/core/pw/image.hh
--- oln/core/pw/image.hh (revision 161)
+++ oln/core/pw/image.hh (working copy)
@@ -46,7 +46,7 @@
// fwd decl
namespace pw {
template <typename I> struct image;
- }
+ }
// super type
template <typename I>
@@ -192,7 +192,7 @@
void impl_resize_border(size_t new_border, bool copy_border) const
{
}
-
+
};
@@ -256,22 +256,22 @@
-
+ // FIXME: Does not work with g++-3.4.
/// Specialization of image_for_all_p that gives a compile-time error.
- template <typename I>
- void image_for_all_p(const abstract::image<I>&)
- {
- struct OLENA_ERROR__arg_of__image_for_all_p__should_not_be_an_image();
- }
+// template <typename I>
+// void image_for_all_p(const abstract::image<I>&)
+// {
+// struct OLENA_ERROR__arg_of__image_for_all_p__should_not_be_an_image();
+// }
- /// Specialization of image_for_all_p that gives a compile-time error.
+// /// Specialization of image_for_all_p that gives a compile-time error.
- template <typename P>
- void image_for_all_p(const abstract::point<P>&)
- {
- struct OLENA_ERROR__arg_of__image_for_all_p__should_not_be_a_point();
- }
+// template <typename P>
+// void image_for_all_p(const abstract::point<P>&)
+// {
+// struct OLENA_ERROR__arg_of__image_for_all_p__should_not_be_a_point();
+// }
Index: oln/utils/invert.hh
--- oln/utils/invert.hh (revision 0)
+++ oln/utils/invert.hh (revision 0)
@@ -0,0 +1,103 @@
+// Copyright (C) 2001, 2002, 2003, 2004, 2005 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, 59 Temple Place - Suite 330, 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 OLENA_CORE_UTILS_INVERT_HH
+# define OLENA_CORE_UTILS_INVERT_HH
+
+# include <oln/core/abstract/image_by_delegation.hh>
+# include <oln/funobj/invert.hh>
+
+namespace oln {
+
+ namespace utils {
+ template <typename I> struct image_inverted;
+ }
+
+ // super type
+
+ template <typename I>
+ struct set_super_type < utils::image_inverted<I> >
+ { typedef abstract::image_by_delegation<const I, utils::image_inverted<I> > ret; };
+
+ // props
+
+ template <typename I>
+ struct set_props < category::image, utils::image_inverted<I> >
+ {
+ typedef oln_type_of(I, concrete) concrete_type;
+ };
+
+
+
+ namespace utils {
+
+ template <typename I>
+ struct image_inverted :
+ public abstract::image_by_delegation<const I, image_inverted<I> >
+ {
+ typedef abstract::image_by_delegation<const I, image_inverted<I> > super_type;
+ typedef oln_type_of(I, value) value_type;
+ typedef oln_type_of(I, point) point_type;
+
+ public:
+
+ image_inverted()
+ {
+ }
+
+ image_inverted(const abstract::image<I>& image) :
+ super_type(image)
+ {
+ }
+
+ I& real() const
+ {
+ return this->image_.unbox();
+ }
+
+ const value_type impl_get(const point_type& p) const
+ {
+ const static oln::funobj::invert& obj = oln::funobj::invert();
+ return obj(this->image_[p].value());
+ }
+
+ };
+
+ template <typename I>
+ image_inverted<I> invert(const abstract::image<I>& input)
+ {
+ image_inverted<I> tmp(input);
+ return tmp;
+ }
+
+ } // end of namespace utils
+
+} // end of namespace oln
+
+#endif // ! OLENA_CORE_UTILS_INVERT_HH
+
Index: oln/morpho/erosion.hh
--- oln/morpho/erosion.hh (revision 161)
+++ oln/morpho/erosion.hh (working copy)
@@ -45,6 +45,10 @@
namespace morpho {
template <typename I> struct erosion_ret;
+
+ template<typename I, typename W>
+ erosion_ret<I> erosion(const abstract::image<I>& input,
+ const abstract::window<W>& win);
}
// super_type
@@ -126,13 +130,13 @@
void impl_run()
{
- oln_type_of(super_type, output) tmp(input.size()); // FIXME: trick
- output = tmp;
+ oln_type_of(super_type, output) tmp(this->input.size()); // FIXME: trick
+ this->output = tmp;
// FIXME: output.resize(input.size);
- oln_type_of(I, fwd_piter) p(input.size());
+ oln_type_of(I, fwd_piter) p(this->input.size());
for_all_p (p)
- output[p] = morpho::min(input, p, win);
+ this->output[p] = morpho::min(this->input, p, this->win);
}
};
@@ -146,10 +150,10 @@
tmp.run();
return tmp;
}
-
+
/// Rectangle2d implementation of erosion (type).
template <typename I>
@@ -171,11 +175,11 @@
box<oln_type_of(super_type, output)> temp; // FIXME: box?
// FIXME: output_type temp;
- win_hline2d hline(win.width);
- win_vline2d vline(win.height);
-
- temp = morpho::erosion(input, hline);
- output = morpho::erosion(temp, vline);
+ win_hline2d hline(this->win.width);
+ win_vline2d vline(this->win.height);
+
+ temp = oln::morpho::erosion(this->input, hline);
+ this->output = oln::morpho::erosion(temp, vline);
}
};
@@ -190,9 +194,9 @@
return tmp;
}
-
+
} // end of namespace oln::morpho::impl