Olena-patches
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- 9625 discussions
Index: ChangeLog
from Damien Thivolle <damien(a)lrde.epita.fr>
* configure.ac: Remove oln/arith from the OLN collection.
configure.ac | 1 -
1 files changed, 1 deletion(-)
Index: configure.ac
--- configure.ac (revision 191)
+++ configure.ac (working copy)
@@ -100,7 +100,6 @@
# OLN_TESTS defined in oln-local.m4
OLN_TESTS([sanity])
- OLN_TESTS([arith])
OLN_TESTS([convert])
OLN_TESTS([core])
OLN_TESTS([io])
1
0
Damien, il y a un problème avec les I/O, car le test io/2d échoue à
l'exécution :
brasilia~/src/oln % make -C _build/olena/tests/io check
make -C _build/olena/tests/io check
make: Entering directory `/home/levill_r/src/oln-proto-1.0/_build/olena/tests/io'
make check-local
make[1]: Entering directory `/home/levill_r/src/oln-proto-1.0/_build/olena/tests/io'
TOP_SRCDIR=../../../.. SRCDIR=../../../../olena/tests/io \
TOP_BUILDDIR=../../.. \
LDFLAGS=" " \
CPPFLAGS="-DHAVE_CONFIG_H -I../../../../metalic/tests/check -I../../../../olena/tests/check -I../../../../metalic -I../../../metalic -I../../../../integre -I../../../integre -I../../../../olena -I../../../olena -I../../.. -I../../../../olena/tests/io -I." \
CXXFLAGS=" -g -Wall -pedantic -Werror " \
LDADD="../check/libolncheck.a -lz" \
/bin/sh ../../../../contrib/runtests
FAIL: 2d (exits with $?=1)
========================================
1 failures.
make[1]: *** [check-runtests] Erreur 1
make[1]: Leaving directory `/home/levill_r/src/oln-proto-1.0/_build/olena/tests/io'
make: *** [check-am] Erreur 2
make: Leaving directory `/home/levill_r/src/oln-proto-1.0/_build/olena/tests/io'
https://svn.lrde.epita.fr/svn/oln/prototypes/proto-1.0
ChangeLog | 6 ++++++
tests/io/loadsave.hh | 9 ++-------
2 files changed, 8 insertions(+), 7 deletions(-)
Index: olena/ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Re-enable I/O tests.
* tests/io/loadsave.hh (loadsave): Really write and read images.
Index: olena/tests/io/loadsave.hh
--- olena/tests/io/loadsave.hh (revision 190)
+++ olena/tests/io/loadsave.hh (working copy)
@@ -38,13 +38,8 @@
T im1, im2;
im1 = oln::io::read(name);
-
-
-// oln::io::write(im1, savename);
-
-
-// im2 = oln::io::read(savename);
- im2 = oln::io::read(name);
+ oln::io::write(im1, savename);
+ im2 = oln::io::read(savename);
if (compare(im1, im2) == true)
std::cout << "OK" << std::endl;
1
0
Index: ChangeLog
from Damien Thivolle <damien(a)lrde.epita.fr>
* oln/core/gen/regular_window.hh: Repair window splitting methods.
* oln/morpho/reconstruction.hh: Add front end for self-dual
reconstruction.
* oln/morpho/reconstruction_by_dilation.hh: Make it compile.
* oln/morpho/tags.hh: Add self-dual tag.
* oln/morpho/reconstruction_selfdual.hh: New. Self-dual reconstruction
implementation
* oln/morpho/reconstruction_by_erosion.hh: Make it compile.
* oln/morpho/stat.trash: Remove
* oln/canvas/reconstruction.hh: Add a missing method in the sequential
canvas. Minor fixes.
canvas/reconstruction.hh | 14 ++-
core/gen/regular_window.hh | 22 ++---
morpho/reconstruction.hh | 39 ++++++----
morpho/reconstruction_by_dilation.hh | 79 +++++++++++---------
morpho/reconstruction_by_erosion.hh | 80 +++++++++++----------
morpho/reconstruction_selfdual.hh | 132 +++++++++++++++++++++++++++++++++++
morpho/stat.trash | 122 --------------------------------
morpho/tags.hh | 13 +++
8 files changed, 279 insertions(+), 222 deletions(-)
Index: oln/core/gen/regular_window.hh
--- oln/core/gen/regular_window.hh (revision 189)
+++ oln/core/gen/regular_window.hh (working copy)
@@ -122,11 +122,11 @@
}
- self_type get_fwd_win() const
+ E get_fwd_win() const
{
- self_type out;
+ E out;
- for (unsigned i = 0; i < this->card(); ++i)
+ for (unsigned i = 0; i < card(); ++i)
{
const dpoint_type& dp = dp_[i];
@@ -143,12 +143,12 @@
}
- self_type get_fwd_win_p() // abstract::window<W>& win)
+ E get_fwd_win_p() const // abstract::window<W>& win)
{
- self_type out;
+ E out;
- for (unsigned i = 0; i < this->card(); ++i)
+ for (unsigned i = 0; i < card(); ++i)
{
const dpoint_type& dp = dp_[i];
@@ -171,9 +171,9 @@
}
- self_type get_bkd_win()
+ E get_bkd_win() const
{
- self_type out;
+ E out;
for (unsigned i = 0; i < card(); ++i)
{
@@ -192,13 +192,13 @@
}
- self_type get_bkd_win_p()
+ E get_bkd_win_p() const
{
- self_type out;
+ E out;
for (unsigned i = 0; i < card(); ++i)
{
- const dpoint_type& dp = this->win.get_dp()[i];
+ const dpoint_type& dp = get_dp()[i];
unsigned n;
for (n = 0; n < dim; ++n)
Index: oln/morpho/reconstruction.hh
--- oln/morpho/reconstruction.hh (revision 189)
+++ oln/morpho/reconstruction.hh (working copy)
@@ -30,6 +30,7 @@
# include <oln/morpho/reconstruction_by_dilation.hh>
# include <oln/morpho/reconstruction_by_erosion.hh>
+# include <oln/morpho/reconstruction_selfdual.hh>
namespace oln {
@@ -41,12 +42,12 @@
// Generic implementation of reconstruction (routine).
- template<typename Op, typename A, typename I1, typename I2>
+ template<typename I1, typename I2, typename A, typename Op>
oln_type_of(I1, concrete)
reconstruction_(const abstract::image_with_nbh<I1>& marker,
const abstract::image<I2>& mask)
{
- reconstruction<Op, A, I1, I2> tmp(marker, mask);
+ reconstruction<I1, I2, A, Op> tmp(marker, mask);
// tmp.entering(); FIXME: something like that ?
tmp.run();
// tmp.exiting(); FIXME: something like that ?
@@ -57,12 +58,12 @@
/// Generic reconstruction (facade).
- template<typename Op, typename I1, typename I2, typename A>
+ template<typename I1, typename I2, typename A, typename Op>
oln_type_of(I1, concrete)
- reconstruction(const tag::oper<Op>& oper_,
- const abstract::image_with_nbh<I1>& marker,
+ reconstruction(const abstract::image_with_nbh<I1>& marker,
const abstract::image<I2>& mask,
- const tag::algo<A>& algo_)
+ const tag::algo<A>& ,
+ const tag::oper<Op>& )
{
mlc::eq<oln_type_of(I1, grid), oln_type_of(I2, grid)>::ensure();
precondition(marker.size() == mask.size());
@@ -70,13 +71,27 @@
entering("morpho::reconstruction");
oln_type_of(I1, concrete) output("output");
-// output = impl::reconstruction_(oper_, marker.exact(), mask.exact(), algo_);
+ output = impl::reconstruction_<I1, I2, A, Op>(marker.exact(),
+ mask.exact());
exiting("morpho::reconstruction");
return output;
}
+ // self dual
+
+ template <typename I1, typename I2>
+ oln_type_of(I1, concrete)
+ reconstruction_selfdual(const abstract::image_with_nbh<I1>& marker,
+ const abstract::image<I2>& mask)
+ {
+ mlc::eq<oln_type_of(I1, grid), oln_type_of(I2, grid)>::ensure();
+ precondition(marker.size() == mask.size());
+
+ return reconstruction(marker, mask, tag::selfdual(), tag::none());
+ }
+
// by dilation
template<typename I1, typename I2, typename A>
@@ -88,7 +103,7 @@
mlc::eq<oln_type_of(I1, grid), oln_type_of(I2, grid)>::ensure();
precondition(marker.size() == mask.size());
- return reconstruction(tag::by_dilation_type(), marker, mask, algo_);
+ return reconstruction(marker, mask, algo_, tag::by_dilation());
}
template<typename I1, typename I2>
@@ -99,8 +114,7 @@
mlc::eq<oln_type_of(I1, grid), oln_type_of(I2, grid)>::ensure();
precondition(marker.size() == mask.size());
- return reconstruction(tag::by_dilation_type(), marker,
- mask, tag::hybrid_type());
+ return reconstruction(marker, mask, tag::hybrid(), tag::by_dilation());
}
// by erosion
@@ -114,7 +128,7 @@
mlc::eq<oln_type_of(I1, grid), oln_type_of(I2, grid)>::ensure();
precondition(marker.size() == mask.size());
- return reconstruction(tag::by_erosion_type(), marker, mask, algo_);
+ return reconstruction(marker, mask, algo_, tag::by_erosion());
}
template<typename I1, typename I2>
@@ -125,8 +139,7 @@
mlc::eq<oln_type_of(I1, grid), oln_type_of(I2, grid)>::ensure();
precondition(marker.size() == mask.size());
- return reconstruction(tag::by_erosion_type(), marker,
- mask, tag::hybrid_type());
+ return reconstruction(marker, mask, tag::hybrid(), tag::by_erosion());
}
} // end of namespace oln::morpho
Index: oln/morpho/stat.trash
--- oln/morpho/stat.trash (revision 189)
+++ oln/morpho/stat.trash (working copy)
@@ -1,122 +0,0 @@
-// 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_MORPHO_STAT_HH
-# define OLENA_MORPHO_STAT_HH
-
-# include <mlc/cmp.hh>
-# include <ntg/bin.hh>
-# include <oln/core/abstract/image_entry.hh>
-# include <oln/core/abstract/window.hh>
-# include <oln/funobj/accum.hh>
-
-
-namespace oln {
-
- namespace morpho {
-
-
- /// Local min on a function.
-
- template <typename I, typename W>
- oln_type_of(I, value) min(const abstract::image<I>& input,
- const oln_type_of(I, point)& p,
- const abstract::window<W>& win)
- {
- mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
-
- oln_wn_type_of(W, fwd_iter) q(win);
- funobj::min_accumulator<oln_type_of(I, value)> minval;
-
- for_all_q_of_p (q, p)
- if (input.hold(q))
- minval(input[q]);
-
- return minval;
- }
-
-
- /// Local min on a set.
-
- template <typename I, typename W>
- bool min(const abstract::binary_image<I>& input,
- const oln_type_of(I, point)& p,
- const abstract::window<W>& win)
- {
- mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
-
- oln_wn_type_of(W, fwd_iter) q(win);
- for_all_q_of_p (q, p)
- if (input.hold(q) and not input[q])
- return false;
- return true;
- }
-
-
- /// Local max on a function.
-
- template <typename I, typename W>
- oln_type_of(I, value) max(const abstract::image<I>& input,
- const oln_type_of(I, point)& p,
- const abstract::window<W>& win)
- {
- mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
-
- oln_wn_type_of(W, fwd_iter) q(win);
- funobj::max_accumulator<oln_type_of(I, value)> maxval;
-
- for_all_q_of_p (q, p)
- if (input.hold(q))
- maxval(input[q]);
-
- return maxval;
- }
-
-
- /// Local max on a set.
-
- template <typename I, typename W>
- bool max(const abstract::binary_image<I>& input,
- const oln_type_of(I, point)& p,
- const abstract::window<W>& win)
- {
- mlc::eq<oln_type_of(I, grid), oln_wn_type_of(W, grid)>::ensure();
-
- oln_wn_type_of(W, fwd_iter) q(win);
- for_all_q_of_p (q, p)
- if (input.hold(q) and input[q])
- return true;
- return false;
- }
-
-
- } // end of namespace morpho
-
-} // end of namespace oln
-
-
-#endif // ! OLENA_MORPHO_STAT_HH
Index: oln/morpho/reconstruction_by_dilation.hh
--- oln/morpho/reconstruction_by_dilation.hh (revision 189)
+++ oln/morpho/reconstruction_by_dilation.hh (working copy)
@@ -39,12 +39,12 @@
// Sequential version
template<typename I1, typename I2>
- struct reconstruction <tag::by_dilation_type, tag::sequential_type, I1, I2>
+ struct reconstruction <I1, I2, tag::sequential_type, tag::by_dilation_type>
: public canvas::sequential_reconstruction<I1, I2,
- reconstruction<tag::by_dilation_type, tag::sequential_type, I1, I2> >
+ reconstruction<I1, I2, tag::sequential_type, tag::by_dilation_type> >
{
- typedef reconstruction<tag::by_dilation_type,
- tag::sequential_type, I1,I2> self_type;
+ typedef reconstruction<I1, I2, tag::sequential_type,
+ tag::by_dilation_type> self_type;
typedef canvas::sequential_reconstruction<I1, I2, self_type> super_type;
reconstruction(const abstract::image_with_nbh<I1>& marker,
@@ -53,27 +53,32 @@
{
}
+ using super_type::marker;
+ using super_type::mask;
+ using super_type::output;
+ using super_type::fwd_p;
+ using super_type::bkd_p;
+ using super_type::win_plus;
+ using super_type::win_minus;
void impl_bkd_loop_body()
{
- this->output[this->bkd_p] = ntg::min(morpho::max(this->output,
- this->bkd_p,
- this->win_minus),
- this->mask[this->bkd_p]);
+
+ //FIXME: Shouldn't be .value()
+ output[bkd_p] = ntg::min(local_max(output, bkd_p, win_minus),
+ mask[bkd_p].value());
}
void impl_fwd_loop_body()
{
- this->output[this->fwd_p] = ntg::min(morpho::max(this->output,
- this->fwd_p,
- this->win_plus),
- this->mask[this->fwd_p]);
+ output[fwd_p] = ntg::min(local_max(output, fwd_p, win_plus),
+ mask[fwd_p].value());
}
// FIXME: unused...
void impl_preconditions()
{
- precondition(level::is_greater_or_equal(this->mask, this->marker));
+ precondition(level::is_greater_or_equal(mask, marker));
}
};
@@ -82,15 +87,27 @@
// Hybrid version
template<typename I1, typename I2>
- struct reconstruction <tag::by_dilation_type, tag::hybrid_type, I1, I2>
+ struct reconstruction <I1, I2, tag::hybrid_type, tag::by_dilation_type>
: public canvas::hybrid_reconstruction<I1, I2,
- reconstruction<tag::by_dilation_type, tag::hybrid_type, I1, I2> >
+ reconstruction<I1, I2, tag::hybrid_type, tag::by_dilation_type> >
{
- typedef reconstruction<tag::by_dilation_type,
- tag::hybrid_type, I1,I2> self_type;
+ typedef reconstruction<I1, I2, tag::hybrid_type,
+ tag::by_dilation_type> self_type;
typedef canvas::hybrid_reconstruction<I1, I2,
self_type> super_type;
+ using super_type::mask;
+ using super_type::marker;
+ using super_type::work;
+ using super_type::output;
+ using super_type::fwd_p;
+ using super_type::bkd_p;
+ using super_type::win_plus;
+ using super_type::win_minus;
+ using super_type::p;
+ using super_type::q;
+ using super_type::fifo;
+
reconstruction(const abstract::image_with_nbh<I1>& marker,
const abstract::image<I2>& mask) :
super_type(marker, mask)
@@ -101,42 +118,34 @@
void impl_bkd_loop_body()
{
- this->output[this->bkd_p] = ntg::min(morpho::max(this->work,
- this->bkd_p,
- this->win_minus),
- this->mask[this->bkd_p]);
+ output[bkd_p] = min(local_max(work, bkd_p, win_minus),
+ mask[bkd_p].value());
}
void impl_fwd_loop_body()
{
- this->output[this->fwd_p] = ntg::min(morpho::max(this->work,
- this->fwd_p,
- this->win_plus),
- this->mask[this->fwd_p]);
+ output[fwd_p] = min(local_max(work, fwd_p, win_plus),
+ mask[fwd_p].value());
}
void impl_fifo_loop_body()
{
- if ((this->output[this->q] < this->output[this->p]) &&
- (this->mask[this->q] != this->output[this->q]))
+ if ((output[q] < output[p]) && (mask[q] != output[q]))
{
- this->output[this->q] = ntg::min(this->output[this->p],
- this->mask[this->q]);
- this->fifo.push(this->q);
+ output[q] = min(output[p].value(), mask[q].value());
+ fifo.push(q);
}
}
bool impl_exist_init()
{
- return this->output.hold(this->q) &&
- (this->output[this->q] < this->output[this->bkd_p]) &&
- (this->output[this->q] < this->mask[this->q]);
+ return output.hold(q) && (output[q] < output[bkd_p]) &&
+ (output[q] < mask[q]);
}
- //FIXME: unused...
void impl_preconditions()
{
- precondition(level::is_greater_or_equal(this->mask, this->marker));
+ precondition(level::is_greater_or_equal(mask, marker));
}
};
Index: oln/morpho/tags.hh
--- oln/morpho/tags.hh (revision 189)
+++ oln/morpho/tags.hh (working copy)
@@ -148,6 +148,7 @@
struct by_dilation_type : public oper< by_dilation_type > {};
struct by_erosion_type : public oper< by_erosion_type > {};
+ struct none_type : public oper< none_type > {};
// Facades.
inline const by_dilation_type& by_dilation()
@@ -162,6 +163,11 @@
return tag;
}
+ inline const none_type& none()
+ {
+ static const none_type tag = none_type();
+ return tag;
+ }
// Tags for common canvas.
@@ -170,6 +176,7 @@
struct sequential_type : public algo< sequential_type > {};
struct hybrid_type : public algo< hybrid_type > {};
struct parallel_type : public algo< parallel_type > {};
+ struct selfdual_type : public algo< selfdual_type > {};
struct unionfind_type : public algo< unionfind_type > {};
// Facades.
@@ -191,6 +198,12 @@
return tag;
}
+ inline const selfdual_type& selfdual()
+ {
+ static const selfdual_type tag = selfdual_type();
+ return tag;
+ }
+
inline const unionfind_type& unionfind()
{
static const unionfind_type tag = unionfind_type();
Index: oln/morpho/reconstruction_selfdual.hh
--- oln/morpho/reconstruction_selfdual.hh (revision 0)
+++ oln/morpho/reconstruction_selfdual.hh (revision 0)
@@ -0,0 +1,132 @@
+// 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 filek 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_MORPHO_RECONSTRUCTION_SELF_DUAL_HH
+# define OLENA_MORPHO_RECONSTRUCTION_SELF_DUAL_HH
+
+# include <oln/canvas/reconstruction.hh>
+# include <oln/morpho/tags.hh>
+
+namespace oln {
+
+
+ namespace morpho {
+
+
+ namespace impl {
+
+
+ template<typename I1, typename I2>
+ struct reconstruction <I1, I2, tag::selfdual_type, tag::none_type>
+ : public canvas::hybrid_reconstruction<I1, I2,
+ reconstruction<I1, I2, tag::selfdual_type, tag::none_type> >
+ {
+ typedef reconstruction<I1, I2, tag::selfdual_type,
+ tag::none_type> self_type;
+ typedef canvas::hybrid_reconstruction<I1, I2,
+ self_type> super_type;
+
+ reconstruction(const abstract::image_with_nbh<I1>& marker,
+ const abstract::image<I2>& mask) :
+ super_type(marker, mask)
+ {
+ }
+
+ using super_type::mask;
+ using super_type::marker;
+ using super_type::work;
+ using super_type::output;
+ using super_type::fwd_p;
+ using super_type::bkd_p;
+ using super_type::win_plus;
+ using super_type::win_minus;
+ using super_type::p;
+ using super_type::q;
+ using super_type::fifo;
+
+
+ void impl_bkd_loop_body()
+ {
+ // FIXME: Shouldn't be .value() !
+ if (work[bkd_p] < mask[bkd_p])
+ output[bkd_p] = ntg::min(local_max(work, bkd_p, win_minus),
+ mask[bkd_p].value());
+ else
+ output[bkd_p] = ntg::max(local_min(work, bkd_p, win_minus),
+ mask[bkd_p].value());
+ }
+
+ void impl_fwd_loop_body()
+ {
+ // FIXME: Shouldn't be .value() !
+ if (work[fwd_p] < mask[fwd_p])
+ output[fwd_p] = ntg::min(local_max(work, fwd_p, win_plus),
+ mask[fwd_p].value());
+ else
+ output[fwd_p] = ntg::max(local_min(work, fwd_p, win_plus),
+ mask[fwd_p].value());
+ }
+
+ void impl_fifo_loop_body()
+ {
+ if (output[q] < mask[p])
+ {
+ if (output[q] < output[p] && mask[q] != output[q])
+ {
+ output[q] = ntg::min(output[p].value(), mask[q].value());
+ fifo.push(q);
+ }
+ }
+ else
+ if (output[q] > output[p] && mask[q] != output[q])
+ {
+ output[q] = ntg::max(output[p].value(), mask[q].value());
+ fifo.push(q);
+ }
+ }
+
+ bool impl_exist_init()
+ {
+ return output.hold(q) &&
+ ((output[q] < output[bkd_p] && output[q] < mask[q]) ||
+ (output[q] > output[bkd_p] && output[q] > mask[q]));
+ }
+
+ void impl_preconditions()
+ {
+ }
+
+ };
+
+ }
+
+ }
+
+}
+
+
+#endif // ! OLENA_MORPHO_RECONSTRUCTION_BY_DILATION_HH
Index: oln/morpho/reconstruction_by_erosion.hh
--- oln/morpho/reconstruction_by_erosion.hh (revision 189)
+++ oln/morpho/reconstruction_by_erosion.hh (working copy)
@@ -40,42 +40,45 @@
// Sequential version
template<typename I1, typename I2>
- struct reconstruction <tag::by_erosion_type, tag::sequential_type, I1, I2>
+ struct reconstruction <I1, I2, tag::sequential_type, tag::by_erosion_type>
: public canvas::sequential_reconstruction<I1, I2,
- reconstruction<tag::by_erosion_type,
- tag::sequential_type, I1, I2> >
+ reconstruction<I1, I2, tag::sequential_type,
+ tag::by_erosion_type> >
{
- typedef reconstruction<tag::by_erosion_type,
- tag::sequential_type, I1, I2> self_type;
+ typedef reconstruction<I1, I2, tag::sequential_type,
+ tag::by_erosion_type> self_type;
typedef canvas::sequential_reconstruction<I1, I2, self_type> super_type;
reconstruction(const abstract::image_with_nbh<I1>& marker,
- const abstract::image<I2>& mask) :
+ const abstract::image<I2>& mask) :
super_type(marker, mask)
{
}
+ using super_type::marker;
+ using super_type::mask;
+ using super_type::output;
+ using super_type::fwd_p;
+ using super_type::bkd_p;
+ using super_type::win_plus;
+ using super_type::win_minus;
void impl_bkd_loop_body()
{
- this->output[this->bkd_p] = ntg::max(morpho::min(this->output,
- this->bkd_p,
- this->win_minus),
- this->mask[this->bkd_p]);
+ output[bkd_p] = ntg::max(local_min(output, bkd_p, win_minus),
+ mask[bkd_p].value());
}
void impl_fwd_loop_body()
{
- this->output[this->fwd_p] = ntg::max(morpho::min(this->output,
- this->fwd_p,
- this->win_plus),
- this->mask[this->fwd_p]);
+ output[fwd_p] = ntg::max(local_min(output, fwd_p, win_plus),
+ mask[fwd_p].value());
}
// FIXME: unused...
void impl_preconditions()
{
- precondition(level::is_greater_or_equal(this->marker, this->mask));
+ precondition(level::is_greater_or_equal(marker, mask));
}
};
@@ -83,12 +86,12 @@
// Hybrid version
template<typename I1, typename I2>
- struct reconstruction <tag::by_erosion_type, tag::hybrid_type, I1, I2>
+ struct reconstruction <I1, I2, tag::hybrid_type, tag::by_erosion_type>
: public canvas::hybrid_reconstruction<I1, I2,
- reconstruction<tag::by_erosion_type, tag::hybrid_type, I1, I2> >
+ reconstruction<I1, I2, tag::hybrid_type, tag::by_erosion_type> >
{
- typedef reconstruction<tag::by_erosion_type,
- tag::hybrid_type, I1,I2> self_type;
+ typedef reconstruction<I1, I2, tag::hybrid_type,
+ tag::by_erosion_type> self_type;
typedef canvas::hybrid_reconstruction<I1, I2,
self_type> super_type;
@@ -98,44 +101,49 @@
{
}
+ using super_type::mask;
+ using super_type::marker;
+ using super_type::work;
+ using super_type::output;
+ using super_type::fwd_p;
+ using super_type::bkd_p;
+ using super_type::win_plus;
+ using super_type::win_minus;
+ using super_type::p;
+ using super_type::q;
+ using super_type::fifo;
+
void impl_bkd_loop_body()
{
- this->output[this->bkd_p] = ntg::max(morpho::min(this->work,
- this->bkd_p,
- this->win_minus),
- this->mask[this->bkd_p]);
+ output[bkd_p] = ntg::max(local_min(work, bkd_p, win_minus),
+ mask[bkd_p].value());
}
void impl_fwd_loop_body()
{
- this->output[this->fwd_p] = ntg::max(morpho::min(this->work,
- this->fwd_p,
- this->win_plus),
- this->mask[this->fwd_p]);
+ output[fwd_p] = ntg::max(local_min(work, fwd_p, win_plus),
+ mask[fwd_p].value());
}
void impl_fifo_loop_body()
{
- if ((this->output[this->q] > this->output[this->p]) &&
- (this->mask[this->q] != this->output[this->q]))
+ if ((output[q] > output[p]) && (mask[q] != output[q]))
{
- this->output[this->q] = ntg::min(this->output[this->p],
- this->mask[this->q]);
- this->fifo.push(this->q);
+ output[q] = ntg::min(output[p].value(), mask[q].value());
+ fifo.push(q);
}
}
bool impl_exist_init()
{
- return this->output.hold(this->q) &&
- (this->output[this->q] > this->output[this->bkd_p]) &&
- (this->output[this->q] > this->mask[this->q]);
+ return output.hold(q) && (output[q] > output[bkd_p]) &&
+ (output[q] > mask[q]);
}
// FIXME: unused...
void impl_preconditions()
{
- precondition(level::is_greater_or_equal(this->marker, this->mask));
+ precondition(level::is_greater_or_equal(marker, mask));
}
};
Index: oln/canvas/reconstruction.hh
--- oln/canvas/reconstruction.hh (revision 189)
+++ oln/canvas/reconstruction.hh (working copy)
@@ -144,15 +144,12 @@
~hybrid_reconstruction()
{
- mlc_check_method_impl(E, void, exist_init, , );
+ mlc_check_method_impl(E, bool, exist_init, , );
mlc_check_method_impl(E, void, bkd_loop_body, , );
mlc_check_method_impl(E, void, fwd_loop_body, , );
mlc_check_method_impl(E, void, fifo_loop_body, , );
}
- oln_type_of(I1, bkd_piter) bkd_p;
- oln_type_of(I1, fwd_piter) fwd_p;
-
oln_type_of(I1, point) p;
oln_type_of(I1, point) q;
@@ -164,6 +161,9 @@
box<const I1> marker;
box<const I2> mask;
+ oln_type_of(I1, bkd_piter) bkd_p;
+ oln_type_of(I1, fwd_piter) fwd_p;
+
std::queue<oln_type_of(I1, point) > fifo;
};
@@ -185,11 +185,15 @@
win_minus = marker.nbh_get().get_win().get_bkd_win_p();
}
- bool impl_is_stable()
+ bool impl_is_stable() const
{
return level::is_equal(work, output);
}
+ void impl_re_loop()
+ {
+ work = clone(output);
+ }
oln_type_of(I1, concrete) get_output()
{
1
0
Index: ChangeLog
from Damien Thivolle <damien(a)lrde.epita.fr>
* tests/io/tests/2d: Add tests.
* tests/io/loadsave.hh: Adapt to new iterators API.
* oln/core/2d/image2d.hh: Restore I/O operator=.
* oln/core/gen/regular_window.hh: Add missing `this->'.
* oln/io/write_image_pnm.hh: New. Add a generic front end for pnm files
writing.
* oln/io/read_image_pnm.hh: New. Add a generic front end for pnm files
reading.
* oln/io/write_image_2d_pnm.hh: Remove.
* oln/io/gz_stream.hh: Restore file.
* oln/io/write_image_pnm_2d.hh: New. Add 2D implementations for pnm
output.
* oln/io/read_image_2d_pnm.hh: Remove.
* oln/io/write_image.hh: Adapt to changes that occured in the pnm front
end.
* oln/io/read_image_pnm_2d.hh: New. Add 2D implementations for pnm
input.
* oln/io/read_image.hh: Adapt to changes that occured in the pnm front
end.
* oln/io/write_image_pnm_decl.hh: New. Forward declarations.
* oln/io/read_image_pnm_decl.hh: New. Forward declarations.
* oln/io/utils.hh: Restore file.
* oln/canvas/reconstruction.hh: Add use of oln::box.
* oln/canvas/io.hh: Add canvas for 1D and 2D images.
oln/canvas/io.hh | 116 ++++++
oln/canvas/reconstruction.hh | 8
oln/core/2d/image2d.hh | 6
oln/core/gen/regular_window.hh | 2
oln/io/gz_stream.hh | 728 ++++++++++++++++++++---------------------
oln/io/read_image.hh | 139 +++----
oln/io/read_image_2d_pnm.hh | 187 ----------
oln/io/read_image_pnm.hh | 157 ++++++++
oln/io/read_image_pnm_2d.hh | 166 +++++++++
oln/io/read_image_pnm_decl.hh | 57 +++
oln/io/utils.hh | 233 ++++++-------
oln/io/write_image.hh | 126 +++----
oln/io/write_image_2d_pnm.hh | 225 ------------
oln/io/write_image_pnm.hh | 173 +++++++++
oln/io/write_image_pnm_2d.hh | 153 ++++++++
oln/io/write_image_pnm_decl.hh | 57 +++
tests/io/loadsave.hh | 10
tests/io/tests/2d | 12
18 files changed, 1492 insertions(+), 1063 deletions(-)
Index: tests/io/tests/2d
--- tests/io/tests/2d (revision 188)
+++ tests/io/tests/2d (working copy)
@@ -37,15 +37,27 @@
typedef oln::image2d<ntg::int_u8> ima_int_u8;
typedef oln::image2d<ntg::rgb_8> ima_rgb_8;
typedef oln::image2d<ntg::bin> ima_bin;
+ typedef oln::image2d<ntg::int_s8> ima_int_s8;
+ typedef oln::image2d<bool> ima_bool;
+ typedef oln::image2d<unsigned char> ima_uchar;
+ typedef oln::image2d<signed char> ima_schar;
fail |= loadsave< ima_int_u8 >(rdata("16x16.pgm"), "16x16.pgm");
fail |= loadsave< ima_bin >(rdata("16x16.pbm"), "16x16.pbm");
fail |= loadsave< ima_rgb_8 >(rdata("16x16.ppm"), "16x16.ppm");
+ fail |= loadsave< ima_int_s8 >(rdata("16x16.pgm"), "16x16.pgm");
+ fail |= loadsave< ima_bool >(rdata("16x16.pbm"), "16x16.pbm");
+ fail |= loadsave< ima_uchar >(rdata("16x16.pgm"), "16x16.pgm");
+ fail |= loadsave< ima_schar >(rdata("16x16.pgm"), "16x16.pgm");
#if HAVE_ZLIB
fail |= loadsave< ima_bin >(rdata("16x16.pbm.gz"), "16x16.pbm.gz");
fail |= loadsave< ima_int_u8 >(rdata("16x16.pgm.gz"), "16x16.pgm.gz");
fail |= loadsave< ima_rgb_8 >(rdata("16x16.ppm.gz"), "16x16.ppm.gz");
+ fail |= loadsave< ima_int_s8 >(rdata("16x16.pgm.gz"), "16x16.pgm.gz");
+ fail |= loadsave< ima_bool >(rdata("16x16.pbm.gz"), "16x16.pbm.gz");
+ fail |= loadsave< ima_uchar >(rdata("16x16.pgm.gz"), "16x16.pgm.gz");
+ fail |= loadsave< ima_schar >(rdata("16x16.pgm.gz"), "16x16.pgm.gz");
#endif
return fail;
Index: tests/io/loadsave.hh
--- tests/io/loadsave.hh (revision 188)
+++ tests/io/loadsave.hh (working copy)
@@ -1,8 +1,8 @@
-#include <oln/basics1d.hh>
-#include <oln/basics2d.hh>
-#include <oln/basics3d.hh>
-#include <oln/all.hh>
+#include <oln/io/write_image.hh>
+#include <oln/io/read_image.hh>
+#include <oln/core/abstract/piter.hh>
+
#include <ntg/all.hh>
#include "check.hh"
@@ -20,7 +20,7 @@
a.size().ncols() != b.size().ncols())
return false;
- for_all(it)
+ for_all_p(it)
{
if (a[it] != b[it])
return false;
Index: oln/core/2d/image2d.hh
--- oln/core/2d/image2d.hh (revision 188)
+++ oln/core/2d/image2d.hh (working copy)
@@ -190,9 +190,9 @@
image2d& operator=(const io::filename& rhs)
{
// FIXME HERE: hack to avoid calling io
-// io::do_read(*this, rhs);
- image2d tmp(4, 4);
- *this = tmp;
+ io::do_read(*this, rhs);
+// image2d tmp(4, 4);
+// *this = tmp;
return *this;
}
Index: oln/core/gen/regular_window.hh
--- oln/core/gen/regular_window.hh (revision 188)
+++ oln/core/gen/regular_window.hh (working copy)
@@ -198,7 +198,7 @@
for (unsigned i = 0; i < card(); ++i)
{
- const dpoint_type& dp = win.get_dp()[i];
+ const dpoint_type& dp = this->win.get_dp()[i];
unsigned n;
for (n = 0; n < dim; ++n)
Index: oln/io/write_image_pnm.hh
--- oln/io/write_image_pnm.hh (revision 0)
+++ oln/io/write_image_pnm.hh (revision 0)
@@ -0,0 +1,173 @@
+// 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 OLN_IO_WRITE_IMAGE_PNM_HH
+# define OLN_IO_WRITE_IMAGE_PNM_HH
+
+# include <oln/io/write_image_pnm_decl.hh>
+# include <oln/io/write_image_pnm_2d.hh>
+
+namespace oln {
+
+
+ namespace io {
+
+
+ namespace impl {
+
+
+ template <typename V, typename I>
+ void write_pnm_(const ntg::real_value<V>&,
+ const abstract::image<I>& ima,
+ std::ostream& istr,
+ const std::string& ext)
+ {
+ typedef oln_type_of(I, size) size_type;
+
+ if (ext == "pgm")
+ {
+ write_pnm_real<I, size_type> tmp(ima, istr);
+
+ tmp.run();
+ }
+ else
+ std::cerr << "io error: extension mismatch data type" << std::endl;
+ }
+
+ template <typename V, typename I>
+ void write_pnm_(const ntg::enum_value<V>&,
+ const abstract::image<I>& ima,
+ std::ostream& ostr,
+ const std::string& ext)
+ {
+ typedef oln_type_of(I, size) size_type;
+
+ if (ext == "pbm")
+ {
+ write_pnm_bin<I, size_type> tmp(ima, ostr);
+
+ tmp.run();
+ }
+ else
+ std::cerr << "io error: extension mismatch data type" << std::endl;
+ }
+
+ template <typename V, typename I>
+ void write_pnm_(const ntg::vect_value<V>&,
+ const abstract::image<I>& ima,
+ std::ostream& ostr,
+ const std::string& ext)
+ {
+ typedef oln_type_of(I, size) size_type;
+ precondition(ntg_nb_comp(V) == 3);
+
+ if (ext == "ppm")
+ {
+ write_pnm_vect<I, size_type> tmp(ima, ostr);
+
+ tmp.run();
+ }
+ else
+ std::cerr << "io error: extension mismatch data type" << std::endl;
+ }
+
+ template <typename V, typename I>
+ void write_pnm(const ntg::value<V>& v,
+ const abstract::image<I>& ima,
+ std::ostream& ostr,
+ const std::string& ext)
+ {
+ write_pnm_(v.exact(), ima.exact(), ostr, ext);
+ }
+
+ }
+
+
+ template <typename V>
+ std::string get_pnm_type(const ntg::enum_value<V>&)
+ {
+ return "P4";
+ }
+
+ template <typename V>
+ std::string get_pnm_type(const ntg::real_value<V>&)
+ {
+ return "P5";
+ }
+
+ template <typename V>
+ std::string get_pnm_type(const ntg::vect_value<V>&)
+ {
+ return "P6";
+ }
+
+ template <typename V>
+ int get_max_val(const ntg::value<V>&)
+ {
+ return ntg_max_val(V) - ntg_min_val(V);
+ }
+
+ template <typename V>
+ int get_max_val(const ntg::vect_value<V>&)
+ {
+ return ntg_max_val(ntg_comp_type(V)) - ntg_min_val(ntg_comp_type(V));
+ }
+
+
+ template <typename I>
+ void write_pnm(const abstract::image<I>& ima,
+ std::ostream& ostr,
+ const std::string& ext)
+ {
+ typedef oln_type_of(I, value) value_type;
+ typedef ntg_type(value_type) ntg_value_type;
+ int max_val = get_max_val(ntg_value_type());
+
+ if (max_val <= 65535)
+ {
+ internal::write_pnm_header(ostr, get_pnm_type(ntg_value_type()),
+ ima.exact().size().ncols(),
+ ima.exact().size().nrows(),
+ max_val);
+
+ impl::write_pnm(ntg_value_type(), ima.exact(), ostr, ext);
+ }
+ else
+ std::cerr << "io error: data type too large" << std::endl;
+
+
+ }
+
+
+ }
+
+
+}
+
+
+
+# endif // ! OLN_IO_WRITE_IMAGE_PNM_HH
Index: oln/io/read_image_pnm.hh
--- oln/io/read_image_pnm.hh (revision 0)
+++ oln/io/read_image_pnm.hh (revision 0)
@@ -0,0 +1,157 @@
+ // 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 OLN_IO_READ_IMAGE_PNM_HH
+# define OLN_IO_READ_IMAGE_PNM_HH
+
+# include <iostream>
+# include <string>
+
+# include <oln/io/read_image_pnm_decl.hh>
+# include <oln/io/read_image_pnm_2d.hh>
+# include <oln/core/abstract/image.hh>
+# include <oln/io/utils.hh>
+
+namespace oln {
+
+
+ namespace io {
+
+
+ namespace impl {
+
+ template <typename V, typename I>
+ void read_pnm_(const ntg::real_value<V>&,
+ abstract::image<I>& ima,
+ std::istream& istr,
+ const internal::pnm_header &hdr)
+ {
+ typedef oln_type_of(I, size) size_type;
+
+ if (hdr.type == "P5")
+ {
+ read_pnm_real<I, size_type> tmp(istr, hdr);
+
+ tmp.run();
+ tmp.get_output(ima.exact());
+ }
+ else
+ std::cerr << "io error: pnm type mismatch data type" << std::endl;
+ }
+
+ template <typename V, typename I>
+ void read_pnm_(const ntg::enum_value<V>&,
+ abstract::image<I>& ima,
+ std::istream& istr,
+ const internal::pnm_header &hdr)
+ {
+ typedef oln_type_of(I, size) size_type;
+
+ if (hdr.type == "P4")
+ {
+ read_pnm_bin<I, size_type> tmp(istr, hdr);
+
+ tmp.run();
+ tmp.get_output(ima.exact());
+ }
+ else
+ std::cerr << "io error: pnm type mismatch data type" << std::endl;
+ }
+
+ template <typename V, typename I>
+ void read_pnm_(const ntg::vect_value<V>&,
+ abstract::image<I>& ima,
+ std::istream& istr,
+ const internal::pnm_header &hdr)
+ {
+ typedef oln_type_of(I, size) size_type;
+
+ if (hdr.type == "P6")
+ {
+ read_pnm_vect<I, size_type> tmp(istr, hdr);
+
+ tmp.run();
+ tmp.get_output(ima.exact());
+ }
+ else
+ std::cerr << "io error: pnm type mismatch data type" << std::endl;
+ }
+
+ template <typename V, typename I>
+ void read_pnm(const ntg::value<V>& v,
+ abstract::image<I>& ima,
+ std::istream& istr,
+ const internal::pnm_header &hdr)
+ {
+ read_pnm_(v.exact(), ima.exact(), istr, hdr);
+ }
+
+ }
+
+
+ void check_hdr_ext(const internal::pnm_header& hdr,
+ const std::string& ext)
+ {
+ if ((ext == "pbm" && hdr.type != "P4") ||
+ (ext == "pgm" && hdr.type != "P5") ||
+ (ext == "ppm" && hdr.type != "P6"))
+ std::cerr << "io warning: extension mismatch pnm type." << std::cerr;
+ }
+
+
+
+ template <typename I>
+ void read_pnm(abstract::image<I>& ima,
+ std::istream& istr,
+ const std::string& ext)
+ {
+ typedef oln_type_of(I, value) value_type;
+ typedef ntg_type(value_type) ntg_value_type;
+ internal::pnm_header hdr;
+
+ if (!internal::read_pnm_header(istr, hdr))
+ {
+ std::cerr << "io error: invalid pnm header." << std::cerr;
+ return;
+ }
+
+ if (hdr.type == "P1" || hdr.type == "P2" || hdr.type == "P3")
+ std::cerr << "io error: ascii pnm format not supported." << std::endl;
+
+ check_hdr_ext(hdr, ext);
+
+ impl::read_pnm(ntg_value_type(), ima, istr, hdr);
+
+ }
+
+
+ }
+
+
+}
+
+#endif // ! OLN_IO_READ_IMAGE_PNM_HH
Index: oln/io/write_image_2d_pnm.hh
--- oln/io/write_image_2d_pnm.hh (revision 188)
+++ oln/io/write_image_2d_pnm.hh (working copy)
@@ -1,225 +0,0 @@
-// 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 OLN_IO_WRITE_IMAGE_2D_PNM_HH
-# define OLN_IO_WRITE_IMAGE_2D_PNM_HH
-
-// # include <iostream>
-// # include <string>
-
-// # include <mlc/box.hh>
-
-// # include <ntg/all.hh>
-
-// # include <oln/core/2d/image2d.hh>
-
-// // commented cause 'void_op' was removed
-// //# include <oln/core/abstract/op.hh>
-
-// # include <oln/io/utils.hh>
-
-// namespace oln {
-
-// namespace io {
-
-// namespace impl {
-
-// template <typename I>
-// struct write_image_2d_raw
-// // commented below cause 'void_op' was removed
-// // : public oln::abstract::void_op<write_image_2d_raw<I> >
-// {
-// typedef oln_type_of(I, value) value_type;
-
-// const I& to_write_;
-// std::ostream& ostr_;
-// int bin_offset;
-// char bin_v;
-
-
-// write_image_2d_raw(const I& to_write, std::ostream& ostr):
-// to_write_(to_write),
-// ostr_(ostr)
-// {
-// bin_offset = 7;
-// bin_v = 0;
-// }
-
-// void run()
-// {
-// point2d p;
-// value_type c;
-
-// for (p.row() = 0; p.row() < to_write_.size().nrows(); ++p.row())
-// {
-// for (p.col() = 0; p.col() < to_write_.size().ncols(); ++p.col())
-// // FIXME: SHOULD NOT BE .value() !!!
-// write_value_type(to_write_[p].value());
-// write_padding(c);
-// }
-// }
-
-// template <typename E>
-// void write_padding(const ntg::value<E>&) {}
-
-// void write_padding(const ntg::bin&)
-// {
-// if (bin_offset != 7)
-// {
-// ostr_.write(&bin_v, 1);
-// bin_offset = 7;
-// bin_v = 0;
-// }
-// }
-
-// //FIXME: Should work with builtin types.
-
-// template <typename E>
-// void write_value_type(const ntg::real_value<E> &c)
-// {
-// typedef oln_io_type(ntg_nbits(E)) v_type;
-
-// v_type v;
-// v = ntg::cast::bound<E, v_type>(c.exact());
-// ostr_.write((char*)&v, sizeof (v_type));
-// }
-
-// template <typename E>
-// void write_value_type(const ntg::vect_value<E> &c)
-// {
-// for (unsigned i = 0; i < 3; i++)
-// {
-// typedef oln_io_type(ntg_nbits(ntg_comp_type(value_type))) v_type;
-
-// v_type v;
-// v = c[i];
-// ostr_.write((char*)&v, sizeof (v_type));
-// }
-// }
-
-// void write_value_type(const ntg::bin &c)
-// {
-// if (bin_offset == -1)
-// {
-// ostr_.write(&bin_v, 1);
-// bin_offset = 7;
-// bin_v = 0;
-// }
-// if (c == value_type(1))
-// bin_v |= 1 << bin_offset;
-// bin_offset--;
-// }
-// };
-
-
-// template <typename I, typename T>
-// void write(const abstract::image2d<I>& to_write,
-// const ntg::real_value<T>&,
-// std::ostream& ostr,
-// const std::string& ext)
-// {
-
-// point2d p;
-// size2d s = to_write.size();
-
-// precondition(ntg_nbits(T) <= 16);
-// if (ext == "pgm")
-// if (internal::write_pnm_header(ostr, "P5",
-// s.ncols(), s.nrows(),
-// ntg_max_val(T)))
-// {
-// write_image_2d_raw<I> tmp(to_write.exact(), ostr);
-// tmp.run();
-// }
-// else
-// std::cerr << "error: unable to write file header" << std::endl;
-// else
-// std::cerr << "error: image data type (`integer') does not match"
-// << " file extension (`" << ext << "')" << std::endl;
-// }
-
-// template <typename I, typename T>
-// void write(const abstract::image2d<I>& to_write,
-// const ntg::color_value<T>&,
-// std::ostream& ostr,
-// const std::string& ext)
-// {
-
-// point2d p;
-// size2d s = to_write.size();
-
-// precondition(ntg_nbits(ntg_comp_type(T)) <= 16);
-// precondition(ntg_nb_comp(T) == 3);
-// if (ext == "ppm")
-// if (internal::write_pnm_header(ostr, "P6",
-// s.ncols(), s.nrows(),
-// ntg_max_val(ntg_comp_type(T))))
-// {
-// write_image_2d_raw<I> tmp(to_write.exact(), ostr);
-// tmp.run();
-// }
-// else
-// std::cerr << "error: unable to write header" << std::endl;
-// else
-// std::cerr << "error: image data type (`color') does not match"
-// << " file extension (`" << ext << "')" << std::endl;
-// }
-
-// template <typename I>
-// void write(const abstract::image2d<I>& to_write,
-// const ntg::bin&,
-// std::ostream& ostr,
-// const std::string& ext)
-// {
-// point2d p;
-// size2d s = to_write.size();
-
-// if (ext == "pbm")
-// if (internal::write_pnm_header(ostr, "P4",
-// s.ncols(), s.nrows(),
-// 1))
-// {
-// write_image_2d_raw<I> tmp(to_write.exact(), ostr);
-// tmp.run();
-// }
-// else
-// std::cerr << "error: unable to write header" << std::endl;
-// else
-// std::cerr << "error: image data type (`enum_value') does not match"
-// << " file extension (`" << ext << "')" << std::endl;
-// }
-
-// }
-
-// }
-
-// }
-
-
-
-#endif // ! OLN_IO_WRITE_IMAGE_2D_PNM_HH
Index: oln/io/gz_stream.hh
--- oln/io/gz_stream.hh (revision 188)
+++ oln/io/gz_stream.hh (working copy)
@@ -28,455 +28,455 @@
#ifndef OLN_IO_GZ_STREAM_HH
# define OLN_IO_GZ_STREAM_HH
-// # include <oln/config/system.hh>
+# include <oln/config/system.hh>
-// #if defined HAVE_ZLIB && HAVE_ZLIB == 1
-// # include <cassert>
-// # include <fstream>
-// # include <string>
-// # include <zlib.h>
+#if defined HAVE_ZLIB && HAVE_ZLIB == 1
+# include <cassert>
+# include <fstream>
+# include <string>
+# include <zlib.h>
-// namespace oln {
+namespace oln {
-// namespace io {
+ namespace io {
-// /// Functions for gz files
-// namespace gz {
+ /// Functions for gz files
+ namespace gz {
-// ///Performs operation on compressed files.
-// class zfilebuf : public std::streambuf
-// {
-// public:
+ ///Performs operation on compressed files.
+ class zfilebuf : public std::streambuf
+ {
+ public:
-// zfilebuf() : file(0), mode(0), own_file_descriptor(0)
-// {
-// inbuf = new char[lenbuf];
-// outbuf = new char[lenbuf];
-// setg(0, 0, 0);
-// setp(outbuf, outbuf + lenbuf);
-// }
+ zfilebuf() : file(0), mode(0), own_file_descriptor(0)
+ {
+ inbuf = new char[lenbuf];
+ outbuf = new char[lenbuf];
+ setg(0, 0, 0);
+ setp(outbuf, outbuf + lenbuf);
+ }
-// virtual ~zfilebuf()
-// {
-// sync();
-// delete[] inbuf;
-// delete[] outbuf;
-// if (own_file_descriptor)
-// close();
-// }
+ virtual ~zfilebuf()
+ {
+ sync();
+ delete[] inbuf;
+ delete[] outbuf;
+ if (own_file_descriptor)
+ close();
+ }
-// /*! \brief Return a stream on the file \a name regarding
-// ** the opening mode: \a io_mode.
-// */
-// zfilebuf*
-// open(const char *name, int io_mode)
-// {
-// if (is_open())
-// return 0;
+ /*! \brief Return a stream on the file \a name regarding
+ ** the opening mode: \a io_mode.
+ */
+ zfilebuf*
+ open(const char *name, int io_mode)
+ {
+ if (is_open())
+ return 0;
-// char char_mode[10];
-// char *p;
-// memset(char_mode,'\0',10);
-// p = char_mode;
+ char char_mode[10];
+ char *p;
+ memset(char_mode,'\0',10);
+ p = char_mode;
-// if (io_mode & std::ios::in)
-// {
-// mode = std::ios::in;
-// *p++ = 'r';
-// }
-// else
-// if (io_mode & std::ios::app)
-// {
-// mode = std::ios::app;
-// *p++ = 'a';
-// }
-// else
-// {
-// mode = std::ios::out;
-// *p++ = 'w';
-// }
-// if (io_mode & std::ios::binary)
-// {
-// mode |= std::ios::binary;
-// *p++ = 'b';
-// }
+ if (io_mode & std::ios::in)
+ {
+ mode = std::ios::in;
+ *p++ = 'r';
+ }
+ else
+ if (io_mode & std::ios::app)
+ {
+ mode = std::ios::app;
+ *p++ = 'a';
+ }
+ else
+ {
+ mode = std::ios::out;
+ *p++ = 'w';
+ }
+ if (io_mode & std::ios::binary)
+ {
+ mode |= std::ios::binary;
+ *p++ = 'b';
+ }
-// // Hard code the compression level
-// if (io_mode & (std::ios::out|std::ios::app))
-// *p++ = '9';
+ // Hard code the compression level
+ if (io_mode & (std::ios::out|std::ios::app))
+ *p++ = '9';
-// if ((file = gzopen(name, char_mode)) == 0)
-// return 0;
+ if ((file = gzopen(name, char_mode)) == 0)
+ return 0;
-// name_ = name;
-// own_file_descriptor = 1;
-// return this;
-// }
+ name_ = name;
+ own_file_descriptor = 1;
+ return this;
+ }
-// /*! \brief Attach a stream on \a file_descriptor regarding
-// ** the opening mode: \a io_mode.
-// */
-// zfilebuf*
-// attach(int file_descriptor, int io_mode)
-// {
-// if (is_open())
-// return 0;
+ /*! \brief Attach a stream on \a file_descriptor regarding
+ ** the opening mode: \a io_mode.
+ */
+ zfilebuf*
+ attach(int file_descriptor, int io_mode)
+ {
+ if (is_open())
+ return 0;
-// char char_mode[10];
-// char *p;
-// memset(char_mode,'\0',10);
-// p = char_mode;
+ char char_mode[10];
+ char *p;
+ memset(char_mode,'\0',10);
+ p = char_mode;
-// if (io_mode & std::ios::in)
-// {
-// mode = std::ios::in;
-// *p++ = 'r';
-// }
-// else
-// if (io_mode & std::ios::app)
-// {
-// mode = std::ios::app;
-// *p++ = 'a';
-// }
-// else
-// {
-// mode = std::ios::out;
-// *p++ = 'w';
-// }
+ if (io_mode & std::ios::in)
+ {
+ mode = std::ios::in;
+ *p++ = 'r';
+ }
+ else
+ if (io_mode & std::ios::app)
+ {
+ mode = std::ios::app;
+ *p++ = 'a';
+ }
+ else
+ {
+ mode = std::ios::out;
+ *p++ = 'w';
+ }
-// if (io_mode & std::ios::binary)
-// {
-// mode |= std::ios::binary;
-// *p++ = 'b';
-// }
+ if (io_mode & std::ios::binary)
+ {
+ mode |= std::ios::binary;
+ *p++ = 'b';
+ }
-// // Hard code the compression level
-// if (io_mode & (std::ios::out|std::ios::app))
-// *p++ = '9';
+ // Hard code the compression level
+ if (io_mode & (std::ios::out|std::ios::app))
+ *p++ = '9';
-// if ((file = gzdopen(file_descriptor, char_mode)) == 0)
-// return 0;
+ if ((file = gzdopen(file_descriptor, char_mode)) == 0)
+ return 0;
-// own_file_descriptor = 0;
-// return this;
-// }
+ own_file_descriptor = 0;
+ return this;
+ }
-// /// Close the stream.
-// zfilebuf*
-// close()
-// {
-// if (is_open())
-// {
-// sync();
-// gzclose(file);
-// file = 0;
-// }
-// return this;
-// }
+ /// Close the stream.
+ zfilebuf*
+ close()
+ {
+ if (is_open())
+ {
+ sync();
+ gzclose(file);
+ file = 0;
+ }
+ return this;
+ }
-// int
-// setcompressionlevel(short comp_level)
-// {
-// return gzsetparams(file, comp_level, -2);
-// }
+ int
+ setcompressionlevel(short comp_level)
+ {
+ return gzsetparams(file, comp_level, -2);
+ }
-// int
-// setcompressionstrategy(short comp_strategy)
-// {
-// return gzsetparams(file, -2, comp_strategy);
-// }
+ int
+ setcompressionstrategy(short comp_strategy)
+ {
+ return gzsetparams(file, -2, comp_strategy);
+ }
-// /// Return true if the stream is open, false otherwise.
-// inline int
-// is_open() const
-// { return (file != 0); }
+ /// Return true if the stream is open, false otherwise.
+ inline int
+ is_open() const
+ { return (file != 0); }
-// virtual std::streampos
-// seekoff(std::streamoff off, std::ios::seekdir dir, int) // which)
-// {
-// return std::streampos(gzseek(file, off, dir));
-// }
+ virtual std::streampos
+ seekoff(std::streamoff off, std::ios::seekdir dir, int) // which)
+ {
+ return std::streampos(gzseek(file, off, dir));
+ }
-// /// Flush the buffer associated to the stream.
-// virtual int
-// sync()
-// {
-// if (!is_open())
-// return EOF;
-// return flushbuf();
-// }
+ /// Flush the buffer associated to the stream.
+ virtual int
+ sync()
+ {
+ if (!is_open())
+ return EOF;
+ return flushbuf();
+ }
-// protected:
+ protected:
-// /*! \brief Return the next character in the stream.
-// ** On failure, \a EOF is returned.
-// */
-// virtual int
-// underflow()
-// {
-// // If the file hasn't been opened for reading, error.
-// if (!is_open() || !(mode & std::ios::in))
-// return EOF;
+ /*! \brief Return the next character in the stream.
+ ** On failure, \a EOF is returned.
+ */
+ virtual int
+ underflow()
+ {
+ // If the file hasn't been opened for reading, error.
+ if (!is_open() || !(mode & std::ios::in))
+ return EOF;
-// if (in_avail())
-// return (unsigned char) *gptr();
+ if (in_avail())
+ return (unsigned char) *gptr();
-// if (flushbuf() == EOF)
-// return EOF;
+ if (flushbuf() == EOF)
+ return EOF;
-// // Attempt to fill the buffer.
-// if (fillbuf() == EOF)
-// return EOF;
+ // Attempt to fill the buffer.
+ if (fillbuf() == EOF)
+ return EOF;
-// assert (eback());
+ assert (eback());
-// return (unsigned char) *gptr();
-// }
+ return (unsigned char) *gptr();
+ }
-// /*! \brief Flush the output buffer associated to the stream
-// ** then write \a c. On failure, \a EOF is returned.
-// */
+ /*! \brief Flush the output buffer associated to the stream
+ ** then write \a c. On failure, \a EOF is returned.
+ */
-// virtual int
-// overflow(int c = EOF)
-// {
-// if (!is_open() || !(mode & std::ios::out))
-// return EOF;
+ virtual int
+ overflow(int c = EOF)
+ {
+ if (!is_open() || !(mode & std::ios::out))
+ return EOF;
-// assert (pbase());
+ assert (pbase());
-// if (flushbuf() == EOF)
-// return EOF;
+ if (flushbuf() == EOF)
+ return EOF;
-// if (c != EOF)
-// {
-// *pptr() = c;
-// pbump(1);
-// }
-// return 0;
-// }
+ if (c != EOF)
+ {
+ *pptr() = c;
+ pbump(1);
+ }
+ return 0;
+ }
-// private:
+ private:
-// gzFile file;
-// short mode;
-// short own_file_descriptor;
-// std::string name_;
-// char *inbuf;
-// char *outbuf;
-// static const int lenbuf = 16 * 1024;
+ gzFile file;
+ short mode;
+ short own_file_descriptor;
+ std::string name_;
+ char *inbuf;
+ char *outbuf;
+ static const int lenbuf = 16 * 1024;
-// /// Flush the output buffer
-// int
-// flushbuf()
-// {
-// int n = pptr() - outbuf;
+ /// Flush the output buffer
+ int
+ flushbuf()
+ {
+ int n = pptr() - outbuf;
-// if (n == 0)
-// return 0;
+ if (n == 0)
+ return 0;
-// if (gzwrite(file, outbuf, n) < n)
-// return EOF;
+ if (gzwrite(file, outbuf, n) < n)
+ return EOF;
-// setp(outbuf, outbuf + lenbuf);
-// return 0;
-// }
-// /// Fill the input buffer.
-// int
-// fillbuf()
-// {
-// int t = gzread(file, inbuf, lenbuf);
-// if (t <= 0) return EOF;
-// setg(inbuf, inbuf, inbuf + t);
-// return t;
-// }
+ setp(outbuf, outbuf + lenbuf);
+ return 0;
+ }
+ /// Fill the input buffer.
+ int
+ fillbuf()
+ {
+ int t = gzread(file, inbuf, lenbuf);
+ if (t <= 0) return EOF;
+ setg(inbuf, inbuf, inbuf + t);
+ return t;
+ }
-// };
+ };
-// ///Define an interface for compressed file stream manipulation.
-// class zfilestream_common : virtual public std::ios
-// {
-// friend class zifstream;
-// friend class zofstream;
-// friend zofstream &setcompressionlevel(zofstream &, int);
-// friend zofstream &setcompressionstrategy(zofstream &, int);
+ ///Define an interface for compressed file stream manipulation.
+ class zfilestream_common : virtual public std::ios
+ {
+ friend class zifstream;
+ friend class zofstream;
+ friend zofstream &setcompressionlevel(zofstream &, int);
+ friend zofstream &setcompressionstrategy(zofstream &, int);
-// public:
-// virtual ~zfilestream_common() {}
+ public:
+ virtual ~zfilestream_common() {}
-// /*! \brief Open the stream on the file descriptor:
-// ** \a fd regarding the opening mode.
-// */
-// void
-// attach(int fd, int io_mode)
-// {
-// if (!buffer.attach(fd, io_mode))
-// clear(std::ios::failbit | std::ios::badbit);
-// else
-// clear();
-// }
+ /*! \brief Open the stream on the file descriptor:
+ ** \a fd regarding the opening mode.
+ */
+ void
+ attach(int fd, int io_mode)
+ {
+ if (!buffer.attach(fd, io_mode))
+ clear(std::ios::failbit | std::ios::badbit);
+ else
+ clear();
+ }
-// /*! \brief Open the stream on the file named \a name
-// ** regarding the opening mode.
-// */
-// void
-// open(const char *name, int io_mode)
-// {
-// if (!buffer.open(name, io_mode))
-// clear(std::ios::failbit | std::ios::badbit);
-// else
-// clear();
-// }
+ /*! \brief Open the stream on the file named \a name
+ ** regarding the opening mode.
+ */
+ void
+ open(const char *name, int io_mode)
+ {
+ if (!buffer.open(name, io_mode))
+ clear(std::ios::failbit | std::ios::badbit);
+ else
+ clear();
+ }
-// /// Close the current stream.
-// void
-// close()
-// {
-// if (!buffer.close())
-// clear(std::ios::failbit | std::ios::badbit);
-// }
+ /// Close the current stream.
+ void
+ close()
+ {
+ if (!buffer.close())
+ clear(std::ios::failbit | std::ios::badbit);
+ }
-// bool
-// is_open()
-// {
-// return buffer.is_open();
-// }
+ bool
+ is_open()
+ {
+ return buffer.is_open();
+ }
-// protected:
-// /// Prevent instantiation.
-// zfilestream_common() : std::ios(zfilestream_common::rdbuf())
-// { }
+ protected:
+ /// Prevent instantiation.
+ zfilestream_common() : std::ios(zfilestream_common::rdbuf())
+ { }
-// private:
-// zfilebuf*
-// rdbuf()
-// {
-// return &buffer;
-// }
+ private:
+ zfilebuf*
+ rdbuf()
+ {
+ return &buffer;
+ }
-// zfilebuf buffer;
-// };
+ zfilebuf buffer;
+ };
-// /// Read only zstream.
-// class zifstream : public zfilestream_common, public std::istream
-// {
-// public:
+ /// Read only zstream.
+ class zifstream : public zfilestream_common, public std::istream
+ {
+ public:
-// zifstream() : std::istream(zfilestream_common::rdbuf())
-// {
-// clear(std::ios::badbit);
-// }
+ zifstream() : std::istream(zfilestream_common::rdbuf())
+ {
+ clear(std::ios::badbit);
+ }
-// /// Open a read only stream on the file named \a name.
-// zifstream(const char *name, int io_mode = std::ios::in) :
-// std::istream(zfilestream_common::rdbuf())
-// {
-// zfilestream_common::open(name, io_mode);
-// }
+ /// Open a read only stream on the file named \a name.
+ zifstream(const char *name, int io_mode = std::ios::in) :
+ std::istream(zfilestream_common::rdbuf())
+ {
+ zfilestream_common::open(name, io_mode);
+ }
-// /// Open a read only stream on the file descriptor \a fd.
-// zifstream(int fd, int io_mode = std::ios::in) :
-// std::istream(zfilestream_common::rdbuf())
-// {
-// zfilestream_common::attach(fd, io_mode);
-// }
+ /// Open a read only stream on the file descriptor \a fd.
+ zifstream(int fd, int io_mode = std::ios::in) :
+ std::istream(zfilestream_common::rdbuf())
+ {
+ zfilestream_common::attach(fd, io_mode);
+ }
-// virtual ~zifstream() {}
-// };
+ virtual ~zifstream() {}
+ };
-// class zofstream : public zfilestream_common, public std::ostream {
+ class zofstream : public zfilestream_common, public std::ostream {
-// public:
+ public:
-// zofstream() : std::ostream(zfilestream_common::rdbuf())
-// {
-// clear(std::ios::badbit);
-// }
+ zofstream() : std::ostream(zfilestream_common::rdbuf())
+ {
+ clear(std::ios::badbit);
+ }
-// /// Open a write only stream on the file named \a name.
-// zofstream(const char *name, int io_mode = std::ios::out) :
-// std::ostream(zfilestream_common::rdbuf())
-// {
-// zfilestream_common::open(name, io_mode);
-// }
+ /// Open a write only stream on the file named \a name.
+ zofstream(const char *name, int io_mode = std::ios::out) :
+ std::ostream(zfilestream_common::rdbuf())
+ {
+ zfilestream_common::open(name, io_mode);
+ }
-// /// Open a write only stream on the file descriptor \a fd.
-// zofstream(int fd, int io_mode = std::ios::out) :
-// std::ostream(zfilestream_common::rdbuf())
-// {
-// zfilestream_common::attach(fd, io_mode);
-// }
+ /// Open a write only stream on the file descriptor \a fd.
+ zofstream(int fd, int io_mode = std::ios::out) :
+ std::ostream(zfilestream_common::rdbuf())
+ {
+ zfilestream_common::attach(fd, io_mode);
+ }
-// virtual ~zofstream() {}
+ virtual ~zofstream() {}
-// };
+ };
-// // Forward declaration.
-// template <class T>
-// class zomanip;
+ // Forward declaration.
+ template <class T>
+ class zomanip;
-// /// Apply a function on \a s via the operator <<.
-// template <class T>
-// zofstream&
-// operator<<(zofstream &s, const zomanip<T> &m) {
-// return (*m.func)(s, m.val);
-// }
+ /// Apply a function on \a s via the operator <<.
+ template <class T>
+ zofstream&
+ operator<<(zofstream &s, const zomanip<T> &m) {
+ return (*m.func)(s, m.val);
+ }
-// /// Define a pair func / val to perform manipulation on zofstream.
-// template<class T> class zomanip
-// {
-// friend zofstream &operator<< <T>(zofstream &, const zomanip<T> &);
-// public:
-// zomanip(zofstream &(*f)(zofstream &, T), T v) : func(f), val(v) { }
-// private:
-// zofstream &(*func)(zofstream &, T);
-// T val;
-// };
+ /// Define a pair func / val to perform manipulation on zofstream.
+ template<class T> class zomanip
+ {
+ friend zofstream &operator<< <T>(zofstream &, const zomanip<T> &);
+ public:
+ zomanip(zofstream &(*f)(zofstream &, T), T v) : func(f), val(v) { }
+ private:
+ zofstream &(*func)(zofstream &, T);
+ T val;
+ };
-// /// Set the compression level of \a s to \a l.
-// inline zofstream&
-// setcompressionlevel(zofstream &s, int l) {
-// (s.rdbuf())->setcompressionlevel(l);
-// return s;
-// }
+ /// Set the compression level of \a s to \a l.
+ inline zofstream&
+ setcompressionlevel(zofstream &s, int l) {
+ (s.rdbuf())->setcompressionlevel(l);
+ return s;
+ }
-// /// Set the compression strategy of \a s to \a l.
-// inline zofstream&
-// setcompressionstrategy(zofstream &s, int l)
-// {
-// (s.rdbuf())->setcompressionstrategy(l);
-// return s;
-// }
+ /// Set the compression strategy of \a s to \a l.
+ inline zofstream&
+ setcompressionstrategy(zofstream &s, int l)
+ {
+ (s.rdbuf())->setcompressionstrategy(l);
+ return s;
+ }
-// /// Specialized version for zomanip<int>
-// inline zomanip<int>
-// setcompressionlevel(int l)
-// {
-// return zomanip<int>(&setcompressionlevel,l);
-// }
+ /// Specialized version for zomanip<int>
+ inline zomanip<int>
+ setcompressionlevel(int l)
+ {
+ return zomanip<int>(&setcompressionlevel,l);
+ }
-// /// Specialized version for zomanip<int>
-// inline zomanip<int>
-// setcompressionstrategy(int l)
-// {
-// return zomanip<int>(&setcompressionstrategy,l);
-// }
+ /// Specialized version for zomanip<int>
+ inline zomanip<int>
+ setcompressionstrategy(int l)
+ {
+ return zomanip<int>(&setcompressionstrategy,l);
+ }
-// } // end of namespace gz
+ } // end of namespace gz
-// } // end of namespace io
+ } // end of namespace io
-// } // end of namespace oln
+} // end of namespace oln
-// # endif // ! HAVE_ZLIB
+# endif // ! HAVE_ZLIB
#endif // ! OLN_IO_GZ_STREAM_HH
Index: oln/io/write_image_pnm_2d.hh
--- oln/io/write_image_pnm_2d.hh (revision 0)
+++ oln/io/write_image_pnm_2d.hh (revision 0)
@@ -0,0 +1,153 @@
+// 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 OLN_IO_WRITE_IMAGE_PNM_2D_HH
+# define OLN_IO_WRITE_IMAGE_PNM_2D_HH
+
+# include <ntg/all.hh>
+
+# include <oln/canvas/io.hh>
+
+# include <oln/core/2d/image2d.hh>
+# include <oln/io/write_image_pnm_decl.hh>
+
+namespace oln {
+
+
+ namespace io {
+
+
+ namespace impl {
+
+
+ template <typename I>
+ struct write_pnm_vect<I, oln::size2d>
+ : public canvas::write_2d<I, write_pnm_vect<I, oln::size2d> >
+ {
+ typedef canvas::write_2d<I, write_pnm_vect<I, oln::size2d> > super_type;
+ typedef oln_type_of(I, value) value_type;
+ typedef ntg_comp_type(value_type) comp_type;
+ typedef oln_io_type(ntg_nbits(ntg_comp_type(value_type))) v_type;
+
+ void impl_write_point()
+ {
+ value_type c = this->input[this->p];
+ for (unsigned i = 0; i < ntg_nb_comp(value_type); ++i)
+ {
+ v_type v;
+ v = c[i];
+ this->ostr.write((char*)&v, sizeof (v_type));
+ }
+ }
+
+ write_pnm_vect(const abstract::image<I>& input,
+ std::ostream& ostr) :
+ super_type(input, ostr)
+ {}
+
+ };
+
+ template <typename I>
+ struct write_pnm_real<I, oln::size2d>
+ : public canvas::write_2d<I, write_pnm_real<I, oln::size2d> >
+ {
+ typedef canvas::write_2d<I, write_pnm_real<I, oln::size2d> > super_type;
+ typedef oln_type_of(I, value) value_type;
+ typedef ntg_type(value_type) ntg_value_type;
+ typedef oln_io_type(ntg_nbits(ntg_value_type)) v_type;
+
+
+ void impl_write_point()
+ {
+ v_type v;
+ v = this->input[this->p];
+ this->ostr.write((char*)&v, sizeof (v_type));
+ }
+
+ write_pnm_real(const abstract::image<I>& input,
+ std::ostream& ostr) :
+ super_type(input, ostr)
+ {}
+
+ };
+
+ template <typename I>
+ struct write_pnm_bin<I, oln::size2d>
+ : public canvas::write_2d<I, write_pnm_bin<I, oln::size2d> >
+ {
+ typedef canvas::write_2d<I, write_pnm_bin<I, oln::size2d> > super_type;
+ typedef oln_type_of(I, value) value_type;
+ typedef ntg_type(value_type) ntg_value_type;
+ typedef oln_io_type(ntg_nbits(ntg_value_type)) v_type;
+
+ int offset;
+ char v;
+
+ void extra_work()
+ {
+ if (offset != 7)
+ {
+ this->ostr.write(&v, 1);
+ offset = 7;
+ v = 0;
+ }
+ }
+
+ void impl_write_point()
+ {
+ if (offset == -1)
+ {
+ this->ostr.write(&v, 1);
+ offset = 7;
+ v = 0;
+ }
+ if (this->input[this->p] == value_type(1))
+ v |= 1 << offset;
+ offset--;
+ }
+
+ write_pnm_bin(const abstract::image<I>& input,
+ std::ostream& ostr) :
+ super_type(input, ostr),
+ offset(7),
+ v(0)
+ {
+ }
+
+ };
+
+
+
+ }
+
+
+ }
+
+
+}
+
+#endif // ! OLN_IO_WRITE_IMAGE_PNM_2D_HH
Index: oln/io/read_image_2d_pnm.hh
--- oln/io/read_image_2d_pnm.hh (revision 188)
+++ oln/io/read_image_2d_pnm.hh (working copy)
@@ -1,187 +0,0 @@
-// 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 OLN_IO_READ_IMAGE_2D_PNM_HH
-# define OLN_IO_READ_IMAGE_2D_PNM_HH
-
-// # include <iostream>
-// # include <string>
-
-// # include <mlc/box.hh>
-// # include <mlc/math.hh>
-
-// # include <ntg/all.hh>
-
-// # include <oln/core/2d/image2d.hh>
-
-// # include <oln/core/abstract/image_operator.hh>
-
-// # include <oln/io/utils.hh>
-
-
-// namespace oln {
-
-// template <typename I>
-// struct image2d;
-
-// // fwd decl
-// namespace io {
-// namespace impl {
-// template <typename I> struct read_image_2d_raw;
-// }
-// }
-
-// // super_type
-// template <typename I>
-// struct set_super_type < io::impl::read_image_2d_raw<I> >
-// {
-// typedef abstract::image_operator<I, io::impl::read_image_2d_raw<I> > ret;
-// };
-
-
-// namespace io {
-
-// namespace impl {
-
-// template <typename I>
-// struct read_image_2d_raw :
-// public oln::abstract::image_operator<I, read_image_2d_raw<I> >
-// {
-// typedef oln::abstract::image_operator<I, read_image_2d_raw<I> >
-// super_type;
-// typedef oln_type_of(I, value) value_type;
-
-// std::istream& istr_;
-// internal::pnm_info& info_;
-// char v;
-// int offset;
-
-// read_image_2d_raw(std::istream &istr,
-// internal::pnm_info &info) :
-// super_type(),
-// istr_(istr),
-// info_(info),
-// offset(-1)
-// {
-// }
-
-// template <typename E>
-// void precond(ntg::real_value<E>& c)
-// {
-// precondition(ntg_max_val(value_type) <= info_.max_val);
-// precondition(info_.type == "P5");
-// }
-
-// template <typename E>
-// void precond(ntg::vect_value<E>& c)
-// {
-// precondition(ntg_max_val(ntg_comp_type(value_type)) <=
-// info_.max_val);
-// precondition(info_.type == "P6");
-// precondition(ntg_nb_comp(value_type) == 3);
-// }
-
-// void precond(ntg::bin& c)
-// {
-// precondition(info_.type == "P4");
-// }
-
-// void impl_run()
-// {
-// value_type c;
-// point2d p;
-// oln::image2d<value_type> tmp(info_.rows, info_.cols);
-
-// precond(c);
-
-// for (p.row() = 0; p.row() < info_.rows && !istr_.eof(); ++p.row())
-// {
-// offset = -1;
-// for (p.col() = 0; p.col() < info_.cols && !istr_.eof(); ++p.col())
-// {
-// read_value_type(c);
-// tmp[p] = c;
-// }
-// }
-// this->output = tmp;
-// }
-
-// //FIXME: Should work with builtin types.
-
-// template <typename E>
-// void read_value_type(ntg::real_value<E> &c)
-// {
-// typedef oln_io_type(ntg_nbits(E)) v_type;
-// v_type v;
-// istr_.read((char*)&v, sizeof (v_type));
-// c = ntg::cast::force<E, v_type>(v);
-// }
-
-// template <typename E>
-// void read_value_type(ntg::vect_value<E> &c)
-// {
-// for (unsigned i = 0; i < ntg_nb_comp(E); i++)
-// {
-// typedef oln_io_type(ntg_nbits(ntg_comp_type(E))) v_type;
-// v_type v;
-// istr_.read((char*)&v, sizeof (v_type));
-// c[i] = ntg::cast::force<ntg_comp_type(E), v_type>(v);
-// }
-// }
-
-// void read_value_type(ntg::bin &c)
-// {
-
-// if (offset == -1)
-// {
-// istr_.read(&v, 1);
-// offset = 7;
-// }
-// if ((int)(v & (1<<offset--)) == 0)
-// c = 0;
-// else
-// c = 1;
-// }
-// };
-
-// template <typename I>
-// read_image_2d_raw<I>
-// read(std::istream& istr, internal::pnm_info info)
-// {
-// read_image_2d_raw<I> tmp(istr, info);
-// tmp.run();
-// return tmp;
-// }
-
-// }
-
-// }
-
-// }
-
-
-#endif // ! OLN_IO_READ_IMAGE_2D_PNM_HH
Index: oln/io/write_image.hh
--- oln/io/write_image.hh (revision 188)
+++ oln/io/write_image.hh (working copy)
@@ -28,84 +28,84 @@
#ifndef OLN_IO_WRITE_IMAGE_HH
# define OLN_IO_WRITE_IMAGE_HH
-// # include <string>
+# include <string>
-// # include <oln/io/gz_stream.hh>
-// # include <oln/io/utils.hh>
-// # include <oln/io/write_image_2d_pnm.hh>
+# include <oln/io/gz_stream.hh>
+# include <oln/io/utils.hh>
+# include <oln/io/write_image_pnm.hh>
-// namespace oln {
+namespace oln {
-// namespace io {
+ namespace io {
-// template <typename I>
-// void do_write(const abstract::image<I>& ima,
-// std::ostream& ostr,
-// const std::string& ext)
-// {
-// typedef oln_type_of(I, value) value_type;
-// value_type t;
+ template <typename I>
+ void write_dispatch_ext(const abstract::image<I>& ima,
+ std::ostream& ostr,
+ const std::string& ext)
+ {
+ if (ext == "pgm" || ext == "pbm" || ext == "ppm" ||
+ ext == "pnm")
+ write_pnm(ima, ostr, ext);
+ else
+ std::cout << "io error: format not supported."
+ << std::endl;
+ }
-// impl::write(ima.exact(), t, ostr, ext);
-// }
+#if defined HAVE_ZLIB && HAVE_ZLIB == 1
+ template <typename I>
+ void write_gz(const abstract::image<I>& ima, const std::string& name)
+ {
+ gz::zofstream zostr(name.c_str(), std::ios::out);
-// #if defined HAVE_ZLIB && HAVE_ZLIB == 1
-// template <typename I>
-// void write_gz(const abstract::image<I>& ima, const std::string& name)
-// {
-// gz::zofstream zostr(name.c_str(), std::ios::out);
+ if (zostr.is_open() == false)
+ std::cerr << "error: couldn't open " << name << std::endl;
+ else
+ {
+ std::string ext;
-// if (zostr.is_open() == false)
-// std::cerr << "error: couldn't open " << name << std::endl;
-// else
-// {
-// std::string ext;
+ ext = internal::extension(name.substr(0, name.size() - 3));
+ write_dispatch_ext(ima, zostr, ext);
+ }
+ zostr.close();
+ }
-// ext = internal::utils::extension(name.substr(0, name.size() - 3));
-// do_write(ima, zostr, ext);
-// }
-// zostr.close();
-// }
+#endif // ! HAVE_ZLIB
-// #endif // ! HAVE_ZLIB
+ template <typename I>
+ void write_non_gz(const abstract::image<I>& ima,
+ const std::string& name,
+ const std::string& ext)
+ {
+ std::ofstream ostr;
-// template <typename I>
-// void write_non_gz(const abstract::image<I>& ima,
-// const std::string& name,
-// const std::string& ext)
-// {
-// std::ofstream ostr;
+ ostr.open(name.c_str(), std::ifstream::out);
-// ostr.open(name.c_str(), std::ifstream::out);
+ if (ostr.is_open() == false)
+ std::cerr << "error: couldn't open " << name << std::endl;
+ else
+ write_dispatch_ext(ima, ostr, ext);
+ ostr.close();
+ }
-// if (ostr.is_open() == false)
-// std::cerr << "error: couldn't open " << name << std::endl;
-// else
-// do_write(ima, ostr, ext);
-// ostr.close();
-// }
+ template <typename I>
+ void write(const abstract::image<I>& ima, const std::string& name)
+ {
+ std::string ext;
-// template <typename I>
-// void write(const abstract::image<I>& ima, const std::string& name)
-// {
-// std::string ext;
-// // FIXME: Unused?
-// // oln_type_of(I, value) t;
+ ext = internal::extension(name);
-// ext = internal::utils::extension(name);
+#if defined HAVE_ZLIB && HAVE_ZLIB == 1
+ if (ext == "gz")
+ write_gz(ima, name);
+ else
+ write_non_gz(ima, name, ext);
+# else
+ write_non_gz(ima, name, ext);
+#endif // ! HAVE_ZLIB
+ }
-// #if defined HAVE_ZLIB && HAVE_ZLIB == 1
-// if (ext == "gz")
-// write_gz(ima, name);
-// else
-// write_non_gz(ima, name, ext);
-// # else
-// write_non_gz(ima, name, ext);
-// #endif // ! HAVE_ZLIB
-// }
+ }
-// }
+}
-// }
-
#endif // ! OLN_IO_WRITE_IMAGE_HH
Index: oln/io/read_image_pnm_2d.hh
--- oln/io/read_image_pnm_2d.hh (revision 0)
+++ oln/io/read_image_pnm_2d.hh (revision 0)
@@ -0,0 +1,166 @@
+// 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 OLN_IO_READ_IMAGE_PNM_2D_HH
+# define OLN_IO_READ_IMAGE_PNM_2D_HH
+
+# include <ntg/all.hh>
+
+# include <oln/canvas/io.hh>
+
+# include <oln/core/2d/image2d.hh>
+# include <oln/io/read_image_pnm_decl.hh>
+
+namespace oln {
+
+
+ namespace io {
+
+
+ namespace impl {
+
+
+ template <typename I>
+ struct read_pnm_vect<I, oln::size2d>
+ : public canvas::read_2d<I, read_pnm_vect<I, oln::size2d> >
+ {
+ typedef canvas::read_2d<I, read_pnm_vect<I, oln::size2d> > super_type;
+ typedef oln_type_of(I, value) value_type;
+ typedef ntg_comp_type(value_type) comp_type;
+ typedef oln_io_type(ntg_nbits(ntg_comp_type(value_type))) v_type;
+
+ void impl_read_point()
+ {
+ value_type c;
+ for (unsigned i = 0; i < ntg_nb_comp(value_type); ++i)
+ {
+ v_type v;
+ this->istr.read((char*)&v, sizeof (v_type));
+ c[i] = (ntg_storage_type(ntg_comp_type(value_type)))v;
+ }
+ this->output[this->p] = c;
+ }
+
+ void impl_preconditions()
+ {
+ precondition(ntg_max_val(comp_type) - ntg_min_val(comp_type)
+ <= this->hdr.max_val);
+ precondition(ntg_nb_comp(value_type) == 3);
+ }
+
+ read_pnm_vect(std::istream& istr,
+ const internal::pnm_header& hdr) :
+ super_type(istr, hdr)
+ {}
+
+ };
+
+ template <typename I>
+ struct read_pnm_real<I, oln::size2d>
+ : public canvas::read_2d<I, read_pnm_real<I, oln::size2d> >
+ {
+ typedef canvas::read_2d<I, read_pnm_real<I, oln::size2d> > super_type;
+ typedef oln_type_of(I, value) value_type;
+ typedef ntg_type(value_type) ntg_value_type;
+ typedef oln_io_type(ntg_nbits(ntg_value_type)) v_type;
+
+
+ void impl_read_point()
+ {
+ v_type v;
+ this->istr.read((char*)&v, sizeof (v_type));
+ this->output[this->p] = (ntg_storage_type(value_type))v;
+ }
+
+ void impl_preconditions()
+ {
+ precondition(ntg_max_val(value_type) - ntg_min_val(value_type)
+ <= this->hdr.max_val);
+ }
+
+ read_pnm_real(std::istream& istr,
+ const internal::pnm_header& hdr) :
+ super_type(istr, hdr)
+ {}
+
+ };
+
+ template <typename I>
+ struct read_pnm_bin<I, oln::size2d>
+ : public canvas::read_2d<I, read_pnm_bin<I, oln::size2d> >
+ {
+ typedef canvas::read_2d<I, read_pnm_bin<I, oln::size2d> > super_type;
+ typedef oln_type_of(I, value) value_type;
+ typedef ntg_type(value_type) ntg_value_type;
+ typedef oln_io_type(ntg_nbits(ntg_value_type)) v_type;
+
+ char v;
+ int offset;
+
+ void impl_extra_work()
+ {
+ offset = -1;
+ }
+
+ void impl_read_point()
+ {
+ if (offset == -1)
+ {
+ this->istr.read(&v, 1);
+ offset = 7;
+ }
+ if ((int)(v & (1<<offset--)) == 0)
+ this->output[this->p] = 0;
+ else
+ this->output[this->p] = 1;
+ }
+
+ void impl_preconditions()
+ {
+ precondition(ntg_max_val(value_type) - ntg_min_val(value_type)
+ <= this->hdr.max_val);
+ }
+
+ read_pnm_bin(std::istream& istr,
+ const internal::pnm_header& hdr) :
+ super_type(istr, hdr),
+ offset(-1)
+ {}
+
+ };
+
+
+
+ }
+
+
+ }
+
+
+}
+
+#endif // ! OLN_IO_READ_IMAGE_PNM_2D_HH
Index: oln/io/read_image.hh
--- oln/io/read_image.hh (revision 188)
+++ oln/io/read_image.hh (working copy)
@@ -35,7 +35,7 @@
# include <ntg/core/macros.hh>
-# include <oln/io/read_image_2d_pnm.hh>
+# include <oln/io/read_image_pnm.hh>
# include <oln/io/utils.hh>
# include <oln/io/gz_stream.hh>
@@ -63,101 +63,74 @@
}
-// template <typename I>
-// void read_dispatch_ext(abstract::image<I>& ima,
-// std::istream& istr,
-// const std::string& ext)
+ template <typename I>
+ void read_dispatch_ext(abstract::image<I>& ima,
+ std::istream& istr,
+ const std::string& ext)
-// {
-// if (ext == "pgm" || ext == "pbm" || ext == "ppm" ||
-// ext == "pnm")
-// {
-// internal::pnm_info info;
+ {
+ if (ext == "pgm" || ext == "pbm" || ext == "ppm" ||
+ ext == "pnm")
+ read_pnm(ima, istr, ext);
+ else
+ std::cout << "io error: format not supported."
+ << std::endl;
+ }
-// if (internal::read_pnm_header(istr, info))
-// if ((ext == "ppm" || ext == "pnm") && info.type == "P6")
-// ima.exact() = impl::read<I>(istr, info);
-// else if ((ext == "ppm" || ext == "pnm") && info.type == "P3")
-// std::cerr << "error: read_image_2d_ppm_ascii not implemented"
-// << std::endl;
-// else if ((ext == "pbm" || ext == "pnm") && info.type == "P4")
-// ima.exact() = impl::read<I>(istr, info);
-// else if ((ext == "pbm" || ext == "pnm") && info.type == "P1")
-// std::cerr << "error: read_image_2d_ppm_ascii not implemented"
-// << std::endl;
-// else if ((ext == "pgm" || ext == "pnm") && info.type == "P5")
-// ima.exact() = impl::read<I>(istr, info);
-// else if ((ext == "pgm" || ext == "pnm") && info.type == "P2")
-// std::cerr << "error: read_image_2d_ppm_ascii not implemented"
-// << std::endl;
-// else
-// std::cerr << "error: file header (`" << info.type
-// << "') does not match file extension (`"
-// << ext << "')" << std::endl;
-// else
-// std::cerr << "error: unable to get a valid header" << std::endl;
-// }
-// else
-// std::cout << "no input method for '"
-// << ext << "' file extension"
-// << std::endl;
-// }
+#if defined HAVE_ZLIB && HAVE_ZLIB == 1
+ template <typename I>
+ void do_read_gz(abstract::image<I>& ima, const std::string& name)
+ {
+ gz::zifstream zistr(name.c_str(), std::ios::in);
-// #if defined HAVE_ZLIB && HAVE_ZLIB == 1
-// template <typename I>
-// void do_read_gz(abstract::image<I>& ima, const std::string& name)
-// {
-// gz::zifstream zistr(name.c_str(), std::ios::in);
+ if (zistr.is_open() == false)
+ std::cerr << "io error: couldn't open " << name << std::endl;
+ else
+ {
+ std::string ext;
-// if (zistr.is_open() == false)
-// std::cerr << "error: couldn't open " << name << std::endl;
-// else
-// {
-// std::string ext;
+ ext = internal::extension(name.substr(0, name.size() - 3));
+ read_dispatch_ext(ima, zistr, ext);
+ }
+ zistr.close();
+ }
+#endif // ! HAVE_ZLIB
-// ext = internal::utils::extension(name.substr(0, name.size() - 3));
-// read_dispatch_ext(ima, zistr, ext);
-// }
-// zistr.close();
-// }
+ template <typename I>
+ void do_read_non_gz(abstract::image<I>& ima,
+ const std::string& name,
+ const std::string& ext)
+ {
+ std::ifstream istr;
-// #endif // ! HAVE_ZLIB
+ istr.open(name.c_str(), std::ifstream::in);
-// template <typename I>
-// void do_read_non_gz(abstract::image<I>& ima,
-// const std::string& name,
-// const std::string& ext)
-// {
-// std::ifstream istr;
+ if (istr.is_open() == false)
+ std::cerr << "io error: couldn't open " << name << std::endl;
+ else
+ read_dispatch_ext(ima, istr, ext);
+ istr.close();
+ }
-// istr.open(name.c_str(), std::ifstream::in);
+ template <typename I>
+ void do_read(abstract::image<I>& ima, const filename& name)
+ {
+ std::string ext;
-// if (istr.is_open() == false)
-// std::cerr << "error: couldn't open " << name << std::endl;
-// else
-// read_dispatch_ext(ima, istr, ext);
-// istr.close();
-// }
+ ext = internal::extension(name.get());
-// template <typename I>
-// void do_read(abstract::image<I>& ima, const filename& name)
-// {
-// std::string ext;
+#if defined HAVE_ZLIB && HAVE_ZLIB == 1
-// ext = internal::utils::extension(name.get());
+ if (ext == "gz")
+ do_read_gz(ima, name.get());
+ else
+ do_read_non_gz(ima, name.get(), ext);
+#else
+ do_read_non_gz(ima, name.get(), ext);
+#endif // ! HAVE_ZLIB
+ }
-// #if defined HAVE_ZLIB && HAVE_ZLIB == 1
-// if (ext == "gz")
-// do_read_gz(ima, name.get());
-// else
-// do_read_non_gz(ima, name.get(), ext);
-// #else
-// do_read_non_gz(ima, name.get(), ext);
-// #endif // ! HAVE_ZLIB
-// }
-
-
}
}
Index: oln/io/write_image_pnm_decl.hh
--- oln/io/write_image_pnm_decl.hh (revision 0)
+++ oln/io/write_image_pnm_decl.hh (revision 0)
@@ -0,0 +1,57 @@
+// 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 OLN_IO_WRITE_IMAGE_PNM_DECL_HH
+# define OLN_IO_WRITE_IMAGE_PNM_DECL_HH
+
+namespace oln {
+
+
+ namespace io {
+
+
+ namespace impl {
+
+ template <typename I, typename S>
+ struct write_pnm_vect {};
+
+ template <typename I, typename S>
+ struct write_pnm_real {};
+
+ template <typename I, typename S>
+ struct write_pnm_bin {};
+
+
+ }
+
+
+ }
+
+
+}
+
+#endif // ! OLN_IO_WRITE_IMAGE_PNM_DECL_HH
Index: oln/io/read_image_pnm_decl.hh
--- oln/io/read_image_pnm_decl.hh (revision 0)
+++ oln/io/read_image_pnm_decl.hh (revision 0)
@@ -0,0 +1,57 @@
+ // 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 OLN_IO_READ_IMAGE_PNM_DECL_HH
+# define OLN_IO_READ_IMAGE_PNM_DECL_HH
+
+namespace oln {
+
+
+ namespace io {
+
+
+ namespace impl {
+
+
+ template <typename I, typename S>
+ struct read_pnm_vect {};
+
+ template <typename I, typename S>
+ struct read_pnm_real {};
+
+ template <typename I, typename S>
+ struct read_pnm_bin {};
+
+ }
+
+
+ }
+
+
+}
+
+#endif // ! OLN_IO_READ_IMAGE_PNM_DECL_HH
Index: oln/io/utils.hh
--- oln/io/utils.hh (revision 188)
+++ oln/io/utils.hh (working copy)
@@ -28,153 +28,144 @@
#ifndef OLENA_IO_UTILS_HH
# define OLENA_IO_UTILS_HH
-// # include <oln/config/system.hh>
+# include <oln/config/system.hh>
-// # include <iostream>
-// # include <fstream>
-// # include <string>
+# include <iostream>
+# include <fstream>
+# include <string>
-// namespace oln {
+namespace oln {
-// namespace io {
+ namespace io {
-// namespace internal {
+ namespace internal {
-// /*!
-// ** \brief Utils for io (get extension of a file).
-// */
-// struct utils
-// {
+ /*!
+ ** \brief Return the extension of a filename.
+ ** \arg name The filename.
+ ** \return The extension (lower case).
+ */
+ std::string extension(const std::string& name)
+ {
+ std::string ext;
+ int pos = name.rfind('.');
+ if (pos > 0)
+ {
+ ext.assign(name, pos + 1, name.size() - pos);
+ for (std::string::iterator i = ext.begin(); i != ext.end(); ++i)
+ *i = tolower(*i);
+ }
+ return ext;
+ }
-// /*!
-// ** \brief Return the extension of a filename.
-// ** \arg name The filename.
-// ** \return The extension (lower case).
-// */
-// static std::string
-// extension(const std::string& name)
-// {
-// std::string ext;
-// int pos = name.rfind('.');
-// if (pos > 0)
-// {
-// ext.assign(name, pos + 1, name.size() - pos);
-// for (std::string::iterator i = ext.begin(); i != ext.end(); ++i)
-// *i = tolower(*i);
-// }
-// return ext;
-// }
-// };
+ struct pnm_header
+ {
+ int max_val;
+ int rows;
+ int cols;
+ std::string type;
+ };
+ bool read_pnm_header(std::istream& istr,
+ internal::pnm_header& hdr)
+ {
+ std::getline(istr, hdr.type);
-// struct pnm_info
-// {
-// int max_val;
-// int rows;
-// int cols;
-// std::string type;
-// };
+ hdr.max_val = 1;
-// bool read_pnm_header(std::istream& istr,
-// internal::pnm_info& info)
-// {
-// std::getline(istr, info.type);
+ // skip comments
+ while (istr.peek() == '#')
+ {
+ std::string line;
+ std::getline(istr, line);
+ }
-// info.max_val = 1;
+ // read size
+ istr >> hdr.cols;
+ // skip comments
+ while (istr.peek() == '#')
+ {
+ std::string line;
+ std::getline(istr, line);
+ }
-// // skip comments
-// while (istr.peek() == '#')
-// {
-// std::string line;
-// std::getline(istr, line);
-// }
-// // read size
-// istr >> info.cols;
-// // skip comments
-// while (istr.peek() == '#')
-// {
-// std::string line;
-// std::getline(istr, line);
-// }
+ istr >> hdr.rows;
+ // skip comments
+ while (istr.peek() == '#')
+ {
+ std::string line;
+ std::getline(istr, line);
+ }
+ if (hdr.cols <= 0 || hdr.rows <= 0) return false;
-// istr >> info.rows;
-// // skip comments
-// while (istr.peek() == '#')
-// {
-// std::string line;
-// std::getline(istr, line);
-// }
+ // skip comments
+ while (istr.peek() == '#')
+ {
+ std::string line;
+ std::getline(istr, line);
+ }
-// if (info.cols <= 0 || info.rows <= 0) return false;
+ // FIXME: it can be either '\n', 'whitespace', ..., not only '\n'!
+ if (istr.get() != '\n') return false;
+ // extract or skip maxvalue
+ if (hdr.type != "P1" && hdr.type != "P4")
+ {
+ istr >> hdr.max_val;
+ if (hdr.max_val > 65535 ||
+ istr.get() != '\n' ||
+ hdr.max_val <= 0)
+ return false;
+ }
+ return true;
+ }
-// // skip comments
-// while (istr.peek() == '#')
-// {
-// std::string line;
-// std::getline(istr, line);
-// }
+ bool write_pnm_header(std::ostream& ostr,
+ const std::string& type,
+ int ncols,
+ int nrows,
+ int max_val)
+ {
+ if (max_val > 65535)
+ return false;
-// // FIXME: it can be either '\n', 'whitespace', ..., not only '\n'!
-// if (istr.get() != '\n') return false;
-// // extract or skip maxvalue
-// if (info.type != "P1" && info.type != "P4")
-// {
-// istr >> info.max_val;
-// if (info.max_val > 65535 ||
-// istr.get() != '\n' ||
-// info.max_val <= 0)
-// return false;
-// }
-// return true;
-// }
+ ostr << type << std::endl
+ << "# Olena 1.0" << std::endl
+ << ncols << " " << nrows << std::endl;
+ if (type != "P1" && type != "P4")
+ ostr << max_val << std::endl;
+ return true;
+ }
-// bool write_pnm_header(std::ostream& ostr,
-// const std::string& type,
-// int ncols,
-// int nrows,
-// int max_val)
-// {
-// if (max_val > 65535)
-// return false;
+ template <bool b>
+ struct pnm_io_helper_bool
+ {
+ typedef unsigned char type;
+ };
-// ostr << type << std::endl
-// << "# Olena 1.0" << std::endl
-// << ncols << " " << nrows << std::endl;
-// if (type != "P1" && type != "P4")
-// ostr << max_val << std::endl;
-// return true;
-// }
+ template <>
+ struct pnm_io_helper_bool<false>
+ {
+ typedef unsigned short type;
+ };
-// template <bool b>
-// struct pnm_io_helper_bool
-// {
-// typedef unsigned char type;
-// };
+ template <unsigned N>
+ struct pnm_io_helper
+ {
+ typedef typename pnm_io_helper_bool<N <= 8>::type type;
+ };
-// template <>
-// struct pnm_io_helper_bool<false>
-// {
-// typedef unsigned short type;
-// };
+ } // end of namespace internal
-// template <unsigned N>
-// struct pnm_io_helper
-// {
-// typedef typename pnm_io_helper_bool<N <= 8>::type type;
-// };
+ } // end of namespace io
-// } // end of namespace internal
+} // end of namespace oln
-// } // end of namespace io
+# define oln_io_type(N) typename oln::io::internal::pnm_io_helper<N>::type
+# define oln_io_type_(N) oln::io::internal::pnm_io_helper<N>::type
-// } // end of namespace oln
-// # define oln_io_type(N) typename oln::io::internal::pnm_io_helper<N>::type
-// # define oln_io_type_(N) oln::io::internal::pnm_io_helper<N>::type
-
-
#endif // ! OLENA_IO_UTILS_HH
Index: oln/canvas/reconstruction.hh
--- oln/canvas/reconstruction.hh (revision 188)
+++ oln/canvas/reconstruction.hh (working copy)
@@ -161,8 +161,8 @@
box<oln_type_of(I1, concrete)> work;
box<oln_type_of(I1, concrete)> output;
- box<I1> marker;
- box<I2> mask;
+ box<const I1> marker;
+ box<const I2> mask;
std::queue<oln_type_of(I1, point) > fifo;
@@ -209,8 +209,8 @@
box<oln_type_of(I1, concrete)> work;
box<oln_type_of(I1, concrete)> output;
- box<I1> marker;
- box<I2> mask;
+ box<const I1> marker;
+ box<const I2> mask;
};
Index: oln/canvas/io.hh
--- oln/canvas/io.hh (revision 188)
+++ oln/canvas/io.hh (working copy)
@@ -31,6 +31,7 @@
# include <iostream>
# include <mlc/any.hh>
+# include <oln/core/box.hh>
# include <oln/core/abstract/image.hh>
# include <oln/io/utils.hh>
@@ -49,6 +50,11 @@
{
}
+ void work()
+ {
+ this->exact().impl_work();
+ }
+
void extra_work()
{
this->exact().impl_extra_work();
@@ -61,10 +67,9 @@
void run()
{
- for (p.row() = 0; p.row() < out.size().nrows(); ++p.row())
+ for (p.row() = 0; p.row() < input.size().nrows(); ++p.row())
{
- for (p.col() = 0; p.col() < out.size().ncols(); ++p.col())
- write_point();
+ work();
extra_work();
}
}
@@ -74,18 +79,60 @@
write(const oln::abstract::image<I>& input,
std::ostream& ostr) :
- input(input),
+ input(input.exact()),
ostr(ostr)
{}
- const I& input;
+ box<const I> input;
std::ostream& ostr;
oln_type_of(I, point) p;
+ };
+
+
+ template <typename I, typename E>
+ struct write_2d: public write<I, E>
+ {
+
+ void impl_work()
+ {
+ for (this->p.col() = 0;
+ this->p.col() < this->input.size().ncols();
+ ++this->p.col())
+ this->write_point();
+ }
+
+ protected:
+ typedef write<I, E> super_type;
+
+ write_2d(const abstract::image<I>& input,
+ std::ostream& ostr) :
+ super_type(input, ostr)
+ {}
+
};
+ template <typename I, typename E>
+ struct write_1d: public write<I, E>
+ {
+ void impl_work()
+ {
+ this->write_point();
+ }
+
+ protected:
+ typedef write<I, E> super_type;
+
+ write_1d(const abstract::image<I>& input,
+ std::ostream& ostr) :
+ super_type(input, ostr)
+ {}
+
+ };
+
+
template <typename I, typename E>
struct read : public mlc::any<E>
{
@@ -107,15 +154,28 @@
this->exact().impl_preconditions();
}
+ void work()
+ {
+ this->exact().impl_work();
+ }
+
+ void get_output(I& ima)
+ {
+ ima = output.unbox();
+ }
+
void run()
{
preconditions();
+ I tmp(hdr.rows, hdr.cols);
+
+ output = tmp;
+
for (p.row() = 0; p.row() < hdr.rows && !istr.eof(); ++p.row())
{
extra_work();
- for (p.col() = 0; p.col() < hdr.cols && !istr_.eof(); ++p.col())
- read_point();
+ work();
}
}
@@ -134,7 +194,49 @@
};
+ template <typename I, typename E>
+ struct read_2d: public read<I, E>
+ {
+ void impl_work()
+ {
+ for (this->p.col() = 0;
+ this->p.col() < this->hdr.cols && !this->istr.eof();
+ ++this->p.col())
+ this->read_point();
+ }
+
+ protected:
+ typedef read<I, E> super_type;
+
+ read_2d(std::istream& istr,
+ const io::internal::pnm_header& hdr) :
+ super_type(istr, hdr)
+ {}
+
+ };
+
+
+ template <typename I, typename E>
+ struct read_1d: public read<I, E>
+ {
+
+ void impl_work()
+ {
+ this->read_point();
+ }
+
+ protected:
+ typedef read<I, E> super_type;
+
+ read_1d(std::istream& istr,
+ const io::internal::pnm_header& hdr) :
+ super_type(istr, hdr)
+ {}
+
+ };
+
+
}
1
0
https://svn.lrde.epita.fr/svn/oln/prototypes/proto-1.0
ChangeLog | 14 +++++++++++
oln/morpho/tags.hh | 39 +++++++++++++++++++++++++++++++++
tests/morpho/tests/dilation | 26 +++++++++-------------
tests/morpho/tests/elementary_dilation | 12 +++++-----
tests/morpho/tests/elementary_erosion | 13 +++++------
tests/morpho/tests/erosion | 5 ----
tests/morpho/tests/reconstruction | 20 ++++++++++------
tests/utils/tests/clone | 3 +-
8 files changed, 92 insertions(+), 40 deletions(-)
Index: olena/ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
* oln/morpho/tags.hh (by_dilation, by_erosion)
(sequential, hybrid, parallel, union-find): New facades.
* tests/morpho/tests/reconstruction (check): Use them.
* tests/morpho/tests/erosion (check): Catch up with current
implementation of erosion.
* tests/morpho/tests/dilation: Aesthetic changes.
* tests/morpho/tests/elementary_dilation,
* tests/morpho/tests/elementary_erosion: Likewise.
Catch up with image_with_nbh definition.
* tests/utils/tests/clone (check): Call oln::clone, not
oln::utils::clone.
2005-05-16 Roland Levillain <roland(a)lrde.epita.fr>
Index: olena/tests/utils/tests/clone
--- olena/tests/utils/tests/clone (revision 187)
+++ olena/tests/utils/tests/clone (working copy)
@@ -1,3 +1,4 @@
+ // -*- C++ -*-
#include "data.hh"
#include <ntg/all.hh>
@@ -17,7 +18,7 @@
ima1 = oln::io::read(rdata("lena.pgm"));
ima2 = oln::io::read(rdata("lena.pgm"));
- ima_copy = oln::utils::clone(ima1);
+ ima_copy = oln::clone(ima1);
oln::level::fill(ima1, 0);
if (oln::level::is_equal(ima2, ima_copy))
Index: olena/tests/morpho/tests/reconstruction
--- olena/tests/morpho/tests/reconstruction (revision 187)
+++ olena/tests/morpho/tests/reconstruction (working copy)
@@ -35,23 +35,27 @@
marker = io::read(rdata("marker.pbm"));
mask = io::read(rdata("mask.pbm"));
- res_dil_hyb = morpho::reconstruction(tag::by_dilation(),
+ res_dil_hyb =
+ morpho::reconstruction(morpho::tag::by_dilation(),
join(marker, neighb_c4()),
mask,
- tag::hybrid());
- res_dil_seq = morpho::reconstruction(tag::by_dilation(),
+ morpho::tag::hybrid());
+ res_dil_seq =
+ morpho::reconstruction(morpho::tag::by_dilation(),
join(marker, neighb_c4()),
mask,
- tag::sequential());
+ morpho::tag::sequential());
- res_ero_hyb = morpho::reconstruction(tag::by_erosion(),
+ res_ero_hyb =
+ morpho::reconstruction(morpho::tag::by_erosion(),
utils::invert(join(marker, neighb_c4())),
utils::invert(mask),
- tag::hybrid());
- res_ero_seq = morpho::reconstruction(tag::by_erosion(),
+ morpho::tag::hybrid());
+ res_ero_seq =
+ morpho::reconstruction(morpho::tag::by_erosion(),
utils::invert(join(marker, neighb_c4())),
utils::invert(mask),
- tag::sequential());
+ morpho::tag::sequential());
if (utils::md5(res_dil_hyb) != key)
return true;
Index: olena/tests/morpho/tests/dilation
--- olena/tests/morpho/tests/dilation (revision 187)
+++ olena/tests/morpho/tests/dilation (working copy)
@@ -8,27 +8,23 @@
#include <oln/level/compare.hh>
#include <ntg/all.hh>
+using namespace oln;
+
bool check()
{
- oln::utils::key::value_type data_key[16] =
+ // MD5 sum of object.pbm's erosion result.
+ // FIXME: Update this sum.
+ utils::key::value_type data_key[16] =
{0xbf, 0x67, 0x3, 0xa1, 0x2d, 0x6c, 0xac, 0xe9,
0xf3, 0x7c, 0x19, 0x4c, 0x3a, 0x3b, 0x4d, 0xaa};
+ utils::key key(data_key);
- oln::utils::key key(data_key);
-
- typedef oln::image2d<ntg::bin> im_type;
+ typedef image2d<ntg::bin> im_type;
im_type ima;
- ima = oln::io::read(rdata("16x16.pbm"));
+ ima = io::read(rdata("16x16.pbm"));
- std::cout << oln::utils::md5(oln::morpho::dilation(ima, oln::win_c8p())) << std::endl;
- if (oln::utils::md5(oln::morpho::dilation(ima, oln::win_c8p())) == key)
- {
- std::cout << "OK" << std::endl;
- return false;
- }
- else
- {
- std::cout << "FAIL" << std::endl;
+ if (utils::md5(morpho::dilation(ima, win_c8p())) != key)
return true;
- }
+
+ return false;
}
Index: olena/tests/morpho/tests/elementary_erosion
--- olena/tests/morpho/tests/elementary_erosion (revision 187)
+++ olena/tests/morpho/tests/elementary_erosion (working copy)
@@ -8,20 +8,21 @@
#include <oln/level/compare.hh>
#include <ntg/all.hh>
+using namespace oln;
+
bool check()
{
// MD5 sum of object.pbm's elementary erosion result.
// FIXME: Replace this fake with the actual result.
- oln::utils::key::value_type data_key[16] =
+ utils::key::value_type data_key[16] =
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
- oln::utils::key key(data_key);
-
- typedef oln::image2d<ntg::bin> im_type;
+ utils::key key(data_key);
+ typedef image2d<ntg::bin> im_type;
im_type ima;
- ima = oln::io::read(rdata("16x16.pbm"));
+ ima = io::read(rdata("16x16.pbm"));
- if (oln::utils::md5(oln::morpho::elementary_erosion(ima) != key)
+ if (utils::md5(morpho::elementary_erosion(join(ima, neighb_c4()))) != key)
return true;
return false;
Index: olena/tests/morpho/tests/elementary_dilation
--- olena/tests/morpho/tests/elementary_dilation (revision 187)
+++ olena/tests/morpho/tests/elementary_dilation (working copy)
@@ -8,20 +8,22 @@
#include <oln/level/compare.hh>
#include <ntg/all.hh>
+using namespace oln;
+
bool check()
{
// MD5 sum of object.pbm's elementary dilation result.
// FIXME: Replace this fake with the actual result.
- oln::utils::key::value_type data_key[16] =
+ utils::key::value_type data_key[16] =
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
- oln::utils::key key(data_key);
+ utils::key key(data_key);
- typedef oln::image2d<ntg::bin> im_type;
+ typedef image2d<ntg::bin> im_type;
im_type ima;
- ima = oln::io::read(rdata("16x16.pbm"));
+ ima = io::read(rdata("16x16.pbm"));
- if (oln::utils::md5(oln::morpho::elementary_dilation(ima) != key)
+ if (utils::md5(morpho::elementary_dilation(join(ima, neighb_c4()))) != key)
return true;
return false;
Index: olena/tests/morpho/tests/erosion
--- olena/tests/morpho/tests/erosion (revision 187)
+++ olena/tests/morpho/tests/erosion (working copy)
@@ -23,11 +23,6 @@
im_type ima;
ima = io::read(rdata("16x16.pbm"));
- // Classical procedure.
- if (utils::md5(morpho::proc::erosion(ima, win_c8p())) != key)
- return true;
-
- // Facade to object-algorithm.
if (utils::md5(morpho::erosion(ima, win_c8p())) != key)
return true;
Index: olena/oln/morpho/tags.hh
--- olena/oln/morpho/tags.hh (revision 187)
+++ olena/oln/morpho/tags.hh (working copy)
@@ -149,6 +149,19 @@
struct by_dilation_type : public oper< by_dilation_type > {};
struct by_erosion_type : public oper< by_erosion_type > {};
+ // Facades.
+ inline const by_dilation_type& by_dilation()
+ {
+ static const by_dilation_type tag = by_dilation_type();
+ return tag;
+ }
+
+ inline const by_erosion_type& by_erosion()
+ {
+ static const by_erosion_type tag = by_erosion_type();
+ return tag;
+ }
+
// Tags for common canvas.
@@ -159,6 +172,32 @@
struct parallel_type : public algo< parallel_type > {};
struct unionfind_type : public algo< unionfind_type > {};
+ // Facades.
+ inline const sequential_type& sequential()
+ {
+ static const sequential_type tag = sequential_type();
+ return tag;
+ }
+
+ inline const hybrid_type& hybrid()
+ {
+ static const hybrid_type tag = hybrid_type();
+ return tag;
+ }
+
+ inline const parallel_type& parallel()
+ {
+ static const parallel_type tag = parallel_type();
+ return tag;
+ }
+
+ inline const unionfind_type& unionfind()
+ {
+ static const unionfind_type tag = unionfind_type();
+ return tag;
+ }
+
+
} // end of namespace oln::morpho::tag
1
0
proto-1.0 187: Fix oln::level::{min, max} and have oln::level:: test pass
by Roland Levillain 16 May '05
by Roland Levillain 16 May '05
16 May '05
En fait, le bug que je cherchais n'avait rien à voir avec des traits
d'Integre manquants ; il s'agissait d'un appel de fonction mal
résolu.
https://svn.lrde.epita.fr/svn/oln/prototypes/proto-1.0
ChangeLog | 5 +++++
oln/ops/arith.hh | 4 ++--
tests/level/tests/max | 3 ---
tests/level/tests/min | 5 -----
4 files changed, 7 insertions(+), 10 deletions(-)
Index: olena/ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
* oln/ops/arith.hh (min, max): Add oln:: namespace qualifier to
resolve the call to the right operator on PWF's.
Index: olena/tests/level/tests/min
--- olena/tests/level/tests/min (revision 186)
+++ olena/tests/level/tests/min (working copy)
@@ -5,8 +5,6 @@
#include <oln/level/compare.hh>
#include <ntg/int.hh>
-
-
bool check()
{
oln::image2d<ntg::int_u8> ima1(10, 10);
@@ -23,6 +21,3 @@
return false;
return true;
}
-
-
-
Index: olena/tests/level/tests/max
--- olena/tests/level/tests/max (revision 186)
+++ olena/tests/level/tests/max (working copy)
@@ -5,8 +5,6 @@
#include <oln/level/compare.hh>
#include <ntg/int.hh>
-
-
bool check()
{
oln::image2d<ntg::int_u8> ima1(10, 10);
@@ -23,4 +21,3 @@
return false;
return true;
}
-
Index: olena/oln/ops/arith.hh
--- olena/oln/ops/arith.hh (revision 186)
+++ olena/oln/ops/arith.hh (working copy)
@@ -46,7 +46,7 @@
min (const abstract::image<L>& lhs,
const abstract::image<R>& rhs)
{
- return image_for_all_p( min(pw_value(lhs), pw_value(rhs)) );
+ return image_for_all_p( oln::min(pw_value(lhs), pw_value(rhs)) );
}
template <typename L, typename R>
@@ -56,7 +56,7 @@
max (const abstract::image<L>& lhs,
const abstract::image<R>& rhs)
{
- return image_for_all_p( max(pw_value(lhs), pw_value(rhs)) );
+ return image_for_all_p( oln::max(pw_value(lhs), pw_value(rhs)) );
}
} // end of namespace oln
1
0
Index: ChangeLog
from Damien Thivolle <damien(a)lrde.epita.fr>
* oln/morpho/reconstruction.hh: Fix indentation.
* oln/canvas/io.hh: New. New I/O canvas.
canvas/io.hh | 144 +++++++++++++++++++++++++++++++++++++++++++++++
morpho/reconstruction.hh | 6 -
2 files changed, 147 insertions(+), 3 deletions(-)
Index: oln/morpho/reconstruction.hh
--- oln/morpho/reconstruction.hh (revision 184)
+++ oln/morpho/reconstruction.hh (working copy)
@@ -108,8 +108,8 @@
template<typename I1, typename I2, typename A>
oln_type_of(I1, concrete)
reconstruction_by_erosion(const abstract::image_with_nbh<I1>& marker,
- const abstract::image<I2>& mask,
- const tag::algo<A>& algo_)
+ const abstract::image<I2>& mask,
+ const tag::algo<A>& algo_)
{
mlc::eq<oln_type_of(I1, grid), oln_type_of(I2, grid)>::ensure();
precondition(marker.size() == mask.size());
@@ -120,7 +120,7 @@
template<typename I1, typename I2>
oln_type_of(I1, concrete)
reconstruction_by_erosion(const abstract::image_with_nbh<I1>& marker,
- const abstract::image<I2>& mask)
+ const abstract::image<I2>& mask)
{
mlc::eq<oln_type_of(I1, grid), oln_type_of(I2, grid)>::ensure();
precondition(marker.size() == mask.size());
Index: oln/canvas/io.hh
--- oln/canvas/io.hh (revision 0)
+++ oln/canvas/io.hh (revision 0)
@@ -0,0 +1,144 @@
+// 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 filek 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_CANVAS_IO_HH
+# define OLENA_CANVAS_IO_HH
+
+# include <iostream>
+
+# include <mlc/any.hh>
+
+# include <oln/core/abstract/image.hh>
+# include <oln/io/utils.hh>
+
+namespace oln {
+
+
+ namespace canvas {
+
+
+ template <typename I, typename E>
+ struct write : public mlc::any<E>
+ {
+
+ void impl_extra_work()
+ {
+ }
+
+ void extra_work()
+ {
+ this->exact().impl_extra_work();
+ }
+
+ void write_point()
+ {
+ this->exact().impl_write_point();
+ }
+
+ void run()
+ {
+ for (p.row() = 0; p.row() < out.size().nrows(); ++p.row())
+ {
+ for (p.col() = 0; p.col() < out.size().ncols(); ++p.col())
+ write_point();
+ extra_work();
+ }
+ }
+
+
+ protected:
+
+ write(const oln::abstract::image<I>& input,
+ std::ostream& ostr) :
+ input(input),
+ ostr(ostr)
+ {}
+
+ const I& input;
+ std::ostream& ostr;
+ oln_type_of(I, point) p;
+
+
+ };
+
+
+ template <typename I, typename E>
+ struct read : public mlc::any<E>
+ {
+
+ void impl_extra_work() {}
+
+ void extra_work()
+ {
+ this->exact().impl_extra_work();
+ }
+
+ void read_point()
+ {
+ this->exact().impl_read_point();
+ }
+
+ void preconditions()
+ {
+ this->exact().impl_preconditions();
+ }
+
+ void run()
+ {
+ preconditions();
+
+ for (p.row() = 0; p.row() < hdr.rows && !istr.eof(); ++p.row())
+ {
+ extra_work();
+ for (p.col() = 0; p.col() < hdr.cols && !istr_.eof(); ++p.col())
+ read_point();
+ }
+ }
+
+ protected:
+
+ read(std::istream& istr,
+ const io::internal::pnm_header& hdr) :
+ istr(istr),
+ hdr(hdr)
+ {}
+
+ box<I> output;
+ std::istream& istr;
+ const io::internal::pnm_header& hdr;
+ oln_type_of(I, point) p;
+
+ };
+
+
+ }
+
+
+}
+
+
+#endif // ! OLENA_CANVAS_IO_HH
1
0
13 May '05
En regardant oln/core/abstract/image_dimension.hh, je me suis demandé
si ce ne devrait pas être le rôle des classes oln::abstract::image1d,
oln::abstract::image2d et oln::abstract::image3d de définir
operator(), point_type, etc., au lieu de oln::image1d, oln::image2d et
oln::image3d (comme c'était grosso modo le cas dans Olena 0.10, dans
oln::abstract::image_with_dim)).
https://svn.lrde.epita.fr/svn/oln/prototypes/proto-1.0
ChangeLog | 24 ++++++++++++++++++++++
oln/core/1d/image1d.hh | 18 ++++++++++++++++
oln/core/2d/image2d.hh | 19 +++++++++++++++++
oln/core/3d/image3d.hh | 20 ++++++++++++++++++
oln/core/abstract/image.hh | 4 +--
oln/utils/clone.hh | 2 -
tests/arith/Makefile.am | 5 ----
tests/arith/tests/max | 25 -----------------------
tests/arith/tests/min | 27 -------------------------
tests/level/tests/max | 5 ++--
tests/level/tests/min | 5 ++--
tests/pw/tests/arith-image | 48 +++++++++++++++++++++++++++++++++++++++++++++
tests/pw/tests/arith-value | 28 ++++++++++++++++++++++++++
13 files changed, 166 insertions(+), 64 deletions(-)
Index: olena/ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add operator()'s on oln::image1d, oln::image2d and oln::image3d.
* oln/core/abstract/image.hh
(operator[](const point_type&) const): Return a value_box<const D>
instead of a value_box<D>.
(operator[](const point_type&)): Return a value_box<D> instead of
a value_box<const D>.
* oln/core/1d/image1d.hh (operator()(coord_t) const)
(operator()(coord_t))
* oln/core/2d/image2d.hh (operator()(coord_t, coord_t) const)
(operator()(coord_t, coord_t))
* oln/core/3d/image3d.hh
(operator()(coord_t, coord_t, coord_t) const)
(operator()(coord_t, coord_t, coord_t)): New operators.
* oln/utils/clone.hh (clone): Adjust comment.
* tests/arith: Remove directory.
* tests/pw/tests/arith-value, tests/pw/tests/arith-image: New
tests.
* tests/level/tests/min, tests/level/tests/max: New
tests (not yet working).
Index: olena/tests/pw/tests/arith-value
--- olena/tests/pw/tests/arith-value (revision 0)
+++ olena/tests/pw/tests/arith-value (revision 0)
@@ -0,0 +1,28 @@
+ // -*- C++ -*-
+#include <iostream>
+#include <cmath>
+
+#include <oln/core/pw/arith.hh>
+#include <oln/core/pw/literal.hh>
+#include <oln/core/pw/value.hh>
+#include <oln/core/any/point.hh>
+
+using namespace oln;
+
+// Check arith operators on pw::value's.
+bool check()
+{
+ any_point p;
+ pw::literal<int> pv1(p_literal(42));
+ pw::literal<int> pv2(p_literal(51));
+
+ int res_min = min(pv1, pv2)(p);
+ if (res_min != 42)
+ return true;
+
+ int res_max = max(pv1, pv2)(p);
+ if (res_max != 51)
+ return true;
+
+ return false;
+}
Index: olena/tests/pw/tests/arith-image
--- olena/tests/pw/tests/arith-image (revision 0)
+++ olena/tests/pw/tests/arith-image (revision 0)
@@ -0,0 +1,48 @@
+ // -*- C++ -*-
+#include <iostream>
+#include <cmath>
+
+#include <oln/core/pw/arith.hh>
+#include <oln/core/pw/literal.hh>
+#include <oln/core/pw/value.hh>
+#include <oln/core/2d/image2d.hh>
+#include <oln/core/2d/point2d.hh>
+
+using namespace oln;
+
+// Check arith operators on pw::images's.
+bool check()
+{
+ typedef image2d<int> ima_type;
+
+ // ima1 =
+ // 1 2 3
+ // 4 5 6
+ // 7 8 9
+ ima_type ima1(3, 3);
+ ima1(0, 0) = 1; ima1(0, 1) = 2; ima1(0, 2) = 3;
+ ima1(1, 0) = 4; ima1(1, 1) = 5; ima1(1, 2) = 6;
+ ima1(2, 0) = 7; ima1(2, 1) = 8; ima1(2, 2) = 9;
+
+ // ima2 =
+ // 1 2 3
+ // 4 5 6
+ // 7 8 9
+ ima_type ima2(3, 3);
+ ima2(0, 0) = 9; ima2(0, 1) = 8; ima2(0, 2) = 7;
+ ima2(1, 0) = 6; ima2(1, 1) = 5; ima2(1, 2) = 4;
+ ima2(2, 0) = 3; ima2(2, 1) = 2; ima2(2, 2) = 1;
+
+ pw::value<ima_type> pv1(pw_value(ima1));
+ pw::value<ima_type> pv2(pw_value(ima2));
+
+ point2d p1(0, 1);
+ if (min(pv1, pv2)(p1) != 2)
+ return true;
+
+ point2d p2(2, 0);
+ if (max(pv1, pv2)(p2) != 7)
+ return true;
+
+ return false;
+}
Index: olena/tests/level/tests/min
--- olena/tests/level/tests/min (revision 181)
+++ olena/tests/level/tests/min (working copy)
@@ -1,5 +1,6 @@
+ // -*- C++ -*-
#include <oln/basics2d.hh>
-#include <oln/arith/min.hh>
+#include <oln/level/arith.hh>
#include <oln/level/fill.hh>
#include <oln/level/compare.hh>
#include <ntg/int.hh>
@@ -16,7 +17,7 @@
oln::image2d<ntg::int_u8> ima;
- ima = oln::arith::min(ima1, ima2);
+ ima = oln::level::min(ima1, ima2);
if (oln::level::is_equal(ima, ima1))
return false;
Index: olena/tests/level/tests/max
--- olena/tests/level/tests/max (revision 181)
+++ olena/tests/level/tests/max (working copy)
@@ -1,5 +1,6 @@
+ // -*- C++ -*-
#include <oln/basics2d.hh>
-#include <oln/arith/max.hh>
+#include <oln/level/arith.hh>
#include <oln/level/fill.hh>
#include <oln/level/compare.hh>
#include <ntg/int.hh>
@@ -16,7 +17,7 @@
oln::image2d<ntg::int_u8> ima;
- ima = oln::arith::max(ima1, ima2);
+ ima = oln::level::max(ima1, ima2);
if (oln::level::is_equal(ima, ima2))
return false;
Index: olena/tests/arith/tests/min
--- olena/tests/arith/tests/min (revision 185)
+++ olena/tests/arith/tests/min (working copy)
@@ -1,27 +0,0 @@
-#include <oln/basics2d.hh>
-#include <oln/arith/min.hh>
-#include <oln/level/fill.hh>
-#include <oln/level/compare.hh>
-#include <ntg/int.hh>
-
-
-
-bool check()
-{
- oln::image2d<ntg::int_u8> ima1(10, 10);
- oln::image2d<ntg::int_u8> ima2(10, 10);
-
- oln::level::fill(ima1, 10);
- oln::level::fill(ima2, 20);
-
- oln::image2d<ntg::int_u8> ima;
-
- ima = oln::arith::min(ima1, ima2);
-
- if (oln::level::is_equal(ima, ima1))
- return false;
- return true;
-}
-
-
-
Index: olena/tests/arith/tests/max
--- olena/tests/arith/tests/max (revision 185)
+++ olena/tests/arith/tests/max (working copy)
@@ -1,25 +0,0 @@
-#include <oln/basics2d.hh>
-#include <oln/arith/max.hh>
-#include <oln/level/fill.hh>
-#include <oln/level/compare.hh>
-#include <ntg/int.hh>
-
-
-
-bool check()
-{
- oln::image2d<ntg::int_u8> ima1(10, 10);
- oln::image2d<ntg::int_u8> ima2(10, 10);
-
- oln::level::fill(ima1, 10);
- oln::level::fill(ima2, 20);
-
- oln::image2d<ntg::int_u8> ima;
-
- ima = oln::arith::max(ima1, ima2);
-
- if (oln::level::is_equal(ima, ima2))
- return false;
- return true;
-}
-
Index: olena/tests/arith/Makefile.am
--- olena/tests/arith/Makefile.am (revision 185)
+++ olena/tests/arith/Makefile.am (working copy)
@@ -1,5 +0,0 @@
-include ../check/Makefile.runtests
-include ../check/Makefile.check
-
-
-check-local: check-runtests
Index: olena/oln/core/abstract/image.hh
--- olena/oln/core/abstract/image.hh (revision 185)
+++ olena/oln/core/abstract/image.hh (working copy)
@@ -443,13 +443,13 @@
return this->delegate().hold_large(p);
}
- value_box<D> operator[](const point_type& p) const
+ value_box<const D> operator[](const point_type& p) const
{
precondition(this->hold_large(p));
return this->delegate().operator[](p);
}
- value_box<const D> operator[](const point_type& p)
+ value_box<D> operator[](const point_type& p)
{
precondition(this->hold_large(p));
return this->delegate().operator[](p);
Index: olena/oln/core/1d/image1d.hh
--- olena/oln/core/1d/image1d.hh (revision 185)
+++ olena/oln/core/1d/image1d.hh (working copy)
@@ -129,6 +129,24 @@
this->exact_ptr = this;
}
+ public:
+
+ /*! Return a reference to the value stored at coordinate \a index
+ ** in the current (const) image.
+ */
+ value_box< const image1d<T> > operator()(coord_t index) const
+ {
+ return (*this)[point1d(index)];
+ }
+
+ /*! Return a reference to the value stored at coordinate \a index
+ ** in the current image.
+ */
+ value_box< image1d<T> > operator()(coord_t index)
+ {
+ return (*this)[point1d(index)];
+ }
+
};
Index: olena/oln/core/2d/image2d.hh
--- olena/oln/core/2d/image2d.hh (revision 185)
+++ olena/oln/core/2d/image2d.hh (working copy)
@@ -202,6 +202,25 @@
// without impl
image2d(const image2d&);
+
+ public:
+
+ /*! Return a reference to the value stored at coordinate
+ ** (\a row, \a col) in the current (const) image.
+ */
+ value_box< const image2d<T> > operator()(coord_t row, coord_t col) const
+ {
+ return (*this)[point2d(row, col)];
+ }
+
+ /*! Return a reference to the value stored at coordinate
+ ** (\a row, \a col) in the current image.
+ */
+ value_box< image2d<T> > operator()(coord_t row, coord_t col)
+ {
+ return (*this)[point2d(row, col)];
+ }
+
};
Index: olena/oln/core/3d/image3d.hh
--- olena/oln/core/3d/image3d.hh (revision 185)
+++ olena/oln/core/3d/image3d.hh (working copy)
@@ -129,6 +129,26 @@
this->exact_ptr = this;
}
+ public:
+
+ /*! Return a reference to the value stored at coordinate
+ ** (\a slice, \a row, \a col) in the current (const) image.
+ */
+ value_box< const image3d<T> >
+ operator()(coord_t slice, coord_t row, coord_t col) const
+ {
+ return (*this)[point3d(slice, row, col)];
+ }
+
+ /*! Return a reference to the value stored at coordinate
+ ** (\a slice, \a row, \a col) in the current image.
+ */
+ value_box< image3d<T> >
+ operator()(coord_t slice, coord_t row, coord_t col)
+ {
+ return (*this)[point3d(slice, row, col)];
+ }
+
};
Index: olena/oln/utils/clone.hh
--- olena/oln/utils/clone.hh (revision 185)
+++ olena/oln/utils/clone.hh (working copy)
@@ -35,7 +35,7 @@
namespace oln
{
- // Fwd decl of erosion's facade.
+ // Fwd decl of clone's facade.
template <typename I>
oln_type_of(I, concrete) clone(const abstract::image<I>& input);
1
0
Index: ChangeLog
from Damien Thivolle <damien(a)lrde.epita.fr>
* oln/core/gen/regular_window.hh: Add splitting methods.
* oln/morpho/reconstruction.hh: New. Add generic facade for the
reconstruction.
* oln/morpho/reconstruction_by_erosion.inctrash: Remove.
* oln/morpho/reconstruction_by_dilation.hh: New. Return of the generic
reconstructions by dilation.
* oln/morpho/splitse.trash: Remove.
* oln/morpho/reconstruction_by_erosion.hh: New. Return of the generic
reconstructions by erosion.
* oln/morpho/reconstruction_by_dilation.inctrash: Remove.
* oln/canvas: New.
* oln/canvas/reconstruction.hh: New. Add hybrid and sequential
reconstruction canvas.
* oln/canvas/backandforth.hh: New. Contains generic back and forth
canvas: both classical and until_convergence versions.
canvas/backandforth.hh | 198 +++++++++++++++++++++++++
canvas/reconstruction.hh | 224 +++++++++++++++++++++++++++++
core/gen/regular_window.hh | 108 +++++++++++++
morpho/reconstruction.hh | 136 +++++++++++++++++
morpho/reconstruction_by_dilation.hh | 151 +++++++++++++++++++
morpho/reconstruction_by_dilation.inctrash | 142 ------------------
morpho/reconstruction_by_erosion.hh | 150 +++++++++++++++++++
morpho/reconstruction_by_erosion.inctrash | 141 ------------------
morpho/splitse.trash | 209 ---------------------------
9 files changed, 962 insertions(+), 497 deletions(-)
Index: oln/core/gen/regular_window.hh
--- oln/core/gen/regular_window.hh (revision 183)
+++ oln/core/gen/regular_window.hh (working copy)
@@ -33,7 +33,7 @@
# include <iterator>
# include <vector>
# include <set>
-
+
# include <mlc/contract.hh>
# include <oln/core/abstract/grid.hh>
# include <oln/core/abstract/dpoint.hh>
@@ -53,7 +53,7 @@
// props
template <typename G, typename E>
- struct set_props< category::window, abstract::regular_window<G, E> >
+ struct set_props< category::window, abstract::regular_window<G, E> >
{
typedef G grid_type;
typedef oln_grd_type_of(G, dpoint) dpoint_type;
@@ -61,9 +61,9 @@
typedef regular_fwd_qiter<G,E> fwd_iter_type;
// typedef regular_fwd_dpiter<G> fwd_dpiter_type; // FIXME: later...
};
-
+
namespace abstract
{
@@ -72,7 +72,7 @@
{
public:
-
+
typedef regular_window<G, E> self_type;
typedef oln_grd_type_of(G, coord) coord_type;
@@ -121,6 +121,101 @@
return this->dp_;
}
+
+ self_type get_fwd_win() const
+ {
+ self_type out;
+
+ for (unsigned i = 0; i < this->card(); ++i)
+ {
+ const dpoint_type& dp = dp_[i];
+
+ for (unsigned n = 0; n < dim; ++n)
+ if (dp.nth(n) < 0)
+ {
+ out.add(dp);
+ break;
+ }
+ else if (dp.nth(n) > 0)
+ break;
+ }
+ return out;
+ }
+
+
+ self_type get_fwd_win_p() // abstract::window<W>& win)
+ {
+ self_type out;
+
+
+ for (unsigned i = 0; i < this->card(); ++i)
+ {
+ const dpoint_type& dp = dp_[i];
+
+ unsigned n;
+ for (n = 0; n < dim; ++n)
+ if (dp.nth(n) < 0)
+ {
+ out.add(dp);
+ break;
+ }
+ else if (dp.nth(n) > 0)
+ break;
+
+ // All p.nth(n) are 0.
+ if (n == dim)
+ out.add(dp);
+
+ }
+ return out;
+ }
+
+
+ self_type get_bkd_win()
+ {
+ self_type out;
+
+ for (unsigned i = 0; i < card(); ++i)
+ {
+ const dpoint_type& dp = dp_[i];
+
+ for (unsigned n = 0; n < dim; ++n)
+ if (dp.nth(n) > 0)
+ {
+ out.add(dp);
+ break;
+ }
+ else if (dp.nth(n) < 0)
+ break;
+ }
+ return out;
+ }
+
+
+ self_type get_bkd_win_p()
+ {
+ self_type out;
+
+ for (unsigned i = 0; i < card(); ++i)
+ {
+ const dpoint_type& dp = win.get_dp()[i];
+
+ unsigned n;
+ for (n = 0; n < dim; ++n)
+ if (dp.nth(n) > 0)
+ {
+ out.add(dp);
+ break;
+ }
+ else if (dp.nth(n) < 0)
+ break;
+ // All p.nth(n) are 0.
+ if (n == dim)
+ out.add(dp);
+ }
+ return out;
+ }
+
protected:
regular_window() :
@@ -153,8 +248,11 @@
this->delta_update_(dp);
}
+
+
+
private:
-
+
std::set<dpoint_type, fwd_less_dpoint> dpset_;
std::vector<dpoint_type> dp_;
coord_type delta_;
Index: oln/morpho/reconstruction.hh
--- oln/morpho/reconstruction.hh (revision 0)
+++ oln/morpho/reconstruction.hh (revision 0)
@@ -0,0 +1,136 @@
+// Copyright (C) 2001, 2002, 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 filek 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_MORPHO_RECONSTRUCTION_HH
+# define OLENA_MORPHO_RECONSTRUCTION_HH
+
+# include <oln/morpho/reconstruction_by_dilation.hh>
+# include <oln/morpho/reconstruction_by_erosion.hh>
+
+namespace oln {
+
+
+ namespace morpho {
+
+
+ namespace impl {
+
+ // Generic implementation of reconstruction (routine).
+
+ template<typename Op, typename A, typename I1, typename I2>
+ oln_type_of(I1, concrete)
+ reconstruction_(const abstract::image_with_nbh<I1>& marker,
+ const abstract::image<I2>& mask)
+ {
+ reconstruction<Op, A, I1, I2> tmp(marker, mask);
+ // tmp.entering(); FIXME: something like that ?
+ tmp.run();
+ // tmp.exiting(); FIXME: something like that ?
+ return tmp.get_output();
+ }
+
+ } // end of namespace impl
+
+ /// Generic reconstruction (facade).
+
+ template<typename Op, typename I1, typename I2, typename A>
+ oln_type_of(I1, concrete)
+ reconstruction(const tag::oper<Op>& oper_,
+ const abstract::image_with_nbh<I1>& marker,
+ const abstract::image<I2>& mask,
+ const tag::algo<A>& algo_)
+ {
+ mlc::eq<oln_type_of(I1, grid), oln_type_of(I2, grid)>::ensure();
+ precondition(marker.size() == mask.size());
+
+ entering("morpho::reconstruction");
+
+ oln_type_of(I1, concrete) output("output");
+// output = impl::reconstruction_(oper_, marker.exact(), mask.exact(), algo_);
+
+ exiting("morpho::reconstruction");
+ return output;
+
+ }
+
+ // by dilation
+
+ template<typename I1, typename I2, typename A>
+ oln_type_of(I1, concrete)
+ reconstruction_by_dilation(const abstract::image_with_nbh<I1>& marker,
+ const abstract::image<I2>& mask,
+ const tag::algo<A>& algo_)
+ {
+ mlc::eq<oln_type_of(I1, grid), oln_type_of(I2, grid)>::ensure();
+ precondition(marker.size() == mask.size());
+
+ return reconstruction(tag::by_dilation_type(), marker, mask, algo_);
+ }
+
+ template<typename I1, typename I2>
+ oln_type_of(I1, concrete)
+ reconstruction_by_dilation(const abstract::image_with_nbh<I1>& marker,
+ const abstract::image<I2>& mask)
+ {
+ mlc::eq<oln_type_of(I1, grid), oln_type_of(I2, grid)>::ensure();
+ precondition(marker.size() == mask.size());
+
+ return reconstruction(tag::by_dilation_type(), marker,
+ mask, tag::hybrid_type());
+ }
+
+ // by erosion
+
+ template<typename I1, typename I2, typename A>
+ oln_type_of(I1, concrete)
+ reconstruction_by_erosion(const abstract::image_with_nbh<I1>& marker,
+ const abstract::image<I2>& mask,
+ const tag::algo<A>& algo_)
+ {
+ mlc::eq<oln_type_of(I1, grid), oln_type_of(I2, grid)>::ensure();
+ precondition(marker.size() == mask.size());
+
+ return reconstruction(tag::by_erosion_type(), marker, mask, algo_);
+ }
+
+ template<typename I1, typename I2>
+ oln_type_of(I1, concrete)
+ reconstruction_by_erosion(const abstract::image_with_nbh<I1>& marker,
+ const abstract::image<I2>& mask)
+ {
+ mlc::eq<oln_type_of(I1, grid), oln_type_of(I2, grid)>::ensure();
+ precondition(marker.size() == mask.size());
+
+ return reconstruction(tag::by_erosion_type(), marker,
+ mask, tag::hybrid_type());
+ }
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+#endif // ! OLENA_MORPHO_RECONSTRUCTION_HH
Index: oln/morpho/reconstruction_by_erosion.inctrash
--- oln/morpho/reconstruction_by_erosion.inctrash (revision 183)
+++ oln/morpho/reconstruction_by_erosion.inctrash (working copy)
@@ -1,141 +0,0 @@
-// 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 filek 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.
-
-namespace oln {
-
- namespace morpho {
-
- namespace impl {
-
- // Sequential version
-
- template<typename I1, typename I2>
- struct generic_reconstruction <tag::by_erosion, tag::sequential, I1, I2>
- : public generic_reconstruction_canvas<I1, I2, tag::sequential,
- generic_reconstruction<tag::by_erosion, tag::sequential, I1, I2> >
- {
- typedef generic_reconstruction<tag::by_erosion,
- tag::sequential, I1,I2> self_type;
- typedef generic_reconstruction_canvas<I1, I2, tag::sequential,
- self_type> super_type;
-
- generic_reconstruction(const abstract::image_with_nbh<I1>& marker,
- const abstract::image<I2>& mask) :
- super_type(marker, mask)
- {
- }
-
-
- void impl_bkd_loop_body()
- {
- this->output[this->bkd_p] = ntg::max(morpho::min(this->output,
- this->bkd_p,
- this->win_minus),
- this->mask[this->bkd_p].value());
- }
-
- void impl_fwd_loop_body()
- {
- this->output[this->fwd_p] = ntg::max(morpho::min(this->output,
- this->fwd_p,
- this->win_plus),
- this->mask[this->fwd_p].value());
- }
-
- void impl_preconditions()
- {
- precondition(level::is_greater_or_equal(this->marker, this->mask));
- }
-
- };
-
- // Hybrid version
-
- template<typename I1, typename I2>
- struct generic_reconstruction <tag::by_erosion, tag::hybrid, I1, I2>
- : public generic_reconstruction_canvas<I1, I2, tag::hybrid,
- generic_reconstruction<tag::by_erosion, tag::hybrid, I1, I2> >
- {
- typedef generic_reconstruction<tag::by_erosion,
- tag::hybrid, I1,I2> self_type;
- typedef generic_reconstruction_canvas<I1, I2, tag::hybrid,
- self_type> super_type;
-
- generic_reconstruction(const abstract::image_with_nbh<I1>& marker,
- const abstract::image<I2>& mask) :
- super_type(marker, mask)
- {
- }
-
-
-
- void impl_bkd_loop_body()
- {
- this->output[this->bkd_p] = ntg::max(morpho::min(this->work,
- this->bkd_p,
- this->win_minus),
- this->mask[this->bkd_p].value());
- }
-
- void impl_fwd_loop_body()
- {
- this->output[this->fwd_p] = ntg::max(morpho::min(this->work,
- this->fwd_p,
- this->win_plus),
- this->mask[this->fwd_p].value());
- }
-
- void impl_fifo_loop_body()
- {
- if ((this->output[this->q] > this->output[this->p]) &&
- (this->mask[this->q] != this->output[this->q]))
- {
- this->output[this->q] = ntg::min(this->output[this->p].value(),
- this->mask[this->q].value());
- this->fifo.push(this->q);
- }
- }
-
- bool impl_exist_init()
- {
- return this->output.hold(this->q) &&
- (this->output[this->q] > this->output[this->bkd_p]) &&
- (this->output[this->q] > this->mask[this->q]);
- }
-
- void impl_preconditions()
- {
- precondition(level::is_greater_or_equal(this->marker, this->mask));
- }
-
- };
-
- }
-
- }
-
-}
Index: oln/morpho/reconstruction_by_dilation.hh
--- oln/morpho/reconstruction_by_dilation.hh (revision 0)
+++ oln/morpho/reconstruction_by_dilation.hh (revision 0)
@@ -0,0 +1,151 @@
+// 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 filek 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_MORPHO_RECONSTRUCTION_BY_DILATION_HH
+# define OLENA_MORPHO_RECONSTRUCTION_BY_DILATION_HH
+
+# include <oln/canvas/reconstruction.hh>
+# include <oln/morpho/tags.hh>
+
+namespace oln {
+
+ namespace morpho {
+
+ namespace impl {
+
+ // Sequential version
+ template<typename I1, typename I2>
+ struct reconstruction <tag::by_dilation_type, tag::sequential_type, I1, I2>
+ : public canvas::sequential_reconstruction<I1, I2,
+ reconstruction<tag::by_dilation_type, tag::sequential_type, I1, I2> >
+ {
+ typedef reconstruction<tag::by_dilation_type,
+ tag::sequential_type, I1,I2> self_type;
+ typedef canvas::sequential_reconstruction<I1, I2, self_type> super_type;
+
+ reconstruction(const abstract::image_with_nbh<I1>& marker,
+ const abstract::image<I2>& mask) :
+ super_type(marker, mask)
+ {
+ }
+
+
+ void impl_bkd_loop_body()
+ {
+ this->output[this->bkd_p] = ntg::min(morpho::max(this->output,
+ this->bkd_p,
+ this->win_minus),
+ this->mask[this->bkd_p]);
+ }
+
+ void impl_fwd_loop_body()
+ {
+ this->output[this->fwd_p] = ntg::min(morpho::max(this->output,
+ this->fwd_p,
+ this->win_plus),
+ this->mask[this->fwd_p]);
+ }
+
+ // FIXME: unused...
+ void impl_preconditions()
+ {
+ precondition(level::is_greater_or_equal(this->mask, this->marker));
+ }
+
+ };
+
+
+ // Hybrid version
+
+ template<typename I1, typename I2>
+ struct reconstruction <tag::by_dilation_type, tag::hybrid_type, I1, I2>
+ : public canvas::hybrid_reconstruction<I1, I2,
+ reconstruction<tag::by_dilation_type, tag::hybrid_type, I1, I2> >
+ {
+ typedef reconstruction<tag::by_dilation_type,
+ tag::hybrid_type, I1,I2> self_type;
+ typedef canvas::hybrid_reconstruction<I1, I2,
+ self_type> super_type;
+
+ reconstruction(const abstract::image_with_nbh<I1>& marker,
+ const abstract::image<I2>& mask) :
+ super_type(marker, mask)
+ {
+ }
+
+
+
+ void impl_bkd_loop_body()
+ {
+ this->output[this->bkd_p] = ntg::min(morpho::max(this->work,
+ this->bkd_p,
+ this->win_minus),
+ this->mask[this->bkd_p]);
+ }
+
+ void impl_fwd_loop_body()
+ {
+ this->output[this->fwd_p] = ntg::min(morpho::max(this->work,
+ this->fwd_p,
+ this->win_plus),
+ this->mask[this->fwd_p]);
+ }
+
+ void impl_fifo_loop_body()
+ {
+ if ((this->output[this->q] < this->output[this->p]) &&
+ (this->mask[this->q] != this->output[this->q]))
+ {
+ this->output[this->q] = ntg::min(this->output[this->p],
+ this->mask[this->q]);
+ this->fifo.push(this->q);
+ }
+ }
+
+ bool impl_exist_init()
+ {
+ return this->output.hold(this->q) &&
+ (this->output[this->q] < this->output[this->bkd_p]) &&
+ (this->output[this->q] < this->mask[this->q]);
+ }
+
+ //FIXME: unused...
+ void impl_preconditions()
+ {
+ precondition(level::is_greater_or_equal(this->mask, this->marker));
+ }
+
+ };
+
+ }
+
+ }
+
+}
+
+
+#endif // ! OLENA_MORPHO_RECONSTRUCTION_BY_DILATION_HH
Index: oln/morpho/splitse.trash
--- oln/morpho/splitse.trash (revision 183)
+++ oln/morpho/splitse.trash (working copy)
@@ -1,209 +0,0 @@
-// Copyright (C) 2001, 2002, 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_MORPHO_SPLITSE_HH
-# define OLENA_MORPHO_SPLITSE_HH
-
-# include <oln/basics.hh>
-
-# include <oln/core/1d/size1d.hh>
-# include <oln/core/2d/size2d.hh>
-# include <oln/core/3d/size3d.hh>
-
-# include <oln/core/abstract/window.hh>
-# include <oln/core/abstract/window.hh>
-
-
-namespace oln {
- namespace morpho {
-
- template <class S>
- struct dim_traits
- {
- };
-
- template <>
- struct dim_traits<size1d>
- {
- enum {dim = 1};
- };
-
- template <>
- struct dim_traits<size2d>
- {
- enum {dim = 2};
- };
-
- template <>
- struct dim_traits<size3d>
- {
- enum {dim = 3};
- };
-
- /*!
- ** \brief Get a sub part of a window.
- **
- ** \param E Exact type of the window.
- **
- ** \arg win The window.
- **
- ** A point p take part of the new window if it exists
- ** a i that belongs to [[0..dim-1]] like p(i) < 0 and for all j
- ** that belongs to [[0..i-1]] p(j) = 0.
- **
- */
-
-
- template<class W>
- W
- get_plus_win_only(const W& win) // FIXME: abstract::window<W>& win)
- {
- W out;
- for (unsigned i = 0; i < win.card(); ++i)
- {
- const oln_wn_type_of(W, dpoint)& dp = win.get_dp()[i];
- unsigned n;
- for (n = 0; n < dim_traits<oln_wn_type_of(W, size)>::dim; ++n)
- if (dp.nth(n) < 0) {
- out.add(dp);
- break;
- } else if (dp.nth(n) > 0) {
- break;
- }
- }
- return out;
- }
-
- /*!
- ** \brief Get a sub part of a window.
- **
- ** \param W Exact type of the window.
- **
- ** \arg win The window.
- **
- ** A point p take part of the new window if it exists
- ** a i that belongs to [[0..dim-1]] like p(i) < 0 and for all j
- ** that belongs to [[0..i-1]] p(j) = 0 or if for all i that
- ** belongs to [[0..dim-1]] p(i) = 0.
- **
- */
- template<class W>
- W
- get_plus_win_p(const W& win) // abstract::window<W>& win)
- {
- W out;
- for (unsigned i = 0; i < win.card(); ++i)
- {
- const oln_wn_type_of(W, dpoint)& dp = win.get_dp()[i];
- unsigned n;
- for (n = 0; n < dim_traits<oln_wn_type_of(W, size)>::dim; ++n)
- if (dp.nth(n) < 0) {
- out.add(dp);
- break;
- } else if (dp.nth(n) > 0) {
- break;
- }
- // All p.nth(n) are 0.
- if (n == dim_traits<oln_wn_type_of(W, size)>::dim)
- out.add(dp);
- }
- return out;
- }
-
- /*!
- ** \brief Get a sub part of a window.
- **
- ** \param W Exact type of the window.
- **
- ** \arg win The window.
- **
- ** A point p take part of the new window if it exists
- ** a i that belongs to [[0..dim-1]] like p(i) > 0 and for all j
- ** that belongs to [[0..i-1]] p(j) = 0.
- **
- */
- template<class W>
- W
- get_minus_win_only(const W& win) // abstract::window<W>& win)
- {
- W out;
- for (unsigned i = 0; i < win.card(); ++i)
- {
- const oln_wn_type_of(W, dpoint)& dp = win.get_dp()[i];
- unsigned n;
- for (n = 0; n < dim_traits<oln_wn_type_of(W, size)>::dim; ++n)
- if (dp.nth(n) > 0) {
- out.add(dp);
- break;
- } else if (dp.nth(n) < 0) {
- break;
- }
- }
- return out;
- }
-
- /*!
- ** \brief Get a sub part of a window.
- **
- ** \param W Exact type of the window.
- **
- ** \arg win The window.
- **
- ** A point p take part of the new window if it exists
- ** a i that belongs to [[0..dim-1]] like p(i) > 0 and for all j
- ** that belongs to [[0..i-1]] p(j) = 0 or if for all i that
- ** belongs to [[0..dim-1]] p(i) = 0.
- **
- */
- template<class W>
- W
- get_minus_win_p(const W& win) // abstract::window<W>& win)
- {
- W out;
- for (unsigned i = 0; i < win.card(); ++i)
- {
- const oln_wn_type_of(W, dpoint)& dp = win.get_dp()[i];
- unsigned n;
- for (n = 0; n < dim_traits<oln_wn_type_of(W, size)>::dim; ++n)
- if (dp.nth(n) > 0) {
- out.add(dp);
- break;
- } else if (dp.nth(n) < 0) {
- break;
- }
- // All p.nth(n) are 0.
- if (n == dim_traits<oln_wn_type_of(W, size)>::dim)
- out.add(dp);
- }
- return out;
- }
-
- } // end of namespace oln::morpho
-
-} // end of namespace oln
-
-#endif // ! OLENA_MORPHO_SPLITSE_HH
Index: oln/morpho/reconstruction_by_erosion.hh
--- oln/morpho/reconstruction_by_erosion.hh (revision 0)
+++ oln/morpho/reconstruction_by_erosion.hh (revision 0)
@@ -0,0 +1,150 @@
+// 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 filek 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_MORPHO_RECONSTRUCTION_BY_EROSION_HH
+# define OLENA_MORPHO_RECONSTRUCTION_BY_EROSION_HH
+
+# include <oln/canvas/reconstruction.hh>
+# include <oln/morpho/tags.hh>
+
+namespace oln {
+
+ namespace morpho {
+
+ namespace impl {
+
+ // Sequential version
+
+ template<typename I1, typename I2>
+ struct reconstruction <tag::by_erosion_type, tag::sequential_type, I1, I2>
+ : public canvas::sequential_reconstruction<I1, I2,
+ reconstruction<tag::by_erosion_type,
+ tag::sequential_type, I1, I2> >
+ {
+ typedef reconstruction<tag::by_erosion_type,
+ tag::sequential_type, I1, I2> self_type;
+ typedef canvas::sequential_reconstruction<I1, I2, self_type> super_type;
+
+ reconstruction(const abstract::image_with_nbh<I1>& marker,
+ const abstract::image<I2>& mask) :
+ super_type(marker, mask)
+ {
+ }
+
+
+ void impl_bkd_loop_body()
+ {
+ this->output[this->bkd_p] = ntg::max(morpho::min(this->output,
+ this->bkd_p,
+ this->win_minus),
+ this->mask[this->bkd_p]);
+ }
+
+ void impl_fwd_loop_body()
+ {
+ this->output[this->fwd_p] = ntg::max(morpho::min(this->output,
+ this->fwd_p,
+ this->win_plus),
+ this->mask[this->fwd_p]);
+ }
+
+ // FIXME: unused...
+ void impl_preconditions()
+ {
+ precondition(level::is_greater_or_equal(this->marker, this->mask));
+ }
+
+ };
+
+ // Hybrid version
+
+ template<typename I1, typename I2>
+ struct reconstruction <tag::by_erosion_type, tag::hybrid_type, I1, I2>
+ : public canvas::hybrid_reconstruction<I1, I2,
+ reconstruction<tag::by_erosion_type, tag::hybrid_type, I1, I2> >
+ {
+ typedef reconstruction<tag::by_erosion_type,
+ tag::hybrid_type, I1,I2> self_type;
+ typedef canvas::hybrid_reconstruction<I1, I2,
+ self_type> super_type;
+
+ reconstruction(const abstract::image_with_nbh<I1>& marker,
+ const abstract::image<I2>& mask) :
+ super_type(marker, mask)
+ {
+ }
+
+ void impl_bkd_loop_body()
+ {
+ this->output[this->bkd_p] = ntg::max(morpho::min(this->work,
+ this->bkd_p,
+ this->win_minus),
+ this->mask[this->bkd_p]);
+ }
+
+ void impl_fwd_loop_body()
+ {
+ this->output[this->fwd_p] = ntg::max(morpho::min(this->work,
+ this->fwd_p,
+ this->win_plus),
+ this->mask[this->fwd_p]);
+ }
+
+ void impl_fifo_loop_body()
+ {
+ if ((this->output[this->q] > this->output[this->p]) &&
+ (this->mask[this->q] != this->output[this->q]))
+ {
+ this->output[this->q] = ntg::min(this->output[this->p],
+ this->mask[this->q]);
+ this->fifo.push(this->q);
+ }
+ }
+
+ bool impl_exist_init()
+ {
+ return this->output.hold(this->q) &&
+ (this->output[this->q] > this->output[this->bkd_p]) &&
+ (this->output[this->q] > this->mask[this->q]);
+ }
+
+ // FIXME: unused...
+ void impl_preconditions()
+ {
+ precondition(level::is_greater_or_equal(this->marker, this->mask));
+ }
+
+ };
+
+ }
+
+ }
+
+}
+
+
+#endif // ! OLENA_MORPHO_RECONSTRUCTION_BY_EROSION_HH
Index: oln/morpho/reconstruction_by_dilation.inctrash
--- oln/morpho/reconstruction_by_dilation.inctrash (revision 183)
+++ oln/morpho/reconstruction_by_dilation.inctrash (working copy)
@@ -1,142 +0,0 @@
-// 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 filek 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.
-
-namespace oln {
-
- namespace morpho {
-
- namespace impl {
-
- // Sequential version
-
- template<typename I1, typename I2>
- struct generic_reconstruction <tag::by_dilation, tag::sequential, I1, I2>
- : public generic_reconstruction_canvas<I1, I2, tag::sequential,
- generic_reconstruction<tag::by_dilation, tag::sequential, I1, I2> >
- {
- typedef generic_reconstruction<tag::by_dilation,
- tag::sequential, I1,I2> self_type;
- typedef generic_reconstruction_canvas<I1, I2, tag::sequential,
- self_type> super_type;
-
- generic_reconstruction(const abstract::image_with_nbh<I1>& marker,
- const abstract::image<I2>& mask) :
- super_type(marker, mask)
- {
- }
-
-
- void impl_bkd_loop_body()
- {
- this->output[this->bkd_p] = ntg::min(morpho::max(this->output,
- this->bkd_p,
- this->win_minus),
- this->mask[this->bkd_p].value());
- }
-
- void impl_fwd_loop_body()
- {
- this->output[this->fwd_p] = ntg::min(morpho::max(this->output,
- this->fwd_p,
- this->win_plus),
- this->mask[this->fwd_p].value());
- }
-
- void impl_preconditions()
- {
- precondition(level::is_greater_or_equal(this->mask, this->marker));
- }
-
- };
-
-
- // Hybrid version
-
- template<typename I1, typename I2>
- struct generic_reconstruction <tag::by_dilation, tag::hybrid, I1, I2>
- : public generic_reconstruction_canvas<I1, I2, tag::hybrid,
- generic_reconstruction<tag::by_dilation, tag::hybrid, I1, I2> >
- {
- typedef generic_reconstruction<tag::by_dilation,
- tag::hybrid, I1,I2> self_type;
- typedef generic_reconstruction_canvas<I1, I2, tag::hybrid,
- self_type> super_type;
-
- generic_reconstruction(const abstract::image_with_nbh<I1>& marker,
- const abstract::image<I2>& mask) :
- super_type(marker, mask)
- {
- }
-
-
-
- void impl_bkd_loop_body()
- {
- this->output[this->bkd_p] = ntg::min(morpho::max(this->work,
- this->bkd_p,
- this->win_minus),
- this->mask[this->bkd_p].value());
- }
-
- void impl_fwd_loop_body()
- {
- this->output[this->fwd_p] = ntg::min(morpho::max(this->work,
- this->fwd_p,
- this->win_plus),
- this->mask[this->fwd_p].value());
- }
-
- void impl_fifo_loop_body()
- {
- if ((this->output[this->q] < this->output[this->p]) &&
- (this->mask[this->q] != this->output[this->q]))
- {
- this->output[this->q] = ntg::min(this->output[this->p].value(),
- this->mask[this->q].value());
- this->fifo.push(this->q);
- }
- }
-
- bool impl_exist_init()
- {
- return this->output.hold(this->q) &&
- (this->output[this->q] < this->output[this->bkd_p]) &&
- (this->output[this->q] < this->mask[this->q]);
- }
-
- void impl_preconditions()
- {
- precondition(level::is_greater_or_equal(this->mask, this->marker));
- }
-
- };
-
- }
-
- }
-
-}
Index: oln/canvas/reconstruction.hh
--- oln/canvas/reconstruction.hh (revision 0)
+++ oln/canvas/reconstruction.hh (revision 0)
@@ -0,0 +1,224 @@
+// 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_CANVAS_RECONSTRUCTION_HH
+# define OLENA_CANVAS_RECONSTRUCTION_HH
+
+# include <queue>
+
+# include <oln/canvas/backandforth.hh>
+# include <oln/level/compare.hh>
+# include <oln/utils/clone.hh>
+
+namespace oln {
+
+ namespace morpho {
+
+ namespace impl {
+
+ template <typename T, typename A, typename I1, typename I2>
+ struct reconstruction {};
+
+ }
+
+ }
+
+ namespace canvas {
+
+ template <typename I1, typename I2, typename E>
+ struct hybrid_reconstruction : public mlc::any<E>
+ {
+
+ typedef oln_type_of(I1, neighb) nbh_type;
+ typedef oln_nbh_type_of(nbh_type, window) window_type;
+ typedef oln_type_of(I1, concrete) output_type;
+
+ bool exist_init()
+ {
+ for (unsigned i = 0; i < win_minus.card(); ++i)
+ {
+ q = win_minus.get_dp()[i] + (oln_type_of(I1, point))bkd_p;
+ if (this->exact().impl_exist_init())
+ return true;
+ }
+ return false;
+ }
+
+
+ void fwd_loop_body()
+ {
+ this->exact().impl_fwd_loop_body();
+ }
+
+ void bkd_loop_body()
+ {
+ this->exact().impl_bkd_loop_body();
+ }
+
+ void fifo_loop_body()
+ {
+ this->exact().impl_fifo_loop_body();
+ }
+
+ void init()
+ {
+ output_type tmp(marker.size());
+
+ output = tmp;
+ work = clone(marker);
+
+ win_plus = marker.nbh_get().get_win().get_fwd_win_p();
+ win_minus = marker.nbh_get().get_win().get_bkd_win_p();
+ }
+
+ void run()
+ {
+ init();
+
+ for_all_p (fwd_p)
+ fwd_loop_body();
+
+ for_all_p (bkd_p)
+ {
+ bkd_loop_body();
+ if (exist_init())
+ fifo.push(bkd_p);
+ }
+
+ // Propagation Step
+ while (!fifo.empty())
+ {
+ p = fifo.front();
+ fifo.pop();
+
+ window_type win = marker.nbh_get().get_win();
+ for (unsigned i = 0; i < win.card(); ++i)
+ {
+ q = win.get_dp()[i] + p;
+
+ if (output.hold(q))
+ fifo_loop_body();
+ }
+ }
+ }
+
+ oln_type_of(I1, concrete) get_output()
+ {
+ return output.unbox();
+ }
+
+ protected:
+
+ hybrid_reconstruction(const abstract::image_with_nbh<I1>& marker,
+ const abstract::image<I2>& mask) :
+ marker(marker.exact()),
+ mask(mask.exact()),
+ bkd_p(marker.size()),
+ fwd_p(marker.size())
+ {
+ }
+
+ ~hybrid_reconstruction()
+ {
+ mlc_check_method_impl(E, void, exist_init, , );
+ mlc_check_method_impl(E, void, bkd_loop_body, , );
+ mlc_check_method_impl(E, void, fwd_loop_body, , );
+ mlc_check_method_impl(E, void, fifo_loop_body, , );
+ }
+
+ oln_type_of(I1, bkd_piter) bkd_p;
+ oln_type_of(I1, fwd_piter) fwd_p;
+
+ oln_type_of(I1, point) p;
+ oln_type_of(I1, point) q;
+
+ window_type win_plus;
+ window_type win_minus;
+
+ box<oln_type_of(I1, concrete)> work;
+ box<oln_type_of(I1, concrete)> output;
+ box<I1> marker;
+ box<I2> mask;
+
+ std::queue<oln_type_of(I1, point) > fifo;
+
+ };
+
+ template <typename I1, typename I2, typename E>
+ struct sequential_reconstruction :
+ public back_and_forth_until_convergence<I1, E>
+ {
+ typedef back_and_forth_until_convergence<I1, E> super_type;
+ typedef oln_type_of(I1, neighb) nbh_type;
+ typedef oln_nbh_type_of(nbh_type, window) window_type;
+
+ void impl_init()
+ {
+ output = clone(marker);
+ work = clone(marker);
+
+ win_plus = marker.nbh_get().get_win().get_fwd_win_p();
+ win_minus = marker.nbh_get().get_win().get_bkd_win_p();
+ }
+
+ bool impl_is_stable()
+ {
+ return level::is_equal(work, output);
+ }
+
+
+ oln_type_of(I1, concrete) get_output()
+ {
+ return output.unbox();
+ }
+
+ sequential_reconstruction(const abstract::image_with_nbh<I1>& marker,
+ const abstract::image<I2>& mask) :
+ super_type(marker),
+ marker(marker.exact()),
+ mask(mask.exact())
+ {
+ }
+
+ oln_nbh_type_of(nbh_type, window) win_plus;
+ oln_nbh_type_of(nbh_type, window) win_minus;
+
+ box<oln_type_of(I1, concrete)> work;
+ box<oln_type_of(I1, concrete)> output;
+ box<I1> marker;
+ box<I2> mask;
+
+ };
+
+
+ }
+
+
+}
+
+
+#endif // ! OLENA_CANVAS_RECONSTRUCTION_HH
Index: oln/canvas/backandforth.hh
--- oln/canvas/backandforth.hh (revision 0)
+++ oln/canvas/backandforth.hh (revision 0)
@@ -0,0 +1,198 @@
+// 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_CANVAS_BACKANDFORTH_HH
+# define OLENA_CANVAS_BACKANDFORTH_HH
+
+# include <mlc/any.hh>
+# include <mlc/contract.hh>
+# include <oln/core/abstract/image.hh>
+# include <oln/core/abstract/piter.hh>
+
+
+namespace oln {
+
+
+ namespace canvas
+ {
+
+ template <typename I, typename E>
+ struct back_and_forth_until_convergence : public mlc::any<E>
+ {
+ // Abstract methods.
+
+ // Initialize 'work'.
+ void init()
+ {
+ this->exact().impl_init();
+ }
+
+ // Do something like 'work -> output'.
+ void bkd_loop_body()
+ {
+ this->exact().impl_bkd_loop_body();
+ }
+
+ // Do something like 'work -> output'.
+ void fwd_loop_body()
+ {
+ this->exact().impl_fwd_loop_body();
+ }
+
+ // Check stability from input, output, and work.
+ bool is_stable() const
+ {
+ return this->exact().impl_is_stable();
+ }
+
+ // Do something like 'work := output'.
+ void re_loop()
+ {
+ return this->exact().impl_re_loop();
+ }
+
+ // Concrete method.
+ void run()
+ {
+ bool stability;
+ init();
+ for (;;)
+ {
+ // back
+ for_all_p (bkd_p)
+ bkd_loop_body();
+
+ // forth
+ for_all_p (fwd_p)
+ fwd_loop_body();
+
+ // stability check
+ stability = is_stable();
+ if (stability)
+ return;
+
+ // prepare a new loop iteration
+ re_loop();
+ }
+ }
+
+
+ protected:
+
+ // Ctor.
+ back_and_forth_until_convergence(const abstract::image<I>& input) :
+ bkd_p(input.size()),
+ fwd_p(input.size())
+ {
+ }
+
+ // Attributes.
+ oln_type_of(I, bkd_piter) bkd_p;
+ oln_type_of(I, fwd_piter) fwd_p;
+
+ // Check for impls..
+ ~back_and_forth_until_convergence()
+ {
+ mlc_check_method_impl(E, void, init, , );
+ mlc_check_method_impl(E, void, bkd_loop_body, , );
+ mlc_check_method_impl(E, void, fwd_loop_body, , );
+ mlc_check_method_impl(E, bool, is_stable, , const);
+ mlc_check_method_impl(E, void, re_loop, , );
+ }
+
+ };
+
+
+ template <typename I, typename E>
+ struct back_and_forth : public mlc::any<E>
+ {
+ // Abstract methods.
+
+ // Initialize 'work'.
+ void init()
+ {
+ this->exact().impl_init();
+ }
+
+ // Do something like 'work -> output'.
+ void bkd_loop_body()
+ {
+ this->exact().impl_bkd_loop_body();
+ }
+
+ // Do something like 'work -> output'.
+ void fwd_loop_body()
+ {
+ this->exact().impl_fwd_loop_body();
+ }
+
+ // Concrete method.
+ void run()
+ {
+ init();
+
+ // forth
+ for_all_p (fwd_p)
+ fwd_loop_body();
+
+ // back
+ for_all_p (bkd_p)
+ bkd_loop_body();
+
+ }
+
+
+ protected:
+
+ // Ctor.
+ back_and_forth(const abstract::image<I>& input) :
+ bkd_p(input.size()),
+ fwd_p(input.size())
+ {
+ }
+
+ // Attributes.
+ oln_type_of(I, bkd_piter) bkd_p;
+ oln_type_of(I, fwd_piter) fwd_p;
+
+ // Check for impls..
+ ~back_and_forth()
+ {
+ mlc_check_method_impl(E, void, init, , );
+ mlc_check_method_impl(E, void, bkd_loop_body, , );
+ mlc_check_method_impl(E, void, fwd_loop_body, , );
+ }
+
+ };
+
+ } // end of namespace oln::canvas
+
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_CANVAS_BACKANDFORTH_HH
1
0
Index: ChangeLog
from Christophe Berger <christophe(a)lrde.epita.fr>
* oln/core/pw/macros.hh: Fix bug.
macros.hh | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
Index: oln/core/pw/macros.hh
--- oln/core/pw/macros.hh (revision 182)
+++ oln/core/pw/macros.hh (working copy)
@@ -60,9 +60,9 @@
operator OperatorSymbol (const oln::pw::abstract::function<L>& lhs, \
const LiteralType& rhs) \
{ \
- precondition(lhs.size() == rhs.size()); \
+ oln::pw::literal<LiteralType> rhs_(rhs); \
oln::pw::binary_op< oln::f_##OperatorName##_type, \
- L, oln::pw::literal<LiteralType> > tmp(lhs, rhs); \
+ L, oln::pw::literal<LiteralType> > tmp(lhs, rhs_); \
return tmp; \
} \
\
@@ -72,9 +72,9 @@
operator OperatorSymbol (const LiteralType& lhs, \
const oln::pw::abstract::function<R>& rhs) \
{ \
- precondition(lhs.size() == rhs.size()); \
+ oln::pw::literal<LiteralType> lhs_(lhs); \
oln::pw::binary_op< oln::f_##OperatorName##_type, \
- oln::pw::literal<LiteralType>, R > tmp(lhs, rhs); \
+ oln::pw::literal<LiteralType>, R > tmp(lhs_, rhs); \
return tmp; \
} \
\
1
0