source: branches/plotter2/src/Plotter2.h@ 3030

Last change on this file since 3030 was 2827, checked in by WataruKawasaki, 11 years ago

New Development: No

JIRA Issue: Yes CAS-3620

Ready for Test: Yes

Interface Changes: No

What Interface Changed:

Test Programs:

Put in Release Notes: No

Module(s): sd

Description: modified plotter2.save() so that the previous filename and device are restored finally.


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