Newer
Older
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
#include <Projection.h>
#include <parser.h>
Projection :: Projection(int ID, string argvComp) :
ID_(ID),
argvComp_(argvComp)
{
//terminal_ = "x11";
terminal_ = "wxt";
border = 0.0;
xmin_ = 0;
xmax_ = 0;
ymin_ = 0;
ymax_ = 0;
geometry_ = PROJECTION;
sRange_ = false;
gplt = new Gnuplot("lines");
gplt->reset_plot();
gplt->cmd("set term %s noraise title 'Projection %d'", terminal_.c_str(), ID);
}
Gnuplot * Projection :: projection()
{
return gplt;
}
void Projection :: addComp(Component *comp_)
{
comp.push_back(comp_);
}
void Projection :: addCmd(Command *cmd_)
{
cmds.push_back(cmd_);
}
void Projection :: geometry(argvOpt g)
{
geometry_ = g;
}
Command * Projection :: cmd(int i)
{
return cmds[i];
}
int Projection :: nCmd()
{
return cmds.size();
}
int Projection :: ID()
{
return ID_;
}
string Projection :: argvComp()
{
return argvComp_;
}
string Projection :: terminal()
{
return terminal_;
}
string Projection :: compToProj(int i)
{
return compToProj_[i];
}
string Projection :: compToLabel(int i)
{
return compToLabel_[i];
}
string Projection :: colorToProj(int i)
{
return colorToProj_[i];
}
int Projection :: nComps()
{
return compToProj_.size();
}
float Projection :: xmin()
{
if ( sRange_ )
return xSmin_;
else
return xmin_;
}
float Projection :: xmax()
{
if ( sRange_ )
return xSmax_;
else
return xmax_;
}
float Projection :: ymin()
{
if ( sRange_ )
return ySmin_;
else
return ymin_;
}
float Projection :: ymax()
{
if ( sRange_ )
return ySmax_;
else
return ymax_;
}
void Projection :: extractArgv()
{
string argvLabel_ = argvComp_;
string argvRange_ = argvComp_;
replaceCompName();
calcRange(argvRange_);
// Strip component names to projection
stringstream ss (argvComp_);
while ( ss.good() )
{
string substr;
getline (ss, substr, ':');
compToProj_.push_back(substr);
}
// apply triangular tranformation
if ( geometry_ == TRIANGLE )
{
if ( compToProj_.size() > 2 )
{
cout << "Triangular projection must have only two components!" << endl;
exit(EXIT_FAILURE);
}
triangularTransform();
}
// Strip component names to Label
stringstream sl (argvLabel_);
while ( sl.good() )
{
string substr;
getline (sl, substr, ':');
compToLabel_.push_back(substr);
}
findColors();
}
void Projection :: calcRange(string argvRange_)
{
Parser prs;
string minRange_ = argvRange_;
string maxRange_ = argvRange_;
stringstream nstr;
// Substitute for min values
for (int i=0; i < comp.size(); i++)
{
nstr << comp[i]->min();
replaceAll (minRange_, comp[i]->name(), nstr.str());
nstr.str(string());
}
// Substitute for max values
for (int i=0; i < comp.size(); i++)
{
nstr << comp[i]->max();
replaceAll (maxRange_, comp[i]->name(), nstr.str());
nstr.str(string());
}
// Strip component names to min Range
vector <float> min;
stringstream s1 (minRange_);
while ( s1.good() )
{
string substr;
getline (s1, substr, ':');
min.push_back(prs.parse(substr.c_str()));
}
// Strip component names to max Range
vector <float> max;
stringstream s2 (maxRange_);
while ( s2.good() )
{
string substr;
getline (s2, substr, ':');
max.push_back(prs.parse(substr.c_str()));
}
xmin_ = min[0];
xmax_ = max[0];
ymin_ = min[1];
ymax_ = max[1];
for (int r=2; r < min.size(); r++)
{
if ( min[r] < ymin_ ) ymin_ = min[r];
if ( max[r] > ymax_ ) ymax_ = max[r];
}
ymin_ = ymin_ - border * (ymax_ - ymin_)/2;
ymax_ = ymax_ + border * (ymax_ - ymin_)/2;
}
void Projection :: replaceCompName()
{
stringstream nstr;
for (int i=0; i < comp.size(); i++)
{
nstr << "$" << i+1;
replaceAll (argvComp_, comp[i]->name(), nstr.str());
nstr.str(string());
}
}
void Projection :: replaceAll(string& str, const string& from, const string& to)
{
if(from.empty())
return;
size_t start_pos = 0;
while((start_pos = str.find(from, start_pos)) != string::npos)
{
str.replace(start_pos, from.length(), to);
start_pos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx'
}
}
bool Projection :: sRange()
{
return sRange_;
}
void Projection :: setSrange(float xmin, float xmax, float ymin, float ymax)
{
xSmin_ = xmin;
xSmax_ = xmax;
ySmin_ = ymin;
ySmax_ = ymax;
sRange_ = true;
}
void Projection :: resetSrange(void)
{
sRange_ = false;
}
void Projection :: triangularTransform()
{
/*
subroutine map ( x, y, xmap, ymap )
real x, y, xmap, ymap
real rt3ov2
data rt3ov2 / 0.8660254 /
xmap = x + 0.5 * y
ymap = rt3ov2 * y
return
end
*/
compToProj_[0] = "(" + compToProj_[0] + "+0.5*" + compToProj_[1] + ")";
compToProj_[1] = "(0.8660254*" + compToProj_[1] + ")";
}
void Projection :: findColors()
{
size_t found;
for (int i=1; i < compToProj_.size(); i++)
{
for (int j=0; j < comp.size(); j++)
{
found = compToProj_[i].find(comp[i]->name());
if ( found != string::npos )
colorToProj_.push_back(comp[i]->color());
}
}
}
void Projection :: showComps()
{
cout << endl << "Projection.showComps() - Available components:" << endl;
for (int i=0; i < comp.size(); i++)
{
cout << "Component Object " << i+1 << endl;
cout << " Name: " << comp[i]->name() << endl;
cout << " Min: " << comp[i]->min() << endl;
cout << " Max: " << comp[i]->max() << endl;
}
cout << endl;
for (int i=0; i < compToProj_.size(); i++)
{
cout << "Comp to project: " << compToProj_[i] << endl;
}
cout << endl;
cout << endl;
}