-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAvAxis.cc
2752 lines (2441 loc) · 70.2 KB
/
AvAxis.cc
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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//# 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
//---------------------------------------------------------------------------
//
// $Header: /home/cvs/aips++/code/trial/apps/aipsview/Attic/AvAxis.cc,v 19.0 2003/07/16 05:46:30 aips2adm Exp $
//
// $Log: AvAxis.cc,v $
// Revision 19.0 2003/07/16 05:46:30 aips2adm
// exhale: Base release 19.000.00
//
// Revision 18.0 2002/06/07 21:28:18 aips2adm
// exhale: Base release 18.000.00
//
// Revision 17.2 2002/03/11 16:54:14 hravlin
// Changed NEED_FORTRAN_UNDERSCORES to be false for HP systems and true
// otherwise. It can now be defined externally to the file.
//
// Revision 17.1 2002/01/25 21:41:58 hravlin
// nlfunc() never initialized cntrl. Neither does pgsbox. This could cause
// a 1000 times increase in axis drawing times.
//
// Revision 17.0 2001/11/12 19:41:46 aips2adm
// exhale: Base release 17.000.00
//
// Revision 16.0 2001/05/03 01:41:56 aips2adm
// exhale: Base release 16.000.00
//
// Revision 15.0 2000/10/26 17:07:46 aips2adm
// exhale: Base release 15.000.00
//
// Revision 14.1 2000/07/18 18:18:41 hravlin
// Replaced "char *idents" by "char idents[]" to avoid compiler warnings.
//
// Revision 14.0 2000/03/23 16:07:31 aips2adm
// exhale: Base release 14.000.00
//
// Revision 13.1 1999/08/25 20:01:44 hravlin
// Edits (mostly casts) to remove compiler warnings.
//
// Revision 13.0 1999/08/10 18:39:10 aips2adm
// exhale: Base release 13.000.00
//
// Revision 12.0 1999/07/15 00:21:15 aips2adm
// exhale: Base release 12.000.00
//
// Revision 11.0 1998/10/03 06:57:47 aips2adm
// exhale: Base release 11.000.00
//
// Revision 10.0 1998/07/20 17:51:17 aips2adm
// exhale: Base release 10.000.00
//
// Revision 9.6 1998/06/09 21:19:31 hr
// Removed unneeded semicolon after DEFINE_MEMBER_INFO macro.
//
// Revision 9.5 1998/02/26 22:15:24 hr
// In drawLabel(), make use of useGlobalColor variable to choose color to draw with.
//
// Revision 9.4 1998/02/20 20:32:36 hr
// Changed label handling to use position and angle controls rather than
// old method.
//
// Revision 9.3 1997/12/17 21:49:45 hr
// Changes to remove warnings from MIPSpro.7x compiler.
//
// Revision 9.2 1997/11/17 16:53:27 hr
// Added support for axis offsets and captions.
//
// Revision 9.1 1997/09/23 20:27:21 hr
// In draw{recti/curvi}linear(), use global character scale to change size
// of numeric axis labels.
//
// Revision 9.0 1997/08/25 21:23:35 aips2adm
// exhale: Base release 09.000.00
//
// Revision 8.13 1997/08/11 20:37:15 hr
// Removed unsused code found by gcc -Wall.
//
// Revision 8.12 1997/08/01 21:40:06 hr
// DCC found some unused code.
//
// Revision 8.11 1997/08/01 21:30:31 hr
// Changed drawMarker() to set window to (0..1) rather than actual values.
//
// Revision 8.10 1997/06/16 21:53:06 hr
// Removed a couple of unused static variables.
//
// Revision 8.9 1997/06/16 15:53:29 hr
// Changes to support m/s <-> km/s, mainly the ScaleInfo class.
//
// Revision 8.8 1997/05/22 19:50:48 hr
// In drawLinearAxis(), y intrvls was being set from crvMajorIntervals.
//
// Revision 8.7 1997/05/21 21:40:29 hr
// AxisGlobalOptions::WorldToPixel() needed to be subtracting start position.
//
// Revision 8.6 1997/04/30 20:05:53 hr
// (Re)initialize cache statistics in resetCache().
//
// Revision 8.5 1997/04/28 14:55:53 bglenden
// Unilaterally declare that we need underscores for now.
//
// Revision 8.4 1997/04/25 16:00:37 hr
// Changed color handling for curvilinear axes. Added global color boolean and
// made labels default to 'default' color rather than global color.
//
// Revision 8.3 1997/04/23 17:46:34 hr
// Cleaned up some DCC compiler warnings.
//
// Revision 8.2 1997/04/23 17:33:09 hr
// Mistyped a directive.
//
// Revision 8.1 1997/04/23 17:10:31 hr
// Changes to support use of pgcrvl.
//
// Revision 8.0 1997/02/20 03:14:30 aips2adm
// exhale: Base release 08.000.00
//
// Revision 7.8 1997/02/11 20:35:16 hr
// In generate(), reset the title to that of the raster. This gets around
// the problem that there is only one option title variable, but many
// axis titles.
//
// Revision 7.7 1997/02/09 00:02:32 hr
// Minor changes to track changing some of AxisOption's variables to
// IntegerNotifiers from DoubleNotifiers.
//
// Revision 7.6 1997/02/05 17:21:24 hr
// Removed unused variable in yLabel().
//
// Revision 7.5 1997/01/24 20:36:55 hr
// Widespread changes to convert to using AvAxisOptions for settable parameters.
//
// Revision 7.4 1996/12/12 09:07:39 droberts
// Final update from monet archive.
//
// Revision 1.5 1996/10/30 21:40:14 hr
// Unit strings are never displayed for an axis.
//
// Revision 1.4 1996/09/25 18:40:18 hr
// Axis labels now include unit information only if print format is DEFAULT.
//
// Revision 1.3 1996/09/20 18:35:42 hr
// Changes to to work with AvAccessor.
//
// Revision 1.2 1996/08/14 17:15:18 hr
// Changes to remove g++ warnings (from bglenden).
//
// Revision 1.1 1996/07/11 21:31:21 pixton
// Automated Checkin
//
// Revision 1.12 1996/06/18 18:45:46 pixton
// Copyright Update
//
// Revision 1.11 1996/03/05 17:33:15 hr
// Removed a call to cpgsci that set the current color to the background color.
//
// Revision 1.10 1996/02/29 17:12:46 hr
// Some variables weren't being initialized. xtype in useRasterInfo
// wasn't being set if axis type was floating.
//
// Revision 1.9 1996/02/23 17:28:27 hr
// Included axis setup code that was in AvCLUImageSetter.
// Removed need to always have a raster.
// Many changes to get text and tick marks to come out reasonably.
//
// Revision 1.8 1996/02/08 18:47:05 hr
// Removed some unused constants.
//
// Revision 1.7 1996/02/08 18:34:39 hr
// Some changes to get labels to display better. The title is scaled to
// fit.
//
// Revision 1.6 1996/02/04 21:18:00 hr
// Added test version of display of "id".
//
// Revision 1.5 1996/02/02 20:58:56 hr
// Moved axis labeling from AvCLUImageSetter to AvAxis::setRaster.
//
// Revision 1.4 1996/01/31 17:53:59 hr
// Removed Grid and 0 line from default display.
//
// Revision 1.3 1996/01/25 17:42:43 hr
// Needed to add Graphics2D initializations.
//
// Revision 1.2 1996/01/24 18:32:15 hr
// DCC didn't like having static const variables in a static function.
//
// Revision 1.1 1996/01/24 18:02:54 hr
// Initial revision
//
//
//---------------------------------------------------------------------------
/* AvAxis.cc
Subclass of AvPolyline that generates a labeled axis. Its primary use
is to draw a labeled axis for a raster.
Uses PGPLOT to draw a 'box' around the object.
*/
#include <stdio.h>
#include "AvAxis.h"
#include "AvViewportSetter.h"
#include "AvRaster.h"
#include "AvPGDriver.h"
#include "AvCanvas.h"
///// Needed for curvilinear axis support.
#include "AvCLUIRaster.h"
#include "AvAccessor.h"
#include "AvUnits.h"
#if defined(AIPSPLUSPLUS) && defined(GLISH)
#include "AvScrollingBufferDataSet.h"
#endif
// If defined, prints out times for pgcrvl.
//#define TIMEIT
#ifdef TIMEIT
#include <time.h>
#endif
extern "C" {
#include <cpgplot.h>
}
// Global options are shared between AvAxis objects of the same
// data set and view axis. Currently, the primary purpose is to support
// parameters used to draw curvilinear axes using pgcrvl.
class AxisGlobalOptions : public AvResource {
public:
AxisGlobalOptions(AvRaster *, const int cachesize=8192);
~AxisGlobalOptions();
void WorldToPixel( const double world[], double pixel[]);
void PixelToWorld( const double pixel[], double world[]);
////////////////////////////////////////////////////////////////
// pgcrvl will cache the extrema values from pgcrvl since it takes
// a long time to generate, we save them.
Boolean haveExtrema()const{return haveExtrema_;}
// Can't save extrema between AvAxis calls if data set is variable.
Boolean mayUseExtrema()const{return mayUseExtrema_;}
void haveExtrema(const Boolean he){haveExtrema_ = he;}
void setExtrema(const double *);
void getExtrema( double *)const;
////////////////////////////////////////////////////////////////
// May only use curvilinear axis routine if there is an accessor.
// (to do pixel to/from world conversions).
// Currently, the only raster that supports one is AvCLUIRaster.
Boolean mayUseCurvilinearAxis()const{return mayUseCurvilinear_;}
// Returns NULL if raster is not subclassed from AvCLUIRaster.
AvAccessor *accessor()const{return accessor_;}
AvRaster *raster()const{return raster_;}
////////////////////////////////////////////////////////////////
// Caching mechanism to minimize world to/from pixel calls.
void resetCache(); // Flush cache.
// Store values in slot.
int storeValues(const int index, const double wx, const double wy,
const double px, const double py);
// Return slot index for args. May or may not be used.
// Returns -1 if no slot was found. (Table full).
int findEntry(const double wx, const double wy);
// Return pixel values from slot.
void getPValues(const int index, double &px, double &py);
// Does slot have an entry?
Boolean isHit(const int indx)const{return inUse_(indx) ? TRUE : FALSE;}
Boolean validIndex(const int index)const
{ return ((index>=0)&&(index<cacheSize_))?TRUE : FALSE;}
// "labden" values. Used in generating hash index.
void setSteps(const int xsteps, const int ysteps);
Boolean cacheEnabled()const{return cacheEnabled_;}
void enableCache(const Boolean enable){cacheEnabled_ = enable;}
int getCacheIndex(const double x, const double y);
void resetCounts(); // Reset monitoring counters.
void getCounts( int &cacheHits, int &cacheSeeks);
////////////////////////////////////////////////////////////////
// Info to convert an axis value into its 'scaled' form (eg m/s->km/s).
// Conversion can be quick via a scale factor or via a call to
// AvUnits::convert. Since the later appears to only do a multiply,
// it is disabled until/unless it is found to be needed. (It's
// an order of magnitude slower).
class ScaleInfo {
public:
ScaleInfo();
~ScaleInfo();
void init(AvAccessor *accessor, const int axis);
// Do (un)scaling, avoiding subroutine calls when possible.
inline double scale(const double val)const
{ return (needscale_) ?
((QUICKSCALE) ? val*scaleFactor_ : scale_(val))
: val;}
inline double unscale(const double val)const
{ return (needscale_) ?
((QUICKSCALE) ? val/scaleFactor_ : unscale_(val))
: val;}
const AvString &abbrev()const{return abbrev_;}
private:
// If TRUE, scaling is done via multiply/divide. If FALSE,
// scale in done via call to a conversion routine.
static Boolean QUICKSCALE;
double scale_(const double val)const;
double unscale_(const double val)const;
Boolean needscale_; // If FALSE, don't scale.
double scaleFactor_;
AvString units_; // 'Base' units for axis.
AvString scaledUnits_; // Units to convert to.
AvString abbrev_; // Short form of scaledUnits_.
AvString measurementName_;
};
const ScaleInfo *scaleInfo(const int i)
const{return (i == 0) ? &xScale_ : &yScale_;}
private:
AvRaster *raster_;
AvAccessor *accessor_;
Boolean haveExtrema_;
Boolean mayUseExtrema_;
Boolean mayUseCurvilinear_;
Boolean cacheEnabled_; // If false, don't cache.
double extrema_[4]; // Extrema result from pgcrvl.
////////////////////////////////////////////////////////////////
// Cache used to store results of world to pixel conversions.
AvWPosition wx_; // world x,
AvWPosition wy_; // world y,
AvWPosition px_; // pixel x,
AvWPosition py_; // pixel y.
AvIPosition inUse_; // Non 0 means entry is used.
int cacheSize_; // # of slots available.
int cacheSeeks_; // Usage stats
int cacheHits_;
// Used in generating hash index.
double wXMin_, wXMax_,
wYMin_, wYMax_,
wXStep_, wYStep_;
int XSteps_, YSteps_;
////////////////////////////////////////////////////////////////
AvWPosition world_; // World & ijk are used to more
AvWPosition ijk_; // efficiently access low lvl rtns.
AvWPosition start_;
int xAxis_, yAxis_; // DS axis used for X & Y.
int zAxis_; // If >= 0, then the z axis.
ScaleInfo xScale_;
ScaleInfo yScale_;
};
DEFINE_MEMBER_INFO(AvAxis)
// Assume a bunch of points (arbitrary).
AvAxis::AvAxis(AvRaster *r, AvAxisOptions *o) : AvPolyline(1024)
{
INIT_CLASS(AvPolyline);
initToZero();
// o Should not be NULL.
if(o == NULL)
o = new AvAxisOptions(NULL);
setOptions(o);
// setRaster will (re)initialize many parameters.
useRasterInfo(r);
}
// Initialize things to 0.
void AvAxis::initToZero()
{
lm_ = rm_ = tm_ = bm_ = 0;
charsize_ = 0.0; // 0 means use whatever we want.
xAxisInput_ = yAxisInput_ = xAxisOutput_ = yAxisOutput_ = FLOAT;
// World window size from DS.
xwin0_ = xwin1_ = ywin0_ = ywin1_ = 0.0;
// Above or massaged for offsets.
Xwin0_ = Xwin1_ = Ywin0_ = Ywin1_ = 0.0;
haveAxis_ = FALSE;
showOffsets_ = FALSE;
// Due to the PG offsets being fractions of a window, axes don't scale
// correctly if the viewport changes size. If the viewport size
// changes, the axis will be recomputed.
vpw_ = vph_ = 0.0;
options_ = NULL;
raster_ = NULL;
// haveExtrema_ = FALSE;
goptions_ = NULL;
}
// When the options object changes mark as needing to regenerate.
static void optionsCB(XtPointer , AvConductor *, XtPointer data)
{AvAxis *me = (AvAxis *)data;
me->touch();
}
// Change current options pointer.
void AvAxis::setOptions(AvAxisOptions *o)
{
if(o == options_)
return;
if(options_ != NULL)
{ options_->removeCallback(&optionsCB, AvConductor::ValueChanged,
this, this);
options_->unref();
}
options_ = o;
if(options_ != NULL)
{ options_->ref();
// Add to front of list so the imageSetter gets called after
// this touches itself.
options_->addCallback(&optionsCB, AvConductor::ValueChanged,
this, this, TRUE);
}
// setOptionMasks(o);
}
AvAxis::~AvAxis()
{
if(options_ != NULL)
options_->unref();
options_ = NULL;
if(goptions_ != NULL)
goptions_->unref();
if(raster_ != NULL)
raster_->unref();
}
#if 0
static const double DEG2SEC = 240.0;
static inline double degrees2sec(const double deg)
{
// (360deg/day * 1day/24hrs * 1hr/3600sec = .004 deg/sec)
return deg *DEG2SEC;
}
static const double HRS2SEC = 3600;
static inline double hours2sec(const double hrs)
{
return hrs *HRS2SEC;
}
#endif
// Use the raster to supply label strings and formats.
void AvAxis::useRasterInfo( AvRaster *r)
{
double xmin, ymin, xmax, ymax;
if(r == NULL)
return; // Nothing to be done.
if(raster_ != r)
{ if(raster_ != NULL)
raster_->unref();
raster_ = r;
if(raster_ != NULL)
raster_->ref();
}
AvRaster::axisInfo *info = r->axisinfo();
if(info == NULL)
return; // Oops.
// Generate labels.
char label[256];
#if 0
// Get around problem with Sun's memory checker.
#if defined(__sun) && defined(__SunOS_5_5)
memset(label, 0, sizeof(label));
#endif
#endif
const int XAXIS = AvRaster::XAXIS;
const int YAXIS = AvRaster::YAXIS;
sprintf(label, "%s",info->label(XAXIS));
AxisGlobalOptions *opts = globalOptions();
// Append units abbreviation, if any.
if(opts != NULL)
{ const AxisGlobalOptions::ScaleInfo *inf = opts->scaleInfo(0);
const char *chrs = inf->abbrev().chars();
if((chrs != NULL) && (strlen(chrs) > 0))
{ strcat(label, " (");
strcat(label, chrs);
strcat(label, ")");
}
}
xLabel( label);
sprintf(label, "%s",info->label(YAXIS));
if(opts != NULL)
{ const AxisGlobalOptions::ScaleInfo *inf = opts->scaleInfo(1);
const char *chrs = inf->abbrev().chars();
if((chrs != NULL) && (strlen(chrs) > 0))
{ strcat(label, " (");
strcat(label, chrs);
strcat(label, ")");
}
}
yLabel( label);
title(r->getName());
// Supply a name for debugging.
sprintf(label, "Axis for %s", r->getName());
name(label);
// Initial values for world coordinate window.
xmin = info->minValue(XAXIS);
xmax = info->maxValue(XAXIS);
ymin = info->minValue(YAXIS);
ymax = info->maxValue(YAXIS);
// RA: display in HMS. Input format is degrees or RADIANS.
switch(info->printFormat(XAXIS)) {
case AvRaster::axisInfo::HMS:
xAxisInput_ = DEGREES;
xAxisOutput_ = HOURS;
break;
case AvRaster::axisInfo::HMS_RAD:// the _RAD parts haven't been tested.
xAxisInput_ = RADIANS;
xAxisOutput_ = HOURS;
break;
case AvRaster::axisInfo::DMS:
xAxisInput_ = HOURS;
xAxisOutput_ = DEGREES;
break;
case AvRaster::axisInfo::DMS_RAD:
xAxisInput_ = RADIANS;
xAxisOutput_ = DEGREES;
break;
default:
xAxisInput_ = FLOAT;
xAxisOutput_ = FLOAT;
break;
}
// DEC:display in DMS. Input format is degrees or RADIANS.
switch(info->printFormat(YAXIS)) {
case AvRaster::axisInfo::HMS:
yAxisInput_ = DEGREES;
yAxisOutput_ = HOURS;
break;
case AvRaster::axisInfo::HMS_RAD:
yAxisInput_ = RADIANS;
yAxisOutput_ = HOURS;
break;
case AvRaster::axisInfo::DMS:
// yAxisInput_ = DEGREES;
yAxisInput_ = HOURS; // This works, DEGREES doesn't.
yAxisOutput_ = DEGREES;
break;
case AvRaster::axisInfo::DMS_RAD:
yAxisInput_ = RADIANS;
yAxisOutput_ = DEGREES;
break;
default:
yAxisInput_ = FLOAT;
yAxisOutput_ = FLOAT;
break;
}
// Set the default World coordinate window values.
setWorldWindow(xmin, xmax, ymin, ymax);
// touch(); // Done in setWorldWindow.
}
void AvAxis::touch()
{
haveAxis_ = FALSE;
reset(-1); // tell AvPolyline to get rid of its point list.
AvPolyline::touch();
}
// Return the suggested number of tick to display along the X axis
static int numXTicks(const int size)
{
int nticks;
if(size < 128)
nticks = 3;
else
if(size <= 192)
nticks = 5;
else
if(size <= 256)
nticks = 7;
else
if(size <= 320)
nticks = 9;
else
nticks = 11;
return nticks;
}
static const float CHARHEIGHT = 0.025; // Character height w/o scaling.
// (= 1/40 max height (1.0)).
// Width of a character in pixels = CHARWIDTH*cscl*<width of drawing surface>.
// Characters are not constant width so this is just a gross estimate.
static const float CHARWIDTH = 0.014;
static const int NUMCHRS = 14; // Max # of chars in a horizontal label.
// "?? -05<deg>24'48"< >" (est.)
static const int CHARS_PER_TICK= 7; // Assumed max # of character/tick
// (From pgbox.f).
/* 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 * width
The width 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 AvAxis::computeCharScale( const float nchrs, const float space,
const int vpsize, const Boolean vertical)
{
float cscl, appc, chrsize, uppc;
if((nchrs == 0) || (vpsize == 0))
return 0.0;
appc = space/nchrs; // # of pixels/char available.
chrsize = (vertical) ? CHARHEIGHT : CHARWIDTH;
// Pixels/character for unit scaling.
uppc = chrsize*vpsize;
cscl = appc/uppc; // scale needed.
#if 0
printf("chrsize %.3f, appc %.2f, nchars %.1f space %.1f vpsize %d\n",
chrsize, appc, nchrs, space, vpsize);
#endif
return cscl;
}
#define BIGN 1000.0
// Return character scale needed for the box.
// 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.
// Caller will need to check the return. If it is zero, there
// wasn't enough room and/or printing is turned off.
float AvAxis::getBoxCharScale( const int vpwidth, const int nxchars,
int &xoptions, int &yoptions)
{
float cscale, maxScale;
float space, vcscale, hcscale;
// Max char scale to allow.
maxScale = maxCharSize()/(CHARHEIGHT*vpwidth);
if(maxScale == 0.0)
maxScale = BIGN; // Default to "no" limt.
//Compute horizontal space needed for vertical labels.
if(yoptions & STDLABELPOSITION)
space = (float) lm_;
else
if(yoptions & NONSTDLABELPOSITION)
space = (float) rm_;
else
space = 0.0; // Not printing
// If there is no room, turn off labels.
if(space == 0.0)
{ yoptions &= ~NOAXISLABEL;
vcscale = BIGN; // Something large.
}
else
vcscale = computeCharScale(NUMCHRS, space, vpwidth, FALSE);
// Horizontal space needed by horizontal labels.
if(xoptions & STDLABELPOSITION)
space = (float) bm_;
else
if(xoptions & NONSTDLABELPOSITION)
space = (float) tm_;
else
space = 0.0; // Not printing
// If there is no room, turn off labels.
if(space == 0.0)
{ xoptions &= ~NOAXISLABEL;
hcscale = BIGN; // Something large.
}
else
{ // Space was used to see if there was vertical room.
// Compute scaling needed to fit an estimated number
// of chars directly under the raster's viewport.
// (There is usually some overhang on the left).
float hsize = nxchars*CHARWIDTH*vpwidth;
hcscale = (vpwidth - (lm_ + rm_))/hsize;
}
cscale = (vcscale <= hcscale) ? vcscale : hcscale;
if(cscale == BIGN)
cscale = 0.0;
else
if(cscale > maxScale)
cscale = maxScale;
#if 0
printf("vcscale %f, hcscale %f scale %f maxScale %f\n",
vcscale, hcscale, cscale, maxScale);
#endif
return cscale;
}
///////////////////////////////////////////////
/* Function to round a value to a "NICE" number. This is PGPLOT's pgrnd
function translated to C because the f2c'd version doesn't seem to work
correctly with aipsview.
*/
static double nice_[] = { 2.0, 5.0, 10.0};
#define ABS(x) ( ((x) >= 0)? (x) : -(x))
double AvAxis::pgrnd(double x, int &nsub)
{
double frac, pwr,xlog, xx, value;
int i, ilog;
if(x == 0.0)
{ nsub = 2;
return 0.0;
}
xx = ABS(x);
xlog = log10(xx);
ilog = (int)xlog;
if(xlog < 0.0)
ilog -= 1;
pwr = pow(10.0, ilog);
frac = xx/pwr;
if(frac <= nice_[0])
i = 0;
else
if(frac <= nice_[1])
i = 1;
else
i = 2;
value = pwr*nice_[i];
value = ABS(value);
if(x < 0.0)
value = -value;
if(i == 0)
nsub = 2;
else
nsub = 5;
return value;
}
///////////////////////////////////////////////
#if 0
// Draw X, Y or Title.
void AvAxis::drawLabel( const AvAxisOptions::axisLabel *Label, float charScale)
{char *side;
float cscl;
float from = Label->fromEdge_.getValue();
float along = Label->alongEdge_.getValue();
float justify;
const char *label;
// Show this label?
if(!Label->drawLabel_.getValue())
return;
label = Label->text_.getString();
if((label == NULL) || (strlen(label) == 0))
return;
switch(Label->justify_.getValue()){
case AvAxisOptions::LEFT:
justify = 0.0;
break;
case AvAxisOptions::RIGHT:
justify = 1.0;
break;
default:
case AvAxisOptions::CENTER:
justify = 0.5;
break;
}
switch(Label->side_.getValue()){
case AvAxisOptions::LEFT:
side = "L";
break;
case AvAxisOptions::LEFTP:
side = "LV";
break;
case AvAxisOptions::RIGHT:
side = "R";
break;
case AvAxisOptions::RIGHTP:
side = "RV";
break;
case AvAxisOptions::BOTTOM:
side = "B";
break;
case AvAxisOptions::TOP:
side = "T";
break;
default:
side = "L";
}
// The resultant scale is the product of the scale computed by
// AvAxis, the global character scale and the per label scale.
cscl= (float)(charScale*Label->charScale_.getValue());
cscl *= (float) options_->gCharScale_.getValue();
cpgsave();
cpgsch(cscl); // Adjust character size.
from /= cscl; // Keeps distance constant when char scale varies.
#if 0
if(!Label->useGlobalColor_.getValue())
{int color = Label->color_.getValue();
cpgsci(color);
// Assume that colored text will overlay the image and that
// we want to clear its background.
if(color == 0)
cpgstbg(1);
else
cpgstbg(0);
}
#else
// Opaque background?
{int color = Label->color_.getValue();
cpgsci(color);
if(Label->opaqueBackground_.getValue())
{ if(color == 0)
cpgstbg(1);
else
cpgstbg(0);
}
}
#endif
cpgmtxt(side, from, along, justify, label);
cpgunsa();
}
#else
// Draw X, Y or Title.
void AvAxis::drawLabel( const AvAxisOptions::axisLabel *Label, float charScale)
{float cscl;
float x = Label->x_.getValue();
float y = Label->y_.getValue();
float angle = Label->angle_.getValue();
float justify;
const char *label;
// Show this label?
if(!Label->drawLabel_.getValue())
return;
label = Label->text_.getString();
if((label == NULL) || (strlen(label) == 0))
return;
switch(Label->justify_.getValue()){
case AvAxisOptions::LEFT:
justify = 0.0;
break;
case AvAxisOptions::RIGHT:
justify = 1.0;
break;
default:
case AvAxisOptions::CENTER:
justify = 0.5;
break;
}
// The resultant scale is the product of the scale computed by
// AvAxis, the global character scale and the per label scale.
cscl= (float)(charScale*Label->charScale_.getValue());
cscl *= (float) options_->gCharScale_.getValue();
cpgsave();
cpgsch(cscl); // Adjust character size.
// Opaque background?
{//int color = Label->color_.getValue();
int color;
if(Label->useGlobalColor_.getValue())
color = options_->gAxisColor_.getValue();
else
color = Label->color_.getValue();
cpgsci(color);
if(Label->opaqueBackground_.getValue())
{ if(color == 0)
cpgstbg(1);
else
cpgstbg(0);
}
}
cpgswin(0.0, 1.0, 0.0, 1.0);
#if 0
from /= cscl; // Keeps distance constant when char scale varies.
cpgmtxt(side, from, along, justify, label);
#else
cpgptxt(x, y, angle, justify, label);
//cout << "X: " << x << " Y: " << y << " Angle: " << angle << endl;
#endif
cpgunsa();
}
#endif
#if 0
// Return the position along a line given its fractional distance along it.
static inline float windowPosition(const double percent,
const float start, const float end)
{
return (float)percent*(end-start) + start;
}
#endif
#ifdef __sgi
double AvAxis::worldX2PG(const double value)
{ switch (xAxisInput_) {
case DEGREES:
return degrees2sec(value);
case HOURS:
return hours2sec(value);
case RADIANS:
return radians2sec(value);
default:
return value;
}
}
double AvAxis::worldY2PG(const double value)
{ switch (yAxisInput_) {
case DEGREES:
return degrees2sec(value);
case HOURS:
return hours2sec(value);
case RADIANS:
return radians2sec(value);
default:
return value;
}
}
#endif
// Draw the marker at the given location.
// extraScale is used to help set marker scale factor. (Usually its = 1.0).
// The x & y positions give the size and position of the viewport in
// world coordinates.
#if 0
void AvAxis::drawMarker(const AvAxisOptions::marker *Marker,
float extraScale, const float x0, const float x1,
const float y0, const float y1)
{float x,y;
if(Marker->show_.getValue() == 0)
return;
float scale = extraScale*Marker->scale_.getValue();
int color = Marker->color_.getValue();
int symbol = Marker->type_.getValue();
cpgsave();
// Is the position stored in world coords or as a fraction of the
// size of the viewport?
int format = Marker->xyFormat_.getValue();
if(format == AvAxisOptions::WORLD)
{ x = (float)worldX2PG(Marker->x_.getValue());
y = (float)worldY2PG(Marker->y_.getValue());
}
else
{ x = Marker->x_.getValue();
y = Marker->y_.getValue();
x = windowPosition(x, x0, x1-1) + 0.5;
y = windowPosition(y, y0, y1-1) + 0.5;
cpgswin(x0, x1, y0, y1);
}
// cpgsave();
cpgsci(color);
cpgsch(scale);
cpgpt(1, &x, &y, symbol);
cpgunsa();
}
#else
#if 0
void AvAxis::drawMarker(const AvAxisOptions::marker *Marker,
float extraScale, const float x0, const float x1,