00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef MLN_IO_PLOT_SAVE_HH
00027 # define MLN_IO_PLOT_SAVE_HH
00028
00032
00033 # include <iostream>
00034 # include <fstream>
00035 # include <mln/core/image/image1d.hh>
00036 # include <mln/util/array.hh>
00037
00038
00039 namespace mln
00040 {
00041
00042 namespace io
00043 {
00044
00045 namespace plot
00046 {
00047
00051 template <typename I>
00052 void save(const image1d<I>& ima,
00053 const std::string& filename);
00054
00060 template <typename T>
00061 void save(util::array<T>& arr,
00062 const std::string& filename,
00063 int start_value = 0);
00064
00065
00066 # ifndef MLN_INCLUDE_ONLY
00067
00068
00069
00070
00071 template <typename T>
00072 inline
00073 void save(const image1d<T>& ima, const std::string& filename)
00074 {
00075 trace::entering("mln::io::plot::save");
00076
00077 std::ofstream file_out(filename.c_str());
00078 unsigned end = ima.bbox().pmax().ind();
00079 for (unsigned i = ima.bbox().pmin().ind(); i <= end; ++i)
00080 file_out << i << " " << ima.at_(i) << std::endl;
00081
00082 trace::exiting("mln::io::plot::save");
00083 }
00084
00085 template <typename T>
00086 inline
00087 void save(const util::array<T>& arr, const std::string& filename,
00088 int start_value = 0)
00089 {
00090 trace::entering("mln::io::plot::save");
00091
00092 std::ofstream file_out(filename.c_str());
00093 for (unsigned i = 0; i < arr.nelements(); ++i)
00094 file_out << start_value + i << " " << arr[i] << std::endl;
00095
00096 trace::exiting("mln::io::plot::save");
00097 }
00098
00099
00100 # endif // ! MLN_INCLUDE_ONLY
00101
00102 }
00103
00104 }
00105
00106 }
00107
00108
00109 #endif // ! MLN_IO_PLOT_SAVE_HH