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
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
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 }
00118
00119 }
00120
00121 }
00122
00123
00124 #endif // ! MLN_IO_PLOT_SAVE_HH