Commit 5ca1c54c authored by Guillaume Lazzara's avatar Guillaume Lazzara
Browse files

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.

git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@3240 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 9d67ffe6
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.
......@@ -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 \
......
// 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
// 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_ALL_HH
# define MLN_IO_CLOUD_ALL_HH
/// \file mln/io/cloud/all.hh
///
/// File that includes all cloud io materials.
namespace mln
{
namespace io
{
/// Namespace of cloud input/output handling.
namespace cloud {}
}
}
# include <mln/io/cloud/load.hh>
# include <mln/io/cloud/save.hh>
#endif // ! MLN_IO_CLOUD_ALL_HH
// 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
// 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
......@@ -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 \
......
// 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.
}
// 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.
}
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