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