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,bool outzero=true);              // if outzero is set, values outside the data domain will be 0, otherwise clamped at the edge
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 //                      update();
00123                         return ymin;
00124                 }
00125 
00126                 float get_maxy()
00127                 {
00128 //                      update();
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

Generated on Tue Jun 11 13:46:20 2013 for EMAN2 by  doxygen 1.3.9.1