URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-15 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add norm l1.
* l1.hh: New norm l1.
---
l1.hh | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 120 insertions(+)
Index: trunk/milena/mln/norm/l1.hh
===================================================================
--- trunk/milena/mln/norm/l1.hh (revision 0)
+++ trunk/milena/mln/norm/l1.hh (revision 1335)
@@ -0,0 +1,120 @@
+// 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 MLN_NORM_L1_HH
+# define MLN_NORM_L1_HH
+
+/*! \file mln/norm/l1.hh
+ *
+ * \brief Define some infinity-norm related routines.
+ */
+
+# include <cmath>
+
+# include <mln/metal/vec.hh>
+
+namespace mln
+{
+
+ namespace norm
+ {
+
+ /// Infinity-norm of a vector \p vec.
+ template <unsigned n, typename C>
+ float l1(const C (&vec)[n]);
+
+ /// Infinity-norm distance between vectors \p v1 and \p v2.
+ template <unsigned n, typename C>
+ float l1_distance(const C (&v1)[n], const C (&v2)[n]);
+
+ template <unsigned n, typename C>
+ float l1(const metal::vec<n,C>& vec);
+
+ template <unsigned n, typename C>
+ float l1_distance(const metal::vec<n,C>& vec1, const metal::vec<n,C>& vec2);
+
+ // FIXME: Replace float by mln_value_sum(C)...
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <unsigned n, typename C>
+ float l1(const C (&vec)[n])
+ {
+ float c = 0;
+ for (unsigned i = 0; i < n; ++i)
+ {
+ float v = vec[i];
+ c += fabs (v);
+ }
+ return c;
+ }
+
+ template <unsigned n, typename C>
+ float l1_distance(const C (&v1)[n], const C (&v2)[n])
+ {
+ float d = 0;
+ for (unsigned i = 0; i < n; ++i)
+ {
+ float v = v1[i] - v2[i];
+ d += fabs (v);
+ }
+ return d;
+ }
+
+ template <unsigned n, typename C>
+ float l1(const metal::vec<n,C>& vec)
+ {
+ float c = 0;
+ for (unsigned i = 0; i < n; ++i)
+ if (vec[i] > 0)
+ c += vec[i];
+ else
+ c -= vec[i];
+ return c;
+ }
+
+ template <unsigned n, typename C>
+ float l1(const metal::vec<n,C>& vec1, const metal::vec<n,C>& vec2)
+ {
+ float d = 0;
+ for (unsigned i = 0; i < n; ++i)
+ {
+ float v = vec1[i] - vec2[i];
+ d += fabs (v);
+ }
+ return d;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::norm
+
+} // end of namespace mln
+
+
+#endif // ! MLN_NORM_L1_HH
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-12 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Add some literals.
* mln/literal/all.hh: Add missing includes.
* mln/literal/colors.hh: New, red, green and blue literals.
* mln/literal/grays.hh: New, medium_gray.
* tests/literal_medium_gray.cc: New, a little test.
* tests/value_rgb8.cc: Update to use literals.
* mln/value/graylevel.hh,
* mln/value/rgb.hh: Constructors and assigments to handle literals.
---
mln/literal/all.hh | 9 ++--
mln/literal/colors.hh | 77 ++++++++++++++++++++++++++++++++++++++++
mln/literal/grays.hh | 60 +++++++++++++++++++++++++++++++
mln/value/graylevel.hh | 26 ++++++++++++-
mln/value/rgb.hh | 81 ++++++++++++++++++++++++++++++-------------
tests/literal_medium_gray.cc | 57 ++++++++++++++++++++++++++++++
tests/value_rgb8.cc | 9 +++-
7 files changed, 285 insertions(+), 34 deletions(-)
Index: trunk/milena/tests/value_rgb8.cc
===================================================================
--- trunk/milena/tests/value_rgb8.cc (revision 1333)
+++ trunk/milena/tests/value_rgb8.cc (revision 1334)
@@ -32,7 +32,7 @@
#include <mln/value/rgb8.hh>
-
+#include <mln/literal/all.hh>
int main()
{
@@ -40,6 +40,9 @@
using value::rgb8;
using value::rgb;
+ using literal::blue;
+ using literal::white;
+
{
rgb8 v;
v.red() = 0;
@@ -57,10 +60,10 @@
std::cout << v << std::endl;
mln_assertion(v != w);
- rgb<20> b = rgb<20>::max_blue;
+ rgb<20> b = blue;
std::cout << b << std::endl;
- rgb<20> c = rgb<20>::white;
+ rgb<20> c = white;
std::cout << c << std::endl;
}
Index: trunk/milena/tests/literal_medium_gray.cc
===================================================================
--- trunk/milena/tests/literal_medium_gray.cc (revision 0)
+++ trunk/milena/tests/literal_medium_gray.cc (revision 1334)
@@ -0,0 +1,57 @@
+// 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.
+
+/*! \file tests/literal_medium_gray.cc
+ *
+ * \brief Tests on mln::literal::medium_gray.
+ */
+
+#include <mln/literal/grays.hh>
+#include <mln/value/graylevel.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ using literal::medium_gray;
+ using value::gl8;
+ using value::gl16;
+
+ gl8 a;
+ gl16 b;
+
+ a = medium_gray;
+
+ std::cout << int(a.value()) << std::endl;
+
+ b = a;
+ std::cout << int(b.value()) << std::endl;
+
+ b = medium_gray;
+ std::cout << int(b.value()) << std::endl;
+}
Index: trunk/milena/mln/literal/colors.hh
===================================================================
--- trunk/milena/mln/literal/colors.hh (revision 0)
+++ trunk/milena/mln/literal/colors.hh (revision 1334)
@@ -0,0 +1,77 @@
+// 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 MLN_LITERAL_COLORS_HH
+# define MLN_LITERAL_COLORS_HH
+
+/*! \file mln/literal/colors.hh
+ * \brief Definition of the colors literal.
+ *
+ */
+
+# include <mln/core/concept/literal.hh>
+
+namespace mln
+{
+
+ namespace literal
+ {
+
+ /// Type of literal blue.
+ struct blue_t : public Literal<blue_t>
+ {
+ };
+
+ /// Type of literal red.
+ struct red_t : public Literal<red_t>
+ {
+ };
+
+ /// Type of literal green.
+ struct green_t : public Literal<green_t>
+ {
+ };
+
+
+ /// Literal red.
+ static red_t red = red_t();
+
+ /// Literal green.
+ static green_t green = green_t();
+
+ /// Literal blue.
+ static blue_t blue = blue_t();
+
+ } // end of namespace mln::literal
+
+} // end of namespace mln
+
+// White and black are color too.
+# include <mln/literal/white.hh>
+# include <mln/literal/black.hh>
+
+#endif // ! MLN_LITERAL_COLORS_HH
Index: trunk/milena/mln/literal/grays.hh
===================================================================
--- trunk/milena/mln/literal/grays.hh (revision 0)
+++ trunk/milena/mln/literal/grays.hh (revision 1334)
@@ -0,0 +1,60 @@
+// 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 MLN_LITERAL_GRAYS_HH
+# define MLN_LITERAL_GRAYS_HH
+
+/*! \file mln/literal/grays.hh
+ * \brief Definition of the colors literal.
+ *
+ */
+
+# include <mln/core/concept/literal.hh>
+
+namespace mln
+{
+
+ namespace literal
+ {
+
+ /// Type of literal grays.
+ struct medium_gray_t : public Literal<medium_gray_t>
+ {
+ };
+
+ /// Literal medium_gray.
+ static medium_gray_t medium_gray = medium_gray_t();
+
+ } // end of namespace mln::literal
+
+} // end of namespace mln
+
+// White and black are grays too.
+# include <mln/literal/white.hh>
+# include <mln/literal/black.hh>
+
+#endif // ! MLN_LITERAL_GRAYS_HH
Index: trunk/milena/mln/literal/all.hh
===================================================================
--- trunk/milena/mln/literal/all.hh (revision 1333)
+++ trunk/milena/mln/literal/all.hh (revision 1334)
@@ -47,12 +47,11 @@
# include <mln/literal/origin.hh>
-// FIXME: Add:
-// # include <mln/literal/white.hh>
-// # include <mln/literal/black.hh>
+# include <mln/literal/white.hh>
+# include <mln/literal/black.hh>
-// # include <mln/literal/grays.hh>
-// # include <mln/literal/colors.hh>
+# include <mln/literal/grays.hh>
+# include <mln/literal/colors.hh>
# include <mln/literal/ops.hh>
Index: trunk/milena/mln/value/graylevel.hh
===================================================================
--- trunk/milena/mln/value/graylevel.hh (revision 1333)
+++ trunk/milena/mln/value/graylevel.hh (revision 1334)
@@ -48,8 +48,14 @@
namespace mln
{
- /// Fwd decl.
- namespace literal { struct black_t; struct white_t; }
+ /// \{ Fwd decls.
+ namespace literal
+ {
+ struct black_t;
+ struct medium_gray_t;
+ struct white_t;
+ }
+ /// \}
namespace value
{
@@ -76,6 +82,7 @@
/// \{ Ctors with literals.
graylevel(const literal::black_t&);
+ graylevel(const literal::medium_gray_t&);
graylevel(const literal::white_t&);
/// \}
@@ -93,6 +100,7 @@
/// \{ Assigment with literals.
graylevel<n>& operator=(const literal::white_t&);
+ graylevel<n>& operator=(const literal::medium_gray_t&);
graylevel<n>& operator=(const literal::black_t&);
/// \}
};
@@ -168,6 +176,12 @@
}
template <unsigned n>
+ graylevel<n>::graylevel(const literal::medium_gray_t&)
+ {
+ this->v_ = metal::math::pow_int<2, n - 1>::value;
+ }
+
+ template <unsigned n>
graylevel<n>::graylevel(const literal::white_t&)
{
this->v_ = mln_max(mln_enc(int_u<n>));
@@ -209,6 +223,14 @@
template <unsigned n>
graylevel<n>&
+ graylevel<n>::operator=(const literal::medium_gray_t&)
+ {
+ this->v_ = metal::math::pow_int<2, n - 1>::value;
+ return *this;
+ }
+
+ template <unsigned n>
+ graylevel<n>&
graylevel<n>::operator=(const literal::white_t&)
{
this->v_ = mln_max(mln_enc(int_u<n>));
Index: trunk/milena/mln/value/rgb.hh
===================================================================
--- trunk/milena/mln/value/rgb.hh (revision 1333)
+++ trunk/milena/mln/value/rgb.hh (revision 1334)
@@ -41,6 +41,18 @@
namespace mln
{
+ /// \{ Fwd decls.
+ namespace literal
+ {
+ struct black_t;
+ struct white_t;
+
+ struct red_t;
+ struct blue_t;
+ struct green_t;
+ }
+ /// \}
+
namespace value
{
@@ -80,6 +92,11 @@
rgb<n>(equiv a);
rgb<n>(enc r, enc g, enc b);
rgb<n>(enc l);
+ rgb<n>(const literal::white_t&);
+ rgb<n>(const literal::black_t&);
+ rgb<n>(const literal::blue_t&);
+ rgb<n>(const literal::red_t&);
+ rgb<n>(const literal::green_t&);
/// \}
/// \{ Assignments.
@@ -90,14 +107,6 @@
/// Zero value.
static const rgb<n> zero;
- /// \{ Colors.
- static const rgb<n> black;
- static const rgb<n> max_red;
- static const rgb<n> max_green;
- static const rgb<n> max_blue;
- static const rgb<n> white;
- /// \}
-
/// addition
rgb<n> operator+(const rgb<n>& v) const;
// FIXME: was:
@@ -190,40 +199,64 @@
}
template <unsigned n>
- rgb<n>&
- rgb<n>::operator=(const rgb<n>& v)
+ rgb<n>::rgb(const literal::white_t&)
{
- std::memcpy(this->c_, v.c_, 3 * sizeof(enc));
- return *this;
+ this->c_[0] = mln_max(enc);
+ this->c_[1] = mln_max(enc);
+ this->c_[2] = mln_max(enc);
}
template <unsigned n>
- rgb<n>&
- rgb<n>::operator=(const enc& v)
+ rgb<n>::rgb(const literal::black_t&)
{
- for (int i = 0; i < 3; i++)
- this->c_[i] = v;
- return *this;
+ this->c_[0] = 0;
+ this->c_[1] = 0;
+ this->c_[2] = 0;
}
template <unsigned n>
- const rgb<n> rgb<n>::zero(0,0,0);
+ rgb<n>::rgb(const literal::red_t&)
+ {
+ this->c_[0] = mln_max(enc);
+ this->c_[1] = 0;
+ this->c_[2] = 0;
+ }
template <unsigned n>
- const rgb<n> rgb<n>::black(0,0,0);
+ rgb<n>::rgb(const literal::green_t&)
+ {
+ this->c_[0] = 0;
+ this->c_[1] = mln_max(enc);
+ this->c_[2] = 0;
+ }
template <unsigned n>
- const rgb<n> rgb<n>::max_red(mln_max(enc), 0, 0);
+ rgb<n>::rgb(const literal::blue_t&)
+ {
+ this->c_[0] = 0;
+ this->c_[1] = 0;
+ this->c_[2] = mln_max(enc);
+ }
template <unsigned n>
- const rgb<n> rgb<n>::max_green(0, mln_max(enc), 0);
+ rgb<n>&
+ rgb<n>::operator=(const rgb<n>& v)
+ {
+ std::memcpy(this->c_, v.c_, 3 * sizeof(enc));
+ return *this;
+ }
template <unsigned n>
- const rgb<n> rgb<n>::max_blue(0, 0, mln_max(enc));
+ rgb<n>&
+ rgb<n>::operator=(const enc& v)
+ {
+ for (int i = 0; i < 3; i++)
+ this->c_[i] = v;
+ return *this;
+ }
template <unsigned n>
- const rgb<n> rgb<n>::white(mln_max(enc), mln_max(enc), mln_max(enc));
-
+ const rgb<n> rgb<n>::zero(0,0,0);
template <unsigned n>
rgb<n>
In order to display a temporary image, now display::save function saves
image and with display::show function finds the path of saved image
and dispay it with specified viewer.
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-12 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Change concept of display show.
* mln/display/save.hh: New.
* mln/display/show.hh,
* tests/show.cc: Update.
---
mln/display/save.hh | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++
mln/display/show.hh | 25 ++-----------
tests/show.cc | 8 +++-
3 files changed, 109 insertions(+), 22 deletions(-)
Index: trunk/milena/tests/show.cc
===================================================================
--- trunk/milena/tests/show.cc (revision 1329)
+++ trunk/milena/tests/show.cc (revision 1330)
@@ -40,6 +40,8 @@
# include <mln/core/inplace.hh>
# include <mln/core/w_window2d_int.hh>
# include <mln/display/show.hh>
+# include <mln/display/save.hh>
+# include <mln/display/color_pretty.hh>
# include <mln/io/ppm/save.hh>
@@ -63,5 +65,9 @@
// Call color_pretty for sub_image.
for (unsigned i = 2; i < 22; i += 2)
- display::show (inplace (tmp | i));
+ {
+ image_if_value<image2d<unsigned> > t = inplace (tmp | i);
+ display::save (t);
+ display::show (t, "xv");
+ }
}
Index: trunk/milena/mln/display/save.hh
===================================================================
--- trunk/milena/mln/display/save.hh (revision 0)
+++ trunk/milena/mln/display/save.hh (revision 1330)
@@ -0,0 +1,98 @@
+// 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 MLN_DISPLAY_SAVE_HH
+# define MLN_DISPLAY_SAVE_HH
+
+/*! \file mln/display/save.hh
+ *
+ * \brief Create a pretty image, which display its content
+ * with red value for non-defined point site.
+ */
+
+# include <mln/trait/image_from_mesh.hh>
+# include <mln/core/image_if_value.hh>
+# include <mln/core/image2d.hh>
+# include <mln/value/rgb8.hh>
+# include <mln/level/fill.hh>
+# include <mln/level/paste.hh>
+# include <mln/display/color_pretty.hh>
+# include <mln/io/ppm/save.hh>
+
+namespace mln
+{
+
+ namespace display
+ {
+
+ std::map<void*, std::string> map_saved_image_tmp_;
+
+ template <typename I>
+ void
+ save(const Image<I>& input_);
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+ template <typename I>
+ void
+ save(const Image<I>& input_)
+ {
+ const I& input = exact (input_);
+ image2d<value::rgb8> out = display::color_pretty(input);
+
+ /// Use of mkstemp instead tempmap.
+ char *tmp = (char*)malloc (12 * sizeof (char));
+ strcpy(tmp, "/tmp/XXXXXX");
+ if (mkstemp(tmp) == -1)
+ return;
+ std::string path_tmp = tmp;
+
+ io::ppm::save(out, path_tmp);
+ std::cout << input.id_ () << " = " << path_tmp << std::endl;
+ map_saved_image_tmp_[(void*)input.id_ ()] = path_tmp;
+ }
+
+ } // end of namespace mln::display::impl
+
+ /// Facade.
+ template <typename I>
+ void
+ save(const Image<I>& input_)
+ {
+ return impl::save(input_);
+ }
+
+# endif // !MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::display
+
+} // end of namespace mln
+
+
+#endif // ! MLN_DISPLAY_SAVE_HH
Index: trunk/milena/mln/display/show.hh
===================================================================
--- trunk/milena/mln/display/show.hh (revision 1329)
+++ trunk/milena/mln/display/show.hh (revision 1330)
@@ -37,12 +37,9 @@
# include <mln/trait/image_from_mesh.hh>
# include <mln/core/image_if_value.hh>
# include <mln/core/image2d.hh>
-# include <mln/value/rgb8.hh>
-# include <mln/level/fill.hh>
-# include <mln/level/paste.hh>
-# include <mln/display/color_pretty.hh>
-# include <mln/io/ppm/save.hh>
-# include <mln/core/image2d.hh>
+# include <mln/display/save.hh>
+
+# include <map>
namespace mln
{
@@ -64,22 +61,8 @@
show(const Image<I>& input_, std::string cmd)
{
const I& input = exact (input_);
- image2d<value::rgb8> out = display::color_pretty(input);
-
-// /// Save output image from color in temporary file.
-// std::string path_tmp = tempnam (0, "ppm");
-
- /// Use of mkstemp instead tempmap.
- char *tmp = (char*)malloc (12 * sizeof (char));
- strcpy(tmp, "/tmp/XXXXXX");
- if (mkstemp(tmp) == -1)
- return;
- std::string path_tmp = tmp;
-
- io::ppm::save(out, path_tmp);
-
- std::string s = cmd + " " + path_tmp + " &";
+ std::string s = cmd + " " + map_saved_image_tmp_[(void*)input.id_ ()] + " &";
system (s.c_str ());
}
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-12 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add test for seed2tiling*.hh .
* seed2tiling.cc: New test for seed2tiling*.
---
seed2tiling.cc | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 101 insertions(+)
Index: trunk/milena/tests/seed2tiling.cc
===================================================================
--- trunk/milena/tests/seed2tiling.cc (revision 0)
+++ trunk/milena/tests/seed2tiling.cc (revision 1327)
@@ -0,0 +1,101 @@
+// 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.
+
+/*! \file tests/seeds2tiling.cc
+ *
+ * \brief Test on mln::geom::seed2tiling*.hh.
+ */
+
+
+# include <mln/core/image2d.hh>
+# include <mln/core/sub_image.hh>
+# include <mln/core/neighb2d.hh>
+# include <mln/value/int_u8.hh>
+# include <mln/level/fill.hh>
+# include <mln/level/stretch.hh>
+# include <mln/border/fill.hh>
+# include <mln/io/pbm/load.hh>
+# include <mln/io/pgm/save.hh>
+# include <mln/labeling/foreground.hh>
+# include <mln/debug/println.hh>
+# include <mln/draw/mesh.hh>
+# include <mln/geom/seeds2tiling.hh>
+# include <mln/geom/seeds2tiling_with_chamfer.hh>
+# include <mln/make/voronoi.hh>
+
+#include <mln/core/image2d.hh>
+#include <mln/core/sub_image.hh>
+#include <mln/core/image_if_value.hh>
+#include <mln/core/inplace.hh>
+
+#include <mln/core/w_window2d_int.hh>
+#include <mln/make/win_chamfer.hh>
+
+int main(int argc, char** argv)
+{
+ if (argc < 2)
+ {
+ std::cerr << "missing argument : specify the location of the binary image (*.pbm)" << std::endl;
+ return 1;
+ }
+ using namespace mln;
+ using value::int_u8;
+ unsigned max = 2048;
+
+ image2d<bool> input = io::pbm::load(argv[1]);
+
+ {
+
+ image2d<unsigned> lab(input.domain());
+ image2d<unsigned> inte(input.domain());
+ image2d<int_u8> inte2(input.domain());
+ image2d<int_u8> out(input.domain());
+
+ const w_window2d_int& w_win = win_chamfer::mk_chamfer_3x3_int<2,3> ();
+
+ unsigned n;
+ labeling::foreground(input, c4(), lab, n);
+ std::cout << "number of labels = " << n << std::endl;
+
+
+ inte = geom::seeds2tiling(lab, c4 ());
+ border::fill (inte, 0);
+ level::stretch (inte, inte2);
+ io::pgm::save(inte2, "ima1.pgm");
+
+ std::cout << "ima1 generate with seeds2tiling"
+ << std::endl;
+ inte = geom::seeds2tiling_with_chamfer(lab, w_win, max, c4 ());
+ border::fill (inte, 0);
+ level::stretch (inte, inte2);
+
+ io::pgm::save(inte2, "ima2.pgm");
+ std::cout << "ima2 generate with seeds2tiling_with_chamfer"
+ << std::endl;
+ }
+
+}
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-10-12 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add seeds2tiling with distance priority (chamfer).
* seeds2tiling_with_chamfer.hh: New.
---
seeds2tiling_with_chamfer.hh | 108 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 108 insertions(+)
Index: trunk/milena/mln/geom/seeds2tiling_with_chamfer.hh
===================================================================
--- trunk/milena/mln/geom/seeds2tiling_with_chamfer.hh (revision 0)
+++ trunk/milena/mln/geom/seeds2tiling_with_chamfer.hh (revision 1326)
@@ -0,0 +1,108 @@
+// 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 MLN_GEOM_SEEDS2TILING_WITH_CHAMFER_HH
+# define MLN_GEOM_SEEDS2TILING_WITH_CHAMFER_HH
+
+/*! \file mln/geom/seeds2tiling_with_chamfer.hh
+ *
+ * \brief .
+ */
+
+# include <map>
+
+
+# include <mln/core/queue_p_fast_priority.hh>
+# include <mln/core/clone.hh>
+# include <mln/accu/mean.hh>
+# include <mln/estim/min_max.hh>
+# include <mln/metal/vec.hh>
+# include <mln/geom/chamfer.hh>
+
+
+namespace mln
+{
+ namespace geom
+ {
+
+ template <typename I, typename N>
+ I
+ seeds2tiling_with_chamfer (Image<I>& ima_, const w_window2d_int& w_win, unsigned max,
+ const Neighborhood<N>& nbh);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I, typename N>
+ I
+ seeds2tiling_with_chamfer (Image<I>& ima_, const w_window2d_int& w_win, unsigned max,
+ const Neighborhood<N>& nbh)
+
+ {
+ I& ima = exact(ima_);
+ image2d<unsigned> dist = geom::chamfer(ima, w_win, max);
+ I out = clone(ima_);
+ queue_p_fast_priority<mln_psite(I), unsigned> q;
+
+ // Init.
+ {
+ mln_piter(I) p(ima.domain());
+
+ for_all(p)
+ q.push_force(p, max - dist(p));
+ }
+
+
+ // Body: alternative version.
+ {
+ while (! q.empty())
+ {
+ mln_psite(I) p = q.front();
+ q.pop();
+ if (out(p) != 0) // p has already been processed so ignore
+ continue;
+ mln_niter(N) n(nbh, p);
+
+ for_all(n) if (ima.has(n))
+ if (out(n) != 0)
+ out(p) = out(n);
+ }
+ }
+
+ return out;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::geom
+
+} // end of namespace mln
+
+
+#endif // ! MLN_GEOM_SEEDS2TILING_WITH_CHAMFER_HH