PLplot: cdexpert.c Source File

PLplot 5.15.0

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)
62 CD_CHECK_RETURN( cdImageSetLineSpec( im, 0 ) );
63 CD_CHECK_RETURN( cdImageSetMarkerSpec( im, 0 ) );
64 CD_CHECK_RETURN( cdImageSetEdgeSpec( im, 0 ) );
65 // Clear the font list, then set it to just contain 1 font
66 CD_CHECK_RETURN( cdImageClearFonts( im ) );
67 CD_CHECK_RETURN( cdImageAddFont( im, "TIMES_ROMAN" ) );
68 // start the picture
69 CD_CHECK_RETURN( cdCgmHeader( im ) );
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
113 CD_CHECK_RETURN( cdImageEndPic( im ) );
114 // set the specifications modes back to the default
115 CD_CHECK_RETURN( cdImageSetLineSpec( im, 1 ) );
116 CD_CHECK_RETURN( cdImageSetMarkerSpec( im, 1 ) );
117 CD_CHECK_RETURN( cdImageSetEdgeSpec( im, 1 ) );
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 }
cdSetLineAttrib
int cdSetLineAttrib(cdImagePtr im, int lntype, int lnwidth, int lncolor)
Definition: cd.c:1652
cdPolyMarker
int cdPolyMarker(cdImagePtr im, cdPointPtr p, int n)
Definition: cd.c:2859
cdImageCgm
int cdImageCgm(cdImagePtr im, FILE *out)
Definition: cd.c:560
cdMarker
int cdMarker(cdImagePtr im, int x, int y)
Definition: cd.c:2188
cdRectangle
int cdRectangle(cdImagePtr im, int x1, int y1, int x2, int y2)
Definition: cd.c:2235
cdImageEndPic
int cdImageEndPic(cdImagePtr im)
Definition: cd.c:3300
cdImageClearFonts
int cdImageClearFonts(cdImagePtr im)
Definition: cd.c:3198
cdImageSetSize
int cdImageSetSize(cdImagePtr im, int x, int y)
Definition: cd.c:3104
cdImageStruct
Definition: cd.h:60
cdImageSetMarkerSpec
int cdImageSetMarkerSpec(cdImagePtr im, int specmode)
Definition: cd.c:3123
cdImageAddFont
int cdImageAddFont(cdImagePtr im, const char *fontname)
Definition: cd.c:3163
cdImageDestroy
int cdImageDestroy(cdImagePtr im)
Definition: cd.c:1766
cdText
int cdText(cdImagePtr im, int x, int y, const char *ts)
Definition: cd.c:2945
cdSetTextAttrib
int cdSetTextAttrib(cdImagePtr im, int font, int color, int height)
Definition: cd.c:1720
main
int main()
Definition: cdexpert.c:35
defines.h
cdLine
int cdLine(cdImagePtr im, int x1, int y1, int x2, int y2)
Definition: cd.c:2116
cdSetShapeFillAttrib
int cdSetShapeFillAttrib(cdImagePtr im, int instyle, int incolor, int inhatch)
Definition: cd.c:1668
cdSetMarkerAttrib
int cdSetMarkerAttrib(cdImagePtr im, int mtype, int msize, int mcolor)
Definition: cd.c:1750
cdImageColorAllocate
int cdImageColorAllocate(cdImagePtr im, int r, int g, int b)
Definition: cd.c:1966
cdCgmPic
int cdCgmPic(cdImagePtr im, int sticky)
Definition: cd.c:365
cdPointStruct::x
int x
Definition: cd.h:130
cd.h
CD_CHECK_RETURN
#define CD_CHECK_RETURN(x)
Definition: cdexpert.c:26
cdCgmHeader
int cdCgmHeader(cdImagePtr im)
Definition: cd.c:214
cdPointStruct
Definition: cd.h:128
cdImageSetEdgeSpec
int cdImageSetEdgeSpec(cdImagePtr im, int specmode)
Definition: cd.c:3134
cdImageSetLineSpec
int cdImageSetLineSpec(cdImagePtr im, int specmode)
Definition: cd.c:3112
cdSetShapeEdgeAttrib
int cdSetShapeEdgeAttrib(cdImagePtr im, int edtype, int edwidth, int edcolor, int edvis)
Definition: cd.c:1693
cdPointStruct::y
int y
Definition: cd.h:130
cdImageStartCgm
cdImagePtr cdImageStartCgm()
Definition: cd.c:3246