-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgrf_display_opengl.cpp
1984 lines (1805 loc) · 37.3 KB
/
grf_display_opengl.cpp
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
# include <cstdlib>
# include <ctime>
# include <cmath>
# include <fstream>
# include <iostream>
# include <iomanip>
//
// This is the include statement I need for Mac OS X.
//
# include <GLUT/glut.h>
//# include <GL/glut.h>
//# include <GL/freeglut.h>
using namespace std;
int main ( int argc, char *argv[] );
bool ch_eqi ( char ch1, char ch2 );
int ch_to_digit ( char ch );
void display ( );
void grf_data_print ( int node_num, int edge_num, int edge_pointer[],
int edge_data[], double xy[] );
void grf_data_read ( string input_filename, int node_num, int edge_num,
int edge_pointer[], int edge_data[], double xy[] );
void grf_header_print ( int node_num, int edge_num );
void grf_header_read ( string input_filename, int *node_num, int *edge_num );
int i4vec_max ( int n, int a[] );
int i4vec_min ( int n, int a[] );
void myinit ( );
double r8_max ( double x, double y );
double *r82vec_max ( int n, double a[] );
double *r82vec_min ( int n, double a[] );
int s_len_trim ( string s );
int s_to_i4 ( string s, int *last, bool *error );
bool s_to_i4vec ( string s, int n, int ivec[] );
double s_to_r8 ( string s, int *lchar, bool *error );
bool s_to_r8vec ( string s, int n, double rvec[] );
int s_word_count ( string s );
void timestamp ( );
void xyl_data_print ( int point_num, int line_num,
int line_data_num, int line_pointer[], int line_data[] );
void xyl_header_print ( int point_num, int line_num, int line_data_num );
//
// Global data.
//
int *line_data = NULL;
int line_data_num;
int line_num;
int *line_pointer = NULL;
int pixel_height;
int pixel_width;
int point_num = 0;
double *xy = NULL;
double *xy_max = NULL;
double *xy_min = NULL;
double xy_range[2];
//****************************************************************************80
int main ( int argc, char *argv[] )
//****************************************************************************80
//
// Purpose:
//
// MAIN is the main program for GRF_DISPLAY_OPENGL.
//
// Discussion:
//
// This program reads a GRF file describing an abstract graph
// and displays an OpenGL image.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 13 January 2009
//
// Author:
//
// John Burkardt
//
// Reference:
//
// Edward Angel,
// Interactive Computer Graphics:
// A Top-Down Approach with OpenGL,
// Second Edition,
// Addison Wesley, 2000.
//
{
int edge;
int *edge_data;
int edge_num;
int *edge_pointer;
int i;
int node_i;
int node_j;
int node_num;
string prefix;
string grf_filename;
cout << "\n";
timestamp ( );
cout << "\n";
cout << "GRF_DISPLAY_OPENGL:\n";
cout << " C++ version\n";
cout << "\n";
cout << " Compiled on " << __DATE__ << " at " << __TIME__ << ".\n";
cout << "\n";
cout << " This is a program which uses OpenGL\n";
cout << " to display a graph stored in the GRF format.\n";
//
// If the user did not supply the prefix, request it.
//
if ( argc <= 1 )
{
cout << "\n";
cout << "GRFL_DISPLAY_OPENGL:\n";
cout << " Please enter the \"prefix\" of the GRF file.\n";
cin >> prefix;
}
else
{
prefix = argv[1];
}
//
// Read the GRF data.
//
grf_filename = prefix + ".grf";
grf_header_read ( grf_filename, &node_num, &edge_num );
grf_header_print ( node_num, edge_num );
edge_pointer = new int[node_num+1];
edge_data = new int[edge_num];
xy = new double[2*node_num];
grf_data_read ( grf_filename, node_num, edge_num, edge_pointer, edge_data, xy );
if ( false )
{
grf_data_print ( node_num, edge_num, edge_pointer, edge_data, xy );
}
//
// Convert the GRF data to XY, XYL data.
//
point_num = node_num;
line_num = edge_num;
line_data_num = 2 * edge_num;
xyl_header_print ( point_num, line_num, line_data_num );
line_pointer = new int[line_num+1];
line_data = new int[line_data_num];
line_num = 0;
line_data_num = 0;
line_pointer[0] = 0;
for ( node_i = 0; node_i < node_num; node_i++ )
{
cout << "node_i = " << node_i << "\n";
for ( edge = edge_pointer[node_i]; edge <= edge_pointer[node_i+1] - 1; edge++ )
{
node_j = edge_data[edge] - 1;
line_data[line_data_num] = node_i;
line_data_num = line_data_num + 1;
line_data[line_data_num] = node_j;
cout << node_i << " " << node_j << "\n";
line_data_num = line_data_num + 1;
line_pointer[line_num+1] = line_data_num;
line_num = line_num + 1;
}
}
if ( false )
{
xyl_data_print ( point_num, line_num, line_data_num, line_pointer,
line_data );
}
//
// Get the scale.
//
xy_min = r82vec_min ( point_num, xy );
xy_max = r82vec_max ( point_num, xy );
xy_range[0] = xy_max[0] - xy_min[0];
xy_range[1] = xy_max[1] - xy_min[1];
cout << "\n";
cout << " Minimum: " << xy_min[0] << " "
<< xy_min[1] << "\n";
cout << " Maximum: " << xy_max[0] << " "
<< xy_max[1] << "\n";
cout << " Range: " << xy_range[0] << " "
<< xy_range[1] << "\n";
if ( xy_range[0] == 0.0 )
{
cout << "\n";
cout << "XYL_DISPLAY_OPENGL - Fatal error!\n";
cout << " The X data range is 0.\n";
exit ( 1 );
}
if ( xy_range[1] == 0.0 )
{
cout << "\n";
cout << "XYL_DISPLAY_OPENGL - Fatal error!\n";
cout << " The Y data range is 0.\n";
exit ( 1 );
}
//
// Begin graphics.
//
glutInit ( &argc, argv );
glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB );
if ( xy_range[1] < xy_range[0] )
{
pixel_width = 500;
pixel_height = ( int )
( ( double ) ( 500 ) * xy_range[1] / xy_range[0] );
}
else
{
pixel_width = ( int )
( ( double ) ( 500 ) * xy_range[0] / xy_range[1] );
pixel_height = 500;
}
cout << " Pixels: " << pixel_width << " "
<< pixel_height << "\n";
glutInitWindowSize ( pixel_width, pixel_height );
glutInitWindowPosition ( 0, 0 );
glutCreateWindow ( prefix.c_str() );
glutDisplayFunc ( display );
myinit ( );
glutMainLoop ( );
//
// Free memory.
//
delete [] edge_data;
delete [] edge_pointer;
delete [] line_data;
delete [] line_pointer;
delete [] xy;
//
// Terminate.
//
cout << "\n";
cout << "GRF_DISPLAY_OPENGL:\n";
cout << " Normal end of execution.\n";
cout << "\n";
timestamp ( );
return 0;
}
//****************************************************************************80
bool ch_eqi ( char ch1, char ch2 )
//****************************************************************************80
//
// Purpose:
//
// CH_EQI is true if two characters are equal, disregarding case.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 13 June 2003
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, char CH1, CH2, the characters to compare.
//
// Output, bool CH_EQI, is true if the two characters are equal,
// disregarding case.
//
{
if ( 97 <= ch1 && ch1 <= 122 )
{
ch1 = ch1 - 32;
}
if ( 97 <= ch2 && ch2 <= 122 )
{
ch2 = ch2 - 32;
}
return ( ch1 == ch2 );
}
//****************************************************************************80
int ch_to_digit ( char ch )
//****************************************************************************80
//
// Purpose:
//
// CH_TO_DIGIT returns the integer value of a base 10 digit.
//
// Example:
//
// CH DIGIT
// --- -----
// '0' 0
// '1' 1
// ... ...
// '9' 9
// ' ' 0
// 'X' -1
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 13 June 2003
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, char CH, the decimal digit, '0' through '9' or blank are legal.
//
// Output, int CH_TO_DIGIT, the corresponding integer value. If the character was
// 'illegal', then DIGIT is -1.
//
{
int digit;
if ( '0' <= ch && ch <= '9' )
{
digit = ch - '0';
}
else if ( ch == ' ' )
{
digit = 0;
}
else
{
digit = -1;
}
return digit;
}
//****************************************************************************80
void display ( )
//****************************************************************************80
//
// Purpose:
//
// DISPLAY generates the graphics output.
//
// Discussion;
//
// We plot the points whose coordinates are in XY.
//
// We also dump an ASCII PPM file of the screen.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 22 June 2006
//
// Author:
//
// John Burkardt
//
// Reference:
//
// Edward Angel,
// Interactive Computer Graphics:
// A Top-Down Approach with OpenGL,
// Second Edition,
// Addison Wesley, 2000.
//
{
int i;
int j;
int line;
float p[2];
int point;
//
// Clear the window.
//
glClear ( GL_COLOR_BUFFER_BIT );
//
// Draw points in BLUE.
//
glColor3f ( 0.0, 0.0, 1.0 );
for ( point = 0; point < point_num; point++ )
{
glBegin ( GL_POINTS );
p[0] = ( float ) xy[0+point*2];
p[1] = ( float ) xy[1+point*2];
glVertex2fv ( p );
glEnd ( );
}
//
// Draw lines in RED.
//
glColor3f ( 1.0, 0.0, 0.0 );
for ( line = 0; line < line_num; line++ )
{
glBegin ( GL_LINE_STRIP );
for ( j = line_pointer[line]; j < line_pointer[line+1]; j++ )
{
point = line_data[j];
p[0] = ( float ) xy[0+point*2];
p[1] = ( float ) xy[1+point*2];
glVertex2fv ( p );
}
glEnd ( );
}
//
// Clear all the buffers.
//
glFlush ( );
return;
}
//****************************************************************************80
void grf_data_print ( int node_num, int edge_num, int edge_pointer[],
int edge_data[], double xy[] )
//****************************************************************************80
//
// Purpose:
//
// GRF_DATA_PRINT prints the data of a GRF file.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 11 January 2009
//
// Author:
//
// John Burkardt
//
// Reference:
//
// Stephen Skiena,
// Implementing Discrete Mathematics,
// Combinatorics and Graph Theory with Mathematica,
// Addison-Wesley, 1990.
//
// Parameters:
//
// Input, int NODE_NUM, the number of nodes.
//
// Input, int EDGE_NUM, the number of edges.
//
// Input, int EDGE_POINTER[NODE_NUM+1], pointers to
// the beginning of edge data for each node.
//
// Input, int EDGE_DATA[EDGE_NUM], the edge data.
//
// Input, double XY[2*NODE_NUM], the node coordinates.
//
{
int edge;
int node;
cout << "\n";
cout << " Edge pointers:\n";
cout << "\n";
cout << " Node First Last\n";
cout << "\n";
for ( node = 0; node < node_num; node++ )
{
cout << " " << setw(4) << node
<< " " << setw(8) << edge_pointer[node]
<< " " << setw(8) << edge_pointer[node+1] - 1 << "\n";
}
cout << "\n";
cout << " Edge data:\n";
cout << "\n";
cout << " Node Adjacent nodes\n";
cout << "\n";
for ( node = 0; node < node_num; node++ )
{
cout << " " << setw(4) << node;
for ( edge = edge_pointer[node]; edge <= edge_pointer[node+1] - 1; edge++ )
{
cout << " " << setw(8) << edge_data[edge];
}
cout << "\n";
}
cout << "\n";
cout << " Node X Y\n";
cout << "\n";
for ( node = 0; node < node_num; node++ )
{
cout << " " << setw(4) << node
<< " " << setw(10) << xy[0+node*2]
<< " " << setw(10) << xy[1+node*2] << "\n";
}
return;
}
//****************************************************************************80
void grf_data_read ( string input_filename, int node_num, int edge_num,
int edge_pointer[], int edge_data[], double xy[] )
//****************************************************************************80
//
// Purpose:
//
// GRF_DATA_READ reads the data of a GRF file.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 13 January 2009
//
// Author:
//
// John Burkardt
//
// Reference:
//
// Stephen Skiena,
// Implementing Discrete Mathematics,
// Combinatorics and Graph Theory with Mathematica,
// Addison-Wesley, 1990.
//
// Parameters:
//
// Input, string INPUT_FILENAME, the name of the file.
//
// Input, int NODE_NUM, the number of nodes.
//
// Input, int EDGE_NUM, the number of edges.
//
// Output, int EDGE_POINTER[NODE_NUM+1], pointers to
// the beginning of edge data for each node.
//
// Output, int EDGE_DATA[EDGE_NUM], the edge data.
//
// Output, double XY[2*NODE_NUM], the node coordinates.
//
{
int edge;
int i;
ifstream input;
int n;
int node;
int node_i;
int node_j;
//char text[255];
string text;
int text_begin;
int text_end;
double xval;
double yval;
for ( edge = 0; edge < edge_num; edge++ )
{
edge_data[edge] = -1;
}
for ( node = 0; node < node_num + 1; node++ )
{
edge_pointer[node] = -1;
}
input.open ( input_filename.c_str() );
if ( !input )
{
cout << "\n";
cout << "GRF_DATA_READ - Fatal error!\n";
cout << " Cannot open the input file \"" << input_filename << "\".\n";
exit ( 1 );
}
//
// Read a line. If it's a blank or comment, skip it.
// Otherwise, count the number of "words", and then reread it.
//
edge = 0;
node = 0;
edge_pointer[0] = 0;
for ( node = 0; node < node_num; node++ )
{
text_begin = input.tellg ( );
// input.getline ( text, sizeof ( text ) );
getline ( input, text );
if ( input.eof ( ) )
{
cout << "\n";
cout << "GRF_DATA_READ - Fatal error!\n";
cout << " Unexpected end of information;\n";
exit ( 1 );
}
if ( s_len_trim ( text ) <= 0 )
{
continue;
}
if ( text[0] == '#' )
{
continue;
}
n = s_word_count ( text );
if ( n < 3 )
{
cout << "\n";
cout << "GRF_DATA_READ - Fatal error!\n";
cout << " Record has less than 3 items.\n";
exit ( 1 );
}
text_end = input.tellg ( );
//
// Back up and reread the line.
//
input.seekg ( text_begin );
input >> node_i >> xval >> yval;
edge_pointer[node+1] = edge_pointer[node] + n - 3;
xy[0+node*2] = xval;
xy[1+node*2] = yval;
for ( i = 0; i < n - 3; i++ )
{
input >> node_j;
edge_data[edge] = node_j;
edge = edge + 1;
}
input.seekg ( text_end );
}
input.close ( );
return;
}
//****************************************************************************80
void grf_header_print ( int node_num, int edge_num )
//****************************************************************************80
//
// Purpose:
//
// GRF_HEADER_PRINT prints the header of a GRF file.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 10 January 2009
//
// Author:
//
// John Burkardt
//
// Reference:
//
// Stephen Skiena,
// Implementing Discrete Mathematics,
// Combinatorics and Graph Theory with Mathematica,
// Addison-Wesley, 1990.
//
// Parameters:
//
// Input, int NODE_NUM, the number of nodes.
//
// Input, int EDGE_NUM, the number of edges.
//
{
cout << "\n";
cout << " The number of nodes NODE_NUM = " << node_num << "\n";
cout << " The number of edges EDGE_NUM = " << edge_num << "\n";
return;
}
//****************************************************************************80
void grf_header_read ( string input_filename, int *node_num, int *edge_num )
//****************************************************************************80
//
// Purpose:
//
// GRF_HEADER_READ reads the header of a GRF file.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 25 October 2010
//
// Author:
//
// John Burkardt
//
// Reference:
//
// Stephen Skiena,
// Implementing Discrete Mathematics,
// Combinatorics and Graph Theory with Mathematica,
// Addison-Wesley, 1990.
//
// Parameters:
//
// Input, string INPUT_FILENAME, the name of the file.
//
// Output, int *NODE_NUM, the number of nodes.
//
// Output, int *EDGE_NUM, the number of edges.
//
{
ifstream input;
int n;
string text;
*edge_num = 0;
*node_num = 0;
input.open ( input_filename.c_str() );
if ( !input )
{
cout << "\n";
cout << "GRF_HEADER_READ - Fatal error!\n";
cout << " Cannot open the input file \"" << input_filename << "\".\n";
exit ( 1 );
}
for ( ; ; )
{
getline ( input, text );
if ( input.eof ( ) )
{
break;
}
if ( text[0] == '#' || s_len_trim ( text ) == 0 )
{
continue;
}
n = s_word_count ( text );
if ( n < 3 )
{
cout << "\n";
cout << "GRF_HEADER_READ - Fatal error!\n";
cout << " Illegal record has less than 3 data items\n";
exit ( 1 );
}
*edge_num = *edge_num + n - 3;
*node_num = *node_num + 1;
}
input.close ( );
return;
}
//****************************************************************************80
int i4vec_max ( int n, int a[] )
//****************************************************************************80
//
// Purpose:
//
// I4VEC_MAX returns the value of the maximum element in an I4VEC.
//
// Discussion:
//
// An I4VEC is a vector of I4's.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 17 May 2003
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, int N, the number of entries in the array.
//
// Input, int A[N], the array to be checked.
//
// Output, int I4VEC_MAX, the value of the maximum element. This
// is set to 0 if N <= 0.
//
{
int i;
int value;
if ( n <= 0 )
{
return 0;
}
value = a[0];
for ( i = 1; i < n; i++ )
{
if ( value < a[i] )
{
value = a[i];
}
}
return value;
}
//****************************************************************************80
int i4vec_min ( int n, int a[] )
//****************************************************************************80
//
// Purpose:
//
// I4VEC_MIN returns the value of the minimum element in an I4VEC.
//
// Discussion:
//
// An I4VEC is a vector of I4's.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 17 May 2003
//
// Author:
//
// John Burkardt
//
// Parameters:
//
// Input, int N, the number of entries in the array.
//
// Input, int A[N], the array to be checked.
//
// Output, int I4VEC_MIN, the value of the minimum element. This
// is set to 0 if N <= 0.
//
{
int i;
int value;
if ( n <= 0 )
{
return 0;
}
value = a[0];
for ( i = 1; i < n; i++ )
{
if ( a[i] < value )
{
value = a[i];
}
}
return value;
}
//****************************************************************************80
void myinit ( )
//****************************************************************************80
//
// Purpose:
//
// MYINIT initializes OpenGL state variables dealing with viewing and attributes.
//
// Licensing:
//
// This code is distributed under the GNU LGPL license.
//
// Modified:
//
// 23 June 2006
//
// Author:
//
// John Burkardt
//
// Reference:
//
// Edward Angel,
// Interactive Computer Graphics:
// A Top-Down Approach with OpenGL,
// Second Edition,
// Addison Wesley, 2000.
{
double margin;
float x_max;
float x_min;
float y_max;
float y_min;
//
// Set the background to WHITE.
//
glClearColor ( 1.0, 1.0, 1.0, 1.0 );
//
// The default point size is 1.0.
//
if ( point_num <= 100 )
{
glPointSize ( 5.0 );
}
else if ( point_num <= 500 )
{
glPointSize ( 3.0 );
}
else
{
glPointSize ( 1.0 );
}
//
// Set up the viewing window with origin at the lower left.
//
glMatrixMode ( GL_PROJECTION );
glLoadIdentity ( );
//
// Determine an amount MARGIN by which it would be appropriate to spread the
// data range, so that all the data is comfortably inside the picture.
//
margin = 0.025 * r8_max (
xy_max[0] - xy_min[0],
xy_max[1] - xy_min[1] );