23 void writePlot(std::string filename,
const std::vector<T>& data);
26 void writePlot(std::string filename,
const std::vector<T>& data,
27 size_t xsize,
size_t ysize);
53 Plotter(
size_t xres = 1024,
size_t yres = 768);
66 int write(std::string fname);
76 int write(
size_t xres,
size_t yres, std::string fname);
103 void setRes(
size_t xres,
size_t yres);
112 void addArray(
size_t sz,
const double* array);
113 void addArray(
size_t sz,
const double* xarr,
const double* yarr);
114 void addArray(
const std::string& style,
size_t sz,
const double* array);
115 void addArray(
const StyleT& style,
size_t sz,
const double* xarr,
const double* yarr);
122 std::list<std::tuple<StyleT, Function>>
funcs;
125 std::list<std::tuple<StyleT, std::vector<double>, std::vector<double>>>
arrs;
143 for(
size_t ii=0; ii<a.size(); ii++) {
146 }
else if(a[ii] ==
'=') {
149 }
else if(a[ii] ==
'-') {
152 }
else if(a[ii] ==
'*') {
154 }
else if(a[ii] ==
'!') {
156 }
else if(a[ii] ==
'#') {
162 for(
int jj=0; ii<a.size() && jj<8; jj++,ii++) {
164 if(a[ii] >=
'A' && a[ii] <=
'F') {
166 rgba[jj/2] = a[ii]-
'A'+10;
168 rgba[jj/2] += (a[ii]-
'A'+10)*16;
169 }
else if(a[ii] >=
'a' && a[ii] <=
'f') {
171 rgba[jj/2] = a[ii]-
'a'+10;
173 rgba[jj/2] += (a[ii]-
'a'+10)*16;
174 }
else if(a[ii] >=
'0' && a[ii] <=
'9') {
176 rgba[jj/2] = a[ii]-
'0';
178 rgba[jj/2] += (a[ii]-
'0')*16;
182 }
else if(a[ii] ==
'r') {
183 rgba[0] = 255; rgba[1] = 0; rgba[2] = 0; rgba[3] = 255;
184 }
else if(a[ii] ==
'g') {
185 rgba[0] = 0; rgba[1] = 255; rgba[2] = 0; rgba[3] = 255;
186 }
else if(a[ii] ==
'b') {
187 rgba[0] = 0; rgba[1] = 0; rgba[2] = 255; rgba[3] = 255;
188 }
else if(a[ii] ==
'k') {
189 rgba[0] = 0; rgba[1] = 0; rgba[2] = 0; rgba[3] = 255;
190 }
else if(a[ii] ==
'w') {
191 rgba[0] = 255; rgba[1] = 255; rgba[2] = 255; rgba[3] = 255;
192 }
else if(a[ii] ==
'y') {
193 rgba[0] = 255; rgba[1] = 255; rgba[2] = 0; rgba[3] = 255;
194 }
else if(a[ii] ==
'p') {
195 rgba[0] = 255; rgba[1] = 0; rgba[2] = 255; rgba[3] = 255;
196 }
else if(a[ii] ==
'G') {
197 rgba[0] = 128; rgba[1] = 128; rgba[2] = 128; rgba[3] = 255;
198 }
else if(a[ii] ==
'c') {
199 rgba[0] = 0; rgba[1] = 255; rgba[2] = 255; rgba[3] = 255;
206 unsigned char rgba[4];
215 void computeRange(
size_t xres);
216 int writeTGA(
size_t xres,
size_t yres, std::string fname);
217 int writeSVG(
size_t xres,
size_t yres, std::string fname);
228 template <
typename T>
229 void writePlot(std::string filename,
const std::vector<T>& data)
232 std::vector<double> tmp(data.size());
233 for(
size_t ii=0; ii<data.size(); ii++)
234 tmp[ii] = (
double)data[ii];
236 plt.
addArray(tmp.size(), tmp.data());
251 template <
typename T>
252 void writePlot(std::string filename,
const std::vector<T>& data,
size_t xsize,
257 std::vector<double> tmp(data.size());
258 for(
size_t ii=0; ii<data.size(); ii++)
259 tmp[ii] = (
double)data[ii];
260 plt.
addArray(tmp.size(), tmp.data());
std::list< StyleT > colors
void setRes(size_t xres, size_t yres)
Sets the default resolution.
int write(std::string fname)
Writes the output image to the given file.
Class for creating basic plots of arrays or functions. An example might be:
double(* Function)(double x)
void addArray(size_t sz, const double *array)
StyleT(std::string name, std::string a)
void setXRange(double low, double high)
Sets the x range. To use the extremal values from input arrays just leave these at the default (NAN's...
void clear()
Removes all state variables, including plotted points, and functions.
void setYRange(double low, double high)
Sets the y range. To use the extremal values from input arrays and computed yvalues from functions...
std::list< std::tuple< StyleT, std::vector< double >, std::vector< double > > > arrs
std::list< StyleT >::iterator curr_color
Plotter(size_t xres=1024, size_t yres=768)
Constructor.
std::list< std::tuple< StyleT, Function > > funcs
void writePlot(std::string filename, const std::vector< T > &data)
Writes a plot to the given filename. This is a convience wrapper around Plotter, which for quick-and-...