source: trunk/src/Plotter2.h @ 2895

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

New Development: Yes

JIRA Issue: Yes CAS-6168

Ready for Test: Yes

Interface Changes:

What Interface Changed:

Test Programs:

Put in Release Notes: Yes

Module(s): sd.plotter2

Description: added methods to sd.plotter2 to enable changing the size and shape of the entire region to be plotted (which is referred to as 'viewsurface' in PGPLOT).


File size: 6.8 KB
Line 
1#include <cstdlib>
2#include <iostream>
3#include <math.h>
4#include <stdio.h>
5#include <string>
6#include <unistd.h>
7#include <vector>
8
9#include <cpgplot.h>
10
11namespace asap {
12
13class Plotter2RectInfo {
14public:
15    Plotter2RectInfo();
16    ~Plotter2RectInfo();
17
18    float xmin;
19    float xmax;
20    float ymin;
21    float ymax;
22
23    int color;
24    int fill;
25    int width;
26    float hsep;
27};
28
29class Plotter2DataInfo {
30public:
31    Plotter2DataInfo();
32    ~Plotter2DataInfo();
33
34    std::vector<float> xData;
35    std::vector<float> yData;
36
37    bool drawLine;
38    int lineColor;
39    int lineWidth;
40    int lineStyle;
41
42    bool drawMarker;
43    int markerType;
44    float markerSize;
45    int markerColor;
46
47    bool hasData;
48};
49
50class Plotter2ViewportInfo {
51public:
52    Plotter2ViewportInfo();
53    ~Plotter2ViewportInfo();
54
55    // show the whole viewport
56    bool showViewport;
57
58    // viewport position in window-coordinate
59    float vpPosXMin;
60    float vpPosXMax;
61    float vpPosYMin;
62    float vpPosYMax;
63
64    // plotting range in world-coordinate
65    float vpRangeXMin;
66    float vpRangeXMax;
67    float vpRangeYMin;
68    float vpRangeYMax;
69
70    // set plotting range automatic
71    bool isAutoRangeX;
72    bool isAutoRangeY;
73    float autoRangeMarginX;
74    float autoRangeMarginY;
75    void adjustRange();
76    std::vector<float> getRangeX();
77    std::vector<float> getRangeY();
78
79    // tick intervals
80    bool isAutoTickIntervalX;
81    bool isAutoTickIntervalY;
82    float majorTickIntervalX;
83    float majorTickIntervalY;
84    int nMajorTickWithinTickNumsX;
85    int nMajorTickWithinTickNumsY;
86    int nMinorTickWithinMajorTicksX;
87    int nMinorTickWithinMajorTicksY;
88    void adjustTickInterval();
89
90    // location of value strings along axes
91    std::string numLocationX;
92    std::string numLocationY;
93
94    // default font size
95    float fontSizeDef;
96
97    // data to be plotted
98    std::vector<Plotter2DataInfo> vData;
99    void setData(const std::vector<float>& inXData, const std::vector<float>& inYData, const int id);
100
101    // rectangles
102    std::vector<Plotter2RectInfo> vRect;
103
104    // x-label
105    std::string labelXString;
106    float labelXPosX;
107    float labelXPosY;
108    float labelXAngle;
109    float labelXFJust;
110    float labelXSize;
111    int labelXColor;
112    int labelXBColor;
113
114    // y-label
115    std::string labelYString;
116    float labelYPosX;
117    float labelYPosY;
118    float labelYAngle;
119    float labelYFJust;
120    float labelYSize;
121    int labelYColor;
122    int labelYBColor;
123
124    // title
125    std::string titleString;
126    float titlePosX;
127    float titlePosY;
128    float titleAngle;
129    float titleFJust;
130    float titleSize;
131    int titleColor;
132    int titleBColor;
133
134    // background colour
135    int vpBColor;
136
137    void getWorldCoordByWindowCoord(const float winX, const float winY, float* worldX, float* worldY);
138
139private:
140    float minXData;
141    float maxXData;
142    float minYData;
143    float maxYData;
144    bool hasDataRange;
145    void updateXDataRange(const float data);
146    void updateYDataRange(const float data);
147    void updateAllDataRanges();
148    void adjustRangeX(float* xmin, float* xmax);
149    void adjustRangeY(float* ymin, float* ymax);
150    void adjustTickIntervalX(const float xmin, const float xmax);
151    void adjustTickIntervalY(const float ymin, const float ymax);
152};
153
154class Plotter2 {
155public:
156    Plotter2();
157    ~Plotter2();
158
159    std::string getFileName();
160    void setFileName(const std::string& inFilename);
161    std::string getDevice();
162    void setDevice(const std::string& inDevice);
163
164    float getViewSurfaceWidth();
165    float getViewSurfaceAspect();
166    void setViewSurface(const float width, const float aspect);
167    int addViewport(const float xmin, const float xmax, const float ymin, const float ymax);
168    void setViewport(const float xmin, const float xmax, const float ymin, const float ymax, const int id);
169    void showViewport(const int inVpid);
170    void hideViewport(const int inVpid);
171    bool getHasDefaultViewport();
172    int getCurrentViewportId();
173    void getViewInfo();
174    void setRange(const float xmin, const float xmax, const float ymin, const float ymax, const int inVpid);
175    void setRangeX(const float xmin, const float xmax, const int inVpid);
176    void setRangeY(const float ymin, const float ymax, const int inVpid);
177    std::vector<float> getRangeX(const int inVpid);
178    std::vector<float> getRangeY(const int inVpid);
179    void setAutoRange(const int inVpid);
180    void setAutoRangeX(const int inVpid);
181    void setAutoRangeY(const int inVpid);
182    void setFontSizeDef(const float size, const int inVpid);
183    void setTicksX(const float interval, const int num, const int inVpid);
184    void setTicksY(const float interval, const int num, const int inVpid);
185    void setAutoTicks(const int inVpid);
186    void setAutoTicksX(const int inVpid);
187    void setAutoTicksY(const int inVpid);
188    void setNumIntervalX(const float interval, const int inVpid);
189    void setNumIntervalY(const float interval, const int inVpid);
190    void setNumLocationX(const std::string& side, const int inVpid);
191    void setNumLocationY(const std::string& side, const int inVpid);
192    void setData(const std::vector<float>& xdata, const std::vector<float>& ydata, const int inVpid, const int inDataid);
193    void setLine(const int color, const int width, const int style, const int inVpid, const int inDataid);
194    void showLine(const int inVpid, const int inDataid);
195    void hideLine(const int inVpid, const int inDataid);
196    void setPoint(const int type, const float size, const int color, const int inVpid, const int inDataid);
197    void showPoint(const int inVpid, const int inDataid);
198    void hidePoint(const int inVpid, const int inDataid);
199    void setMaskX(const float xmin, const float xmax, const int color, const int fill, const int width, const float hsep, const int inVpid);
200    void setLabelX(const std::string& label, const float posx, const float posy, const float size, const std::string& style, const int color, const int bgcolor, const int inVpid);
201    void setLabelY(const std::string& label, const float posx, const float posy, const float size, const std::string& style, const int color, const int bgcolor, const int inVpid);
202    void setTitle(const std::string& label, const float posx, const float posy, const float size, const std::string& style, const int color, const int bgcolor, const int inVpid);
203    void setViewportBackgroundColor(const int bgcolor, const int inVpid);
204    //void setAnnotation(const std::string& label, const float posx, const float posy, const float angle, const float fjust, const float size, const std::string& style, const int color, const int bgcolor, const int inVpid);
205    void plot();
206private:
207    std::string filename;
208    std::string device;
209    bool hasDevice;
210    std::vector<Plotter2ViewportInfo> vInfo;
211    bool hasDefaultViewport;
212    int currentViewportId;
213    float width;
214    float aspect;
215    void open();
216    void close();
217};
218
219} // namespace asap
Note: See TracBrowser for help on using the repository browser.