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);
00083
00084 float get_x(size_t i) const
00085 {
00086 return data[i].x;
00087 }
00088
00089 void set_x(size_t i, float x)
00090 {
00091 if (i>=data.size()) data.resize(i+1,Pair(0,0));
00092 data[i].x = x;
00093 }
00094
00095 float get_y(size_t i) const
00096 {
00097 return data[i].y;
00098 }
00099
00100 void set_y(size_t i, float y)
00101 {
00102 if (i>=data.size()) data.resize(i+1,Pair(0,0));
00103 data[i].y = y;
00104 }
00105
00106 vector<float> get_xlist() const;
00107
00108 vector<float> get_ylist() const;
00109
00110 void set_xy_list(const vector<float>& xlist, const vector<float>& ylist);
00111
00112 size_t get_size() const
00113 {
00114 return data.size();
00115 }
00116
00117 void set_size(size_t n);
00118
00119 float get_miny()
00120 {
00121
00122 return ymin;
00123 }
00124
00125 float get_maxy()
00126 {
00127
00128 return ymax;
00129 }
00130
00131 bool is_validx(float x) const
00132 {
00133 if (x < data[0].x || x > data[data.size() - 1].x)
00134 {
00135 return false;
00136 }
00137 return true;
00138 }
00139
00140 private:
00141 vector < Pair > data;
00142 float ymin;
00143 float ymax;
00144 float mean_x_spacing;
00145 };
00146 }
00147
00148
00149 #endif