-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathPlotWithDomain.cpp
104 lines (100 loc) · 3.68 KB
/
PlotWithDomain.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "PlotWithDomain.h"
namespace nV {
namespace Graphics {
PlotWithDomain::PlotWithDomain(F1P *f1 ,std::vector<domain *> domains, double ymin, double ymax)
{
f=f1;
this->Domains=domains;
this->WithDomain=true;
this->ymax = ymax;
this->ymin = ymin;
makePoints(domains);
}
PlotWithDomain::PlotWithDomain(F1P *f1 ,std::vector<domain *> domains,F1P *cf, double ymin, double ymax)
{
f=f1;
this->Domains=domains;
this->WithDomain=true;
this->ymax = ymax;
this->ymin = ymin;
makePoints(domains);
isColorfulCurve = true;
this->cf = cf;
useColorFunction();
}
void PlotWithDomain::makePoints(std::vector<domain *> domains)
{
dataNum = getBaseNum();
double *x = new double[dataNum];
double *y = new double[dataNum];
for(std::vector<domain *>::iterator dt=domains.begin();dt!=domains.end();dt++)
{
double xmin=(*dt)->min;
double xmax=(*dt)->max;
//dataNum = getBaseNum() * ((xmax - xmin) / ((*(domains.end() - 1))->max - (*domains.begin())->min));
for (int i = 0; i < dataNum; i++) {
x[i] = xmin + (xmax - xmin) * i / (dataNum - 1);
}
f->getArrayData(x, y, dataNum);
LineStrip* lineStrip;
//add the first in-range point
int i = 0;
while (((y[i] < ymin) || (y[i] > ymax) || isNaN(y[i])) && i < dataNum)
i++;
if (i == dataNum) {
return;
}
lineStrip = new LineStrip;
lineStrips.add(lineStrip);
if (i == 0) {
lineStrip->vert.add(new Point2d(x[i], y[i]));
} else { //xmin point was excluded
double newx = getPointOnRangeFromLeft(x[i-1], x[i], 1);
double newy = f->getSingleData(newx);
lineStrip->vert.add(new Point2d(newx, newy));
lineStrip->vert.add(new Point2d(x[i], y[i]));
}
i++;
int state = 0;
while (i < dataNum) {
if ((y[i] > ymin) && (y[i] < ymax) && !isNaN(y[i])) {
if (state == 0) {
//line strip still going
lineStrip->vert.add(new Point2d(x[i], y[i]));
} else {
//make a new line strip
lineStrip = new LineStrip;
lineStrips.add(lineStrip);
double newx = getPointOnRangeFromLeft(x[i-1], x[i], 1);
double newy = f->getSingleData(newx);
lineStrip->vert.add(new Point2d(newx, newy));
lineStrip->vert.add(new Point2d(x[i], y[i]));
state = 0;
}
} else {
if (state == 0) {
//a line strip ends
double newx = getPointOnRangeFromRight(x[i-1], x[i], 1);
double newy = f->getSingleData(newx);
lineStrip->vert.add(new Point2d(newx, newy));
state = 1;
} else {
//do nothing
}
}
i++;
}
spx = xmax - xmin;
spy = ymax - ymin;
graphScale = spy / spx;
dx = spx / LARGE;
for (unsigned int i = 0; i < lineStrips.size(); i++)
addVerts(lineStrips[i]);
}
delete []x;
delete []y;
}
PlotWithDomain::~PlotWithDomain()
{}
}
}