URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2009-05-19 Fabien Freling <fabien.freling(a)lrde.epita.fr>
Extend plot I/O with load() function.
* mln/io/all.hh: Update plot/ entries.
* mln/io/plot/all.hh: New file including plot/ files.
* mln/io/plot/load.hh: New draft for plot loading, nonfunctional.
* mln/io/plot/save.hh: Update delimiter to simple whitespace.
* mln/labeling/compute.hh: Allow accumulator array to be
passed as an argument.
---
io/all.hh | 1
io/plot/all.hh | 50 +++++++++++++++++++++
io/plot/load.hh | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++
io/plot/save.hh | 7 ---
labeling/compute.hh | 79 ++++++++++++++++++++++++++++++++++
5 files changed, 251 insertions(+), 5 deletions(-)
Index: trunk/milena/mln/io/all.hh
===================================================================
--- trunk/milena/mln/io/all.hh (revision 3854)
+++ trunk/milena/mln/io/all.hh (revision 3855)
@@ -53,6 +53,7 @@
# include <mln/io/pbm/all.hh>
# include <mln/io/pfm/all.hh>
# include <mln/io/pgm/all.hh>
+# include <mln/io/plot/all.hh>
# include <mln/io/pnm/all.hh>
# include <mln/io/ppm/all.hh>
# include <mln/io/tiff/all.hh>
Index: trunk/milena/mln/io/plot/all.hh
===================================================================
--- trunk/milena/mln/io/plot/all.hh (revision 0)
+++ trunk/milena/mln/io/plot/all.hh (revision 3855)
@@ -0,0 +1,50 @@
+// Copyright (C) 2009 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
+// 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_IO_PLOT_ALL_HH
+# define MLN_IO_PLOT_ALL_HH
+
+/// \file mln/io/plot/all.hh
+///
+/// File that includes all plot io materials.
+
+
+namespace mln
+{
+
+ namespace io
+ {
+ /// Namespace of plot input/output handling.
+ namespace plot {}
+ }
+
+}
+
+# include <mln/io/plot/load.hh>
+# include <mln/io/plot/save.hh>
+
+#endif // ! MLN_IO_PLOT_ALL_HH
Index: trunk/milena/mln/io/plot/save.hh
===================================================================
--- trunk/milena/mln/io/plot/save.hh (revision 3854)
+++ trunk/milena/mln/io/plot/save.hh (revision 3855)
@@ -36,10 +36,7 @@
# include <iostream>
# include <fstream>
# include <mln/core/image/image1d.hh>
-# include <mln/metal/equal.hh>
# include <mln/util/array.hh>
-# include <mln/value/int_u8.hh>
-# include <mln/value/rgb8.hh>
namespace mln
@@ -88,7 +85,7 @@
std::ofstream file_out(filename.c_str());
for (unsigned i = 0; i < ima.ninds(); ++i)
- file_out << start_value + i << ", " << ima.at_(i) <<
std::endl;
+ file_out << start_value + i << " " << ima.at_(i) <<
std::endl;
trace::exiting("mln::io::plot::save");
}
@@ -102,7 +99,7 @@
std::ofstream file_out(filename.c_str());
for (unsigned i = 0; i < arr.nelements(); ++i)
- file_out << start_value + i << ", " << arr[i] <<
std::endl;
+ file_out << start_value + i << " " << arr[i] <<
std::endl;
trace::exiting("mln::io::plot::save");
}
Index: trunk/milena/mln/io/plot/load.hh
===================================================================
--- trunk/milena/mln/io/plot/load.hh (revision 0)
+++ trunk/milena/mln/io/plot/load.hh (revision 3855)
@@ -0,0 +1,119 @@
+// Copyright (C) 2009 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_IO_PLOT_LOAD_HH
+# define MLN_IO_PLOT_LOAD_HH
+
+///
+/// \file mln/io/plot/load.hh
+///
+/// Define a routine which loads in a plot format.
+
+# include <iostream>
+# include <fstream>
+# include <mln/core/image/image1d.hh>
+# include <mln/metal/equal.hh>
+# include <mln/util/array.hh>
+# include <mln/value/int_u8.hh>
+# include <mln/value/rgb8.hh>
+
+
+namespace mln
+{
+
+ namespace io
+ {
+
+ namespace plot
+ {
+
+ /*! Load a Milena 1D image from a plot file.
+ *
+ * \param[in] ima A reference to the image to load.
+ * \param[out] filename The output file.
+ * \param[in] start_value The start index value of the plot
+ * (optional).
+ */
+ template <typename I>
+ void load(image1d<I>& ima,
+ const std::string& filename);
+
+ /*! Load a Milena array from a plot file.
+ *
+ * \param[in] arr A reference to the array to load.
+ * \param[out] filename The output file.
+ * \param[in] start_value The start index value of the plot
+ * (optional).
+ */
+ template <typename I>
+ void load(util::array<I>& arr,
+ const std::string& filename);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename I>
+ inline
+ void load(image1d<I>& ima, const std::string& filename)
+ {
+ trace::entering("mln::io::plot::load");
+
+ std::ifstream file_out(filename.c_str());
+ for (unsigned i = 0; i < ima.ninds(); ++i)
+ file_out << start_value + i << ", " << ima.at_(i) <<
std::endl;
+
+ trace::exiting("mln::io::plot::load");
+ }
+
+ template <typename I>
+ inline
+ void load(util::array<I>& arr, const std::string& filename)
+ {
+ trace::entering("mln::io::plot::load");
+
+ std::ifstream file_out(filename.c_str());
+ while (!oef)
+ {
+ if (line is comment)
+ continue;
+ }
+
+ trace::exiting("mln::io::plot::load");
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::io::plot
+
+ } // end of namespace mln::io
+
+} // end of namespace mln
+
+
+#endif // ! MLN_IO_PLOT_LOAD_HH
Index: trunk/milena/mln/labeling/compute.hh
===================================================================
--- trunk/milena/mln/labeling/compute.hh (revision 3854)
+++ trunk/milena/mln/labeling/compute.hh (revision 3855)
@@ -63,6 +63,23 @@
/// Compute an accumulator onto the pixel values of the image \p input.
/// for each component of the image \p label.
///
+ /// \param[in] a An array of accumulator.
+ /// \param[in] input The input image.
+ /// \param[in] label The labeled image.
+ /// \param[in] nlabels The number of labels in \p label.
+ /// \return A mln::p_array of accumulator result (one result per label).
+ //
+ template <typename A, typename I, typename L>
+ util::array<mln_result(A)>
+ compute(util::array<A>& a,
+ const Image<I>& input,
+ const Image<L>& label,
+ const mln_value(L)& nlabels);
+
+
+ /// Compute an accumulator onto the pixel values of the image \p input.
+ /// for each component of the image \p label.
+ ///
/// \param[in] a An accumulator.
/// \param[in] input The input image.
/// \param[in] label The labeled image.
@@ -227,6 +244,35 @@
return res;
}
+ template <typename A, typename I, typename L>
+ inline
+ util::array<mln_result(A)>
+ compute(util::array<A>& accus,
+ const Image<I>& input_,
+ const Image<L>& label_,
+ const mln_value(L)& nlabels)
+ {
+ trace::entering("labeling::impl::generic::compute");
+ //internal::compute_tests(a_, input_, label_, nlabels);
+
+ //const A& a = exact(a_);
+ const I& input = exact(input_);
+ const L& label = exact(label_);
+
+ // FIXME: Check accus size with nlabels.
+ //util::array<A> accus(static_cast<unsigned>(nlabels) + 1, a);
+
+ mln_piter(I) p(input.domain());
+ for_all(p)
+ accus[label(p)].take(input(p));
+
+ util::array<mln_result(A)> res;
+ convert::from_to(accus, res);
+
+ trace::exiting("labeling::impl::generic::compute");
+ return res;
+ }
+
} // end of namespace mln::labeling::impl::generic
} // end of namespace mln::labeling::impl
@@ -236,6 +282,7 @@
namespace internal
{
+
template <typename A, typename L>
inline
util::array<mln_result(A)>
@@ -258,6 +305,19 @@
return impl::generic::compute(a, input, label, nlabels);
}
+
+ template <typename A, typename I, typename L>
+ inline
+ util::array<mln_result(A)>
+ compute_dispatch(util::array<A>& a,
+ const Image<I>& input,
+ const Image<L>& label,
+ const mln_value(L)& nlabels)
+ {
+ return impl::generic::compute(a, input, label, nlabels);
+ }
+
+
} // end of namespace mln::labeling::internal
@@ -267,6 +327,25 @@
template <typename A, typename I, typename L>
inline
util::array<mln_result(A)>
+ compute(util::array<A>& a,
+ const Image<I>& input,
+ const Image<L>& label,
+ const mln_value(L)& nlabels)
+ {
+ trace::entering("labeling::compute");
+
+ //internal::compute_tests(a, input, label, nlabels);
+
+ typedef util::array<mln_result(A)> R;
+ R res = internal::compute_dispatch(a, input, label, nlabels);
+
+ trace::exiting("labeling::compute");
+ return res;
+ }
+
+ template <typename A, typename I, typename L>
+ inline
+ util::array<mln_result(A)>
compute(const Accumulator<A>& a,
const Image<I>& input,
const Image<L>& label,