-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAvImageWindow.cc
More file actions
2696 lines (2396 loc) · 73.8 KB
/
AvImageWindow.cc
File metadata and controls
2696 lines (2396 loc) · 73.8 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
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
//# aipsview@ncsa.uiuc.edu
//# --------------------------------------------------
//
// $Header: /home/cvs/aips++/code/trial/apps/aipsview/Attic/AvImageWindow.cc,v 19.0 2003/07/16 05:47:44 aips2adm Exp $
//
// $Log: AvImageWindow.cc,v $
// Revision 19.0 2003/07/16 05:47:44 aips2adm
// exhale: Base release 19.000.00
//
// Revision 18.0 2002/06/07 21:29:21 aips2adm
// exhale: Base release 18.000.00
//
// Revision 17.3 2002/01/22 21:59:46 hravlin
// Added (uInt) cast for NSCALES. And a cast for ButtonMasks. (For 64 bit cmpls).
//
// Revision 17.2 2002/01/07 22:31:59 hravlin
// Removed check for __P.
//
// Revision 17.1 2002/01/03 22:07:02 hravlin
// Added support for OpenGL/WIREGL.
//
// Revision 17.0 2001/11/12 19:42:50 aips2adm
// exhale: Base release 17.000.00
//
// Revision 16.0 2001/05/03 01:42:57 aips2adm
// exhale: Base release 16.000.00
//
// Revision 15.0 2000/10/26 17:12:02 aips2adm
// exhale: Base release 15.000.00
//
// Revision 14.1 2000/07/18 16:45:58 hravlin
// Changed some char * to const char *.
//
// Revision 14.0 2000/03/23 16:08:50 aips2adm
// exhale: Base release 14.000.00
//
// Revision 13.5 1999/09/28 21:54:44 hravlin
// Worked on color use in setInclude. Removed references to Gadgets.
//
// Revision 13.4 1999/09/27 15:50:40 hravlin
// Added busy indicator around printImage.
//
// Revision 13.3 1999/09/24 21:14:35 hravlin
// More work on print options: Filename is now from printOptions_, added
// user comments and other PostScript file comment changes.
//
// Revision 13.2 1999/09/15 21:29:48 hravlin
// Added new "Print Options" panels and printing to new PostScript driver.
//
// Revision 13.1 1999/08/25 19:47:29 hravlin
// Edits (mostly casts) to remove compiler warnings.
//
// Revision 13.0 1999/08/10 18:40:38 aips2adm
// exhale: Base release 13.000.00
//
// Revision 12.0 1999/07/15 00:23:47 aips2adm
// exhale: Base release 12.000.00
//
// Revision 11.0 1998/10/03 07:01:24 aips2adm
// exhale: Base release 11.000.00
//
// Revision 10.0 1998/07/20 17:55:29 aips2adm
// exhale: Base release 10.000.00
//
// Revision 9.2 1998/01/14 16:24:19 hr
// In mouseMoveCB(), added loop to ignore all but last motion notify event.
//
// Revision 9.1 1997/12/08 22:34:42 hr
// Added ability to draw a cross in drawBox().
//
// Revision 9.0 1997/08/25 21:30:14 aips2adm
// exhale: Base release 09.000.00
//
// Revision 8.6 1997/08/01 21:14:56 hr
// Changes to handle rewrite of AvPosition.
//
// Revision 8.5 1997/06/11 19:10:36 hr
// Including math.h brought the _P problem for g++.
// Removed two unused variables.
//
// Revision 8.4 1997/06/11 19:04:56 hr
// Added printing of some simple statistics.
//
// Revision 8.3 1997/05/20 17:41:02 hr
// Added the "Redisplay image" menu item to dump cache, etc. information
// when the user knows the image data have changed.
//
// Revision 8.2 1997/04/15 20:04:21 hr
// Added "Misc" menu and "Raw Position".
//
// Revision 8.1 1997/02/20 14:55:10 hr
// Changed setInclude() to ignore requests to change state if new is same
// as old.
//
// Revision 7.6 1997/02/05 17:41:25 hr
// Changed an unsigned/int comparision. Added calls to IVP's edit menus.
//
// Revision 7.5 1997/01/24 20:24:21 hr
// Added mouse tracker conductor.
// Moved Options:Setup menu to Edit. Added Axis and Wedge setup entries.
// Changed the way AvConfigInfo::writeOptions() gets called.
//
// Revision 7.4 1997/01/09 18:23:38 hr
// Changed init() to check for "DisplaySize" resource and to set "equalScales_"
// to FALSE if the initial window size is not square.
//
// Revision 7.3 1996/12/12 08:50:02 droberts
// Final update from monet archive.
//
// Revision 1.16 1996/11/12 15:45:48 hr
// Was overrunning character buffer in displayTitle().
//
// Revision 1.15 1996/11/11 17:59:46 hr
// Moved equalScales() to here from AvImageViewItem. Added code to
// set "X=Y" toggle if equalScales_ gets changed elsewhere.
//
// Revision 1.14 1996/11/11 16:07:31 hr
// Widespread changes to support independent scaling of X and Y axes.
//
// Revision 1.13 1996/11/06 17:02:01 hr
// Sun's 4.1.3 compiler complains about variables named "end" overriding
// variables of the same name in an outer scope.
//
// Revision 1.12 1996/11/05 21:15:51 hr
// Added menu options to allow user to save configuration settings.
//
// Revision 1.11 1996/10/02 17:22:52 hr
// In mouse movement routines, calls to viewPanel::setSlice needed say
// z value was SR.
//
// Revision 1.10 1996/10/02 16:57:38 hr
// Added setPosition(s) to set included windows to a new AvPosition.
//
// Revision 1.9 1996/09/27 17:04:49 hr
// Removed an unused routine.
//
// Revision 1.8 1996/09/27 16:40:35 hr
// Added a pointer to the imported accessor in order to keep track of
// whether AvCLUImageSetter had already disconnected from it.
//
// Revision 1.7 1996/09/25 21:30:46 hr
// Mouse/cursor handling routines were heavily modified. Several old routines
// were removed. Several variable's names were changed.
// Added code to support tracking of cursor in 3D.
// A couple of classes are no longer friends.
//
// Revision 1.6 1996/09/20 20:19:35 pixton
// Prefixed all classes with Av
//
// Revision 1.5 1996/09/20 18:40:23 hr
// Fixed a number of <xyz>Axis() -> <ZYZ>AXIS problems.
//
// Revision 1.4 1996/09/18 19:27:35 hr
// More integration with AvAccessor.
//
// Revision 1.3 1996/09/10 16:55:28 hr
// Initial changes for integration with AvAccessor & AvDataSet.
//
// Revision 1.2 1996/08/14 18:59:14 hr
// Changes to remove g++ warnings (from bglenden).
//
// Revision 1.1 1996/07/11 21:31:21 pixton
// Automated Checkin
//
// Revision 1.39 1996/06/18 18:46:16 pixton
// Copyright Update
//
// Revision 1.38 1996/04/16 20:29:27 hr
// Added more scale menu entries. Added call to setAtWindow().
//
// Revision 1.37 1996/04/11 16:09:57 hr
// Some minor changes to the scale menus.
//
// Revision 1.36 1996/04/08 14:44:35 hr
// Moved print and close image to new "File" menu.
//
// Revision 1.35 1996/03/27 22:25:56 hr
// Changed the way the SCALE menu is generated so that really non square
// images will have a selection of scale factors.
// If region() is called and the region is not set, the return parameters
// are set to 0.
//
// Revision 1.34 1996/03/20 17:35:44 hr
// Changes to refer to AvXColorApp rather than AvApp.
//
// Revision 1.33 1996/03/19 22:02:16 hr
// Changed the print menu string to "Print Image".
//
// Revision 1.32 1996/03/13 16:00:01 hr
// Moved "Options" submenu to last.
//
// Revision 1.31 1996/03/07 21:15:51 hr
// The filename passed to AvPGCanvas is now retrieved from the imagesetter
// rather than vItem_.
//
// Revision 1.30 1996/02/29 17:26:34 hr
// Added PRINT menu entry.
//
// Revision 1.29 1996/02/23 17:08:13 hr
// Replaced use of getRasterOffsets with getMargins.
//
// Revision 1.28 1996/02/09 18:17:18 hr
// Moved Region/Profile menu building & handling to AvImageViewPanel.
//
// Revision 1.27 1996/02/08 18:15:53 hr
// Added a separator to the show menu. init takes into account potential
// axis offsets (perhaps pointlessly).
//
// Revision 1.26 1996/02/05 21:33:05 hr
// Removed "75%" scaling since the X Canvas can only scale in integral
// amounts.
//
// Revision 1.25 1996/02/02 15:35:45 hr
// Redid Option menu. "Show" now controls all displays. "Setup" has been
// added to support setup windows (eg. contour user interface).
//
// Revision 1.24 1996/01/30 22:54:22 hr
// Added Axis menu item.
// Changed IJKToWindow and WindowToIJK to handle possible offset of raster
// image.
//
// Revision 1.23 1996/01/26 21:45:54 hr
// raster_ wasn't being initialized to NULL.
//
// Revision 1.22 1996/01/24 18:16:34 hr
// Added support for contouring menus.
// Ignore requests to replace raster_ with itself.
//
// Revision 1.21 1995/11/13 22:07:34 hr
// Under certain conditions (small fonts?) showImage() wasn't being called.
// Now, setDisplayObject gets called when the AvCLUImage object gets
// set.
//
// Revision 1.20 1995/09/20 20:03:06 baker
// Release Beta 1.0
//
// Revision 1.20 1995/09/20 01:56:34 baker
// Release Beta 1.0
//
// Revision 1.19 1995/09/07 14:45:02 hr
// Wasn't terminating the string copied from buttonName in processMenu.
//
// Revision 1.18 1995/07/11 21:28:59 hr
// Added more Scale menu items. Renamed "Info"/"Show" menu & submenus.
// Added "Invisible" to "Region Draw Mode" menu and renamed the menu.
// Added 'updateBox() & boxType_ to support disabling box drawing from
// imageViewPanels toggles.
// moveMouseCB now checks to make sure x/y are in bounds before doing anything.
// IJKToWindow - added check for scalefactor > 1.
//
// Revision 1.17 1995/06/16 18:00:05 hr
// "Show Profile" menu item is only generated for multiplane datasets.
// Let AvImageViewPanel hide profile/region when built.
//
// Revision 1.16 1995/06/12 21:19:14 hr
// Fixed ghost box problem (I hope).
// Scale menu will only present 'reasonable' choices.
// Added viewPanel() function.
//
// Revision 1.15 1995/06/09 19:37:30 hr
// Moved creation of the imageViewPanel here from AvImageView.
// The AvImageViewPanel can be created either inside the imageWindow or in its
// own shell.
// The Scale factor is now displayed with the window title.
//
// Revision 1.14 1995/05/24 14:59:00 hr
// Worked on getting box drawing to work between windows and with different
// scales. For now, drawBox takes IJK args.
//
// Revision 1.13 1995/05/18 20:56:11 hr
// Turned synchronized picking back on.
// Changed "Include" to a submenu.
// Added "Region Draw Mode".
//
// Revision 1.12 1995/05/12 21:20:09 hr
// Changes to data clip min/max are propagated to profile display.
//
// Revision 1.11 1995/05/12 14:24:56 hr
// Temporarily remove "Draw Mode 1".
//
// Revision 1.10 1995/05/11 21:51:34 hr
// Numerous changes dealing with window scaling:
// Doesn't initiate a redisplay of the display list when window is resized
// since the canvas will do it.
// resizeCB may be called from the Canvas callback list.
// If expose count is > 0, ignore.
// If the resize callback gets recursively called, ignore.
//
// Revision 1.9 1995/05/05 15:11:39 hr
// Check for boxStart, boxEnd in resizeCB.
//
// Revision 1.8 1995/05/05 14:52:00 hr
// Added support for synchronized picking.
//
// Revision 1.7 1995/04/25 16:52:02 hr
// Added redraw flag to scale.
//
// Revision 1.6 1995/04/14 19:25:15 hr
// Changes to allow pixmap caching to work.
//
// Revision 1.5 1995/04/07 21:06:18 hr
// Need to ref/unref the canvas
//
// Revision 1.4 1995/04/03 15:52:16 hr
// Reset included flag when turning off include toggle
//
// Revision 1.3 1995/03/30 22:21:56 hr
// Renamed optionMenu in init to avoid name conflict.
// Removed fallbacks variable from class.
//
// Revision 1.2 1995/03/24 15:46:54 baker
// *** empty log message ***
//
// Revision 1.1 1995/03/16 19:45:22 pixton
// Initial revision
//
//
//---------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
#include <string.h> // strrchr
#include <X11/cursorfont.h>
#include <math.h> // for statistics.
#include <Xm/Xm.h>
#include <Xm/ArrowB.h>
#include <Xm/Label.h>
#include <Xm/DrawingA.h>
#include <Xm/Form.h>
#include <Xm/Frame.h>
#include <Xm/Separator.h>
#include <Xm/PushB.h>
#include <Xm/RowColumn.h>
#include <Xm/Text.h>
#include <Xm/TextF.h>
#include <Xm/ToggleB.h>
#include <Xm/Command.h>
#include <Xm/MainW.h>
#include "AvCLUImage.h"
#include "AvCLUImageSetter.h" // For menus
#include "AvImageDataPanel.h"
#include "AvImageView.h"
#include "AvImageViewPanel.h"
#include "AvImageWindow.h"
#include "AvXCanvases.h"
#ifdef AVOGL
#include "AvGLCanvas.h"
#endif
#include "AvPosition.h"
#include "AvPSCanvas.h"
#ifdef TCL
#include "AvConfigInfo.h"
#endif
#include "AvPrintOptions.h"
#include "AvPrintConfig.h"
// If defined, reports how long statistics calculations take.
//#define TIMEIT
#ifdef TIMEIT
#include <time.h>
#endif
////////////////////////////////////////////////////////////////
/* Object to do calculations on an image plane. It is defined here since
it is used here. It could be anywhere. If a GLISH interface is ever
needed, it will probably be put somewhere else. (Functions are at the
bottom of this file).
*/
// Perform a set of statistics on current image plane of an accessor.
// Calculations are currently done at creation time.
class AvStatistics : public AvResource
{
public:
// Creating the object generates the statistics.
AvStatistics(AvAccessor *ac);
AvStatistics(AvAccessor *ac,
const float clipMin, const float clipMax);
AvAccessor *accessor()const{return accessor_;}
class Stats {
public:
Stats();
~Stats();
// Do calculations for point at x, y.
// (Currently unused since it takes longer).
void calc(const float datum, const int x, const int y);
void init(AvAccessor *ac, const float clipMin, const float clipMax);
void init(AvAccessor *ac);
// # of data points involved. (Width()*Height() - #blanked - #outside).
void numpoints(const int v){ npoints_ = v;}
int numpoints()const{return npoints_;}
// Sum of values.
void sum(const double v){ sum_ = v;}
double sum()const{return sum_;}
// Sum of square of values.
void sumsqr(const double v){ sumsqr_ = v;}
double sumsqr()const{return sumsqr_;}
//
double rms()const;
double average()const
{return (numpoints()>0) ? sum()/numpoints() : 0.0 ;}
Boolean checkClip()const{return checkClip_;}
void checkClip(const Boolean cc){checkClip_ = cc;}
void dataMin(const float v, const int x, const int y)
{ dataMin_ = v; minWhere_(0) = x; minWhere_(1) = y;}
void dataMax(const float v, const int x, const int y)
{ dataMax_ = v; maxWhere_(0) = x; maxWhere_(1) = y;}
void overcount(const int nover){overcount_ = nover;}
int overcount()const {return overcount_;}
void undercount(const int nunder){undercount_ = nunder;}
int undercount()const {return undercount_;}
float clipMin()const{return clipMin_;}
float clipMax()const{return clipMax_;}
float dataMin()const{return dataMin_;}
float dataMax()const{return dataMax_;}
AvString clipMinStr()const;
AvString clipMaxStr()const;
AvString dataMinStr()const;
AvString dataMaxStr()const;
AvIPosition whereMinIJK()const {return minWhere_;}
AvIPosition whereMaxIJK()const {return maxWhere_;}
friend ostream &operator<<(ostream &s, const AvStatistics::Stats &x);
private:
AvAccessor *accessor_;
int npoints_; // # of data points in calculations.
// (Width() x Height() - #ignored).
int overcount_, // # of points outside range.
undercount_;
Boolean checkClip_; // Ignore clipMin/Max if true.
float clipMin_, // Ignore values outside this range.
clipMax_;
float dataMin_,dataMax_; // min/max in region.
AvIPosition minWhere_, // Where in data set. (IJK coords).
maxWhere_;
double sum_; // sum(D(i,j))
double sumsqr_; // sum(D(i,j)^2)
};
// Display values.
void print(ostream &output);
protected:
~AvStatistics();
private:
void init(AvAccessor *ac, const float clipMin, const float clipMax);
void calc(); // Do the calculations.
AvAccessor *accessor_;
void reset(const float min, const float max);
Stats stats_[2]; // Only within clip min/max.
int blankcount_; // # of blanked pixels.
};
////////////////////////////////////////////////////////////////
// If the scale factor is > than this, a box will be drawn around the data
// point as the cursor is drug around the image. Otherwise, it is only drawn
// when the mouse button is released.
static const float MinBoxScale = 6.0;
const char * AvImageWindow::className () const
{
return ("AvImageWindow");
}
#if 0
// Use of this constructor may result in problems since AvImageWindow
// now assumes it has vItem_ during construction.
AvImageWindow::AvImageWindow
(char * appClass, int & argc, String * argv, String * fallbacks)
: AvDisplayWindow (appClass, argc, argv, fallbacks)
{
cerr << "AvImageWindow::AvImageWindow called with NULL ImageViewItem.\n";
vItem_ = NULL;
init ();
}
#endif
// Which accessor actions we're interested in.
static const int ACCMASK = AvAccessor::DEFAULTMASK | AvDataSet::DEFAULTMASK
| AvAccessor::PLANE;
// 'v' should not be NULL.
AvImageWindow::AvImageWindow(Widget parent, int buildInsideParent,
AvImageViewItem * v): AvDisplayWindow (parent, buildInsideParent)
{
vItem_ = v;
// Connect to accessor.
accessor_ = vItem_->accessor();
accessor()->ref();
accessor()->addCallback(&AvImageWindow::accessorCB_,
ACCMASK, this, NULL);
init();
}
// List of possible menu scale factors. A separator is inserted where there
// is a NULL. Not all of these will be used since some would result in
// an image of too weird a size.
static const char *scales[] = {
"10000%","9000%", "8000%", "7000%", "6000%", "5000%", "4000%",
"3200%", "2000%", "1600%", "1200%", "1000%", "800%", "600%", "500%",
"400%", "300%", "200%", "100%",
NULL,
"50%", "33%", "25%", "12.5%", "10%", "6.25%", "5%"
};
#define NSCALES (uInt)(sizeof(scales)/sizeof(*scales))
static const char *EQUALSCALES = "X = Y";
// Minimum size (in pixels) we will allow menu to scale an image.
// Minimum value is probably 1.
static const int minSize = 64;
static int maxWidth = 0; // Filled in later.
static int maxHeight = 0; // Filled in later.
static const char *PRINT = "Print Image";
// Flush caches, etc. Then redisplay. Used if user knows data file has changed.
static const char *REDISPLAY = "Redisplay Image";
static const char *RAWPOSITION = "Raw Position";
static const char *PRINTSTATS = "Print Statistics";
#ifdef TCL
static const char *SAVEINFO = "Update file's rc";
static const char *SAVEALLINFO = "Create filerc.list";
#endif
static const char *PRINTOPTIONS = "Print Options";
// Build the scale, xscale or yscale menus.
void AvImageWindow::buildScaleMenu(AvMenu *menu, const float estScale,
const int Size, const int maxSize, const int option)
{Boolean needSep = FALSE; // To keep a separator from being last on menu.
for(int i=0; i< (int)NSCALES; i++)
if(scales[i] == NULL)
needSep = TRUE;
else
{ Boolean needItem;
// Force the scale factor to be included if it is close to the
// estimated initial scale size.
float scl = atof(scales[i])*.01;
float delta = scl - estScale;
if(delta < 0.0) delta = -delta;
needItem = (delta < .01) ? TRUE: FALSE;
int size = (int)((scl*Size) + 0.5);
// Only include scale factor if it will generate a reasonable size
// image or it is a likely candidate for the initial scale factor.
if(((size >= minSize) && (size <= maxSize)) || needItem)
{ if(needSep)
{ needSep = FALSE;
menu->add ("", SEPARATOR);
}
menu->add (scales[i], PUSH_BUTTON, option);
}
}
}
void AvImageWindow::init (int makeMenus)
{
int marginWidth=0, marginHeight=0;
xScaleFactor_ = 1.0;
yScaleFactor_ = 1.0;
equalScales_ = TRUE; // X & y scales are initially forced to be the same.
equalScalesW_ = NULL;
// All of these are in SR coordinates.
// Currently drawn box.
boxStart_.x = boxStart_.y = boxEnd_.x = boxEnd_.y = 0;
cursor_.x = cursor_.y = 0; // Cursor location
included_ = FALSE;
track3D_ = TRUE;
boxStarted_ = FALSE;
boxDrawn_ = FALSE;
boxType_ = NoBox;
drawCross_ = FALSE; // Don't draw cross in cursor/region box.
// CENTER is not implemented yet.
regionType_ = CORNERS; // Default region type.
viewPanel_ = NULL;
raster_ = NULL;
printConfig_ = NULL;
printOptions_ = new AvPrintOptions(accessor()->dataset()->fileName(),
"print");
printOptions_->ref();
// did the user set the width and height in the resources file?
Dimension ww = getIntegerResource ("DisplayWidth");
Dimension hh = getIntegerResource ("DisplayHeight");
Dimension sz = getIntegerResource ("DisplaySize");
if(sz > 0) // Overrides width & height
hh = ww = sz;
// if not, set to 256 by 256
if (ww == 0) ww = 256;
if (hh == 0) hh = 256;
if(ww != hh)
equalScales_ = FALSE;
if (makeMenus) {
AvMenu *file_Menu = new AvMenu(7);
file_Menu->add (PRINT, PUSH_BUTTON, SV_OPTION);
file_Menu->add (REDISPLAY, PUSH_BUTTON, SV_OPTION);
#ifdef TCL
file_Menu->add ("", SEPARATOR);
file_Menu->add (SAVEINFO, PUSH_BUTTON, SV_OPTION);
file_Menu->add (SAVEALLINFO, PUSH_BUTTON, SV_OPTION);
#endif
file_Menu->add ("", SEPARATOR);
file_Menu->add ("Close View", PUSH_BUTTON, SV_OPTION);
editMenu = new AvMenu(10);
AvCLUImageSetter::buildSetupMenu(editMenu, SV_SETUP);
AvImageViewPanel::buildEditMenu(editMenu, SV_SETUP, accessor_);
editMenu->add(PRINTOPTIONS, PUSH_BUTTON, SV_SETUP);
// The scale menu is built using what are considered the most useful
// entries of the above list. The scaling that is assumed to be the
// initial value is always included.
scaleMenu_ = new AvMenu (NSCALES+4);
xScaleMenu_ = new AvMenu (NSCALES+2);
yScaleMenu_ = new AvMenu (NSCALES+2);
scaleMenu_->add (EQUALSCALES, TOGGLE_BUTTON, SV_SCALE, NULL, equalScales_);
scaleMenu_->add ("X", SUBMENU_BUTTON, 0, xScaleMenu_);
scaleMenu_->add ("Y", SUBMENU_BUTTON, 0, yScaleMenu_);
scaleMenu_->add ("", SEPARATOR);
// Menus won't scale an image to be greater than about 1 screen size.
maxWidth = WidthOfScreen(XtScreen(parentWidget()));
maxHeight = HeightOfScreen(XtScreen(parentWidget()));
int width = vItem_->getCLUImage()->width();
int height = vItem_->getCLUImage()->height();
float estXscale = (float)ww/(float)width; // Guess of initial scale.
float estYscale = (float)hh/(float)height; // Guess of initial scale.
float estScale = (width+height)/2.0;
buildScaleMenu(scaleMenu_, estScale, (width+height)/2,
(maxWidth+maxHeight)/2, SV_SCALE);
buildScaleMenu(xScaleMenu_, estXscale, width, maxWidth, SV_XSCALE);
buildScaleMenu(yScaleMenu_, estYscale, height, maxHeight, SV_YSCALE);
// Add in any offsets (due to the display of the axis).
vItem_->getCLUImage()->getMargins(marginWidth, marginHeight);
ww += marginWidth;
hh += marginHeight;
////////////////////////////////////////////////////////////////
// Build other menus //
////////////////////////////////////////////////////////////////
AvMenu * optionMenu0 = new AvMenu (10);
AvMenu *showMenu = new AvMenu(16);
optionMenu0->add ("Show", SUBMENU_BUTTON, 0, showMenu);
// The profile and region displays can be part of the image window or
// separate. The related menus are built to reflect that.
if((panelIsInside_ = AvImageView::buildInside()))
{ AvImageViewPanel::buildShowMenu(showMenu, SV_OPTION, vItem_);
}
else
showMenu->add ("Show View Info", TOGGLE_BUTTON, SV_OPTION);
showMenu->add ("", SEPARATOR);
// Let the image setter add its own menu items.
AvCLUImageSetter::buildShowMenu(showMenu, SV_SHOW);
// (Un)Include all windows.
AvMenu* includeMenu = new AvMenu(6);
includeMenu->add("This", PUSH_BUTTON, SV_OPTION);
includeMenu->add("All", PUSH_BUTTON, SV_OPTION);
includeMenu->add("None", PUSH_BUTTON, SV_OPTION);
includeMenu->add("Invert", PUSH_BUTTON, SV_OPTION);
includeMenu->add("", SEPARATOR);
includeMenu->add ("Track 3D", TOGGLE_BUTTON, SV_OPTION, NULL,
track3D());
optionMenu0->add ("Include", SUBMENU_BUTTON, 0, includeMenu);
// Different line drawing styles for region.
AvMenu* drawMenu = new AvMenu(5);
drawMenu->add("Normal", PUSH_BUTTON, SV_OPTION);
drawMenu->add("Mode 1", PUSH_BUTTON, SV_OPTION);
drawMenu->add("Mode 2", PUSH_BUTTON, SV_OPTION);
drawMenu->add("Invisible", PUSH_BUTTON, SV_OPTION);
drawMenu->add("Cross", TOGGLE_BUTTON, SV_OPTION);
optionMenu0->add ("Box Draw Mode", SUBMENU_BUTTON, 0, drawMenu);
AvMenu *miscMenu = new AvMenu(4);
miscMenu->add(RAWPOSITION, TOGGLE_BUTTON, SV_OPTION, NULL, 0);
miscMenu->add(PRINTSTATS, PUSH_BUTTON, SV_OPTION);
optionMenu0->add ("Misc", SUBMENU_BUTTON, 0, miscMenu);
AvMenu * mainMenu = new AvMenu (4);
mainMenu->add ("File", SUBMENU_BUTTON, 0, file_Menu);
mainMenu->add ("Edit", SUBMENU_BUTTON, 0, editMenu);
mainMenu->add ("Scale", SUBMENU_BUTTON, 0, scaleMenu_);
mainMenu->add ("Options", SUBMENU_BUTTON, 0, optionMenu0);
makeMainMenu (mainMenu);
}
XtVaSetValues (parentWidget_,
XmNcolormap, AvXColorApp::colormap(),
XmNallowShellResize, TRUE,
NULL);
// Create the info panel either inside this window's shell or in its own.
if(AvImageView::buildInside())
{ Widget parts = XtVaCreateManagedWidget
("ImageWindow", xmFormWidgetClass, baseWidget_,
XmNspacing, 3,
XmNmarginTop, 10,
XmNmarginWidth, 8,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
// XmNtopAttachment, XmATTACH_FORM,
// XmNbottomAttachment, XmATTACH_FORM,
NULL);
// The frame that goes around the data panel.
Widget infoFrame = XtVaCreateManagedWidget("infoFrame",
xmFrameWidgetClass, parts,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
XmNtopAttachment, XmATTACH_FORM,
NULL);
if(vItem_ != NULL)
{ // The panel that shows info: region, profile, etc.
viewPanel_ = new AvImageViewPanel(infoFrame, TRUE, *vItem_);
viewPanel_->show(); // Show panel.
}
// The frame that goes around the canvas.
workArea_ = XtVaCreateManagedWidget("DispWin2WorkArea",
xmFrameWidgetClass, parts,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, infoFrame,
XmNbottomAttachment, XmATTACH_FORM,
// If these are set, aipsview under Linux can't resize.
// (eg. profiles or scale)
// XmNwidth, ww,
// XmNheight, hh,
NULL);
}
else // Build imageViewPanel in its own shell.
{
if(vItem_ != NULL)
viewPanel_ = new AvImageViewPanel(parentWidget_, FALSE, *vItem_);
// The frame that goes around the canvas.
workArea_ = XtVaCreateManagedWidget("DispWin2WorkArea",
xmFrameWidgetClass, mainWindow_,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
XmNtopAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
NULL);
}
// make the X canvas within drawing frame
int i = 0;
Arg args[10];
#if 0
XtSetArg(args[i], XmNtopAttachment, XmATTACH_FORM); i++;
XtSetArg(args[i], XmNleftAttachment, XmATTACH_FORM); i++;
XtSetArg(args[i], XmNrightAttachment, XmATTACH_FORM); i++;
XtSetArg(args[i], XmNbottomAttachment, XmATTACH_FORM); i++;
#endif
XtSetArg(args[i], XmNwidth, ww); i++;
XtSetArg(args[i], XmNheight, hh); i++;
#ifdef AVOGL
AvGLCanvas *canvas = new AvGLCanvas
("DisplayWin2Canvas", workArea_, AvXColorApp::palette(), args, i);
canvas->ref();
#else
AvXWindow *canvas = new AvXWindow
("DisplayWin2Canvas", workArea_, AvXColorApp::palette(), args, i);
canvas->ref();
#endif
canvas->setRasterCacheParameters(TRUE, 128); // Enable Raster caching.
canvas_ = canvas;
drawArea_ = canvas->widget();
XtVaSetValues(workArea_, XmNworkWindow, drawArea_, NULL);
XtAddCallback (drawArea_, XmNexposeCallback,
(XtCallbackProc) &AvImageWindow::redrawCB,
(XtPointer) this);
XtManageChild (baseWidget_);
XtVaSetValues (parentWidget_, XmNminWidth, 172, NULL);
XGCValues values;
// fill in foreground and background
XtVaGetValues (drawArea_,
XmNforeground, &values.foreground,
XmNbackground, &values.background,
XmNheight, &windowHeight_,
XmNwidth, &windowWidth_,
NULL);
values.foreground = values.foreground ^ values.background;
values.line_style = LineSolid;
values.function = GXinvert;
gc_ = XtGetGC (drawArea_,
GCForeground | GCBackground | GCFunction | GCLineStyle,
&values);
feedbackCursor_ = XCreateFontCursor (display_, XC_crosshair);
if(!externalDrawingArea())
XtAddCallback (drawArea_, XmNresizeCallback,
(XtCallbackProc) &AvImageWindow::resizeCB,
(XtPointer) this);
if(vItem_ != NULL)
{ displayTitle ();
viewPanel_->setTitle (vItem_->label());
}
activateFeedbackHandlers ();
tracker_ = new AvConductor();
}
static const char * TITLEFMT="%s %sx%s";
void AvImageWindow::displayTitle()
{
if(vItem_ == NULL)
return;
float xScale = xScaleFactor_*100;
float yScale = yScaleFactor_*100;
char xbuf[64], ybuf[64];
if((float)(int)xScale == xScale)
sprintf(xbuf, "%d%%", (int)xScale);
else
sprintf(xbuf, "%.1f%%", xScale);
if((float)(int)yScale == yScale)
sprintf(ybuf, "%d%%", (int)yScale);
else
sprintf(ybuf, "%.1f%%", yScale);
// Currently, some datasets return the path with the fileName() call.
// So make sure there is no path name.
const char *ptr = strrchr(vItem_->label(), '/');
if(ptr == NULL)
ptr = vItem_->label();
else
ptr += 1;
char *title = new char[ strlen(vItem_->label()) +
strlen(xbuf) + strlen(ybuf) +
strlen(TITLEFMT) + 4];
sprintf(title, TITLEFMT, ptr, xbuf, ybuf);
setTitle(title);
delete [] title;
}
// Handle resize events. Called by resizeCB.
void AvImageWindow::resize (Widget )
{
// Resizing erases the box
boxDrawn_ = FALSE;
// When the window gets resized, we need to ensure that the raster gets
// scaled to its best fit.
// Pick up new size.
if(externalDrawingArea())
{ windowWidth_ = canvas()->width();
windowHeight_ = canvas()->height();
} else
XtVaGetValues(drawArea_, XmNheight, &windowHeight_,
XmNwidth, &windowWidth_, NULL);
#if 0
printf("AvImageWindow::resize: width %d, height %d\n",
windowWidth_, windowHeight_);
#endif
vItem_->fitRasterToWindow ();
// Then, the window needs to change size to fit the raster.
// Also, redraw the image and any box.
vItem_->fitWindowToRaster (TRUE);
}
void AvImageWindow::resizeCB (Widget w, AvImageWindow * win,
XmDrawingAreaCallbackStruct *)
{
XtRemoveCallback (w, XmNresizeCallback,
(XtCallbackProc) &AvImageWindow::resizeCB,
(XtPointer) win);
win->resize(w);
XtAddCallback (w, XmNresizeCallback,
(XtCallbackProc) &AvImageWindow::resizeCB,
(XtPointer) win);
}
// Set/clear the included flag.
void AvImageWindow::setInclude(const Boolean include)
{
// Ignore if trying to set to current state.
if(include == included_)
return;
if(include)
{ // save the current color
XtVaGetValues(mainMenuBar_,
XmNbackground, &menuBackgroundColor_,
NULL);
// Change the background color to signify "Included"
// Child buttons should not be affected since they are
// Widgets rather than gadgets.
Pixel incbackground = AvApp::whitePixel();
if(incbackground == menuBackgroundColor_)
incbackground = AvApp::blackPixel();
XtVaSetValues(mainMenuBar_,
XmNbackground, incbackground,
NULL);
// set the "include" flag
included_ = TRUE;
}
else
{
// change the color back to its original state
XtVaSetValues (mainMenuBar_,
XmNbackground, menuBackgroundColor_,
NULL);
// reset the "include" flag
included_ = FALSE;
}
}
// Set/clear the included flag for all windows.
void AvImageWindow::setIncludeList(const IncludeMode mode)
{
AvImageViewItem **list;
int listlen;
if(mode == INCTHIS)
{ setInclude( ! include());
return;
}
list = AvImageView::instance()->getImageViewList(listlen,
AvImageView::ALL);
for(int i=0; i< listlen; i++)
{AvImageWindow *win = list[i]->getImageWindow();
switch (mode) {
case INCALL:
win->setInclude(TRUE);
break;
case INCINVERT:
win->setInclude(! win->include());
break;
case INCNONE:
win->setInclude(FALSE);
break;
default:;
}
}
delete [] list;
}
// Change the way region lines are drawn.
void AvImageWindow::setRegionDrawMode(const DrawMode mode)
{
XGCValues values;