inlib
1.2.0
|
00001 // Copyright (C) 2010, Guy Barrand. All rights reserved. 00002 // See the file inlib.license for terms. 00003 00004 #ifndef inlib_sg_vec2plot 00005 #define inlib_sg_vec2plot 00006 00007 // Inheritance : 00008 #include "plottable" 00009 00010 #include "../smanip" 00011 #include "../vmanip" 00012 #include "../mnmx" 00013 00014 namespace inlib { 00015 namespace sg { 00016 00017 template <class T> 00018 class xy2plot : public virtual points2D { 00019 public: //plottable 00020 virtual plottable* copy() const {return new xy2plot(*this);} 00021 virtual bool is_valid() const {return true;} 00022 virtual std::string name(){return m_name;} 00023 virtual void set_name(const std::string& a_s) {m_name = a_s;} 00024 virtual std::string title(){return "";} 00025 virtual std::string legend(){return m_legend;} 00026 virtual void set_legend(const std::string& a_s) {m_legend = a_s;} 00027 00028 virtual std::string infos(const std::string& a_opts){ 00029 std::string f_lf("\n"); 00030 std::string sinfos; 00031 std::vector<std::string> words; 00032 inlib::words(a_opts," ",false,words); 00033 std::vector<std::string>::const_iterator it; 00034 00035 for(it=words.begin();it!=words.end();++it) { 00036 if(((*it)=="name") && m_name.size()) { 00037 if(sinfos.size()) sinfos += f_lf; 00038 sinfos += "Name\n"; 00039 sinfos += m_name; 00040 00041 } else if((*it)=="entries") { 00042 if(sinfos.size()) sinfos += f_lf; 00043 sinfos += "Entries\n"; 00044 sinfos += inlib::to<int> 00045 (inlib::mn<unsigned int>(m_x.size(),m_y.size())); 00046 00047 } 00048 } 00049 00050 return sinfos; 00051 } 00052 public: //points2D 00053 virtual float x_axis_min() const {return float(m_x_min);} 00054 virtual float x_axis_max() const {return float(m_x_max);} 00055 virtual float y_axis_min() const {return float(m_y_min);} 00056 virtual float y_axis_max() const {return float(m_y_max);} 00057 00058 virtual unsigned int points() const { 00059 return inlib::mn<unsigned int>(m_x.size(),m_y.size()); 00060 } 00061 virtual bool ith_point(unsigned int a_index,float& a_x,float& a_y) const { 00062 if(a_index>=m_x.size()) {a_x = T();a_y = T();return false;} 00063 if(a_index>=m_y.size()) {a_x = T();a_y = T();return false;} 00064 a_x = m_x[a_index]; 00065 a_y = m_y[a_index]; 00066 return true; 00067 } 00068 public: 00069 typedef typename std::vector<T> data_t; 00070 public: 00071 xy2plot(const data_t& a_x,const data_t& a_y) 00072 :m_x(a_x) 00073 ,m_y(a_y) 00074 { 00075 inlib::minimum<T>(a_x,m_x_min); 00076 inlib::maximum<T>(a_x,m_x_max); 00077 00078 inlib::minimum<T>(a_y,m_y_min); 00079 inlib::maximum<T>(a_y,m_y_max); 00080 } 00081 virtual ~xy2plot(){} 00082 protected: 00083 xy2plot(const xy2plot& a_from) 00084 :plottable(a_from),points2D(a_from) 00085 ,m_x(a_from.m_x) 00086 ,m_y(a_from.m_y) 00087 ,m_name(a_from.m_name) 00088 ,m_legend(a_from.m_legend) 00089 ,m_x_min(a_from.m_x_min) 00090 ,m_x_max(a_from.m_x_max) 00091 ,m_y_min(a_from.m_y_min) 00092 ,m_y_max(a_from.m_y_max) 00093 {} 00094 private: 00095 xy2plot& operator=(const xy2plot&){return *this;} 00096 private: 00097 const data_t& m_x; 00098 const data_t& m_y; 00099 std::string m_name; 00100 std::string m_legend; 00101 T m_x_min; 00102 T m_x_max; 00103 T m_y_min; 00104 T m_y_max; 00105 private: 00106 static void check_instantiation() { 00107 std::vector< std::pair<float,float> > data; 00108 xy2plot<float> dummy(data); 00109 } 00110 }; 00111 00112 }} 00113 00114 #endif