PLplot  5.10.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
cdexpert.c
Go to the documentation of this file.
1 //
2 // cdexpert highlights the expert functions in CD. You probably
3 // don't want to use these unless you have to.
4 //
5 //
6 // cdexpert.c: test program for the cgmdraw module.
7 //
8 // Written by G. Edward Johnson <mailto:lorax@nist.gov>
9 // Date: January 1997
10 // Copyright: cd software produced by NIST, an agency of the
11 // U.S. government, is by statute not subject to copyright
12 // in the United States. Recipients of this software assume all
13 // responsibilities associated with its operation, modification
14 // and maintenance.
15 //
16 //
17 
18 
19 #include <stdio.h>
20 #include <math.h>
21 #include <string.h>
22 #include <stdlib.h>
23 #include "defines.h"
24 #include "cd.h"
25 
26 #define CD_CHECK_RETURN( x ) \
27  if ( !( x ) ) \
28  { \
29  cdImageDestroy( im ); \
30  fclose( outf ); \
31  return 1; \
32  }
33 
34 
35 int main()
36 {
37  // you must create a pointer to the image(s) that you will be using
38  // not suprisingly, it is of type cdImagePtr
39  cdImagePtr im;
40  cdPoint points[2];
41 
42  // this is a pointer to the output file you will be using
43  FILE *outf;
44 
45  // these will be index's into the color palette containing
46  // the corresponding colors
47  int black, white, blue;
48 
49  // Create an image
50  im = cdImageStartCgm();
51  // now open the file lets call it cdexpert1.cgm
52  outf = fopen( "cdexp1.cgm", "wb" );
53  if ( !outf )
54  {
55  cdImageDestroy( im );
56  return 1;
57  }
58  // set its size to 500x500
59  CD_CHECK_RETURN( cdImageSetSize( im, 500, 500 ) );
60  // set Line, Marker, and Edge specification modes to absolute (0)
61  // the default is scaled (1)
65  // Clear the font list, then set it to just contain 1 font
67  CD_CHECK_RETURN( cdImageAddFont( im, "TIMES_ROMAN" ) );
68  // start the picture
70  CD_CHECK_RETURN( cdCgmPic( im, 2 ) );
71 
72 
73  // allocate some colors (isn't this fun?)
74  // the first color allocated is the background color
75  white = cdImageColorAllocate( im, 255, 255, 255 );
76  black = cdImageColorAllocate( im, 0, 0, 0 );
77  blue = cdImageColorAllocate( im, 0, 0, 255 );
78 
79  // fill attributes: Empty
80  CD_CHECK_RETURN( cdSetShapeFillAttrib( im, 4, -1, -1 ) );
81 
82  // Edge attributes: dots, width 3, blue, visible edges.
83  CD_CHECK_RETURN( cdSetShapeEdgeAttrib( im, 2, 3, blue, 1 ) );
84 
85  // Text attributes: Times, black, size 25
86  CD_CHECK_RETURN( cdSetTextAttrib( im, 1, black, 25 ) );
87 
88  // Line attributes: Solid Black Line of Width 5
89  CD_CHECK_RETURN( cdSetLineAttrib( im, 1, 5, black ) );
90 
91  // Marker attributes: style pluses, size 3, black
92  CD_CHECK_RETURN( cdSetMarkerAttrib( im, 2, 3, black ) );
93 
94  // Now that we have set some attributes, lets do some drawing
95 
96  // Draw a rectangle (10,450) is upper left, (350,350) is lower right
97  CD_CHECK_RETURN( cdRectangle( im, 10, 450, 350, 350 ) );
98  // Draw a line (300,100) to (400,100)
99  CD_CHECK_RETURN( cdLine( im, 300, 100, 400, 100 ) );
100 
101  // Add Two markers
102  CD_CHECK_RETURN( cdMarker( im, 325, 150 ) );
103  CD_CHECK_RETURN( cdMarker( im, 375, 150 ) );
104 
105  // lets put some text in the picture too.
106  // (100,100) is the point at the lower left corner of the text
107  CD_CHECK_RETURN( cdText( im, 100, 100, "Hello World" ) );
108 
109  // we could just finish off the CGM here with a
110  // cdImageCgm(im, outf), but lets put another picture in.
111 
112  // close the picture
114  // set the specifications modes back to the default
118  // start a new picture, keeping all the changes we made, including
119  // the color table
120  CD_CHECK_RETURN( cdCgmPic( im, 1 ) );
121 
122  // draw the same image again, notice the Specification modes are
123  // different
124  // Draw a rectangle (10,450) is upper left, (350,350) is lower right
125  CD_CHECK_RETURN( cdRectangle( im, 10, 450, 350, 350 ) );
126 
127  // Draw a line (300,100) to (400,100)
128  CD_CHECK_RETURN( cdLine( im, 300, 100, 400, 100 ) );
129 
130  // Add Two markers
131  // we are doing the markers a little bit differently this time
132  points[0].x = 325;
133  points[0].y = 150;
134  points[1].x = 375;
135  points[1].y = 150;
136  CD_CHECK_RETURN( cdPolyMarker( im, points, 2 ) );
137 
138  // lets put some text in the picture too.
139  // (100,100) is the point at the lower left corner of the text
140  CD_CHECK_RETURN( cdText( im, 100, 100, "Hello World" ) );
141 
142  cdImageCgm( im, outf );
143  fclose( outf );
144  outf = 0;
145 
146  // Remember to destroy the image when you are done
147  cdImageDestroy( im );
148  im = 0;
149 
150  printf( "I am a CGM expert!!!\n" );
151 
152  return 0;
153 }