Index: ChangeLog
from Nicolas Ballas <ballas(a)lrde.epita.fr>
add point implementation for Iterator_On_Points.
* olena/tests/core/iter_point1d.cc, olena/tests/core/iter_point2d.cc: New.
* olena/tests/core/iter_point3d.cc: New test file.
* olena/tests/core/Makefile.am: Add new tests in make check.
* olena/oln/core/internal/iterator_on_points_impl.hh: New, implementations for Iterator_On_Points.
* olena/oln/core/internal/iterator_on_points_base.hh: Now derive from itertor_on_points_impl
oln/core/internal/iterator_on_points_base.hh | 10 +
oln/core/internal/iterator_on_points_impl.hh | 141 +++++++++++++++++++++++++++
tests/core/Makefile.am | 6 +
tests/core/iter_point1d.cc | 48 +++++++++
tests/core/iter_point2d.cc | 50 +++++++++
tests/core/iter_point3d.cc | 52 +++++++++
6 files changed, 305 insertions(+), 2 deletions(-)
Index: olena/tests/core/iter_point1d.cc
--- olena/tests/core/iter_point1d.cc (revision 0)
+++ olena/tests/core/iter_point1d.cc (revision 0)
@@ -0,0 +1,48 @@
+// 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>
+#include <oln/core/internal/iterator_on_points_base.hh>
+
+
+
+int
+main()
+{
+
+ oln::image1d<int> ima1(40);
+ oln::image1d<int>::piter p (ima1.points());
+ oln::point1d p1;
+
+ for (p.start(); p.is_valid(); p.next())
+ p1.ind() = p.ind();
+
+ assert(p1.ind() == 39);
+ return 0;
+}
Index: olena/tests/core/iter_point2d.cc
--- olena/tests/core/iter_point2d.cc (revision 0)
+++ olena/tests/core/iter_point2d.cc (revision 0)
@@ -0,0 +1,50 @@
+// 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()
+{
+
+ oln::image2d<int> ima1(40, 30);
+ oln::image2d<int>::piter p (ima1.points());
+ oln::point2d p1;
+
+ for (p.start(); p.is_valid(); p.next())
+ {
+ p1.row() = p.row();
+ p1.col() = p.col();
+ }
+
+ assert(p1.row() == 39);
+ assert(p1.col() == 29);
+
+ return 0;
+}
Index: olena/tests/core/iter_point3d.cc
--- olena/tests/core/iter_point3d.cc (revision 0)
+++ olena/tests/core/iter_point3d.cc (revision 0)
@@ -0,0 +1,52 @@
+// 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()
+{
+
+ oln::image3d<int> ima1(40, 30, 20);
+ oln::image3d<int>::piter p (ima1.points());
+ oln::point3d p1;
+
+ for (p.start(); p.is_valid(); p.next())
+ {
+ p1.row() = p.row();
+ p1.col() = p.col();
+ p1.slice() = p.slice();
+ }
+
+ assert(p1.row() == 39);
+ assert(p1.col() == 29);
+ assert(p1.slice() == 19);
+
+ return 0;
+}
Index: olena/tests/core/Makefile.am
--- olena/tests/core/Makefile.am (revision 923)
+++ olena/tests/core/Makefile.am (working copy)
@@ -25,6 +25,9 @@
grid \
image1d \
image2d \
+ iter_point1d \
+ iter_point2d \
+ iter_point3d \
neighb2d \
npoints \
point2d \
@@ -40,6 +43,9 @@
grid_SOURCES = grid.cc
image1d_SOURCES = image1d.cc
image2d_SOURCES = image2d.cc
+iter_point1d_SOURCES = iter_point1d.cc
+iter_point2d_SOURCES = iter_point2d.cc
+iter_point3d_SOURCES = iter_point3d.cc
neighb2d_SOURCES = neighb2d.cc
npoints_SOURCES = npoints.cc
point2d_SOURCES = point2d.cc
Index: olena/oln/core/internal/iterator_on_points_impl.hh
--- olena/oln/core/internal/iterator_on_points_impl.hh (revision 0)
+++ olena/oln/core/internal/iterator_on_points_impl.hh (revision 0)
@@ -0,0 +1,141 @@
+// 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_ITERATOR_ON_POINTS_IMPL_HH
+# define OLN_CORE_INTERNAL_ITERATOR_ON_POINTS_IMPL_HH
+
+
+namespace oln
+{
+
+ // Forward declarations
+ namespace impl
+ {
+ template <unsigned n, typename Exact, typename P>
+ struct iterator_on_points_impl;
+ }
+
+
+ template <unsigned n, typename Exact, typename P>
+ struct super_trait_< impl::iterator_on_points_impl<n, Exact, P> >
+ {
+ typedef Any<P> ret;
+ };
+
+ template <unsigned n, typename Exact, typename P>
+ struct vtypes< impl::iterator_on_points_impl<n, Exact, P> >
+ {
+ };
+
+
+ namespace impl
+ {
+ template <unsigned n, typename Exact, typename P>
+ struct iterator_on_points_impl : public virtual Any<Exact>
+ {
+ };
+
+ /// point1d interface
+ template <typename Exact, typename P>
+ struct iterator_on_points_impl<1, Exact, P> : public virtual Any< Exact >
+ {
+ typename P::coord ind() const;
+ };
+
+ /// point2d interface
+ template <typename Exact, typename P>
+ struct iterator_on_points_impl<2, Exact, P>: public virtual Any< Exact >
+ {
+ typename P::coord row() const;
+ typename P::coord col() const;
+ };
+
+ /// point3d interface
+ template <typename Exact, typename P>
+ struct iterator_on_points_impl<3, Exact, P>: public virtual Any< Exact >
+ {
+ typename P::coord row() const;
+ typename P::coord col() const;
+ typename P::coord slice() const;
+ };
+
+# ifndef OLN_INCLUDE_ONLY
+
+ // point1d
+ template <typename Exact, typename P>
+ typename P::coord
+ iterator_on_points_impl<1, Exact, P>::ind() const
+ {
+ return exact(this)->to_point().ind();
+ }
+
+ // point2d
+ template <typename Exact, typename P>
+ typename P::coord
+ iterator_on_points_impl<2, Exact, P>::row() const
+ {
+ return exact(this)->to_point().row();
+ }
+
+
+ template <typename Exact, typename P>
+ typename P::coord
+ iterator_on_points_impl<2, Exact, P>::col() const
+ {
+ return exact(this)->to_point().col();
+ }
+
+ // point3d
+ template <typename Exact, typename P>
+ typename P::coord
+ iterator_on_points_impl<3, Exact, P>::row() const
+ {
+ return exact(this)->to_point().row();
+ }
+
+ template <typename Exact, typename P>
+ typename P::coord
+ iterator_on_points_impl<3, Exact, P>::col() const
+ {
+ return exact(this)->to_point().col();
+ }
+
+ template <typename Exact, typename P>
+ typename P::coord
+ iterator_on_points_impl<3, Exact, P>::slice() const
+ {
+ return exact(this)->to_point().slice();
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln
+
+} // end of namespace oln
+
+#endif // ! OLN_CORE_INTERNAL_ITERATOR_ON_POINTS_IMPL_HH
Index: olena/oln/core/internal/iterator_on_points_base.hh
--- olena/oln/core/internal/iterator_on_points_base.hh (revision 923)
+++ olena/oln/core/internal/iterator_on_points_base.hh (working copy)
@@ -29,6 +29,7 @@
# define OLN_CORE_INTERNAL_ITERATOR_ON_POINTS_BASE_HH
# include <oln/core/concept/iterator_on_points.hh>
+# include <oln/core/internal/iterator_on_points_impl.hh>
namespace oln
@@ -57,15 +58,20 @@
typedef stc::final< oln_coord(point__) > coord;
typedef stc::final< oln_dim(point__) > dim;
typedef stc::final< oln_dpoint(point__) > dpoint;
- };
+ // for getting point implementation
+ typedef stc_deferred(dim) dim__;
+ };
namespace internal
{
template <typename Exact>
- class iterator_on_points_base_ : public Iterator_on_Points<Exact>
+ class iterator_on_points_base_ : public Iterator_on_Points<Exact>,
+ public impl::iterator_on_points_impl
+ <mlc_value(typename vtypes< internal::iterator_on_points_base_<Exact> >::dim__),
+ Exact, typename vtypes< internal::iterator_on_points_base_<Exact> >::point__>
{
protected:
iterator_on_points_base_();
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Fix CC_tarjan + test, sequential reconstruction.
* tests/algorithms/cc_tarjan.cc: .
* oln/morpho/reconstruction.hh: New.
* oln/morpho/cc_tarjan.hh: .
* oln/io/pnm.hh: .
oln/io/pnm.hh | 53 ++++++++++++++--------------
oln/morpho/cc_tarjan.hh | 9 +---
oln/morpho/reconstruction.hh | 78 ++++++++++++++++++++++++++++++++++++++++++
tests/algorithms/cc_tarjan.cc | 52 ++++++++++------------------
4 files changed, 128 insertions(+), 64 deletions(-)
Index: tests/algorithms/cc_tarjan.cc
--- tests/algorithms/cc_tarjan.cc (revision 919)
+++ tests/algorithms/cc_tarjan.cc (working copy)
@@ -4,42 +4,30 @@
#include <oln/morpho/cc_tarjan.hh>
-#include <oln/debug/print.hh>
-
-
-template <typename I>
-void set(I& ima,
- int i,
- int j)
-{
- oln_point(I) p(i, j);
- ima(p) = true;
-}
-
int main()
{
using namespace oln;
typedef image2d<bool> I;
I ima(3, 3);
- set(ima, 0, 0);
- set(ima, 0, 1);
- set(ima, 0, 2);
-
- set(ima, 2, 0);
- set(ima, 2, 1);
- set(ima, 2, 2);
-
- I out = morpho::cc_tarjan(ima + c4);
-
-// for (unsigned i; i < 3; i++)
-// for (unsigned j; j < 3; j++)
-// {
-// if (i == 0)
-// assert(ima(i, j) == 1);
-// if (i == 1)
-// assert(ima(i, j) == 0);
-// if (i == 2)
-// assert(ima(i, j) == 2);
-// }
+ ima.at(0, 0) = true;
+ ima.at(0, 1) = true;
+ ima.at(0, 2) = true;
+
+ ima.at(2, 0) = true;
+ ima.at(2, 1) = true;
+ ima.at(2, 2) = true;
+
+ image2d<unsigned int> out = (morpho::cc_tarjan(ima + c4)).image();
+
+ for (unsigned i = 0; i < 3; i++)
+ for (unsigned j = 0; j < 3; j++)
+ {
+ if (i == 0)
+ assert(out.at(i, j) == 1);
+ if (i == 1)
+ assert(out.at(i, j) == 0);
+ if (i == 2)
+ assert(out.at(i, j) == 2);
+ }
}
Index: oln/morpho/reconstruction.hh
--- oln/morpho/reconstruction.hh (revision 0)
+++ oln/morpho/reconstruction.hh (revision 0)
@@ -0,0 +1,78 @@
+// 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_RECONSTRUCTION_HH
+# define OLN_MORPHO_RECONSTRUCTION_HH
+
+#include <oln/accumulator/max.hh>
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ namespace impl
+ {
+
+ template <typename I , typename J>
+ void // FIXME : slow version.
+ reconstruction_(const Image_with_Nbh<I>& marker,
+ const Binary_Image<I>& mask)
+ {
+ // first
+ oln_fwd_piter(I) p(input.points());
+ for_all(p)
+ marker(p) = local(max, marker, p) && mask(p); // FIXME : local_sup.
+
+
+ // second
+ oln_bkd_piter(I) p(input.points());
+ for_all(p)
+ marker(p) = local(max, marker, p) && mask(p); // FIXME : local_inf.
+ }
+
+ } // end of namespace oln::morpho::impl
+
+ template <typename I , typename J>
+ void
+ reconstruction(const Image_with_Nbh<I>& marker,
+ const Binary_Image<J>& mask)
+ {
+ impl::reconstruction_(exact(mask), exact(marker));
+ }
+
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_DILATION_HH
Index: oln/morpho/cc_tarjan.hh
--- oln/morpho/cc_tarjan.hh (revision 919)
+++ oln/morpho/cc_tarjan.hh (working copy)
@@ -10,7 +10,7 @@
// 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
+// 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.
@@ -70,18 +70,15 @@
oln_bkd_piter(I) p(input.points());
for_all(p)
{
+ parent(p) = p;
if ( input(p) )
{
- parent(p) = p;
oln_niter(I) n(p, input);
for_all(n)
{
- if ( input(n) )
- {
- if ( is_processed(n) )
+ if ( input(n) && is_processed(n) )
do_union(input ,n, p, parent);
}
- }
is_processed(p) = true;
}
}
Index: oln/io/pnm.hh
--- oln/io/pnm.hh (revision 919)
+++ oln/io/pnm.hh (working copy)
@@ -33,8 +33,9 @@
# include <fstream>
# include <string>
-# include <oln/basics2d.hh>
-
+# include <oln/core/2d/image2d.hh>
+# include <oln/core/2d/window2d.hh>
+# include <oln/core/2d/neighb2d.hh>
namespace oln {
@@ -117,7 +118,7 @@
oln_coord(I) cols = 0;
unsigned bits = 0;
unsigned char c = 0;
- oln_fwd_piter(I) p(ima.topo());
+ oln_fwd_piter(I) p(ima.points());
for_all(p)
{
if (bits == 0)
@@ -126,7 +127,7 @@
bits = 8;
}
ima(p) = (c & (1 << --bits)) ? false : true;
- if (++cols >= int(ima.bbox().ncols()))
+ if (++cols >= int(ima.max_col()))
cols = bits = 0;
}
}
@@ -136,7 +137,7 @@
template <typename I>
void load_pbm_ascii(std::ifstream& file, I& ima)
{
- oln_fwd_piter(I) p(ima.topo());
+ oln_fwd_piter(I) p(ima.points());
for_all(p)
ima(p) = (file.get() == '0');
}
@@ -162,7 +163,7 @@
template <typename I>
void load_pnm_raw_2d(std::ifstream& file, I& ima)
{
- int col = ima.pmin().col();
+ int col = ima.col();
size_t len = ima.bbox().ncols();
for (int row = ima.pmin().row(); row <= ima.pmax().row(); ++row)
file.read((char*)(ima.adr_at(row, col)),
@@ -195,26 +196,26 @@
}
- image2d<unsigned char> load_pgm(const std::string& filename)
- {
- std::ifstream file(filename.c_str());
- if (not file)
- {
- std::cerr << "error: file '" << filename
- << "' not found!";
- abort();
- }
- char type;
- int nrows, ncols;
- internal::read_pnm_header('2', '5', file, type, nrows, ncols);
- image2d<unsigned char> ima(nrows, ncols);
- if (type == '4')
- internal::load_pnm_raw_2d(file, ima);
- else
- // type == '1'
- internal::load_pnm_ascii(file, ima);
- return ima;
- }
+// image2d<unsigned char> load_pgm(const std::string& filename)
+// {
+// std::ifstream file(filename.c_str());
+// if (not file)
+// {
+// std::cerr << "error: file '" << filename
+// << "' not found!";
+// abort();
+// }
+// char type;
+// int nrows, ncols;
+// internal::read_pnm_header('2', '5', file, type, nrows, ncols);
+// image2d<unsigned char> ima(nrows, ncols);
+// if (type == '4')
+// internal::load_pnm_raw_2d(file, ima);
+// else
+// // type == '1'
+// internal::load_pnm_ascii(file, ima);
+// return ima;
+// }
} // end of namespace oln::io