source: trunk/src/Plotter2.cpp

Last change on this file was 2909, checked in by WataruKawasaki, 10 years ago

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: No

What Interface Changed:

Test Programs:

Put in Release Notes:

Module(s): sd

Description: (1) a bug fix in sd.scantable.parse_spw_selection(). modified to get rest frequency value correctly based on molecule ID stored for each spw (the first spectrum having the specified spw in scantable). (2) renamed 'annotation' to 'text' in class or variable names for sd.plotter2.


File size: 39.9 KB
Line 
1#include "Plotter2.h"
2
3namespace asap {
4
5Plotter2TextInfo::Plotter2TextInfo() {
6    text = "";
7    posx = 0.0;
8    posy = 0.0;
9    angle = 0.0;
10    fjust = 0.0;
11    size = 1.0;
12    color = 1;    // black
13    bgcolor = -1; // transparent
14}
15
16Plotter2TextInfo::~Plotter2TextInfo() {
17}
18
19Plotter2ArrowInfo::Plotter2ArrowInfo() {
20    xhead = 1.0;
21    xtail = 0.0;
22    yhead = 1.0;
23    ytail = 0.0;
24    color = 1;         // black
25    width = 1;
26    lineStyle = 1;     // solid line
27    headSize = 1.0;
28    headFillStyle = 1; // solid
29    headAngle = 45.0;
30    headVent = 0.3;
31}
32
33Plotter2ArrowInfo::~Plotter2ArrowInfo() {
34}
35
36Plotter2RectInfo::Plotter2RectInfo() {
37    xmin = 0.0;
38    xmax = 1.0;
39    ymin = 0.0;
40    ymax = 1.0;
41    color = 15; // gray
42    fill  = 4;  // hatch
43    width = 1;
44}
45
46Plotter2RectInfo::~Plotter2RectInfo() {
47}
48
49Plotter2DataInfo::Plotter2DataInfo() {
50    xData.clear();
51    yData.clear();
52
53    drawLine  = true;
54    lineStyle = 1;       // solid line
55    lineWidth = 1;
56    lineColor = -1;      // undefined (default color should be assigned)
57
58    drawMarker  = false;
59    markerType  = 20;    // small circle
60    markerSize  = 1.0;
61    markerColor = 1;     // default foreground color (black)
62
63    hasData = false;     // has no data
64}
65
66Plotter2DataInfo::~Plotter2DataInfo() {
67}
68
69Plotter2ViewportInfo::Plotter2ViewportInfo() {
70    showViewport = true;
71
72    vpPosXMin = 0.1;
73    vpPosXMax = 0.9;
74    vpPosYMin = 0.1;
75    vpPosYMax = 0.9;
76
77    vpRangeXMin = 0.0;
78    vpRangeXMax = 1.0;
79    vpRangeYMin = 0.0;
80    vpRangeYMax = 1.0;
81    isAutoRangeX = true;
82    isAutoRangeY = true;
83    autoRangeMarginX = 0.0;
84    autoRangeMarginY = 0.1;
85
86    hasDataRange = false;
87
88    isAutoTickIntervalX = true;
89    isAutoTickIntervalY = true;
90    majorTickIntervalX = 0.1;
91    majorTickIntervalY = 0.1;
92    nMajorTickWithinTickNumsX = 2;
93    nMajorTickWithinTickNumsY = 2;
94    nMinorTickWithinMajorTicksX = 5;
95    nMinorTickWithinMajorTicksY = 5;
96
97    numLocationX = "b";
98    numLocationY = "l";
99
100    fontSizeDef = 1.0;
101
102    vData.clear();
103    vRect.clear();
104    vArro.clear();
105    vText.clear();
106
107    labelXString = "";
108    labelXPosX = 0.5;
109    labelXPosY = 0.05;
110    labelXAngle = 0.0;
111    labelXFJust = 0.5;
112    labelXSize = fontSizeDef * 1.1;
113    labelXColor = 1;
114    labelXBColor = 0;
115
116    labelYString = "";
117    labelYPosX = 0.05;
118    labelYPosY = 0.5;
119    labelYAngle = 90.0;
120    labelYFJust = 0.5;
121    labelYSize = fontSizeDef * 1.1;
122    labelYColor = 1;
123    labelYBColor = 0;
124
125    titleString = "";
126    titlePosX = 0.5;
127    titlePosY = 0.95;
128    titleAngle = 0.0;
129    titleFJust = 0.5;
130    titleSize = fontSizeDef * 1.5;
131    titleColor = 1;
132    titleBColor = 0;
133
134    vpBColor = -1; // transparent (<0)
135}
136
137Plotter2ViewportInfo::~Plotter2ViewportInfo() {
138    vData.clear();
139    vRect.clear();
140    vArro.clear();
141    vText.clear();
142}
143
144void Plotter2ViewportInfo::adjustRange() {
145    if (hasDataRange) {
146        if (isAutoRangeX) {
147            adjustRangeX(&vpRangeXMin, &vpRangeXMax);
148        }
149        if (isAutoRangeY) {
150            adjustRangeY(&vpRangeYMin, &vpRangeYMax);
151        }
152    }
153}
154
155void Plotter2ViewportInfo::adjustRangeX(float* xmin, float* xmax) {
156    float xmargin = (maxXData - minXData) * autoRangeMarginX;
157    *xmin = minXData - xmargin;
158    *xmax = maxXData + xmargin;
159}
160
161void Plotter2ViewportInfo::adjustRangeY(float* ymin, float* ymax) {
162    float ymargin = (maxYData - minYData) * autoRangeMarginY;
163    *ymin = minYData - ymargin;
164    *ymax = maxYData + ymargin;
165}
166
167std::vector<float> Plotter2ViewportInfo::getRangeX() {
168    float minX, maxX;
169
170    if (isAutoRangeX) {
171        adjustRangeX(&minX, &maxX);
172    } else {
173        minX = vpRangeXMin;
174        maxX = vpRangeXMax;
175    }
176
177    std::vector<float> res;
178    res.clear();
179    res.push_back(minX);
180    res.push_back(maxX);
181
182    return res;
183}
184
185std::vector<float> Plotter2ViewportInfo::getRangeY() {
186    float minY, maxY;
187
188    if (isAutoRangeY) {
189        adjustRangeY(&minY, &maxY);
190    } else {
191        minY = vpRangeYMin;
192        maxY = vpRangeYMax;
193    }
194
195    std::vector<float> res;
196    res.clear();
197    res.push_back(minY);
198    res.push_back(maxY);
199
200    return res;
201}
202
203void Plotter2ViewportInfo::adjustTickInterval() {
204    if (hasDataRange) {
205        if (isAutoTickIntervalX) {
206            adjustTickIntervalX(vpRangeXMin, vpRangeXMax);
207        }
208        if (isAutoTickIntervalY) {
209            adjustTickIntervalY(vpRangeYMin, vpRangeYMax);
210        }
211    }
212}
213
214void Plotter2ViewportInfo::adjustTickIntervalX(const float xmin, const float xmax) {
215    majorTickIntervalX = (float)pow(10.0, ceil(log10((xmax - xmin)/10.0)));
216    if ((xmax - xmin) / majorTickIntervalX < 4.0) {
217        majorTickIntervalX /= 2.0;
218    }
219    if ((xmax - xmin) / majorTickIntervalX < 4.0) {
220        majorTickIntervalX /= 2.0;
221    }
222}
223
224void Plotter2ViewportInfo::adjustTickIntervalY(const float ymin, const float ymax) {
225    majorTickIntervalY = (float)pow(10.0, ceil(log10((ymax - ymin)/10.0)));
226    if ((ymax - ymin) / majorTickIntervalY < 4.0) {
227        majorTickIntervalY /= 2.0;
228    }
229    if ((ymax - ymin) / majorTickIntervalY < 4.0) {
230        majorTickIntervalY /= 2.0;
231    }
232}
233
234void Plotter2ViewportInfo::setData(const std::vector<float>& inXData, const std::vector<float>& inYData, const int id) {
235    if (!hasDataRange) {
236        minXData = inXData[0];
237        maxXData = inXData[0];
238        minYData = inYData[0];
239        maxYData = inYData[0];
240
241        hasDataRange = true;
242    }
243
244    Plotter2DataInfo* info = &vData[id];
245
246    info->xData.clear();
247    info->xData.reserve(inXData.size());
248    for (unsigned int i = 0; i < inXData.size(); ++i) {
249        info->xData.push_back(inXData[i]);
250
251        if (!info->hasData) {
252            updateXDataRange(inXData[i]);
253        }
254    }
255
256    info->yData.clear();
257    info->yData.reserve(inYData.size());
258    for (unsigned int i = 0; i < inYData.size(); ++i) {
259        info->yData.push_back(inYData[i]);
260
261        if (!info->hasData) {
262            updateYDataRange(inYData[i]);
263        }
264    }
265
266    if (info->hasData) {
267        updateAllDataRanges();
268    } else {
269        info->hasData = true;
270    }
271
272    adjustRange();
273    adjustTickInterval();
274}
275
276void Plotter2ViewportInfo::updateXDataRange(const float data) {
277    if (data < minXData) {
278        minXData = data;
279    }
280    if (maxXData < data) {
281        maxXData = data;
282    }
283}
284
285void Plotter2ViewportInfo::updateYDataRange(const float data) {
286    if (data < minYData) {
287        minYData = data;
288    }
289    if (maxYData < data) {
290        maxYData = data;
291    }
292}
293
294void Plotter2ViewportInfo::updateAllDataRanges() {
295    minXData = vData[0].xData[0];
296    maxXData = minXData;
297    minYData = vData[0].yData[0];
298    maxYData = minYData;
299
300    for (unsigned int i = 0; i < vData.size(); ++i) {
301        for (unsigned int j = 0; j < vData[i].xData.size(); ++j) {
302            updateXDataRange(vData[i].xData[j]);
303            updateYDataRange(vData[i].yData[j]);
304        }
305    }
306}
307
308void Plotter2ViewportInfo::getWorldCoordByWindowCoord(const float winX, const float winY, float* worldX, float* worldY) {
309    float xratio = (winX - vpPosXMin) / (vpPosXMax - vpPosXMin);
310    if (winX < 0.0) {
311        xratio = 0.5;
312    }
313    *worldX = vpRangeXMin + xratio * (vpRangeXMax - vpRangeXMin);
314    float yratio = (winY - vpPosYMin) / (vpPosYMax - vpPosYMin);
315    if (winY < 0.0) {
316        yratio = 0.5;
317    }
318    *worldY = vpRangeYMin + yratio * (vpRangeYMax - vpRangeYMin);
319}
320
321Plotter2::Plotter2() {
322    filename = "";
323    device = "xwindow";
324    hasDevice = false;
325
326    vInfo.clear();
327    Plotter2ViewportInfo vi;
328    vInfo.push_back(vi);
329
330    hasDefaultViewport = true;
331    currentViewportId = 0;
332
333    width = 8.82796; // default viewsurface width seems to be this value.
334    aspect = 0.75;   // default viewsurface aspect
335}
336
337Plotter2::~Plotter2() {
338    close();
339    vInfo.clear();
340}
341
342std::string Plotter2::getFileName() {
343    return filename;
344}
345
346void Plotter2::setFileName(const std::string& inFilename) {
347    filename = inFilename;
348}
349
350std::string Plotter2::getDevice() {
351    return device;
352}
353
354void Plotter2::setDevice(const std::string& inDevice) {
355    device = inDevice;
356}
357
358void Plotter2::open() {
359    cpgopen((filename + "/" + device).c_str());
360    hasDevice = true;
361}
362
363float Plotter2::getViewSurfaceWidth() {
364    return width;
365}
366
367float Plotter2::getViewSurfaceAspect() {
368    return aspect;
369}
370
371void Plotter2::setViewSurface(const float inWidth, const float inAspect) {
372    width = inWidth;
373    aspect = inAspect;
374}
375
376int Plotter2::addViewport(const float xmin, const float xmax, const float ymin, const float ymax) {
377    Plotter2ViewportInfo vi;
378
379    vi.vpPosXMin = xmin;
380    vi.vpPosXMax = xmax;
381    vi.vpPosYMin = ymin;
382    vi.vpPosYMax = ymax;
383
384    vInfo.push_back(vi);
385    currentViewportId = vInfo.size() - 1;
386
387    return currentViewportId;
388}
389
390void Plotter2::setViewport(const float xmin, const float xmax, const float ymin, const float ymax, const int id) {
391  if (id >= (int)vInfo.size()) {
392      return;
393    }
394    Plotter2ViewportInfo* vi = &vInfo[id];
395
396    vi->vpPosXMin = xmin;
397    vi->vpPosXMax = xmax;
398    vi->vpPosYMin = ymin;
399    vi->vpPosYMax = ymax;
400
401    hasDefaultViewport = false;
402}
403
404void Plotter2::showViewport(const int inVpid) {
405    int vpid = inVpid;
406    if (vpid >= (int)vInfo.size()) {
407        return;
408    }
409    if (vpid < 0) {
410        vpid = vInfo.size() - 1;
411    }
412    if (vpid < 0) {
413        exit(0);
414    }
415
416    Plotter2ViewportInfo* vi = &vInfo[vpid];
417    vi->showViewport = true;
418}
419
420void Plotter2::hideViewport(const int inVpid) {
421    int vpid = inVpid;
422    if (vpid >= (int)vInfo.size()) {
423        return;
424    }
425    if (vpid < 0) {
426        vpid = vInfo.size() - 1;
427    }
428    if (vpid < 0) {
429        exit(0);
430    }
431
432    Plotter2ViewportInfo* vi = &vInfo[vpid];
433    vi->showViewport = false;
434}
435
436bool Plotter2::getHasDefaultViewport() {
437    return hasDefaultViewport;
438}
439
440int Plotter2::getCurrentViewportId() {
441    return currentViewportId;
442}
443
444void Plotter2::getViewInfo() {
445    std::string colorNames[16] = {"white", "black", "red", "green",
446                                  "blue", "cyan", "magenta", "yellow",
447                                  "orange", "yellowgreen", "emerald", "skyblue",
448                                  "purple", "pink", "gray", "lightgray"};
449    std::string lstyleNames[6] = {"", "solid", "dashed", "dash-dotted", "dotted", "dash-dot-dot-dotted"};
450    std::string fstyleNames[5] = {"", "solid", "outline", "hatched", "crosshatched"};
451
452    for (unsigned int i = 0; i < vInfo.size(); ++i) {
453        std::cout << "Viewport [ID = " << i << "] (" << (i+1) << "/" << vInfo.size() << ") ";
454        std::cout << "=============================================================" << std::endl;
455
456        std::cout << "  Visible: " << (vInfo[i].showViewport ? "Yes" : "No") << std::endl;
457
458        std::cout << "  Position in Window Coordinate: ";
459        std::cout << "X(left=" << vInfo[i].vpPosXMin << ",right=" << vInfo[i].vpPosXMax << "), ";
460        std::cout << "Y(bottom=" << vInfo[i].vpPosYMin << ",top=" << vInfo[i].vpPosYMax << ")" << std::endl;
461
462        std::cout << "  Display Range: ";
463        std::cout << "X(" << (vInfo[i].isAutoRangeX ? "automatic" : "manual") << ", ";
464        std::cout << "min=" << vInfo[i].vpRangeXMin << ", max=" << vInfo[i].vpRangeXMax << "), ";
465        std::cout << "Y(" << (vInfo[i].isAutoRangeY ? "automatic" : "manual") << ", ";
466        std::cout << "min=" << vInfo[i].vpRangeYMin << ", max=" << vInfo[i].vpRangeYMax << ")" << std::endl;
467
468        std::cout << "  Numbering/Ticks:" << std::endl;
469        std::cout << "    X(" << ((vInfo[i].numLocationX == "b") ? "bottom" : ((vInfo[i].numLocationX == "t") ? "top" : (vInfo[i].numLocationX + " [*INVAILD*]"))) << ", interval[" << (vInfo[i].isAutoTickIntervalX ? "automatic" : "manual") << ", ";
470        std::cout << "numbering=" << (vInfo[i].majorTickIntervalX * vInfo[i].nMajorTickWithinTickNumsX) << ", ";
471        std::cout << "majortick=" << vInfo[i].majorTickIntervalX << ", ";
472        std::cout << "minortick=" << (vInfo[i].majorTickIntervalX / vInfo[i].nMinorTickWithinMajorTicksX) << "])" << std::endl;
473        std::cout << "    Y(" << ((vInfo[i].numLocationY == "l") ? "left" : ((vInfo[i].numLocationY == "r") ? "right" : (vInfo[i].numLocationY + " [*INVAILD*]"))) << ", interval[" << (vInfo[i].isAutoTickIntervalY ? "automatic" : "manual") << ", ";
474        std::cout << "numbering=" << (vInfo[i].majorTickIntervalY * vInfo[i].nMajorTickWithinTickNumsY) << ", ";
475        std::cout << "majortick=" << vInfo[i].majorTickIntervalY << ", ";
476        std::cout << "minortick=" << (vInfo[i].majorTickIntervalY / vInfo[i].nMinorTickWithinMajorTicksY) << "])" << std::endl;
477
478        std::cout << "  X Label: ";
479        if (vInfo[i].labelXString != "") {
480            std::cout << "\"" << vInfo[i].labelXString << "\"" << std::endl;
481            std::cout << "    position=(" << vInfo[i].labelXPosX << "," << vInfo[i].labelXPosY << "), ";
482            std::cout << "justification=" << vInfo[i].labelXFJust << ", ";
483            std::cout << "angle=" << vInfo[i].labelXAngle << "deg, ";
484            std::cout << "fontsize=" << vInfo[i].labelXSize << std::endl;
485        } else {
486            std::cout << "No" << std::endl;
487        }
488
489        std::cout << "  Y Label: ";
490        if (vInfo[i].labelYString != "") {
491            std::cout << "\"" << vInfo[i].labelYString << "\"" << std::endl;
492            std::cout << "    position=(" << vInfo[i].labelYPosX << "," << vInfo[i].labelYPosY << "), ";
493            std::cout << "justification=" << vInfo[i].labelYFJust << ", ";
494            std::cout << "angle=" << vInfo[i].labelYAngle << "deg, ";
495            std::cout << "fontsize=" << vInfo[i].labelYSize << std::endl;
496        } else {
497            std::cout << "No" << std::endl;
498        }
499
500        std::cout << "  Title: ";
501        if (vInfo[i].titleString != "") {
502            std::cout << "\"" << vInfo[i].titleString << "\"" << std::endl;
503            std::cout << "    position=(" << vInfo[i].titlePosX << "," << vInfo[i].titlePosY << "), ";
504            std::cout << "justification=" << vInfo[i].titleFJust << ", ";
505            std::cout << "angle=" << vInfo[i].titleAngle << "deg, ";
506            std::cout << "fontsize=" << vInfo[i].titleSize << std::endl;
507        } else {
508            std::cout << "No" << std::endl;
509        }
510
511        std::cout << "  Background Color = ";
512        if (vInfo[i].vpBColor < 0) {
513            std::cout << "transparent" << std::endl;
514        } else if (vInfo[i].vpBColor < 16) {
515            std::cout << colorNames[vInfo[i].vpBColor] << std::endl;
516        } else {
517            std::cout << "index:" << vInfo[i].vpBColor << " [INVAILD VALUE!]" << std::endl;
518        }
519
520        for (unsigned int j = 0; j < vInfo[i].vData.size(); ++j) {
521            std::cout << "  Dataset [ID = " << j << "] (" << (j+1) << "/" << vInfo[i].vData.size() << ") ";
522            std::cout << "----------------------------------------------" << std::endl;
523
524            bool showDataset = (vInfo[i].vData[j].drawLine || vInfo[i].vData[j].drawMarker);
525            bool showViewport = vInfo[i].showViewport;
526            std::cout << "    Visible: " << (showViewport ? "" : "(");
527            std::cout << (showDataset ? "Yes" : "No") << (showViewport ? "" : ")") << std::endl;
528            std::cout << "    Number of Data Points: " << vInfo[i].vData[j].xData.size() << std::endl;
529            if (vInfo[i].vData[j].drawLine) {
530                std::cout << "    Line: color=";
531                if (vInfo[i].vData[j].lineColor < 0) {
532                  int defaultColorIdx = (j + 1) % 15 + 1;
533                    std::cout << "default(" << colorNames[defaultColorIdx] << ")";
534                } else if (vInfo[i].vData[j].lineColor < 16) {
535                    std::cout << colorNames[vInfo[i].vData[j].lineColor];
536                } else {
537                    std::cout << "index:" << vInfo[i].vData[j].lineColor << " [*INVAILD*]";
538                }
539                std::cout << ", width=" << vInfo[i].vData[j].lineWidth;
540                std::cout << ", style=" << lstyleNames[vInfo[i].vData[j].lineStyle] << std::endl;
541            }
542            if (vInfo[i].vData[j].drawMarker) {
543                std::cout << "    Marker: color=";
544                if (vInfo[i].vData[j].markerColor < 0) {
545                    std::cout << "default";
546                } else if (vInfo[i].vData[j].markerColor < 16) {
547                    std::cout << colorNames[vInfo[i].vData[j].markerColor];
548                } else {
549                    std::cout << "index:" << vInfo[i].vData[j].markerColor << " [*INVAILD*]";
550                }
551                std::cout << ", shape=" << vInfo[i].vData[j].markerType;
552                std::cout << ", size=" << vInfo[i].vData[j].markerSize << std::endl;
553            }
554
555        }
556
557        for (unsigned int j = 0; j < vInfo[i].vRect.size(); ++j) {
558            std::cout << "  XMask [ID = " << j << "] (" << (j+1) << "/" << vInfo[i].vRect.size() << ") ";
559            std::cout << "----------------------------------------------" << std::endl;
560            std::cout << "    Range: (min=" << vInfo[i].vRect[j].xmin << ", max=" << vInfo[i].vRect[j].xmax << ")" << std::endl;
561            std::cout << "    Attributes: (color=" << colorNames[vInfo[i].vRect[j].color];
562            std::string fstyle = fstyleNames[vInfo[i].vRect[j].fill];
563            std::cout << ", fillstyle=" << fstyle;
564            if (fstyle == "outline") {
565                std::cout << ", outlinewidth=" << vInfo[i].vRect[j].width;
566            }
567            if ((fstyle == "hatched")||(fstyle == "crosshatched")) {
568                std::cout << ", hatchspacing=" << vInfo[i].vRect[j].hsep;
569            }
570            std::cout << ")" << std::endl;
571        }
572    }
573    std::cout << "=====================================================================================" << std::endl << std::flush;
574}
575
576void Plotter2::setRange(const float xmin, const float xmax, const float ymin, const float ymax, const int inVpid) {
577    setRangeX(xmin, xmax, inVpid);
578    setRangeY(ymin, ymax, inVpid);
579}
580
581void Plotter2::setRangeX(const float xmin, const float xmax, const int inVpid) {
582    int vpid = inVpid;
583    if (vpid >= (int)vInfo.size()) {
584        return;
585    }
586    if (vpid < 0) {
587        vpid = vInfo.size() - 1;
588    }
589    if (vpid < 0) {
590        Plotter2ViewportInfo vi;
591        vInfo.push_back(vi);
592        vpid = 0;
593    }
594
595    Plotter2ViewportInfo* vi = &vInfo[vpid];
596    vi->vpRangeXMin = xmin;
597    vi->vpRangeXMax = xmax;
598    vi->isAutoRangeX = false;
599}
600
601void Plotter2::setRangeY(const float ymin, const float ymax, const int inVpid) {
602    int vpid = inVpid;
603    if (vpid >= (int)vInfo.size()) {
604        return;
605    }
606    if (vpid < 0) {
607        vpid = vInfo.size() - 1;
608    }
609    if (vpid < 0) {
610        Plotter2ViewportInfo vi;
611        vInfo.push_back(vi);
612        vpid = 0;
613    }
614
615    Plotter2ViewportInfo* vi = &vInfo[vpid];
616    vi->vpRangeYMin = ymin;
617    vi->vpRangeYMax = ymax;
618    vi->isAutoRangeY = false;
619}
620
621std::vector<float> Plotter2::getRangeX(const int inVpid) {
622    int vpid = inVpid;
623    if (vpid >= (int)vInfo.size()) {
624        exit(0);
625    }
626    if (vpid < 0) {
627        vpid = vInfo.size() - 1;
628    }
629    if (vpid < 0) {
630        exit(0);
631    }
632
633    return vInfo[vpid].getRangeX();
634}
635
636std::vector<float> Plotter2::getRangeY(const int inVpid) {
637    int vpid = inVpid;
638    if (vpid >= (int)vInfo.size()) {
639        exit(0);
640    }
641    if (vpid < 0) {
642        vpid = vInfo.size() - 1;
643    }
644    if (vpid < 0) {
645        exit(0);
646    }
647
648    return vInfo[vpid].getRangeY();
649}
650
651void Plotter2::setAutoRange(const int inVpid) {
652    setAutoRangeX(inVpid);
653    setAutoRangeY(inVpid);
654}
655
656void Plotter2::setAutoRangeX(const int inVpid) {
657    int vpid = inVpid;
658    if (vpid >= (int)vInfo.size()) {
659        exit(0);
660    }
661    if (vpid < 0) {
662        vpid = vInfo.size() - 1;
663    }
664    if (vpid < 0) {
665        Plotter2ViewportInfo vi;
666        vInfo.push_back(vi);
667        vpid = 0;
668    }
669
670    Plotter2ViewportInfo* vi = &vInfo[vpid];
671    vi->isAutoRangeX = true;
672}
673
674void Plotter2::setAutoRangeY(const int inVpid) {
675    int vpid = inVpid;
676    if (vpid >= (int)vInfo.size()) {
677        exit(0);
678    }
679    if (vpid < 0) {
680        vpid = vInfo.size() - 1;
681    }
682    if (vpid < 0) {
683        Plotter2ViewportInfo vi;
684        vInfo.push_back(vi);
685        vpid = 0;
686    }
687
688    Plotter2ViewportInfo* vi = &vInfo[vpid];
689    vi->isAutoRangeY = true;
690}
691
692void Plotter2::setFontSizeDef(const float size, const int inVpid) {
693    int vpid = inVpid;
694    if (vpid >= (int)vInfo.size()) {
695        exit(0);
696    }
697    if (vpid < 0) {
698        vpid = vInfo.size() - 1;
699    }
700    if (vpid < 0) {
701        Plotter2ViewportInfo vi;
702        vInfo.push_back(vi);
703        vpid = 0;
704    }
705
706    Plotter2ViewportInfo* vi = &vInfo[vpid];
707    vi->fontSizeDef = size;
708}
709
710void Plotter2::setTicksX(const float interval, const int num, const int inVpid) {
711    int vpid = inVpid;
712    if (vpid >= (int)vInfo.size()) {
713        exit(0);
714    }
715    if (vpid < 0) {
716        vpid = vInfo.size() - 1;
717    }
718    if (vpid < 0) {
719        Plotter2ViewportInfo vi;
720        vInfo.push_back(vi);
721        vpid = 0;
722    }
723
724    Plotter2ViewportInfo* vi = &vInfo[vpid];
725    vi->majorTickIntervalX = interval;
726    vi->nMinorTickWithinMajorTicksX = num;
727    vi->isAutoTickIntervalX = false;
728}
729
730void Plotter2::setTicksY(const float interval, const int num, const int inVpid) {
731    int vpid = inVpid;
732    if (vpid >= (int)vInfo.size()) {
733        exit(0);
734    }
735    if (vpid < 0) {
736        vpid = vInfo.size() - 1;
737    }
738    if (vpid < 0) {
739        Plotter2ViewportInfo vi;
740        vInfo.push_back(vi);
741        vpid = 0;
742    }
743
744    Plotter2ViewportInfo* vi = &vInfo[vpid];
745    vi->majorTickIntervalY = interval;
746    vi->nMinorTickWithinMajorTicksY = num;
747    vi->isAutoTickIntervalY = false;
748}
749
750void Plotter2::setAutoTicks(const int inVpid) {
751    setAutoTicksX(inVpid);
752    setAutoTicksY(inVpid);
753}
754
755void Plotter2::setAutoTicksX(const int inVpid) {
756    int vpid = inVpid;
757    if (vpid >= (int)vInfo.size()) {
758        exit(0);
759    }
760    if (vpid < 0) {
761        vpid = vInfo.size() - 1;
762    }
763    if (vpid < 0) {
764        Plotter2ViewportInfo vi;
765        vInfo.push_back(vi);
766        vpid = 0;
767    }
768
769    Plotter2ViewportInfo* vi = &vInfo[vpid];
770    vi->isAutoTickIntervalX = true;
771}
772
773void Plotter2::setAutoTicksY(const int inVpid) {
774    int vpid = inVpid;
775    if (vpid >= (int)vInfo.size()) {
776        exit(0);
777    }
778    if (vpid < 0) {
779        vpid = vInfo.size() - 1;
780    }
781    if (vpid < 0) {
782        Plotter2ViewportInfo vi;
783        vInfo.push_back(vi);
784        vpid = 0;
785    }
786
787    Plotter2ViewportInfo* vi = &vInfo[vpid];
788    vi->isAutoTickIntervalY = true;
789}
790
791void Plotter2::setNumIntervalX(const float interval, const int inVpid) {
792    int vpid = inVpid;
793    if (vpid >= (int)vInfo.size()) {
794        exit(0);
795    }
796    if (vpid < 0) {
797        vpid = vInfo.size() - 1;
798    }
799    if (vpid < 0) {
800        Plotter2ViewportInfo vi;
801        vInfo.push_back(vi);
802        vpid = 0;
803    }
804
805    Plotter2ViewportInfo* vi = &vInfo[vpid];
806    vi->nMajorTickWithinTickNumsX = (int)(interval / vi->majorTickIntervalX);
807}
808
809void Plotter2::setNumIntervalY(const float interval, const int inVpid) {
810    int vpid = inVpid;
811    if (vpid >= (int)vInfo.size()) {
812        exit(0);
813    }
814    if (vpid < 0) {
815        vpid = vInfo.size() - 1;
816    }
817    if (vpid < 0) {
818        Plotter2ViewportInfo vi;
819        vInfo.push_back(vi);
820        vpid = 0;
821    }
822
823    Plotter2ViewportInfo* vi = &vInfo[vpid];
824    vi->nMajorTickWithinTickNumsY = (int)(interval / vi->majorTickIntervalY);
825}
826
827void Plotter2::setNumLocationX(const std::string& side, const int inVpid) {
828    int vpid = inVpid;
829    if (vpid >= (int)vInfo.size()) {
830        exit(0);
831    }
832    if (vpid < 0) {
833        vpid = vInfo.size() - 1;
834    }
835    if (vpid < 0) {
836        Plotter2ViewportInfo vi;
837        vInfo.push_back(vi);
838        vpid = 0;
839    }
840
841    Plotter2ViewportInfo* vi = &vInfo[vpid];
842    vi->numLocationX = side;
843}
844
845void Plotter2::setNumLocationY(const std::string& side, const int inVpid) {
846    int vpid = inVpid;
847    if (vpid >= (int)vInfo.size()) {
848        exit(0);
849    }
850    if (vpid < 0) {
851        vpid = vInfo.size() - 1;
852    }
853    if (vpid < 0) {
854        Plotter2ViewportInfo vi;
855        vInfo.push_back(vi);
856        vpid = 0;
857    }
858
859    Plotter2ViewportInfo* vi = &vInfo[vpid];
860    vi->numLocationY = side;
861}
862
863void Plotter2::setData(const std::vector<float>& xdata, const std::vector<float>& ydata, const int inVpid, const int inDataid) {
864    int vpid = inVpid;
865    if (vpid >= (int)vInfo.size()) {
866        exit(0);
867    }
868    if (vpid < 0) {
869        vpid = vInfo.size() - 1;
870    }
871    if (vpid < 0) {
872        Plotter2ViewportInfo vi;
873        vInfo.push_back(vi);
874        vpid = 0;
875    }
876
877    Plotter2ViewportInfo* vi = &vInfo[vpid];
878
879    int dataid = inDataid;
880    if (dataid < 0) {
881        Plotter2DataInfo di;
882        vi->vData.push_back(di);
883        dataid = vi->vData.size() - 1;
884    } else if (dataid >= (int)vi->vData.size()) {
885        exit(0);
886    }
887
888    vi->setData(xdata, ydata, dataid);
889}
890
891void Plotter2::setLine(const int color, const int width, const int style, const int inVpid, const int inDataid) {
892    int vpid = inVpid;
893    if (vpid >= (int)vInfo.size()) {
894        exit(0);
895    }
896    if (vpid < 0) {
897        vpid = vInfo.size() - 1;
898    }
899    if (vpid < 0) {
900        Plotter2ViewportInfo vi;
901        vInfo.push_back(vi);
902        vpid = 0;
903    }
904
905    Plotter2ViewportInfo* vi = &vInfo[vpid];
906
907    int dataid = inDataid;
908    if (dataid < 0) {
909        dataid = vi->vData.size() - 1;
910    } else if (dataid >= (int)vi->vData.size()) {
911        exit(0);
912    }
913
914    Plotter2DataInfo* di = &vi->vData[dataid];
915    di->drawLine  = true;
916    di->lineColor = color;
917    di->lineWidth = width;
918    di->lineStyle = style;
919}
920
921void Plotter2::showLine(const int inVpid, const int inDataid) {
922    int vpid = inVpid;
923    if (vpid >= (int)vInfo.size()) {
924        exit(0);
925    }
926    if (vpid < 0) {
927        vpid = vInfo.size() - 1;
928    }
929    if (vpid < 0) {
930        exit(0);
931    }
932
933    int dataid = inDataid;
934    if (dataid >= (int)vInfo[vpid].vData.size()) {
935        exit(0);
936    }
937    if (dataid < 0) {
938        dataid = vInfo[vpid].vData.size() - 1;
939    }
940    if (dataid < 0) {
941        exit(0);
942    }
943
944    Plotter2ViewportInfo* vi = &vInfo[vpid];
945    vi->vData[dataid].drawLine  = true;
946}
947
948void Plotter2::hideLine(const int inVpid, const int inDataid) {
949    int vpid = inVpid;
950    if (vpid >= (int)vInfo.size()) {
951        exit(0);
952    }
953    if (vpid < 0) {
954        vpid = vInfo.size() - 1;
955    }
956    if (vpid < 0) {
957        exit(0);
958    }
959
960    int dataid = inDataid;
961    if (dataid >= (int)vInfo[vpid].vData.size()) {
962        exit(0);
963    }
964    if (dataid < 0) {
965        dataid = vInfo[vpid].vData.size() - 1;
966    }
967    if (dataid < 0) {
968        exit(0);
969    }
970
971    Plotter2ViewportInfo* vi = &vInfo[vpid];
972    vi->vData[dataid].drawLine  = false;
973}
974
975void Plotter2::setPoint(const int type, const float size, const int color, const int inVpid, const int inDataid) {
976    int vpid = inVpid;
977    if (vpid >= (int)vInfo.size()) {
978        exit(0);
979    }
980    if (vpid < 0) {
981        vpid = vInfo.size() - 1;
982    }
983    if (vpid < 0) {
984        Plotter2ViewportInfo vi;
985        vInfo.push_back(vi);
986        vpid = 0;
987    }
988
989    int dataid = inDataid;
990    if (dataid >= (int)vInfo[vpid].vData.size()) {
991        exit(0);
992    }
993    if (dataid < 0) {
994        dataid = vInfo[vpid].vData.size() - 1;
995    }
996
997    Plotter2ViewportInfo* vi = &vInfo[vpid];
998    vi->vData[dataid].drawMarker  = true;
999    vi->vData[dataid].markerType  = type;
1000    vi->vData[dataid].markerSize  = size;
1001    vi->vData[dataid].markerColor = color;
1002}
1003
1004void Plotter2::showPoint(const int inVpid, const int inDataid) {
1005    int vpid = inVpid;
1006    if (vpid >= (int)vInfo.size()) {
1007        exit(0);
1008    }
1009    if (vpid < 0) {
1010        vpid = vInfo.size() - 1;
1011    }
1012    if (vpid < 0) {
1013        exit(0);
1014    }
1015
1016    int dataid = inDataid;
1017    if (dataid >= (int)vInfo[vpid].vData.size()) {
1018        exit(0);
1019    }
1020    if (dataid < 0) {
1021        dataid = vInfo[vpid].vData.size() - 1;
1022    }
1023    if (dataid < 0) {
1024        exit(0);
1025    }
1026
1027    Plotter2ViewportInfo* vi = &vInfo[vpid];
1028    vi->vData[dataid].drawMarker  = true;
1029}
1030
1031void Plotter2::hidePoint(const int inVpid, const int inDataid) {
1032    int vpid = inVpid;
1033    if (vpid >= (int)vInfo.size()) {
1034        exit(0);
1035    }
1036    if (vpid < 0) {
1037        vpid = vInfo.size() - 1;
1038    }
1039    if (vpid < 0) {
1040        exit(0);
1041    }
1042
1043    int dataid = inDataid;
1044    if (dataid >= (int)vInfo[vpid].vData.size()) {
1045        exit(0);
1046    }
1047    if (dataid < 0) {
1048        dataid = vInfo[vpid].vData.size() - 1;
1049    }
1050    if (dataid < 0) {
1051        exit(0);
1052    }
1053
1054    Plotter2ViewportInfo* vi = &vInfo[vpid];
1055    vi->vData[dataid].drawMarker  = false;
1056}
1057
1058void Plotter2::setMaskX(const float xmin, const float xmax, const int color, const int fill, const int width, const float hsep, const int inVpid) {
1059    int vpid = inVpid;
1060    if (vpid >= (int)vInfo.size()) {
1061        exit(0);
1062    }
1063    if (vpid < 0) {
1064        vpid = vInfo.size() - 1;
1065    }
1066    if (vpid < 0) {
1067        Plotter2ViewportInfo vi;
1068        vInfo.push_back(vi);
1069        vpid = 0;
1070    }
1071
1072    Plotter2ViewportInfo* vi = &vInfo[vpid];
1073
1074    Plotter2RectInfo ri;
1075    ri.xmin  = xmin;
1076    ri.xmax  = xmax;
1077    //y-range of xmask should be calculated in plot().
1078    //std::vector<float> yrange = vi->getRangeY();
1079    //float yexcess = 0.1*(yrange[1] - yrange[0]);
1080    //ri.ymin  = yrange[0] - yexcess;
1081    //ri.ymax  = yrange[1] + yexcess;
1082    ri.color = color;
1083    ri.fill  = fill;
1084    ri.width = width;
1085    ri.hsep  = hsep;
1086
1087    vi->vRect.push_back(ri);
1088}
1089
1090void Plotter2::setArrow(const float xtail, const float xhead, const float ytail,
1091                          const float yhead, const int color, const int width,
1092                          const int lineStyle, const float headSize,
1093                          const int headFillStyle, const float headAngle,
1094                          const float headVent, const int inVpid, const int inArrowid) {
1095    int vpid = inVpid;
1096    if (vpid >= (int)vInfo.size()) {
1097        exit(0);
1098    }
1099    if (vpid < 0) {
1100        vpid = vInfo.size() - 1;
1101    }
1102    if (vpid < 0) {
1103        Plotter2ViewportInfo vi;
1104        vInfo.push_back(vi);
1105        vpid = 0;
1106    }
1107
1108    Plotter2ViewportInfo* vi = &vInfo[vpid];
1109
1110    int arrowid = inArrowid;
1111    if (arrowid < 0) {
1112        Plotter2ArrowInfo ai;
1113        vi->vArro.push_back(ai);
1114        arrowid = vi->vArro.size() - 1;
1115    } else if (arrowid >= (int)vi->vArro.size()) {
1116        exit(0);
1117    }
1118
1119    Plotter2ArrowInfo* ai = &vi->vArro[arrowid];
1120
1121    ai->xhead = xhead;
1122    ai->xtail = xtail;
1123    ai->yhead = yhead;
1124    ai->ytail = ytail;
1125    ai->color = color;
1126    ai->width = width;
1127    ai->lineStyle = lineStyle;
1128    ai->headSize = headSize;
1129    ai->headFillStyle = headFillStyle;
1130    ai->headAngle = headAngle;
1131    ai->headVent = headVent;
1132}
1133
1134void Plotter2::setText(const std::string& text, const float inPosx, const float inPosy, const float angle, const float fjust, const float size, const std::string& style, const int color, const int bgcolor, const int inVpid, const int inTextid) {
1135    int vpid = inVpid;
1136    if (vpid >= (int)vInfo.size()) {
1137        exit(0);
1138    }
1139    if (vpid < 0) {
1140        vpid = vInfo.size() - 1;
1141    }
1142    if (vpid < 0) {
1143        Plotter2ViewportInfo vi;
1144        vInfo.push_back(vi);
1145        vpid = 0;
1146    }
1147
1148    Plotter2ViewportInfo* vi = &vInfo[vpid];
1149
1150    int annotationid = inTextid;
1151    if (annotationid < 0) {
1152        Plotter2TextInfo ti;
1153        vi->vText.push_back(ti);
1154        annotationid = vi->vText.size() - 1;
1155    } else if (annotationid >= (int)vi->vText.size()) {
1156        exit(0);
1157    }
1158
1159    Plotter2TextInfo* ti = &vi->vText[annotationid];
1160
1161    std::string styleString;
1162    if (style == "") {
1163      styleString = "";
1164    } else if (style == "roman") {
1165      styleString = "\\fr";
1166    } else if (style == "italic") {
1167      styleString = "\\fi";
1168    } else if (style == "script") {
1169      styleString = "\\fs";
1170    }
1171
1172    ti->text = styleString + text;
1173
1174    float posx = inPosx;
1175    if (posx < 0.0) {
1176        posx = 0.5*(vi->vpPosXMin + vi->vpPosXMax);
1177    }
1178    ti->posx = posx;
1179
1180    float posy = inPosy;
1181    if (posy < 0.0) {
1182        posy = 0.5*(vi->vpPosYMin + vi->vpPosYMax);
1183    }
1184    ti->posy = posy;
1185
1186    ti->angle = angle;
1187    ti->fjust = fjust;
1188    ti->size = size;
1189    ti->color = color;
1190    ti->bgcolor = bgcolor;
1191}
1192
1193void Plotter2::setLabelX(const std::string& label, const float inPosx, const float inPosy, const float size, const std::string& style, const int color, const int bgcolor, const int inVpid) {
1194    int vpid = inVpid;
1195    if (vpid >= (int)vInfo.size()) {
1196        exit(0);
1197    }
1198    if (vpid < 0) {
1199        vpid = vInfo.size() - 1;
1200    }
1201    if (vpid < 0) {
1202        Plotter2ViewportInfo vi;
1203        vInfo.push_back(vi);
1204        vpid = 0;
1205    }
1206
1207    Plotter2ViewportInfo* vi = &vInfo[vpid];
1208
1209    std::string styleString;
1210    if (style == "") {
1211      styleString = "";
1212    } else if (style == "roman") {
1213      styleString = "\\fr";
1214    } else if (style == "italic") {
1215      styleString = "\\fi";
1216    } else if (style == "script") {
1217      styleString = "\\fs";
1218    }
1219    vi->labelXString = styleString + label;
1220
1221    float posx = inPosx;
1222    if (posx < 0.0) {
1223        posx = 0.5*(vi->vpPosXMin + vi->vpPosXMax);
1224    }
1225    vi->labelXPosX   = posx;
1226
1227    float posy = inPosy;
1228    if (posy < 0.0) {
1229        posy = 0.35*vi->vpPosYMin;
1230    }
1231    vi->labelXPosY   = posy;
1232
1233    vi->labelXAngle  = 0.0;
1234    vi->labelXFJust  = 0.5;
1235    vi->labelXSize   = size;
1236    vi->labelXColor  = color;
1237    vi->labelXBColor = bgcolor;
1238}
1239
1240void Plotter2::setLabelY(const std::string& label, const float inPosx, const float inPosy, const float size, const std::string& style, const int color, const int bgcolor, const int inVpid) {
1241    int vpid = inVpid;
1242    if (vpid >= (int)vInfo.size()) {
1243        exit(0);
1244    }
1245    if (vpid < 0) {
1246        vpid = vInfo.size() - 1;
1247    }
1248    if (vpid < 0) {
1249        Plotter2ViewportInfo vi;
1250        vInfo.push_back(vi);
1251        vpid = 0;
1252    }
1253
1254    Plotter2ViewportInfo* vi = &vInfo[vpid];
1255
1256    std::string styleString;
1257    if (style == "") {
1258      styleString = "";
1259    } else if (style == "roman") {
1260      styleString = "\\fr";
1261    } else if (style == "italic") {
1262      styleString = "\\fi";
1263    } else if (style == "script") {
1264      styleString = "\\fs";
1265    }
1266    vi->labelYString = styleString + label;
1267
1268    float posx = inPosx;
1269    if (posx < 0.0) {
1270        posx = 0.35*vi->vpPosXMin;
1271    }
1272    vi->labelYPosX   = posx;
1273
1274    float posy = inPosy;
1275    if (posy < 0.0) {
1276        posy = 0.5*(vi->vpPosYMin + vi->vpPosYMax);
1277    }
1278    vi->labelYPosY   = posy;
1279
1280    vi->labelYAngle  = 90.0;
1281    vi->labelYFJust  = 0.5;
1282    vi->labelYSize   = size;
1283    vi->labelYColor  = color;
1284    vi->labelYBColor = bgcolor;
1285}
1286
1287void Plotter2::setTitle(const std::string& label, const float inPosx, const float inPosy, const float size, const std::string& style, const int color, const int bgcolor, const int inVpid) {
1288    int vpid = inVpid;
1289    if (vpid >= (int)vInfo.size()) {
1290        exit(0);
1291    }
1292    if (vpid < 0) {
1293        vpid = vInfo.size() - 1;
1294    }
1295    if (vpid < 0) {
1296        Plotter2ViewportInfo vi;
1297        vInfo.push_back(vi);
1298        vpid = 0;
1299    }
1300
1301    Plotter2ViewportInfo* vi = &vInfo[vpid];
1302
1303    std::string styleString;
1304    if (style == "") {
1305      styleString = "";
1306    } else if (style == "roman") {
1307      styleString = "\\fr";
1308    } else if (style == "italic") {
1309      styleString = "\\fi";
1310    } else if (style == "script") {
1311      styleString = "\\fs";
1312    }
1313    vi->titleString = styleString + label;
1314
1315    float posx = inPosx;
1316    if (posx < 0.0) {
1317        posx = 0.5*(vi->vpPosXMin + vi->vpPosXMax);
1318    }
1319    vi->titlePosX   = posx;
1320
1321    float posy = inPosy;
1322    if (posy < 0.0) {
1323        posy = vi->vpPosYMax + 0.25*(1.0 - vi->vpPosYMax);
1324    }
1325    vi->titlePosY   = posy;
1326
1327    vi->titleAngle  = 0.0;
1328    vi->titleFJust  = 0.5;
1329    vi->titleSize   = size;
1330    vi->titleColor  = color;
1331    vi->titleBColor = bgcolor;
1332}
1333
1334void Plotter2::setViewportBackgroundColor(const int bgcolor, const int inVpid) {
1335    int vpid = inVpid;
1336    if (vpid >= (int)vInfo.size()) {
1337        exit(0);
1338    }
1339    if (vpid < 0) {
1340        vpid = vInfo.size() - 1;
1341    }
1342    if (vpid < 0) {
1343        exit(0);
1344    }
1345
1346    Plotter2ViewportInfo* vi = &vInfo[vpid];
1347    vi->vpBColor = bgcolor;
1348}
1349
1350void Plotter2::close() {
1351    if (hasDevice) {
1352        cpgclos();
1353        hasDevice = false;
1354    }
1355}
1356
1357void Plotter2::resetAttributes(const Plotter2ViewportInfo& vi) {
1358    cpgstbg(0); // reset background colour to the initial one (white)
1359    cpgsci(1);  // reset foreground colour to the initial one (black)
1360    cpgsls(1);  // reset line style to solid
1361    cpgslw(1);  // reset line width to 1
1362    cpgscf(1);  // reset font style to normal
1363    cpgsch(vi.fontSizeDef);// reset font size
1364    cpgsfs(1);  // reset fill style (solid)
1365}
1366
1367void Plotter2::plot() {
1368    open();
1369
1370    if ((width > 0.0) && (aspect > 0.0)) {
1371        cpgpap(width, aspect);
1372    }
1373
1374    cpgscr(0, 1.0, 1.0, 1.0); // set background color white
1375    cpgscr(1, 0.0, 0.0, 0.0); // set foreground color black
1376
1377    for (unsigned int i = 0; i < vInfo.size(); ++i) {
1378        Plotter2ViewportInfo vi = vInfo[i];
1379
1380        if (vi.showViewport) {
1381            resetAttributes(vi);
1382
1383            // setup viewport
1384            cpgsvp(vi.vpPosXMin, vi.vpPosXMax, vi.vpPosYMin, vi.vpPosYMax);
1385            cpgswin(vi.vpRangeXMin, vi.vpRangeXMax, vi.vpRangeYMin, vi.vpRangeYMax);
1386
1387            // background color (default is transparent)
1388            if (vi.vpBColor >= 0) {
1389                cpgsci(vi.vpBColor);
1390                cpgrect(vi.vpRangeXMin, vi.vpRangeXMax, vi.vpRangeYMin, vi.vpRangeYMax);
1391                cpgsci(1);  // reset foreground colour to the initial one (black)
1392            }
1393
1394            // data
1395            for (unsigned int j = 0; j < vi.vData.size(); ++j) {
1396                resetAttributes(vi);
1397
1398                Plotter2DataInfo di = vi.vData[j];
1399                std::vector<float> vxdata = di.xData;
1400                int ndata = vxdata.size();
1401                float* pxdata = new float[ndata];
1402                float* pydata = new float[ndata];
1403                for (int k = 0; k < ndata; ++k) {
1404                    pxdata[k] = di.xData[k];
1405                    pydata[k] = di.yData[k];
1406                }
1407
1408                if (di.drawLine) {
1409                    cpgsls(di.lineStyle);
1410                    cpgslw(di.lineWidth);
1411                    int colorIdx = di.lineColor;
1412                    if (colorIdx < 0) {
1413                        colorIdx = (j + 1) % 15 + 1;
1414                    }
1415                    cpgsci(colorIdx);
1416                    cpgline(ndata, pxdata, pydata);
1417                }
1418
1419                if (di.drawMarker) {
1420                    cpgsch(di.markerSize);
1421                    cpgsci(di.markerColor);
1422                    cpgpt(ndata, pxdata, pydata, di.markerType);
1423                }
1424
1425                delete [] pxdata;
1426                delete [] pydata;
1427            }
1428
1429            //calculate y-range of xmasks
1430            std::vector<float> yrange = vi.getRangeY();
1431            float yexcess = 0.1*(yrange[1] - yrange[0]);
1432            float xmaskymin = yrange[0] - yexcess;
1433            float xmaskymax = yrange[1] + yexcess;
1434
1435            // masks
1436            for (unsigned int j = 0; j < vi.vRect.size(); ++j) {
1437                resetAttributes(vi);
1438
1439                Plotter2RectInfo ri = vi.vRect[j];
1440                cpgsci(ri.color);
1441                cpgsfs(ri.fill);
1442                cpgslw(ri.width);
1443                cpgshs(45.0, ri.hsep, 0.0);
1444                float* mxdata = new float[4];
1445                float* mydata = new float[4];
1446                mxdata[0] = ri.xmin;
1447                mxdata[1] = ri.xmax;
1448                mxdata[2] = ri.xmax;
1449                mxdata[3] = ri.xmin;
1450                mydata[0] = xmaskymin;
1451                mydata[1] = xmaskymin;
1452                mydata[2] = xmaskymax;
1453                mydata[3] = xmaskymax;
1454                cpgpoly(4, mxdata, mydata);
1455            }
1456
1457            // arrows
1458            for (unsigned int j = 0; j < vi.vArro.size(); ++j) {
1459                resetAttributes(vi);
1460
1461                Plotter2ArrowInfo ai = vi.vArro[j];
1462                cpgsci(ai.color);
1463                cpgslw(ai.width);
1464                cpgsls(ai.lineStyle);
1465                cpgsch(ai.headSize);
1466                cpgsah(ai.headFillStyle, ai.headAngle, ai.headVent);
1467                cpgarro(ai.xtail, ai.ytail, ai.xhead, ai.yhead);
1468            }
1469
1470            // arbitrary texts
1471            for (unsigned int j = 0; j < vi.vText.size(); ++j) {
1472                resetAttributes(vi);
1473
1474                Plotter2TextInfo ti = vi.vText[j];
1475                cpgsch(ti.size);
1476                cpgsci(ti.color);
1477                cpgstbg(ti.bgcolor);
1478                cpgptxt(ti.posx, ti.posy, ti.angle, ti.fjust, ti.text.c_str());
1479            }
1480
1481            // viewport outline and ticks
1482            resetAttributes(vi);
1483
1484            cpgbox("BCTS",  vi.majorTickIntervalX, vi.nMinorTickWithinMajorTicksX,
1485                   "BCTSV", vi.majorTickIntervalY, vi.nMinorTickWithinMajorTicksY);
1486
1487            // viewport numberings
1488            std::string numformatx, numformaty;
1489            if (vi.numLocationX == "b") {
1490                numformatx = "N";
1491            } else if (vi.numLocationX == "t") {
1492                numformatx = "M";
1493            } else if (vi.numLocationX == "") {
1494                numformatx = "";
1495            }
1496            if (vi.numLocationY == "l") {
1497                numformaty = "NV";
1498            } else if (vi.numLocationY == "r") {
1499                numformaty = "MV";
1500            } else if (vi.numLocationY == "") {
1501                numformaty = "";
1502            }
1503
1504            cpgbox(numformatx.c_str(), vi.majorTickIntervalX * vi.nMajorTickWithinTickNumsX, 0,
1505                   numformaty.c_str(), vi.majorTickIntervalY * vi.nMajorTickWithinTickNumsY, 0);
1506
1507            float xpos, ypos;
1508
1509            // x-label
1510            vi.getWorldCoordByWindowCoord(vi.labelXPosX, vi.labelXPosY, &xpos, &ypos);
1511            cpgsch(vi.labelXSize);
1512            cpgsci(vi.labelXColor);
1513            cpgstbg(vi.labelXBColor); //outside viewports, works ONLY with /xwindow
1514            cpgptxt(xpos, ypos, vi.labelXAngle, vi.labelXFJust, vi.labelXString.c_str());
1515
1516            // y-label
1517            vi.getWorldCoordByWindowCoord(vi.labelYPosX, vi.labelYPosY, &xpos, &ypos);
1518            cpgsch(vi.labelYSize);
1519            cpgsci(vi.labelYColor);
1520            cpgstbg(vi.labelYBColor); //outside viewports, works ONLY with /xwindow
1521            cpgptxt(xpos, ypos, vi.labelYAngle, vi.labelYFJust, vi.labelYString.c_str());
1522
1523            // title
1524            vi.getWorldCoordByWindowCoord(vi.titlePosX, vi.titlePosY, &xpos, &ypos);
1525            cpgsch(vi.titleSize);
1526            cpgsci(vi.titleColor);
1527            cpgstbg(vi.titleBColor); //outside viewports, works ONLY with /xwindow
1528            cpgptxt(xpos, ypos, vi.titleAngle, vi.titleFJust, vi.titleString.c_str());
1529        }
1530
1531    }
1532
1533    close();
1534}
1535
1536} // namespace asap
Note: See TracBrowser for help on using the repository browser.