-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAvAxis.h
More file actions
364 lines (338 loc) · 12.1 KB
/
AvAxis.h
File metadata and controls
364 lines (338 loc) · 12.1 KB
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
353
354
355
356
357
358
359
360
361
362
363
364
//# Copyright (C) 1995-2002 Board of Trustees of the University of Illinois
//#
//# This software, both binary and source, is copyrighted by The
//# Board of Trustees of the University of Illinois. Ownership
//# remains with the University. You should have received a copy
//# of a licensing agreement with this software. See the file
//# "AIPSVIEW_COPYRIGHT", or contact the University at this address:
//#
//# The NCSA AipsView Visualization System
//# National Center for Supercomputing Applications
//# University of Illinois
//# 405 North Mathews Ave.
//# Urbana, IL 61801
//# aipsview@ncsa.uiuc.edu
//---------------------------------------------------------------------------
//
// $Header: /home/cvs/aips++/code/trial/apps/aipsview/Attic/AvAxis.h,v 19.0 2003/07/16 05:48:07 aips2adm Exp $
//
// $Log: AvAxis.h,v $
// Revision 19.0 2003/07/16 05:48:07 aips2adm
// exhale: Base release 19.000.00
//
// Revision 18.0 2002/06/07 21:29:41 aips2adm
// exhale: Base release 18.000.00
//
// Revision 17.1 2002/01/07 22:26:28 hravlin
// Removed check for __P.
//
// Revision 17.0 2001/11/12 19:43:09 aips2adm
// exhale: Base release 17.000.00
//
// Revision 16.0 2001/05/03 01:43:15 aips2adm
// exhale: Base release 16.000.00
//
// Revision 15.0 2000/10/26 17:12:46 aips2adm
// exhale: Base release 15.000.00
//
// Revision 14.0 2000/03/23 16:09:13 aips2adm
// exhale: Base release 14.000.00
//
// Revision 13.0 1999/08/10 18:41:04 aips2adm
// exhale: Base release 13.000.00
//
// Revision 12.0 1999/07/15 00:24:31 aips2adm
// exhale: Base release 12.000.00
//
// Revision 11.0 1998/10/03 07:02:26 aips2adm
// exhale: Base release 11.000.00
//
// Revision 10.0 1998/07/20 17:56:43 aips2adm
// exhale: Base release 10.000.00
//
// Revision 9.3 1998/06/09 21:09:29 hr
// Removed unneeded semicolon from DECLARE_HEADER.
//
// Revision 9.2 1998/02/20 20:33:22 hr
// Changed label handling to use position and angle controls rather than
// old method.
//
// Revision 9.1 1997/11/17 16:54:14 hr
// Added support for axis offsets and captions.
//
// Revision 9.0 1997/08/25 21:32:05 aips2adm
// exhale: Base release 09.000.00
//
// Revision 8.1 1997/04/23 17:11:01 hr
// Changes to support use of pgcrvl including globalOptions.
//
// Revision 8.0 1997/02/20 03:14:27 aips2adm
// exhale: Base release 08.000.00
//
// Revision 7.6 1997/02/11 20:38:12 hr
// Added a pointer to the raster.
//
// Revision 7.5 1997/02/05 17:22:29 hr
// The __P problem with g++ and math.h.
//
// Revision 7.4 1997/01/24 20:37:54 hr
// Widespread changes to convert to using AvAxisOptions for settable parameters.
//
// Revision 7.3 1996/12/12 09:18:33 droberts
// added HMS_RAD and DMS_RAD types to support radian datasets.
//
// Revision 1.1 1996/07/11 21:31:21 pixton
// Automated Checkin
//
// Revision 1.5 1996/06/18 18:42:36 pixton
// Copyright Update
//
// Revision 1.4 1996/02/23 17:37:31 hr
// Several changes to cleanup, to incorporate code from AvCLUImageSetter
// and to help display text and tick marks better.
//
// Revision 1.3 1996/02/08 18:41:04 hr
// Added charSize().
//
// Revision 1.2 1996/01/25 17:43:17 hr
// Needed to add Graphics2D initializations.
//
// Revision 1.1 1996/01/24 18:05:51 hr
// Initial revision
//
//
//---------------------------------------------------------------------------
/* AvAxis.h
Subclass of AvPolyline that generates a labeled axis.
The drawing area for the axis information is greater than for the raster
so this assumes the raster is contained within a smaller viewport that
is offset from the one into which the axis information will be drawn.
The surrounding viewport is assumed to be the size of the raster's viewport
plus margins.
VPS ->VPR(at xoffset, yoffset) ->Raster
->Axis: using xoffset, yoffset
VPS is the enclosing viewport containing VPR and the AvAxis object.
VPR should be a viewportsetter containing the raster and should be offset
from VPS' origin by the given offsets.
--------------
Example:
static const int OFFSET=150;
vpr = new AvViewportSetter(OFFSET, OFFSET, raster);
// Viewport to enclose raster's vp and have room for grid & labels.
vps = new AvViewportSetter(0.0, 0.0,
width+OFFSET*2, height+OFFSET*2, vpr);
// (width, height are the dimensions of the scaled raster).
AvAxis *axis = new AvAxis(raster, axisoptions);
// The box will be drawn around a box with these margins
// (in pixels) from the surrounding viewport.
// If lm = rm and tm = bm, then the following can be used:
axis->offset(OFFSET, OFFSET);
// If the margins are different, use:
axis->setMargins(lm, rm, tm, bm);
vps->append( axis);
// If a raster is not used, it will be necessary to make calls to
// these routines:
xLabel(), yLabel(), title() and setWorldWindow().
--------------
Various options to change the appearance of the plot may be set.
These are set via the AvAxisOptions object.
Option Function Default
GRID Draw grid line. Yes
LOG Logarithmic axis. No
MAJORTICKS Draw Major tick marks Yes
MINORTICKS Draw Minor tick marks Yes
VERTLABELS Draw Y axis labels vertically Yes
rather than parallel to Y axis.
STDLABELPOSITION
Draw labels in 'standard' Yes
position.
NONSTDLABELPOSITION
Draw labels in 'nonstandard' No
position.
(Don't set both of the above).
SHOWZEROLINE
Show the zero line. No
HMS Use hours minutes seconds No (Print as 'floats').
labeling.
DMS Use degrees minutes seconds No
labeling.
(Don't set both of the above).
*/
#ifndef AvAxis_h
#define AvAxis_h
//#if defined(__GNUC__) && defined(__P) && !defined(__linux__)
//#undef __P
//#endif
#include <math.h>
#include "AvPolyline.h"
#include "AvAxisOptions.h"
class AvRaster;
class AxisGlobalOptions;
class AvAxis : public AvPolyline {
public:
// The raster is used to initialize labels and label formats.
// If NULL, they will need to be set separately.
AvAxis(AvRaster * = NULL, AvAxisOptions * = NULL);
// Use a different options var.
void setOptions(AvAxisOptions *o);
AvAxisOptions *getOptions()const{return options_;}
// Use the raster to set labels and axis types.
void useRasterInfo(AvRaster *);
// Set X/Y label, title.
void xLabel(const char *);
void yLabel(const char *);
void title(const char *);
// Offsets within viewport to start drawing. (Pixels).
void setMargins(const int lm, const int rm,
const int tm, const int bm);
// Different axis options. (Used internally).
enum OPTIONS { NOOPTIONS=0,
// Axis, grid, axis labels.
DECIMAL=1, EXPONENTIAL=2, // If neither, use default.
FRAME=0x10, GRID=0x20, HMS=0x40, DMS=0x80,
STDLABELPOSITION=0x100, NONSTDLABELPOSITION=0x200,
NOAXISLABEL=STDLABELPOSITION|NONSTDLABELPOSITION,
VERTYLABELS=0x400,
ZEROLINENOTICKS=0x1000, ZEROLINEWITHTICKS=0x2000,
ZEROLINE = ZEROLINENOTICKS|ZEROLINEWITHTICKS,
// Labels
SHOWLABEL=0x10000,
MAJORTICKS=0x100000, USERMAJORINTERVALS=0x200000,
MINORTICKS=0x400000, USERMINORINTERVALS=0x800000
};
// AXISTYPE gives the input and output formats.
enum AXISFORMAT { FLOAT=0, HOURS, DEGREES, RADIANS};
// Size of window in world coordinates.
void setWorldWindow(const float x0, const float x1,
const float y0, const float y1);
void getWorldWindow(const int xAxisInput, float &x0, float &x1,
const int yAxisInput, float &y0, float &y1)const;
// Desired max size in pixels for characters. (rough approximation).
void maxCharSize(const float size);
float maxCharSize()const { return charsize_;}
virtual void draw(AvCanvas &);
virtual void draw(AvCanvas *);
// Returns TRUE if the vector list exists.
inline Boolean haveAxis()const{return haveAxis_;}
// Get rid of current Axis. (clears haveAxis_).
virtual void touch();
/* Compute the (approximate) scalefactor needed to fit n chars into
space # of pixels. If vertical is FALSE, scale is for
horizontal drawing, else vertical. The space needed for a
character string is:
#chars * charsize * charscale * viewportsize
The viewport size is needed since characters are drawn with
fractional vectors: increasing the viewport size increases
the size of the characters.
nchrs # of characters to draw.
space # of pixels to draw into
vpsize Size of drawing surface (height for vertical=TRUE,
width otherwise).
vertical Whether text will be drawn vertically.
*/
float computeCharScale( const float nchrs, const float space,
const int vpsize, const Boolean vertical);
void showAxis(const Boolean);
Boolean showAxis()const;
// PGPLOT's pgrnd.
static double pgrnd(double x, int &nsub);
static inline float hours2sec(const float hrs){return hrs *3600;}
//[ (1day/360deg) * (24hrs/day) * (3600sec/hr) = 240.0sec/deg].
static inline float degrees2sec(const float deg){return deg *240.0;}
// 360deg/2PIradians = 57.2957795130823208768463.
static inline float radians2deg(const float r)
{return (float)(r*57.29577951308232);}
static inline float radians2sec(const float r)
{return degrees2sec(radians2deg(r));}
// Given a value in world coordinates, convert it to what PGPLOT
// expects ('Time' related values in seconds).
#ifndef __sgi
inline double worldX2PG(const double value)
{ switch (xAxisInput_) {
case DEGREES:
return degrees2sec(value);
case HOURS:
return hours2sec(value);
case RADIANS:
return radians2sec(value);
default:
return value;
}
}
inline double worldY2PG(const double value)
{ switch (yAxisInput_) {
case DEGREES:
return degrees2sec(value);
case HOURS:
return hours2sec(value);
case RADIANS:
return radians2sec(value);
default:
return value;
}
}
#else
// The sgi compiler under 5.3 gives a
//"number outside range for double precision floating point values"
// warning in the assemble when compiled with -g and inlined.
double worldX2PG(const double value);
double worldY2PG(const double value);
#endif
// Global options are shared between AvAxis objects of the same
// data set and view axis.
AxisGlobalOptions *globalOptions()const{return goptions_;}
void globalOptions(AxisGlobalOptions *opt);
static AxisGlobalOptions *makeGlobalOptions(AvRaster *, const int s=0);
protected:
virtual ~AvAxis();
// Return character scale needed for the box. Uses charSize if set
// or else computes a scale factor for estimated label sizes.
// If there is no space, for a label in the requested position,
// the corresponding option will be turned off.
float getBoxCharScale( const int vpwidth, const int xchrs,
int &xoptions, int &yoptions);
private:
void initToZero();
void generate(AvCanvas *c); // Generate the Axis vector list.
void drawLinearAxis(AvCanvas *c, const int xMask, const int yMask,
const int lineColor);
void drawCurviLinearAxis(const int xMask, const int yMask,
const int lineColor);
char *strDup(const char *str)const;
int getGlobalOptionMask(AvAxisOptions *options)const;
int getAxisOptionMask(const AvAxisOptions::axis *axis,
const AXISFORMAT af,
const Boolean useCurvilinearAxis)const;
// Convert option var to PGPLOT option string.
// Return a pointer to the buffer.
char *makeOptionString(const int o, char *buf)const;
// As above, but only turns on grid, frame and tickmarks.
char *makeLineOptionString(const int o, char *buf)const;
void drawLabel(const AvAxisOptions::axisLabel *Label,
float charScale);
void drawMarker(const AvAxisOptions::marker *Marker,
float charScale, const float x0, const float x1,
const float y0, const float y1);
private:
DECLARE_HEADER
Boolean haveAxis_; // Set when the axis has been generated
float xwin0_, xwin1_; // World coordinates of window...
float ywin0_, ywin1_; // Set in useRasterWindow.
float Xwin0_, Xwin1_; // What gets used. Either xwin0_, etc.
float Ywin0_, Ywin1_; // Or the 'offset' version.
Boolean showOffsets_; // If true, show delta axis.
// Otherwise, standard.
int lm_, bm_, tm_, rm_; // Margins within viewport to draw
// axis' box.
float charsize_;
float vpw_, vph_; // Size of canvas' viewport.
AvAxisOptions *options_;
AvRaster *raster_;
// Axis input/output data format. Set from raster info.
AXISFORMAT xAxisInput_;
AXISFORMAT yAxisInput_;
AXISFORMAT xAxisOutput_;
AXISFORMAT yAxisOutput_;
AxisGlobalOptions *goptions_;
};
#endif