source: trunk/src/Plotter2.h@ 2887

Last change on this file since 2887 was 2861, checked in by WataruKawasaki, 11 years ago

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: No

What Interface Changed:

Test Programs:

Put in Release Notes: Yes

Module(s): sd

Description: (1) bugfix in setting masks

(2) finished implementation of get_vinfo()
(3) change get_*index() to class methods
(4) modify get_*index() to raise exception when invalid value given


File size: 6.6 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 int addViewport(const float xmin, const float xmax, const float ymin, const float ymax);
165 void setViewport(const float xmin, const float xmax, const float ymin, const float ymax, const int id);
166 void showViewport(const int inVpid);
167 void hideViewport(const int inVpid);
168 bool getHasDefaultViewport();
169 int getCurrentViewportId();
170 void getViewInfo();
171 void setRange(const float xmin, const float xmax, const float ymin, const float ymax, const int inVpid);
172 void setRangeX(const float xmin, const float xmax, const int inVpid);
173 void setRangeY(const float ymin, const float ymax, const int inVpid);
174 std::vector<float> getRangeX(const int inVpid);
175 std::vector<float> getRangeY(const int inVpid);
176 void setAutoRange(const int inVpid);
177 void setAutoRangeX(const int inVpid);
178 void setAutoRangeY(const int inVpid);
179 void setFontSizeDef(const float size, const int inVpid);
180 void setTicksX(const float interval, const int num, const int inVpid);
181 void setTicksY(const float interval, const int num, const int inVpid);
182 void setAutoTicks(const int inVpid);
183 void setAutoTicksX(const int inVpid);
184 void setAutoTicksY(const int inVpid);
185 void setNumIntervalX(const float interval, const int inVpid);
186 void setNumIntervalY(const float interval, const int inVpid);
187 void setNumLocationX(const std::string& side, const int inVpid);
188 void setNumLocationY(const std::string& side, const int inVpid);
189 void setData(const std::vector<float>& xdata, const std::vector<float>& ydata, const int inVpid, const int inDataid);
190 void setLine(const int color, const int width, const int style, const int inVpid, const int inDataid);
191 void showLine(const int inVpid, const int inDataid);
192 void hideLine(const int inVpid, const int inDataid);
193 void setPoint(const int type, const float size, const int color, const int inVpid, const int inDataid);
194 void showPoint(const int inVpid, const int inDataid);
195 void hidePoint(const int inVpid, const int inDataid);
196 void setMaskX(const float xmin, const float xmax, const int color, const int fill, const int width, const float hsep, const int inVpid);
197 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);
198 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);
199 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);
200 void setViewportBackgroundColor(const int bgcolor, const int inVpid);
201 //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);
202 void plot();
203private:
204 std::string filename;
205 std::string device;
206 bool hasDevice;
207 std::vector<Plotter2ViewportInfo> vInfo;
208 bool hasDefaultViewport;
209 int currentViewportId;
210 void open();
211 void close();
212};
213
214} // namespace asap
Note: See TracBrowser for help on using the repository browser.