EMAN2
xydata.h
Go to the documentation of this file.
1/*
2 * Author: Steven Ludtke, 04/10/2003 (sludtke@bcm.edu)
3 * Copyright (c) 2000-2006 Baylor College of Medicine
4 *
5 * This software is issued under a joint BSD/GNU license. You may use the
6 * source code in this file under either license. However, note that the
7 * complete EMAN2 and SPARX software packages have some GPL dependencies,
8 * so you are responsible for compliance with the licenses of these packages
9 * if you opt to use BSD licensing. The warranty disclaimer below holds
10 * in either instance.
11 *
12 * This complete copyright notice must be included in any revised version of the
13 * source code. Additional authorship citations may be added, but existing
14 * author citations must be preserved.
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 *
30 * */
31
32#ifndef eman__xydata_h__
33#define eman__xydata_h__ 1
34
35#include <string>
36#include <vector>
37#include "exception.h"
38
39using std::string;
40using std::vector;
41
42namespace EMAN
43{
46 class XYData
47 {
48 public:
49 struct Pair
50 {
51 Pair(float xx, float yy)
52 :x(xx), y(yy)
53 {
54 }
55
56 bool operator<(const Pair & p) const
57 {
58 return (x < p.x);
59 }
60
61 float x;
62 float y;
63 };
64
65 public:
66 XYData();
67 virtual ~ XYData()
68 {
69 }
70
71 int read_file(const string & filename);
72
73 int write_file(const string & filename) const;
74
75 float calc_correlation(XYData * xy, float minx, float maxx) const;
76
77 void update();
78
79 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
80
81 float get_yatx_smooth(float x,int smoothing); // This will use interpolation to smooth the returned values, and will continue interpolating outside the domain
82 // smoothing=1 (linear) is the only supported mode at the moment
83
84 float get_x(size_t i) const
85 {
86 return data[i].x;
87 }
88
89 void set_x(size_t i, float x)
90 {
91 if (i>=data.size()) data.resize(i+1,Pair(0,0));
92 data[i].x = x;
93 }
94
95 float get_y(size_t i) const
96 {
97 if (i>=data.size()) throw InvalidValueException(i, "Attempt to access XYData out of range");
98 return data[i].y;
99 }
100
101 void set_y(size_t i, float y)
102 {
103 if (i>=data.size()) data.resize(i+1,Pair(0,0));
104 data[i].y = y;
105 }
106
107 // inserts a new value in x-sorted position, lengthens vector by 1
108 void insort(float x, float y);
109
110 // If any identical X values exist, y values will be averaged and a point removed
111 // data must be sorted on X for this to work (see update)
112 void dedupx();
113
114 vector<float> get_xlist() const;
115
116 vector<float> get_ylist() const;
117
118 vector<float> get_state() const;
119
120 void set_state(vector<float>);
121
122 void set_xy_list(const vector<float>& xlist, const vector<float>& ylist);
123
124 // This will create a Gaussian with n points, with x from 0 to xmax and a HWHM of width
125 void make_gauss(int n,float xmax, float width);
126
127 size_t get_size() const
128 {
129 return data.size();
130 }
131
132 void set_size(size_t n);
133
134 float get_miny()
135 {
136// update();
137 return ymin;
138 }
139
140 float get_maxy()
141 {
142// update();
143 return ymax;
144 }
145
146 bool is_validx(float x) const
147 {
148 if (x < data[0].x || x > data[data.size() - 1].x)
149 {
150 return false;
151 }
152 return true;
153 }
154
155 private:
156 vector < Pair > data;
157 float ymin;
158 float ymax;
160 };
161}
162
163
164#endif
XYData defines a 1D (x,y) data set.
Definition: xydata.h:47
float get_maxy()
Definition: xydata.h:140
void make_gauss(int n, float xmax, float width)
Definition: xydata.cpp:162
void update()
Definition: xydata.cpp:53
void set_x(size_t i, float x)
Definition: xydata.h:89
size_t get_size() const
Definition: xydata.h:127
vector< Pair > data
Definition: xydata.h:156
float calc_correlation(XYData *xy, float minx, float maxx) const
Definition: xydata.cpp:129
float get_y(size_t i) const
Definition: xydata.h:95
float get_yatx(float x, bool outzero=true)
Definition: xydata.cpp:172
float get_yatx_smooth(float x, int smoothing)
Definition: xydata.cpp:194
void insort(float x, float y)
Definition: xydata.cpp:233
void set_y(size_t i, float y)
Definition: xydata.h:101
int write_file(const string &filename) const
Definition: xydata.cpp:109
void dedupx()
Definition: xydata.cpp:253
float mean_x_spacing
Definition: xydata.h:159
float ymin
Definition: xydata.h:157
void set_xy_list(const vector< float > &xlist, const vector< float > &ylist)
Definition: xydata.cpp:269
float ymax
Definition: xydata.h:158
bool is_validx(float x) const
Definition: xydata.h:146
float get_x(size_t i) const
Definition: xydata.h:84
vector< float > get_xlist() const
Definition: xydata.cpp:310
vector< float > get_state() const
Definition: xydata.cpp:285
void set_size(size_t n)
Definition: xydata.cpp:280
int read_file(const string &filename)
Definition: xydata.cpp:77
float get_miny()
Definition: xydata.h:134
vector< float > get_ylist() const
Definition: xydata.cpp:321
void set_state(vector< float >)
Definition: xydata.cpp:297
#define InvalidValueException(val, desc)
Definition: exception.h:285
E2Exception class.
Definition: aligner.h:40
#define y(i, j)
Definition: projector.cpp:1516
#define x(i)
Definition: projector.cpp:1517
Pair(float xx, float yy)
Definition: xydata.h:51
bool operator<(const Pair &p) const
Definition: xydata.h:56