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
April 2007
- 7 participants
- 47 discussions
30 Apr '07
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Canvas : Add union-find, two_pass version. Fix reconstruction.
* oln/core/internal/point_impl.hh: Whitespaces.
* oln/morpho/binary_reconstruction_v0.hh: Procedure version.
* oln/morpho/fast_binary_reconstruction.hh: Fast hybrid version.
* oln/morpho/reconstruction.hh: removed.
* oln/morpho/binary_reconstruction.hh: Removed.
* oln/morpho/binary_reconstruction_v1.hh: Canvas version.
* oln/level/local_sup.hh: Fixed.
* oln/level/local_inf.hh: Fixed.
* oln/canvas/union_find.hh: New.
* oln/canvas/two_pass.hh: New version (v4) with inheritens.
canvas/two_pass.hh | 40 ++++++------
canvas/union_find.hh | 76 ++++++++++++++++++++++
level/local_inf.hh | 6 -
level/local_sup.hh | 6 -
morpho/binary_reconstruction_v0.hh | 123 +++++++++++++++++++++++++++++++++++++
morpho/binary_reconstruction_v1.hh | 122 ++++++++++++++++++++++++++++++++++++
morpho/cc_tarjan_v1.hh | 5 -
7 files changed, 353 insertions(+), 25 deletions(-)
Index: oln/core/internal/point_impl.hh
Index: oln/morpho/binary_reconstruction_v0.hh
--- oln/morpho/binary_reconstruction_v0.hh (revision 0)
+++ oln/morpho/binary_reconstruction_v0.hh (revision 0)
@@ -0,0 +1,123 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_MORPHO_BINARY_RECONSTRUCTION_HH
+# define OLN_MORPHO_BINARY_RECONSTRUCTION_HH
+
+# include <oln/core/concept/image.hh>
+# include <oln/accumulator/max.hh>
+# include <oln/level/clone.hh>
+# include <oln/level/fill.hh>
+# include <oln/level/local_inf.hh>
+# include <oln/level/local_sup.hh>
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ template <typename I , typename J>
+ void
+ binary_reconstruction(const Binary_Image<I>& marker,
+ const Binary_Image<J>& mask);
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ template <typename I>
+ bool
+ stability(const Image_with_Nbh<I>& marker,
+ oln_plain(I)& tmp)
+ {
+ oln_piter(I) p(marker.points());
+ for_all(p)
+ if (marker(p) != tmp(p))
+ return false;
+ return true;
+ }
+
+ template <typename I, typename J>
+ oln_plain(I)
+ binary_reconstruction_loop(const Image_with_Nbh<I>& marker,
+ const Binary_Image<J>& mask)
+ {
+ oln_plain(I) output;
+ prepare(output, with, marker);
+
+ accumulator::max_<oln_value(I)> max;
+
+ // first pass
+ oln_fwd_piter(I) p(marker.points());
+ for_all(p)
+ output(p) = level::local_sup(max, marker, p) and mask(p);
+
+ // second pass
+ oln_bkd_piter(I) p2(marker.points());
+ for_all(p2)
+ output(p2) = level::local_inf(max, marker, p2) and mask(p2);
+
+ return output;
+ }
+
+ template <typename I , typename J>
+ void // FIXME : Slow impl.
+ binary_reconstruction_(const Image_with_Nbh<I>& marker,
+ const Binary_Image<J>& mask)
+ {
+ oln_plain(I) tmp = level::clone(marker);
+
+ while ( not stability(marker, tmp) )
+ {
+ level::fill(inplace(exact(marker).image()), tmp);
+ tmp = binary_reconstruction_loop(marker, mask);
+ }
+
+ level::fill(inplace(exact(marker).image()), tmp);
+ }
+
+ } // end of namespace oln::morpho::impl
+
+ template <typename I , typename J>
+ void
+ binary_reconstruction(Binary_Image<I>& marker,
+ const Binary_Image<J>& mask)
+ {
+ impl::binary_reconstruction_(marker + c4, mask);
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_BINARY_RECONSTRUCTION_HH
Index: oln/morpho/fast_binary_reconstruction.hh
Index: oln/morpho/cc_tarjan_v1.hh
--- oln/morpho/cc_tarjan_v1.hh (revision 972)
+++ oln/morpho/cc_tarjan_v1.hh (working copy)
@@ -54,7 +54,8 @@
namespace impl
{
- template <typename I>
+ template <typename I> // FIXME : template< op_<I, extended_by, N>,
+ // typename I, Typename N> ?
struct cc_tarjan_
{
typedef oln_point(I) point;
@@ -128,7 +129,7 @@
{
point r = find_root(n);
if (r != p)
- parent(r) = p;
+ parent(r) = p5A5A;
}
};
Index: oln/morpho/binary_reconstruction_v1.hh
--- oln/morpho/binary_reconstruction_v1.hh (revision 0)
+++ oln/morpho/binary_reconstruction_v1.hh (revision 0)
@@ -0,0 +1,122 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_MORPHO_BINARY_RECONSTRUCTION_HH
+# define OLN_MORPHO_BINARY_RECONSTRUCTION_HH
+
+# include <oln/core/concept/image.hh>
+# include <oln/accumulator/max.hh>
+# include <oln/level/clone.hh>
+# include <oln/level/fill.hh>
+# include <oln/level/local_inf.hh>
+# include <oln/level/local_sup.hh>
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ template <typename I , typename J>
+ void
+ binary_reconstruction(const Binary_Image<I>& marker,
+ const Binary_Image<J>& mask);
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ template <typename I>
+ bool
+ stability(const Image_with_Nbh<I>& marker,
+ oln_plain(I)& tmp)
+ {
+ oln_piter(I) p(marker.points());
+ for_all(p)
+ if (marker(p) != tmp(p))
+ return false;
+ return true;
+ }
+
+ template <typename I, typename J>
+ oln_plain(I)
+ binary_reconstruction_loop(const Image_with_Nbh<I>& marker,
+ const Binary_Image<J>& mask)
+ {
+ oln_plain(I) output;
+ prepare(output, with, marker);
+
+ accumulator::max_<oln_value(I)> max;
+
+ // first pass
+ oln_fwd_piter(I) p(marker.points());
+ for_all(p)
+ output(p) = level::local_sup(max, marker, p) and mask(p);
+
+ // second pass
+ oln_bkd_piter(I) p2(marker.points());
+ for_all(p2)
+ output(p2) = level::local_inf(max, marker, p2) and mask(p2);
+
+ return output;
+ }
+
+ template <typename I , typename J>
+ void // FIXME : Slow impl.
+ binary_reconstruction_(const Image_with_Nbh<I>& marker,
+ const Binary_Image<J>& mask)
+ {
+ oln_plain(I) tmp = level::clone(marker);
+
+ while ( not stability(marker, tmp) )
+ {
+ level::fill(inplace(exact(marker).image()), tmp);
+ tmp = binary_reconstruction_loop(marker, mask);
+ }
+
+ level::fill(inplace(exact(marker).image()), tmp);
+ }
+
+ } // end of namespace oln::morpho::impl
+
+ template <typename I , typename J>
+ void
+ binary_reconstruction(Binary_Image<I>& marker,
+ const Binary_Image<J>& mask)
+ {
+ impl::binary_reconstruction_(marker + c4, mask);
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_BINARY_RECONSTRUCTION_HH
Index: oln/level/local_sup.hh
--- oln/level/local_sup.hh (revision 972)
+++ oln/level/local_sup.hh (working copy)
@@ -68,7 +68,7 @@
const oln_point(I)& p)
{
f.init_with(input(p));
- oln_niter(I) n(p, input);
+ oln_niter(I) n(input, p);
for_all(n)
if (n > p)
f(input(n));
@@ -86,7 +86,7 @@
f.init_with(input(p));
if (f.value() == true)
return true;
- oln_niter(I) n(p, input);
+ oln_niter(I) n(input, p);
for_all(n)
if (n > p)
{
@@ -106,7 +106,7 @@
const oln_point(I)& p)
{
f.init_with(input(p));
- oln_niter(I) n(p, input);
+ oln_niter(I) n(input, p);
for_all(n)
if (n > p)
{
Index: oln/level/local_inf.hh
--- oln/level/local_inf.hh (revision 972)
+++ oln/level/local_inf.hh (working copy)
@@ -68,7 +68,7 @@
const oln_point(I)& p)
{
f.init_with(input(p));
- oln_niter(I) n(p, input);
+ oln_niter(I) n(input, p);
for_all(n)
if (n < p)
f(input(n));
@@ -86,7 +86,7 @@
f.init_with(input(p));
if (f.value() == true)
return true;
- oln_niter(I) n(p, input);
+ oln_niter(I) n(input, p);
for_all(n)
if (n < p)
{
@@ -106,7 +106,7 @@
const oln_point(I)& p)
{
f.init_with(input(p));
- oln_niter(I) n(p, input);
+ oln_niter(I) n(input, p);
for_all(n)
if (n < p)
{
Index: oln/canvas/union_find.hh
--- oln/canvas/union_find.hh (revision 0)
+++ oln/canvas/union_find.hh (revision 0)
@@ -0,0 +1,76 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have receiv a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#include <oln/core/concept/image.hh>
+
+#ifndef OLN_CANVAS_UNION_FIND_HH
+# define OLN_CANVAS_UNION_FIND_HH
+
+namespace canvas
+{
+
+ template <template <class> class F,
+ typename I>
+ void union_find(F<I> fun)
+ {
+ fun.init();
+
+ // first pass
+ oln_bkd_piter(I) p1(fun.f.points());
+ for_all(p1)
+ {
+ fun.parent(p1) = p1;
+ if (fun.f(p) == true)
+ {
+ oln_niter(I) n(f, p);
+ for_all(n)
+ {
+ if (is_processed(n))
+ if (f.condition_bck(p1, n))
+ fun.first_pass_body(p1);
+ }
+ }
+ }
+
+ // second pass
+ oln_fwd_piter(I) p2(fun.f.points());
+ for_all(p2)
+ {
+ if (fun.f(p2) == true)
+ if (fun.condition_fwd(p2))
+ {
+ fun.second_pass_body(p2);
+ }
+ }
+
+ fun.final();
+ }
+
+}
+
+
+#endif // ! OLN_CANVAS_UNION_FIND_HH
Index: oln/canvas/two_pass.hh
--- oln/canvas/two_pass.hh (revision 972)
+++ oln/canvas/two_pass.hh (working copy)
@@ -5,8 +5,8 @@
// 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
+// 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.
//
@@ -60,7 +60,7 @@
namespace v2 // Data owned by f but not input.
{
template <typename F, typename I>
- void two_pass(F fun, I f)
+ void two_pass(F& fun, I f)
{
// mlc::assert_< mlc_is_a(I, Image) >::check();
@@ -83,7 +83,7 @@
namespace v3 // Auxiliar data given as argument.
{
template <typename F, typename I, typename A>
- void two_pass(F fun, I f, A aux)
+ void two_pass(F fun, I f, A& aux)
{
// mlc::assert_< mlc_is_a(I, Image) >::check();
@@ -107,38 +107,44 @@
namespace v4 // Via Inheritance.
{
- template <typename I>
+ template <typename Exact>
struct two_pass
{
+ void init()
+ {
+ this->exact().impl_init();
+ }
- const I& f;
-
-
-
- void init();
-
- void final();
+ void final()
+ {
+ this->exact().impl_final();
+ }
- void first_pass_body(const oln_point(I)& p);
+ void first_pass_body(const oln_point(I)& p)
+ {
+ this->exact().impl_first_pass_body(p);
+ }
- void second_pass_body(const oln_point(I)& p);
+ void second_pass_body(const oln_point(I)& p)
+ {
+ this->exact().impl_second_pass_body(p);
+ }
void run()
{
init(f);
// first pass
- oln_bkd_piter(I) p1(f.points());
+ oln_bkd_piter(typename Exact::I) p1(f.points());
for_all(p1)
first_pass_body(p1);
// second pass
- oln_fwd_piter(I) p2(f.points());
+ oln_fwd_piter(typename Exact::I) p2(f.points());
for_all(p2)
second_pass_body(p2);
final(f);
-
}
};
1
0
Re: [Olena-patches] 970: cc-tarjan(two_pass) : Fix + Comparative statement : v0, v1, v2.
by Ugo Jardonnet 30 Apr '07
by Ugo Jardonnet 30 Apr '07
30 Apr '07
Ugo Jardonnet wrote (en vrai):
> cc_tarjan :
>
> ---------------------------------------/code
> #include <oln/core/2d/image2d.hh>
> #include <oln/core/2d/neighb2d.hh>
>
> #include <oln/morpho/cc_tarjan_v4.hh>
>
> int main()
> {
> using namespace oln;
>
> unsigned N = 128;
>
> image2d<bool> img(N, N);
>
> float tmp;
>
> for (unsigned i = 0; i < N; i++)
> for (unsigned j = 0; j < N; j++)
> {
> tmp = 5 * cos(i) * cos(j);
> img.at(i, j) = (tmp > 0) ? tmp : 0;
> }
>
> morpho::cc_tarjan(img + c4);
> }
> ---------------------------------------code/
>
> - v0 // Procedure.
> Compile:
> 15,76s
> Execution:
> 1,22s
> +OPTIM->
> Compile:
> 67,67s
> Execution:
> 0,03s
> 1024 iter : 1,75s
>
> - v1 // Data owned by f.
> Compile:
> 16,39s
> Execution:
> 1,16s
> Execution(optim):
> +OPTIM->
> Compile:
> 71,90s
> Execution:
> 0,03s
> 1024 iter : 1,78s
>
> - v2 // Data owned by f but not input.
> Compile:
> 16,35s
> Execution:
> 1,35s
> Execution(optim):
> +OPTIM->
> Compile:
> 71,96s
> Execution:
> 0,06s
> 1024 iter : 4,03s
>
>
>
> Index: ChangeLog
> from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
>
> cc-tarjan(two_pass) : Fix + Comparative statement : v0, v1, v2.
>
> * tests/algorithms/cc_tarjan_v2.cc: New.
> * tests/algorithms/Makefile.am: .
> * tests/algorithms/cc_tarjan_v0.cc: New.
> * tests/algorithms/cc_tarjan_v1.cc: New.
> * oln/core/concept/point.hh: .
> * oln/morpho/cc_tarjan_v1.hh: .
> * oln/morpho/cc_tarjan_v2.hh: .
> * oln/morpho/cc_tarjan_v4.hh: .
> * oln/canvas/two_pass.hh: .
>
> oln/canvas/two_pass.hh | 79 +++++++++++++++++++--------------------
> oln/core/concept/point.hh | 1
> oln/morpho/cc_tarjan_v1.hh | 11 ++---
> oln/morpho/cc_tarjan_v2.hh | 14 ++++--
> oln/morpho/cc_tarjan_v4.hh | 35 ++++++++++-------
> tests/algorithms/Makefile.am | 8 +++
> tests/algorithms/cc_tarjan_v0.cc | 24 +++++++++++
> tests/algorithms/cc_tarjan_v1.cc | 24 +++++++++++
> tests/algorithms/cc_tarjan_v2.cc | 24 +++++++++++
> 9 files changed, 157 insertions(+), 63 deletions(-)
>
> Index: tests/algorithms/cc_tarjan_v2.cc
> --- tests/algorithms/cc_tarjan_v2.cc (revision 0)
> +++ tests/algorithms/cc_tarjan_v2.cc (revision 0)
> @@ -0,0 +1,24 @@
> +#include <oln/core/2d/image2d.hh>
> +#include <oln/core/2d/neighb2d.hh>
> +
> +#include <oln/morpho/cc_tarjan_v0.hh>
> +
> +int main()
> +{
> + using namespace oln;
> +
> + unsigned N = 128;
> +
> + image2d<bool> img(N, N);
> +
> + float tmp;
> +
> + for (unsigned i = 0; i < N; i++)
> + for (unsigned j = 0; j < N; j++)
> + {
> + tmp = 5 * cos(i) * cos(j);
> + img.at(i, j) = (tmp > 0) ? tmp : 0;
> + }
> +
> + morpho::cc_tarjan(img + c4);
> +}
> Index: tests/algorithms/Makefile.am
> --- tests/algorithms/Makefile.am (revision 969)
> +++ tests/algorithms/Makefile.am (working copy)
> @@ -25,11 +25,17 @@
> check_PROGRAMS = \
> fill \
> basic_morpho \
> - cc_tarjan
> + cc_tarjan \
> + cc_tarjan_v0 \
> + cc_tarjan_v1 \
> + cc_tarjan_v2
>
> # Algorithms.
> fill_SOURCES = fill.cc
> basic_morpho_SOURCES = basic_morpho.cc
> cc_tarjan_SOURCES = cc_tarjan.cc
> +cc_tarjan_v0_SOURCES = cc_tarjan_v0.cc
> +cc_tarjan_v1_SOURCES = cc_tarjan_v1.cc
> +cc_tarjan_v2_SOURCES = cc_tarjan_v2..cc
>
> TESTS = $(check_PROGRAMS)
> Index: tests/algorithms/cc_tarjan_v0.cc
> --- tests/algorithms/cc_tarjan_v0.cc (revision 0)
> +++ tests/algorithms/cc_tarjan_v0.cc (revision 0)
> @@ -0,0 +1,24 @@
> +#include <oln/core/2d/image2d.hh>
> +#include <oln/core/2d/neighb2d.hh>
> +
> +#include <oln/morpho/cc_tarjan_v0.hh>
> +
> +int main()
> +{
> + using namespace oln;
> +
> + unsigned N = 128;
> +
> + image2d<bool> img(N, N);
> +
> + float tmp;
> +
> + for (unsigned i = 0; i < N; i++)
> + for (unsigned j = 0; j < N; j++)
> + {
> + tmp = 5 * cos(i) * cos(j);
> + img.at(i, j) = (tmp > 0) ? tmp : 0;
> + }
> +
> + morpho::cc_tarjan(img + c4);
> +}
> Index: tests/algorithms/cc_tarjan_v1.cc
> --- tests/algorithms/cc_tarjan_v1.cc (revision 0)
> +++ tests/algorithms/cc_tarjan_v1.cc (revision 0)
> @@ -0,0 +1,24 @@
> +#include <oln/core/2d/image2d.hh>
> +#include <oln/core/2d/neighb2d.hh>
> +
> +#include <oln/morpho/cc_tarjan_v0.hh>
> +
> +int main()
> +{
> + using namespace oln;
> +
> + unsigned N = 128;
> +
> + image2d<bool> img(N, N);
> +
> + float tmp;
> +
> + for (unsigned i = 0; i < N; i++)
> + for (unsigned j = 0; j < N; j++)
> + {
> + tmp = 5 * cos(i) * cos(j);
> + img.at(i, j) = (tmp > 0) ? tmp : 0;
> + }
> +
> + morpho::cc_tarjan(img + c4);
> +}
> Index: oln/core/concept/point.hh
> --- oln/core/concept/point.hh (revision 969)
> +++ oln/core/concept/point.hh (working copy)
> @@ -30,6 +30,7 @@
> # define OLN_CORE_CONCEPT_POINT_HH
>
> # include <mlc/value.hh>
> +# include <xtd/vec.hh>
>
> # include <oln/core/concept/grid.hh>
> # include <oln/core/concept/operators.hh>
> Index: oln/morpho/cc_tarjan_v1.hh
> --- oln/morpho/cc_tarjan_v1.hh (revision 969)
> +++ oln/morpho/cc_tarjan_v1.hh (working copy)
> @@ -32,6 +32,7 @@
>
> # include <oln/canvas/two_pass.hh>
> # include <oln/level/fill.hh>
> +# include <oln/core/internal/f_ch_value.hh>
>
> namespace oln
> {
> @@ -55,7 +56,7 @@
> const I& f;
>
> oln_plain_value(I, unsigned) output;
> - oln_plain(I, bool) is_processed;
> + oln_plain_value(I, bool) is_processed;
> oln_plain_value(I, point) parent;
>
> cc_tarjan_(const I& f)
> @@ -65,9 +66,9 @@
>
> void init()
> {
> - prepare(is_processed, with, in);
> - prepare(output, with, in);
> - prepare(parent, with, in);
> + prepare(is_processed, with, f);
> + prepare(output, with, f);
> + prepare(parent, with, f);
> level::fill(inplace(is_processed), false);
> }
>
> @@ -114,7 +115,7 @@
> void do_union(const point& n,
> const point& p)
> {
> - point r = find_root(ima, n, parent);
> + point r = find_root(n);
> if (r != p)
> parent(r) = p;
> }
> Index: oln/morpho/cc_tarjan_v2.hh
> --- oln/morpho/cc_tarjan_v2.hh (revision 969)
> +++ oln/morpho/cc_tarjan_v2.hh (working copy)
> @@ -29,6 +29,7 @@
> # define OLN_MORPHO_CC_TARJAN_HH
>
> # include <oln/core/concept/image.hh>
> +# include <oln/core/internal/f_ch_value.hh>
>
> # include <oln/canvas/two_pass.hh>
> # include <oln/level/fill.hh>
> @@ -54,9 +55,11 @@
> typedef oln_point(I) point;
>
> oln_plain_value(I, unsigned) output;
> - oln_plain(I, bool) is_processed;
> + oln_plain_value(I, bool) is_processed;
> oln_plain_value(I, point) parent;
>
> + cc_tarjan_() {}
> +
> void init(I f)
> {
> prepare(is_processed, with, f);
> @@ -92,6 +95,7 @@
>
> void final(I f)
> {
> + f = f;
> }
>
> point find_root(const I& ima,
> @@ -106,7 +110,9 @@
> }
>
> void do_union(const I& ima,
> - const point& n)
> + const point& n,
> + const point& p)
> +
> {
> point r = find_root(ima, n);
> if (r != p)
> @@ -123,8 +129,8 @@
> oln_plain_value(I, unsigned)
> cc_tarjan(const Image_with_Nbh<I>& f)
> {
> - impl::cc_tarjan_<I> run(exact(f));
> - canvas::v2::two_pass(run, f);
> + impl::cc_tarjan_<I> run;
> + canvas::v2::two_pass(run, exact(f));
> return run.output;
> }
>
> Index: oln/morpho/cc_tarjan_v4.hh
> --- oln/morpho/cc_tarjan_v4.hh (revision 969)
> +++ oln/morpho/cc_tarjan_v4.hh (working copy)
> @@ -28,6 +28,9 @@
> #ifndef OLN_MORPHO_CC_TARJAN_HH
> # define OLN_MORPHO_CC_TARJAN_HH
>
> +# include <oln/core/concept/image.hh>
> +# include <oln/core/internal/f_ch_value.hh>
> +
> # include <oln/canvas/two_pass.hh>
> # include <oln/level/fill.hh>
>
> @@ -49,7 +52,7 @@
> {
>
> template <typename I>
> - struct cc_tarjan_ : canvas::v4::two_pass<I>
> + struct cc_tarjan_ : public canvas::v4::two_pass<I>
> {
> typedef oln_point(I) point;
>
> @@ -57,40 +60,44 @@
> oln_plain_value(I, bool) is_processed;
> oln_plain_value(I, point) parent;
>
> - void init(I f)
> + cc_tarjan_(const I& img)
> {
> - prepare(is_processed, with, f);
> - prepare(output, with, f);
> - prepare(parent, with, f);
> + }
> +
> + void init()
> + {
> + prepare(is_processed, with, this.f);
> + prepare(output, with, this.f);
> + prepare(parent, with, this.f);
> level::fill(inplace(is_processed), false);
> }
>
> - void first_pass_body(const point& p, I f)
> + void first_pass_body(const point& p)
> {
> parent(p) = p;
> if ( f(p) )
> {
> - oln_niter(I) n(f, p);
> + oln_niter(I) n(this.f, p);
> for_all(n)
> {
> - if ( f(n) == true and is_processed(n) )
> - do_union(f, n, p);
> + if ( this.f(n) == true and is_processed(n) )
> + do_union(this.f, n, p);
> }
> is_processed(p) = true;
> }
>
> }
>
> - void second_pass_body(const point& p, I f)
> + void second_pass_body(const point& p)
> {
> unsigned current_label = 0;
> - if ( f(p) == true and parent(p) == p )
> + if ( this.f(p) == true and parent(p) == p )
> output(p) = ++current_label;
> else
> output(p) = output(parent(p));
> }
>
> - void final(I f)
> + void final()
> {
> }
>
> @@ -129,7 +136,9 @@
> {
> impl::cc_tarjan_<I> f_cc_tarjan(exact(f));
>
> - return f_cc_tarjan.run();
> + f_cc_tarjan.run();
> +
> + return f_cc_tarjan.output;
> }
>
> # endif // ! OLN_INCLUDE_ONLY
> Index: oln/canvas/two_pass.hh
> --- oln/canvas/two_pass.hh (revision 969)
> +++ oln/canvas/two_pass.hh (working copy)
> @@ -37,69 +37,69 @@
> {
> template <template <class> class F,
> typename I> // Data owned by f.
> - void two_pass(F<I> f)
> + void two_pass(F<I> fun)
> {
> // mlc::assert_< mlc_is_a(I, Image) >::check();
>
> - f.init();
> + fun.init();
>
> // first pass
> - oln_bkd_piter(I) p1(f.input.points());
> + oln_bkd_piter(I) p1(fun.f.points());
> for_all(p1)
> - f.first_pass_body(p1);
> + fun.first_pass_body(p1);
>
> // second pass
> - oln_fwd_piter(I) p2(f.input.points());
> + oln_fwd_piter(I) p2(fun.f.points());
> for_all(p2)
> - f.second_pass_body(p2);
> + fun.second_pass_body(p2);
>
> - f.final();
> + fun.final();
> }
> }
>
> - namespace v2 // Data owned by f but not input
> + namespace v2 // Data owned by f but not input.
> {
> template <typename F, typename I>
> - void two_pass(F f, I input)
> + void two_pass(F fun, I f)
> {
> // mlc::assert_< mlc_is_a(I, Image) >::check();
>
> - f.init(input);
> + fun.init(f);
>
> // first pass
> - oln_bkd_piter(I) p1(input.points());
> + oln_bkd_piter(I) p1(f.points());
> for_all(p1)
> - f.first_pass_body(p1, input);
> + fun.first_pass_body(p1, f);
>
> // second pass
> - oln_fwd_piter(I) p2(input.points());
> + oln_fwd_piter(I) p2(f.points());
> for_all(p2)
> - f.second_pass_body(p2, input);
> + fun.second_pass_body(p2, f);
>
> - f.final(input);
> + fun.final(f);
> }
> }
>
> namespace v3 // Auxiliar data given as argument.
> {
> template <typename F, typename I, typename A>
> - void two_pass(F f, I input, A aux)
> + void two_pass(F fun, I f, A aux)
> {
> // mlc::assert_< mlc_is_a(I, Image) >::check();
>
> - f.init(input, aux);
> + f.init(f, aux);
>
> // first pass
> - oln_bkd_piter(I) p1(input.points());
> + oln_bkd_piter(I) p1(f.points());
> for_all(p1)
> - f.first_pass_body(p1, input, aux);
> + f.first_pass_body(p1, f, aux);
>
> // second pass
> - oln_fwd_piter(I) p2(input.points());
> + oln_fwd_piter(I) p2(f.points());
> for_all(p2)
> - f.second_pass_body(p2, input, aux);
> + f.second_pass_body(p2, f, aux);
>
> - f.final(input, aux);
> + f.final(f, aux);
> }
> }
>
> @@ -108,38 +108,37 @@
> {
>
> template <typename I>
> - class two_pass
> + struct two_pass
> {
>
> - void init(I input) { }
> + const I& f;
>
> - void final(I input) { }
>
> - void first_pass_body(const oln_point(I)& p)
> - {
> - assert (0 && "two_pass canvas : procedure 'void first_pass_body(const oln_point(I)& p)' must be defined");
> - }
>
> - void second_pass_body(const oln_point(I)& p)
> - {
> - assert (0 && "two_pass canvas : procedure 'void second_pass_body(const oln_point(I)& p)' must be defined");
> - }
> + void init();
>
> - void run(I input)
> + void final();
> +
> + void first_pass_body(const oln_point(I)& p);
> +
> + void second_pass_body(const oln_point(I)& p);
> +
> + void run()
> {
> - init(input);
> + init(f);
>
> // first pass
> - oln_bkd_piter(I) p1(input.points());
> + oln_bkd_piter(I) p1(f.points());
> for_all(p1)
> - first_pass_body(p1, input);
> + first_pass_body(p1);
>
> // second pass
> - oln_fwd_piter(I) p2(input.points());
> + oln_fwd_piter(I) p2(f.points());
> for_all(p2)
> - second_pass_body(p2, input);
> + second_pass_body(p2);
> +
> + final(f);
>
> - final(input);
> }
>
> };
1
0
Index: ChangeLog
from Nicolas Ballas <ballas(a)lrde.epita.fr>
fast iterator on image3b_b.
* tests/core/fiter_point2d_b.cc: update test.
* tests/core/fiter_point3d_b.cc: New test.
* tests/core/Makefile.am: Update.
* oln/core/2d/fast_iterator_2d.hh,
* oln/core/2d/fast_iterator_2d_b.hh,
* oln/core/3d/fast_iterator_3d.hh: clean code.
* oln/core/3d/image3d_b.hh: add method to get the image array.
* oln/core/3d/fast_iterator_3d_b.hh: New fast iterator.
oln/core/2d/fast_iterator_2d.hh | 3
oln/core/2d/fast_iterator_2d_b.hh | 18 ++---
oln/core/3d/fast_iterator_3d.hh | 5 -
oln/core/3d/fast_iterator_3d_b.hh | 134 ++++++++++++++++++++++++++++++++++++++
oln/core/3d/image3d_b.hh | 23 ++++++
tests/core/Makefile.am | 2
tests/core/fiter_point2d_b.cc | 2
tests/core/fiter_point3d_b.cc | 61 +++++++++++++++++
8 files changed, 230 insertions(+), 18 deletions(-)
Index: tests/core/fiter_point2d_b.cc
--- tests/core/fiter_point2d_b.cc (revision 971)
+++ tests/core/fiter_point2d_b.cc (working copy)
@@ -34,7 +34,7 @@
{
using namespace oln;
- image2d_b<int> ima(2, 5, 2);
+ image2d_b<int> ima(50, 50, 2);
image2d_b<int>::piter p(ima.points());
image2d_b<int>::fiter f(ima);
Index: tests/core/fiter_point3d_b.cc
--- tests/core/fiter_point3d_b.cc (revision 0)
+++ tests/core/fiter_point3d_b.cc (revision 0)
@@ -0,0 +1,61 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#include <cassert>
+#include <oln/core/3d/image3d_b.hh>
+
+
+int
+main()
+{
+ using namespace oln;
+
+ image3d_b<int> ima(100, 100, 100, 2);
+
+ image3d_b<int>::piter p(ima.points());
+ image3d_b<int>::fiter f(ima);
+ int i = 0;
+
+ for_all(p)
+ ima(p) = i++;
+
+ i = 0;
+
+ for_all(f)
+ {
+ assert(*f == i++);
+ *f = 5;
+ }
+
+ for_all(p)
+ assert(ima(p) == 5);
+
+ f.start();
+ assert(f.is_valid());
+ f.invalidate();
+ assert(!f.is_valid());
+}
Index: tests/core/Makefile.am
--- tests/core/Makefile.am (revision 971)
+++ tests/core/Makefile.am (working copy)
@@ -32,6 +32,7 @@
fiter_point3d \
fiter_point1d_b \
fiter_point2d_b \
+ fiter_point3d_b \
neighb2d \
npoints \
point2d \
@@ -56,6 +57,7 @@
fiter_point3d_SOURCES = fiter_point3d.cc
fiter_point1d_b_SOURCES = fiter_point1d_b.cc
fiter_point2d_b_SOURCES = fiter_point2d_b.cc
+fiter_point3d_b_SOURCES = fiter_point3d_b.cc
neighb2d_SOURCES = neighb2d.cc
npoints_SOURCES = npoints.cc
point2d_SOURCES = point2d.cc
Index: oln/core/2d/fast_iterator_2d.hh
--- oln/core/2d/fast_iterator_2d.hh (revision 971)
+++ oln/core/2d/fast_iterator_2d.hh (working copy)
@@ -72,8 +72,7 @@
template <typename T>
fast_iterator_2d<T>::fast_iterator_2d(image2d<T>& ima)
{
- this->start_ = ima.img_array().buffer() +
- ima.img_array().imin() * ima.img_array().jmin() + ima.img_array().jmin();
+ this->start_ = ima.img_array().buffer();
this->current_elt_ = this->start_;
this->eoi_ = ima.img_array().buffer() + (ima.img_array().imax() + 1) *
(ima.img_array().jmax() + 1);
Index: oln/core/2d/fast_iterator_2d_b.hh
--- oln/core/2d/fast_iterator_2d_b.hh (revision 971)
+++ oln/core/2d/fast_iterator_2d_b.hh (working copy)
@@ -18,7 +18,7 @@
//
// 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
+// instantiate templates or use macros or inraw 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
@@ -53,7 +53,7 @@
typedef T value;
};
- // Fast iterator for image in one dimension
+ // Fast iterator for image in two dimension
template <typename T>
class fast_iterator_2d_b :
public internal::fast_iterator_base_< fast_iterator_2d_b<T> >
@@ -68,7 +68,7 @@
protected:
unsigned border_size_;
- int line_offset_;
+ int row_offset_;
value *eor_; // end of row
};
@@ -76,22 +76,20 @@
template <typename T>
fast_iterator_2d_b<T>::fast_iterator_2d_b(image2d_b<T>& ima) :
- border_size_(ima.border()), line_offset_(ima.img_array().i_pad())
+ border_size_(ima.border()), row_offset_(ima.img_array().i_pad())
{
this->start_ = ima.img_array().buffer() +
- (this->border_size_) * this->line_offset_ + this->border_size_;
+ (this->border_size_) * this->row_offset_ + this->border_size_;
this->current_elt_ = this->start_;
this->eor_ = ima.img_array().buffer() +
- (this->border_size_) * this->line_offset_ + this->line_offset_ -
+ (this->border_size_) * this->row_offset_ + this->row_offset_ -
this->border_size_;
this->eoi_ = this->eor_ +
- this->line_offset_ * (ima.img_array().imax() - this->border_size_);
-
-
+ this->row_offset_ * (ima.img_array().imax() - this->border_size_);
}
template <typename T>
@@ -103,7 +101,7 @@
if (this->current_elt_ == this->eor_ and this->current_elt_ != this->eoi_)
{
this->current_elt_ += 2 * this->border_size_;
- this->eor_ += this->line_offset_;
+ this->eor_ += this->row_offset_;
}
}
Index: oln/core/3d/image3d_b.hh
--- oln/core/3d/image3d_b.hh (revision 971)
+++ oln/core/3d/image3d_b.hh (working copy)
@@ -33,7 +33,7 @@
# include <oln/core/internal/image_base.hh>
# include <oln/core/internal/utils.hh>
# include <oln/core/3d/array3d.hh>
-
+# include <oln/core/3d/fast_iterator_3d_b.hh>
namespace oln
{
@@ -65,6 +65,8 @@
typedef image3d_b<T> plain;
typedef image3d_b<pl::value> skeleton;
+
+ typedef fast_iterator_3d_b<value> fiter;
};
@@ -86,6 +88,8 @@
typedef internal::plain_primitive_image_<current> super;
typedef array3d_<T, int> array_t;
public:
+ //FIXME (fast image concept??)
+ typedef typename vtypes< image3d_b<T> >::fiter fiter;
stc_using(data);
image3d_b();
@@ -94,6 +98,9 @@
image3d_b(unsigned nslis, unsigned nrows, unsigned ncols,
unsigned border = 2);
+ array_t& img_array();
+ const array_t& img_array() const;
+
bool impl_owns_(const point3d& p) const;
bool impl_has_at(int sli, int row, int col) const;
@@ -164,6 +171,20 @@
}
template <typename T>
+ typename image3d_b<T>::array_t&
+ image3d_b<T>::img_array()
+ {
+ return this->data_->first;
+ }
+
+ template <typename T>
+ const typename image3d_b<T>::array_t&
+ image3d_b<T>::img_array() const
+ {
+ return this->data_->first;
+ }
+
+ template <typename T>
bool image3d_b<T>::impl_owns_(const point3d& p) const
{
assert(this->has_data());
Index: oln/core/3d/fast_iterator_3d.hh
--- oln/core/3d/fast_iterator_3d.hh (revision 971)
+++ oln/core/3d/fast_iterator_3d.hh (working copy)
@@ -71,10 +71,7 @@
template <typename T>
fast_iterator_3d<T>::fast_iterator_3d(image3d<T>& ima)
{
- this->start_ = ima.img_array().buffer() +
- ima.img_array().imin() * ima.img_array().jmin() * ima.img_array().kmin() +
- ima.img_array().jmin() * ima.img_array().kmin() +
- ima.img_array().kmin();
+ this->start_ = ima.img_array().buffer();
this->current_elt_ = this->start_;
Index: oln/core/3d/fast_iterator_3d_b.hh
--- oln/core/3d/fast_iterator_3d_b.hh (revision 0)
+++ oln/core/3d/fast_iterator_3d_b.hh (revision 0)
@@ -0,0 +1,134 @@
+// Copyright (C) 2007 EPITA
+// Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 3 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 03111-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_CORE_3D_FAST_ITERATOR_3D_B_HH
+# define OLN_CORE_3D_FAST_ITERATOR_3D_B_HH
+
+# include <cstddef>
+# include <oln/core/internal/fast_iterator_base.hh>
+# include <oln/core/3d/point3d.hh>
+
+namespace oln
+{
+ // Fwd decl.
+ template <typename T> class image3d_b;
+ template <typename T> class fast_iterator_3d_b;
+
+ // Super type.
+ template <typename T>
+ struct super_trait_< fast_iterator_3d_b<T> >
+ {
+ typedef fast_iterator_3d_b<T> current;
+ typedef internal::fast_iterator_base_<current> ret;
+ };
+
+ // Virtual types.
+ template <typename T>
+ struct vtypes< fast_iterator_3d_b<T> >
+ {
+ typedef T value;
+ };
+
+ // Fast iterator for image in one dimension
+ template <typename T>
+ class fast_iterator_3d_b :
+ public internal::fast_iterator_base_< fast_iterator_3d_b<T> >
+ {
+ typedef fast_iterator_3d_b<T> current;
+ typedef internal::fast_iterator_base_<current> super;
+ public:
+ stc_using(value);
+
+ fast_iterator_3d_b(image3d_b<T>& ima);
+ void impl_next();
+
+ protected:
+ unsigned border_size_;
+ int sli_offset_;
+ int row_offset_;
+
+ value *eor_; // end of row
+ value *eos_; // end of slice
+
+ };
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename T>
+ fast_iterator_3d_b<T>::fast_iterator_3d_b(image3d_b<T>& ima) :
+ border_size_(ima.border()),
+ sli_offset_(ima.img_array().i_pad()),
+ row_offset_(ima.img_array().j_pad())
+ {
+ this->start_ = &ima(point3d(0, 0, 0));
+
+ this->current_elt_ = this->start_;
+
+ this->eor_ = this->start_ + ima.ncols();
+
+ this->eos_ = ima.img_array().buffer() +
+ this->sli_offset_ * this->border_size_ +
+ this->row_offset_ * (ima.img_array().jlen() - 1 - this->border_size_) +
+ + ima.img_array().klen() - this->border_size_ ;
+
+ this->eoi_ = ima.img_array().buffer() +
+ this->sli_offset_ * (ima.img_array().ilen() - 1 - this->border_size_) +
+ this->row_offset_ * (ima.img_array().jlen() - 1 - this->border_size_) +
+ + ima.img_array().klen() - this->border_size_ ;
+ }
+
+ template <typename T>
+ void
+ fast_iterator_3d_b<T>::impl_next()
+ {
+ ++(this->current_elt_);
+
+ if (this->current_elt_ == this->eor_ and this->current_elt_ != this->eoi_)
+ {
+ if (this->current_elt_ != this->eos_) // end of a sli
+ {
+ this->current_elt_ += 2 * this->border_size_;
+ this->eor_ += this->row_offset_;
+ }
+ else // end of a slice
+ {
+ this->eor_ += (2 * this->border_size_ + 1) * this->row_offset_;
+
+ this->current_elt_ += 2 * this->border_size_ +
+ (2 * this->border_size_) * this->row_offset_;
+
+ this->eos_ += this->sli_offset_;
+ }
+ }
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+#endif // OLN_CORE_3D_FAST_ITERATOR_3D_B_HH
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Augment morphology.
* oln/core/gen/ternary_fun.hh: New.
* oln/logic: New directory.
* oln/logic/and.hh,
* oln/logic/not.hh,
* oln/morpho/hit_or_miss_all.hh,
* oln/morpho/hit_or_miss.hh,
* oln/morpho/hit_or_miss_background_closing.hh,
* oln/morpho/hit_or_miss_background_opening.hh,
* oln/morpho/hit_or_miss_closing.hh,
* oln/morpho/complementation.hh,
* oln/morpho/hit_or_miss_opening.hh,
* oln/level/ternary.hh,
* oln/arith/min.hh,
* oln/arith/negate.hh: New.
* oln/convert/to_window.hh
(to_window_values_, fill_): New in internal.
(to_window): New overload.
* oln/convert/to_weighted_window.hh: Update.
* oln/core/gen/dpoints_piter.hh
(dpoints_fwd_piter_, dpoints_bkd_piter_): New ctor overloads.
* oln/core/gen/window.hh (impl_fill_with): New.
* oln/core/gen/pw_value.hh (pw_value_base_): New.
(pw_value): Make inheritance flexible.
* oln/core/concept/window.hh (is_centered): New.
* oln/core/internal/window.hh (impl_is_centered): New.
* oln/core/internal/dpoints_impl.hh: Fix.
* oln/morpho/cc_tarjan_v1.hh (cc_tarjan): New facade.
* oln/morpho/cc_tarjan_v2.hh: Fix.
* oln/morpho/erosion.hh (postcondition): Fix.
* oln/morpho/dilation.hh (postcondition): Fix.
* oln/level/apply.hh: Cosmetic change.
* oln/canvas/two_pass.hh: Fix.
arith/min.hh | 86 ++++++++++++++++++++
arith/negate.hh | 96 ++++++++++++++++++++++
canvas/two_pass.hh | 4
convert/to_weighted_window.hh | 18 ++--
convert/to_window.hh | 63 +++++++++++++--
core/concept/window.hh | 8 +
core/gen/dpoints_piter.hh | 44 ++++++++++
core/gen/pw_value.hh | 33 +++++++
core/gen/ternary_fun.hh | 121 ++++++++++++++++++++++++++++
core/gen/window.hh | 3
core/internal/dpoints_impl.hh | 2
core/internal/window.hh | 9 ++
level/apply.hh | 6 -
level/ternary.hh | 90 +++++++++++++++++++++
logic/and.hh | 96 ++++++++++++++++++++++
logic/not.hh | 95 ++++++++++++++++++++++
morpho/cc_tarjan_v1.hh | 52 +++++++++---
morpho/cc_tarjan_v2.hh | 7 -
morpho/complementation.hh | 89 +++++++++++++++++++++
morpho/dilation.hh | 1
morpho/erosion.hh | 1
morpho/hit_or_miss.hh | 130 +++++++++++++++++++++++++++++++
morpho/hit_or_miss_all.hh | 41 +++++++++
morpho/hit_or_miss_background_closing.hh | 89 +++++++++++++++++++++
morpho/hit_or_miss_background_opening.hh | 89 +++++++++++++++++++++
morpho/hit_or_miss_closing.hh | 91 +++++++++++++++++++++
morpho/hit_or_miss_opening.hh | 92 +++++++++++++++++++++
27 files changed, 1415 insertions(+), 41 deletions(-)
Index: oln/convert/to_window.hh
--- oln/convert/to_window.hh (revision 970)
+++ oln/convert/to_window.hh (working copy)
@@ -30,6 +30,7 @@
# include <oln/core/concept/image.hh>
# include <oln/core/internal/f_image_to_window.hh>
+# include <oln/convert/to_dpoint.hh>
namespace oln
@@ -38,12 +39,23 @@
namespace convert
{
- // Fwd decl.
+ // Fwd decls.
+
+ namespace internal
+ {
+ template <unsigned n>
+ struct to_window_values_;
+ }
template <typename I>
oln_f_image_to_window(I)
to_window(const Binary_Image<I>& input);
+ template <unsigned n>
+ internal::to_window_values_<n>
+ to_window(const bool (&values)[n]);
+ // FIXME: Wrong semantics: to_window should really give a window...
+
# ifndef OLN_INCLUDE_ONLY
@@ -53,18 +65,59 @@
oln_f_image_to_window(I)
to_window(const Binary_Image<I>& input)
{
- oln_f_image_to_window(I) tmp;
+ oln_f_image_to_window(I) win;
oln_dpoint(I) dp;
oln_piter(I) p(input.points());
for_all(p)
if (input(p) = true)
+ win.take(convert::to_dpoint(p));
+ return win;
+ }
+
+
+ namespace internal
{
- dp.vec() = p.vec();
- // FIXME: Better s.a. dp = p.to_dpoint();
- tmp.take(dp);
+
+ template <typename G, typename W, unsigned n>
+ void fill_(W& win, const bool (&values)[n])
+ {
+ int h = int(std::sqrt(n)) / 2;
+ precondition((2 * h + 1) * (2 * h + 1) = n);
+ unsigned i = 0;
+ for (int drow = -h; drow <= h; ++drow) // FIXME: Replace 'int' by 'oln_coord(W)'
+ for (int dcol = -h; dcol <= h; ++dcol)
+ if (values[i++] = true)
+ win.take(oln_dpoint(W)(drow, dcol));
}
+
+ template <unsigned n>
+ struct to_window_values_
+ {
+ const bool (&values_)[n];
+
+ to_window_values_(const bool (&values)[n])
+ : values_(values)
+ {}
+
+ template <typename W>
+ operator W() const
+ {
+ mlc::assert_< mlc_is_a(W, Window) >::check(); // FIXME: Add err msg.
+ W tmp;
+ fill_<oln_grid(W)>(tmp, values_);
return tmp;
}
+ };
+
+ } // end of namespace oln::convert::internal
+
+
+ template <unsigned n>
+ internal::to_window_values_<n>
+ to_window(const bool (&values)[n])
+ {
+ return internal::to_window_values_<n>(values);
+ }
# endif // ! OLN_INCLUDE_ONLY
Index: oln/convert/to_weighted_window.hh
--- oln/convert/to_weighted_window.hh (revision 970)
+++ oln/convert/to_weighted_window.hh (working copy)
@@ -28,10 +28,11 @@
#ifndef OLN_CONVERT_TO_WEIGHTED_WINDOW_HH
# define OLN_CONVERT_TO_WEIGHTED_WINDOW_HH
-# include <oln/core/gen/zero.hh>
# include <oln/core/concept/image.hh>
# include <oln/core/concept/window.hh>
# include <oln/core/concept/function.hh>
+# include <oln/core/gen/zero.hh>
+# include <oln/convert/to_dpoint.hh>
# include <oln/core/internal/f_weighted_window.hh>
@@ -62,11 +63,11 @@
oln_f_image_to_weighted_window(I)
to_weighted_window(const Image<I>& input)
{
- oln_f_image_to_weighted_window(I) output;
+ oln_f_image_to_weighted_window(I) w_win;
oln_piter(I) p(input.points());
for_all(p)
- output.take(input(p), zero - oln_point(I)(p));
- return output;
+ w_win.take(input(p), convert::to_dpoint(p));
+ return w_win;
}
template <typename F, typename W>
@@ -74,12 +75,11 @@
to_weighted_window(const Function_p2v<F>& weight, const Window<W>& win)
{
const F& weight_ = exact(weight);
- oln_f_weighted_window(oln_result(F), oln_dpoint(W)) output;
- oln_point(W) O; O.set_all(0);
- oln_qiter(W) q(win, O);
+ oln_f_weighted_window(oln_result(F), oln_dpoint(W)) w_win;
+ oln_qiter(W) q(win, zero);
for_all(q)
- output.take(weight_(q), O - oln_point(W)(q)); // FIXME: to_point
- return output;
+ w_win.take(weight_(q), convert::to_dpoint(q));
+ return w_win;
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/core/gen/dpoints_piter.hh
--- oln/core/gen/dpoints_piter.hh (revision 970)
+++ oln/core/gen/dpoints_piter.hh (working copy)
@@ -75,12 +75,18 @@
template <typename W, typename Pl>
dpoints_fwd_piter_(const Window<W>& win, const Generalized_Point<Pl>& p);
+ template <typename W>
+ dpoints_fwd_piter_(const Window<W>& win, const P& p);
+
template <typename I, typename Pl>
dpoints_fwd_piter_(const Image_with_Nbh<I>& ima, const Generalized_Point<Pl>& p);
template <typename N, typename Pl>
dpoints_fwd_piter_(const Neighborhood<N>& nbh, const Generalized_Point<Pl>& p);
+ template <typename N>
+ dpoints_fwd_piter_(const Neighborhood<N>& nbh, const P& p);
+
}; // end of class oln::dpoints_fwd_piter_<P>
@@ -120,12 +126,18 @@
template <typename W, typename Pl>
dpoints_bkd_piter_(const Window<W>& win, const Generalized_Point<Pl>& p);
+ template <typename W>
+ dpoints_bkd_piter_(const Window<W>& win, const P& p);
+
template <typename I, typename Pl>
dpoints_bkd_piter_(const Image_with_Nbh<I>& ima, const Generalized_Point<Pl>& p);
template <typename N, typename Pl>
dpoints_bkd_piter_(const Neighborhood<N>& nbh, const Generalized_Point<Pl>& p);
+ template <typename N>
+ dpoints_bkd_piter_(const Neighborhood<N>& nbh, const P& p);
+
}; // end of class oln::dpoints_bkd_piter_<P>
@@ -143,6 +155,14 @@
}
template <typename P>
+ template <typename W>
+ dpoints_fwd_piter_<P>::dpoints_fwd_piter_(const Window<W>& win, const P& p)
+ :
+ internal::dpoints_fwd_piter_impl_<P>(p, exact(win)) // FIXME: Propagate "win first, then p".
+ {
+ }
+
+ template <typename P>
template <typename I, typename Pl>
dpoints_fwd_piter_<P>::dpoints_fwd_piter_(const Image_with_Nbh<I>& ima, const Generalized_Point<Pl>& p)
:
@@ -158,6 +178,14 @@
{
}
+ template <typename P>
+ template <typename N>
+ dpoints_fwd_piter_<P>::dpoints_fwd_piter_(const Neighborhood<N>& nbh, const P& p)
+ :
+ internal::dpoints_fwd_piter_impl_<P>(p, exact(nbh))
+ {
+ }
+
// bkd
template <typename P>
@@ -169,6 +197,14 @@
}
template <typename P>
+ template <typename W>
+ dpoints_bkd_piter_<P>::dpoints_bkd_piter_(const Window<W>& win, const P& p)
+ :
+ internal::dpoints_bkd_piter_impl_<P>(p, exact(win))
+ {
+ }
+
+ template <typename P>
template <typename I, typename Pl>
dpoints_bkd_piter_<P>::dpoints_bkd_piter_(const Image_with_Nbh<I>& ima, const Generalized_Point<Pl>& p)
:
@@ -184,6 +220,14 @@
{
}
+ template <typename P>
+ template <typename N>
+ dpoints_bkd_piter_<P>::dpoints_bkd_piter_(const Neighborhood<N>& nbh, const P& p)
+ :
+ internal::dpoints_bkd_piter_impl_<P>(p, exact(nbh))
+ {
+ }
+
# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/gen/window.hh
--- oln/core/gen/window.hh (revision 970)
+++ oln/core/gen/window.hh (working copy)
@@ -65,6 +65,9 @@
gen_window();
+ template <unsigned n>
+ void impl_fill_with(const bool (&values)[n]);
+
}; // end of class oln::gen_window<Dp>
Index: oln/core/gen/pw_value.hh
--- oln/core/gen/pw_value.hh (revision 970)
+++ oln/core/gen/pw_value.hh (working copy)
@@ -45,10 +45,34 @@
} // end of namespace oln::ERROR
+ // Fwd decl.
+ template <typename I> class pw_value_;
+
+
+ namespace internal
+ {
+
+ template <bool b, typename I>
+ struct pw_value_base_;
+
+ template <typename I>
+ struct pw_value_base_< true, I > : public Function_p2b< pw_value_<I> >
+ {
+ };
+
template <typename I>
- class pw_value_ : public Function_p2v< pw_value_<I> >,
- private mlc::assert_< mlc_is_a(I, Image),
- ERROR::pw_value_works_on_images_not_on_<I> >
+ struct pw_value_base_< false, I > : public Function_p2v< pw_value_<I> >
+ {
+ };
+
+ } // end of namespace oln::internal
+
+
+ template <typename I>
+ class pw_value_
+ :
+ public internal::pw_value_base_< mlc_is_a(I, Binary_Image)::eval::value,
+ I >
{
public:
typedef oln_point(I) argument; // FIXME: psite?
@@ -64,6 +88,7 @@
};
+
template <typename I>
pw_value_<I> pw_value(const Image<I>& ima);
@@ -94,6 +119,8 @@
return this->ima_;
}
+ // pw_value
+
template <typename I>
pw_value_<I>
pw_value(const Image<I>& ima)
Index: oln/core/gen/ternary_fun.hh
--- oln/core/gen/ternary_fun.hh (revision 0)
+++ oln/core/gen/ternary_fun.hh (revision 0)
@@ -0,0 +1,121 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_CORE_GEN_TERNARY_FUN_HH
+# define OLN_CORE_GEN_TERNARY_FUN_HH
+
+# include <oln/core/concept/function.hh>
+
+
+
+namespace oln
+{
+
+
+ namespace internal
+ {
+
+ template <bool b, typename B, typename T, typename F>
+ struct ternary_base_;
+
+ template <typename B, typename T, typename F>
+ struct ternary_base_< true, B,T,F > : public Function_p2b< ternary_fun_<B,T,F> >
+ {
+ };
+
+ template <typename B, typename T, typename F>
+ struct ternary_base_< false, B,T,F > : public Function_p2v< ternary_fun_<B,T,F> >
+ {
+ };
+
+ } // end of namespace oln::internal
+
+
+
+ template <typename B, typename T, typename F>
+ class ternary_fun_
+ :
+ public internal::ternary_base_< mlc_is_a(oln_result(T), bool), B,T,F >
+ {
+ public:
+ typedef oln_argument(B) argument;
+ typedef oln_result(T) result; // FIXME: oln_promote_trait( oln_result(T), oln_result(F) )?
+
+ ternary_fun_(const B& b, const T& t, const F& f);
+
+ result operator()(argument arg) const;
+
+ protected:
+ B b_;
+ T t_;
+ F f_;
+ };
+
+
+ template <typename B, typename T, typename F>
+ ternary_fun_<B,T,F> ternary_fun(const Function_p2b<B>& b,
+ const Function_p2v<T>& t, const Function_p2v<F>& f);
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ // ternary_fun_<B,T,F>
+
+ template <typename B, typename T, typename F>
+ ternary_fun_<B,T,F>::ternary_fun_(const B& b, const T& t, const F& f)
+ : b_(b),
+ t_(t),
+ f_(f)
+ {
+ }
+
+ template <typename B, typename T, typename F>
+ typename ternary_fun_<B,T,F>::result
+ ternary_fun_<B,T,F>::operator()(argument arg) const
+ {
+ return this->b_(arg) ? this->t_(arg) : this->f_(arg);
+ }
+
+ // ternary_fun
+
+ template <typename B, typename T, typename F>
+ ternary_fun_<B,T,F>
+ ternary_fun(const Function_p2b<B>& b,
+ const Function_p2v<T>& t, const Function_p2v<F>& f)
+ {
+ // FIXME: Add static asserts here!
+ ternary_fun_<B,T,F> tmp(exact(b), exact(t), exact(f));
+ return tmp;
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_GEN_TERNARY_FUN_HH
Index: oln/core/concept/window.hh
--- oln/core/concept/window.hh (revision 970)
+++ oln/core/concept/window.hh (working copy)
@@ -48,6 +48,7 @@
stc_typename(bkd_qiter);
unsigned size() const;
+ bool is_centered() const;
protected:
Window();
@@ -73,6 +74,13 @@
return exact(this)->impl_size();
}
+ template <typename Exact>
+ bool
+ Window<Exact>::is_centered() const
+ {
+ return exact(this)->impl_is_centered();
+ }
+
template <typename W>
W operator - (const Window<W>& rhs)
{
Index: oln/core/internal/window.hh
--- oln/core/internal/window.hh (revision 970)
+++ oln/core/internal/window.hh (working copy)
@@ -31,6 +31,7 @@
# include <oln/core/internal/window_base.hh>
# include <oln/core/internal/dpoints_impl.hh>
# include <oln/core/gen/dpoints_piter.hh>
+# include <oln/core/gen/zero.hh>
namespace oln
@@ -76,6 +77,7 @@
Exact& take(const dpoint& dp);
Exact& impl_take(const dpoint& dp);
+ bool impl_is_centered() const;
Exact impl_op_unary_minus_() const;
@@ -108,6 +110,13 @@
}
template <typename Exact>
+ bool
+ window_<Exact>::impl_is_centered() const
+ {
+ return this->has(zero);
+ }
+
+ template <typename Exact>
Exact
window_<Exact>::impl_op_unary_minus_() const
{
Index: oln/core/internal/dpoints_impl.hh
--- oln/core/internal/dpoints_impl.hh (revision 970)
+++ oln/core/internal/dpoints_impl.hh (working copy)
@@ -74,7 +74,7 @@
const dpoints_impl_<Dp>& dps)
{
ostr << "[ ";
- unsigned n = dps.size();
+ unsigned n = dps.impl_size();
for (unsigned i = 0; i < n; ++i)
ostr << dps[i] << (i = n - 1 ? " ]" : ", ");
return ostr;
Index: oln/logic/and.hh
--- oln/logic/and.hh (revision 0)
+++ oln/logic/and.hh (revision 0)
@@ -0,0 +1,96 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_LOGIC_AND_HH
+# define OLN_LOGIC_AND_HH
+
+# include <oln/core/concept/image.hh>
+# include <oln/core/gen/traits.hh>
+# include <oln/core/gen/pw_value.hh>
+# include <oln/level/fill.hh>
+
+
+
+namespace oln
+{
+
+ // Trait.
+
+ template <typename I>
+ struct set_trait_< Image, I, and_id, Image, I >
+ {
+ typedef oln_plain(I) ret;
+ };
+
+
+ // Fwd decl.
+
+ template <typename I>
+ oln_plain(I)
+ operator and (const Binary_Image<I>& lhs, const Binary_Image<I>& rhs);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace logic
+ {
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename I>
+ oln_plain(I)
+ and_(const Binary_Image<I>& lhs, const Binary_Image<I>& rhs)
+ {
+ oln_plain(I) output;
+ prepare(output, with, lhs);
+ level::fill(inplace(output), pw_value(lhs) and pw_value(rhs));
+ return output;
+ }
+
+
+ } // end of namespace oln::logic::impl
+
+ } // end of namespace oln::logic
+
+
+ // Facade.
+
+ template <typename I>
+ oln_plain(I)
+ operator and (const Binary_Image<I>& lhs, const Binary_Image<I>& rhs)
+ {
+ precondition(lhs.points() = rhs.points());
+ return logic::impl::and_(lhs, rhs);
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+#endif // ! OLN_LOGIC_AND_HH
Index: oln/logic/not.hh
--- oln/logic/not.hh (revision 0)
+++ oln/logic/not.hh (revision 0)
@@ -0,0 +1,95 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_LOGIC_NOT_HH
+# define OLN_LOGIC_NOT_HH
+
+# include <oln/core/concept/image.hh>
+# include <oln/core/gen/traits.hh>
+# include <oln/core/gen/pw_value.hh>
+# include <oln/level/fill.hh>
+
+
+
+namespace oln
+{
+
+ // Trait.
+
+ template <typename I>
+ struct set_utrait_< not_id, Image, I >
+ {
+ typedef oln_plain(I) ret;
+ };
+
+
+ // Fwd decl.
+
+ template <typename I>
+ oln_plain(I)
+ operator not (const Binary_Image<I>& rhs);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace logic
+ {
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename I>
+ oln_plain(I)
+ not_(const Binary_Image<I>& rhs)
+ {
+ oln_plain(I) output;
+ prepare(output, with, rhs);
+ level::fill(inplace(output), not pw_value(rhs));
+ return output;
+ }
+
+
+ } // end of namespace oln::logic::impl
+
+ } // end of namespace oln::logic
+
+
+ // Facade.
+
+ template <typename I>
+ oln_plain(I)
+ operator not (const Binary_Image<I>& rhs)
+ {
+ return logic::impl::not_(rhs);
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+#endif // ! OLN_LOGIC_NOT_HH
Index: oln/morpho/cc_tarjan_v2.hh
--- oln/morpho/cc_tarjan_v2.hh (revision 970)
+++ oln/morpho/cc_tarjan_v2.hh (working copy)
@@ -68,7 +68,7 @@
level::fill(inplace(is_processed), false);
}
- void first_pass_body(const point& p, I f)
+ void first_pass_body(const point& p, const I& f)
{
parent(p) = p;
if ( f(p) )
@@ -84,7 +84,7 @@
}
- void second_pass_body(const point& p, I f)
+ void second_pass_body(const point& p, const I& f)
{
unsigned current_label = 0;
if ( f(p) = true and parent(p) = p )
@@ -93,9 +93,8 @@
output(p) = output(parent(p));
}
- void final(I f)
+ void final(const I&)
{
- f = f;
}
point find_root(const I& ima,
Index: oln/morpho/hit_or_miss_all.hh
--- oln/morpho/hit_or_miss_all.hh (revision 0)
+++ oln/morpho/hit_or_miss_all.hh (revision 0)
@@ -0,0 +1,41 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_MORPHO_HIT_OR_MISS_ALL_HH
+# define OLN_MORPHO_HIT_OR_MISS_ALL_HH
+
+
+# include <oln/morpho/hit_or_miss.hh>
+
+# include <oln/morpho/hit_or_miss_opening.hh>
+# include <oln/morpho/hit_or_miss_closing.hh>
+
+# include <oln/morpho/hit_or_miss_background_opening.hh>
+# include <oln/morpho/hit_or_miss_background_closing.hh>
+
+
+#endif // ! OLN_MORPHO_HIT_OR_MISS_ALL_HH
Index: oln/morpho/erosion.hh
--- oln/morpho/erosion.hh (revision 970)
+++ oln/morpho/erosion.hh (working copy)
@@ -119,6 +119,7 @@
erosion(const Image<I>& input, const Window<W>& win)
{
oln_plain(I) output = impl::erosion_(exact(input), exact(win));
+ if (win.is_centered())
postcondition(output <= input);
return output;
}
Index: oln/morpho/hit_or_miss.hh
--- oln/morpho/hit_or_miss.hh (revision 0)
+++ oln/morpho/hit_or_miss.hh (revision 0)
@@ -0,0 +1,130 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_MORPHO_HIT_OR_MISS_HH
+# define OLN_MORPHO_HIT_OR_MISS_HH
+
+# include <oln/morpho/erosion.hh>
+
+# include <oln/arith/min.hh>
+# include <oln/arith/negate.hh>
+
+# include <oln/logic/not.hh>
+# include <oln/logic/and.hh>
+
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ // Fwd decl.
+
+ template <typename I, typename W1, typename W2>
+ oln_plain(I)
+ hit_or_miss(const Image<I>& input,
+ const Window<W1>& B1, const Window<W2>& B2);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic versions.
+
+ template <typename I, typename W1, typename W2>
+ oln_plain(I)
+ hit_or_miss_on_function_(const Image<I>& input,
+ const Window<W1>& B1, const Window<W2>& B2)
+ {
+ oln_plain(I)
+ fit = erosion(input, B1),
+ miss = erosion(arith::negate(input), B2);
+ return arith::min(fit, miss);
+ }
+
+ template <typename I, typename W1, typename W2>
+ oln_plain(I)
+ hit_or_miss_on_set_(const Binary_Image<I>& input,
+ const Window<W1>& B1, const Window<W2>& B2)
+ {
+ oln_plain(I)
+ fit = erosion(input, B1),
+ miss = erosion(not input, B2);
+ return fit and miss;
+ }
+
+ // FIXME: Add a fast version.
+
+
+ // Impl facade.
+
+ template <typename I, typename W1, typename W2>
+ oln_plain(I)
+ hit_or_miss_(const Image<I>& input,
+ const W1& B1, const W2& B2)
+ {
+ return hit_or_miss_on_function_(exact(input), B1, B2);
+ }
+
+ template <typename I, typename W1, typename W2>
+ oln_plain(I)
+ hit_or_miss_(const Binary_Image<I>& input,
+ const W1& B1, const W2& B2)
+ {
+ return hit_or_miss_on_set_(exact(input), B1, B2);
+ }
+
+
+ } // end of namespace oln::morpho::impl
+
+
+ // Facade.
+
+ template <typename I, typename W1, typename W2>
+ oln_plain(I)
+ hit_or_miss(const Image<I>& input,
+ const Window<W1>& B1, const Window<W2>& B2)
+ {
+ // FIXME: Add: precondition(inter(B1, B2).card() = 0);
+ oln_plain(I) output = impl::hit_or_miss_(exact(input),
+ exact(B1), exact(B2));
+ if (B1.is_centered()) // FIXME: ok?
+ postcondition(output <= input);
+ return output;
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_HIT_OR_MISS_HH
Index: oln/morpho/cc_tarjan_v1.hh
--- oln/morpho/cc_tarjan_v1.hh (revision 970)
+++ oln/morpho/cc_tarjan_v1.hh (working copy)
@@ -34,6 +34,7 @@
# include <oln/level/fill.hh>
# include <oln/core/internal/f_ch_value.hh>
+
namespace oln
{
@@ -44,6 +45,11 @@
oln_plain_value(I, unsigned)
cc_tarjan(const Image_with_Nbh<I>& f);
+ template <typename I>
+ oln_plain_value(I, unsigned)
+ cc_tarjan(const Image_with_Nbh<I>& f, unsigned& nlabels);
+
+
# ifndef OLN_INCLUDE_ONLY
namespace impl
@@ -58,6 +64,7 @@
oln_plain_value(I, unsigned) output;
oln_plain_value(I, bool) is_processed;
oln_plain_value(I, point) parent;
+ unsigned nlabels;
cc_tarjan_(const I& f)
: f(f)
@@ -70,12 +77,13 @@
prepare(output, with, f);
prepare(parent, with, f);
level::fill(inplace(is_processed), false);
+ nlabels = 0;
}
void first_pass_body(const point& p)
{
parent(p) = p;
- if ( f(p) )
+ if (f(p) = true)
{
oln_niter(I) n(f, p);
for_all(n)
@@ -85,31 +93,34 @@
}
is_processed(p) = true;
}
-
}
void second_pass_body(const point& p)
{
- unsigned current_label = 0;
- if ( f(p) = true and parent(p) = p )
- output(p) = ++current_label;
+ if (f(p) = true)
+ {
+ if (parent(p) = p)
+ output(p) = ++nlabels;
else
output(p) = output(parent(p));
}
+ else
+ output(p) = 0; // bg label
+ }
- void final() { }
+ void final()
+ {
+ }
// auxiliary methods
- point find_root(const point& x)
+ point find_root(const point& x) // FIXME: or w/o const&?
{
- if (parent(x) != x)
- {
- parent(x) = find_root(parent(x));
- return parent(x);
- }
+ if (parent(x) = x)
return x;
+ else
+ return parent(x) = find_root(parent(x));
}
void do_union(const point& n,
@@ -124,15 +135,28 @@
} // end of namespace oln::morpho::impl
+
// Facades.
template <typename I>
oln_plain_value(I, unsigned)
- cc_tarjan(const Image_with_Nbh<I>& f)
+ cc_tarjan(const Image_with_Nbh<I>& f, unsigned& nlabels)
{
impl::cc_tarjan_<I> run(exact(f));
+ std::cout << run.output.is_empty() << std::endl;
canvas::v1::two_pass(run);
- return run.output;
+ std::cout << run.output.is_empty() << std::endl;
+ nlabels = run.nlabels;
+ oln_plain_value(I, unsigned) tmp = run.output;
+ return tmp;
+ }
+
+ template <typename I>
+ oln_plain_value(I, unsigned)
+ cc_tarjan(const Image_with_Nbh<I>& f)
+ {
+ unsigned nlabels;
+ return cc_tarjan(f, nlabels);
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/morpho/hit_or_miss_background_closing.hh
--- oln/morpho/hit_or_miss_background_closing.hh (revision 0)
+++ oln/morpho/hit_or_miss_background_closing.hh (revision 0)
@@ -0,0 +1,89 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_MORPHO_HIT_OR_MISS_BACKGROUND_CLOSING_HH
+# define OLN_MORPHO_HIT_OR_MISS_BACKGROUND_CLOSING_HH
+
+# include <oln/morpho/hit_or_miss_closing.hh>
+# include <oln/morpho/complementation.hh>
+
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ // Fwd decl.
+
+ template <typename I, typename W1, typename W2>
+ oln_plain(I)
+ hit_or_miss_background_closing(const Image<I>& input,
+ const Window<W1>& B1, const Window<W2>& B2);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename I, typename W1, typename W2>
+ oln_plain(I)
+ hit_or_miss_background_closing_(const Image<I>& input,
+ const Window<W1>& B1, const Window<W2>& B2)
+ {
+ oln_plain(I)
+ com = morpho::complementation(input),
+ output = morpho::hit_or_miss_closing(com, B2, B1);
+ return output;
+ }
+
+ } // end of namespace oln::morpho::impl
+
+
+ // Facade.
+
+ template <typename I, typename W1, typename W2>
+ oln_plain(I)
+ hit_or_miss_background_closing(const Image<I>& input,
+ const Window<W1>& B1, const Window<W2>& B2)
+ {
+ // FIXME: Add: precondition(inter(B1, B2).card() = 0);
+ return impl::hit_or_miss_background_closing_(exact(input),
+ exact(B1), exact(B2));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_HIT_OR_MISS_BACKGROUND_CLOSING_HH
Index: oln/morpho/hit_or_miss_background_opening.hh
--- oln/morpho/hit_or_miss_background_opening.hh (revision 0)
+++ oln/morpho/hit_or_miss_background_opening.hh (revision 0)
@@ -0,0 +1,89 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_MORPHO_HIT_OR_MISS_BACKGROUND_OPENING_HH
+# define OLN_MORPHO_HIT_OR_MISS_BACKGROUND_OPENING_HH
+
+# include <oln/morpho/hit_or_miss_opening.hh>
+# include <oln/morpho/complementation.hh>
+
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ // Fwd decl.
+
+ template <typename I, typename W1, typename W2>
+ oln_plain(I)
+ hit_or_miss_background_opening(const Image<I>& input,
+ const Window<W1>& B1, const Window<W2>& B2);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename I, typename W1, typename W2>
+ oln_plain(I)
+ hit_or_miss_background_opening_(const Image<I>& input,
+ const Window<W1>& B1, const Window<W2>& B2)
+ {
+ oln_plain(I)
+ com = morpho::complementation(input),
+ output = morpho::hit_or_miss_opening(com, B2, B1);
+ return output;
+ }
+
+ } // end of namespace oln::morpho::impl
+
+
+ // Facade.
+
+ template <typename I, typename W1, typename W2>
+ oln_plain(I)
+ hit_or_miss_background_opening(const Image<I>& input,
+ const Window<W1>& B1, const Window<W2>& B2)
+ {
+ // FIXME: Add: precondition(inter(B1, B2).card() = 0);
+ return impl::hit_or_miss_background_opening_(exact(input),
+ exact(B1), exact(B2));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_HIT_OR_MISS_BACKGROUND_OPENING_HH
Index: oln/morpho/hit_or_miss_closing.hh
--- oln/morpho/hit_or_miss_closing.hh (revision 0)
+++ oln/morpho/hit_or_miss_closing.hh (revision 0)
@@ -0,0 +1,91 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_MORPHO_HIT_OR_MISS_CLOSING_HH
+# define OLN_MORPHO_HIT_OR_MISS_CLOSING_HH
+
+# include <oln/morpho/hit_or_miss_opening.hh>
+# include <oln/morpho/complementation.hh>
+# include <oln/morpho/closing.hh>
+
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ // Fwd decl.
+
+ template <typename I, typename W1, typename W2>
+ oln_plain(I)
+ hit_or_miss_closing(const Image<I>& input,
+ const Window<W1>& B1, const Window<W2>& B2);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename I, typename W1, typename W2>
+ oln_plain(I)
+ hit_or_miss_closing_(const Image<I>& input,
+ const Window<W1>& B1, const Window<W2>& B2)
+ {
+ oln_plain(I)
+ com = morpho::complementation(input),
+ ope = morpho::hit_or_miss_opening(com, B1, B2);
+ return morpho::complementation(ope);
+ }
+
+ } // end of namespace oln::morpho::impl
+
+
+ // Facade.
+
+ template <typename I, typename W1, typename W2>
+ oln_plain(I)
+ hit_or_miss_closing(const Image<I>& input,
+ const Window<W1>& B1, const Window<W2>& B2)
+ {
+ // FIXME: Add: precondition(inter(B1, B2).card() = 0);
+ oln_plain(I) output = impl::hit_or_miss_closing_(exact(input),
+ exact(B1), exact(B2));
+ postcondition(output >= morpho::closing(input, B1));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_HIT_OR_MISS_CLOSING_HH
Index: oln/morpho/complementation.hh
--- oln/morpho/complementation.hh (revision 0)
+++ oln/morpho/complementation.hh (revision 0)
@@ -0,0 +1,89 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_MORPHO_COMPLEMENTATION_HH
+# define OLN_MORPHO_COMPLEMENTATION_HH
+
+# include <oln/arith/negate.hh>
+# include <oln/logic/not.hh>
+
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ // Fwd decl.
+
+ template <typename I>
+ oln_plain(I)
+ complementation(const Image<I>& input);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic versions.
+
+ template <typename I>
+ oln_plain(I)
+ complementation_(const Image<I>& input)
+ {
+ return arith::negate(input);
+ }
+
+ template <typename I>
+ oln_plain(I)
+ complementation_(const Binary_Image<I>& input)
+ {
+ return not input;
+ }
+
+ } // end of namespace oln::morpho::impl
+
+
+ // Facade.
+
+ template <typename I>
+ oln_plain(I)
+ complementation(const Image<I>& input)
+ {
+ oln_plain(I) output = impl::complementation_(exact(input));
+ return output;
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_COMPLEMENTATION_HH
Index: oln/morpho/hit_or_miss_opening.hh
--- oln/morpho/hit_or_miss_opening.hh (revision 0)
+++ oln/morpho/hit_or_miss_opening.hh (revision 0)
@@ -0,0 +1,92 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_MORPHO_HIT_OR_MISS_OPENING_HH
+# define OLN_MORPHO_HIT_OR_MISS_OPENING_HH
+
+# include <oln/morpho/hit_or_miss.hh>
+# include <oln/morpho/opening.hh>
+
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ // Fwd decl.
+
+ template <typename I, typename W1, typename W2>
+ oln_plain(I)
+ hit_or_miss_opening(const Image<I>& input,
+ const Window<W1>& B1, const Window<W2>& B2);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename I, typename W1, typename W2>
+ oln_plain(I)
+ hit_or_miss_opening_(const Image<I>& input,
+ const Window<W1>& B1, const Window<W2>& B2)
+ {
+ oln_plain(I) hom = morpho::hit_or_miss(input, B1, B2);
+ return morpho::dilation(hom, - B1);
+ }
+
+ // FIXME: Add a fast version.
+
+
+ } // end of namespace oln::morpho::impl
+
+
+ // Facade.
+
+ template <typename I, typename W1, typename W2>
+ oln_plain(I)
+ hit_or_miss_opening(const Image<I>& input,
+ const Window<W1>& B1, const Window<W2>& B2)
+ {
+ // FIXME: Add: precondition(inter(B1, B2).card() = 0);
+ oln_plain(I) output = impl::hit_or_miss_opening_(exact(input),
+ exact(B1), exact(B2));
+ postcondition(output <= morpho::opening(input, B1));
+ return output;
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_HIT_OR_MISS_OPENING_HH
Index: oln/morpho/dilation.hh
--- oln/morpho/dilation.hh (revision 970)
+++ oln/morpho/dilation.hh (working copy)
@@ -100,6 +100,7 @@
dilation(const Image<I>& input, const Window<W>& win)
{
oln_plain(I) output = impl::dilation_(exact(input), exact(win));
+ if (win.is_centered())
postcondition(output >= input);
return output;
}
Index: oln/level/ternary.hh
--- oln/level/ternary.hh (revision 0)
+++ oln/level/ternary.hh (revision 0)
@@ -0,0 +1,90 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_LEVEL_TERNARY_HH
+# define OLN_LEVEL_TERNARY_HH
+
+# include <oln/core/concept/image.hh>
+# include <oln/core/gen/ternary_fun.hh>
+# include <oln/core/gen/pw_value.hh>
+# include <oln/core/level/fill.hh>
+
+
+namespace oln
+{
+
+ namespace level
+ {
+
+ // Fwd decl.
+
+ template <typename B, typename T, typename F>
+ oln_plain(T) // FIXME: oln_promote_trait(oln_value(T), oln_value(B))
+ ternary(const Binary_Image<B>& b, const Image<T>& t, const Image<F>& f);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename B, typename T, typename F>
+ oln_plain(T)
+ ternary(const Binary_Image<B>& b, const Image<T>& t, const Image<F>& f)
+ {
+ oln_plain(T) output;
+ prepare(output, with, t);
+ return level::fill(inplace(output),
+ ternary_fun(pw_value(b), pw_value(t), pw_value(f)));
+ }
+
+ } // end of namespace oln::level::impl
+
+
+ // Facades.
+
+ template <typename B, typename T, typename F>
+ oln_plain(T)
+ ternary(const Binary_Image<B>& b, const Image<T>& t, const Image<F>& f)
+ {
+ oln::assert_same_point_<B, T>::check();
+ oln::assert_same_point_<T, F>::check();
+ precondition(b.points() >= t.points());
+ precondition(t.points() = f.points());
+ return impl::ternary_(exact(b), exact(t), exact(f));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::level
+
+} // end of namespace oln
+
+
+#endif // ! OLN_LEVEL_TERNARY_HH
Index: oln/level/apply.hh
--- oln/level/apply.hh (revision 970)
+++ oln/level/apply.hh (working copy)
@@ -40,7 +40,7 @@
namespace level
{
- /// Fwd decls.
+ // Fwd decls.
template <typename F, typename I>
oln_plain_value(I, typename F::result)
@@ -76,7 +76,7 @@
} // end of namespace oln::level::impl
- /// Facades.
+ // Facades.
template <typename F, typename I>
oln_plain_value(I, typename F::result)
@@ -93,7 +93,7 @@
}
-# endif
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln::level
Index: oln/arith/min.hh
--- oln/arith/min.hh (revision 0)
+++ oln/arith/min.hh (revision 0)
@@ -0,0 +1,86 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_ARITH_MIN_HH
+# define OLN_ARITH_MIN_HH
+
+# include <oln/core/concept/image.hh>
+
+
+namespace oln
+{
+
+ namespace arith
+ {
+
+ // Fwd decl.
+
+ template <typename I>
+ oln_plain(I)
+ min(const Image<I>& input1, const Image<I>& input2);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename I>
+ oln_plain(I)
+ min_(const Image<I>& input1, const Image<I>& input2)
+ {
+ oln_plain(I) output;
+ prepare(output, with, input1);
+ oln_piter(I) p(input1.points());
+ for_all(p)
+ output(p) = ( input1(p) < input2(p)
+ ? input1(p)
+ : input2(p) );
+ return output;
+ }
+
+ } // end of namespace oln::arith::impl
+
+
+ // Facade.
+
+ template <typename I>
+ oln_plain(I)
+ min(const Image<I>& input1, const Image<I>& input2)
+ {
+ return impl::min_(exact(input1), exact(input2));
+ }
+
+ } // end of namespace oln::arith
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+#endif // ! OLN_ARITH_MIN_HH
Index: oln/arith/negate.hh
--- oln/arith/negate.hh (revision 0)
+++ oln/arith/negate.hh (revision 0)
@@ -0,0 +1,96 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_ARITH_NEGATE_HH
+# define OLN_ARITH_NEGATE_HH
+
+# include <oln/core/concept/image.hh>
+# include <oln/core/internal/max_value.hh>
+# include <oln/core/internal/min_value.hh>
+
+
+namespace oln
+{
+
+ namespace arith
+ {
+
+ // Fwd decl.
+
+ template <typename I>
+ oln_plain(I)
+ negate(const Image<I>& input);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // FIXME: Trash code! Not so simple...
+
+ template <typename T>
+ T value_negate_(const T& v)
+ {
+ return static_cast<T>(oln_min(T) + (oln_max(T) - v));
+ }
+
+
+ // Generic version.
+
+ template <typename I>
+ oln_plain(I)
+ negate_(const Image<I>& input)
+ {
+ oln_plain(I) output;
+ prepare(output, with, input);
+ oln_piter(I) p(input.points());
+ for_all(p)
+ output(p) = value_negate_<oln_value(I)>(input(p));
+ return output;
+ }
+
+ } // end of namespace oln::arith::impl
+
+
+ // Facade.
+
+ template <typename I>
+ oln_plain(I)
+ negate(const Image<I>& input)
+ {
+ return impl::negate_(exact(input));
+ }
+
+
+ } // end of namespace oln::arith
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+#endif // ! OLN_ARITH_NEGATE_HH
Index: oln/canvas/two_pass.hh
--- oln/canvas/two_pass.hh (revision 970)
+++ oln/canvas/two_pass.hh (working copy)
@@ -37,7 +37,7 @@
{
template <template <class> class F,
typename I> // Data owned by f.
- void two_pass(F<I> fun)
+ void two_pass(F<I>& fun)
{
// mlc::assert_< mlc_is_a(I, Image) >::check();
@@ -104,7 +104,7 @@
}
- namespace v4 // Via Inheritens.
+ namespace v4 // Via Inheritance.
{
template <typename I>
1
0
26 Apr '07
cc_tarjan :
---------------------------------------/code
#include <oln/core/2d/image2d.hh>
#include <oln/core/2d/neighb2d.hh>
#include <oln/morpho/cc_tarjan_v4.hh>
int main()
{
using namespace oln;
unsigned N = 128;
image2d<bool> img(N, N);
float tmp;
for (unsigned i = 0; i < N; i++)
for (unsigned j = 0; j < N; j++)
{
tmp = 5 * cos(i) * cos(j);
img.at(i, j) = (tmp > 0) ? tmp : 0;
}
morpho::cc_tarjan(img + c4);
}
---------------------------------------code/
- v0 // Data owned by f.
Compile:
15,76s
Execution:
1,22s
+OPTIM->
Compile:
67,67s
Execution:
0,03s
1024 iter : 1,75s
- v1 // Data owned by f but not input.
Compile:
16,39s
Execution:
1,16s
Execution(optim):
+OPTIM->
Compile:
71,90s
Execution:
0,03s
1024 iter : 1,78s
- v2 // Auxiliar data given as argument.
Compile:
16,35s
Execution:
1,35s
Execution(optim):
+OPTIM->
Compile:
71,96s
Execution:
0,06s
1024 iter : 4,03s
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
cc-tarjan(two_pass) : Fix + Comparative statement : v0, v1, v2.
* tests/algorithms/cc_tarjan_v2.cc: New.
* tests/algorithms/Makefile.am: .
* tests/algorithms/cc_tarjan_v0.cc: New.
* tests/algorithms/cc_tarjan_v1.cc: New.
* oln/core/concept/point.hh: .
* oln/morpho/cc_tarjan_v1.hh: .
* oln/morpho/cc_tarjan_v2.hh: .
* oln/morpho/cc_tarjan_v4.hh: .
* oln/canvas/two_pass.hh: .
oln/canvas/two_pass.hh | 79 +++++++++++++++++++--------------------
oln/core/concept/point.hh | 1
oln/morpho/cc_tarjan_v1.hh | 11 ++---
oln/morpho/cc_tarjan_v2.hh | 14 ++++--
oln/morpho/cc_tarjan_v4.hh | 35 ++++++++++-------
tests/algorithms/Makefile.am | 8 +++
tests/algorithms/cc_tarjan_v0.cc | 24 +++++++++++
tests/algorithms/cc_tarjan_v1.cc | 24 +++++++++++
tests/algorithms/cc_tarjan_v2.cc | 24 +++++++++++
9 files changed, 157 insertions(+), 63 deletions(-)
Index: tests/algorithms/cc_tarjan_v2.cc
--- tests/algorithms/cc_tarjan_v2.cc (revision 0)
+++ tests/algorithms/cc_tarjan_v2.cc (revision 0)
@@ -0,0 +1,24 @@
+#include <oln/core/2d/image2d.hh>
+#include <oln/core/2d/neighb2d.hh>
+
+#include <oln/morpho/cc_tarjan_v0.hh>
+
+int main()
+{
+ using namespace oln;
+
+ unsigned N = 128;
+
+ image2d<bool> img(N, N);
+
+ float tmp;
+
+ for (unsigned i = 0; i < N; i++)
+ for (unsigned j = 0; j < N; j++)
+ {
+ tmp = 5 * cos(i) * cos(j);
+ img.at(i, j) = (tmp > 0) ? tmp : 0;
+ }
+
+ morpho::cc_tarjan(img + c4);
+}
Index: tests/algorithms/Makefile.am
--- tests/algorithms/Makefile.am (revision 969)
+++ tests/algorithms/Makefile.am (working copy)
@@ -25,11 +25,17 @@
check_PROGRAMS = \
fill \
basic_morpho \
- cc_tarjan
+ cc_tarjan \
+ cc_tarjan_v0 \
+ cc_tarjan_v1 \
+ cc_tarjan_v2
# Algorithms.
fill_SOURCES = fill.cc
basic_morpho_SOURCES = basic_morpho.cc
cc_tarjan_SOURCES = cc_tarjan.cc
+cc_tarjan_v0_SOURCES = cc_tarjan_v0.cc
+cc_tarjan_v1_SOURCES = cc_tarjan_v1.cc
+cc_tarjan_v2_SOURCES = cc_tarjan_v2..cc
TESTS = $(check_PROGRAMS)
Index: tests/algorithms/cc_tarjan_v0.cc
--- tests/algorithms/cc_tarjan_v0.cc (revision 0)
+++ tests/algorithms/cc_tarjan_v0.cc (revision 0)
@@ -0,0 +1,24 @@
+#include <oln/core/2d/image2d.hh>
+#include <oln/core/2d/neighb2d.hh>
+
+#include <oln/morpho/cc_tarjan_v0.hh>
+
+int main()
+{
+ using namespace oln;
+
+ unsigned N = 128;
+
+ image2d<bool> img(N, N);
+
+ float tmp;
+
+ for (unsigned i = 0; i < N; i++)
+ for (unsigned j = 0; j < N; j++)
+ {
+ tmp = 5 * cos(i) * cos(j);
+ img.at(i, j) = (tmp > 0) ? tmp : 0;
+ }
+
+ morpho::cc_tarjan(img + c4);
+}
Index: tests/algorithms/cc_tarjan_v1.cc
--- tests/algorithms/cc_tarjan_v1.cc (revision 0)
+++ tests/algorithms/cc_tarjan_v1.cc (revision 0)
@@ -0,0 +1,24 @@
+#include <oln/core/2d/image2d.hh>
+#include <oln/core/2d/neighb2d.hh>
+
+#include <oln/morpho/cc_tarjan_v0.hh>
+
+int main()
+{
+ using namespace oln;
+
+ unsigned N = 128;
+
+ image2d<bool> img(N, N);
+
+ float tmp;
+
+ for (unsigned i = 0; i < N; i++)
+ for (unsigned j = 0; j < N; j++)
+ {
+ tmp = 5 * cos(i) * cos(j);
+ img.at(i, j) = (tmp > 0) ? tmp : 0;
+ }
+
+ morpho::cc_tarjan(img + c4);
+}
Index: oln/core/concept/point.hh
--- oln/core/concept/point.hh (revision 969)
+++ oln/core/concept/point.hh (working copy)
@@ -30,6 +30,7 @@
# define OLN_CORE_CONCEPT_POINT_HH
# include <mlc/value.hh>
+# include <xtd/vec.hh>
# include <oln/core/concept/grid.hh>
# include <oln/core/concept/operators.hh>
Index: oln/morpho/cc_tarjan_v1.hh
--- oln/morpho/cc_tarjan_v1.hh (revision 969)
+++ oln/morpho/cc_tarjan_v1.hh (working copy)
@@ -32,6 +32,7 @@
# include <oln/canvas/two_pass.hh>
# include <oln/level/fill.hh>
+# include <oln/core/internal/f_ch_value.hh>
namespace oln
{
@@ -55,7 +56,7 @@
const I& f;
oln_plain_value(I, unsigned) output;
- oln_plain(I, bool) is_processed;
+ oln_plain_value(I, bool) is_processed;
oln_plain_value(I, point) parent;
cc_tarjan_(const I& f)
@@ -65,9 +66,9 @@
void init()
{
- prepare(is_processed, with, in);
- prepare(output, with, in);
- prepare(parent, with, in);
+ prepare(is_processed, with, f);
+ prepare(output, with, f);
+ prepare(parent, with, f);
level::fill(inplace(is_processed), false);
}
@@ -114,7 +115,7 @@
void do_union(const point& n,
const point& p)
{
- point r = find_root(ima, n, parent);
+ point r = find_root(n);
if (r != p)
parent(r) = p;
}
Index: oln/morpho/cc_tarjan_v2.hh
--- oln/morpho/cc_tarjan_v2.hh (revision 969)
+++ oln/morpho/cc_tarjan_v2.hh (working copy)
@@ -29,6 +29,7 @@
# define OLN_MORPHO_CC_TARJAN_HH
# include <oln/core/concept/image.hh>
+# include <oln/core/internal/f_ch_value.hh>
# include <oln/canvas/two_pass.hh>
# include <oln/level/fill.hh>
@@ -54,9 +55,11 @@
typedef oln_point(I) point;
oln_plain_value(I, unsigned) output;
- oln_plain(I, bool) is_processed;
+ oln_plain_value(I, bool) is_processed;
oln_plain_value(I, point) parent;
+ cc_tarjan_() {}
+
void init(I f)
{
prepare(is_processed, with, f);
@@ -92,6 +95,7 @@
void final(I f)
{
+ f = f;
}
point find_root(const I& ima,
@@ -106,7 +110,9 @@
}
void do_union(const I& ima,
- const point& n)
+ const point& n,
+ const point& p)
+
{
point r = find_root(ima, n);
if (r != p)
@@ -123,8 +129,8 @@
oln_plain_value(I, unsigned)
cc_tarjan(const Image_with_Nbh<I>& f)
{
- impl::cc_tarjan_<I> run(exact(f));
- canvas::v2::two_pass(run, f);
+ impl::cc_tarjan_<I> run;
+ canvas::v2::two_pass(run, exact(f));
return run.output;
}
Index: oln/morpho/cc_tarjan_v4.hh
--- oln/morpho/cc_tarjan_v4.hh (revision 969)
+++ oln/morpho/cc_tarjan_v4.hh (working copy)
@@ -28,6 +28,9 @@
#ifndef OLN_MORPHO_CC_TARJAN_HH
# define OLN_MORPHO_CC_TARJAN_HH
+# include <oln/core/concept/image.hh>
+# include <oln/core/internal/f_ch_value.hh>
+
# include <oln/canvas/two_pass.hh>
# include <oln/level/fill.hh>
@@ -49,7 +52,7 @@
{
template <typename I>
- struct cc_tarjan_ : canvas::v4::two_pass<I>
+ struct cc_tarjan_ : public canvas::v4::two_pass<I>
{
typedef oln_point(I) point;
@@ -57,40 +60,44 @@
oln_plain_value(I, bool) is_processed;
oln_plain_value(I, point) parent;
- void init(I f)
+ cc_tarjan_(const I& img)
{
- prepare(is_processed, with, f);
- prepare(output, with, f);
- prepare(parent, with, f);
+ }
+
+ void init()
+ {
+ prepare(is_processed, with, this.f);
+ prepare(output, with, this.f);
+ prepare(parent, with, this.f);
level::fill(inplace(is_processed), false);
}
- void first_pass_body(const point& p, I f)
+ void first_pass_body(const point& p)
{
parent(p) = p;
if ( f(p) )
{
- oln_niter(I) n(f, p);
+ oln_niter(I) n(this.f, p);
for_all(n)
{
- if ( f(n) == true and is_processed(n) )
- do_union(f, n, p);
+ if ( this.f(n) == true and is_processed(n) )
+ do_union(this.f, n, p);
}
is_processed(p) = true;
}
}
- void second_pass_body(const point& p, I f)
+ void second_pass_body(const point& p)
{
unsigned current_label = 0;
- if ( f(p) == true and parent(p) == p )
+ if ( this.f(p) == true and parent(p) == p )
output(p) = ++current_label;
else
output(p) = output(parent(p));
}
- void final(I f)
+ void final()
{
}
@@ -129,7 +136,9 @@
{
impl::cc_tarjan_<I> f_cc_tarjan(exact(f));
- return f_cc_tarjan.run();
+ f_cc_tarjan.run();
+
+ return f_cc_tarjan.output;
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/canvas/two_pass.hh
--- oln/canvas/two_pass.hh (revision 969)
+++ oln/canvas/two_pass.hh (working copy)
@@ -37,69 +37,69 @@
{
template <template <class> class F,
typename I> // Data owned by f.
- void two_pass(F<I> f)
+ void two_pass(F<I> fun)
{
// mlc::assert_< mlc_is_a(I, Image) >::check();
- f.init();
+ fun.init();
// first pass
- oln_bkd_piter(I) p1(f.input.points());
+ oln_bkd_piter(I) p1(fun.f.points());
for_all(p1)
- f.first_pass_body(p1);
+ fun.first_pass_body(p1);
// second pass
- oln_fwd_piter(I) p2(f.input.points());
+ oln_fwd_piter(I) p2(fun.f.points());
for_all(p2)
- f.second_pass_body(p2);
+ fun.second_pass_body(p2);
- f.final();
+ fun.final();
}
}
- namespace v2 // Data owned by f but not input
+ namespace v2 // Data owned by f but not input.
{
template <typename F, typename I>
- void two_pass(F f, I input)
+ void two_pass(F fun, I f)
{
// mlc::assert_< mlc_is_a(I, Image) >::check();
- f.init(input);
+ fun.init(f);
// first pass
- oln_bkd_piter(I) p1(input.points());
+ oln_bkd_piter(I) p1(f.points());
for_all(p1)
- f.first_pass_body(p1, input);
+ fun.first_pass_body(p1, f);
// second pass
- oln_fwd_piter(I) p2(input.points());
+ oln_fwd_piter(I) p2(f.points());
for_all(p2)
- f.second_pass_body(p2, input);
+ fun.second_pass_body(p2, f);
- f.final(input);
+ fun.final(f);
}
}
namespace v3 // Auxiliar data given as argument.
{
template <typename F, typename I, typename A>
- void two_pass(F f, I input, A aux)
+ void two_pass(F fun, I f, A aux)
{
// mlc::assert_< mlc_is_a(I, Image) >::check();
- f.init(input, aux);
+ f.init(f, aux);
// first pass
- oln_bkd_piter(I) p1(input.points());
+ oln_bkd_piter(I) p1(f.points());
for_all(p1)
- f.first_pass_body(p1, input, aux);
+ f.first_pass_body(p1, f, aux);
// second pass
- oln_fwd_piter(I) p2(input.points());
+ oln_fwd_piter(I) p2(f.points());
for_all(p2)
- f.second_pass_body(p2, input, aux);
+ f.second_pass_body(p2, f, aux);
- f.final(input, aux);
+ f.final(f, aux);
}
}
@@ -108,38 +108,37 @@
{
template <typename I>
- class two_pass
+ struct two_pass
{
- void init(I input) { }
+ const I& f;
- void final(I input) { }
- void first_pass_body(const oln_point(I)& p)
- {
- assert (0 && "two_pass canvas : procedure 'void first_pass_body(const oln_point(I)& p)' must be defined");
- }
- void second_pass_body(const oln_point(I)& p)
- {
- assert (0 && "two_pass canvas : procedure 'void second_pass_body(const oln_point(I)& p)' must be defined");
- }
+ void init();
- void run(I input)
+ void final();
+
+ void first_pass_body(const oln_point(I)& p);
+
+ void second_pass_body(const oln_point(I)& p);
+
+ void run()
{
- init(input);
+ init(f);
// first pass
- oln_bkd_piter(I) p1(input.points());
+ oln_bkd_piter(I) p1(f.points());
for_all(p1)
- first_pass_body(p1, input);
+ first_pass_body(p1);
// second pass
- oln_fwd_piter(I) p2(input.points());
+ oln_fwd_piter(I) p2(f.points());
for_all(p2)
- second_pass_body(p2, input);
+ second_pass_body(p2);
+
+ final(f);
- final(input);
}
};
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Introduce zero and update some traits and ops.
* oln/convert/to_dpoint.hh: New.
* oln/core/gen/zero.hh: New.
* oln/core/concept/literal.hh: New.
* tests/core/pw_value.cc,
* oln/core/gen/over.hh,
* oln/convert/to_weighted_window.hh,
* oln/draw/bresenham.hh,
* oln/morpho/elementary_gradient.hh,
* oln/morpho/elementary_gradient_external.hh,
* oln/morpho/gradient_internal.hh,
* oln/morpho/top_hat_black.hh,
* oln/morpho/gradient.hh,
* oln/morpho/top_hat_white.hh,
* oln/morpho/gradient_external.hh,
* oln/morpho/elementary_gradient_internal.hh,
* oln/level/compare.hh,
* oln/linear/convolution.hh,
* oln/linear/mean.hh: Update.
* oln/core/gen/traits.hh
(oln_internal_specialize_un_trait_T_): New.
(clean_for_trait_): New specializations.
* oln/core/gen/value.hh (set_trait_): Remove.
* oln/core/gen/such_as.hh: Add reminder.
* oln/core/concept/iterator_on_points.hh
(set_trait_): New specializations.
* oln/core/concept/point.hh (assign_): New.
(operator): Fix.
* oln/core/concept/dpoint.hh: Likewise.
* oln/core/concept/window.hh (op_unary_minus_): Change into...
(operator-): ...this.
* oln/core/concept/operators.hh: Fix.
* oln/core/internal/dpoint_base.hh
(impl_op_equal_),
(impl_op_mod_equal_),
(impl_op_less_),
(impl_op_plus_equal_),
(impl_op_minus_equal_),
(impl_op_mod_equal_),
(impl_op_unary_minus_): Rmove; obsolete.
* oln/value/builtin.hh (super_trait_): New ones.
* oln/value/builtin_traits.hh (set_trait_): New one.
oln/convert/to_dpoint.hh | 67 +++++++++++++++++++++
oln/convert/to_weighted_window.hh | 4 -
oln/core/concept/dpoint.hh | 14 +++-
oln/core/concept/iterator_on_points.hh | 16 +++++
oln/core/concept/literal.hh | 88 ++++++++++++++++++++++++++++
oln/core/concept/operators.hh | 18 +----
oln/core/concept/point.hh | 23 +++++--
oln/core/concept/window.hh | 17 ++---
oln/core/gen/over.hh | 15 ++--
oln/core/gen/such_as.hh | 7 ++
oln/core/gen/traits.hh | 52 ++++++++++++++--
oln/core/gen/value.hh | 8 --
oln/core/gen/zero.hh | 91 +++++++++++++++++++++++++++++
oln/core/internal/dpoint_base.hh | 44 --------------
oln/draw/bresenham.hh | 2
oln/level/compare.hh | 19 ++----
oln/linear/convolution.hh | 13 +---
oln/linear/mean.hh | 6 -
oln/morpho/elementary_gradient.hh | 3
oln/morpho/elementary_gradient_external.hh | 3
oln/morpho/elementary_gradient_internal.hh | 3
oln/morpho/gradient.hh | 3
oln/morpho/gradient_external.hh | 3
oln/morpho/gradient_internal.hh | 3
oln/morpho/top_hat_black.hh | 3
oln/morpho/top_hat_white.hh | 3
oln/value/builtin.hh | 14 ++++
oln/value/builtin_traits.hh | 6 +
tests/core/pw_value.cc | 2
29 files changed, 423 insertions(+), 127 deletions(-)
Index: tests/core/pw_value.cc
--- tests/core/pw_value.cc (revision 968)
+++ tests/core/pw_value.cc (working copy)
@@ -45,6 +45,6 @@
image2d<double> ima2(3,3);
ima2(p) = 2.3;
- double d = ((pw_value(ima1) + pw_value(ima2) * literal(4.)) / literal(.2))(p);
+ double d = ((pw_value(ima1) + pw_value(ima2) * 4.) / .2)(p);
assert(d > 50.9999 and d < 51.0001);
}
Index: oln/convert/to_weighted_window.hh
--- oln/convert/to_weighted_window.hh (revision 968)
+++ oln/convert/to_weighted_window.hh (working copy)
@@ -28,6 +28,7 @@
#ifndef OLN_CONVERT_TO_WEIGHTED_WINDOW_HH
# define OLN_CONVERT_TO_WEIGHTED_WINDOW_HH
+# include <oln/core/gen/zero.hh>
# include <oln/core/concept/image.hh>
# include <oln/core/concept/window.hh>
# include <oln/core/concept/function.hh>
@@ -61,11 +62,10 @@
oln_f_image_to_weighted_window(I)
to_weighted_window(const Image<I>& input)
{
- oln_point(I) O; O.set_all(0);
oln_f_image_to_weighted_window(I) output;
oln_piter(I) p(input.points());
for_all(p)
- output.take(input(p), O - oln_point(I)(p)); // FIXME: replace to_point by zero - p
+ output.take(input(p), zero - oln_point(I)(p));
return output;
}
Index: oln/convert/to_dpoint.hh
--- oln/convert/to_dpoint.hh (revision 0)
+++ oln/convert/to_dpoint.hh (revision 0)
@@ -0,0 +1,67 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_CONVERT_TO_DPOINT_HH
+# define OLN_CONVERT_TO_DPOINT_HH
+
+# include <oln/core/concept/point.hh>
+
+
+namespace oln
+{
+
+ namespace convert
+ {
+
+ // Fwd decl.
+
+ template <typename P>
+ oln_dpoint(P)
+ to_dpoint(const Generalized_Point<P>& p);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ // Generic version.
+
+ template <typename P>
+ oln_dpoint(P)
+ to_dpoint(const Generalized_Point<P>& p)
+ {
+ oln_dpoint(P) tmp;
+ tmp.vec() = exact(p).vec();
+ return tmp;
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::convert
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CONVERT_TO_DPOINT_HH
Index: oln/core/gen/traits.hh
--- oln/core/gen/traits.hh (revision 968)
+++ oln/core/gen/traits.hh (working copy)
@@ -115,6 +115,15 @@
}
+# define oln_internal_specialize_un_trait_T_(Name) \
+ \
+ template <typename T> \
+ struct set_utrait_< Name##_id, Any, T > \
+ { \
+ typedef T ret; \
+ }
+
+
namespace oln
@@ -146,6 +155,18 @@
};
+ // "absorbing" a literal:
+ template <typename L> struct Literal; // Fwd decl
+ template <typename L, typename Op, template <class> class C, typename R>
+ struct set_trait_<Literal, L, Op, C, R>
+ : public set_trait_<C, R, Op, C, R>
+ {};
+ template <template <class> class C, typename L, typename Op, typename R>
+ struct set_trait_<C, L, Op, Literal, R>
+ : public set_trait_<C, L, Op, C, L>
+ {};
+
+
// set_utrait_ for unary operators.
@@ -209,6 +230,8 @@
oln_internal_specialize_bin_trait_T_(div);
oln_internal_specialize_bin_trait_T_(mod);
+ oln_internal_specialize_un_trait_T_(uminus);
+
oln_internal_specialize_bin_trait_bool_(eq);
oln_internal_specialize_bin_trait_bool_(neq);
@@ -221,6 +244,8 @@
oln_internal_specialize_bin_trait_T_(or);
oln_internal_specialize_bin_trait_T_(xor);
+ oln_internal_specialize_un_trait_T_(not);
+
// Fwd decl.
template <typename T> struct value_;
@@ -259,17 +284,30 @@
template <typename T>
struct clean_for_trait_
{
- typedef T ret;
+ typedef T ret; // default is identity
};
template <typename T>
- struct clean_for_trait_< const oln::value_<T> > { typedef T ret; };
+ struct clean_for_trait_< T& >
+ {
+ // remove &
+ typedef typename clean_for_trait_<T>::ret ret;
+ };
+
template <typename T>
- struct clean_for_trait_< const oln::value_<T>& > { typedef T ret; };
+ struct clean_for_trait_< const oln::value_<T> > { typedef T ret; };
template <typename T>
- struct clean_for_trait_< oln::value_<T>& > { typedef T ret; };
+ struct clean_for_trait_< oln::value_<T> > { typedef T ret; };
- // FIXME: Add clean_for_trait_ for builtins?
+ // builtins
+ template <> struct clean_for_trait_< const unsigned > { typedef unsigned ret; };
+ template <> struct clean_for_trait_< unsigned > { typedef unsigned ret; };
+ template <> struct clean_for_trait_< const int > { typedef int ret; };
+ template <> struct clean_for_trait_< int > { typedef int ret; };
+ template <> struct clean_for_trait_< const float > { typedef float ret; };
+ template <> struct clean_for_trait_< float > { typedef float ret; };
+ template <> struct clean_for_trait_< const double > { typedef double ret; };
+ template <> struct clean_for_trait_< double > { typedef double ret; };
} // end of namespace oln::internal
@@ -284,7 +322,9 @@
};
template <typename Op, typename T>
- struct get_utrait_ : public internal::get_utrait_cat__< Op, oln_category_of_(T), T >
+ struct get_utrait_ : public internal::get_utrait_cat__< Op,
+ oln_category_of_(T),
+ typename internal::clean_for_trait_<T>::ret >
{
};
Index: oln/core/gen/such_as.hh
--- oln/core/gen/such_as.hh (revision 968)
+++ oln/core/gen/such_as.hh (working copy)
@@ -60,6 +60,13 @@
// Image | Function_p2b
+ // FIXME: Do it!
+// template <typename I, typename F>
+// set_trait_< Image, I, pipe_id, Function_p2b, F >
+// {
+// typedef op_<I, such_as, F> ret;
+// };
+
template <typename I, typename F>
op_<const I, such_as, const F>
operator | (const Image<I>& ima, const Function_p2b<F>& f);
Index: oln/core/gen/over.hh
--- oln/core/gen/over.hh (revision 968)
+++ oln/core/gen/over.hh (working copy)
@@ -37,7 +37,8 @@
# include <oln/core/internal/op_fp2v_over_pset.hh>
# include <oln/core/gen/fun.hh>
-# include <oln/core/gen/literal.hh>
+# include <oln/core/gen/constant.hh>
+# include <oln/core/gen/value.hh>
namespace oln
@@ -60,8 +61,8 @@
// V / Point_Set
template <typename V, typename S>
- op_<const lit_p2v_<oln_point(S), V>, over, const S>
- operator / (const literal_<V>& value, const Point_Set<S>& pset);
+ op_<const constant_p2v_<oln_point(S), V>, over, const S>
+ operator / (const value_<V>& v, const Point_Set<S>& pset);
@@ -92,11 +93,11 @@
// V / Point_Set
template <typename V, typename S>
- op_<const lit_p2v_<oln_point(S), V>, over, const S>
- operator / (const literal_<V>& value, const Point_Set<S>& pset)
+ op_<const constant_p2v_<oln_point(S), V>, over, const S>
+ operator / (const value_<V>& v, const Point_Set<S>& pset)
{
- lit_p2v_<oln_point(S), V> lit(value);
- op_<const lit_p2v_<oln_point(S), V>, over, const S> tmp(lit, exact(pset));
+ constant_p2v_<oln_point(S), V> v_(v);
+ op_<const constant_p2v_<oln_point(S), V>, over, const S> tmp(v_, exact(pset));
return tmp;
}
Index: oln/core/gen/value.hh
--- oln/core/gen/value.hh (revision 968)
+++ oln/core/gen/value.hh (working copy)
@@ -93,14 +93,6 @@
value_<T> make_value(const value_<T>& val);
- // traits
-
- template <typename L, typename Op, typename R>
- struct set_trait_< Value, value_<L>, Op, Value, value_<R> >
- {
- typedef typename get_trait_<L, Op, R>::ret ret;
- };
-
# ifndef OLN_INCLUDE_ONLY
Index: oln/core/gen/zero.hh
--- oln/core/gen/zero.hh (revision 0)
+++ oln/core/gen/zero.hh (revision 0)
@@ -0,0 +1,91 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_CORE_GEN_ZERO_HH
+# define OLN_CORE_GEN_ZERO_HH
+
+# include <oln/core/concept/literal.hh>
+
+
+namespace oln
+{
+
+ struct zero_t : public Literal< zero_t >
+ {
+
+ template <typename T>
+ operator T() const;
+
+ // builtins:
+ operator unsigned() const;
+ operator int() const;
+ operator float() const;
+ operator double() const;
+ }
+
+ zero;
+
+
+
+ // Default unary minus operator.
+
+ template <typename T>
+ T
+ operator - (const Any<T>& rhs); // Use binary -.
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename T>
+ zero_t::operator T() const
+ {
+ mlc::assert_< mlc_is_a(T, Any) >::check(); // FIXME: Add err msg.
+ T tmp;
+ tmp.assign_(*this);
+ return tmp;
+ }
+
+ zero_t::operator unsigned() const { return 0u; }
+ zero_t::operator int() const { return 0; }
+ zero_t::operator float() const { return 0.f; }
+ zero_t::operator double() const { return 0.; }
+
+
+ template <typename T>
+ T
+ operator - (const Any<T>& rhs)
+ {
+ return zero - exact(rhs);
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_GEN_ZERO_HH
Index: oln/core/concept/iterator_on_points.hh
--- oln/core/concept/iterator_on_points.hh (revision 968)
+++ oln/core/concept/iterator_on_points.hh (working copy)
@@ -99,6 +99,22 @@
typedef oln_minus_trait(Pit1, Pit2) ret;
};
+ template <typename Exact> struct Dpoint; // Fwd decl.
+
+ template <typename It, typename D>
+ struct set_trait_< Iterator_on_Points, It, plus_id, Dpoint, D >
+ {
+ typedef oln_point(It) P;
+ typedef oln_plus_trait(P, D) ret;
+ };
+
+ template <typename It, typename D>
+ struct set_trait_< Iterator_on_Points, It, minus_id, Dpoint, D >
+ {
+ typedef oln_point(It) P;
+ typedef oln_minus_trait(P, D) ret;
+ };
+
// \}
Index: oln/core/concept/point.hh
--- oln/core/concept/point.hh (revision 968)
+++ oln/core/concept/point.hh (working copy)
@@ -33,6 +33,7 @@
# include <oln/core/concept/grid.hh>
# include <oln/core/concept/operators.hh>
+# include <oln/core/gen/zero.hh>
@@ -116,6 +117,9 @@
template <typename Exact>
struct Point : public Generalized_Point<Exact>
{
+
+ void assign_(zero_t);
+
protected:
Point();
@@ -171,6 +175,13 @@
{
}
+ template <typename Exact>
+ void
+ Point<Exact>::assign_(zero_t)
+ {
+ exact(this)->vec().set_all(0);
+ }
+
template <typename P>
oln_minus_trait(P, P)
operator - (const Generalized_Point<P>& lhs, const Generalized_Point<P>& rhs)
@@ -191,9 +202,10 @@
bool
operator < (const Generalized_Point<P1>& lhs, const Generalized_Point<P2>& rhs)
{
- return exact(lhs).vec() < exact(rhs).vec();
+ return xtd::lexi_less(exact(lhs).vec(), exact(rhs).vec());
}
+
// Invalid operators.
template <typename P1, typename P2>
@@ -201,7 +213,7 @@
const Generalized_Point<P2>& rhs)
{
mlc::abort_<P1,
- ERROR::operator_< plus_id >::template _is_invalid_for_types_<P1, P2>
+ typename ERROR::operator_< plus_id >::template _is_invalid_for_types_<P1, P2>
>::check();
}
@@ -210,7 +222,7 @@
const Generalized_Point<P2>& rhs)
{
mlc::abort_<P1,
- ERROR::operator_< plus_equal_id >::template _is_invalid_for_types_<P1, P2>
+ typename ERROR::operator_< plus_equal_id >::template _is_invalid_for_types_<P1, P2>
>::check();
}
@@ -219,7 +231,7 @@
const Generalized_Point<P2>& rhs)
{
mlc::abort_<P1,
- ERROR::operator_< minus_equal_id >::template _is_invalid_for_types_<P1, P2>
+ typename ERROR::operator_< minus_equal_id >::template _is_invalid_for_types_<P1, P2>
>::check();
}
@@ -227,7 +239,7 @@
void operator - (const Generalized_Point<P>& rhs)
{
mlc::abort_<P,
- ERROR::operator_< uminus_id >::template _is_invalid_for_<P>
+ typename ERROR::operator_< uminus_id >::template _is_invalid_for_<P>
>::check();
}
@@ -260,4 +272,5 @@
} // end of namespace oln
+
#endif // ! OLN_CORE_CONCEPT_POINT_HH
Index: oln/core/concept/literal.hh
--- oln/core/concept/literal.hh (revision 0)
+++ oln/core/concept/literal.hh (revision 0)
@@ -0,0 +1,88 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_CORE_CONCEPT_LITERAL_HH
+# define OLN_CORE_CONCEPT_LITERAL_HH
+
+# include <oln/core/concept/operators.hh>
+
+
+namespace oln
+{
+
+ /// Concept-class "Literal".
+
+ template <typename Exact>
+ struct Literal : public Any<Exact>
+ {
+ typedef Literal<void> category;
+ protected:
+ Literal();
+ };
+
+
+ // Default.
+
+ template <typename L, typename R>
+ oln_minus_trait(R, R)
+ operator - (const Literal<L>& lhs, const Any<R>& rhs);
+
+ template <typename L, typename R>
+ oln_plus_trait(R, R)
+ operator + (const Literal<L>& lhs, const Any<R>& rhs);
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename Exact>
+ Literal<Exact>::Literal()
+ {
+ }
+
+ template <typename L, typename R>
+ oln_minus_trait(R, R)
+ operator - (const Literal<L>& lhs, const Any<R>& rhs)
+ {
+ oln_minus_trait(R, R) tmp = exact(lhs).operator R() - exact(rhs);
+ return tmp;
+ }
+
+ template <typename L, typename R>
+ oln_plus_trait(R, R)
+ operator + (const Literal<L>& lhs, const Any<R>& rhs)
+ {
+ oln_plus_trait(R, R) tmp = exact(lhs).operator R() + exact(rhs);
+ return tmp;
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_CONCEPT_LITERAL_HH
Index: oln/core/concept/dpoint.hh
--- oln/core/concept/dpoint.hh (revision 968)
+++ oln/core/concept/dpoint.hh (working copy)
@@ -59,6 +59,8 @@
enum { n = mlc_value(dim) };
+ void assign_(zero_t);
+
protected:
Dpoint();
@@ -144,6 +146,12 @@
// mlc::assert_defined_< oln_vtype(Exact, dim) >::check();
}
+ template <typename Exact>
+ void
+ Dpoint<Exact>::assign_(zero_t)
+ {
+ exact(this)->vec().set_all(0);
+ }
// Operators on Dpoints.
@@ -156,7 +164,7 @@
template <typename D1, typename D2>
bool operator < (const Dpoint<D1>& lhs, const Dpoint<D2>& rhs)
{
- return exact(lhs).vec() < exact(rhs).vec();
+ return xtd::lexi_less(exact(lhs).vec(), exact(rhs).vec());
}
template <typename D, typename D2>
@@ -230,7 +238,7 @@
void operator + (const Dpoint<D>& lhs, const Generalized_Point<P>& rhs)
{
mlc::abort_<D,
- ERROR::operator_< plus_id >::template _is_invalid_for_types_<D, P>
+ typename ERROR::operator_< plus_id >::template _is_invalid_for_types_<D, P>
>::check();
}
@@ -238,7 +246,7 @@
void operator - (const Dpoint<D>& lhs, const Generalized_Point<P>& rhs)
{
mlc::abort_<D,
- ERROR::operator_< minus_id >::template _is_invalid_for_types_<D, P>
+ typename ERROR::operator_< minus_id >::template _is_invalid_for_types_<D, P>
>::check();
}
Index: oln/core/concept/window.hh
--- oln/core/concept/window.hh (revision 968)
+++ oln/core/concept/window.hh (working copy)
@@ -47,7 +47,6 @@
stc_typename(fwd_qiter);
stc_typename(bkd_qiter);
- Exact op_unary_minus_() const;
unsigned size() const;
protected:
@@ -56,6 +55,9 @@
}; // end of oln::Window<Exact>
+ template <typename W>
+ W operator - (const Window<W>& rhs);
+
# ifndef OLN_INCLUDE_ONLY
@@ -65,19 +67,18 @@
}
template <typename Exact>
- Exact
- Window<Exact>::op_unary_minus_() const
- {
- return exact(this)->impl_op_unary_minus_();
- }
-
- template <typename Exact>
unsigned
Window<Exact>::size() const
{
return exact(this)->impl_size();
}
+ template <typename W>
+ W operator - (const Window<W>& rhs)
+ {
+ return exact(rhs).impl_op_unary_minus_();
+ }
+
# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/concept/operators.hh
--- oln/core/concept/operators.hh (revision 968)
+++ oln/core/concept/operators.hh (working copy)
@@ -70,12 +70,6 @@
-
- // FIXME: Add: template <typename T> T operator - (const Any<T>& rhs);
-
-
-
-
namespace ERROR
{
@@ -184,7 +178,7 @@
void operator = (const Any<L>& lhs, const Any<R>& rhs)
{
mlc::abort_<L,
- ERROR::operator_< eq_id >::template _is_missing_for_types_<L, R>
+ typename ERROR::operator_< eq_id >::_is_missing_for_types_<L, R>
>::check();
}
@@ -193,7 +187,7 @@
void operator < (const Any<L>& lhs, const Any<R>& rhs)
{
mlc::abort_<L,
- ERROR::operator_< less_id >::template _is_missing_for_types_<L, R>
+ typename ERROR::operator_< less_id >::template _is_missing_for_types_<L, R>
>::check();
}
@@ -202,7 +196,7 @@
void operator += (const Any<L>& lhs, const Any<R>& rhs)
{
mlc::abort_<L,
- ERROR::operator_< plus_equal_id >::template _is_missing_for_types_<L, R>
+ typename ERROR::operator_< plus_equal_id >::template _is_missing_for_types_<L, R>
>::check();
}
@@ -211,7 +205,7 @@
void operator -= (const Any<L>& lhs, const Any<R>& rhs)
{
mlc::abort_<L,
- ERROR::operator_< minus_equal_id >::template _is_missing_for_types_<L, R>
+ typename ERROR::operator_< minus_equal_id >::template _is_missing_for_types_<L, R>
>::check();
}
@@ -220,7 +214,7 @@
void operator %= (const Any<L>& lhs, const Any<R>& rhs)
{
mlc::abort_<L,
- ERROR::operator_< modulus_equal_id >::template _is_missing_for_types_<L, R>
+ typename ERROR::operator_< modulus_equal_id >::template _is_missing_for_types_<L, R>
>::check();
}
@@ -229,7 +223,7 @@
void operator - (const Any<T>& rhs)
{
mlc::abort_<T,
- ERROR::operator_< uminus_id >::template _is_missing_for_<T>
+ typename ERROR::operator_< uminus_id >::template _is_missing_for_<T>
>::check();
}
Index: oln/core/internal/dpoint_base.hh
--- oln/core/internal/dpoint_base.hh (revision 968)
+++ oln/core/internal/dpoint_base.hh (working copy)
@@ -85,15 +85,7 @@
coord operator[](unsigned i) const;
coord& operator[](unsigned i);
- bool impl_op_equal_(const Exact& rhs) const;
-
- bool impl_op_less_(const Exact& rhs) const;
-
- Exact& impl_op_plus_equal_(const Exact& rhs);
- Exact& impl_op_minus_equal_(const Exact& rhs);
- Exact& impl_op_mod_equal_(const Exact& rhs);
-
- Exact impl_op_unary_minus_() const;
+ Exact& impl_op_mod_equal_(const Exact& rhs); // FIXME: Remove HERE
typedef xtd::vec<n, coord> vec_t;
const vec_t& vec() const;
@@ -126,32 +118,6 @@
}
template <typename Exact>
- bool dpoint_base_<Exact>::impl_op_equal_(const Exact& rhs) const
- {
- return v_ = rhs.v_;
- }
-
- template <typename Exact>
- bool dpoint_base_<Exact>::impl_op_less_(const Exact& rhs) const
- {
- return xtd::lexi_less(v_, rhs.v_);
- }
-
- template <typename Exact>
- Exact& dpoint_base_<Exact>::impl_op_plus_equal_(const Exact& rhs)
- {
- v_ += rhs.v_;
- return exact(*this);
- }
-
- template <typename Exact>
- Exact& dpoint_base_<Exact>::impl_op_minus_equal_(const Exact& rhs)
- {
- v_ -= rhs.v_;
- return exact(*this);
- }
-
- template <typename Exact>
Exact& dpoint_base_<Exact>::impl_op_mod_equal_(const Exact& rhs)
{
for (unsigned i = 0; i < n; ++i)
@@ -164,14 +130,6 @@
}
template <typename Exact>
- Exact dpoint_base_<Exact>::impl_op_unary_minus_() const
- {
- Exact tmp;
- tmp.v_ = - v_;
- return tmp;
- }
-
- template <typename Exact>
const typename dpoint_base_<Exact>::vec_t&
dpoint_base_<Exact>::vec() const
{
Index: oln/draw/bresenham.hh
--- oln/draw/bresenham.hh (revision 968)
+++ oln/draw/bresenham.hh (working copy)
@@ -61,7 +61,7 @@
const oln_point(I)& begin, const oln_point(I)& end,
const oln_value(I)& value)
{
- level::paste(literal(value) / line2d(begin, end),
+ level::paste(make_value(value) / line2d(begin, end),
inplace(in_out));
}
Index: oln/morpho/elementary_gradient.hh
--- oln/morpho/elementary_gradient.hh (revision 968)
+++ oln/morpho/elementary_gradient.hh (working copy)
@@ -28,6 +28,7 @@
#ifndef OLN_MORPHO_ELEMENTARY_GRADIENT_HH
# define OLN_MORPHO_ELEMENTARY_GRADIENT_HH
+# include <oln/core/gen/zero.hh>
# include <oln/morpho/elementary_erosion.hh>
# include <oln/morpho/elementary_dilation.hh>
# include <oln/arith/minus.hh>
@@ -75,7 +76,7 @@
elementary_gradient(const Image_with_Nbh<I>& input)
{
oln_plain(I) output = impl::elementary_gradient_(exact(input));
- postcondition(output >= literal(0));
+ postcondition(output >= zero);
return output;
}
Index: oln/morpho/elementary_gradient_external.hh
--- oln/morpho/elementary_gradient_external.hh (revision 968)
+++ oln/morpho/elementary_gradient_external.hh (working copy)
@@ -28,6 +28,7 @@
#ifndef OLN_MORPHO_EXTERNAL_GRADIENT_HH
# define OLN_MORPHO_EXTERNAL_GRADIENT_HH
+# include <oln/core/gen/zero.hh>
# include <oln/morpho/elementary_dilation.hh>
# include <oln/arith/minus.hh>
@@ -73,7 +74,7 @@
elementary_gradient_external(const Image_with_Nbh<I>& input)
{
oln_plain(I) output = impl::elementary_gradient_external_(exact(input));
- postcondition(output >= literal(0));
+ postcondition(output >= zero);
return output;
}
Index: oln/morpho/gradient_internal.hh
--- oln/morpho/gradient_internal.hh (revision 968)
+++ oln/morpho/gradient_internal.hh (working copy)
@@ -28,6 +28,7 @@
#ifndef OLN_MORPHO_GRADIENT_INTERNAL_HH
# define OLN_MORPHO_GRADIENT_INTERNAL_HH
+# include <oln/core/gen/zero.hh>
# include <oln/morpho/erosion.hh>
# include <oln/arith/minus.hh>
@@ -72,7 +73,7 @@
gradient_internal(const Image<I>& input, const Window<W>& win)
{
oln_plain(I) output = impl::gradient_internal_(exact(input), exact(win));
- postcondition(output >= literal(0));
+ postcondition(output >= zero);
return output;
}
Index: oln/morpho/top_hat_black.hh
--- oln/morpho/top_hat_black.hh (revision 968)
+++ oln/morpho/top_hat_black.hh (working copy)
@@ -28,6 +28,7 @@
#ifndef OLN_MORPHO_TOP_HAT_BLACK_HH
# define OLN_MORPHO_TOP_HAT_BLACK_HH
+# include <oln/core/gen/zero.hh>
# include <oln/morpho/opening.hh>
# include <oln/morpho/closing.hh>
# include <oln/arith/minus.hh>
@@ -74,7 +75,7 @@
top_hat_black(const Image<I>& input, const Window<W>& win)
{
oln_plain(I) output = impl::top_hat_black_(exact(input), exact(win));
- postcondition(output >= literal(0));
+ postcondition(output >= zero);
return output;
}
Index: oln/morpho/gradient.hh
--- oln/morpho/gradient.hh (revision 968)
+++ oln/morpho/gradient.hh (working copy)
@@ -28,6 +28,7 @@
#ifndef OLN_MORPHO_GRADIENT_HH
# define OLN_MORPHO_GRADIENT_HH
+# include <oln/core/gen/zero.hh>
# include <oln/morpho/erosion.hh>
# include <oln/morpho/dilation.hh>
# include <oln/arith/minus.hh>
@@ -73,7 +74,7 @@
gradient(const Image<I>& input, const Window<W>& win)
{
oln_plain(I) output = impl::gradient_(exact(input), exact(win));
- postcondition(output >= literal(0));
+ postcondition(output >= zero);
return output;
}
Index: oln/morpho/top_hat_white.hh
--- oln/morpho/top_hat_white.hh (revision 968)
+++ oln/morpho/top_hat_white.hh (working copy)
@@ -28,6 +28,7 @@
#ifndef OLN_MORPHO_TOP_HAT_WHITE_HH
# define OLN_MORPHO_TOP_HAT_WHITE_HH
+# include <oln/core/gen/zero.hh>
# include <oln/morpho/opening.hh>
# include <oln/morpho/closing.hh>
# include <oln/arith/minus.hh>
@@ -73,7 +74,7 @@
top_hat_white(const Image<I>& input, const Window<W>& win)
{
oln_plain(I) output = impl::top_hat_white_(exact(input), exact(win));
- postcondition(output >= literal(0));
+ postcondition(output >= zero);
return output;
}
Index: oln/morpho/gradient_external.hh
--- oln/morpho/gradient_external.hh (revision 968)
+++ oln/morpho/gradient_external.hh (working copy)
@@ -28,6 +28,7 @@
#ifndef OLN_MORPHO_GRADIENT_EXTERNAL_HH
# define OLN_MORPHO_GRADIENT_EXTERNAL_HH
+# include <oln/core/gen/zero.hh>
# include <oln/morpho/dilation.hh>
# include <oln/arith/minus.hh>
@@ -71,7 +72,7 @@
gradient_external(const Image<I>& input, const Window<W>& win)
{
oln_plain(I) output = impl::gradient_external_(exact(input), exact(win));
- postcondition(output >= literal(0));
+ postcondition(output >= zero);
return output;
}
Index: oln/morpho/elementary_gradient_internal.hh
--- oln/morpho/elementary_gradient_internal.hh (revision 968)
+++ oln/morpho/elementary_gradient_internal.hh (working copy)
@@ -28,6 +28,7 @@
#ifndef OLN_MORPHO_ELEMENTARY_GRADIENT_INTERNAL_HH
# define OLN_MORPHO_ELEMENTARY_GRADIENT_INTERNAL_HH
+# include <oln/core/gen/zero.hh>
# include <oln/morpho/elementary_erosion.hh>
# include <oln/arith/minus.hh>
@@ -73,7 +74,7 @@
elementary_gradient_internal(const Image_with_Nbh<I>& input)
{
oln_plain(I) output = impl::elementary_gradient_internal_(exact(input));
- postcondition(output >= literal(0));
+ postcondition(output >= zero);
return output;
}
Index: oln/level/compare.hh
--- oln/level/compare.hh (revision 968)
+++ oln/level/compare.hh (working copy)
@@ -30,7 +30,6 @@
# include <oln/core/concept/image.hh>
# include <oln/core/gen/pset_compare.hh>
-# include <oln/core/gen/literal.hh>
// FIXME: Rename this file as "comparison.hh".
@@ -45,19 +44,19 @@
bool operator = (const Image<L>& lhs, const Image<R>& rhs);
template <typename I>
- bool operator = (const Image<I>& lhs, const literal_<oln_value(I)>& val);
+ bool operator = (const Image<I>& lhs, const oln_value(I)& val);
template <typename L, typename R>
bool operator < (const Image<L>& lhs, const Image<R>& rhs);
template <typename I>
- bool operator < (const Image<I>& lhs, const literal_<oln_value(I)>& val);
+ bool operator < (const Image<I>& lhs, const oln_value(I)& val);
template <typename L, typename R>
bool operator <= (const Image<L>& lhs, const Image<R>& rhs);
template <typename I>
- bool operator <= (const Image<I>& lhs, const literal_<oln_value(I)>& val);
+ bool operator <= (const Image<I>& lhs, const oln_value(I)& val);
// FIXME: is-it a good idea to have "ima = lit"?
@@ -92,7 +91,7 @@
// Generic version.
template <typename I>
- bool op_eq_(const Image<I>& lhs, const literal_<oln_value(I)>& val)
+ bool op_eq_(const Image<I>& lhs, const oln_value(I)& val)
{
oln_piter(I) p(lhs.points());
for_all(p)
@@ -125,7 +124,7 @@
// Generic version.
template <typename I>
- bool op_less_(const Image<I>& lhs, const literal_<oln_value(I)>& val)
+ bool op_less_(const Image<I>& lhs, const oln_value(I)& val)
{
oln_piter(I) p(lhs.points());
for_all(p)
@@ -158,7 +157,7 @@
// Generic version.
template <typename I>
- bool op_leq_(const Image<I>& lhs, const literal_<oln_value(I)>& val)
+ bool op_leq_(const Image<I>& lhs, const oln_value(I)& val)
{
oln_piter(I) p(lhs.points());
for_all(p)
@@ -181,7 +180,7 @@
}
template <typename I>
- bool operator = (const Image<I>& lhs, const literal_<oln_value(I)>& val)
+ bool operator = (const Image<I>& lhs, const oln_value(I)& val)
{
return impl::op_eq_(exact(lhs), val);
}
@@ -194,7 +193,7 @@
}
template <typename I>
- bool operator < (const Image<I>& lhs, const literal_<oln_value(I)>& val)
+ bool operator < (const Image<I>& lhs, const oln_value(I)& val)
{
return impl::op_less_(exact(lhs), val);
}
@@ -207,7 +206,7 @@
}
template <typename I>
- bool operator <= (const Image<I>& lhs, const literal_<oln_value(I)>& val)
+ bool operator <= (const Image<I>& lhs, const oln_value(I)& val)
{
return impl::op_leq_(exact(lhs), val);
}
Index: oln/linear/convolution.hh
--- oln/linear/convolution.hh (revision 968)
+++ oln/linear/convolution.hh (working copy)
@@ -30,9 +30,9 @@
# include <oln/core/concept/image.hh>
# include <oln/core/concept/weighted_window.hh>
-
# include <oln/core/internal/f_weighted_window.hh>
# include <oln/core/internal/f_ch_value.hh>
+# include <oln/convert/to_dpoint.hh>
namespace oln
@@ -69,10 +69,6 @@
{
oln_plain_value(I, V) output;
prepare(output, with, f);
-
- oln_point(I) O; O.set_all(0);
- oln_point(I) p_q;
-
oln_piter(I) p(f.points());
oln_piter(J) q(g.points());
for_all(p)
@@ -80,10 +76,9 @@
V val = 0;
for_all(q)
{
- oln_dpoint(I) dp = O - oln_point(I)(q); // FIXME: to_point
- p_q = oln_point(I)(p) + dp; // FIXME: to_point
+ oln_point(I) p_q = p - convert::to_dpoint(q);
if (f.has(p_q))
- val += g(q) * f(p_q); // FIXME: f(p + (O - q));
+ val += g(q) * f(p_q);
}
output(p) = val;
}
@@ -102,7 +97,7 @@
V val = 0;
for (unsigned i = 0; i < w_win.size(); ++i)
{
- oln_point(I) q = oln_point(I)(p) + w_win.dp(i); // FIXME: to_point
+ oln_point(I) q = p + w_win.dp(i);
if (input.has(q))
val += w_win.w(i) * input(q);
}
Index: oln/linear/mean.hh
--- oln/linear/mean.hh (revision 968)
+++ oln/linear/mean.hh (working copy)
@@ -28,9 +28,9 @@
#ifndef OLN_LINEAR_MEAN_HH
# define OLN_LINEAR_MEAN_HH
-# include <oln/core/gen/literal.hh>
-# include <oln/convert/to_weighted_window.hh>
# include <oln/linear/convolution.hh>
+# include <oln/convert/to_weighted_window.hh>
+# include <oln/core/gen/constant.hh>
namespace oln
@@ -57,7 +57,7 @@
oln_plain_value(I, V)
mean_(const Image<I>& f, const Window<W>& win)
{
- lit_p2v_<oln_point(I), float> g(1.f / win.size());
+ constant_p2v_<oln_point(I), float> g(1.f / win.size());
return linear::convolution<V>(f, convert::to_weighted_window(g, win));
}
Index: oln/value/builtin.hh
--- oln/value/builtin.hh (revision 968)
+++ oln/value/builtin.hh (working copy)
@@ -72,7 +72,13 @@
- // int, float, ...
+ // unsigned, int, float, double,...
+
+ template <>
+ struct super_trait_< unsigned >
+ {
+ typedef internal::builtin_base<unsigned> ret;
+ };
template <>
struct super_trait_< int >
@@ -86,6 +92,12 @@
typedef internal::builtin_base<float> ret;
};
+ template <>
+ struct super_trait_< double >
+ {
+ typedef internal::builtin_base<double> ret;
+ };
+
} // end of namespace oln
Index: oln/value/builtin_traits.hh
--- oln/value/builtin_traits.hh (revision 968)
+++ oln/value/builtin_traits.hh (working copy)
@@ -42,6 +42,12 @@
};
template <typename Op>
+ struct set_trait_< Value, double, Op, Value, double >
+ {
+ typedef double ret;
+ };
+
+ template <typename Op>
struct set_trait_< Value, int, Op, Value, double >
{
typedef double ret;
1
0
Please make sure that the current directory is the right one
*before* committing.
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Better oln operators mechanism.
* oln/core/gen/literal.hh: Rename as...
* oln/core/gen/constant.hh: ...this.
(lit_p2v_, lit_p2b_): Rename as...
(constant_p2v_, constant_p2b_): ...these.
(literal_): Remove.
* oln/core/gen/value.hh: New.
* oln/core/gen/traits.hh
(oln_not_trait, not_id),
(set_utrait_, get_utrait_),
(uminus_id, plus_equal_id, minus_equal_id, modulus_equal_id):
New.
* oln/core/gen/fun_ops.hh
(oln_decl_p2v_cmp_),
(oln_decl_p2v_arith_),
(oln_decl_p2b_bin_): Merge into...
(oln_decl_binary_fun_): ...this new macro.
(oln_decl_p2v_un_),
(oln_decl_p2b_un_): Merge into...
(oln_decl_unary_fun_): ...this new macro.
(oln_decl_binary_op_),
(oln_decl_binary_op_p2v_),
(oln_decl_builtin_op_),
(oln_decl_unary_op_): New.
* oln/core/concept/iterator_on_points.hh (set_trait_): New.
* oln/core/concept/function.hh
(Function_p2v): Change inheritance to Function_v2v.
(Function_p2b): Change inheritance to Function_p2v.
(Function_p2p): Change inheritance to Function_p2v.
(Function_v2w2v): New commentary.
* oln/core/concept/point.hh
(op_equal_, op_less_, op_plus_equal_): Remove.
(op_minus_equal_, op_minus_): Remove.
(operator): New.
* oln/core/concept/dpoint.hh: Likewise.
* oln/core/concept/operators.hh: Rewrite.
* oln/value/builtin_traits.hh
(set_trait_, set_utrait_): New specializations.
core/concept/dpoint.hh | 185 +++++++++++++++----------
core/concept/function.hh | 36 ++--
core/concept/iterator_on_points.hh | 31 ++++
core/concept/operators.hh | 181 +++++++++++++++---------
core/concept/point.hh | 155 +++++++++++++--------
core/gen/constant.hh | 107 ++------------
core/gen/fun_ops.hh | 273 ++++++++++++++++---------------------
core/gen/traits.hh | 91 +++++++++++-
core/gen/value.hh | 174 +++++++++++++++++++++++
value/builtin_traits.hh | 19 ++
10 files changed, 798 insertions(+), 454 deletions(-)
Index: oln/core/gen/constant.hh
--- oln/core/gen/constant.hh (revision 961)
+++ oln/core/gen/constant.hh (working copy)
@@ -25,55 +25,26 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_CORE_GEN_LITERAL_HH
-# define OLN_CORE_GEN_LITERAL_HH
+#ifndef OLN_CORE_GEN_CONSTANT_HH
+# define OLN_CORE_GEN_CONSTANT_HH
# include <oln/core/concept/generator.hh>
# include <oln/core/concept/point.hh>
-# include <oln/core/concept/value.hh>
+# include <oln/core/gen/value.hh>
namespace oln
{
- // ----------------------------- literal_<T>
-
-
- template <typename T>
- struct literal_ : public Generator< literal_<T> >
- {
- typedef const T& result;
-
- literal_(const T& val);
-
- const T& operator()() const;
-
- operator T() const;
-
- template <typename U>
- operator literal_<U>() const;
-
- const T& value() const;
-
- private:
- T val_;
- };
-
-
- template <typename T>
- literal_<T> literal(const T& val);
-
-
- // ----------------------------- lit_p2v_<P,T>
-
+ // constant_p2v_<P,T>
template <typename P, typename V>
- struct lit_p2v_ : public Function_p2v< lit_p2v_<P,V> >
+ struct constant_p2v_ : public Function_p2v< constant_p2v_<P,V> >
{
typedef P argument;
typedef const V& result;
- lit_p2v_(const V& val);
+ constant_p2v_(const V& val);
const V& operator()(const P&) const;
@@ -82,16 +53,15 @@
};
- // ----------------------------- lit_p2b_<P,B>
-
+ // constant_p2b_<P,B>
template <typename P, typename B>
- struct lit_p2b_ : public Function_p2b< lit_p2b_<P,B> >
+ struct constant_p2b_ : public Function_p2b< constant_p2b_<P,B> >
{
typedef P argument;
typedef const B& result;
- lit_p2b_(const B& val);
+ constant_p2b_(const B& val);
const B& operator()(const P&) const;
@@ -104,78 +74,33 @@
# ifndef OLN_INCLUDE_ONLY
- // literal_<T>
-
- template <typename T>
- literal_<T>::literal_(const T& val)
- : val_(val)
- {
- }
-
- template <typename T>
- const T&
- literal_<T>::operator()() const
- {
- return this->val_;
- }
-
- template <typename T>
- literal_<T>::operator T() const
- {
- return this->val_;
- }
-
- template <typename T>
- template <typename U>
- literal_<T>::operator literal_<U>() const
- {
- literal_<U> tmp(this->val_);
- return tmp;
- }
-
- template <typename T>
- const T&
- literal_<T>::value() const
- {
- return this->val_;
- }
-
- template <typename T>
- literal_<T>
- literal(const T& val)
- {
- literal_<T> tmp(val);
- return tmp;
- }
-
-
- // lit_p2v_<P,V>
+ // constant_p2v_<P,V>
template <typename P, typename V>
- lit_p2v_<P,V>::lit_p2v_(const V& val)
+ constant_p2v_<P,V>::constant_p2v_(const V& val)
: val_(val)
{
}
template <typename P, typename V>
const V&
- lit_p2v_<P,V>::operator()(const P&) const
+ constant_p2v_<P,V>::operator()(const P&) const
{
return this->val_;
}
- //lit_p2b_<P,B>
+ //constant_p2b_<P,B>
template <typename P, typename B>
- lit_p2b_<P,B>::lit_p2b_(const B& val)
+ constant_p2b_<P,B>::constant_p2b_(const B& val)
: val_(val)
{
}
template <typename P, typename B>
const B&
- lit_p2b_<P,B>::operator()(const P&) const
+ constant_p2b_<P,B>::operator()(const P&) const
{
return this->val_;
}
@@ -185,4 +110,4 @@
} // end of namespace oln
-#endif // ! OLN_CORE_GEN_LITERAL_HH
+#endif // ! OLN_CORE_GEN_CONSTANT_HH
Index: oln/core/gen/traits.hh
--- oln/core/gen/traits.hh (revision 965)
+++ oln/core/gen/traits.hh (working copy)
@@ -48,6 +48,10 @@
# define oln_mod_trait(L, R) \
typename oln::get_trait_<L, oln::mod_id, R>::ret
+# define oln_uminus_trait(T) \
+ typename oln::get_utrait_<oln::uminus_id, T>::ret
+
+
// cmp
# define oln_eq_trait(L, R) \
@@ -56,6 +60,7 @@
# define oln_neq_trait(L, R) \
typename oln::get_trait_<L, oln::neq_id, R>::ret
+
// ord
# define oln_less_trait(L, R) \
@@ -70,6 +75,7 @@
# define oln_greater_trait(L, R) \
typename oln::get_trait_<L, oln::greater_id, R>::ret
+
// logic
# define oln_and_trait(L, R) \
@@ -81,6 +87,9 @@
# define oln_xor_trait(L, R) \
typename oln::get_trait_<L, oln::xor_id, R>::ret
+# define oln_not_trait(T) \
+ typename oln::get_utrait_<oln::not_id, T>::ret
+
@@ -111,8 +120,8 @@
namespace oln
{
- // set_trait_
+ // set_trait_ for binary operators.
template <template <class> class Cl, typename L,
typename Op,
@@ -130,8 +139,33 @@
template <template <class> class Cl, typename L,
typename Op,
template <class> class Cr, typename R>
- struct set_trait_ // default is
- : public set_trait_<Any, L, Op, Any, R>
+ struct set_trait_
+ : // default is
+ public set_trait_<Any, L, Op, Any, R>
+ {
+ };
+
+
+
+ // set_utrait_ for unary operators.
+
+ template <typename Op,
+ template <class> class C, typename T>
+ struct set_utrait_;
+
+
+ template <typename Op, typename T>
+ struct set_utrait_<Op, Any, T>
+ {
+ // nothing => do not compile
+ };
+
+
+ template <typename Op,
+ template <class> class C, typename T>
+ struct set_utrait_
+ : // default is
+ public set_utrait_<Op, Any, T>
{
};
@@ -145,6 +179,12 @@
struct div_id;
struct mod_id;
+ struct uminus_id;
+
+ struct plus_equal_id;
+ struct minus_equal_id;
+ struct modulus_equal_id;
+
struct eq_id;
struct neq_id;
@@ -156,6 +196,7 @@
struct and_id;
struct or_id;
struct xor_id;
+ struct not_id;
@@ -181,6 +222,10 @@
oln_internal_specialize_bin_trait_T_(xor);
+ // Fwd decl.
+ template <typename T> struct value_;
+
+
namespace internal
{
@@ -197,11 +242,49 @@
typedef typename oln::set_trait_< Cl, L, Op, Cr, R >::ret ret;
};
+ // get_utrait_cat_
+
+ template <typename Op, typename C, typename T>
+ struct get_utrait_cat__;
+
+ template < typename Op,
+ template <class> class C, typename T >
+ struct get_utrait_cat__< Op, stc::is<C>, T >
+ {
+ typedef typename oln::set_utrait_< Op, C, T >::ret ret;
+ };
+
+ // clean_for_trait_
+
+ template <typename T>
+ struct clean_for_trait_
+ {
+ typedef T ret;
+ };
+
+ template <typename T>
+ struct clean_for_trait_< const oln::value_<T> > { typedef T ret; };
+ template <typename T>
+ struct clean_for_trait_< const oln::value_<T>& > { typedef T ret; };
+ template <typename T>
+ struct clean_for_trait_< oln::value_<T>& > { typedef T ret; };
+
+ // FIXME: Add clean_for_trait_ for builtins?
+
} // end of namespace oln::internal
template <typename L, typename Op, typename R>
- struct get_trait_ : public internal::get_trait_cat__< oln_category_of_(L), L, Op, oln_category_of_(R), R >
+ struct get_trait_ : public internal::get_trait_cat__< oln_category_of_(L),
+ typename internal::clean_for_trait_<L>::ret,
+ Op,
+ oln_category_of_(R),
+ typename internal::clean_for_trait_<R>::ret >
+ {
+ };
+
+ template <typename Op, typename T>
+ struct get_utrait_ : public internal::get_utrait_cat__< Op, oln_category_of_(T), T >
{
};
Index: oln/core/gen/fun_ops.hh
--- oln/core/gen/fun_ops.hh (revision 965)
+++ oln/core/gen/fun_ops.hh (working copy)
@@ -29,184 +29,171 @@
# define OLN_CORE_GEN_FUN_OPS_HH
# include <oln/core/gen/fun.hh>
-# include <oln/core/gen/literal.hh>
+# include <oln/core/gen/constant.hh>
-# define oln_decl_p2v_cmp_(Name, Sym) \
+# define oln_decl_binary_fun_(Kind, Name, Sym) \
\
template <typename L, typename R> \
- struct p2v_##Name##_ : public Function_p2b< p2v_##Name##_<L,R> > \
+ struct Kind##_##Name##_ : public Function_##Kind< Kind##_##Name##_<L,R> > \
{ \
- typedef oln_arg_of_(L) argument; \
- typedef bool result; /* FIXME: trait! */ \
+ typedef oln_argument(L) argument; \
+ typedef oln_##Name##_trait(oln_result(L), oln_result(R)) result; \
\
- p2v_##Name##_(const Function_p2v<L>& left, const Function_p2v<R>& right) \
- : left_(exact(left)), \
- right_(exact(right)) \
+ Kind##_##Name##_(const L& left, const R& right) \
+ : left_(left), \
+ right_(right) \
{ \
} \
- bool operator()(argument arg) const \
+ \
+ result operator()(argument arg) const \
{ \
return this->left_(arg) Sym this->right_(arg); \
} \
+ \
private: \
L left_; \
R right_; \
}; \
\
- template <typename L, typename R> \
- p2v_##Name##_<L,R> \
- operator Sym (const Function_p2v<L>& left, const Function_p2v<R>& right) \
+ struct e_n_d___w_i_t_h___s_e_m_i_c_o_l_u_m_n
+
+
+
+
+# define oln_decl_unary_fun_(Kind, Name, Sym) \
+ \
+ template <typename T> \
+ struct Kind##_##Name##_ : public Function_##Kind< Kind##_##Name##_<T> > \
{ \
- mlc::assert_< mlc_is_a(oln_argument(L), Point) >::check(); \
- mlc::assert_< mlc_is_a(oln_argument(R), Point) >::check(); \
- mlc::assert_equal_< oln_argument(L), oln_argument(R) >::check(); \
- p2v_##Name##_<L,R> tmp(left, right); \
- return tmp; \
- } \
+ typedef oln_argument(T) argument; \
+ typedef oln_##Name##_trait(oln_result(T)) result; \
\
- template <typename L, typename R> \
- p2v_##Name##_<L, lit_p2v_<oln_argument(L), R> > \
- operator Sym (const Function_p2v<L>& left, const literal_<R>& right) \
+ Kind##_##Name##_(const T& oper) \
+ : oper_(oper) \
{ \
- mlc::assert_< mlc_is_a(oln_argument(L), Point) >::check(); \
- lit_p2v_<oln_argument(L), R> right_(right.value()); \
- p2v_##Name##_<L, lit_p2v_<oln_argument(L), R> > tmp(left, right_); \
- return tmp; \
} \
\
- template <typename L> \
- p2v_##Name##_<L, lit_p2v_<oln_argument(L), oln_result(L)> > \
- operator Sym (const Function_p2v<L>& left, const oln_result(L)& right) \
+ result operator()(argument arg) const \
{ \
- mlc::assert_< mlc_is_a(oln_argument(L), Point) >::check(); \
- lit_p2v_<oln_argument(L), oln_result(L)> right_(right); \
- p2v_##Name##_<L, lit_p2v_<oln_argument(L), oln_result(L)> > tmp(left, right_); \
- return tmp; \
+ return Sym this->oper_(arg); \
} \
\
+ private: \
+ T oper_; \
+ }; \
+ \
struct e_n_d___w_i_t_h___s_e_m_i_c_o_l_u_m_n
-# define oln_decl_p2v_arith_(Name, Sym) \
+
+# define oln_decl_binary_op_(IKind, Name, Sym, OKind) \
+ \
+ \
+ oln_decl_binary_fun_(OKind, Name, Sym); \
+ \
\
template <typename L, typename R> \
- struct p2v_##Name##_ : public Function_p2v< p2v_##Name##_<L,R> > \
+ struct set_trait_< Function_##IKind, L, Name##_id, Function_##IKind, R > \
{ \
- typedef oln_arg_of_(L) argument; \
- typedef oln_res_of_(L) result; /* FIXME: trait! */ \
+ typedef OKind##_##Name##_<L, R> ret; \
+ }; \
\
- p2v_##Name##_(const Function_p2v<L>& left, const Function_p2v<R>& right) \
- : left_(exact(left)), \
- right_(exact(right)) \
+ template <typename L, typename R> \
+ oln_##Name##_trait(L, R) \
+ operator Sym (const Function_##IKind<L>& left, const Function_##IKind<R>& right) \
{ \
+ mlc::assert_< mlc_is_a(oln_argument(L), Point) >::check(); \
+ mlc::assert_< mlc_is_a(oln_argument(R), Point) >::check(); \
+ mlc::assert_equal_< oln_argument(L), oln_argument(R) >::check(); \
+ oln_##Name##_trait(L, R) tmp(exact(left), exact(right)); \
+ return tmp; \
} \
- result operator()(argument arg) const \
+ \
+ \
+ template <typename L, typename R> \
+ struct set_trait_< Function_##IKind, L, Name##_id, Value, R > \
{ \
- return this->left_(arg) Sym this->right_(arg); \
- } \
- private: \
- L left_; \
- R right_; \
+ typedef OKind##_##Name##_<L, constant_##IKind##_<oln_argument(L), R> > ret; \
}; \
\
template <typename L, typename R> \
- p2v_##Name##_<L,R> \
- operator Sym (const Function_p2v<L>& left, const Function_p2v<R>& right) \
+ oln_##Name##_trait(L, value_<R>) \
+ operator Sym (const Function_##IKind<L>& left, const value_<R>& right) \
{ \
mlc::assert_< mlc_is_a(oln_argument(L), Point) >::check(); \
- mlc::assert_< mlc_is_a(oln_argument(R), Point) >::check(); \
- p2v_##Name##_<L,R> tmp(left, right); \
+ oln_##Name##_trait(L, value_<R>) tmp(exact(left), make_value(right)); \
return tmp; \
} \
\
+ \
template <typename L, typename R> \
- p2v_##Name##_<L, lit_p2v_<oln_argument(L), R> > \
- operator Sym (const Function_p2v<L>& left, const literal_<R>& right) \
+ struct set_trait_< Value, L, Name##_id, Function_##IKind, R > \
{ \
- mlc::assert_< mlc_is_a(oln_argument(L), Point) >::check(); \
- lit_p2v_<oln_argument(L), R> right_(right.value()); \
- p2v_##Name##_<L, lit_p2v_<oln_argument(L), R> > tmp(left, right_); \
+ typedef OKind##_##Name##_<constant_##IKind##_<oln_argument(R), L>, R> ret; \
+ }; \
+ \
+ template <typename L, typename R> \
+ oln_##Name##_trait(value_<L>, R) \
+ operator Sym (const value_<L>& left, const Function_##IKind<R>& right) \
+ { \
+ mlc::assert_< mlc_is_a(oln_argument(R), Point) >::check(); \
+ oln_##Name##_trait(value_<L>, R) tmp(make_value(left), exact(right)); \
return tmp; \
} \
\
+ \
struct e_n_d___w_i_t_h___s_e_m_i_c_o_l_u_m_n
-# define oln_decl_p2v_un_(Name, Sym) \
+
+
+# define oln_decl_unary_op_(IKind, Name, Sym, OKind) \
\
- template <typename T> \
- struct p2v_##Name##_ : public Function_p2v< p2v_##Name##_<T> > \
- { \
- typedef oln_arg_of_(T) argument; \
- typedef oln_res_of_(T) result; /* FIXME: trait! */ \
\
- p2v_##Name##_(const Function_p2v<T>& oper) \
- : oper_(exact(oper)) \
- { \
- } \
- result operator()(argument arg) const \
+ oln_decl_unary_fun_(OKind, Name, Sym); \
+ \
+ \
+ template <typename T> \
+ struct set_utrait_< Name##_id, Function_##IKind, T > \
{ \
- return Sym this->oper_(arg); \
- } \
- private: \
- T oper_; \
+ typedef OKind##_##Name##_<T> ret; \
}; \
\
template <typename T> \
- p2v_##Name##_<T> \
- operator Sym (const Function_p2v<T>& oper) \
+ oln_##Name##_trait(T) \
+ operator Sym (const Function_##IKind<T>& oper) \
{ \
- p2v_##Name##_<T> tmp(oper); \
+ oln_##Name##_trait(T) tmp(exact(oper)); \
return tmp; \
} \
\
+ \
struct e_n_d___w_i_t_h___s_e_m_i_c_o_l_u_m_n
-# define oln_decl_p2b_bin_(Name, Sym) \
- \
- template <typename L, typename R> \
- struct p2b_##Name##_ : public Function_p2b< p2b_##Name##_<L,R> > \
- { \
- typedef oln_arg_of_(L) argument; \
- typedef oln_res_of_(L) result; \
- \
- p2b_##Name##_(const Function_p2b<L>& left, const Function_p2b<R>& right) \
- : left_(exact(left)), \
- right_(exact(right)) \
- { \
- } \
- result operator()(argument arg) const \
- { \
- return this->left_(arg) Sym this->right_(arg); \
- } \
- private: \
- L left_; \
- R right_; \
- }; \
+
+# define oln_decl_builtin_op_(IKind, Name, Sym, Builtin) \
\
- template <typename L, typename R> \
- p2b_##Name##_<L,R> \
- operator Sym (const Function_p2b<L>& left, const Function_p2b<R>& right) \
+ template <typename L> \
+ oln_##Name##_trait(L, value_<Builtin>) \
+ operator Sym (const Function_##IKind<L>& left, const Builtin& right) \
{ \
mlc::assert_< mlc_is_a(oln_argument(L), Point) >::check(); \
- mlc::assert_< mlc_is_a(oln_argument(R), Point) >::check(); \
- p2b_##Name##_<L,R> tmp(left, right); \
+ oln_##Name##_trait(L, value_<Builtin>) tmp(exact(left), make_value(right)); \
return tmp; \
} \
\
- template <typename L, typename R> \
- p2b_##Name##_<L, lit_p2b_<oln_argument(L), R> > \
- operator Sym (const Function_p2b<L>& left, const literal_<R>& right) \
+ template <typename R> \
+ oln_##Name##_trait(value_<Builtin>, R) \
+ operator Sym (const Builtin& left, const Function_##IKind<R>& right) \
{ \
- mlc::assert_< mlc_is_a(oln_argument(L), Point) >::check(); \
- lit_p2b_<oln_argument(L), R> right_(right.value()); \
- p2b_##Name##_<L, lit_p2b_<oln_argument(L), R> > tmp(left, right_); \
+ mlc::assert_< mlc_is_a(oln_argument(R), Point) >::check(); \
+ oln_##Name##_trait(value_<Builtin>, R) tmp(make_value(left), exact(right)); \
return tmp; \
} \
\
@@ -214,34 +201,14 @@
-
-# define oln_decl_p2b_un_(Name, Sym) \
- \
- template <typename T> \
- struct p2b_##Name##_ : public Function_p2b< p2b_##Name##_<T> > \
- { \
- typedef oln_arg_of_(T) argument; \
- typedef oln_res_of_(T) result; /* FIXME: trait! */ \
+# define oln_decl_binary_op_p2v_(Name, Sym, OKind) \
\
- p2b_##Name##_(const Function_p2b<T>& oper) \
- : oper_(exact(oper)) \
- { \
- } \
- result operator()(argument arg) const \
- { \
- return Sym this->oper_(arg); \
- } \
- private: \
- T oper_; \
- }; \
+ oln_decl_binary_op_( p2v, Name, Sym, OKind ); \
\
- template <typename T> \
- p2b_##Name##_<T> \
- operator Sym (const Function_p2b<T>& oper) \
- { \
- p2b_##Name##_<T> tmp(oper); \
- return tmp; \
- } \
+ oln_decl_builtin_op_( p2v, Name, Sym, unsigned ); \
+ oln_decl_builtin_op_( p2v, Name, Sym, int ); \
+ oln_decl_builtin_op_( p2v, Name, Sym, float ); \
+ oln_decl_builtin_op_( p2v, Name, Sym, double ); \
\
struct e_n_d___w_i_t_h___s_e_m_i_c_o_l_u_m_n
@@ -250,30 +217,36 @@
namespace oln
{
- oln_decl_p2v_cmp_( eq, = );
- oln_decl_p2v_cmp_( not_eq, != );
- oln_decl_p2v_cmp_( less, < );
- oln_decl_p2v_cmp_( leq, <= );
- oln_decl_p2v_cmp_( greater, > );
- oln_decl_p2v_cmp_( geq, >= );
-
- oln_decl_p2v_arith_( plus, + );
- oln_decl_p2v_arith_( minus, - );
- oln_decl_p2v_arith_( times, * );
- oln_decl_p2v_arith_( div, / );
- oln_decl_p2v_arith_( mod, % );
-
- oln_decl_p2v_un_( uminus, - );
-
- oln_decl_p2b_bin_( and, && );
- oln_decl_p2b_bin_( or, || );
- oln_decl_p2b_bin_( xor, ^ );
- // FIXME: nand, nor, xnor?
+ // input output
+ // vvv vvv
+
+ oln_decl_binary_op_p2v_( eq, =, p2b );
+ oln_decl_binary_op_p2v_( neq, !=, p2b );
+
+ oln_decl_binary_op_p2v_( less, < , p2b );
+ oln_decl_binary_op_p2v_( leq, <=, p2b );
+ oln_decl_binary_op_p2v_( greater, > , p2b );
+ oln_decl_binary_op_p2v_( geq, >=, p2b );
+
+ oln_decl_binary_op_p2v_( plus, +, p2v );
+ oln_decl_binary_op_p2v_( minus, -, p2v );
+ oln_decl_binary_op_p2v_( times, *, p2v );
+ oln_decl_binary_op_p2v_( div, /, p2v );
+ oln_decl_binary_op_p2v_( mod, %, p2v );
+
+ oln_decl_unary_op_( p2v, uminus, -, p2v );
+
+ oln_decl_binary_op_( p2b, and, &&, p2b );
+ oln_decl_binary_op_( p2b, or, ||, p2b );
+ oln_decl_binary_op_( p2b, xor, ^, p2b );
- oln_decl_p2b_un_( not, ! );
+ oln_decl_unary_op_( p2b, not, !, p2b );
} // end of namespace oln
+ // FIXME: nand, nor, xnor?
+
+
#endif // ! OLN_CORE_GEN_FUN_OPS_HH
Index: oln/core/gen/value.hh
--- oln/core/gen/value.hh (revision 0)
+++ oln/core/gen/value.hh (revision 0)
@@ -0,0 +1,174 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_CORE_GEN_VALUE_HH
+# define OLN_CORE_GEN_VALUE_HH
+
+# include <oln/core/concept/value.hh>
+
+
+namespace oln
+{
+
+ // Fwd decl.
+ template <typename T> struct value_;
+
+
+ // Super trait.
+ template <typename T>
+ struct super_trait_< value_<T> >
+ {
+ typedef Value< value_<T> > ret;
+ };
+
+
+ // Virtual types.
+ template <typename T>
+ struct vtypes< value_<T> >
+ {
+ typedef stc::is<Value> category; // FIXME: Temporary code.
+ };
+
+
+ // Wrapper class for a value.
+ template <typename T>
+ struct value_ : public Value< value_<T> >
+ {
+ typedef T encoding;
+
+ value_();
+
+ template <typename U>
+ value_(const U& v);
+
+ template <typename U>
+ value_(const value_<U>& v);
+
+ template <typename U>
+ value_<T>& operator=(const value_<U>& v);
+
+ operator T() const;
+
+ template <typename U>
+ operator U() const;
+
+ template <typename U>
+ operator value_<U>() const;
+
+ private:
+ T val_;
+ };
+
+
+ // make_value
+
+ template <typename T>
+ value_<T> make_value(const T& val);
+
+ template <typename T>
+ value_<T> make_value(const value_<T>& val);
+
+
+ // traits
+
+ template <typename L, typename Op, typename R>
+ struct set_trait_< Value, value_<L>, Op, Value, value_<R> >
+ {
+ typedef typename get_trait_<L, Op, R>::ret ret;
+ };
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename T>
+ value_<T>::value_()
+ {
+ }
+
+ template <typename T>
+ template <typename U>
+ value_<T>::value_(const U& v)
+ : val_(v)
+ {
+ }
+
+ template <typename T>
+ template <typename U>
+ value_<T>::value_(const value_<U>& v)
+ : val_(U(v))
+ {
+ }
+
+ template <typename T>
+ template <typename U>
+ value_<T>&
+ value_<T>::operator=(const value_<U>& v)
+ {
+ this->val_ = U(v);
+ return *this;
+ }
+
+ template <typename T>
+ value_<T>::operator T() const
+ {
+ return this->val_;
+ }
+
+ template <typename T>
+ template <typename U>
+ value_<T>::operator U() const
+ {
+ return static_cast<U>(this->val_);
+ }
+
+ template <typename T>
+ template <typename U>
+ value_<T>::operator value_<U>() const
+ {
+ value_<U> tmp = static_cast<U>(this->val_);
+ return tmp;
+ }
+
+ template <typename T>
+ value_<T> make_value(const T& val)
+ {
+ value_<T> tmp = val;
+ return tmp;
+ }
+
+ template <typename T>
+ value_<T> make_value(const value_<T>& val)
+ {
+ return val;
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_GEN_VALUE_HH
Index: oln/core/concept/iterator_on_points.hh
--- oln/core/concept/iterator_on_points.hh (revision 965)
+++ oln/core/concept/iterator_on_points.hh (working copy)
@@ -73,6 +73,37 @@
} // end of namespace oln::internal
+
+ // \{
+ // Operator - traits.
+
+ template <typename P, typename It>
+ struct set_trait_< Point, P, minus_id, Iterator_on_Points, It >
+ {
+ typedef oln_point(It) Pit;
+ typedef oln_minus_trait(P, Pit) ret;
+ };
+
+ template <typename It, typename P>
+ struct set_trait_< Iterator_on_Points, It, minus_id, Point, P >
+ {
+ typedef oln_point(It) Pit;
+ typedef oln_minus_trait(Pit, P) ret;
+ };
+
+ template <typename It1, typename It2>
+ struct set_trait_< Iterator_on_Points, It1, minus_id, Iterator_on_Points, It2 >
+ {
+ typedef oln_point(It1) Pit1;
+ typedef oln_point(It2) Pit2;
+ typedef oln_minus_trait(Pit1, Pit2) ret;
+ };
+
+ // \}
+
+
+
+
# ifndef OLN_INCLUDE_ONLY
template <typename Exact>
Index: oln/core/concept/function.hh
--- oln/core/concept/function.hh (revision 965)
+++ oln/core/concept/function.hh (working copy)
@@ -45,10 +45,21 @@
};
+ // Value -> Value.
+
+ template <typename Exact>
+ struct Function_v2v : public Function<Exact>
+ {
+ typedef Function_v2v<void> category;
+ protected:
+ Function_v2v();
+ };
+
+
// Point -> Value.
template <typename Exact>
- struct Function_p2v : public Function<Exact>
+ struct Function_p2v : public Function_v2v<Exact>
{
typedef Function_p2v<void> category;
protected:
@@ -59,7 +70,7 @@
// Point -> bool.
template <typename Exact>
- struct Function_p2b : public Function<Exact>
+ struct Function_p2b : public Function_p2v<Exact>
{
typedef Function_p2b<void> category;
protected:
@@ -67,21 +78,21 @@
};
- // Value -> Value.
+ // Point -> Point.
template <typename Exact>
- struct Function_v2v : public Function<Exact>
+ struct Function_p2p : public Function_p2v<Exact>
{
- typedef Function_v2v<void> category;
+ typedef Function_p2p<void> category;
protected:
- Function_v2v();
+ Function_p2p();
};
// Value1 -> Value2 *and* Value2 -> Value1.
template <typename Exact>
- struct Function_v2w2v : public Function<Exact>
+ struct Function_v2w2v : public Function<Exact> // FIXME: public Function_v2v<Exact>?
{
typedef Function_v2w2v<void> category;
protected:
@@ -89,17 +100,6 @@
};
- // Point -> Point.
-
- template <typename Exact>
- struct Function_p2p : public Function<Exact>
- {
- typedef Function_p2p<void> category;
- protected:
- Function_p2p();
- };
-
-
# ifndef OLN_INCLUDE_ONLY
template <typename Exact>
Index: oln/core/concept/point.hh
--- oln/core/concept/point.hh (revision 965)
+++ oln/core/concept/point.hh (working copy)
@@ -40,6 +40,10 @@
namespace oln
{
+ // Fwd decl.
+ template <typename Exact> struct Dpoint;
+
+
/// Concept-class "Generalized_Point".
template <typename Exact>
@@ -57,62 +61,75 @@
};
- /// Concept-class "Point".
+ // Operator -.
- template <typename Exact>
- struct Point : public Generalized_Point<Exact>
- {
- stc_using_from(Generalized_Point, dpoint);
+ template <typename P1, typename P2>
+ oln_minus_trait(P1, P2)
+ operator - (const Generalized_Point<P1>& lhs, const Generalized_Point<P2>& rhs);
- /// Operator =.
- bool op_equal_(const Exact& rhs) const;
+ // Operator =.
- /// Operator <.
- bool op_less_(const Exact& rhs) const;
+ template <typename P1, typename P2>
+ bool operator = (const Generalized_Point<P1>& lhs, const Generalized_Point<P2>& rhs);
- /// Operator +=.
- Exact& op_plus_equal_(const dpoint& rhs);
+ // Operator <.
- /// Operator -=.
- Exact& op_minus_equal_(const dpoint& rhs);
+ template <typename P1, typename P2>
+ bool operator < (const Generalized_Point<P1>& lhs, const Generalized_Point<P2>& rhs);
- /// Operator -.
- dpoint op_minus_(const Exact& rhs) const;
+ // Operator +=.
- protected:
- Point();
+ template <typename P, typename Dp> // Defined in oln/core/concept/dpoint.hh
+ P& operator += (Generalized_Point<P>& lhs, const Dpoint<Dp>& rhs);
- }; // end of oln::Point<Exact>
+ // Operator -=.
+ template <typename P, typename Dp> // Defined in oln/core/concept/dpoint.hh
+ P& operator -= (Generalized_Point<P>& lhs, const Dpoint<Dp>& rhs);
- /// Operator -.
- template <typename P>
- struct set_trait_< Point, P, minus_id, Point, P >
- {
- typedef typename P::dpoint ret;
- };
+ // \{
+ // Invalid operators.
+
+ template <typename P1, typename P2>
+ void operator + (const Generalized_Point<P1>& lhs,
+ const Generalized_Point<P2>& rhs);
+
+ template <typename P1, typename P2>
+ void operator += (const Generalized_Point<P1>& lhs,
+ const Generalized_Point<P2>& rhs);
template <typename P>
- typename P::dpoint
- operator - (const Point<P>& lhs, const Point<P>& rhs);
+ void operator - (const Generalized_Point<P>& rhs);
+ template <typename P1, typename P2>
+ void operator -= (const Generalized_Point<P1>& lhs,
+ const Generalized_Point<P2>& rhs);
+ // \}
- /// \{
- /// Invalid operators.
- template <typename P>
- void operator-(const Point<P>& rhs) /* error */ ;
- template <typename P1, typename P2>
- void operator+(const Point<P1>& lhs, const Point<P2>& rhs) /* error */ ;
+ /// Concept-class "Point".
- /// \}
+ template <typename Exact>
+ struct Point : public Generalized_Point<Exact>
+ {
+ protected:
+ Point();
+
+ }; // end of oln::Point<Exact>
+ template <typename P>
+ struct set_trait_< Point, P, minus_id, Point, P >
+ {
+ typedef oln_dpoint(P) ret; // FIXME: Wrong! (too restrictive)
+ };
+
+
namespace internal
{
@@ -147,41 +164,76 @@
# ifndef OLN_INCLUDE_ONLY
+ // Generalized_Point
+
template <typename Exact>
Generalized_Point<Exact>::Generalized_Point()
{
}
- template <typename Exact>
- bool Point<Exact>::op_equal_(const Exact& rhs) const
+ template <typename P>
+ oln_minus_trait(P, P)
+ operator - (const Generalized_Point<P>& lhs, const Generalized_Point<P>& rhs)
{
- return exact(this)->impl_op_equal_(rhs);
+ oln_minus_trait(P, P) tmp;
+ tmp.vec() = exact(lhs).vec() - exact(rhs).vec();
+ return tmp;
}
- template <typename Exact>
- bool Point<Exact>::op_less_(const Exact& rhs) const
+ template <typename P1, typename P2>
+ bool
+ operator = (const Generalized_Point<P1>& lhs, const Generalized_Point<P2>& rhs)
{
- return exact(this)->impl_op_less_(rhs);
+ return exact(lhs).vec() = exact(rhs).vec();
}
- template <typename Exact>
- Exact& Point<Exact>::op_plus_equal_(const typename Point<Exact>::dpoint& rhs)
+ template <typename P1, typename P2>
+ bool
+ operator < (const Generalized_Point<P1>& lhs, const Generalized_Point<P2>& rhs)
{
- return exact(this)->impl_op_plus_equal_(rhs);
+ return exact(lhs).vec() < exact(rhs).vec();
}
- template <typename Exact>
- Exact& Point<Exact>::op_minus_equal_(const typename Point<Exact>::dpoint& rhs)
+ // Invalid operators.
+
+ template <typename P1, typename P2>
+ void operator + (const Generalized_Point<P1>& lhs,
+ const Generalized_Point<P2>& rhs)
{
- return exact(this)->impl_op_minus_equal_(rhs);
+ mlc::abort_<P1,
+ ERROR::operator_< plus_id >::template _is_invalid_for_types_<P1, P2>
+ >::check();
}
- template <typename Exact>
- typename Point<Exact>::dpoint Point<Exact>::op_minus_(const Exact& rhs) const
+ template <typename P1, typename P2>
+ void operator += (const Generalized_Point<P1>& lhs,
+ const Generalized_Point<P2>& rhs)
+ {
+ mlc::abort_<P1,
+ ERROR::operator_< plus_equal_id >::template _is_invalid_for_types_<P1, P2>
+ >::check();
+ }
+
+ template <typename P1, typename P2>
+ void operator -= (const Generalized_Point<P1>& lhs,
+ const Generalized_Point<P2>& rhs)
{
- return exact(this)->impl_op_minus_(rhs);
+ mlc::abort_<P1,
+ ERROR::operator_< minus_equal_id >::template _is_invalid_for_types_<P1, P2>
+ >::check();
}
+ template <typename P>
+ void operator - (const Generalized_Point<P>& rhs)
+ {
+ mlc::abort_<P,
+ ERROR::operator_< uminus_id >::template _is_invalid_for_<P>
+ >::check();
+ }
+
+
+ // Point
+
template <typename Exact>
Point<Exact>::Point()
{
@@ -203,13 +255,6 @@
} // end of namespace oln::internal
- template <typename P>
- typename P::dpoint
- operator-(const Point<P>& lhs, const Point<P>& rhs)
- {
- return lhs.op_minus_(exact(rhs));
- }
-
# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/concept/dpoint.hh
--- oln/core/concept/dpoint.hh (revision 965)
+++ oln/core/concept/dpoint.hh (working copy)
@@ -59,143 +59,190 @@
enum { n = mlc_value(dim) };
- /// Operator =.
- bool op_equal_(const Exact& rhs) const;
+ protected:
+ Dpoint();
- /// Operator <.
- bool op_less_(const Exact& rhs) const;
+ }; // end of oln::Dpoint<Exact>
- /// Operator +=.
- Exact& op_plus_equal_(const Exact& rhs);
- /// Operator -=.
- Exact& op_minus_equal_(const Exact& rhs);
- /// Operator %=.
- Exact& op_mod_equal_(const Exact& rhs);
+ // Operators on Dpoints.
- /// Operator -.
- Exact op_unary_minus_() const;
+ template <typename D1, typename D2>
+ bool operator = (const Dpoint<D1>& lhs, const Dpoint<D2>& rhs);
- protected:
- Dpoint();
+ template <typename D1, typename D2>
+ bool operator < (const Dpoint<D1>& lhs, const Dpoint<D2>& rhs);
- }; // end of oln::Dpoint<Exact>
+ template <typename D, typename D2>
+ D& operator += (Dpoint<D>& lhs, const Dpoint<D2>& rhs);
+
+ template <typename D, typename D2>
+ D& operator -= (Dpoint<D>& lhs, const Dpoint<D2>& rhs);
+
+ template <typename D>
+ D operator - (const Dpoint<D>& rhs);
+ template <typename D, typename D2>
+ D& operator %= (Dpoint<D>& lhs, const Dpoint<D2>& rhs);
- /// \{
- /// Operator "Point - Dpoint".
+
+
+ // \{
+ // Traits.
template <typename P, typename D>
- struct set_trait_< Point, P, minus_id, Dpoint, D >
+ struct set_trait_< Point, P, plus_id, Dpoint, D >
{
- typedef P ret;
+ typedef P ret; // FIXME: Wrong! (too restrictive)
};
template <typename P, typename D>
- P operator-(const Point<P>& lhs, const Dpoint<D>& rhs);
+ struct set_trait_< Point, P, minus_id, Dpoint, D >
+ {
+ typedef P ret; // FIXME: Wrong! (too restrictive)
+ };
- /// \}
+ // \}
- /// \{
- /// Operator "Point + Dpoint".
+
+ // Operators mixing Generalized_Point and Dpoint.
template <typename P, typename D>
- struct set_trait_< Point, P, plus_id, Dpoint, D >
- {
- typedef P ret;
- };
+ oln_plus_trait(P, D)
+ operator + (const Generalized_Point<P>& lhs, const Dpoint<D>& rhs);
template <typename P, typename D>
- P operator+(const Point<P>& lhs, const Dpoint<D>& rhs);
+ oln_minus_trait(P, D)
+ operator - (const Generalized_Point<P>& lhs, const Dpoint<D>& rhs);
- /// \}
- /// \{
- /// Invalid operators.
+ // \{
+ // Invalid operators.
template <typename D, typename P>
- void operator-(const Dpoint<D>& lhs, const Point<P>& rhs) /* error */ ;
+ void operator - (const Dpoint<D>& lhs, const Generalized_Point<P>& rhs);
template <typename D, typename P>
- void operator+(const Dpoint<D>& lhs, const Point<P>& rhs) /* error */ ;
+ void operator + (const Dpoint<D>& lhs, const Generalized_Point<P>& rhs);
- /// \}
+ // \}
-# ifndef OLN_INCLUDE_ONLY
+# ifndef OLN_INCLUDE_ONLY
template <typename Exact>
- bool Dpoint<Exact>::op_equal_(const Exact& rhs) const
+ Dpoint<Exact>::Dpoint()
{
- return exact(this)->impl_op_equal_(rhs);
+ // FIXME: Uncomment!
+ // mlc::assert_defined_< oln_vtype(Exact, grid) >::check();
+ // mlc::assert_defined_< oln_vtype(Exact, point) >::check();
+ // mlc::assert_defined_< oln_vtype(Exact, coord) >::check();
+ // mlc::assert_defined_< oln_vtype(Exact, dim) >::check();
}
- template <typename Exact>
- bool Dpoint<Exact>::op_less_(const Exact& rhs) const
+
+ // Operators on Dpoints.
+
+ template <typename D1, typename D2>
+ bool operator = (const Dpoint<D1>& lhs, const Dpoint<D2>& rhs)
{
- return exact(this)->impl_op_less_(rhs);
+ return exact(lhs).vec() = exact(rhs).vec();
}
- template <typename Exact>
- Exact& Dpoint<Exact>::op_plus_equal_(const Exact& rhs)
+ template <typename D1, typename D2>
+ bool operator < (const Dpoint<D1>& lhs, const Dpoint<D2>& rhs)
{
- return exact(this)->impl_op_plus_equal_(rhs);
+ return exact(lhs).vec() < exact(rhs).vec();
}
- template <typename Exact>
- Exact& Dpoint<Exact>::op_minus_equal_(const Exact& rhs)
+ template <typename D, typename D2>
+ D& operator += (Dpoint<D>& lhs, const Dpoint<D2>& rhs)
{
- return exact(this)->impl_op_minus_equal_(rhs);
+ exact(lhs).vec() += exact(rhs).vec();
+ return exact(lhs);
}
- template <typename Exact>
- Exact& Dpoint<Exact>::op_mod_equal_(const Exact& rhs)
+ template <typename D, typename D2>
+ D& operator -= (Dpoint<D>& lhs, const Dpoint<D2>& rhs)
{
- return exact(this)->impl_op_mod_equal_(rhs);
+ exact(lhs).vec() -= exact(rhs).vec();
+ return exact(lhs);
}
- template <typename Exact>
- Exact Dpoint<Exact>::op_unary_minus_() const
+ template <typename D>
+ D operator - (const Dpoint<D>& rhs)
{
- return exact(this)->impl_op_unary_minus_();
+ D tmp;
+ tmp.vec() = - exact(rhs).vec();
+ return tmp;
}
- template <typename Exact>
- Dpoint<Exact>::Dpoint()
+ template <typename D, typename D2>
+ D& operator %= (Dpoint<D>& lhs, const Dpoint<D2>& rhs)
{
- // FIXME: Uncomment!
- // mlc::assert_defined_< oln_vtype(Exact, grid) >::check();
- // mlc::assert_defined_< oln_vtype(Exact, point) >::check();
- // mlc::assert_defined_< oln_vtype(Exact, coord) >::check();
- // mlc::assert_defined_< oln_vtype(Exact, dim) >::check();
+ exact(lhs).vec() %= exact(rhs).vec();
+ return exact(lhs);
}
- /// \{
- /// Operators.
+ // Operators mixing Generalized_Point and Dpoint.
+
+ template <typename P, typename D> // from oln/core/concept/point.hh
+ P& operator += (Generalized_Point<P>& lhs, const Dpoint<D>& rhs)
+ {
+ exact(lhs).vec() += exact(rhs).vec();
+ return exact(lhs);
+ }
+
+ template <typename P, typename D> // from oln/core/concept/point.hh
+ P& operator -= (Generalized_Point<P>& lhs, const Dpoint<D>& rhs)
+ {
+ exact(lhs).vec() -= exact(rhs).vec();
+ return exact(lhs);
+ }
template <typename P, typename D>
- P operator-(const Point<P>& lhs, const Dpoint<D>& rhs)
+ oln_plus_trait(P, D)
+ operator + (const Generalized_Point<P>& lhs, const Dpoint<D>& rhs)
{
- P tmp = exact(lhs);
- return tmp -= rhs;
+ oln_plus_trait(P, D) tmp;
+ tmp.vec() = exact(lhs).vec() + exact(rhs).vec();
+ return tmp;
}
template <typename P, typename D>
- P operator+(const Point<P>& lhs, const Dpoint<D>& rhs)
+ oln_minus_trait(P, D)
+ operator - (const Generalized_Point<P>& lhs, const Dpoint<D>& rhs)
{
- P tmp = exact(lhs);
- return tmp += rhs;
+ oln_minus_trait(P, D) tmp;
+ tmp.vec() = exact(lhs).vec() - exact(rhs).vec();
+ return tmp;
}
- /// \}
-# endif // ! OLN_INCLUDE_ONLY
+ // Invalid operators.
+
+ template <typename D, typename P>
+ void operator + (const Dpoint<D>& lhs, const Generalized_Point<P>& rhs)
+ {
+ mlc::abort_<D,
+ ERROR::operator_< plus_id >::template _is_invalid_for_types_<D, P>
+ >::check();
+ }
+ template <typename D, typename P>
+ void operator - (const Dpoint<D>& lhs, const Generalized_Point<P>& rhs)
+ {
+ mlc::abort_<D,
+ ERROR::operator_< minus_id >::template _is_invalid_for_types_<D, P>
+ >::check();
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/concept/operators.hh
--- oln/core/concept/operators.hh (revision 965)
+++ oln/core/concept/operators.hh (working copy)
@@ -30,86 +30,112 @@
# include <oln/core/equipment.hh>
# include <oln/core/gen/traits.hh>
+# include <oln/core/gen/value.hh>
namespace oln
{
- /// Operator = (default version).
- template <typename L, typename R>
- bool operator=(const Any<L>& lhs, const Any<R>& rhs);
- /// Operator != (default version).
+ // Default versions for some operators.
+
template <typename L, typename R>
- bool operator!=(const Any<L>& lhs, const Any<R>& rhs);
+ bool
+ operator != (const Any<L>& lhs, const Any<R>& rhs); // Using "=".
- /// Operator < (default version).
template <typename L, typename R>
- bool operator< (const Any<L>& lhs, const Any<R>& rhs);
+ bool
+ operator > (const Any<L>& lhs, const Any<R>& rhs); // Using "<".
- /// Operator > (default version).
template <typename L, typename R>
- bool operator> (const Any<L>& lhs, const Any<R>& rhs);
+ bool
+ operator <= (const Any<L>& lhs, const Any<R>& rhs); // Using "<".
- /// Operator >= (default version).
template <typename L, typename R>
- bool operator>=(const Any<L>& lhs, const Any<R>& rhs);
+ bool
+ operator >= (const Any<L>& lhs, const Any<R>& rhs); // Using "<=".
+
+ template <typename T>
+ T
+ operator + (const Any<T>& lhs, const Any<T>& rhs); // Using "+=".
+
+ template <typename T>
+ T
+ operator - (const Any<T>& lhs, const Any<T>& rhs); // Using "+=".
+
+ template <typename T>
+ T
+ operator % (const Any<T>& lhs, const Any<T>& rhs); // Using "%=".
+
+
+
+
+
+ // FIXME: Add: template <typename T> T operator - (const Any<T>& rhs);
+
+
- /// Operator <= (default version).
+
+ namespace ERROR
+ {
+
+ template <typename Op>
+ struct operator_
+ {
+ // unary
+ template <typename T> struct _is_missing_for_;
+ template <typename T> struct _is_invalid_for_;
+ // binary
+ template <typename L, typename R> struct _is_missing_for_types_;
+ template <typename L, typename R> struct _is_invalid_for_types_;
+ };
+
+ } // end of namespace oln::ERROR
+
+
+
+ // Guards.
+ // ----------------
+
+ // Operator =.
template <typename L, typename R>
- bool operator<=(const Any<L>& lhs, const Any<R>& rhs);
+ void operator = (const Any<L>& lhs, const Any<R>& rhs);
- /// Operator += (default version).
+ // Operator <.
template <typename L, typename R>
- L& operator+=(Any<L>& lhs, const Any<R>& rhs);
+ void operator < (const Any<L>& lhs, const Any<R>& rhs);
- /// Operator + (default version).
+ // Operator -.
template <typename T>
- T operator+ (const Any<T>& lhs, const Any<T>& rhs);
+ void operator - (const Any<T>& rhs);
- /// Operator %= (default version).
+ // Operator +=.
template <typename L, typename R>
- L& operator%=(Any<L>& lhs, const Any<R>& rhs);
+ void operator += (const Any<L>& lhs, const Any<R>& rhs);
- /// Operator % (default version).
- template <typename T>
- T operator% (const Any<T>& lhs, const Any<T>& rhs);
+ // Operator -=.
+ template <typename L, typename R>
+ void operator -= (const Any<L>& lhs, const Any<R>& rhs);
- /// Operator -= (default version).
+ // Operator %=.
template <typename L, typename R>
- L& operator-=(Any<L>& lhs, const Any<R>& rhs);
+ void operator %= (const Any<L>& lhs, const Any<R>& rhs);
- /// Operator - (default version).
- template <typename T>
- T operator- (const Any<T>& lhs, const Any<T>& rhs);
+ // ----------------
+ // end of Guards.
- /// Operator - (default version).
- template <typename T>
- T operator- (const Any<T>& rhs);
# ifndef OLN_INCLUDE_ONLY
template <typename L, typename R>
- bool operator=(const Any<L>& lhs, const Any<R>& rhs)
- {
- return exact(lhs).op_equal_(exact(rhs));
- }
-
- template <typename L, typename R>
bool operator!=(const Any<L>& lhs, const Any<R>& rhs)
{
return not (exact(lhs) = exact(rhs));
}
template <typename L, typename R>
- bool operator< (const Any<L>& lhs, const Any<R>& rhs)
- {
- return exact(lhs).op_less_(exact(rhs));
- }
-
- template <typename L, typename R>
bool operator> (const Any<L>& lhs, const Any<R>& rhs)
{
return exact(rhs) < exact(lhs); // use "operator <"
@@ -127,12 +153,6 @@
return exact(rhs) <= exact(lhs); // use "operator <="
}
- template <typename L, typename R>
- L& operator+=(Any<L>& lhs, const Any<R>& rhs)
- {
- return exact(lhs).op_plus_equal_(exact(rhs));
- }
-
template <typename T>
T operator+ (const Any<T>& lhs, const Any<T>& rhs)
{
@@ -147,12 +167,6 @@
return tmp -= exact(rhs);
}
- template <typename L, typename R>
- L& operator%=(Any<L>& lhs, const Any<R>& rhs)
- {
- return exact(lhs).op_mod_equal_(exact(rhs));
- }
-
template <typename T>
T operator% (const Any<T>& lhs, const Any<T>& rhs)
{
@@ -160,35 +174,68 @@
return tmp %= exact(rhs);
}
+
+
+ // Guards.
+ // ----------------
+
+ // Operator =.
template <typename L, typename R>
- L& operator-=(Any<L>& lhs, const Any<R>& rhs)
+ void operator = (const Any<L>& lhs, const Any<R>& rhs)
{
- return exact(lhs).op_minus_equal_(exact(rhs));
+ mlc::abort_<L,
+ ERROR::operator_< eq_id >::template _is_missing_for_types_<L, R>
+ >::check();
}
- template <typename T>
- T operator- (const Any<T>& rhs)
+ // Operator <.
+ template <typename L, typename R>
+ void operator < (const Any<L>& lhs, const Any<R>& rhs)
{
- return exact(rhs).op_unary_minus_();
+ mlc::abort_<L,
+ ERROR::operator_< less_id >::template _is_missing_for_types_<L, R>
+ >::check();
}
- /*
-
- FIXME: Activate?
+ // Operator +=.
+ template <typename L, typename R>
+ void operator += (const Any<L>& lhs, const Any<R>& rhs)
+ {
+ mlc::abort_<L,
+ ERROR::operator_< plus_equal_id >::template _is_missing_for_types_<L, R>
+ >::check();
+ }
+ // Operator -=.
template <typename L, typename R>
- xtd_op_plus_trait(L, R) operator+ (const Any<L>& lhs, const Any<R>& rhs)
+ void operator -= (const Any<L>& lhs, const Any<R>& rhs)
{
- return exact(lhs).op_plus_(exact(rhs));
+ mlc::abort_<L,
+ ERROR::operator_< minus_equal_id >::template _is_missing_for_types_<L, R>
+ >::check();
}
+ // Operator %=.
template <typename L, typename R>
- xtd_op_minus_trait(L, R) operator- (const Any<L>& lhs, const Any<R>& rhs)
+ void operator %= (const Any<L>& lhs, const Any<R>& rhs)
{
- return exact(lhs).op_minus_(exact(rhs));
+ mlc::abort_<L,
+ ERROR::operator_< modulus_equal_id >::template _is_missing_for_types_<L, R>
+ >::check();
}
- */
+ // Operator -.
+ template <typename T>
+ void operator - (const Any<T>& rhs)
+ {
+ mlc::abort_<T,
+ ERROR::operator_< uminus_id >::template _is_missing_for_<T>
+ >::check();
+ }
+
+ // ----------------
+ // end of Guards.
+
# endif // ! OLN_INCLUDE_ONLY
Index: oln/value/builtin_traits.hh
--- oln/value/builtin_traits.hh (revision 965)
+++ oln/value/builtin_traits.hh (working copy)
@@ -42,11 +42,30 @@
};
template <typename Op>
+ struct set_trait_< Value, int, Op, Value, double >
+ {
+ typedef double ret;
+ };
+
+ template <typename Op>
struct set_trait_< Value, float, Op, Value, int >
{
typedef float ret;
};
+
+ template <typename Op>
+ struct set_trait_< Value, bool, Op, Value, bool >
+ {
+ typedef bool ret;
+ };
+
+ template <typename Op>
+ struct set_utrait_< Op, Boolean, bool >
+ {
+ typedef bool ret;
+ };
+
// FIXME: To be continued...
1
0
Index: ChangeLog
from Nicolas Ballas <ballas(a)lrde.epita.fr>
Add fast iterator for image with border in 1d or 2d.
* olena/tests/core/fiter_point1d_b.cc,
* olena/tests/core/fiter_point2d_b.cc: New test.
* olena/tests/core/Makefile.am: Update.
* olena/oln/core/1d/fast_iterator_1d_b.hh:
New fast_iterator for image1d_b.
* olena/oln/core/2d/fast_iterator_2d_b.hh:
New fast_iterator for image1d_b.
* olena/oln/core/1d/fast_iterator_1d.hh,
* olena/oln/core/2d/fast_iterator_2d.hh,
* olena/oln/core/3d/fast_iterator_3d.hh: factorizing some codes
* olena/oln/core/1d/image1d_b.hh,
* olena/oln/core/2d/image2d_b.hh: add method to get the
array associated with the image.
* olena/oln/core/1d/image1d.hh,
* olena/oln/core/2d/image2d.hh,
* olena/oln/core/3d/image3d.hh: Change fiter type.
* olena/oln/core/concept/fast_iterator.hh: factorizing some codes.
* olena/oln/core/internal/fast_iterator_base.hh: New base class
for fast iterator based on image with array.
oln/core/1d/fast_iterator_1d.hh | 95 +++-------------
oln/core/1d/fast_iterator_1d_b.hh | 93 +++++++++++++++
oln/core/1d/image1d.hh | 2
oln/core/1d/image1d_b.hh | 26 ++++
oln/core/2d/fast_iterator_2d.hh | 99 +++-------------
oln/core/2d/fast_iterator_2d_b.hh | 114 +++++++++++++++++++
oln/core/2d/image2d.hh | 2
oln/core/2d/image2d_b.hh | 22 +++
oln/core/3d/fast_iterator_3d.hh | 98 +++-------------
oln/core/3d/image3d.hh | 2
oln/core/concept/fast_iterator.hh | 2
oln/core/internal/fast_iterator_base.hh | 189 ++++++++++++++++++++++++++++++++
tests/core/Makefile.am | 4
tests/core/fiter_point1d_b.cc | 60 ++++++++++
tests/core/fiter_point2d_b.cc | 63 ++++++++++
15 files changed, 633 insertions(+), 238 deletions(-)
Index: olena/tests/core/fiter_point1d_b.cc
--- olena/tests/core/fiter_point1d_b.cc (revision 0)
+++ olena/tests/core/fiter_point1d_b.cc (revision 0)
@@ -0,0 +1,60 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#include <cassert>
+#include <oln/core/1d/image1d_b.hh>
+
+int
+main()
+{
+ using namespace oln;
+
+ image1d_b<int> ima(50, 5);
+
+ image1d_b<int>::piter p(ima.points());
+ image1d_b<int>::fiter f(ima);
+ int i = 0;
+
+ for_all(p)
+ ima(p) = i++;
+
+ i = 0;
+
+ for_all(f)
+ {
+ assert(*f == i ++);
+ *f = 5;
+ }
+
+ for_all(p)
+ assert(ima(p) == 5);
+
+ f.start();
+ assert(f.is_valid());
+ f.invalidate();
+ assert(!f.is_valid());
+}
Index: olena/tests/core/fiter_point2d_b.cc
--- olena/tests/core/fiter_point2d_b.cc (revision 0)
+++ olena/tests/core/fiter_point2d_b.cc (revision 0)
@@ -0,0 +1,63 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#include <cassert>
+#include <oln/core/2d/image2d_b.hh>
+
+
+int
+main()
+{
+ using namespace oln;
+
+ image2d_b<int> ima(2, 5, 2);
+
+ image2d_b<int>::piter p(ima.points());
+ image2d_b<int>::fiter f(ima);
+ int i = 0;
+
+ for_all(p)
+ {
+ ima(p) = i++;
+ }
+
+ i = 0;
+
+ for_all(f)
+ {
+ assert(*f == i ++);
+ *f = 5;
+ }
+
+ for_all(p)
+ assert(ima(p) == 5);
+
+ f.start();
+ assert(f.is_valid());
+ f.invalidate();
+ assert(!f.is_valid());
+}
Index: olena/tests/core/Makefile.am
--- olena/tests/core/Makefile.am (revision 964)
+++ olena/tests/core/Makefile.am (working copy)
@@ -30,6 +30,8 @@
fiter_point1d \
fiter_point2d \
fiter_point3d \
+ fiter_point1d_b \
+ fiter_point2d_b \
neighb2d \
npoints \
point2d \
@@ -52,6 +54,8 @@
fiter_point1d_SOURCES = fiter_point1d.cc
fiter_point2d_SOURCES = fiter_point2d.cc
fiter_point3d_SOURCES = fiter_point3d.cc
+fiter_point1d_b_SOURCES = fiter_point1d_b.cc
+fiter_point2d_b_SOURCES = fiter_point2d_b.cc
neighb2d_SOURCES = neighb2d.cc
npoints_SOURCES = npoints.cc
point2d_SOURCES = point2d.cc
Index: olena/oln/core/1d/image1d.hh
--- olena/oln/core/1d/image1d.hh (revision 964)
+++ olena/oln/core/1d/image1d.hh (working copy)
@@ -62,7 +62,7 @@
typedef image1d<T> plain;
typedef image1d<pl::value> skeleton;
- typedef fast_iterator_1d<value, coord> fiter;
+ typedef fast_iterator_1d<value> fiter;
};
Index: olena/oln/core/1d/image1d_b.hh
--- olena/oln/core/1d/image1d_b.hh (revision 964)
+++ olena/oln/core/1d/image1d_b.hh (working copy)
@@ -32,6 +32,7 @@
# include <oln/core/internal/image_base.hh>
# include <oln/core/internal/utils.hh>
# include <oln/core/1d/array1d.hh>
+# include <oln/core/1d/fast_iterator_1d_b.hh>
namespace oln
@@ -63,6 +64,8 @@
typedef image1d_b<T> plain;
typedef image1d_b<pl::value> skeleton;
+
+ typedef fast_iterator_1d_b<value> fiter;
};
@@ -84,12 +87,17 @@
typedef internal::plain_primitive_image_<current> super;
typedef array1d_<T, int> array_t;
public:
+ //FIXME (fast image concept??)
+ typedef typename vtypes< image1d_b<T> >::fiter fiter;
stc_using(data);
image1d_b();
image1d_b(const box1d& b, unsigned border = 2);
image1d_b(unsigned n, unsigned border = 2);
+ array_t& img_array();
+ const array_t& img_array() const;
+
bool impl_owns_(const point1d& p) const;
const T& impl_read(const point1d& p) const;
@@ -135,7 +143,21 @@
this->data_ = new data(new array_t(- border,
n - 1 + border),
border,
- box1d(0, n - 1));
+ box1d(point1d(0), point1d(n - 1)));
+ }
+
+ template <typename T>
+ typename image1d_b<T>::array_t&
+ image1d_b<T>::img_array()
+ {
+ return this->data_->first;
+ }
+
+ template <typename T>
+ const typename image1d_b<T>::array_t&
+ image1d_b<T>::img_array() const
+ {
+ return this->data_->first;
}
template <typename T>
@@ -201,7 +223,7 @@
{
precondition(not target.has_data());
box1d b;
- bool box_ok = init(b, with, dat);
+ bool box_ok = init5A(b, with, dat);
postcondition(box_ok);
unsigned border = 2; // FIXME: Use init!
array1d_<T,int>* ptr = new array1d_<T,int>(b.pmin().ind() - border,
Index: olena/oln/core/1d/fast_iterator_1d.hh
--- olena/oln/core/1d/fast_iterator_1d.hh (revision 964)
+++ olena/oln/core/1d/fast_iterator_1d.hh (working copy)
@@ -29,109 +29,50 @@
#ifndef OLN_CORE_1D_FAST_ITERATOR_1D_HH
# define OLN_CORE_1D_FAST_ITERATOR_1D_HH
-# include <cassert>
-# include <oln/core/concept/fast_iterator.hh>
+# include <oln/core/internal/fast_iterator_base.hh>
namespace oln
{
// Fwd decl.
template <typename T> class image1d;
- template <typename T, typename C> class fast_iterator_1d;
+ template <typename T> class fast_iterator_1d;
// Super type.
- template <typename T, typename C>
- struct super_trait_< fast_iterator_1d<T, C> >
+ template <typename T>
+ struct super_trait_< fast_iterator_1d<T> >
{
- typedef fast_iterator_1d<T, C> current;
- typedef Fast_Iterator<current> ret;
+ typedef fast_iterator_1d<T> current;
+ typedef internal::fast_iterator_without_b_<current> ret;
};
// Virtual types.
- template <typename T, typename C>
- struct vtypes< fast_iterator_1d<T, C> >
+ template <typename T>
+ struct vtypes< fast_iterator_1d<T> >
{
typedef T value;
};
// Fast iterator for image in one dimension
- template <typename T, typename C>
- class fast_iterator_1d : public Fast_Iterator< fast_iterator_1d<T, C> >
+ template <typename T>
+ class fast_iterator_1d :
+ public internal::fast_iterator_without_b_< fast_iterator_1d<T> >
{
- typedef fast_iterator_1d<T, C> current;
- typedef Fast_Iterator<current> super;
+ typedef fast_iterator_1d<T> current;
+ typedef internal::fast_iterator_without_b_<current> super;
public:
- stc_using(value);
fast_iterator_1d(image1d<T>& ima);
-
- void impl_start();
- void impl_next();
- void impl_invalidate();
- bool impl_is_valid() const;
-
- value& impl_dereference();
- const value& impl_dereference() const;
-
- protected:
- T* start_; // buffer start
- T* current_elt_;
- T* eoi_; // buffer end;
};
# ifndef OLN_INCLUDE_ONLY
// initialize the fields start_ and eoi_, to image buffer start and end
- template <typename T, typename C>
- fast_iterator_1d<T, C>::fast_iterator_1d(image1d<T>& ima)
- {
- start_ = ima.img_array().buffer() + ima.img_array().imin();
- current_elt_ = start_;
- eoi_ = ima.img_array().buffer() + ima.img_array().imax() + 1;
- }
-
- template <typename T, typename C>
- void
- fast_iterator_1d<T, C>::impl_start()
- {
- current_elt_ = start_;
- }
-
- template <typename T, typename C>
- void
- fast_iterator_1d<T, C>::impl_next()
- {
- assert(this->impl_is_valid());
- ++current_elt_;
- }
-
- template <typename T, typename C>
- void
- fast_iterator_1d<T, C>::impl_invalidate()
- {
- current_elt_ = eoi_;
- }
-
- template <typename T, typename C>
- bool
- fast_iterator_1d<T, C>::impl_is_valid() const
- {
- return current_elt_ != eoi_;
- }
-
- template <typename T, typename C>
- typename fast_iterator_1d<T, C>::value&
- fast_iterator_1d<T, C>::impl_dereference()
- {
- assert(this->impl_is_valid());
- return *current_elt_;
- }
-
- template <typename T, typename C>
- const typename fast_iterator_1d<T, C>::value&
- fast_iterator_1d<T, C>::impl_dereference() const
+ template <typename T>
+ fast_iterator_1d<T>::fast_iterator_1d(image1d<T>& ima)
{
- assert(this->impl_is_valid());
- return *current_elt_;
+ this->start_ = ima.img_array().buffer() + ima.img_array().imin();
+ this->current_elt_ = this->start_;
+ this->eoi_ = ima.img_array().buffer() + ima.img_array().imax() + 1;
}
# endif // ! OLN_INCLUDE_ONLY
Index: olena/oln/core/1d/fast_iterator_1d_b.hh
--- olena/oln/core/1d/fast_iterator_1d_b.hh (revision 0)
+++ olena/oln/core/1d/fast_iterator_1d_b.hh (revision 0)
@@ -0,0 +1,93 @@
+// Copyright (C) 2007 EPITA
+// Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_CORE_1D_FAST_ITERATOR_1D_B_HH
+# define OLN_CORE_1D_FAST_ITERATOR_1D_B_HH
+
+# include <oln/core/internal/fast_iterator_base.hh>
+
+namespace oln
+{
+ // Fwd decl.
+ template <typename T> class image1d_b;
+ template <typename T> class fast_iterator_1d_b;
+
+ // Super type.
+ template <typename T>
+ struct super_trait_< fast_iterator_1d_b<T> >
+ {
+ typedef fast_iterator_1d_b<T> current;
+ typedef internal::fast_iterator_base_<current> ret;
+ };
+
+ // Virtual types.
+ template <typename T>
+ struct vtypes< fast_iterator_1d_b<T> >
+ {
+ typedef T value;
+ };
+
+ // Fast iterator for image in one dimension
+ template <typename T>
+ class fast_iterator_1d_b :
+ public internal::fast_iterator_base_< fast_iterator_1d_b<T> >
+ {
+ typedef fast_iterator_1d_b<T> current;
+ typedef internal::fast_iterator_base_<current> super;
+ public:
+
+ fast_iterator_1d_b(image1d_b<T>& ima);
+ void impl_next();
+ };
+
+# ifndef OLN_INCLUDE_ONLY
+
+ // initialize the fields start_ and eoi_, to image buffer start and end
+ template <typename T>
+ fast_iterator_1d_b<T>::fast_iterator_1d_b(image1d_b<T>& ima)
+ {
+ unsigned border = ima.border();
+
+ this->start_ = ima.img_array().buffer() + ima.img_array().imin() + border;
+ this->current_elt_ = this->start_;
+ this->eoi_ = ima.img_array().buffer() + ima.img_array().imax() - border + 1;
+ }
+
+ template <typename T>
+ void
+ fast_iterator_1d_b<T>::impl_next()
+ {
+ ++(this->current_elt_);
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+#endif // OLN_CORE_1D_FAST_ITERATOR_1D_B_HH
+
Index: olena/oln/core/2d/fast_iterator_2d.hh
--- olena/oln/core/2d/fast_iterator_2d.hh (revision 964)
+++ olena/oln/core/2d/fast_iterator_2d.hh (working copy)
@@ -30,110 +30,53 @@
# define OLN_CORE_2D_FAST_ITERATOR_2D_HH
# include <cassert>
-# include <oln/core/concept/fast_iterator.hh>
+# include <oln/core/internal/fast_iterator_base.hh>
namespace oln
{
// Fwd decl.
template <typename T> class image2d;
- template <typename T, typename C> class fast_iterator_2d;
+ template <typename T> class fast_iterator_2d;
// Super type.
- template <typename T, typename C>
- struct super_trait_< fast_iterator_2d<T, C> >
+ template <typename T>
+ struct super_trait_< fast_iterator_2d<T> >
{
- typedef fast_iterator_2d<T, C> current;
- typedef Fast_Iterator<current> ret;
+ typedef fast_iterator_2d<T> current;
+ typedef internal::fast_iterator_without_b_<current> ret;
};
// Virtual types.
- template <typename T, typename C>
- struct vtypes< fast_iterator_2d<T, C> >
+ template <typename T>
+ struct vtypes< fast_iterator_2d<T> >
{
typedef T value;
};
// fast iterator for image2d
- template <typename T, typename C>
- class fast_iterator_2d : public Fast_Iterator< fast_iterator_2d<T, C> >
+ template <typename T>
+ class fast_iterator_2d :
+ public internal::fast_iterator_without_b_< fast_iterator_2d<T> >
{
- typedef fast_iterator_2d<T, C> current;
- typedef Fast_Iterator<current> super;
+ typedef fast_iterator_2d<T> current;
+ typedef internal::fast_iterator_without_b_<current> super;
public:
- stc_using(value);
- fast_iterator_2d(image2d<T>& ima);
- void impl_start();
- void impl_next();
- void impl_invalidate();
- bool impl_is_valid() const;
-
- value& impl_dereference();
- const value& impl_dereference() const;
-
- protected:
- T* start_; // buffer start
- T* current_elt_;
- T* eoi_; // buffer end;
+ fast_iterator_2d(image2d<T>& ima);
};
# ifndef OLN_INCLUDE_ONLY
// initialize the fields start_ and eoi_, to image buffer start and end
- template <typename T, typename C>
- fast_iterator_2d<T, C>::fast_iterator_2d(image2d<T>& ima)
- {
- start_ = ima.img_array().buffer() + ima.img_array().imin() * ima.img_array().jmin() +
- ima.img_array().jmin();
- current_elt_ = start_;
- eoi_ = ima.img_array().buffer() + (ima.img_array().imax() - ima.img_array().imin() + 1) *
- (ima.img_array().jmax() - ima.img_array().imin() + 1);
- }
-
- template <typename T, typename C>
- void
- fast_iterator_2d<T, C>::impl_start()
- {
- current_elt_ = start_;
- }
-
- template <typename T, typename C>
- void
- fast_iterator_2d<T, C>::impl_next()
- {
- assert(this->impl_is_valid());
- ++current_elt_;
- }
-
- template <typename T, typename C>
- void
- fast_iterator_2d<T, C>::impl_invalidate()
- {
- current_elt_ = eoi_;
- }
-
- template <typename T, typename C>
- bool
- fast_iterator_2d<T, C>::impl_is_valid() const
- {
- return current_elt_ != eoi_;
- }
-
- template <typename T, typename C>
- typename fast_iterator_2d<T, C>::value&
- fast_iterator_2d<T, C>::impl_dereference()
- {
- assert(this->impl_is_valid());
- return *current_elt_;
- }
-
- template <typename T, typename C>
- const typename fast_iterator_2d<T, C>::value&
- fast_iterator_2d<T, C>::impl_dereference() const
+ template <typename T>
+ fast_iterator_2d<T>::fast_iterator_2d(image2d<T>& ima)
{
- assert(this->impl_is_valid());
- return *current_elt_;
+ this->start_ = ima.img_array().buffer() +
+ ima.img_array().imin() * ima.img_array().jmin() + ima.img_array().jmin();
+ this->current_elt_ = this->start_;
+ this->eoi_ = ima.img_array().buffer() + (ima.img_array().imax() + 1) *
+ (ima.img_array().jmax() + 1);
}
# endif // ! OLN_INCLUDE_ONLY
Index: olena/oln/core/2d/fast_iterator_2d_b.hh
--- olena/oln/core/2d/fast_iterator_2d_b.hh (revision 0)
+++ olena/oln/core/2d/fast_iterator_2d_b.hh (revision 0)
@@ -0,0 +1,114 @@
+// Copyright (C) 2007 EPITA
+// Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_CORE_2D_FAST_ITERATOR_2D_B_HH
+# define OLN_CORE_2D_FAST_ITERATOR_2D_B_HH
+
+# include <cstddef>
+# include <oln/core/internal/fast_iterator_base.hh>
+
+namespace oln
+{
+ // Fwd decl.
+ template <typename T> class image2d_b;
+ template <typename T> class fast_iterator_2d_b;
+
+ // Super type.
+ template <typename T>
+ struct super_trait_< fast_iterator_2d_b<T> >
+ {
+ typedef fast_iterator_2d_b<T> current;
+ typedef internal::fast_iterator_base_<current> ret;
+ };
+
+ // Virtual types.
+ template <typename T>
+ struct vtypes< fast_iterator_2d_b<T> >
+ {
+ typedef T value;
+ };
+
+ // Fast iterator for image in one dimension
+ template <typename T>
+ class fast_iterator_2d_b :
+ public internal::fast_iterator_base_< fast_iterator_2d_b<T> >
+ {
+ typedef fast_iterator_2d_b<T> current;
+ typedef internal::fast_iterator_base_<current> super;
+ public:
+ stc_using(value);
+
+ fast_iterator_2d_b(image2d_b<T>& ima);
+ void impl_next();
+
+ protected:
+ unsigned border_size_;
+ int line_offset_;
+ value *eor_; // end of row
+ };
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename T>
+ fast_iterator_2d_b<T>::fast_iterator_2d_b(image2d_b<T>& ima) :
+ border_size_(ima.border()), line_offset_(ima.img_array().i_pad())
+ {
+ this->start_ = ima.img_array().buffer() +
+ (this->border_size_) * this->line_offset_ + this->border_size_;
+
+ this->current_elt_ = this->start_;
+
+
+ this->eor_ = ima.img_array().buffer() +
+ (this->border_size_) * this->line_offset_ + this->line_offset_ -
+ this->border_size_;
+
+ this->eoi_ = this->eor_ +
+ this->line_offset_ * (ima.img_array().imax() - this->border_size_);
+
+
+ }
+
+ template <typename T>
+ void
+ fast_iterator_2d_b<T>::impl_next()
+ {
+ ++(this->current_elt_);
+
+ if (this->current_elt_ == this->eor_ and this->current_elt_ != this->eoi_)
+ {
+ this->current_elt_ += 2 * this->border_size_;
+ this->eor_ += this->line_offset_;
+ }
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+#endif // OLN_CORE_2D_FAST_ITERATOR_2D_B_HH
Index: olena/oln/core/2d/image2d.hh
--- olena/oln/core/2d/image2d.hh (revision 964)
+++ olena/oln/core/2d/image2d.hh (working copy)
@@ -62,7 +62,7 @@
typedef image2d<T> plain;
typedef image2d<pl::value> skeleton;
- typedef fast_iterator_2d<value, coord> fiter;
+ typedef fast_iterator_2d<value> fiter;
};
Index: olena/oln/core/2d/image2d_b.hh
--- olena/oln/core/2d/image2d_b.hh (revision 964)
+++ olena/oln/core/2d/image2d_b.hh (working copy)
@@ -33,6 +33,7 @@
# include <oln/core/internal/image_base.hh>
# include <oln/core/internal/utils.hh>
# include <oln/core/2d/array2d.hh>
+# include <oln/core/2d/fast_iterator_2d_b.hh>
namespace oln
@@ -65,6 +66,8 @@
typedef image2d_b<T> plain;
typedef image2d_b<pl::value> skeleton;
+
+ typedef fast_iterator_2d_b<value> fiter;
};
@@ -86,12 +89,17 @@
typedef internal::plain_primitive_image_<current> super;
typedef array2d_<T, int> array_t;
public:
+ //FIXME (fast image concept??)
+ typedef typename vtypes< image2d_b<T> >::fiter fiter;
stc_using(data);
image2d_b();
image2d_b(const box2d& b, unsigned border = 2);
image2d_b(unsigned nrows, unsigned ncols, unsigned border = 2);
+ array_t& img_array();
+ const array_t& img_array() const;
+
bool impl_owns_(const point2d& p) const;
bool impl_has_at(int row, int col) const;
@@ -154,6 +162,20 @@
}
template <typename T>
+ typename image2d_b<T>::array_t&
+ image2d_b<T>::img_array()
+ {
+ return this->data_->first;
+ }
+
+ template <typename T>
+ const typename image2d_b<T>::array_t&
+ image2d_b<T>::img_array() const
+ {
+ return this->data_->first;
+ }
+
+ template <typename T>
bool image2d_b<T>::impl_owns_(const point2d& p) const
{
assert(this->has_data());
Index: olena/oln/core/3d/image3d.hh
--- olena/oln/core/3d/image3d.hh (revision 964)
+++ olena/oln/core/3d/image3d.hh (working copy)
@@ -62,7 +62,7 @@
typedef image3d<T> plain;
typedef image3d<pl::value> skeleton;
- typedef fast_iterator_3d<value, coord> fiter;
+ typedef fast_iterator_3d<value> fiter;
};
Index: olena/oln/core/3d/fast_iterator_3d.hh
--- olena/oln/core/3d/fast_iterator_3d.hh (revision 964)
+++ olena/oln/core/3d/fast_iterator_3d.hh (working copy)
@@ -26,122 +26,64 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_CORE_2D_FAST_ITERATOR_3D_HH
-# define OLN_CORE_2D_FAST_ITERATOR_3D_HH
+#ifndef OLN_CORE_3D_FAST_ITERATOR_3D_HH
+# define OLN_CORE_3D_FAST_ITERATOR_3D_HH
# include <cassert>
-# include <oln/core/concept/fast_iterator.hh>
+# include <oln/core/internal/fast_iterator_base.hh>
namespace oln
{
// Fwd decl.
template <typename T> class image3d;
- template <typename T, typename C> class fast_iterator_3d;
+ template <typename T> class fast_iterator_3d;
// Super type.
- template <typename T, typename C>
- struct super_trait_< fast_iterator_3d<T, C> >
+ template <typename T>
+ struct super_trait_< fast_iterator_3d<T> >
{
- typedef fast_iterator_3d<T, C> current;
- typedef Fast_Iterator<current> ret;
+ typedef fast_iterator_3d<T> current;
+ typedef internal::fast_iterator_without_b_<current> ret;
};
// Virtual types.
- template <typename T, typename C>
- struct vtypes< fast_iterator_3d<T, C> >
+ template <typename T>
+ struct vtypes< fast_iterator_3d<T> >
{
typedef T value;
};
// fast iterator for image3d
- template <typename T, typename C>
- class fast_iterator_3d : public Fast_Iterator< fast_iterator_3d<T, C> >
+ template <typename T>
+ class fast_iterator_3d : public internal::fast_iterator_without_b_< fast_iterator_3d<T> >
{
- typedef fast_iterator_3d<T, C> current;
- typedef Fast_Iterator<current> super;
+ typedef fast_iterator_3d<T> current;
+ typedef internal::fast_iterator_without_b_<current> super;
public:
- stc_using(value);
- fast_iterator_3d(image3d<T>& ima);
- void impl_start();
- void impl_next();
- void impl_invalidate();
- bool impl_is_valid() const;
-
- value& impl_dereference();
- const value& impl_dereference() const;
-
- protected:
- T* start_; // buffer start
- T* current_elt_;
- T* eoi_; // buffer end;
+ fast_iterator_3d(image3d<T>& ima);
};
# ifndef OLN_INCLUDE_ONLY
// initialize the fields start_ and eoi_, to image buffer start and end
- template <typename T, typename C>
- fast_iterator_3d<T, C>::fast_iterator_3d(image3d<T>& ima)
+ template <typename T>
+ fast_iterator_3d<T>::fast_iterator_3d(image3d<T>& ima)
{
- start_ = ima.img_array().buffer() +
+ this->start_ = ima.img_array().buffer() +
ima.img_array().imin() * ima.img_array().jmin() * ima.img_array().kmin() +
ima.img_array().jmin() * ima.img_array().kmin() +
ima.img_array().kmin();
- current_elt_ = start_;
+ this->current_elt_ = this->start_;
- eoi_ = ima.img_array().buffer() +
+ this->eoi_ = ima.img_array().buffer() +
(ima.img_array().imax() - ima.img_array().imin() + 1) *
(ima.img_array().jmax() - ima.img_array().imin() + 1) *
(ima.img_array().kmax() - ima.img_array().kmin() + 1);
}
- template <typename T, typename C>
- void
- fast_iterator_3d<T, C>::impl_start()
- {
- current_elt_ = start_;
- }
-
- template <typename T, typename C>
- void
- fast_iterator_3d<T, C>::impl_next()
- {
- assert(this->impl_is_valid());
- ++current_elt_;
- }
-
- template <typename T, typename C>
- void
- fast_iterator_3d<T, C>::impl_invalidate()
- {
- current_elt_ = eoi_;
- }
-
- template <typename T, typename C>
- bool
- fast_iterator_3d<T, C>::impl_is_valid() const
- {
- return current_elt_ != eoi_;
- }
-
- template <typename T, typename C>
- typename fast_iterator_3d<T, C>::value&
- fast_iterator_3d<T, C>::impl_dereference()
- {
- assert(this->impl_is_valid());
- return *current_elt_;
- }
-
- template <typename T, typename C>
- const typename fast_iterator_3d<T, C>::value&
- fast_iterator_3d<T, C>::impl_dereference() const
- {
- assert(this->impl_is_valid());
- return *current_elt_;
- }
-
# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: olena/oln/core/concept/fast_iterator.hh
--- olena/oln/core/concept/fast_iterator.hh (revision 964)
+++ olena/oln/core/concept/fast_iterator.hh (working copy)
@@ -62,6 +62,7 @@
typename Fast_Iterator<Exact>::value&
Fast_Iterator<Exact>::operator* ()
{
+ precondition(exact(this)->impl_is_valid());
return exact(this)->impl_dereference();
}
@@ -69,6 +70,7 @@
const typename Fast_Iterator<Exact>::value&
Fast_Iterator<Exact>::operator* () const
{
+ precondition(exact(this)->impl_is_valid());
return exact(this)->impl_dereference();
}
Index: olena/oln/core/internal/fast_iterator_base.hh
--- olena/oln/core/internal/fast_iterator_base.hh (revision 0)
+++ olena/oln/core/internal/fast_iterator_base.hh (revision 0)
@@ -0,0 +1,189 @@
+// Copyright (C) 2007 EPITA
+// Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_CORE_INTERNAL_FAST_ITERATOR_BASE_HH
+# define OLN_CORE_INTERNAL_FAST_ITERATOR_BASE_HH
+
+# include <oln/core/concept/fast_iterator.hh>
+
+namespace oln
+{
+
+ // fast iterator on image based on a array
+
+ // Fwd decl.
+ namespace internal { template <typename Exact> class fast_iterator_base_; }
+
+ // Super type.
+ template <typename Exact>
+ struct super_trait_< internal::fast_iterator_base_<Exact> >
+ {
+ typedef Fast_Iterator<Exact> ret;
+ };
+
+ // Virtual types.
+ template <typename Exact>
+ struct vtypes< internal::fast_iterator_base_<Exact> >
+ {
+ typedef stc::abstract value;
+ };
+
+ namespace internal
+ {
+ // Fast iterator for image in one dimension
+ template <typename Exact>
+ class fast_iterator_base_ : public Fast_Iterator< Exact >
+ {
+ typedef fast_iterator_base_<Exact> current;
+ typedef Fast_Iterator<Exact> super;
+ public:
+ stc_using(value);
+
+ void impl_start();
+ void impl_next();
+ void impl_invalidate();
+ bool impl_is_valid() const;
+
+ value& impl_dereference();
+ const value& impl_dereference() const;
+
+ protected:
+ fast_iterator_base_();
+
+ value* start_; // buffer start
+ value* current_elt_;
+ value* eoi_; // buffer end;
+ };
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename Exact>
+ fast_iterator_base_<Exact>::fast_iterator_base_()
+ {
+ }
+
+ template <typename Exact>
+ void
+ fast_iterator_base_<Exact>::impl_start()
+ {
+ this->current_elt_ = this->start_;
+ }
+
+ template <typename Exact>
+ void
+ fast_iterator_base_<Exact>::impl_invalidate()
+ {
+ this->current_elt_ = this->eoi_;
+ }
+
+ template <typename Exact>
+ bool
+ fast_iterator_base_<Exact>::impl_is_valid() const
+ {
+ return this->current_elt_ != this->eoi_;
+ }
+
+ template <typename Exact>
+ typename fast_iterator_base_<Exact>::value&
+ fast_iterator_base_<Exact>::impl_dereference()
+ {
+
+ return *(this->current_elt_);
+ }
+
+ template <typename Exact>
+ const typename fast_iterator_base_<Exact>::value&
+ fast_iterator_base_<Exact>::impl_dereference() const
+ {
+ return *(this->current_elt_);
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace internal
+
+
+ // fast iterator on array image without border
+
+ // Fwd decl.
+ namespace internal
+ {
+ template <typename Exact> class fast_iterator_without_b_;
+ }
+
+ // Super type.
+ template <typename Exact>
+ struct super_trait_< internal::fast_iterator_without_b_<Exact> >
+ {
+ typedef internal::fast_iterator_base_<Exact> ret;
+ };
+
+ // Virtual types.
+ template <typename Exact>
+ struct vtypes< internal::fast_iterator_without_b_<Exact> >
+ {
+ };
+
+ namespace internal
+ {
+
+ template <typename Exact>
+ class fast_iterator_without_b_ : public internal::fast_iterator_base_<Exact>
+ {
+ typedef fast_iterator_without_b_<Exact> current;
+ typedef internal::fast_iterator_base_<Exact> super;
+
+ public:
+ void impl_next();
+
+ protected:
+ fast_iterator_without_b_();
+ };
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename Exact>
+ fast_iterator_without_b_<Exact>::fast_iterator_without_b_()
+ {
+ }
+
+ template <typename Exact>
+ void
+ fast_iterator_without_b_<Exact>::impl_next()
+ {
+ ++(this->current_elt_);
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+
+ } // end of namespace internal
+
+} // end of namespace oln
+
+#endif // OLN_CORE_1D_FAST_ITERATOR_1D_HH
1
0
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Fix cc_tarjan alorithms (4 versions).
* oln/morpho/union_find.hh: Remove.
* oln/morpho/cc_tarjan_v0.hh: New.
* oln/morpho/cc_tarjan_v1.hh: New.
* oln/morpho/cc_tarjan_v2.hh: New.
* oln/morpho/cc_tarjan_v3.hh: New.
* oln/morpho/cc_tarjan_v4.hh: New.
* oln/morpho/union_find_v2.hh: Remove.
* oln/morpho/union_find_procedure.hh: Remove.
* oln/morpho/union_find_v3.hh: Remove.
* oln/morpho/union_find_v4.hh: Remove.
* oln/canvas/two_pass.hh: .
canvas/two_pass.hh | 16 +++----
morpho/cc_tarjan_v1.hh | 95 +++++++++++++++++++++----------------------
morpho/cc_tarjan_v2.hh | 97 ++++++++++++++++++++------------------------
morpho/cc_tarjan_v3.hh | 16 +++----
morpho/cc_tarjan_v4.hh | 107 +++++++++++++++++++++++--------------------------
5 files changed, 158 insertions(+), 173 deletions(-)
Index: oln/morpho/cc_tarjan_v1.hh
--- oln/morpho/cc_tarjan_v1.hh (revision 963)
+++ oln/morpho/cc_tarjan_v1.hh (working copy)
@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_MORPHO_UNION_FIND_HH
-# define OLN_MORPHO_UNION_FIND_HH
+#ifndef OLN_MORPHO_CC_TARJAN_HH
+# define OLN_MORPHO_CC_TARJAN_HH
# include <oln/core/concept/image.hh>
@@ -41,85 +41,82 @@
template <typename I>
oln_plain_value(I, unsigned)
- union_find(const Image_with_Nbh<I>& input);
+ cc_tarjan(const Image_with_Nbh<I>& f);
# ifndef OLN_INCLUDE_ONLY
namespace impl
{
template <typename I>
- struct union_find_
+ struct cc_tarjan_
{
- const I& input;
- oln_plain_value(I, unsigned) output;
+ typedef oln_point(I) point;
- oln_plain(I) is_processed;
- oln_plain_value(I, oln_point(I)) parent;
+ const I& f;
- union_find_(const I& in)
- : input(in)
- {
- prepare(is_processed, with, in);
- prepare(output, with, in);
- prepare(parent, with, in);
- }
-
- oln_point(I)
- find_root(const I& ima,
- const oln_point(I)& x,
- oln_plain_value(I, oln_point(I))& parent)
- {
- if (parent(x) != x)
- {
- parent(x) = find_root(ima, parent(x), parent);
- return parent(x);
- }
- return x;
- }
+ oln_plain_value(I, unsigned) output;
+ oln_plain(I, bool) is_processed;
+ oln_plain_value(I, point) parent;
- void
- do_union(const I& ima,
- const oln_point(I)& n,
- const oln_point(I)& p,
- oln_plain_value(I, oln_point(I))& parent)
+ cc_tarjan_(const I& f)
+ : f(f)
{
- oln_point(I) r = find_root(ima, n, parent);
- if (r != p)
- parent(r) = p;
}
void init()
{
+ prepare(is_processed, with, in);
+ prepare(output, with, in);
+ prepare(parent, with, in);
level::fill(inplace(is_processed), false);
}
- void first_pass_body(const oln_point(I)& p)
+ void first_pass_body(const point& p)
{
parent(p) = p;
- if ( input(p) )
+ if ( f(p) )
{
- oln_niter(I) n(input, p);
+ oln_niter(I) n(f, p);
for_all(n)
{
- if ( input(n) == true and is_processed(n) )
- do_union(input, n, p, parent);
+ if ( f(n) == true and is_processed(n) )
+ do_union(n, p);
}
is_processed(p) = true;
}
}
- void second_pass_body(const oln_point(I)& p)
+ void second_pass_body(const point& p)
{
unsigned current_label = 0;
- if ( input(p) == true and parent(p) == p )
+ if ( f(p) == true and parent(p) == p )
output(p) = ++current_label;
else
output(p) = output(parent(p));
}
- void final()
+ void final() { }
+
+
+ // auxiliary methods
+
+ point find_root(const point& x)
+ {
+ if (parent(x) != x)
+ {
+ parent(x) = find_root(parent(x));
+ return parent(x);
+ }
+ return x;
+ }
+
+ void do_union(const point& n,
+ const point& p)
{
+ point r = find_root(ima, n, parent);
+ if (r != p)
+ parent(r) = p;
}
};
@@ -130,11 +127,11 @@
template <typename I>
oln_plain_value(I, unsigned)
- union_find(const Image_with_Nbh<I>& input)
+ cc_tarjan(const Image_with_Nbh<I>& f)
{
- impl::union_find_<I> f(exact(input));
- canvas::v1::two_pass(f);
- return f.output;
+ impl::cc_tarjan_<I> run(exact(f));
+ canvas::v1::two_pass(run);
+ return run.output;
}
# endif // ! OLN_INCLUDE_ONLY
@@ -144,4 +141,4 @@
} // end of namespace oln
-#endif // ! OLN_MORPHO_UNION_FIND_HH
+#endif // ! OLN_MORPHO_CC_TARJAN_HH
Index: oln/morpho/cc_tarjan_v2.hh
--- oln/morpho/cc_tarjan_v2.hh (revision 963)
+++ oln/morpho/cc_tarjan_v2.hh (working copy)
@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_MORPHO_UNION_FIND_HH
-# define OLN_MORPHO_UNION_FIND_HH
+#ifndef OLN_MORPHO_CC_TARJAN_HH
+# define OLN_MORPHO_CC_TARJAN_HH
# include <oln/core/concept/image.hh>
@@ -41,7 +41,7 @@
template <typename I>
oln_plain_value(I, unsigned)
- union_find(const Image_with_Nbh<I>& input);
+ cc_tarjan(const Image_with_Nbh<I>& f);
# ifndef OLN_INCLUDE_ONLY
@@ -49,76 +49,69 @@
{
template <typename I>
- struct union_find_
+ struct cc_tarjan_
{
- oln_plain_value(I, unsigned) output;
-
- oln_plain(I) is_processed;
- oln_plain_value(I, oln_point(I)) parent;
-
- union_find_(I in)
- {
- prepare(is_processed, with, in);
- prepare(output, with, in);
- prepare(parent, with, in);
- }
-
- oln_point(I)
- find_root(const I& ima,
- const oln_point(I)& x,
- oln_plain_value(I, oln_point(I))& parent)
- {
- if (parent(x) != x)
- {
- parent(x) = find_root(ima, parent(x), parent);
- return parent(x);
- }
- return x;
- }
+ typedef oln_point(I) point;
- void
- do_union(const I& ima,
- const oln_point(I)& n,
- const oln_point(I)& p,
- oln_plain_value(I, oln_point(I))& parent)
- {
- oln_point(I) r = find_root(ima, n, parent);
- if (r != p)
- parent(r) = p;
- }
+ oln_plain_value(I, unsigned) output;
+ oln_plain(I, bool) is_processed;
+ oln_plain_value(I, point) parent;
- void init()
+ void init(I f)
{
+ prepare(is_processed, with, f);
+ prepare(output, with, f);
+ prepare(parent, with, f);
level::fill(inplace(is_processed), false);
}
- void first_pass_body(const oln_point(I)& p, I input)
+ void first_pass_body(const point& p, I f)
{
parent(p) = p;
- if ( input(p) )
+ if ( f(p) )
{
- oln_niter(I) n(input, p);
+ oln_niter(I) n(f, p);
for_all(n)
{
- if ( input(n) == true and is_processed(n) )
- do_union(input, n, p, parent);
+ if ( f(n) == true and is_processed(n) )
+ do_union(f, n, p);
}
is_processed(p) = true;
}
}
- void second_pass_body(const oln_point(I)& p, I input)
+ void second_pass_body(const point& p, I f)
{
unsigned current_label = 0;
- if ( input(p) == true and parent(p) == p )
+ if ( f(p) == true and parent(p) == p )
output(p) = ++current_label;
else
output(p) = output(parent(p));
}
- void final()
+ void final(I f)
+ {
+ }
+
+ point find_root(const I& ima,
+ const point& x)
+ {
+ if (parent(x) != x)
+ {
+ parent(x) = find_root(ima, parent(x));
+ return parent(x);
+ }
+ return x;
+ }
+
+ void do_union(const I& ima,
+ const point& n)
{
+ point r = find_root(ima, n);
+ if (r != p)
+ parent(r) = p;
+ }
};
@@ -128,11 +121,11 @@
template <typename I>
oln_plain_value(I, unsigned)
- union_find(const Image_with_Nbh<I>& input)
+ cc_tarjan(const Image_with_Nbh<I>& f)
{
- impl::union_find_<I> f(exact(input));
- canvas::v2::two_pass(f, input);
- return f.output;
+ impl::cc_tarjan_<I> run(exact(f));
+ canvas::v2::two_pass(run, f);
+ return run.output;
}
# endif // ! OLN_INCLUDE_ONLY
@@ -142,4 +135,4 @@
} // end of namespace oln
-#endif // ! OLN_MORPHO_UNION_FIND_HH
+#endif // ! OLN_MORPHO_CC_TARJAN_HH
Index: oln/morpho/cc_tarjan_v3.hh
--- oln/morpho/cc_tarjan_v3.hh (revision 963)
+++ oln/morpho/cc_tarjan_v3.hh (working copy)
@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_MORPHO_UNION_FIND_HH
-# define OLN_MORPHO_UNION_FIND_HH
+#ifndef OLN_MORPHO_CC_TARJAN_HH
+# define OLN_MORPHO_CC_TARJAN_HH
# include <oln/core/concept/image.hh>
@@ -41,14 +41,14 @@
template <typename I>
oln_plain_value(I, unsigned)
- union_find(const Image_with_Nbh<I>& input);
+ cc_tarjan(const Image_with_Nbh<I>& input);
# ifndef OLN_INCLUDE_ONLY
namespace impl
{
template <typename I>
- struct union_find_
+ struct cc_tarjan_
{
const I& input;
oln_plain_value(I, unsigned) output;
@@ -56,7 +56,7 @@
oln_plain(I) is_processed;
oln_plain_value(I, oln_point(I)) parent;
- union_find_(const I& in)
+ cc_tarjan_(const I& in)
: input(in)
{
prepare(is_processed, with, in);
@@ -130,9 +130,9 @@
template <typename I>
oln_plain_value(I, unsigned)
- union_find(const Image_with_Nbh<I>& input)
+ cc_tarjan(const Image_with_Nbh<I>& input)
{
- impl::union_find_<I> f(exact(input));
+ impl::cc_tarjan_<I> f(exact(input));
canvas::v1::two_pass(f);
return f.output;
}
@@ -144,4 +144,4 @@
} // end of namespace oln
-#endif // ! OLN_MORPHO_UNION_FIND_HH
+#endif // ! OLN_MORPHO_CC_TARJAN_HH
Index: oln/morpho/cc_tarjan_v4.hh
--- oln/morpho/cc_tarjan_v4.hh (revision 963)
+++ oln/morpho/cc_tarjan_v4.hh (working copy)
@@ -25,10 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_MORPHO_UNION_FIND_HH
-# define OLN_MORPHO_UNION_FIND_HH
-
-# include <oln/core/concept/image.hh>
+#ifndef OLN_MORPHO_CC_TARJAN_HH
+# define OLN_MORPHO_CC_TARJAN_HH
# include <oln/canvas/two_pass.hh>
# include <oln/level/fill.hh>
@@ -39,87 +37,84 @@
namespace morpho
{
+ // Fwd declaration.
+
template <typename I>
oln_plain_value(I, unsigned)
- union_find(const Image_with_Nbh<I>& input);
+ cc_tarjan(const Image_with_Nbh<I>& f);
# ifndef OLN_INCLUDE_ONLY
namespace impl
{
- template <typename I>
- struct union_find_
- {
- const I& input;
- oln_plain_value(I, unsigned) output;
-
- oln_plain(I) is_processed;
- oln_plain_value(I, oln_point(I)) parent;
-
- union_find_(const I& in)
- : input(in)
- {
- prepare(is_processed, with, in);
- prepare(output, with, in);
- prepare(parent, with, in);
- }
- oln_point(I)
- find_root(const I& ima,
- const oln_point(I)& x,
- oln_plain_value(I, oln_point(I))& parent)
- {
- if (parent(x) != x)
+ template <typename I>
+ struct cc_tarjan_ : canvas::v4::two_pass<I>
{
- parent(x) = find_root(ima, parent(x), parent);
- return parent(x);
- }
- return x;
- }
+ typedef oln_point(I) point;
- void
- do_union(const I& ima,
- const oln_point(I)& n,
- const oln_point(I)& p,
- oln_plain_value(I, oln_point(I))& parent)
- {
- oln_point(I) r = find_root(ima, n, parent);
- if (r != p)
- parent(r) = p;
- }
+ oln_plain_value(I, unsigned) output;
+ oln_plain_value(I, bool) is_processed;
+ oln_plain_value(I, point) parent;
- void init()
+ void init(I f)
{
+ prepare(is_processed, with, f);
+ prepare(output, with, f);
+ prepare(parent, with, f);
level::fill(inplace(is_processed), false);
}
- void first_pass_body(const oln_point(I)& p)
+ void first_pass_body(const point& p, I f)
{
parent(p) = p;
- if ( input(p) )
+ if ( f(p) )
{
- oln_niter(I) n(input, p);
+ oln_niter(I) n(f, p);
for_all(n)
{
- if ( input(n) == true and is_processed(n) )
- do_union(input, n, p, parent);
+ if ( f(n) == true and is_processed(n) )
+ do_union(f, n, p);
}
is_processed(p) = true;
}
}
- void second_pass_body(const oln_point(I)& p)
+ void second_pass_body(const point& p, I f)
{
unsigned current_label = 0;
- if ( input(p) == true and parent(p) == p )
+ if ( f(p) == true and parent(p) == p )
output(p) = ++current_label;
else
output(p) = output(parent(p));
}
- void final()
+ void final(I f)
+ {
+ }
+
+
+ // auxiliary methods
+
+ point find_root(const I& ima,
+ const point& x)
+ {
+ if (parent(x) != x)
+ {
+ parent(x) = find_root(ima, parent(x));
+ return parent(x);
+ }
+ return x;
+ }
+
+ void do_union(const I& ima,
+ const point& n,
+ const point& p)
{
+ point r = find_root(ima, n);
+ if (r != p)
+ parent(r) = p;
}
};
@@ -130,11 +125,11 @@
template <typename I>
oln_plain_value(I, unsigned)
- union_find(const Image_with_Nbh<I>& input)
+ cc_tarjan(const Image_with_Nbh<I>& f)
{
- impl::union_find_<I> f(exact(input));
- canvas::v1::two_pass(f);
- return f.output;
+ impl::cc_tarjan_<I> f_cc_tarjan(exact(f));
+
+ return f_cc_tarjan.run();
}
# endif // ! OLN_INCLUDE_ONLY
@@ -144,4 +139,4 @@
} // end of namespace oln
-#endif // ! OLN_MORPHO_UNION_FIND_HH
+#endif // ! OLN_MORPHO_CC_TARJAN_HH
Index: oln/canvas/two_pass.hh
--- oln/canvas/two_pass.hh (revision 963)
+++ oln/canvas/two_pass.hh (working copy)
@@ -44,12 +44,12 @@
f.init();
// first pass
- oln_fwd_piter(I) p1(f.input.points());
+ oln_bkd_piter(I) p1(f.input.points());
for_all(p1)
f.first_pass_body(p1);
// second pass
- oln_bkd_piter(I) p2(f.input.points());
+ oln_fwd_piter(I) p2(f.input.points());
for_all(p2)
f.second_pass_body(p2);
@@ -67,12 +67,12 @@
f.init(input);
// first pass
- oln_fwd_piter(I) p1(input.points());
+ oln_bkd_piter(I) p1(input.points());
for_all(p1)
f.first_pass_body(p1, input);
// second pass
- oln_bkd_piter(I) p2(input.points());
+ oln_fwd_piter(I) p2(input.points());
for_all(p2)
f.second_pass_body(p2, input);
@@ -90,12 +90,12 @@
f.init(input, aux);
// first pass
- oln_fwd_piter(I) p1(input.points());
+ oln_bkd_piter(I) p1(input.points());
for_all(p1)
f.first_pass_body(p1, input, aux);
// second pass
- oln_bkd_piter(I) p2(input.points());
+ oln_fwd_piter(I) p2(input.points());
for_all(p2)
f.second_pass_body(p2, input, aux);
@@ -130,12 +130,12 @@
init(input);
// first pass
- oln_fwd_piter(I) p1(input.points());
+ oln_bkd_piter(I) p1(input.points());
for_all(p1)
first_pass_body(p1, input);
// second pass
- oln_bkd_piter(I) p2(input.points());
+ oln_fwd_piter(I) p2(input.points());
for_all(p2)
second_pass_body(p2, input);
1
0