URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-06-19 Etienne FOLIO <folio(a)lrde.epita.fr>
Update histo compute and project tests and algorithms.
* folio/mln/histo/compute_histo_3d.hh: Add headers.
* folio/mln/histo/project_histo_3d.hh: New projection algorithm.
* folio/test/histo/compute_histo_3d.cc: New test.
* folio/test/histo/project_histo_3d_add.cc: New test.
* folio/test/histo/project_histo_3d_mean.cc: New test.
---
mln/histo/compute_histo_3d.hh | 30 +++++++++++--
mln/histo/project_histo_3d.hh | 56 +++++++++++++++++++++++++
test/histo/compute_histo_3d.cc | 54 ++++++++++++++++++------
test/histo/project_histo_3d_add.cc | 75 +++++++++++++++++++++++++++++++++
test/histo/project_histo_3d_mean.cc | 80 ++++++++++++++++++++++++++++++++++++
5 files changed, 277 insertions(+), 18 deletions(-)
Index: trunk/milena/sandbox/folio/test/histo/project_histo_3d_mean.cc
===================================================================
--- trunk/milena/sandbox/folio/test/histo/project_histo_3d_mean.cc (revision 0)
+++ trunk/milena/sandbox/folio/test/histo/project_histo_3d_mean.cc (revision 4173)
@@ -0,0 +1,80 @@
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project 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 <mln/accu/stat/mean.hh>
+#include <mln/literal/all.hh>
+#include <mln/value/rgb8.hh>
+
+#include "../../mln/histo/compute_histo_3d.hh"
+#include "../../mln/histo/project_histo_3d.hh"
+
+using namespace mln;
+using namespace value;
+
+
+inline
+void
+init_test_image(image2d<rgb8>& ima)
+{
+ rgb8 red = literal::red;
+ rgb8 green = literal::green;
+ rgb8 black = literal::black;
+
+ for (unsigned i = 1; i < 8; ++i)
+ for (unsigned j = 0; j < 8; ++j)
+ ima(point2d(j, i)) = black;
+
+ for (unsigned i = 0; i < 8; ++i)
+ ima(point2d(i, 0)) = red;
+
+ ima(point2d(4, 5)) = green;
+}
+
+
+int
+main(int argc, char* argv[])
+{
+ // build test image
+ image2d<rgb8> ima(8, 8);
+ init_test_image(ima);
+
+ // build histo
+ image3d<unsigned> histo = histo::compute_histo_3d(ima);
+
+ // project it
+ image2d<unsigned> proj =
+ histo::project_histo<accu::stat::mean<unsigned, unsigned>, 1>(histo);
+
+ // mln_fwd_piter_(image2d<unsigned>) p(proj.domain());
+ // for_all(p)
+ // if (proj(p) != 0)
+ // std::cout << p << " " << proj(p) << std::endl;
+
+ // verify...
+ mln_assertion(proj(point2d(255, 0)) == 8);
+ mln_assertion(proj(point2d(0, 0)) == 56);
+ mln_assertion(proj(point2d(0, 255)) == 0);
+}
Index: trunk/milena/sandbox/folio/test/histo/compute_histo_3d.cc
===================================================================
--- trunk/milena/sandbox/folio/test/histo/compute_histo_3d.cc (revision 4172)
+++ trunk/milena/sandbox/folio/test/histo/compute_histo_3d.cc (revision 4173)
@@ -1,27 +1,45 @@
-/*!
- * \file compute_histo_rgb.cc<2>
- * \author etiennefolio <ornthalas(a)gmail.com>
- */
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project 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 <iostream>
#include <mln/literal/all.hh>
-#include <mln/value/rgb.hh>
#include <mln/value/int_u8.hh>
+#include <mln/value/rgb8.hh>
#include "../../mln/histo/compute_histo_3d.hh"
-int main()
-{
using namespace mln;
using namespace value;
- typedef rgb<3> rgb3;
- // build test image
- image2d<rgb3> ima(8, 8);
- rgb3 red = literal::red;
- rgb3 green = literal::green;
- rgb3 black = literal::black;
+void
+init_test_image(image2d<rgb8>& ima)
+{
+ rgb8 red = literal::red;
+ rgb8 green = literal::green;
+ rgb8 black = literal::black;
for (unsigned i = 1; i < 8; ++i)
for (unsigned j = 0; j < 8; ++j)
@@ -38,6 +56,14 @@
point2d p(4, 5);
ima(p) = green;
+}
+
+
+int main()
+{
+ // build test image
+ image2d<rgb8> ima(8, 8);
+ init_test_image(ima);
// build histo
image3d<unsigned> out = histo::compute_histo_3d(ima);
Index: trunk/milena/sandbox/folio/test/histo/project_histo_3d_add.cc
===================================================================
--- trunk/milena/sandbox/folio/test/histo/project_histo_3d_add.cc (revision 0)
+++ trunk/milena/sandbox/folio/test/histo/project_histo_3d_add.cc (revision 4173)
@@ -0,0 +1,75 @@
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project 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 <mln/accu/math/sum.hh>
+#include <mln/literal/all.hh>
+#include <mln/value/rgb8.hh>
+
+#include "../../mln/histo/compute_histo_3d.hh"
+#include "../../mln/histo/project_histo_3d.hh"
+
+using namespace mln;
+using namespace value;
+
+
+inline
+void
+init_test_image(image2d<rgb8>& ima)
+{
+ rgb8 red = literal::red;
+ rgb8 green = literal::green;
+ rgb8 black = literal::black;
+
+ for (unsigned i = 1; i < 8; ++i)
+ for (unsigned j = 0; j < 8; ++j)
+ ima(point2d(j, i)) = black;
+
+ for (unsigned i = 0; i < 8; ++i)
+ ima(point2d(i, 0)) = red;
+
+ ima(point2d(4, 5)) = green;
+}
+
+
+int
+main(int argc, char* argv[])
+{
+ // build test image
+ image2d<rgb8> ima(8, 8);
+ init_test_image(ima);
+
+ // build histo
+ image3d<unsigned> histo = histo::compute_histo_3d(ima);
+
+ // project it
+ image2d<unsigned> proj =
+ histo::project_histo<accu::math::sum<unsigned, unsigned>, 1>(histo);
+
+ // verify...
+ mln_assertion(proj(point2d(255, 0)) == 8);
+ mln_assertion(proj(point2d(0, 0)) == 56);
+ mln_assertion(proj(point2d(0, 255)) == 0);
+}
Index: trunk/milena/sandbox/folio/mln/histo/project_histo_3d.hh
===================================================================
--- trunk/milena/sandbox/folio/mln/histo/project_histo_3d.hh (revision 0)
+++ trunk/milena/sandbox/folio/mln/histo/project_histo_3d.hh (revision 4173)
@@ -0,0 +1,56 @@
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project 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 <mln/accu/image/init.hh>
+#include <mln/accu/image/take.hh>
+#include <mln/accu/image/to_result.hh>
+#include <mln/core/image/dmorph/unproject_image.hh>
+#include <mln/core/image/image2d.hh>
+#include <mln/fun/v2v/projection.hh>
+
+
+namespace mln
+{
+ namespace histo
+ {
+
+ template <typename A, unsigned Direction, typename V>
+ image2d<mln_result(A)>
+ project_histo(const image3d<V>& h)
+ {
+ image2d<A> h_2d_a(h.nrows(), h.ncols());
+ accu::image::init(h_2d_a);
+
+ accu::image::take( unproject( h_2d_a,
+ h.domain(),
+ fun::v2v::projection<point3d, Direction>() ).rw(),
+ h );
+
+ return accu::image::to_result(h_2d_a);
+ }
+
+ }
+}
Index: trunk/milena/sandbox/folio/mln/histo/compute_histo_3d.hh
===================================================================
--- trunk/milena/sandbox/folio/mln/histo/compute_histo_3d.hh (revision 4172)
+++ trunk/milena/sandbox/folio/mln/histo/compute_histo_3d.hh (revision 4173)
@@ -1,12 +1,34 @@
-/*!
- * \file compute_histo_3d.cc
- * \author etiennefolio <ornthalas(a)gmail.com>
- */
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project 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 <mln/core/image/image2d.hh>
#include <mln/core/image/image3d.hh>
#include <mln/trait/value/comp.hh>
+
namespace mln
{
namespace histo
* build-aux/build_unit_test.sh,
* build-aux/generate_dist_headers.sh: copy scripts from milena/ and
milena/tests/unit_test.
* build-aux/Makefile.am: add the previous scripts to EXTRA_DIST.
* bootstrap,
* Makefile.am: update the use of these scripts.
---
ChangeLog | 13 +++++
Makefile.am | 4 ++
bootstrap | 8 ++--
build-aux/Makefile.am | 1 +
build-aux/build_unit_test.sh | 92 ++++++++++++++++++++++++++++++++++++
build-aux/generate_dist_headers.sh | 39 +++++++++++++++
6 files changed, 153 insertions(+), 4 deletions(-)
create mode 100755 build-aux/build_unit_test.sh
create mode 100755 build-aux/generate_dist_headers.sh
diff --git a/ChangeLog b/ChangeLog
index ac210a6..3fbe99f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2009-06-19 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
+ Add build_unit_test.sh and generate_dist_headers.sh to build-aux.
+
+ * build-aux/build_unit_test.sh,
+ * build-aux/generate_dist_headers.sh: copy scripts from milena/ and
+ milena/tests/unit_test.
+
+ * build-aux/Makefile.am: add the previous scripts to EXTRA_DIST.
+
+ * bootstrap,
+ * Makefile.am: update the use of these scripts.
+
2009-06-18 Roland Levillain <roland(a)lrde.epita.fr>
* m4/with-swilena.m4 (_OLN_WITH_SWIG): Require Python 2.5.
diff --git a/Makefile.am b/Makefile.am
index 000fd42..3657461 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -97,6 +97,10 @@ dist-hook:
$(top_srcdir)/build-aux/strip-lrde $$f; \
done; \
rm -rf $(LRDE_NODIST_FILES) && \
+ $(top_srcdir)/build-aux/build_unit_test.sh \
+ $(distdir)/milena/mln \
+ $(distdir)/milena/tests/unit_test \
+ $(top_srcdir)/milena/tests/unit_test/disabled_tests && \
( \
cd $(distdir); \
set -evx; \
diff --git a/bootstrap b/bootstrap
index 9827b9c..7273e79 100755
--- a/bootstrap
+++ b/bootstrap
@@ -129,20 +129,20 @@ require $libtoolize 1.5.22
set -x
# Generate milena/headers.mk
-run milena ./generate_dist_headers.sh
+run milena `pwd`/build-aux/generate_dist_headers.sh mln ./headers.mk ./nodist-headers
# Generate scribo/headers.mk
-run scribo ./generate_dist_headers.sh
+run . `pwd`/build-aux/generate_dist_headers.sh scribo scribo/headers.mk scribo/nodist-headers
# Generate lists of files to be part of the distribution
# for the tutorial.
run milena/doc ./generate_dist_files.sh
# Generate unit test files.
-run milena/tests/unit_test ./build_unit_test.sh `pwd`/milena/mln
+run . ./build-aux/build_unit_test.sh `pwd`/milena/mln milena/tests/unit_test milena/tests/unit_test/disabled_tests
# Generate unit test files for Scribo.
-run scribo/tests/unit_test ./build_unit_test.sh `pwd`/scribo
+run scribo/tests/unit_test ./build_unit_test.sh `pwd`/scribo .
# Install the GNU Build System.
autoreconf -f -v -i
diff --git a/build-aux/Makefile.am b/build-aux/Makefile.am
index 7a2901f..1185eaf 100644
--- a/build-aux/Makefile.am
+++ b/build-aux/Makefile.am
@@ -16,3 +16,4 @@
#
## Process this file through Automake to produce Makefile.in.
+EXTRA_DIST = generate_dist_headers.sh build_unit_test.sh
diff --git a/build-aux/build_unit_test.sh b/build-aux/build_unit_test.sh
new file mode 100755
index 0000000..8080ef2
--- /dev/null
+++ b/build-aux/build_unit_test.sh
@@ -0,0 +1,92 @@
+#! /bin/sh
+
+# Copyright (C) 2007, 2009 EPITA Research and Development Laboratory
+# (LRDE)
+#
+# This file is part of Olena.
+#
+# Olena is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, version 2 of the License.
+#
+# Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
+
+## FIXME: Don't use `echo -n', as echo's options are not portable.
+##
+## http://www.gnu.org/software/autoconf/manual/html_node/Limitations-of-Builti…
+##
+## As an ugly workaround, use `printf' instead. The right approach
+## would be to only emit lines ended with newlines.
+ECHO_N=printf
+
+# Use the C locale to have a deterministic sort.
+export LC_ALL=C
+
+test $# -eq 3 || { echo "Usage: $0 <scanned dir> <output_dir> <disabled_tests>" && exit 1; }
+
+scanned_dir=$1
+output_dir=$2
+disabled_tests=$3
+
+## FIXME: We do not include these directories
+##
+## mln/io/dicom
+## mln/io/fits
+## mln/io/magick
+## mln/io/tiff
+##
+## because they contain files depending on optional (external)
+## libraries. We should test them conditionally.
+HEADERS=$(find $scanned_dir -type f -name "*.hh" \
+ | sort \
+ | sed -e 's/.*\/mln\/\(.*\)/mln\/\1/g' | sed 's/\.\.\/\.\.\///g' \
+ | comm -23 - "$disabled_tests")
+
+output="$output_dir/unit-tests.mk"
+
+rm -f "$output"
+rm -f mln_*.cc
+
+# Build unit-tests.mk.
+echo "## Generated by $0, do not modify." >"$output"
+echo >>"$output"
+$ECHO_N "check_PROGRAMS = " >>"$output"
+
+for i in $HEADERS; do
+ FILE_CC=`echo $i | sed 's/[/.]/_/g' | sed 's/_hh/\.cc/g'`
+
+ # Build .cc.
+ cat > $output_dir/$FILE_CC << EOF
+// Unit test for $i.
+// Generated by $0, do not modify.
+
+// Include the file twice, so we detect missing inclusion guards.
+#include <$i>
+#include <$i>
+
+int main()
+{
+ // Nothing.
+}
+EOF
+
+ # Build unit-tests.mk.
+ TARGET=`echo "${FILE_CC}" | sed 's/\.cc//'`
+ echo " \\" >>"$output"
+ $ECHO_N "${TARGET}" >>"$output"
+done
+
+# Build "$output".
+echo "" >>"$output"
+echo "" >>"$output"
+for i in $HEADERS; do
+ FILE_CC=`echo $i | sed 's/[/.]/_/g' | sed 's/_hh/\.cc/g'`
+ NAME=`echo $FILE_CC | sed 's/\.cc//g'`
+ echo "${NAME}_SOURCES = $FILE_CC" >>"$output"
+done
diff --git a/build-aux/generate_dist_headers.sh b/build-aux/generate_dist_headers.sh
new file mode 100755
index 0000000..60aa946
--- /dev/null
+++ b/build-aux/generate_dist_headers.sh
@@ -0,0 +1,39 @@
+#! /bin/sh
+
+# Generate a list of distributed files w.r.t. a list of file which must
+# be excluded.
+# --------------------
+# List all the headers in order to make them part of distribution.
+
+# Use the C locale to have a deterministic sort.
+export LC_ALL=C
+
+if [ $# -ne 3 ]; then
+ echo "$0 <scanned_dir> <output> <nodist-headers>"
+ exit 1
+fi
+
+me=`basename $0`
+scanned_dir=$1
+output=$2
+nodist_headers=$3
+test -f "$nodist_headers" \
+ || { echo "$me: Cannot find \`$nodist_headers' in `pwd`."; exit 1; }
+
+echo "Generating $output..." >&2
+rm -f "$output"
+cat <<EOF >"$output"
+## Generated by \`$me', do not edit by hand.
+
+nobase_include_HEADERS = \\
+EOF
+
+find $scanned_dir -type f -a \( -name '*.hh' -o -name '*.hxx' \) \
+ | sort \
+ | comm -23 - "$nodist_headers" \
+ | sed -e 's/$/ \\/g' >> $output
+
+last_line=`tail -n 1 $output | sed -e 's/\\\//g'` # remove '\' in last line
+sed '$d' < $output > $output.tmp # remove last line
+mv $output.tmp $output
+echo $last_line >> $output # put the cleaned last line back.
--
1.5.6.5
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Augment demo on neighborhood genericity.
* mln/core/image/dmorph/transformed_image.hh
(operator()): Fix precondition.
Layout.
* mln/make/neighb2d.hh: New.
* mln/make/all.hh: Update.
* demos/genericity/neighborhood: New directory.
* demos/genericity/neighborhood.cc: Move...
* demos/genericity/neighborhood/neighborhood.cc: ...here.
Revamp.
* demos/genericity/neighborhood/duality.cc: New.
* demos/genericity/neighborhood/world.pbm: New.
* demos/genericity/neighborhood/drawing.pbm: New.
* demos/genericity/neighborhood/permissive.cc: New.
demos/genericity/neighborhood/duality.cc | 66 +++++++++++++++
demos/genericity/neighborhood/neighborhood.cc | 110 ++++++++++++++------------
demos/genericity/neighborhood/permissive.cc | 70 ++++++++++++++++
mln/core/image/dmorph/transformed_image.hh | 18 ++--
mln/make/all.hh | 4
mln/make/neighb2d.hh | 70 ++++++++++++++++
6 files changed, 280 insertions(+), 58 deletions(-)
Index: mln/core/image/dmorph/transformed_image.hh
--- mln/core/image/dmorph/transformed_image.hh (revision 4166)
+++ mln/core/image/dmorph/transformed_image.hh (working copy)
@@ -139,10 +139,6 @@
- template <typename I, typename F, typename J>
- void init_(tag::image_t, transformed_image<I,F>& target, const J& model);
-
-
# ifndef MLN_INCLUDE_ONLY
@@ -153,12 +149,18 @@
void init_(tag::image_t, transformed_image<I,F>& target, const J& model)
{
I ima;
- init_(tag::image, ima, model);
+ init_(tag::image, ima, exact(model));
F f;
- init_(tag::function, f, model);
+ init_(tag::function, f, exact(model));
target.init_(ima, f);
}
+ template <typename I, typename F>
+ void init_(tag::function_t, F& f, const transformed_image<I,F>& model)
+ {
+ f = model.domain().function();
+ }
+
// internal::data< transformed_image<I,F> >
@@ -216,7 +218,7 @@
{
mln_precondition(this->delegatee_() != 0);
mln_precondition(exact(this)->has(p));
- mln_precondition(this->delegatee_()->has(p));
+ mln_precondition(this->delegatee_()->has(this->data_->f_(p)));
return this->delegatee_()->operator()(this->data_->f_(p));
}
@@ -227,7 +229,7 @@
{
mln_precondition(this->delegatee_() != 0);
mln_precondition(exact(this)->has(p));
- mln_precondition(this->delegatee_()->has(p));
+ mln_precondition(this->delegatee_()->has(this->data_->f_(p)));
return this->delegatee_()->operator()(this->data_->f_(p));
}
Index: mln/make/neighb2d.hh
--- mln/make/neighb2d.hh (revision 0)
+++ mln/make/neighb2d.hh (revision 0)
@@ -0,0 +1,70 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project 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 MLN_MAKE_NEIGHB2D_HH
+# define MLN_MAKE_NEIGHB2D_HH
+
+/// \file
+///
+/// \brief Routine to create a double neighborhood.
+///
+/// \todo Add overload with 'when_*' being Neighborhood<N>...
+
+# include <mln/core/alias/neighb2d.hh>
+
+
+namespace mln
+{
+
+ namespace make
+ {
+
+ template <unsigned S>
+ mln::neighb2d
+ neighb2d(bool const (&vals) [S]);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <unsigned S>
+ inline
+ mln::neighb2d
+ neighb2d(bool const (&vals) [S])
+ {
+ enum { h = mlc_sqrt_int(S) / 2 };
+ mlc_bool((2 * h + 1) * (2 * h + 1) == S)::check();
+ mln::neighb2d nbh;
+ convert::from_to(vals, nbh);
+ return nbh;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::make
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MAKE_NEIGHB2D_HH
Index: mln/make/all.hh
--- mln/make/all.hh (revision 4166)
+++ mln/make/all.hh (working copy)
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -49,6 +50,7 @@
# include <mln/make/image2d.hh>
# include <mln/make/image3d.hh>
# include <mln/make/mat.hh>
+# include <mln/make/neighb2d.hh>
# include <mln/make/pix.hh>
# include <mln/make/pixel.hh>
# include <mln/make/point2d_h.hh>
Index: demos/genericity/neighborhood/duality.cc
--- demos/genericity/neighborhood/duality.cc (revision 0)
+++ demos/genericity/neighborhood/duality.cc (revision 0)
@@ -0,0 +1,66 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+/// \file demos/genericity/neighborhood/duality.cc
+///
+/// Demo on dual neighborhoods.
+
+#include <mln/core/image/image2d.hh>
+#include <mln/io/pbm/load.hh>
+#include <mln/labeling/colorize.hh>
+#include <mln/labeling/flat_zones.hh>
+#include <mln/value/rgb8.hh>
+#include <mln/io/ppm/save.hh>
+
+#include <mln/core/alias/neighb2d.hh>
+#include <mln/make/dual_neighb.hh>
+
+
+
+template <typename N>
+void labelize(const mln::image2d<bool>& pic,
+ const N& nbh,
+ const std::string& filename)
+{
+ using namespace mln;
+ using value::rgb8;
+ unsigned n;
+ image2d<unsigned> lab = labeling::flat_zones(pic, nbh, n);
+ image2d<rgb8> out = labeling::colorize(rgb8(), lab, n);
+ io::ppm::save(out, filename);
+}
+
+
+
+int main()
+{
+ using namespace mln;
+
+ image2d<bool> pic = io::pbm::load("drawing.pbm");
+
+ labelize(pic, make::dual_neighb(pic, c4(), c8()), "c4_c8.ppm");
+ labelize(pic, make::dual_neighb(pic, c8(), c4()), "c8_c4.ppm");
+ labelize(pic, c6_2d(), "c6_c6.ppm");
+}
Index: demos/genericity/neighborhood/world.pbm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: demos/genericity/neighborhood/world.pbm
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Index: demos/genericity/neighborhood/drawing.pbm
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: demos/genericity/neighborhood/drawing.pbm
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Index: demos/genericity/neighborhood/permissive.cc
--- demos/genericity/neighborhood/permissive.cc (revision 0)
+++ demos/genericity/neighborhood/permissive.cc (revision 0)
@@ -0,0 +1,70 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+/// \file demos/genericity/neighborhood/permissive.cc
+///
+/// Demo on user-defined simple neighborhood.
+
+#include <mln/core/image/image2d.hh>
+#include <mln/io/pbm/load.hh>
+
+#include <mln/make/neighb2d.hh>
+#include <mln/labeling/blobs.hh>
+
+#include <mln/io/ppm/save.hh>
+#include <mln/labeling/colorize.hh>
+#include <mln/value/rgb8.hh>
+
+#include <mln/fun/p2p/fold.hh>
+#include <mln/core/image/dmorph/transformed_image.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+
+ image2d<bool> world = io::pbm::load("world.pbm");
+
+ bool large[] = { 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1,
+ 1, 1, 0, 1, 1,
+ 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1 };
+ neighb2d nbh = make::neighb2d(large);
+
+ unsigned n;
+ image2d<unsigned> labeled = labeling::blobs(world, nbh, n);
+
+ io::ppm::save(labeling::colorize(value::rgb8(), labeled, n),
+ "world.ppm");
+
+
+ fun::p2p::fold<point2d,0,1> f(world.domain());
+ labeled = labeling::blobs(transform_domain(world, f), nbh, n).unmorph_();
+
+ io::ppm::save(labeling::colorize(value::rgb8(), labeled, n),
+ "world_bis.ppm");
+}
Index: demos/genericity/neighborhood/neighborhood.cc
--- demos/genericity/neighborhood/neighborhood.cc (revision 0)
+++ demos/genericity/neighborhood/neighborhood.cc (working copy)
@@ -1,52 +1,46 @@
// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
//
-// This file is part of the Milena 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 file is part of Olena.
//
-// This library is distributed in the hope that it will be useful,
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena 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.
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
//
// As a special exception, you may use this file as part of a free
-// software library without restriction. Specifically, if other files
+// software project without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
-// file, or you compile this file and link it with other files to
-// produce an executable, this file does not by itself cause the
-// resulting executable to be covered by the GNU General Public
-// License. This exception does not however invalidate any other
-// reasons why the executable file might be covered by the GNU General
-// Public License.
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
-/// \file demos/genericity/neighborhood.cc
+/// \file demos/genericity/neighborhood/neighborhood.cc
///
-/// Test on mln::labeling::blobs.
+/// Demo on using or defining neighborhoods.
#include <mln/core/image/image2d.hh>
-#include <mln/io/pbm/load.hh>
#include <mln/labeling/blobs.hh>
#include <mln/labeling/colorize.hh>
-#include <mln/labeling/flat_zones.hh>
#include <mln/value/rgb8.hh>
#include <mln/io/ppm/save.hh>
-#include <mln/core/alias/neighb2d.hh>
-#include <mln/make/dual_neighb.hh>
+#include <mln/io/pbm/load.hh>
+#include <mln/make/neighb2d.hh>
#include <mln/make/double_neighb2d.hh>
-#include <mln/debug/println.hh>
-#include "../../tests/data.hh"
template <typename N>
-void run(const mln::image2d<bool>& pic,
+void labelize(const mln::image2d<bool>& pic,
const N& nbh,
const std::string& filename)
{
@@ -59,41 +53,59 @@
}
+bool chess(const mln::point2d& p)
+{
+ return (p.row() + p.col()) % 2 == 0;
+}
+
+bool top_right(const mln::point2d& p)
+{
+ return p.col() >= p.row();
+}
+
+
int main()
{
using namespace mln;
- image2d<bool> pic = io::pbm::load(MLN_IMG_DIR "/small.pbm");
+ image2d<bool> pic = io::pbm::load("drawing.pbm");
- run(pic, c4(), "c4.ppm");
- run(pic, c8(), "c8.ppm");
- run(pic, c6_2d(), "c6.ppm");
+ // Classical 2D neighborhoods.
- {
- bool vert[] = { 0, 1, 0,
- 0, 0, 0,
- 0, 1, 0 };
+ labelize(pic, c4(), "c4.ppm");
+ labelize(pic, c8(), "c8.ppm");
- bool hori[] = { 0, 0, 0,
+
+ // A user-defined simple neighborhood.
+
+ bool horiz[] = { 0, 0, 0,
1, 0, 1,
0, 0, 0 };
- run(pic,
- make::double_neighb2d(fun::p2b::chess(), vert, hori),
- "cmy.ppm");
- }
+ labelize(pic, make::neighb2d(horiz), "c2.ppm");
- {
- using value::rgb8;
- unsigned n;
- image2d<unsigned> lab;
- lab = labeling::flat_zones(pic,
- make::dual_neighb(pic,
- c4(), // object
- c8()), // background
- n);
- image2d<rgb8> out = labeling::colorize(rgb8(), lab, n);
- io::ppm::save(out, "cdual48.ppm");
- }
+ // Another user-defined simple neighborhood.
+
+ bool tilt[] = { 1, 1, 0,
+ 0, 0, 0,
+ 0, 1, 1 };
+ labelize(pic, make::neighb2d(tilt), "cZ.ppm");
+
+
+ // A user-defined double-neighborhood.
+
+ bool nbh1[] = { 1, 1, 0,
+ 1, 0, 1,
+ 0, 1, 1 };
+
+ bool nbh2[] = { 0, 1, 1,
+ 1, 0, 1,
+ 1, 1, 0 };
+ labelize(pic, make::double_neighb2d(chess, nbh1, nbh2), "c6.ppm");
+
+
+ // Another user-defined double-neighborhood.
+
+ labelize(pic, make::double_neighb2d(top_right, nbh1, nbh2), "cX.ppm");
}
Property changes on: demos/genericity/neighborhood/neighborhood.cc
___________________________________________________________________
Added: svn:mergeinfo