Commit 1fa75d51 authored by Thierry Geraud's avatar Thierry Geraud
Browse files

Clean-up from_to, add some new overloads, and fix (c).

	* milena/tests/core/other/w_window.cc: New.
	* milena/tests/core/other/Makefile.am: Update.
	* milena/tests/core/alias/window2d.cc: Remove echos.
	* milena/mln/make/image2d.hh: New.
	* milena/tests/make/image2d.cc: New.
	* milena/tests/make/Makefile.am: Update.
	* milena/tests/convert/to_image.cc: Fix copyright.
	(include): Remove; useless.
	* milena/mln/core/alias/window2d.hh: Fix include.
	* milena/mln/core/w_window.hh (from_to): New overload.
	* milena/mln/core/dpoint.hh: Fix (c).
	* milena/mln/core/concept/weighted_window.hh: Fix (c).
	* milena/mln/core/concept/object.hh: Include all metal math.
	Include metal converts_to.
	* milena/mln/core/concept/window.hh (from_to): New overload.
	(todo): New.
	* milena/mln/core/concept/image.hh (from_to): New overload.
	* milena/mln/core/concept/gpoint.hh: Fix doc.
	* milena/mln/core/concept/gdpoint.hh (from_to): New overload.
	* milena/mln/core/def/all.hh: New.
	* milena/mln/core/window.hh: Fix copyright.
	* milena/mln/linear/convolve.hh: Fix warning + copyright.
	* milena/mln/make/image.hh (image): New overload for 3D.
	* milena/mln/make/w_window2d.hh: Fix copyright.
	Remove useless include.
	* milena/mln/convert/to_image.hh
	(mln_image_from, helper_dim_, helper_image_from_): Remove.
	Redundant with image_from_grid.
	(to_image): Update and use convert::from_to.
	* milena/mln/convert/from_to.hxx: Layout and update.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008@2752 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent e6db8768
2008-10-31 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Clean-up from_to, add some new overloads, and fix (c).
* milena/tests/core/other/w_window.cc: New.
* milena/tests/core/other/Makefile.am: Update.
* milena/tests/core/alias/window2d.cc: Remove echos.
* milena/mln/make/image2d.hh: New.
* milena/tests/make/image2d.cc: New.
* milena/tests/make/Makefile.am: Update.
* milena/tests/convert/to_image.cc: Fix copyright.
(include): Remove; useless.
* milena/mln/core/alias/window2d.hh: Fix include.
* milena/mln/core/w_window.hh (from_to): New overload.
* milena/mln/core/dpoint.hh: Fix (c).
* milena/mln/core/concept/weighted_window.hh: Fix (c).
* milena/mln/core/concept/object.hh: Include all metal math.
Include metal converts_to.
* milena/mln/core/concept/window.hh (from_to): New overload.
(todo): New.
* milena/mln/core/concept/image.hh (from_to): New overload.
* milena/mln/core/concept/gpoint.hh: Fix doc.
* milena/mln/core/concept/gdpoint.hh (from_to): New overload.
* milena/mln/core/def/all.hh: New.
* milena/mln/core/window.hh: Fix copyright.
* milena/mln/linear/convolve.hh: Fix warning + copyright.
* milena/mln/make/image.hh (image): New overload for 3D.
* milena/mln/make/w_window2d.hh: Fix copyright.
Remove useless include.
* milena/mln/convert/to_image.hh
(mln_image_from, helper_dim_, helper_image_from_): Remove.
Redundant with image_from_grid.
(to_image): Update and use convert::from_to.
* milena/mln/convert/from_to.hxx: Layout and update.
2008-10-31 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Introduce make::image.
......
// Copyright (C) 2008 EPITA Research and Development Laboratory
// 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
......@@ -33,6 +33,9 @@
// All overloaded "convert::from_to" routines have to be declared in
// the present file. It allows for *deferred* use of these routines.
# include <mln/core/def/all.hh>
# include <mln/core/grids.hh>
namespace mln
{
......@@ -40,17 +43,22 @@ namespace mln
// Forward declarations.
template <typename E> struct Gdpoint;
template <typename E> struct Gpoint;
template <typename E> struct Image;
template <typename E> struct Object;
template <typename E> struct Proxy;
template <typename E> struct Image;
template <typename E> struct Site_Set;
template <typename E> struct Weighted_Window;
template <typename E> struct Gpoint;
template <typename E> struct Value;
template <typename E> struct Weighted_Window;
template <typename E> struct Window;
template <typename G, typename C> struct dpoint;
template <typename G, typename C> struct point;
template <typename D, typename W> class w_window;
template <typename D> class neighb;
template <typename D> class window;
template <typename D, typename W> class w_window;
namespace algebra {
template <unsigned n, typename T> class vec;
......@@ -87,16 +95,8 @@ namespace mln
template <typename F, typename T>
void
from_to(const Object<F>&, Object<T>&);
// end of Guard.
// Image -> Site_Set.
template <typename I, typename S>
void
from_to(const Image<I>& from, Site_Set<S>& to);
// Gpoint -> algebra::vec.
template <typename P, unsigned n, typename T>
void
from_to(const Gpoint<P>& from, algebra::vec<n,T>& to);
// algebra::vec -> Gpoint.
template <unsigned n, typename T, typename P>
......@@ -108,11 +108,39 @@ namespace mln
void
from_to(const algebra::vec<3,T>& from, value::rgb<m>& to);
// bool -> rgb.
template <unsigned m>
void
from_to(bool from, value::rgb<m>& to);
// C-array -> Image.
template <typename V, unsigned S, typename I>
void
from_to(const V (&values)[S], Image<I>& to);
// C-array -> w_window
template <typename V, unsigned S, typename D, typename W>
void
from_to(const V (&weight)[S], w_window<D,W>& to);
// C-array -> window2d
template <unsigned S>
void
from_to(const bool (&values)[S], window< dpoint<grid::square, def::coord> >& win);
template <unsigned R, unsigned C>
void
from_to(const bool (&values)[R][C], window< dpoint<grid::square, def::coord> >& win);
// Gdpoint -> point
template <typename D>
void
from_to(const Gdpoint<D>& from, mln_site(D)& to);
// Value -> Value
template <typename F, typename T>
void
......@@ -133,22 +161,28 @@ namespace mln
void
from_to(const Proxy<P>& from, T& to);
// Gpoint -> algebra::vec.
template <typename P, unsigned n, typename T>
void
from_to(const Gpoint<P>& from, algebra::vec<n,T>& to);
// Gpoint -> delta-point
template <typename P>
void
from_to(const Gpoint<P>& from, mln_delta(P)& to);
// Image -> Site_Set.
template <typename I, typename S>
void
from_to(const Image<I>& from, Site_Set<S>& to);
// Image -> w_window
template <typename I, typename D, typename W>
void
from_to(const Image<I>& from, w_window<D,W>& to);
// C-array -> w_window
template <typename V, unsigned S, typename D, typename W>
void
from_to(const V (&weight)[S], w_window<D,W>& to);
// neighb<W> -> W
template <typename W>
......@@ -160,6 +194,18 @@ namespace mln
void
from_to(const W& from, mln::neighb<W>& to);
// Window -> Image
template <typename W, typename I>
void
from_to(const Window<W>& from, Image<I>& to);
// w_window -> Image
template <typename D, typename W, typename I>
void
from_to(const w_window<D,W>& from, Image<I>& to);
} // end of namespace mln::convert
} // end of namespace mln
......
// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE)
// Copyright (C) 2007, 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
......@@ -28,16 +29,11 @@
#ifndef MLN_CONVERT_TO_IMAGE_HH
# define MLN_CONVERT_TO_IMAGE_HH
/*! \file mln/convert/to_image.hh
*
* \brief Conversions to mln::Image.
*
* \todo Remove. Use from_to instead...
*/
/// mln/convert/to_image.hh
///
/// Conversions to mln::Image.
# include <mln/core/image/image1d.hh>
# include <mln/core/image/image2d.hh>
# include <mln/core/image/image3d.hh>
# include <mln/trait/image_from_grid.hh>
# include <mln/core/concept/site_set.hh>
# include <mln/core/concept/window.hh>
......@@ -45,64 +41,16 @@
# include <mln/core/concept/neighborhood.hh>
# include <mln/literal/zero.hh>
# include <mln/convert/to_window.hh>
# include <mln/geom/bbox.hh>
# include <mln/level/fill.hh>
# include <mln/histo/data.hh>
# define mln_image_from(Src, Value) typename mln::image_from_< Src, Value >::ret
namespace mln
{
// FIXME: Move elsewhere.
namespace internal
{
template <typename T>
struct helper_dim_
{
typedef mln_psite(T) P;
enum { value = P::dim };
};
template <unsigned dim, typename V> struct helper_image_from_;
template <typename V>
struct helper_image_from_< 3, V >
{
typedef image3d<V> ret;
};
template <typename V>
struct helper_image_from_< 2, V >
{
typedef image2d<V> ret;
};
template <typename V>
struct helper_image_from_< 1, V >
{
typedef image1d<V> ret;
};
} // end of namespace mln::internal
// FIXME: Doc + move elsewhere!
template <typename T, typename V>
struct image_from_
{
enum { dim = internal::helper_dim_<T>::value };
typedef typename internal::helper_image_from_< dim, V >::ret ret;
};
namespace convert
{
......@@ -110,23 +58,28 @@ namespace mln
/// Convert a point set \p pset into a binary image. Width of the
/// converted image will be pset.bbox + 2 * \p border.
template <typename S>
mln_image_from(S, bool) to_image(const Site_Set<S>& pset, unsigned border = 1);
mln_image_from_grid(mln_site(S)::grid, bool)
to_image(const Site_Set<S>& pset, unsigned border = 1);
/// Convert a window \p win into a binary image.
template <typename W>
mln_image_from(W, bool) to_image(const Window<W>& win);
/// Convert a neighborhood \p nbh into a binary image.
template <typename N>
mln_image_from(N, bool) to_image(const Neighborhood<N>& nbh);
mln_image_from_grid(mln_site(W)::grid, bool)
to_image(const Window<W>& win);
/// Convert a weighted window \p w_win into an image.
template <typename W>
mln_image_from(W, mln_weight(W)) to_image(const Weighted_Window<W>& w_win);
mln_image_from_grid(mln_site(W)::grid, bool)
to_image(const Weighted_Window<W>& w_win);
/// Convert a neighborhood \p nbh into a binary image.
template <typename N>
mln_image_from_grid(mln_site(N)::grid, bool)
to_image(const Neighborhood<N>& nbh);
/// Convert an histo \p h into an image1d<std::size_t>.
template <typename T>
image1d<std::size_t> to_image(const histo::data<T>& h);
image1d<std::size_t>
to_image(const histo::data<T>& h);
......@@ -134,10 +87,12 @@ namespace mln
template <typename S>
inline
mln_image_from(S, bool) to_image(const Site_Set<S>& pset_, unsigned border)
mln_image_from_grid(mln_site(S)::grid, bool)
to_image(const Site_Set<S>& pset_, unsigned border)
{
const S& pset = exact(pset_);
mln_image_from(S, bool) ima(geom::bbox(pset).to_larger(border));
mln_image_from_grid(mln_site(S)::grid, bool) ima;
ima.init_(geom::bbox(pset).to_larger(border));
level::fill(ima, false);
mln_piter(S) p(pset);
for_all(p)
......@@ -147,52 +102,41 @@ namespace mln
template <typename W>
inline
mln_image_from(W, bool) to_image(const Window<W>& win_)
mln_image_from_grid(mln_site(W)::grid, bool)
to_image(const Window<W>& win)
{
const W& win = exact(win_);
mln_precondition(! win.is_empty());
typedef mln_psite(W) P;
box<P> b = geom::bbox(win);
mln_image_from(W, bool) ima(b);
level::fill(ima, false);
P O = P::origin;
mln_qiter(W) q(win, O);
for_all(q)
ima(q) = true;
return ima;
mln_is_simple_window(W)::check();
// mln_precondition(exact(win).is_valid());
mln_image_from_grid(mln_site(W)::grid, bool) tmp;
convert::from_to(win, tmp);
return tmp;
}
template <typename N>
template <typename W>
inline
mln_image_from(N, bool) to_image(const Neighborhood<N>& nbh)
mln_image_from_grid(mln_site(W)::grid, bool)
to_image(const Weighted_Window<W>& w_win)
{
return to_image(convert::to_window(nbh));
mln_is_simple_window(W)::check();
// mln_precondition(exact(w_win).is_valid());
mln_image_from_grid(mln_site(W)::grid, bool) tmp;
convert::from_to(exact(w_win), tmp);
return tmp;
}
template <typename W>
template <typename N>
inline
mln_image_from(W, mln_weight(W)) to_image(const Weighted_Window<W>& w_win_)
mln_image_from_grid(mln_site(N)::grid, bool)
to_image(const Neighborhood<N>& nbh)
{
const W& w_win = exact(w_win_);
mln_precondition(! w_win.is_empty());
typedef mln_psite(W) P;
box<P> b = geom::bbox(w_win);
mln_image_from(W, mln_weight(W)) ima(b);
// Fill the image with zeros, as (weighted) windows are not
// necessarily box-shaped (there might be holes corresponding to
// null weights).
level::fill(ima, literal::zero);
mln_qiter(W) q(w_win, P::origin);
for_all(q)
ima(q) = q.w();
return ima;
// mln_precondition(exact(nbh).is_valid());
return to_image(exact(nbh).win());
}
template <typename T>
inline
image1d<std::size_t> to_image(const histo::data<T>& h)
image1d<std::size_t>
to_image(const histo::data<T>& h)
{
T v_min = h.vset()[0],
v_max = h.vset()[h.vset().nvalues() - 1];
......
// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE)
// Copyright (C) 2007, 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
......@@ -29,7 +30,8 @@
# define MLN_CORE_ALIAS_WINDOW2D_HH
/// \file mln/core/alias/window2d.hh
/// \brief Definition of the mln::window2d alias and of a construction
///
/// Definition of the mln::window2d alias and of a construction
/// routine.
///
/// \todo c8p etc.
......@@ -37,7 +39,7 @@
# include <mln/core/window.hh>
# include <mln/core/alias/dpoint2d.hh>
# include <mln/metal/math/sqrt.hh>
# include <mln/convert/from_to.hh>
# include <mln/convert/from_to.hxx>
namespace mln
......
// Copyright (C) 2007, 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
......@@ -124,6 +125,23 @@ namespace mln
namespace convert
{
template <typename D>
void
from_to(const Gdpoint<D>& from, mln_site(D)& to);
// template <typename D, unsigned n, typename T>
// void
// from_to(const Gdpoint<D>& from, algebra::vec<n,T>& to);
// template <unsigned n, typename T, typename D>
// void
// from_to(const algebra::vec<n,T>& from, Gdpoint<D>& to);
} // end of namespace::convert
# ifndef MLN_INCLUDE_ONLY
......@@ -174,6 +192,23 @@ namespace mln
return tmp;
}
namespace convert
{
template <typename D>
inline
void
from_to(const Gdpoint<D>& dp_, mln_site(D)& p)
{
enum { n = D::dim };
const D& dp = exact(dp_);
for (unsigned i = 0; i < n; ++i)
p[i] = dp[i];
}
} // end of namespace::convert
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
......
// Copyright (C) 2007, 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
......@@ -43,7 +44,7 @@
namespace mln
{
// Fwd decl.
// Forward declaration.
template <typename E> struct Gpoint;
......@@ -308,6 +309,7 @@ namespace mln
// Gpoint -> algebra::vec.
template <typename P, unsigned n, typename T>
inline
void
from_to(const Gpoint<P>& from_, algebra::vec<n,T>& to)
{
......
// Copyright (C) 2007, 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
......@@ -28,15 +29,17 @@
#ifndef MLN_CORE_CONCEPT_IMAGE_HH
# define MLN_CORE_CONCEPT_IMAGE_HH
/*! \file mln/core/concept/image.hh
* \brief Definition of the concept of mln::Image.
*/
/// \file mln/core/concept/image.hh
///
/// Definition of the concept of mln::Image.
# include <mln/core/concept/site_set.hh>
# include <mln/core/concept/mesh.hh>
# include <mln/core/trait/all.hh> // FIXME: Move out of core!
# include <mln/core/macros.hh>
# include <mln/core/site_set/box.hh>
# include <mln/trait/concrete.hh> // FIXME: Should be in all.hh!
# include <mln/trait/images.hh>
......@@ -109,6 +112,18 @@ namespace mln
};
namespace convert
{
template <typename V, unsigned S, typename I>
void
from_to(const V (&values)[S], Image<I>& to);
} // end of namespace mln::convert
# ifndef MLN_INCLUDE_ONLY
......@@ -224,10 +239,40 @@ namespace mln
E>::run();
}
namespace convert
{
template <typename V, unsigned S, typename I>
void
from_to(const V (&values)[S], Image<I>& to_)
{
mlc_bool(S != 0)::check();
mlc_converts_to(V, mln_value(I))::check();
typedef mln_site(I) P;
enum { d = P::dim,
s = mlc_root(d,S)::value / 2 };
metal::bool_<(mlc_pow_int(2 * s + 1, d) == S)>::check();
I& to = exact(to_);
mln_precondition(! to.has_data());
box<P> b(all_to(0), all_to(2 * s));
to.init_(b);
mln_fwd_piter(box<P>) p(b);
unsigned i = 0;
for_all(p)
to(p) = values[i++];
}
} // end of namespace mln::convert
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
# include <mln/core/routine/initialize.hh>
#endif // ! MLN_CORE_CONCEPT_IMAGE_HH
// Copyright (C) 2007, 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
......@@ -46,8 +47,10 @@
# include <mln/metal/is_a.hh>
# include <mln/metal/is.hh>
# include <mln/metal/is_not.hh>
# include <mln/metal/converts_to.hh>
# include <mln/metal/ret.hh>
# include <mln/metal/unqualif.hh>
# include <mln/metal/math/all.hh>
/*! \mainpage Documentation of milena
......
// Copyright (C) 2007, 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
......
// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
// (LRDE)