• 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(const util::array<T>& arr, const std::string& filename,
00062                 int start_value = 0);
00063 
00065       template <typename T>
00066       void save(const histo::array<T>& arr, const std::string& filename);
00067 
00068 # ifndef MLN_INCLUDE_ONLY
00069 
00070 
00071 
00072       // FIXME: Make it generic.
00073       template <typename T>
00074       inline
00075       void save(const image1d<T>& ima, const std::string& filename)
00076       {
00077         trace::entering("mln::io::plot::save");
00078 
00079         std::ofstream file_out(filename.c_str());
00080         unsigned end = ima.bbox().pmax().ind();
00081         for (unsigned i = ima.bbox().pmin().ind(); i <= end; ++i)
00082           file_out << i << " " << ima.at_(i) << std::endl;
00083 
00084         trace::exiting("mln::io::plot::save");
00085       }
00086 
00087       template <typename T>
00088       inline
00089       void save(const util::array<T>& arr, const std::string& filename,
00090                 int start_value = 0)
00091       {
00092         trace::entering("mln::io::plot::save");
00093 
00094         std::ofstream file_out(filename.c_str());
00095         for (unsigned i = 0; i < arr.nelements(); ++i)
00096           file_out << start_value + i << " " << arr[i] << std::endl;
00097 
00098         trace::exiting("mln::io::plot::save");
00099       }
00100 
00101       template <typename T>
00102       inline
00103       void save(const histo::array<T>& arr, const std::string& filename)
00104       {
00105         trace::entering("mln::io::plot::save");
00106 
00107         std::ofstream file_out(filename.c_str());
00108         for (unsigned i = 0; i < arr.nvalues(); ++i)
00109           file_out << i << " " << arr[i] << std::endl;
00110 
00111         trace::exiting("mln::io::plot::save");
00112       }
00113 
00114 
00115 # endif // ! MLN_INCLUDE_ONLY
00116 
00117     } // end of namespace mln::io::plot
00118 
00119   } // end of namespace mln::io
00120 
00121 } // end of namespace mln
00122 
00123 
00124 #endif // ! MLN_IO_PLOT_SAVE_HH

Generated on Tue Oct 4 2011 15:24:23 for Milena (Olena) by  doxygen 1.7.1