00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef eman__xydata_h__
00037 #define eman__xydata_h__ 1
00038
00039 #include <string>
00040 #include <vector>
00041
00042 using std::string;
00043 using std::vector;
00044
00045 namespace EMAN
00046 {
00049 class XYData
00050 {
00051 public:
00052 struct Pair
00053 {
00054 Pair(float xx, float yy)
00055 :x(xx), y(yy)
00056 {
00057 }
00058
00059 bool operator<(const Pair & p) const
00060 {
00061 return (x < p.x);
00062 }
00063
00064 float x;
00065 float y;
00066 };
00067
00068 public:
00069 XYData();
00070 virtual ~ XYData()
00071 {
00072 }
00073
00074 int read_file(const string & filename);
00075
00076 int write_file(const string & filename) const;
00077
00078 float calc_correlation(XYData * xy, float minx, float maxx) const;
00079
00080 void update();
00081
00082 float get_yatx(float x,bool outzero=true);
00083
00084
00085 float get_x(size_t i) const
00086 {
00087 return data[i].x;
00088 }
00089
00090 void set_x(size_t i, float x)
00091 {
00092 if (i>=data.size()) data.resize(i+1,Pair(0,0));
00093 data[i].x = x;
00094 }
00095
00096 float get_y(size_t i) const
00097 {
00098 return data[i].y;
00099 }
00100
00101 void set_y(size_t i, float y)
00102 {
00103 if (i>=data.size()) data.resize(i+1,Pair(0,0));
00104 data[i].y = y;
00105 }
00106
00107 vector<float> get_xlist() const;
00108
00109 vector<float> get_ylist() const;
00110
00111 void set_xy_list(const vector<float>& xlist, const vector<float>& ylist);
00112
00113 size_t get_size() const
00114 {
00115 return data.size();
00116 }
00117
00118 void set_size(size_t n);
00119
00120 float get_miny()
00121 {
00122
00123 return ymin;
00124 }
00125
00126 float get_maxy()
00127 {
00128
00129 return ymax;
00130 }
00131
00132 bool is_validx(float x) const
00133 {
00134 if (x < data[0].x || x > data[data.size() - 1].x)
00135 {
00136 return false;
00137 }
00138 return true;
00139 }
00140
00141 private:
00142 vector < Pair > data;
00143 float ymin;
00144 float ymax;
00145 float mean_x_spacing;
00146 };
00147 }
00148
00149
00150 #endif