Commit 81025ad4 authored by Thierry Geraud's avatar Thierry Geraud
Browse files

Introduce make::image.

	When there is no ambiguity, the user can call make::image.
	
	* milena/mln/make/image2d.hh: Rename as...
	* milena/mln/make/image.hh: ...this.
	Import code from...
	* milena/mln/make/image1d.hh: ...this removed file.
	* milena/mln/make/all.hh: Update.
	* milena/tests/debug/iota.cc,
	* milena/tests/draw/graph.cc,
	* milena/tests/level/abs.cc,
	* milena/tests/level/replace.cc,
	* milena/tests/level/stretch.cc,
	* milena/tests/level/apply.cc,
	* milena/tests/level/compare.cc,
	* milena/tests/level/saturate.cc,
	* milena/tests/arith/minus.cc,
	* milena/tests/arith/times.cc,
	* milena/tests/arith/plus.cc,
	* milena/tests/arith/revert.cc,
	* milena/tests/accu/compute.cc,
	* milena/tests/geom/resize.cc,
	* milena/tests/geom/seed2tiling_roundness.cc,
	* milena/tests/geom/seed2tiling.cc,
	* milena/tests/display/color_pretty.cc,
	* milena/tests/logical/or.cc,
	* milena/tests/logical/not.cc,
	* milena/tests/logical/and_not.cc,
	* milena/tests/logical/and.cc,
	* milena/tests/canvas/chamfer.cc,
	* milena/tests/util/tree_to_image.cc,
	* milena/tests/util/lemmings.cc,
	* milena/tests/util/tree_fast_to_image.cc,
	* milena/tests/labeling/compute.cc,
	* milena/mln/core/image/image1d.hh: Update.
	* milena/mln/core/image/image2d.hh: Update.
	(todo): New.
	* milena/mln/core/w_window.hh (from_to): New overload.
	* milena/mln/make/w_window2d.hh: Change tests into checks.
	* milena/mln/convert/from_to.hxx: Update.
	* milena/mln/canvas/browsing/directional.hh: .
	* milena/tests/core/alias/w_window2d_int.cc: Add alt code.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008@2748 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent ab64c53a
2008-10-31 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Introduce make::image.
When there is no ambiguity, the user can call make::image.
* milena/mln/make/image2d.hh: Rename as...
* milena/mln/make/image.hh: ...this.
Import code from...
* milena/mln/make/image1d.hh: ...this removed file.
* milena/mln/make/all.hh: Update.
* milena/tests/debug/iota.cc,
* milena/tests/draw/graph.cc,
* milena/tests/level/abs.cc,
* milena/tests/level/replace.cc,
* milena/tests/level/stretch.cc,
* milena/tests/level/apply.cc,
* milena/tests/level/compare.cc,
* milena/tests/level/saturate.cc,
* milena/tests/arith/minus.cc,
* milena/tests/arith/times.cc,
* milena/tests/arith/plus.cc,
* milena/tests/arith/revert.cc,
* milena/tests/accu/compute.cc,
* milena/tests/geom/resize.cc,
* milena/tests/geom/seed2tiling_roundness.cc,
* milena/tests/geom/seed2tiling.cc,
* milena/tests/display/color_pretty.cc,
* milena/tests/logical/or.cc,
* milena/tests/logical/not.cc,
* milena/tests/logical/and_not.cc,
* milena/tests/logical/and.cc,
* milena/tests/canvas/chamfer.cc,
* milena/tests/util/tree_to_image.cc,
* milena/tests/util/lemmings.cc,
* milena/tests/util/tree_fast_to_image.cc,
* milena/tests/labeling/compute.cc,
* milena/mln/core/image/image1d.hh: Update.
* milena/mln/core/image/image2d.hh: Update.
(todo): New.
* milena/mln/core/w_window.hh (from_to): New overload.
* milena/mln/make/w_window2d.hh: Change tests into checks.
* milena/mln/convert/from_to.hxx: Update.
* milena/mln/canvas/browsing/directional.hh: .
* milena/tests/core/alias/w_window2d_int.cc: Add alt code.
2008-10-30 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Add a generic discrete distance transform.
......
// Copyright (C) 2007 EPITA Research and Development Laboratory
// 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
......@@ -105,7 +105,6 @@ namespace mln
void
directional_t::operator()(F& f) const
{
trace::entering("canvas::browsing::directional");
mln_precondition(f.dir < f.dim);
typedef typename F::I I;
......@@ -115,9 +114,7 @@ namespace mln
f.p = pmin;
trace::entering("canvas::browsing::directional::init");
f.init();
trace::exiting("canvas::browsing::directional::init");
do
{
......@@ -147,10 +144,7 @@ namespace mln
} while (f.p != pmin);
trace::entering("canvas::browsing::directional::final");
f.final();
trace::exiting("canvas::browsing::directional::final");
trace::exiting("canvas::browsing::directional");
}
# endif // ! MLN_INCLUDE_ONLY
......
......@@ -138,11 +138,18 @@ namespace mln
void
from_to(const Gpoint<P>& from, mln_delta(P)& 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>
void
......
// 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
......@@ -600,6 +601,6 @@ namespace mln
} // end of namespace mln
# include <mln/make/image1d.hh>
# include <mln/make/image.hh>
#endif // ! MLN_CORE_IMAGE_IMAGE1D_HH
......@@ -31,6 +31,8 @@
/// \file mln/core/image/image2d.hh
/// \brief Definition of the basic mln::image2d class.
///
/// \todo Re-activate include at EOF when make::image2d is up again.
# include <mln/core/internal/image_primary.hh>
# include <mln/core/internal/fixme.hh>
......@@ -687,6 +689,9 @@ namespace mln
} // end of namespace mln
# include <mln/make/image2d.hh>
# include <mln/make/image.hh>
// # include <mln/make/image2d.hh>
#endif // ! MLN_CORE_IMAGE_IMAGE2D_HH
......@@ -37,12 +37,14 @@
# include <mln/core/concept/weighted_window.hh>
# include <mln/core/concept/image.hh>
# include <mln/core/site_set/box.hh>
# include <mln/core/window.hh>
# include <mln/core/dpsites_piter.hh>
# include <mln/value/ops.hh>
# include <mln/util/ord.hh>
# include <mln/metal/converts_to.hh>
# include <mln/metal/math/root.hh>
# include <mln/literal/zero.hh>
# include <mln/convert/to.hh>
......@@ -150,7 +152,7 @@ namespace mln
template <typename V, unsigned S, typename D, typename W>
void
from_to(const V (&values)[S], w_window<D,W>& to);
from_to(const V (&weight)[S], w_window<D,W>& to);
} // end of namespace mln::convert
......@@ -343,18 +345,26 @@ namespace mln
to.insert(ima(p), convert::to<D>(p));
}
// template <typename V, unsigned S, typename D, typename W>
// void
// from_to(const V (&values)[S], w_window<D,W>& to)
// {
// enum { d = D::dim,
// s = mlc_root(d,S)::value / 2 };
// metal::bool_<(mlc_pow_int(2 * s + 1, d) == S)>::check();
// to.clear();
// D dp;
// dp.set_all(-s);
// FIXME
// }
template <typename V, unsigned S, typename D, typename W>
void
from_to(const V (&weight)[S], w_window<D,W>& to)
{
mlc_converts_to(V, W)::check();
enum { d = D::dim,
s = mlc_root(d,S)::value / 2 };
metal::bool_<(mlc_pow_int(2 * s + 1, d) == S)>::check();
to.clear();
typedef mln_site(D) P;
box<P> b(all_to(-s), all_to(+s));
mln_fwd_piter(box<P>) p(b);
unsigned i = 0;
for_all(p)
{
if (weight[i] != literal::zero)
to.insert(weight[i], convert::to<D>(p));
++i;
}
}
} // end of namespace mln::convert
......
// 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
......@@ -47,6 +48,7 @@ namespace mln
# include <mln/make/box2d_h.hh>
# include <mln/make/box3d.hh>
# include <mln/make/dpoint2d_h.hh>
# include <mln/make/image.hh>
# include <mln/make/mat.hh>
# include <mln/make/pixel.hh>
# include <mln/make/pix.hh>
......
// Copyright (C) 2007 EPITA Research and Development Laboratory
// 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
......@@ -25,14 +26,15 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
#ifndef MLN_MAKE_IMAGE2D_HH
# define MLN_MAKE_IMAGE2D_HH
#ifndef MLN_MAKE_IMAGE_HH
# define MLN_MAKE_IMAGE_HH
/*! \file mln/make/image2d.hh
/*! \file mln/make/image.hh
*
* \brief Routine to create an mln::image2d in the 2D case.
* \brief Routine to create an image from various input.
*/
# include <mln/core/image/image1d.hh>
# include <mln/core/image/image2d.hh>
......@@ -42,6 +44,16 @@ namespace mln
namespace make
{
/*! \brief Create an image1d from an 1d array of values.
*
* \param[in] values 1d array.
*
* \return A 1D image.
*/
template <typename V, unsigned L>
mln::image1d<V> image1d(V (&values)[L]);
/*! \brief Create an image2d from an 2d array of values.
*
* \param[in] values 2d array.
......@@ -49,15 +61,25 @@ namespace mln
* \return A 2D image.
*/
template <typename V, unsigned R, unsigned C>
mln::image2d<V> image2d(V (&values)[R][C]);
mln::image2d<V> image(V (&values)[R][C]);
# ifndef MLN_INCLUDE_ONLY
template <typename V, unsigned L>
mln::image1d<V>
image1d(V (&values)[L])
{
mlc_bool(L != 0)::check();
mln::image1d<V> tmp(L);
for (unsigned ind = 0; ind < L; ++ind)
tmp(point1d(ind)) = values[ind];
return tmp;
}
template <typename V, unsigned R, unsigned C>
inline
mln::image2d<V>
image2d(V (&values)[R][C])
image(V (&values)[R][C])
{
mln::image2d<V> tmp(R, C);
for (unsigned row = 0; row < R; ++row)
......@@ -73,4 +95,4 @@ namespace mln
} // end of namespace mln
#endif // ! MLN_MAKE_IMAGE2D_HH
#endif // ! MLN_MAKE_IMAGE_HH
// 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_MAKE_IMAGE1D_HH
# define MLN_MAKE_IMAGE1D_HH
/*! \file mln/make/image1d.hh
*
* \brief Routine to create an mln::image1d.
*/
# include <mln/core/image/image1d.hh>
namespace mln
{
namespace make
{
/*! \brief Create an image1d from an 1d array of values.
*
* \param[in] values 1d array.
*
* \return A 1D image.
*/
template <typename V, unsigned L>
mln::image1d<V> image1d(V (&values)[L]);
# ifndef MLN_INCLUDE_ONLY
template <typename V, unsigned L>
inline
mln::image1d<V>
image1d(V (&values)[L])
{
mln::image1d<V> tmp(L);
for (unsigned ind = 0; ind < L; ++ind)
tmp(point1d(ind)) = values[ind];
return tmp;
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::make
} // end of namespace mln
#endif // ! MLN_MAKE_IMAGE1D_HH
// Copyright (C) 2007 EPITA Research and Development Laboratory
// 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
......@@ -33,10 +33,9 @@
* \brief Routine to create an mln::w_window in the 2D case.
*/
# include <cmath>
# include <mln/core/w_window.hh>
# include <mln/core/alias/dpoint2d.hh>
# include <mln/metal/math/sqrt.hh>
namespace mln
......@@ -49,32 +48,25 @@ namespace mln
*
* \param[in] weights Array.
*
* \pre The array size, \c M, has to be a square of an odd integer.
* \pre The array size, \c S, has to be a square of an odd integer.
*
* \return A 2D weighted window.
*/
template <typename W, unsigned M>
mln::w_window<mln::dpoint2d, W> w_window2d(W (&weights)[M]);
template <typename W, unsigned S>
mln::w_window<mln::dpoint2d, W> w_window2d(W (&weights)[S]);
# ifndef MLN_INCLUDE_ONLY
template <typename W, unsigned M>
template <typename W, unsigned S>
inline
mln::w_window<mln::dpoint2d, W>
w_window2d(W (&weights)[M])
w_window2d(W (&weights)[S])
{
int h = unsigned(std::sqrt(float(M))) / 2;
mln_precondition((2 * h + 1) * (2 * h + 1) == M);
enum { s = mlc_sqrt_int(S) / 2 };
metal::bool_<(((2 * s + 1) * (2 * s + 1)) == S)>::check();
mln::w_window<mln::dpoint2d, W> tmp;
unsigned i = 0;
for (int row = - h; row <= h; ++row)
for (int col = - h; col <= h; ++col)
{
if (weights[i] != 0)
tmp.insert(weights[i], dpoint2d(row, col));
i++;
}
convert::from_to(weights, tmp);
return tmp;
}
......
......@@ -48,7 +48,7 @@ int main()
// {6,5,4},
// {3,2,1} };
// image2d<int_u8> ima = make::image2d(vs);
// image2d<int_u8> ima = make::image(vs);
// int a = accu::compute<accu::min>(ima);
// std::cout << a << std::endl;
......
......@@ -51,7 +51,7 @@ int main()
{6, 7, 8}
};
image2d<int> ref(make::image2d(vs));
image2d<int> ref(make::image(vs));
mln_assertion (ima - 1 == ref);
}
......
......@@ -52,7 +52,7 @@ int main()
};
ima += 2;
image2d<int> ref(make::image2d(vs));
image2d<int> ref(make::image(vs));
mln_assertion (ima + 1 == ref);
}
......
......@@ -52,7 +52,7 @@ int main()
{ -8, -9, -10}
};
image2d<int> ref(make::image2d(vs));
image2d<int> ref(make::image(vs));
arith::revert_inplace(ima);
mln_assertion (ima == ref);
......
......@@ -51,7 +51,7 @@ int main()
{14, 16, 18}
};
image2d<int> ref(make::image2d(vs));
image2d<int> ref(make::image(vs));
mln_assertion (ima * 2 == ref);
}
......
......@@ -69,7 +69,7 @@ int main()
{16, 14, 12, 10, 8, 10, 12, 14, 16}
};
image2d<unsigned> ref (make::image2d(r));
image2d<unsigned> ref (make::image(r));
mln_assertion (out == ref);
}
......@@ -92,7 +92,7 @@ int main()
{12, 11, 10, 9, 8, 9, 10, 11, 12}
};
image2d<unsigned> ref (make::image2d(r));
image2d<unsigned> ref (make::image(r));
mln_assertion (out == ref);
}
......@@ -118,7 +118,7 @@ int main()
{12, 10, 9, 8, 8, 8, 9, 10, 12}
};
image2d<unsigned> ref (make::image2d(r));
image2d<unsigned> ref (make::image(r));
mln_assertion (out == ref);
}
......
......@@ -56,6 +56,10 @@ int main()
-1, 0, 1 };
w_window2d_int w_win = make::w_window2d(ws);
// w_window2d_int w_win;
// convert::from_to(ws, w_win);
// std::cout << w_win << std::endl;
image2d<int> ima = convert::to_image(w_win);
w_window2d_int w_win_2 = convert::to<w_window2d_int>(ima);
mln_assertion(w_win_2 == w_win);
......
......@@ -48,7 +48,7 @@ int main()
{9, 10,11,12},
{13,14,15,16} };
image2d<int> ref = make::image2d(vs);
image2d<int> ref = make::image(vs);
image2d<int> ima(4, 4);
debug::iota(ima);
......
......@@ -63,7 +63,7 @@ int main()
{value::rgb8(255, 0, 0), value::rgb8(51, 51, 51)}
};
image2d<value::rgb8> ref (make::image2d(vs));
image2d<value::rgb8> ref (make::image(vs));
mln_assertion (ref == out);
}
......@@ -87,7 +87,7 @@ int main()
{value::rgb8(0, 0, 255), value::rgb8(0, 0, 0)}
};
image2d<value::rgb8> ref (make::image2d(vs));
image2d<value::rgb8> ref (make::image(vs));
mln_assertion (ref == out);
}
}
......@@ -90,7 +90,7 @@ main ()
{0, 1, 0},
{0, 0, 2}
};
image2d<int> ref (make::image2d(vs));
image2d<int> ref (make::image(vs));
// Points associated to nodes.
points_type points;
......@@ -117,7 +117,7 @@ main ()
{0, 0, 0, 1, 1},
{0, 0, 0, 2, 2},
};
image2d<int> ref (make::image2d(vs));
image2d<int> ref (make::image(vs));
// Points associated to nodes.
points_type points;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment