• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

save.hh

00001 // Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
00002 // (LRDE)
00003 //
00004 // This file is part of Olena.
00005 //
00006 // Olena is free software: you can redistribute it and/or modify it under
00007 // the terms of the GNU General Public License as published by the Free
00008 // Software Foundation, version 2 of the License.
00009 //
00010 // Olena is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software project without restriction.  Specifically, if other files
00020 // instantiate templates or use macros or inline functions from this
00021 // file, or you compile this file and link it with other files to produce
00022 // an executable, this file does not by itself cause the resulting
00023 // executable to be covered by the GNU General Public License.  This
00024 // exception does not however invalidate any other reasons why the
00025 // executable file might be covered by the GNU General Public License.
00026 
00027 #ifndef MLN_IO_PLOT_SAVE_HH
00028 # define MLN_IO_PLOT_SAVE_HH
00029 
00033 
00034 # include <iostream>
00035 # include <fstream>
00036 # include <mln/core/image/image1d.hh>
00037 # include <mln/util/array.hh>
00038 
00039 
00040 namespace mln
00041 {
00042 
00043   namespace io
00044   {
00045 
00046     namespace plot
00047     {
00048 
00052       template <typename I>
00053       void save(const image1d<I>& ima, const std::string& filename);
00054 
00060       template <typename T>
00061       void save(util::array<T>& arr, const std::string& filename,
00062                 int start_value);
00063 
00065       template <typename T>
00066       inline
00067       void save(const histo::array<T>& arr, const std::string& filename);
00068 
00069 # ifndef MLN_INCLUDE_ONLY
00070 
00071 
00072 
00073       // FIXME: Make it generic.
00074       template <typename T>
00075       inline
00076       void save(const image1d<T>& ima, const std::string& filename)
00077       {
00078         trace::entering("mln::io::plot::save");
00079 
00080         std::ofstream file_out(filename.c_str());
00081         unsigned end = ima.bbox().pmax().ind();
00082         for (unsigned i = ima.bbox().pmin().ind(); i <= end; ++i)
00083           file_out << i << " " << ima.at_(i) << std::endl;
00084 
00085         trace::exiting("mln::io::plot::save");
00086       }
00087 
00088       template <typename T>
00089       inline
00090       void save(const util::array<T>& arr, const std::string& filename,
00091                 int start_value = 0)
00092       {
00093         trace::entering("mln::io::plot::save");
00094 
00095         std::ofstream file_out(filename.c_str());
00096         for (unsigned i = 0; i < arr.nelements(); ++i)
00097           file_out << start_value + i << " " << arr[i] << std::endl;
00098 
00099         trace::exiting("mln::io::plot::save");
00100       }
00101 
00102       template <typename T>
00103       inline
00104       void save(const histo::array<T>& arr, const std::string& filename)
00105       {
00106         trace::entering("mln::io::plot::save");
00107 
00108         std::ofstream file_out(filename.c_str());
00109         for (unsigned i = 0; i < arr.nvalues(); ++i)
00110           file_out << i << " " << arr[i] << std::endl;
00111 
00112         trace::exiting("mln::io::plot::save");
00113       }
00114 
00115 
00116 # endif // ! MLN_INCLUDE_ONLY
00117 
00118     } // end of namespace mln::io::plot
00119 
00120   } // end of namespace mln::io
00121 
00122 } // end of namespace mln
00123 
00124 
00125 #endif // ! MLN_IO_PLOT_SAVE_HH

Generated on Fri Oct 19 2012 04:16:21 for Milena (Olena) by  doxygen 1.7.1