* mln/io/flo/load.hh,
* mln/io/flo/save.hh,
* mln/io/flo/all.hh: New.
---
milena/ChangeLog | 8 ++
milena/mln/io/{pgms => flo}/all.hh | 19 +++--
milena/mln/io/flo/load.hh | 129 ++++++++++++++++++++++++++++++++++++
milena/mln/io/flo/save.hh | 118 ++++++++++++++++++++++++++++++++
4 files changed, 266 insertions(+), 8 deletions(-)
copy milena/mln/io/{pgms => flo}/all.hh (78%)
create mode 100644 milena/mln/io/flo/load.hh
create mode 100644 milena/mln/io/flo/save.hh
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 360e77e..3fde486 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,11 @@
+2012-05-03 Sylvain Lobry <lobry(a)lrde.epita.fr>
+
+ Added .flo i/o routines.
+
+ * mln/io/flo/load.hh,
+ * mln/io/flo/save.hh,
+ * mln/io/flo/all.hh: New.
+
2011-03-15 Guillaume Lazzara <z(a)lrde.epita.fr>
Regen generated files.
diff --git a/milena/mln/io/pgms/all.hh b/milena/mln/io/flo/all.hh
similarity index 78%
copy from milena/mln/io/pgms/all.hh
copy to milena/mln/io/flo/all.hh
index 3525744..918add7 100644
--- a/milena/mln/io/pgms/all.hh
+++ b/milena/mln/io/flo/all.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -23,11 +23,11 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef MLN_IO_PGMS_ALL_HH
-# define MLN_IO_PGMS_ALL_HH
+#ifndef MLN_IO_FLO_ALL_HH
+# define MLN_IO_FLO_ALL_HH
/// \file
-/// \brief Inclusion of all PGMS I/O routines.
+/// \brief Inclusion of all FLO I/O routines.
namespace mln
@@ -35,12 +35,15 @@ namespace mln
namespace io
{
- /// Namespace of pgms input/output handling.
- namespace pgms {}
+ /// Namespace of pbm input/output handling.
+ namespace flo
+ {
+ }
}
}
-# include <mln/io/pgms/load.hh>
+# include <mln/io/flo/load.hh>
+# include <mln/io/flo/save.hh>
-#endif // ! MLN_IO_PGMS_ALL_HH
+#endif // ! MLN_IO_FLO_ALL_HH
diff --git a/milena/mln/io/flo/load.hh b/milena/mln/io/flo/load.hh
new file mode 100644
index 0000000..d29f6f6
--- /dev/null
+++ b/milena/mln/io/flo/load.hh
@@ -0,0 +1,129 @@
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project 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_FLO_LOAD_HH
+# define MLN_IO_FLO_LOAD_HH
+
+/// \file
+///
+/// Define a function which loads an image of kind .flo with given path.
+/// Information about .flo can be found there :
+///
http://vision.middlebury.edu/flow/data/
+
+# include <stdio.h>
+# include <stdlib.h>
+# include <string>
+
+# include <mln/core/image/image2d.hh>
+# include <mln/core/alias/vec2d.hh>
+# include <mln/make/box2d.hh>
+
+# define TAG_FLOAT 202021.25
+
+namespace mln
+{
+
+ namespace io
+ {
+
+ namespace flo
+ {
+
+ /// Load a .flo vector field in a Milena structure.
+ ///
+ /// \param[out] optical_flow A refernce to the image which will receive
+ /// the data.
+ /// \param[in] filename The source.
+ ///
+ void
+ load (mln::image2d <mln::vec2d_f>& optical_flow,
+ const std::string &filename);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ inline
+ void
+ load (mln::image2d <mln::vec2d_f>& optical_flow,
+ const std::string &filename)
+ {
+ trace::entering("mln::io::flo::load");
+
+ FILE *stream = fopen (filename.c_str (), "rb");
+ if (stream == NULL)
+ {
+ std::cerr << "error: file '" << filename
+ << "' not found!";
+ abort();
+ }
+
+ int width, height;
+ float tag;
+
+ if ((fread (&tag, sizeof(float), 1, stream) != 1)
+ || (fread (&width, sizeof(int), 1, stream) != 1)
+ || (fread (&height, sizeof(int), 1, stream) != 1))
+ {
+ std::cerr << "error while reading header of " << filename;
+ abort();
+ }
+
+ if (tag != TAG_FLOAT)
+ {
+ std::cerr << "error: Wrong magic-number in " << filename;
+ abort();
+ }
+
+ optical_flow.init_ (mln::make::box2d (height, width));
+
+ mln::point2d p;
+ for (p.row () = 0; p.row () < height; ++p.row ())
+ for (p.col () = 0; p.col () < width; ++p.col ())
+ {
+ float u, v;
+ if ((fread (&u, sizeof(float), 1, stream) != 1)
+ || (fread (&v, sizeof(float), 1, stream) != 1))
+ {
+ std::cerr << "error while reading the " << p << "th
point.";
+ abort ();
+ }
+ optical_flow (p)[0] = u;
+ optical_flow (p)[1] = v;
+ }
+
+ fclose (stream);
+
+ trace::exiting("mln::io::flo::load");
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::io::flo
+
+ } // end of namespace mln::io
+
+} // end of namespace mln
+
+#endif // ! MLN_IO_FLO_LOAD_HH
diff --git a/milena/mln/io/flo/save.hh b/milena/mln/io/flo/save.hh
new file mode 100644
index 0000000..651313a
--- /dev/null
+++ b/milena/mln/io/flo/save.hh
@@ -0,0 +1,118 @@
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project 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_FLO_SAVE_HH
+# define MLN_IO_FLO_SAVE_HH
+
+/// \file
+///
+/// Define a function which saves an image of kind flo with given path.
+/// Information about .flo can be found there :
+///
http://vision.middlebury.edu/flow/data/
+
+# define TAG_STRING "PIEH"
+
+# include <stdio.h>
+# include <stdlib.h>
+# include <string>
+
+# include <mln/core/image/image2d.hh>
+# include <mln/core/alias/vec2d.hh>
+
+namespace mln
+{
+
+ namespace io
+ {
+
+ namespace flo
+ {
+
+ /// Save vector field in a .flo file.
+ ///
+ /// \param[in] optical_flow A refernce to the image which contains the
+ /// vector field
+ /// \param[in] filename The destination.
+ ///
+ void
+ save (const mln::image2d <mln::vec2d_f>& optical_flow,
+ const std::string& filename);
+
+# ifndef MLN_INCLUDE_ONLY
+
+ inline
+ void
+ save (const mln::image2d <mln::vec2d_f>& optical_flow,
+ const std::string& filename)
+ {
+ trace::entering("mln::io::flo::save");
+
+ int width = optical_flow.ncols ();
+ int height = optical_flow.nrows ();
+
+ FILE *stream = fopen (filename.c_str (), "wb");
+ if (!stream)
+ {
+ std::cerr << "error: can not write into '" << filename
<< "'.";
+ abort ();
+ }
+
+ fprintf (stream, TAG_STRING);
+ if ((fwrite (&width, sizeof(int), 1, stream) != 1)
+ || (fwrite (&height, sizeof(int), 1, stream) != 1))
+ {
+ std::cerr << "error: could not write header.";
+ abort ();
+ }
+
+ mln::point2d p;
+ for (p.row () = 0; p.row () < height; ++p.row ())
+ for (p.col () = 0; p.col () < width; ++p.col ())
+ {
+ float u = optical_flow (p)[0];
+ float v = optical_flow (p)[1];
+
+ if ((fwrite (&u, sizeof(float), 1, stream) != 1)
+ || (fwrite (&v, sizeof(float), 1, stream) != 1))
+ {
+ std::cerr << "error while writing the " << p << "th
point.";
+ abort ();
+ }
+ }
+
+ fclose (stream);
+
+ trace::exiting("mln::io::flo::save");
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::io::flo
+
+ } // end of namespace mln::io
+
+} // end of namespace mln
+
+#endif // ! MLN_IO_FLO_SAVE_HH
--
1.7.2.5