#118: Ensure Milena supports separate compilation
-----------------------+----------------------------------------------------
Reporter: levill_r | Owner: Olena Team
Type: defect | Status: new
Priority: critical | Milestone: Olena 1.0ß
Component: Milena | Version: 1.0
Resolution: | Keywords: multiple objects separate compilation
-----------------------+----------------------------------------------------
Old description:
> Currently, several things prevent any attempt to use Milena in a
> multiple-object (`.o` files) context:
> * method and function definitions shall be tagged `inline` to prevent
> any name clash;
> * definitions of global variables shall be replaced by function serving
> a static variable;
> * and so on.
>
> I (Roland) am not sure which test protocol we should use to check this is
> fixed correctly in the whole library. Maybe include the whole headers in
> two separate units, and link them together. Or proceed component per
> component?
New description:
This ticket depends on #43.
Currently, several things prevent any attempt to use Milena in a multiple-
object (`.o` files) context:
* method and function definitions shall be tagged `inline` to prevent any
name clash;
* definitions of global variables shall be replaced by function serving a
static variable;
* and so on.
I (Roland) am not sure which test protocol we should use to check this is
fixed correctly in the whole library. Maybe include the whole headers in
two separate units, and link them together. Or proceed component per
component?
Comment (by levill_r):
Mention ticket:43.
--
Ticket URL: <https://trac.lrde.org/olena/ticket/118#comment:1>
Olena <http://olena.lrde.epita.fr>
Olena, a generic and efficient C++ image library.
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2008-01-08 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add file for example of character extraction.
* sandbox/nivault/extract_character.cc: New example.
---
extract_character.cc | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 69 insertions(+)
Index: trunk/milena/sandbox/nivault/extract_character.cc
===================================================================
--- trunk/milena/sandbox/nivault/extract_character.cc (revision 0)
+++ trunk/milena/sandbox/nivault/extract_character.cc (revision 1640)
@@ -0,0 +1,69 @@
+// Copyright (C) 2007, 2008 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 <mln/core/image2d.hh>
+# include <mln/io/pbm/load.hh>
+# include <mln/debug/println.hh>
+# include <mln/logical/not.hh>
+# include <mln/logical/or.hh>
+# include <mln/io/pbm/save.hh>
+
+# include <mln/morpho/erosion.hh>
+# include <mln/morpho/dilation.hh>
+# include <mln/make/w_window2d.hh>
+# include <mln/win/rectangle2d.hh>
+# include <mln/win/vline2d.hh>
+# include <mln/win/hline2d.hh>
+# include <mln/level/fill.hh>
+
+
+using namespace mln;
+
+int
+main(int argc, char** argv)
+{
+ using value::int_u8;
+
+ if (argc != 3)
+ {
+ std::cerr << "Usage : " << argv[0]
+ << " input.pbm output.pbm" << std::endl;
+ exit(1);
+ }
+ std::string path_input = argv[1];
+ std::string path_output = argv[2];
+
+ image2d<bool> input = io::pbm::load (path_input);
+
+ image2d<bool> output = clone(input);
+ output = logical::not_(output);
+
+ io::pbm::save (output, path_output);
+
+ std::cout << path_output << " generated" << std::endl;
+}
+
https://svn.lrde.epita.fr/svn/oln/trunk
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
* configure.ac: Configure milena/tests/data.hh.
configure.ac | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
Index: configure.ac
--- configure.ac (revision 1638)
+++ configure.ac (working copy)
@@ -78,7 +78,10 @@
## Tests. ##
## ------- ##
-# FIXME: Should be performed through oln.m4 macros?
+#
+AC_CONFIG_FILES([milena/tests/data.hh])
+
+# FIXME: Should be performed through oln.m4 macros, as we did in Olena 0.11?
AC_CONFIG_FILES([
milena/tests/Makefile
milena/tests/core/Makefile
https://svn.lrde.epita.fr/svn/oln/trunk/milena
I'll extend this to other tests, and I ask everybody to stop using
hard-coded paths to images in tests as of now. Thanks in advance!
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Have morpho tests using input images be independent of the
location of the build tree w.r.t. the source tree by removing
hard-coded paths.
* tests/data.hh.in: New.
* tests/morpho/contrast.cc,
* tests/morpho/dilation.cc,
* tests/morpho/dilation_max_h.cc,
* tests/morpho/erosion.cc,
* tests/morpho/erosion_min_h.cc,
* tests/morpho/gradient.cc,
* tests/morpho/hit_or_miss.cc,
* tests/morpho/laplacian.cc,
* tests/morpho/opening_area.cc,
* tests/morpho/thinning.cc: Use tests/data.hh to get the path to
the img/ directory.
* tests/tests.mk (AM_CPPFLAGS): Add -I$(top_builddir)/milena.
data.hh.in | 39 +++++++++++++++++++++++++++++++++++++++
morpho/contrast.cc | 4 +++-
morpho/dilation.cc | 4 +++-
morpho/dilation_max_h.cc | 4 +++-
morpho/erosion.cc | 4 +++-
morpho/erosion_min_h.cc | 4 +++-
morpho/gradient.cc | 3 ++-
morpho/hit_or_miss.cc | 9 ++++++++-
morpho/laplacian.cc | 4 +++-
morpho/opening_area.cc | 4 +++-
morpho/thinning.cc | 10 ++++++----
tests.mk | 6 ++++--
12 files changed, 80 insertions(+), 15 deletions(-)
Index: tests/tests.mk
--- tests/tests.mk (revision 1637)
+++ tests/tests.mk (working copy)
@@ -1,12 +1,14 @@
## FIXME: Revamp (see Olena 0.11's test suite).
-AM_CPPFLAGS = -I$(top_srcdir)/milena
+# Look for Milena header in srcdir and for (generated) test headers
+# (like data.hh) in builddir.
+AM_CPPFLAGS = -I$(top_srcdir)/milena -I$(top_builddir)/milena
# FIXME: Add
#
# AM_CXXFLAGS = $(CXXFLAGS_STRICT) $(CXXFLAGS_DEBUG)
#
# when oln.m4 is available in the distribution, instead of using the
-# set-by-hand TESTS_CXXFLAGS.
+# hand-made TESTS_CXXFLAGS.
TESTS_CXXFLAGS = @TESTS_CXXFLAGS@
AM_CXXFLAGS = $(TESTS_CXXFLAGS)
Index: tests/data.hh.in
--- tests/data.hh.in (revision 0)
+++ tests/data.hh.in (revision 0)
@@ -0,0 +1,39 @@
+// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// 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 TESTS_DATA_HH
+# define TESTS_DATA_HH
+
+# include <string>
+
+/** \brief The absolute path to the img directory of Milena.
+
+ Macros are evil, but they save us an extra compilation unit here
+ (as well as additional burden in Makefiles, too.). */
+# define MLN_IMG_DIR "@abs_top_srcdir@/milena/img"
+
+#endif // ! TESTS_DATA_HH
Index: tests/morpho/contrast.cc
--- tests/morpho/contrast.cc (revision 1637)
+++ tests/morpho/contrast.cc (working copy)
@@ -41,6 +41,8 @@
#include <mln/morpho/contrast.hh>
+#include "tests/data.hh"
+
int main()
{
@@ -51,7 +53,7 @@
border::thickness = 1;
image2d<int_u8> lena;
- io::pgm::load(lena, "../../img/tiny.pgm");
+ io::pgm::load(lena, MLN_IMG_DIR "/tiny.pgm");
image2d<int_u8> out = morpho::contrast(lena, rect);
io::pgm::save(out, "out.pgm");
Index: tests/morpho/gradient.cc
--- tests/morpho/gradient.cc (revision 1637)
+++ tests/morpho/gradient.cc (working copy)
@@ -39,6 +39,7 @@
#include <mln/value/int_u8.hh>
#include <mln/morpho/gradient.hh>
+#include "tests/data.hh"
int main()
@@ -50,7 +51,7 @@
border::thickness = 2;
image2d<int_u8> lena;
- io::pgm::load(lena, "../../img/tiny.pgm");
+ io::pgm::load(lena, MLN_IMG_DIR "/tiny.pgm");
io::pgm::save( morpho::gradient(lena, rect),
"out.pgm" );
Index: tests/morpho/erosion.cc
--- tests/morpho/erosion.cc (revision 1637)
+++ tests/morpho/erosion.cc (working copy)
@@ -51,6 +51,8 @@
#include <mln/convert/to_p_array.hh>
#include <mln/convert/to_window.hh>
+#include "tests/data.hh"
+
int main()
{
@@ -75,7 +77,7 @@
// 25 66 15
image2d<int_u8> lena;
- io::pgm::load(lena, "../../img/lena.pgm");
+ io::pgm::load(lena, MLN_IMG_DIR "/lena.pgm");
// trace::quiet = false;
Index: tests/morpho/thinning.cc
--- tests/morpho/thinning.cc (revision 1637)
+++ tests/morpho/thinning.cc (working copy)
@@ -43,6 +43,8 @@
#include <mln/morpho/thinning.hh>
+#include "tests/data.hh"
+
int main()
{
@@ -63,12 +65,12 @@
{
image2d<bool> pic;
- io::pbm::load(pic, "../../img/picasso.pbm");
+ io::pbm::load(pic, MLN_IMG_DIR "/picasso.pbm");
io::pbm::save(morpho::thinning(pic, win_fg, win_bg), "out.pbm" );
}
+ // FIXME: Dead code?
// {
-// image2d<int_u8> pic = io::pgm::load("../img/picasso.pgm");
-// io::pgm::save( morpho::thinning(pic, win_fg, win_bg),
-// "out.pgm" );
+// image2d<int_u8> pic = io::pgm::load(MLN_IMG_DIR "/picasso.pgm");
+// io::pgm::save( morpho::thinning(pic, win_fg, win_bg), "out.pgm" );
// }
}
Index: tests/morpho/dilation_max_h.cc
--- tests/morpho/dilation_max_h.cc (revision 1637)
+++ tests/morpho/dilation_max_h.cc (working copy)
@@ -43,6 +43,8 @@
#include <mln/convert/to_p_array.hh>
#include <mln/convert/to_window.hh>
+#include "tests/data.hh"
+
int main()
{
@@ -53,7 +55,7 @@
border::thickness = 66;
image2d<int_u8> lena;
- io::pgm::load(lena, "../../img/lena.pgm");
+ io::pgm::load(lena, MLN_IMG_DIR "/lena.pgm");
{
p_array<point2d> vec = convert::to_p_array(rec, point2d::origin);
Index: tests/morpho/hit_or_miss.cc
--- tests/morpho/hit_or_miss.cc (revision 1637)
+++ tests/morpho/hit_or_miss.cc (working copy)
@@ -45,6 +45,8 @@
#include <mln/morpho/hit_or_miss.hh>
+#include "tests/data.hh"
+
int main()
{
@@ -76,8 +78,13 @@
border::thickness = 2;
image2d<bool> pic;
- io::pbm::load(pic, "../../img/picasso.pbm");
+ io::pbm::load(pic, MLN_IMG_DIR "/picasso.pbm");
image2d<bool> out = morpho::hit_or_miss(pic, win_hit, win_miss);
+ // FIXME: We shall handle out images as well as input images.
+ // Currently, output images are named `out.*', and each test
+ // overwrites the product(s) of the previous one. Moreover, nothing
+ // is cleaned upon `make clean', which will probably bother `make
+ // distcheck'.
io::pbm::save(out, "out.pbm");
mln_postcondition(morpho::hit_or_miss(morpho::complementation(pic),
Index: tests/morpho/dilation.cc
--- tests/morpho/dilation.cc (revision 1637)
+++ tests/morpho/dilation.cc (working copy)
@@ -51,6 +51,8 @@
#include <mln/convert/to_p_array.hh>
#include <mln/convert/to_window.hh>
+#include "tests/data.hh"
+
int main()
{
@@ -61,7 +63,7 @@
border::thickness = 66;
image2d<int_u8> lena;
- io::pgm::load(lena, "../../img/lena.pgm");
+ io::pgm::load(lena, MLN_IMG_DIR "/lena.pgm");
// {
// image2d<int_u8> out(lena.domain());
Index: tests/morpho/laplacian.cc
--- tests/morpho/laplacian.cc (revision 1637)
+++ tests/morpho/laplacian.cc (working copy)
@@ -43,6 +43,8 @@
#include <mln/morpho/laplacian.hh>
+#include "tests/data.hh"
+
int main()
@@ -54,7 +56,7 @@
border::thickness = 2;
image2d<int_u8> tiny;
- io::pgm::load(tiny, "../../img/tiny.pgm");
+ io::pgm::load(tiny, MLN_IMG_DIR "/tiny.pgm");
image2d<int> lap(tiny.domain());
morpho::laplacian(tiny, rect, lap);
Index: tests/morpho/opening_area.cc
--- tests/morpho/opening_area.cc (revision 1637)
+++ tests/morpho/opening_area.cc (working copy)
@@ -39,6 +39,8 @@
#include <mln/morpho/opening_area.hh>
+#include "tests/data.hh"
+
int main()
@@ -47,7 +49,7 @@
using value::int_u8;
image2d<int_u8> lena;
- io::pgm::load(lena, "../../img/lena.pgm");
+ io::pgm::load(lena, MLN_IMG_DIR "/lena.pgm");
image2d<int_u8> out(lena.domain());
morpho::opening_area(lena, c4(), 510, out);
Index: tests/morpho/erosion_min_h.cc
--- tests/morpho/erosion_min_h.cc (revision 1637)
+++ tests/morpho/erosion_min_h.cc (working copy)
@@ -43,6 +43,8 @@
#include <mln/convert/to_p_array.hh>
#include <mln/convert/to_window.hh>
+#include "tests/data.hh"
+
int main()
{
@@ -53,7 +55,7 @@
border::thickness = 66;
image2d<int_u8> lena;
- io::pgm::load(lena, "../../img/lena.pgm");
+ io::pgm::load(lena, MLN_IMG_DIR "/lena.pgm");
{
p_array<point2d> vec = convert::to_p_array(rec, point2d::origin);