Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

xydata.h

Go to the documentation of this file.
00001 
00005 /*
00006  * Author: Steven Ludtke, 04/10/2003 (sludtke@bcm.edu)
00007  * Copyright (c) 2000-2006 Baylor College of Medicine
00008  *
00009  * This software is issued under a joint BSD/GNU license. You may use the
00010  * source code in this file under either license. However, note that the
00011  * complete EMAN2 and SPARX software packages have some GPL dependencies,
00012  * so you are responsible for compliance with the licenses of these packages
00013  * if you opt to use BSD licensing. The warranty disclaimer below holds
00014  * in either instance.
00015  *
00016  * This complete copyright notice must be included in any revised version of the
00017  * source code. Additional authorship citations may be added, but existing
00018  * author citations must be preserved.
00019  *
00020  * This program is free software; you can redistribute it and/or modify
00021  * it under the terms of the GNU General Public License as published by
00022  * the Free Software Foundation; either version 2 of the License, or
00023  * (at your option) any later version.
00024  *
00025  * This program is distributed in the hope that it will be useful,
00026  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00027  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00028  * GNU General Public License for more details.
00029  *
00030  * You should have received a copy of the GNU General Public License
00031  * along with this program; if not, write to the Free Software
00032  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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 //                      update();
00122                         return ymin;
00123                 }
00124 
00125                 float get_maxy()
00126                 {
00127 //                      update();
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

Generated on Tue May 25 17:34:17 2010 for EMAN2 by  doxygen 1.4.4