PLplot: cdtest.c Source File

PLplot 5.10.0

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
cdtest.c
Go to the documentation of this file.
1
2 #include <stdio.h>
3 #include <math.h>
4 #include <string.h>
5 #include <stdlib.h>
6 #include "defines.h"
7 #include "cd.h"
8
9 // cdtest.c: test program for the cgmdraw module.
10 //
11 // Written by G. Edward Johnson <mailto:lorax@nist.gov>
12 // Date: April 1996
13 // Copyright: cd software produced by NIST, an agency of the
14 // U.S. government, is by statute not subject to copyright
15 // in the United States. Recipients of this software assume all
16 // responsibilities associated with its operation, modification
17 // and maintenance.
18 //
19 //
20
21
22 int main()
23 {
24 cdImagePtr myimage;
25
26 // Color indexes
27 int white;
28 int blue;
29 int red;
30 int green;
31 int black;
32 int lavender;
33 // points for polygons and polylines
34 cdPoint points[15];
35 // output file
36 FILE *outf;
37
38
39 // create an image, 1000 by 1000 pixels
40 myimage = cdImageCreate( 1000, 1000 );
41
42 // Allocate the background color
43 white = cdImageColorAllocate( myimage, 255, 255, 255 );
44 red = cdImageColorAllocate( myimage, 255, 0, 0 );
45 green = cdImageColorAllocate( myimage, 0, 255, 0 );
46 blue = cdImageColorAllocate( myimage, 0, 0, 255 );
47 black = cdImageColorAllocate( myimage, 0, 0, 0 );
48
49 if ( cdSetLineColor( myimage, blue ) )
50 {
51 fprintf( stderr, "cdSetLineColor Successful\n" );
52 }
53 else
54 {
55 fprintf( stderr, "cdSetLineColor Unsuccessful\n" );
56 }
57
58 if ( cdSetLineColor( myimage, blue ) )
59 {
60 fprintf( stderr, "cdSetLineColor Successful\n" );
61 }
62 else
63 {
64 fprintf( stderr, "cdSetLineColor Unsuccessful\n" );
65 }
66
67
68 if ( cdImageLine( myimage, 400, 8, 520, 8, green ) )
69 {
70 fprintf( stderr, "cdImageLine Successful\n" );
71 }
72 else
73 {
74 fprintf( stderr, "cdImageLine Unsuccessful\n" );
75 }
76
77 if ( cdImageLine( myimage, 50, 50, 500, 500, red ) )
78 {
79 fprintf( stderr, "cdImageLine Successful\n" );
80 }
81 else
82 {
83 fprintf( stderr, "cdImageLine Unsuccessful\n" );
84 }
85
86 if ( cdSetLineAttrib( myimage, 2, 3, red ) )
87 {
88 fprintf( stderr, "cdSetLineAttrib Successful\n" );
89 }
90 else
91 {
92 fprintf( stderr, "cdSetLineAttrib Unsuccessful\n" );
93 }
94
95 if ( cdLine( myimage, 500, 50, 50, 500 ) )
96 {
97 fprintf( stderr, "cdLine Successful\n" );
98 }
99 else
100 {
101 fprintf( stderr, "cdLine Unsuccessful\n" );
102 }
103
104 // Now, build a rectangle
105 if ( cdSetShapeFillAttrib( myimage, 3, blue, 6 ) )
106 {
107 fprintf( stderr, "cdSetShapeFillAttrib Successful\n" );
108 }
109 else
110 {
111 fprintf( stderr, "cdSetShapeFillAttrib Unsuccessful\n" );
112 }
113
114 if ( cdSetShapeEdgeAttrib( myimage, 1, 2, green, 1 ) )
115 {
116 fprintf( stderr, "cdSetShapeEdgeAttrib Successful\n" );
117 }
118 else
119 {
120 fprintf( stderr, "cdSetShapeEdgeAttrib Unsuccessful\n" );
121 }
122
123 if ( cdRectangle( myimage, 100, 100, 250, 250 ) )
124 {
125 fprintf( stderr, "cdRectangle Successful\n" );
126 }
127 else
128 {
129 fprintf( stderr, "cdRectangle Unsuccessful\n" );
130 }
131
132
133
134 // now check out each of the line styles in order
135
136 if ( cdSetLineAttrib( myimage, 5, 4, green ) )
137 {
138 fprintf( stderr, "cdSetLineAttrib Successful\n" );
139 }
140 else
141 {
142 fprintf( stderr, "cdSetLineAttrib Unsuccessful\n" );
143 }
144
145 if ( cdLine( myimage, 100, 600, 500, 600 ) )
146 {
147 fprintf( stderr, "cdLine Successful\n" );
148 }
149 else
150 {
151 fprintf( stderr, "cdLine Unsuccessful\n" );
152 }
153
154 if ( cdSetLineAttrib( myimage, 4, -1, -1 ) )
155 {
156 fprintf( stderr, "cdSetLineAttrib Successful\n" );
157 }
158 else
159 {
160 fprintf( stderr, "cdSetLineAttrib Unsuccessful\n" );
161 }
162 if ( cdLine( myimage, 100, 625, 500, 625 ) )
163 {
164 fprintf( stderr, "cdLine Successful\n" );
165 }
166 else
167 {
168 fprintf( stderr, "cdLine Unsuccessful\n" );
169 }
170
171 if ( cdSetLineAttrib( myimage, 3, -1, -1 ) )
172 {
173 fprintf( stderr, "cdSetLineAttrib Successful\n" );
174 }
175 else
176 {
177 fprintf( stderr, "cdSetLineAttrib Unsuccessful\n" );
178 }
179 if ( cdLine( myimage, 100, 650, 500, 650 ) )
180 {
181 fprintf( stderr, "cdLine Successful\n" );
182 }
183 else
184 {
185 fprintf( stderr, "cdLine Unsuccessful\n" );
186 }
187
188
189 if ( cdSetLineAttrib( myimage, 2, -1, -1 ) )
190 {
191 fprintf( stderr, "cdSetLineAttrib Successful\n" );
192 }
193 else
194 {
195 fprintf( stderr, "cdSetLineAttrib Unsuccessful\n" );
196 }
197 if ( cdLine( myimage, 100, 675, 500, 675 ) )
198 {
199 fprintf( stderr, "cdLine Successful\n" );
200 }
201 else
202 {
203 fprintf( stderr, "cdLine Unsuccessful\n" );
204 }
205
206 if ( cdSetLineAttrib( myimage, 1, -1, -1 ) )
207 {
208 fprintf( stderr, "cdSetLineAttrib Successful\n" );
209 }
210 else
211 {
212 fprintf( stderr, "cdSetLineAttrib Unsuccessful\n" );
213 }
214 if ( cdLine( myimage, 100, 700, 500, 700 ) )
215 {
216 fprintf( stderr, "cdLine Successful\n" );
217 }
218 else
219 {
220 fprintf( stderr, "cdLine Unsuccessful\n" );
221 }
222
223 // now make a circle
224 if ( cdSetShapeFillAttrib( myimage, 1, -1, 6 ) )
225 {
226 fprintf( stderr, "cdSetShapeFillAttrib Successful\n" );
227 }
228 else
229 {
230 fprintf( stderr, "cdSetShapeFillAttrib Unsuccessful\n" );
231 }
232
233 if ( cdSetShapeEdgeAttrib( myimage, 1, 2, green, 0 ) )
234 {
235 fprintf( stderr, "cdSetShapeEdgeAttrib Successful\n" );
236 }
237 else
238 {
239 fprintf( stderr, "cdSetShapeEdgeAttrib Unsuccessful\n" );
240 }
241
242 if ( cdCircle( myimage, 500, 500, 25 ) )
243 {
244 fprintf( stderr, "cdCircle Successful\n" );
245 }
246 else
247 {
248 fprintf( stderr, "cdCircle Unsuccessful\n" );
249 }
250
251 // how about a Circular Arc now
252 if ( cdArc3Pt( myimage, 550, 500, 600, 600, 650, 550 ) )
253 {
254 fprintf( stderr, "cdArc3Pt Successful\n" );
255 }
256 else
257 {
258 fprintf( stderr, "cdArc3Pt Unsuccessful\n" );
259 }
260
261 // now draw a closed Circular Arc
262 if ( cdArc3PtClose( myimage, 550, 200, 600, 300, 650, 250, 0 ) )
263 {
264 fprintf( stderr, "cdArc3PtClose Successful\n" );
265 }
266 else
267 {
268 fprintf( stderr, "cdArc3PtClose Unsuccessful\n" );
269 }
270
271 // and now for an ellipse
272 if ( cdSetShapeEdgeAttrib( myimage, 1, 2, green, 1 ) )
273 {
274 fprintf( stderr, "cdSetShapeEdgeAttrib Successful\n" );
275 }
276 else
277 {
278 fprintf( stderr, "cdSetShapeEdgeAttrib Unsuccessful\n" );
279 }
280
281 if ( cdEllipse( myimage, 750, 200, 800, 250, 750, 300 ) )
282 {
283 fprintf( stderr, "cdEllipse Successful\n" );
284 }
285 else
286 {
287 fprintf( stderr, "cdEllipse Unsuccessful\n" );
288 }
289
290
291 // Now, the harder ones. First lets try the polygon stuff
292 // a polygon with 7 or less points
293
294 points[0].x = 700;
295 points[0].y = 700;
296 points[1].x = 725;
297 points[1].y = 750;
298 points[2].x = 775;
299 points[2].y = 650;
300
301 if ( cdPolygon( myimage, points, 3 ) )
302 {
303 fprintf( stderr, "cdPolygon Successful\n" );
304 }
305 else
306 {
307 fprintf( stderr, "cdPolygon Unsuccessful\n" );
308 }
309
310 // Here's a tough one, a polygon with more than seven points
311
312 points[0].x = 800;
313 points[0].y = 700;
314 points[1].x = 825;
315 points[1].y = 725;
316 points[2].x = 850;
317 points[2].y = 700;
318 points[3].x = 875;
319 points[3].y = 750;
320 points[4].x = 900;
321 points[4].y = 775;
322 points[5].x = 925;
323 points[5].y = 750;
324 points[6].x = 950;
325 points[6].y = 850;
326 points[7].x = 925;
327 points[7].y = 850;
328 points[8].x = 875;
329 points[8].y = 800;
330 points[9].x = 850;
331 points[9].y = 825;
332 points[10].x = 825;
333 points[10].y = 900;
334
335 if ( cdPolygon( myimage, points, 11 ) )
336 {
337 fprintf( stderr, "cdPolygon Successful\n" );
338 }
339 else
340 {
341 fprintf( stderr, "cdPolygon Unsuccessful\n" );
342 }
343
344 // Now for a polygon set, two polygons (both triangles) the first one
345 // with an invisible edge closing it.
346
347 points[0].x = 500; // start of first polygon
348 points[0].y = 350;
349 points[0].e = 1; // edge out is visible
350 points[1].x = 575;
351 points[1].y = 350;
352 points[1].e = 1;
353 points[2].x = 575;
354 points[2].y = 430;
355 points[2].e = 3; // close polygon with visible edge
356 points[3].x = 600; // start of second polygon
357 points[3].y = 350;
358 points[3].e = 0; // edge out is invisible
359 points[4].x = 700;
360 points[4].y = 350;
361 points[4].e = 1;
362 points[5].x = 650;
363 points[5].y = 475;
364 points[5].e = 2; // close polygone with an invisible edge
365
366 // make the edges wider so it is easier to see if they are there
367 if ( cdSetEdgeWidth( myimage, 3 ) )
368 {
369 fprintf( stderr, "cdSetEdgeWidth Successful\n" );
370 }
371 else
372 {
373 fprintf( stderr, "cdSetEdgeWidth Unsuccessful\n" );
374 }
375 if ( cdPolygonSet( myimage, points, 6 ) ) // draw the polygonset
376 {
377 fprintf( stderr, "cdPolygonSet Successful\n" );
378 }
379 else
380 {
381 fprintf( stderr, "cdPolygonSet Unsuccessful\n" );
382 }
383
384 // now for poly lines, just like polygons (except they're lines)
385
386 if ( cdSetLineAttrib( myimage, 1, 1, red ) )
387 {
388 fprintf( stderr, "cdSetLineAttrib Successful\n" );
389 }
390 else
391 {
392 fprintf( stderr, "cdSetLineAttrib Unsuccessful\n" );
393 }
394
395
396 points[0].x = 400;
397 points[0].y = 16;
398 points[1].x = 520;
399 points[1].y = 16;
400 if ( cdPolyLine( myimage, points, 2 ) )
401 {
402 fprintf( stderr, "cdPolyLine Successful\n" );
403 }
404 else
405 {
406 fprintf( stderr, "cdPolyLine Unsuccessful\n" );
407 }
408
409 points[0].x = 800;
410 points[0].y = 650;
411 points[1].x = 825;
412 points[1].y = 675;
413 points[2].x = 850;
414 points[2].y = 650;
415 points[3].x = 875;
416 points[3].y = 700;
417 if ( cdPolyLine( myimage, points, 4 ) )
418 {
419 fprintf( stderr, "cdPolyLine Successful\n" );
420 }
421 else
422 {
423 fprintf( stderr, "cdPolyLine Unsuccessful\n" );
424 }
425
426
427 // Markers
428 // set the attributes
429 if ( cdSetMarkerAttrib( myimage, 1, 1, green ) )
430 {
431 fprintf( stderr, "cdSetMarkerAttrib Successful\n" );
432 }
433 else
434 {
435 fprintf( stderr, "cdSetMarkerAttrib Unsuccessful\n" );
436 }
437
438 // now plot the marker
439
440 if ( cdMarker( myimage, 900, 500 ) )
441 {
442 fprintf( stderr, "cdMarker Successful\n" );
443 }
444 else
445 {
446 fprintf( stderr, "cdMarker Unsuccessful\n" );
447 }
448
449
450 if ( cdSetMarkerAttrib( myimage, 5, 3, black ) )
451 {
452 // set the marker type to cross
453 fprintf( stderr, "cdSetMarkerAttrib Successful\n" );
454 }
455 else
456 {
457 fprintf( stderr, "cdSetMarkerAttrib Unsuccessful\n" );
458 }
459
460 // a Poly Marker, two markers in different places
461 points[0].x = 715;
462 points[0].y = 785;
463 points[1].x = 735;
464 points[1].y = 815;
465
466 if ( cdPolyMarker( myimage, points, 2 ) )
467 {
468 fprintf( stderr, "cdPolyMarker Successful\n" );
469 }
470 else
471 {
472 fprintf( stderr, "cdMarker Unsuccessful\n" );
473 }
474
475
476 // Hey, things are going so well, lets do some text
477 lavender = cdImageColorAllocate( myimage, 204, 102, 255 );
478
479 if ( cdSetTextAttrib( myimage, 1, lavender, 50 ) )
480 {
481 fprintf( stderr, "cdSetTextAttrib Successful\n" );
482 }
483 else
484 {
485 fprintf( stderr, "cdSetTextAttrib Unsuccessful\n" );
486 }
487
488 if ( cdText( myimage, 50, 800, "CGM Draw Version 1.3" ) )
489 {
490 fprintf( stderr, "cdText Successful\n" );
491 }
492 else
493 {
494 fprintf( stderr, "cdText Unsuccessful\n" );
495 }
496
497 // More text. This time test TextPath and TextOrient
498 if ( cdSetTextPath( myimage, 3 ) )
499 {
500 fprintf( stderr, "cdSetTextPath Successful\n" );
501 }
502 else
503 {
504 fprintf( stderr, "cdSetTextPath Unsuccessful\n" );
505 }
506
507 if ( cdText( myimage, 50, 800, "CGM Draw" ) )
508 {
509 fprintf( stderr, "cdText Successful\n" );
510 }
511 else
512 {
513 fprintf( stderr, "cdText Unsuccessful\n" );
514 }
515
516 if ( cdSetTextOrient( myimage, 1, 0, 0, -1 ) )
517 {
518 fprintf( stderr, "cdSetTextOrient Successful\n" );
519 }
520 else
521 {
522 fprintf( stderr, "cdSetTextOrient Unsuccessful\n" );
523 }
524
525 if ( cdSetTextPath( myimage, 0 ) )
526 {
527 fprintf( stderr, "cdSetTextPath Successful\n" );
528 }
529 else
530 {
531 fprintf( stderr, "cdSetTextPath Unsuccessful\n" );
532 }
533
534 if ( cdText( myimage, 950, 400, "CGM Draw" ) )
535 {
536 fprintf( stderr, "cdText Successful\n" );
537 }
538 else
539 {
540 fprintf( stderr, "cdText Unsuccessful\n" );
541 }
542
543
544 if ( cdSetTextOrient( myimage, 0, 1, 1, 0 ) )
545 {
546 fprintf( stderr, "cdSetTextOrient Successful\n" );
547 }
548 else
549 {
550 fprintf( stderr, "cdSetTextOrient Unsuccessful\n" );
551 }
552
553
554 if ( cdSetTextAttrib( myimage, 5, -1, 25 ) )
555 {
556 fprintf( stderr, "cdSetTextAttrib Successful\n" );
557 }
558 else
559 {
560 fprintf( stderr, "cdSetTextAttrib Unsuccessful\n" );
561 }
562
563 if ( cdText( myimage, 5, 5, "G. Edward Johnson" ) )
564 {
565 fprintf( stderr, "cdText Successful\n" );
566 }
567 else
568 {
569 fprintf( stderr, "cdText Unsuccessful\n" );
570 }
571
572
573
574
575 outf = fopen( "cdout.cgm", "wb" );
576 if ( !outf )
577 return 1;
578 cdImageCgm( myimage, outf );
579 fclose( outf );
580 outf = 0;
581
582 cdImageDestroy( myimage );
583
584
585 return 0;
586 }