Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Canvas : Add union-find, two_pass version. Fix reconstruction.
* oln/core/internal/point_impl.hh: Whitespaces.
* oln/morpho/binary_reconstruction_v0.hh: Procedure version.
* oln/morpho/fast_binary_reconstruction.hh: Fast hybrid version.
* oln/morpho/reconstruction.hh: removed.
* oln/morpho/binary_reconstruction.hh: Removed.
* oln/morpho/binary_reconstruction_v1.hh: Canvas version.
* oln/level/local_sup.hh: Fixed.
* oln/level/local_inf.hh: Fixed.
* oln/canvas/union_find.hh: New.
* oln/canvas/two_pass.hh: New version (v4) with inheritens.
canvas/two_pass.hh | 40 ++++++------
canvas/union_find.hh | 76 ++++++++++++++++++++++
level/local_inf.hh | 6 -
level/local_sup.hh | 6 -
morpho/binary_reconstruction_v0.hh | 123 +++++++++++++++++++++++++++++++++++++
morpho/binary_reconstruction_v1.hh | 122 ++++++++++++++++++++++++++++++++++++
morpho/cc_tarjan_v1.hh | 5 -
7 files changed, 353 insertions(+), 25 deletions(-)
Index: oln/core/internal/point_impl.hh
Index: oln/morpho/binary_reconstruction_v0.hh
--- oln/morpho/binary_reconstruction_v0.hh (revision 0)
+++ oln/morpho/binary_reconstruction_v0.hh (revision 0)
@@ -0,0 +1,123 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_MORPHO_BINARY_RECONSTRUCTION_HH
+# define OLN_MORPHO_BINARY_RECONSTRUCTION_HH
+
+# include <oln/core/concept/image.hh>
+# include <oln/accumulator/max.hh>
+# include <oln/level/clone.hh>
+# include <oln/level/fill.hh>
+# include <oln/level/local_inf.hh>
+# include <oln/level/local_sup.hh>
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ template <typename I , typename J>
+ void
+ binary_reconstruction(const Binary_Image<I>& marker,
+ const Binary_Image<J>& mask);
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ template <typename I>
+ bool
+ stability(const Image_with_Nbh<I>& marker,
+ oln_plain(I)& tmp)
+ {
+ oln_piter(I) p(marker.points());
+ for_all(p)
+ if (marker(p) != tmp(p))
+ return false;
+ return true;
+ }
+
+ template <typename I, typename J>
+ oln_plain(I)
+ binary_reconstruction_loop(const Image_with_Nbh<I>& marker,
+ const Binary_Image<J>& mask)
+ {
+ oln_plain(I) output;
+ prepare(output, with, marker);
+
+ accumulator::max_<oln_value(I)> max;
+
+ // first pass
+ oln_fwd_piter(I) p(marker.points());
+ for_all(p)
+ output(p) = level::local_sup(max, marker, p) and mask(p);
+
+ // second pass
+ oln_bkd_piter(I) p2(marker.points());
+ for_all(p2)
+ output(p2) = level::local_inf(max, marker, p2) and mask(p2);
+
+ return output;
+ }
+
+ template <typename I , typename J>
+ void // FIXME : Slow impl.
+ binary_reconstruction_(const Image_with_Nbh<I>& marker,
+ const Binary_Image<J>& mask)
+ {
+ oln_plain(I) tmp = level::clone(marker);
+
+ while ( not stability(marker, tmp) )
+ {
+ level::fill(inplace(exact(marker).image()), tmp);
+ tmp = binary_reconstruction_loop(marker, mask);
+ }
+
+ level::fill(inplace(exact(marker).image()), tmp);
+ }
+
+ } // end of namespace oln::morpho::impl
+
+ template <typename I , typename J>
+ void
+ binary_reconstruction(Binary_Image<I>& marker,
+ const Binary_Image<J>& mask)
+ {
+ impl::binary_reconstruction_(marker + c4, mask);
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_BINARY_RECONSTRUCTION_HH
Index: oln/morpho/fast_binary_reconstruction.hh
Index: oln/morpho/cc_tarjan_v1.hh
--- oln/morpho/cc_tarjan_v1.hh (revision 972)
+++ oln/morpho/cc_tarjan_v1.hh (working copy)
@@ -54,7 +54,8 @@
namespace impl
{
- template <typename I>
+ template <typename I> // FIXME : template< op_<I, extended_by, N>,
+ // typename I, Typename N> ?
struct cc_tarjan_
{
typedef oln_point(I) point;
@@ -128,7 +129,7 @@
{
point r = find_root(n);
if (r != p)
- parent(r) = p;
+ parent(r) = p5A5A;
}
};
Index: oln/morpho/binary_reconstruction_v1.hh
--- oln/morpho/binary_reconstruction_v1.hh (revision 0)
+++ oln/morpho/binary_reconstruction_v1.hh (revision 0)
@@ -0,0 +1,122 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_MORPHO_BINARY_RECONSTRUCTION_HH
+# define OLN_MORPHO_BINARY_RECONSTRUCTION_HH
+
+# include <oln/core/concept/image.hh>
+# include <oln/accumulator/max.hh>
+# include <oln/level/clone.hh>
+# include <oln/level/fill.hh>
+# include <oln/level/local_inf.hh>
+# include <oln/level/local_sup.hh>
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ template <typename I , typename J>
+ void
+ binary_reconstruction(const Binary_Image<I>& marker,
+ const Binary_Image<J>& mask);
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ template <typename I>
+ bool
+ stability(const Image_with_Nbh<I>& marker,
+ oln_plain(I)& tmp)
+ {
+ oln_piter(I) p(marker.points());
+ for_all(p)
+ if (marker(p) != tmp(p))
+ return false;
+ return true;
+ }
+
+ template <typename I, typename J>
+ oln_plain(I)
+ binary_reconstruction_loop(const Image_with_Nbh<I>& marker,
+ const Binary_Image<J>& mask)
+ {
+ oln_plain(I) output;
+ prepare(output, with, marker);
+
+ accumulator::max_<oln_value(I)> max;
+
+ // first pass
+ oln_fwd_piter(I) p(marker.points());
+ for_all(p)
+ output(p) = level::local_sup(max, marker, p) and mask(p);
+
+ // second pass
+ oln_bkd_piter(I) p2(marker.points());
+ for_all(p2)
+ output(p2) = level::local_inf(max, marker, p2) and mask(p2);
+
+ return output;
+ }
+
+ template <typename I , typename J>
+ void // FIXME : Slow impl.
+ binary_reconstruction_(const Image_with_Nbh<I>& marker,
+ const Binary_Image<J>& mask)
+ {
+ oln_plain(I) tmp = level::clone(marker);
+
+ while ( not stability(marker, tmp) )
+ {
+ level::fill(inplace(exact(marker).image()), tmp);
+ tmp = binary_reconstruction_loop(marker, mask);
+ }
+
+ level::fill(inplace(exact(marker).image()), tmp);
+ }
+
+ } // end of namespace oln::morpho::impl
+
+ template <typename I , typename J>
+ void
+ binary_reconstruction(Binary_Image<I>& marker,
+ const Binary_Image<J>& mask)
+ {
+ impl::binary_reconstruction_(marker + c4, mask);
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_BINARY_RECONSTRUCTION_HH
Index: oln/level/local_sup.hh
--- oln/level/local_sup.hh (revision 972)
+++ oln/level/local_sup.hh (working copy)
@@ -68,7 +68,7 @@
const oln_point(I)& p)
{
f.init_with(input(p));
- oln_niter(I) n(p, input);
+ oln_niter(I) n(input, p);
for_all(n)
if (n > p)
f(input(n));
@@ -86,7 +86,7 @@
f.init_with(input(p));
if (f.value() == true)
return true;
- oln_niter(I) n(p, input);
+ oln_niter(I) n(input, p);
for_all(n)
if (n > p)
{
@@ -106,7 +106,7 @@
const oln_point(I)& p)
{
f.init_with(input(p));
- oln_niter(I) n(p, input);
+ oln_niter(I) n(input, p);
for_all(n)
if (n > p)
{
Index: oln/level/local_inf.hh
--- oln/level/local_inf.hh (revision 972)
+++ oln/level/local_inf.hh (working copy)
@@ -68,7 +68,7 @@
const oln_point(I)& p)
{
f.init_with(input(p));
- oln_niter(I) n(p, input);
+ oln_niter(I) n(input, p);
for_all(n)
if (n < p)
f(input(n));
@@ -86,7 +86,7 @@
f.init_with(input(p));
if (f.value() == true)
return true;
- oln_niter(I) n(p, input);
+ oln_niter(I) n(input, p);
for_all(n)
if (n < p)
{
@@ -106,7 +106,7 @@
const oln_point(I)& p)
{
f.init_with(input(p));
- oln_niter(I) n(p, input);
+ oln_niter(I) n(input, p);
for_all(n)
if (n < p)
{
Index: oln/canvas/union_find.hh
--- oln/canvas/union_find.hh (revision 0)
+++ oln/canvas/union_find.hh (revision 0)
@@ -0,0 +1,76 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have receiv a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#include <oln/core/concept/image.hh>
+
+#ifndef OLN_CANVAS_UNION_FIND_HH
+# define OLN_CANVAS_UNION_FIND_HH
+
+namespace canvas
+{
+
+ template <template <class> class F,
+ typename I>
+ void union_find(F<I> fun)
+ {
+ fun.init();
+
+ // first pass
+ oln_bkd_piter(I) p1(fun.f.points());
+ for_all(p1)
+ {
+ fun.parent(p1) = p1;
+ if (fun.f(p) == true)
+ {
+ oln_niter(I) n(f, p);
+ for_all(n)
+ {
+ if (is_processed(n))
+ if (f.condition_bck(p1, n))
+ fun.first_pass_body(p1);
+ }
+ }
+ }
+
+ // second pass
+ oln_fwd_piter(I) p2(fun.f.points());
+ for_all(p2)
+ {
+ if (fun.f(p2) == true)
+ if (fun.condition_fwd(p2))
+ {
+ fun.second_pass_body(p2);
+ }
+ }
+
+ fun.final();
+ }
+
+}
+
+
+#endif // ! OLN_CANVAS_UNION_FIND_HH
Index: oln/canvas/two_pass.hh
--- oln/canvas/two_pass.hh (revision 972)
+++ oln/canvas/two_pass.hh (working copy)
@@ -5,8 +5,8 @@
// of the GNU General Public License version 2 as published by the
// Free Software Foundation.
//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// This library is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
@@ -60,7 +60,7 @@
namespace v2 // Data owned by f but not input.
{
template <typename F, typename I>
- void two_pass(F fun, I f)
+ void two_pass(F& fun, I f)
{
// mlc::assert_< mlc_is_a(I, Image) >::check();
@@ -83,7 +83,7 @@
namespace v3 // Auxiliar data given as argument.
{
template <typename F, typename I, typename A>
- void two_pass(F fun, I f, A aux)
+ void two_pass(F fun, I f, A& aux)
{
// mlc::assert_< mlc_is_a(I, Image) >::check();
@@ -107,38 +107,44 @@
namespace v4 // Via Inheritance.
{
- template <typename I>
+ template <typename Exact>
struct two_pass
{
+ void init()
+ {
+ this->exact().impl_init();
+ }
- const I& f;
-
-
-
- void init();
-
- void final();
+ void final()
+ {
+ this->exact().impl_final();
+ }
- void first_pass_body(const oln_point(I)& p);
+ void first_pass_body(const oln_point(I)& p)
+ {
+ this->exact().impl_first_pass_body(p);
+ }
- void second_pass_body(const oln_point(I)& p);
+ void second_pass_body(const oln_point(I)& p)
+ {
+ this->exact().impl_second_pass_body(p);
+ }
void run()
{
init(f);
// first pass
- oln_bkd_piter(I) p1(f.points());
+ oln_bkd_piter(typename Exact::I) p1(f.points());
for_all(p1)
first_pass_body(p1);
// second pass
- oln_fwd_piter(I) p2(f.points());
+ oln_fwd_piter(typename Exact::I) p2(f.points());
for_all(p2)
second_pass_body(p2);
final(f);
-
}
};
Index: ChangeLog
from Nicolas Ballas <ballas(a)lrde.epita.fr>
fast iterator on image3b_b.
* tests/core/fiter_point2d_b.cc: update test.
* tests/core/fiter_point3d_b.cc: New test.
* tests/core/Makefile.am: Update.
* oln/core/2d/fast_iterator_2d.hh,
* oln/core/2d/fast_iterator_2d_b.hh,
* oln/core/3d/fast_iterator_3d.hh: clean code.
* oln/core/3d/image3d_b.hh: add method to get the image array.
* oln/core/3d/fast_iterator_3d_b.hh: New fast iterator.
oln/core/2d/fast_iterator_2d.hh | 3
oln/core/2d/fast_iterator_2d_b.hh | 18 ++---
oln/core/3d/fast_iterator_3d.hh | 5 -
oln/core/3d/fast_iterator_3d_b.hh | 134 ++++++++++++++++++++++++++++++++++++++
oln/core/3d/image3d_b.hh | 23 ++++++
tests/core/Makefile.am | 2
tests/core/fiter_point2d_b.cc | 2
tests/core/fiter_point3d_b.cc | 61 +++++++++++++++++
8 files changed, 230 insertions(+), 18 deletions(-)
Index: tests/core/fiter_point2d_b.cc
--- tests/core/fiter_point2d_b.cc (revision 971)
+++ tests/core/fiter_point2d_b.cc (working copy)
@@ -34,7 +34,7 @@
{
using namespace oln;
- image2d_b<int> ima(2, 5, 2);
+ image2d_b<int> ima(50, 50, 2);
image2d_b<int>::piter p(ima.points());
image2d_b<int>::fiter f(ima);
Index: tests/core/fiter_point3d_b.cc
--- tests/core/fiter_point3d_b.cc (revision 0)
+++ tests/core/fiter_point3d_b.cc (revision 0)
@@ -0,0 +1,61 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#include <cassert>
+#include <oln/core/3d/image3d_b.hh>
+
+
+int
+main()
+{
+ using namespace oln;
+
+ image3d_b<int> ima(100, 100, 100, 2);
+
+ image3d_b<int>::piter p(ima.points());
+ image3d_b<int>::fiter f(ima);
+ int i = 0;
+
+ for_all(p)
+ ima(p) = i++;
+
+ i = 0;
+
+ for_all(f)
+ {
+ assert(*f == i++);
+ *f = 5;
+ }
+
+ for_all(p)
+ assert(ima(p) == 5);
+
+ f.start();
+ assert(f.is_valid());
+ f.invalidate();
+ assert(!f.is_valid());
+}
Index: tests/core/Makefile.am
--- tests/core/Makefile.am (revision 971)
+++ tests/core/Makefile.am (working copy)
@@ -32,6 +32,7 @@
fiter_point3d \
fiter_point1d_b \
fiter_point2d_b \
+ fiter_point3d_b \
neighb2d \
npoints \
point2d \
@@ -56,6 +57,7 @@
fiter_point3d_SOURCES = fiter_point3d.cc
fiter_point1d_b_SOURCES = fiter_point1d_b.cc
fiter_point2d_b_SOURCES = fiter_point2d_b.cc
+fiter_point3d_b_SOURCES = fiter_point3d_b.cc
neighb2d_SOURCES = neighb2d.cc
npoints_SOURCES = npoints.cc
point2d_SOURCES = point2d.cc
Index: oln/core/2d/fast_iterator_2d.hh
--- oln/core/2d/fast_iterator_2d.hh (revision 971)
+++ oln/core/2d/fast_iterator_2d.hh (working copy)
@@ -72,8 +72,7 @@
template <typename T>
fast_iterator_2d<T>::fast_iterator_2d(image2d<T>& ima)
{
- this->start_ = ima.img_array().buffer() +
- ima.img_array().imin() * ima.img_array().jmin() + ima.img_array().jmin();
+ this->start_ = ima.img_array().buffer();
this->current_elt_ = this->start_;
this->eoi_ = ima.img_array().buffer() + (ima.img_array().imax() + 1) *
(ima.img_array().jmax() + 1);
Index: oln/core/2d/fast_iterator_2d_b.hh
--- oln/core/2d/fast_iterator_2d_b.hh (revision 971)
+++ oln/core/2d/fast_iterator_2d_b.hh (working copy)
@@ -18,7 +18,7 @@
//
// As a special exception, you may use this file as part of a free
// software library without restriction. Specifically, if other files
-// instantiate templates or use macros or inline functions from this
+// instantiate templates or use macros or inraw functions from this
// file, or you compile this file and link it with other files to
// produce an executable, this file does not by itself cause the
// resulting executable to be covered by the GNU General Public
@@ -53,7 +53,7 @@
typedef T value;
};
- // Fast iterator for image in one dimension
+ // Fast iterator for image in two dimension
template <typename T>
class fast_iterator_2d_b :
public internal::fast_iterator_base_< fast_iterator_2d_b<T> >
@@ -68,7 +68,7 @@
protected:
unsigned border_size_;
- int line_offset_;
+ int row_offset_;
value *eor_; // end of row
};
@@ -76,22 +76,20 @@
template <typename T>
fast_iterator_2d_b<T>::fast_iterator_2d_b(image2d_b<T>& ima) :
- border_size_(ima.border()), line_offset_(ima.img_array().i_pad())
+ border_size_(ima.border()), row_offset_(ima.img_array().i_pad())
{
this->start_ = ima.img_array().buffer() +
- (this->border_size_) * this->line_offset_ + this->border_size_;
+ (this->border_size_) * this->row_offset_ + this->border_size_;
this->current_elt_ = this->start_;
this->eor_ = ima.img_array().buffer() +
- (this->border_size_) * this->line_offset_ + this->line_offset_ -
+ (this->border_size_) * this->row_offset_ + this->row_offset_ -
this->border_size_;
this->eoi_ = this->eor_ +
- this->line_offset_ * (ima.img_array().imax() - this->border_size_);
-
-
+ this->row_offset_ * (ima.img_array().imax() - this->border_size_);
}
template <typename T>
@@ -103,7 +101,7 @@
if (this->current_elt_ == this->eor_ and this->current_elt_ != this->eoi_)
{
this->current_elt_ += 2 * this->border_size_;
- this->eor_ += this->line_offset_;
+ this->eor_ += this->row_offset_;
}
}
Index: oln/core/3d/image3d_b.hh
--- oln/core/3d/image3d_b.hh (revision 971)
+++ oln/core/3d/image3d_b.hh (working copy)
@@ -33,7 +33,7 @@
# include <oln/core/internal/image_base.hh>
# include <oln/core/internal/utils.hh>
# include <oln/core/3d/array3d.hh>
-
+# include <oln/core/3d/fast_iterator_3d_b.hh>
namespace oln
{
@@ -65,6 +65,8 @@
typedef image3d_b<T> plain;
typedef image3d_b<pl::value> skeleton;
+
+ typedef fast_iterator_3d_b<value> fiter;
};
@@ -86,6 +88,8 @@
typedef internal::plain_primitive_image_<current> super;
typedef array3d_<T, int> array_t;
public:
+ //FIXME (fast image concept??)
+ typedef typename vtypes< image3d_b<T> >::fiter fiter;
stc_using(data);
image3d_b();
@@ -94,6 +98,9 @@
image3d_b(unsigned nslis, unsigned nrows, unsigned ncols,
unsigned border = 2);
+ array_t& img_array();
+ const array_t& img_array() const;
+
bool impl_owns_(const point3d& p) const;
bool impl_has_at(int sli, int row, int col) const;
@@ -164,6 +171,20 @@
}
template <typename T>
+ typename image3d_b<T>::array_t&
+ image3d_b<T>::img_array()
+ {
+ return this->data_->first;
+ }
+
+ template <typename T>
+ const typename image3d_b<T>::array_t&
+ image3d_b<T>::img_array() const
+ {
+ return this->data_->first;
+ }
+
+ template <typename T>
bool image3d_b<T>::impl_owns_(const point3d& p) const
{
assert(this->has_data());
Index: oln/core/3d/fast_iterator_3d.hh
--- oln/core/3d/fast_iterator_3d.hh (revision 971)
+++ oln/core/3d/fast_iterator_3d.hh (working copy)
@@ -71,10 +71,7 @@
template <typename T>
fast_iterator_3d<T>::fast_iterator_3d(image3d<T>& ima)
{
- this->start_ = ima.img_array().buffer() +
- ima.img_array().imin() * ima.img_array().jmin() * ima.img_array().kmin() +
- ima.img_array().jmin() * ima.img_array().kmin() +
- ima.img_array().kmin();
+ this->start_ = ima.img_array().buffer();
this->current_elt_ = this->start_;
Index: oln/core/3d/fast_iterator_3d_b.hh
--- oln/core/3d/fast_iterator_3d_b.hh (revision 0)
+++ oln/core/3d/fast_iterator_3d_b.hh (revision 0)
@@ -0,0 +1,134 @@
+// Copyright (C) 2007 EPITA
+// Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 3 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 03111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_CORE_3D_FAST_ITERATOR_3D_B_HH
+# define OLN_CORE_3D_FAST_ITERATOR_3D_B_HH
+
+# include <cstddef>
+# include <oln/core/internal/fast_iterator_base.hh>
+# include <oln/core/3d/point3d.hh>
+
+namespace oln
+{
+ // Fwd decl.
+ template <typename T> class image3d_b;
+ template <typename T> class fast_iterator_3d_b;
+
+ // Super type.
+ template <typename T>
+ struct super_trait_< fast_iterator_3d_b<T> >
+ {
+ typedef fast_iterator_3d_b<T> current;
+ typedef internal::fast_iterator_base_<current> ret;
+ };
+
+ // Virtual types.
+ template <typename T>
+ struct vtypes< fast_iterator_3d_b<T> >
+ {
+ typedef T value;
+ };
+
+ // Fast iterator for image in one dimension
+ template <typename T>
+ class fast_iterator_3d_b :
+ public internal::fast_iterator_base_< fast_iterator_3d_b<T> >
+ {
+ typedef fast_iterator_3d_b<T> current;
+ typedef internal::fast_iterator_base_<current> super;
+ public:
+ stc_using(value);
+
+ fast_iterator_3d_b(image3d_b<T>& ima);
+ void impl_next();
+
+ protected:
+ unsigned border_size_;
+ int sli_offset_;
+ int row_offset_;
+
+ value *eor_; // end of row
+ value *eos_; // end of slice
+
+ };
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename T>
+ fast_iterator_3d_b<T>::fast_iterator_3d_b(image3d_b<T>& ima) :
+ border_size_(ima.border()),
+ sli_offset_(ima.img_array().i_pad()),
+ row_offset_(ima.img_array().j_pad())
+ {
+ this->start_ = &ima(point3d(0, 0, 0));
+
+ this->current_elt_ = this->start_;
+
+ this->eor_ = this->start_ + ima.ncols();
+
+ this->eos_ = ima.img_array().buffer() +
+ this->sli_offset_ * this->border_size_ +
+ this->row_offset_ * (ima.img_array().jlen() - 1 - this->border_size_) +
+ + ima.img_array().klen() - this->border_size_ ;
+
+ this->eoi_ = ima.img_array().buffer() +
+ this->sli_offset_ * (ima.img_array().ilen() - 1 - this->border_size_) +
+ this->row_offset_ * (ima.img_array().jlen() - 1 - this->border_size_) +
+ + ima.img_array().klen() - this->border_size_ ;
+ }
+
+ template <typename T>
+ void
+ fast_iterator_3d_b<T>::impl_next()
+ {
+ ++(this->current_elt_);
+
+ if (this->current_elt_ == this->eor_ and this->current_elt_ != this->eoi_)
+ {
+ if (this->current_elt_ != this->eos_) // end of a sli
+ {
+ this->current_elt_ += 2 * this->border_size_;
+ this->eor_ += this->row_offset_;
+ }
+ else // end of a slice
+ {
+ this->eor_ += (2 * this->border_size_ + 1) * this->row_offset_;
+
+ this->current_elt_ += 2 * this->border_size_ +
+ (2 * this->border_size_) * this->row_offset_;
+
+ this->eos_ += this->sli_offset_;
+ }
+ }
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+#endif // OLN_CORE_3D_FAST_ITERATOR_3D_B_HH
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Augment morphology.
* oln/core/gen/ternary_fun.hh: New.
* oln/logic: New directory.
* oln/logic/and.hh,
* oln/logic/not.hh,
* oln/morpho/hit_or_miss_all.hh,
* oln/morpho/hit_or_miss.hh,
* oln/morpho/hit_or_miss_background_closing.hh,
* oln/morpho/hit_or_miss_background_opening.hh,
* oln/morpho/hit_or_miss_closing.hh,
* oln/morpho/complementation.hh,
* oln/morpho/hit_or_miss_opening.hh,
* oln/level/ternary.hh,
* oln/arith/min.hh,
* oln/arith/negate.hh: New.
* oln/convert/to_window.hh
(to_window_values_, fill_): New in internal.
(to_window): New overload.
* oln/convert/to_weighted_window.hh: Update.
* oln/core/gen/dpoints_piter.hh
(dpoints_fwd_piter_, dpoints_bkd_piter_): New ctor overloads.
* oln/core/gen/window.hh (impl_fill_with): New.
* oln/core/gen/pw_value.hh (pw_value_base_): New.
(pw_value): Make inheritance flexible.
* oln/core/concept/window.hh (is_centered): New.
* oln/core/internal/window.hh (impl_is_centered): New.
* oln/core/internal/dpoints_impl.hh: Fix.
* oln/morpho/cc_tarjan_v1.hh (cc_tarjan): New facade.
* oln/morpho/cc_tarjan_v2.hh: Fix.
* oln/morpho/erosion.hh (postcondition): Fix.
* oln/morpho/dilation.hh (postcondition): Fix.
* oln/level/apply.hh: Cosmetic change.
* oln/canvas/two_pass.hh: Fix.
arith/min.hh | 86 ++++++++++++++++++++
arith/negate.hh | 96 ++++++++++++++++++++++
canvas/two_pass.hh | 4
convert/to_weighted_window.hh | 18 ++--
convert/to_window.hh | 63 +++++++++++++--
core/concept/window.hh | 8 +
core/gen/dpoints_piter.hh | 44 ++++++++++
core/gen/pw_value.hh | 33 +++++++
core/gen/ternary_fun.hh | 121 ++++++++++++++++++++++++++++
core/gen/window.hh | 3
core/internal/dpoints_impl.hh | 2
core/internal/window.hh | 9 ++
level/apply.hh | 6 -
level/ternary.hh | 90 +++++++++++++++++++++
logic/and.hh | 96 ++++++++++++++++++++++
logic/not.hh | 95 ++++++++++++++++++++++
morpho/cc_tarjan_v1.hh | 52 +++++++++---
morpho/cc_tarjan_v2.hh | 7 -
morpho/complementation.hh | 89 +++++++++++++++++++++
morpho/dilation.hh | 1
morpho/erosion.hh | 1
morpho/hit_or_miss.hh | 130 +++++++++++++++++++++++++++++++
morpho/hit_or_miss_all.hh | 41 +++++++++
morpho/hit_or_miss_background_closing.hh | 89 +++++++++++++++++++++
morpho/hit_or_miss_background_opening.hh | 89 +++++++++++++++++++++
morpho/hit_or_miss_closing.hh | 91 +++++++++++++++++++++
morpho/hit_or_miss_opening.hh | 92 +++++++++++++++++++++
27 files changed, 1415 insertions(+), 41 deletions(-)
Index: oln/convert/to_window.hh
--- oln/convert/to_window.hh (revision 970)
+++ oln/convert/to_window.hh (working copy)
@@ -30,6 +30,7 @@
# include <oln/core/concept/image.hh>
# include <oln/core/internal/f_image_to_window.hh>
+# include <oln/convert/to_dpoint.hh>
namespace oln
@@ -38,12 +39,23 @@
namespace convert
{
- // Fwd decl.
+ // Fwd decls.
+
+ namespace internal
+ {
+ template <unsigned n>
+ struct to_window_values_;
+ }
template <typename I>
oln_f_image_to_window(I)
to_window(const Binary_Image<I>& input);
+ template <unsigned n>
+ internal::to_window_values_<n>
+ to_window(const bool (&values)[n]);
+ // FIXME: Wrong semantics: to_window should really give a window...
+
# ifndef OLN_INCLUDE_ONLY
@@ -53,18 +65,59 @@
oln_f_image_to_window(I)
to_window(const Binary_Image<I>& input)
{
- oln_f_image_to_window(I) tmp;
+ oln_f_image_to_window(I) win;
oln_dpoint(I) dp;
oln_piter(I) p(input.points());
for_all(p)
if (input(p) = true)
+ win.take(convert::to_dpoint(p));
+ return win;
+ }
+
+
+ namespace internal
{
- dp.vec() = p.vec();
- // FIXME: Better s.a. dp = p.to_dpoint();
- tmp.take(dp);
+
+ template <typename G, typename W, unsigned n>
+ void fill_(W& win, const bool (&values)[n])
+ {
+ int h = int(std::sqrt(n)) / 2;
+ precondition((2 * h + 1) * (2 * h + 1) = n);
+ unsigned i = 0;
+ for (int drow = -h; drow <= h; ++drow) // FIXME: Replace 'int' by 'oln_coord(W)'
+ for (int dcol = -h; dcol <= h; ++dcol)
+ if (values[i++] = true)
+ win.take(oln_dpoint(W)(drow, dcol));
}
+
+ template <unsigned n>
+ struct to_window_values_
+ {
+ const bool (&values_)[n];
+
+ to_window_values_(const bool (&values)[n])
+ : values_(values)
+ {}
+
+ template <typename W>
+ operator W() const
+ {
+ mlc::assert_< mlc_is_a(W, Window) >::check(); // FIXME: Add err msg.
+ W tmp;
+ fill_<oln_grid(W)>(tmp, values_);
return tmp;
}
+ };
+
+ } // end of namespace oln::convert::internal
+
+
+ template <unsigned n>
+ internal::to_window_values_<n>
+ to_window(const bool (&values)[n])
+ {
+ return internal::to_window_values_<n>(values);
+ }
# endif // ! OLN_INCLUDE_ONLY
Index: oln/convert/to_weighted_window.hh
--- oln/convert/to_weighted_window.hh (revision 970)
+++ oln/convert/to_weighted_window.hh (working copy)
@@ -28,10 +28,11 @@
#ifndef OLN_CONVERT_TO_WEIGHTED_WINDOW_HH
# define OLN_CONVERT_TO_WEIGHTED_WINDOW_HH
-# include <oln/core/gen/zero.hh>
# include <oln/core/concept/image.hh>
# include <oln/core/concept/window.hh>
# include <oln/core/concept/function.hh>
+# include <oln/core/gen/zero.hh>
+# include <oln/convert/to_dpoint.hh>
# include <oln/core/internal/f_weighted_window.hh>
@@ -62,11 +63,11 @@
oln_f_image_to_weighted_window(I)
to_weighted_window(const Image<I>& input)
{
- oln_f_image_to_weighted_window(I) output;
+ oln_f_image_to_weighted_window(I) w_win;
oln_piter(I) p(input.points());
for_all(p)
- output.take(input(p), zero - oln_point(I)(p));
- return output;
+ w_win.take(input(p), convert::to_dpoint(p));
+ return w_win;
}
template <typename F, typename W>
@@ -74,12 +75,11 @@
to_weighted_window(const Function_p2v<F>& weight, const Window<W>& win)
{
const F& weight_ = exact(weight);
- oln_f_weighted_window(oln_result(F), oln_dpoint(W)) output;
- oln_point(W) O; O.set_all(0);
- oln_qiter(W) q(win, O);
+ oln_f_weighted_window(oln_result(F), oln_dpoint(W)) w_win;
+ oln_qiter(W) q(win, zero);
for_all(q)
- output.take(weight_(q), O - oln_point(W)(q)); // FIXME: to_point
- return output;
+ w_win.take(weight_(q), convert::to_dpoint(q));
+ return w_win;
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/core/gen/dpoints_piter.hh
--- oln/core/gen/dpoints_piter.hh (revision 970)
+++ oln/core/gen/dpoints_piter.hh (working copy)
@@ -75,12 +75,18 @@
template <typename W, typename Pl>
dpoints_fwd_piter_(const Window<W>& win, const Generalized_Point<Pl>& p);
+ template <typename W>
+ dpoints_fwd_piter_(const Window<W>& win, const P& p);
+
template <typename I, typename Pl>
dpoints_fwd_piter_(const Image_with_Nbh<I>& ima, const Generalized_Point<Pl>& p);
template <typename N, typename Pl>
dpoints_fwd_piter_(const Neighborhood<N>& nbh, const Generalized_Point<Pl>& p);
+ template <typename N>
+ dpoints_fwd_piter_(const Neighborhood<N>& nbh, const P& p);
+
}; // end of class oln::dpoints_fwd_piter_<P>
@@ -120,12 +126,18 @@
template <typename W, typename Pl>
dpoints_bkd_piter_(const Window<W>& win, const Generalized_Point<Pl>& p);
+ template <typename W>
+ dpoints_bkd_piter_(const Window<W>& win, const P& p);
+
template <typename I, typename Pl>
dpoints_bkd_piter_(const Image_with_Nbh<I>& ima, const Generalized_Point<Pl>& p);
template <typename N, typename Pl>
dpoints_bkd_piter_(const Neighborhood<N>& nbh, const Generalized_Point<Pl>& p);
+ template <typename N>
+ dpoints_bkd_piter_(const Neighborhood<N>& nbh, const P& p);
+
}; // end of class oln::dpoints_bkd_piter_<P>
@@ -143,6 +155,14 @@
}
template <typename P>
+ template <typename W>
+ dpoints_fwd_piter_<P>::dpoints_fwd_piter_(const Window<W>& win, const P& p)
+ :
+ internal::dpoints_fwd_piter_impl_<P>(p, exact(win)) // FIXME: Propagate "win first, then p".
+ {
+ }
+
+ template <typename P>
template <typename I, typename Pl>
dpoints_fwd_piter_<P>::dpoints_fwd_piter_(const Image_with_Nbh<I>& ima, const Generalized_Point<Pl>& p)
:
@@ -158,6 +178,14 @@
{
}
+ template <typename P>
+ template <typename N>
+ dpoints_fwd_piter_<P>::dpoints_fwd_piter_(const Neighborhood<N>& nbh, const P& p)
+ :
+ internal::dpoints_fwd_piter_impl_<P>(p, exact(nbh))
+ {
+ }
+
// bkd
template <typename P>
@@ -169,6 +197,14 @@
}
template <typename P>
+ template <typename W>
+ dpoints_bkd_piter_<P>::dpoints_bkd_piter_(const Window<W>& win, const P& p)
+ :
+ internal::dpoints_bkd_piter_impl_<P>(p, exact(win))
+ {
+ }
+
+ template <typename P>
template <typename I, typename Pl>
dpoints_bkd_piter_<P>::dpoints_bkd_piter_(const Image_with_Nbh<I>& ima, const Generalized_Point<Pl>& p)
:
@@ -184,6 +220,14 @@
{
}
+ template <typename P>
+ template <typename N>
+ dpoints_bkd_piter_<P>::dpoints_bkd_piter_(const Neighborhood<N>& nbh, const P& p)
+ :
+ internal::dpoints_bkd_piter_impl_<P>(p, exact(nbh))
+ {
+ }
+
# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/gen/window.hh
--- oln/core/gen/window.hh (revision 970)
+++ oln/core/gen/window.hh (working copy)
@@ -65,6 +65,9 @@
gen_window();
+ template <unsigned n>
+ void impl_fill_with(const bool (&values)[n]);
+
}; // end of class oln::gen_window<Dp>
Index: oln/core/gen/pw_value.hh
--- oln/core/gen/pw_value.hh (revision 970)
+++ oln/core/gen/pw_value.hh (working copy)
@@ -45,10 +45,34 @@
} // end of namespace oln::ERROR
+ // Fwd decl.
+ template <typename I> class pw_value_;
+
+
+ namespace internal
+ {
+
+ template <bool b, typename I>
+ struct pw_value_base_;
+
+ template <typename I>
+ struct pw_value_base_< true, I > : public Function_p2b< pw_value_<I> >
+ {
+ };
+
template <typename I>
- class pw_value_ : public Function_p2v< pw_value_<I> >,
- private mlc::assert_< mlc_is_a(I, Image),
- ERROR::pw_value_works_on_images_not_on_<I> >
+ struct pw_value_base_< false, I > : public Function_p2v< pw_value_<I> >
+ {
+ };
+
+ } // end of namespace oln::internal
+
+
+ template <typename I>
+ class pw_value_
+ :
+ public internal::pw_value_base_< mlc_is_a(I, Binary_Image)::eval::value,
+ I >
{
public:
typedef oln_point(I) argument; // FIXME: psite?
@@ -64,6 +88,7 @@
};
+
template <typename I>
pw_value_<I> pw_value(const Image<I>& ima);
@@ -94,6 +119,8 @@
return this->ima_;
}
+ // pw_value
+
template <typename I>
pw_value_<I>
pw_value(const Image<I>& ima)
Index: oln/core/gen/ternary_fun.hh
--- oln/core/gen/ternary_fun.hh (revision 0)
+++ oln/core/gen/ternary_fun.hh (revision 0)
@@ -0,0 +1,121 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_CORE_GEN_TERNARY_FUN_HH
+# define OLN_CORE_GEN_TERNARY_FUN_HH
+
+# include <oln/core/concept/function.hh>
+
+
+
+namespace oln
+{
+
+
+ namespace internal
+ {
+
+ template <bool b, typename B, typename T, typename F>
+ struct ternary_base_;
+
+ template <typename B, typename T, typename F>
+ struct ternary_base_< true, B,T,F > : public Function_p2b< ternary_fun_<B,T,F> >
+ {
+ };
+
+ template <typename B, typename T, typename F>
+ struct ternary_base_< false, B,T,F > : public Function_p2v< ternary_fun_<B,T,F> >
+ {
+ };
+
+ } // end of namespace oln::internal
+
+
+
+ template <typename B, typename T, typename F>
+ class ternary_fun_
+ :
+ public internal::ternary_base_< mlc_is_a(oln_result(T), bool), B,T,F >
+ {
+ public:
+ typedef oln_argument(B) argument;
+ typedef oln_result(T) result; // FIXME: oln_promote_trait( oln_result(T), oln_result(F) )?
+
+ ternary_fun_(const B& b, const T& t, const F& f);
+
+ result operator()(argument arg) const;
+
+ protected:
+ B b_;
+ T t_;
+ F f_;
+ };
+
+
+ template <typename B, typename T, typename F>
+ ternary_fun_<B,T,F> ternary_fun(const Function_p2b<B>& b,
+ const Function_p2v<T>& t, const Function_p2v<F>& f);
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ // ternary_fun_<B,T,F>
+
+ template <typename B, typename T, typename F>
+ ternary_fun_<B,T,F>::ternary_fun_(const B& b, const T& t, const F& f)
+ : b_(b),
+ t_(t),
+ f_(f)
+ {
+ }
+
+ template <typename B, typename T, typename F>
+ typename ternary_fun_<B,T,F>::result
+ ternary_fun_<B,T,F>::operator()(argument arg) const
+ {
+ return this->b_(arg) ? this->t_(arg) : this->f_(arg);
+ }
+
+ // ternary_fun
+
+ template <typename B, typename T, typename F>
+ ternary_fun_<B,T,F>
+ ternary_fun(const Function_p2b<B>& b,
+ const Function_p2v<T>& t, const Function_p2v<F>& f)
+ {
+ // FIXME: Add static asserts here!
+ ternary_fun_<B,T,F> tmp(exact(b), exact(t), exact(f));
+ return tmp;
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_GEN_TERNARY_FUN_HH
Index: oln/core/concept/window.hh
--- oln/core/concept/window.hh (revision 970)
+++ oln/core/concept/window.hh (working copy)
@@ -48,6 +48,7 @@
stc_typename(bkd_qiter);
unsigned size() const;
+ bool is_centered() const;
protected:
Window();
@@ -73,6 +74,13 @@
return exact(this)->impl_size();
}
+ template <typename Exact>
+ bool
+ Window<Exact>::is_centered() const
+ {
+ return exact(this)->impl_is_centered();
+ }
+
template <typename W>
W operator - (const Window<W>& rhs)
{
Index: oln/core/internal/window.hh
--- oln/core/internal/window.hh (revision 970)
+++ oln/core/internal/window.hh (working copy)
@@ -31,6 +31,7 @@
# include <oln/core/internal/window_base.hh>
# include <oln/core/internal/dpoints_impl.hh>
# include <oln/core/gen/dpoints_piter.hh>
+# include <oln/core/gen/zero.hh>
namespace oln
@@ -76,6 +77,7 @@
Exact& take(const dpoint& dp);
Exact& impl_take(const dpoint& dp);
+ bool impl_is_centered() const;
Exact impl_op_unary_minus_() const;
@@ -108,6 +110,13 @@
}
template <typename Exact>
+ bool
+ window_<Exact>::impl_is_centered() const
+ {
+ return this->has(zero);
+ }
+
+ template <typename Exact>
Exact
window_<Exact>::impl_op_unary_minus_() const
{
Index: oln/core/internal/dpoints_impl.hh
--- oln/core/internal/dpoints_impl.hh (revision 970)
+++ oln/core/internal/dpoints_impl.hh (working copy)
@@ -74,7 +74,7 @@
const dpoints_impl_<Dp>& dps)
{
ostr << "[ ";
- unsigned n = dps.size();
+ unsigned n = dps.impl_size();
for (unsigned i = 0; i < n; ++i)
ostr << dps[i] << (i = n - 1 ? " ]" : ", ");
return ostr;
Index: oln/logic/and.hh
--- oln/logic/and.hh (revision 0)
+++ oln/logic/and.hh (revision 0)
@@ -0,0 +1,96 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_LOGIC_AND_HH
+# define OLN_LOGIC_AND_HH
+
+# include <oln/core/concept/image.hh>
+# include <oln/core/gen/traits.hh>
+# include <oln/core/gen/pw_value.hh>
+# include <oln/level/fill.hh>
+
+
+
+namespace oln
+{
+
+ // Trait.
+
+ template <typename I>
+ struct set_trait_< Image, I, and_id, Image, I >
+ {
+ typedef oln_plain(I) ret;
+ };
+
+
+ // Fwd decl.
+
+ template <typename I>
+ oln_plain(I)
+ operator and (const Binary_Image<I>& lhs, const Binary_Image<I>& rhs);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace logic
+ {
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename I>
+ oln_plain(I)
+ and_(const Binary_Image<I>& lhs, const Binary_Image<I>& rhs)
+ {
+ oln_plain(I) output;
+ prepare(output, with, lhs);
+ level::fill(inplace(output), pw_value(lhs) and pw_value(rhs));
+ return output;
+ }
+
+
+ } // end of namespace oln::logic::impl
+
+ } // end of namespace oln::logic
+
+
+ // Facade.
+
+ template <typename I>
+ oln_plain(I)
+ operator and (const Binary_Image<I>& lhs, const Binary_Image<I>& rhs)
+ {
+ precondition(lhs.points() = rhs.points());
+ return logic::impl::and_(lhs, rhs);
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+#endif // ! OLN_LOGIC_AND_HH
Index: oln/logic/not.hh
--- oln/logic/not.hh (revision 0)
+++ oln/logic/not.hh (revision 0)
@@ -0,0 +1,95 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_LOGIC_NOT_HH
+# define OLN_LOGIC_NOT_HH
+
+# include <oln/core/concept/image.hh>
+# include <oln/core/gen/traits.hh>
+# include <oln/core/gen/pw_value.hh>
+# include <oln/level/fill.hh>
+
+
+
+namespace oln
+{
+
+ // Trait.
+
+ template <typename I>
+ struct set_utrait_< not_id, Image, I >
+ {
+ typedef oln_plain(I) ret;
+ };
+
+
+ // Fwd decl.
+
+ template <typename I>
+ oln_plain(I)
+ operator not (const Binary_Image<I>& rhs);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace logic
+ {
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename I>
+ oln_plain(I)
+ not_(const Binary_Image<I>& rhs)
+ {
+ oln_plain(I) output;
+ prepare(output, with, rhs);
+ level::fill(inplace(output), not pw_value(rhs));
+ return output;
+ }
+
+
+ } // end of namespace oln::logic::impl
+
+ } // end of namespace oln::logic
+
+
+ // Facade.
+
+ template <typename I>
+ oln_plain(I)
+ operator not (const Binary_Image<I>& rhs)
+ {
+ return logic::impl::not_(rhs);
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+#endif // ! OLN_LOGIC_NOT_HH
Index: oln/morpho/cc_tarjan_v2.hh
--- oln/morpho/cc_tarjan_v2.hh (revision 970)
+++ oln/morpho/cc_tarjan_v2.hh (working copy)
@@ -68,7 +68,7 @@
level::fill(inplace(is_processed), false);
}
- void first_pass_body(const point& p, I f)
+ void first_pass_body(const point& p, const I& f)
{
parent(p) = p;
if ( f(p) )
@@ -84,7 +84,7 @@
}
- void second_pass_body(const point& p, I f)
+ void second_pass_body(const point& p, const I& f)
{
unsigned current_label = 0;
if ( f(p) = true and parent(p) = p )
@@ -93,9 +93,8 @@
output(p) = output(parent(p));
}
- void final(I f)
+ void final(const I&)
{
- f = f;
}
point find_root(const I& ima,
Index: oln/morpho/hit_or_miss_all.hh
--- oln/morpho/hit_or_miss_all.hh (revision 0)
+++ oln/morpho/hit_or_miss_all.hh (revision 0)
@@ -0,0 +1,41 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_MORPHO_HIT_OR_MISS_ALL_HH
+# define OLN_MORPHO_HIT_OR_MISS_ALL_HH
+
+
+# include <oln/morpho/hit_or_miss.hh>
+
+# include <oln/morpho/hit_or_miss_opening.hh>
+# include <oln/morpho/hit_or_miss_closing.hh>
+
+# include <oln/morpho/hit_or_miss_background_opening.hh>
+# include <oln/morpho/hit_or_miss_background_closing.hh>
+
+
+#endif // ! OLN_MORPHO_HIT_OR_MISS_ALL_HH
Index: oln/morpho/erosion.hh
--- oln/morpho/erosion.hh (revision 970)
+++ oln/morpho/erosion.hh (working copy)
@@ -119,6 +119,7 @@
erosion(const Image<I>& input, const Window<W>& win)
{
oln_plain(I) output = impl::erosion_(exact(input), exact(win));
+ if (win.is_centered())
postcondition(output <= input);
return output;
}
Index: oln/morpho/hit_or_miss.hh
--- oln/morpho/hit_or_miss.hh (revision 0)
+++ oln/morpho/hit_or_miss.hh (revision 0)
@@ -0,0 +1,130 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_MORPHO_HIT_OR_MISS_HH
+# define OLN_MORPHO_HIT_OR_MISS_HH
+
+# include <oln/morpho/erosion.hh>
+
+# include <oln/arith/min.hh>
+# include <oln/arith/negate.hh>
+
+# include <oln/logic/not.hh>
+# include <oln/logic/and.hh>
+
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ // Fwd decl.
+
+ template <typename I, typename W1, typename W2>
+ oln_plain(I)
+ hit_or_miss(const Image<I>& input,
+ const Window<W1>& B1, const Window<W2>& B2);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic versions.
+
+ template <typename I, typename W1, typename W2>
+ oln_plain(I)
+ hit_or_miss_on_function_(const Image<I>& input,
+ const Window<W1>& B1, const Window<W2>& B2)
+ {
+ oln_plain(I)
+ fit = erosion(input, B1),
+ miss = erosion(arith::negate(input), B2);
+ return arith::min(fit, miss);
+ }
+
+ template <typename I, typename W1, typename W2>
+ oln_plain(I)
+ hit_or_miss_on_set_(const Binary_Image<I>& input,
+ const Window<W1>& B1, const Window<W2>& B2)
+ {
+ oln_plain(I)
+ fit = erosion(input, B1),
+ miss = erosion(not input, B2);
+ return fit and miss;
+ }
+
+ // FIXME: Add a fast version.
+
+
+ // Impl facade.
+
+ template <typename I, typename W1, typename W2>
+ oln_plain(I)
+ hit_or_miss_(const Image<I>& input,
+ const W1& B1, const W2& B2)
+ {
+ return hit_or_miss_on_function_(exact(input), B1, B2);
+ }
+
+ template <typename I, typename W1, typename W2>
+ oln_plain(I)
+ hit_or_miss_(const Binary_Image<I>& input,
+ const W1& B1, const W2& B2)
+ {
+ return hit_or_miss_on_set_(exact(input), B1, B2);
+ }
+
+
+ } // end of namespace oln::morpho::impl
+
+
+ // Facade.
+
+ template <typename I, typename W1, typename W2>
+ oln_plain(I)
+ hit_or_miss(const Image<I>& input,
+ const Window<W1>& B1, const Window<W2>& B2)
+ {
+ // FIXME: Add: precondition(inter(B1, B2).card() = 0);
+ oln_plain(I) output = impl::hit_or_miss_(exact(input),
+ exact(B1), exact(B2));
+ if (B1.is_centered()) // FIXME: ok?
+ postcondition(output <= input);
+ return output;
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_HIT_OR_MISS_HH
Index: oln/morpho/cc_tarjan_v1.hh
--- oln/morpho/cc_tarjan_v1.hh (revision 970)
+++ oln/morpho/cc_tarjan_v1.hh (working copy)
@@ -34,6 +34,7 @@
# include <oln/level/fill.hh>
# include <oln/core/internal/f_ch_value.hh>
+
namespace oln
{
@@ -44,6 +45,11 @@
oln_plain_value(I, unsigned)
cc_tarjan(const Image_with_Nbh<I>& f);
+ template <typename I>
+ oln_plain_value(I, unsigned)
+ cc_tarjan(const Image_with_Nbh<I>& f, unsigned& nlabels);
+
+
# ifndef OLN_INCLUDE_ONLY
namespace impl
@@ -58,6 +64,7 @@
oln_plain_value(I, unsigned) output;
oln_plain_value(I, bool) is_processed;
oln_plain_value(I, point) parent;
+ unsigned nlabels;
cc_tarjan_(const I& f)
: f(f)
@@ -70,12 +77,13 @@
prepare(output, with, f);
prepare(parent, with, f);
level::fill(inplace(is_processed), false);
+ nlabels = 0;
}
void first_pass_body(const point& p)
{
parent(p) = p;
- if ( f(p) )
+ if (f(p) = true)
{
oln_niter(I) n(f, p);
for_all(n)
@@ -85,31 +93,34 @@
}
is_processed(p) = true;
}
-
}
void second_pass_body(const point& p)
{
- unsigned current_label = 0;
- if ( f(p) = true and parent(p) = p )
- output(p) = ++current_label;
+ if (f(p) = true)
+ {
+ if (parent(p) = p)
+ output(p) = ++nlabels;
else
output(p) = output(parent(p));
}
+ else
+ output(p) = 0; // bg label
+ }
- void final() { }
+ void final()
+ {
+ }
// auxiliary methods
- point find_root(const point& x)
+ point find_root(const point& x) // FIXME: or w/o const&?
{
- if (parent(x) != x)
- {
- parent(x) = find_root(parent(x));
- return parent(x);
- }
+ if (parent(x) = x)
return x;
+ else
+ return parent(x) = find_root(parent(x));
}
void do_union(const point& n,
@@ -124,15 +135,28 @@
} // end of namespace oln::morpho::impl
+
// Facades.
template <typename I>
oln_plain_value(I, unsigned)
- cc_tarjan(const Image_with_Nbh<I>& f)
+ cc_tarjan(const Image_with_Nbh<I>& f, unsigned& nlabels)
{
impl::cc_tarjan_<I> run(exact(f));
+ std::cout << run.output.is_empty() << std::endl;
canvas::v1::two_pass(run);
- return run.output;
+ std::cout << run.output.is_empty() << std::endl;
+ nlabels = run.nlabels;
+ oln_plain_value(I, unsigned) tmp = run.output;
+ return tmp;
+ }
+
+ template <typename I>
+ oln_plain_value(I, unsigned)
+ cc_tarjan(const Image_with_Nbh<I>& f)
+ {
+ unsigned nlabels;
+ return cc_tarjan(f, nlabels);
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/morpho/hit_or_miss_background_closing.hh
--- oln/morpho/hit_or_miss_background_closing.hh (revision 0)
+++ oln/morpho/hit_or_miss_background_closing.hh (revision 0)
@@ -0,0 +1,89 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_MORPHO_HIT_OR_MISS_BACKGROUND_CLOSING_HH
+# define OLN_MORPHO_HIT_OR_MISS_BACKGROUND_CLOSING_HH
+
+# include <oln/morpho/hit_or_miss_closing.hh>
+# include <oln/morpho/complementation.hh>
+
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ // Fwd decl.
+
+ template <typename I, typename W1, typename W2>
+ oln_plain(I)
+ hit_or_miss_background_closing(const Image<I>& input,
+ const Window<W1>& B1, const Window<W2>& B2);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename I, typename W1, typename W2>
+ oln_plain(I)
+ hit_or_miss_background_closing_(const Image<I>& input,
+ const Window<W1>& B1, const Window<W2>& B2)
+ {
+ oln_plain(I)
+ com = morpho::complementation(input),
+ output = morpho::hit_or_miss_closing(com, B2, B1);
+ return output;
+ }
+
+ } // end of namespace oln::morpho::impl
+
+
+ // Facade.
+
+ template <typename I, typename W1, typename W2>
+ oln_plain(I)
+ hit_or_miss_background_closing(const Image<I>& input,
+ const Window<W1>& B1, const Window<W2>& B2)
+ {
+ // FIXME: Add: precondition(inter(B1, B2).card() = 0);
+ return impl::hit_or_miss_background_closing_(exact(input),
+ exact(B1), exact(B2));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_HIT_OR_MISS_BACKGROUND_CLOSING_HH
Index: oln/morpho/hit_or_miss_background_opening.hh
--- oln/morpho/hit_or_miss_background_opening.hh (revision 0)
+++ oln/morpho/hit_or_miss_background_opening.hh (revision 0)
@@ -0,0 +1,89 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_MORPHO_HIT_OR_MISS_BACKGROUND_OPENING_HH
+# define OLN_MORPHO_HIT_OR_MISS_BACKGROUND_OPENING_HH
+
+# include <oln/morpho/hit_or_miss_opening.hh>
+# include <oln/morpho/complementation.hh>
+
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ // Fwd decl.
+
+ template <typename I, typename W1, typename W2>
+ oln_plain(I)
+ hit_or_miss_background_opening(const Image<I>& input,
+ const Window<W1>& B1, const Window<W2>& B2);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename I, typename W1, typename W2>
+ oln_plain(I)
+ hit_or_miss_background_opening_(const Image<I>& input,
+ const Window<W1>& B1, const Window<W2>& B2)
+ {
+ oln_plain(I)
+ com = morpho::complementation(input),
+ output = morpho::hit_or_miss_opening(com, B2, B1);
+ return output;
+ }
+
+ } // end of namespace oln::morpho::impl
+
+
+ // Facade.
+
+ template <typename I, typename W1, typename W2>
+ oln_plain(I)
+ hit_or_miss_background_opening(const Image<I>& input,
+ const Window<W1>& B1, const Window<W2>& B2)
+ {
+ // FIXME: Add: precondition(inter(B1, B2).card() = 0);
+ return impl::hit_or_miss_background_opening_(exact(input),
+ exact(B1), exact(B2));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_HIT_OR_MISS_BACKGROUND_OPENING_HH
Index: oln/morpho/hit_or_miss_closing.hh
--- oln/morpho/hit_or_miss_closing.hh (revision 0)
+++ oln/morpho/hit_or_miss_closing.hh (revision 0)
@@ -0,0 +1,91 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_MORPHO_HIT_OR_MISS_CLOSING_HH
+# define OLN_MORPHO_HIT_OR_MISS_CLOSING_HH
+
+# include <oln/morpho/hit_or_miss_opening.hh>
+# include <oln/morpho/complementation.hh>
+# include <oln/morpho/closing.hh>
+
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ // Fwd decl.
+
+ template <typename I, typename W1, typename W2>
+ oln_plain(I)
+ hit_or_miss_closing(const Image<I>& input,
+ const Window<W1>& B1, const Window<W2>& B2);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename I, typename W1, typename W2>
+ oln_plain(I)
+ hit_or_miss_closing_(const Image<I>& input,
+ const Window<W1>& B1, const Window<W2>& B2)
+ {
+ oln_plain(I)
+ com = morpho::complementation(input),
+ ope = morpho::hit_or_miss_opening(com, B1, B2);
+ return morpho::complementation(ope);
+ }
+
+ } // end of namespace oln::morpho::impl
+
+
+ // Facade.
+
+ template <typename I, typename W1, typename W2>
+ oln_plain(I)
+ hit_or_miss_closing(const Image<I>& input,
+ const Window<W1>& B1, const Window<W2>& B2)
+ {
+ // FIXME: Add: precondition(inter(B1, B2).card() = 0);
+ oln_plain(I) output = impl::hit_or_miss_closing_(exact(input),
+ exact(B1), exact(B2));
+ postcondition(output >= morpho::closing(input, B1));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_HIT_OR_MISS_CLOSING_HH
Index: oln/morpho/complementation.hh
--- oln/morpho/complementation.hh (revision 0)
+++ oln/morpho/complementation.hh (revision 0)
@@ -0,0 +1,89 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_MORPHO_COMPLEMENTATION_HH
+# define OLN_MORPHO_COMPLEMENTATION_HH
+
+# include <oln/arith/negate.hh>
+# include <oln/logic/not.hh>
+
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ // Fwd decl.
+
+ template <typename I>
+ oln_plain(I)
+ complementation(const Image<I>& input);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic versions.
+
+ template <typename I>
+ oln_plain(I)
+ complementation_(const Image<I>& input)
+ {
+ return arith::negate(input);
+ }
+
+ template <typename I>
+ oln_plain(I)
+ complementation_(const Binary_Image<I>& input)
+ {
+ return not input;
+ }
+
+ } // end of namespace oln::morpho::impl
+
+
+ // Facade.
+
+ template <typename I>
+ oln_plain(I)
+ complementation(const Image<I>& input)
+ {
+ oln_plain(I) output = impl::complementation_(exact(input));
+ return output;
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_COMPLEMENTATION_HH
Index: oln/morpho/hit_or_miss_opening.hh
--- oln/morpho/hit_or_miss_opening.hh (revision 0)
+++ oln/morpho/hit_or_miss_opening.hh (revision 0)
@@ -0,0 +1,92 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_MORPHO_HIT_OR_MISS_OPENING_HH
+# define OLN_MORPHO_HIT_OR_MISS_OPENING_HH
+
+# include <oln/morpho/hit_or_miss.hh>
+# include <oln/morpho/opening.hh>
+
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ // Fwd decl.
+
+ template <typename I, typename W1, typename W2>
+ oln_plain(I)
+ hit_or_miss_opening(const Image<I>& input,
+ const Window<W1>& B1, const Window<W2>& B2);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename I, typename W1, typename W2>
+ oln_plain(I)
+ hit_or_miss_opening_(const Image<I>& input,
+ const Window<W1>& B1, const Window<W2>& B2)
+ {
+ oln_plain(I) hom = morpho::hit_or_miss(input, B1, B2);
+ return morpho::dilation(hom, - B1);
+ }
+
+ // FIXME: Add a fast version.
+
+
+ } // end of namespace oln::morpho::impl
+
+
+ // Facade.
+
+ template <typename I, typename W1, typename W2>
+ oln_plain(I)
+ hit_or_miss_opening(const Image<I>& input,
+ const Window<W1>& B1, const Window<W2>& B2)
+ {
+ // FIXME: Add: precondition(inter(B1, B2).card() = 0);
+ oln_plain(I) output = impl::hit_or_miss_opening_(exact(input),
+ exact(B1), exact(B2));
+ postcondition(output <= morpho::opening(input, B1));
+ return output;
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_HIT_OR_MISS_OPENING_HH
Index: oln/morpho/dilation.hh
--- oln/morpho/dilation.hh (revision 970)
+++ oln/morpho/dilation.hh (working copy)
@@ -100,6 +100,7 @@
dilation(const Image<I>& input, const Window<W>& win)
{
oln_plain(I) output = impl::dilation_(exact(input), exact(win));
+ if (win.is_centered())
postcondition(output >= input);
return output;
}
Index: oln/level/ternary.hh
--- oln/level/ternary.hh (revision 0)
+++ oln/level/ternary.hh (revision 0)
@@ -0,0 +1,90 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_LEVEL_TERNARY_HH
+# define OLN_LEVEL_TERNARY_HH
+
+# include <oln/core/concept/image.hh>
+# include <oln/core/gen/ternary_fun.hh>
+# include <oln/core/gen/pw_value.hh>
+# include <oln/core/level/fill.hh>
+
+
+namespace oln
+{
+
+ namespace level
+ {
+
+ // Fwd decl.
+
+ template <typename B, typename T, typename F>
+ oln_plain(T) // FIXME: oln_promote_trait(oln_value(T), oln_value(B))
+ ternary(const Binary_Image<B>& b, const Image<T>& t, const Image<F>& f);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename B, typename T, typename F>
+ oln_plain(T)
+ ternary(const Binary_Image<B>& b, const Image<T>& t, const Image<F>& f)
+ {
+ oln_plain(T) output;
+ prepare(output, with, t);
+ return level::fill(inplace(output),
+ ternary_fun(pw_value(b), pw_value(t), pw_value(f)));
+ }
+
+ } // end of namespace oln::level::impl
+
+
+ // Facades.
+
+ template <typename B, typename T, typename F>
+ oln_plain(T)
+ ternary(const Binary_Image<B>& b, const Image<T>& t, const Image<F>& f)
+ {
+ oln::assert_same_point_<B, T>::check();
+ oln::assert_same_point_<T, F>::check();
+ precondition(b.points() >= t.points());
+ precondition(t.points() = f.points());
+ return impl::ternary_(exact(b), exact(t), exact(f));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::level
+
+} // end of namespace oln
+
+
+#endif // ! OLN_LEVEL_TERNARY_HH
Index: oln/level/apply.hh
--- oln/level/apply.hh (revision 970)
+++ oln/level/apply.hh (working copy)
@@ -40,7 +40,7 @@
namespace level
{
- /// Fwd decls.
+ // Fwd decls.
template <typename F, typename I>
oln_plain_value(I, typename F::result)
@@ -76,7 +76,7 @@
} // end of namespace oln::level::impl
- /// Facades.
+ // Facades.
template <typename F, typename I>
oln_plain_value(I, typename F::result)
@@ -93,7 +93,7 @@
}
-# endif
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln::level
Index: oln/arith/min.hh
--- oln/arith/min.hh (revision 0)
+++ oln/arith/min.hh (revision 0)
@@ -0,0 +1,86 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_ARITH_MIN_HH
+# define OLN_ARITH_MIN_HH
+
+# include <oln/core/concept/image.hh>
+
+
+namespace oln
+{
+
+ namespace arith
+ {
+
+ // Fwd decl.
+
+ template <typename I>
+ oln_plain(I)
+ min(const Image<I>& input1, const Image<I>& input2);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename I>
+ oln_plain(I)
+ min_(const Image<I>& input1, const Image<I>& input2)
+ {
+ oln_plain(I) output;
+ prepare(output, with, input1);
+ oln_piter(I) p(input1.points());
+ for_all(p)
+ output(p) = ( input1(p) < input2(p)
+ ? input1(p)
+ : input2(p) );
+ return output;
+ }
+
+ } // end of namespace oln::arith::impl
+
+
+ // Facade.
+
+ template <typename I>
+ oln_plain(I)
+ min(const Image<I>& input1, const Image<I>& input2)
+ {
+ return impl::min_(exact(input1), exact(input2));
+ }
+
+ } // end of namespace oln::arith
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+#endif // ! OLN_ARITH_MIN_HH
Index: oln/arith/negate.hh
--- oln/arith/negate.hh (revision 0)
+++ oln/arith/negate.hh (revision 0)
@@ -0,0 +1,96 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_ARITH_NEGATE_HH
+# define OLN_ARITH_NEGATE_HH
+
+# include <oln/core/concept/image.hh>
+# include <oln/core/internal/max_value.hh>
+# include <oln/core/internal/min_value.hh>
+
+
+namespace oln
+{
+
+ namespace arith
+ {
+
+ // Fwd decl.
+
+ template <typename I>
+ oln_plain(I)
+ negate(const Image<I>& input);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // FIXME: Trash code! Not so simple...
+
+ template <typename T>
+ T value_negate_(const T& v)
+ {
+ return static_cast<T>(oln_min(T) + (oln_max(T) - v));
+ }
+
+
+ // Generic version.
+
+ template <typename I>
+ oln_plain(I)
+ negate_(const Image<I>& input)
+ {
+ oln_plain(I) output;
+ prepare(output, with, input);
+ oln_piter(I) p(input.points());
+ for_all(p)
+ output(p) = value_negate_<oln_value(I)>(input(p));
+ return output;
+ }
+
+ } // end of namespace oln::arith::impl
+
+
+ // Facade.
+
+ template <typename I>
+ oln_plain(I)
+ negate(const Image<I>& input)
+ {
+ return impl::negate_(exact(input));
+ }
+
+
+ } // end of namespace oln::arith
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+#endif // ! OLN_ARITH_NEGATE_HH
Index: oln/canvas/two_pass.hh
--- oln/canvas/two_pass.hh (revision 970)
+++ oln/canvas/two_pass.hh (working copy)
@@ -37,7 +37,7 @@
{
template <template <class> class F,
typename I> // Data owned by f.
- void two_pass(F<I> fun)
+ void two_pass(F<I>& fun)
{
// mlc::assert_< mlc_is_a(I, Image) >::check();
@@ -104,7 +104,7 @@
}
- namespace v4 // Via Inheritens.
+ namespace v4 // Via Inheritance.
{
template <typename I>