1 //--------------------------------------------------------------------------
2 // Copyright (C) 1993-2001 Maurice LeBrun
3 // Copyright (C) 2000-2018 Alan W. Irwin
4 // Copyright (C) 2003-2013 Andrew Ross
5 // Copyright (C) 2004-2005 Rafael Laboissiere
6 // Copyright (C) 2010 Hezekiah M. Carty
7 // Copyright (C) 2014 Phil Rosenberg
8 //
9 // This file is part of PLplot.
10 //
11 // PLplot is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU Library General Public License as published by
13 // the Free Software Foundation; version 2 of the License.
14 //
15 // PLplot is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 // GNU Library General Public License for more details.
19 //
20 // You should have received a copy of the GNU Library General Public License
21 // along with PLplot; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
23 //--------------------------------------------------------------------------
24 //
25 //--------------------------------------------------------------------------
26 // Implementation of PLplot example 15 in C++.
27 //--------------------------------------------------------------------------
28 
29 #include "plc++demos.h"
30 
31 #ifdef PL_USE_NAMESPACE
32 using namespace std;
33 #endif
34 
35 class x15 {
36 public:
37     x15( int, char ** );
38     void plot1( PLFLT_MATRIX z, PLFLT zmin, PLFLT zmax );
39     void plot2( PLFLT_MATRIX z, PLFLT zmin, PLFLT zmax );
40     void plot3();
41 
42 private:
43     // Class data
44     plstream         *pls;
45 
46     const static int XPTS;
47     const static int YPTS;
48 };
49 
50 const int x15::  XPTS = 35;
51 const int x15::  YPTS = 46;
52 
x15(int argc,char ** argv)53 x15::x15( int argc, char ** argv )
54 {
55     int             i, j;
56 
57     PLFLT           xx;
58     PLFLT           yy;
59     PLFLT           z[XPTS][YPTS];
60     PLFLT_NC_VECTOR zIliffe[XPTS];
61     PLFLT           zmin, zmax;
62 
63     // PLplot initialization
64 
65     pls = new plstream();
66 
67     // Parse and process command line arguments.
68     pls->parseopts( &argc, argv, PL_PARSE_FULL );
69 
70     // Initialize PLplot.
71     pls->init();
72     // no need to fiddle with color maps since example uses default cmap0
73     // and the cmap1 fiddling that x15c.c does is completely irrelevant
74     // (although interesting).
75 
76     // Calculate z data array that is statically allocated above.
77 
78     for ( i = 0; i < XPTS; i++ )
79     {
80         xx = (PLFLT) ( i - ( XPTS / 2 ) ) / (PLFLT) ( XPTS / 2 );
81         for ( j = 0; j < YPTS; j++ )
82         {
83             yy      = ( (PLFLT) ( j - ( YPTS / 2 ) ) / (PLFLT) ( YPTS / 2 ) ) - 1.;
84             z[i][j] = xx * xx - yy * yy + ( xx - yy ) / ( xx * xx + yy * yy + 0.1 );
85         }
86     }
87 
88     // Calculate corresponding Iliffe vector, maximum, and minimum.
89     pls->Static2dGrid( (PLFLT_NC_MATRIX) zIliffe, (PLFLT_VECTOR) ( &z[0][0] ), XPTS, YPTS );
90     pls->MinMax2dGrid( (PLFLT_MATRIX) zIliffe, XPTS, YPTS, &zmax, &zmin );
91 
92     plot1( (PLFLT_MATRIX) zIliffe, zmin, zmax );
93     plot2( (PLFLT_MATRIX) zIliffe, zmin, zmax );
94     plot3();
95 
96     //pls->end();
97 
98     delete pls;
99 }
100 
101 // Illustrates a single shaded region.
102 
plot1(PLFLT_MATRIX z,PLFLT zmin,PLFLT zmax)103 void x15::plot1( PLFLT_MATRIX z, PLFLT zmin, PLFLT zmax )
104 {
105     PLFLT shade_min, shade_max, sh_color;
106     int   sh_cmap = 0;
107     PLFLT sh_width;
108     int   min_color = 0, max_color = 0;
109     PLFLT min_width = 0.0, max_width = 0.0;
110 
111     pls->adv( 0 );
112     pls->vpor( 0.1, 0.9, 0.1, 0.9 );
113     pls->wind( -1.0, 1.0, -1.0, 1.0 );
114 
115     // Plot using identity transform
116 
117     shade_min = zmin + ( zmax - zmin ) * 0.4;
118     shade_max = zmin + ( zmax - zmin ) * 0.6;
119     sh_color  = 7;
120     sh_width  = 2.0;
121     min_color = 9;
122     max_color = 2;
123     min_width = 2.0;
124     max_width = 2.0;
125 
126     pls->psty( 8 );
127 
128     pls->shade( z, XPTS, YPTS, NULL, -1., 1., -1., 1.,
129         shade_min, shade_max,
130         sh_cmap, sh_color, sh_width,
131         min_color, min_width, max_color, max_width,
132         plcallback::fill, true, NULL, NULL );
133 
134     pls->col0( 1 );
135     pls->box( "bcnst", 0.0, 0, "bcnstv", 0.0, 0 );
136     pls->col0( 2 );
137     pls->lab( "distance", "altitude", "Bogon flux" );
138 }
139 
140 // Illustrates multiple adjacent shaded regions, using different fill
141 // patterns for each region.
142 
plot2(PLFLT_MATRIX z,PLFLT zmin,PLFLT zmax)143 void x15::plot2( PLFLT_MATRIX z, PLFLT zmin, PLFLT zmax )
144 {
145     PLFLT        shade_min, shade_max, sh_color;
146     int          sh_cmap = 0;
147     PLFLT        sh_width;
148     int          min_color = 0, max_color = 0;
149     PLFLT        min_width = 0.0, max_width = 0.0;
150     int          i;
151     static PLINT nlin[10]   = { 1, 1, 1, 1, 1, 2, 2, 2, 2, 2 };
152     static PLINT inc[10][2] = { { 450,    0 }, { -450,    0 }, { 0,   0 }, { 900,   0 },
153                                 { 300,    0 }, {  450, -450 }, { 0, 900 }, {   0, 450 },
154                                 { 450, -450 }, {    0,  900 } };
155     static PLINT del[10][2] = { { 2000, 2000 }, { 2000, 2000 }, { 2000, 2000 },
156                                 { 2000, 2000 }, { 2000, 2000 }, { 2000, 2000 },
157                                 { 2000, 2000 }, { 2000, 2000 }, { 4000, 4000 },
158                                 { 4000, 2000 } };
159     sh_width = 2.0;
160 
161     pls->adv( 0 );
162     pls->vpor( 0.1, 0.9, 0.1, 0.9 );
163     pls->wind( -1.0, 1.0, -1.0, 1.0 );
164 
165     // Plot using identity transform
166 
167     for ( i = 0; i < 10; i++ )
168     {
169         shade_min = zmin + ( zmax - zmin ) * i / 10.0;
170         shade_max = zmin + ( zmax - zmin ) * ( i + 1 ) / 10.0;
171         sh_color  = i + 6;
172         pls->pat( nlin[i], inc[i], del[i] );
173 
174         pls->shade( z, XPTS, YPTS, NULL, -1., 1., -1., 1.,
175             shade_min, shade_max,
176             sh_cmap, sh_color, sh_width,
177             min_color, min_width, max_color, max_width,
178             plcallback::fill, true, NULL, NULL );
179     }
180 
181     pls->col0( 1 );
182     pls->box( "bcnst", 0.0, 0, "bcnstv", 0.0, 0 );
183     pls->col0( 2 );
184     pls->lab( "distance", "altitude", "Bogon flux" );
185 }
186 
187 // Illustrates shaded regions in 3d, using a different fill pattern for
188 // each region.
189 
plot3()190 void x15::plot3()
191 {
192     static PLFLT xx[2][5] = { { -1.0, 1.0, 1.0, -1.0, -1.0 },
193                               { -1.0, 1.0, 1.0, -1.0, -1.0 } };
194     static PLFLT yy[2][5] = { {  1.0,  1.0, 0.0, 0.0,  1.0 },
195                               { -1.0, -1.0, 0.0, 0.0, -1.0 } };
196     static PLFLT zz[2][5] = { { 0.0, 0.0, 1.0, 1.0, 0.0 },
197                               { 0.0, 0.0, 1.0, 1.0, 0.0 } };
198 
199     pls->adv( 0 );
200     pls->vpor( 0.1, 0.9, 0.1, 0.9 );
201     pls->wind( -1.0, 1.0, -1.0, 1.0 );
202     pls->w3d( 1., 1., 1., -1.0, 1.0, -1.0, 1.0, 0.0, 1.5, 30, -40 );
203 
204 // Plot using identity transform
205 
206     pls->col0( 1 );
207     pls->box3( "bntu", "X", 0.0, 0, "bntu", "Y", 0.0, 0, "bcdfntu", "Z", 0.5, 0 );
208     pls->col0( 2 );
209     pls->lab( "", "", "3-d polygon filling" );
210 
211     pls->col0( 3 );
212     pls->psty( 1 );
213     pls->line3( 5, xx[0], yy[0], zz[0] );
214     pls->fill3( 4, xx[0], yy[0], zz[0] );
215     pls->psty( 2 );
216     pls->line3( 5, xx[1], yy[1], zz[1] );
217     pls->fill3( 4, xx[1], yy[1], zz[1] );
218 }
219 
220 
main(int argc,char ** argv)221 int main( int argc, char ** argv )
222 {
223     x15 *x = new x15( argc, argv );
224 
225     delete x;
226 }
227 
228 
229 //--------------------------------------------------------------------------
230 //                              End of x15.cc
231 //--------------------------------------------------------------------------
232