Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Implementations for each canvas propositions.
* oln/morpho/cc_tarjan.hh: Rename union_find_procedure.
* oln/morpho/union_find.hh: Update.
* oln/morpho/union_find_v2.hh: New.
* oln/morpho/union_find_procedure.hh: New.
* oln/morpho/union_find_v3.hh: New.
* oln/morpho/union_find_v4.hh: New.
* oln/canvas/two_pass.hh: update.
canvas/two_pass.hh | 57 ++++++++++++++++--
morpho/union_find.hh | 6 -
morpho/union_find_v2.hh | 145 +++++++++++++++++++++++++++++++++++++++++++++++
morpho/union_find_v3.hh | 147 ++++++++++++++++++++++++++++++++++++++++++++++++
morpho/union_find_v4.hh | 147 ++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 493 insertions(+), 9 deletions(-)
Index: oln/morpho/union_find.hh
--- oln/morpho/union_find.hh (revision 962)
+++ oln/morpho/union_find.hh (working copy)
@@ -90,7 +90,7 @@
void init()
{
- level::fill(is_processed, false);
+ level::fill(inplace(is_processed), false);
}
void first_pass_body(const oln_point(I)& p)
@@ -98,7 +98,7 @@
parent(p) = p;
if ( input(p) )
{
- oln_niter(I) n(p, input);
+ oln_niter(I) n(input, p);
for_all(n)
{
if ( input(n) == true and is_processed(n) )
@@ -133,7 +133,7 @@
union_find(const Image_with_Nbh<I>& input)
{
impl::union_find_<I> f(exact(input));
- canvas::two_pass(f, input);
+ canvas::v1::two_pass(f);
return f.output;
}
Index: oln/morpho/union_find_v2.hh
--- oln/morpho/union_find_v2.hh (revision 0)
+++ oln/morpho/union_find_v2.hh (revision 0)
@@ -0,0 +1,145 @@
+// 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.
+
+#ifndef OLN_MORPHO_UNION_FIND_HH
+# define OLN_MORPHO_UNION_FIND_HH
+
+# include <oln/core/concept/image.hh>
+
+# include <oln/canvas/two_pass.hh>
+# include <oln/level/fill.hh>
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ template <typename I>
+ oln_plain_value(I, unsigned)
+ union_find(const Image_with_Nbh<I>& input);
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ template <typename I>
+ struct union_find_
+ {
+ 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;
+ }
+
+ 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;
+ }
+
+ void init()
+ {
+ level::fill(inplace(is_processed), false);
+ }
+
+ void first_pass_body(const oln_point(I)& p, I input)
+ {
+ parent(p) = p;
+ if ( input(p) )
+ {
+ oln_niter(I) n(input, p);
+ for_all(n)
+ {
+ if ( input(n) == true and is_processed(n) )
+ do_union(input, n, p, parent);
+ }
+ is_processed(p) = true;
+ }
+
+ }
+
+ void second_pass_body(const oln_point(I)& p, I input)
+ {
+ unsigned current_label = 0;
+ if ( input(p) == true and parent(p) == p )
+ output(p) = ++current_label;
+ else
+ output(p) = output(parent(p));
+ }
+
+ void final()
+ {
+
+ };
+
+ } // end of namespace oln::morpho::impl
+
+// Facades.
+
+ template <typename I>
+ oln_plain_value(I, unsigned)
+ union_find(const Image_with_Nbh<I>& input)
+ {
+ impl::union_find_<I> f(exact(input));
+ canvas::v2::two_pass(f, input);
+ return f.output;
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_UNION_FIND_HH
Index: oln/morpho/union_find_v3.hh
--- oln/morpho/union_find_v3.hh (revision 0)
+++ oln/morpho/union_find_v3.hh (revision 0)
@@ -0,0 +1,147 @@
+// 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.
+
+#ifndef OLN_MORPHO_UNION_FIND_HH
+# define OLN_MORPHO_UNION_FIND_HH
+
+# include <oln/core/concept/image.hh>
+
+# include <oln/canvas/two_pass.hh>
+# include <oln/level/fill.hh>
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ template <typename I>
+ oln_plain_value(I, unsigned)
+ union_find(const Image_with_Nbh<I>& input);
+
+# 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)
+ {
+ parent(x) = find_root(ima, parent(x), parent);
+ return parent(x);
+ }
+ return x;
+ }
+
+ 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;
+ }
+
+ void init()
+ {
+ level::fill(inplace(is_processed), false);
+ }
+
+ void first_pass_body(const oln_point(I)& p)
+ {
+ parent(p) = p;
+ if ( input(p) )
+ {
+ oln_niter(I) n(input, p);
+ for_all(n)
+ {
+ if ( input(n) == true and is_processed(n) )
+ do_union(input, n, p, parent);
+ }
+ is_processed(p) = true;
+ }
+
+ }
+
+ void second_pass_body(const oln_point(I)& p)
+ {
+ unsigned current_label = 0;
+ if ( input(p) == true and parent(p) == p )
+ output(p) = ++current_label;
+ else
+ output(p) = output(parent(p));
+ }
+
+ void final()
+ {
+ }
+
+ };
+
+ } // end of namespace oln::morpho::impl
+
+// Facades.
+
+ template <typename I>
+ oln_plain_value(I, unsigned)
+ union_find(const Image_with_Nbh<I>& input)
+ {
+ impl::union_find_<I> f(exact(input));
+ canvas::v1::two_pass(f);
+ return f.output;
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_UNION_FIND_HH
Index: oln/morpho/union_find_v4.hh
--- oln/morpho/union_find_v4.hh (revision 0)
+++ oln/morpho/union_find_v4.hh (revision 0)
@@ -0,0 +1,147 @@
+// 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.
+
+#ifndef OLN_MORPHO_UNION_FIND_HH
+# define OLN_MORPHO_UNION_FIND_HH
+
+# include <oln/core/concept/image.hh>
+
+# include <oln/canvas/two_pass.hh>
+# include <oln/level/fill.hh>
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ template <typename I>
+ oln_plain_value(I, unsigned)
+ union_find(const Image_with_Nbh<I>& input);
+
+# 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)
+ {
+ parent(x) = find_root(ima, parent(x), parent);
+ return parent(x);
+ }
+ return x;
+ }
+
+ 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;
+ }
+
+ void init()
+ {
+ level::fill(inplace(is_processed), false);
+ }
+
+ void first_pass_body(const oln_point(I)& p)
+ {
+ parent(p) = p;
+ if ( input(p) )
+ {
+ oln_niter(I) n(input, p);
+ for_all(n)
+ {
+ if ( input(n) == true and is_processed(n) )
+ do_union(input, n, p, parent);
+ }
+ is_processed(p) = true;
+ }
+
+ }
+
+ void second_pass_body(const oln_point(I)& p)
+ {
+ unsigned current_label = 0;
+ if ( input(p) == true and parent(p) == p )
+ output(p) = ++current_label;
+ else
+ output(p) = output(parent(p));
+ }
+
+ void final()
+ {
+ }
+
+ };
+
+ } // end of namespace oln::morpho::impl
+
+// Facades.
+
+ template <typename I>
+ oln_plain_value(I, unsigned)
+ union_find(const Image_with_Nbh<I>& input)
+ {
+ impl::union_find_<I> f(exact(input));
+ canvas::v1::two_pass(f);
+ return f.output;
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_UNION_FIND_HH
Index: oln/canvas/two_pass.hh
--- oln/canvas/two_pass.hh (revision 962)
+++ oln/canvas/two_pass.hh (working copy)
@@ -25,6 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
+# include <oln/core/concept/image.hh>
+
#ifndef OLN_CANVAS_TWO_PASS_HH
# define OLN_CANVAS_TWO_PASS_HH
@@ -34,10 +36,10 @@
namespace v1
{
template <template <class> class F,
- typename I>
+ typename I> // Data owned by f.
void two_pass(F<I> f)
{
- mlc::assert_< mlc_is_a(I, Image) >::check();
+// mlc::assert_< mlc_is_a(I, Image) >::check();
f.init();
@@ -55,12 +57,12 @@
}
}
- namespace v2
+ namespace v2 // Data owned by f but not input
{
template <typename F, typename I>
void two_pass(F f, I input)
{
- mlc::assert_< mlc_is_a(I, Image) >::check();
+// mlc::assert_< mlc_is_a(I, Image) >::check();
f.init(input);
@@ -78,12 +80,12 @@
}
}
- namespace v3
+ namespace v3 // Auxiliar data given as argument.
{
template <typename F, typename I, typename A>
void two_pass(F f, I input, A aux)
{
- mlc::assert_< mlc_is_a(I, Image) >::check();
+// mlc::assert_< mlc_is_a(I, Image) >::check();
f.init(input, aux);
@@ -101,6 +103,49 @@
}
}
+
+ namespace v4 // Via Inheritens.
+ {
+
+ template <typename I>
+ class two_pass
+ {
+
+ void init(I input) { }
+
+ 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 run(I input)
+ {
+ init(input);
+
+ // first pass
+ oln_fwd_piter(I) p1(input.points());
+ for_all(p1)
+ first_pass_body(p1, input);
+
+ // second pass
+ oln_bkd_piter(I) p2(input.points());
+ for_all(p2)
+ second_pass_body(p2, input);
+
+ final(input);
+ }
+
+ };
+
+ }
+
}
#endif // ! OLN_CANVAS_TWO_PASS_HH
https://svn.lrde.epita.fr/svn/oln/trunk/metalic
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add metalic unconst.
* mlc/unconst.hh: New.
unconst.hh | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 72 insertions(+)
Index: mlc/unconst.hh
--- mlc/unconst.hh (revision 0)
+++ mlc/unconst.hh (revision 0)
@@ -0,0 +1,72 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLC_UNCONST_HH
+# define MLC_UNCONST_HH
+
+
+
+/// Macro mlc_unconst(T).
+
+# define mlc_unconst(T) typename mlc::unconst_< T >::ret
+
+
+
+namespace mlc
+{
+
+ template <typename T>
+ struct unconst_
+ {
+ typedef T ret;
+ };
+
+ template <typename T>
+ struct unconst_< const T >
+ {
+ typedef T ret;
+ };
+
+
+ template <typename T>
+ T& unconst_cast(const T& obj)
+ {
+ return const_cast<T&>(obj);
+ }
+
+ template <typename T>
+ T* unconst_cast(const T* ptr)
+ {
+ return const_cast<T*>(ptr);
+ }
+
+
+
+} // end of namespace mlc
+
+
+#endif // ! MLC_UNCONST_HH
Index: ChangeLog
from Nicolas Ballas <ballas(a)lrde.epita.fr>
fast iterator for image 2d and 3d.
* tests/core/fiter_point1d.cc: Update test.
* tests/core/fiter_point2d.cc:,
* tests/core/fiter_point3d.cc: New test.
* tests/core/Makefile.am: Update.
* oln/core/1d/fast_iterator_1d.hh: remove a useless include.
* oln/core/2d/fast_iterator_2d.hh,
* oln/core/3d/fast_iterator_3d.hh: New fast iterator
* oln/core/2d/image2d.hh,
* oln/core/3d/image3d.hh: add fast iterator on the image
oln/core/1d/fast_iterator_1d.hh | 1
oln/core/2d/fast_iterator_2d.hh | 144 ++++++++++++++++++++++++++++++++++++++
oln/core/2d/image2d.hh | 22 +++++
oln/core/3d/fast_iterator_3d.hh | 150 ++++++++++++++++++++++++++++++++++++++++
oln/core/3d/image3d.hh | 22 +++++
tests/core/Makefile.am | 4 +
tests/core/fiter_point1d.cc | 6 +
tests/core/fiter_point2d.cc | 64 +++++++++++++++++
tests/core/fiter_point3d.cc | 61 ++++++++++++++++
9 files changed, 472 insertions(+), 2 deletions(-)
Index: tests/core/fiter_point1d.cc
--- tests/core/fiter_point1d.cc (revision 959)
+++ tests/core/fiter_point1d.cc (working copy)
@@ -28,7 +28,6 @@
#include <cassert>
#include <oln/core/1d/image1d.hh>
-
int
main()
{
@@ -52,6 +51,11 @@
*f = 5;
}
+ for_all(p)
+ {
+ assert(ima(p) == 5);
+ }
+
f.start();
assert(f.is_valid());
f.invalidate();
Index: tests/core/fiter_point2d.cc
--- tests/core/fiter_point2d.cc (revision 0)
+++ tests/core/fiter_point2d.cc (revision 0)
@@ -0,0 +1,64 @@
+// 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.hh>
+
+
+int
+main()
+{
+ using namespace oln;
+
+ image2d<int> ima(20, 20);
+
+ image2d<int>::piter p(ima.points());
+ image2d<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/fiter_point3d.cc
--- tests/core/fiter_point3d.cc (revision 0)
+++ tests/core/fiter_point3d.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.hh>
+
+
+int
+main()
+{
+ using namespace oln;
+
+ image3d<int> ima(20, 20, 20);
+
+ image3d<int>::piter p(ima.points());
+ image3d<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 959)
+++ tests/core/Makefile.am (working copy)
@@ -28,6 +28,8 @@
iter_point1d \
iter_point2d \
fiter_point1d \
+ fiter_point2d \
+ fiter_point3d \
neighb2d \
npoints \
point2d \
@@ -48,6 +50,8 @@
iter_point1d_SOURCES = iter_point1d.cc
iter_point2d_SOURCES = iter_point2d.cc
fiter_point1d_SOURCES = fiter_point1d.cc
+fiter_point2d_SOURCES = fiter_point2d.cc
+fiter_point3d_SOURCES = fiter_point3d.cc
neighb2d_SOURCES = neighb2d.cc
npoints_SOURCES = npoints.cc
point2d_SOURCES = point2d.cc
Index: oln/core/1d/fast_iterator_1d.hh
--- oln/core/1d/fast_iterator_1d.hh (revision 959)
+++ oln/core/1d/fast_iterator_1d.hh (working copy)
@@ -31,7 +31,6 @@
# include <cassert>
# include <oln/core/concept/fast_iterator.hh>
-# include <oln/core/1d/array1d.hh>
namespace oln
{
Index: oln/core/2d/fast_iterator_2d.hh
--- oln/core/2d/fast_iterator_2d.hh (revision 0)
+++ oln/core/2d/fast_iterator_2d.hh (revision 0)
@@ -0,0 +1,144 @@
+// 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_HH
+# define OLN_CORE_2D_FAST_ITERATOR_2D_HH
+
+# include <cassert>
+# include <oln/core/concept/fast_iterator.hh>
+
+namespace oln
+{
+
+ // Fwd decl.
+ template <typename T> class image2d;
+ template <typename T, typename C> class fast_iterator_2d;
+
+ // Super type.
+ template <typename T, typename C>
+ struct super_trait_< fast_iterator_2d<T, C> >
+ {
+ typedef fast_iterator_2d<T, C> current;
+ typedef Fast_Iterator<current> ret;
+ };
+
+ // Virtual types.
+ template <typename T, typename C>
+ struct vtypes< fast_iterator_2d<T, C> >
+ {
+ typedef T value;
+ };
+
+ // fast iterator for image2d
+ template <typename T, typename C>
+ class fast_iterator_2d : public Fast_Iterator< fast_iterator_2d<T, C> >
+ {
+ typedef fast_iterator_2d<T, C> current;
+ typedef Fast_Iterator<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;
+ };
+
+# 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
+ {
+ assert(this->impl_is_valid());
+ return *current_elt_;
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+
+#endif // !OLN_CORE_2D_FAST_ITERATOR_2D_HH
Index: oln/core/2d/image2d.hh
--- oln/core/2d/image2d.hh (revision 959)
+++ oln/core/2d/image2d.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.hh>
namespace oln
@@ -60,6 +61,8 @@
typedef image2d<T> plain;
typedef image2d<pl::value> skeleton;
+
+ typedef fast_iterator_2d<value, coord> fiter;
};
@@ -81,6 +84,8 @@
typedef internal::plain_primitive_image_<current> super;
typedef array2d_<T, int> array_t;
public:
+ //FIXME (fast image concept??)
+ typedef typename vtypes< image2d<T> >::fiter fiter;
stc_using(data);
image2d();
@@ -88,6 +93,9 @@
image2d(unsigned nrows, unsigned ncols);
image2d(int min_row, int min_col, int max_row, int max_col);
+ 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;
@@ -150,6 +158,20 @@
}
template <typename T>
+ typename image2d<T>::array_t&
+ image2d<T>::img_array()
+ {
+ return this->data_->first;
+ }
+
+ template <typename T>
+ const typename image2d<T>::array_t&
+ image2d<T>::img_array() const
+ {
+ return this->data_->first;
+ }
+
+ template <typename T>
bool image2d<T>::impl_owns_(const point2d& p) const
{
assert(this->has_data());
Index: oln/core/3d/image3d.hh
--- oln/core/3d/image3d.hh (revision 959)
+++ oln/core/3d/image3d.hh (working copy)
@@ -33,6 +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.hh>
namespace oln
@@ -60,6 +61,8 @@
typedef image3d<T> plain;
typedef image3d<pl::value> skeleton;
+
+ typedef fast_iterator_3d<value, coord> fiter;
};
@@ -81,12 +84,17 @@
typedef internal::plain_primitive_image_<current> super;
typedef array3d_<T, int> array_t;
public:
+ //FIXME (fast image concept??)
+ typedef typename vtypes< image3d<T> >::fiter fiter;
stc_using(data);
image3d();
image3d(const box3d& b);
image3d(unsigned nslis, unsigned nrows, unsigned ncols);
+ 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;
@@ -147,6 +155,20 @@
}
template <typename T>
+ typename image3d<T>::array_t&
+ image3d<T>::img_array()
+ {
+ return this->data_->first;
+ }
+
+ template <typename T>
+ const typename image3d<T>::array_t&
+ image3d<T>::img_array() const
+ {
+ return this->data_->first;
+ }
+
+ template <typename T>
bool image3d<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 0)
+++ oln/core/3d/fast_iterator_3d.hh (revision 0)
@@ -0,0 +1,150 @@
+// Copyright (C) 2007
+// EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_CORE_2D_FAST_ITERATOR_3D_HH
+# define OLN_CORE_2D_FAST_ITERATOR_3D_HH
+
+# include <cassert>
+# include <oln/core/concept/fast_iterator.hh>
+
+namespace oln
+{
+
+ // Fwd decl.
+ template <typename T> class image3d;
+ template <typename T, typename C> class fast_iterator_3d;
+
+ // Super type.
+ template <typename T, typename C>
+ struct super_trait_< fast_iterator_3d<T, C> >
+ {
+ typedef fast_iterator_3d<T, C> current;
+ typedef Fast_Iterator<current> ret;
+ };
+
+ // Virtual types.
+ template <typename T, typename C>
+ struct vtypes< fast_iterator_3d<T, C> >
+ {
+ typedef T value;
+ };
+
+ // fast iterator for image3d
+ template <typename T, typename C>
+ class fast_iterator_3d : public Fast_Iterator< fast_iterator_3d<T, C> >
+ {
+ typedef fast_iterator_3d<T, C> current;
+ typedef Fast_Iterator<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;
+ };
+
+# 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)
+ {
+ 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_;
+
+ 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
+
+
+#endif // !OLN_CORE_3D_FAST_ITERATOR_3D_HH
Index: ChangeLog
from Nicolas Ballas <ballas(a)lrde.epita.fr>
fast_iterator for image1d.
* tests/core/fiter_point1d.cc: New test.
* tests/core/3dtorle.cc: Update test (it was too long).
* tests/core/Makefile.am: Update.
* oln/core/1d/image1d.hh: new fiter type.
* oln/core/1d/fast_iterator_1d.hh: New, fast iterator for image 1d.
* oln/core/concept/fast_iterator.hh: New concept (operator* for fast iterators).
oln/core/1d/fast_iterator_1d.hh | 143 ++++++++++++++++++++++++++++++++++++++
oln/core/1d/image1d.hh | 22 +++++
oln/core/concept/fast_iterator.hh | 87 +++++++++++++++++++++++
tests/core/3dtorle.cc | 19 ++---
tests/core/Makefile.am | 2
tests/core/fiter_point1d.cc | 59 +++++++++++++++
6 files changed, 322 insertions(+), 10 deletions(-)
Index: tests/core/fiter_point1d.cc
--- tests/core/fiter_point1d.cc (revision 0)
+++ tests/core/fiter_point1d.cc (revision 0)
@@ -0,0 +1,59 @@
+// 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.hh>
+
+
+int
+main()
+{
+ using namespace oln;
+
+ image1d<int> ima(10);
+
+ image1d<int>::piter p(ima.points());
+ image1d<int>::fiter f(ima);
+ int i = 0;
+
+ for_all(p)
+ {
+ ima(p) = i++;
+ }
+ i = 0;
+
+ for_all(f)
+ {
+ assert(*f == i ++);
+ *f = 5;
+ }
+
+ f.start();
+ assert(f.is_valid());
+ f.invalidate();
+ assert(!f.is_valid());
+}
Index: tests/core/3dtorle.cc
--- tests/core/3dtorle.cc (revision 958)
+++ tests/core/3dtorle.cc (working copy)
@@ -46,7 +46,7 @@
using namespace oln;
// Fill a 3D image with a cos.
- image3d<float> ima3d(100, 100, 100);
+ image3d<float> ima3d(20, 20, 20);
level::fill(inplace(ima3d), my_sinus);
@@ -55,7 +55,7 @@
// value < 0 => -1
// value > 0 => 1
// value next to 0 => 0
- image3d<short> ima3s(100, 100, 100);
+ image3d<short> ima3s(20, 20, 20);
image3d<float>::piter p(ima3d.points());
for_all(p)
{
@@ -79,13 +79,12 @@
ima3rle = rle_encode(ima3s);
rle_image<point3d, short>::piter p1(ima3rle.points());
-// std::cout << "start test" << std::endl;
-// for_all(p1)
-// {
-// // std::cout << "point: " << p1.to_point() << std::endl;
-// // std::cout << "3s : " << ima3s(p1) << std::endl;
-// // std::cout << "rle: " << ima3rle(p1) << std::endl;
-// assert(ima3s(p1) == ima3rle(p1));
-// }
+ for_all(p1)
+ {
+// if (ima3rle(p1))
+// ima3rle(p1) = 42;
+ // this test is too long
+ assert(ima3s(p1) == ima3rle(p1));
+ }
}
Index: tests/core/Makefile.am
--- tests/core/Makefile.am (revision 958)
+++ tests/core/Makefile.am (working copy)
@@ -27,6 +27,7 @@
image2d \
iter_point1d \
iter_point2d \
+ fiter_point1d \
neighb2d \
npoints \
point2d \
@@ -46,6 +47,7 @@
image2d_SOURCES = image2d.cc
iter_point1d_SOURCES = iter_point1d.cc
iter_point2d_SOURCES = iter_point2d.cc
+fiter_point1d_SOURCES = fiter_point1d.cc
neighb2d_SOURCES = neighb2d.cc
npoints_SOURCES = npoints.cc
point2d_SOURCES = point2d.cc
Index: oln/core/1d/image1d.hh
--- oln/core/1d/image1d.hh (revision 958)
+++ oln/core/1d/image1d.hh (working copy)
@@ -33,6 +33,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.hh>
namespace oln
@@ -60,6 +61,8 @@
typedef image1d<T> plain;
typedef image1d<pl::value> skeleton;
+
+ typedef fast_iterator_1d<value, coord> fiter;
};
@@ -81,6 +84,8 @@
typedef internal::plain_primitive_image_<current> super;
typedef array1d_<T, int> array_t;
public:
+ //FIXME (fast image concept??)
+ typedef typename vtypes< image1d<T> >::fiter fiter;
stc_using(data);
image1d();
@@ -89,6 +94,9 @@
image1d(int imin, int imax);
image1d(unsigned n);
+ 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;
@@ -153,6 +161,20 @@
}
template <typename T>
+ typename image1d<T>::array_t&
+ image1d<T>::img_array()
+ {
+ return this->data_->first;
+ }
+
+ template <typename T>
+ const typename image1d<T>::array_t&
+ image1d<T>::img_array() const
+ {
+ return this->data_->first;
+ }
+
+ template <typename T>
bool image1d<T>::impl_owns_(const point1d& p) const
{
assert(this->has_data());
Index: oln/core/1d/fast_iterator_1d.hh
--- oln/core/1d/fast_iterator_1d.hh (revision 0)
+++ oln/core/1d/fast_iterator_1d.hh (revision 0)
@@ -0,0 +1,143 @@
+// 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_HH
+# define OLN_CORE_1D_FAST_ITERATOR_1D_HH
+
+# include <cassert>
+# include <oln/core/concept/fast_iterator.hh>
+# include <oln/core/1d/array1d.hh>
+
+namespace oln
+{
+ // Fwd decl.
+ template <typename T> class image1d;
+ template <typename T, typename C> class fast_iterator_1d;
+
+ // Super type.
+ template <typename T, typename C>
+ struct super_trait_< fast_iterator_1d<T, C> >
+ {
+ typedef fast_iterator_1d<T, C> current;
+ typedef Fast_Iterator<current> ret;
+ };
+
+ // Virtual types.
+ template <typename T, typename C>
+ struct vtypes< fast_iterator_1d<T, C> >
+ {
+ 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> >
+ {
+ typedef fast_iterator_1d<T, C> current;
+ typedef Fast_Iterator<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
+ {
+ assert(this->impl_is_valid());
+ return *current_elt_;
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+#endif // OLN_CORE_1D_FAST_ITERATOR_1D_HH
+
Index: oln/core/concept/fast_iterator.hh
--- oln/core/concept/fast_iterator.hh (revision 0)
+++ oln/core/concept/fast_iterator.hh (revision 0)
@@ -0,0 +1,87 @@
+// 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_FAST_ITERATOR_HH
+# define OLN_CORE_CONCEPT_FAST_ITERATOR_HH
+
+# include <oln/core/concept/iterator.hh>
+
+namespace oln
+{
+
+ // Concept-class "Fast_Iterator".
+ template <typename Exact>
+ struct Fast_Iterator : public Iterator<Exact>
+ {
+ stc_typename(value);
+
+ value& operator* ();
+ const value& operator*() const;
+
+ protected:
+ Fast_Iterator();
+
+ private:
+ void check__() const;
+ };
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename Exact>
+ Fast_Iterator<Exact>::Fast_Iterator()
+ {
+ }
+
+ template <typename Exact>
+ typename Fast_Iterator<Exact>::value&
+ Fast_Iterator<Exact>::operator* ()
+ {
+ return exact(this)->impl_dereference();
+ }
+
+ template <typename Exact>
+ const typename Fast_Iterator<Exact>::value&
+ Fast_Iterator<Exact>::operator* () const
+ {
+ return exact(this)->impl_dereference();
+ }
+
+ template <typename Exact>
+ void Fast_Iterator<Exact>::check__() const
+ {
+ // FIXME
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+
+
+#endif // ! OLN_CORE_CONCEPT_FAST_ITERATOR_HH
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add some linear filters and update.
* oln/convert/to_weighted_window.hh,
* oln/core/1d/weighted_window1d.hh,
* oln/core/3d/weighted_window3d.hh,
* oln/linear/log_5x5.hh,
* oln/linear/laplacian_8_cross.hh,
* oln/linear/laplacian.hh,
* oln/linear/log_7x7.hh,
* oln/linear/laplacian_4.hh,
* oln/linear/log_17x17.hh,
* oln/linear/laplacian_8.hh,
* oln/linear/log_13x13.hh,
* oln/linear/sharpen.hh,
* oln/linear/mean.hh,
* oln/linear/mexican_hat.hh: New.
* tests/core/window2d.cc: Update.
* tests/core/3dtorle.cc: Fix.
* tests/core/neighb2d.cc: Update.
* oln/core/2d/weighted_window2d.hh: Update.
* oln/core/concept/point.hh (check__): Remove.
* oln/core/concept/dpoint.hh (check__): Remove.
* oln/core/concept/window.hh (size): New.
* oln/core/internal/dpoint_base.hh
(impl_op_plus_equal_),
(impl_op_minus_equal_),
(impl_op_minus_): Disambiguate.
* oln/core/internal/f_weighted_window.hh: Update.
* oln/core/internal/dpoints_impl.hh (size): Rename as...
(impl_size): ...this.
* oln/morpho/cc_tarjan.hh: Update.
* oln/linear/convolution.hh: Cosmetic change.
oln/convert/to_weighted_window.hh | 92 +++++++++++++++++++++++++++
oln/core/1d/weighted_window1d.hh | 110 ++++++++++++++++++++++++++++++++
oln/core/2d/weighted_window2d.hh | 6 -
oln/core/3d/weighted_window3d.hh | 112 +++++++++++++++++++++++++++++++++
oln/core/concept/dpoint.hh | 22 ------
oln/core/concept/point.hh | 19 -----
oln/core/concept/window.hh | 8 ++
oln/core/internal/dpoint_base.hh | 8 +-
oln/core/internal/dpoints_impl.hh | 4 -
oln/core/internal/f_weighted_window.hh | 23 ++++++
oln/linear/convolution.hh | 16 ++--
oln/linear/laplacian.hh | 95 +++++++++++++++++++++++++++
oln/linear/laplacian_4.hh | 84 ++++++++++++++++++++++++
oln/linear/laplacian_8.hh | 84 ++++++++++++++++++++++++
oln/linear/laplacian_8_cross.hh | 85 +++++++++++++++++++++++++
oln/linear/log_13x13.hh | 95 +++++++++++++++++++++++++++
oln/linear/log_17x17.hh | 99 +++++++++++++++++++++++++++++
oln/linear/log_5x5.hh | 87 +++++++++++++++++++++++++
oln/linear/log_7x7.hh | 89 ++++++++++++++++++++++++++
oln/linear/mean.hh | 83 ++++++++++++++++++++++++
oln/linear/mexican_hat.hh | 86 +++++++++++++++++++++++++
oln/linear/sharpen.hh | 85 +++++++++++++++++++++++++
oln/morpho/cc_tarjan.hh | 2
tests/core/3dtorle.cc | 2
tests/core/neighb2d.cc | 2
tests/core/window2d.cc | 2
26 files changed, 1335 insertions(+), 65 deletions(-)
Index: tests/core/window2d.cc
--- tests/core/window2d.cc (revision 957)
+++ tests/core/window2d.cc (working copy)
@@ -39,7 +39,7 @@
const oln::Window<W>& win)
{
oln_piter(I) p(input.points());
- oln_qiter(W) q(p, win);
+ oln_qiter(W) q(win, p);
unsigned count = 0;
for_all(p)
for_all(q)
Index: tests/core/3dtorle.cc
--- tests/core/3dtorle.cc (revision 957)
+++ tests/core/3dtorle.cc (working copy)
@@ -36,7 +36,7 @@
float my_sinus(const oln::point3d& p)
{
- return sin(p.sli() + p.row() + p.col());
+ return std::sin(float(p.sli() + p.row() + p.col()));
}
Index: tests/core/neighb2d.cc
--- tests/core/neighb2d.cc (revision 957)
+++ tests/core/neighb2d.cc (working copy)
@@ -38,7 +38,7 @@
unsigned run(const oln::Image_with_Nbh<I>& input)
{
oln_piter(I) p(input.points());
- oln_niter(I) n(p, input);
+ oln_niter(I) n(input, p);
unsigned count = 0;
for_all(p)
Index: oln/convert/to_weighted_window.hh
--- oln/convert/to_weighted_window.hh (revision 0)
+++ oln/convert/to_weighted_window.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_CONVERT_TO_WEIGHTED_WINDOW_HH
+# define OLN_CONVERT_TO_WEIGHTED_WINDOW_HH
+
+# include <oln/core/concept/image.hh>
+# include <oln/core/concept/window.hh>
+# include <oln/core/concept/function.hh>
+# include <oln/core/internal/f_weighted_window.hh>
+
+
+namespace oln
+{
+
+ namespace convert
+ {
+
+ // Fwd decl.
+
+ template <typename I>
+ oln_f_image_to_weighted_window(I)
+ to_weighted_window(const Image<I>& input);
+
+
+ template <typename F, typename W>
+ oln_f_weighted_window(oln_result(F), oln_dpoint(W))
+ to_weighted_window(const Function_p2v<F>& weight, // FIXME: should be Function_dp2v?
+ const Window<W>& win);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ // Generic versions.
+
+ template <typename I>
+ 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 - p.to_point()); // FIXME: zero - p
+ return output;
+ }
+
+ template <typename F, typename W>
+ oln_f_weighted_window(oln_result(F), oln_dpoint(W))
+ 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);
+ for_all(q)
+ output.take(weight_(q), O - q.to_point());
+ return output;
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::convert
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CONVERT_TO_WEIGHTED_WINDOW_HH
Index: oln/core/1d/weighted_window1d.hh
--- oln/core/1d/weighted_window1d.hh (revision 0)
+++ oln/core/1d/weighted_window1d.hh (revision 0)
@@ -0,0 +1,110 @@
+// 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_WEIGHTED_WINDOW1D_HH
+# define OLN_CORE_1D_WEIGHTED_WINDOW1D_HH
+
+# include <cmath>
+# include <oln/core/internal/weighted_window.hh>
+# include <oln/core/1d/dpoint1d.hh>
+
+
+
+namespace oln
+{
+
+
+ // Fwd decl.
+ template <typename W> class weighted_window1d;
+
+
+# define current weighted_window1d<W>
+# define super internal::weighted_window_< current >
+
+
+ // Super type.
+ template <typename W>
+ struct super_trait_< current >
+ {
+ typedef super ret;
+ };
+
+
+ // Virtual types.
+ template <typename W>
+ struct vtypes< current >
+ {
+ typedef W weight;
+ typedef point1d point;
+ };
+
+
+ /// Generic classical weighted_window1d class.
+
+ template <typename W>
+ class weighted_window1d : public super
+ {
+ public:
+ stc_using(weight);
+
+ weighted_window1d();
+
+ template <unsigned n>
+ void impl_fill_with(const weight (&values)[n]);
+
+ }; // end of class oln::weighted_window1d<W>
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename W>
+ weighted_window1d<W>::weighted_window1d()
+ {
+ }
+
+ template <typename W>
+ template <unsigned n>
+ void
+ weighted_window1d<W>::impl_fill_with(const weight (&values)[n])
+ {
+ precondition(n % 2 = 1);
+ int h = int(n) / 2;
+ unsigned i = 0;
+ for (int dind = -h; dind <= h; ++dind)
+ this->take(values[i++], dpoint1d(dind));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+# undef super
+# undef current
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_1D_WEIGHTED_WINDOW1D_HH
Index: oln/core/2d/weighted_window2d.hh
--- oln/core/2d/weighted_window2d.hh (revision 957)
+++ oln/core/2d/weighted_window2d.hh (working copy)
@@ -97,11 +97,7 @@
unsigned i = 0;
for (int drow = -h; drow <= h; ++drow)
for (int dcol = -h; dcol <= h; ++dcol)
- {
- if (values[i] != 0)
- this->take(values[i], dpoint2d(drow, dcol));
- ++i;
- }
+ this->take(values[i++], dpoint2d(drow, dcol));
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/core/3d/weighted_window3d.hh
--- oln/core/3d/weighted_window3d.hh (revision 0)
+++ oln/core/3d/weighted_window3d.hh (revision 0)
@@ -0,0 +1,112 @@
+// 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_3D_WEIGHTED_WINDOW3D_HH
+# define OLN_CORE_3D_WEIGHTED_WINDOW3D_HH
+
+# include <cmath>
+# include <oln/core/internal/weighted_window.hh>
+# include <oln/core/3d/dpoint3d.hh>
+
+
+
+namespace oln
+{
+
+
+ // Fwd decl.
+ template <typename W> class weighted_window3d;
+
+
+# define current weighted_window3d<W>
+# define super internal::weighted_window_< current >
+
+
+ // Super type.
+ template <typename W>
+ struct super_trait_< current >
+ {
+ typedef super ret;
+ };
+
+
+ // Virtual types.
+ template <typename W>
+ struct vtypes< current >
+ {
+ typedef W weight;
+ typedef point3d point;
+ };
+
+
+ /// Generic classical weighted_window3d class.
+
+ template <typename W>
+ class weighted_window3d : public super
+ {
+ public:
+ stc_using(weight);
+
+ weighted_window3d();
+
+ template <unsigned n>
+ void impl_fill_with(const weight (&values)[n]);
+
+ }; // end of class oln::weighted_window3d<W>
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename W>
+ weighted_window3d<W>::weighted_window3d()
+ {
+ }
+
+ template <typename W>
+ template <unsigned n>
+ void
+ weighted_window3d<W>::impl_fill_with(const weight (&values)[n])
+ {
+ int h = int(std::pow(n, 1./3.)) / 2;
+ precondition((2 * h + 1) * (2 * h + 1) * (2 * h + 1) = n);
+ unsigned i = 0;
+ for (int dsli = -h; dsli <= h; ++dsli)
+ for (int drow = -h; drow <= h; ++drow)
+ for (int dcol = -h; dcol <= h; ++dcol)
+ this->take(values[i++], dpoint3d(dsli, drow, dcol));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+# undef super
+# undef current
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_3D_WEIGHTED_WINDOW3D_HH
Index: oln/core/concept/point.hh
--- oln/core/concept/point.hh (revision 957)
+++ oln/core/concept/point.hh (working copy)
@@ -82,9 +82,6 @@
protected:
Point();
- private:
- void check__() const;
-
}; // end of oln::Point<Exact>
@@ -178,7 +175,6 @@
template <typename Exact>
Point<Exact>::Point()
{
- this->check__();
// FIXME: Uncomment!
// mlc::assert_defined_< oln_vtype(Exact, grid) >::check();
// mlc::assert_defined_< oln_vtype(Exact, dPoint) >::check();
@@ -186,21 +182,6 @@
// mlc::assert_defined_< oln_vtype(Exact, dim) >::check();
}
- template <typename Exact>
- void Point<Exact>::check__() const
- {
- bool (Exact::*impl_op_equal_adr)(const Exact& rhs) const = & Exact::impl_op_equal_;
- impl_op_equal_adr = 0;
- bool (Exact::*impl_op_less_adr)(const Exact& rhs) const = & Exact::impl_op_less_;
- impl_op_less_adr = 0;
- Exact& (Exact::*impl_op_plus_equal_adr)(const dpoint& rhs) = & Exact::impl_op_plus_equal_;
- impl_op_plus_equal_adr = 0;
- Exact& (Exact::*impl_op_minus_equal_adr)(const dpoint& rhs) = & Exact::impl_op_minus_equal_;
- impl_op_minus_equal_adr = 0;
- dpoint (Exact::*impl_op_minus_adr)(const Exact& rhs) const = & Exact::impl_op_minus_;
- impl_op_minus_adr = 0;
- }
-
template <typename P>
typename P::dpoint
operator-(const Point<P>& lhs, const Point<P>& rhs)
Index: oln/core/concept/dpoint.hh
--- oln/core/concept/dpoint.hh (revision 957)
+++ oln/core/concept/dpoint.hh (working copy)
@@ -80,9 +80,6 @@
protected:
Dpoint();
- private:
- void check__() const;
-
}; // end of oln::Dpoint<Exact>
@@ -170,7 +167,6 @@
template <typename Exact>
Dpoint<Exact>::Dpoint()
{
- this->check__();
// FIXME: Uncomment!
// mlc::assert_defined_< oln_vtype(Exact, grid) >::check();
// mlc::assert_defined_< oln_vtype(Exact, point) >::check();
@@ -179,24 +175,6 @@
}
- template <typename Exact>
- void Dpoint<Exact>::check__() const
- {
- bool (Exact::*impl_op_equal_adr)(const Exact& rhs) const = & Exact::impl_op_equal_;
- impl_op_equal_adr = 0;
- bool (Exact::*impl_op_less_adr)(const Exact& rhs) const = & Exact::impl_op_less_;
- impl_op_less_adr = 0;
- Exact& (Exact::*impl_op_plus_equal_adr)(const Exact& rhs) = & Exact::impl_op_plus_equal_;
- impl_op_plus_equal_adr = 0;
- Exact& (Exact::*impl_op_minus_equal_adr)(const Exact& rhs) = & Exact::impl_op_minus_equal_;
- impl_op_minus_equal_adr = 0;
- Exact& (Exact::*impl_op_mod_equal_adr)(const Exact& rhs) = & Exact::impl_op_mod_equal_;
- impl_op_mod_equal_adr = 0;
- Exact (Exact::*impl_op_unary_minus_adr)() const = & Exact::impl_op_unary_minus_;
- impl_op_unary_minus_adr = 0;
- }
-
-
/// \{
/// Operators.
Index: oln/core/concept/window.hh
--- oln/core/concept/window.hh (revision 957)
+++ oln/core/concept/window.hh (working copy)
@@ -48,6 +48,7 @@
stc_typename(bkd_qiter);
Exact op_unary_minus_() const;
+ unsigned size() const;
protected:
Window();
@@ -70,6 +71,13 @@
return exact(this)->impl_op_unary_minus_();
}
+ template <typename Exact>
+ unsigned
+ Window<Exact>::size() const
+ {
+ return exact(this)->impl_size();
+ }
+
# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/internal/dpoint_base.hh
--- oln/core/internal/dpoint_base.hh (revision 957)
+++ oln/core/internal/dpoint_base.hh (working copy)
@@ -204,7 +204,8 @@
Exact&
point_base_<Exact>::impl_op_plus_equal_(const typename point_base_<Exact>::dpoint& rhs)
{
- this->v_ += rhs.vec();
+ typedef typename point_base_<Exact>::dpoint dpoint__;
+ this->v_ += rhs.dpoint_base_<dpoint__>::vec();
return exact(*this);
}
@@ -212,7 +213,8 @@
Exact&
point_base_<Exact>::impl_op_minus_equal_(const typename point_base_<Exact>::dpoint& rhs)
{
- this->v_ -= rhs.vec();
+ typedef typename point_base_<Exact>::dpoint dpoint__;
+ this->v_ -= rhs.dpoint_base_<dpoint__>::vec();
return exact(*this);
}
@@ -221,7 +223,7 @@
point_base_<Exact>::impl_op_minus_(const Exact& rhs) const
{
typename point_base_<Exact>::dpoint tmp;
- tmp.vec() = this->v_ - rhs.vec();
+ tmp.vec() = this->v_ - rhs.point_base_<Exact>::vec();
return tmp;
}
Index: oln/core/internal/f_weighted_window.hh
--- oln/core/internal/f_weighted_window.hh (revision 957)
+++ oln/core/internal/f_weighted_window.hh (working copy)
@@ -28,12 +28,17 @@
#ifndef OLN_CORE_INTERNAL_F_WEIGHTED_WINDOW_HH
# define OLN_CORE_INTERNAL_F_WEIGHTED_WINDOW_HH
+# include <mlc/basic.hh>
# include <oln/core/concept/dpoint.hh>
# include <oln/core/concept/weighted_window.hh>
# define oln_f_weighted_window(W, Dp) \
-typename oln::internal::f_weighted_window_< W, Dp >::ret
+typename oln::internal::f_weighted_window_< mlc_basic( W ), Dp >::ret
+
+
+# define oln_f_image_to_weighted_window(I) \
+typename oln::internal::f_weighted_window_< oln_value(I), oln_dpoint(I) >::ret
namespace oln
@@ -51,7 +56,9 @@
// Weighted window types.
+ template <typename W> struct weighted_window1d;
template <typename W> struct weighted_window2d;
+ template <typename W> struct weighted_window3d;
template <typename W, typename Dp> class weighted_window;
/// \}
@@ -75,12 +82,24 @@
};
template <typename W>
+ struct weighted_window__< W, dpoint1d >
+ {
+ typedef weighted_window1d<W> ret;
+ };
+
+ template <typename W>
struct weighted_window__< W, dpoint2d >
{
typedef weighted_window2d<W> ret;
};
- // FIXME: 1D, 3D, 2D hex/tri...
+ // FIXME: 2D hex/tri...
+
+ template <typename W>
+ struct weighted_window__< W, dpoint3d >
+ {
+ typedef weighted_window3d<W> ret;
+ };
/// \}
Index: oln/core/internal/dpoints_impl.hh
--- oln/core/internal/dpoints_impl.hh (revision 957)
+++ oln/core/internal/dpoints_impl.hh (working copy)
@@ -49,7 +49,7 @@
{
public:
- unsigned size() const;
+ unsigned impl_size() const;
const Dp& operator[](unsigned i) const;
const std::vector<Dp>& dpoints() const;
bool has(const Dp& dp) const;
@@ -87,7 +87,7 @@
template <typename Dp>
unsigned
- dpoints_impl_<Dp>::size() const
+ dpoints_impl_<Dp>::impl_size() const
{
return v_.size();
}
Index: oln/morpho/cc_tarjan.hh
--- oln/morpho/cc_tarjan.hh (revision 957)
+++ oln/morpho/cc_tarjan.hh (working copy)
@@ -81,7 +81,7 @@
parent(p) = p;
if ( input(p) )
{
- oln_niter(I) n(p, input);
+ oln_niter(I) n(input, p);
for_all(n)
{
if ( input(n) = true and is_processed(n) )
Index: oln/linear/log_5x5.hh
--- oln/linear/log_5x5.hh (revision 0)
+++ oln/linear/log_5x5.hh (revision 0)
@@ -0,0 +1,87 @@
+// 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_LINEAR_LOG_5X5_HH
+# define OLN_LINEAR_LOG_5X5_HH
+
+# include <oln/linear/convolution.hh>
+# include <oln/core/2d/weighted_window2d.hh>
+
+
+namespace oln
+{
+
+ namespace linear
+ {
+
+ // Fwd decl.
+
+ template <typename V, typename I>
+ oln_plain_value(I, V)
+ log_5x5(const Image_2D<I>& f);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic versions.
+
+ template <typename V, typename I>
+ oln_plain_value(I, V)
+ log_5x5_(const Image_2D<I>& f)
+ {
+ // Ref: Cf. Sonka et al., pages 85-86.
+ static int values[] = { 0, 0, -1, 0, 0,
+ 0, -1, -2, -1, 0,
+ -1, -2, 16, -2, -1,
+ 0, -1, -2, -1, 0,
+ 0, 0, -1, 0, 0 };
+ return oln::linear::convolution<V>(f, values);
+ }
+
+ } // end of namespace oln::linear::impl
+
+
+ // Facade.
+
+ template <typename V, typename I>
+ oln_plain_value(I, V)
+ log_5x5(const Image_2D<I>& f)
+ {
+ return impl::log_5x5_<V>(f);
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::linear
+
+} // end of namespace oln
+
+
+#endif // ! OLN_LINEAR_LOG_5X5_HH
Index: oln/linear/laplacian_8_cross.hh
--- oln/linear/laplacian_8_cross.hh (revision 0)
+++ oln/linear/laplacian_8_cross.hh (revision 0)
@@ -0,0 +1,85 @@
+// 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_LINEAR_LAPLACIAN_8_cross_HH
+# define OLN_LINEAR_LAPLACIAN_8_cross_HH
+
+# include <oln/linear/convolution.hh>
+# include <oln/core/2d/weighted_window2d.hh>
+
+
+namespace oln
+{
+
+ namespace linear
+ {
+
+ // Fwd decl.
+
+ template <typename V, typename I>
+ oln_plain_value(I, V)
+ laplacian_8_cross(const Image_2D<I>& f);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename V, typename I>
+ oln_plain_value(I, V)
+ laplacian_8_cross_(const Image_2D<I>& f)
+ {
+ static int values[] = { 2, -1, 2,
+ -1, -4, -1,
+ 2, -1, 2 };
+ return oln::linear::convolution<V>(f, values);
+ }
+
+
+ } // end of namespace oln::linear::impl
+
+
+ // Facade.
+
+ template <typename V, typename I>
+ oln_plain_value(I, V)
+ laplacian_8_cross(const Image_2D<I>& f)
+ {
+ return impl::laplacian_8_cross_<V>(f);
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::linear
+
+} // end of namespace oln
+
+
+#endif // ! OLN_LINEAR_LAPLACIAN_8_cross_HH
Index: oln/linear/laplacian.hh
--- oln/linear/laplacian.hh (revision 0)
+++ oln/linear/laplacian.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_LINEAR_LAPLACIAN_HH
+# define OLN_LINEAR_LAPLACIAN_HH
+
+
+# ifdef OLN_ENV_2D
+# include <oln/linear/laplacian_4.hh>
+# endif // ! OLN_ENV_2D
+
+// FIXME: 1D, 3D, ...
+
+
+
+namespace oln
+{
+
+ namespace linear
+ {
+
+ // Fwd decl.
+
+ template <typename V, typename I>
+ oln_plain_value(I, V)
+ laplacian(const Image<I>& f);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Dispatch w.r.t. image dimension.
+
+
+# ifdef OLN_ENV_2D
+
+ template <typename V, typename I>
+ oln_plain_value(I, V)
+ laplacian_(const Image_2D<I>& f)
+ {
+ return oln::linear::laplacian_4<V>(f);
+ }
+
+# endif // ! OLN_ENV_2D
+
+
+ // FIXME: 1D, 3D, ...
+
+
+ } // end of namespace oln::linear::impl
+
+
+ // Facade.
+
+ template <typename V, typename I>
+ oln_plain_value(I, V)
+ laplacian(const Image<I>& f)
+ {
+ return impl::laplacian_<V>(f);
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::linear
+
+} // end of namespace oln
+
+
+#endif // ! OLN_LINEAR_LAPLACIAN_HH
Index: oln/linear/log_7x7.hh
--- oln/linear/log_7x7.hh (revision 0)
+++ oln/linear/log_7x7.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_LINEAR_LOG_7X7_HH
+# define OLN_LINEAR_LOG_7X7_HH
+
+# include <oln/linear/convolution.hh>
+# include <oln/core/2d/weighted_window2d.hh>
+
+
+namespace oln
+{
+
+ namespace linear
+ {
+
+ // Fwd decl.
+
+ template <typename V, typename I>
+ oln_plain_value(I, V)
+ log_7x7(const Image_2D<I>& f);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic versions.
+
+ template <typename V, typename I>
+ oln_plain_value(I, V)
+ log_7x7_(const Image_2D<I>& f)
+ {
+ // Ref: Cf. Russ, p. 250.
+ static int values[] = { 0, 0, -1, -1, -1, 0, 0,
+ 0, -1, -3, -3, -3, -1, 0,
+ -1, -3, 0, 7, 0, -3, -1,
+ -1, -3, 7, 24, 7, -3, -1,
+ -1, -3, 0, 7, 0, -3, -1,
+ 0, -1, -3, -3, -3, -1, 0,
+ 0, 0, -1, -1, -1, 0, 0 };
+ return oln::linear::convolution<V>(f, values);
+ }
+
+ } // end of namespace oln::linear::impl
+
+
+ // Facade.
+
+ template <typename V, typename I>
+ oln_plain_value(I, V)
+ log_7x7(const Image_2D<I>& f)
+ {
+ return impl::log_7x7_<V>(f);
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::linear
+
+} // end of namespace oln
+
+
+#endif // ! OLN_LINEAR_LOG_7X7_HH
Index: oln/linear/laplacian_4.hh
--- oln/linear/laplacian_4.hh (revision 0)
+++ oln/linear/laplacian_4.hh (revision 0)
@@ -0,0 +1,84 @@
+// 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_LINEAR_LAPLACIAN_4_HH
+# define OLN_LINEAR_LAPLACIAN_4_HH
+
+# include <oln/linear/convolution.hh>
+# include <oln/core/2d/weighted_window2d.hh>
+
+
+namespace oln
+{
+
+ namespace linear
+ {
+
+ // Fwd decl.
+
+ template <typename V, typename I>
+ oln_plain_value(I, V)
+ laplacian_4(const Image_2D<I>& f);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic versions.
+
+ template <typename V, typename I>
+ oln_plain_value(I, V)
+ laplacian_4_(const Image_2D<I>& f)
+ {
+ static int values[] = { 0, 1, 0,
+ 1, -4, 1,
+ 0, 1, 0 };
+ return oln::linear::convolution<V>(f, values);
+ }
+
+ } // end of namespace oln::linear::impl
+
+
+ // Facade.
+
+ template <typename V, typename I>
+ oln_plain_value(I, V)
+ laplacian_4(const Image_2D<I>& f)
+ {
+ return impl::laplacian_4_<V>(f);
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::linear
+
+} // end of namespace oln
+
+
+#endif // ! OLN_LINEAR_LAPLACIAN_4_HH
Index: oln/linear/log_17x17.hh
--- oln/linear/log_17x17.hh (revision 0)
+++ oln/linear/log_17x17.hh (revision 0)
@@ -0,0 +1,99 @@
+// 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_LINEAR_LOG_17X17_HH
+# define OLN_LINEAR_LOG_17X17_HH
+
+# include <oln/linear/convolution.hh>
+# include <oln/core/2d/weighted_window2d.hh>
+
+
+namespace oln
+{
+
+ namespace linear
+ {
+
+ // Fwd decl.
+
+ template <typename V, typename I>
+ oln_plain_value(I, V)
+ log_17x17(const Image_2D<I>& f);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic versions.
+
+ template <typename V, typename I>
+ oln_plain_value(I, V)
+ log_17x17_(const Image_2D<I>& f)
+ {
+ // Ref: Cf. Sonka et al., pages 85-86.
+ static int values[] = { 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0,
+ 0, 0, -1, -1, -1, -2, -3, -3, -3, -3, -3, -2, -1, -1, -1, 0, 0,
+ 0, 0, -1, -1, -2, -3, -3, -3, -3, -3, -3, -3, -2, -1, -1, 0, 0,
+ 0, -1, -1, -2, -3, -3, -3, -2, -3, -2, -3, -3, -3, -2, -1, -1, 0,
+ 0, -1, -2, -3, -3, -3, 0, 2, 4, 2, 0, -3, -3, -3, -2, -1, 0,
+ -1, -1, -3, -3, -3, 0, 4, 10, 12, 10, 4, 0, -3, -3, -3, -1, -1,
+ -1, -1, -3, -3, -2, 2, 10, 18, 21, 18, 10, 2, -2, -3, -3, -1, -1,
+ -1, -1, -3, -3, -3, 4, 12, 21, 24, 21, 12, 4, -3, -3, -3, -1, -1,
+ -1, -1, -3, -3, -2, 2, 10, 18, 21, 18, 10, 2, -2, -3, -3, -1, -1,
+ -1, -1, -3, -3, -3, 0, 4, 10, 12, 10, 4, 0, -3, -3, -3, -1, -1,
+ 0, -1, -2, -3, -3, -3, 0, 2, 4, 2, 0, -3, -3, -3, -2, -1, 0,
+ 0, -1, -1, -2, -3, -3, -3, -2, -3, -2, -3, -3, -3, -2, -1, -1, 0,
+ 0, 0, -1, -1, -2, -3, -3, -3, -3, -3, -3, -3, -2, -1, -1, 0, 0,
+ 0, 0, -1, -1, -1, -2, -3, -3, -3, -3, -3, -2, -1, -1, -1, 0, 0,
+ 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0 };
+ return oln::linear::convolution<V>(f, values);
+ }
+
+ } // end of namespace oln::linear::impl
+
+
+ // Facade.
+
+ template <typename V, typename I>
+ oln_plain_value(I, V)
+ log_17x17(const Image_2D<I>& f)
+ {
+ return impl::log_17x17_<V>(f);
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::linear
+
+} // end of namespace oln
+
+
+#endif // ! OLN_LINEAR_LOG_17X17_HH
Index: oln/linear/laplacian_8.hh
--- oln/linear/laplacian_8.hh (revision 0)
+++ oln/linear/laplacian_8.hh (revision 0)
@@ -0,0 +1,84 @@
+// 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_LINEAR_LAPLACIAN_8_HH
+# define OLN_LINEAR_LAPLACIAN_8_HH
+
+# include <oln/linear/convolution.hh>
+# include <oln/core/2d/weighted_window2d.hh>
+
+
+namespace oln
+{
+
+ namespace linear
+ {
+
+ // Fwd decl.
+
+ template <typename V, typename I>
+ oln_plain_value(I, V)
+ laplacian_8(const Image_2D<I>& f);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic versions.
+
+ template <typename V, typename I>
+ oln_plain_value(I, V)
+ laplacian_8_(const Image_2D<I>& f)
+ {
+ static int values[] = { -1, 2, -1,
+ 2, -4, 2,
+ -1, 2, -1 };
+ return oln::linear::convolution<V>(f, values);
+ }
+
+ } // end of namespace oln::linear::impl
+
+
+ // Facade.
+
+ template <typename V, typename I>
+ oln_plain_value(I, V)
+ laplacian_8(const Image_2D<I>& f)
+ {
+ return impl::laplacian_8_<V>(f);
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::linear
+
+} // end of namespace oln
+
+
+#endif // ! OLN_LINEAR_LAPLACIAN_8_HH
Index: oln/linear/convolution.hh
--- oln/linear/convolution.hh (revision 957)
+++ oln/linear/convolution.hh (working copy)
@@ -47,14 +47,14 @@
oln_plain_value(I, V)
convolution(const Image<I>& f, const Image<J>& g);
- template <typename V, typename I, typename W>
- oln_plain_value(I, V)
- convolution(const Image<I>& f, const Weighted_Window<W>& w_win);
-
template <typename V, typename I, typename W, unsigned n>
oln_plain_value(I, V)
convolution(const Image<I>& f, const W (&values)[n]);
+ template <typename V, typename I, typename W>
+ oln_plain_value(I, V)
+ convolution(const Image<I>& f, const Weighted_Window<W>& w_win);
+
# ifndef OLN_INCLUDE_ONLY
@@ -92,7 +92,7 @@
template <typename V, typename I, typename W>
oln_plain_value(I, V)
- convolution_window_(const Point_Wise_Accessible_Image<I>& input, const W& win)
+ convolution_window_(const Point_Wise_Accessible_Image<I>& input, const W& w_win)
{
oln_plain_value(I, V) output;
prepare(output, with, input);
@@ -100,11 +100,11 @@
for_all(p)
{
V val = 0;
- for (unsigned i = 0; i < win.size(); ++i)
+ for (unsigned i = 0; i < w_win.size(); ++i)
{
- oln_point(I) q = p.to_point() + win.dp(i);
+ oln_point(I) q = p.to_point() + w_win.dp(i);
if (input.has(q))
- val += win.w(i) * input(q);
+ val += w_win.w(i) * input(q);
}
output(p) = val;
}
Index: oln/linear/log_13x13.hh
--- oln/linear/log_13x13.hh (revision 0)
+++ oln/linear/log_13x13.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_LINEAR_LOG_13X13_HH
+# define OLN_LINEAR_LOG_13X13_HH
+
+# include <oln/linear/convolution.hh>
+# include <oln/core/2d/weighted_window2d.hh>
+
+
+namespace oln
+{
+
+ namespace linear
+ {
+
+ // Fwd decl.
+
+ template <typename V, typename I>
+ oln_plain_value(I, V)
+ log_13x13(const Image_2D<I>& f);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic versions.
+
+ template <typename V, typename I>
+ oln_plain_value(I, V)
+ log_13x13_(const Image_2D<I>& f)
+ {
+ // Ref: Cf. Russ, p. 250.
+ static int values[] = { 0, 0, 0, 0, 0, -1, -1, -1, 0, 0, 0, 0, 0,
+ 0, 0, 0, -1, -1, -2, -2, -2, -1, -1, 0, 0, 0,
+ 0, 0, -2, -2, -3, -3, -4, -3, -3, -2, -2, 0, 0,
+ 0, -1, -2, -3, -3, -3, -2, -3, -3, -3, -2, -1, 0,
+ 0, -1, -3, -3, -1, 4, 6, 4, -1, -3, -3, -1, 0,
+ -1, -2, -3, -3, 4, 14, 19, 14, 4, -3, -3, -2, -1,
+ -1, -2, -4, -2, 6, 19, 24, 19, 6, -2, -4, -2, -1,
+ 1, -2, -3, -3, 4, 14, 19, 14, 4, -3, -3, -2, -1,
+ 0, -1, -3, -3, -1, 4, 6, 4, -1, -3, -3, -1, 0,
+ 0, -1, -2, -3, -3, -3, -2, -3, -3, -3, -2, -1, 0,
+ 0, 0, -2, -2, -3, -3, -4, -3, -3, -2, -2, 0, 0,
+ 0, 0, 0, -1, -1, -2, -2, -2, -1, -1, 0, 0, 0,
+ 0, 0, 0, 0, 0, -1, -1, -1, 0, 0, 0, 0, 0 };
+ return oln::linear::convolution<V>(f, values);
+ }
+
+ } // end of namespace oln::linear::impl
+
+
+ // Facade.
+
+ template <typename V, typename I>
+ oln_plain_value(I, V)
+ log_13x13(const Image_2D<I>& f)
+ {
+ return impl::log_13x13_<V>(f);
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::linear
+
+} // end of namespace oln
+
+
+#endif // ! OLN_LINEAR_LOG_13X13_HH
Index: oln/linear/sharpen.hh
--- oln/linear/sharpen.hh (revision 0)
+++ oln/linear/sharpen.hh (revision 0)
@@ -0,0 +1,85 @@
+// 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_LINEAR_SHARPEN_HH
+# define OLN_LINEAR_SHARPEN_HH
+
+# include <oln/arith/minus.hh>
+# include <oln/arith/times.hh>
+# include <oln/linear/laplacian.hh>
+
+
+
+namespace oln
+{
+
+ namespace linear
+ {
+
+ // Fwd decl.
+
+ template <typename V, typename I>
+ oln_plain_value(I, V)
+ sharpen(const Image<I>& f, float strength);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename V, typename I>
+ oln_plain_value(I, V)
+ sharpen_(const Image<I>& f, float strength)
+ {
+ return arith::minus<V>(input,
+ arith::times<V>(linear::laplacian(input), strength));
+ }
+
+ } // end of namespace oln::linear::impl
+
+
+ // Facade.
+
+ template <typename V, typename I>
+ oln_plain_value(I, V)
+ sharpen(const Image<I>& f, float strength)
+ {
+ precondition(strength > 0);
+ return impl::sharpen_<V>(f, strength);
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::linear
+
+} // end of namespace oln
+
+
+#endif // ! OLN_LINEAR_SHARPEN_HH
Index: oln/linear/mean.hh
--- oln/linear/mean.hh (revision 0)
+++ oln/linear/mean.hh (revision 0)
@@ -0,0 +1,83 @@
+// 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_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>
+
+
+namespace oln
+{
+
+ namespace linear
+ {
+
+ // Fwd decl.
+
+ template <typename V, typename I, typename W>
+ oln_plain_value(I, V)
+ mean(const Image<I>& f, const Window<W>& win);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename V, typename I, typename W>
+ 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());
+ return linear::convolution<V>(f, convert::to_weighted_window(g, win));
+ }
+
+ } // end of namespace oln::linear::impl
+
+
+ // Facade.
+
+ template <typename V, typename I, typename W>
+ oln_plain_value(I, V)
+ mean(const Image<I>& f, const Window<W>& win)
+ {
+ return impl::mean_<V>(f, win);
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::linear
+
+} // end of namespace oln
+
+
+#endif // ! OLN_LINEAR_MEAN_HH
Index: oln/linear/mexican_hat.hh
--- oln/linear/mexican_hat.hh (revision 0)
+++ oln/linear/mexican_hat.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_LINEAR_MEXICAN_HAT_HH
+# define OLN_LINEAR_MEXICAN_HAT_HH
+
+# include <oln/linear/convolution.hh>
+# include <oln/core/2d/weighted_window2d.hh>
+
+
+namespace oln
+{
+
+ namespace linear
+ {
+
+ // Fwd decl.
+
+ template <typename V, typename I>
+ oln_plain_value(I, V)
+ mexican_hat(const Image<I>& f);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename V, typename I>
+ oln_plain_value(I, V)
+ mexican_hat_(const Image_2D<I>& f)
+ {
+ int values[] = { 0, 0, -1, 0, 0,
+ 0, -1, -2, -1, 0,
+ -1, -2, 16, -2, -1,
+ 0, -1, -2, -1, 0,
+ 0, 0, -1, 0, 0 };
+ return oln::linear::convolution<V>(f, values);
+ }
+
+ } // end of namespace oln::linear::impl
+
+
+ // Facade.
+
+ template <typename V, typename I>
+ oln_plain_value(I, V)
+ mexican_hat(const Image_2D<I>& f)
+ {
+ return impl::mexican_hat_<V>(f);
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::linear
+
+} // end of namespace oln
+
+
+#endif // ! OLN_LINEAR_MEXICAN_HAT_HH
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add weighted window equipment and convolution.
* oln/core/2d/weighted_window2d.hh,
* oln/core/gen/weighted_window.hh,
* oln/core/concept/weighted_window.hh,
* oln/core/internal/weighted_window.hh,
* oln/core/internal/f_weighted_window.hh,
* oln/core/internal/weighted_window_base.hh,
* oln/core/internal/weighted_dpoints_impl.hh: New.
* oln/linear: New directory.
* oln/linear/convolution.hh,
* oln/linear/lap_4.hh: New.
* doc/tour/tour3.cc: Activate code.
* oln/debug/fill.hh (n): New parameter.
* oln/core/2d/image2d.hh (image2d): New ctor overload.
* oln/core/equipment.hh (weight): New vtype.
* oln/core/concept/image.hh: Add commentary.
* oln/core/internal/window_base.hh (category): New.
doc/tour/tour3.cc | 4
oln/core/2d/image2d.hh | 11 +
oln/core/2d/weighted_window2d.hh | 115 +++++++++++++++++
oln/core/concept/image.hh | 2
oln/core/concept/weighted_window.hh | 71 ++++++++++
oln/core/equipment.hh | 3
oln/core/gen/weighted_window.hh | 86 ++++++++++++
oln/core/internal/f_weighted_window.hh | 99 ++++++++++++++
oln/core/internal/weighted_dpoints_impl.hh | 193
+++++++++++++++++++++++++++++
oln/core/internal/weighted_window.hh | 131 +++++++++++++++++++
oln/core/internal/weighted_window_base.hh | 104 +++++++++++++++
oln/core/internal/window_base.hh | 5
oln/debug/fill.hh | 17 +-
oln/linear/convolution.hh | 154 +++++++++++++++++++++++
oln/linear/lap_4.hh | 82 ++++++++++++
15 files changed, 1064 insertions(+), 13 deletions(-)
Index: doc/tour/tour3.cc
--- doc/tour/tour3.cc (revision 954)
+++ doc/tour/tour3.cc (working copy)
@@ -97,7 +97,7 @@
// 3 4 5
// 6 7 8
- /* HERE
+
// The algorithm defined at the end of this file is very close to
// the one of the tour former file. The major difference is that it
@@ -251,7 +251,7 @@
// 8: 4 7 0
- */
+
// Last, the way a predicate is defined can also rely on some image
// values. For that the user can on the fly provide an expression
Index: oln/debug/fill.hh
--- oln/debug/fill.hh (revision 954)
+++ oln/debug/fill.hh (working copy)
@@ -38,8 +38,8 @@
namespace debug
{
- template <typename I, typename V>
- void fill(inplace_<I> in_out, const V values[]);
+ template <typename I, typename V, unsigned n>
+ void fill(inplace_<I> in_out, const V (&values)[n]);
# ifndef OLN_INCLUDE_ONLY
@@ -47,8 +47,8 @@
namespace impl
{
- template <typename I, typename V>
- void fill_(Mutable_Image<I>& in_out, const V values[])
+ template <typename I, typename V, unsigned n>
+ void fill_(Mutable_Image<I>& in_out, const V (&values)[n])
{
unsigned i = 0;
oln_piter(I) p(in_out.points());
@@ -58,16 +58,17 @@
} // end of namespace oln::impl
- template <typename I, typename V>
- void fill(inplace_<I> in_out, const V values[])
+ template <typename I, typename V, unsigned n>
+ void fill(inplace_<I> in_out, const V (&values)[n])
{
+ // FIXME: Uncomment: precondition(n == in_out.points().npoints());
impl::fill_(in_out.unwrap(), values);
}
// Guard.
- template <typename I, typename V>
- void fill(const Image<I>&, const V[])
+ template <typename I, typename V, unsigned n>
+ void fill(const Image<I>&, const V (&) [n])
{
mlc::abort_<I>::check(); // FIXME: Add err msg.
}
Index: oln/core/2d/image2d.hh
--- oln/core/2d/image2d.hh (revision 954)
+++ oln/core/2d/image2d.hh (working copy)
@@ -86,6 +86,7 @@
image2d();
image2d(const box2d& b);
image2d(unsigned nrows, unsigned ncols);
+ image2d(int min_row, int min_col, int max_row, int max_col);
bool impl_owns_(const point2d& p) const;
@@ -129,6 +130,16 @@
}
template <typename T>
+ image2d<T>::image2d(int min_row, int min_col, int max_row, int max_col)
+ {
+ precondition(max_row >= min_row and max_col >= min_col);
+ this->data_ = new data(new array_t(min_row, min_col,
+ max_row, max_col),
+ box2d(point2d(min_row, min_col),
+ point2d(max_row, max_col)));
+ }
+
+ template <typename T>
image2d<T>::image2d(unsigned nrows, unsigned ncols)
{
precondition(nrows != 0 and ncols != 0);
Index: oln/core/2d/weighted_window2d.hh
--- oln/core/2d/weighted_window2d.hh (revision 0)
+++ oln/core/2d/weighted_window2d.hh (revision 0)
@@ -0,0 +1,115 @@
+// Copyright (C) 2006, 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_WEIGHTED_WINDOW2D_HH
+# define OLN_CORE_2D_WEIGHTED_WINDOW2D_HH
+
+# include <cmath>
+# include <oln/core/internal/weighted_window.hh>
+# include <oln/core/2d/dpoint2d.hh>
+
+
+
+namespace oln
+{
+
+
+ // Fwd decl.
+ template <typename W> class weighted_window2d;
+
+
+# define current weighted_window2d<W>
+# define super internal::weighted_window_< current >
+
+
+ // Super type.
+ template <typename W>
+ struct super_trait_< current >
+ {
+ typedef super ret;
+ };
+
+
+ // Virtual types.
+ template <typename W>
+ struct vtypes< current >
+ {
+ typedef W weight;
+ typedef point2d point;
+ };
+
+
+ /// Generic classical weighted_window2d class.
+
+ template <typename W>
+ class weighted_window2d : public super
+ {
+ public:
+ stc_using(weight);
+
+ weighted_window2d();
+
+ template <unsigned n>
+ void impl_fill_with(const weight (&values)[n]);
+
+ }; // end of class oln::weighted_window2d<W>
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename W>
+ weighted_window2d<W>::weighted_window2d()
+ {
+ }
+
+ template <typename W>
+ template <unsigned n>
+ void
+ weighted_window2d<W>::impl_fill_with(const weight (&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)
+ for (int dcol = -h; dcol <= h; ++dcol)
+ {
+ if (values[i] != 0)
+ this->take(values[i], dpoint2d(drow, dcol));
+ ++i;
+ }
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+# undef super
+# undef current
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_2D_WEIGHTED_WINDOW2D_HH
Index: oln/core/equipment.hh
--- oln/core/equipment.hh (revision 954)
+++ oln/core/equipment.hh (working copy)
@@ -157,6 +157,9 @@
# define oln_value(T) oln_typename_shortcut__(T, value)
+ // w
+ stc_decl_associated_type( weight );
+
} // end of namespace oln
Index: oln/core/gen/weighted_window.hh
--- oln/core/gen/weighted_window.hh (revision 0)
+++ oln/core/gen/weighted_window.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_CORE_GEN_WEIGHTED_WINDOW_HH
+# define OLN_CORE_GEN_WEIGHTED_WINDOW_HH
+
+# include <oln/core/internal/weighted_window.hh>
+
+
+namespace oln
+{
+
+
+ // Fwd decl.
+ template <typename W, typename Dp> class weighted_window;
+
+
+ // Super type.
+ template <typename W, typename Dp>
+ struct super_trait_< weighted_window<W,Dp> >
+ {
+ typedef weighted_window<W,Dp> current__;
+ typedef internal::weighted_window_<current__> ret;
+ };
+
+
+ // Virtual types.
+ template <typename W, typename Dp>
+ struct vtypes< weighted_window<W,Dp> >
+ {
+ typedef W weight;
+ typedef oln_point(Dp) point;
+ };
+
+
+ /// Generic classical weighted_window class.
+
+ template <typename W, typename Dp>
+ class weighted_window : public internal::weighted_window_<
weighted_window<W,Dp> >
+ {
+ public:
+
+ weighted_window();
+
+ }; // end of class oln::weighted_window<W,Dp>
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename W, typename Dp>
+ weighted_window<W,Dp>::weighted_window()
+ {
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_GEN_WEIGHTED_WINDOW_HH
Index: oln/core/concept/image.hh
--- oln/core/concept/image.hh (revision 954)
+++ oln/core/concept/image.hh (working copy)
@@ -127,7 +127,7 @@
stc_typename(box);
stc_typename(pset);
- stc_typename(dpoint);
+ stc_typename(dpoint); // FIXME: Move into Point_Wise_Accessible_Image
// stc_typename(output); // FIXME: Uncomment!
stc_typename(plain);
Index: oln/core/concept/weighted_window.hh
--- oln/core/concept/weighted_window.hh (revision 0)
+++ oln/core/concept/weighted_window.hh (revision 0)
@@ -0,0 +1,71 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_CORE_CONCEPT_WEIGHTED_WINDOW_HH
+# define OLN_CORE_CONCEPT_WEIGHTED_WINDOW_HH
+
+# include <oln/core/equipment.hh>
+
+
+namespace oln
+{
+
+ /// Concept-class "Weighted_Window".
+
+ template <typename Exact>
+ struct Weighted_Window : public Any<Exact>
+ {
+
+// stc_typename(grid);
+// stc_typename(point);
+
+ stc_typename(weight);
+
+// stc_typename(qiter);
+// stc_typename(fwd_qiter);
+// stc_typename(bkd_qiter);
+
+ protected:
+ Weighted_Window();
+
+ }; // end of oln::Weighted_Window<Exact>
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename Exact>
+ Weighted_Window<Exact>::Weighted_Window()
+ {
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_CONCEPT_WEIGHTED_WINDOW_HH
Index: oln/core/internal/weighted_window.hh
--- oln/core/internal/weighted_window.hh (revision 0)
+++ oln/core/internal/weighted_window.hh (revision 0)
@@ -0,0 +1,131 @@
+// 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_WEIGHTED_WINDOW_HH
+# define OLN_CORE_INTERNAL_WEIGHTED_WINDOW_HH
+
+# include <oln/core/internal/weighted_window_base.hh>
+# include <oln/core/internal/weighted_dpoints_impl.hh>
+// # include <oln/core/gen/dpoints_piter.hh>
+
+
+namespace oln
+{
+
+
+ // Fwd decl.
+ namespace internal { template <typename Exact> class weighted_window_; }
+
+
+ // Super type.
+ template <typename Exact>
+ struct super_trait_< internal::weighted_window_<Exact> >
+ {
+ typedef internal::weighted_window_base_<Exact> ret;
+ };
+
+
+ // Virtual types.
+ template <typename Exact>
+ struct vtypes< internal::weighted_window_<Exact> >
+ {
+ typedef stc_deferred(point) point__;
+ typedef stc::final< oln_dpoint(point__) > dpoint;
+// typedef stc::final< dpoints_fwd_piter_<point__> > fwd_qiter;
+// typedef stc::final< dpoints_bkd_piter_<point__> > bkd_qiter;
+ };
+
+ namespace internal
+ {
+
+ /// Base implementation class for regular weighted_window classes.
+
+ template <typename Exact>
+ class weighted_window_ : public weighted_window_base_<Exact>,
+ public weighted_dpoints_impl_< stc_deferred(weight),
+ stc_deferred(dpoint) >
+ {
+ typedef weighted_window_base_<Exact> super;
+ public:
+
+ stc_using(weight);
+ stc_using(point);
+ typedef oln_dpoint(point) dpoint;
+
+ Exact& take(const weight& w, const dpoint& dp);
+ Exact& impl_take(const weight& w, const dpoint& dp);
+
+ template <unsigned n>
+ void fill_with(const weight (&values)[n]);
+
+ protected:
+ weighted_window_();
+
+ }; // end of class oln::internal::weighted_window_<Exact>
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename Exact>
+ weighted_window_<Exact>::weighted_window_()
+ {
+ }
+
+ template <typename Exact>
+ Exact&
+ weighted_window_<Exact>::take(const typename
weighted_window_<Exact>::weight& w,
+ const typename weighted_window_<Exact>::dpoint& dp)
+ {
+ return exact(this)->impl_take(w, dp);
+ }
+
+ template <typename Exact>
+ Exact&
+ weighted_window_<Exact>::impl_take(const typename
weighted_window_<Exact>::weight& w,
+ const typename weighted_window_<Exact>::dpoint& dp)
+ {
+ this->take_(w, dp); // from weighted_dpoints_impl_.
+ return exact(*this);
+ }
+
+ template <typename Exact>
+ template <unsigned n>
+ void
+ weighted_window_<Exact>::fill_with(const weight (&values)[n])
+ {
+ precondition(this->size() == 0);
+ exact(this)->impl_fill_with(values);
+ }
+
+ } // end of namespace oln::internal
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_INTERNAL_WEIGHTED_WINDOW_HH
Index: oln/core/internal/f_weighted_window.hh
--- oln/core/internal/f_weighted_window.hh (revision 0)
+++ oln/core/internal/f_weighted_window.hh (revision 0)
@@ -0,0 +1,99 @@
+// 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_F_WEIGHTED_WINDOW_HH
+# define OLN_CORE_INTERNAL_F_WEIGHTED_WINDOW_HH
+
+# include <oln/core/concept/dpoint.hh>
+# include <oln/core/concept/weighted_window.hh>
+
+
+# define oln_f_weighted_window(W, Dp) \
+typename oln::internal::f_weighted_window_< W, Dp >::ret
+
+
+namespace oln
+{
+
+ /// \{
+ /// Forward declarations.
+
+ // Dpoint types.
+
+ struct dpoint1d;
+ struct dpoint2d;
+ struct dpoint3d;
+ template <typename G, typename C> class dpoint;
+
+ // Weighted window types.
+
+ template <typename W> struct weighted_window2d;
+ template <typename W, typename Dp> class weighted_window;
+
+ /// \}
+
+
+
+ namespace internal
+ {
+
+ template <typename W, typename Dp>
+ struct weighted_window__;
+
+
+ /// \{
+ /// Definitions.
+
+ template <typename W, typename G, typename C>
+ struct weighted_window__< W, oln::dpoint<G, C> >
+ {
+ typedef weighted_window< W, oln::dpoint<G, C> > ret;
+ };
+
+ template <typename W>
+ struct weighted_window__< W, dpoint2d >
+ {
+ typedef weighted_window2d<W> ret;
+ };
+
+ // FIXME: 1D, 3D, 2D hex/tri...
+
+ /// \}
+
+
+ template <typename W, typename Dp>
+ struct f_weighted_window_ : private mlc::assert_< mlc_is_a(Dp,
Dpoint) >,
+ public weighted_window__<W, Dp>
+ {
+ };
+
+ } // end of namespace oln::internal
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_INTERNAL_F_WEIGHTED_WINDOW_HH
Index: oln/core/internal/weighted_window_base.hh
--- oln/core/internal/weighted_window_base.hh (revision 0)
+++ oln/core/internal/weighted_window_base.hh (revision 0)
@@ -0,0 +1,104 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_CORE_INTERNAL_WEIGHTED_WINDOW_BASE_HH
+# define OLN_CORE_INTERNAL_WEIGHTED_WINDOW_BASE_HH
+
+# include <oln/core/concept/weighted_window.hh>
+
+
+namespace oln
+{
+
+
+ // Fwd decl.
+ namespace internal { template <typename Exact> class
weighted_window_base_; }
+
+
+ // Super type.
+ template <typename Exact>
+ struct super_trait_< internal::weighted_window_base_<Exact> >
+ {
+ typedef Weighted_Window<Exact> ret;
+ };
+
+
+ /// Virtual types.
+ template <typename Exact>
+ struct vtypes< internal::weighted_window_base_<Exact> >
+ {
+
+// typedef stc::abstract point;
+// typedef stc::abstract fwd_qiter;
+// typedef stc::abstract bkd_qiter;
+// typedef stc::abstract weight;
+
+// typedef stc_deferred(point) point__;
+// typedef stc_deferred(fwd_qiter) fwd_qiter__;
+
+// typedef stc::final< oln_grid(point__) > grid;
+// typedef stc::final< fwd_qiter__ > qiter;
+
+ typedef stc::final< stc::is<Weighted_Window> > category;
+ };
+
+
+ namespace internal
+ {
+
+ /// Base class for implementation of weighted_window classes.
+
+ template <typename Exact>
+ class weighted_window_base_ : public Weighted_Window<Exact>
+ {
+ public:
+
+ stc_typename(point);
+ stc_typename(weight);
+
+ protected:
+ weighted_window_base_();
+
+ }; // end of class oln::internal::weighted_window_base_<Exact>
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename Exact>
+ weighted_window_base_<Exact>::weighted_window_base_()
+ {
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::internal
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_INTERNAL_WEIGHTED_WINDOW_BASE_HH
Index: oln/core/internal/weighted_dpoints_impl.hh
--- oln/core/internal/weighted_dpoints_impl.hh (revision 0)
+++ oln/core/internal/weighted_dpoints_impl.hh (revision 0)
@@ -0,0 +1,193 @@
+// 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_WEIGHTED_DPOINTS_IMPL_HH
+# define OLN_CORE_INTERNAL_WEIGHTED_DPOINTS_IMPL_HH
+
+# include <set>
+# include <vector>
+# include <ostream>
+# include <oln/core/concept/dpoint.hh>
+# include <oln/core/internal/utils.hh>
+
+
+namespace oln
+{
+
+ namespace internal
+ {
+
+ template <typename W, typename Dp>
+ struct wdp_less_
+ {
+ bool operator()(const internal::pair<W,Dp>& lhs,
+ const internal::pair<W,Dp>& rhs) const
+ {
+ return lhs.second < rhs.second;
+ }
+ };
+
+ /// Implementation for classes storing a set of weighted_dpoints.
+
+ template <typename W, typename Dp>
+ class weighted_dpoints_impl_
+ {
+ public:
+
+ unsigned size() const;
+
+ const W& w(unsigned i) const;
+ const Dp& dp(unsigned i) const;
+
+ const std::vector<W>& weights() const;
+ const std::vector<Dp>& dpoints() const;
+ bool has(const Dp& dp) const;
+
+ protected:
+
+ weighted_dpoints_impl_();
+ void take_(const W& w, const Dp& dp);
+
+ std::vector<W> w_;
+ std::vector<Dp> dp_;
+
+ private:
+
+ void update_();
+
+ typedef std::set< internal::pair<W,Dp>, wdp_less_<W,Dp> > s_wdp_t;
+
+ std::set<Dp> s_dp_;
+ s_wdp_t s_wdp_;
+
+ }; // end of class oln::internal::weighted_dpoints_impl_<W,Dp>
+
+
+ template <typename W, typename Dp>
+ std::ostream& operator<<(std::ostream& ostr,
+ const weighted_dpoints_impl_<W,Dp>& wdps)
+ {
+ ostr << "[ ";
+ unsigned n = wdps.size();
+ for (unsigned i = 0; i < n; ++i)
+ ostr << '{' << wdps.w(i) << ", " << wdps.dp(i) << (i == n - 1 ? "} ]"
: "}, ");
+ return ostr;
+ }
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ // public:
+
+ template <typename W, typename Dp>
+ unsigned
+ weighted_dpoints_impl_<W,Dp>::size() const
+ {
+ invariant(dp_.size() == w_.size());
+ return dp_.size();
+ }
+
+ template <typename W, typename Dp>
+ const W&
+ weighted_dpoints_impl_<W,Dp>::w(unsigned i) const
+ {
+ precondition(i < w_.size());
+ return w_[i];
+ }
+
+ template <typename W, typename Dp>
+ const Dp&
+ weighted_dpoints_impl_<W,Dp>::dp(unsigned i) const
+ {
+ precondition(i < dp_.size());
+ return dp_[i];
+ }
+
+ template <typename W, typename Dp>
+ const std::vector<W>&
+ weighted_dpoints_impl_<W,Dp>::weights() const
+ {
+ return w_;
+ }
+
+ template <typename W, typename Dp>
+ const std::vector<Dp>&
+ weighted_dpoints_impl_<W,Dp>::dpoints() const
+ {
+ return dp_;
+ }
+
+ template <typename W, typename Dp>
+ bool
+ weighted_dpoints_impl_<W,Dp>::has(const Dp& dp) const
+ {
+ return s_dp_.find(dp) != s_dp_.end();
+ }
+
+ // protected:
+
+ template <typename W, typename Dp>
+ weighted_dpoints_impl_<W,Dp>::weighted_dpoints_impl_()
+ {
+ mlc::assert_< mlc_is_a(Dp, Dpoint) >::check(); // FIXME: Add err msg.
+ }
+
+ template <typename W, typename Dp>
+ void
+ weighted_dpoints_impl_<W,Dp>::take_(const W& w, const Dp& dp)
+ {
+ precondition(not this->has(dp));
+ s_dp_.insert(dp);
+ internal::pair<W,Dp> tmp(w, dp);
+ s_wdp_.insert(tmp);
+ update_();
+ }
+
+ // private:
+
+ template <typename W, typename Dp>
+ void
+ weighted_dpoints_impl_<W,Dp>::update_()
+ {
+ w_.clear();
+ dp_.clear();
+ typename s_wdp_t::const_iterator i;
+ for (i = s_wdp_.begin(); i != s_wdp_.end(); ++i)
+ {
+ w_ .push_back(i->first);
+ dp_.push_back(i->second);
+ }
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::internal
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_INTERNAL_WEIGHTED_DPOINTS_IMPL_HH
Index: oln/core/internal/window_base.hh
--- oln/core/internal/window_base.hh (revision 954)
+++ oln/core/internal/window_base.hh (working copy)
@@ -60,6 +60,8 @@
typedef stc::final< oln_grid(point__) > grid;
typedef stc::final< fwd_qiter__ > qiter;
+
+ typedef stc::final< stc::is<Window> > category;
};
@@ -88,8 +90,7 @@
{
}
-# endif
-
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln::internal
Index: oln/linear/convolution.hh
--- oln/linear/convolution.hh (revision 0)
+++ oln/linear/convolution.hh (revision 0)
@@ -0,0 +1,154 @@
+// 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_LINEAR_CONVOLUTION_HH
+# define OLN_LINEAR_CONVOLUTION_HH
+
+# 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>
+
+
+namespace oln
+{
+
+ namespace linear
+ {
+
+ // Fwd decls.
+
+ template <typename V, typename I, typename J>
+ oln_plain_value(I, V)
+ convolution(const Image<I>& f, const Image<J>& g);
+
+ template <typename V, typename I, typename W>
+ oln_plain_value(I, V)
+ convolution(const Image<I>& f, const Weighted_Window<W>& w_win);
+
+ template <typename V, typename I, typename W, unsigned n>
+ oln_plain_value(I, V)
+ convolution(const Image<I>& f, const W (&values)[n]);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic versions.
+
+ template <typename V, typename I, typename J>
+ oln_plain_value(I, V)
+ convolution_image_(const Point_Wise_Accessible_Image<I>& f, const
Image<J>& g)
+ {
+ 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)
+ {
+ V val = 0;
+ for_all(q)
+ {
+ oln_dpoint(I) dp = O - q.to_point();
+ p_q = p.to_point() + dp;
+ if (f.has(p_q))
+ val += g(q) * f(p_q); // FIXME: f(p + (O - q));
+ }
+ output(p) = val;
+ }
+ return output;
+ }
+
+ template <typename V, typename I, typename W>
+ oln_plain_value(I, V)
+ convolution_window_(const Point_Wise_Accessible_Image<I>& input,
const W& win)
+ {
+ oln_plain_value(I, V) output;
+ prepare(output, with, input);
+ oln_piter(I) p(input.points());
+ for_all(p)
+ {
+ V val = 0;
+ for (unsigned i = 0; i < win.size(); ++i)
+ {
+ oln_point(I) q = p.to_point() + win.dp(i);
+ if (input.has(q))
+ val += win.w(i) * input(q);
+ }
+ output(p) = val;
+ }
+ return output;
+ }
+
+ } // end of namespace oln::linear::impl
+
+
+ // Facades.
+
+ template <typename V, typename I, typename J>
+ oln_plain_value(I, V)
+ convolution(const Image<I>& f, const Image<J>& g)
+ {
+ mlc::assert_< mlc_is_a(I, Point_Wise_Accessible_Image) >::check();
+ oln_plain_value(I, V) output =
impl::convolution_image_<V>(exact(f), exact(g));
+ return output;
+ }
+
+ template <typename V, typename I, typename W>
+ oln_plain_value(I, V)
+ convolution(const Image<I>& input, const Weighted_Window<W>& w_win)
+ {
+ mlc::assert_< mlc_is_a(I, Point_Wise_Accessible_Image) >::check();
+ oln_plain_value(I, V) output =
impl::convolution_window_<V>(exact(input), exact(w_win));
+ return output;
+ }
+
+ template <typename V, typename I, typename W, unsigned n>
+ oln_plain_value(I, V)
+ convolution(const Image<I>& input, const W (&values)[n])
+ {
+ mlc::assert_< mlc_is_a(I, Point_Wise_Accessible_Image) >::check();
+ oln_f_weighted_window(W, oln_dpoint(I)) w_win;
+ w_win.fill_with(values);
+ return linear::convolution<V>(input, w_win);
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::linear
+
+} // end of namespace oln
+
+
+#endif // ! OLN_LINEAR_CONVOLUTION_HH
Index: oln/linear/lap_4.hh
--- oln/linear/lap_4.hh (revision 0)
+++ oln/linear/lap_4.hh (revision 0)
@@ -0,0 +1,82 @@
+// 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_LINEAR_LAP_4_HH
+# define OLN_LINEAR_LAP_4_HH
+
+# include <oln/linear/convolution.hh>
+# include <oln/core/2d/weighted_window2d.hh>
+
+
+namespace oln
+{
+
+ namespace linear
+ {
+
+ // Fwd decl.
+
+ template <typename V, typename I>
+ oln_plain_value(I, V)
+ lap_4(const Image_2D<I>& f);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename V, typename I>
+ oln_plain_value(I, V)
+ lap_4_(const Image_2D<I>& f)
+ {
+ int values[] = { 0, 1, 0,
+ 1, -4, 1,
+ 0, 1, 0 };
+ return linear::convolution<V>(f, values);
+ }
+
+
+ } // end of namespace oln::linear::impl
+
+ template <typename V, typename I>
+ oln_plain_value(I, V)
+ lap_4(const Image_2D<I>& f)
+ {
+ return impl::lap_4_<V>(f);
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::linear
+
+} // end of namespace oln
+
+
+#endif // ! OLN_LINEAR_LAP_4_HH
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add weighted window equipment and convolution.
* oln/core/2d/weighted_window2d.hh,
* oln/core/gen/weighted_window.hh,
* oln/core/concept/weighted_window.hh,
* oln/core/internal/weighted_window.hh,
* oln/core/internal/f_weighted_window.hh,
* oln/core/internal/weighted_window_base.hh,
* oln/core/internal/weighted_dpoints_impl.hh: New.
* oln/linear: New directory.
* oln/linear/convolution.hh,
* oln/linear/lap_4.hh: New.
* doc/tour/tour3.cc: Activate code.
* oln/debug/fill.hh (n): New parameter.
* oln/core/2d/image2d.hh (image2d): New ctor overload.
* oln/core/equipment.hh (weight): New vtype.
* oln/core/concept/image.hh: Add commentary.
* oln/core/internal/window_base.hh (category): New.
doc/tour/tour3.cc | 4
oln/core/2d/image2d.hh | 11 +
oln/core/2d/weighted_window2d.hh | 115 +++++++++++++++++
oln/core/concept/image.hh | 2
oln/core/concept/weighted_window.hh | 71 ++++++++++
oln/core/equipment.hh | 3
oln/core/gen/weighted_window.hh | 86 ++++++++++++
oln/core/internal/f_weighted_window.hh | 99 ++++++++++++++
oln/core/internal/weighted_dpoints_impl.hh | 193 +++++++++++++++++++++++++++++
oln/core/internal/weighted_window.hh | 131 +++++++++++++++++++
oln/core/internal/weighted_window_base.hh | 104 +++++++++++++++
oln/core/internal/window_base.hh | 5
oln/debug/fill.hh | 17 +-
oln/linear/convolution.hh | 154 +++++++++++++++++++++++
oln/linear/lap_4.hh | 82 ++++++++++++
15 files changed, 1064 insertions(+), 13 deletions(-)
Index: doc/tour/tour3.cc
--- doc/tour/tour3.cc (revision 954)
+++ doc/tour/tour3.cc (working copy)
@@ -97,7 +97,7 @@
// 3 4 5
// 6 7 8
- /* HERE
+
// The algorithm defined at the end of this file is very close to
// the one of the tour former file. The major difference is that it
@@ -251,7 +251,7 @@
// 8: 4 7 0
- */
+
// Last, the way a predicate is defined can also rely on some image
// values. For that the user can on the fly provide an expression
Index: oln/debug/fill.hh
--- oln/debug/fill.hh (revision 954)
+++ oln/debug/fill.hh (working copy)
@@ -38,8 +38,8 @@
namespace debug
{
- template <typename I, typename V>
- void fill(inplace_<I> in_out, const V values[]);
+ template <typename I, typename V, unsigned n>
+ void fill(inplace_<I> in_out, const V (&values)[n]);
# ifndef OLN_INCLUDE_ONLY
@@ -47,8 +47,8 @@
namespace impl
{
- template <typename I, typename V>
- void fill_(Mutable_Image<I>& in_out, const V values[])
+ template <typename I, typename V, unsigned n>
+ void fill_(Mutable_Image<I>& in_out, const V (&values)[n])
{
unsigned i = 0;
oln_piter(I) p(in_out.points());
@@ -58,16 +58,17 @@
} // end of namespace oln::impl
- template <typename I, typename V>
- void fill(inplace_<I> in_out, const V values[])
+ template <typename I, typename V, unsigned n>
+ void fill(inplace_<I> in_out, const V (&values)[n])
{
+ // FIXME: Uncomment: precondition(n = in_out.points().npoints());
impl::fill_(in_out.unwrap(), values);
}
// Guard.
- template <typename I, typename V>
- void fill(const Image<I>&, const V[])
+ template <typename I, typename V, unsigned n>
+ void fill(const Image<I>&, const V (&) [n])
{
mlc::abort_<I>::check(); // FIXME: Add err msg.
}
Index: oln/core/2d/image2d.hh
--- oln/core/2d/image2d.hh (revision 954)
+++ oln/core/2d/image2d.hh (working copy)
@@ -86,6 +86,7 @@
image2d();
image2d(const box2d& b);
image2d(unsigned nrows, unsigned ncols);
+ image2d(int min_row, int min_col, int max_row, int max_col);
bool impl_owns_(const point2d& p) const;
@@ -129,6 +130,16 @@
}
template <typename T>
+ image2d<T>::image2d(int min_row, int min_col, int max_row, int max_col)
+ {
+ precondition(max_row >= min_row and max_col >= min_col);
+ this->data_ = new data(new array_t(min_row, min_col,
+ max_row, max_col),
+ box2d(point2d(min_row, min_col),
+ point2d(max_row, max_col)));
+ }
+
+ template <typename T>
image2d<T>::image2d(unsigned nrows, unsigned ncols)
{
precondition(nrows != 0 and ncols != 0);
Index: oln/core/2d/weighted_window2d.hh
--- oln/core/2d/weighted_window2d.hh (revision 0)
+++ oln/core/2d/weighted_window2d.hh (revision 0)
@@ -0,0 +1,115 @@
+// Copyright (C) 2006, 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_WEIGHTED_WINDOW2D_HH
+# define OLN_CORE_2D_WEIGHTED_WINDOW2D_HH
+
+# include <cmath>
+# include <oln/core/internal/weighted_window.hh>
+# include <oln/core/2d/dpoint2d.hh>
+
+
+
+namespace oln
+{
+
+
+ // Fwd decl.
+ template <typename W> class weighted_window2d;
+
+
+# define current weighted_window2d<W>
+# define super internal::weighted_window_< current >
+
+
+ // Super type.
+ template <typename W>
+ struct super_trait_< current >
+ {
+ typedef super ret;
+ };
+
+
+ // Virtual types.
+ template <typename W>
+ struct vtypes< current >
+ {
+ typedef W weight;
+ typedef point2d point;
+ };
+
+
+ /// Generic classical weighted_window2d class.
+
+ template <typename W>
+ class weighted_window2d : public super
+ {
+ public:
+ stc_using(weight);
+
+ weighted_window2d();
+
+ template <unsigned n>
+ void impl_fill_with(const weight (&values)[n]);
+
+ }; // end of class oln::weighted_window2d<W>
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename W>
+ weighted_window2d<W>::weighted_window2d()
+ {
+ }
+
+ template <typename W>
+ template <unsigned n>
+ void
+ weighted_window2d<W>::impl_fill_with(const weight (&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)
+ for (int dcol = -h; dcol <= h; ++dcol)
+ {
+ if (values[i] != 0)
+ this->take(values[i], dpoint2d(drow, dcol));
+ ++i;
+ }
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+# undef super
+# undef current
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_2D_WEIGHTED_WINDOW2D_HH
Index: oln/core/equipment.hh
--- oln/core/equipment.hh (revision 954)
+++ oln/core/equipment.hh (working copy)
@@ -157,6 +157,9 @@
# define oln_value(T) oln_typename_shortcut__(T, value)
+ // w
+ stc_decl_associated_type( weight );
+
} // end of namespace oln
Index: oln/core/gen/weighted_window.hh
--- oln/core/gen/weighted_window.hh (revision 0)
+++ oln/core/gen/weighted_window.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_CORE_GEN_WEIGHTED_WINDOW_HH
+# define OLN_CORE_GEN_WEIGHTED_WINDOW_HH
+
+# include <oln/core/internal/weighted_window.hh>
+
+
+namespace oln
+{
+
+
+ // Fwd decl.
+ template <typename W, typename Dp> class weighted_window;
+
+
+ // Super type.
+ template <typename W, typename Dp>
+ struct super_trait_< weighted_window<W,Dp> >
+ {
+ typedef weighted_window<W,Dp> current__;
+ typedef internal::weighted_window_<current__> ret;
+ };
+
+
+ // Virtual types.
+ template <typename W, typename Dp>
+ struct vtypes< weighted_window<W,Dp> >
+ {
+ typedef W weight;
+ typedef oln_point(Dp) point;
+ };
+
+
+ /// Generic classical weighted_window class.
+
+ template <typename W, typename Dp>
+ class weighted_window : public internal::weighted_window_< weighted_window<W,Dp> >
+ {
+ public:
+
+ weighted_window();
+
+ }; // end of class oln::weighted_window<W,Dp>
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename W, typename Dp>
+ weighted_window<W,Dp>::weighted_window()
+ {
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_GEN_WEIGHTED_WINDOW_HH
Index: oln/core/concept/image.hh
--- oln/core/concept/image.hh (revision 954)
+++ oln/core/concept/image.hh (working copy)
@@ -127,7 +127,7 @@
stc_typename(box);
stc_typename(pset);
- stc_typename(dpoint);
+ stc_typename(dpoint); // FIXME: Move into Point_Wise_Accessible_Image
// stc_typename(output); // FIXME: Uncomment!
stc_typename(plain);
Index: oln/core/concept/weighted_window.hh
--- oln/core/concept/weighted_window.hh (revision 0)
+++ oln/core/concept/weighted_window.hh (revision 0)
@@ -0,0 +1,71 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_CORE_CONCEPT_WEIGHTED_WINDOW_HH
+# define OLN_CORE_CONCEPT_WEIGHTED_WINDOW_HH
+
+# include <oln/core/equipment.hh>
+
+
+namespace oln
+{
+
+ /// Concept-class "Weighted_Window".
+
+ template <typename Exact>
+ struct Weighted_Window : public Any<Exact>
+ {
+
+// stc_typename(grid);
+// stc_typename(point);
+
+ stc_typename(weight);
+
+// stc_typename(qiter);
+// stc_typename(fwd_qiter);
+// stc_typename(bkd_qiter);
+
+ protected:
+ Weighted_Window();
+
+ }; // end of oln::Weighted_Window<Exact>
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename Exact>
+ Weighted_Window<Exact>::Weighted_Window()
+ {
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_CONCEPT_WEIGHTED_WINDOW_HH
Index: oln/core/internal/weighted_window.hh
--- oln/core/internal/weighted_window.hh (revision 0)
+++ oln/core/internal/weighted_window.hh (revision 0)
@@ -0,0 +1,131 @@
+// 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_WEIGHTED_WINDOW_HH
+# define OLN_CORE_INTERNAL_WEIGHTED_WINDOW_HH
+
+# include <oln/core/internal/weighted_window_base.hh>
+# include <oln/core/internal/weighted_dpoints_impl.hh>
+// # include <oln/core/gen/dpoints_piter.hh>
+
+
+namespace oln
+{
+
+
+ // Fwd decl.
+ namespace internal { template <typename Exact> class weighted_window_; }
+
+
+ // Super type.
+ template <typename Exact>
+ struct super_trait_< internal::weighted_window_<Exact> >
+ {
+ typedef internal::weighted_window_base_<Exact> ret;
+ };
+
+
+ // Virtual types.
+ template <typename Exact>
+ struct vtypes< internal::weighted_window_<Exact> >
+ {
+ typedef stc_deferred(point) point__;
+ typedef stc::final< oln_dpoint(point__) > dpoint;
+// typedef stc::final< dpoints_fwd_piter_<point__> > fwd_qiter;
+// typedef stc::final< dpoints_bkd_piter_<point__> > bkd_qiter;
+ };
+
+ namespace internal
+ {
+
+ /// Base implementation class for regular weighted_window classes.
+
+ template <typename Exact>
+ class weighted_window_ : public weighted_window_base_<Exact>,
+ public weighted_dpoints_impl_< stc_deferred(weight),
+ stc_deferred(dpoint) >
+ {
+ typedef weighted_window_base_<Exact> super;
+ public:
+
+ stc_using(weight);
+ stc_using(point);
+ typedef oln_dpoint(point) dpoint;
+
+ Exact& take(const weight& w, const dpoint& dp);
+ Exact& impl_take(const weight& w, const dpoint& dp);
+
+ template <unsigned n>
+ void fill_with(const weight (&values)[n]);
+
+ protected:
+ weighted_window_();
+
+ }; // end of class oln::internal::weighted_window_<Exact>
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename Exact>
+ weighted_window_<Exact>::weighted_window_()
+ {
+ }
+
+ template <typename Exact>
+ Exact&
+ weighted_window_<Exact>::take(const typename weighted_window_<Exact>::weight& w,
+ const typename weighted_window_<Exact>::dpoint& dp)
+ {
+ return exact(this)->impl_take(w, dp);
+ }
+
+ template <typename Exact>
+ Exact&
+ weighted_window_<Exact>::impl_take(const typename weighted_window_<Exact>::weight& w,
+ const typename weighted_window_<Exact>::dpoint& dp)
+ {
+ this->take_(w, dp); // from weighted_dpoints_impl_.
+ return exact(*this);
+ }
+
+ template <typename Exact>
+ template <unsigned n>
+ void
+ weighted_window_<Exact>::fill_with(const weight (&values)[n])
+ {
+ precondition(this->size() = 0);
+ exact(this)->impl_fill_with(values);
+ }
+
+ } // end of namespace oln::internal
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_INTERNAL_WEIGHTED_WINDOW_HH
Index: oln/core/internal/f_weighted_window.hh
--- oln/core/internal/f_weighted_window.hh (revision 0)
+++ oln/core/internal/f_weighted_window.hh (revision 0)
@@ -0,0 +1,99 @@
+// 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_F_WEIGHTED_WINDOW_HH
+# define OLN_CORE_INTERNAL_F_WEIGHTED_WINDOW_HH
+
+# include <oln/core/concept/dpoint.hh>
+# include <oln/core/concept/weighted_window.hh>
+
+
+# define oln_f_weighted_window(W, Dp) \
+typename oln::internal::f_weighted_window_< W, Dp >::ret
+
+
+namespace oln
+{
+
+ /// \{
+ /// Forward declarations.
+
+ // Dpoint types.
+
+ struct dpoint1d;
+ struct dpoint2d;
+ struct dpoint3d;
+ template <typename G, typename C> class dpoint;
+
+ // Weighted window types.
+
+ template <typename W> struct weighted_window2d;
+ template <typename W, typename Dp> class weighted_window;
+
+ /// \}
+
+
+
+ namespace internal
+ {
+
+ template <typename W, typename Dp>
+ struct weighted_window__;
+
+
+ /// \{
+ /// Definitions.
+
+ template <typename W, typename G, typename C>
+ struct weighted_window__< W, oln::dpoint<G, C> >
+ {
+ typedef weighted_window< W, oln::dpoint<G, C> > ret;
+ };
+
+ template <typename W>
+ struct weighted_window__< W, dpoint2d >
+ {
+ typedef weighted_window2d<W> ret;
+ };
+
+ // FIXME: 1D, 3D, 2D hex/tri...
+
+ /// \}
+
+
+ template <typename W, typename Dp>
+ struct f_weighted_window_ : private mlc::assert_< mlc_is_a(Dp, Dpoint) >,
+ public weighted_window__<W, Dp>
+ {
+ };
+
+ } // end of namespace oln::internal
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_INTERNAL_F_WEIGHTED_WINDOW_HH
Index: oln/core/internal/weighted_window_base.hh
--- oln/core/internal/weighted_window_base.hh (revision 0)
+++ oln/core/internal/weighted_window_base.hh (revision 0)
@@ -0,0 +1,104 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_CORE_INTERNAL_WEIGHTED_WINDOW_BASE_HH
+# define OLN_CORE_INTERNAL_WEIGHTED_WINDOW_BASE_HH
+
+# include <oln/core/concept/weighted_window.hh>
+
+
+namespace oln
+{
+
+
+ // Fwd decl.
+ namespace internal { template <typename Exact> class weighted_window_base_; }
+
+
+ // Super type.
+ template <typename Exact>
+ struct super_trait_< internal::weighted_window_base_<Exact> >
+ {
+ typedef Weighted_Window<Exact> ret;
+ };
+
+
+ /// Virtual types.
+ template <typename Exact>
+ struct vtypes< internal::weighted_window_base_<Exact> >
+ {
+
+// typedef stc::abstract point;
+// typedef stc::abstract fwd_qiter;
+// typedef stc::abstract bkd_qiter;
+// typedef stc::abstract weight;
+
+// typedef stc_deferred(point) point__;
+// typedef stc_deferred(fwd_qiter) fwd_qiter__;
+
+// typedef stc::final< oln_grid(point__) > grid;
+// typedef stc::final< fwd_qiter__ > qiter;
+
+ typedef stc::final< stc::is<Weighted_Window> > category;
+ };
+
+
+ namespace internal
+ {
+
+ /// Base class for implementation of weighted_window classes.
+
+ template <typename Exact>
+ class weighted_window_base_ : public Weighted_Window<Exact>
+ {
+ public:
+
+ stc_typename(point);
+ stc_typename(weight);
+
+ protected:
+ weighted_window_base_();
+
+ }; // end of class oln::internal::weighted_window_base_<Exact>
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename Exact>
+ weighted_window_base_<Exact>::weighted_window_base_()
+ {
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::internal
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_INTERNAL_WEIGHTED_WINDOW_BASE_HH
Index: oln/core/internal/weighted_dpoints_impl.hh
--- oln/core/internal/weighted_dpoints_impl.hh (revision 0)
+++ oln/core/internal/weighted_dpoints_impl.hh (revision 0)
@@ -0,0 +1,193 @@
+// 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_WEIGHTED_DPOINTS_IMPL_HH
+# define OLN_CORE_INTERNAL_WEIGHTED_DPOINTS_IMPL_HH
+
+# include <set>
+# include <vector>
+# include <ostream>
+# include <oln/core/concept/dpoint.hh>
+# include <oln/core/internal/utils.hh>
+
+
+namespace oln
+{
+
+ namespace internal
+ {
+
+ template <typename W, typename Dp>
+ struct wdp_less_
+ {
+ bool operator()(const internal::pair<W,Dp>& lhs,
+ const internal::pair<W,Dp>& rhs) const
+ {
+ return lhs.second < rhs.second;
+ }
+ };
+
+ /// Implementation for classes storing a set of weighted_dpoints.
+
+ template <typename W, typename Dp>
+ class weighted_dpoints_impl_
+ {
+ public:
+
+ unsigned size() const;
+
+ const W& w(unsigned i) const;
+ const Dp& dp(unsigned i) const;
+
+ const std::vector<W>& weights() const;
+ const std::vector<Dp>& dpoints() const;
+ bool has(const Dp& dp) const;
+
+ protected:
+
+ weighted_dpoints_impl_();
+ void take_(const W& w, const Dp& dp);
+
+ std::vector<W> w_;
+ std::vector<Dp> dp_;
+
+ private:
+
+ void update_();
+
+ typedef std::set< internal::pair<W,Dp>, wdp_less_<W,Dp> > s_wdp_t;
+
+ std::set<Dp> s_dp_;
+ s_wdp_t s_wdp_;
+
+ }; // end of class oln::internal::weighted_dpoints_impl_<W,Dp>
+
+
+ template <typename W, typename Dp>
+ std::ostream& operator<<(std::ostream& ostr,
+ const weighted_dpoints_impl_<W,Dp>& wdps)
+ {
+ ostr << "[ ";
+ unsigned n = wdps.size();
+ for (unsigned i = 0; i < n; ++i)
+ ostr << '{' << wdps.w(i) << ", " << wdps.dp(i) << (i = n - 1 ? "} ]" : "}, ");
+ return ostr;
+ }
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ // public:
+
+ template <typename W, typename Dp>
+ unsigned
+ weighted_dpoints_impl_<W,Dp>::size() const
+ {
+ invariant(dp_.size() = w_.size());
+ return dp_.size();
+ }
+
+ template <typename W, typename Dp>
+ const W&
+ weighted_dpoints_impl_<W,Dp>::w(unsigned i) const
+ {
+ precondition(i < w_.size());
+ return w_[i];
+ }
+
+ template <typename W, typename Dp>
+ const Dp&
+ weighted_dpoints_impl_<W,Dp>::dp(unsigned i) const
+ {
+ precondition(i < dp_.size());
+ return dp_[i];
+ }
+
+ template <typename W, typename Dp>
+ const std::vector<W>&
+ weighted_dpoints_impl_<W,Dp>::weights() const
+ {
+ return w_;
+ }
+
+ template <typename W, typename Dp>
+ const std::vector<Dp>&
+ weighted_dpoints_impl_<W,Dp>::dpoints() const
+ {
+ return dp_;
+ }
+
+ template <typename W, typename Dp>
+ bool
+ weighted_dpoints_impl_<W,Dp>::has(const Dp& dp) const
+ {
+ return s_dp_.find(dp) != s_dp_.end();
+ }
+
+ // protected:
+
+ template <typename W, typename Dp>
+ weighted_dpoints_impl_<W,Dp>::weighted_dpoints_impl_()
+ {
+ mlc::assert_< mlc_is_a(Dp, Dpoint) >::check(); // FIXME: Add err msg.
+ }
+
+ template <typename W, typename Dp>
+ void
+ weighted_dpoints_impl_<W,Dp>::take_(const W& w, const Dp& dp)
+ {
+ precondition(not this->has(dp));
+ s_dp_.insert(dp);
+ internal::pair<W,Dp> tmp(w, dp);
+ s_wdp_.insert(tmp);
+ update_();
+ }
+
+ // private:
+
+ template <typename W, typename Dp>
+ void
+ weighted_dpoints_impl_<W,Dp>::update_()
+ {
+ w_.clear();
+ dp_.clear();
+ typename s_wdp_t::const_iterator i;
+ for (i = s_wdp_.begin(); i != s_wdp_.end(); ++i)
+ {
+ w_ .push_back(i->first);
+ dp_.push_back(i->second);
+ }
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::internal
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_INTERNAL_WEIGHTED_DPOINTS_IMPL_HH
Index: oln/core/internal/window_base.hh
--- oln/core/internal/window_base.hh (revision 954)
+++ oln/core/internal/window_base.hh (working copy)
@@ -60,6 +60,8 @@
typedef stc::final< oln_grid(point__) > grid;
typedef stc::final< fwd_qiter__ > qiter;
+
+ typedef stc::final< stc::is<Window> > category;
};
@@ -88,8 +90,7 @@
{
}
-# endif
-
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln::internal
Index: oln/linear/convolution.hh
--- oln/linear/convolution.hh (revision 0)
+++ oln/linear/convolution.hh (revision 0)
@@ -0,0 +1,154 @@
+// 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_LINEAR_CONVOLUTION_HH
+# define OLN_LINEAR_CONVOLUTION_HH
+
+# 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>
+
+
+namespace oln
+{
+
+ namespace linear
+ {
+
+ // Fwd decls.
+
+ template <typename V, typename I, typename J>
+ oln_plain_value(I, V)
+ convolution(const Image<I>& f, const Image<J>& g);
+
+ template <typename V, typename I, typename W>
+ oln_plain_value(I, V)
+ convolution(const Image<I>& f, const Weighted_Window<W>& w_win);
+
+ template <typename V, typename I, typename W, unsigned n>
+ oln_plain_value(I, V)
+ convolution(const Image<I>& f, const W (&values)[n]);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic versions.
+
+ template <typename V, typename I, typename J>
+ oln_plain_value(I, V)
+ convolution_image_(const Point_Wise_Accessible_Image<I>& f, const Image<J>& g)
+ {
+ 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)
+ {
+ V val = 0;
+ for_all(q)
+ {
+ oln_dpoint(I) dp = O - q.to_point();
+ p_q = p.to_point() + dp;
+ if (f.has(p_q))
+ val += g(q) * f(p_q); // FIXME: f(p + (O - q));
+ }
+ output(p) = val;
+ }
+ return output;
+ }
+
+ template <typename V, typename I, typename W>
+ oln_plain_value(I, V)
+ convolution_window_(const Point_Wise_Accessible_Image<I>& input, const W& win)
+ {
+ oln_plain_value(I, V) output;
+ prepare(output, with, input);
+ oln_piter(I) p(input.points());
+ for_all(p)
+ {
+ V val = 0;
+ for (unsigned i = 0; i < win.size(); ++i)
+ {
+ oln_point(I) q = p.to_point() + win.dp(i);
+ if (input.has(q))
+ val += win.w(i) * input(q);
+ }
+ output(p) = val;
+ }
+ return output;
+ }
+
+ } // end of namespace oln::linear::impl
+
+
+ // Facades.
+
+ template <typename V, typename I, typename J>
+ oln_plain_value(I, V)
+ convolution(const Image<I>& f, const Image<J>& g)
+ {
+ mlc::assert_< mlc_is_a(I, Point_Wise_Accessible_Image) >::check();
+ oln_plain_value(I, V) output = impl::convolution_image_<V>(exact(f), exact(g));
+ return output;
+ }
+
+ template <typename V, typename I, typename W>
+ oln_plain_value(I, V)
+ convolution(const Image<I>& input, const Weighted_Window<W>& w_win)
+ {
+ mlc::assert_< mlc_is_a(I, Point_Wise_Accessible_Image) >::check();
+ oln_plain_value(I, V) output = impl::convolution_window_<V>(exact(input), exact(w_win));
+ return output;
+ }
+
+ template <typename V, typename I, typename W, unsigned n>
+ oln_plain_value(I, V)
+ convolution(const Image<I>& input, const W (&values)[n])
+ {
+ mlc::assert_< mlc_is_a(I, Point_Wise_Accessible_Image) >::check();
+ oln_f_weighted_window(W, oln_dpoint(I)) w_win;
+ w_win.fill_with(values);
+ return linear::convolution<V>(input, w_win);
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::linear
+
+} // end of namespace oln
+
+
+#endif // ! OLN_LINEAR_CONVOLUTION_HH
Index: oln/linear/lap_4.hh
--- oln/linear/lap_4.hh (revision 0)
+++ oln/linear/lap_4.hh (revision 0)
@@ -0,0 +1,82 @@
+// 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_LINEAR_LAP_4_HH
+# define OLN_LINEAR_LAP_4_HH
+
+# include <oln/linear/convolution.hh>
+# include <oln/core/2d/weighted_window2d.hh>
+
+
+namespace oln
+{
+
+ namespace linear
+ {
+
+ // Fwd decl.
+
+ template <typename V, typename I>
+ oln_plain_value(I, V)
+ lap_4(const Image_2D<I>& f);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename V, typename I>
+ oln_plain_value(I, V)
+ lap_4_(const Image_2D<I>& f)
+ {
+ int values[] = { 0, 1, 0,
+ 1, -4, 1,
+ 0, 1, 0 };
+ return linear::convolution<V>(f, values);
+ }
+
+
+ } // end of namespace oln::linear::impl
+
+ template <typename V, typename I>
+ oln_plain_value(I, V)
+ lap_4(const Image_2D<I>& f)
+ {
+ return impl::lap_4_<V>(f);
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::linear
+
+} // end of namespace oln
+
+
+#endif // ! OLN_LINEAR_LAP_4_HH
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add tour3.cc and update.
* doc/tour/tour3.cc: New.
* oln/convert: New directory.
* oln/convert/to_window.hh: New.
* oln/core/internal/f_grid_to_window.hh: New.
* oln/core/internal/f_image_to_window.hh: New.
* doc/tour/tour2.cc: Add some text.
* doc/tour/tour1_extra.cc (include): Fix missing.
(at): Update.
* doc/tour/tour1.cc: Change a word.
* oln/debug/fill.hh (fill_): New.
(fill): Update.
* oln/debug/print.hh (format): Move into...
* oln/debug/format.hh: ...this new file.
* oln/core/1d/window1d.hh: Fix.
* oln/core/1d/image1d.hh,
* oln/core/2d/image2d_b.hh,
* oln/core/3d/image3d.hh (init_): New.
* oln/core/gen/torus_pset.hh (operator Ps): New.
(torus_pset): Fix ctor.
* oln/core/gen/niter_has.hh: Update.
* oln/core/gen/fun_ops.hh (oln_decl_p2v_cmp_): New overload.
* oln/core/concept/image.hh (dpoint): New in Image.
* oln/core/internal/box.hh: Add static check.
* oln/core/internal/op_image_extended_by_nbh.hh (operator I): New.
* oln/core/internal/point_base.hh (point_base_): New ctor overload;
decl only.
* oln/core/internal/op_pset_such_as_fp2b.hh
(pset_such_as_fp2b_fwd_piter_),
(pset_such_as_fp2b_bkd_piter_): New ctor overload.
* oln/core/internal/iterator_on_points_impl.hh
(iterator_on_points_impl_base_): New.
(vec): New.
* oln/core/internal/iterator_on_points_base.hh (point):
Disambiguate.
* oln/level/local.hh: Update.
* oln/level/clone.hh (clone_): New.
(clone): Update.
doc/tour/tour1.cc | 2
doc/tour/tour1_extra.cc | 6
doc/tour/tour2.cc | 47 +++
doc/tour/tour3.cc | 331
++++++++++++++++++++++++++
oln/convert/to_window.hh | 76 +++++
oln/core/1d/image1d.hh | 10
oln/core/1d/window1d.hh | 2
oln/core/2d/image2d_b.hh | 25 -
oln/core/3d/image3d.hh | 10
oln/core/concept/image.hh | 1
oln/core/gen/fun_ops.hh | 10
oln/core/gen/niter_has.hh | 10
oln/core/gen/torus_pset.hh | 16 -
oln/core/internal/box.hh | 2
oln/core/internal/f_grid_to_window.hh | 118 +++++++++
oln/core/internal/f_image_to_window.hh | 37 ++
oln/core/internal/iterator_on_points_base.hh | 3
oln/core/internal/iterator_on_points_impl.hh | 38 ++
oln/core/internal/op_image_extended_by_nbh.hh | 7
oln/core/internal/op_pset_such_as_fp2b.hh | 17 +
oln/core/internal/point_base.hh | 3
oln/debug/fill.hh | 25 +
oln/debug/format.hh | 76 +++++
oln/debug/print.hh | 18 -
oln/level/clone.hh | 6
oln/level/local.hh | 6
26 files changed, 840 insertions(+), 62 deletions(-)
Index: doc/tour/tour2.cc
--- doc/tour/tour2.cc (revision 952)
+++ doc/tour/tour2.cc (working copy)
@@ -29,12 +29,10 @@
#include <oln/core/2d/image2d.hh>
#include <oln/core/2d/window2d.hh>
-#include <oln/level/fill.hh>
#include <oln/debug/println.hh>
-
// Note to the reader: If you do not have read the tour1.cc file, you
// should have a quick look at it before proceeding with this present
// file. Some important features and practices are described in the
@@ -318,9 +316,52 @@
} // End of 2nd version.
+ std::cout << std::endl;
+
+
+ // Above, p and q behave just like points; for instance, the
+ // following expressions are valid:
+
+ // int r = p.row();
+ // to get the current row value,
+
+ // bool b = img(p);
+ // to get the pixel value at the current point,
+
+ // or point2d pp = p + dp;
+ // where dp is a delta-point to get a point nearby p.
+
+ // Yet, p and q are "more than points" since they allow to
+ // browse/iterate over a set of points, respectivelly, the domain of
+ // 'img' and the window centered at p.
+
+
+ // The domain of 'img' is obtained with "img.points()" and is
+ // provided to the 'p' object so that it knows how to iterate.
+
+ // For a "basic" image, its set of points is an n-dimensional box.
+ // In the 2D space, the box type is called 'box2d'. We also have
+ // 'box1d' and 'box3d' for other dimensions.
+
+ box2d pts = img.points();
+ std::cout << "img points are " << pts << std::endl;
+ // Prints:
+ // img points are { (0, 0) .. (3, 4) }
+
+ // The type of iterators over a point set is obtained with the
+ // expression: "name_of_the_point_set_type::piter", where 'piter'
+ // means "point iterator" for short.
+
+ // The same construction is available for iterators on window
+ // points, whose types are obtained in a similar way with
+ // "name_of_the_window_type::qiter". Here the 'q' in 'qiter'
+ // emphases the fact that a window is not really a set of points but
+ // "a set of dpoints and a center point".
+
- // This last version is:
+ // The second version of our example contrasts with the more
+ // "classical" ones; it is:
// - shorter,
// so it is less error-prone for the developer;
Index: doc/tour/tour3.cc
--- doc/tour/tour3.cc (revision 0)
+++ doc/tour/tour3.cc (revision 0)
@@ -0,0 +1,331 @@
+// Copyright (C) 2001, 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+// File: tour2.cc.
+
+#include <oln/core/2d/image2d.hh>
+#include <oln/core/2d/neighb2d.hh>
+
+#include <oln/core/gen/such_as.hh>
+#include <oln/core/gen/torus_image.hh>
+#include <oln/core/gen/pw_value.hh>
+#include <oln/core/gen/fun_ops.hh>
+
+#include <oln/level/fill.hh>
+#include <oln/debug/fill.hh>
+#include <oln/debug/println.hh>
+
+
+// Note to the reader: you should have read the files tour1.cc and
+// tour2.cc before starting with this present file.
+
+
+
+// We have encapsulated an algorithm into a procedure which is forward
+// declared below so that it can be used in the section 'main'.
+template <typename I> void algo(const I& img);
+
+
+// Some functions that will be useful in the following:
+bool chessboard(oln::point2d p)
+{
+ return (p.row() + p.col()) % 2;
+}
+
+
+
+int main()
+{
+ using namespace oln;
+
+ // First our domain is 2d box:
+ box2d b(point2d(0, 0), point2d(2, 2));
+ // ^^^^ ^^^^
+ // from to
+
+ // We define a binary image with values on that box.
+ image2d<bool> img(b);
+
+ // With an array of Booleans (1 means true, 0 means false)...
+ bool vals[] = { 1, 0, 0,
+ 0, 1, 0,
+ 0, 1, 1 };
+ // ...the debug::fill routine allows for manually initializing
+ // image data:
+ debug::fill(inplace(img), vals);
+ std::cout << "img = " << std::endl;
+ debug::println(img);
+ // img =
+ // | - -
+ // - | -
+ // - | |
+
+ image2d<int> ima(b); // An image of integers with the same
+ box2d::piter p(ima.points()); // domain as img...
+ int i = 0;
+ for_all(p)
+ ima(p) = i++; // ...and manually filled with values.
+
+ std::cout << "ima = " << std::endl;
+ debug::println(ima);
+ // ima =
+ // 0 1 2
+ // 3 4 5
+ // 6 7 8
+
+ /* HERE
+
+ // The algorithm defined at the end of this file is very close to
+ // the one of the tour former file. The major difference is that it
+ // does not rely on a window but on a neighborhood.
+
+ // In image processing, we usually say that "an image has a given
+ // neighborhood" or that "we associate/embed a neighborhood to/into
+ // an image". In Olena, that is really the case: the image can
+ // "have" a neighborhood, meaning that a neighborhood can be added
+ // to an image in order to obtain an "image with a neighborhood".
+
+ // Joining an image with a neighborhood is performed with the
+ // operator '+':
+ algo(ima + c4); // c4 is the 2D neighborhood corresponding to
+ // 4-connectivity; such as many classical
+ // neighborhoods it is provided by Olena.
+ // The result is given below.
+
+ // ---input:
+ // 0 1 2
+ // 1 2 3
+ // 2 3 4
+ // ---output:
+ // 0: 1 1
+ // 1: 0 2 2
+ // 2: 1 3
+ // 1: 0 2 2
+ // 2: 1 1 3 3
+ // 3: 2 2 4
+ // 2: 1 3
+ // 3: 2 2 4
+ // 4: 3 3
+
+ // That was expectable...
+
+
+ // And now for a little test: what is the result of this code?
+ {
+ image2d<int> test(ima.points());
+ level::fill(inplace(test), ima);
+ (test + c4).at(1, 1) = 9;
+ debug::println(test);
+ }
+ // and can you tell why?
+ // The answers are given in the file tour3-test.txt
+
+
+ // Now let us start experimenting the genericity of Olena!
+
+
+ // First, imagine that you want to restrict the domain of ima to a
+ // subset of points, a region or whatever. For instance, the
+ // chessboard function takes a point as argument and returns a
+ // Boolean so it is like a predicate. We can want to consider only
+ // the points of ima "such as" this predicate is verified. The
+ // "such as" mathematical symbol is '|' so let's rock:
+
+ algo((ima | chessboard) + c8);
+ // gives:
+
+ // ---input:
+ // 1
+ // 3 5
+ // 7
+ // ---output:
+ // 1: 3 5
+ // 3: 1 7
+ // 5: 1 7
+ // 7: 3 5
+
+ // where the blanks in printing the input image denote that the
+ // corresponding points do NOT belong to the image domain.
+
+ // Another similar example is based on the binary image created at
+ // the beginning of this tour:
+ algo((ima | img) + c8);
+ // which gives:
+
+ // ---input:
+ // 0
+ // 4
+ // 7 8
+ // ---output:
+ // 0: 4
+ // 4: 0 7 8
+ // 7: 4 8
+ // 8: 4 7
+
+
+
+ // Second, imagine that you want your initial image to get the
+ // geodesy of a torus, that is, a 2D image wrapped on a torus.
+ // Points located at the image boundary have neighbors; for
+ // instance, the point denoted by the 'x' cross below has for
+ // 4-connectivity neighbors: t, l, r, and b (respectively for top,
+ // left, right, and bottom):
+
+ // b o o o
+ // o o o o
+ // t o o o
+ // x r o l
+
+ // Let us try:
+ algo(torus(ima) + c8);
+ // gives:
+
+ // ---input:
+ // 0 1 2
+ // 3 4 5
+ // 6 7 8
+ // ---output:
+ // 0: 8 6 7 2 1 5 3 4
+ // 1: 6 7 8 0 2 3 4 5
+ // 2: 7 8 6 1 0 4 5 3
+ // 3: 2 0 1 5 4 8 6 7
+ // 4: 0 1 2 3 5 6 7 8
+ // 5: 1 2 0 4 3 7 8 6
+ // 6: 5 3 4 8 7 2 0 1
+ // 7: 3 4 5 6 8 0 1 2
+ // 8: 4 5 3 7 6 1 2 0
+
+
+
+ // We can have both the torus geodesy and a sub-domain:
+
+ algo(torus(ima | chessboard) + c8);
+ algo(torus(ima | img) + c8);
+
+ // which respectively give:
+
+ // ---input:
+ // 1
+ // 3 5
+ // 7
+ // ---output:
+ // 1: 7 3 5
+ // 3: 1 5 7
+ // 5: 1 3 7
+ // 7: 3 5 1
+
+ // and:
+
+ // ---input:
+ // 0
+ // 4
+ // 7 8
+ // ---output:
+ // 0: 8 7 4
+ // 4: 0 7 8
+ // 7: 4 8 0
+ // 8: 4 7 0
+
+
+ */
+
+ // Last, the way a predicate is defined can also rely on some image
+ // values. For that the user can on the fly provide an expression
+ // built with the "pw_value" facility, where "pw_" means
+ // "point-wise" for short:
+
+ algo((ima | (pw_value(ima) < 4)) + c4);
+
+ // In this example, "pw_value(ima)" is the function that represents
+ // the point-wise value of the 'ima' image, that is, the function
+ // "p -> ima(p)". This naturally leads to:
+
+ // ---input:
+ // 0 1 2
+ // 3
+ //
+ // ---output:
+ // 0: 1 3
+ // 1: 0 2
+ // 2: 1
+ // 3: 0
+
+
+
+ // From those examples, you should realize that:
+
+
+ // +-----------------------------------------------------------+
+ // | |
+ // | The level of "genericity" provided by Olena is rather |
+ // | high; it means: |
+ // | |
+ // | - taking the image dimension you work on; |
+ // | |
+ // | - having the type of pixel values you need; |
+ // | |
+ // | - choosing the neighborhood you want; |
+ // | |
+ // | - changing the geodesy if you need it; |
+ // | |
+ // | - being able to restrict the image domain; |
+ // | |
+ // | - and many other features that are addressed further |
+ // | in the tour... |
+ // | |
+ // +-----------------------------------------------------------+
+
+}
+
+
+
+
+
+// The algorithm 'algo':
+
+template <typename I>
+void algo(const I& img)
+{
+ std::cout << "---input:" << std::endl;
+ oln::debug::print(img);
+ std::cout << "---output:" << std::endl;
+
+ oln_piter(I) p(img.points()); // p iterates on img points
+ oln_niter(I) n(img, p); // n iterates in img on neighbors of p
+
+ for_all(p)
+ {
+ std::cout << oln::debug::format(img(p))
+ << ':';
+ for_all(n)
+ std::cout << ' '
+ << oln::debug::format(img(n));
+ std::cout << std::endl;
+ }
+
+ std::cout << std::endl;
+}
Index: doc/tour/tour1_extra.cc
--- doc/tour/tour1_extra.cc (revision 952)
+++ doc/tour/tour1_extra.cc (working copy)
@@ -29,6 +29,8 @@
#include <oln/core/1d/image1d.hh>
#include <oln/arith/plus.hh>
+#include <oln/debug/println.hh>
+
int main()
@@ -91,7 +93,7 @@
{
image1d<int> orig(5); // An original image.
for (int i = 0; i < 5; ++i)
- orig(i) = i;
+ orig.at(i) = i;
debug::println(orig);
// 0 1 2 3 4
@@ -160,7 +162,7 @@
{
image1d<int> ima(5);
for (int i = 0; i < 5; ++i)
- ima(i) = i;
+ ima.at(i) = i;
debug::println(ima);
// 0 1 2 3 4
Index: doc/tour/tour1.cc
--- doc/tour/tour1.cc (revision 952)
+++ doc/tour/tour1.cc (working copy)
@@ -311,7 +311,7 @@
// Indeed, the loops above depict the "classical" way to iterate
- // over the contents of a 1D image. The next tour file explains
+ // over the contents of a 1D image. The next tour file introduces
// the solution provided by Olena to write better loops...
Index: oln/convert/to_window.hh
--- oln/convert/to_window.hh (revision 0)
+++ oln/convert/to_window.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 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_WINDOW_HH
+# define OLN_CONVERT_TO_WINDOW_HH
+
+# include <oln/core/concept/image.hh>
+# include <oln/core/internal/f_image_to_window.hh>
+
+
+namespace oln
+{
+
+ namespace convert
+ {
+
+ // Fwd decl.
+
+ template <typename I>
+ oln_f_image_to_window(I)
+ to_window(const Binary_Image<I>& input);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ // Generic version.
+
+ template <typename I>
+ oln_f_image_to_window(I)
+ to_window(const Binary_Image<I>& input)
+ {
+ oln_f_image_to_window(I) tmp;
+ oln_dpoint(I) dp;
+ oln_piter(I) p(input.points());
+ for_all(p)
+ if (input(p) == true)
+ {
+ dp.vec() = p.vec();
+ // FIXME: Better s.a. dp = p.to_dpoint();
+ tmp.take(dp);
+ }
+ return tmp;
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::convert
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CONVERT_TO_WINDOW_HH
Index: oln/debug/fill.hh
--- oln/debug/fill.hh (revision 952)
+++ oln/debug/fill.hh (working copy)
@@ -39,26 +39,37 @@
{
template <typename I, typename V>
- void fill(Mutable_Image<I>& in_out, const V values[]);
-
- template <typename I, typename V>
void fill(inplace_<I> in_out, const V values[]);
# ifndef OLN_INCLUDE_ONLY
- template <typename I>
- void fill(Mutable_Image<I>& in_out, const oln_value(I)& value)
+ namespace impl
+ {
+
+ template <typename I, typename V>
+ void fill_(Mutable_Image<I>& in_out, const V values[])
{
+ unsigned i = 0;
oln_piter(I) p(in_out.points());
for_all(p)
- in_out(p) = value;
+ in_out(p) = values[i++];
}
+ } // end of namespace oln::impl
+
template <typename I, typename V>
void fill(inplace_<I> in_out, const V values[])
{
- fill(in_out.unwrap(), values);
+ impl::fill_(in_out.unwrap(), values);
+ }
+
+ // Guard.
+
+ template <typename I, typename V>
+ void fill(const Image<I>&, const V[])
+ {
+ mlc::abort_<I>::check(); // FIXME: Add err msg.
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/debug/format.hh
--- oln/debug/format.hh (revision 0)
+++ oln/debug/format.hh (revision 0)
@@ -0,0 +1,76 @@
+// Copyright (C) 2006, 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_DEBUG_FORMAT_HH
+# define OLN_DEBUG_FORMAT_HH
+
+
+namespace oln
+{
+
+ namespace debug
+ {
+
+ // Fwd decls.
+
+ template <typename T>
+ const T&
+ format(const T& value);
+
+ unsigned
+ format(const unsigned char& value);
+
+ char
+ format(bool value);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename T>
+ const T& format(const T& value)
+ {
+ return value;
+ }
+
+ unsigned format(const unsigned char& value)
+ {
+ return value;
+ }
+
+ char format(bool value)
+ {
+ return value ? '|' : '-';
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::debug
+
+} // end of namespace oln
+
+
+#endif // ! OLN_DEBUG_FORMAT_HH
Index: oln/debug/print.hh
--- oln/debug/print.hh (revision 952)
+++ oln/debug/print.hh (working copy)
@@ -30,6 +30,7 @@
# include <iostream>
# include <oln/core/concept/image.hh>
+# include <oln/debug/format.hh>
# ifdef OLN_ENV_2D
# include <oln/core/2d/point2d.hh>
@@ -53,23 +54,6 @@
namespace impl
{
- template <typename T>
- const T& format(const T& value)
- {
- return value;
- }
-
- unsigned format(const unsigned char& value)
- {
- return value;
- }
-
- char format(bool value)
- {
- return value ? '|' : '-';
- }
-
-
/// Generic version.
template <typename I>
Index: oln/core/1d/image1d.hh
--- oln/core/1d/image1d.hh (revision 952)
+++ oln/core/1d/image1d.hh (working copy)
@@ -108,6 +108,9 @@
template <typename T, typename D>
bool prepare(image1d<T>& target, with_t, const D& dat);
+ template <typename T>
+ bool init_(box1d* this_, const image1d<T>& data);
+
# ifndef OLN_INCLUDE_ONLY
@@ -242,6 +245,13 @@
return box_ok;
}
+ template <typename T>
+ bool init_(box1d* this_, const image1d<T>& data)
+ {
+ *this_ = data.bbox();
+ return true;
+ }
+
# endif // ! OLN_INCLUDE_ONLY
Index: oln/core/1d/window1d.hh
--- oln/core/1d/window1d.hh (revision 952)
+++ oln/core/1d/window1d.hh (working copy)
@@ -36,7 +36,7 @@
{
// FIXME: window1d should be an actual type, not an alias...
- typedef window_<dpoint1d> window1d;
+ typedef gen_window<dpoint1d> window1d;
} // end of namespace oln
Index: oln/core/2d/image2d_b.hh
--- oln/core/2d/image2d_b.hh (revision 952)
+++ oln/core/2d/image2d_b.hh (working copy)
@@ -114,12 +114,12 @@
std::size_t pad(const dpoint2d& dp) const;
};
-// template <typename T, typename D>
-// bool init_(image2d_b<T>* this_, const D& dat);
-
template <typename T, typename D>
bool prepare(image2d_b<T>& target, with_t, const D& dat);
+ template <typename T>
+ bool init_(box2d* this_, const image2d_b<T>& data);
+
# ifndef OLN_INCLUDE_ONLY
@@ -239,18 +239,6 @@
return this->data_->first.i_pad() * dp.row() + dp.col();
}
-// template <typename T, typename D>
-// bool init_(image2d_b<T>* this_, const D& dat)
-// {
-// precondition(not this_->has_data());
-// box2d b;
-// bool box_ok = init(b, with, dat);
-// postcondition(box_ok);
-// unsigned border = 2; // FIXME: Use init!
-// this_->data__() = new typename image2d_b<T>::data(b.pmin(),
b.pmax(), border);
-// return box_ok;
-// }
-
template <typename T, typename D>
bool prepare(image2d_b<T>& target, with_t, const D& dat)
{
@@ -267,6 +255,13 @@
return box_ok;
}
+ template <typename T>
+ bool init_(box2d* this_, const image2d_b<T>& data)
+ {
+ *this_ = data.bbox();
+ return true;
+ }
+
# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/3d/image3d.hh
--- oln/core/3d/image3d.hh (revision 952)
+++ oln/core/3d/image3d.hh (working copy)
@@ -109,6 +109,9 @@
template <typename T, typename D>
bool prepare(image3d<T>& target, with_t, const D& dat);
+ template <typename T>
+ bool init_(box3d* this_, const image3d<T>& data);
+
# ifndef OLN_INCLUDE_ONLY
@@ -240,6 +243,13 @@
return box_ok;
}
+ template <typename T>
+ bool init_(box3d* this_, const image3d<T>& data)
+ {
+ *this_ = data.bbox();
+ return true;
+ }
+
# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/gen/torus_pset.hh
--- oln/core/gen/torus_pset.hh (revision 952)
+++ oln/core/gen/torus_pset.hh (working copy)
@@ -76,6 +76,8 @@
torus_pset(const Ps& pset);
void init_pset(const Ps& pset);
+ operator Ps() const;
+
point relocate(const point& p) const;
bool impl_has(const point& p) const;
@@ -105,9 +107,9 @@
: super(pset)
{
mlc::assert_< mlc_is_a(Ps, Point_Set) >::check();
- this->pmin_ = pset.pmin();
+ this->pmin_ = pset.bbox().pmin();
dpoint unit; unit.set_all(1);
- this->size_ = pset.pmax() - pset.pmin() + unit;
+ this->size_ = pset.bbox().pmax() - pset.bbox().pmin() + unit;
}
template <typename Ps>
@@ -115,9 +117,15 @@
current::init_pset(const Ps& pset)
{
this->ps_ = pset;
- this->pmin_ = pset.pmin();
+ this->pmin_ = pset.bbox().pmin();
dpoint unit; unit.set_all(1);
- this->size_ = pset.pmax() - pset.pmin() + unit;
+ this->size_ = pset.bbox().pmax() - pset.bbox().pmin() + unit;
+ }
+
+ template <typename Ps>
+ current::operator Ps() const
+ {
+ return this->ps_;
}
template <typename Ps>
Index: oln/core/gen/niter_has.hh
--- oln/core/gen/niter_has.hh (revision 952)
+++ oln/core/gen/niter_has.hh (working copy)
@@ -69,8 +69,8 @@
{
public:
- template <typename Pl, typename I>
- niter_has_(const Generalized_Point<Pl>& p, const Image_with_Nbh<I>&
ima);
+ template <typename I, typename Pl>
+ niter_has_(const Image_with_Nbh<I>& ima, const
Generalized_Point<Pl>& p);
void impl_start();
void impl_next();
@@ -87,10 +87,10 @@
# ifndef OLN_INCLUDE_ONLY
template <typename It, typename Ps>
- template <typename Pl, typename I>
- current::niter_has_(const Generalized_Point<Pl>& p, const
Image_with_Nbh<I>& ima)
+ template <typename I, typename Pl>
+ current::niter_has_(const Image_with_Nbh<I>& ima, const
Generalized_Point<Pl>& p)
:
- super( It(p, ima) ),
+ super( It(ima, p) ),
pset_( ima.points() )
{
}
Index: oln/core/gen/fun_ops.hh
--- oln/core/gen/fun_ops.hh (revision 952)
+++ oln/core/gen/fun_ops.hh (working copy)
@@ -76,6 +76,16 @@
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) \
+ { \
+ 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; \
+ } \
+ \
struct e_n_d___w_i_t_h___s_e_m_i_c_o_l_u_m_n
Index: oln/core/concept/image.hh
--- oln/core/concept/image.hh (revision 952)
+++ oln/core/concept/image.hh (working copy)
@@ -127,6 +127,7 @@
stc_typename(box);
stc_typename(pset);
+ stc_typename(dpoint);
// stc_typename(output); // FIXME: Uncomment!
stc_typename(plain);
Index: oln/core/internal/box.hh
--- oln/core/internal/box.hh (revision 952)
+++ oln/core/internal/box.hh (working copy)
@@ -306,6 +306,7 @@
box_fwd_piter_<B>::box_fwd_piter_(const Point_Set<Ps>& ps)
: b_(ps.bbox())
{
+ mlc::assert_< mlc_is_a(B, Point_Set) >::check(); // FIXME: Add err msg.
nop_ = b_.pmax();
++nop_[0];
p_ = nop_;
@@ -371,6 +372,7 @@
box_bkd_piter_<B>::box_bkd_piter_(const Point_Set<Ps>& ps)
: b_(ps.bbox())
{
+ mlc::assert_< mlc_is_a(B, Point_Set) >::check(); // FIXME: Add err msg.
nop_ = b_.pmin();
--nop_[0];
p_ = nop_;
Index: oln/core/internal/op_image_extended_by_nbh.hh
--- oln/core/internal/op_image_extended_by_nbh.hh (revision 952)
+++ oln/core/internal/op_image_extended_by_nbh.hh (working copy)
@@ -108,6 +108,8 @@
const nbh& impl_nbhood() const;
nbh& impl_nbhood();
+ operator I() const;
+
protected:
special_op_();
special_op_(I& ima, N& n);
@@ -150,6 +152,11 @@
namespace internal
{
+ template <typename I, typename N>
+ current::operator I() const
+ {
+ return this->image();
+ }
template <typename I, typename N>
current::special_op_()
Index: oln/core/internal/point_base.hh
--- oln/core/internal/point_base.hh (revision 952)
+++ oln/core/internal/point_base.hh (working copy)
@@ -97,8 +97,11 @@
vec_t& vec();
void set_all(const coord& c);
+ // FIXME: Add 'static const Exact& zero();'
+
protected:
point_base_();
+ point_base_(coord val);
vec_t v_;
};
Index: oln/core/internal/f_grid_to_window.hh
--- oln/core/internal/f_grid_to_window.hh (revision 0)
+++ oln/core/internal/f_grid_to_window.hh (revision 0)
@@ -0,0 +1,118 @@
+// 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_F_GRID_TO_WINDOW_HH
+# define OLN_CORE_INTERNAL_F_GRID_TO_WINDOW_HH
+
+# include <oln/core/concept/grid.hh>
+# include <oln/core/gen/window.hh>
+
+
+#define oln_f_grid_to_window(G) typename
oln::internal::f_grid_to_window_< G >::ret
+
+
+namespace oln
+{
+
+ /// \{
+ /// Forward declarations.
+
+ // Grid types.
+
+ struct grid1d;
+ struct grid2d;
+ struct grid2d_hex;
+ struct grid2d_tri;
+ struct grid3d;
+ // ...
+
+ // Dpoint types.
+ struct dpoint1d;
+ struct dpoint2d;
+ struct dpoint3d;
+ // ...
+
+ // Window types.
+
+ typedef gen_window<dpoint1d> window1d;
+ typedef gen_window<dpoint2d> window2d;
+ typedef gen_window<dpoint3d> window3d;
+ // ...
+
+ /// \}
+
+
+
+ namespace internal
+ {
+
+ // Fwd decl.
+
+ template <typename G> struct f_grid_to_;
+
+
+ /// \{
+ /// Definitions.
+
+ template <typename G>
+ struct grid_to_window__;
+
+ template <>
+ struct grid_to_window__< grid1d >
+ {
+ typedef window1d ret;
+ };
+
+ template <>
+ struct grid_to_window__< grid2d >
+ {
+ typedef window2d ret;
+ };
+
+ // FIXME: 2D hex/tri...
+
+ template <>
+ struct grid_to_window__< grid3d >
+ {
+ typedef window3d ret;
+ };
+
+ /// \}
+
+
+ template <typename G>
+ struct f_grid_to_window_ : private mlc::assert_< mlc_is_a(G, Grid) >,
+ public grid_to_window__< G >
+ {
+ };
+
+ } // end of namespace oln::internal
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_INTERNAL_F_GRID_TO_WINDOW_HH
Index: oln/core/internal/op_pset_such_as_fp2b.hh
--- oln/core/internal/op_pset_such_as_fp2b.hh (revision 952)
+++ oln/core/internal/op_pset_such_as_fp2b.hh (working copy)
@@ -209,7 +209,7 @@
{
public:
- pset_such_as_fp2b_fwd_piter_();
+ pset_such_as_fp2b_fwd_piter_(const op_<S, such_as, F>& pset);
pset_such_as_fp2b_fwd_piter_(const Point_Set< op_<S, such_as, F>
>& pset);
void impl_start();
@@ -224,6 +224,13 @@
# ifndef OLN_INCLUDE_ONLY
template <typename S, typename F>
+ current::pset_such_as_fp2b_fwd_piter_(const op_<S, such_as, F>& pset)
+ : super(pset.adapted_()),
+ f_(pset.fun_())
+ {
+ }
+
+ template <typename S, typename F>
current::pset_such_as_fp2b_fwd_piter_(const Point_Set< op_<S,
such_as, F> >& pset)
: super(exact(pset).adapted_()),
f_(exact(pset).fun_())
@@ -285,6 +292,7 @@
{
public:
+ pset_such_as_fp2b_bkd_piter_(const op_<S, such_as, F>& pset);
pset_such_as_fp2b_bkd_piter_(const Point_Set< op_<S, such_as, F>
>& pset);
void impl_start();
@@ -299,6 +307,13 @@
# ifndef OLN_INCLUDE_ONLY
template <typename S, typename F>
+ current::pset_such_as_fp2b_bkd_piter_(const op_<S, such_as, F>& pset)
+ : super(pset.adapted_()),
+ f_(pset.fun_())
+ {
+ }
+
+ template <typename S, typename F>
current::pset_such_as_fp2b_bkd_piter_(const Point_Set< op_<S,
such_as, F> >& pset)
: super(exact(pset).adapted_()),
f_(exact(pset).fun_())
Index: oln/core/internal/iterator_on_points_impl.hh
--- oln/core/internal/iterator_on_points_impl.hh (revision 952)
+++ oln/core/internal/iterator_on_points_impl.hh (working copy)
@@ -37,6 +37,22 @@
namespace internal
{
+ // base impl
+
+ template <typename Exact>
+ struct iterator_on_points_impl_base_
+ {
+ private:
+ stc_typename(point);
+ typedef typename point::vec_t vec_t;
+ public:
+ const vec_t& vec() const;
+ vec_t& vec();
+ };
+
+
+ // no-d impl is empty
+
template <unsigned n, typename Exact>
struct iterator_on_points_impl_
{
@@ -45,6 +61,8 @@
// 1d impl
template <typename Exact>
struct iterator_on_points_impl_< 1, Exact >
+ :
+ public iterator_on_points_impl_base_<Exact>
{
private:
stc_typename(coord);
@@ -55,6 +73,8 @@
// 2d impl
template <typename Exact>
struct iterator_on_points_impl_< 2, Exact >
+ :
+ public iterator_on_points_impl_base_<Exact>
{
private:
stc_typename(coord);
@@ -66,6 +86,8 @@
// 3d impl
template <typename Exact>
struct iterator_on_points_impl_< 3, Exact >
+ :
+ public iterator_on_points_impl_base_<Exact>
{
private:
stc_typename(coord);
@@ -77,6 +99,22 @@
# ifndef OLN_INCLUDE_ONLY
+ // base impl
+
+ template <typename Exact>
+ const typename iterator_on_points_impl_base_<Exact>::vec_t&
+ iterator_on_points_impl_base_<Exact>::vec() const
+ {
+ return static_cast<const Exact&>(*this).to_point().vec();
+ }
+
+ template <typename Exact>
+ typename iterator_on_points_impl_base_<Exact>::vec_t&
+ iterator_on_points_impl_base_<Exact>::vec()
+ {
+ return static_cast<const Exact&>(*this).to_point().vec();
+ }
+
// 1d impl
template <typename Exact>
Index: oln/core/internal/iterator_on_points_base.hh
--- oln/core/internal/iterator_on_points_base.hh (revision 952)
+++ oln/core/internal/iterator_on_points_base.hh (working copy)
@@ -69,6 +69,9 @@
: public Iterator_on_Points<Exact>,
public
internal::iterator_on_points_impl_<mlc_value(stc_deferred(dim)), Exact>
{
+ public:
+ // Disambiguate.
+ stc_using_from(Iterator_on_Points, point);
protected:
iterator_on_points_base_();
};
Index: oln/core/internal/f_image_to_window.hh
--- oln/core/internal/f_image_to_window.hh (revision 0)
+++ oln/core/internal/f_image_to_window.hh (revision 0)
@@ -0,0 +1,37 @@
+// 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_F_IMAGE_TO_WINDOW_HH
+# define OLN_CORE_INTERNAL_F_IMAGE_TO_WINDOW_HH
+
+# include <oln/core/internal/f_grid_to_window.hh>
+
+
+#define oln_f_image_to_window(I) oln_f_grid_to_window(oln_grid(I))
+
+
+#endif // ! OLN_CORE_INTERNAL_F_IMAGE_TO_WINDOW_HH
Index: oln/level/local.hh
--- oln/level/local.hh (revision 952)
+++ oln/level/local.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)
f(input(n));
return f.value();
@@ -85,7 +85,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)
{
f(input(n)); // FIXME: Change to f.take(input(n))?
@@ -104,7 +104,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)
{
f(input(n)); // FIXME: Change to f.take(input(n))?
Index: oln/level/clone.hh
--- oln/level/clone.hh (revision 952)
+++ oln/level/clone.hh (working copy)
@@ -50,11 +50,11 @@
// Generic version.
template <typename I>
- oln_plain(I) clone(const Image<I>& input)
+ oln_plain(I) clone_(const Image<I>& input)
{
oln_plain(I) output;
prepare(output, with, input);
- level::fill(output, input);
+ level::fill(inplace(output), input);
return output;
}
@@ -65,7 +65,7 @@
template <typename I>
oln_plain(I) clone(const Image<I>& input)
{
- return impl::clone(input);
+ return impl::clone_(input);
}
# endif // ! OLN_INCLUDE_ONLY