* mln/core/site_set/box.hh:
- Add a new version of enlarge() which can be applied on a single
dimension passed as parameter.
- Add center() which returns an approximated central site of a bo
---
milena/ChangeLog | 9 +++++++++
milena/mln/core/site_set/box.hh | 30 ++++++++++++++++++++++++++++++
2 files changed, 39 insertions(+), 0 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 1a947ad..2649954 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,14 @@
2008-10-27 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Add box::center() and a new overload of box::enlarge().
+
+ * mln/core/site_set/box.hh:
+ - Add a new version of enlarge() which can be applied on a single
+ dimension passed as parameter.
+ - Add center() which returns an approximated central site of a box.
+
+2008-10-27 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Fix wrong or missing traces.
* milena/mln/level/fill_with_image.spe.hh,
* milena/mln/morpho/erosion.spe.hh:
diff --git a/milena/mln/core/site_set/box.hh b/milena/mln/core/site_set/box.hh
index 9e8c6db..9a03897 100644
--- a/milena/mln/core/site_set/box.hh
+++ b/milena/mln/core/site_set/box.hh
@@ -137,9 +137,16 @@ namespace mln
/// Enlarge the box with a border \p b.
void enlarge(unsigned b);
+ /// Enlarge the box with a border \p b for dimension \p dim.
+ void enlarge(unsigned dim, unsigned b);
+
/// Give a larger box.
box<P> to_larger(unsigned b) const;
+ /// Return the approximated central site of this box.
+ /// FIXME: Do we want a routine as well like geom::bbox()?
+ P center() const;
+
/// Test that the box owns valid data, i.e., is initialized and
/// with pmin being 'less-than' pmax.
bool is_valid() const;
@@ -296,6 +303,17 @@ namespace mln
template <typename P>
inline
+ void
+ box<P>::enlarge(unsigned dim, unsigned b)
+ {
+ mln_precondition(is_valid());
+ pmin_[dim] -= b;
+ pmax_[dim] += b;
+ mln_postcondition(is_valid());
+ }
+
+ template <typename P>
+ inline
box<P>
larger_than(const box<P> a, const box<P> b)
{
@@ -329,6 +347,18 @@ namespace mln
template <typename P>
inline
+ P
+ box<P>::center() const
+ {
+ mln_precondition(is_valid());
+ point2d center;
+ for (unsigned i = 0; i < P::dim; ++i)
+ center[i] = pmin_[i] + ((pmax_[i] - pmin_[i]) / 2);
+ return center;
+ }
+
+ template <typename P>
+ inline
std::size_t
box<P>::memory_size() const
{
--
1.5.6.5
https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena/sandbox
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
INIM: Classif: Add projection.
* classif/iccvg04.cc: Fix wrong init.
* classif/proj.hh: Add generic proj.
iccvg04.cc | 6 +++--
proj.hh | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 68 insertions(+), 2 deletions(-)
Index: classif/iccvg04.cc
--- classif/iccvg04.cc (revision 2696)
+++ classif/iccvg04.cc (working copy)
@@ -31,6 +31,7 @@
#include <string.h>
#include <stdlib.h>
+#include "proj.hh"
using namespace mln;
@@ -102,7 +103,7 @@
memset(count, 0, (nbasins + 1) * sizeof(unsigned));
algebra::vec<3, unsigned> sum[nbasins + 1];
- for (int i = 1; i < nbasins + 1; ++i)
+ for (int i = 0; i < nbasins + 1; ++i)
sum[i] = literal::zero;
// Compute representatives of every class
@@ -127,7 +128,6 @@
I out(ima.domain());
for_all(pi)
{
-
//retrieve color class
value::rgb8 coul = ima(pi);
int w = ws(point3d(coul.red() / f, coul.green() / f, coul.blue() / f));
@@ -177,4 +177,6 @@
//classify image
classify_image(ima, histo, ws, nbasins, div_factor);
+
+ save_class(histo_closure, "histo.ppm");
}
Index: classif/proj.hh
--- classif/proj.hh (revision 0)
+++ classif/proj.hh (revision 0)
@@ -0,0 +1,64 @@
+// Copyright (C) 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
+// 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_PROJ_HH
+# define MLN_PROJ_HH
+
+#include <mln/io/ppm/save.hh>
+#include <mln/io/pgm/save.hh>
+#include <mln/level/paste.hh>
+#include <mln/accu/mean.hh>
+
+namespace mln
+{
+
+ template <typename T, typename A>
+ image2d<mln_result(A)>
+ proj(const image3d<T>& input, A a)
+ {
+ image2d<A> acc(geom::nslis(input), geom::nrows(input));
+ mln_piter(image3d<T>) p(input.domain());
+ for_all(p) // 3d
+ acc.at(p.sli(), p.row()).take(input(p));
+
+ image2d<mln_result(A)> output(acc.domain());
+ level::paste(acc, output);
+ return output;
+ }
+
+ template <typename T>
+ void
+ save_class(const image3d<T>& histo, const char * fn)
+ {
+ accu::mean<unsigned, unsigned long, value::int_u8> mean;
+ io::pgm::save(proj(histo, mean), fn);
+ }
+
+} // end of namespace mln
+
+#endif /* MLN_PROJ_HH */
+
https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add fun::v2v::convert and level::convert.
* milena/mln/fun/v2v/convert.hh: New.
* milena/mln/fun/v2v/cast.hh (todo): New.
* milena/mln/level/convert.hh: New.
* milena/tests/level/convert.cc: New.
* milena/tests/level/Makefile.am: Update.
* milena/mln/value/rgb.hh (todo): New.
(from_to): New overload for bool->rgbn.
* milena/mln/convert/from_to.hxx
(from_to): New decl for bool->rgbn.
* milena/sandbox/scribo/demat.hh
(include): Remove obsolete dependency.
mln/convert/from_to.hxx | 5 ++
mln/fun/v2v/cast.hh | 5 ++
mln/fun/v2v/convert.hh | 85 ++++++++++++++++++++++++++++++++++++++++++++++
mln/level/convert.hh | 87 ++++++++++++++++++++++++++++++++++++++++++++++++
mln/value/rgb.hh | 21 +++++++++++
sandbox/scribo/demat.hh | 2 -
tests/level/Makefile.am | 2 +
tests/level/convert.cc | 56 ++++++++++++++++++++++++++++++
8 files changed, 260 insertions(+), 3 deletions(-)
Index: milena/tests/level/convert.cc
--- milena/tests/level/convert.cc (revision 0)
+++ milena/tests/level/convert.cc (revision 0)
@@ -0,0 +1,56 @@
+// Copyright (C) 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
+// 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/level/convert.cc
+ *
+ * \brief Tests on mln::level::convert
+ */
+
+#include <mln/core/image/image2d.hh>
+#include <mln/level/convert.hh>
+
+#include <mln/value/rgb8.hh>
+#include <mln/literal/grays.hh>
+
+
+int main()
+{
+ using namespace mln;
+ using value::rgb8;
+
+// trace::quiet = false;
+
+ // bool -> rgb8
+ {
+ image2d<bool> ima(1, 2);
+ ima.at(0, 0) = false;
+ ima.at(0, 1) = true;
+ image2d<rgb8> out = level::convert(rgb8(), ima);
+ mln_assertion(out.at(0, 0) == literal::black);
+ mln_assertion(out.at(0, 1) == literal::white);
+ }
+}
Index: milena/tests/level/Makefile.am
--- milena/tests/level/Makefile.am (revision 2695)
+++ milena/tests/level/Makefile.am (working copy)
@@ -11,6 +11,7 @@
assign \
compare \
compute \
+ convert \
fill \
fill_with_value \
fill_with_image \
@@ -35,6 +36,7 @@
assign_SOURCES = assign.cc
compare_SOURCES = compare.cc
compute_SOURCES = compute.cc
+convert_SOURCES = convert.cc
fill_SOURCES = fill.cc
fill_with_value_SOURCES = fill_with_value.cc
fill_with_image_SOURCES = fill_with_image.cc
Index: milena/mln/level/convert.hh
--- milena/mln/level/convert.hh (revision 0)
+++ milena/mln/level/convert.hh (revision 0)
@@ -0,0 +1,87 @@
+// Copyright (C) 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
+// 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_LEVEL_CONVERT_HH
+# define MLN_LEVEL_CONVERT_HH
+
+/*! \file mln/level/convert.hh
+ *
+ * \brief Convert the contents of an image into another one.
+ *
+ * \todo Re-write doc.
+ */
+
+# include <mln/fun/v2v/convert.hh>
+# include <mln/level/transform.hh>
+
+
+namespace mln
+{
+
+ namespace level
+ {
+
+ /*! Convert the image \p input by changing the value type.
+ *
+ * \param[in] v A value of the destination type.
+ * \param[in] input The input image.
+ * \param[out] output The result image.
+ */
+ template <typename V, typename I>
+ mln_ch_value(I, V)
+ convert(const V&, const Image<I>& input);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ // Facade.
+
+ template <typename V, typename I>
+ inline
+ mln_ch_value(I, V)
+ convert(const V&, const Image<I>& input)
+ {
+ trace::entering("level::convert");
+
+ mln_precondition(exact(input).has_data());
+ fun::v2v::convert<V> f;
+ mln_ch_value(I, V) output = level::transform(input, f);
+
+ trace::exiting("level::convert");
+ return output;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::level
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LEVEL_CONVERT_HH
Index: milena/mln/value/rgb.hh
--- milena/mln/value/rgb.hh (revision 2695)
+++ milena/mln/value/rgb.hh (working copy)
@@ -32,6 +32,11 @@
*
* \brief Color class for red-green-blue where every component is
* n-bit encoded.
+ *
+ * \todo Split decl and def for from_to.
+ *
+ * \todo Introduce the concept of Color, then generalize from_to to
+ * colors.
*/
# include <mln/value/ops.hh>
@@ -515,6 +520,22 @@
to = value::rgb<m>(tmp);
}
+ // bool -> rgb.
+ template <unsigned m>
+ void
+ from_to(bool from, value::rgb<m>& to)
+ {
+ static literal::white_t* white_ = 0;
+ static literal::black_t* black_ = 0;
+ // We do not use literal::white (the object) so that we
+ // do not introduce any coupling with the file where
+ // literals are defined.
+ if (from)
+ to = *white_;
+ else
+ to = *black_;
+ }
+
} // end of namespace mln::convert
} // end of namespace mln
Index: milena/mln/convert/from_to.hxx
--- milena/mln/convert/from_to.hxx (revision 2695)
+++ milena/mln/convert/from_to.hxx (working copy)
@@ -108,6 +108,11 @@
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);
+
// Value -> Value
template <typename F, typename T>
void
Index: milena/mln/fun/v2v/cast.hh
--- milena/mln/fun/v2v/cast.hh (revision 2695)
+++ milena/mln/fun/v2v/cast.hh (working copy)
@@ -1,4 +1,4 @@
-// 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
@@ -31,6 +31,9 @@
/*! \file mln/fun/v2v/cast.hh
*
* \brief FIXME.
+ *
+ * \todo The function is intrisically meta; how to handle that
+ * particular case?
*/
# include <mln/core/concept/function.hh>
Index: milena/mln/fun/v2v/convert.hh
--- milena/mln/fun/v2v/convert.hh (revision 0)
+++ milena/mln/fun/v2v/convert.hh (revision 0)
@@ -0,0 +1,85 @@
+// Copyright (C) 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
+// 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_FUN_V2V_CONVERT_HH
+# define MLN_FUN_V2V_CONVERT_HH
+
+/*! \file mln/fun/v2v/convert.hh
+ *
+ * \brief FIXME.
+ *
+ * \todo The function is intrisically meta; how to handle that
+ * particular case?
+ */
+
+# include <mln/core/concept/function.hh>
+# include <mln/convert/to.hh>
+
+
+
+namespace mln
+{
+
+ namespace fun
+ {
+
+ namespace v2v
+ {
+
+ // FIXME: Doc!
+
+ template <typename V>
+ struct convert : public Function_v2v< convert<V> >
+ {
+ typedef V result;
+
+ template <typename W>
+ V operator()(const W& w) const;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename V>
+ template <typename W>
+ inline
+ V
+ convert<V>::operator()(const W& w) const
+ {
+ return mln::convert::to<V>(w);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::fun::v2v
+
+ } // end of namespace mln::fun
+
+} // end of namespace mln
+
+
+#endif // ! MLN_FUN_V2V_CONVERT_HH
Index: milena/sandbox/scribo/demat.hh
--- milena/sandbox/scribo/demat.hh (revision 2695)
+++ milena/sandbox/scribo/demat.hh (working copy)
@@ -55,8 +55,6 @@
# include <mln/draw/box.hh>
-# include <mln/estim/nsites.hh>
-
# include <mln/fun/i2v/array.hh>
# include <mln/io/pbm/load.hh>