
* headers.mk: add new headers to distribution. * mln/io/all.hh: include new headers. * mln/io/cloud/all.hh, * mln/io/cloud/load.hh, * mln/io/cloud/save.hh: load and save a cloud of points. * tests/unit_test/Makefile.am, * tests/unit_test/mln_io_cloud_load.cc, * tests/unit_test/mln_io_cloud_save.cc: add new unit tests. --- milena/ChangeLog | 16 ++++ milena/headers.mk | 2 + milena/mln/io/all.hh | 16 ++-- milena/mln/io/{ => cloud}/all.hh | 30 +++----- milena/mln/io/cloud/load.hh | 118 +++++++++++++++++++++++++++ milena/mln/io/cloud/save.hh | 110 +++++++++++++++++++++++++ milena/tests/unit_test/Makefile.am | 2 + milena/tests/unit_test/mln_io_cloud_load.cc | 11 +++ milena/tests/unit_test/mln_io_cloud_save.cc | 11 +++ 9 files changed, 290 insertions(+), 26 deletions(-) copy milena/mln/io/{ => cloud}/all.hh (70%) create mode 100644 milena/mln/io/cloud/load.hh create mode 100644 milena/mln/io/cloud/save.hh create mode 100644 milena/tests/unit_test/mln_io_cloud_load.cc create mode 100644 milena/tests/unit_test/mln_io_cloud_save.cc diff --git a/milena/ChangeLog b/milena/ChangeLog index f2defdd..9e9189d 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,21 @@ 2009-02-02 Guillaume Lazzara <z@lrde.epita.fr> + Add io::cloud. + + * headers.mk: add new headers to distribution. + + * mln/io/all.hh: include new headers. + + * mln/io/cloud/all.hh, + * mln/io/cloud/load.hh, + * mln/io/cloud/save.hh: load and save a cloud of points. + + * tests/unit_test/Makefile.am, + * tests/unit_test/mln_io_cloud_load.cc, + * tests/unit_test/mln_io_cloud_save.cc: add new unit tests. + +2009-02-02 Guillaume Lazzara <z@lrde.epita.fr> + Add accu::rms. * headers.mk: add new header to distribution. diff --git a/milena/headers.mk b/milena/headers.mk index 6a937c5..28e24e7 100644 --- a/milena/headers.mk +++ b/milena/headers.mk @@ -993,6 +993,8 @@ mln/io/pfm/save.hh \ mln/io/raw/load.hh \ mln/io/raw/all.hh \ mln/io/raw/save.hh \ +mln/io/cloud/load.hh \ +mln/io/cloud/save.hh \ mln/io/all.hh \ mln/io/pbm/load.hh \ mln/io/pbm/all.hh \ diff --git a/milena/mln/io/all.hh b/milena/mln/io/all.hh index bb6f7d3..777ffb7 100644 --- a/milena/mln/io/all.hh +++ b/milena/mln/io/all.hh @@ -1,4 +1,4 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// 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 @@ -28,10 +28,10 @@ #ifndef MLN_IO_ALL_HH # define MLN_IO_ALL_HH -/*! \file mln/io/all.hh - * - * \brief File that includes all io materials. - */ +/// \file mln/io/all.hh +/// +/// File that includes all io materials. + namespace mln @@ -46,13 +46,15 @@ namespace mln } -//# include <mln/io/fits/all.hh> -//# include <mln/io/off/all.hh> +# include <mln/io/cloud/all.hh> # include <mln/io/pbm/all.hh> # include <mln/io/pfm/all.hh> # include <mln/io/pgm/all.hh> # include <mln/io/pnm/all.hh> # include <mln/io/ppm/all.hh> +# include <mln/io/raw/all.hh> # include <mln/io/txt/all.hh> +//# include <mln/io/fits/all.hh> +//# include <mln/io/off/all.hh> #endif // ! MLN_IO_ALL_HH diff --git a/milena/mln/io/all.hh b/milena/mln/io/cloud/all.hh similarity index 70% copy from milena/mln/io/all.hh copy to milena/mln/io/cloud/all.hh index bb6f7d3..f3bceb4 100644 --- a/milena/mln/io/all.hh +++ b/milena/mln/io/cloud/all.hh @@ -1,4 +1,4 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// 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 @@ -25,34 +25,26 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef MLN_IO_ALL_HH -# define MLN_IO_ALL_HH +#ifndef MLN_IO_CLOUD_ALL_HH +# define MLN_IO_CLOUD_ALL_HH -/*! \file mln/io/all.hh - * - * \brief File that includes all io materials. - */ +/// \file mln/io/cloud/all.hh +/// +/// File that includes all cloud io materials. namespace mln { - /// Namespace of input/output handling. namespace io { - /// Internal namespace of io namespace. - namespace internal {} + /// Namespace of cloud input/output handling. + namespace cloud {} } } -//# include <mln/io/fits/all.hh> -//# include <mln/io/off/all.hh> -# include <mln/io/pbm/all.hh> -# include <mln/io/pfm/all.hh> -# include <mln/io/pgm/all.hh> -# include <mln/io/pnm/all.hh> -# include <mln/io/ppm/all.hh> -# include <mln/io/txt/all.hh> +# include <mln/io/cloud/load.hh> +# include <mln/io/cloud/save.hh> -#endif // ! MLN_IO_ALL_HH +#endif // ! MLN_IO_CLOUD_ALL_HH diff --git a/milena/mln/io/cloud/load.hh b/milena/mln/io/cloud/load.hh new file mode 100644 index 0000000..83f1e85 --- /dev/null +++ b/milena/mln/io/cloud/load.hh @@ -0,0 +1,118 @@ +// 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_CLOUD_LOAD_HH +# define MLN_IO_CLOUD_LOAD_HH + +/// \file mln/io/cloud/load.hh +/// +/// Load a cloud of points. +/// A cloud file must contain one point per line. +/// For a list of 3d points, a line would looks like the following: +/// +/// 35 4 5 +/// +/// +/// \todo Support 1 and 2d images. +/// \todo Make it generic? + +# include <iostream> +# include <fstream> + +# include <mln/core/concept/image.hh> +# include <mln/core/site_set/p_array.hh> + +namespace mln +{ + + namespace io + { + + namespace cloud + { + + /// Load a cloud of points. + /// + /// \param[in,out] arr the site set where to load the data. + /// \param[in] filename file to load. + template <typename P> + void load(p_array<P>& arr, const std::string& filename); + + +# ifndef MLN_INCLUDE_ONLY + + namespace internal + { + + template <typename P> + inline + void load_data(p_array<P>& arr, std::ifstream& file) + { + std::string line; + while (std::getline(file, line)) + { + algebra::vec<P::dim,float> v; + std::istringstream sline(line); + sline >> v[0] >> v[1] >> v[2]; + arr.append(v); + } + } + + } // end of namespace mln::io::cloud::internal + + + + template <typename P> + void load(p_array<P>& arr, const std::string& filename) + { + trace::entering("mln::io::cloud::load"); + + /// FIXME: do we really want this? + mln_precondition(P::dim == 3u); + + std::ifstream file(filename.c_str()); + if (! file) + { + std::cerr << "error: cannot open file '" << filename << "'!"; + abort(); + } + + internal::load_data(arr, file); + + trace::exiting("mln::io::cloud::load"); + } + + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::io::cloud + + } // end of namespace mln::io + +} // end of namespace mln + +#endif // ! MLN_IO_CLOUD_LOAD_HH diff --git a/milena/mln/io/cloud/save.hh b/milena/mln/io/cloud/save.hh new file mode 100644 index 0000000..fc42228 --- /dev/null +++ b/milena/mln/io/cloud/save.hh @@ -0,0 +1,110 @@ +// 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_CLOUD_SAVE_HH +# define MLN_IO_CLOUD_SAVE_HH + +/// \file mln/io/cloud/save.hh +/// +/// Save an image as a cloud of points. + +# include <iostream> +# include <fstream> + +# include <mln/core/concept/image.hh> +# include <mln/core/site_set/p_array.hh> + +namespace mln +{ + + namespace io + { + + namespace cloud + { + + /// Load a cloud of points + /// + /// \param[in] arr the cloud of points to save. + /// \param[in] filename the destination. + template <typename P> + void save(const p_array<P>& arr, const std::string& filename); + + +# ifndef MLN_INCLUDE_ONLY + + namespace internal + { + + template <typename P> + inline + void save_data(const p_array<P>& arr, std::ofstream& file) + { + std::ostringstream sline; + mln_piter(p_array<P>) p(arr); + for_all(p) + { + algebra::vec<P::dim,float> v = p.to_site().to_vec(); + sline << v[0]; + for (unsigned i = 1; i < P::dim; ++i) + sline << ' ' << v[i]; + sline << std::endl; + file << sline.str(); + } + } + + } // end of namespace mln::io::cloud::internal + + + + template <typename P> + void save(const p_array<P>& arr, const std::string& filename) + { + trace::entering("mln::io::cloud::save"); + + std::ofstream file(filename.c_str()); + if (! file) + { + std::cerr << "error: cannot open file '" << filename << "'!"; + abort(); + } + + internal::save_data(arr, file); + + trace::exiting("mln::io::cloud::save"); + } + + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::io::cloud + + } // end of namespace mln::io + +} // end of namespace mln + +#endif // ! MLN_IO_CLOUD_SAVE_HH diff --git a/milena/tests/unit_test/Makefile.am b/milena/tests/unit_test/Makefile.am index b31efec..7139e44 100644 --- a/milena/tests/unit_test/Makefile.am +++ b/milena/tests/unit_test/Makefile.am @@ -959,6 +959,8 @@ mln_io_pfm_save \ mln_io_raw_load \ mln_io_raw_all \ mln_io_raw_save \ +mln_io_cloud_load \ +mln_io_cloud_save \ mln_io_all \ mln_io_pbm_load \ mln_io_pbm_all \ diff --git a/milena/tests/unit_test/mln_io_cloud_load.cc b/milena/tests/unit_test/mln_io_cloud_load.cc new file mode 100644 index 0000000..8edc601 --- /dev/null +++ b/milena/tests/unit_test/mln_io_cloud_load.cc @@ -0,0 +1,11 @@ +// Unit test for mln/io/cloud/load.hh. +// Generated by ./build_unit_test.sh, do not modify. + +// Include the file twice, so we detect missing inclusion guards. +#include <mln/io/cloud/load.hh> +#include <mln/io/cloud/load.hh> + +int main() +{ + // Nothing. +} diff --git a/milena/tests/unit_test/mln_io_cloud_save.cc b/milena/tests/unit_test/mln_io_cloud_save.cc new file mode 100644 index 0000000..8d27cc9 --- /dev/null +++ b/milena/tests/unit_test/mln_io_cloud_save.cc @@ -0,0 +1,11 @@ +// Unit test for mln/io/cloud/save.hh. +// Generated by ./build_unit_test.sh, do not modify. + +// Include the file twice, so we detect missing inclusion guards. +#include <mln/io/cloud/save.hh> +#include <mln/io/cloud/save.hh> + +int main() +{ + // Nothing. +} -- 1.5.6.5