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>
 
* mln/draw/dashed_line.hh: New draw line routine.
......@@ -28,7 +28,7 @@
/// \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/core/concept/meta_accumulator.hh>
......@@ -40,7 +40,7 @@ namespace mln
namespace accu
{
/// \brief Count a given value.
/// \brief Define an accumulator that counts the occurrence of a given value.
///
/// \ingroup modaccuvalues
//
......
......@@ -163,9 +163,14 @@ namespace mln
void
from_to_(bool from, value::rgb<m>& to);
// rgb32 -> bool
void
from_to_(const value::qt::rgb32& from, bool& to);
// bool -> rgb32
void
from_to_(const bool& from, value::qt::rgb32& to);
// int_u -> rgb.
template <unsigned m>
void from_to_(const value::int_u<m>& from, value::rgb<m>& to);
......@@ -182,6 +187,11 @@ namespace mln
template <unsigned n>
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.
template <unsigned n>
void
......
......@@ -41,6 +41,8 @@
# include <mln/value/qt/rgb32.hh>
# include <mln/value/rgb8.hh>
// FIXME: not generic.
# include <mln/core/alias/dpoint2d.hh>
# if QT_VERSION < 0x040000
# error "Your version of Qt is too old and is not supported."
......
......@@ -121,7 +121,7 @@ namespace mln
template <typename I>
inline
QImage to_qimage_nocopy_nocopy(const Image<I>& ima_)
QImage to_qimage_nocopy(const Image<I>& ima_)
{
const I& ima = exact(ima_);
mln_precondition(ima.is_valid());
......
......@@ -38,6 +38,7 @@ namespace mln
// Forward declarations.
template <typename E> struct Function;
template <typename E> struct Function_n2v;
template <typename E> struct Function_v2v;
template <typename E> struct Function_v2b;
template <typename E> struct Function_vv2v;
......@@ -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. |
`-----------------*/
......@@ -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.
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.
//
......@@ -115,7 +116,7 @@ namespace mln
mlc_is_a(S,Box)::check();
// 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;
trans_t
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.
//
......@@ -46,7 +47,7 @@ namespace mln
/// Compute the histogram of image \p input.
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
......@@ -59,9 +60,9 @@ namespace mln
template <typename I>
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());
for_all(p)
++h(input(p));
......@@ -75,13 +76,13 @@ namespace mln
template <typename I>
inline
array<mln_value(I)> compute(const Image<I>& input)
histo::array<mln_value(I)> compute(const Image<I>& input)
{
trace::entering("histo::compute");
mlc_equal(mln_trait_image_quant(I), mln::trait::image::quant::low)::check();
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));
trace::exiting("histo::compute");
......
// 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.
//
......@@ -37,6 +38,7 @@
# include <mln/metal/equal.hh>
# include <mln/value/int_u8.hh>
# include <mln/value/rgb8.hh>
# include <mln/value/qt/rgb32.hh>
# include <Magick++.h>
......@@ -90,6 +92,14 @@ namespace mln
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>
inline
void save(const Image<I>& ima_, const std::string& filename)
......@@ -100,7 +110,8 @@ namespace mln
const I& ima = exact(ima_);
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::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 << "supported formats: binary, 8bits grayscale (int_u8), 8bits truecolor (rgb8)" << std::endl;
......@@ -112,11 +123,13 @@ namespace mln
Magick::PixelPacket* pixel_cache = im_file.getPixels(0, 0, ima.nrows(), ima.ncols());
Magick::PixelPacket* pixel;
mln_site(I) pmin = ima.domain().pmin();
mln_piter(I) p(ima.domain());
for_all(p)
{
pixel = pixel_cache + (int) p.to_site().to_vec()[0] * ima.ncols()
+ (int) p.to_site().to_vec()[1];
pixel = pixel_cache + (int) (p.to_site().to_vec()[0] - pmin.to_vec()[0]) * ima.ncols()
+ (int) (p.to_site().to_vec()[1] - pmin.to_vec()[1]);
*pixel = get_color(ima(p));
}
im_file.syncPixels();
......
......@@ -50,8 +50,7 @@ namespace mln
\param[in] ima A reference to the image to save.
\param[out] filename The output file. */
template <typename I>
void save(const image1d<I>& ima,
const std::string& filename);
void save(const image1d<I>& ima, const std::string& filename);
/*! \brief Save a Milena array in a plot file.
\param[in] arr A reference to the array to save.
......@@ -59,10 +58,13 @@ namespace mln
\param[in] start_value The start index value of the plot
(optional). */
template <typename T>
void save(util::array<T>& arr,
const std::string& filename,
void save(util::array<T>& arr, const std::string& filename,
int start_value);
/// \overload
template <typename T>
inline
void save(const histo::array<T>& arr, const std::string& filename);
# ifndef MLN_INCLUDE_ONLY
......@@ -97,6 +99,19 @@ namespace mln
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
......
......@@ -83,27 +83,27 @@ namespace mln
/// Remove components and relabel a labeled image inplace.
/// \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
/// by the background.
//
template <typename I, typename F>
void
relabel_inplace(Image<I>& label,
mln_value(I)& nlabels,
const mln_value(I)& nlabels,
const Function_v2b<F>& fv2b);
/// Remove components and relabel a labeled image inplace.
/// \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
/// pixel value.
//
template <typename I, typename F>
void
relabel_inplace(Image<I>& label,
mln_value(I)& nlabels,
const mln_value(I)& nlabels,
const Function_v2v<F>& fv2v);
......@@ -160,7 +160,7 @@ namespace mln
inline
void
relabel_inplace_tests(Image<I>& label,
mln_value(I)& nlabels,
const mln_value(I)& nlabels,
const Function<F>& f)
{
// FIXME: we may want to check that it is exactly a label.
......@@ -221,7 +221,7 @@ namespace mln
inline
void
relabel_inplace(Image<I>& label,
mln_value(I)& nlabels,
const mln_value(I)& nlabels,
const Function_v2v<F>& fv2v)
{
trace::entering("labeling::relabel_inplace");
......@@ -240,7 +240,7 @@ namespace mln
inline
void
relabel_inplace(Image<I>& label,
mln_value(I)& nlabels,
const mln_value(I)& nlabels,
const Function_v2b<F>& fv2b)
{
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.
//
......@@ -34,6 +35,7 @@
# include <mln/core/concept/neighborhood.hh>
# include <mln/data/fill.hh>
namespace mln
{
......@@ -101,6 +103,7 @@ namespace mln
# ifndef MLN_INCLUDE_ONLY
template <typename I, typename D, typename N>
mln_concrete(I)
crest(const Image<I>& input_, const Image<D>& dist_map_,
......@@ -139,7 +142,7 @@ namespace mln
{
if (dist_map(n) == dist_map(p))
++nb_eq;
else
else if (dist_map(n) < dist_map(p))
++nb_lt;
}
......
......@@ -122,6 +122,12 @@ namespace mln
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
......@@ -217,6 +223,16 @@ namespace mln
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
......
......@@ -37,6 +37,7 @@
# include <mln/literal/zero.hh>
# include <mln/literal/black.hh>
# include <mln/literal/white.hh>
namespace mln
{
......@@ -84,14 +85,18 @@ namespace mln
template <unsigned m>
void from_to_(const value::int_u<m>& from, value::qt::rgb32& to);
// hsl -> rgb8.
// hsl -> rgb32.
template <typename H, typename S, typename L>
void from_to_(const value::hsl_<H,S,L>&, value::qt::rgb32& to);
// rgb8 -> bool.
// rgb32 -> bool.
void from_to_(const value::qt::rgb32& from, bool& to);
// bool -> rgb32.
void from_to_(const bool& from, value::qt::rgb32& to);
} // end of namespace mln::convert::over_load
} // end of namespace mln::convert
......@@ -774,6 +779,15 @@ namespace mln
}
void from_to_(const bool& from, value::qt::rgb32& to)
{
if (from)
to = literal::white;
else
to = literal::black;
}
} // end of namespace mln::convert::over_load
} // end of namespace mln::convert
......
// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
......@@ -23,59 +23,19 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
#include <mln/core/alias/box1d.hh>
#include <mln/core/alias/box2d.hh>
#include <mln/core/alias/box3d.hh>
#include <mln/core/box_runstart_piter.hh>
int main()
{
using namespace mln;
/// Test with box1d
{
box1d b1(point1d(40), point1d(42));
box_runstart_piter<point1d> p1(b1);
for_all(p1)
{
mln_assertion(p1[0] == 40);
std::cout << p1 <<std::endl;
}
std::cout << "run_len : " << p1.run_length()<<std::endl;
mln_assertion(p1.run_length() == 3);
}
/// Test with box2d
{
box2d b2(point2d(1,2), point2d(5,8));
box_runstart_piter<point2d> p2(b2);
int i = 1;
for_all(p2)
{
mln_assertion(p2[1] == 2 && p2[0] == i++);
std::cout << p2 <<std::endl;
}
std::cout << "run_len : " << p2.run_length()<<std::endl;
mln_assertion(p2.run_length() == 7);
}
// Test with image 3d
{
box3d b3(point3d(1,2,3), point3d(5,8,7));
box_runstart_piter<point3d> p3(b3);
int i = 1;
int j = 2;
for_all(p3)
{
std::cout << p3 << std::endl;
if (i++ == 5)
i = 1;
if (j++ == 8)
j = 2;
}
std::cout << "run_len : " << p3.run_length() << std::endl;
mln_assertion(p3.run_length() == 5);
}
box2d b(3,3);
box_runstart_piter<point2d> p(b);
unsigned i = 0;
for_all(p)
mln_assertion(p == point2d(i, 0));
mln_assertion(p.run_length() == 3);
}
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