Commit 4bfd663c authored by Guillaume Lazzara's avatar Guillaume Lazzara
Browse files

Small fixes.

	* mln/accu/count_value.hh: Fix doc.

	* mln/convert/from_to.hxx,
	* mln/value/int_u.hh,
	* mln/value/qt/rgb32.hhL: Add new from_to overloads.

	* mln/convert/to_qimage.hh: Add a missing include.

	* mln/convert/to_qimage_nocopy.hh: Rename an overload.

	* mln/core/concept/function.hh: Add new concept n2v.

	* mln/geom/rotate.hh: rename center() to pcenter().

	* mln/histo/compute.hh: Fix a namespace ambiguity.

	* mln/io/magick/save.hh: Handle qt::rgb32.

	* mln/io/plot/save.hh: Add an overload for histograms.

	* mln/labeling/relabel.hh: Make 'nlabels' const.

	* mln/topo/skeleton/crest.hh: Fix a bug.

	* tests/core/other/box_runstart_piter.cc: Write a valid test.
parent ce6a4248
2010-03-11 Guillaume Lazzara <z@lrde.epita.fr>
Small fixes.
* mln/accu/count_value.hh: Fix doc.
* mln/convert/from_to.hxx,
* mln/value/int_u.hh,
* mln/value/qt/rgb32.hhL: Add new from_to overloads.
* mln/convert/to_qimage.hh: Add a missing include.
* mln/convert/to_qimage_nocopy.hh: Rename an overload.
* mln/core/concept/function.hh: Add new concept n2v.
* mln/geom/rotate.hh: rename center() to pcenter().
* mln/histo/compute.hh: Fix a namespace ambiguity.
* mln/io/magick/save.hh: Handle qt::rgb32.
* mln/io/plot/save.hh: Add an overload for histograms.
* mln/labeling/relabel.hh: Make 'nlabels' const.
* mln/topo/skeleton/crest.hh: Fix a bug.
* tests/core/other/box_runstart_piter.cc: Write a valid test.
2010-03-11 Guillaume Lazzara <z@lrde.epita.fr> 2010-03-11 Guillaume Lazzara <z@lrde.epita.fr>
   
* mln/draw/dashed_line.hh: New draw line routine. * mln/draw/dashed_line.hh: New draw line routine.
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
/// \file /// \file
/// ///
/// Define an accumulator that counts the number of different value. /// \brief Define an accumulator that counts the occurrence of a given value.
# include <mln/accu/internal/base.hh> # include <mln/accu/internal/base.hh>
# include <mln/core/concept/meta_accumulator.hh> # include <mln/core/concept/meta_accumulator.hh>
...@@ -40,7 +40,7 @@ namespace mln ...@@ -40,7 +40,7 @@ namespace mln
namespace accu namespace accu
{ {
/// \brief Count a given value. /// \brief Define an accumulator that counts the occurrence of a given value.
/// ///
/// \ingroup modaccuvalues /// \ingroup modaccuvalues
// //
......
...@@ -163,9 +163,14 @@ namespace mln ...@@ -163,9 +163,14 @@ namespace mln
void void
from_to_(bool from, value::rgb<m>& to); from_to_(bool from, value::rgb<m>& to);
// rgb32 -> bool
void void
from_to_(const value::qt::rgb32& from, bool& to); from_to_(const value::qt::rgb32& from, bool& to);
// bool -> rgb32
void
from_to_(const bool& from, value::qt::rgb32& to);
// int_u -> rgb. // int_u -> rgb.
template <unsigned m> template <unsigned m>
void from_to_(const value::int_u<m>& from, value::rgb<m>& to); void from_to_(const value::int_u<m>& from, value::rgb<m>& to);
...@@ -182,6 +187,11 @@ namespace mln ...@@ -182,6 +187,11 @@ namespace mln
template <unsigned n> template <unsigned n>
void from_to_(const value::int_u<n>& from, unsigned& to_); void from_to_(const value::int_u<n>& from, unsigned& to_);
// int_u -> bool.
template <unsigned n>
void
from_to_(const value::int_u<n>& from, bool& to_);
// label -> int_u. // label -> int_u.
template <unsigned n> template <unsigned n>
void void
......
...@@ -41,6 +41,8 @@ ...@@ -41,6 +41,8 @@
# include <mln/value/qt/rgb32.hh> # include <mln/value/qt/rgb32.hh>
# include <mln/value/rgb8.hh> # include <mln/value/rgb8.hh>
// FIXME: not generic.
# include <mln/core/alias/dpoint2d.hh>
# if QT_VERSION < 0x040000 # if QT_VERSION < 0x040000
# error "Your version of Qt is too old and is not supported." # error "Your version of Qt is too old and is not supported."
......
...@@ -121,7 +121,7 @@ namespace mln ...@@ -121,7 +121,7 @@ namespace mln
template <typename I> template <typename I>
inline inline
QImage to_qimage_nocopy_nocopy(const Image<I>& ima_) QImage to_qimage_nocopy(const Image<I>& ima_)
{ {
const I& ima = exact(ima_); const I& ima = exact(ima_);
mln_precondition(ima.is_valid()); mln_precondition(ima.is_valid());
......
...@@ -38,6 +38,7 @@ namespace mln ...@@ -38,6 +38,7 @@ namespace mln
// Forward declarations. // Forward declarations.
template <typename E> struct Function; template <typename E> struct Function;
template <typename E> struct Function_n2v;
template <typename E> struct Function_v2v; template <typename E> struct Function_v2v;
template <typename E> struct Function_v2b; template <typename E> struct Function_v2b;
template <typename E> struct Function_vv2v; template <typename E> struct Function_vv2v;
...@@ -72,6 +73,31 @@ namespace mln ...@@ -72,6 +73,31 @@ namespace mln
}; };
/*---------------.
| Nil -> Value. |
`---------------*/
template <>
struct Function_n2v<void> { typedef Function<void> super; };
/// \brief Base class for implementation of function-objects from
/// Nil to value.
///
/// The parameter \a E is the exact type.
///
/// \ingroup modfun
//
template <typename E>
struct Function_n2v : public Function<E>
{
typedef Function_n2v<void> category;
protected:
Function_n2v();
Function_n2v(const Function_n2v&);
};
/*-----------------. /*-----------------.
| Value -> Value. | | Value -> Value. |
`-----------------*/ `-----------------*/
...@@ -195,6 +221,23 @@ namespace mln ...@@ -195,6 +221,23 @@ namespace mln
{ {
} }
// Function_n2v.
template <typename E>
inline
Function_n2v<E>::Function_n2v()
{
}
template <typename E>
inline
Function_n2v<E>::Function_n2v(const Function_n2v<E>& rhs)
: Function<E>(rhs)
{
}
// Function_v2v. // Function_v2v.
template <typename E> template <typename E>
......
// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) // Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
// (LRDE)
// //
// This file is part of Olena. // This file is part of Olena.
// //
...@@ -115,7 +116,7 @@ namespace mln ...@@ -115,7 +116,7 @@ namespace mln
mlc_is_a(S,Box)::check(); mlc_is_a(S,Box)::check();
// FIXME: A precondition is probably missing for the extension value. // FIXME: A precondition is probably missing for the extension value.
mln_site(I) c = geom::bbox(input).center(); mln_site(I) c = geom::bbox(input).pcenter();
typedef fun::x2x::translation<2,double> trans_t; typedef fun::x2x::translation<2,double> trans_t;
trans_t trans_t
t(-1 * c.to_vec()), t(-1 * c.to_vec()),
......
// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE) // Copyright (C) 2007, 2008, 2009, 2010 EPITA Research and Development
// Laboratory (LRDE)
// //
// This file is part of Olena. // This file is part of Olena.
// //
...@@ -46,7 +47,7 @@ namespace mln ...@@ -46,7 +47,7 @@ namespace mln
/// Compute the histogram of image \p input. /// Compute the histogram of image \p input.
template <typename I> template <typename I>
array<mln_value(I)> compute(const Image<I>& input); histo::array<mln_value(I)> compute(const Image<I>& input);
# ifndef MLN_INCLUDE_ONLY # ifndef MLN_INCLUDE_ONLY
...@@ -59,9 +60,9 @@ namespace mln ...@@ -59,9 +60,9 @@ namespace mln
template <typename I> template <typename I>
inline inline
array<mln_value(I)> compute_(const I& input) histo::array<mln_value(I)> compute_(const I& input)
{ {
array<mln_value(I)> h; histo::array<mln_value(I)> h;
mln_piter(I) p(input.domain()); mln_piter(I) p(input.domain());
for_all(p) for_all(p)
++h(input(p)); ++h(input(p));
...@@ -75,14 +76,14 @@ namespace mln ...@@ -75,14 +76,14 @@ namespace mln
template <typename I> template <typename I>
inline inline
array<mln_value(I)> compute(const Image<I>& input) histo::array<mln_value(I)> compute(const Image<I>& input)
{ {
trace::entering("histo::compute"); trace::entering("histo::compute");
mlc_equal(mln_trait_image_quant(I), mln::trait::image::quant::low)::check(); mlc_equal(mln_trait_image_quant(I), mln::trait::image::quant::low)::check();
mln_precondition(exact(input).is_valid()); mln_precondition(exact(input).is_valid());
array<mln_value(I)> h = impl::compute_(mln_trait_image_speed(I)(), histo::array<mln_value(I)> h = impl::compute_(mln_trait_image_speed(I)(),
exact(input)); exact(input));
trace::exiting("histo::compute"); trace::exiting("histo::compute");
return h; return h;
......
// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) // Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
// (LRDE)
// //
// This file is part of Olena. // This file is part of Olena.
// //
...@@ -37,6 +38,7 @@ ...@@ -37,6 +38,7 @@
# include <mln/metal/equal.hh> # include <mln/metal/equal.hh>
# include <mln/value/int_u8.hh> # include <mln/value/int_u8.hh>
# include <mln/value/rgb8.hh> # include <mln/value/rgb8.hh>
# include <mln/value/qt/rgb32.hh>
# include <Magick++.h> # include <Magick++.h>
...@@ -90,6 +92,14 @@ namespace mln ...@@ -90,6 +92,14 @@ namespace mln
256 - value.blue()); 256 - value.blue());
} }
inline
Magick::Color get_color(const value::qt::rgb32& value)
{
return Magick::ColorRGB(256 - value.red(),
256 - value.green(),
256 - value.blue());
}
template <typename I> template <typename I>
inline inline
void save(const Image<I>& ima_, const std::string& filename) void save(const Image<I>& ima_, const std::string& filename)
...@@ -100,7 +110,8 @@ namespace mln ...@@ -100,7 +110,8 @@ namespace mln
const I& ima = exact(ima_); const I& ima = exact(ima_);
if (!(mln::metal::equal<mln_value(I), bool>::value || if (!(mln::metal::equal<mln_value(I), bool>::value ||
mln::metal::equal<mln_value(I), value::int_u8>::value || mln::metal::equal<mln_value(I), value::int_u8>::value ||
mln::metal::equal<mln_value(I), value::rgb8>::value)) mln::metal::equal<mln_value(I), value::rgb8>::value ||
mln::metal::equal<mln_value(I), value::qt::rgb32>::value))
{ {
std::cerr << "error: trying to save an unsupported format" << std::endl; std::cerr << "error: trying to save an unsupported format" << std::endl;
std::cerr << "supported formats: binary, 8bits grayscale (int_u8), 8bits truecolor (rgb8)" << std::endl; std::cerr << "supported formats: binary, 8bits grayscale (int_u8), 8bits truecolor (rgb8)" << std::endl;
...@@ -112,11 +123,13 @@ namespace mln ...@@ -112,11 +123,13 @@ namespace mln
Magick::PixelPacket* pixel_cache = im_file.getPixels(0, 0, ima.nrows(), ima.ncols()); Magick::PixelPacket* pixel_cache = im_file.getPixels(0, 0, ima.nrows(), ima.ncols());
Magick::PixelPacket* pixel; Magick::PixelPacket* pixel;
mln_site(I) pmin = ima.domain().pmin();
mln_piter(I) p(ima.domain()); mln_piter(I) p(ima.domain());
for_all(p) for_all(p)
{ {
pixel = pixel_cache + (int) p.to_site().to_vec()[0] * ima.ncols() pixel = pixel_cache + (int) (p.to_site().to_vec()[0] - pmin.to_vec()[0]) * ima.ncols()
+ (int) p.to_site().to_vec()[1]; + (int) (p.to_site().to_vec()[1] - pmin.to_vec()[1]);
*pixel = get_color(ima(p)); *pixel = get_color(ima(p));
} }
im_file.syncPixels(); im_file.syncPixels();
......
...@@ -50,8 +50,7 @@ namespace mln ...@@ -50,8 +50,7 @@ namespace mln
\param[in] ima A reference to the image to save. \param[in] ima A reference to the image to save.
\param[out] filename The output file. */ \param[out] filename The output file. */
template <typename I> template <typename I>
void save(const image1d<I>& ima, void save(const image1d<I>& ima, const std::string& filename);
const std::string& filename);
/*! \brief Save a Milena array in a plot file. /*! \brief Save a Milena array in a plot file.
\param[in] arr A reference to the array to save. \param[in] arr A reference to the array to save.
...@@ -59,10 +58,13 @@ namespace mln ...@@ -59,10 +58,13 @@ namespace mln
\param[in] start_value The start index value of the plot \param[in] start_value The start index value of the plot
(optional). */ (optional). */
template <typename T> template <typename T>
void save(util::array<T>& arr, void save(util::array<T>& arr, const std::string& filename,
const std::string& filename,
int start_value); int start_value);
/// \overload
template <typename T>
inline
void save(const histo::array<T>& arr, const std::string& filename);
# ifndef MLN_INCLUDE_ONLY # ifndef MLN_INCLUDE_ONLY
...@@ -97,6 +99,19 @@ namespace mln ...@@ -97,6 +99,19 @@ namespace mln
trace::exiting("mln::io::plot::save"); trace::exiting("mln::io::plot::save");
} }
template <typename T>
inline
void save(const histo::array<T>& arr, const std::string& filename)
{
trace::entering("mln::io::plot::save");
std::ofstream file_out(filename.c_str());
for (unsigned i = 0; i < arr.nvalues(); ++i)
file_out << i << " " << arr[i] << std::endl;
trace::exiting("mln::io::plot::save");
}
# endif // ! MLN_INCLUDE_ONLY # endif // ! MLN_INCLUDE_ONLY
......
...@@ -83,27 +83,27 @@ namespace mln ...@@ -83,27 +83,27 @@ namespace mln
/// Remove components and relabel a labeled image inplace. /// Remove components and relabel a labeled image inplace.
/// \param[in, out] label the labeled image. /// \param[in, out] label the labeled image.
/// \param[in, out] nlabels the number of labels in \p label. /// \param[in] nlabels the number of labels in \p label.
/// \param[in] fv2b function returning whether a label must be replaced /// \param[in] fv2b function returning whether a label must be replaced
/// by the background. /// by the background.
// //
template <typename I, typename F> template <typename I, typename F>
void void
relabel_inplace(Image<I>& label, relabel_inplace(Image<I>& label,
mln_value(I)& nlabels, const mln_value(I)& nlabels,
const Function_v2b<F>& fv2b); const Function_v2b<F>& fv2b);
/// Remove components and relabel a labeled image inplace. /// Remove components and relabel a labeled image inplace.
/// \param[in, out] label the labeled image. /// \param[in, out] label the labeled image.
/// \param[in, out] nlabels the number of labels in \p label. /// \param[in] nlabels the number of labels in \p label.
/// \param[in] fv2v function returning the new component id for each /// \param[in] fv2v function returning the new component id for each
/// pixel value. /// pixel value.
// //
template <typename I, typename F> template <typename I, typename F>
void void
relabel_inplace(Image<I>& label, relabel_inplace(Image<I>& label,
mln_value(I)& nlabels, const mln_value(I)& nlabels,
const Function_v2v<F>& fv2v); const Function_v2v<F>& fv2v);
...@@ -160,7 +160,7 @@ namespace mln ...@@ -160,7 +160,7 @@ namespace mln
inline inline
void void
relabel_inplace_tests(Image<I>& label, relabel_inplace_tests(Image<I>& label,
mln_value(I)& nlabels, const mln_value(I)& nlabels,
const Function<F>& f) const Function<F>& f)
{ {
// FIXME: we may want to check that it is exactly a label. // FIXME: we may want to check that it is exactly a label.
...@@ -221,7 +221,7 @@ namespace mln ...@@ -221,7 +221,7 @@ namespace mln
inline inline
void void
relabel_inplace(Image<I>& label, relabel_inplace(Image<I>& label,
mln_value(I)& nlabels, const mln_value(I)& nlabels,
const Function_v2v<F>& fv2v) const Function_v2v<F>& fv2v)
{ {
trace::entering("labeling::relabel_inplace"); trace::entering("labeling::relabel_inplace");
...@@ -240,7 +240,7 @@ namespace mln ...@@ -240,7 +240,7 @@ namespace mln
inline inline
void void
relabel_inplace(Image<I>& label, relabel_inplace(Image<I>& label,
mln_value(I)& nlabels, const mln_value(I)& nlabels,
const Function_v2b<F>& fv2b) const Function_v2b<F>& fv2b)
{ {
trace::entering("labeling::relabel_inplace"); trace::entering("labeling::relabel_inplace");
......
// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) // Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
// (LRDE)
// //
// This file is part of Olena. // This file is part of Olena.
// //
...@@ -34,6 +35,7 @@ ...@@ -34,6 +35,7 @@
# include <mln/core/concept/neighborhood.hh> # include <mln/core/concept/neighborhood.hh>
# include <mln/data/fill.hh> # include <mln/data/fill.hh>
namespace mln namespace mln
{ {
...@@ -101,6 +103,7 @@ namespace mln ...@@ -101,6 +103,7 @@ namespace mln
# ifndef MLN_INCLUDE_ONLY # ifndef MLN_INCLUDE_ONLY
template <typename I, typename D, typename N> template <typename I, typename D, typename N>
mln_concrete(I) mln_concrete(I)
crest(const Image<I>& input_, const Image<D>& dist_map_, crest(const Image<I>& input_, const Image<D>& dist_map_,
...@@ -139,7 +142,7 @@ namespace mln ...@@ -139,7 +142,7 @@ namespace mln
{ {
if (dist_map(n) == dist_map(p)) if (dist_map(n) == dist_map(p))
++nb_eq; ++nb_eq;
else else if (dist_map(n) < dist_map(p))
++nb_lt; ++nb_lt;
} }
......
...@@ -122,6 +122,12 @@ namespace mln ...@@ -122,6 +122,12 @@ namespace mln
from_to_(const value::int_u<n>& from, unsigned& to_); from_to_(const value::int_u<n>& from, unsigned& to_);
// int_u -> bool.
template <unsigned n>
void
from_to_(const value::int_u<n>& from, bool& to_);
} // end of namespace mln::convert::over_load } // end of namespace mln::convert::over_load
} // end of namespace mln::convert } // end of namespace mln::convert
...@@ -217,6 +223,16 @@ namespace mln ...@@ -217,6 +223,16 @@ namespace mln
to_ = from; to_ = from;
} }
// int_u -> bool.
template <unsigned n>
inline
void
from_to_(const value::int_u<n>& from, bool& to_)
{
to_ = (from != 0u);
}
} // end of namespace mln::convert::over_load } // end of namespace mln::convert::over_load
} // end of namespace mln::convert } // end of namespace mln::convert
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
# include <mln/literal/zero.hh> # include <mln/literal/zero.hh>